gui update: enable menu items depending on whether a simulation is loaded or not
This commit is contained in:
parent
efbae10245
commit
02b5d5e230
1 changed files with 347 additions and 192 deletions
|
@ -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.126 2009/05/27 23:23:41 nifi Exp $
|
* $Id: GUI.java,v 1.127 2009/05/28 12:55:14 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -277,6 +277,8 @@ public class GUI extends Observable {
|
||||||
|
|
||||||
private Vector<Plugin> startedPlugins = new Vector<Plugin>();
|
private Vector<Plugin> startedPlugins = new Vector<Plugin>();
|
||||||
|
|
||||||
|
private ArrayList<Action> guiActions = new ArrayList<Action>();
|
||||||
|
|
||||||
// Platform configuration variables
|
// Platform configuration variables
|
||||||
// Maintained via method reparseProjectConfig()
|
// Maintained via method reparseProjectConfig()
|
||||||
private ProjectConfig projectConfig;
|
private ProjectConfig projectConfig;
|
||||||
|
@ -578,15 +580,80 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateGUIComponentState() {
|
||||||
|
Action[] arr = guiActions.toArray(new Action[0]);
|
||||||
|
for (Action a: arr) {
|
||||||
|
a.setEnabled(a.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX The plugins menu items are not always correctly enabled */
|
||||||
|
for (Component menuComponent : menuPlugins.getMenuComponents()) {
|
||||||
|
if (menuComponent instanceof JMenuItem &&
|
||||||
|
((JMenuItem)menuComponent).getAction() == startSimPluginAction) {
|
||||||
|
((JMenuItem)menuComponent).setEnabled(startSimPluginAction.isEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
menuMoteTypeClasses.setEnabled(getSimulation() != null);
|
||||||
|
menuMoteTypes.setEnabled(getSimulation() != null);
|
||||||
|
}
|
||||||
|
|
||||||
private JMenuBar createMenuBar() {
|
private JMenuBar createMenuBar() {
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
JMenu menu;
|
JMenu menu;
|
||||||
JMenuItem menuItem;
|
JMenuItem menuItem;
|
||||||
|
|
||||||
// File menu
|
/* Prepare GUI actions */
|
||||||
|
newSimulationAction.putValue(Action.NAME, "New simulation");
|
||||||
|
newSimulationAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N);
|
||||||
|
newSimulationAction.putValue(Action.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
|
||||||
|
guiActions.add(newSimulationAction);
|
||||||
|
|
||||||
|
closeSimulationAction.putValue(Action.NAME, "Close simulation");
|
||||||
|
closeSimulationAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
|
||||||
|
guiActions.add(closeSimulationAction);
|
||||||
|
|
||||||
|
reloadSimulationAction.putValue(Action.NAME, "keep random seed");
|
||||||
|
reloadSimulationAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_K);
|
||||||
|
reloadSimulationAction.putValue(Action.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
|
||||||
|
guiActions.add(reloadSimulationAction);
|
||||||
|
|
||||||
|
reloadRandomSimulationAction.putValue(Action.NAME, "new random seed");
|
||||||
|
reloadRandomSimulationAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N);
|
||||||
|
reloadRandomSimulationAction.putValue(Action.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
|
||||||
|
guiActions.add(reloadRandomSimulationAction);
|
||||||
|
|
||||||
|
saveSimulationAction.putValue(Action.NAME, "Save simulation");
|
||||||
|
saveSimulationAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
|
||||||
|
guiActions.add(saveSimulationAction);
|
||||||
|
|
||||||
|
closePluginsAction.putValue(Action.NAME, "Close all plugins");
|
||||||
|
guiActions.add(closePluginsAction);
|
||||||
|
|
||||||
|
exitCoojaAction.putValue(Action.NAME, "Exit");
|
||||||
|
exitCoojaAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X);
|
||||||
|
exitCoojaAction.putValue(Action.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
|
||||||
|
guiActions.add(exitCoojaAction);
|
||||||
|
|
||||||
|
startStopSimulationAction.putValue(Action.NAME, "Start/Stop simulation");
|
||||||
|
startStopSimulationAction.putValue(Action.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
|
||||||
|
guiActions.add(startStopSimulationAction);
|
||||||
|
|
||||||
|
removeAllMotesAction.putValue(Action.NAME, "Remove all motes");
|
||||||
|
guiActions.add(removeAllMotesAction);
|
||||||
|
|
||||||
|
guiActions.add(startSimPluginAction);
|
||||||
|
|
||||||
|
/* File menu */
|
||||||
menu = new JMenu("File");
|
menu = new JMenu("File");
|
||||||
menu.addMenuListener(new MenuListener() {
|
menu.addMenuListener(new MenuListener() {
|
||||||
public void menuSelected(MenuEvent e) {
|
public void menuSelected(MenuEvent e) {
|
||||||
|
updateGUIComponentState();
|
||||||
updateOpenHistoryMenuItems();
|
updateOpenHistoryMenuItems();
|
||||||
}
|
}
|
||||||
public void menuDeselected(MenuEvent e) {
|
public void menuDeselected(MenuEvent e) {
|
||||||
|
@ -598,63 +665,14 @@ public class GUI extends Observable {
|
||||||
menu.setMnemonic(KeyEvent.VK_F);
|
menu.setMnemonic(KeyEvent.VK_F);
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
|
||||||
menuItem = new JMenuItem("New simulation");
|
menu.add(new JMenuItem(newSimulationAction));
|
||||||
menuItem.setMnemonic(KeyEvent.VK_N);
|
|
||||||
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
menuItem.setActionCommand("new sim");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
|
||||||
|
|
||||||
menuItem = new JMenu("Reload simulation");
|
menuItem = new JMenu("Reload simulation");
|
||||||
|
menuItem.add(new JMenuItem(reloadSimulationAction));
|
||||||
|
menuItem.add(new JMenuItem(reloadRandomSimulationAction));
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
|
||||||
ActionListener reloadListener = new ActionListener() {
|
menu.add(new JMenuItem(closeSimulationAction));
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if (getSimulation() == null) {
|
|
||||||
// Load last opened simulation configuration file when
|
|
||||||
// reloading without simulation (ask for a file if no file
|
|
||||||
// has been previously opened)
|
|
||||||
final File file = getLastOpenedFile();
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
myGUI.doLoadConfig(true, true, file);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
long seed = getSimulation().getRandomSeed();
|
|
||||||
if ("new random seed".equals(e.getActionCommand())) {
|
|
||||||
seed++;
|
|
||||||
}
|
|
||||||
reloadCurrentSimulation(
|
|
||||||
getSimulation().isRunning(),
|
|
||||||
seed);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
JMenuItem menuItem2 = new JMenuItem("same random seed");
|
|
||||||
menuItem2.setActionCommand("same random seed");
|
|
||||||
menuItem2.setMnemonic(KeyEvent.VK_R);
|
|
||||||
menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
menuItem2.addActionListener(reloadListener);
|
|
||||||
menuItem.add(menuItem2);
|
|
||||||
|
|
||||||
menuItem2 = new JMenuItem("new random seed");
|
|
||||||
menuItem2.setActionCommand("new random seed");
|
|
||||||
menuItem2.setMnemonic(KeyEvent.VK_R);
|
|
||||||
menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
|
|
||||||
ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
|
|
||||||
menuItem2.addActionListener(reloadListener);
|
|
||||||
menuItem.add(menuItem2);
|
|
||||||
|
|
||||||
menuItem = new JMenuItem("Close simulation");
|
|
||||||
menuItem.setMnemonic(KeyEvent.VK_C);
|
|
||||||
menuItem.setActionCommand("close sim");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
|
||||||
|
|
||||||
menuOpenSimulation = new JMenu("Open simulation");
|
menuOpenSimulation = new JMenu("Open simulation");
|
||||||
menuOpenSimulation.setMnemonic(KeyEvent.VK_O);
|
menuOpenSimulation.setMnemonic(KeyEvent.VK_O);
|
||||||
|
@ -673,77 +691,55 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
hasFileHistoryChanged = true;
|
hasFileHistoryChanged = true;
|
||||||
|
|
||||||
menuItem = new JMenuItem("Save simulation");
|
menu.add(new JMenuItem(saveSimulationAction));
|
||||||
menuItem.setMnemonic(KeyEvent.VK_S);
|
|
||||||
menuItem.setActionCommand("save sim");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
|
||||||
if (isVisualizedInApplet()) {
|
|
||||||
menuItem.setEnabled(false);
|
|
||||||
menuItem.setToolTipText("Not available in applet version");
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
menuItem = new JMenuItem("Close all plugins");
|
menu.add(new JMenuItem(closePluginsAction));
|
||||||
menuItem.setActionCommand("close plugins");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
menuItem = new JMenuItem("Exit");
|
menu.add(new JMenuItem(exitCoojaAction));
|
||||||
menuItem.setMnemonic(KeyEvent.VK_X);
|
|
||||||
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
menuItem.setActionCommand("quit");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
|
||||||
if (isVisualizedInApplet()) {
|
|
||||||
menuItem.setEnabled(false);
|
|
||||||
menuItem.setToolTipText("Not available in applet version");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulation menu
|
/* Simulation menu */
|
||||||
menu = new JMenu("Simulation");
|
menu = new JMenu("Simulation");
|
||||||
|
menu.addMenuListener(new MenuListener() {
|
||||||
|
public void menuSelected(MenuEvent e) {
|
||||||
|
updateGUIComponentState();
|
||||||
|
}
|
||||||
|
public void menuDeselected(MenuEvent e) {
|
||||||
|
}
|
||||||
|
public void menuCanceled(MenuEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
menu.setMnemonic(KeyEvent.VK_S);
|
menu.setMnemonic(KeyEvent.VK_S);
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Start/Stop simulation");
|
menu.add(new JMenuItem(startStopSimulationAction));
|
||||||
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
|
|
||||||
ActionEvent.CTRL_MASK));
|
|
||||||
menuItem.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
/* Start/Stop current simulation */
|
|
||||||
Simulation sim = getSimulation();
|
|
||||||
if (sim == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (sim.isRunning()) {
|
|
||||||
sim.stopSimulation();
|
|
||||||
} else {
|
|
||||||
sim.startSimulation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.add(menuItem);
|
|
||||||
|
|
||||||
menuItem = new JMenuItem("Open Control");
|
menuItem = new JMenuItem(startSimPluginAction);
|
||||||
|
menuItem.setText("Control panel");
|
||||||
menuItem.setMnemonic(KeyEvent.VK_C);
|
menuItem.setMnemonic(KeyEvent.VK_C);
|
||||||
menuItem.setActionCommand("start plugin");
|
|
||||||
menuItem.putClientProperty("class", SimControl.class);
|
menuItem.putClientProperty("class", SimControl.class);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Information");
|
menuItem = new JMenuItem(startSimPluginAction);
|
||||||
|
menuItem.setText("Information");
|
||||||
menuItem.setMnemonic(KeyEvent.VK_I);
|
menuItem.setMnemonic(KeyEvent.VK_I);
|
||||||
menuItem.setActionCommand("start plugin");
|
|
||||||
menuItem.putClientProperty("class", SimInformation.class);
|
menuItem.putClientProperty("class", SimInformation.class);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
|
||||||
// Mote type menu
|
// Mote type menu
|
||||||
menu = new JMenu("Mote Types");
|
menu = new JMenu("Mote Types");
|
||||||
|
menu.addMenuListener(new MenuListener() {
|
||||||
|
public void menuSelected(MenuEvent e) {
|
||||||
|
updateGUIComponentState();
|
||||||
|
}
|
||||||
|
public void menuDeselected(MenuEvent e) {
|
||||||
|
}
|
||||||
|
public void menuCanceled(MenuEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
menu.setMnemonic(KeyEvent.VK_T);
|
menu.setMnemonic(KeyEvent.VK_T);
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
|
||||||
|
@ -812,15 +808,23 @@ public class GUI extends Observable {
|
||||||
});
|
});
|
||||||
menu.add(menuMoteTypeClasses);
|
menu.add(menuMoteTypeClasses);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Information");
|
menuItem = new JMenuItem(startSimPluginAction);
|
||||||
menuItem.setActionCommand("start plugin");
|
menuItem.setText("Information");
|
||||||
menuItem.putClientProperty("class", MoteTypeInformation.class);
|
menuItem.putClientProperty("class", MoteTypeInformation.class);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
|
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
|
||||||
// Mote menu
|
// Mote menu
|
||||||
menu = new JMenu("Motes");
|
menu = new JMenu("Motes");
|
||||||
|
menu.addMenuListener(new MenuListener() {
|
||||||
|
public void menuSelected(MenuEvent e) {
|
||||||
|
updateGUIComponentState();
|
||||||
|
}
|
||||||
|
public void menuDeselected(MenuEvent e) {
|
||||||
|
}
|
||||||
|
public void menuCanceled(MenuEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
menu.setMnemonic(KeyEvent.VK_M);
|
menu.setMnemonic(KeyEvent.VK_M);
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
|
||||||
|
@ -857,11 +861,7 @@ public class GUI extends Observable {
|
||||||
});
|
});
|
||||||
menu.add(menuMoteTypes);
|
menu.add(menuMoteTypes);
|
||||||
|
|
||||||
menuItem = new JMenuItem("Remove all motes");
|
menu.add(new JMenuItem(removeAllMotesAction));
|
||||||
menuItem.setActionCommand("remove all motes");
|
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
|
|
||||||
menu.add(menuItem);
|
|
||||||
|
|
||||||
// Plugins menu
|
// Plugins menu
|
||||||
if (menuPlugins == null) {
|
if (menuPlugins == null) {
|
||||||
|
@ -879,6 +879,15 @@ public class GUI extends Observable {
|
||||||
|
|
||||||
// Settings menu
|
// Settings menu
|
||||||
menu = new JMenu("Settings");
|
menu = new JMenu("Settings");
|
||||||
|
menu.addMenuListener(new MenuListener() {
|
||||||
|
public void menuSelected(MenuEvent e) {
|
||||||
|
updateGUIComponentState();
|
||||||
|
}
|
||||||
|
public void menuDeselected(MenuEvent e) {
|
||||||
|
}
|
||||||
|
public void menuCanceled(MenuEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
menuBar.add(menu);
|
menuBar.add(menu);
|
||||||
|
|
||||||
menuItem = new JMenuItem("External tools paths");
|
menuItem = new JMenuItem("External tools paths");
|
||||||
|
@ -1524,6 +1533,7 @@ public class GUI extends Observable {
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
plugin.closePlugin();
|
plugin.closePlugin();
|
||||||
startedPlugins.remove(plugin);
|
startedPlugins.remove(plugin);
|
||||||
|
updateGUIComponentState();
|
||||||
|
|
||||||
/* Dispose visualized components */
|
/* Dispose visualized components */
|
||||||
if (plugin.getGUI() != null) {
|
if (plugin.getGUI() != null) {
|
||||||
|
@ -1622,6 +1632,7 @@ public class GUI extends Observable {
|
||||||
|
|
||||||
// Add to active plugins list
|
// Add to active plugins list
|
||||||
startedPlugins.add(plugin);
|
startedPlugins.add(plugin);
|
||||||
|
updateGUIComponentState();
|
||||||
|
|
||||||
// Show plugin if visualizer type
|
// Show plugin if visualizer type
|
||||||
if (plugin.getGUI() != null) {
|
if (plugin.getGUI() != null) {
|
||||||
|
@ -1744,9 +1755,9 @@ public class GUI extends Observable {
|
||||||
public Boolean work() {
|
public Boolean work() {
|
||||||
// Create 'start plugin'-menu item
|
// Create 'start plugin'-menu item
|
||||||
JMenuItem menuItem = new JMenuItem(description);
|
JMenuItem menuItem = new JMenuItem(description);
|
||||||
menuItem.setActionCommand("start plugin");
|
|
||||||
menuItem.putClientProperty("class", newPluginClass);
|
menuItem.putClientProperty("class", newPluginClass);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
|
||||||
|
String tooltip = "<html>";
|
||||||
|
|
||||||
/* Sort menu according to plugin type */
|
/* Sort menu according to plugin type */
|
||||||
int itemIndex=0;
|
int itemIndex=0;
|
||||||
|
@ -1756,7 +1767,7 @@ public class GUI extends Observable {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuItem.setToolTipText("COOJA plugin: " + newPluginClass.getName());
|
tooltip += "COOJA plugin: " + newPluginClass.getName();
|
||||||
} else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) {
|
} else if (pluginType == PluginType.SIM_PLUGIN || pluginType == PluginType.SIM_STANDARD_PLUGIN) {
|
||||||
for (; itemIndex < menuPlugins.getItemCount(); itemIndex++) {
|
for (; itemIndex < menuPlugins.getItemCount(); itemIndex++) {
|
||||||
if (menuPlugins.getItem(itemIndex) == null /* separator */) {
|
if (menuPlugins.getItem(itemIndex) == null /* separator */) {
|
||||||
|
@ -1769,15 +1780,28 @@ public class GUI extends Observable {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuItem.setToolTipText("Simulation plugin: " + newPluginClass.getName());
|
tooltip += "Simulation plugin: " + newPluginClass.getName();
|
||||||
|
menuItem.setAction(startSimPluginAction);
|
||||||
|
menuItem.setText(description);
|
||||||
} else if (pluginType == PluginType.MOTE_PLUGIN) {
|
} else if (pluginType == PluginType.MOTE_PLUGIN) {
|
||||||
// Disable previous menu item and add new item to mote plugins menu
|
// Disable previous menu item and add new item to mote plugins menu
|
||||||
menuItem.setEnabled(false);
|
menuItem.setEnabled(false);
|
||||||
menuItem.setToolTipText("Mote plugin: " + newPluginClass.getName());
|
tooltip += "Mote plugin: " + newPluginClass.getName();
|
||||||
|
tooltip += "<br>Start mote plugins by right-clicking a mote in the simulation visualizer";
|
||||||
menuMotePluginClasses.add(newPluginClass);
|
menuMotePluginClasses.add(newPluginClass);
|
||||||
itemIndex = menuPlugins.getItemCount();
|
itemIndex = menuPlugins.getItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if plugin was imported by a project directory */
|
||||||
|
File project =
|
||||||
|
getProjectConfig().getUserProjectDefining(GUI.class, "PLUGINS", newPluginClass.getName());
|
||||||
|
if (project != null) {
|
||||||
|
tooltip += "<br>Loaded by project: " + project.getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
tooltip += "</html>";
|
||||||
|
menuItem.setToolTipText(tooltip);
|
||||||
|
|
||||||
menuPlugins.add(menuItem, itemIndex);
|
menuPlugins.add(menuItem, itemIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1817,7 +1841,6 @@ public class GUI extends Observable {
|
||||||
|
|
||||||
for (Class<? extends Plugin> motePluginClass: menuMotePluginClasses) {
|
for (Class<? extends Plugin> motePluginClass: menuMotePluginClasses) {
|
||||||
JMenuItem menuItem = new JMenuItem(getDescriptionOf(motePluginClass));
|
JMenuItem menuItem = new JMenuItem(getDescriptionOf(motePluginClass));
|
||||||
menuItem.setActionCommand("start plugin");
|
|
||||||
menuItem.putClientProperty("class", motePluginClass);
|
menuItem.putClientProperty("class", motePluginClass);
|
||||||
menuItem.putClientProperty("mote", mote);
|
menuItem.putClientProperty("mote", mote);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
|
@ -1840,6 +1863,7 @@ public class GUI extends Observable {
|
||||||
doRemoveSimulation(false);
|
doRemoveSimulation(false);
|
||||||
}
|
}
|
||||||
mySimulation = sim;
|
mySimulation = sim;
|
||||||
|
updateGUIComponentState();
|
||||||
|
|
||||||
// Set frame title
|
// Set frame title
|
||||||
if (frame != null) {
|
if (frame != null) {
|
||||||
|
@ -1953,6 +1977,7 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
|
|
||||||
mySimulation = null;
|
mySimulation = null;
|
||||||
|
updateGUIComponentState();
|
||||||
|
|
||||||
// Unregister temporary plugin classes
|
// Unregister temporary plugin classes
|
||||||
Class<? extends Plugin>[] pluginClasses =
|
Class<? extends Plugin>[] pluginClasses =
|
||||||
|
@ -2281,8 +2306,7 @@ public class GUI extends Observable {
|
||||||
String s1 = "Overwrite";
|
String s1 = "Overwrite";
|
||||||
String s2 = "Cancel";
|
String s2 = "Cancel";
|
||||||
Object[] options = { s1, s2 };
|
Object[] options = { s1, s2 };
|
||||||
int n = JOptionPane
|
int n = JOptionPane.showOptionDialog(
|
||||||
.showOptionDialog(
|
|
||||||
GUI.getTopParentContainer(),
|
GUI.getTopParentContainer(),
|
||||||
"A file with the same name already exists.\nDo you want to remove it?",
|
"A file with the same name already exists.\nDo you want to remove it?",
|
||||||
"Overwrite existing file?", JOptionPane.YES_NO_OPTION,
|
"Overwrite existing file?", JOptionPane.YES_NO_OPTION,
|
||||||
|
@ -2597,11 +2621,7 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (e.getActionCommand().equals("new sim")) {
|
if (e.getActionCommand().equals("confopen sim")) {
|
||||||
myGUI.doCreateSimulation(true);
|
|
||||||
} else if (e.getActionCommand().equals("close sim")) {
|
|
||||||
myGUI.doRemoveSimulation(true);
|
|
||||||
} else if (e.getActionCommand().equals("confopen sim")) {
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
myGUI.doLoadConfig(true, false, null);
|
myGUI.doLoadConfig(true, false, null);
|
||||||
|
@ -2627,10 +2647,6 @@ public class GUI extends Observable {
|
||||||
myGUI.doLoadConfig(true, true, file);
|
myGUI.doLoadConfig(true, true, file);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
} else if (e.getActionCommand().equals("save sim")) {
|
|
||||||
myGUI.doSaveConfig(true);
|
|
||||||
} else if (e.getActionCommand().equals("quit")) {
|
|
||||||
myGUI.doQuit(true);
|
|
||||||
} else if (e.getActionCommand().equals("create mote type")) {
|
} else if (e.getActionCommand().equals("create mote type")) {
|
||||||
myGUI.doCreateMoteType((Class<? extends MoteType>) ((JMenuItem) e
|
myGUI.doCreateMoteType((Class<? extends MoteType>) ((JMenuItem) e
|
||||||
.getSource()).getClientProperty("class"));
|
.getSource()).getClientProperty("class"));
|
||||||
|
@ -2639,21 +2655,6 @@ public class GUI extends Observable {
|
||||||
.getClientProperty("motetype"));
|
.getClientProperty("motetype"));
|
||||||
} else if (e.getActionCommand().equals("edit paths")) {
|
} else if (e.getActionCommand().equals("edit paths")) {
|
||||||
ExternalToolsDialog.showDialog(GUI.getTopParentContainer());
|
ExternalToolsDialog.showDialog(GUI.getTopParentContainer());
|
||||||
} else if (e.getActionCommand().equals("close plugins")) {
|
|
||||||
Object[] plugins = startedPlugins.toArray();
|
|
||||||
for (Object plugin : plugins) {
|
|
||||||
removePlugin((Plugin) plugin, false);
|
|
||||||
}
|
|
||||||
} else if (e.getActionCommand().equals("remove all motes")) {
|
|
||||||
if (getSimulation() != null) {
|
|
||||||
if (getSimulation().isRunning()) {
|
|
||||||
getSimulation().stopSimulation();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (getSimulation().getMotesCount() > 0) {
|
|
||||||
getSimulation().removeMote(getSimulation().getMote(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (e.getActionCommand().equals("manage projects")) {
|
} else if (e.getActionCommand().equals("manage projects")) {
|
||||||
Vector<File> newProjects = ProjectDirectoriesDialog.showDialog(
|
Vector<File> newProjects = ProjectDirectoriesDialog.showDialog(
|
||||||
GUI.getTopParentContainer(), currentProjectDirs, null);
|
GUI.getTopParentContainer(), currentProjectDirs, null);
|
||||||
|
@ -2674,11 +2675,6 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
} else if (e.getActionCommand().equals("configuration wizard")) {
|
} else if (e.getActionCommand().equals("configuration wizard")) {
|
||||||
ConfigurationWizard.startWizard(GUI.getTopParentContainer(), GUI.this);
|
ConfigurationWizard.startWizard(GUI.getTopParentContainer(), GUI.this);
|
||||||
} else if (e.getActionCommand().equals("start plugin")) {
|
|
||||||
Class<Plugin> pluginClass =
|
|
||||||
(Class<Plugin>) ((JMenuItem) e.getSource()).getClientProperty("class");
|
|
||||||
Mote mote = (Mote) ((JMenuItem) e.getSource()).getClientProperty("mote");
|
|
||||||
startPlugin(pluginClass, myGUI, mySimulation, mote);
|
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unhandled action: " + e.getActionCommand());
|
logger.warn("Unhandled action: " + e.getActionCommand());
|
||||||
}
|
}
|
||||||
|
@ -2703,8 +2699,7 @@ public class GUI extends Observable {
|
||||||
|
|
||||||
if (callingObject != null) {
|
if (callingObject != null) {
|
||||||
try {
|
try {
|
||||||
return callingObject.getClass().getClassLoader().loadClass(className)
|
return callingObject.getClass().getClassLoader().loadClass(className).asSubclass(classType);
|
||||||
.asSubclass(classType);
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
} catch (UnsupportedClassVersionError e) {
|
} catch (UnsupportedClassVersionError e) {
|
||||||
}
|
}
|
||||||
|
@ -3235,8 +3230,7 @@ public class GUI extends Observable {
|
||||||
// (Only return config of non-GUI plugins)
|
// (Only return config of non-GUI plugins)
|
||||||
Element pluginElement, pluginSubElement;
|
Element pluginElement, pluginSubElement;
|
||||||
for (Plugin startedPlugin : startedPlugins) {
|
for (Plugin startedPlugin : startedPlugins) {
|
||||||
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class)
|
int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();
|
||||||
.value();
|
|
||||||
|
|
||||||
// Ignore GUI plugins
|
// Ignore GUI plugins
|
||||||
if (pluginType == PluginType.COOJA_PLUGIN
|
if (pluginType == PluginType.COOJA_PLUGIN
|
||||||
|
@ -3800,4 +3794,165 @@ public class GUI extends Observable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* GUI actions */
|
||||||
|
Action newSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
myGUI.doCreateSimulation(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action closeSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
myGUI.doRemoveSimulation(true);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return getSimulation() != null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action reloadSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (getSimulation() == null) {
|
||||||
|
/* Reload last opened simulation */
|
||||||
|
final File file = getLastOpenedFile();
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
myGUI.doLoadConfig(true, true, file);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reload current simulation */
|
||||||
|
long seed = getSimulation().getRandomSeed();
|
||||||
|
reloadCurrentSimulation(getSimulation().isRunning(), seed);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action reloadRandomSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Replace seed before reloading */
|
||||||
|
getSimulation().setRandomSeed(getSimulation().getRandomSeed()+1);
|
||||||
|
reloadSimulationAction.actionPerformed(null);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return reloadSimulationAction.isEnabled();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action saveSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
myGUI.doSaveConfig(true);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return getSimulation() != null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action closePluginsAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object[] plugins = startedPlugins.toArray();
|
||||||
|
for (Object plugin : plugins) {
|
||||||
|
removePlugin((Plugin) plugin, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return !startedPlugins.isEmpty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action exitCoojaAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
myGUI.doQuit(true);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action startStopSimulationAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start/Stop current simulation */
|
||||||
|
Simulation sim = getSimulation();
|
||||||
|
if (sim == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sim.isRunning()) {
|
||||||
|
sim.stopSimulation();
|
||||||
|
} else {
|
||||||
|
sim.startSimulation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void setEnabled(boolean newValue) {
|
||||||
|
if (getSimulation() == null) {
|
||||||
|
putValue(NAME, "Start/Stop simulation");
|
||||||
|
} else if (getSimulation().isRunning()) {
|
||||||
|
putValue(NAME, "Stop simulation");
|
||||||
|
} else {
|
||||||
|
putValue(NAME, "Start simulation");
|
||||||
|
}
|
||||||
|
super.setEnabled(newValue);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return getSimulation() != null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action startSimPluginAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Class<Plugin> pluginClass =
|
||||||
|
(Class<Plugin>) ((JMenuItem) e.getSource()).getClientProperty("class");
|
||||||
|
Mote mote = (Mote) ((JMenuItem) e.getSource()).getClientProperty("mote");
|
||||||
|
startPlugin(pluginClass, myGUI, mySimulation, mote);
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return getSimulation() != null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Action removeAllMotesAction = new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (!isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getSimulation().isRunning()) {
|
||||||
|
getSimulation().stopSimulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (getSimulation().getMotesCount() > 0) {
|
||||||
|
getSimulation().removeMote(getSimulation().getMote(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return getSimulation() != null && getSimulation().getMotesCount() > 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue