mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-03 14:29:00 +00:00
plugin cleanup: removed list of mote interfaces, instead providing links to useful mote plugins
This commit is contained in:
parent
f237e16d71
commit
8d7f9e2d72
@ -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;
|
||||||
|
|
||||||
|
JPanel mainPane = new JPanel();
|
||||||
|
mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||||
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
/* Mote type */
|
||||||
|
smallPane = new JPanel(new BorderLayout());
|
||||||
|
label = new JLabel("Mote type");
|
||||||
|
label.setPreferredSize(size);
|
||||||
|
smallPane.add(BorderLayout.WEST, label);
|
||||||
|
label = new JLabel(mote.getType().getDescription());
|
||||||
|
label.setPreferredSize(size);
|
||||||
|
smallPane.add(BorderLayout.EAST, label);
|
||||||
|
mainPane.add(smallPane);
|
||||||
|
|
||||||
|
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 */
|
||||||
|
smallPane = new JPanel(new BorderLayout());
|
||||||
|
label = new JLabel("Mote interfaces");
|
||||||
|
label.setPreferredSize(size);
|
||||||
|
smallPane.add(BorderLayout.WEST, label);
|
||||||
|
label = new JLabel(mote.getInterfaces().getInterfaces().size() + " interfaces");
|
||||||
|
label.setPreferredSize(size);
|
||||||
|
smallPane.add(BorderLayout.EAST, label);
|
||||||
|
mainPane.add(smallPane);
|
||||||
|
|
||||||
|
smallPane = new JPanel(new BorderLayout());
|
||||||
|
button = new JButton("Mote interface viewer");
|
||||||
|
button.setPreferredSize(size);
|
||||||
|
button.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
simulation.getGUI().tryStartPlugin(MoteInterfaceViewer.class, simulation.getGUI(), simulation, mote);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove button */
|
/* Remove button */
|
||||||
smallPane = new JPanel(new BorderLayout());
|
smallPane = new JPanel(new BorderLayout());
|
||||||
label = new JLabel("Remove mote");
|
label = new JLabel("Remove mote");
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
label.setPreferredSize(size);
|
||||||
smallPane.add(BorderLayout.WEST, label);
|
smallPane.add(BorderLayout.WEST, label);
|
||||||
|
|
||||||
JButton button = new JButton("Remove");
|
button = new JButton("Remove");
|
||||||
button.setActionCommand("removeMote");
|
button.setPreferredSize(size);
|
||||||
button.addActionListener(new ActionListener() {
|
button.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
mySimulation.removeMote(mote);
|
/* TODO In simulation event (if running) */
|
||||||
dispose();
|
simulation.removeMote(MoteInformation.this.mote);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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(smallPane);
|
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
|
|
||||||
|
|
||||||
/* Mote type */
|
|
||||||
smallPane = new JPanel(new BorderLayout());
|
|
||||||
label = new JLabel("-- MOTE TYPE --");
|
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
|
||||||
smallPane.add(BorderLayout.WEST, label);
|
|
||||||
label = new JLabel(moteToView.getType().getIdentifier() + ": \"" + moteToView.getType().getDescription() + "\"");
|
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
|
||||||
smallPane.add(BorderLayout.EAST, label);
|
|
||||||
|
|
||||||
mainPane.add(smallPane);
|
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,25)));
|
|
||||||
|
|
||||||
/* Mote interfaces */
|
|
||||||
smallPane = new JPanel(new BorderLayout());
|
|
||||||
label = new JLabel("-- MOTE INTERFACES --");
|
|
||||||
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
|
|
||||||
smallPane.add(BorderLayout.NORTH, label);
|
|
||||||
|
|
||||||
mainPane.add(smallPane);
|
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,10)));
|
|
||||||
|
|
||||||
for (MoteInterface intf : mote.getInterfaces().getInterfaces()) {
|
|
||||||
smallPane = new JPanel();
|
|
||||||
smallPane.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
String interfaceDescription = GUI.getDescriptionOf(intf);
|
|
||||||
JPanel interfaceVisualizer = intf.getInterfaceVisualizer();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
mainPane.add(smallPane);
|
|
||||||
mainPane.add(Box.createRigidArea(new Dimension(0,5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user