From 2fd44015fa9eb737b8c1fb1bbb30fe08f1868dd5 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 9 Jan 2007 10:03:51 +0000 Subject: [PATCH] minor updates due to removed static variables and new method params --- .../se/sics/cooja/dialogs/AddMoteDialog.java | 30 +++++++++++-------- .../sics/cooja/dialogs/CreateSimDialog.java | 15 ++++++---- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/dialogs/AddMoteDialog.java b/tools/cooja/java/se/sics/cooja/dialogs/AddMoteDialog.java index 01328fb85..47539e0cf 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/AddMoteDialog.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/AddMoteDialog.java @@ -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.1 2006/08/21 12:13:01 fros4943 Exp $ + * $Id: AddMoteDialog.java,v 1.2 2007/01/09 10:03:51 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -63,24 +63,29 @@ public class AddMoteDialog extends JDialog { private JButton addButton; private MoteType moteType = null; + private Simulation simulation = null; private JFormattedTextField numberOfMotesField, startX, endX, startY, endY, startZ, endZ; private JComboBox positionDistributionBox, ipDistributionBox; + /** * Shows a dialog which enables a user to create and add motes of the given * type. * * @param parentFrame * Parent frame for dialog + * @param simulation + * Simulation * @param moteType * Mote type * @return New motes or null if aborted */ - public static Vector showDialog(Frame parentFrame, MoteType moteType) { + public static Vector showDialog(Frame parentFrame, + Simulation simulation, MoteType moteType) { - AddMoteDialog myDialog = new AddMoteDialog(parentFrame, moteType); + AddMoteDialog myDialog = new AddMoteDialog(parentFrame, simulation, moteType); myDialog.setLocationRelativeTo(parentFrame); myDialog.checkSettings(); @@ -90,10 +95,11 @@ public class AddMoteDialog extends JDialog { return myDialog.newMotes; } - private AddMoteDialog(Frame frame, MoteType moteType) { + private AddMoteDialog(Frame frame, Simulation simulation, MoteType moteType) { super(frame, "Add motes (" + moteType.getDescription() + ")", true); this.moteType = moteType; - + this.simulation = simulation; + JLabel label; JPanel mainPane = new JPanel(); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); @@ -154,7 +160,7 @@ public class AddMoteDialog extends JDialog { label = new JLabel("IP Addressing"); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); - Vector> ipDistributors = GUI.currentGUI + Vector> ipDistributors = simulation.getGUI() .getRegisteredIPDistributors(); String[] ipDistributions = new String[ipDistributors.size()]; for (int i = 0; i < ipDistributions.length; i++) @@ -182,7 +188,7 @@ public class AddMoteDialog extends JDialog { label = new JLabel("Positioning"); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); - Vector> positioners = GUI.currentGUI + Vector> positioners = simulation.getGUI() .getRegisteredPositioners(); String[] posDistributions = new String[positioners.size()]; for (int i = 0; i < posDistributions.length; i++) @@ -409,13 +415,13 @@ public class AddMoteDialog extends JDialog { // Create new motes int motesToAdd = ((Number) numberOfMotesField.getValue()).intValue(); while (newMotes.size() < motesToAdd) { - Mote newMote = moteType.generateMote(GUI.currentSimulation); + Mote newMote = moteType.generateMote(simulation); newMotes.add(newMote); } // Position new motes Class positionerClass = null; - for (Class positioner : GUI.currentGUI + for (Class positioner : simulation.getGUI() .getRegisteredPositioners()) { if (GUI.getDescriptionOf(positioner).equals( (String) positionDistributionBox.getSelectedItem())) @@ -455,8 +461,8 @@ public class AddMoteDialog extends JDialog { // Set unique mote id's for all new motes int nextMoteID = 1; - for (int i = 0; i < GUI.currentSimulation.getMotesCount(); i++) { - MoteID moteID = GUI.currentSimulation.getMote(i).getInterfaces() + for (int i = 0; i < simulation.getMotesCount(); i++) { + MoteID moteID = simulation.getMote(i).getInterfaces() .getMoteID(); if (moteID != null && moteID.getMoteID() >= nextMoteID) nextMoteID = moteID.getMoteID() + 1; @@ -471,7 +477,7 @@ public class AddMoteDialog extends JDialog { // IP address new motes Class ipDistClass = null; - for (Class ipDistributor : GUI.currentGUI + for (Class ipDistributor : simulation.getGUI() .getRegisteredIPDistributors()) { if (GUI.getDescriptionOf(ipDistributor).equals( (String) ipDistributionBox.getSelectedItem())) diff --git a/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java b/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java index f593e4f65..1d4b4bd78 100644 --- a/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java +++ b/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java @@ -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.1 2006/08/21 12:13:02 fros4943 Exp $ + * $Id: CreateSimDialog.java,v 1.2 2007/01/09 10:03:51 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -57,6 +57,7 @@ public class CreateSimDialog extends JDialog { private final static int LABEL_HEIGHT = 15; private Simulation mySimulation = null; + private GUI myGUI = null; private CreateSimDialog myDialog; @@ -75,7 +76,7 @@ public class CreateSimDialog extends JDialog { * @return True if simulation configured correctly */ public static boolean showDialog(Frame parentFrame, Simulation simulationToConfigure) { - CreateSimDialog myDialog = new CreateSimDialog(parentFrame); + CreateSimDialog myDialog = new CreateSimDialog(parentFrame, simulationToConfigure.getGUI()); myDialog.mySimulation = simulationToConfigure; @@ -127,10 +128,11 @@ public class CreateSimDialog extends JDialog { return false; } - private CreateSimDialog(Frame frame) { + private CreateSimDialog(Frame frame, GUI gui) { super(frame, "Create new simulation", true); myDialog = this; + myGUI = gui; JPanel mainPane = new JPanel(); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); @@ -193,7 +195,7 @@ public class CreateSimDialog extends JDialog { label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); Vector radioMediumDescriptions = new Vector(); - for (Class radioMediumClass: GUI.currentGUI.getRegisteredRadioMediums()) { + for (Class radioMediumClass: gui.getRegisteredRadioMediums()) { String description = GUI.getDescriptionOf(radioMediumClass); radioMediumDescriptions.add(description); } @@ -312,12 +314,13 @@ public class CreateSimDialog extends JDialog { mySimulation.setTitle(title.getText()); String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem(); - for (Class radioMediumClass: GUI.currentGUI.getRegisteredRadioMediums()) { + for (Class radioMediumClass: myGUI.getRegisteredRadioMediums()) { String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass); if (currentRadioMediumDescription.equals(radioMediumDescription)) { try { - mySimulation.setRadioMedium(radioMediumClass.newInstance()); + RadioMedium radioMedium = RadioMedium.generateInterface(radioMediumClass, mySimulation); + mySimulation.setRadioMedium(radioMedium); } catch (Exception ex) { logger.fatal("Exception when creating radio medium: " + ex); mySimulation.setRadioMedium(null);