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
* 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
* Created : 3 jul 2008
* Updated : $Date: 2010/10/13 22:55:47 $
* $Revision: 1.28 $
* Updated : $Date: 2010/10/14 18:13:09 $
* $Revision: 1.29 $
*/
package se.sics.contiki.collect;
@ -128,12 +128,12 @@ public class CollectServer implements SerialConnectionListener {
private JFrame window;
private JTabbedPane mainPanel;
private HashMap<String,JTabbedPane> categoryTable = new HashMap<String,JTabbedPane>();
private JMenuItem serialItem;
private JMenuItem runInitScriptItem;
private final Visualizer[] visualizers;
private final MapPanel mapPanel;
private final SerialConsole serialConsole;
private final ConnectSerialAction connectSerialAction;
private final MoteProgramAction moteProgramAction;
private JFileChooser fileChooser;
@ -182,6 +182,7 @@ public class CollectServer implements SerialConnectionListener {
});
moteProgramAction = new MoteProgramAction("Program Nodes...");
connectSerialAction = new ConnectSerialAction("Connect to serial");
nodeModel = new DefaultListModel();
nodeModel.addElement("<All>");
@ -585,9 +586,7 @@ public class CollectServer implements SerialConnectionListener {
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
serialItem = new JMenuItem("Connect to serial");
serialItem.addActionListener(new SerialItemHandler());
fileMenu.add(serialItem);
fileMenu.add(new JMenuItem(connectSerialAction));
fileMenu.add(new JMenuItem(moteProgramAction));
fileMenu.addSeparator();
@ -872,6 +871,10 @@ public class CollectServer implements SerialConnectionListener {
return moteProgramAction;
}
public Action getConnectSerialAction() {
return connectSerialAction;
}
protected void setSystemMessage(final String message) {
SwingUtilities.invokeLater(new Runnable() {
@ -882,7 +885,8 @@ public class CollectServer implements SerialConnectionListener {
} else {
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
&& serialConnection.isSerialOutputSupported() && hasInitScript());
}
@ -1210,10 +1214,16 @@ public class CollectServer implements SerialConnectionListener {
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;
public ConnectSerialAction(String name) {
super(name);
}
public void actionPerformed(ActionEvent e) {
if (!isRunning) {
isRunning = true;

View File

@ -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.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
* Created : 27 sep 2010
* Updated : $Date: 2010/10/12 16:28:19 $
* $Revision: 1.6 $
* Updated : $Date: 2010/10/14 18:13:10 $
* $Revision: 1.7 $
*/
package se.sics.contiki.collect.gui;
@ -135,13 +135,20 @@ public class NodeControl implements Visualizer {
c.gridy++;
c.gridwidth = 1;
controlPanel.add(new JLabel("Program Connected Nodes", JLabel.RIGHT), c);
c.gridwidth = 2;
c.gridwidth = 3;
c.fill = GridBagConstraints.NONE;
controlPanel.add(new JButton(server.getMoteProgramAction()), c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy++;
c.gridwidth = 1;
controlPanel.add(new JLabel("Serial Connection", JLabel.RIGHT), c);
c.gridwidth = 3;
c.fill = GridBagConstraints.NONE;
controlPanel.add(new JButton(server.getConnectSerialAction()), c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy++;
controlPanel.add(new JSeparator(), c);
c.gridy++;
@ -209,7 +216,8 @@ public class NodeControl implements Visualizer {
"<lu>" +
"<li> Connect nodes to USB. Press the <strong>Program Nodes...</strong> button." +
"<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." +
"</lu>" +
"</html>");