From 89a062aa066e8d241aee86fcd9ec250029abeb99 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Mon, 17 Mar 2008 08:35:10 +0000 Subject: [PATCH] automatically close mote plugins when mote is removed --- tools/cooja/java/se/sics/cooja/GUI.java | 28 ++++++++++++++++++- .../cooja/java/se/sics/cooja/Simulation.java | 5 +++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/GUI.java b/tools/cooja/java/se/sics/cooja/GUI.java index 745c815f6..3bcfbdcab 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.71 2008/02/18 08:18:01 fros4943 Exp $ + * $Id: GUI.java,v 1.72 2008/03/17 08:35:10 fros4943 Exp $ */ package se.sics.cooja; @@ -1647,6 +1647,32 @@ public class GUI { myDesktopPane.moveToFront(plugin); } + /** + * Close all mote plugins for given mote. + * + * @param mote Mote + */ + public void closeMotePlugins(Mote mote) { + Vector pluginsToRemove = new Vector(); + + for (Plugin startedPlugin : startedPlugins) { + int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); + + if (pluginType != PluginType.MOTE_PLUGIN) { + continue; + } + + Mote pluginMote = (Mote) startedPlugin.getTag(); + if (pluginMote == mote) { + pluginsToRemove.add(startedPlugin); + } + } + + for (Plugin pluginToRemove: pluginsToRemove) { + removePlugin(pluginToRemove, false); + } + } + /** * Remove a plugin from working area. * diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 5dd709e59..909252864 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.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: Simulation.java,v 1.20 2008/02/12 15:31:22 fros4943 Exp $ + * $Id: Simulation.java,v 1.21 2008/03/17 08:35:10 fros4943 Exp $ */ package se.sics.cooja; @@ -543,6 +543,7 @@ public class Simulation extends Observable implements Runnable { * Mote to remove */ public void removeMote(Mote mote) { + if (isRunning()) { stopSimulation(); motes.remove(mote); @@ -551,7 +552,9 @@ public class Simulation extends Observable implements Runnable { motes.remove(mote); } + myGUI.closeMotePlugins(mote); currentRadioMedium.unregisterMote(mote, this); + this.setChanged(); this.notifyObservers(this); }