removed public static JFrame frame variable. components should instead access the top parent container via getTopParentContainer()

This commit is contained in:
fros4943 2008-02-12 15:03:02 +00:00
parent 27ac84d009
commit 6c8151b449
16 changed files with 399 additions and 230 deletions

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* Institute nor the names of its contributors may be used to endorse or promote * Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written * products derived from this software without specific prior written
* permission. * permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -23,8 +23,8 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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: CoreComm.java,v 1.10 2007/05/11 10:15:42 fros4943 Exp $ * $Id: CoreComm.java,v 1.11 2008/02/12 15:03:02 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -52,7 +52,7 @@ import se.sics.cooja.dialogs.MessageList;
* that even if a mote type is deleted, a new one cannot be created using the * that even if a mote type is deleted, a new one cannot be created using the
* same corecomm class without restarting the JVM and thus the entire * same corecomm class without restarting the JVM and thus the entire
* simulation. * simulation.
* *
* Each implemented CoreComm class needs read access to the following core * Each implemented CoreComm class needs read access to the following core
* variables: * variables:
* <ul> * <ul>
@ -65,7 +65,7 @@ import se.sics.cooja.dialogs.MessageList;
* <li>getReferenceAbsAddr() * <li>getReferenceAbsAddr()
* <li>getMemory(int start, int length, byte[] mem) * <li>getMemory(int start, int length, byte[] mem)
* <li>setMemory(int start, int length, byte[] mem) * <li>setMemory(int start, int length, byte[] mem)
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public abstract class CoreComm { public abstract class CoreComm {
@ -80,7 +80,7 @@ public abstract class CoreComm {
/** /**
* Has any library been loaded? Since libraries can't be unloaded the entire * Has any library been loaded? Since libraries can't be unloaded the entire
* simulator may have to be restarted. * simulator may have to be restarted.
* *
* @return True if any library has been loaded this session * @return True if any library has been loaded this session
*/ */
public static boolean hasLibraryBeenLoaded() { public static boolean hasLibraryBeenLoaded() {
@ -92,24 +92,26 @@ public abstract class CoreComm {
* library can be removed, but not unloaded during one session. And a new * library can be removed, but not unloaded during one session. And a new
* library file, named the same as an earlier loaded and removed file, can't * library file, named the same as an earlier loaded and removed file, can't
* be loaded either. * be loaded either.
* *
* @param libraryFile * @param libraryFile
* Library file * Library file
* @return True if a library has already been loaded from the given file's * @return True if a library has already been loaded from the given file's
* filename * filename
*/ */
public static boolean hasLibraryFileBeenLoaded(File libraryFile) { public static boolean hasLibraryFileBeenLoaded(File libraryFile) {
for (File loadedFile : coreCommFiles) for (File loadedFile : coreCommFiles) {
if (loadedFile != null if (loadedFile != null
&& loadedFile.getName().equals(libraryFile.getName())) && loadedFile.getName().equals(libraryFile.getName())) {
return true; return true;
}
}
return false; return false;
} }
/** /**
* Get the class name of next free core communicator class. If null is * Get the class name of next free core communicator class. If null is
* returned, no classes are available. * returned, no classes are available.
* *
* @return Class name * @return Class name
*/ */
public static String getAvailableClassName() { public static String getAvailableClassName() {
@ -119,7 +121,7 @@ public abstract class CoreComm {
/** /**
* Generates new source file by reading default source template and replacing * Generates new source file by reading default source template and replacing
* the class name field. * the class name field.
* *
* @param className * @param className
* Java class name (without extension) * Java class name (without extension)
* @throws MoteTypeCreationException * @throws MoteTypeCreationException
@ -151,8 +153,9 @@ public abstract class CoreComm {
destFilename = className + ".java"; destFilename = className + ".java";
File dir = new File("se/sics/cooja/corecomm"); File dir = new File("se/sics/cooja/corecomm");
if (!dir.exists()) if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
}
sourceFileWriter = new BufferedWriter(new OutputStreamWriter( sourceFileWriter = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("se/sics/cooja/corecomm/" + destFilename))); new FileOutputStream("se/sics/cooja/corecomm/" + destFilename)));
@ -168,10 +171,12 @@ public abstract class CoreComm {
templateFileReader.close(); templateFileReader.close();
} catch (Exception e) { } catch (Exception e) {
try { try {
if (sourceFileWriter != null) if (sourceFileWriter != null) {
sourceFileWriter.close(); sourceFileWriter.close();
if (templateFileReader != null) }
if (templateFileReader != null) {
templateFileReader.close(); templateFileReader.close();
}
} catch (Exception e2) { } catch (Exception e2) {
} }
@ -181,16 +186,17 @@ public abstract class CoreComm {
} }
File genFile = new File("se/sics/cooja/corecomm/" + destFilename); File genFile = new File("se/sics/cooja/corecomm/" + destFilename);
if (genFile.exists()) if (genFile.exists()) {
return; return;
}
throw (MoteTypeCreationException) new MoteTypeCreationException( throw new MoteTypeCreationException(
"Could not generate corecomm source file: " + className + ".java"); "Could not generate corecomm source file: " + className + ".java");
} }
/** /**
* Compiles Java class. * Compiles Java class.
* *
* @param className * @param className
* Java class name (without extension) * Java class name (without extension)
* @throws MoteTypeCreationException * @throws MoteTypeCreationException
@ -222,8 +228,9 @@ public abstract class CoreComm {
} }
p.waitFor(); p.waitFor();
if (classFile.exists()) if (classFile.exists()) {
return; return;
}
// Try including cooja.jar // Try including cooja.jar
cmd = new String[] { cmd = new String[] {
@ -246,8 +253,9 @@ public abstract class CoreComm {
} }
p.waitFor(); p.waitFor();
if (classFile.exists()) if (classFile.exists()) {
return; return;
}
} catch (IOException e) { } catch (IOException e) {
MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException( MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
@ -271,7 +279,7 @@ public abstract class CoreComm {
/** /**
* Loads given Java class file from disk. * Loads given Java class file from disk.
* *
* @param classFile * @param classFile
* Java class (without extension) * Java class (without extension)
* @return Loaded class * @return Loaded class
@ -282,8 +290,9 @@ public abstract class CoreComm {
throws MoteTypeCreationException { throws MoteTypeCreationException {
Class loadedClass = null; Class loadedClass = null;
try { try {
ClassLoader urlClassLoader = new URLClassLoader(new URL[] { new File(".") ClassLoader urlClassLoader = new URLClassLoader(
.toURL() }, CoreComm.class.getClassLoader()); new URL[] { new File(".").toURI().toURL() },
CoreComm.class.getClassLoader());
loadedClass = urlClassLoader.loadClass("se.sics.cooja.corecomm." loadedClass = urlClassLoader.loadClass("se.sics.cooja.corecomm."
+ className); + className);
@ -296,9 +305,10 @@ public abstract class CoreComm {
"Could not load corecomm class file: " + className + ".class") "Could not load corecomm class file: " + className + ".class")
.initCause(e); .initCause(e);
} }
if (loadedClass == null) if (loadedClass == null) {
throw (MoteTypeCreationException) new MoteTypeCreationException( throw new MoteTypeCreationException(
"Could not load corecomm class file: " + className + ".class"); "Could not load corecomm class file: " + className + ".class");
}
return loadedClass; return loadedClass;
} }
@ -306,7 +316,7 @@ public abstract class CoreComm {
/** /**
* Create and return an instance of the core communicator identified by * Create and return an instance of the core communicator identified by
* className. This core communicator will load the native library libFile. * className. This core communicator will load the native library libFile.
* *
* @param className * @param className
* Class name of core communicator * Class name of core communicator
* @param libFile * @param libFile
@ -353,14 +363,14 @@ public abstract class CoreComm {
/** /**
* Returns absolute memory location of the core variable referenceVar. Used to * Returns absolute memory location of the core variable referenceVar. Used to
* get offset between relative and absolute memory addresses. * get offset between relative and absolute memory addresses.
* *
* @return Absolute memory address * @return Absolute memory address
*/ */
public abstract int getReferenceAbsAddr(); public abstract int getReferenceAbsAddr();
/** /**
* Fills an byte array with memory segment identified by start and length. * Fills an byte array with memory segment identified by start and length.
* *
* @param start * @param start
* Start address of segment * Start address of segment
* @param length * @param length
@ -372,7 +382,7 @@ public abstract class CoreComm {
/** /**
* Overwrites a memory segment identified by start and length. * Overwrites a memory segment identified by start and length.
* *
* @param start * @param start
* Start address of segment * Start address of segment
* @param length * @param length

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: Simulation.java,v 1.18 2007/10/03 14:20:57 fros4943 Exp $ * $Id: Simulation.java,v 1.19 2008/02/12 15:03:43 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -470,7 +470,7 @@ public class Simulation extends Observable implements Runnable {
// Show configure simulation dialog // Show configure simulation dialog
boolean createdOK = false; boolean createdOK = false;
if (visAvailable) { if (visAvailable) {
createdOK = CreateSimDialog.showDialog(GUI.frame, this); createdOK = CreateSimDialog.showDialog(GUI.getTopParentContainer(), this);
} else { } else {
createdOK = true; createdOK = true;
} }

View file

@ -26,12 +26,13 @@
* 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: ContikiMoteType.java,v 1.24 2008/02/11 14:00:19 fros4943 Exp $ * $Id: ContikiMoteType.java,v 1.25 2008/02/12 15:04:43 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.*; import java.io.*;
import java.security.*; import java.security.*;
@ -202,10 +203,10 @@ public class ContikiMoteType implements MoteType {
return new ContikiMote(this, simulation); return new ContikiMote(this, simulation);
} }
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, public boolean configureAndInit(Container parentContainer, Simulation simulation,
boolean visAvailable) throws MoteTypeCreationException { boolean visAvailable) throws MoteTypeCreationException {
if (visAvailable) { if (visAvailable) {
return ContikiMoteTypeDialog.showDialog(parentFrame, simulation, this); return ContikiMoteTypeDialog.showDialog(parentContainer, simulation, this);
} else { } else {
// Create temp output directory if not already exists // Create temp output directory if not already exists
@ -1401,7 +1402,7 @@ public class ContikiMoteType implements MoteType {
} }
mySimulation = simulation; mySimulation = simulation;
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable); boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
return createdOK; return createdOK;
} }

View file

@ -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: ContikiMoteTypeDialog.java,v 1.39 2008/01/08 12:33:25 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.40 2008/02/12 15:04:20 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -116,19 +116,29 @@ public class ContikiMoteTypeDialog extends JDialog {
* Shows a dialog for configuring a Contiki mote type and compiling the shared * Shows a dialog for configuring a Contiki mote type and compiling the shared
* library it uses. * library it uses.
* *
* @param parentFrame * @param parentContainer
* Parent frame for dialog * Parent container for dialog
* @param simulation * @param simulation
* Simulation holding (or that will hold) mote type * Simulation holding (or that will hold) mote type
* @param moteTypeToConfigure * @param moteTypeToConfigure
* Mote type to configure * Mote type to configure
* @return True if compilation succeded and library is ready to be loaded * @return True if compilation succeeded and library is ready to be loaded
*/ */
public static boolean showDialog(Frame parentFrame, Simulation simulation, public static boolean showDialog(Container parentContainer, Simulation simulation,
ContikiMoteType moteTypeToConfigure) { ContikiMoteType moteTypeToConfigure) {
final ContikiMoteTypeDialog myDialog = new ContikiMoteTypeDialog( ContikiMoteTypeDialog myDialog = null;
parentFrame); if (parentContainer instanceof Window) {
myDialog = new ContikiMoteTypeDialog((Window) parentContainer);
} else if (parentContainer instanceof Dialog) {
myDialog = new ContikiMoteTypeDialog((Dialog) parentContainer);
} else if (parentContainer instanceof Frame) {
myDialog = new ContikiMoteTypeDialog((Frame) parentContainer);
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return false;
}
myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
myDialog.myMoteType = moteTypeToConfigure; myDialog.myMoteType = moteTypeToConfigure;
@ -403,7 +413,7 @@ public class ContikiMoteTypeDialog extends JDialog {
// Set position and focus of dialog // Set position and focus of dialog
myDialog.pack(); myDialog.pack();
myDialog.setLocationRelativeTo(parentFrame); myDialog.setLocationRelativeTo(parentContainer);
myDialog.textDescription.requestFocus(); myDialog.textDescription.requestFocus();
myDialog.textDescription.select(0, myDialog.textDescription.getText() myDialog.textDescription.select(0, myDialog.textDescription.getText()
.length()); .length());
@ -428,9 +438,20 @@ public class ContikiMoteTypeDialog extends JDialog {
return false; return false;
} }
private ContikiMoteTypeDialog(Dialog dialog) {
super(dialog, "Add Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private ContikiMoteTypeDialog(Window window) {
super(window, "Add Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private ContikiMoteTypeDialog(Frame frame) { private ContikiMoteTypeDialog(Frame frame) {
super(frame, "Add Mote Type", true); super(frame, "Add Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private void setupDialog() {
myDialog = this; myDialog = this;
JLabel label; JLabel label;
@ -2513,8 +2534,8 @@ public class ContikiMoteTypeDialog extends JDialog {
// Find and load the mote interface classes // Find and load the mote interface classes
for (String moteInterface : moteInterfaces) { for (String moteInterface : moteInterfaces) {
try { try {
Class<? extends MoteInterface> newMoteInterfaceClass = classLoader Class<? extends MoteInterface> newMoteInterfaceClass =
.loadClass(moteInterface).asSubclass(MoteInterface.class); myGUI.tryLoadClass(this, MoteInterface.class, moteInterface);
moteIntfClasses.add(newMoteInterfaceClass); moteIntfClasses.add(newMoteInterfaceClass);
// logger.info("Loaded mote interface: " + newMoteInterfaceClass); // logger.info("Loaded mote interface: " + newMoteInterfaceClass);
} catch (Exception ce) { } catch (Exception ce) {

View file

@ -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: AddMoteDialog.java,v 1.4 2007/11/29 05:37:35 fros4943 Exp $ * $Id: AddMoteDialog.java,v 1.5 2008/02/12 15:05:14 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -74,19 +74,30 @@ public class AddMoteDialog extends JDialog {
* Shows a dialog which enables a user to create and add motes of the given * Shows a dialog which enables a user to create and add motes of the given
* type. * type.
* *
* @param parentFrame * @param parentContainer
* Parent frame for dialog * Parent container for dialog
* @param simulation * @param simulation
* Simulation * Simulation
* @param moteType * @param moteType
* Mote type * Mote type
* @return New motes or null if aborted * @return New motes or null if aborted
*/ */
public static Vector<Mote> showDialog(Frame parentFrame, public static Vector<Mote> showDialog(Container parentContainer,
Simulation simulation, MoteType moteType) { Simulation simulation, MoteType moteType) {
AddMoteDialog myDialog = new AddMoteDialog(parentFrame, simulation, moteType); AddMoteDialog myDialog = null;
myDialog.setLocationRelativeTo(parentFrame); if (parentContainer instanceof Window) {
myDialog = new AddMoteDialog((Window)parentContainer, simulation, moteType);
} else if (parentContainer instanceof Dialog) {
myDialog = new AddMoteDialog((Dialog)parentContainer, simulation, moteType);
} else if (parentContainer instanceof Frame) {
myDialog = new AddMoteDialog((Frame)parentContainer, simulation, moteType);
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return null;
}
myDialog.setLocationRelativeTo(parentContainer);
myDialog.checkSettings(); myDialog.checkSettings();
if (myDialog != null) { if (myDialog != null) {
@ -96,7 +107,19 @@ public class AddMoteDialog extends JDialog {
} }
private AddMoteDialog(Frame frame, Simulation simulation, MoteType moteType) { private AddMoteDialog(Frame frame, Simulation simulation, MoteType moteType) {
super(frame, "Add motes (" + moteType.getDescription() + ")", true); super(frame, "Add motes (" + moteType.getDescription() + ")", ModalityType.APPLICATION_MODAL);
setupDialog(simulation, moteType);
}
private AddMoteDialog(Window window, Simulation simulation, MoteType moteType) {
super(window, "Add motes (" + moteType.getDescription() + ")", ModalityType.APPLICATION_MODAL);
setupDialog(simulation, moteType);
}
private AddMoteDialog(Dialog dialog, Simulation simulation, MoteType moteType) {
super(dialog, "Add motes (" + moteType.getDescription() + ")", ModalityType.APPLICATION_MODAL);
setupDialog(simulation, moteType);
}
private void setupDialog(Simulation simulation, MoteType moteType) {
this.moteType = moteType; this.moteType = moteType;
this.simulation = simulation; this.simulation = simulation;

View file

@ -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: CreateSimDialog.java,v 1.7 2007/09/30 12:03:49 fros4943 Exp $ * $Id: CreateSimDialog.java,v 1.8 2008/02/12 15:06:09 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -70,12 +70,22 @@ public class CreateSimDialog extends JDialog {
/** /**
* Shows a dialog for configuring a simulation. * Shows a dialog for configuring a simulation.
* *
* @param parentFrame Parent frame for dialog * @param parentContainer Parent container for dialog
* @param simulationToConfigure Simulation to configure * @param simulationToConfigure Simulation to configure
* @return True if simulation configured correctly * @return True if simulation configured correctly
*/ */
public static boolean showDialog(Frame parentFrame, Simulation simulationToConfigure) { public static boolean showDialog(Container parentContainer, Simulation simulationToConfigure) {
final CreateSimDialog myDialog = new CreateSimDialog(parentFrame, simulationToConfigure.getGUI()); final CreateSimDialog myDialog;
if (parentContainer instanceof Window) {
myDialog = new CreateSimDialog((Window) parentContainer, simulationToConfigure.getGUI());
} else if (parentContainer instanceof Dialog) {
myDialog = new CreateSimDialog((Dialog) parentContainer, simulationToConfigure.getGUI());
} else if (parentContainer instanceof Frame) {
myDialog = new CreateSimDialog((Frame) parentContainer, simulationToConfigure.getGUI());
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return false;
}
myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
myDialog.addWindowListener(new WindowListener() { myDialog.addWindowListener(new WindowListener() {
@ -149,7 +159,7 @@ public class CreateSimDialog extends JDialog {
// Set position and focus of dialog // Set position and focus of dialog
myDialog.setLocationRelativeTo(parentFrame); myDialog.setLocationRelativeTo(parentContainer);
myDialog.title.requestFocus(); myDialog.title.requestFocus();
myDialog.title.select(0, myDialog.title.getText().length()); myDialog.title.select(0, myDialog.title.getText().length());
@ -172,9 +182,20 @@ public class CreateSimDialog extends JDialog {
return false; return false;
} }
private CreateSimDialog(Dialog dialog, GUI gui) {
super(dialog, "Create new simulation", ModalityType.TOOLKIT_MODAL);
setupDialog(gui);
}
private CreateSimDialog(Window window, GUI gui) {
super(window, "Create new simulation", ModalityType.TOOLKIT_MODAL);
setupDialog(gui);
}
private CreateSimDialog(Frame frame, GUI gui) { private CreateSimDialog(Frame frame, GUI gui) {
super(frame, "Create new simulation", true); super(frame, "Create new simulation", ModalityType.TOOLKIT_MODAL);
setupDialog(gui);
}
private void setupDialog(GUI gui) {
myDialog = this; myDialog = this;
myGUI = gui; myGUI = gui;

View file

@ -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.7 2007/09/28 07:21:21 fros4943 Exp $ * $Id: ExternalToolsDialog.java,v 1.8 2008/02/12 15:06:09 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -61,21 +61,43 @@ public class ExternalToolsDialog extends JDialog {
/** /**
* Creates a dialog for viewing/editing external tools settings. * Creates a dialog for viewing/editing external tools settings.
* *
* @param parentFrame * @param parentContainer
* Parent frame for dialog * Parent container for dialog
*/ */
public static void showDialog(Frame parentFrame) { public static void showDialog(Container parentContainer) {
ExternalToolsDialog myDialog = new ExternalToolsDialog(parentFrame);
myDialog.setLocationRelativeTo(parentFrame); ExternalToolsDialog myDialog = null;
if (parentContainer instanceof Window) {
myDialog = new ExternalToolsDialog((Window) parentContainer);
} else if (parentContainer instanceof Dialog) {
myDialog = new ExternalToolsDialog((Dialog) parentContainer);
} else if (parentContainer instanceof Frame) {
myDialog = new ExternalToolsDialog((Frame) parentContainer);
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return;
}
myDialog.setLocationRelativeTo(parentContainer);
if (myDialog != null) { if (myDialog != null) {
myDialog.setVisible(true); myDialog.setVisible(true);
} }
} }
private ExternalToolsDialog(Dialog dialog) {
super(dialog, "Edit Settings", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private ExternalToolsDialog(Window window) {
super(window, "Edit Settings", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private ExternalToolsDialog(Frame frame) { private ExternalToolsDialog(Frame frame) {
super(frame, "Edit Settings", true); super(frame, "Edit Settings", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private void setupDialog() {
myDialog = this; myDialog = this;
JLabel label; JLabel label;

View file

@ -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.4 2007/08/21 14:18:04 fros4943 Exp $ * $Id: ProjectDirectoriesDialog.java,v 1.5 2008/02/12 15:06:09 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -63,30 +63,37 @@ public class ProjectDirectoriesDialog extends JDialog {
private List changableProjectsList = new List(); private List changableProjectsList = new List();
private List fixedProjectsList = null; private List fixedProjectsList = null;
private Vector<File> changableProjects = null; private Vector<File> changableProjects = null;
private Vector<File> fixedProjects = null;
private ProjectDirectoriesDialog myDialog; private ProjectDirectoriesDialog myDialog;
private Frame myParentFrame = null;
private Dialog myParentDialog = null;
/** /**
* Allows user to alter the given project directories list by adding new, * Allows user to alter the given project directories list by adding new,
* reordering or removing project directories. Only the changable project directories * reordering or removing project directories. Only the changable project directories
* can be altered. * can be altered.
* *
* @param parentFrame * @param parentContainer
* Parent frame * Parent container
* @param changableProjects * @param changableProjects
* Changeable project directories * Changeable project directories
* @param fixedProjects * @param fixedProjects
* Fixed project directory * Fixed project directory
* @return Null if dialog aborted, else the new CHANGEABLE project directory list. * @return Null if dialog aborted, else the new CHANGEABLE project directory list.
*/ */
public static Vector<File> showDialog(Frame parentFrame, public static Vector<File> showDialog(Container parentContainer,
Vector<File> changableProjects, Vector<File> fixedProjects) { Vector<File> changableProjects, Vector<File> fixedProjects) {
ProjectDirectoriesDialog myDialog = new ProjectDirectoriesDialog(parentFrame,
changableProjects, fixedProjects); ProjectDirectoriesDialog myDialog = null;
myDialog.setLocationRelativeTo(parentFrame); if (parentContainer instanceof Window) {
myDialog = new ProjectDirectoriesDialog((Window) parentContainer, changableProjects, fixedProjects);
} else if (parentContainer instanceof Dialog) {
myDialog = new ProjectDirectoriesDialog((Dialog) parentContainer, changableProjects, fixedProjects);
} else if (parentContainer instanceof Frame) {
myDialog = new ProjectDirectoriesDialog((Frame) parentContainer, changableProjects, fixedProjects);
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return null;
}
myDialog.setLocationRelativeTo(parentContainer);
if (myDialog != null) { if (myDialog != null) {
myDialog.setVisible(true); myDialog.setVisible(true);
@ -123,19 +130,23 @@ public class ProjectDirectoriesDialog extends JDialog {
private ProjectDirectoriesDialog(Frame frame, Vector<File> changableProjects, private ProjectDirectoriesDialog(Frame frame, Vector<File> changableProjects,
Vector<File> fixedProjects) { Vector<File> fixedProjects) {
super(frame, "Manage Project Directories", true); super(frame, "Manage Project Directories", ModalityType.APPLICATION_MODAL);
myParentFrame = frame; setupDialog(changableProjects, fixedProjects);
init(changableProjects, fixedProjects);
} }
private ProjectDirectoriesDialog(Dialog dialog, Vector<File> changableProjects, private ProjectDirectoriesDialog(Dialog dialog, Vector<File> changableProjects,
Vector<File> fixedProjects) { Vector<File> fixedProjects) {
super(dialog, "Manage Project Directories", true); super(dialog, "Manage Project Directories", ModalityType.APPLICATION_MODAL);
myParentDialog = dialog; setupDialog(changableProjects, fixedProjects);
init(changableProjects, fixedProjects);
} }
private void init(Vector<File> changablePlatforms, Vector<File> fixedProjects) { private ProjectDirectoriesDialog(Window window, Vector<File> changableProjects,
Vector<File> fixedProjects) {
super(window, "Manage Project Directories", ModalityType.APPLICATION_MODAL);
setupDialog(changableProjects, fixedProjects);
}
private void setupDialog(Vector<File> changablePlatforms, Vector<File> fixedProjects) {
myDialog = this; myDialog = this;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
@ -339,11 +350,7 @@ public class ProjectDirectoriesDialog extends JDialog {
} }
// Show merged configuration // Show merged configuration
if (myParentFrame != null) { ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);
ConfigViewer.showDialog(myParentFrame, config);
} else {
ConfigViewer.showDialog(myParentDialog, config);
}
} }
}); });
addRemovePane.add(button); addRemovePane.add(button);
@ -353,10 +360,10 @@ public class ProjectDirectoriesDialog extends JDialog {
button = new JButton("Add manually"); button = new JButton("Add manually");
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ProjectDirectoryInputDialog pathDialog = new ProjectDirectoryInputDialog(myParentFrame); ProjectDirectoryInputDialog pathDialog = new ProjectDirectoryInputDialog(ProjectDirectoriesDialog.this);
pathDialog.pack(); pathDialog.pack();
pathDialog.setLocationRelativeTo(myParentFrame); pathDialog.setLocationRelativeTo(ProjectDirectoriesDialog.this);
pathDialog.setVisible(true); pathDialog.setVisible(true);
File projectPath = pathDialog.getProjectDirectory(); File projectPath = pathDialog.getProjectDirectory();

View file

@ -21,9 +21,20 @@ class ProjectDirectoryInputDialog extends JDialog implements ActionListener, Pro
private String buttonAdd = "Add"; private String buttonAdd = "Add";
private String buttonCancel = "Cancel"; private String buttonCancel = "Cancel";
public ProjectDirectoryInputDialog(Frame parent) { public ProjectDirectoryInputDialog(Window window) {
super(parent, true); super(window, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public ProjectDirectoryInputDialog(Dialog dialog) {
super(dialog, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public ProjectDirectoryInputDialog(Frame frame) {
super(frame, ModalityType.APPLICATION_MODAL);
setupDialog();
}
public void setupDialog() {
setTitle("Enter path"); setTitle("Enter path");
textField = new JTextField(10); textField = new JTextField(10);
@ -37,7 +48,7 @@ class ProjectDirectoryInputDialog extends JDialog implements ActionListener, Pro
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
pathChanged(); pathChanged();
} }
}); });
Object[] objects = {"Enter path to project directory", textField}; Object[] objects = {"Enter path to project directory", textField};
Object[] options = {buttonAdd, buttonCancel}; Object[] options = {buttonAdd, buttonCancel};

View file

@ -26,12 +26,13 @@
* 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: MantisMoteType.java,v 1.5 2007/09/18 11:33:58 fros4943 Exp $ * $Id: MantisMoteType.java,v 1.6 2008/02/12 15:10:49 fros4943 Exp $
*/ */
package se.sics.cooja.mantismote; package se.sics.cooja.mantismote;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -40,7 +41,6 @@ import java.util.regex.Pattern;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -61,7 +61,7 @@ import se.sics.cooja.contikimote.ContikiMoteType;
* Mantis system in order to create the initial memory. When a new mote is * Mantis system in order to create the initial memory. When a new mote is
* created the createInitialMemory() method should be called to get this initial * created the createInitialMemory() method should be called to get this initial
* memory for the mote. * memory for the mote.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("Mantis Mote Type") @ClassDescription("Mantis Mote Type")
@ -96,7 +96,7 @@ public class MantisMoteType implements MoteType {
* loaded by the first available CoreComm. Each mote generated from this mote * loaded by the first available CoreComm. Each mote generated from this mote
* type will have the interfaces specified in the given mote interface class * type will have the interfaces specified in the given mote interface class
* list. * list.
* *
* @param libFile * @param libFile
* Library file to load * Library file to load
* @param objFile * @param objFile
@ -106,21 +106,22 @@ public class MantisMoteType implements MoteType {
*/ */
public MantisMoteType(File libFile, File objFile, public MantisMoteType(File libFile, File objFile,
Vector<Class<? extends MoteInterface>> moteInterfaceClasses) { Vector<Class<? extends MoteInterface>> moteInterfaceClasses) {
if (!doInit(libFile, objFile, moteInterfaceClasses)) if (!doInit(libFile, objFile, moteInterfaceClasses)) {
logger.fatal("Mantis mote type creation failed!"); logger.fatal("Mantis mote type creation failed!");
}
} }
/** /**
* This is an mote type initialization method and should normally never be * This is an mote type initialization method and should normally never be
* called by any other part than the mote type constructor. It is called from * called by any other part than the mote type constructor. It is called from
* the constructor with an identifier argument, but not from the standard * the constructor with an identifier argument, but not from the standard
* constructor. This method may be called from the simulator when loading * constructor. This method may be called from the simulator when loading
* configuration files, and the libraries must be recompiled. * configuration files, and the libraries must be recompiled.
* *
* This method allocates a core communicator, loads the Mantis library file, * This method allocates a core communicator, loads the Mantis library file,
* creates variable name to address mappings and finally creates the Mantis * creates variable name to address mappings and finally creates the Mantis
* mote initial memory. * mote initial memory.
* *
* @param libFile Library file * @param libFile Library file
* @param objFile Object file * @param objFile Object file
* @param moteInterfaceClasses Mote interface classes * @param moteInterfaceClasses Mote interface classes
@ -131,7 +132,7 @@ public class MantisMoteType implements MoteType {
myObjectFilename = objFile.getAbsolutePath(); myObjectFilename = objFile.getAbsolutePath();
myIdentifier = libFile.getName(); myIdentifier = libFile.getName();
myDescription = libFile.getAbsolutePath(); myDescription = libFile.getAbsolutePath();
// Allocate core communicator class // Allocate core communicator class
libraryClassName = CoreComm.getAvailableClassName(); libraryClassName = CoreComm.getAvailableClassName();
try { try {
@ -195,7 +196,7 @@ public class MantisMoteType implements MoteType {
logger.fatal("BSS section size parsing failed"); logger.fatal("BSS section size parsing failed");
return false; return false;
} }
// Get offset between relative and absolute addresses // Get offset between relative and absolute addresses
offsetRelToAbs = myCoreComm.getReferenceAbsAddr() - (Integer) varAddresses.get("referenceVar"); offsetRelToAbs = myCoreComm.getReferenceAbsAddr() - (Integer) varAddresses.get("referenceVar");
@ -209,17 +210,17 @@ public class MantisMoteType implements MoteType {
myInitialMemory = new SectionMoteMemory(varAddresses); myInitialMemory = new SectionMoteMemory(varAddresses);
myInitialMemory.setMemorySegment(relDataSectionAddr, initialDataSection); myInitialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
myInitialMemory.setMemorySegment(relBssSectionAddr, initialBssSection); myInitialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
this.moteInterfaceClasses = moteInterfaceClasses; this.moteInterfaceClasses = moteInterfaceClasses;
return true; return true;
} }
/** /**
* Creates and returns a copy of this mote type's initial memory (just after * Creates and returns a copy of this mote type's initial memory (just after
* the init function has been run). When a new mote is created it should get * the init function has been run). When a new mote is created it should get
* it's memory from here. * it's memory from here.
* *
* @return Initial memory of a mote type * @return Initial memory of a mote type
*/ */
public SectionMoteMemory createInitialMemory() { public SectionMoteMemory createInitialMemory() {
@ -237,7 +238,7 @@ public class MantisMoteType implements MoteType {
/** /**
* Copy core memory to given memory. This should not be used directly, but * Copy core memory to given memory. This should not be used directly, but
* instead via MantisMote.getMemory(). * instead via MantisMote.getMemory().
* *
* @param mem * @param mem
* Memory to set * Memory to set
*/ */
@ -246,7 +247,7 @@ public class MantisMoteType implements MoteType {
int startAddr = mem.getStartAddrOfSection(i); int startAddr = mem.getStartAddrOfSection(i);
int size = mem.getSizeOfSection(i); int size = mem.getSizeOfSection(i);
byte[] data = mem.getDataOfSection(i); byte[] data = mem.getDataOfSection(i);
getCoreMemory(startAddr + offsetRelToAbs, getCoreMemory(startAddr + offsetRelToAbs,
size, data); size, data);
} }
@ -255,7 +256,7 @@ public class MantisMoteType implements MoteType {
/** /**
* Copy given memory to the Mantis system. This should not be used directly, * Copy given memory to the Mantis system. This should not be used directly,
* but instead via MantisMote.setMemory(). * but instead via MantisMote.setMemory().
* *
* @param mem * @param mem
* New memory * New memory
*/ */
@ -277,7 +278,7 @@ public class MantisMoteType implements MoteType {
/** /**
* Returns all mote interfaces of this mote type * Returns all mote interfaces of this mote type
* *
* @return All mote interfaces * @return All mote interfaces
*/ */
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() { public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
@ -296,7 +297,7 @@ public class MantisMoteType implements MoteType {
return myIdentifier; return myIdentifier;
} }
public void setIdentifier(String identifier) { public void setIdentifier(String identifier) {
myIdentifier = identifier; myIdentifier = identifier;
} }
@ -360,9 +361,11 @@ public class MantisMoteType implements MoteType {
return new MantisMote(this, mySimulation); return new MantisMote(this, mySimulation);
} }
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable) { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
if (!visAvailable) logger.fatal(">>>>>>> NOT IMPLEMENTED"); if (!visAvailable) {
return MantisMoteTypeDialog.showDialog(parentFrame, simulation, this); logger.fatal(">>>>>>> NOT IMPLEMENTED");
}
return MantisMoteTypeDialog.showDialog(parentContainer, simulation, this);
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
@ -406,7 +409,7 @@ public class MantisMoteType implements MoteType {
} }
} }
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable); boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
return createdOK; return createdOK;
} }

View file

@ -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: MantisMoteTypeDialog.java,v 1.5 2007/03/24 00:44:55 fros4943 Exp $ * $Id: MantisMoteTypeDialog.java,v 1.6 2008/02/12 15:10:49 fros4943 Exp $
*/ */
package se.sics.cooja.mantismote; package se.sics.cooja.mantismote;
@ -44,15 +44,15 @@ import se.sics.cooja.dialogs.MessageList;
/** /**
* A dialog for configuring Mantis mote types and compiling KMantis mote type * A dialog for configuring Mantis mote types and compiling KMantis mote type
* libraries. * libraries.
* *
* The dialog takes a Mantis mote type as argument and pre-selects the values * The dialog takes a Mantis mote type as argument and pre-selects the values
* already set in that mote type before showing the dialog. Any changes made to * already set in that mote type before showing the dialog. Any changes made to
* the settings are written to the mote type if the compilation is successful * the settings are written to the mote type if the compilation is successful
* and the user presses OK. * and the user presses OK.
* *
* This dialog uses external tools to scan for sources and compile libraries. * This dialog uses external tools to scan for sources and compile libraries.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class MantisMoteTypeDialog extends JDialog { public class MantisMoteTypeDialog extends JDialog {
@ -74,12 +74,12 @@ public class MantisMoteTypeDialog extends JDialog {
private JTextField textID, textOutputFiles, textDescription, textMantisBinary; private JTextField textID, textOutputFiles, textDescription, textMantisBinary;
private JButton createButton, compileButton; private JButton createButton, compileButton;
private File objFile = null; private File objFile = null;
private File workingDir = null; private File workingDir = null;
private File libFile = null; private File libFile = null;
private File srcFile = null; private File srcFile = null;
private Vector<Class<? extends MoteInterface>> moteInterfaceClasses = null; private Vector<Class<? extends MoteInterface>> moteInterfaceClasses = null;
private boolean settingsOK = false; // Do all settings seem correct? private boolean settingsOK = false; // Do all settings seem correct?
@ -92,20 +92,29 @@ public class MantisMoteTypeDialog extends JDialog {
/** /**
* Shows a dialog for configuring a Mantis mote type. * Shows a dialog for configuring a Mantis mote type.
* *
* @param parentFrame * @param parentContainer
* Parent frame for dialog * Parent container for dialog
* @param simulation * @param simulation
* Simulation holding (or that will hold) mote type * Simulation holding (or that will hold) mote type
* @param moteTypeToConfigure * @param moteTypeToConfigure
* Mote type to configure * Mote type to configure
* @return True if mote type configuration succeded and library is ready to be loaded * @return True if mote type configuration succeded and library is ready to be loaded
*/ */
public static boolean showDialog(Frame parentFrame, Simulation simulation, public static boolean showDialog(Container parentContainer, Simulation simulation,
MantisMoteType moteTypeToConfigure) { MantisMoteType moteTypeToConfigure) {
final MantisMoteTypeDialog myDialog = new MantisMoteTypeDialog( MantisMoteTypeDialog myDialog = null;
parentFrame); if (parentContainer instanceof Window) {
myDialog = new MantisMoteTypeDialog((Window) parentContainer);
} else if (parentContainer instanceof Dialog) {
myDialog = new MantisMoteTypeDialog((Dialog) parentContainer);
} else if (parentContainer instanceof Frame) {
myDialog = new MantisMoteTypeDialog((Frame) parentContainer);
} else {
logger.fatal("Unknown parent container type: " + parentContainer);
return false;
}
myDialog.myMoteType = moteTypeToConfigure; myDialog.myMoteType = moteTypeToConfigure;
myDialog.allOtherTypes = simulation.getMoteTypes(); myDialog.allOtherTypes = simulation.getMoteTypes();
@ -160,7 +169,7 @@ public class MantisMoteTypeDialog extends JDialog {
myDialog.moteInterfaceClasses = new Vector<Class<? extends MoteInterface>>(); myDialog.moteInterfaceClasses = new Vector<Class<? extends MoteInterface>>();
for (String moteInterface : moteInterfaces) { for (String moteInterface : moteInterfaces) {
try { try {
Class<? extends MoteInterface> newMoteInterfaceClass = Class<? extends MoteInterface> newMoteInterfaceClass =
simulation.getGUI().tryLoadClass(simulation.getGUI(), MoteInterface.class, moteInterface); simulation.getGUI().tryLoadClass(simulation.getGUI(), MoteInterface.class, moteInterface);
myDialog.moteInterfaceClasses.add(newMoteInterfaceClass); myDialog.moteInterfaceClasses.add(newMoteInterfaceClass);
/*logger.info("Loaded Mantis mote interface: " + newMoteInterfaceClass);*/ /*logger.info("Loaded Mantis mote interface: " + newMoteInterfaceClass);*/
@ -172,7 +181,7 @@ public class MantisMoteTypeDialog extends JDialog {
// Set position and focus of dialog // Set position and focus of dialog
myDialog.pack(); myDialog.pack();
myDialog.setLocationRelativeTo(parentFrame); myDialog.setLocationRelativeTo(parentContainer);
myDialog.textDescription.requestFocus(); myDialog.textDescription.requestFocus();
myDialog.textDescription.select(0, myDialog.textDescription.getText().length()); myDialog.textDescription.select(0, myDialog.textDescription.getText().length());
myDialog.pathsWereUpdated(); myDialog.pathsWereUpdated();
@ -185,9 +194,20 @@ public class MantisMoteTypeDialog extends JDialog {
return false; return false;
} }
private MantisMoteTypeDialog(Dialog dialog) {
super(dialog, "Configure Mantis Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private MantisMoteTypeDialog(Window window) {
super(window, "Configure Mantis Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private MantisMoteTypeDialog(Frame frame) { private MantisMoteTypeDialog(Frame frame) {
super(frame, "Configure Mantis Mote Type", true); super(frame, "Configure Mantis Mote Type", ModalityType.TOOLKIT_MODAL);
setupDialog();
}
private void setupDialog() {
myDialog = this; myDialog = this;
JLabel label; JLabel label;
@ -361,8 +381,9 @@ public class MantisMoteTypeDialog extends JDialog {
if (compilationThread != null && compilationThread.isAlive()) { if (compilationThread != null && compilationThread.isAlive()) {
compilationThread.interrupt(); compilationThread.interrupt();
} }
if (progressDialog != null && progressDialog.isDisplayable()) if (progressDialog != null && progressDialog.isDisplayable()) {
progressDialog.dispose(); progressDialog.dispose();
}
} }
}); });
@ -385,30 +406,31 @@ public class MantisMoteTypeDialog extends JDialog {
if (srcFile.exists()) { if (srcFile.exists()) {
srcFile.delete(); srcFile.delete();
} }
if (srcFile.exists()) { if (srcFile.exists()) {
throw new Exception("could not remove old source file"); throw new Exception("could not remove old source file");
} }
generateSourceFile(srcFile); generateSourceFile(srcFile);
if (!srcFile.exists()) { if (!srcFile.exists()) {
throw new Exception("source file not created"); throw new Exception("source file not created");
} }
} catch (Exception e) { } catch (Exception e) {
libraryCreatedOK = false; libraryCreatedOK = false;
progressBar.setBackground(Color.ORANGE); progressBar.setBackground(Color.ORANGE);
if (e.getMessage() != null) if (e.getMessage() != null) {
progressBar.setString("source file generation failed: " + e.getMessage()); progressBar.setString("source file generation failed: " + e.getMessage());
else } else {
progressBar.setString("source file generation failed"); progressBar.setString("source file generation failed");
}
progressBar.setIndeterminate(false); progressBar.setIndeterminate(false);
progressBar.setValue(0); progressBar.setValue(0);
createButton.setEnabled(libraryCreatedOK); createButton.setEnabled(libraryCreatedOK);
return; return;
} }
// Test compile shared library // Test compile shared library
progressBar.setString("..compiling.."); progressBar.setString("..compiling..");
@ -418,7 +440,7 @@ public class MantisMoteTypeDialog extends JDialog {
compilationThread = new Thread(new Runnable() { compilationThread = new Thread(new Runnable() {
public void run() { public void run() {
compilationSucceded = compilationSucceded =
MantisMoteTypeDialog.compileLibrary( MantisMoteTypeDialog.compileLibrary(
libFile, libFile,
objFile, objFile,
@ -445,8 +467,9 @@ public class MantisMoteTypeDialog extends JDialog {
libraryCreatedOK = false; libraryCreatedOK = false;
} else { } else {
libraryCreatedOK = true; libraryCreatedOK = true;
if (!libFile.exists()) if (!libFile.exists()) {
libraryCreatedOK = false; libraryCreatedOK = false;
}
} }
if (libraryCreatedOK) { if (libraryCreatedOK) {
@ -467,7 +490,7 @@ public class MantisMoteTypeDialog extends JDialog {
/** /**
* Generates new source file by reading default source template and replacing * Generates new source file by reading default source template and replacing
* certain field in order to be loadable from given Java class. * certain field in order to be loadable from given Java class.
* *
* @param outputFile Source file to create * @param outputFile Source file to create
* @throws Exception * @throws Exception
*/ */
@ -500,7 +523,7 @@ public class MantisMoteTypeDialog extends JDialog {
} }
sourceFile = new BufferedReader(reader); sourceFile = new BufferedReader(reader);
destFile = new BufferedWriter(new OutputStreamWriter( destFile = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile))); new FileOutputStream(outputFile)));
@ -515,10 +538,12 @@ public class MantisMoteTypeDialog extends JDialog {
sourceFile.close(); sourceFile.close();
} catch (Exception e) { } catch (Exception e) {
try { try {
if (destFile != null) if (destFile != null) {
destFile.close(); destFile.close();
if (sourceFile != null) }
if (sourceFile != null) {
sourceFile.close(); sourceFile.close();
}
} catch (Exception e2) { } catch (Exception e2) {
} }
@ -526,10 +551,10 @@ public class MantisMoteTypeDialog extends JDialog {
throw e; throw e;
} }
} }
/** /**
* Compiles a mote type shared library using the standard Mantis makefile. * Compiles a mote type shared library using the standard Mantis makefile.
* *
* @param libFile Library file to create * @param libFile Library file to create
* @param binFile Binary file to link against * @param binFile Binary file to link against
* @param sourceFile Source file to compile * @param sourceFile Source file to compile
@ -545,42 +570,48 @@ public class MantisMoteTypeDialog extends JDialog {
// Check needed files // Check needed files
if (!workingDir.exists()) { if (!workingDir.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad paths"); errorStream.println("Bad paths");
}
logger.fatal("Working directory does not exist"); logger.fatal("Working directory does not exist");
return false; return false;
} }
if (!workingDir.isDirectory()) { if (!workingDir.isDirectory()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad paths"); errorStream.println("Bad paths");
}
logger.fatal("Working directory is not a directory"); logger.fatal("Working directory is not a directory");
return false; return false;
} }
if (libFile.exists()) { if (libFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
}
logger.fatal("Library already exists"); logger.fatal("Library already exists");
return false; return false;
} }
if (!sourceFile.exists()) { if (!sourceFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad dependency files"); errorStream.println("Bad dependency files");
}
logger.fatal("Source file not found"); logger.fatal("Source file not found");
return false; return false;
} }
if (!binFile.exists()) { if (!binFile.exists()) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad dependency files"); errorStream.println("Bad dependency files");
}
logger.fatal("Link object file not found"); logger.fatal("Link object file not found");
return false; return false;
} }
if (CoreComm.hasLibraryFileBeenLoaded(libFile)) { if (CoreComm.hasLibraryFileBeenLoaded(libFile)) {
if (errorStream != null) if (errorStream != null) {
errorStream.println("Bad output filenames"); errorStream.println("Bad output filenames");
}
logger.fatal("A library has already been loaded with the same name before"); logger.fatal("A library has already been loaded with the same name before");
return false; return false;
} }
@ -606,8 +637,9 @@ public class MantisMoteTypeDialog extends JDialog {
String readLine; String readLine;
try { try {
while ((readLine = input.readLine()) != null) { while ((readLine = input.readLine()) != null) {
if (outputStream != null && readLine != null) if (outputStream != null && readLine != null) {
outputStream.println(readLine); outputStream.println(readLine);
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while reading from process"); logger.warn("Error while reading from process");
@ -620,8 +652,9 @@ public class MantisMoteTypeDialog extends JDialog {
String readLine; String readLine;
try { try {
while ((readLine = err.readLine()) != null) { while ((readLine = err.readLine()) != null) {
if (errorStream != null && readLine != null) if (errorStream != null && readLine != null) {
errorStream.println(readLine); errorStream.println(readLine);
}
} }
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while reading from process"); logger.warn("Error while reading from process");
@ -711,39 +744,42 @@ public class MantisMoteTypeDialog extends JDialog {
} else { } else {
textOutputFiles.setText(""); textOutputFiles.setText("");
} }
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
compileButton.setEnabled(settingsOK); compileButton.setEnabled(settingsOK);
} }
private class MoteTypeEventHandler private class MoteTypeEventHandler
implements implements
ActionListener, ActionListener,
DocumentListener { DocumentListener {
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
if (myDialog.isVisible()) if (myDialog.isVisible()) {
javax.swing.SwingUtilities.invokeLater(new Runnable() { javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
pathsWereUpdated(); pathsWereUpdated();
} }
}); });
}
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("cancel")) { if (e.getActionCommand().equals("cancel")) {
@ -783,8 +819,9 @@ public class MantisMoteTypeDialog extends JDialog {
} }
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
pathsWereUpdated(); pathsWereUpdated();
} else } else {
logger.warn("Unhandled action: " + e.getActionCommand()); logger.warn("Unhandled action: " + e.getActionCommand());
}
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2007, Swedish Institute of Computer Science. All rights * Copyright (c) 2007, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* Institute nor the names of its contributors may be used to endorse or promote * Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written * products derived from this software without specific prior written
* permission. * permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -23,13 +23,14 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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: AbstractApplicationMoteType.java,v 1.1 2007/05/31 07:21:29 fros4943 Exp $ * $Id: AbstractApplicationMoteType.java,v 1.2 2008/02/12 15:10:49 fros4943 Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
@ -62,7 +63,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
description = "Application Mote Type #" + identifier; description = "Application Mote Type #" + identifier;
} }
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable) { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
if (identifier == null) { if (identifier == null) {
// Create unique identifier // Create unique identifier
@ -104,7 +105,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
/** /**
* Returns all mote interfaces of this mote type * Returns all mote interfaces of this mote type
* *
* @return All mote interfaces * @return All mote interfaces
*/ */
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() { public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
@ -113,7 +114,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
/** /**
* Set mote interfaces of this mote type * Set mote interfaces of this mote type
* *
* @param moteInterfaces * @param moteInterfaces
* New mote interfaces * New mote interfaces
*/ */
@ -233,7 +234,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
} }
} }
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable); boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
return createdOK; return createdOK;
} }

View file

@ -32,6 +32,7 @@
package se.sics.cooja.motes; package se.sics.cooja.motes;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
@ -76,7 +77,7 @@ public class DisturberMoteType implements MoteType {
return new DisturberMote(this, simulation); return new DisturberMote(this, simulation);
} }
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable) { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
if (identifier == null) { if (identifier == null) {
// Create unique identifier // Create unique identifier
@ -251,7 +252,7 @@ public class DisturberMoteType implements MoteType {
} }
} }
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable); boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
return createdOK; return createdOK;
} }

View file

@ -26,11 +26,12 @@
* 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: DummyMoteType.java,v 1.4 2008/02/07 10:34:45 fros4943 Exp $ * $Id: DummyMoteType.java,v 1.5 2008/02/12 15:10:49 fros4943 Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
import java.awt.Container;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
@ -61,7 +62,7 @@ public class DummyMoteType implements MoteType {
return new DummyMote(this, simulation); return new DummyMote(this, simulation);
} }
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable) { public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
if (identifier == null) { if (identifier == null) {
// Create unique identifier // Create unique identifier
@ -152,7 +153,7 @@ public class DummyMoteType implements MoteType {
} }
} }
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable); boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
return createdOK; return createdOK;
} }

View file

@ -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: LogListener.java,v 1.7 2008/02/08 14:42:33 fros4943 Exp $ * $Id: LogListener.java,v 1.8 2008/02/12 15:11:40 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -155,7 +155,7 @@ public class LogListener extends VisPlugin {
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(GUI.frame); int returnVal = fc.showSaveDialog(GUI.getTopParentContainer());
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
File saveFile = fc.getSelectedFile(); File saveFile = fc.getSelectedFile();
@ -163,9 +163,8 @@ public class LogListener extends VisPlugin {
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.frame,
"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,
JOptionPane.QUESTION_MESSAGE, null, options, s1); JOptionPane.QUESTION_MESSAGE, null, options, s1);

View file

@ -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: Visualizer2D.java,v 1.11 2007/05/30 20:57:58 fros4943 Exp $ * $Id: Visualizer2D.java,v 1.12 2008/02/12 15:11:40 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -45,17 +45,17 @@ import se.sics.cooja.interfaces.*;
/** /**
* Visualizer2D is an abstract mote visualizer for simulations. All motes are * Visualizer2D is an abstract mote visualizer for simulations. All motes are
* painted in the XY-plane, as seen from positive Z axis. * painted in the XY-plane, as seen from positive Z axis.
* *
* An implementation of this class must colorize the different motes, each mote * An implementation of this class must colorize the different motes, each mote
* has two different colors; inner and outer. * has two different colors; inner and outer.
* *
* By right-clicking the mouse on a mote a popup menu will be displayed. From * By right-clicking the mouse on a mote a popup menu will be displayed. From
* this menu mote plugins can be started. or the mote can be moved. Each * this menu mote plugins can be started. or the mote can be moved. Each
* implementation may also register its own actions to be accessed from this * implementation may also register its own actions to be accessed from this
* menu. * menu.
* *
* A Visualizer2D observers both the simulation and all mote positions. * A Visualizer2D observers both the simulation and all mote positions.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("2D Mote Visualizer") @ClassDescription("2D Mote Visualizer")
@ -89,7 +89,7 @@ public abstract class Visualizer2D extends VisPlugin {
private Mote highlightedMote = null; private Mote highlightedMote = null;
private Color highlightColor = Color.GRAY; private Color highlightColor = Color.GRAY;
private Timer highlightTimer = null; private Timer highlightTimer = null;
public interface MoteMenuAction { public interface MoteMenuAction {
public boolean isEnabled(Mote mote); public boolean isEnabled(Mote mote);
public String getDescription(Mote mote); public String getDescription(Mote mote);
@ -126,7 +126,7 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Registers as an simulation observer and initializes the canvas. * Registers as an simulation observer and initializes the canvas.
* *
* @param simulationToVisualize * @param simulationToVisualize
* Simulation to visualize * Simulation to visualize
*/ */
@ -188,12 +188,14 @@ public abstract class Visualizer2D extends VisPlugin {
// Detect mote highligts // Detect mote highligts
myGUI.addMoteHighligtObserver(moteHighligtObserver = new Observer() { myGUI.addMoteHighligtObserver(moteHighligtObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
if (!(obj instanceof Mote)) if (!(obj instanceof Mote)) {
return; return;
}
if (highlightTimer != null && highlightTimer.isRunning())
if (highlightTimer != null && highlightTimer.isRunning()) {
highlightTimer.stop(); highlightTimer.stop();
}
highlightTimer = new Timer(100, null); highlightTimer = new Timer(100, null);
highlightedMote = (Mote) obj; highlightedMote = (Mote) obj;
highlightTimer.addActionListener(new ActionListener() { highlightTimer.addActionListener(new ActionListener() {
@ -207,15 +209,16 @@ public abstract class Visualizer2D extends VisPlugin {
} }
// Toggle color // Toggle color
if (highlightColor == Color.GRAY) if (highlightColor == Color.GRAY) {
highlightColor = Color.CYAN; highlightColor = Color.CYAN;
else } else {
highlightColor = Color.GRAY; highlightColor = Color.GRAY;
}
highlightTimer.setDelay(highlightTimer.getDelay()-1); highlightTimer.setDelay(highlightTimer.getDelay()-1);
repaint(); repaint();
} }
}); });
highlightTimer.start(); highlightTimer.start();
} }
}); });
@ -231,31 +234,34 @@ public abstract class Visualizer2D extends VisPlugin {
// Detect mouse events // Detect mouse events
canvas.addMouseListener(new MouseListener() { canvas.addMouseListener(new MouseListener() {
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) if (e.isPopupTrigger()) {
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y); myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
else if (SwingUtilities.isLeftMouseButton(e)){ } else if (SwingUtilities.isLeftMouseButton(e)){
//myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, false); //myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, false);
beginMoveRequest(e.getPoint().x, e.getPoint().y); beginMoveRequest(e.getPoint().x, e.getPoint().y);
} }
} }
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) if (e.isPopupTrigger()) {
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y); myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
else { } else {
myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, true); myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, true);
} }
} }
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (e.isPopupTrigger()) if (e.isPopupTrigger()) {
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y); myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
}
} }
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
if (e.isPopupTrigger()) if (e.isPopupTrigger()) {
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y); myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
}
} }
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (e.isPopupTrigger()) if (e.isPopupTrigger()) {
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y); myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
}
} }
}); });
@ -283,7 +289,7 @@ public abstract class Visualizer2D extends VisPlugin {
// Add menu action for clicking mote button // Add menu action for clicking mote button
addMoteMenuAction(new ButtonClickMoteMenuAction()); addMoteMenuAction(new ButtonClickMoteMenuAction());
try { try {
setSelected(true); setSelected(true);
} catch (java.beans.PropertyVetoException e) { } catch (java.beans.PropertyVetoException e) {
@ -293,7 +299,7 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Add new mote menu action. * Add new mote menu action.
* *
* @see MoteMenuAction * @see MoteMenuAction
* @param menuAction Menu action * @param menuAction Menu action
*/ */
@ -303,8 +309,9 @@ public abstract class Visualizer2D extends VisPlugin {
private void handlePopupRequest(final int x, final int y) { private void handlePopupRequest(final int x, final int y) {
final Vector<Mote> foundMotes = findMotesAtPosition(x, y); final Vector<Mote> foundMotes = findMotesAtPosition(x, y);
if (foundMotes == null || foundMotes.size() == 0) if (foundMotes == null || foundMotes.size() == 0) {
return; return;
}
JPopupMenu pickMoteMenu = new JPopupMenu(); JPopupMenu pickMoteMenu = new JPopupMenu();
pickMoteMenu.add(new JLabel("Select action:")); pickMoteMenu.add(new JLabel("Select action:"));
@ -312,10 +319,6 @@ public abstract class Visualizer2D extends VisPlugin {
// Add 'show mote plugins'-actions // Add 'show mote plugins'-actions
for (final Mote mote : foundMotes) { for (final Mote mote : foundMotes) {
final Point pos = new Point(canvas.getLocationOnScreen().x + x, canvas
.getLocationOnScreen().y
+ y);
pickMoteMenu.add(simulation.getGUI().createMotePluginsSubmenu(mote)); pickMoteMenu.add(simulation.getGUI().createMotePluginsSubmenu(mote));
} }
@ -345,8 +348,9 @@ public abstract class Visualizer2D extends VisPlugin {
private void beginMoveRequest(final int x, final int y) { private void beginMoveRequest(final int x, final int y) {
final Vector<Mote> foundMotes = findMotesAtPosition(x, y); final Vector<Mote> foundMotes = findMotesAtPosition(x, y);
if (foundMotes == null || foundMotes.size() == 0) if (foundMotes == null || foundMotes.size() == 0) {
return; return;
}
moteMoveBeginTime = System.currentTimeMillis(); moteMoveBeginTime = System.currentTimeMillis();
beginMoveRequest(foundMotes.get(0)); beginMoveRequest(foundMotes.get(0));
@ -360,7 +364,7 @@ public abstract class Visualizer2D extends VisPlugin {
private void handleMoveRequest(final int x, final int y, private void handleMoveRequest(final int x, final int y,
boolean wasJustReleased) { boolean wasJustReleased) {
if (!moteIsBeingMoved) { if (!moteIsBeingMoved) {
return; return;
} }
@ -374,7 +378,7 @@ public abstract class Visualizer2D extends VisPlugin {
// Stopped moving mote // Stopped moving mote
canvas.setCursor(Cursor.getDefaultCursor()); canvas.setCursor(Cursor.getDefaultCursor());
moteIsBeingMoved = false; moteIsBeingMoved = false;
Position newXYValues = transformPixelToPositon(new Point(x, y)); Position newXYValues = transformPixelToPositon(new Point(x, y));
if (moteMoveBeginTime <= 0 || System.currentTimeMillis() - moteMoveBeginTime > 300) { if (moteMoveBeginTime <= 0 || System.currentTimeMillis() - moteMoveBeginTime > 300) {
@ -382,7 +386,7 @@ public abstract class Visualizer2D extends VisPlugin {
+ "\nX=" + newXYValues.getXCoordinate() + "\nY=" + "\nX=" + newXYValues.getXCoordinate() + "\nY="
+ newXYValues.getYCoordinate() + "\nZ=" + newXYValues.getYCoordinate() + "\nZ="
+ moteToMove.getInterfaces().getPosition().getZCoordinate()); + moteToMove.getInterfaces().getPosition().getZCoordinate());
if (returnValue == JOptionPane.OK_OPTION) { if (returnValue == JOptionPane.OK_OPTION) {
moteToMove.getInterfaces().getPosition().setCoordinates( moteToMove.getInterfaces().getPosition().setCoordinates(
newXYValues.getXCoordinate(), newXYValues.getYCoordinate(), newXYValues.getXCoordinate(), newXYValues.getYCoordinate(),
@ -396,7 +400,7 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Returns all motes at given position. * Returns all motes at given position.
* *
* @param clickedX * @param clickedX
* X coordinate * X coordinate
* @param clickedY * @param clickedY
@ -428,8 +432,9 @@ public abstract class Visualizer2D extends VisPlugin {
motesFound.add(simulation.getMote(i)); motesFound.add(simulation.getMote(i));
} }
} }
if (motesFound.size() == 0) if (motesFound.size() == 0) {
return null; return null;
}
return motesFound; return motesFound;
} }
@ -437,13 +442,13 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Get colors a certain mote should be painted with. May be overridden to get * Get colors a certain mote should be painted with. May be overridden to get
* a different color scheme. * a different color scheme.
* *
* Normally this method returns an array of two colors, one for the state * Normally this method returns an array of two colors, one for the state
* (outer circle), the other for the type (inner circle). * (outer circle), the other for the type (inner circle).
* *
* If this method only returns one color, the entire mote will be painted * If this method only returns one color, the entire mote will be painted
* using that. * using that.
* *
* @param mote * @param mote
* Mote to paint * Mote to paint
* @return Color[] { Inner color, Outer color } * @return Color[] { Inner color, Outer color }
@ -479,7 +484,7 @@ public abstract class Visualizer2D extends VisPlugin {
g.setColor(moteColors[0]); g.setColor(moteColors[0]);
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
2 * MOTE_RADIUS); 2 * MOTE_RADIUS);
} }
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS, g.drawOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
@ -511,37 +516,43 @@ public abstract class Visualizer2D extends VisPlugin {
for (int i = 0; i < simulation.getMotesCount(); i++) { for (int i = 0; i < simulation.getMotesCount(); i++) {
motePos = simulation.getMote(i).getInterfaces().getPosition(); motePos = simulation.getMote(i).getInterfaces().getPosition();
if (motePos.getXCoordinate() < smallestXCoord) if (motePos.getXCoordinate() < smallestXCoord) {
smallestXCoord = motePos.getXCoordinate(); smallestXCoord = motePos.getXCoordinate();
}
if (motePos.getXCoordinate() > biggestXCoord) if (motePos.getXCoordinate() > biggestXCoord) {
biggestXCoord = motePos.getXCoordinate(); biggestXCoord = motePos.getXCoordinate();
}
if (motePos.getYCoordinate() < smallestYCoord) if (motePos.getYCoordinate() < smallestYCoord) {
smallestYCoord = motePos.getYCoordinate(); smallestYCoord = motePos.getYCoordinate();
}
if (motePos.getYCoordinate() > biggestYCoord) if (motePos.getYCoordinate() > biggestYCoord) {
biggestYCoord = motePos.getYCoordinate(); biggestYCoord = motePos.getYCoordinate();
}
} }
if ((biggestXCoord - smallestXCoord) == 0) { if ((biggestXCoord - smallestXCoord) == 0) {
factorXCoordToPixel = 1; factorXCoordToPixel = 1;
} else } else {
factorXCoordToPixel = ((double) canvas.getPreferredSize().width - 2 * CANVAS_BORDER_WIDTH) factorXCoordToPixel = ((double) canvas.getPreferredSize().width - 2 * CANVAS_BORDER_WIDTH)
/ (biggestXCoord - smallestXCoord); / (biggestXCoord - smallestXCoord);
}
if ((biggestYCoord - smallestYCoord) == 0) { if ((biggestYCoord - smallestYCoord) == 0) {
factorYCoordToPixel = 1; factorYCoordToPixel = 1;
} else } else {
factorYCoordToPixel = ((double) canvas.getPreferredSize().height - 2 * CANVAS_BORDER_WIDTH) factorYCoordToPixel = ((double) canvas.getPreferredSize().height - 2 * CANVAS_BORDER_WIDTH)
/ (biggestYCoord - smallestYCoord); / (biggestYCoord - smallestYCoord);
}
} }
/** /**
* Transforms a real-world position to a pixel which can be painted onto the * Transforms a real-world position to a pixel which can be painted onto the
* current sized canvas. * current sized canvas.
* *
* @param pos * @param pos
* Real-world position * Real-world position
* @return Pixel coordinates * @return Pixel coordinates
@ -554,7 +565,7 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Transforms real-world coordinates to a pixel which can be painted onto the * Transforms real-world coordinates to a pixel which can be painted onto the
* current sized canvas. * current sized canvas.
* *
* @param x Real world X * @param x Real world X
* @param y Real world Y * @param y Real world Y
* @param z Real world Z (ignored) * @param z Real world Z (ignored)
@ -566,7 +577,7 @@ public abstract class Visualizer2D extends VisPlugin {
/** /**
* Transforms a pixel coordinate to a real-world. Z-value will always be 0. * Transforms a pixel coordinate to a real-world. Z-value will always be 0.
* *
* @param pixelPos * @param pixelPos
* On-screen pixel coordinate * On-screen pixel coordinate
* @return Real world coordinate (z=0). * @return Real world coordinate (z=0).
@ -593,11 +604,11 @@ public abstract class Visualizer2D extends VisPlugin {
+ CANVAS_BORDER_WIDTH; + CANVAS_BORDER_WIDTH;
} }
private double factorXPixelToCoord(int xPixel) { private double factorXPixelToCoord(int xPixel) {
return ((double) (xPixel - CANVAS_BORDER_WIDTH) / factorXCoordToPixel) return ((xPixel - CANVAS_BORDER_WIDTH) / factorXCoordToPixel)
+ smallestXCoord; + smallestXCoord;
} }
private double factorYPixelToCoord(int yPixel) { private double factorYPixelToCoord(int yPixel) {
return ((double) (yPixel - CANVAS_BORDER_WIDTH) / factorYCoordToPixel) return ((yPixel - CANVAS_BORDER_WIDTH) / factorYCoordToPixel)
+ smallestYCoord; + smallestYCoord;
} }