From 11d124882c499e7f8d4c71a429265f793803d1ae Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Wed, 14 Aug 2013 13:00:00 +0200 Subject: [PATCH] made mote-to-mote relations optional, reordered how skins are painted to more easily decide which skin is painted first --- .../se/sics/cooja/plugins/Visualizer.java | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java index 410b6e66c..b7b02cb35 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java @@ -550,7 +550,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { try { VisualizerSkin newSkin = skinClass.newInstance(); newSkin.setActive(Visualizer.this.simulation, Visualizer.this); - currentSkins.add(newSkin); + currentSkins.add(0, newSkin); } catch (InstantiationException e1) { e1.printStackTrace(); } catch (IllegalAccessException e1) { @@ -700,7 +700,26 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { menu.setVisible(true); } + private boolean showMoteToMoteRelations = true; private void populateSkinMenu(MenuElement menu) { + /* Mote-to-mote relations */ + JCheckBoxMenuItem moteRelationsItem = new JCheckBoxMenuItem("Mote relations", showMoteToMoteRelations); + moteRelationsItem.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + JCheckBoxMenuItem menuItem = ((JCheckBoxMenuItem)e.getItem()); + showMoteToMoteRelations = menuItem.isSelected(); + repaint(); + } + }); + if (menu instanceof JMenu) { + ((JMenu)menu).add(moteRelationsItem); + ((JMenu)menu).add(new JSeparator()); + } + if (menu instanceof JPopupMenu) { + ((JPopupMenu)menu).add(moteRelationsItem); + ((JPopupMenu)menu).add(new JSeparator()); + } + for (Class skinClass: visualizerSkins) { /* Should skin be enabled in this simulation? */ if (!isSkinCompatible(skinClass)) { @@ -998,16 +1017,18 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { Mote[] allMotes = simulation.getMotes(); /* Paint mote relations */ - MoteRelation[] relations = simulation.getGUI().getMoteRelations(); - for (MoteRelation r: relations) { - Position sourcePos = r.source.getInterfaces().getPosition(); - Position destPos = r.dest.getInterfaces().getPosition(); + if (showMoteToMoteRelations) { + MoteRelation[] relations = simulation.getGUI().getMoteRelations(); + for (MoteRelation r: relations) { + Position sourcePos = r.source.getInterfaces().getPosition(); + Position destPos = r.dest.getInterfaces().getPosition(); - Point sourcePoint = transformPositionToPixel(sourcePos); - Point destPoint = transformPositionToPixel(destPos); + Point sourcePoint = transformPositionToPixel(sourcePos); + Point destPoint = transformPositionToPixel(destPos); - g.setColor(r.color == null ? Color.black : r.color); - drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, MOTE_RADIUS + 1); + g.setColor(r.color == null ? Color.black : r.color); + drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, MOTE_RADIUS + 1); + } } for (Mote mote: allMotes) { @@ -1264,11 +1285,19 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { ArrayList config = new ArrayList(); Element element; + /* Show mote-to-mote relations */ + if (showMoteToMoteRelations) { + element = new Element("moterelations"); + element.setText("" + true); + config.add(element); + } + /* Skins */ - for (VisualizerSkin skin: currentSkins) { - element = new Element("skin"); - element.setText(skin.getClass().getName()); - config.add(element); + for (int i=currentSkins.size()-1; i >= 0; i--) { + VisualizerSkin skin = currentSkins.get(i); + element = new Element("skin"); + element.setText(skin.getClass().getName()); + config.add(element); } /* Viewport */ @@ -1298,6 +1327,7 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { public boolean setConfigXML(Collection configXML, boolean visAvailable) { loadedConfig = true; + showMoteToMoteRelations = false; for (Element element : configXML) { if (element.getName().equals("skin")) { @@ -1319,6 +1349,8 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { if (wanted != null) { logger.warn("Could not load visualizer: " + element.getText()); } + } else if (element.getName().equals("moterelations")) { + showMoteToMoteRelations = true; } else if (element.getName().equals("viewport")) { try { String[] matrix = element.getText().split(" ");