removed delay configuration option + lots of obsolete code from dialog
This commit is contained in:
parent
977809144f
commit
28f910b8d9
1 changed files with 95 additions and 201 deletions
|
@ -26,21 +26,44 @@
|
||||||
* 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: CreateSimDialog.java,v 1.16 2009/05/26 14:25:07 fros4943 Exp $
|
* $Id: CreateSimDialog.java,v 1.17 2009/11/13 08:51:23 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import java.awt.Component;
|
||||||
import java.text.*;
|
import java.awt.Container;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Window;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import javax.swing.*;
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.InputMap;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFormattedTextField;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.GUI;
|
||||||
|
import se.sics.cooja.RadioMedium;
|
||||||
|
import se.sics.cooja.Simulation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dialog for creating and configuring a simulation.
|
* A dialog for creating and configuring a simulation.
|
||||||
|
@ -51,18 +74,12 @@ public class CreateSimDialog extends JDialog {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static Logger logger = Logger.getLogger(CreateSimDialog.class);
|
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_WIDTH = 170;
|
||||||
private final static int LABEL_HEIGHT = 25;
|
private final static int LABEL_HEIGHT = 25;
|
||||||
|
|
||||||
private Simulation mySimulation = null;
|
private Simulation mySimulation = null;
|
||||||
private GUI myGUI = null;
|
|
||||||
|
|
||||||
private CreateSimDialog myDialog;
|
private JFormattedTextField randomSeed, delayedStartup;
|
||||||
|
|
||||||
private JFormattedTextField delayTime, simulationTime, tickTime;
|
|
||||||
private JFormattedTextField randomSeed, tickLists, delayedStartup;
|
|
||||||
private JCheckBox randomSeedGenerated;
|
private JCheckBox randomSeedGenerated;
|
||||||
|
|
||||||
private JTextField title;
|
private JTextField title;
|
||||||
|
@ -73,136 +90,86 @@ public class CreateSimDialog extends JDialog {
|
||||||
/**
|
/**
|
||||||
* Shows a dialog for configuring a simulation.
|
* Shows a dialog for configuring a simulation.
|
||||||
*
|
*
|
||||||
* @param parentContainer Parent container for dialog
|
* @param parent Parent container for dialog
|
||||||
* @param simulationToConfigure Simulation to configure
|
* @param simulation Simulation to configure
|
||||||
* @return True if simulation configured correctly
|
* @return True if simulation configured correctly
|
||||||
*/
|
*/
|
||||||
public static boolean showDialog(Container parentContainer, Simulation simulationToConfigure) {
|
public static boolean showDialog(Container parent, Simulation simulation) {
|
||||||
final CreateSimDialog myDialog;
|
final CreateSimDialog dialog = new CreateSimDialog((Window) parent, simulation.getGUI());
|
||||||
if (parentContainer instanceof Window) {
|
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
|
||||||
myDialog = new CreateSimDialog((Window) parentContainer, simulationToConfigure.getGUI());
|
dialog.addWindowListener(new WindowAdapter() {
|
||||||
} 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() {
|
|
||||||
public void windowDeactivated(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowIconified(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowDeiconified(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowOpened(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowClosed(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowActivated(WindowEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
myDialog.cancelButton.doClick();
|
dialog.cancelButton.doClick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
myDialog.mySimulation = simulationToConfigure;
|
dialog.mySimulation = simulation;
|
||||||
|
|
||||||
// Set title
|
// Set title
|
||||||
if (simulationToConfigure.getTitle() != null) {
|
if (simulation.getTitle() != null) {
|
||||||
// Title already preset
|
// Title already preset
|
||||||
myDialog.title.setText(simulationToConfigure.getTitle());
|
dialog.title.setText(simulation.getTitle());
|
||||||
} else {
|
} else {
|
||||||
// Suggest title
|
// Suggest title
|
||||||
myDialog.title.setText("My simulation");
|
dialog.title.setText("My simulation");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set delay time
|
|
||||||
myDialog.delayTime.setValue(new Integer(simulationToConfigure.getDelayTime()));
|
|
||||||
|
|
||||||
// Set simulation time
|
|
||||||
myDialog.simulationTime.setValue(new Long(simulationToConfigure.getSimulationTime()/Simulation.MILLISECOND));
|
|
||||||
|
|
||||||
// Select radio medium
|
// Select radio medium
|
||||||
if (simulationToConfigure.getRadioMedium() != null) {
|
if (simulation.getRadioMedium() != null) {
|
||||||
Class<? extends RadioMedium> radioMediumClass =
|
Class<? extends RadioMedium> radioMediumClass =
|
||||||
simulationToConfigure.getRadioMedium().getClass();
|
simulation.getRadioMedium().getClass();
|
||||||
|
|
||||||
String currentDescription = GUI.getDescriptionOf(radioMediumClass);
|
String currentDescription = GUI.getDescriptionOf(radioMediumClass);
|
||||||
|
|
||||||
for (int i=0; i < myDialog.radioMediumBox.getItemCount(); i++) {
|
for (int i=0; i < dialog.radioMediumBox.getItemCount(); i++) {
|
||||||
String menuDescription = (String) myDialog.radioMediumBox.getItemAt(i);
|
String menuDescription = (String) dialog.radioMediumBox.getItemAt(i);
|
||||||
if (menuDescription.equals(currentDescription)) {
|
if (menuDescription.equals(currentDescription)) {
|
||||||
myDialog.radioMediumBox.setSelectedIndex(i);
|
dialog.radioMediumBox.setSelectedIndex(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set random seed
|
// Set random seed
|
||||||
if (simulationToConfigure.getRandomSeedGenerated()) {
|
if (simulation.getRandomSeedGenerated()) {
|
||||||
myDialog.randomSeedGenerated.setSelected(true);
|
dialog.randomSeedGenerated.setSelected(true);
|
||||||
myDialog.randomSeed.setEnabled(false);
|
dialog.randomSeed.setEnabled(false);
|
||||||
myDialog.randomSeed.setText("[autogenerated]");
|
dialog.randomSeed.setText("[autogenerated]");
|
||||||
} else {
|
} else {
|
||||||
myDialog.randomSeed.setEnabled(true);
|
dialog.randomSeed.setEnabled(true);
|
||||||
myDialog.randomSeed.setValue(new Long(simulationToConfigure.getRandomSeed()));
|
dialog.randomSeed.setValue(new Long(simulation.getRandomSeed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set delayed mote startup time (ms)
|
// Set delayed mote startup time (ms)
|
||||||
myDialog.delayedStartup.setValue(new Long(simulationToConfigure.getDelayedMoteStartupTime()/Simulation.MILLISECOND));
|
dialog.delayedStartup.setValue(new Long(simulation.getDelayedMoteStartupTime()/Simulation.MILLISECOND));
|
||||||
|
|
||||||
|
|
||||||
// Set position and focus of dialog
|
// Set position and focus of dialog
|
||||||
myDialog.setLocationRelativeTo(parentContainer);
|
dialog.setLocationRelativeTo(parent);
|
||||||
myDialog.title.requestFocus();
|
dialog.title.requestFocus();
|
||||||
myDialog.title.select(0, myDialog.title.getText().length());
|
dialog.title.select(0, dialog.title.getText().length());
|
||||||
|
|
||||||
// Dispose on escape key
|
// Dispose on escape key
|
||||||
InputMap inputMap = myDialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "dispose");
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "dispose");
|
||||||
AbstractAction cancelAction = new AbstractAction(){
|
AbstractAction cancelAction = new AbstractAction(){
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
myDialog.cancelButton.doClick();
|
dialog.cancelButton.doClick();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
myDialog.getRootPane().getActionMap().put("dispose", cancelAction);
|
dialog.getRootPane().getActionMap().put("dispose", cancelAction);
|
||||||
|
|
||||||
myDialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
||||||
if (myDialog.mySimulation != null) {
|
if (dialog.mySimulation != null) {
|
||||||
// Simulation configured correctly
|
// Simulation configured correctly
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CreateSimDialog(Dialog dialog, GUI gui) {
|
|
||||||
super(dialog, "Create new simulation", ModalityType.APPLICATION_MODAL);
|
|
||||||
setupDialog(gui);
|
|
||||||
}
|
|
||||||
private CreateSimDialog(Window window, GUI gui) {
|
private CreateSimDialog(Window window, GUI gui) {
|
||||||
super(window, "Create new simulation", ModalityType.APPLICATION_MODAL);
|
super(window, "Create new simulation", ModalityType.APPLICATION_MODAL);
|
||||||
setupDialog(gui);
|
|
||||||
}
|
|
||||||
private CreateSimDialog(Frame frame, GUI gui) {
|
|
||||||
super(frame, "Create new simulation", ModalityType.APPLICATION_MODAL);
|
|
||||||
setupDialog(gui);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupDialog(GUI gui) {
|
|
||||||
myDialog = this;
|
|
||||||
myGUI = gui;
|
|
||||||
|
|
||||||
Box vertBox = Box.createVerticalBox();
|
Box vertBox = Box.createVerticalBox();
|
||||||
|
|
||||||
JLabel label;
|
JLabel label;
|
||||||
|
@ -221,15 +188,18 @@ public class CreateSimDialog extends JDialog {
|
||||||
buttonBox.add(Box.createHorizontalGlue());
|
buttonBox.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
cancelButton = new JButton("Cancel");
|
cancelButton = new JButton("Cancel");
|
||||||
cancelButton.setActionCommand("cancel");
|
cancelButton.addActionListener(new ActionListener() {
|
||||||
cancelButton.addActionListener(myEventHandler);
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
mySimulation = null;
|
||||||
|
dispose();
|
||||||
|
};
|
||||||
|
});
|
||||||
buttonBox.add(cancelButton);
|
buttonBox.add(cancelButton);
|
||||||
|
|
||||||
button = new JButton("Create");
|
button = new JButton("Create");
|
||||||
button.setActionCommand("create");
|
button.addActionListener(createSimulationListener);
|
||||||
button.addActionListener(myEventHandler);
|
|
||||||
buttonBox.add(Box.createHorizontalStrut(5));
|
buttonBox.add(Box.createHorizontalStrut(5));
|
||||||
myDialog.rootPane.setDefaultButton(button);
|
getRootPane().setDefaultButton(button);
|
||||||
buttonBox.add(button);
|
buttonBox.add(button);
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,54 +251,10 @@ public class CreateSimDialog extends JDialog {
|
||||||
vertBox.add(horizBox);
|
vertBox.add(horizBox);
|
||||||
vertBox.add(Box.createRigidArea(new Dimension(0,5)));
|
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 --
|
// -- Advanced settings --
|
||||||
Box advancedBox = Box.createVerticalBox();
|
Box advancedBox = Box.createVerticalBox();
|
||||||
advancedBox.setBorder(BorderFactory.createTitledBorder("Advanced settings"));
|
advancedBox.setBorder(BorderFactory.createTitledBorder("Advanced settings"));
|
||||||
|
|
||||||
// Start time
|
|
||||||
horizBox = Box.createHorizontalBox();
|
|
||||||
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
|
||||||
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);
|
|
||||||
numberField.setEnabled(false); /* Disabled: Almost never used */
|
|
||||||
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)));
|
|
||||||
|
|
||||||
// Delayed startup
|
// Delayed startup
|
||||||
horizBox = Box.createHorizontalBox();
|
horizBox = Box.createHorizontalBox();
|
||||||
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
||||||
|
@ -349,30 +275,6 @@ public class CreateSimDialog extends JDialog {
|
||||||
advancedBox.add(horizBox);
|
advancedBox.add(horizBox);
|
||||||
advancedBox.add(Box.createVerticalStrut(5));
|
advancedBox.add(Box.createVerticalStrut(5));
|
||||||
|
|
||||||
advancedBox.add(Box.createVerticalStrut(5));
|
|
||||||
|
|
||||||
// Delay time
|
|
||||||
horizBox = Box.createHorizontalBox();
|
|
||||||
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
|
||||||
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);
|
|
||||||
horizBox.setToolTipText("Delay between each simulated millisecond. Controls simulation speed.");
|
|
||||||
|
|
||||||
advancedBox.add(horizBox);
|
|
||||||
advancedBox.add(Box.createVerticalStrut(5));
|
|
||||||
|
|
||||||
advancedBox.add(Box.createVerticalStrut(5));
|
|
||||||
|
|
||||||
// Random seed
|
// Random seed
|
||||||
horizBox = Box.createHorizontalBox();
|
horizBox = Box.createHorizontalBox();
|
||||||
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT));
|
||||||
|
@ -420,18 +322,12 @@ public class CreateSimDialog extends JDialog {
|
||||||
pack();
|
pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AddSimEventHandler implements ActionListener {
|
private ActionListener createSimulationListener = new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (e.getActionCommand().equals("cancel")) {
|
|
||||||
mySimulation = null;
|
|
||||||
dispose();
|
|
||||||
} else if (e.getActionCommand().equals("create")) {
|
|
||||||
mySimulation.setDelayTime(((Number) delayTime.getValue()).intValue());
|
|
||||||
mySimulation.setSimulationTime(((Number) simulationTime.getValue()).intValue());
|
|
||||||
mySimulation.setTitle(title.getText());
|
mySimulation.setTitle(title.getText());
|
||||||
|
|
||||||
String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem();
|
String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem();
|
||||||
for (Class<? extends RadioMedium> radioMediumClass: myGUI.getRegisteredRadioMediums()) {
|
for (Class<? extends RadioMedium> radioMediumClass: mySimulation.getGUI().getRegisteredRadioMediums()) {
|
||||||
String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass);
|
String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass);
|
||||||
|
|
||||||
if (currentRadioMediumDescription.equals(radioMediumDescription)) {
|
if (currentRadioMediumDescription.equals(radioMediumDescription)) {
|
||||||
|
@ -439,8 +335,7 @@ public class CreateSimDialog extends JDialog {
|
||||||
RadioMedium radioMedium = RadioMedium.generateRadioMedium(radioMediumClass, mySimulation);
|
RadioMedium radioMedium = RadioMedium.generateRadioMedium(radioMediumClass, mySimulation);
|
||||||
mySimulation.setRadioMedium(radioMedium);
|
mySimulation.setRadioMedium(radioMedium);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Exception when creating radio medium: " + ex);
|
logger.fatal("Error generating radio medium: " + ex.getMessage(), ex);
|
||||||
ex.printStackTrace();
|
|
||||||
mySimulation.setRadioMedium(null);
|
mySimulation.setRadioMedium(null);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -459,7 +354,6 @@ public class CreateSimDialog extends JDialog {
|
||||||
|
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue