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
This commit is contained in:
Fredrik Osterlind 2012-06-01 12:24:30 +02:00
parent e96a375e33
commit f703965b67
2 changed files with 37 additions and 14 deletions

View File

@ -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

View File

@ -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<? extends RadioMedium>[] radioMediums = skinClass.getAnnotation(SupportedArguments.class).radioMediums();
for (Class<? extends Object> 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<? extends VisualizerSkin> 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<? extends RadioMedium>[] radioMediums = skinClass.getAnnotation(SupportedArguments.class).radioMediums();
for (Class<? extends Object> 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();