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

@ -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: 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;
@ -99,10 +99,12 @@ public abstract class CoreComm {
* 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;
}
@ -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,10 +186,11 @@ 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");
}
@ -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(
@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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);

View file

@ -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;
@ -106,9 +106,10 @@ 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
@ -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;
}

View file

@ -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;
@ -93,19 +93,28 @@ 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();
@ -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,9 +381,10 @@ public class MantisMoteTypeDialog extends JDialog {
if (compilationThread != null && compilationThread.isAlive()) {
compilationThread.interrupt();
}
if (progressDialog != null && progressDialog.isDisplayable())
if (progressDialog != null && progressDialog.isDisplayable()) {
progressDialog.dispose();
}
}
});
progressPanel.add(BorderLayout.CENTER, new JScrollPane(taskOutput));
@ -398,10 +419,11 @@ public class MantisMoteTypeDialog extends JDialog {
} 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);
@ -445,9 +467,10 @@ public class MantisMoteTypeDialog extends JDialog {
libraryCreatedOK = false;
} else {
libraryCreatedOK = true;
if (!libFile.exists())
if (!libFile.exists()) {
libraryCreatedOK = false;
}
}
if (libraryCreatedOK) {
progressBar.setBackground(Color.GREEN);
@ -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) {
}
@ -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,9 +637,10 @@ 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,9 +652,10 @@ 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");
}
@ -722,29 +755,32 @@ public class MantisMoteTypeDialog extends JDialog {
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")) {
// Cancel creation of mote type
@ -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);

View file

@ -24,12 +24,13 @@
* (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
@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
@ -188,11 +188,13 @@ 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;
@ -207,10 +209,11 @@ public abstract class Visualizer2D extends VisPlugin {
}
// Toggle color
if (highlightColor == Color.GRAY)
if (highlightColor == Color.GRAY) {
highlightColor = Color.CYAN;
else
} else {
highlightColor = Color.GRAY;
}
highlightTimer.setDelay(highlightTimer.getDelay()-1);
repaint();
}
@ -231,32 +234,35 @@ 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);
}
}
});
// Detect component events
@ -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));
@ -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;
}
@ -511,32 +516,38 @@ 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
@ -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;
}