From f703965b67913b27034abd3000e095eaeb4c0376 Mon Sep 17 00:00:00 2001 From: Fredrik Osterlind Date: Fri, 1 Jun 2012 12:24:30 +0200 Subject: [PATCH] verify that visualizer skin is compatible with the current simulation before starting it, set udgm/dgrm/mrm radio medium skins to be started as default --- tools/cooja/config/external_tools.config | 8 +++- .../se/sics/cooja/plugins/Visualizer.java | 43 +++++++++++++------ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/tools/cooja/config/external_tools.config b/tools/cooja/config/external_tools.config index 53798041d..5e4b69186 100755 --- a/tools/cooja/config/external_tools.config +++ b/tools/cooja/config/external_tools.config @@ -41,4 +41,10 @@ COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]A[ \t]_edata$ COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]A[ \t]__bss_start$ COMMAND_BSS_END = ^([0-9A-Fa-f]*)[ \t]A[ \t]_end$ -VISUALIZER_DEFAULT_SKINS=se.sics.cooja.plugins.skins.IDVisualizerSkin;se.sics.cooja.plugins.skins.GridVisualizerSkin +VISUALIZER_DEFAULT_SKINS=\ +se.sics.cooja.plugins.skins.IDVisualizerSkin;\ +se.sics.cooja.plugins.skins.GridVisualizerSkin;\ +se.sics.cooja.plugins.skins.DGRMVisualizerSkin;\ +se.sics.cooja.plugins.skins.TrafficVisualizerSkin;\ +se.sics.cooja.plugins.skins.UDGMVisualizerSkin;\ +se.sics.mrm.MRMVisualizerSkin diff --git a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java index ecba403e1..594e30a88 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java +++ b/tools/cooja/java/se/sics/cooja/plugins/Visualizer.java @@ -494,6 +494,11 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { } } + if (!isSkinCompatible(skinClass)) { + /*logger.warn("Skin is not compatible with current simulation: " + skinClass);*/ + return; + } + /* Create and activate new skin */ try { VisualizerSkin newSkin = skinClass.newInstance(); @@ -707,19 +712,8 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { }); - /* Check if skin depends on any particular radio medium */ - boolean showMenuItem = true; - if (skinClass.getAnnotation(SupportedArguments.class) != null) { - showMenuItem = false; - Class[] radioMediums = skinClass.getAnnotation(SupportedArguments.class).radioMediums(); - for (Class o: radioMediums) { - if (o.isAssignableFrom(simulation.getRadioMedium().getClass())) { - showMenuItem = true; - break; - } - } - } - if (!showMenuItem) { + /* Should skin be enabled in this simulation? */ + if (!isSkinCompatible(skinClass)) { continue; } @@ -732,6 +726,29 @@ public class Visualizer extends VisPlugin implements HasQuickHelp { } } + public boolean isSkinCompatible(Class skinClass) { + if (skinClass == null) { + return false; + } + + /* Check if skin depends on any particular radio medium */ + boolean showMenuItem = true; + if (skinClass.getAnnotation(SupportedArguments.class) != null) { + showMenuItem = false; + Class[] radioMediums = skinClass.getAnnotation(SupportedArguments.class).radioMediums(); + for (Class o: radioMediums) { + if (o.isAssignableFrom(simulation.getRadioMedium().getClass())) { + showMenuItem = true; + break; + } + } + } + if (!showMenuItem) { + return false; + } + return true; + } + private void handleMousePress(MouseEvent mouseEvent) { int x = mouseEvent.getX(); int y = mouseEvent.getY();