using MotePlugin interface, rather than object tagging

This commit is contained in:
fros4943 2010-01-15 10:47:36 +00:00
parent 61890416f5
commit e16107b053
2 changed files with 12 additions and 26 deletions

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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; package se.sics.cooja;
@ -1584,12 +1584,11 @@ public class GUI extends Observable {
*/ */
public void closeMotePlugins(Mote mote) { public void closeMotePlugins(Mote mote) {
for (Plugin p: startedPlugins.toArray(new Plugin[0])) { for (Plugin p: startedPlugins.toArray(new Plugin[0])) {
int pluginType = p.getClass().getAnnotation(PluginType.class).value(); if (!(p instanceof MotePlugin)) {
if (pluginType != PluginType.MOTE_PLUGIN) {
continue; continue;
} }
Mote pluginMote = (Mote) p.getTag(); Mote pluginMote = ((MotePlugin)p).getMote();
if (pluginMote == mote) { if (pluginMote == mote) {
removePlugin(p, false); removePlugin(p, false);
} }
@ -1716,9 +1715,6 @@ public class GUI extends Observable {
pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, GUI.class }) pluginClass.getConstructor(new Class[] { Mote.class, Simulation.class, GUI.class })
.newInstance(argMote, argSimulation, argGUI); .newInstance(argMote, argSimulation, argGUI);
/* Tag plugin with mote */
plugin.tagWithObject(argMote);
} else if (pluginType == PluginType.SIM_PLUGIN } else if (pluginType == PluginType.SIM_PLUGIN
|| pluginType == PluginType.SIM_STANDARD_PLUGIN) { || pluginType == PluginType.SIM_STANDARD_PLUGIN) {
if (argGUI == null) { if (argGUI == null) {
@ -3378,11 +3374,10 @@ public class GUI extends Observable {
* @return Config or null * @return Config or null
*/ */
public Collection<Element> getPluginsConfigXML() { public Collection<Element> getPluginsConfigXML() {
Vector<Element> config = new Vector<Element>(); ArrayList<Element> config = new ArrayList<Element>();
// Loop through all started plugins
// (Only return config of non-GUI plugins)
Element pluginElement, pluginSubElement; Element pluginElement, pluginSubElement;
/* Loop over all plugins */
for (Plugin startedPlugin : startedPlugins) { for (Plugin startedPlugin : startedPlugins) {
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value(); int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
@ -3396,10 +3391,9 @@ public class GUI extends Observable {
pluginElement.setText(startedPlugin.getClass().getName()); pluginElement.setText(startedPlugin.getClass().getName());
// Create mote argument config (if mote plugin) // Create mote argument config (if mote plugin)
if (pluginType == PluginType.MOTE_PLUGIN if (pluginType == PluginType.MOTE_PLUGIN) {
&& startedPlugin.getTag() != null) {
pluginSubElement = new Element("mote_arg"); pluginSubElement = new Element("mote_arg");
Mote taggedMote = (Mote) startedPlugin.getTag(); Mote taggedMote = ((MotePlugin) startedPlugin).getMote();
for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) { for (int moteNr = 0; moteNr < mySimulation.getMotesCount(); moteNr++) {
if (mySimulation.getMote(moteNr) == taggedMote) { if (mySimulation.getMote(moteNr) == taggedMote) {
pluginSubElement.setText(Integer.toString(moteNr)); pluginSubElement.setText(Integer.toString(moteNr));

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja;
@ -54,7 +54,6 @@ import se.sics.cooja.plugins.SimControl;
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public abstract class VisPlugin extends JInternalFrame implements Plugin { public abstract class VisPlugin extends JInternalFrame implements Plugin {
private Object tag = null;
public VisPlugin(String title, final GUI gui) { public VisPlugin(String title, final GUI gui) {
this(title, gui, true); this(title, gui, true);
@ -75,8 +74,9 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin {
} }
public void internalFrameActivated(InternalFrameEvent e) { public void internalFrameActivated(InternalFrameEvent e) {
/* Highlight mote in COOJA */ /* Highlight mote in COOJA */
if (VisPlugin.this.tag != null && tag instanceof Mote) { Plugin p = VisPlugin.this;
gui.signalMoteHighlight((Mote) tag); if (p instanceof MotePlugin) {
gui.signalMoteHighlight(((MotePlugin)p).getMote());
} }
gui.loadQuickHelp(VisPlugin.this); gui.loadQuickHelp(VisPlugin.this);
} }
@ -96,14 +96,6 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin {
return false; return false;
} }
public void tagWithObject(Object tag) {
this.tag = tag;
}
public Object getTag() {
return tag;
}
public void startPlugin() { public void startPlugin() {
} }
public void closePlugin() { public void closePlugin() {