removed public static JFrame frame variable. components should instead access the top parent container via getTopParentContainer()
This commit is contained in:
parent
27ac84d009
commit
6c8151b449
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights
|
||||
* reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 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
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* 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
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* 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;
|
||||
|
@ -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
|
||||
* same corecomm class without restarting the JVM and thus the entire
|
||||
* simulation.
|
||||
*
|
||||
*
|
||||
* Each implemented CoreComm class needs read access to the following core
|
||||
* variables:
|
||||
* <ul>
|
||||
|
@ -65,7 +65,7 @@ import se.sics.cooja.dialogs.MessageList;
|
|||
* <li>getReferenceAbsAddr()
|
||||
* <li>getMemory(int start, int length, byte[] mem)
|
||||
* <li>setMemory(int start, int length, byte[] mem)
|
||||
*
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
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
|
||||
* simulator may have to be restarted.
|
||||
*
|
||||
*
|
||||
* @return True if any library has been loaded this session
|
||||
*/
|
||||
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 file, named the same as an earlier loaded and removed file, can't
|
||||
* be loaded either.
|
||||
*
|
||||
*
|
||||
* @param libraryFile
|
||||
* Library file
|
||||
* @return True if a library has already been loaded from the given file's
|
||||
* filename
|
||||
*/
|
||||
public static boolean hasLibraryFileBeenLoaded(File libraryFile) {
|
||||
for (File loadedFile : coreCommFiles)
|
||||
for (File loadedFile : coreCommFiles) {
|
||||
if (loadedFile != null
|
||||
&& loadedFile.getName().equals(libraryFile.getName()))
|
||||
&& loadedFile.getName().equals(libraryFile.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name of next free core communicator class. If null is
|
||||
* returned, no classes are available.
|
||||
*
|
||||
*
|
||||
* @return Class name
|
||||
*/
|
||||
public static String getAvailableClassName() {
|
||||
|
@ -119,7 +121,7 @@ public abstract class CoreComm {
|
|||
/**
|
||||
* Generates new source file by reading default source template and replacing
|
||||
* the class name field.
|
||||
*
|
||||
*
|
||||
* @param className
|
||||
* Java class name (without extension)
|
||||
* @throws MoteTypeCreationException
|
||||
|
@ -151,8 +153,9 @@ public abstract class CoreComm {
|
|||
destFilename = className + ".java";
|
||||
|
||||
File dir = new File("se/sics/cooja/corecomm");
|
||||
if (!dir.exists())
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
sourceFileWriter = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream("se/sics/cooja/corecomm/" + destFilename)));
|
||||
|
@ -168,10 +171,12 @@ public abstract class CoreComm {
|
|||
templateFileReader.close();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (sourceFileWriter != null)
|
||||
if (sourceFileWriter != null) {
|
||||
sourceFileWriter.close();
|
||||
if (templateFileReader != null)
|
||||
}
|
||||
if (templateFileReader != null) {
|
||||
templateFileReader.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
|
||||
|
@ -181,16 +186,17 @@ public abstract class CoreComm {
|
|||
}
|
||||
|
||||
File genFile = new File("se/sics/cooja/corecomm/" + destFilename);
|
||||
if (genFile.exists())
|
||||
if (genFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
||||
throw new MoteTypeCreationException(
|
||||
"Could not generate corecomm source file: " + className + ".java");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles Java class.
|
||||
*
|
||||
*
|
||||
* @param className
|
||||
* Java class name (without extension)
|
||||
* @throws MoteTypeCreationException
|
||||
|
@ -222,8 +228,9 @@ public abstract class CoreComm {
|
|||
}
|
||||
p.waitFor();
|
||||
|
||||
if (classFile.exists())
|
||||
if (classFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try including cooja.jar
|
||||
cmd = new String[] {
|
||||
|
@ -246,8 +253,9 @@ public abstract class CoreComm {
|
|||
}
|
||||
p.waitFor();
|
||||
|
||||
if (classFile.exists())
|
||||
if (classFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
MoteTypeCreationException exception = (MoteTypeCreationException) new MoteTypeCreationException(
|
||||
|
@ -271,7 +279,7 @@ public abstract class CoreComm {
|
|||
|
||||
/**
|
||||
* Loads given Java class file from disk.
|
||||
*
|
||||
*
|
||||
* @param classFile
|
||||
* Java class (without extension)
|
||||
* @return Loaded class
|
||||
|
@ -282,8 +290,9 @@ public abstract class CoreComm {
|
|||
throws MoteTypeCreationException {
|
||||
Class loadedClass = null;
|
||||
try {
|
||||
ClassLoader urlClassLoader = new URLClassLoader(new URL[] { new File(".")
|
||||
.toURL() }, CoreComm.class.getClassLoader());
|
||||
ClassLoader urlClassLoader = new URLClassLoader(
|
||||
new URL[] { new File(".").toURI().toURL() },
|
||||
CoreComm.class.getClassLoader());
|
||||
loadedClass = urlClassLoader.loadClass("se.sics.cooja.corecomm."
|
||||
+ className);
|
||||
|
||||
|
@ -296,9 +305,10 @@ public abstract class CoreComm {
|
|||
"Could not load corecomm class file: " + className + ".class")
|
||||
.initCause(e);
|
||||
}
|
||||
if (loadedClass == null)
|
||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
||||
if (loadedClass == null) {
|
||||
throw new MoteTypeCreationException(
|
||||
"Could not load corecomm class file: " + className + ".class");
|
||||
}
|
||||
|
||||
return loadedClass;
|
||||
}
|
||||
|
@ -306,7 +316,7 @@ public abstract class CoreComm {
|
|||
/**
|
||||
* Create and return an instance of the core communicator identified by
|
||||
* className. This core communicator will load the native library libFile.
|
||||
*
|
||||
*
|
||||
* @param className
|
||||
* Class name of core communicator
|
||||
* @param libFile
|
||||
|
@ -353,14 +363,14 @@ public abstract class CoreComm {
|
|||
/**
|
||||
* Returns absolute memory location of the core variable referenceVar. Used to
|
||||
* get offset between relative and absolute memory addresses.
|
||||
*
|
||||
*
|
||||
* @return Absolute memory address
|
||||
*/
|
||||
public abstract int getReferenceAbsAddr();
|
||||
|
||||
/**
|
||||
* Fills an byte array with memory segment identified by start and length.
|
||||
*
|
||||
*
|
||||
* @param start
|
||||
* Start address of segment
|
||||
* @param length
|
||||
|
@ -372,7 +382,7 @@ public abstract class CoreComm {
|
|||
|
||||
/**
|
||||
* Overwrites a memory segment identified by start and length.
|
||||
*
|
||||
*
|
||||
* @param start
|
||||
* Start address of segment
|
||||
* @param length
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* 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;
|
||||
|
@ -470,7 +470,7 @@ public class Simulation extends Observable implements Runnable {
|
|||
// Show configure simulation dialog
|
||||
boolean createdOK = false;
|
||||
if (visAvailable) {
|
||||
createdOK = CreateSimDialog.showDialog(GUI.frame, this);
|
||||
createdOK = CreateSimDialog.showDialog(GUI.getTopParentContainer(), this);
|
||||
} else {
|
||||
createdOK = true;
|
||||
}
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
|
@ -202,10 +203,10 @@ public class ContikiMoteType implements MoteType {
|
|||
return new ContikiMote(this, simulation);
|
||||
}
|
||||
|
||||
public boolean configureAndInit(JFrame parentFrame, Simulation simulation,
|
||||
public boolean configureAndInit(Container parentContainer, Simulation simulation,
|
||||
boolean visAvailable) throws MoteTypeCreationException {
|
||||
if (visAvailable) {
|
||||
return ContikiMoteTypeDialog.showDialog(parentFrame, simulation, this);
|
||||
return ContikiMoteTypeDialog.showDialog(parentContainer, simulation, this);
|
||||
} else {
|
||||
|
||||
// Create temp output directory if not already exists
|
||||
|
@ -1401,7 +1402,7 @@ public class ContikiMoteType implements MoteType {
|
|||
}
|
||||
|
||||
mySimulation = simulation;
|
||||
boolean createdOK = configureAndInit(GUI.frame, simulation, visAvailable);
|
||||
boolean createdOK = configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable);
|
||||
return createdOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -116,19 +116,29 @@ public class ContikiMoteTypeDialog extends JDialog {
|
|||
* Shows a dialog for configuring a Contiki mote type and compiling the shared
|
||||
* library it uses.
|
||||
*
|
||||
* @param parentFrame
|
||||
* Parent frame for dialog
|
||||
* @param parentContainer
|
||||
* Parent container for dialog
|
||||
* @param simulation
|
||||
* Simulation holding (or that will hold) mote type
|
||||
* @param moteTypeToConfigure
|
||||
* 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) {
|
||||
|
||||
final ContikiMoteTypeDialog myDialog = new ContikiMoteTypeDialog(
|
||||
parentFrame);
|
||||
ContikiMoteTypeDialog myDialog = null;
|
||||
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.myMoteType = moteTypeToConfigure;
|
||||
|
@ -403,7 +413,7 @@ public class ContikiMoteTypeDialog extends JDialog {
|
|||
|
||||
// Set position and focus of dialog
|
||||
myDialog.pack();
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
myDialog.setLocationRelativeTo(parentContainer);
|
||||
myDialog.textDescription.requestFocus();
|
||||
myDialog.textDescription.select(0, myDialog.textDescription.getText()
|
||||
.length());
|
||||
|
@ -428,9 +438,20 @@ public class ContikiMoteTypeDialog extends JDialog {
|
|||
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) {
|
||||
super(frame, "Add Mote Type", true);
|
||||
super(frame, "Add Mote Type", ModalityType.TOOLKIT_MODAL);
|
||||
setupDialog();
|
||||
}
|
||||
|
||||
private void setupDialog() {
|
||||
myDialog = this;
|
||||
|
||||
JLabel label;
|
||||
|
@ -2513,8 +2534,8 @@ public class ContikiMoteTypeDialog extends JDialog {
|
|||
// Find and load the mote interface classes
|
||||
for (String moteInterface : moteInterfaces) {
|
||||
try {
|
||||
Class<? extends MoteInterface> newMoteInterfaceClass = classLoader
|
||||
.loadClass(moteInterface).asSubclass(MoteInterface.class);
|
||||
Class<? extends MoteInterface> newMoteInterfaceClass =
|
||||
myGUI.tryLoadClass(this, MoteInterface.class, moteInterface);
|
||||
moteIntfClasses.add(newMoteInterfaceClass);
|
||||
// logger.info("Loaded mote interface: " + newMoteInterfaceClass);
|
||||
} catch (Exception ce) {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -74,19 +74,30 @@ public class AddMoteDialog extends JDialog {
|
|||
* Shows a dialog which enables a user to create and add motes of the given
|
||||
* type.
|
||||
*
|
||||
* @param parentFrame
|
||||
* Parent frame for dialog
|
||||
* @param parentContainer
|
||||
* Parent container for dialog
|
||||
* @param simulation
|
||||
* Simulation
|
||||
* @param moteType
|
||||
* Mote type
|
||||
* @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) {
|
||||
|
||||
AddMoteDialog myDialog = new AddMoteDialog(parentFrame, simulation, moteType);
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
AddMoteDialog myDialog = null;
|
||||
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();
|
||||
|
||||
if (myDialog != null) {
|
||||
|
@ -96,7 +107,19 @@ public class AddMoteDialog extends JDialog {
|
|||
}
|
||||
|
||||
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.simulation = simulation;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -70,12 +70,22 @@ public class CreateSimDialog extends JDialog {
|
|||
/**
|
||||
* Shows a dialog for configuring a simulation.
|
||||
*
|
||||
* @param parentFrame Parent frame for dialog
|
||||
* @param parentContainer Parent container for dialog
|
||||
* @param simulationToConfigure Simulation to configure
|
||||
* @return True if simulation configured correctly
|
||||
*/
|
||||
public static boolean showDialog(Frame parentFrame, Simulation simulationToConfigure) {
|
||||
final CreateSimDialog myDialog = new CreateSimDialog(parentFrame, simulationToConfigure.getGUI());
|
||||
public static boolean showDialog(Container parentContainer, Simulation simulationToConfigure) {
|
||||
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.addWindowListener(new WindowListener() {
|
||||
|
@ -149,7 +159,7 @@ public class CreateSimDialog extends JDialog {
|
|||
|
||||
|
||||
// Set position and focus of dialog
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
myDialog.setLocationRelativeTo(parentContainer);
|
||||
myDialog.title.requestFocus();
|
||||
myDialog.title.select(0, myDialog.title.getText().length());
|
||||
|
||||
|
@ -172,9 +182,20 @@ public class CreateSimDialog extends JDialog {
|
|||
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) {
|
||||
super(frame, "Create new simulation", true);
|
||||
super(frame, "Create new simulation", ModalityType.TOOLKIT_MODAL);
|
||||
setupDialog(gui);
|
||||
}
|
||||
|
||||
private void setupDialog(GUI gui) {
|
||||
myDialog = this;
|
||||
myGUI = gui;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -61,21 +61,43 @@ public class ExternalToolsDialog extends JDialog {
|
|||
/**
|
||||
* Creates a dialog for viewing/editing external tools settings.
|
||||
*
|
||||
* @param parentFrame
|
||||
* Parent frame for dialog
|
||||
* @param parentContainer
|
||||
* Parent container for dialog
|
||||
*/
|
||||
public static void showDialog(Frame parentFrame) {
|
||||
ExternalToolsDialog myDialog = new ExternalToolsDialog(parentFrame);
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
public static void showDialog(Container parentContainer) {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
super(frame, "Edit Settings", true);
|
||||
super(frame, "Edit Settings", ModalityType.TOOLKIT_MODAL);
|
||||
setupDialog();
|
||||
}
|
||||
|
||||
private void setupDialog() {
|
||||
myDialog = this;
|
||||
|
||||
JLabel label;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -63,30 +63,37 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
private List changableProjectsList = new List();
|
||||
private List fixedProjectsList = null;
|
||||
private Vector<File> changableProjects = null;
|
||||
private Vector<File> fixedProjects = null;
|
||||
|
||||
private ProjectDirectoriesDialog myDialog;
|
||||
private Frame myParentFrame = null;
|
||||
private Dialog myParentDialog = null;
|
||||
|
||||
/**
|
||||
* Allows user to alter the given project directories list by adding new,
|
||||
* reordering or removing project directories. Only the changable project directories
|
||||
* can be altered.
|
||||
*
|
||||
* @param parentFrame
|
||||
* Parent frame
|
||||
* @param parentContainer
|
||||
* Parent container
|
||||
* @param changableProjects
|
||||
* Changeable project directories
|
||||
* @param fixedProjects
|
||||
* Fixed project directory
|
||||
* @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) {
|
||||
ProjectDirectoriesDialog myDialog = new ProjectDirectoriesDialog(parentFrame,
|
||||
changableProjects, fixedProjects);
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
|
||||
ProjectDirectoriesDialog myDialog = null;
|
||||
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) {
|
||||
myDialog.setVisible(true);
|
||||
|
@ -123,19 +130,23 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
|
||||
private ProjectDirectoriesDialog(Frame frame, Vector<File> changableProjects,
|
||||
Vector<File> fixedProjects) {
|
||||
super(frame, "Manage Project Directories", true);
|
||||
myParentFrame = frame;
|
||||
init(changableProjects, fixedProjects);
|
||||
super(frame, "Manage Project Directories", ModalityType.APPLICATION_MODAL);
|
||||
setupDialog(changableProjects, fixedProjects);
|
||||
}
|
||||
|
||||
private ProjectDirectoriesDialog(Dialog dialog, Vector<File> changableProjects,
|
||||
Vector<File> fixedProjects) {
|
||||
super(dialog, "Manage Project Directories", true);
|
||||
myParentDialog = dialog;
|
||||
init(changableProjects, fixedProjects);
|
||||
super(dialog, "Manage Project Directories", ModalityType.APPLICATION_MODAL);
|
||||
setupDialog(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;
|
||||
|
||||
JPanel mainPane = new JPanel();
|
||||
|
@ -339,11 +350,7 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
}
|
||||
|
||||
// Show merged configuration
|
||||
if (myParentFrame != null) {
|
||||
ConfigViewer.showDialog(myParentFrame, config);
|
||||
} else {
|
||||
ConfigViewer.showDialog(myParentDialog, config);
|
||||
}
|
||||
ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);
|
||||
}
|
||||
});
|
||||
addRemovePane.add(button);
|
||||
|
@ -353,10 +360,10 @@ public class ProjectDirectoriesDialog extends JDialog {
|
|||
button = new JButton("Add manually");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ProjectDirectoryInputDialog pathDialog = new ProjectDirectoryInputDialog(myParentFrame);
|
||||
ProjectDirectoryInputDialog pathDialog = new ProjectDirectoryInputDialog(ProjectDirectoriesDialog.this);
|
||||
pathDialog.pack();
|
||||
|
||||
pathDialog.setLocationRelativeTo(myParentFrame);
|
||||
pathDialog.setLocationRelativeTo(ProjectDirectoriesDialog.this);
|
||||
pathDialog.setVisible(true);
|
||||
|
||||
File projectPath = pathDialog.getProjectDirectory();
|
||||
|
|
|
@ -21,9 +21,20 @@ class ProjectDirectoryInputDialog extends JDialog implements ActionListener, Pro
|
|||
private String buttonAdd = "Add";
|
||||
private String buttonCancel = "Cancel";
|
||||
|
||||
public ProjectDirectoryInputDialog(Frame parent) {
|
||||
super(parent, true);
|
||||
public ProjectDirectoryInputDialog(Window window) {
|
||||
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");
|
||||
|
||||
textField = new JTextField(10);
|
||||
|
@ -37,7 +48,7 @@ class ProjectDirectoryInputDialog extends JDialog implements ActionListener, Pro
|
|||
public void changedUpdate(DocumentEvent e) {
|
||||
pathChanged();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Object[] objects = {"Enter path to project directory", textField};
|
||||
Object[] options = {buttonAdd, buttonCancel};
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -40,7 +41,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
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
|
||||
* created the createInitialMemory() method should be called to get this initial
|
||||
* memory for the mote.
|
||||
*
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
@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
|
||||
* type will have the interfaces specified in the given mote interface class
|
||||
* list.
|
||||
*
|
||||
*
|
||||
* @param libFile
|
||||
* Library file to load
|
||||
* @param objFile
|
||||
|
@ -106,21 +106,22 @@ public class MantisMoteType implements MoteType {
|
|||
*/
|
||||
public MantisMoteType(File libFile, File objFile,
|
||||
Vector<Class<? extends MoteInterface>> moteInterfaceClasses) {
|
||||
if (!doInit(libFile, objFile, moteInterfaceClasses))
|
||||
if (!doInit(libFile, objFile, moteInterfaceClasses)) {
|
||||
logger.fatal("Mantis mote type creation failed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* the constructor with an identifier argument, but not from the standard
|
||||
* constructor. This method may be called from the simulator when loading
|
||||
* configuration files, and the libraries must be recompiled.
|
||||
*
|
||||
*
|
||||
* This method allocates a core communicator, loads the Mantis library file,
|
||||
* creates variable name to address mappings and finally creates the Mantis
|
||||
* mote initial memory.
|
||||
*
|
||||
*
|
||||
* @param libFile Library file
|
||||
* @param objFile Object file
|
||||
* @param moteInterfaceClasses Mote interface classes
|
||||
|
@ -131,7 +132,7 @@ public class MantisMoteType implements MoteType {
|
|||
myObjectFilename = objFile.getAbsolutePath();
|
||||
myIdentifier = libFile.getName();
|
||||
myDescription = libFile.getAbsolutePath();
|
||||
|
||||
|
||||
// Allocate core communicator class
|
||||
libraryClassName = CoreComm.getAvailableClassName();
|
||||
try {
|
||||
|
@ -195,7 +196,7 @@ public class MantisMoteType implements MoteType {
|
|||
logger.fatal("BSS section size parsing failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Get offset between relative and absolute addresses
|
||||
offsetRelToAbs = myCoreComm.getReferenceAbsAddr() - (Integer) varAddresses.get("referenceVar");
|
||||
|
||||
|
@ -209,17 +210,17 @@ public class MantisMoteType implements MoteType {
|
|||
myInitialMemory = new SectionMoteMemory(varAddresses);
|
||||
myInitialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
myInitialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
|
||||
|
||||
this.moteInterfaceClasses = moteInterfaceClasses;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* it's memory from here.
|
||||
*
|
||||
*
|
||||
* @return Initial memory of a mote type
|
||||
*/
|
||||
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
|
||||
* instead via MantisMote.getMemory().
|
||||
*
|
||||
*
|
||||
* @param mem
|
||||
* Memory to set
|
||||
*/
|
||||
|
@ -246,7 +247,7 @@ public class MantisMoteType implements MoteType {
|
|||
int startAddr = mem.getStartAddrOfSection(i);
|
||||
int size = mem.getSizeOfSection(i);
|
||||
byte[] data = mem.getDataOfSection(i);
|
||||
|
||||
|
||||
getCoreMemory(startAddr + offsetRelToAbs,
|
||||
size, data);
|
||||
}
|
||||
|
@ -255,7 +256,7 @@ public class MantisMoteType implements MoteType {
|
|||
/**
|
||||
* Copy given memory to the Mantis system. This should not be used directly,
|
||||
* but instead via MantisMote.setMemory().
|
||||
*
|
||||
*
|
||||
* @param mem
|
||||
* New memory
|
||||
*/
|
||||
|
@ -277,7 +278,7 @@ public class MantisMoteType implements MoteType {
|
|||
|
||||
/**
|
||||
* Returns all mote interfaces of this mote type
|
||||
*
|
||||
*
|
||||
* @return All mote interfaces
|
||||
*/
|
||||
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
|
||||
|
@ -296,7 +297,7 @@ public class MantisMoteType implements MoteType {
|
|||
return myIdentifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
public void setIdentifier(String identifier) {
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
|
@ -360,9 +361,11 @@ public class MantisMoteType implements MoteType {
|
|||
return new MantisMote(this, mySimulation);
|
||||
}
|
||||
|
||||
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable) {
|
||||
if (!visAvailable) logger.fatal(">>>>>>> NOT IMPLEMENTED");
|
||||
return MantisMoteTypeDialog.showDialog(parentFrame, simulation, this);
|
||||
public boolean configureAndInit(Container parentContainer, Simulation simulation, boolean visAvailable) {
|
||||
if (!visAvailable) {
|
||||
logger.fatal(">>>>>>> NOT IMPLEMENTED");
|
||||
}
|
||||
return MantisMoteTypeDialog.showDialog(parentContainer, simulation, this);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -44,15 +44,15 @@ import se.sics.cooja.dialogs.MessageList;
|
|||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
* and the user presses OK.
|
||||
*
|
||||
*
|
||||
* This dialog uses external tools to scan for sources and compile libraries.
|
||||
*
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class MantisMoteTypeDialog extends JDialog {
|
||||
|
@ -74,12 +74,12 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
|
||||
private JTextField textID, textOutputFiles, textDescription, textMantisBinary;
|
||||
private JButton createButton, compileButton;
|
||||
|
||||
|
||||
private File objFile = null;
|
||||
private File workingDir = null;
|
||||
private File libFile = null;
|
||||
private File srcFile = null;
|
||||
|
||||
|
||||
private Vector<Class<? extends MoteInterface>> moteInterfaceClasses = null;
|
||||
|
||||
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.
|
||||
*
|
||||
* @param parentFrame
|
||||
* Parent frame for dialog
|
||||
*
|
||||
* @param parentContainer
|
||||
* Parent container for dialog
|
||||
* @param simulation
|
||||
* Simulation holding (or that will hold) mote type
|
||||
* @param moteTypeToConfigure
|
||||
* Mote type to configure
|
||||
* @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) {
|
||||
|
||||
final MantisMoteTypeDialog myDialog = new MantisMoteTypeDialog(
|
||||
parentFrame);
|
||||
MantisMoteTypeDialog myDialog = null;
|
||||
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.allOtherTypes = simulation.getMoteTypes();
|
||||
|
@ -160,7 +169,7 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
myDialog.moteInterfaceClasses = new Vector<Class<? extends MoteInterface>>();
|
||||
for (String moteInterface : moteInterfaces) {
|
||||
try {
|
||||
Class<? extends MoteInterface> newMoteInterfaceClass =
|
||||
Class<? extends MoteInterface> newMoteInterfaceClass =
|
||||
simulation.getGUI().tryLoadClass(simulation.getGUI(), MoteInterface.class, moteInterface);
|
||||
myDialog.moteInterfaceClasses.add(newMoteInterfaceClass);
|
||||
/*logger.info("Loaded Mantis mote interface: " + newMoteInterfaceClass);*/
|
||||
|
@ -172,7 +181,7 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
|
||||
// Set position and focus of dialog
|
||||
myDialog.pack();
|
||||
myDialog.setLocationRelativeTo(parentFrame);
|
||||
myDialog.setLocationRelativeTo(parentContainer);
|
||||
myDialog.textDescription.requestFocus();
|
||||
myDialog.textDescription.select(0, myDialog.textDescription.getText().length());
|
||||
myDialog.pathsWereUpdated();
|
||||
|
@ -185,9 +194,20 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
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) {
|
||||
super(frame, "Configure Mantis Mote Type", true);
|
||||
super(frame, "Configure Mantis Mote Type", ModalityType.TOOLKIT_MODAL);
|
||||
setupDialog();
|
||||
}
|
||||
|
||||
private void setupDialog() {
|
||||
myDialog = this;
|
||||
|
||||
JLabel label;
|
||||
|
@ -361,8 +381,9 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
if (compilationThread != null && compilationThread.isAlive()) {
|
||||
compilationThread.interrupt();
|
||||
}
|
||||
if (progressDialog != null && progressDialog.isDisplayable())
|
||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
||||
progressDialog.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -385,30 +406,31 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
if (srcFile.exists()) {
|
||||
srcFile.delete();
|
||||
}
|
||||
|
||||
|
||||
if (srcFile.exists()) {
|
||||
throw new Exception("could not remove old source file");
|
||||
}
|
||||
|
||||
|
||||
generateSourceFile(srcFile);
|
||||
|
||||
|
||||
if (!srcFile.exists()) {
|
||||
throw new Exception("source file not created");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
libraryCreatedOK = false;
|
||||
progressBar.setBackground(Color.ORANGE);
|
||||
if (e.getMessage() != null)
|
||||
if (e.getMessage() != null) {
|
||||
progressBar.setString("source file generation failed: " + e.getMessage());
|
||||
else
|
||||
} else {
|
||||
progressBar.setString("source file generation failed");
|
||||
|
||||
}
|
||||
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setValue(0);
|
||||
createButton.setEnabled(libraryCreatedOK);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Test compile shared library
|
||||
progressBar.setString("..compiling..");
|
||||
|
||||
|
@ -418,7 +440,7 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
|
||||
compilationThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
compilationSucceded =
|
||||
compilationSucceded =
|
||||
MantisMoteTypeDialog.compileLibrary(
|
||||
libFile,
|
||||
objFile,
|
||||
|
@ -445,8 +467,9 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
libraryCreatedOK = false;
|
||||
} else {
|
||||
libraryCreatedOK = true;
|
||||
if (!libFile.exists())
|
||||
if (!libFile.exists()) {
|
||||
libraryCreatedOK = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (libraryCreatedOK) {
|
||||
|
@ -467,7 +490,7 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
/**
|
||||
* Generates new source file by reading default source template and replacing
|
||||
* certain field in order to be loadable from given Java class.
|
||||
*
|
||||
*
|
||||
* @param outputFile Source file to create
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -500,7 +523,7 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
}
|
||||
|
||||
sourceFile = new BufferedReader(reader);
|
||||
|
||||
|
||||
destFile = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(outputFile)));
|
||||
|
||||
|
@ -515,10 +538,12 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
sourceFile.close();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
if (destFile != null)
|
||||
if (destFile != null) {
|
||||
destFile.close();
|
||||
if (sourceFile != null)
|
||||
}
|
||||
if (sourceFile != null) {
|
||||
sourceFile.close();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
}
|
||||
|
||||
|
@ -526,10 +551,10 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles a mote type shared library using the standard Mantis makefile.
|
||||
*
|
||||
*
|
||||
* @param libFile Library file to create
|
||||
* @param binFile Binary file to link against
|
||||
* @param sourceFile Source file to compile
|
||||
|
@ -545,42 +570,48 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
|
||||
// Check needed files
|
||||
if (!workingDir.exists()) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad paths");
|
||||
}
|
||||
logger.fatal("Working directory does not exist");
|
||||
return false;
|
||||
}
|
||||
if (!workingDir.isDirectory()) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad paths");
|
||||
}
|
||||
logger.fatal("Working directory is not a directory");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (libFile.exists()) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad output filenames");
|
||||
}
|
||||
logger.fatal("Library already exists");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sourceFile.exists()) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad dependency files");
|
||||
}
|
||||
logger.fatal("Source file not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!binFile.exists()) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad dependency files");
|
||||
}
|
||||
logger.fatal("Link object file not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CoreComm.hasLibraryFileBeenLoaded(libFile)) {
|
||||
if (errorStream != null)
|
||||
if (errorStream != null) {
|
||||
errorStream.println("Bad output filenames");
|
||||
}
|
||||
logger.fatal("A library has already been loaded with the same name before");
|
||||
return false;
|
||||
}
|
||||
|
@ -606,8 +637,9 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
String readLine;
|
||||
try {
|
||||
while ((readLine = input.readLine()) != null) {
|
||||
if (outputStream != null && readLine != null)
|
||||
if (outputStream != null && readLine != null) {
|
||||
outputStream.println(readLine);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("Error while reading from process");
|
||||
|
@ -620,8 +652,9 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
String readLine;
|
||||
try {
|
||||
while ((readLine = err.readLine()) != null) {
|
||||
if (errorStream != null && readLine != null)
|
||||
if (errorStream != null && readLine != null) {
|
||||
errorStream.println(readLine);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("Error while reading from process");
|
||||
|
@ -711,39 +744,42 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
} else {
|
||||
textOutputFiles.setText("");
|
||||
}
|
||||
|
||||
|
||||
createButton.setEnabled(libraryCreatedOK = false);
|
||||
compileButton.setEnabled(settingsOK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class MoteTypeEventHandler
|
||||
implements
|
||||
ActionListener,
|
||||
DocumentListener {
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (myDialog.isVisible())
|
||||
if (myDialog.isVisible()) {
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
pathsWereUpdated();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (myDialog.isVisible())
|
||||
if (myDialog.isVisible()) {
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
pathsWereUpdated();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (myDialog.isVisible())
|
||||
if (myDialog.isVisible()) {
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
pathsWereUpdated();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getActionCommand().equals("cancel")) {
|
||||
|
@ -783,8 +819,9 @@ public class MantisMoteTypeDialog extends JDialog {
|
|||
}
|
||||
createButton.setEnabled(libraryCreatedOK = false);
|
||||
pathsWereUpdated();
|
||||
} else
|
||||
} else {
|
||||
logger.warn("Unhandled action: " + e.getActionCommand());
|
||||
}
|
||||
|
||||
createButton.setEnabled(libraryCreatedOK = false);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Swedish Institute of Computer Science. All rights
|
||||
* reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 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
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* 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
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* 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;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
|
@ -62,7 +63,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
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) {
|
||||
// Create unique identifier
|
||||
|
@ -104,7 +105,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
|
||||
/**
|
||||
* Returns all mote interfaces of this mote type
|
||||
*
|
||||
*
|
||||
* @return All mote interfaces
|
||||
*/
|
||||
public Vector<Class<? extends MoteInterface>> getMoteInterfaces() {
|
||||
|
@ -113,7 +114,7 @@ public abstract class AbstractApplicationMoteType implements MoteType {
|
|||
|
||||
/**
|
||||
* Set mote interfaces of this mote type
|
||||
*
|
||||
*
|
||||
* @param moteInterfaces
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
package se.sics.cooja.motes;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
|
@ -76,7 +77,7 @@ public class DisturberMoteType implements MoteType {
|
|||
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) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,12 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -61,7 +62,7 @@ public class DummyMoteType implements MoteType {
|
|||
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) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -155,7 +155,7 @@ public class LogListener extends VisPlugin {
|
|||
public void actionPerformed(ActionEvent ev) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
|
||||
int returnVal = fc.showSaveDialog(GUI.frame);
|
||||
int returnVal = fc.showSaveDialog(GUI.getTopParentContainer());
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File saveFile = fc.getSelectedFile();
|
||||
|
||||
|
@ -163,9 +163,8 @@ public class LogListener extends VisPlugin {
|
|||
String s1 = "Overwrite";
|
||||
String s2 = "Cancel";
|
||||
Object[] options = { s1, s2 };
|
||||
int n = JOptionPane
|
||||
.showOptionDialog(
|
||||
GUI.frame,
|
||||
int n = JOptionPane.showOptionDialog(
|
||||
GUI.getTopParentContainer(),
|
||||
"A file with the same name already exists.\nDo you want to remove it?",
|
||||
"Overwrite existing file?", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, options, s1);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -45,17 +45,17 @@ import se.sics.cooja.interfaces.*;
|
|||
/**
|
||||
* Visualizer2D is an abstract mote visualizer for simulations. All motes are
|
||||
* painted in the XY-plane, as seen from positive Z axis.
|
||||
*
|
||||
*
|
||||
* An implementation of this class must colorize the different motes, each mote
|
||||
* has two different colors; inner and outer.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* implementation may also register its own actions to be accessed from this
|
||||
* menu.
|
||||
*
|
||||
*
|
||||
* A Visualizer2D observers both the simulation and all mote positions.
|
||||
*
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
@ClassDescription("2D Mote Visualizer")
|
||||
|
@ -89,7 +89,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
private Mote highlightedMote = null;
|
||||
private Color highlightColor = Color.GRAY;
|
||||
private Timer highlightTimer = null;
|
||||
|
||||
|
||||
public interface MoteMenuAction {
|
||||
public boolean isEnabled(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.
|
||||
*
|
||||
*
|
||||
* @param simulationToVisualize
|
||||
* Simulation to visualize
|
||||
*/
|
||||
|
@ -188,12 +188,14 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
// Detect mote highligts
|
||||
myGUI.addMoteHighligtObserver(moteHighligtObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
if (!(obj instanceof Mote))
|
||||
if (!(obj instanceof Mote)) {
|
||||
return;
|
||||
|
||||
if (highlightTimer != null && highlightTimer.isRunning())
|
||||
}
|
||||
|
||||
if (highlightTimer != null && highlightTimer.isRunning()) {
|
||||
highlightTimer.stop();
|
||||
|
||||
}
|
||||
|
||||
highlightTimer = new Timer(100, null);
|
||||
highlightedMote = (Mote) obj;
|
||||
highlightTimer.addActionListener(new ActionListener() {
|
||||
|
@ -207,15 +209,16 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
}
|
||||
|
||||
// Toggle color
|
||||
if (highlightColor == Color.GRAY)
|
||||
if (highlightColor == Color.GRAY) {
|
||||
highlightColor = Color.CYAN;
|
||||
else
|
||||
highlightColor = Color.GRAY;
|
||||
} else {
|
||||
highlightColor = Color.GRAY;
|
||||
}
|
||||
highlightTimer.setDelay(highlightTimer.getDelay()-1);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
highlightTimer.start();
|
||||
highlightTimer.start();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -231,31 +234,34 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
// Detect mouse events
|
||||
canvas.addMouseListener(new MouseListener() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
if (e.isPopupTrigger()) {
|
||||
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);
|
||||
beginMoveRequest(e.getPoint().x, e.getPoint().y);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
if (e.isPopupTrigger()) {
|
||||
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
|
||||
else {
|
||||
} else {
|
||||
myPlugin.handleMoveRequest(e.getPoint().x, e.getPoint().y, true);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
if (e.isPopupTrigger()) {
|
||||
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
|
||||
}
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
if (e.isPopupTrigger()) {
|
||||
myPlugin.handlePopupRequest(e.getPoint().x, e.getPoint().y);
|
||||
}
|
||||
}
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.isPopupTrigger())
|
||||
if (e.isPopupTrigger()) {
|
||||
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
|
||||
addMoteMenuAction(new ButtonClickMoteMenuAction());
|
||||
|
||||
|
||||
try {
|
||||
setSelected(true);
|
||||
} catch (java.beans.PropertyVetoException e) {
|
||||
|
@ -293,7 +299,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
|
||||
/**
|
||||
* Add new mote menu action.
|
||||
*
|
||||
*
|
||||
* @see MoteMenuAction
|
||||
* @param menuAction Menu action
|
||||
*/
|
||||
|
@ -303,8 +309,9 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
|
||||
private void handlePopupRequest(final int x, final int y) {
|
||||
final Vector<Mote> foundMotes = findMotesAtPosition(x, y);
|
||||
if (foundMotes == null || foundMotes.size() == 0)
|
||||
if (foundMotes == null || foundMotes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
JPopupMenu pickMoteMenu = new JPopupMenu();
|
||||
pickMoteMenu.add(new JLabel("Select action:"));
|
||||
|
@ -312,10 +319,6 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
|
||||
// Add 'show mote plugins'-actions
|
||||
for (final Mote mote : foundMotes) {
|
||||
final Point pos = new Point(canvas.getLocationOnScreen().x + x, canvas
|
||||
.getLocationOnScreen().y
|
||||
+ y);
|
||||
|
||||
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) {
|
||||
final Vector<Mote> foundMotes = findMotesAtPosition(x, y);
|
||||
if (foundMotes == null || foundMotes.size() == 0)
|
||||
if (foundMotes == null || foundMotes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
moteMoveBeginTime = System.currentTimeMillis();
|
||||
beginMoveRequest(foundMotes.get(0));
|
||||
|
@ -360,7 +364,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
|
||||
private void handleMoveRequest(final int x, final int y,
|
||||
boolean wasJustReleased) {
|
||||
|
||||
|
||||
if (!moteIsBeingMoved) {
|
||||
return;
|
||||
}
|
||||
|
@ -374,7 +378,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
// Stopped moving mote
|
||||
canvas.setCursor(Cursor.getDefaultCursor());
|
||||
moteIsBeingMoved = false;
|
||||
|
||||
|
||||
Position newXYValues = transformPixelToPositon(new Point(x, y));
|
||||
|
||||
if (moteMoveBeginTime <= 0 || System.currentTimeMillis() - moteMoveBeginTime > 300) {
|
||||
|
@ -382,7 +386,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
+ "\nX=" + newXYValues.getXCoordinate() + "\nY="
|
||||
+ newXYValues.getYCoordinate() + "\nZ="
|
||||
+ moteToMove.getInterfaces().getPosition().getZCoordinate());
|
||||
|
||||
|
||||
if (returnValue == JOptionPane.OK_OPTION) {
|
||||
moteToMove.getInterfaces().getPosition().setCoordinates(
|
||||
newXYValues.getXCoordinate(), newXYValues.getYCoordinate(),
|
||||
|
@ -396,7 +400,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
|
||||
/**
|
||||
* Returns all motes at given position.
|
||||
*
|
||||
*
|
||||
* @param clickedX
|
||||
* X coordinate
|
||||
* @param clickedY
|
||||
|
@ -428,8 +432,9 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
motesFound.add(simulation.getMote(i));
|
||||
}
|
||||
}
|
||||
if (motesFound.size() == 0)
|
||||
if (motesFound.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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
|
||||
* a different color scheme.
|
||||
*
|
||||
*
|
||||
* Normally this method returns an array of two colors, one for the state
|
||||
* (outer circle), the other for the type (inner circle).
|
||||
*
|
||||
*
|
||||
* If this method only returns one color, the entire mote will be painted
|
||||
* using that.
|
||||
*
|
||||
*
|
||||
* @param mote
|
||||
* Mote to paint
|
||||
* @return Color[] { Inner color, Outer color }
|
||||
|
@ -479,7 +484,7 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
g.setColor(moteColors[0]);
|
||||
g.fillOval(x - MOTE_RADIUS, y - MOTE_RADIUS, 2 * MOTE_RADIUS,
|
||||
2 * MOTE_RADIUS);
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
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++) {
|
||||
motePos = simulation.getMote(i).getInterfaces().getPosition();
|
||||
|
||||
if (motePos.getXCoordinate() < smallestXCoord)
|
||||
if (motePos.getXCoordinate() < smallestXCoord) {
|
||||
smallestXCoord = motePos.getXCoordinate();
|
||||
}
|
||||
|
||||
if (motePos.getXCoordinate() > biggestXCoord)
|
||||
if (motePos.getXCoordinate() > biggestXCoord) {
|
||||
biggestXCoord = motePos.getXCoordinate();
|
||||
}
|
||||
|
||||
if (motePos.getYCoordinate() < smallestYCoord)
|
||||
if (motePos.getYCoordinate() < smallestYCoord) {
|
||||
smallestYCoord = motePos.getYCoordinate();
|
||||
}
|
||||
|
||||
if (motePos.getYCoordinate() > biggestYCoord)
|
||||
if (motePos.getYCoordinate() > biggestYCoord) {
|
||||
biggestYCoord = motePos.getYCoordinate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((biggestXCoord - smallestXCoord) == 0) {
|
||||
factorXCoordToPixel = 1;
|
||||
} else
|
||||
} else {
|
||||
factorXCoordToPixel = ((double) canvas.getPreferredSize().width - 2 * CANVAS_BORDER_WIDTH)
|
||||
/ (biggestXCoord - smallestXCoord);
|
||||
}
|
||||
|
||||
if ((biggestYCoord - smallestYCoord) == 0) {
|
||||
factorYCoordToPixel = 1;
|
||||
} else
|
||||
} else {
|
||||
factorYCoordToPixel = ((double) canvas.getPreferredSize().height - 2 * CANVAS_BORDER_WIDTH)
|
||||
/ (biggestYCoord - smallestYCoord);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a real-world position to a pixel which can be painted onto the
|
||||
* current sized canvas.
|
||||
*
|
||||
*
|
||||
* @param pos
|
||||
* Real-world position
|
||||
* @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
|
||||
* current sized canvas.
|
||||
*
|
||||
*
|
||||
* @param x Real world X
|
||||
* @param y Real world Y
|
||||
* @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.
|
||||
*
|
||||
*
|
||||
* @param pixelPos
|
||||
* On-screen pixel coordinate
|
||||
* @return Real world coordinate (z=0).
|
||||
|
@ -593,11 +604,11 @@ public abstract class Visualizer2D extends VisPlugin {
|
|||
+ CANVAS_BORDER_WIDTH;
|
||||
}
|
||||
private double factorXPixelToCoord(int xPixel) {
|
||||
return ((double) (xPixel - CANVAS_BORDER_WIDTH) / factorXCoordToPixel)
|
||||
return ((xPixel - CANVAS_BORDER_WIDTH) / factorXCoordToPixel)
|
||||
+ smallestXCoord;
|
||||
}
|
||||
private double factorYPixelToCoord(int yPixel) {
|
||||
return ((double) (yPixel - CANVAS_BORDER_WIDTH) / factorYCoordToPixel)
|
||||
return ((yPixel - CANVAS_BORDER_WIDTH) / factorYCoordToPixel)
|
||||
+ smallestYCoord;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue