/* * 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 control of the log dispatcher. * * @author akipp */ package de.unibi.airobots.resaijavaclient.gui.panels.components; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import java.util.Observable; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JPanel; import de.unibi.airobots.resaijavaclient.communicaton.Communicator; import de.unibi.airobots.resaijavaclient.constants.Constants; import de.unibi.airobots.resaijavaclient.gui.panels.components.template.PanelTemplate; public class LogPanel extends PanelTemplate implements ActionListener { private static final long serialVersionUID = 1L; private static JPanel pnlCheckBoxes = new JPanel(); private static JButton btnStart = new JButton("Start Logging"); private static JButton btnStop = new JButton("Stop Logging"); private HashMap checkedBoxes = new HashMap(); public LogPanel() { pnlCheckBoxes.setLayout(new BoxLayout(pnlCheckBoxes, BoxLayout.PAGE_AXIS)); add(pnlCheckBoxes); pnlCheckBoxes.add(btnStart); pnlCheckBoxes.add(btnStop); btnStart.addActionListener(this); btnStart.setActionCommand(Constants.START); btnStop.addActionListener(this); btnStop.setActionCommand(Constants.STOP); btnStop.setEnabled(false); } @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) && receivedProperties.containsKey(Constants.SET_LIST)) { for (String prop : receivedProperties.keySet()) { if (receivedProperties.get(prop).equals( Constants.ELEMENT)) { JCheckBox cb = new JCheckBox(); cb.setText(prop); pnlCheckBoxes.add(cb); cb.addActionListener(this); cb.setActionCommand(prop); checkedBoxes.put(prop, cb); } } } } } } @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(Constants.START)) { HashMap propertiesToSend = new HashMap(); propertiesToSend.put(Constants.TAG, Constants.LOGDISPATCHER); propertiesToSend.put(Constants.START, Constants.TRUE); for (String prop : checkedBoxes.keySet()) { if (checkedBoxes.get(prop).isSelected()) { propertiesToSend.put(prop, Constants.ELEMENT); } checkedBoxes.get(prop).setEnabled(false); } overviewController.sendMessage(propertiesToSend); btnStart.setEnabled(false); btnStop.setEnabled(true); } else if (e.getActionCommand().equals(Constants.STOP)) { HashMap propertiesToSend = new HashMap(); propertiesToSend.put(Constants.TAG, Constants.LOGDISPATCHER); propertiesToSend.put(Constants.STOP, Constants.TRUE); overviewController.sendMessage(propertiesToSend); for (String prop : checkedBoxes.keySet()) { checkedBoxes.get(prop).setEnabled(true); } btnStart.setEnabled(true); btnStop.setEnabled(false); } } }