3 import diku
.distlab
.motecontrolclientlib
.client
.*;
5 import java
.awt
.event
.*;
7 import java
.util
.Properties
;
9 * Created on Sep 18, 2005
11 * TODO To change the template for this generated file go to
12 * Window - Preferences - Java - Code Style - Code Templates
18 * TODO To change the template for this generated type comment go to Window -
19 * Preferences - Java - Code Style - Code Templates
21 public class MoteToolBar
extends JToolBar
implements ActionListener
{
26 private static final long serialVersionUID
= 3453850507315394343L;
27 private long moteid
[] = new long[1];
28 private SimpleMoteManager moteManager
;
29 public MoteToolBar(long moteid
, SimpleMoteManager moteManager
)
31 super("Mote control");
32 this.moteid
[0] = moteid
;
33 this.moteManager
= moteManager
;
34 // put buttons on the toolbar
35 this.setFloatable(false);
36 add(MainWindow
.createButton("program","/toolbarButtonGraphics/general/Save16.gif","Upload a program to the selected mote(s).",this));
37 add(MainWindow
.createButton("cancelprogram","/toolbarButtonGraphics/general/Stop16.gif","Cancel the programming of the mote.",this));
38 add(MainWindow
.createButton("start","/toolbarButtonGraphics/media/Play16.gif","Start the selected mote(s).",this));
39 add(MainWindow
.createButton("stop","/toolbarButtonGraphics/media/Stop16.gif","Stop the selected mote(s).",this));
40 add(MainWindow
.createButton("reset","/toolbarButtonGraphics/media/StepForward16.gif","Reset the selected mote(s).",this));
43 public void actionPerformed(ActionEvent e
)
45 Properties settings
= MainWindow
.getMainWindow().getSettings();
48 String cmd
= e
.getActionCommand();
49 if ( cmd
.equals("program") )
51 JFileChooser fc
= new JFileChooser(settings
.getProperty("flashImagePath","/"));
52 fc
.setFileFilter(new FlashImageFilter());
53 int returnVal
= fc
.showOpenDialog(this);
55 if (returnVal
== JFileChooser
.APPROVE_OPTION
) {
56 File file
= fc
.getSelectedFile();
57 FileInputStream fi
= new FileInputStream(file
);
58 byte[] image
= new byte[(int)file
.length()];
60 moteManager
.program(moteid
,image
);
62 settings
.setProperty("flashImagePath",file
.getParent());
63 MainWindow
.getMainWindow().saveSettings();
66 else if ( cmd
.equals("cancelprogram") )
68 moteManager
.cancelProgramming(moteid
);
70 else if ( cmd
.equals("start") )
72 moteManager
.start(moteid
);
74 else if ( cmd
.equals("stop") )
76 moteManager
.stop(moteid
);
78 else if ( cmd
.equals("reset") )
80 moteManager
.reset(moteid
);