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