From e16107b0538b1c4b8cb2b9ef918e6698ae03f7c6 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Fri, 15 Jan 2010 10:47:36 +0000 Subject: [PATCH] using MotePlugin interface, rather than object tagging --- tools/cooja/java/se/sics/cooja/GUI.java | 22 +++++++------------ tools/cooja/java/se/sics/cooja/VisPlugin.java | 16 ++++---------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index ce5097a21..a99b46860 100644 --- a/tools/cooja/java/se/sics/cooja/GUI.java +++ b/tools/cooja/java/se/sics/cooja/GUI.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: GUI.java,v 1.156 2009/12/14 13:29:35 fros4943 Exp $ + * $Id: GUI.java,v 1.157 2010/01/15 10:47:36 fros4943 Exp $ */ package se.sics.cooja; @@ -1584,12 +1584,11 @@ public class GUI extends Observable { */ public void closeMotePlugins(Mote mote) { for (Plugin p: startedPlugins.toArray(new Plugin[0])) { - int pluginType = p.getClass().getAnnotation(PluginType.class).value(); - if (pluginType != PluginType.MOTE_PLUGIN) { + if (!(p instanceof MotePlugin)) { continue; } - Mote pluginMote = (Mote) p.getTag(); + Mote pluginMote = ((MotePlugin)p).getMote(); if (pluginMote == mote) { removePlugin(p, false); } @@ -1716,9 +1715,6 @@ public class GUI extends Observable { pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, GUI.class }) .newInstance(argMote, argSimulation, argGUI); - /* Tag plugin with mote */ - plugin.tagWithObject(argMote); - } else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) { if (argGUI == null) { @@ -3378,11 +3374,10 @@ public class GUI extends Observable { * @return Config or null */ public Collection getPluginsConfigXML() { - Vector config = new Vector(); - - // Loop through all started plugins - // (Only return config of non-GUI plugins) + ArrayList config = new ArrayList(); Element pluginElement, pluginSubElement; + + /* Loop over all plugins */ for (Plugin startedPlugin : startedPlugins) { int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); @@ -3396,10 +3391,9 @@ public class GUI extends Observable { pluginElement.setText(startedPlugin.getClass().getName()); // Create mote argument config (if mote plugin) - if (pluginType == PluginType.MOTE_PLUGIN - && startedPlugin.getTag() != null) { + if (pluginType == PluginType.MOTE_PLUGIN) { pluginSubElement = new Element("mote_arg"); - Mote taggedMote = (Mote) startedPlugin.getTag(); + Mote taggedMote = ((MotePlugin) startedPlugin).getMote(); for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) { if (mySimulation.getMote(moteNr) == taggedMote) { pluginSubElement.setText(Integer.toString(moteNr)); diff --git a/tools/cooja/java/se/sics/cooja/VisPlugin.java b/tools/cooja/java/se/sics/cooja/VisPlugin.java index 97f4a013e..d265db8dd 100644 --- a/tools/cooja/java/se/sics/cooja/VisPlugin.java +++ b/tools/cooja/java/se/sics/cooja/VisPlugin.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: VisPlugin.java,v 1.11 2009/12/14 13:29:35 fros4943 Exp $ + * $Id: VisPlugin.java,v 1.12 2010/01/15 10:47:36 fros4943 Exp $ */ package se.sics.cooja; @@ -54,7 +54,6 @@ import se.sics.cooja.plugins.SimControl; * @author Fredrik Osterlind */ public abstract class VisPlugin extends JInternalFrame implements Plugin { - private Object tag = null; public VisPlugin(String title, final GUI gui) { this(title, gui, true); @@ -75,8 +74,9 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin { } public void internalFrameActivated(InternalFrameEvent e) { /* Highlight mote in COOJA */ - if (VisPlugin.this.tag != null && tag instanceof Mote) { - gui.signalMoteHighlight((Mote) tag); + Plugin p = VisPlugin.this; + if (p instanceof MotePlugin) { + gui.signalMoteHighlight(((MotePlugin)p).getMote()); } gui.loadQuickHelp(VisPlugin.this); } @@ -96,14 +96,6 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin { return false; } - public void tagWithObject(Object tag) { - this.tag = tag; - } - - public Object getTag() { - return tag; - } - public void startPlugin() { } public void closePlugin() {