added access control when applet
This commit is contained in:
parent
d74fd06536
commit
3675479274
4 changed files with 195 additions and 103 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.70 2008/02/12 15:31:22 fros4943 Exp $
|
* $Id: GUI.java,v 1.71 2008/02/18 08:18:01 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -36,6 +36,7 @@ import java.beans.PropertyVetoException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.security.AccessControlException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -88,8 +89,7 @@ public class GUI {
|
||||||
* External tools user settings filename.
|
* External tools user settings filename.
|
||||||
*/
|
*/
|
||||||
public static final String EXTERNAL_TOOLS_USER_SETTINGS_FILENAME = ".cooja.user.properties";
|
public static final String EXTERNAL_TOOLS_USER_SETTINGS_FILENAME = ".cooja.user.properties";
|
||||||
public static File externalToolsUserSettingsFile =
|
public static File externalToolsUserSettingsFile;
|
||||||
new File(System.getProperty("user.home"), EXTERNAL_TOOLS_USER_SETTINGS_FILENAME);
|
|
||||||
private static boolean externalToolsUserSettingsFileReadOnly = false;
|
private static boolean externalToolsUserSettingsFileReadOnly = false;
|
||||||
|
|
||||||
private static String specifiedContikiPath = null;
|
private static String specifiedContikiPath = null;
|
||||||
|
@ -102,7 +102,7 @@ public class GUI {
|
||||||
/**
|
/**
|
||||||
* Default project configuration filename.
|
* Default project configuration filename.
|
||||||
*/
|
*/
|
||||||
public static final String PROJECT_DEFAULT_CONFIG_FILENAME = "/cooja_default.config";
|
public static String PROJECT_DEFAULT_CONFIG_FILENAME = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User project configuration filename.
|
* User project configuration filename.
|
||||||
|
@ -258,27 +258,29 @@ public class GUI {
|
||||||
String defaultProjectDirs = getExternalToolsSetting(
|
String defaultProjectDirs = getExternalToolsSetting(
|
||||||
"DEFAULT_PROJECTDIRS", null);
|
"DEFAULT_PROJECTDIRS", null);
|
||||||
if (defaultProjectDirs != null) {
|
if (defaultProjectDirs != null) {
|
||||||
String[] defaultProjectDirsArr = defaultProjectDirs.split(";");
|
if (!isVisualizedInApplet()) {
|
||||||
if (defaultProjectDirsArr.length > 0) {
|
String[] defaultProjectDirsArr = defaultProjectDirs.split(";");
|
||||||
for (String defaultProjectDir : defaultProjectDirsArr) {
|
if (defaultProjectDirsArr.length > 0) {
|
||||||
File projectDir = new File(defaultProjectDir);
|
for (String defaultProjectDir : defaultProjectDirsArr) {
|
||||||
if (projectDir.exists() && projectDir.isDirectory()) {
|
File projectDir = new File(defaultProjectDir);
|
||||||
currentProjectDirs.add(projectDir);
|
if (projectDir.exists() && projectDir.isDirectory()) {
|
||||||
|
currentProjectDirs.add(projectDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Load extendable parts (using current project config)
|
// Load extendable parts (using current project config)
|
||||||
try {
|
try {
|
||||||
reparseProjectConfig();
|
reparseProjectConfig();
|
||||||
} catch (ParseProjectsException e) {
|
} catch (ParseProjectsException e) {
|
||||||
logger.fatal("Error when loading project directories: " + e.getMessage());
|
logger.fatal("Error when loading project directories: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (myDesktopPane != null) {
|
if (myDesktopPane != null) {
|
||||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
"Loading project directories failed.\nStack trace printed to console.",
|
"Loading project directories failed.\nStack trace printed to console.",
|
||||||
"Error", JOptionPane.ERROR_MESSAGE);
|
"Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +425,10 @@ public class GUI {
|
||||||
private void updateOpenHistoryMenuItems() {
|
private void updateOpenHistoryMenuItems() {
|
||||||
menuConfOpenSimulation.removeAll();
|
menuConfOpenSimulation.removeAll();
|
||||||
|
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
JMenuItem browseItem = new JMenuItem("Browse...");
|
JMenuItem browseItem = new JMenuItem("Browse...");
|
||||||
browseItem.setActionCommand("confopen sim");
|
browseItem.setActionCommand("confopen sim");
|
||||||
browseItem.addActionListener(guiEventHandler);
|
browseItem.addActionListener(guiEventHandler);
|
||||||
|
@ -502,16 +508,28 @@ public class GUI {
|
||||||
menuOpenSimulation = new JMenu("Open simulation");
|
menuOpenSimulation = new JMenu("Open simulation");
|
||||||
menuOpenSimulation.setMnemonic(KeyEvent.VK_O);
|
menuOpenSimulation.setMnemonic(KeyEvent.VK_O);
|
||||||
menu.add(menuOpenSimulation);
|
menu.add(menuOpenSimulation);
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
menuOpenSimulation.setEnabled(false);
|
||||||
|
menuOpenSimulation.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
menuConfOpenSimulation = new JMenu("Open & Reconfigure simulation");
|
menuConfOpenSimulation = new JMenu("Open & Reconfigure simulation");
|
||||||
menuConfOpenSimulation.setMnemonic(KeyEvent.VK_R);
|
menuConfOpenSimulation.setMnemonic(KeyEvent.VK_R);
|
||||||
menu.add(menuConfOpenSimulation);
|
menu.add(menuConfOpenSimulation);
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
menuConfOpenSimulation.setEnabled(false);
|
||||||
|
menuConfOpenSimulation.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
menuItem = new JMenuItem("Save simulation");
|
menuItem = new JMenuItem("Save simulation");
|
||||||
menuItem.setMnemonic(KeyEvent.VK_S);
|
menuItem.setMnemonic(KeyEvent.VK_S);
|
||||||
menuItem.setActionCommand("save sim");
|
menuItem.setActionCommand("save sim");
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
menuItem.setEnabled(false);
|
||||||
|
menuItem.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
|
@ -529,6 +547,10 @@ public class GUI {
|
||||||
menuItem.setActionCommand("quit");
|
menuItem.setActionCommand("quit");
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
menu.add(menuItem);
|
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");
|
||||||
|
@ -596,6 +618,10 @@ public class GUI {
|
||||||
menuItem.putClientProperty("class", moteTypeClass);
|
menuItem.putClientProperty("class", moteTypeClass);
|
||||||
menuItem.setToolTipText(abstractionLevelDescription);
|
menuItem.setToolTipText(abstractionLevelDescription);
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
|
if (isVisualizedInApplet() && moteTypeClass.equals(ContikiMoteType.class)) {
|
||||||
|
menuItem.setEnabled(false);
|
||||||
|
menuItem.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
/* Add new item directly after cross level separator */
|
/* Add new item directly after cross level separator */
|
||||||
for (int i=0; i < menuMoteTypeClasses.getMenuComponentCount(); i++) {
|
for (int i=0; i < menuMoteTypeClasses.getMenuComponentCount(); i++) {
|
||||||
|
@ -683,11 +709,19 @@ public class GUI {
|
||||||
menuItem.setActionCommand("edit paths");
|
menuItem.setActionCommand("edit paths");
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
menuItem.setEnabled(false);
|
||||||
|
menuItem.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
menuItem = new JMenuItem("Manage project directories");
|
menuItem = new JMenuItem("Manage project directories");
|
||||||
menuItem.setActionCommand("manage projects");
|
menuItem.setActionCommand("manage projects");
|
||||||
menuItem.addActionListener(guiEventHandler);
|
menuItem.addActionListener(guiEventHandler);
|
||||||
menu.add(menuItem);
|
menu.add(menuItem);
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
menuItem.setEnabled(false);
|
||||||
|
menuItem.setToolTipText("Not available in applet version");
|
||||||
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
|
@ -1384,6 +1418,14 @@ public class GUI {
|
||||||
* Any registered temporary plugins will be saved and reregistered.
|
* 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 (isVisualizedInApplet()) {
|
||||||
|
PROJECT_DEFAULT_CONFIG_FILENAME = "/cooja_applet.config";
|
||||||
|
} else {
|
||||||
|
PROJECT_DEFAULT_CONFIG_FILENAME = "/cooja_default.config";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Backup temporary plugins
|
// Backup temporary plugins
|
||||||
Vector<Class<? extends Plugin>> oldTempPlugins = (Vector<Class<? extends Plugin>>) pluginClassesTemporary
|
Vector<Class<? extends Plugin>> oldTempPlugins = (Vector<Class<? extends Plugin>>) pluginClassesTemporary
|
||||||
.clone();
|
.clone();
|
||||||
|
@ -1412,32 +1454,34 @@ public class GUI {
|
||||||
+ PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
|
+ PROJECT_DEFAULT_CONFIG_FILENAME).initCause(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append project directory configurations
|
if (!isVisualizedInApplet()) {
|
||||||
for (File projectDir : currentProjectDirs) {
|
// Append project directory configurations
|
||||||
|
for (File projectDir : currentProjectDirs) {
|
||||||
try {
|
try {
|
||||||
// Append config to general config
|
// Append config to general config
|
||||||
projectConfig.appendProjectDir(projectDir);
|
projectConfig.appendProjectDir(projectDir);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.fatal("Could not find project config file: " + projectDir);
|
logger.fatal("Could not find project config file: " + projectDir);
|
||||||
throw (ParseProjectsException) new ParseProjectsException(
|
throw (ParseProjectsException) new ParseProjectsException(
|
||||||
"Could not find project config file: " + projectDir).initCause(e);
|
"Could not find project config file: " + projectDir).initCause(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("Error when reading project config file: " + projectDir);
|
logger.fatal("Error when reading project config file: " + projectDir);
|
||||||
throw (ParseProjectsException) new ParseProjectsException(
|
throw (ParseProjectsException) new ParseProjectsException(
|
||||||
"Error when reading project config file: " + projectDir).initCause(e);
|
"Error when reading project config file: " + projectDir).initCause(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Create class loader
|
// Create class loader
|
||||||
try {
|
try {
|
||||||
projectDirClassLoader = createClassLoader(currentProjectDirs);
|
projectDirClassLoader = createClassLoader(currentProjectDirs);
|
||||||
} 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
|
||||||
String[] moteTypeClassNames = projectConfig.getStringArrayValue(GUI.class,
|
String[] moteTypeClassNames = projectConfig.getStringArrayValue(GUI.class,
|
||||||
"MOTETYPES");
|
"MOTETYPES");
|
||||||
|
@ -1527,6 +1571,9 @@ public class GUI {
|
||||||
// Register radio mediums
|
// Register radio mediums
|
||||||
String[] radioMediumsClassNames = projectConfig.getStringArrayValue(
|
String[] radioMediumsClassNames = projectConfig.getStringArrayValue(
|
||||||
GUI.class, "RADIOMEDIUMS");
|
GUI.class, "RADIOMEDIUMS");
|
||||||
|
for (String s: radioMediumsClassNames) {
|
||||||
|
System.out.println(">>>: " + s);
|
||||||
|
}
|
||||||
if (radioMediumsClassNames != null) {
|
if (radioMediumsClassNames != null) {
|
||||||
for (String radioMediumClassName : radioMediumsClassNames) {
|
for (String radioMediumClassName : radioMediumsClassNames) {
|
||||||
Class<? extends RadioMedium> radioMediumClass = tryLoadClass(this,
|
Class<? extends RadioMedium> radioMediumClass = tryLoadClass(this,
|
||||||
|
@ -2020,6 +2067,9 @@ public class GUI {
|
||||||
* @param configFile Configuration file to load, if null a dialog will appear
|
* @param configFile Configuration file to load, if null a dialog will appear
|
||||||
*/
|
*/
|
||||||
public void doLoadConfig(boolean askForConfirmation, final boolean quick, File configFile) {
|
public void doLoadConfig(boolean askForConfirmation, final boolean quick, File configFile) {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (CoreComm.hasLibraryBeenLoaded()) {
|
if (CoreComm.hasLibraryBeenLoaded()) {
|
||||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
|
@ -2315,6 +2365,10 @@ public class GUI {
|
||||||
* Ask for confirmation before overwriting file
|
* Ask for confirmation before overwriting file
|
||||||
*/
|
*/
|
||||||
public void doSaveConfig(boolean askForConfirmation) {
|
public void doSaveConfig(boolean askForConfirmation) {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mySimulation != null) {
|
if (mySimulation != null) {
|
||||||
mySimulation.stopSimulation();
|
mySimulation.stopSimulation();
|
||||||
|
|
||||||
|
@ -2423,6 +2477,10 @@ public class GUI {
|
||||||
* Should we ask for confirmation before quitting?
|
* Should we ask for confirmation before quitting?
|
||||||
*/
|
*/
|
||||||
public void doQuit(boolean askForConfirmation) {
|
public void doQuit(boolean askForConfirmation) {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (askForConfirmation) {
|
if (askForConfirmation) {
|
||||||
String s1 = "Quit";
|
String s1 = "Quit";
|
||||||
String s2 = "Cancel";
|
String s2 = "Cancel";
|
||||||
|
@ -2557,6 +2615,10 @@ public class GUI {
|
||||||
* Load user values from external properties file
|
* Load user values from external properties file
|
||||||
*/
|
*/
|
||||||
public static void loadExternalToolsUserSettings() {
|
public static void loadExternalToolsUserSettings() {
|
||||||
|
if (externalToolsUserSettingsFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileInputStream in = new FileInputStream(externalToolsUserSettingsFile);
|
FileInputStream in = new FileInputStream(externalToolsUserSettingsFile);
|
||||||
Properties settings = new Properties();
|
Properties settings = new Properties();
|
||||||
|
@ -2581,6 +2643,10 @@ public class GUI {
|
||||||
* Save external tools user settings to file.
|
* Save external tools user settings to file.
|
||||||
*/
|
*/
|
||||||
public static void saveExternalToolsUserSettings() {
|
public static void saveExternalToolsUserSettings() {
|
||||||
|
if (isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (externalToolsUserSettingsFileReadOnly) {
|
if (externalToolsUserSettingsFileReadOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2739,14 +2805,16 @@ public class GUI {
|
||||||
} catch (UnsupportedClassVersionError e) {
|
} catch (UnsupportedClassVersionError e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!isVisualizedInApplet()) {
|
||||||
if (projectDirClassLoader != null) {
|
try {
|
||||||
return projectDirClassLoader.loadClass(className).asSubclass(
|
if (projectDirClassLoader != null) {
|
||||||
classType);
|
return projectDirClassLoader.loadClass(className).asSubclass(
|
||||||
|
classType);
|
||||||
|
}
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
} catch (UnsupportedClassVersionError e) {
|
||||||
}
|
}
|
||||||
} catch (NoClassDefFoundError e) {
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
} catch (UnsupportedClassVersionError e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -2877,6 +2945,7 @@ public class GUI {
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
// Configure logger
|
// Configure logger
|
||||||
if ((new File(LOG_CONFIG_FILE)).exists()) {
|
if ((new File(LOG_CONFIG_FILE)).exists()) {
|
||||||
DOMConfigurator.configure(LOG_CONFIG_FILE);
|
DOMConfigurator.configure(LOG_CONFIG_FILE);
|
||||||
|
@ -2885,6 +2954,11 @@ public class GUI {
|
||||||
DOMConfigurator.configure(GUI.class.getResource("/" + LOG_CONFIG_FILE));
|
DOMConfigurator.configure(GUI.class.getResource("/" + LOG_CONFIG_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
externalToolsUserSettingsFile = new File(System.getProperty("user.home"), EXTERNAL_TOOLS_USER_SETTINGS_FILENAME);
|
||||||
|
} catch (AccessControlException e) {
|
||||||
|
externalToolsUserSettingsFile = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse general command arguments
|
// Parse general command arguments
|
||||||
for (String element : args) {
|
for (String element : args) {
|
||||||
if (element.startsWith("-contiki=")) {
|
if (element.startsWith("-contiki=")) {
|
||||||
|
@ -3013,6 +3087,7 @@ public class GUI {
|
||||||
public void run() {
|
public void run() {
|
||||||
JDesktopPane desktop = new JDesktopPane();
|
JDesktopPane desktop = new JDesktopPane();
|
||||||
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
||||||
|
applet = CoojaApplet.applet;
|
||||||
GUI gui = new GUI(desktop);
|
GUI gui = new GUI(desktop);
|
||||||
configureApplet(gui, false);
|
configureApplet(gui, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ProjectConfig.java,v 1.1 2007/03/23 23:34:33 fros4943 Exp $
|
* $Id: ProjectConfig.java,v 1.2 2008/02/18 08:18:18 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -38,49 +38,49 @@ import org.apache.log4j.Logger;
|
||||||
/**
|
/**
|
||||||
* A project configuration may hold the configuration for one or several project
|
* A project configuration may hold the configuration for one or several project
|
||||||
* directories as well as a general simulator configuration.
|
* directories as well as a general simulator configuration.
|
||||||
*
|
*
|
||||||
* The configuration for a project directory may for example consist of which
|
* The configuration for a project directory may for example consist of which
|
||||||
* plugins, interfaces and processes that the specific project directory supplies.
|
* plugins, interfaces and processes that the specific project directory supplies.
|
||||||
* Each project directory configuration is read from the property file cooja.config, a
|
* Each project directory configuration is read from the property file cooja.config, a
|
||||||
* file which is required in each project directory.
|
* file which is required in each project directory.
|
||||||
*
|
*
|
||||||
* Values can be fetched as String, Boolean, Integer, Double or String array.
|
* Values can be fetched as String, Boolean, Integer, Double or String array.
|
||||||
*
|
*
|
||||||
* Several configurations can be merged, together forming a final overall
|
* Several configurations can be merged, together forming a final overall
|
||||||
* configuration. The order of the how configurations are merged matter - later
|
* configuration. The order of the how configurations are merged matter - later
|
||||||
* values will overwrite earlier. For example merging two configurations with
|
* values will overwrite earlier. For example merging two configurations with
|
||||||
* the key 'SOMEKEY' in the following order:
|
* the key 'SOMEKEY' in the following order:
|
||||||
*
|
*
|
||||||
* SOMEKEY = a b c
|
* SOMEKEY = a b c
|
||||||
*
|
*
|
||||||
* SOMEKEY = d e
|
* SOMEKEY = d e
|
||||||
*
|
*
|
||||||
* will result in the final value "d e".
|
* will result in the final value "d e".
|
||||||
*
|
*
|
||||||
* If a specific value should be extended instead of overwritten, the value must
|
* If a specific value should be extended instead of overwritten, the value must
|
||||||
* start with a single space-surrounded '+'. For example, merging two
|
* start with a single space-surrounded '+'. For example, merging two
|
||||||
* configurations with the key as above in the following order:
|
* configurations with the key as above in the following order:
|
||||||
*
|
*
|
||||||
* SOMEKEY = a b c
|
* SOMEKEY = a b c
|
||||||
*
|
*
|
||||||
* SOMEKEY = + d e
|
* SOMEKEY = + d e
|
||||||
*
|
*
|
||||||
* will result in the final value "a b c d e".
|
* will result in the final value "a b c d e".
|
||||||
*
|
*
|
||||||
* The simulator will hold a merged project configuration, depending on which
|
* The simulator will hold a merged project configuration, depending on which
|
||||||
* project directories are used. Additionally. each mote type may also have a
|
* project directories are used. Additionally. each mote type may also have a
|
||||||
* configuration of its own, that differs from the general simulator
|
* configuration of its own, that differs from the general simulator
|
||||||
* configuration.
|
* configuration.
|
||||||
*
|
*
|
||||||
* Often, but not necessarily, keys are named depending on which class is
|
* Often, but not necessarily, keys are named depending on which class is
|
||||||
* associated with the information. For example, let's say a battery interface
|
* associated with the information. For example, let's say a battery interface
|
||||||
* wants to store its initial capacity (a double) using this approach. Data
|
* wants to store its initial capacity (a double) using this approach. Data
|
||||||
* stored in the external configuration file can look like the following:
|
* stored in the external configuration file can look like the following:
|
||||||
* se.sics.cooja.interfaces.Battery.initial_capacity 54.123321
|
* se.sics.cooja.interfaces.Battery.initial_capacity 54.123321
|
||||||
*
|
*
|
||||||
* This value is then be read by: myMoteTypeConfig.getDoubleValue(Battery.class,
|
* This value is then be read by: myMoteTypeConfig.getDoubleValue(Battery.class,
|
||||||
* "initial_capacity");
|
* "initial_capacity");
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
public class ProjectConfig {
|
public class ProjectConfig {
|
||||||
|
@ -91,7 +91,7 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new project configuration.
|
* Creates new project configuration.
|
||||||
*
|
*
|
||||||
* @param useDefault
|
* @param useDefault
|
||||||
* If true the default configuration will be loaded
|
* If true the default configuration will be loaded
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
|
@ -105,6 +105,7 @@ public class ProjectConfig {
|
||||||
myConfig = new Properties();
|
myConfig = new Properties();
|
||||||
myProjectDirHistory = new Vector<File>();
|
myProjectDirHistory = new Vector<File>();
|
||||||
|
|
||||||
|
|
||||||
if (useDefault) {
|
if (useDefault) {
|
||||||
InputStream input = GUI.class
|
InputStream input = GUI.class
|
||||||
.getResourceAsStream(GUI.PROJECT_DEFAULT_CONFIG_FILENAME);
|
.getResourceAsStream(GUI.PROJECT_DEFAULT_CONFIG_FILENAME);
|
||||||
|
@ -123,7 +124,7 @@ public class ProjectConfig {
|
||||||
/**
|
/**
|
||||||
* Appends the given project directory's config file. This method also saves a
|
* Appends the given project directory's config file. This method also saves a
|
||||||
* local history of which project directories has been loaded.
|
* local history of which project directories has been loaded.
|
||||||
*
|
*
|
||||||
* @param projectDir
|
* @param projectDir
|
||||||
* Project directory
|
* Project directory
|
||||||
* @return True if loaded OK
|
* @return True if loaded OK
|
||||||
|
@ -147,7 +148,7 @@ public class ProjectConfig {
|
||||||
* element is non-null, then the project directory that added this element will be
|
* element is non-null, then the project directory that added this element will be
|
||||||
* returned instead. If no such project directory can be found null is returned
|
* returned instead. If no such project directory can be found null is returned
|
||||||
* instead.
|
* instead.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belong to
|
* Class which value belong to
|
||||||
* @param key
|
* @param key
|
||||||
|
@ -162,14 +163,15 @@ public class ProjectConfig {
|
||||||
if (getStringValue(callingClass, key, null) == null) {
|
if (getStringValue(callingClass, key, null) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that element really exists, if any
|
// Check that element really exists, if any
|
||||||
if (arrayElement != null) {
|
if (arrayElement != null) {
|
||||||
String[] array = getStringArrayValue(callingClass, key);
|
String[] array = getStringArrayValue(callingClass, key);
|
||||||
boolean foundValue = false;
|
boolean foundValue = false;
|
||||||
for (int c=0; c < array.length; c++) {
|
for (String element : array) {
|
||||||
if (array[c].equals(arrayElement))
|
if (element.equals(arrayElement)) {
|
||||||
foundValue = true;
|
foundValue = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!foundValue) {
|
if (!foundValue) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -179,16 +181,17 @@ public class ProjectConfig {
|
||||||
// Search in all project directory in reversed order
|
// Search in all project directory in reversed order
|
||||||
try {
|
try {
|
||||||
ProjectConfig remadeConfig = new ProjectConfig(false);
|
ProjectConfig remadeConfig = new ProjectConfig(false);
|
||||||
|
|
||||||
for (int i=myProjectDirHistory.size()-1; i >= 0; i--) {
|
for (int i=myProjectDirHistory.size()-1; i >= 0; i--) {
|
||||||
remadeConfig.appendProjectDir(myProjectDirHistory.get(i));
|
remadeConfig.appendProjectDir(myProjectDirHistory.get(i));
|
||||||
|
|
||||||
if (arrayElement != null) {
|
if (arrayElement != null) {
|
||||||
// Look for array
|
// Look for array
|
||||||
String[] array = remadeConfig.getStringArrayValue(callingClass, key);
|
String[] array = remadeConfig.getStringArrayValue(callingClass, key);
|
||||||
for (int c=0; c < array.length; c++) {
|
for (String element : array) {
|
||||||
if (array[c].equals(arrayElement))
|
if (element.equals(arrayElement)) {
|
||||||
return myProjectDirHistory.get(i);
|
return myProjectDirHistory.get(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Look for key
|
// Look for key
|
||||||
|
@ -197,12 +200,12 @@ public class ProjectConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.fatal("Exception when searching in project directory history: " + e);
|
logger.fatal("Exception when searching in project directory history: " + e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +213,10 @@ public class ProjectConfig {
|
||||||
* Loads the given property file and appends it to the current configuration.
|
* Loads the given property file and appends it to the current configuration.
|
||||||
* If a property already exists it will be overwritten, unless the new value
|
* If a property already exists it will be overwritten, unless the new value
|
||||||
* begins with a '+' in which case the old value will be extended.
|
* begins with a '+' in which case the old value will be extended.
|
||||||
*
|
*
|
||||||
* WARNING! The project directory history will not be saved if this method is
|
* WARNING! The project directory history will not be saved if this method is
|
||||||
* called, instead the appendUserPlatform method should be used.
|
* called, instead the appendUserPlatform method should be used.
|
||||||
*
|
*
|
||||||
* @param propertyFile
|
* @param propertyFile
|
||||||
* Property file to read
|
* Property file to read
|
||||||
* @return True if file was read ok, false otherwise
|
* @return True if file was read ok, false otherwise
|
||||||
|
@ -233,10 +236,10 @@ public class ProjectConfig {
|
||||||
* configuration. If a property already exists it will be overwritten, unless
|
* configuration. If a property already exists it will be overwritten, unless
|
||||||
* the new value begins with a '+' in which case the old value will be
|
* the new value begins with a '+' in which case the old value will be
|
||||||
* extended.
|
* extended.
|
||||||
*
|
*
|
||||||
* WARNING! The project directory history will not be saved if this method is
|
* WARNING! The project directory history will not be saved if this method is
|
||||||
* called, instead the appendUserPlatform method should be used.
|
* called, instead the appendUserPlatform method should be used.
|
||||||
*
|
*
|
||||||
* @param configFileStream
|
* @param configFileStream
|
||||||
* Stream to read from
|
* Stream to read from
|
||||||
* @return True if stream was read ok, false otherwise
|
* @return True if stream was read ok, false otherwise
|
||||||
|
@ -262,13 +265,15 @@ public class ProjectConfig {
|
||||||
String key = (String) en.nextElement();
|
String key = (String) en.nextElement();
|
||||||
String property = newProps.getProperty(key);
|
String property = newProps.getProperty(key);
|
||||||
if (property.startsWith("+ ")) {
|
if (property.startsWith("+ ")) {
|
||||||
if (currentValues.getProperty(key) != null)
|
if (currentValues.getProperty(key) != null) {
|
||||||
currentValues.setProperty(key, currentValues.getProperty(key) + " "
|
currentValues.setProperty(key, currentValues.getProperty(key) + " "
|
||||||
+ property.substring(1).trim());
|
+ property.substring(1).trim());
|
||||||
else
|
} else {
|
||||||
currentValues.setProperty(key, property.substring(1).trim());
|
currentValues.setProperty(key, property.substring(1).trim());
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
currentValues.setProperty(key, property);
|
currentValues.setProperty(key, property);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -283,7 +288,7 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string value with given id.
|
* Get string value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -312,21 +317,22 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns value of given name.
|
* Returns value of given name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* Name
|
* Name
|
||||||
* @return Value as string
|
* @return Value as string
|
||||||
*/
|
*/
|
||||||
public String getStringValue(String name) {
|
public String getStringValue(String name) {
|
||||||
if (!myConfig.containsKey(name))
|
if (!myConfig.containsKey(name)) {
|
||||||
logger.debug("Could not find key named '" + name + "'");
|
logger.debug("Could not find key named '" + name + "'");
|
||||||
|
}
|
||||||
|
|
||||||
return myConfig.getProperty(name);
|
return myConfig.getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string value with given id.
|
* Get string value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -339,7 +345,7 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string array value with given id.
|
* Get string array value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -348,15 +354,16 @@ public class ProjectConfig {
|
||||||
*/
|
*/
|
||||||
public String[] getStringArrayValue(Class callingClass, String id) {
|
public String[] getStringArrayValue(Class callingClass, String id) {
|
||||||
String stringVal = getStringValue(callingClass, id, null);
|
String stringVal = getStringValue(callingClass, id, null);
|
||||||
if (stringVal == null)
|
if (stringVal == null) {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
return getStringValue(callingClass, id, "").split(" ");
|
return getStringValue(callingClass, id, "").split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string value with given id.
|
* Get string value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -369,22 +376,23 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get string array value with given id.
|
* Get string array value with given id.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* Id of value to return
|
* Id of value to return
|
||||||
* @return Value or null if id wasn't found
|
* @return Value or null if id wasn't found
|
||||||
*/
|
*/
|
||||||
public String[] getStringArrayValue(String id) {
|
public String[] getStringArrayValue(String id) {
|
||||||
String stringVal = getStringValue(id);
|
String stringVal = getStringValue(id);
|
||||||
if (stringVal == null)
|
if (stringVal == null) {
|
||||||
return new String[0];
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
return getStringValue(id).split(" ");
|
return getStringValue(id).split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get integer value with given id.
|
* Get integer value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -395,15 +403,16 @@ public class ProjectConfig {
|
||||||
*/
|
*/
|
||||||
public int getIntegerValue(Class callingClass, String id, int defaultValue) {
|
public int getIntegerValue(Class callingClass, String id, int defaultValue) {
|
||||||
String str = getStringValue(callingClass, id);
|
String str = getStringValue(callingClass, id);
|
||||||
if (str == null)
|
if (str == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
return Integer.parseInt(str);
|
return Integer.parseInt(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get integer value with given id.
|
* Get integer value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -416,7 +425,7 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get double value with given id.
|
* Get double value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -428,15 +437,16 @@ public class ProjectConfig {
|
||||||
public double getDoubleValue(Class callingClass, String id,
|
public double getDoubleValue(Class callingClass, String id,
|
||||||
double defaultValue) {
|
double defaultValue) {
|
||||||
String str = getStringValue(callingClass, id);
|
String str = getStringValue(callingClass, id);
|
||||||
if (str == null)
|
if (str == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
return Double.parseDouble(str);
|
return Double.parseDouble(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get double value with given id.
|
* Get double value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -449,7 +459,7 @@ public class ProjectConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get boolean value with given id.
|
* Get boolean value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -461,15 +471,16 @@ public class ProjectConfig {
|
||||||
public boolean getBooleanValue(Class callingClass, String id,
|
public boolean getBooleanValue(Class callingClass, String id,
|
||||||
boolean defaultValue) {
|
boolean defaultValue) {
|
||||||
String str = getStringValue(callingClass, id);
|
String str = getStringValue(callingClass, id);
|
||||||
if (str == null)
|
if (str == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
return Boolean.parseBoolean(str);
|
return Boolean.parseBoolean(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get boolean value with given id.
|
* Get boolean value with given id.
|
||||||
*
|
*
|
||||||
* @param callingClass
|
* @param callingClass
|
||||||
* Class which value belongs to
|
* Class which value belongs to
|
||||||
* @param id
|
* @param id
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ExternalToolsDialog.java,v 1.9 2008/02/12 15:25:41 fros4943 Exp $
|
* $Id: ExternalToolsDialog.java,v 1.10 2008/02/18 08:18:18 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
|
@ -65,6 +65,9 @@ public class ExternalToolsDialog extends JDialog {
|
||||||
* Parent container for dialog
|
* Parent container for dialog
|
||||||
*/
|
*/
|
||||||
public static void showDialog(Container parentContainer) {
|
public static void showDialog(Container parentContainer) {
|
||||||
|
if (GUI.isVisualizedInApplet()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ExternalToolsDialog myDialog = null;
|
ExternalToolsDialog myDialog = null;
|
||||||
if (parentContainer instanceof Window) {
|
if (parentContainer instanceof Window) {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ProjectDirectoriesDialog.java,v 1.5 2008/02/12 15:06:09 fros4943 Exp $
|
* $Id: ProjectDirectoriesDialog.java,v 1.6 2008/02/18 08:18:18 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
|
@ -81,6 +81,9 @@ public class ProjectDirectoriesDialog extends JDialog {
|
||||||
*/
|
*/
|
||||||
public static Vector<File> showDialog(Container parentContainer,
|
public static Vector<File> showDialog(Container parentContainer,
|
||||||
Vector<File> changableProjects, Vector<File> fixedProjects) {
|
Vector<File> changableProjects, Vector<File> fixedProjects) {
|
||||||
|
if (GUI.isVisualizedInApplet()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProjectDirectoriesDialog myDialog = null;
|
ProjectDirectoriesDialog myDialog = null;
|
||||||
if (parentContainer instanceof Window) {
|
if (parentContainer instanceof Window) {
|
||||||
|
|
Loading…
Reference in a new issue