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

View file

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

View file

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

View file

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

View file

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

View file

@ -50,18 +50,19 @@ import se.sics.cooja.Mote;
import se.sics.cooja.MotePlugin; import se.sics.cooja.MotePlugin;
import se.sics.cooja.PluginType; import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin; import se.sics.cooja.VisPlugin;
import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMote;
import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.ui.StackUI; import se.sics.mspsim.ui.StackUI;
import se.sics.mspsim.ui.WindowManager;
import se.sics.mspsim.util.Utils; import se.sics.mspsim.util.Utils;
@ClassDescription("Msp Stack Watcher") @ClassDescription("Msp Stack Watcher")
@PluginType(PluginType.MOTE_PLUGIN) @PluginType(PluginType.MOTE_PLUGIN)
@SupportedArguments(motes = {MspMote.class})
public class MspStackWatcher extends VisPlugin implements MotePlugin { public class MspStackWatcher extends VisPlugin implements MotePlugin {
private static Logger logger = Logger.getLogger(MspStackWatcher.class); private static Logger logger = Logger.getLogger(MspStackWatcher.class);
private MspMote mspMote; private MspMote mspMote;
private MSP430 cpu; private MSP430 cpu;
private StackUI stackUI; private StackUI stackUI;
@ -121,7 +122,7 @@ public class MspStackWatcher extends VisPlugin implements MotePlugin {
stackUI = new StackUI(cpu); stackUI = new StackUI(cpu);
stackUI.init("MSPSim stack", mspMote.registry); stackUI.init("MSPSim stack", mspMote.registry);
stackUI.start(); stackUI.start();
// Register as log listener // Register as log listener
/*if (logObserver == null && mspMote.getInterfaces().getLog() != null) { /*if (logObserver == null && mspMote.getInterfaces().getLog() != null) {
mspMote.getInterfaces().getLog().addObserver(logObserver = new Observer() { 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.Mote;
import se.sics.cooja.PluginType; import se.sics.cooja.PluginType;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.SupportedArguments;
import se.sics.cooja.VisPlugin; import se.sics.cooja.VisPlugin;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.radiomediums.AbstractRadioMedium; import se.sics.cooja.radiomediums.AbstractRadioMedium;
@ -74,14 +75,15 @@ import se.sics.cooja.radiomediums.DirectedGraphMedium.Edge;
import se.sics.cooja.util.StringUtils; 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). * Radio Medium (DGRM).
* *
* @see DirectedGraphMedium * @see DirectedGraphMedium
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("DGRM Links") @ClassDescription("DGRM Links")
@PluginType(PluginType.SIM_PLUGIN) @PluginType(PluginType.SIM_PLUGIN)
@SupportedArguments(radioMediums = {DirectedGraphMedium.class})
public class DGRMConfigurator extends VisPlugin { public class DGRMConfigurator extends VisPlugin {
private static final long serialVersionUID = 4769638341635882051L; private static final long serialVersionUID = 4769638341635882051L;
private static Logger logger = Logger.getLogger(DGRMConfigurator.class); 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.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
graphTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); graphTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JPanel southPanel = new JPanel(new GridLayout(1, 3)); JPanel southPanel = new JPanel(new GridLayout(1, 3));
JButton button = new JButton("Add"); JButton button = new JButton("Add");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
@ -202,11 +204,11 @@ public class DGRMConfigurator extends VisPlugin {
} }
}); });
southPanel.add(button); southPanel.add(button);
getContentPane().setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout());
add(BorderLayout.CENTER, new JScrollPane(graphTable)); add(BorderLayout.CENTER, new JScrollPane(graphTable));
add(BorderLayout.SOUTH, southPanel); add(BorderLayout.SOUTH, southPanel);
graphTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { graphTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) { public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel)e.getSource(); ListSelectionModel lsm = (ListSelectionModel)e.getSource();
@ -336,14 +338,14 @@ public class DGRMConfigurator extends VisPlugin {
public static DirectedGraphMedium.Edge[] parseDGRMLinksFile(File file, Simulation simulation) { public static DirectedGraphMedium.Edge[] parseDGRMLinksFile(File file, Simulation simulation) {
String fileContents = StringUtils.loadFromFile(file); String fileContents = StringUtils.loadFromFile(file);
ArrayList<DirectedGraphMedium.Edge> edges = new ArrayList<DirectedGraphMedium.Edge>(); ArrayList<DirectedGraphMedium.Edge> edges = new ArrayList<DirectedGraphMedium.Edge>();
/* format: # [src] [dst] [prr] [prr_ci] [num_tx] [num_rx] [rssi] [rssi_min] [rssi_max] */ /* format: # [src] [dst] [prr] [prr_ci] [num_tx] [num_rx] [rssi] [rssi_min] [rssi_max] */
for (String l: fileContents.split("\n")) { for (String l: fileContents.split("\n")) {
l = l.trim(); l = l.trim();
if (l.startsWith("#")) { if (l.startsWith("#")) {
continue; continue;
} }
Mote m; Mote m;
String[] arr = l.split(" "); String[] arr = l.split(" ");
int source = Integer.parseInt(arr[INDEX_SRC]); int source = Integer.parseInt(arr[INDEX_SRC]);
@ -365,7 +367,7 @@ public class DGRMConfigurator extends VisPlugin {
double rssi = Double.parseDouble(arr[INDEX_RSSI_MEDIAN]); double rssi = Double.parseDouble(arr[INDEX_RSSI_MEDIAN]);
/*int rssiMin <- INDEX_RSSI_MIN;*/ /*int rssiMin <- INDEX_RSSI_MIN;*/
/*int rssiMax <- INDEX_RSSI_MAX;*/ /*int rssiMax <- INDEX_RSSI_MAX;*/
DirectedGraphMedium.Edge edge = new DirectedGraphMedium.Edge(sourceRadio, destRadio); DirectedGraphMedium.Edge edge = new DirectedGraphMedium.Edge(sourceRadio, destRadio);
destRadio.delay = 0; destRadio.delay = 0;
destRadio.ratio = prr; destRadio.ratio = prr;
@ -375,7 +377,7 @@ public class DGRMConfigurator extends VisPlugin {
} }
return edges.toArray(new DirectedGraphMedium.Edge[0]); return edges.toArray(new DirectedGraphMedium.Edge[0]);
} }
final AbstractTableModel model = new AbstractTableModel() { final AbstractTableModel model = new AbstractTableModel() {
private static final long serialVersionUID = 9101118401527171218L; private static final long serialVersionUID = 9101118401527171218L;
public String getColumnName(int column) { public String getColumnName(int column) {

View file

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