removed temporary plugins, fixed compiler warnings, using new cooja projects class

This commit is contained in:
fros4943 2010-12-02 15:29:07 +00:00
parent 6f66d45917
commit 773fbf8727

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.171 2010/09/24 12:48:04 fros4943 Exp $ * $Id: GUI.java,v 1.172 2010/12/02 15:29:07 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -148,6 +148,10 @@ import se.sics.cooja.util.ExecuteJAR;
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class GUI extends Observable { public class GUI extends Observable {
private static JFrame frame = null;
private static JApplet applet = null;
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(GUI.class);
/** /**
* External tools default Win32 settings filename. * External tools default Win32 settings filename.
@ -224,14 +228,6 @@ public class GUI extends Observable {
} }
}; };
private static JFrame frame = null;
private static JApplet applet = null;
private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(GUI.class);
// External tools setting names // External tools setting names
public static Properties defaultExternalToolsSettings; public static Properties defaultExternalToolsSettings;
public static Properties currentExternalToolsSettings; public static Properties currentExternalToolsSettings;
@ -303,7 +299,7 @@ public class GUI extends Observable {
// Maintained via method reparseProjectConfig() // Maintained via method reparseProjectConfig()
private ProjectConfig projectConfig; private ProjectConfig projectConfig;
private Vector<File> currentProjectDirs = new Vector<File>(); private ArrayList<COOJAProject> currentProjects = new ArrayList<COOJAProject>();
public ClassLoader projectDirClassLoader; public ClassLoader projectDirClassLoader;
@ -311,12 +307,8 @@ public class GUI extends Observable {
private Vector<Class<? extends Plugin>> pluginClasses = new Vector<Class<? extends Plugin>>(); private Vector<Class<? extends Plugin>> pluginClasses = new Vector<Class<? extends Plugin>>();
private Vector<Class<? extends Plugin>> pluginClassesTemporary = new Vector<Class<? extends Plugin>>();
private Vector<Class<? extends RadioMedium>> radioMediumClasses = new Vector<Class<? extends RadioMedium>>(); private Vector<Class<? extends RadioMedium>> radioMediumClasses = new Vector<Class<? extends RadioMedium>>();
private Vector<Class<? extends IPDistributor>> ipDistributorClasses = new Vector<Class<? extends IPDistributor>>();
private Vector<Class<? extends Positioner>> positionerClasses = new Vector<Class<? extends Positioner>>(); private Vector<Class<? extends Positioner>> positionerClasses = new Vector<Class<? extends Positioner>>();
private class HighlightObservable extends Observable { private class HighlightObservable extends Observable {
@ -407,7 +399,7 @@ public class GUI extends Observable {
String[] arr = defaultProjectDirs.split(";"); String[] arr = defaultProjectDirs.split(";");
for (String p : arr) { for (String p : arr) {
File projectDir = restorePortablePath(new File(p)); File projectDir = restorePortablePath(new File(p));
currentProjectDirs.add(projectDir); currentProjects.add(new COOJAProject(projectDir));
} }
} }
@ -417,12 +409,13 @@ public class GUI extends Observable {
} catch (ParseProjectsException e) { } catch (ParseProjectsException e) {
logger.fatal("Error when loading projects: " + e.getMessage(), e); logger.fatal("Error when loading projects: " + e.getMessage(), e);
if (isVisualized()) { if (isVisualized()) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(), JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Default projects could not load, reconfigure project directories:" + "All COOJA projects could not load.\n\n" +
"\n\tMenu->Settings->COOJA projects" + "To manage COOJA projects:\n" +
"\n\nSee console for stack trace with more information.", "Menu->Settings->COOJA projects",
"Project loading error", JOptionPane.ERROR_MESSAGE); "Reconfigure COOJA projects", JOptionPane.INFORMATION_MESSAGE);
} }
showErrorDialog(getTopParentContainer(), "COOJA projects load error", e, false);
} }
// Start all standard GUI plugins // Start all standard GUI plugins
@ -1100,7 +1093,8 @@ public class GUI extends Observable {
private static JDesktopPane createDesktopPane() { private static JDesktopPane createDesktopPane() {
final JDesktopPane desktop = new JDesktopPane() { final JDesktopPane desktop = new JDesktopPane() {
public void setBounds(int x, int y, int w, int h) { private static final long serialVersionUID = -8272040875621119329L;
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x, y, w, h); super.setBounds(x, y, w, h);
updateDesktopSize(this); updateDesktopSize(this);
} }
@ -1115,7 +1109,8 @@ public class GUI extends Observable {
} }
}; };
desktop.setDesktopManager(new DefaultDesktopManager() { desktop.setDesktopManager(new DefaultDesktopManager() {
public void endResizingFrame(JComponent f) { private static final long serialVersionUID = -5987404936292377152L;
public void endResizingFrame(JComponent f) {
super.endResizingFrame(f); super.endResizingFrame(f);
updateDesktopSize(desktop); updateDesktopSize(desktop);
} }
@ -1228,42 +1223,6 @@ public class GUI extends Observable {
return moteTypeClasses; return moteTypeClasses;
} }
/**
* Register new IP distributor class
*
* @param ipDistributorClass
* Class to register
* @return True if class was registered
*/
public boolean registerIPDistributor(
Class<? extends IPDistributor> ipDistributorClass) {
// Check that vector constructor exists
try {
ipDistributorClass.getConstructor(new Class[] { Vector.class });
} catch (Exception e) {
logger.fatal("No vector constructor found of IP distributor: "
+ ipDistributorClass);
return false;
}
ipDistributorClasses.add(ipDistributorClass);
return true;
}
/**
* Unregister all IP distributors.
*/
public void unregisterIPDistributors() {
ipDistributorClasses.clear();
}
/**
* @return All registered IP distributors
*/
public Vector<Class<? extends IPDistributor>> getRegisteredIPDistributors() {
return ipDistributorClasses;
}
/** /**
* Register new positioner class. * Register new positioner class.
* *
@ -1339,12 +1298,10 @@ public class GUI extends Observable {
/** /**
* Builds new project configuration using current project directories settings. * Builds new project configuration using current project directories settings.
* Reregisters mote types, plugins, IP distributors, positioners and radio * Reregisters mote types, plugins, positioners and radio
* mediums. This method may still return true even if all classes could not be * mediums. This method may still return true even if all classes could not be
* registered, but always returns false if all project directory configuration * registered, but always returns false if all project directory configuration
* files were not parsed correctly. * files were not parsed correctly.
*
* Any registered temporary plugins will be saved and reregistered.
*/ */
public void reparseProjectConfig() throws ParseProjectsException { public void reparseProjectConfig() throws ParseProjectsException {
if (PROJECT_DEFAULT_CONFIG_FILENAME == null) { if (PROJECT_DEFAULT_CONFIG_FILENAME == null) {
@ -1355,40 +1312,29 @@ public class GUI extends Observable {
} }
} }
// Backup temporary plugins /* Remove current dependencies */
Vector<Class<? extends Plugin>> oldTempPlugins =
(Vector<Class<? extends Plugin>>) pluginClassesTemporary.clone();
// Reset current configuration
unregisterMoteTypes(); unregisterMoteTypes();
unregisterPlugins(); unregisterPlugins();
unregisterIPDistributors();
unregisterPositioners(); unregisterPositioners();
unregisterRadioMediums(); unregisterRadioMediums();
projectDirClassLoader = null;
/* Build cooja configuration */
try { try {
// Read default configuration
projectConfig = new ProjectConfig(true); projectConfig = new ProjectConfig(true);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logger.fatal("Could not find default project config file: " logger.fatal("Could not find default project config file: " + PROJECT_DEFAULT_CONFIG_FILENAME);
+ PROJECT_DEFAULT_CONFIG_FILENAME);
throw (ParseProjectsException) new ParseProjectsException( throw (ParseProjectsException) new ParseProjectsException(
"Could not find default project config file: " "Could not find default project config file: " + PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
+ PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
} catch (IOException e) { } catch (IOException e) {
logger.fatal("Error when reading default project config file: " logger.fatal("Error when reading default project config file: " + PROJECT_DEFAULT_CONFIG_FILENAME);
+ PROJECT_DEFAULT_CONFIG_FILENAME);
throw (ParseProjectsException) new ParseProjectsException( throw (ParseProjectsException) new ParseProjectsException(
"Error when reading default project config file: " "Error when reading default project config file: " + PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
+ PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
} }
if (!isVisualizedInApplet()) { if (!isVisualizedInApplet()) {
// Append project directory configurations for (COOJAProject project: currentProjects) {
for (File projectDir : currentProjectDirs) {
try { try {
// Append config to general config projectConfig.appendProjectDir(project.dir);
projectConfig.appendProjectDir(projectDir);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw (ParseProjectsException) new ParseProjectsException( throw (ParseProjectsException) new ParseProjectsException(
"Error when loading project: " + e.getMessage()).initCause(e); "Error when loading project: " + e.getMessage()).initCause(e);
@ -1397,16 +1343,14 @@ public class GUI extends Observable {
"Error when reading project config: " + e.getMessage()).initCause(e); "Error when reading project config: " + e.getMessage()).initCause(e);
} }
} }
// Create class loader /* Create project class loader */
try { try {
projectDirClassLoader = createClassLoader(currentProjectDirs); projectDirClassLoader = createClassLoader(currentProjects);
} catch (ClassLoaderCreationException e) { } catch (ClassLoaderCreationException e) {
throw (ParseProjectsException) new ParseProjectsException( throw (ParseProjectsException) new ParseProjectsException(
"Error when creating class loader").initCause(e); "Error when creating class loader").initCause(e);
} }
} else {
projectDirClassLoader = null;
} }
// Register mote types // Register mote types
@ -1446,37 +1390,6 @@ public class GUI extends Observable {
} }
} }
// Reregister temporary plugins again
if (oldTempPlugins != null) {
for (Class<? extends Plugin> pluginClass : oldTempPlugins) {
if (registerTemporaryPlugin(pluginClass)) {
// logger.info("Reregistered temporary plugin class: " +
// getDescriptionOf(pluginClass));
} else {
logger.warn("Could not reregister temporary plugin class: "
+ getDescriptionOf(pluginClass));
}
}
}
// Register IP distributors
String[] ipDistClassNames = projectConfig.getStringArrayValue(GUI.class,
"IP_DISTRIBUTORS");
if (ipDistClassNames != null) {
for (String ipDistClassName : ipDistClassNames) {
Class<? extends IPDistributor> ipDistClass = tryLoadClass(this,
IPDistributor.class, ipDistClassName);
if (ipDistClass != null) {
registerIPDistributor(ipDistClass);
// logger.info("Loaded IP distributor class: " + ipDistClassName);
} else {
logger
.warn("Could not load IP distributor class: " + ipDistClassName);
}
}
}
// Register positioners // Register positioners
String[] positionerClassNames = projectConfig.getStringArrayValue( String[] positionerClassNames = projectConfig.getStringArrayValue(
GUI.class, "POSITIONERS"); GUI.class, "POSITIONERS");
@ -1529,8 +1442,8 @@ public class GUI extends Observable {
* *
* @return Current project directories. * @return Current project directories.
*/ */
public Vector<File> getProjectDirs() { public COOJAProject[] getProjects() {
return currentProjectDirs; return currentProjects.toArray(new COOJAProject[0]);
} }
// // PLUGIN METHODS //// // // PLUGIN METHODS ////
@ -1782,57 +1695,26 @@ public class GUI extends Observable {
return registerPlugin(newPluginClass, true); return registerPlugin(newPluginClass, true);
} }
/**
* Register a temporary plugin to be included in the GUI. The plugin will be
* visible in the menubar. This plugin will automatically be unregistered if
* the current simulation is removed.
*
* @param newPluginClass
* New plugin to register
* @return True if this plugin was registered ok, false otherwise
*/
public boolean registerTemporaryPlugin(Class<? extends Plugin> newPluginClass) {
if (pluginClasses.contains(newPluginClass)) {
return false;
}
boolean returnVal = registerPlugin(newPluginClass, true);
if (!returnVal) {
return false;
}
pluginClassesTemporary.add(newPluginClass);
return true;
}
/** /**
* Unregister a plugin class. Removes any plugin menu items links as well. * Unregister a plugin class. Removes any plugin menu items links as well.
* *
* @param pluginClass * @param pluginClass Plugin class
* Plugin class to unregister
*/ */
public void unregisterPlugin(Class<? extends Plugin> pluginClass) { public void unregisterPlugin(Class<? extends Plugin> pluginClass) {
/* Remove from menu */
// Remove (if existing) plugin class menu items
for (Component menuComponent : menuPlugins.getMenuComponents()) { for (Component menuComponent : menuPlugins.getMenuComponents()) {
if (menuComponent.getClass().isAssignableFrom(JMenuItem.class)) { if (!(menuComponent instanceof JMenuItem)) {
JMenuItem menuItem = (JMenuItem) menuComponent; continue;
if (menuItem.getClientProperty("class").equals(pluginClass)) { }
menuPlugins.remove(menuItem);
} JMenuItem menuItem = (JMenuItem) menuComponent;
if (menuItem.getClientProperty("class").equals(pluginClass)) {
menuPlugins.remove(menuItem);
} }
} }
if (menuMotePluginClasses.contains(pluginClass)) {
menuMotePluginClasses.remove(pluginClass);
}
// Remove from plugin vectors (including temporary) menuMotePluginClasses.remove(pluginClass);
if (pluginClasses.contains(pluginClass)) { pluginClasses.remove(pluginClass);
pluginClasses.remove(pluginClass);
}
if (pluginClassesTemporary.contains(pluginClass)) {
pluginClassesTemporary.remove(pluginClass);
}
} }
/** /**
@ -1954,7 +1836,7 @@ public class GUI extends Observable {
} }
/** /**
* Unregister all plugin classes, including temporary plugins. * Unregister all plugin classes
*/ */
public void unregisterPlugins() { public void unregisterPlugins() {
if (menuPlugins != null) { if (menuPlugins != null) {
@ -1968,7 +1850,6 @@ public class GUI extends Observable {
menuMotePluginClasses.clear(); menuMotePluginClasses.clear();
} }
pluginClasses.clear(); pluginClasses.clear();
pluginClassesTemporary.clear();
} }
/** /**
@ -2027,7 +1908,7 @@ public class GUI extends Observable {
// Set frame title // Set frame title
if (frame != null) { if (frame != null) {
frame.setTitle("COOJA Simulator" + " - " + sim.getTitle()); frame.setTitle(sim.getTitle() + " - COOJA Simulator");
} }
// Open standard plugins (if none opened already) // Open standard plugins (if none opened already)
@ -2150,14 +2031,6 @@ public class GUI extends Observable {
mySimulation = null; mySimulation = null;
updateGUIComponentState(); updateGUIComponentState();
// Unregister temporary plugin classes
Class<? extends Plugin>[] pluginClasses =
new Class[pluginClassesTemporary.size()];
pluginClassesTemporary.toArray(pluginClasses);
for (Class<? extends Plugin> pClass: pluginClasses) {
unregisterPlugin(pClass);
}
// Reset frame title // Reset frame title
if (isVisualizedInFrame()) { if (isVisualizedInFrame()) {
frame.setTitle("COOJA Simulator"); frame.setTitle("COOJA Simulator");
@ -2861,27 +2734,28 @@ public class GUI extends Observable {
} 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("manage projects")) { } else if (e.getActionCommand().equals("manage projects")) {
File[] newProjects = ProjectDirectoriesDialog.showDialog( COOJAProject[] newProjects = ProjectDirectoriesDialog.showDialog(
GUI.getTopParentContainer(), GUI.getTopParentContainer(),
GUI.this, GUI.this,
currentProjectDirs.toArray(new File[0]) getProjects()
); );
if (newProjects != null) { if (newProjects != null) {
currentProjectDirs.clear(); currentProjects.clear();
for (File p: newProjects) { for (COOJAProject p: newProjects) {
currentProjectDirs.add(p); currentProjects.add(p);
} }
try { try {
reparseProjectConfig(); reparseProjectConfig();
} catch (ParseProjectsException ex) { } catch (ParseProjectsException ex) {
logger.fatal("Error when loading projects: " + ex.getMessage(), ex); logger.fatal("Error when loading projects: " + ex.getMessage(), ex);
if (isVisualized()) { if (isVisualized()) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(), JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Configured projects could not load, reconfigure project directories:" + "All COOJA projects could not load.\n\n" +
"\n\tMenu->Settings->COOJA projects" + "To manage COOJA projects:\n" +
"\n\nSee console for stack trace with more information.", "Menu->Settings->COOJA projects",
"Project loading error", JOptionPane.ERROR_MESSAGE); "Reconfigure COOJA projects", JOptionPane.INFORMATION_MESSAGE);
} }
showErrorDialog(getTopParentContainer(), "COOJA projects load error", ex, false);
} }
} }
} else if (e.getActionCommand().equals("configuration wizard")) { } else if (e.getActionCommand().equals("configuration wizard")) {
@ -2934,22 +2808,12 @@ public class GUI extends Observable {
return null; return null;
} }
public ClassLoader createProjectDirClassLoader(Vector<File> projectsDirs) private ClassLoader createClassLoader(Collection<COOJAProject> projects)
throws ParseProjectsException, ClassLoaderCreationException { throws ClassLoaderCreationException {
if (projectDirClassLoader == null) { return createClassLoader(ClassLoader.getSystemClassLoader(), projects);
reparseProjectConfig();
}
return createClassLoader(projectDirClassLoader, projectsDirs);
} }
private ClassLoader createClassLoader(Vector<File> currentProjectDirs) public static File findJarFile(File projectDir, String jarfile) {
throws ClassLoaderCreationException
{
return createClassLoader(ClassLoader.getSystemClassLoader(),
currentProjectDirs);
}
private File findJarFile(File projectDir, String jarfile) {
File fp = new File(jarfile); File fp = new File(jarfile);
if (!fp.exists()) { if (!fp.exists()) {
fp = new File(projectDir, jarfile); fp = new File(projectDir, jarfile);
@ -2966,17 +2830,16 @@ public class GUI extends Observable {
return fp.exists() ? fp : null; return fp.exists() ? fp : null;
} }
private ClassLoader createClassLoader(ClassLoader parent, private ClassLoader createClassLoader(ClassLoader parent, Collection<COOJAProject> projects)
Vector<File> projectDirs) throws ClassLoaderCreationException { throws ClassLoaderCreationException {
if (projectDirs == null || projectDirs.isEmpty()) { if (projects == null || projects.isEmpty()) {
return parent; return parent;
} }
// Combine class loader from all project directories (including any /* Create class loader from JARs */
// specified JAR files)
ArrayList<URL> urls = new ArrayList<URL>(); ArrayList<URL> urls = new ArrayList<URL>();
for (int j = projectDirs.size() - 1; j >= 0; j--) { for (COOJAProject project: projects) {
File projectDir = projectDirs.get(j); File projectDir = project.dir;
try { try {
urls.add((new File(projectDir, "java")).toURI().toURL()); urls.add((new File(projectDir, "java")).toURI().toURL());
@ -3394,9 +3257,9 @@ public class GUI extends Observable {
Element root = new Element("simconf"); Element root = new Element("simconf");
/* Store project directories meta data */ /* Store project directories meta data */
for (File project: currentProjectDirs) { for (COOJAProject project: currentProjects) {
Element projectElement = new Element("project"); Element projectElement = new Element("project");
projectElement.addContent(createPortablePath(project).getPath().replaceAll("\\\\", "/")); projectElement.addContent(createPortablePath(project.dir).getPath().replaceAll("\\\\", "/"));
projectElement.setAttribute("EXPORT", "discard"); projectElement.setAttribute("EXPORT", "discard");
root.addContent(projectElement); root.addContent(projectElement);
} }
@ -3507,9 +3370,9 @@ public class GUI extends Observable {
} }
boolean found = false; boolean found = false;
for (File currentProject: currentProjectDirs) { for (COOJAProject currentProject: currentProjects) {
if (projectFile.getPath().replaceAll("\\\\", "/"). if (projectFile.getPath().replaceAll("\\\\", "/").
equals(currentProject.getPath().replaceAll("\\\\", "/"))) { equals(currentProject.dir.getPath().replaceAll("\\\\", "/"))) {
found = true; found = true;
break; break;
} }
@ -3665,25 +3528,29 @@ public class GUI extends Observable {
} }
public class ParseProjectsException extends Exception { public class ParseProjectsException extends Exception {
public ParseProjectsException(String message) { private static final long serialVersionUID = 1508168026300714850L;
public ParseProjectsException(String message) {
super(message); super(message);
} }
} }
public class ClassLoaderCreationException extends Exception { public class ClassLoaderCreationException extends Exception {
public ClassLoaderCreationException(String message) { private static final long serialVersionUID = 1578001681266277774L;
public ClassLoaderCreationException(String message) {
super(message); super(message);
} }
} }
public class SimulationCreationException extends Exception { public class SimulationCreationException extends Exception {
public SimulationCreationException(String message) { private static final long serialVersionUID = -2414899187405770448L;
public SimulationCreationException(String message) {
super(message); super(message);
} }
} }
public class PluginConstructionException extends Exception { public class PluginConstructionException extends Exception {
public PluginConstructionException(String message) { private static final long serialVersionUID = 8004171223353676751L;
public PluginConstructionException(String message) {
super(message); super(message);
} }
} }
@ -3761,7 +3628,8 @@ public class GUI extends Observable {
if (retryAvailable) { if (retryAvailable) {
Action retryAction = new AbstractAction() { Action retryAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 2370456199250998435L;
public void actionPerformed(ActionEvent e) {
errorDialog.setTitle("-RETRY-"); errorDialog.setTitle("-RETRY-");
errorDialog.dispose(); errorDialog.dispose();
} }
@ -3777,7 +3645,8 @@ public class GUI extends Observable {
} }
AbstractAction closeAction = new AbstractAction(){ AbstractAction closeAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 6225539435993362733L;
public void actionPerformed(ActionEvent e) {
errorDialog.dispose(); errorDialog.dispose();
} }
}; };
@ -3836,7 +3705,8 @@ public class GUI extends Observable {
/* Close on escape */ /* Close on escape */
AbstractAction closeAction = new AbstractAction(){ AbstractAction closeAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 2646163984382201634L;
public void actionPerformed(ActionEvent e) {
dialog.dispose(); dialog.dispose();
} }
}; };
@ -4235,7 +4105,8 @@ public class GUI extends Observable {
/* GUI actions */ /* GUI actions */
abstract class GUIAction extends AbstractAction { abstract class GUIAction extends AbstractAction {
public GUIAction(String name) { private static final long serialVersionUID = 6946179457635198477L;
public GUIAction(String name) {
super(name); super(name);
} }
public GUIAction(String name, int nmenomic) { public GUIAction(String name, int nmenomic) {
@ -4253,7 +4124,8 @@ public class GUI extends Observable {
public abstract boolean shouldBeEnabled(); public abstract boolean shouldBeEnabled();
} }
GUIAction newSimulationAction = new GUIAction("New simulation", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)) { GUIAction newSimulationAction = new GUIAction("New simulation", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 5053703908505299911L;
public void actionPerformed(ActionEvent e) {
myGUI.doCreateSimulation(true); myGUI.doCreateSimulation(true);
} }
public boolean shouldBeEnabled() { public boolean shouldBeEnabled() {
@ -4261,7 +4133,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction closeSimulationAction = new GUIAction("Close simulation", KeyEvent.VK_C) { GUIAction closeSimulationAction = new GUIAction("Close simulation", KeyEvent.VK_C) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -4783032948880161189L;
public void actionPerformed(ActionEvent e) {
myGUI.doRemoveSimulation(true); myGUI.doRemoveSimulation(true);
} }
public boolean shouldBeEnabled() { public boolean shouldBeEnabled() {
@ -4269,7 +4142,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction reloadSimulationAction = new GUIAction("keep random seed", KeyEvent.VK_K, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)) { GUIAction reloadSimulationAction = new GUIAction("keep random seed", KeyEvent.VK_K, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 66579555555421977L;
public void actionPerformed(ActionEvent e) {
if (getSimulation() == null) { if (getSimulation() == null) {
/* Reload last opened simulation */ /* Reload last opened simulation */
final File file = getLastOpenedFile(); final File file = getLastOpenedFile();
@ -4290,7 +4164,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction reloadRandomSimulationAction = new GUIAction("new random seed", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)) { GUIAction reloadRandomSimulationAction = new GUIAction("new random seed", KeyEvent.VK_N, KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -4494402222740250203L;
public void actionPerformed(ActionEvent e) {
/* Replace seed before reloading */ /* Replace seed before reloading */
if (getSimulation() != null) { if (getSimulation() != null) {
getSimulation().setRandomSeed(getSimulation().getRandomSeed()+1); getSimulation().setRandomSeed(getSimulation().getRandomSeed()+1);
@ -4302,7 +4177,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction saveSimulationAction = new GUIAction("Save simulation", KeyEvent.VK_S) { GUIAction saveSimulationAction = new GUIAction("Save simulation", KeyEvent.VK_S) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 1132582220401954286L;
public void actionPerformed(ActionEvent e) {
myGUI.doSaveConfig(true); myGUI.doSaveConfig(true);
} }
public boolean shouldBeEnabled() { public boolean shouldBeEnabled() {
@ -4313,7 +4189,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction closePluginsAction = new GUIAction("Close all plugins") { GUIAction closePluginsAction = new GUIAction("Close all plugins") {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -37575622808266989L;
public void actionPerformed(ActionEvent e) {
Object[] plugins = startedPlugins.toArray(); Object[] plugins = startedPlugins.toArray();
for (Object plugin : plugins) { for (Object plugin : plugins) {
removePlugin((Plugin) plugin, false); removePlugin((Plugin) plugin, false);
@ -4324,7 +4201,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction exportExecutableJARAction = new GUIAction("Export simulation as executable JAR") { GUIAction exportExecutableJARAction = new GUIAction("Export simulation as executable JAR") {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = -203601967460630049L;
public void actionPerformed(ActionEvent e) {
getSimulation().stopSimulation(); getSimulation().stopSimulation();
/* Info message */ /* Info message */
@ -4400,7 +4278,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction exitCoojaAction = new GUIAction("Exit", KeyEvent.VK_X, KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)) { GUIAction exitCoojaAction = new GUIAction("Exit", KeyEvent.VK_X, KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 7523822251658687665L;
public void actionPerformed(ActionEvent e) {
myGUI.doQuit(true); myGUI.doQuit(true);
} }
public boolean shouldBeEnabled() { public boolean shouldBeEnabled() {
@ -4411,7 +4290,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction startStopSimulationAction = new GUIAction("Start/Stop simulation", KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) { GUIAction startStopSimulationAction = new GUIAction("Start/Stop simulation", KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 6750107157493939710L;
public void actionPerformed(ActionEvent e) {
/* Start/Stop current simulation */ /* Start/Stop current simulation */
Simulation s = getSimulation(); Simulation s = getSimulation();
if (s == null) { if (s == null) {
@ -4438,7 +4318,8 @@ public class GUI extends Observable {
} }
}; };
class StartPluginGUIAction extends GUIAction { class StartPluginGUIAction extends GUIAction {
public StartPluginGUIAction(String name) { private static final long serialVersionUID = 7368495576372376196L;
public StartPluginGUIAction(String name) {
super(name); super(name);
} }
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
@ -4456,7 +4337,8 @@ public class GUI extends Observable {
} }
} }
GUIAction removeAllMotesAction = new GUIAction("Remove all motes") { GUIAction removeAllMotesAction = new GUIAction("Remove all motes") {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 4709776747913364419L;
public void actionPerformed(ActionEvent e) {
Simulation s = getSimulation(); Simulation s = getSimulation();
if (s.isRunning()) { if (s.isRunning()) {
s.stopSimulation(); s.stopSimulation();
@ -4472,7 +4354,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction showQuickHelpAction = new GUIAction("Quick help", KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)) { GUIAction showQuickHelpAction = new GUIAction("Quick help", KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)) {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 3151729036597971681L;
public void actionPerformed(ActionEvent e) {
if (!(e.getSource() instanceof JCheckBoxMenuItem)) { if (!(e.getSource() instanceof JCheckBoxMenuItem)) {
return; return;
} }
@ -4488,7 +4371,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction showKeyboardShortcutsAction = new GUIAction("Keyboard shortcuts") { GUIAction showKeyboardShortcutsAction = new GUIAction("Keyboard shortcuts") {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 2382848024856978524L;
public void actionPerformed(ActionEvent e) {
loadQuickHelp("KEYBOARD_SHORTCUTS"); loadQuickHelp("KEYBOARD_SHORTCUTS");
JCheckBoxMenuItem checkBox = ((JCheckBoxMenuItem)showQuickHelpAction.getValue("checkbox")); JCheckBoxMenuItem checkBox = ((JCheckBoxMenuItem)showQuickHelpAction.getValue("checkbox"));
if (checkBox == null) { if (checkBox == null) {
@ -4505,7 +4389,8 @@ public class GUI extends Observable {
} }
}; };
GUIAction showBufferSettingsAction = new GUIAction("Buffer sizes") { GUIAction showBufferSettingsAction = new GUIAction("Buffer sizes") {
public void actionPerformed(ActionEvent e) { private static final long serialVersionUID = 7018661735211901837L;
public void actionPerformed(ActionEvent e) {
if (mySimulation == null) { if (mySimulation == null) {
return; return;
} }