minor updates due to removed static variables and new method params

This commit is contained in:
fros4943 2007-01-09 10:03:51 +00:00
parent 6a6b900955
commit 2fd44015fa
2 changed files with 27 additions and 18 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: 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; package se.sics.cooja.dialogs;
@ -63,24 +63,29 @@ public class AddMoteDialog extends JDialog {
private JButton addButton; private JButton addButton;
private MoteType moteType = null; private MoteType moteType = null;
private Simulation simulation = null;
private JFormattedTextField numberOfMotesField, startX, endX, startY, endY, private JFormattedTextField numberOfMotesField, startX, endX, startY, endY,
startZ, endZ; startZ, endZ;
private JComboBox positionDistributionBox, ipDistributionBox; private JComboBox positionDistributionBox, ipDistributionBox;
/** /**
* Shows a dialog which enables a user to create and add motes of the given * Shows a dialog which enables a user to create and add motes of the given
* type. * type.
* *
* @param parentFrame * @param parentFrame
* Parent frame for dialog * Parent frame for dialog
* @param simulation
* Simulation
* @param moteType * @param moteType
* Mote type * Mote type
* @return New motes or null if aborted * @return New motes or null if aborted
*/ */
public static Vector<Mote> showDialog(Frame parentFrame, MoteType moteType) { public static Vector<Mote> showDialog(Frame parentFrame,
Simulation simulation, MoteType moteType) {
AddMoteDialog myDialog = new AddMoteDialog(parentFrame, moteType); AddMoteDialog myDialog = new AddMoteDialog(parentFrame, simulation, moteType);
myDialog.setLocationRelativeTo(parentFrame); myDialog.setLocationRelativeTo(parentFrame);
myDialog.checkSettings(); myDialog.checkSettings();
@ -90,10 +95,11 @@ public class AddMoteDialog extends JDialog {
return myDialog.newMotes; return myDialog.newMotes;
} }
private AddMoteDialog(Frame frame, MoteType moteType) { private AddMoteDialog(Frame frame, Simulation simulation, MoteType moteType) {
super(frame, "Add motes (" + moteType.getDescription() + ")", true); super(frame, "Add motes (" + moteType.getDescription() + ")", true);
this.moteType = moteType; this.moteType = moteType;
this.simulation = simulation;
JLabel label; JLabel label;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
@ -154,7 +160,7 @@ public class AddMoteDialog extends JDialog {
label = new JLabel("IP Addressing"); label = new JLabel("IP Addressing");
label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));
Vector<Class<? extends IPDistributor>> ipDistributors = GUI.currentGUI Vector<Class<? extends IPDistributor>> ipDistributors = simulation.getGUI()
.getRegisteredIPDistributors(); .getRegisteredIPDistributors();
String[] ipDistributions = new String[ipDistributors.size()]; String[] ipDistributions = new String[ipDistributors.size()];
for (int i = 0; i < ipDistributions.length; i++) for (int i = 0; i < ipDistributions.length; i++)
@ -182,7 +188,7 @@ public class AddMoteDialog extends JDialog {
label = new JLabel("Positioning"); label = new JLabel("Positioning");
label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));
Vector<Class<? extends Positioner>> positioners = GUI.currentGUI Vector<Class<? extends Positioner>> positioners = simulation.getGUI()
.getRegisteredPositioners(); .getRegisteredPositioners();
String[] posDistributions = new String[positioners.size()]; String[] posDistributions = new String[positioners.size()];
for (int i = 0; i < posDistributions.length; i++) for (int i = 0; i < posDistributions.length; i++)
@ -409,13 +415,13 @@ public class AddMoteDialog extends JDialog {
// Create new motes // Create new motes
int motesToAdd = ((Number) numberOfMotesField.getValue()).intValue(); int motesToAdd = ((Number) numberOfMotesField.getValue()).intValue();
while (newMotes.size() < motesToAdd) { while (newMotes.size() < motesToAdd) {
Mote newMote = moteType.generateMote(GUI.currentSimulation); Mote newMote = moteType.generateMote(simulation);
newMotes.add(newMote); newMotes.add(newMote);
} }
// Position new motes // Position new motes
Class<? extends Positioner> positionerClass = null; Class<? extends Positioner> positionerClass = null;
for (Class<? extends Positioner> positioner : GUI.currentGUI for (Class<? extends Positioner> positioner : simulation.getGUI()
.getRegisteredPositioners()) { .getRegisteredPositioners()) {
if (GUI.getDescriptionOf(positioner).equals( if (GUI.getDescriptionOf(positioner).equals(
(String) positionDistributionBox.getSelectedItem())) (String) positionDistributionBox.getSelectedItem()))
@ -455,8 +461,8 @@ public class AddMoteDialog extends JDialog {
// Set unique mote id's for all new motes // Set unique mote id's for all new motes
int nextMoteID = 1; int nextMoteID = 1;
for (int i = 0; i < GUI.currentSimulation.getMotesCount(); i++) { for (int i = 0; i < simulation.getMotesCount(); i++) {
MoteID moteID = GUI.currentSimulation.getMote(i).getInterfaces() MoteID moteID = simulation.getMote(i).getInterfaces()
.getMoteID(); .getMoteID();
if (moteID != null && moteID.getMoteID() >= nextMoteID) if (moteID != null && moteID.getMoteID() >= nextMoteID)
nextMoteID = moteID.getMoteID() + 1; nextMoteID = moteID.getMoteID() + 1;
@ -471,7 +477,7 @@ public class AddMoteDialog extends JDialog {
// IP address new motes // IP address new motes
Class<? extends IPDistributor> ipDistClass = null; Class<? extends IPDistributor> ipDistClass = null;
for (Class<? extends IPDistributor> ipDistributor : GUI.currentGUI for (Class<? extends IPDistributor> ipDistributor : simulation.getGUI()
.getRegisteredIPDistributors()) { .getRegisteredIPDistributors()) {
if (GUI.getDescriptionOf(ipDistributor).equals( if (GUI.getDescriptionOf(ipDistributor).equals(
(String) ipDistributionBox.getSelectedItem())) (String) ipDistributionBox.getSelectedItem()))

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: 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; package se.sics.cooja.dialogs;
@ -57,6 +57,7 @@ public class CreateSimDialog extends JDialog {
private final static int LABEL_HEIGHT = 15; private final static int LABEL_HEIGHT = 15;
private Simulation mySimulation = null; private Simulation mySimulation = null;
private GUI myGUI = null;
private CreateSimDialog myDialog; private CreateSimDialog myDialog;
@ -75,7 +76,7 @@ public class CreateSimDialog extends JDialog {
* @return True if simulation configured correctly * @return True if simulation configured correctly
*/ */
public static boolean showDialog(Frame parentFrame, Simulation simulationToConfigure) { public static boolean showDialog(Frame parentFrame, Simulation simulationToConfigure) {
CreateSimDialog myDialog = new CreateSimDialog(parentFrame); CreateSimDialog myDialog = new CreateSimDialog(parentFrame, simulationToConfigure.getGUI());
myDialog.mySimulation = simulationToConfigure; myDialog.mySimulation = simulationToConfigure;
@ -127,10 +128,11 @@ public class CreateSimDialog extends JDialog {
return false; return false;
} }
private CreateSimDialog(Frame frame) { private CreateSimDialog(Frame frame, GUI gui) {
super(frame, "Create new simulation", true); super(frame, "Create new simulation", true);
myDialog = this; myDialog = this;
myGUI = gui;
JPanel mainPane = new JPanel(); JPanel mainPane = new JPanel();
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); 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)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
Vector<String> radioMediumDescriptions = new Vector<String>(); Vector<String> radioMediumDescriptions = new Vector<String>();
for (Class<? extends RadioMedium> radioMediumClass: GUI.currentGUI.getRegisteredRadioMediums()) { for (Class<? extends RadioMedium> radioMediumClass: gui.getRegisteredRadioMediums()) {
String description = GUI.getDescriptionOf(radioMediumClass); String description = GUI.getDescriptionOf(radioMediumClass);
radioMediumDescriptions.add(description); radioMediumDescriptions.add(description);
} }
@ -312,12 +314,13 @@ public class CreateSimDialog extends JDialog {
mySimulation.setTitle(title.getText()); mySimulation.setTitle(title.getText());
String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem(); String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem();
for (Class<? extends RadioMedium> radioMediumClass: GUI.currentGUI.getRegisteredRadioMediums()) { for (Class<? extends RadioMedium> radioMediumClass: myGUI.getRegisteredRadioMediums()) {
String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass); String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass);
if (currentRadioMediumDescription.equals(radioMediumDescription)) { if (currentRadioMediumDescription.equals(radioMediumDescription)) {
try { try {
mySimulation.setRadioMedium(radioMediumClass.newInstance()); RadioMedium radioMedium = RadioMedium.generateInterface(radioMediumClass, mySimulation);
mySimulation.setRadioMedium(radioMedium);
} catch (Exception ex) { } catch (Exception ex) {
logger.fatal("Exception when creating radio medium: " + ex); logger.fatal("Exception when creating radio medium: " + ex);
mySimulation.setRadioMedium(null); mySimulation.setRadioMedium(null);