From a244cf647e2481df34512b5b9624d2807d0de50c Mon Sep 17 00:00:00 2001 From: nifi Date: Tue, 28 Sep 2010 23:32:51 +0000 Subject: [PATCH] Added stop button to stop any running commands --- .../sics/contiki/collect/gui/NodeControl.java | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/examples/sky-shell/src/se/sics/contiki/collect/gui/NodeControl.java b/examples/sky-shell/src/se/sics/contiki/collect/gui/NodeControl.java index 3a0ce8b3b..05661060e 100644 --- a/examples/sky-shell/src/se/sics/contiki/collect/gui/NodeControl.java +++ b/examples/sky-shell/src/se/sics/contiki/collect/gui/NodeControl.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: NodeControl.java,v 1.1 2010/09/28 23:12:18 nifi Exp $ + * $Id: NodeControl.java,v 1.2 2010/09/28 23:32:51 nifi Exp $ * * ----------------------------------------------------------------- * @@ -34,8 +34,8 @@ * * Authors : Niclas Finne * Created : 27 sep 2010 - * Updated : $Date: 2010/09/28 23:12:18 $ - * $Revision: 1.1 $ + * Updated : $Date: 2010/09/28 23:32:51 $ + * $Revision: 1.2 $ */ package se.sics.contiki.collect.gui; @@ -63,19 +63,31 @@ import se.sics.contiki.collect.Visualizer; */ public class NodeControl implements Visualizer { + private final CollectServer server; private final String category; private final JPanel panel; + private final JLabel statusLabel; - public NodeControl(final CollectServer server, String category) { + public NodeControl(CollectServer server, String category) { + this.server = server; this.category = category; this.panel = new JPanel(new BorderLayout()); final JFormattedTextField intervalField = new JFormattedTextField(new Integer(60)); final JFormattedTextField randomField = new JFormattedTextField(new Integer(2)); final JFormattedTextField reportsField = new JFormattedTextField(new Integer(0)); - final JLabel statusLabel = new JLabel("", JLabel.CENTER); + statusLabel = new JLabel("", JLabel.CENTER); statusLabel.setOpaque(true); + JButton stopButton = new JButton("Send stop to nodes"); + stopButton.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + sendCommand("netcmd killall"); + } + + }); + JButton sendButton = new JButton("Send command to nodes"); sendButton.addActionListener(new ActionListener() { @@ -84,18 +96,8 @@ public class NodeControl implements Visualizer { int random = (Integer)randomField.getValue(); int reports = (Integer)reportsField.getValue(); - String cmd = "netcmd { repeat " + reports - + " " + interval + " { randwait " + random - + " sky-alldata | blink | send } }"; - statusLabel.setBackground(Color.white); - statusLabel.setBorder(LineBorder.createBlackLineBorder()); - if (server.sendToNode(cmd)) { - statusLabel.setForeground(Color.black); - statusLabel.setText("Sent command '" + cmd + "'"); - } else { - statusLabel.setForeground(Color.red); - statusLabel.setText("Failed to send command. No serial connection."); - } + sendCommand("netcmd { repeat " + reports + " " + interval + + " { randwait " + random + " sky-alldata | blink | send } }"); } }); @@ -147,6 +149,22 @@ public class NodeControl implements Visualizer { controlPanel.add(statusLabel, c); panel.add(controlPanel, BorderLayout.NORTH); + + controlPanel = new JPanel(); + controlPanel.add(stopButton); + panel.add(controlPanel, BorderLayout.SOUTH); + } + + protected void sendCommand(String command) { + statusLabel.setBackground(Color.white); + statusLabel.setBorder(LineBorder.createBlackLineBorder()); + if (server.sendToNode(command)) { + statusLabel.setForeground(Color.black); + statusLabel.setText("Sent command '" + command + "'"); + } else { + statusLabel.setForeground(Color.red); + statusLabel.setText("Failed to send command. No serial connection."); + } } public String getCategory() {