explicitly calling startPlugin and showPlugin methods, instead of relying on the plugin constructor to configure the plugin. if a simulation is loaded, startPlugin() is called after the simulation configuration is set

This commit is contained in:
fros4943 2009-12-14 13:29:35 +00:00
parent 32936c3df8
commit 9ddc25527d
3 changed files with 49 additions and 13 deletions

View File

@ -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.155 2009/11/25 20:47:18 fros4943 Exp $
* $Id: GUI.java,v 1.156 2009/12/14 13:29:35 fros4943 Exp $
*/
package se.sics.cooja;
@ -1640,10 +1640,10 @@ public class GUI extends Observable {
* @param argMote Plugin mote argument
* @return Started plugin
*/
public Plugin tryStartPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote) {
private Plugin tryStartPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote, boolean activate) {
try {
return startPlugin(pluginClass, argGUI, argSimulation, argMote);
return startPlugin(pluginClass, argGUI, argSimulation, argMote, activate);
} catch (PluginConstructionException ex) {
if (GUI.isVisualized()) {
GUI.showErrorDialog(GUI.getTopParentContainer(), "Error when starting plugin", ex, false);
@ -1663,6 +1663,18 @@ public class GUI extends Observable {
return null;
}
public Plugin tryStartPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote) {
return tryStartPlugin(pluginClass, argGUI, argSimulation, argMote, true);
}
public Plugin startPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote)
throws PluginConstructionException
{
return startPlugin(pluginClass, argGUI, argSimulation, argMote, true);
}
/**
* Starts given plugin. If visualized, the plugin is also shown.
*
@ -1674,8 +1686,8 @@ public class GUI extends Observable {
* @return Started plugin
* @throws PluginConstructionException At errors
*/
public Plugin startPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote)
private Plugin startPlugin(final Class<? extends Plugin> pluginClass,
final GUI argGUI, final Simulation argSimulation, final Mote argMote, boolean activate)
throws PluginConstructionException
{
@ -1743,15 +1755,19 @@ public class GUI extends Observable {
throw ex;
}
if (activate) {
plugin.startPlugin();
}
// Add to active plugins list
startedPlugins.add(plugin);
updateGUIComponentState();
// Show plugin if visualizer type
if (plugin.getGUI() != null) {
if (activate && plugin.getGUI() != null) {
myGUI.showPlugin(plugin);
}
return plugin;
}
@ -3515,7 +3531,7 @@ public class GUI extends Observable {
}
/* Start plugin */
final Plugin startedPlugin = tryStartPlugin(pluginClass, this, simulation, mote);
final Plugin startedPlugin = tryStartPlugin(pluginClass, this, simulation, mote, false);
if (startedPlugin == null) {
continue;
}
@ -3527,6 +3543,9 @@ public class GUI extends Observable {
}
}
/* Activate plugin */
startedPlugin.startPlugin();
/* If Cooja not visualized, ignore window configuration */
if (startedPlugin.getGUI() == null) {
continue;
@ -3573,6 +3592,7 @@ public class GUI extends Observable {
}
} catch (Exception e) { }
showPlugin(startedPlugin);
return true;
}
}.invokeAndWait();

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: Plugin.java,v 1.3 2008/12/16 15:07:14 fros4943 Exp $
* $Id: Plugin.java,v 1.4 2009/12/14 13:29:35 fros4943 Exp $
*/
package se.sics.cooja;
@ -54,6 +54,16 @@ public interface Plugin {
*/
public JInternalFrame getGUI();
/**
* This method is called to activate a new plugin, after constructing it.
* If a simulation is loaded, this method is called after {@link #setConfigXML(Collection, boolean)}.
*
* @see #setConfigXML(Collection, boolean)
* @see #closePlugin()
*/
public void startPlugin();
/**
* This method is called when an opened plugin is about to close.
* It should release any resources such as registered observers or

View File

@ -26,16 +26,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: VisPlugin.java,v 1.10 2009/06/30 12:46:26 fros4943 Exp $
* $Id: VisPlugin.java,v 1.11 2009/12/14 13:29:35 fros4943 Exp $
*/
package se.sics.cooja;
import java.util.Collection;
import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import org.jdom.Element;
import se.sics.cooja.plugins.SimControl;
@ -103,6 +104,11 @@ public abstract class VisPlugin extends JInternalFrame implements Plugin {
return tag;
}
public class PluginRequiresVisualizationException extends RuntimeException {
public void startPlugin() {
}
public void closePlugin() {
}
public static class PluginRequiresVisualizationException extends RuntimeException {
}
}