/* * This file is part of the Remote Sensor Actuator Interface (ReSAI). * * Copyright(c) Andreas Kipp, Frederic Siepmann * http://opensource.cit-ec.de/projects/resai * * This file may be licensed under the terms of of the * GNU Lesser General Public License Version 3 (the ``LGPL''), * or (at your option) any later version. * * Software distributed under the License is distributed * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either * express or implied. See the LGPL for the specific language * governing rights and limitations. * * You should have received a copy of the LGPL along with this * program. If not, go to http://www.gnu.org/licenses/lgpl.html * or write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The development of this software was supported by the * Excellence Cluster EXC 277 Cognitive Interaction Technology. * The Excellence Cluster EXC 277 is a grant of the Deutsche * Forschungsgemeinschaft (DFG) in the context of the German * Excellence Initiative. * */ /** * Panel for the SLAM sensor. * * @author akipp */ package de.unibi.airobots.resaijavaclient.gui.panels.components; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Observable; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import org.jivesoftware.smack.util.Base64; import de.unibi.airobots.resaijavaclient.communicaton.Communicator; import de.unibi.airobots.resaijavaclient.gui.panels.components.template.PanelTemplate; import de.unibi.airobots.resaijavaclient.helper.DataPacker; public class SlamPanel extends PanelTemplate implements MouseListener, ActionListener { private static final long serialVersionUID = 1L; private JLabel lblImage = new JLabel(); private JLabel lblX = new JLabel("0"); private JLabel lblY = new JLabel("0"); private JButton btnSendTarget = new JButton("Send Target"); private JButton btnManualStop = new JButton("Manual Stop"); public SlamPanel() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JScrollPane imagePane = new JScrollPane(lblImage); imagePane.setSize(new Dimension(900, 400)); imagePane.setMinimumSize(new Dimension(800, 400)); imagePane.setMaximumSize(new Dimension(800, 400)); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; add(imagePane, c); lblImage.addMouseListener(this); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; add(btnSendTarget, c); btnSendTarget.addActionListener(this); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; add(btnManualStop, c); btnManualStop.addActionListener(this); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 2; add(lblX, c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 2; add(lblY, c); } @Override public void update(Observable o, Object arg) { if (o instanceof Communicator) { Communicator com = (Communicator) o; if (arg instanceof HashMap) { @SuppressWarnings("unchecked") HashMap receivedProperties = (HashMap) arg; if (com.getRecipientTAG().equals(component)) { String _img = receivedProperties.get(component + "_IMG") .toString(); if (_img.length() > 0) { byte[] imageByte = DataPacker.decompressBytes(Base64 .decode(_img)); ImageIcon ic = new ImageIcon(imageByte); BufferedImage img = new BufferedImage( ic.getIconWidth(), ic.getIconHeight(), 1); Graphics g = img.getGraphics(); g.drawImage(ic.getImage(), 0, 0, null); g.setColor(java.awt.Color.blue); g.fillOval(Integer.parseInt(lblX.getText()) - 5, Integer.parseInt(lblY.getText()) - 5, 10, 10); ic.setImage(img); lblImage.setIcon(ic); } } } } } @Override public void mouseClicked(MouseEvent e) { lblX.setText(String.valueOf(e.getX())); lblY.setText(String.valueOf(e.getY())); } @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(btnSendTarget)) { if (JOptionPane.showConfirmDialog(null, "Send new target?", "Navigation", JOptionPane.OK_CANCEL_OPTION) == 0) { HashMap propertiesToSend = new HashMap(); propertiesToSend.put("TAG", "NavigationActuatorThread"); propertiesToSend.put("NAVDATA", "true"); propertiesToSend.put("X", lblX.getText()); propertiesToSend.put("Y", lblY.getText()); overviewController.sendMessage(propertiesToSend); } } if (e.getSource().equals(btnManualStop)) { HashMap propertiesToSend = new HashMap(); propertiesToSend.put("TAG", "NavigationActuatorThread"); propertiesToSend.put("NavigationActuatorThread", "True"); propertiesToSend.put("MANUALSTOP", "true"); overviewController.sendMessage(propertiesToSend); } } }