bug fix: user platform dialog had wrong owner window

This commit is contained in:
fros4943 2006-08-23 14:29:44 +00:00
parent 44201a4f4e
commit 5d6358b602
2 changed files with 96 additions and 39 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMoteTypeDialog.java,v 1.4 2006/08/22 15:28:18 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.5 2006/08/23 14:31:12 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -103,7 +103,6 @@ public class ContikiMoteTypeDialog extends JDialog {
private Vector<MoteType> allOtherTypes = null; // Used to check for private Vector<MoteType> allOtherTypes = null; // Used to check for
// conflicting parameters // conflicting parameters
private Frame myParentFrame;
private ContikiMoteTypeDialog myDialog; private ContikiMoteTypeDialog myDialog;
/** /**
@ -331,7 +330,6 @@ public class ContikiMoteTypeDialog extends JDialog {
super(frame, "Add Mote Type", true); super(frame, "Add Mote Type", true);
myDialog = this; myDialog = this;
myParentFrame = frame;
JLabel label; JLabel label;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
@ -728,12 +726,12 @@ public class ContikiMoteTypeDialog extends JDialog {
Container contentPane = getContentPane(); Container contentPane = getContentPane();
JScrollPane mainScrollPane = new JScrollPane(mainPane); JScrollPane mainScrollPane = new JScrollPane(mainPane);
// mainScrollPane.setPreferredSize(new Dimension( // mainScrollPane.setPreferredSize(new Dimension(
// mainPane.getPreferredSize().width + 50, 500)); // mainPane.getPreferredSize().width + 50, 500));
contentPane.add(mainScrollPane, BorderLayout.CENTER); contentPane.add(mainScrollPane, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.SOUTH); contentPane.add(buttonPane, BorderLayout.SOUTH);
// pack(); // pack();
} }
/** /**
@ -906,8 +904,8 @@ public class ContikiMoteTypeDialog extends JDialog {
ContikiMoteType.class, "C_SOURCES", projectSourceFile); ContikiMoteType.class, "C_SOURCES", projectSourceFile);
if (userPlatform != null) { if (userPlatform != null) {
// We found a user platform - Add directory // We found a user platform - Add directory
filesToCompile.add(new File(userPlatform.getPath(), filesToCompile.add(new File(userPlatform.getPath(), file
file.getParent())); .getParent()));
} }
} }
filesToCompile.add(new File(file.getName())); filesToCompile.add(new File(file.getName()));
@ -1183,12 +1181,13 @@ public class ContikiMoteTypeDialog extends JDialog {
// Add directory to search path // Add directory to search path
sourceDirs += " " sourceDirs += " "
+ sourceFile.getPath().replace(File.separatorChar, '/'); + sourceFile.getPath().replace(File.separatorChar, '/');
ccFlags += " -I" + sourceFile.getPath().replace(File.separatorChar, '/'); ccFlags += " -I"
+ sourceFile.getPath().replace(File.separatorChar, '/');
} else if (sourceFile.isFile()) { } else if (sourceFile.isFile()) {
// Add both file name and directory // Add both file name and directory
if (sourceFile.getParent() != null) { if (sourceFile.getParent() != null) {
sourceDirs += " " + sourceDirs += " "
sourceFile.getParent().replace(File.separatorChar, '/'); + sourceFile.getParent().replace(File.separatorChar, '/');
} }
sourceFileNames += " " + sourceFile.getName(); sourceFileNames += " " + sourceFile.getName();
} else { } else {
@ -1887,7 +1886,7 @@ public class ContikiMoteTypeDialog extends JDialog {
pathsWereUpdated(); pathsWereUpdated();
} else if (e.getActionCommand().equals("manageuserplatforms")) { } else if (e.getActionCommand().equals("manageuserplatforms")) {
Vector<File> newPlatforms = UserPlatformsDialog.showDialog( Vector<File> newPlatforms = UserPlatformsDialog.showDialog(
myParentFrame, moteTypeUserPlatforms, GUI.currentGUI ContikiMoteTypeDialog.this, moteTypeUserPlatforms, GUI.currentGUI
.getUserPlatforms()); .getUserPlatforms());
if (newPlatforms != null) { if (newPlatforms != null) {
moteTypeUserPlatforms = newPlatforms; moteTypeUserPlatforms = newPlatforms;
@ -1941,7 +1940,7 @@ public class ContikiMoteTypeDialog extends JDialog {
testButton.setEnabled(settingsOK = false); testButton.setEnabled(settingsOK = false);
} }
processPanel.revalidate(); processPanel.revalidate();
processPanel.repaint(); processPanel.repaint();
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
@ -1977,7 +1976,7 @@ public class ContikiMoteTypeDialog extends JDialog {
testButton.setEnabled(settingsOK = false); testButton.setEnabled(settingsOK = false);
} }
sensorPanel.revalidate(); sensorPanel.revalidate();
sensorPanel.repaint(); sensorPanel.repaint();
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
} else if (e.getActionCommand().equals("scancoreinterfaces")) { } else if (e.getActionCommand().equals("scancoreinterfaces")) {
@ -2014,7 +2013,7 @@ public class ContikiMoteTypeDialog extends JDialog {
} }
recheckInterfaceDependencies(); recheckInterfaceDependencies();
coreInterfacePanel.revalidate(); coreInterfacePanel.revalidate();
coreInterfacePanel.repaint(); coreInterfacePanel.repaint();
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
@ -2040,20 +2039,19 @@ public class ContikiMoteTypeDialog extends JDialog {
ContikiMoteType.class, "MOTE_INTERFACES"); ContikiMoteType.class, "MOTE_INTERFACES");
Vector<Class<? extends MoteInterface>> moteIntfClasses = new Vector<Class<? extends MoteInterface>>(); Vector<Class<? extends MoteInterface>> moteIntfClasses = new Vector<Class<? extends MoteInterface>>();
ClassLoader classLoader = ClassLoader classLoader = GUI.currentGUI
GUI.currentGUI.createUserPlatformClassLoader(moteTypeUserPlatforms); .createUserPlatformClassLoader(moteTypeUserPlatforms);
// Find and load the mote interface classes // Find and load the mote interface classes
for (String moteInterface : moteInterfaces) { for (String moteInterface : moteInterfaces) {
try { try {
Class<? extends MoteInterface> newMoteInterfaceClass = Class<? extends MoteInterface> newMoteInterfaceClass = classLoader
classLoader.loadClass(moteInterface). .loadClass(moteInterface).asSubclass(MoteInterface.class);
asSubclass(MoteInterface.class);
moteIntfClasses.add(newMoteInterfaceClass); moteIntfClasses.add(newMoteInterfaceClass);
// logger.info("Loaded mote interface: " + newMoteInterfaceClass); // logger.info("Loaded mote interface: " + newMoteInterfaceClass);
} catch (Exception ce) { } catch (Exception ce) {
logger.warn("Failed to load mote interface: " + moteInterface); logger.warn("Failed to load mote interface: " + moteInterface);
} }
} }
// Create and add checkboxes for all mote interfaces // Create and add checkboxes for all mote interfaces
@ -2076,7 +2074,7 @@ public class ContikiMoteTypeDialog extends JDialog {
testButton.setEnabled(settingsOK = false); testButton.setEnabled(settingsOK = false);
} }
moteInterfacePanel.revalidate(); moteInterfacePanel.revalidate();
moteInterfacePanel.repaint(); moteInterfacePanel.repaint();
createButton.setEnabled(libraryCreatedOK = false); createButton.setEnabled(libraryCreatedOK = false);
} else if (e.getActionCommand().equals("addprocess")) { } else if (e.getActionCommand().equals("addprocess")) {
@ -2092,8 +2090,8 @@ public class ContikiMoteTypeDialog extends JDialog {
processCheckBox.addActionListener(myEventHandler); processCheckBox.addActionListener(myEventHandler);
processPanel.add(processCheckBox); processPanel.add(processCheckBox);
processPanel.revalidate(); processPanel.revalidate();
processPanel.repaint(); processPanel.repaint();
} }
} else if (e.getActionCommand().equals("addsensor")) { } else if (e.getActionCommand().equals("addsensor")) {
String newSensorName = JOptionPane.showInputDialog(myDialog, String newSensorName = JOptionPane.showInputDialog(myDialog,
@ -2103,8 +2101,8 @@ public class ContikiMoteTypeDialog extends JDialog {
sensorCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); sensorCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
sensorCheckBox.setSelected(true); sensorCheckBox.setSelected(true);
sensorPanel.add(sensorCheckBox); sensorPanel.add(sensorCheckBox);
sensorPanel.revalidate(); sensorPanel.revalidate();
sensorPanel.repaint(); sensorPanel.repaint();
} }
} else if (e.getActionCommand().equals("addinterface")) { } else if (e.getActionCommand().equals("addinterface")) {
String newInterfaceName = JOptionPane.showInputDialog(myDialog, String newInterfaceName = JOptionPane.showInputDialog(myDialog,
@ -2114,8 +2112,8 @@ public class ContikiMoteTypeDialog extends JDialog {
interfaceCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); interfaceCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT);
interfaceCheckBox.setSelected(true); interfaceCheckBox.setSelected(true);
coreInterfacePanel.add(interfaceCheckBox); coreInterfacePanel.add(interfaceCheckBox);
coreInterfacePanel.revalidate(); coreInterfacePanel.revalidate();
coreInterfacePanel.repaint(); coreInterfacePanel.repaint();
} }
} else if (e.getActionCommand().equals("recheck_interface_dependencies")) { } else if (e.getActionCommand().equals("recheck_interface_dependencies")) {
recheckInterfaceDependencies(); recheckInterfaceDependencies();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: UserPlatformsDialog.java,v 1.3 2006/08/22 15:28:18 fros4943 Exp $ * $Id: UserPlatformsDialog.java,v 1.4 2006/08/23 14:29:44 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -66,7 +66,8 @@ public class UserPlatformsDialog extends JDialog {
private Vector<File> changableUserPlatforms = null; private Vector<File> changableUserPlatforms = null;
private UserPlatformsDialog myDialog; private UserPlatformsDialog myDialog;
private Frame myParentFrame; private Frame myParentFrame = null;
private Dialog myParentDialog = null;
/** /**
* Allows user to alter the given user platforms list by adding new, * Allows user to alter the given user platforms list by adding new,
@ -94,11 +95,47 @@ public class UserPlatformsDialog extends JDialog {
return myDialog.changableUserPlatforms; return myDialog.changableUserPlatforms;
} }
/**
* Allows user to alter the given user platforms list by adding new,
* reordering or removing user platforms. Only the changable user platforms
* may be changed,
*
* @param parentDialog
* Parent dialog
* @param changablePlatforms
* Changeable user platforms
* @param fixedPlatforms
* Fixed user platform
* @return Null if dialog aborted, else the new CHANGEABLE user platform list.
*/
public static Vector<File> showDialog(Dialog parentDialog,
Vector<File> changablePlatforms, Vector<File> fixedPlatforms) {
UserPlatformsDialog myDialog = new UserPlatformsDialog(parentDialog,
changablePlatforms, fixedPlatforms);
myDialog.setLocationRelativeTo(parentDialog);
if (myDialog != null) {
myDialog.setVisible(true);
}
return myDialog.changableUserPlatforms;
}
private UserPlatformsDialog(Frame frame, Vector<File> changablePlatforms, private UserPlatformsDialog(Frame frame, Vector<File> changablePlatforms,
Vector<File> fixedPlatforms) { Vector<File> fixedPlatforms) {
super(frame, "Manage User Platforms", true); super(frame, "Manage User Platforms", true);
myParentFrame = frame; myParentFrame = frame;
init(changablePlatforms, fixedPlatforms);
}
private UserPlatformsDialog(Dialog dialog, Vector<File> changablePlatforms,
Vector<File> fixedPlatforms) {
super(dialog, "Manage User Platforms", true);
myParentDialog = dialog;
init(changablePlatforms, fixedPlatforms);
}
private void init(Vector<File> changablePlatforms, Vector<File> fixedPlatforms) {
myDialog = this; myDialog = this;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
@ -257,7 +294,10 @@ public class UserPlatformsDialog extends JDialog {
} }
// Show merged configuration // Show merged configuration
ConfigViewer.showDialog(myParentFrame, config); if (myParentFrame != null)
ConfigViewer.showDialog(myParentFrame, config);
else
ConfigViewer.showDialog(myParentDialog, config);
} }
}); });
addRemovePane.add(button); addRemovePane.add(button);
@ -361,15 +401,34 @@ class ConfigViewer extends JDialog {
public static void showDialog(Frame parentFrame, PlatformConfig config) { public static void showDialog(Frame parentFrame, PlatformConfig config) {
ConfigViewer myDialog = new ConfigViewer(parentFrame, config); ConfigViewer myDialog = new ConfigViewer(parentFrame, config);
myDialog.setLocationRelativeTo(parentFrame); myDialog.setLocationRelativeTo(parentFrame);
myDialog.setAlwaysOnTop(true);
if (myDialog != null) { if (myDialog != null) {
myDialog.setVisible(true); myDialog.setVisible(true);
} }
} }
public static void showDialog(Dialog parentDialog, PlatformConfig config) {
ConfigViewer myDialog = new ConfigViewer(parentDialog, config);
myDialog.setLocationRelativeTo(parentDialog);
myDialog.setAlwaysOnTop(true);
if (myDialog != null) {
myDialog.setVisible(true);
}
}
private ConfigViewer(Dialog dialog, PlatformConfig config) {
super(dialog, "Current class configuration", true);
init(config);
}
private ConfigViewer(Frame frame, PlatformConfig config) { private ConfigViewer(Frame frame, PlatformConfig config) {
super(frame, "Current class configuration", true); super(frame, "Current class configuration", true);
init(config);
}
private void init(PlatformConfig config) {
JPanel mainPane = new JPanel(new BorderLayout()); JPanel mainPane = new JPanel(new BorderLayout());
JLabel label; JLabel label;
JButton button; JButton button;