added support for gui standard plugin

This commit is contained in:
fros4943 2006-12-13 11:57:04 +00:00
parent 67048e9ea0
commit 76bb1dbd5f
3 changed files with 39 additions and 6 deletions

View file

@ -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<? extends VisPlugin> 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<? extends VisPlugin>) frameClass)
.getAnnotation(VisPluginType.class).value();
if (pluginType != VisPluginType.GUI_PLUGIN)
if (pluginType != VisPluginType.GUI_PLUGIN &&
pluginType != VisPluginType.GUI_STANDARD_PLUGIN)
removePlugin((VisPlugin) openededFrame, false);
}
}

View file

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

View file

@ -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();
}