disallowed starting plugins/visualizer skins for non-compatible motes/simulations

This commit is contained in:
Fredrik Osterlind 2012-05-24 13:58:12 +02:00
parent e18cc3b6b9
commit 24aafe5554
8 changed files with 95 additions and 51 deletions

View File

@ -102,6 +102,7 @@ import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.interfaces.DirectionalAntennaRadio;
import se.sics.cooja.interfaces.Position;
@ -123,6 +124,7 @@ import se.sics.mrm.ChannelModel.TxPair;
*/
@ClassDescription("MRM Radio environment")
@PluginType(PluginType.SIM_PLUGIN)
@SupportedArguments(radioMediums = {MRM.class})
public class AreaViewer extends VisPlugin {
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(AreaViewer.class);
@ -211,9 +213,9 @@ public class AreaViewer extends VisPlugin {
private JRadioButton panModeButton;
private JRadioButton zoomModeButton;
private JRadioButton trackModeButton;
private Action paintEnvironmentAction;
/**
* Initializes an AreaViewer.
*
@ -267,7 +269,7 @@ public class AreaViewer extends VisPlugin {
trackModeButton.setActionCommand("set track rays mode");
trackModeButton.addActionListener(canvasModeHandler);
trackModeButton.setEnabled(false);
ButtonGroup group = new ButtonGroup();
group.add(selectModeButton);
group.add(panModeButton);
@ -676,7 +678,7 @@ public class AreaViewer extends VisPlugin {
panModeButton.doClick();
//canvasModeHandler.actionPerformed(new ActionEvent(e, 0, "set zoom mode"));
}
if (popUpToolTip != null) {
popUpToolTip.hide();
popUpToolTip = null;
@ -751,16 +753,16 @@ public class AreaViewer extends VisPlugin {
};
trackedComponents = currentChannelModel.getRaysOfTransmission(txPair);
canvas.repaint();
/* Show popup */
JToolTip t = AreaViewer.this.createToolTip();
String logHtml =
"<html>" +
String logHtml =
"<html>" +
trackedComponents.log.replace("\n", "<br>").replace(" pi", " &pi;") +
"</html>";
t.setTipText(logHtml);
if (t.getTipText() == null || t.getTipText().equals("")) {
return;
}

View File

@ -31,17 +31,38 @@
package se.sics.mrm;
import java.awt.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.NumberFormat;
import java.util.*;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.mrm.ChannelModel.Parameter;
/**
@ -51,6 +72,7 @@ import se.sics.mrm.ChannelModel.Parameter;
*/
@ClassDescription("MRM Settings")
@PluginType(PluginType.SIM_PLUGIN)
@SupportedArguments(radioMediums = {MRM.class})
public class FormulaViewer extends se.sics.cooja.VisPlugin {
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(FormulaViewer.class);
@ -164,14 +186,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
collapsableArea,
channelModel.getParameterDoubleValue(Parameter.captureEffectPreambleDuration)
);
addDoubleParameter(
Parameter.captureEffectSignalTreshold,
Parameter.getDescription(Parameter.captureEffectSignalTreshold),
collapsableArea,
channelModel.getParameterDoubleValue(Parameter.captureEffectSignalTreshold)
);
// Transmitter parameters
collapsableArea = createCollapsableArea("Transmitter parameters", allComponents);
areaTransmitter = collapsableArea;
@ -429,14 +451,14 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
textField.setBackground(null);
textField.setToolTipText(null);
}
allDoubleParameters.add(textField);
contentPane.add(panel);
return textField;
}
/**
* Creates and adds a panel with a label and a
* text field which accepts integers.
@ -534,7 +556,7 @@ public class FormulaViewer extends se.sics.cooja.VisPlugin {
} else {
checkBox.setText("");
}
allBooleanParameters.add(checkBox);
contentPane.add(panel);

View File

@ -39,6 +39,7 @@ import org.apache.log4j.Logger;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.plugins.Visualizer;
@ -47,6 +48,7 @@ import se.sics.mrm.ChannelModel.RadioPair;
import se.sics.mrm.ChannelModel.TxPair;
@ClassDescription("Radio environment (MRM)")
@SupportedArguments(radioMediums = {MRM.class})
public class MRMVisualizerSkin implements VisualizerSkin {
private static Logger logger = Logger.getLogger(MRMVisualizerSkin.class);
@ -79,7 +81,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
public void paintBeforeMotes(Graphics g) {
final Mote selectedMote = visualizer.getSelectedMote();
if (simulation == null
if (simulation == null
|| selectedMote == null
|| selectedMote.getInterfaces().getRadio() == null) {
return;

View File

@ -52,6 +52,7 @@ import se.sics.cooja.Mote;
import se.sics.cooja.MotePlugin;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.dialogs.UpdateAggregator;
import se.sics.cooja.mspmote.MspMote;
@ -61,6 +62,7 @@ import se.sics.mspsim.cli.LineOutputStream;
@ClassDescription("Msp CLI")
@PluginType(PluginType.MOTE_PLUGIN)
@SupportedArguments(motes = {MspMote.class})
public class MspCLI extends VisPlugin implements MotePlugin {
private static final long serialVersionUID = 2833218439838209672L;

View File

@ -35,17 +35,31 @@ import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.*;
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.SupportedArguments;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.mspmote.MspMote;
import se.sics.mspsim.core.MSP430;
@ClassDescription("Msp Cycle Watcher")
@PluginType(PluginType.MOTE_PLUGIN)
@SupportedArguments(motes = {MspMote.class})
public class MspCycleWatcher extends VisPlugin implements MotePlugin {
private static Logger logger = Logger.getLogger(MspStackWatcher.class);
private MspMote mspMote;

View File

@ -50,18 +50,19 @@ import se.sics.cooja.Mote;
import se.sics.cooja.MotePlugin;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.mspmote.MspMote;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.ui.StackUI;
import se.sics.mspsim.ui.WindowManager;
import se.sics.mspsim.util.Utils;
@ClassDescription("Msp Stack Watcher")
@PluginType(PluginType.MOTE_PLUGIN)
@SupportedArguments(motes = {MspMote.class})
public class MspStackWatcher extends VisPlugin implements MotePlugin {
private static Logger logger = Logger.getLogger(MspStackWatcher.class);
private MspMote mspMote;
private MSP430 cpu;
private StackUI stackUI;
@ -121,7 +122,7 @@ public class MspStackWatcher extends VisPlugin implements MotePlugin {
stackUI = new StackUI(cpu);
stackUI.init("MSPSim stack", mspMote.registry);
stackUI.start();
// Register as log listener
/*if (logObserver == null && mspMote.getInterfaces().getLog() != null) {
mspMote.getInterfaces().getLog().addObserver(logObserver = new Observer() {

View File

@ -65,6 +65,7 @@ import se.sics.cooja.GUI;
import se.sics.cooja.Mote;
import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin;
import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.radiomediums.AbstractRadioMedium;
@ -74,14 +75,15 @@ import se.sics.cooja.radiomediums.DirectedGraphMedium.Edge;
import se.sics.cooja.util.StringUtils;
/**
* Simple user interface for configuring edges for the Directed Graph
* Simple user interface for configuring edges for the Directed Graph
* Radio Medium (DGRM).
*
*
* @see DirectedGraphMedium
* @author Fredrik Osterlind
*/
@ClassDescription("DGRM Links")
@PluginType(PluginType.SIM_PLUGIN)
@SupportedArguments(radioMediums = {DirectedGraphMedium.class})
public class DGRMConfigurator extends VisPlugin {
private static final long serialVersionUID = 4769638341635882051L;
private static Logger logger = Logger.getLogger(DGRMConfigurator.class);
@ -177,7 +179,7 @@ public class DGRMConfigurator extends VisPlugin {
graphTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
graphTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JPanel southPanel = new JPanel(new GridLayout(1, 3));
JButton button = new JButton("Add");
button.addActionListener(new ActionListener() {
@ -202,11 +204,11 @@ public class DGRMConfigurator extends VisPlugin {
}
});
southPanel.add(button);
getContentPane().setLayout(new BorderLayout());
add(BorderLayout.CENTER, new JScrollPane(graphTable));
add(BorderLayout.SOUTH, southPanel);
graphTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
@ -336,14 +338,14 @@ public class DGRMConfigurator extends VisPlugin {
public static DirectedGraphMedium.Edge[] parseDGRMLinksFile(File file, Simulation simulation) {
String fileContents = StringUtils.loadFromFile(file);
ArrayList<DirectedGraphMedium.Edge> edges = new ArrayList<DirectedGraphMedium.Edge>();
/* format: # [src] [dst] [prr] [prr_ci] [num_tx] [num_rx] [rssi] [rssi_min] [rssi_max] */
for (String l: fileContents.split("\n")) {
l = l.trim();
if (l.startsWith("#")) {
continue;
}
Mote m;
String[] arr = l.split(" ");
int source = Integer.parseInt(arr[INDEX_SRC]);
@ -365,7 +367,7 @@ public class DGRMConfigurator extends VisPlugin {
double rssi = Double.parseDouble(arr[INDEX_RSSI_MEDIAN]);
/*int rssiMin <- INDEX_RSSI_MIN;*/
/*int rssiMax <- INDEX_RSSI_MAX;*/
DirectedGraphMedium.Edge edge = new DirectedGraphMedium.Edge(sourceRadio, destRadio);
destRadio.delay = 0;
destRadio.ratio = prr;
@ -375,7 +377,7 @@ public class DGRMConfigurator extends VisPlugin {
}
return edges.toArray(new DirectedGraphMedium.Edge[0]);
}
final AbstractTableModel model = new AbstractTableModel() {
private static final long serialVersionUID = 9101118401527171218L;
public String getColumnName(int column) {

View File

@ -35,9 +35,6 @@ import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
@ -52,27 +49,29 @@ import org.apache.log4j.Logger;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.plugins.Visualizer;
import se.sics.cooja.plugins.VisualizerSkin;
import se.sics.cooja.plugins.Visualizer.SimulationMenuAction;
import se.sics.cooja.plugins.VisualizerSkin;
import se.sics.cooja.radiomediums.UDGM;
/**
* Visualizer skin for configuring the Unit Disk Graph radio medium (UDGM).
*
*
* Allows a user to change the collective TX/interference ranges, and the TX/RX
* success ratio.
*
*
* To also see radio traffic, this skin can be combined with {@link
* TrafficVisualizerSkin}.
*
*
* @see TrafficVisualizerSkin
* @see UDGM
* @author Fredrik Osterlind
*/
@ClassDescription("Radio environment (UDGM)")
@SupportedArguments(radioMediums = {UDGM.class})
public class UDGMVisualizerSkin implements VisualizerSkin {
private static Logger logger = Logger.getLogger(UDGMVisualizerSkin.class);
@ -179,7 +178,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
/* UI components */
top = Box.createVerticalBox();
top.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(Color.BLACK),
BorderFactory.createLineBorder(Color.BLACK),
BorderFactory.createEmptyBorder(0, 3, 0, 3)));
top.setOpaque(true);
top.setBackground(Color.LIGHT_GRAY);
@ -239,7 +238,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
public void paintBeforeMotes(Graphics g) {
Mote selectedMote = visualizer.getSelectedMote();
if (simulation == null
if (simulation == null
|| selectedMote == null
|| selectedMote.getInterfaces().getRadio() == null) {
return;
@ -264,13 +263,13 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
/ (double) selectedRadio.getOutputPowerIndicatorMax());
Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
Point translatedInterference =
Point translatedInterference =
visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
Point translatedTransmission =
Point translatedTransmission =
visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
Point translatedInterferenceMax =
Point translatedInterferenceMax =
visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
Point translatedTransmissionMax =
Point translatedTransmissionMax =
visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);
translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
@ -313,7 +312,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
2 * translatedTransmissionMax.x,
2 * translatedTransmissionMax.y);
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.BLACK);
@ -322,18 +321,18 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
if (m == selectedMote) {
continue;
}
double prob =
double prob =
((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
if (prob == 0.0d) {
continue;
}
String msg = (double)(((int)(1000*prob))/10.0) + "%";
String msg = (((int)(1000*prob))/10.0) + "%";
Position pos = m.getInterfaces().getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
int msgWidth = fm.stringWidth(msg);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 2*Visualizer.MOTE_RADIUS + 3);
}
}
public void paintAfterMotes(Graphics g) {