From 76bb1dbd5fc2dfdb840103468007e79c81e2222d Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 13 Dec 2006 11:57:04 +0000 Subject: [PATCH] added support for gui standard plugin --- tools/cooja/java/se/sics/cooja/GUI.java | 27 ++++++++++++++++--- .../cooja/java/se/sics/cooja/Simulation.java | 6 +++-- .../java/se/sics/cooja/VisPluginType.java | 12 ++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index fd8d61dcc..4b60ba196 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: GUI.java,v 1.11 2006/12/01 14:12:50 fros4943 Exp $ + * $Id: GUI.java,v 1.12 2006/12/13 11:57:04 fros4943 Exp $ */ package se.sics.cooja; @@ -198,6 +198,16 @@ public class GUI extends JDesktopPane { // Load extendable parts (using current platform config) reparsePlatformConfig(); + + // EXPERIMENTAL: Start all standard GUI plugins + for (Class visPluginClass : pluginClasses) { + int pluginType = visPluginClass.getAnnotation(VisPluginType.class) + .value(); + if (pluginType == VisPluginType.GUI_STANDARD_PLUGIN) { + startPlugin(visPluginClass); + } + } + } private JMenuBar createMenuBar() { @@ -1207,6 +1217,14 @@ public class GUI extends JDesktopPane { return false; } + newPlugin = pluginClass.getConstructor(new Class[]{GUI.class}) + .newInstance(currentGUI); + } else if (pluginType == VisPluginType.GUI_STANDARD_PLUGIN) { + if (currentGUI == null) { + logger.fatal("Can't start GUI plugin (no GUI)"); + return false; + } + newPlugin = pluginClass.getConstructor(new Class[]{GUI.class}) .newInstance(currentGUI); } @@ -1321,6 +1339,8 @@ public class GUI extends JDesktopPane { newPluginClass.getConstructor(new Class[]{Simulation.class}); } else if (pluginType == VisPluginType.GUI_PLUGIN) { newPluginClass.getConstructor(new Class[]{GUI.class}); + } else if (pluginType == VisPluginType.GUI_STANDARD_PLUGIN) { + newPluginClass.getConstructor(new Class[]{GUI.class}); } else { logger.fatal("Could not find valid plugin type annotation in class " + newPluginClass); @@ -1388,7 +1408,7 @@ public class GUI extends JDesktopPane { // // GUI CONTROL METHODS //// - private void setSimulation(Simulation sim) { + public void setSimulation(Simulation sim) { if (sim != null) { doRemoveSimulation(false); } @@ -1469,7 +1489,8 @@ public class GUI extends JDesktopPane { if (pluginClasses.contains(frameClass)) { int pluginType = ((Class) frameClass) .getAnnotation(VisPluginType.class).value(); - if (pluginType != VisPluginType.GUI_PLUGIN) + if (pluginType != VisPluginType.GUI_PLUGIN && + pluginType != VisPluginType.GUI_STANDARD_PLUGIN) removePlugin((VisPlugin) openededFrame, false); } } diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 82d47b96c..252f4a848 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Simulation.java,v 1.5 2006/12/07 15:14:19 fros4943 Exp $ + * $Id: Simulation.java,v 1.6 2006/12/13 11:58:02 fros4943 Exp $ */ package se.sics.cooja; @@ -184,6 +184,7 @@ public class Simulation extends Observable implements Runnable { */ public void startSimulation() { if (!isRunning()) { + isRunning = true; thread = new Thread(this); thread.start(); } @@ -376,7 +377,8 @@ public class Simulation extends Observable implements Runnable { pluginElement.setText(openedPlugin.getClass().getName()); pluginSubElement = new Element("constructor"); - if (pluginType == VisPluginType.GUI_PLUGIN) { + if (pluginType == VisPluginType.GUI_PLUGIN || + pluginType == VisPluginType.GUI_STANDARD_PLUGIN) { pluginSubElement.setText("gui"); pluginElement.addContent(pluginSubElement); } else if (pluginType == VisPluginType.SIM_PLUGIN || diff --git a/tools/cooja/java/se/sics/cooja/VisPluginType.java b/tools/cooja/java/se/sics/cooja/VisPluginType.java index e30f62519..5ebdb1628 100644 --- a/tools/cooja/java/se/sics/cooja/VisPluginType.java +++ b/tools/cooja/java/se/sics/cooja/VisPluginType.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: VisPluginType.java,v 1.1 2006/08/21 12:12:57 fros4943 Exp $ + * $Id: VisPluginType.java,v 1.2 2006/12/13 11:58:28 fros4943 Exp $ */ package se.sics.cooja; @@ -104,6 +104,16 @@ public @interface VisPluginType { */ public static final int SIM_STANDARD_PLUGIN = 4; + + /** + * GUI Standard Plugin + * + * This is treated exactly like a GUI Plugin, with the + * only difference that this will automatically be opened + * when a GUI is created. + */ + public static final int GUI_STANDARD_PLUGIN = 5; + int value(); }