From e10f020fecc1f3a72ef33bf9d91265a2abb64335 Mon Sep 17 00:00:00 2001 From: nifi Date: Tue, 22 Aug 2006 12:26:36 +0000 Subject: [PATCH] mote type classloaders + no pack() --- .../contikimote/ContikiMoteTypeDialog.java | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteTypeDialog.java b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteTypeDialog.java index 2b0d1ab47..667cd97e1 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteTypeDialog.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMoteTypeDialog.java @@ -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.2 2006/08/21 15:06:28 fros4943 Exp $ + * $Id: ContikiMoteTypeDialog.java,v 1.3 2006/08/22 12:26:36 nifi Exp $ */ package se.sics.cooja.contikimote; @@ -313,11 +313,11 @@ public class ContikiMoteTypeDialog extends JDialog { } // Set position and focus of dialog + myDialog.pack(); myDialog.setLocationRelativeTo(parentFrame); myDialog.textDescription.requestFocus(); myDialog.textDescription.select(0, myDialog.textDescription.getText() .length()); - myDialog.setVisible(true); if (myDialog.myMoteType != null) { @@ -728,12 +728,12 @@ public class ContikiMoteTypeDialog extends JDialog { Container contentPane = getContentPane(); JScrollPane mainScrollPane = new JScrollPane(mainPane); - mainScrollPane.setPreferredSize(new Dimension( - mainPane.getPreferredSize().width + 50, 500)); +// mainScrollPane.setPreferredSize(new Dimension( +// mainPane.getPreferredSize().width + 50, 500)); contentPane.add(mainScrollPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.SOUTH); - pack(); +// pack(); } /** @@ -1035,8 +1035,8 @@ public class ContikiMoteTypeDialog extends JDialog { processString = "PROCINIT(NULL);"; if (!userProcessString.equals("")) - processString = processString.concat("\nAUTOSTART_PROCESSES(" - + userProcessString + ");"); + processString = processString + "\nAUTOSTART_PROCESSES(" + + userProcessString + ");"; else processString = processString.concat("\nAUTOSTART_PROCESSES(NULL);"); @@ -1056,7 +1056,7 @@ public class ContikiMoteTypeDialog extends JDialog { reader = new FileReader(mainTemplate); } else { InputStream input = ContikiMoteTypeDialog.class - .getResourceAsStream(File.separatorChar + mainTemplate); + .getResourceAsStream('/' + mainTemplate); if (input == null) { throw new FileNotFoundException(mainTemplate + " not found"); } @@ -1173,7 +1173,8 @@ public class ContikiMoteTypeDialog extends JDialog { + sourceFile.getPath().replace(File.separatorChar, '/'); } else if (sourceFile.isFile()) { // Add both file name and directory - sourceDirs += " " + sourceFile.getParent(); + sourceDirs += " " + + sourceFile.getParent().replace(File.separatorChar, '/'); sourceFileNames += " " + sourceFile.getName(); } else { // Add filename and hope Contiki knows where to find it... @@ -1530,7 +1531,6 @@ public class ContikiMoteTypeDialog extends JDialog { processCheckBox.addActionListener(myEventHandler); processPanel.add(processCheckBox); - myDialog.pack(); } } else { JCheckBox processCheckBox = new JCheckBox(autostartProcess, @@ -1542,7 +1542,6 @@ public class ContikiMoteTypeDialog extends JDialog { processCheckBox.addActionListener(myEventHandler); processPanel.add(processCheckBox); - myDialog.pack(); } } } @@ -1562,9 +1561,13 @@ public class ContikiMoteTypeDialog extends JDialog { moteInterfacePanel.removeAll(); processPanel.removeAll(); sensorPanel.removeAll(); + coreInterfacePanel.revalidate(); coreInterfacePanel.repaint(); + moteInterfacePanel.revalidate(); moteInterfacePanel.repaint(); + processPanel.revalidate(); processPanel.repaint(); + sensorPanel.revalidate(); sensorPanel.repaint(); createButton.setEnabled(libraryCreatedOK = false); @@ -1694,8 +1697,11 @@ public class ContikiMoteTypeDialog extends JDialog { coreInterfacePanel.removeAll(); processPanel.removeAll(); sensorPanel.removeAll(); + coreInterfacePanel.revalidate(); coreInterfacePanel.repaint(); + processPanel.revalidate(); processPanel.repaint(); + sensorPanel.revalidate(); sensorPanel.repaint(); testButton.setEnabled(settingsOK = false); createButton.setEnabled(libraryCreatedOK = false); @@ -1916,8 +1922,8 @@ public class ContikiMoteTypeDialog extends JDialog { testButton.setEnabled(settingsOK = false); } + processPanel.revalidate(); processPanel.repaint(); - myDialog.pack(); createButton.setEnabled(libraryCreatedOK = false); } else if (e.getActionCommand().equals("scansensors")) { @@ -1952,8 +1958,8 @@ public class ContikiMoteTypeDialog extends JDialog { testButton.setEnabled(settingsOK = false); } + sensorPanel.revalidate(); sensorPanel.repaint(); - myDialog.pack(); createButton.setEnabled(libraryCreatedOK = false); } else if (e.getActionCommand().equals("scancoreinterfaces")) { // Clear core interface panel @@ -1989,8 +1995,8 @@ public class ContikiMoteTypeDialog extends JDialog { } recheckInterfaceDependencies(); + coreInterfacePanel.revalidate(); coreInterfacePanel.repaint(); - myDialog.pack(); createButton.setEnabled(libraryCreatedOK = false); } else if (e.getActionCommand().equals("scanmoteinterfaces")) { @@ -2021,18 +2027,20 @@ public class ContikiMoteTypeDialog extends JDialog { ContikiMoteType.class, "MOTE_INTERFACES"); Vector> moteIntfClasses = new Vector>(); + ClassLoader classLoader = + GUI.currentGUI.createUserPlatformClassLoader(moteTypeUserPlatforms); + // Find and load the mote interface classes for (String moteInterface : moteInterfaces) { - - Class newMoteInterfaceClass = GUI.currentGUI - .tryLoadClass(this, MoteInterface.class, moteInterface); - - if (newMoteInterfaceClass == null) { - logger.warn("Failed to load mote interface: " + moteInterface); - } else { + try { + Class newMoteInterfaceClass = + classLoader.loadClass(moteInterface). + asSubclass(MoteInterface.class); moteIntfClasses.add(newMoteInterfaceClass); // logger.info("Loaded mote interface: " + newMoteInterfaceClass); - } + } catch (Exception ce) { + logger.warn("Failed to load mote interface: " + moteInterface); + } } // Create and add checkboxes for all mote interfaces @@ -2055,8 +2063,8 @@ public class ContikiMoteTypeDialog extends JDialog { testButton.setEnabled(settingsOK = false); } + moteInterfacePanel.revalidate(); moteInterfacePanel.repaint(); - myDialog.pack(); createButton.setEnabled(libraryCreatedOK = false); } else if (e.getActionCommand().equals("addprocess")) { String newProcessName = JOptionPane.showInputDialog(myDialog, @@ -2071,8 +2079,9 @@ public class ContikiMoteTypeDialog extends JDialog { processCheckBox.addActionListener(myEventHandler); processPanel.add(processCheckBox); + processPanel.revalidate(); + processPanel.repaint(); } - myDialog.pack(); } else if (e.getActionCommand().equals("addsensor")) { String newSensorName = JOptionPane.showInputDialog(myDialog, "Enter sensor name"); @@ -2081,8 +2090,9 @@ public class ContikiMoteTypeDialog extends JDialog { sensorCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); sensorCheckBox.setSelected(true); sensorPanel.add(sensorCheckBox); + sensorPanel.revalidate(); + sensorPanel.repaint(); } - myDialog.pack(); } else if (e.getActionCommand().equals("addinterface")) { String newInterfaceName = JOptionPane.showInputDialog(myDialog, "Enter interface name"); @@ -2091,8 +2101,9 @@ public class ContikiMoteTypeDialog extends JDialog { interfaceCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); interfaceCheckBox.setSelected(true); coreInterfacePanel.add(interfaceCheckBox); + coreInterfacePanel.revalidate(); + coreInterfacePanel.repaint(); } - myDialog.pack(); } else if (e.getActionCommand().equals("recheck_interface_dependencies")) { recheckInterfaceDependencies(); } else if (e.getActionCommand().startsWith("process_clicked")) {