Added button to connect to serial in the node control panel

This commit is contained in:
nifi 2010-10-14 18:13:09 +00:00
parent 0322b4ed22
commit b49db633f3
2 changed files with 32 additions and 14 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: CollectServer.java,v 1.28 2010/10/13 22:55:47 nifi Exp $ * $Id: CollectServer.java,v 1.29 2010/10/14 18:13:09 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/10/13 22:55:47 $ * Updated : $Date: 2010/10/14 18:13:09 $
* $Revision: 1.28 $ * $Revision: 1.29 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -128,12 +128,12 @@ public class CollectServer implements SerialConnectionListener {
private JFrame window; private JFrame window;
private JTabbedPane mainPanel; private JTabbedPane mainPanel;
private HashMap<String,JTabbedPane> categoryTable = new HashMap<String,JTabbedPane>(); private HashMap<String,JTabbedPane> categoryTable = new HashMap<String,JTabbedPane>();
private JMenuItem serialItem;
private JMenuItem runInitScriptItem; private JMenuItem runInitScriptItem;
private final Visualizer[] visualizers; private final Visualizer[] visualizers;
private final MapPanel mapPanel; private final MapPanel mapPanel;
private final SerialConsole serialConsole; private final SerialConsole serialConsole;
private final ConnectSerialAction connectSerialAction;
private final MoteProgramAction moteProgramAction; private final MoteProgramAction moteProgramAction;
private JFileChooser fileChooser; private JFileChooser fileChooser;
@ -182,6 +182,7 @@ public class CollectServer implements SerialConnectionListener {
}); });
moteProgramAction = new MoteProgramAction("Program Nodes..."); moteProgramAction = new MoteProgramAction("Program Nodes...");
connectSerialAction = new ConnectSerialAction("Connect to serial");
nodeModel = new DefaultListModel(); nodeModel = new DefaultListModel();
nodeModel.addElement("<All>"); nodeModel.addElement("<All>");
@ -585,9 +586,7 @@ public class CollectServer implements SerialConnectionListener {
JMenu fileMenu = new JMenu("File"); JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F); fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu); menuBar.add(fileMenu);
serialItem = new JMenuItem("Connect to serial"); fileMenu.add(new JMenuItem(connectSerialAction));
serialItem.addActionListener(new SerialItemHandler());
fileMenu.add(serialItem);
fileMenu.add(new JMenuItem(moteProgramAction)); fileMenu.add(new JMenuItem(moteProgramAction));
fileMenu.addSeparator(); fileMenu.addSeparator();
@ -872,6 +871,10 @@ public class CollectServer implements SerialConnectionListener {
return moteProgramAction; return moteProgramAction;
} }
public Action getConnectSerialAction() {
return connectSerialAction;
}
protected void setSystemMessage(final String message) { protected void setSystemMessage(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@ -882,7 +885,8 @@ public class CollectServer implements SerialConnectionListener {
} else { } else {
window.setTitle(WINDOW_TITLE + " (" + message + ')'); window.setTitle(WINDOW_TITLE + " (" + message + ')');
} }
serialItem.setText(isOpen ? "Disconnect from serial" : "Connect to serial"); connectSerialAction.putValue(ConnectSerialAction.NAME,
isOpen ? "Disconnect from serial" : "Connect to serial");
runInitScriptItem.setEnabled(isOpen runInitScriptItem.setEnabled(isOpen
&& serialConnection.isSerialOutputSupported() && hasInitScript()); && serialConnection.isSerialOutputSupported() && hasInitScript());
} }
@ -1210,10 +1214,16 @@ public class CollectServer implements SerialConnectionListener {
this.sensorDataOutput = null; this.sensorDataOutput = null;
} }
protected class SerialItemHandler implements ActionListener, Runnable { protected class ConnectSerialAction extends AbstractAction implements Runnable {
private static final long serialVersionUID = 1L;
private boolean isRunning; private boolean isRunning;
public ConnectSerialAction(String name) {
super(name);
}
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (!isRunning) { if (!isRunning) {
isRunning = true; isRunning = true;

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: NodeControl.java,v 1.6 2010/10/12 16:28:19 nifi Exp $ * $Id: NodeControl.java,v 1.7 2010/10/14 18:13:10 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Niclas Finne * Authors : Niclas Finne
* Created : 27 sep 2010 * Created : 27 sep 2010
* Updated : $Date: 2010/10/12 16:28:19 $ * Updated : $Date: 2010/10/14 18:13:10 $
* $Revision: 1.6 $ * $Revision: 1.7 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -135,13 +135,20 @@ public class NodeControl implements Visualizer {
c.gridy++; c.gridy++;
c.gridwidth = 1; c.gridwidth = 1;
controlPanel.add(new JLabel("Program Connected Nodes", JLabel.RIGHT), c); controlPanel.add(new JLabel("Program Connected Nodes", JLabel.RIGHT), c);
c.gridwidth = 2; c.gridwidth = 3;
c.fill = GridBagConstraints.NONE; c.fill = GridBagConstraints.NONE;
controlPanel.add(new JButton(server.getMoteProgramAction()), c); controlPanel.add(new JButton(server.getMoteProgramAction()), c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy++; c.gridy++;
c.gridwidth = 1;
controlPanel.add(new JLabel("Serial Connection", JLabel.RIGHT), c);
c.gridwidth = 3; c.gridwidth = 3;
c.fill = GridBagConstraints.NONE;
controlPanel.add(new JButton(server.getConnectSerialAction()), c);
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.gridy++;
controlPanel.add(new JSeparator(), c); controlPanel.add(new JSeparator(), c);
c.gridy++; c.gridy++;
@ -209,7 +216,8 @@ public class NodeControl implements Visualizer {
"<lu>" + "<lu>" +
"<li> Connect nodes to USB. Press the <strong>Program Nodes...</strong> button." + "<li> Connect nodes to USB. Press the <strong>Program Nodes...</strong> button." +
"<li> Disconnect all except one node. " + "<li> Disconnect all except one node. " +
"Press the <strong>Start Collect</strong> button." + "Press the <strong>Connect to Serial</strong> button." +
"<li> Press the <strong>Start Collect</strong> button." +
"<li> Press the <strong>Send command to nodes</strong> button." + "<li> Press the <strong>Send command to nodes</strong> button." +
"</lu>" + "</lu>" +
"</html>"); "</html>");