[cooja] Added @Override annotations for Visualizer and skins
This commit is contained in:
parent
8e648bcece
commit
6e9b0e1497
@ -56,6 +56,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
private Simulation simulation = null;
|
private Simulation simulation = null;
|
||||||
private Visualizer visualizer = null;
|
private Visualizer visualizer = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setActive(Simulation simulation, Visualizer vis) {
|
public void setActive(Simulation simulation, Visualizer vis) {
|
||||||
if (!(simulation.getRadioMedium() instanceof MRM)) {
|
if (!(simulation.getRadioMedium() instanceof MRM)) {
|
||||||
logger.fatal("Cannot activate MRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
logger.fatal("Cannot activate MRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||||
@ -65,6 +66,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
this.visualizer = vis;
|
this.visualizer = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setInactive() {
|
public void setInactive() {
|
||||||
if (simulation == null) {
|
if (simulation == null) {
|
||||||
/* Skin was never activated */
|
/* Skin was never activated */
|
||||||
@ -72,6 +74,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
if (visualizer.getSelectedMotes().contains(mote)) {
|
if (visualizer.getSelectedMotes().contains(mote)) {
|
||||||
return new Color[] { Color.CYAN };
|
return new Color[] { Color.CYAN };
|
||||||
@ -79,6 +82,7 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null || selectedMotes == null) {
|
if (simulation == null || selectedMotes == null) {
|
||||||
@ -120,9 +124,11 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
final Radio dRadio = d.getInterfaces().getRadio();
|
final Radio dRadio = d.getInterfaces().getRadio();
|
||||||
TxPair txPair = new RadioPair() {
|
TxPair txPair = new RadioPair() {
|
||||||
|
@Override
|
||||||
public Radio getFromRadio() {
|
public Radio getFromRadio() {
|
||||||
return selectedMote.getInterfaces().getRadio();
|
return selectedMote.getInterfaces().getRadio();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public Radio getToRadio() {
|
public Radio getToRadio() {
|
||||||
return dRadio;
|
return dRadio;
|
||||||
}
|
}
|
||||||
@ -154,9 +160,11 @@ public class MRMVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintAfterMotes(Graphics g) {
|
public void paintAfterMotes(Graphics g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Visualizer getVisualizer() {
|
public Visualizer getVisualizer() {
|
||||||
return visualizer;
|
return visualizer;
|
||||||
}
|
}
|
||||||
|
@ -249,12 +249,15 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
viewMenu = new JMenu("View");
|
viewMenu = new JMenu("View");
|
||||||
viewMenu.addMenuListener(new MenuListener() {
|
viewMenu.addMenuListener(new MenuListener() {
|
||||||
|
@Override
|
||||||
public void menuSelected(MenuEvent e) {
|
public void menuSelected(MenuEvent e) {
|
||||||
viewMenu.removeAll();
|
viewMenu.removeAll();
|
||||||
populateSkinMenu(viewMenu);
|
populateSkinMenu(viewMenu);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void menuDeselected(MenuEvent e) {
|
public void menuDeselected(MenuEvent e) {
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void menuCanceled(MenuEvent e) {
|
public void menuCanceled(MenuEvent e) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -266,6 +269,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
this.setJMenuBar(menuBar);
|
this.setJMenuBar(menuBar);
|
||||||
|
|
||||||
Action zoomInAction = new AbstractAction("Zoom in") {
|
Action zoomInAction = new AbstractAction("Zoom in") {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
zoomToFactor(zoomFactor() * 1.2);
|
zoomToFactor(zoomFactor() * 1.2);
|
||||||
}
|
}
|
||||||
@ -278,6 +282,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
zoomMenu.add(zoomInItem);
|
zoomMenu.add(zoomInItem);
|
||||||
|
|
||||||
Action zoomOutAction = new AbstractAction("Zoom out") {
|
Action zoomOutAction = new AbstractAction("Zoom out") {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
zoomToFactor(zoomFactor() / 1.2);
|
zoomToFactor(zoomFactor() / 1.2);
|
||||||
}
|
}
|
||||||
@ -291,6 +296,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
JMenuItem resetViewportItem = new JMenuItem("Reset viewport");
|
JMenuItem resetViewportItem = new JMenuItem("Reset viewport");
|
||||||
resetViewportItem.addActionListener(new ActionListener() {
|
resetViewportItem.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
resetViewport = 1;
|
resetViewport = 1;
|
||||||
repaint();
|
repaint();
|
||||||
@ -302,6 +308,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
/* Main canvas */
|
/* Main canvas */
|
||||||
canvas = new JPanel() {
|
canvas = new JPanel() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
@ -328,16 +335,19 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
/* Observe simulation and mote positions */
|
/* Observe simulation and mote positions */
|
||||||
posObserver = new Observer() {
|
posObserver = new Observer() {
|
||||||
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
simulation.getEventCentral().addMoteCountListener(newMotesListener = new MoteCountListener() {
|
simulation.getEventCentral().addMoteCountListener(newMotesListener = new MoteCountListener() {
|
||||||
|
@Override
|
||||||
public void moteWasAdded(Mote mote) {
|
public void moteWasAdded(Mote mote) {
|
||||||
Position pos = mote.getInterfaces().getPosition();
|
Position pos = mote.getInterfaces().getPosition();
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
pos.addObserver(posObserver);
|
pos.addObserver(posObserver);
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
resetViewport = 1;
|
resetViewport = 1;
|
||||||
repaint();
|
repaint();
|
||||||
@ -345,6 +355,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void moteWasRemoved(Mote mote) {
|
public void moteWasRemoved(Mote mote) {
|
||||||
Position pos = mote.getInterfaces().getPosition();
|
Position pos = mote.getInterfaces().getPosition();
|
||||||
if (pos != null) {
|
if (pos != null) {
|
||||||
@ -362,6 +373,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
/* Observe mote highlights */
|
/* Observe mote highlights */
|
||||||
gui.addMoteHighlightObserver(moteHighligtObserver = new Observer() {
|
gui.addMoteHighlightObserver(moteHighligtObserver = new Observer() {
|
||||||
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
if (!(obj instanceof Mote)) {
|
if (!(obj instanceof Mote)) {
|
||||||
return;
|
return;
|
||||||
@ -370,6 +382,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
final Timer timer = new Timer(100, null);
|
final Timer timer = new Timer(100, null);
|
||||||
final Mote mote = (Mote) obj;
|
final Mote mote = (Mote) obj;
|
||||||
timer.addActionListener(new ActionListener() {
|
timer.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
/* Count down */
|
/* Count down */
|
||||||
if (timer.getDelay() < 90) {
|
if (timer.getDelay() < 90) {
|
||||||
@ -395,6 +408,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
/* Observe mote relations */
|
/* Observe mote relations */
|
||||||
gui.addMoteRelationsObserver(moteRelationsObserver = new Observer() {
|
gui.addMoteRelationsObserver(moteRelationsObserver = new Observer() {
|
||||||
|
@Override
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
@ -408,6 +422,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
canvas.addMouseListener(new MouseAdapter() {
|
canvas.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if (e.isPopupTrigger()) {
|
if (e.isPopupTrigger()) {
|
||||||
handlePopupRequest(e.getPoint());
|
handlePopupRequest(e.getPoint());
|
||||||
@ -418,6 +433,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
handleMousePress(e);
|
handleMousePress(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
if (e.isPopupTrigger()) {
|
if (e.isPopupTrigger()) {
|
||||||
handlePopupRequest(e.getPoint());
|
handlePopupRequest(e.getPoint());
|
||||||
@ -430,6 +446,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
canvas.addMouseWheelListener(new MouseWheelListener() {
|
canvas.addMouseWheelListener(new MouseWheelListener() {
|
||||||
|
@Override
|
||||||
public void mouseWheelMoved(MouseWheelEvent mwe) {
|
public void mouseWheelMoved(MouseWheelEvent mwe) {
|
||||||
int x = mwe.getX();
|
int x = mwe.getX();
|
||||||
int y = mwe.getY();
|
int y = mwe.getY();
|
||||||
@ -457,6 +474,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|
|
||||||
/* Drag and drop files to motes */
|
/* Drag and drop files to motes */
|
||||||
DropTargetListener dTargetListener = new DropTargetListener() {
|
DropTargetListener dTargetListener = new DropTargetListener() {
|
||||||
|
@Override
|
||||||
public void dragEnter(DropTargetDragEvent dtde) {
|
public void dragEnter(DropTargetDragEvent dtde) {
|
||||||
if (acceptOrRejectDrag(dtde)) {
|
if (acceptOrRejectDrag(dtde)) {
|
||||||
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
||||||
@ -464,8 +482,10 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
dtde.rejectDrag();
|
dtde.rejectDrag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void dragExit(DropTargetEvent dte) {
|
public void dragExit(DropTargetEvent dte) {
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void dropActionChanged(DropTargetDragEvent dtde) {
|
public void dropActionChanged(DropTargetDragEvent dtde) {
|
||||||
if (acceptOrRejectDrag(dtde)) {
|
if (acceptOrRejectDrag(dtde)) {
|
||||||
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
||||||
@ -473,6 +493,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
dtde.rejectDrag();
|
dtde.rejectDrag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void dragOver(DropTargetDragEvent dtde) {
|
public void dragOver(DropTargetDragEvent dtde) {
|
||||||
if (acceptOrRejectDrag(dtde)) {
|
if (acceptOrRejectDrag(dtde)) {
|
||||||
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
|
||||||
@ -480,6 +501,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
dtde.rejectDrag();
|
dtde.rejectDrag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void drop(DropTargetDropEvent dtde) {
|
public void drop(DropTargetDropEvent dtde) {
|
||||||
Transferable transferable = dtde.getTransferable();
|
Transferable transferable = dtde.getTransferable();
|
||||||
|
|
||||||
@ -589,6 +611,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void startPlugin() {
|
public void startPlugin() {
|
||||||
super.startPlugin();
|
super.startPlugin();
|
||||||
if (loadedConfig) {
|
if (loadedConfig) {
|
||||||
@ -677,6 +700,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
if (menuAction.isEnabled(this, mote)) {
|
if (menuAction.isEnabled(this, mote)) {
|
||||||
JMenuItem menuItem = new JMenuItem(menuAction.getDescription(this, mote));
|
JMenuItem menuItem = new JMenuItem(menuAction.getDescription(this, mote));
|
||||||
menuItem.addActionListener(new ActionListener() {
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
menuAction.doAction(Visualizer.this, mote);
|
menuAction.doAction(Visualizer.this, mote);
|
||||||
}
|
}
|
||||||
@ -700,6 +724,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
if (menuAction.isEnabled(this, simulation)) {
|
if (menuAction.isEnabled(this, simulation)) {
|
||||||
JMenuItem menuItem = new JMenuItem(menuAction.getDescription(this, simulation));
|
JMenuItem menuItem = new JMenuItem(menuAction.getDescription(this, simulation));
|
||||||
menuItem.addActionListener(new ActionListener() {
|
menuItem.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
menuAction.doAction(Visualizer.this, simulation);
|
menuAction.doAction(Visualizer.this, simulation);
|
||||||
}
|
}
|
||||||
@ -735,6 +760,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
/* Mote-to-mote relations */
|
/* Mote-to-mote relations */
|
||||||
JCheckBoxMenuItem moteRelationsItem = new JCheckBoxMenuItem("Mote relations", showMoteToMoteRelations);
|
JCheckBoxMenuItem moteRelationsItem = new JCheckBoxMenuItem("Mote relations", showMoteToMoteRelations);
|
||||||
moteRelationsItem.addItemListener(new ItemListener() {
|
moteRelationsItem.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
JCheckBoxMenuItem menuItem = ((JCheckBoxMenuItem)e.getItem());
|
JCheckBoxMenuItem menuItem = ((JCheckBoxMenuItem)e.getItem());
|
||||||
showMoteToMoteRelations = menuItem.isSelected();
|
showMoteToMoteRelations = menuItem.isSelected();
|
||||||
@ -769,6 +795,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
item.addItemListener(new ItemListener() {
|
item.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
public void itemStateChanged(ItemEvent e) {
|
public void itemStateChanged(ItemEvent e) {
|
||||||
JCheckBoxMenuItem menuItem = ((JCheckBoxMenuItem)e.getItem());
|
JCheckBoxMenuItem menuItem = ((JCheckBoxMenuItem)e.getItem());
|
||||||
if (menuItem == null) {
|
if (menuItem == null) {
|
||||||
@ -1248,6 +1275,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
/* Center visible motes */
|
/* Center visible motes */
|
||||||
final double smallXfinal = smallX, bigXfinal = bigX, smallYfinal = smallY, bigYfinal = bigY;
|
final double smallXfinal = smallX, bigXfinal = bigX, smallYfinal = smallY, bigYfinal = bigY;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Position viewMid =
|
Position viewMid =
|
||||||
transformPixelToPosition(canvas.getWidth()/2, canvas.getHeight()/2);
|
transformPixelToPosition(canvas.getWidth()/2, canvas.getHeight()/2);
|
||||||
@ -1331,6 +1359,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
return (y - viewportTransform.getTranslateY())/viewportTransform.getScaleY() ;
|
return (y - viewportTransform.getTranslateY())/viewportTransform.getScaleY() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
for (VisualizerSkin skin: currentSkins) {
|
for (VisualizerSkin skin: currentSkins) {
|
||||||
skin.setInactive();
|
skin.setInactive();
|
||||||
@ -1367,6 +1396,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
return selectedMotes;
|
return selectedMotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
ArrayList<Element> config = new ArrayList<Element>();
|
ArrayList<Element> config = new ArrayList<Element>();
|
||||||
Element element;
|
Element element;
|
||||||
@ -1411,6 +1441,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
|
||||||
loadedConfig = true;
|
loadedConfig = true;
|
||||||
showMoteToMoteRelations = false;
|
showMoteToMoteRelations = false;
|
||||||
@ -1429,6 +1460,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
|| wanted.equals(Cooja.getDescriptionOf(skinClass))) {
|
|| wanted.equals(Cooja.getDescriptionOf(skinClass))) {
|
||||||
final Class<? extends VisualizerSkin> skin = skinClass;
|
final Class<? extends VisualizerSkin> skin = skinClass;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
generateAndActivateSkin(skin);
|
generateAndActivateSkin(skin);
|
||||||
}
|
}
|
||||||
@ -1467,6 +1499,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AbstractAction makeSkinsDefaultAction = new AbstractAction() {
|
private AbstractAction makeSkinsDefaultAction = new AbstractAction() {
|
||||||
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (VisualizerSkin skin: currentSkins) {
|
for (VisualizerSkin skin: currentSkins) {
|
||||||
@ -1480,37 +1513,46 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected static class ButtonClickMoteMenuAction implements MoteMenuAction {
|
protected static class ButtonClickMoteMenuAction implements MoteMenuAction {
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
||||||
return mote.getInterfaces().getButton() != null
|
return mote.getInterfaces().getButton() != null
|
||||||
&& !mote.getInterfaces().getButton().isPressed();
|
&& !mote.getInterfaces().getButton().isPressed();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Mote mote) {
|
public String getDescription(Visualizer visualizer, Mote mote) {
|
||||||
return "Click button on " + mote;
|
return "Click button on " + mote;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Mote mote) {
|
public void doAction(Visualizer visualizer, Mote mote) {
|
||||||
mote.getInterfaces().getButton().clickButton();
|
mote.getInterfaces().getButton().clickButton();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static class DeleteMoteMenuAction implements MoteMenuAction {
|
protected static class DeleteMoteMenuAction implements MoteMenuAction {
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Mote mote) {
|
public String getDescription(Visualizer visualizer, Mote mote) {
|
||||||
return "Delete " + mote;
|
return "Delete " + mote;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Mote mote) {
|
public void doAction(Visualizer visualizer, Mote mote) {
|
||||||
mote.getSimulation().removeMote(mote);
|
mote.getSimulation().removeMote(mote);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static class ShowLEDMoteMenuAction implements MoteMenuAction {
|
protected static class ShowLEDMoteMenuAction implements MoteMenuAction {
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
||||||
return mote.getInterfaces().getLED() != null;
|
return mote.getInterfaces().getLED() != null;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Mote mote) {
|
public String getDescription(Visualizer visualizer, Mote mote) {
|
||||||
return "Show LEDs on " + mote;
|
return "Show LEDs on " + mote;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Mote mote) {
|
public void doAction(Visualizer visualizer, Mote mote) {
|
||||||
Simulation simulation = mote.getSimulation();
|
Simulation simulation = mote.getSimulation();
|
||||||
LED led = mote.getInterfaces().getLED();
|
LED led = mote.getInterfaces().getLED();
|
||||||
@ -1536,6 +1578,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected static class ShowSerialMoteMenuAction implements MoteMenuAction {
|
protected static class ShowSerialMoteMenuAction implements MoteMenuAction {
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
||||||
for (MoteInterface intf: mote.getInterfaces().getInterfaces()) {
|
for (MoteInterface intf: mote.getInterfaces().getInterfaces()) {
|
||||||
if (intf instanceof SerialPort) {
|
if (intf instanceof SerialPort) {
|
||||||
@ -1544,9 +1587,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Mote mote) {
|
public String getDescription(Visualizer visualizer, Mote mote) {
|
||||||
return "Show serial port on " + mote;
|
return "Show serial port on " + mote;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Mote mote) {
|
public void doAction(Visualizer visualizer, Mote mote) {
|
||||||
Simulation simulation = mote.getSimulation();
|
Simulation simulation = mote.getSimulation();
|
||||||
SerialPort serialPort = null;
|
SerialPort serialPort = null;
|
||||||
@ -1579,31 +1624,38 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected static class MoveMoteMenuAction implements MoteMenuAction {
|
protected static class MoveMoteMenuAction implements MoteMenuAction {
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
public boolean isEnabled(Visualizer visualizer, Mote mote) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Mote mote) {
|
public String getDescription(Visualizer visualizer, Mote mote) {
|
||||||
return "Move " + mote;
|
return "Move " + mote;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Mote mote) {
|
public void doAction(Visualizer visualizer, Mote mote) {
|
||||||
visualizer.beginMoveRequest(mote, false, false);
|
visualizer.beginMoveRequest(mote, false, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static class ResetViewportAction implements SimulationMenuAction {
|
protected static class ResetViewportAction implements SimulationMenuAction {
|
||||||
|
@Override
|
||||||
public void doAction(Visualizer visualizer, Simulation simulation) {
|
public void doAction(Visualizer visualizer, Simulation simulation) {
|
||||||
visualizer.resetViewport = 1;
|
visualizer.resetViewport = 1;
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Simulation simulation) {
|
public String getDescription(Visualizer visualizer, Simulation simulation) {
|
||||||
return "Reset viewport";
|
return "Reset viewport";
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected static class ToggleDecorationsMenuAction implements SimulationMenuAction {
|
protected static class ToggleDecorationsMenuAction implements SimulationMenuAction {
|
||||||
|
@Override
|
||||||
public void doAction(final Visualizer visualizer, Simulation simulation) {
|
public void doAction(final Visualizer visualizer, Simulation simulation) {
|
||||||
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
||||||
return;
|
return;
|
||||||
@ -1620,11 +1672,13 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
visualizer.revalidate();
|
visualizer.revalidate();
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String getDescription(Visualizer visualizer, Simulation simulation) {
|
public String getDescription(Visualizer visualizer, Simulation simulation) {
|
||||||
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
||||||
return "Hide window decorations";
|
return "Hide window decorations";
|
||||||
@ -1637,6 +1691,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
return "Hide window decorations";
|
return "Hide window decorations";
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
public boolean isEnabled(Visualizer visualizer, Simulation simulation) {
|
||||||
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
if (!(visualizer.getUI() instanceof BasicInternalFrameUI)) {
|
||||||
return false;
|
return false;
|
||||||
@ -1645,6 +1700,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getQuickHelp() {
|
public String getQuickHelp() {
|
||||||
return "<b>Network</b> "
|
return "<b>Network</b> "
|
||||||
+ "<p>The network window shows the positions of simulated motes. "
|
+ "<p>The network window shows the positions of simulated motes. "
|
||||||
|
@ -58,6 +58,7 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
|||||||
private Simulation simulation = null;
|
private Simulation simulation = null;
|
||||||
private Visualizer visualizer = null;
|
private Visualizer visualizer = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setActive(Simulation simulation, Visualizer vis) {
|
public void setActive(Simulation simulation, Visualizer vis) {
|
||||||
if (!(simulation.getRadioMedium() instanceof DirectedGraphMedium)) {
|
if (!(simulation.getRadioMedium() instanceof DirectedGraphMedium)) {
|
||||||
logger.fatal("Cannot activate DGRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
logger.fatal("Cannot activate DGRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||||
@ -67,6 +68,7 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
|||||||
this.visualizer = vis;
|
this.visualizer = vis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setInactive() {
|
public void setInactive() {
|
||||||
if (simulation == null) {
|
if (simulation == null) {
|
||||||
/* Skin was never activated */
|
/* Skin was never activated */
|
||||||
@ -74,6 +76,7 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
if (visualizer.getSelectedMotes().contains(mote)) {
|
if (visualizer.getSelectedMotes().contains(mote)) {
|
||||||
return new Color[] { Color.CYAN };
|
return new Color[] { Color.CYAN };
|
||||||
@ -81,6 +84,7 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintBeforeMotes(Graphics g) {
|
public void paintBeforeMotes(Graphics g) {
|
||||||
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
Set<Mote> selectedMotes = visualizer.getSelectedMotes();
|
||||||
if (simulation == null || selectedMotes == null) {
|
if (simulation == null || selectedMotes == null) {
|
||||||
@ -150,9 +154,11 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void paintAfterMotes(Graphics g) {
|
public void paintAfterMotes(Graphics g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Visualizer getVisualizer() {
|
public Visualizer getVisualizer() {
|
||||||
return visualizer;
|
return visualizer;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user