📄 createsimdialog.java
字号:
horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Radio Medium"); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); Vector<String> radioMediumDescriptions = new Vector<String>(); for (Class<? extends RadioMedium> radioMediumClass: gui.getRegisteredRadioMediums()) { 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(); 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); 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); horizBox.setToolTipText("Simulated time increase each simulation loop"); 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); horizBox.setToolTipText("Maximum mote startup delay (random interval: [0, time])"); advancedBox.add(horizBox); 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 time step"); advancedBox.add(horizBox); advancedBox.add(Box.createVerticalStrut(5)); advancedBox.add(Box.createVerticalStrut(5)); // Random seed horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); 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); tickLists = numberField; horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); horizBox.add(numberField); horizBox.setToolTipText("<html>Number of tick lists.<p>Every simulated mote belongs to a tick list, and each simulated loop only one list is allowed to act.<br>If the number of tick lists is 1, all motes are tick every simulation time increase.</html>"); 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")) { mySimulation = null; dispose(); } else if (e.getActionCommand().equals("create")) { mySimulation.setDelayTime(((Number) delayTime.getValue()).intValue()); mySimulation.setSimulationTime(((Number) simulationTime.getValue()).intValue()); mySimulation.setTickTime(((Number) tickTime.getValue()).intValue()); mySimulation.setTitle(title.getText()); String currentRadioMediumDescription = (String) radioMediumBox.getSelectedItem(); for (Class<? extends RadioMedium> radioMediumClass: myGUI.getRegisteredRadioMediums()) { String radioMediumDescription = GUI.getDescriptionOf(radioMediumClass); if (currentRadioMediumDescription.equals(radioMediumDescription)) { try { RadioMedium radioMedium = RadioMedium.generateRadioMedium(radioMediumClass, mySimulation); 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(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -