removed mote type visualizer (only showing identifier)

This commit is contained in:
fros4943 2008-02-07 13:15:22 +00:00
parent cbdb1c242d
commit b0e07a06cf

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: MoteInformation.java,v 1.4 2007/04/02 16:44:44 fros4943 Exp $ * $Id: MoteInformation.java,v 1.5 2008/02/07 13:15:22 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -62,9 +62,9 @@ public class MoteInformation extends VisPlugin {
private Observer stateObserver; private Observer stateObserver;
private Vector<JPanel> visibleMoteInterfaces = new Vector<JPanel>(); private Vector<JPanel> visibleMoteInterfaces = new Vector<JPanel>();
private Simulation mySimulation; private Simulation mySimulation;
/** /**
* Create a new mote information window. * Create a new mote information window.
* *
@ -75,7 +75,7 @@ public class MoteInformation extends VisPlugin {
mote = moteToView; mote = moteToView;
mySimulation = simulation; mySimulation = simulation;
JLabel label; JLabel label;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
@ -87,7 +87,7 @@ public class MoteInformation extends VisPlugin {
label = new JLabel("Remove mote"); label = new JLabel("Remove mote");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
smallPane.add(BorderLayout.WEST, label); smallPane.add(BorderLayout.WEST, label);
JButton button = new JButton("Remove"); JButton button = new JButton("Remove");
button.setActionCommand("removeMote"); button.setActionCommand("removeMote");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
@ -96,22 +96,23 @@ public class MoteInformation extends VisPlugin {
dispose(); dispose();
} }
}); });
smallPane.add(BorderLayout.EAST, button); smallPane.add(BorderLayout.EAST, button);
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25))); mainPane.add(Box.createRigidArea(new Dimension(0,25)));
// Visualize mote type // Visualize state
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- STATE --"); label = new JLabel("-- STATE --");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
smallPane.add(BorderLayout.WEST, label); smallPane.add(BorderLayout.WEST, label);
if (mote.getState() == Mote.State.ACTIVE) if (mote.getState() == Mote.State.ACTIVE) {
label = new JLabel("active"); label = new JLabel("active");
else if (mote.getState() == State.LPM) } else if (mote.getState() == State.LPM) {
label = new JLabel("low power mode"); label = new JLabel("low power mode");
else } else {
label = new JLabel("dead"); label = new JLabel("dead");
}
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
stateLabel = label; stateLabel = label;
@ -126,16 +127,13 @@ public class MoteInformation extends VisPlugin {
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(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.WEST, label);
JPanel moteVis = mote.getType().getTypeVisualizer(); label = new JLabel(moteToView.getType().getIdentifier() + ": \"" + moteToView.getType().getDescription() + "\"");
if (moteVis != null) { label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
moteVis.setBorder(BorderFactory.createEtchedBorder()); smallPane.add(BorderLayout.EAST, label);
smallPane.add(moteVis);
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
}
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
// All interfaces // All interfaces
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
@ -145,7 +143,7 @@ public class MoteInformation extends VisPlugin {
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,10))); mainPane.add(Box.createRigidArea(new Dimension(0,10)));
for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) { for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) {
smallPane = new JPanel(); smallPane = new JPanel();
smallPane.setLayout(new BorderLayout()); smallPane.setLayout(new BorderLayout());
@ -156,7 +154,7 @@ public class MoteInformation extends VisPlugin {
label = new JLabel(interfaceDescription); label = new JLabel(interfaceDescription);
label.setAlignmentX(JLabel.CENTER_ALIGNMENT); label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.NORTH, label);
if (interfaceVisualizer != null) { if (interfaceVisualizer != null) {
interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder()); interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder());
smallPane.add(BorderLayout.CENTER, interfaceVisualizer); smallPane.add(BorderLayout.CENTER, interfaceVisualizer);
@ -165,7 +163,7 @@ public class MoteInformation extends VisPlugin {
interfaceVisualizer.putClientProperty("my_interface", moteInterface); interfaceVisualizer.putClientProperty("my_interface", moteInterface);
visibleMoteInterfaces.add(interfaceVisualizer); visibleMoteInterfaces.add(interfaceVisualizer);
} }
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,5))); mainPane.add(Box.createRigidArea(new Dimension(0,5)));
} }
@ -175,12 +173,12 @@ public class MoteInformation extends VisPlugin {
MoteInterface moteInterface = mote.getInterfaces().getAllPassiveInterfaces().get(i); MoteInterface moteInterface = mote.getInterfaces().getAllPassiveInterfaces().get(i);
String interfaceDescription = GUI.getDescriptionOf(moteInterface); String interfaceDescription = GUI.getDescriptionOf(moteInterface);
JPanel interfaceVisualizer = moteInterface.getInterfaceVisualizer(); JPanel interfaceVisualizer = moteInterface.getInterfaceVisualizer();
label = new JLabel(interfaceDescription); label = new JLabel(interfaceDescription);
label.setAlignmentX(JLabel.CENTER_ALIGNMENT); label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.NORTH, label);
if (interfaceVisualizer != null) { if (interfaceVisualizer != null) {
interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder()); interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder());
smallPane.add(BorderLayout.CENTER, interfaceVisualizer); smallPane.add(BorderLayout.CENTER, interfaceVisualizer);
@ -189,49 +187,51 @@ public class MoteInformation extends VisPlugin {
interfaceVisualizer.putClientProperty("my_interface", moteInterface); interfaceVisualizer.putClientProperty("my_interface", moteInterface);
visibleMoteInterfaces.add(interfaceVisualizer); visibleMoteInterfaces.add(interfaceVisualizer);
} }
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,5))); mainPane.add(Box.createRigidArea(new Dimension(0,5)));
} }
this.getContentPane().add(BorderLayout.NORTH, new JScrollPane(mainPane, this.getContentPane().add(BorderLayout.NORTH, new JScrollPane(mainPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
pack(); pack();
setPreferredSize(new Dimension(350,500)); setPreferredSize(new Dimension(350,500));
setSize(new Dimension(350,500)); setSize(new Dimension(350,500));
try { try {
setSelected(true); setSelected(true);
} catch (java.beans.PropertyVetoException e) { } catch (java.beans.PropertyVetoException e) {
// Could not select // Could not select
} }
// Register as state observer to detect if mote changes state // Register as state observer to detect if mote changes state
mote.addStateObserver(stateObserver = new Observer() { mote.addStateObserver(stateObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
if (mote.getState() == State.ACTIVE) if (mote.getState() == State.ACTIVE) {
stateLabel.setText("active"); stateLabel.setText("active");
else if (mote.getState() == Mote.State.LPM) } else if (mote.getState() == Mote.State.LPM) {
stateLabel.setText("low power mode"); stateLabel.setText("low power mode");
else } else {
stateLabel.setText("dead"); stateLabel.setText("dead");
}
} }
}); });
} }
public void closePlugin() { public void closePlugin() {
// Remove state observer // Remove state observer
mote.deleteStateObserver(stateObserver); mote.deleteStateObserver(stateObserver);
// Release all interface visualizations // Release all interface visualizations
for (JPanel interfaceVisualization: visibleMoteInterfaces) { for (JPanel interfaceVisualization: visibleMoteInterfaces) {
MoteInterface moteInterface = (MoteInterface) interfaceVisualization.getClientProperty("my_interface"); MoteInterface moteInterface = (MoteInterface) interfaceVisualization.getClientProperty("my_interface");
if (moteInterface != null && interfaceVisualization != null) if (moteInterface != null && interfaceVisualization != null) {
moteInterface.releaseInterfaceVisualizer(interfaceVisualization); moteInterface.releaseInterfaceVisualizer(interfaceVisualization);
else } else {
logger.warn("Could not release panel"); logger.warn("Could not release panel");
}
} }
} }