From 3ace4c55cd17e9c7e2a9fb174735cb4cf43c14f4 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Sun, 30 Sep 2007 12:03:49 +0000 Subject: [PATCH] code formatting and more debugging output at radio medium failure --- .../sics/cooja/dialogs/CreateSimDialog.java | 155 +++++++++--------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java b/tools/cooja/java/se/sics/cooja/dialogs/CreateSimDialog.java index f9f2c944f..3a320bdd4 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.6 2007/08/21 08:54:48 fros4943 Exp $ + * $Id: CreateSimDialog.java,v 1.7 2007/09/30 12:03:49 fros4943 Exp $ */ package se.sics.cooja.dialogs; @@ -48,25 +48,25 @@ import se.sics.cooja.*; public class CreateSimDialog extends JDialog { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(CreateSimDialog.class); - + private AddSimEventHandler myEventHandler = new AddSimEventHandler(); - + private final static int LABEL_WIDTH = 170; private final static int LABEL_HEIGHT = 15; private Simulation mySimulation = null; private GUI myGUI = null; - + private CreateSimDialog myDialog; - + private JFormattedTextField delayTime, simulationTime, tickTime; private JFormattedTextField randomSeed, tickLists, delayedStartup; - + private JTextField title; private JComboBox radioMediumBox; - + private JButton cancelButton; - + /** * Shows a dialog for configuring a simulation. * @@ -124,11 +124,11 @@ public class CreateSimDialog extends JDialog { // Select radio medium if (simulationToConfigure.getRadioMedium() != null) { - Class radioMediumClass = + Class radioMediumClass = simulationToConfigure.getRadioMedium().getClass(); - - String currentDescription = GUI.getDescriptionOf(radioMediumClass); - + + String currentDescription = GUI.getDescriptionOf(radioMediumClass); + for (int i=0; i < myDialog.radioMediumBox.getItemCount(); i++) { String menuDescription = (String) myDialog.radioMediumBox.getItemAt(i); if (menuDescription.equals(currentDescription)) { @@ -147,7 +147,7 @@ public class CreateSimDialog extends JDialog { // Set delayed mote startup time myDialog.delayedStartup.setValue(new Integer(simulationToConfigure.getDelayedMoteStartupTime())); - + // Set position and focus of dialog myDialog.setLocationRelativeTo(parentFrame); myDialog.title.requestFocus(); @@ -160,26 +160,26 @@ public class CreateSimDialog extends JDialog { public void actionPerformed(ActionEvent e) { myDialog.cancelButton.doClick(); } - }; + }; myDialog.getRootPane().getActionMap().put("dispose", cancelAction); - + myDialog.setVisible(true); - + if (myDialog.mySimulation != null) { // Simulation configured correctly return true; } return false; } - + private CreateSimDialog(Frame frame, GUI gui) { super(frame, "Create new simulation", true); - + myDialog = this; myGUI = gui; - + Box vertBox = Box.createVerticalBox(); - + JLabel label; JTextField textField; Box horizBox; @@ -187,97 +187,97 @@ public class CreateSimDialog extends JDialog { JComboBox comboBox; JFormattedTextField numberField; NumberFormat integerFormat = NumberFormat.getIntegerInstance(); - - + + // BOTTOM BUTTON PART Box buttonBox = Box.createHorizontalBox(); buttonBox.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); - + buttonBox.add(Box.createHorizontalGlue()); - + cancelButton = new JButton("Cancel"); cancelButton.setActionCommand("cancel"); cancelButton.addActionListener(myEventHandler); buttonBox.add(cancelButton); - + button = new JButton("Create"); button.setActionCommand("create"); button.addActionListener(myEventHandler); buttonBox.add(Box.createHorizontalStrut(5)); myDialog.rootPane.setDefaultButton(button); buttonBox.add(button); - - + + // MAIN PART - + // Title horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Simulation title"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + textField = new JTextField(); textField.setText("[no title]"); textField.setColumns(25); title = textField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(10)); horizBox.add(textField); vertBox.add(horizBox); vertBox.add(Box.createRigidArea(new Dimension(0,5))); - + // Radio Medium selection horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Radio Medium"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + Vector radioMediumDescriptions = new Vector(); for (Class radioMediumClass: gui.getRegisteredRadioMediums()) { - String description = GUI.getDescriptionOf(radioMediumClass); + String description = GUI.getDescriptionOf(radioMediumClass); radioMediumDescriptions.add(description); } comboBox = new JComboBox(radioMediumDescriptions); - + comboBox.setSelectedIndex(0); radioMediumBox = comboBox; label.setLabelFor(comboBox); - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(10)); horizBox.add(comboBox); horizBox.setToolTipText("Determines the radio surroundings behaviour"); - + vertBox.add(horizBox); vertBox.add(Box.createRigidArea(new Dimension(0,5))); - - + + /* // Radio Medium Logging selection smallPane = Box.createHorizontalBox(); smallPane.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); smallPane.setAlignmentX(Component.LEFT_ALIGNMENT); logCheckBox = new JCheckBox("Log all radio traffic?"); logCheckBox.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + textField = new JTextField(); textField.setText("[filename]"); textField.setColumns(25); logFilename = textField; - + smallPane.add(logCheckBox); smallPane.add(Box.createHorizontalStrut(10)); smallPane.add(textField); - - + + mainPane.add(smallPane); mainPane.add(Box.createRigidArea(new Dimension(0,5))); -*/ - +*/ + // -- Advanced settings -- Box advancedBox = Box.createVerticalBox(); @@ -289,32 +289,32 @@ public class CreateSimDialog extends JDialog { horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Simulation start time (ms)"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(0)); numberField.setColumns(4); simulationTime = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); horizBox.setToolTipText("Initial value of simulated time"); - + advancedBox.add(horizBox); advancedBox.add(Box.createRigidArea(new Dimension(0,5))); - + // Tick time horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Simulation tick time (ms)"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(1)); numberField.setColumns(4); tickTime = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); @@ -322,19 +322,19 @@ public class CreateSimDialog extends JDialog { advancedBox.add(horizBox); advancedBox.add(Box.createRigidArea(new Dimension(0,5))); - + // Delayed startup horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Mote startup delay (max, ms)"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(10000)); numberField.setColumns(4); delayedStartup = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); @@ -342,7 +342,7 @@ public class CreateSimDialog extends JDialog { advancedBox.add(horizBox); advancedBox.add(Box.createVerticalStrut(5)); - + advancedBox.add(Box.createVerticalStrut(5)); // Delay time @@ -351,12 +351,12 @@ public class CreateSimDialog extends JDialog { horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Delay time (ms)"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(100)); numberField.setColumns(4); delayTime = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); @@ -373,53 +373,53 @@ public class CreateSimDialog extends JDialog { horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Main random seed"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(123456)); numberField.setColumns(4); randomSeed = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); horizBox.setToolTipText("Main random seed. Determines mote tick order, mote startup delay etc."); - + advancedBox.add(horizBox); advancedBox.add(Box.createVerticalStrut(5)); - + // Tick lists horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Number of tick lists"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); - + numberField = new JFormattedTextField(integerFormat); numberField.setValue(new Integer(1)); - numberField.setColumns(4); + numberField.setColumns(4); tickLists = numberField; - + horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); horizBox.setToolTipText("Number of tick lists.

Every simulated mote belongs to a tick list, and each simulated loop only one list is allowed to act.
If the number of tick lists is 1, all motes are tick every simulation time increase."); - + advancedBox.add(horizBox); advancedBox.add(Box.createVerticalGlue()); - - + + vertBox.add(advancedBox); vertBox.add(Box.createVerticalGlue()); - + vertBox.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); - + Container contentPane = getContentPane(); contentPane.add(vertBox, BorderLayout.CENTER); contentPane.add(buttonBox, BorderLayout.SOUTH); - + pack(); } - + private class AddSimEventHandler implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("cancel")) { @@ -430,10 +430,10 @@ public class CreateSimDialog extends JDialog { mySimulation.setSimulationTime(((Number) simulationTime.getValue()).intValue()); mySimulation.setTickTime(((Number) tickTime.getValue()).intValue()); mySimulation.setTitle(title.getText()); - + String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem(); for (Class radioMediumClass: myGUI.getRegisteredRadioMediums()) { - String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass); + String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass); if (currentRadioMediumDescription.equals(radioMediumDescription)) { try { @@ -441,25 +441,26 @@ public class CreateSimDialog extends JDialog { mySimulation.setRadioMedium(radioMedium); } catch (Exception ex) { logger.fatal("Exception when creating radio medium: " + ex); + ex.printStackTrace(); mySimulation.setRadioMedium(null); } break; } } - + /* if (logCheckBox.isSelected()) { ConnectionLogger connLogger = new ConnectionLogger(new File(logFilename.getText())); mySimulation.getRadioMedium().setConnectionLogger(connLogger); } -*/ - +*/ + mySimulation.setRandomSeed(((Number) randomSeed.getValue()).longValue()); mySimulation.setNrTickLists(((Number) tickLists.getValue()).intValue()); mySimulation.setDelayedMoteStartupTime(((Number) delayedStartup.getValue()).intValue()); - + dispose(); } } } - + }