Initial import of ClientModules from the sourceforge CVS repository
[remote/remote-gui.git] / DIKUClientMainModule / old / gui / MoteToolBar.java
blobe847d52351581aa95efa4afd5b4a6d4bdff8eba4
1 package gui;
2 import javax.swing.*;
3 import diku.distlab.motecontrolclientlib.client.*;
5 import java.awt.event.*;
6 import java.io.*;
7 import java.util.Properties;
8 /*
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
15 /**
16 * @author zept
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 {
23 /**
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();
46 try
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()];
59 fi.read(image);
60 moteManager.program(moteid,image);
61 fi.close();
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);
83 catch (Exception ex)