mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-10 11:29:38 +00:00
cleaning up after a removed simulation by the removed() methods +
exposing methods for loading simulations from external plugins + minor bug fix: the reload progress dialog sometimes disappear even when a simulation is loading
This commit is contained in:
parent
467cf88bcd
commit
977809144f
@ -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.151 2009/11/02 13:18:27 fros4943 Exp $
|
* $Id: GUI.java,v 1.152 2009/11/13 08:49:26 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
@ -1580,24 +1580,17 @@ public class GUI extends Observable {
|
|||||||
* @param mote Mote
|
* @param mote Mote
|
||||||
*/
|
*/
|
||||||
public void closeMotePlugins(Mote mote) {
|
public void closeMotePlugins(Mote mote) {
|
||||||
Vector<Plugin> pluginsToRemove = new Vector<Plugin>();
|
for (Plugin p: startedPlugins.toArray(new Plugin[0])) {
|
||||||
|
int pluginType = p.getClass().getAnnotation(PluginType.class).value();
|
||||||
for (Plugin startedPlugin : startedPlugins) {
|
|
||||||
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
|
|
||||||
|
|
||||||
if (pluginType != PluginType.MOTE_PLUGIN) {
|
if (pluginType != PluginType.MOTE_PLUGIN) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mote pluginMote = (Mote) startedPlugin.getTag();
|
Mote pluginMote = (Mote) p.getTag();
|
||||||
if (pluginMote == mote) {
|
if (pluginMote == mote) {
|
||||||
pluginsToRemove.add(startedPlugin);
|
removePlugin(p, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Plugin pluginToRemove: pluginsToRemove) {
|
|
||||||
removePlugin(pluginToRemove, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2032,25 +2025,38 @@ public class GUI extends Observable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new mote type of the given mote type class.
|
* Creates a new mote type of the given mote type class.
|
||||||
*
|
* This may include displaying a dialog for user configurations.
|
||||||
* @param moteTypeClass
|
*
|
||||||
* Mote type class
|
* If mote type is created successfully, the add motes dialog will appear.
|
||||||
|
*
|
||||||
|
* @param moteTypeClass Mote type class
|
||||||
*/
|
*/
|
||||||
public void doCreateMoteType(Class<? extends MoteType> moteTypeClass) {
|
public void doCreateMoteType(Class<? extends MoteType> moteTypeClass) {
|
||||||
|
doCreateMoteType(moteTypeClass, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new mote type of the given mote type class.
|
||||||
|
* This may include displaying a dialog for user configurations.
|
||||||
|
*
|
||||||
|
* @param moteTypeClass Mote type class
|
||||||
|
* @param addMotes Show add motes dialog after successfully adding mote type
|
||||||
|
*/
|
||||||
|
public void doCreateMoteType(Class<? extends MoteType> moteTypeClass, boolean addMotes) {
|
||||||
if (mySimulation == null) {
|
if (mySimulation == null) {
|
||||||
logger.fatal("Can't create mote type (no simulation)");
|
logger.fatal("Can't create mote type (no simulation)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop simulation (if running)
|
|
||||||
mySimulation.stopSimulation();
|
mySimulation.stopSimulation();
|
||||||
|
|
||||||
// Create mote type
|
// Create mote type
|
||||||
MoteType newMoteType = null;
|
MoteType newMoteType = null;
|
||||||
boolean moteTypeOK = false;
|
|
||||||
try {
|
try {
|
||||||
newMoteType = moteTypeClass.newInstance();
|
newMoteType = moteTypeClass.newInstance();
|
||||||
moteTypeOK = newMoteType.configureAndInit(GUI.getTopParentContainer(), mySimulation, isVisualized());
|
if (!newMoteType.configureAndInit(GUI.getTopParentContainer(), mySimulation, isVisualized())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mySimulation.addMoteType(newMoteType);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.fatal("Exception when creating mote type", e);
|
logger.fatal("Exception when creating mote type", e);
|
||||||
if (isVisualized()) {
|
if (isVisualized()) {
|
||||||
@ -2059,11 +2065,8 @@ public class GUI extends Observable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add mote type to simulation
|
/* Allow user to immediately add motes */
|
||||||
if (moteTypeOK) {
|
if (addMotes) {
|
||||||
mySimulation.addMoteType(newMoteType);
|
|
||||||
|
|
||||||
/* Allow user to immediately add motes */
|
|
||||||
doAddMotes(newMoteType);
|
doAddMotes(newMoteType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2115,6 +2118,7 @@ public class GUI extends Observable {
|
|||||||
// Delete simulation
|
// Delete simulation
|
||||||
mySimulation.deleteObservers();
|
mySimulation.deleteObservers();
|
||||||
mySimulation.stopSimulation();
|
mySimulation.stopSimulation();
|
||||||
|
mySimulation.removed();
|
||||||
|
|
||||||
/* Clear current mote relations */
|
/* Clear current mote relations */
|
||||||
MoteRelation relations[] = getMoteRelations();
|
MoteRelation relations[] = getMoteRelations();
|
||||||
@ -2223,18 +2227,7 @@ public class GUI extends Observable {
|
|||||||
|
|
||||||
progressDialog = new RunnableInEDT<JDialog>() {
|
progressDialog = new RunnableInEDT<JDialog>() {
|
||||||
public JDialog work() {
|
public JDialog work() {
|
||||||
final JDialog progressDialog;
|
final JDialog progressDialog = new JDialog((Window) GUI.getTopParentContainer(), progressTitle, ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
if (GUI.getTopParentContainer() instanceof Window) {
|
|
||||||
progressDialog = new JDialog((Window) GUI.getTopParentContainer(), progressTitle, ModalityType.APPLICATION_MODAL);
|
|
||||||
} else if (GUI.getTopParentContainer() instanceof Frame) {
|
|
||||||
progressDialog = new JDialog((Frame) GUI.getTopParentContainer(), progressTitle, ModalityType.APPLICATION_MODAL);
|
|
||||||
} else if (GUI.getTopParentContainer() instanceof Dialog) {
|
|
||||||
progressDialog = new JDialog((Dialog) GUI.getTopParentContainer(), progressTitle, ModalityType.APPLICATION_MODAL);
|
|
||||||
} else {
|
|
||||||
logger.warn("No parent container");
|
|
||||||
progressDialog = new JDialog((Frame) null, progressTitle, ModalityType.APPLICATION_MODAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
JPanel progressPanel = new JPanel(new BorderLayout());
|
JPanel progressPanel = new JPanel(new BorderLayout());
|
||||||
JProgressBar progressBar;
|
JProgressBar progressBar;
|
||||||
@ -2253,9 +2246,6 @@ public class GUI extends Observable {
|
|||||||
loadThread.interrupt();
|
loadThread.interrupt();
|
||||||
doRemoveSimulation(false);
|
doRemoveSimulation(false);
|
||||||
}
|
}
|
||||||
if (progressDialog.isDisplayable()) {
|
|
||||||
progressDialog.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2380,9 +2370,6 @@ public class GUI extends Observable {
|
|||||||
loadThread.interrupt();
|
loadThread.interrupt();
|
||||||
doRemoveSimulation(false);
|
doRemoveSimulation(false);
|
||||||
}
|
}
|
||||||
if (progressDialog.isDisplayable()) {
|
|
||||||
progressDialog.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2544,6 +2531,10 @@ public class GUI extends Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getSimulation() != null) {
|
||||||
|
doRemoveSimulation(false);
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up resources
|
// Clean up resources
|
||||||
Object[] plugins = startedPlugins.toArray();
|
Object[] plugins = startedPlugins.toArray();
|
||||||
for (Object plugin : plugins) {
|
for (Object plugin : plugins) {
|
||||||
@ -3186,7 +3177,7 @@ public class GUI extends Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Simulation loadSimulationConfig(StringReader stringReader, boolean quick)
|
public Simulation loadSimulationConfig(StringReader stringReader, boolean quick)
|
||||||
throws SimulationCreationException {
|
throws SimulationCreationException {
|
||||||
try {
|
try {
|
||||||
SAXBuilder builder = new SAXBuilder();
|
SAXBuilder builder = new SAXBuilder();
|
||||||
@ -3203,7 +3194,7 @@ public class GUI extends Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Simulation loadSimulationConfig(Element root, boolean quick, Long manualRandomSeed)
|
public Simulation loadSimulationConfig(Element root, boolean quick, Long manualRandomSeed)
|
||||||
throws SimulationCreationException {
|
throws SimulationCreationException {
|
||||||
Simulation newSim = null;
|
Simulation newSim = null;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user