simplified mote selection in visualizer skins
This commit is contained in:
parent
b34e92dfba
commit
faf2943e02
@ -203,9 +203,10 @@ public class Visualizer extends VisPlugin {
|
||||
String[] skins = gui.getProjectConfig().getStringArrayValue(Visualizer.class, "SKINS");
|
||||
if (skins != null) {
|
||||
for (String skinClass: skins) {
|
||||
logger.info("Registering external visualizer skin: " + skinClass);
|
||||
Class<? extends VisualizerSkin> skin = gui.tryLoadClass(this, VisualizerSkin.class, skinClass);
|
||||
registerVisualizerSkin(skin);
|
||||
if (registerVisualizerSkin(skin)) {
|
||||
logger.info("Registered external visualizer skin: " + skinClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,6 +413,7 @@ public class Visualizer extends VisPlugin {
|
||||
}
|
||||
|
||||
handleMouseMove(e, true);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
@ -597,11 +599,12 @@ public class Visualizer extends VisPlugin {
|
||||
moteMenuActions.remove(menuAction);
|
||||
}
|
||||
|
||||
public static void registerVisualizerSkin(Class<? extends VisualizerSkin> skin) {
|
||||
public static boolean registerVisualizerSkin(Class<? extends VisualizerSkin> skin) {
|
||||
if (visualizerSkins.contains(skin)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
visualizerSkins.add(skin);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void unregisterVisualizerSkin(Class<? extends VisualizerSkin> skin) {
|
||||
@ -1102,6 +1105,13 @@ public class Visualizer extends VisPlugin {
|
||||
logger.fatal("Drag and drop not implemented: " + file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Selected mote
|
||||
*/
|
||||
public Mote getSelectedMote() {
|
||||
return clickedMote;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
ArrayList<Element> config = new ArrayList<Element>();
|
||||
Element element;
|
||||
|
@ -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 org.apache.log4j.Logger;
|
||||
|
||||
@ -59,22 +56,6 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||
private Simulation simulation = null;
|
||||
private Visualizer visualizer = null;
|
||||
|
||||
private Mote selectedMote = null;
|
||||
|
||||
private MouseListener selectMoteMouseListener = new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Mote[] motes = visualizer.findMotesAtPosition(e.getX(), e.getY());
|
||||
if (motes == null || motes.length == 0) {
|
||||
selectedMote = null;
|
||||
visualizer.repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
selectedMote = motes[0];
|
||||
visualizer.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
public void setActive(Simulation simulation, Visualizer vis) {
|
||||
if (!(simulation.getRadioMedium() instanceof DirectedGraphMedium)) {
|
||||
logger.fatal("Cannot activate DGRM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||
@ -82,9 +63,6 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||
}
|
||||
this.simulation = simulation;
|
||||
this.visualizer = vis;
|
||||
|
||||
/* Register mouse listener */
|
||||
visualizer.getCurrentCanvas().addMouseListener(selectMoteMouseListener);
|
||||
}
|
||||
|
||||
public void setInactive() {
|
||||
@ -92,19 +70,18 @@ public class DGRMVisualizerSkin implements VisualizerSkin {
|
||||
/* Skin was never activated */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove mouse listener */
|
||||
visualizer.getCurrentCanvas().removeMouseListener(selectMoteMouseListener);
|
||||
}
|
||||
|
||||
public Color[] getColorOf(Mote mote) {
|
||||
if (mote == selectedMote) {
|
||||
return new Color[] { Color.CYAN };
|
||||
}
|
||||
return null;
|
||||
Mote selectedMote = visualizer.getSelectedMote();
|
||||
if (mote == selectedMote) {
|
||||
return new Color[] { Color.CYAN };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void paintBeforeMotes(Graphics g) {
|
||||
Mote selectedMote = visualizer.getSelectedMote();
|
||||
if (simulation == null
|
||||
|| selectedMote == null
|
||||
|| selectedMote.getInterfaces().getRadio() == null) {
|
||||
|
@ -83,29 +83,8 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||
private Visualizer visualizer = null;
|
||||
private UDGM radioMedium = null;
|
||||
|
||||
private Mote selectedMote = null;
|
||||
|
||||
private Box top, ratioRX, ratioTX, rangeTX, rangeINT;
|
||||
|
||||
private MouseListener selectMoteMouseListener = new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
Mote[] motes = visualizer.findMotesAtPosition(e.getX(), e.getY());
|
||||
if (motes == null || motes.length == 0) {
|
||||
selectedMote = null;
|
||||
rangeTX.setVisible(false);
|
||||
rangeINT.setVisible(false);
|
||||
ratioRX.setVisible(false);
|
||||
ratioTX.setVisible(false);
|
||||
top.setVisible(false);
|
||||
visualizer.repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
selectedMote = motes[0];
|
||||
visualizer.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
public void setActive(Simulation simulation, Visualizer vis) {
|
||||
if (!(simulation.getRadioMedium() instanceof UDGM)) {
|
||||
logger.fatal("Cannot activate UDGM skin for unknown radio medium: " + simulation.getRadioMedium());
|
||||
@ -193,9 +172,6 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||
}
|
||||
});
|
||||
|
||||
/* Register mouse listener */
|
||||
visualizer.getCurrentCanvas().addMouseListener(selectMoteMouseListener);
|
||||
|
||||
/* Register menu actions */
|
||||
visualizer.registerSimulationMenuAction(RangeMenuAction.class);
|
||||
visualizer.registerSimulationMenuAction(SuccessRatioMenuAction.class);
|
||||
@ -245,9 +221,6 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Remove mouse listener */
|
||||
visualizer.getCurrentCanvas().removeMouseListener(selectMoteMouseListener);
|
||||
|
||||
/* Remove spinners etc */
|
||||
visualizer.getCurrentCanvas().remove(top);
|
||||
|
||||
@ -257,6 +230,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||
}
|
||||
|
||||
public Color[] getColorOf(Mote mote) {
|
||||
Mote selectedMote = visualizer.getSelectedMote();
|
||||
if (mote == selectedMote) {
|
||||
return new Color[] { Color.CYAN };
|
||||
}
|
||||
@ -264,6 +238,7 @@ public class UDGMVisualizerSkin implements VisualizerSkin {
|
||||
}
|
||||
|
||||
public void paintBeforeMotes(Graphics g) {
|
||||
Mote selectedMote = visualizer.getSelectedMote();
|
||||
if (simulation == null
|
||||
|| selectedMote == null
|
||||
|| selectedMote.getInterfaces().getRadio() == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user