plugin cleanup: removed list of mote interfaces, instead providing links to useful mote plugins

This commit is contained in:
fros4943 2010-05-17 09:30:27 +00:00
parent f237e16d71
commit 8d7f9e2d72
1 changed files with 106 additions and 90 deletions

View File

@ -26,18 +26,33 @@
* 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: MoteInformation.java,v 1.8 2010/01/15 10:54:42 fros4943 Exp $ * $Id: MoteInformation.java,v 1.9 2010/05/17 09:30:27 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*; import java.awt.Dimension;
import java.util.*; import java.awt.event.ActionEvent;
import javax.swing.*; import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.*; import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.Mote;
import se.sics.cooja.MotePlugin;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.motes.AbstractEmulatedMote;
/** /**
* Mote information displays information about a given mote. * Mote information displays information about a given mote.
@ -47,101 +62,118 @@ import se.sics.cooja.*;
@ClassDescription("Mote Information") @ClassDescription("Mote Information")
@PluginType(PluginType.MOTE_PLUGIN) @PluginType(PluginType.MOTE_PLUGIN)
public class MoteInformation extends VisPlugin implements MotePlugin { public class MoteInformation extends VisPlugin implements MotePlugin {
private static final long serialVersionUID = 2359676837283723500L;
private static Logger logger = Logger.getLogger(MoteInformation.class); private static Logger logger = Logger.getLogger(MoteInformation.class);
private static final long serialVersionUID = 1L;
private Mote mote; private Mote mote;
private final static int LABEL_WIDTH = 170; private final static int LABEL_WIDTH = 170;
private final static int LABEL_HEIGHT = 15; private final static int LABEL_HEIGHT = 20;
private final static Dimension size = new Dimension(LABEL_WIDTH,LABEL_HEIGHT);
private Vector<JPanel> visibleMoteInterfaces = new Vector<JPanel>();
private Simulation simulation;
private Simulation mySimulation;
/** /**
* Create a new mote information window. * Create a new mote information window.
* *
* @param moteToView Mote to view * @param m Mote
* @param s Simulation
* @param gui Simulator
*/ */
public MoteInformation(Mote moteToView, Simulation simulation, GUI gui) { public MoteInformation(Mote m, Simulation s, GUI gui) {
super("Mote Information (" + moteToView + ")", gui); super("Mote Information (" + m + ")", gui);
this.mote = m;
mote = moteToView; this.simulation = s;
mySimulation = simulation;
JLabel label; JLabel label;
JPanel mainPane = new JPanel(); JButton button;
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
JPanel smallPane; JPanel smallPane;
/* Remove button */ JPanel mainPane = new JPanel();
smallPane = new JPanel(new BorderLayout()); mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
label = new JLabel("Remove mote"); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
smallPane.add(BorderLayout.WEST, label);
JButton button = new JButton("Remove");
button.setActionCommand("removeMote");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mySimulation.removeMote(mote);
dispose();
}
});
smallPane.add(BorderLayout.EAST, button);
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
/* Mote type */ /* Mote type */
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- MOTE TYPE --"); label = new JLabel("Mote type");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(size);
smallPane.add(BorderLayout.WEST, label); smallPane.add(BorderLayout.WEST, label);
label = new JLabel(moteToView.getType().getIdentifier() + ": \"" + moteToView.getType().getDescription() + "\""); label = new JLabel(mote.getType().getDescription());
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(size);
smallPane.add(BorderLayout.EAST, label); smallPane.add(BorderLayout.EAST, label);
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
smallPane = new JPanel(new BorderLayout());
label = new JLabel(mote.getType().getIdentifier());
label.setPreferredSize(size);
smallPane.add(BorderLayout.EAST, label);
mainPane.add(smallPane);
smallPane = new JPanel(new BorderLayout());
button = new JButton("Mote type information");
button.setPreferredSize(size);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
simulation.getGUI().tryStartPlugin(MoteTypeInformation.class, simulation.getGUI(), simulation, mote);
}
});
smallPane.add(BorderLayout.EAST, button);
mainPane.add(smallPane);
/* Mote interfaces */ /* Mote interfaces */
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- MOTE INTERFACES --"); label = new JLabel("Mote interfaces");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(size);
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.WEST, label);
label = new JLabel(mote.getInterfaces().getInterfaces().size() + " interfaces");
label.setPreferredSize(size);
smallPane.add(BorderLayout.EAST, label);
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,10)));
for (MoteInterface intf : mote.getInterfaces().getInterfaces()) { smallPane = new JPanel(new BorderLayout());
smallPane = new JPanel(); button = new JButton("Mote interface viewer");
smallPane.setLayout(new BorderLayout()); button.setPreferredSize(size);
button.addActionListener(new ActionListener() {
String interfaceDescription = GUI.getDescriptionOf(intf); public void actionPerformed(ActionEvent e) {
JPanel interfaceVisualizer = intf.getInterfaceVisualizer(); simulation.getGUI().tryStartPlugin(MoteInterfaceViewer.class, simulation.getGUI(), simulation, mote);
label = new JLabel(interfaceDescription);
label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
smallPane.add(BorderLayout.NORTH, label);
if (interfaceVisualizer != null) {
interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder());
smallPane.add(BorderLayout.CENTER, interfaceVisualizer);
// Tag each visualized interface
interfaceVisualizer.putClientProperty("my_interface", intf);
visibleMoteInterfaces.add(interfaceVisualizer);
} }
});
smallPane.add(BorderLayout.EAST, button);
mainPane.add(smallPane);
/* CPU frequency */
if (mote instanceof AbstractEmulatedMote) {
AbstractEmulatedMote emulatedMote = (AbstractEmulatedMote) mote;
smallPane = new JPanel(new BorderLayout());
label = new JLabel("CPU frequency");
label.setPreferredSize(size);
smallPane.add(BorderLayout.WEST, label);
if (emulatedMote.getCPUFrequency() < 0) {
label = new JLabel("[unknown]");
} else {
label = new JLabel(emulatedMote.getCPUFrequency() + " Hz");
}
label.setPreferredSize(size);
smallPane.add(BorderLayout.EAST, label);
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,5)));
} }
/* Remove button */
smallPane = new JPanel(new BorderLayout());
label = new JLabel("Remove mote");
label.setPreferredSize(size);
smallPane.add(BorderLayout.WEST, label);
button = new JButton("Remove");
button.setPreferredSize(size);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/* TODO In simulation event (if running) */
simulation.removeMote(MoteInformation.this.mote);
}
});
smallPane.add(BorderLayout.EAST, button);
mainPane.add(smallPane);
this.getContentPane().add(BorderLayout.CENTER, this.getContentPane().add(BorderLayout.CENTER,
new JScrollPane(mainPane, new JScrollPane(mainPane,
@ -149,26 +181,10 @@ public class MoteInformation extends VisPlugin implements MotePlugin {
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
pack(); pack();
setPreferredSize(new Dimension(getWidth()+15, 250)); setSize(new Dimension(getWidth()+15, getHeight()+15));
setSize(new Dimension(getWidth()+15, 250));
try {
setSelected(true);
} catch (java.beans.PropertyVetoException e) {
// Could not select
}
} }
public void closePlugin() { public void closePlugin() {
// Release all interface visualizations
for (JPanel interfaceVisualization: visibleMoteInterfaces) {
MoteInterface moteInterface = (MoteInterface) interfaceVisualization.getClientProperty("my_interface");
if (moteInterface != null) {
moteInterface.releaseInterfaceVisualizer(interfaceVisualization);
} else {
logger.warn("Could not release panel");
}
}
} }
public Mote getMote() { public Mote getMote() {