⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addmotedialog.java

📁 Contiki is an open source, highly portable, multi-tasking operating system for memory-constrained n
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2006, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. Neither the name of the Institute nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: AddMoteDialog.java,v 1.3 2007/01/10 14:59:07 fros4943 Exp $ */package se.sics.cooja.dialogs;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.text.*;import java.util.*;import javax.swing.*;import org.apache.log4j.Logger;import se.sics.cooja.*;import se.sics.cooja.interfaces.*;/** * A dialog for adding motes. *  * @author Fredrik Osterlind */public class AddMoteDialog extends JDialog {  private static final long serialVersionUID = 1L;  private static Logger logger = Logger.getLogger(AddMoteDialog.class);  private AddMotesEventHandler myEventHandler = new AddMotesEventHandler();  private final static int LABEL_WIDTH = 170;  private final static int LABEL_HEIGHT = 15;  private Vector<Mote> newMotes = null;  private boolean settingsOK = true;  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<Mote> showDialog(Frame parentFrame,      Simulation simulation, MoteType moteType) {    AddMoteDialog myDialog = new AddMoteDialog(parentFrame, simulation, moteType);    myDialog.setLocationRelativeTo(parentFrame);    myDialog.checkSettings();    if (myDialog != null) {      myDialog.setVisible(true);    }    return myDialog.newMotes;  }  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));    JPanel smallPane;    JFormattedTextField numberField;    JButton button;    JComboBox comboBox;    NumberFormat integerFormat = NumberFormat.getIntegerInstance();    NumberFormat doubleFormat = NumberFormat.getNumberInstance();    // BOTTOM BUTTON PART    JPanel buttonPane = new JPanel();    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));    buttonPane.add(Box.createHorizontalGlue());    button = new JButton("Cancel");    button.setActionCommand("cancel");    button.addActionListener(myEventHandler);    buttonPane.add(button);    button = new JButton("Create and Add");    button.setEnabled(settingsOK);    button.setActionCommand("add");    button.addActionListener(myEventHandler);    this.getRootPane().setDefaultButton(button);    addButton = button;    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));    buttonPane.add(button);    // MAIN PART    // Number of new motes    smallPane = new JPanel();    smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);    smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));    label = new JLabel("Number of new motes");    label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));    numberField = new JFormattedTextField(integerFormat);    numberField.setValue(new Integer(1));    numberField.setColumns(10);    numberField.addPropertyChangeListener("value", myEventHandler);    numberOfMotesField = numberField;    smallPane.add(label);    smallPane.add(Box.createHorizontalStrut(10));    smallPane.add(numberField);    mainPane.add(smallPane);    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));    // IP address distribution    smallPane = new JPanel();    smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);    smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));    label = new JLabel("IP Addressing");    label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));    Vector<Class<? extends IPDistributor>> ipDistributors = simulation.getGUI()        .getRegisteredIPDistributors();    String[] ipDistributions = new String[ipDistributors.size()];    for (int i = 0; i < ipDistributions.length; i++)      ipDistributions[i] = GUI.getDescriptionOf(ipDistributors.get(i));    comboBox = new JComboBox(ipDistributions);    comboBox.setSelectedIndex(0);    comboBox.addActionListener(myEventHandler);    comboBox.addFocusListener(myEventHandler);    ipDistributionBox = comboBox;    label.setLabelFor(comboBox);    smallPane.add(label);    smallPane.add(Box.createHorizontalStrut(10));    smallPane.add(comboBox);    mainPane.add(smallPane);    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));    // Position distribution    smallPane = new JPanel();    smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);    smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));    label = new JLabel("Positioning");    label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));    Vector<Class<? extends Positioner>> positioners = simulation.getGUI()        .getRegisteredPositioners();    String[] posDistributions = new String[positioners.size()];    for (int i = 0; i < posDistributions.length; i++)      posDistributions[i] = GUI.getDescriptionOf(positioners.get(i));    comboBox = new JComboBox(posDistributions);    comboBox.setSelectedIndex(0);    comboBox.addActionListener(myEventHandler);    comboBox.addFocusListener(myEventHandler);    positionDistributionBox = comboBox;    label.setLabelFor(comboBox);    smallPane.add(label);    smallPane.add(Box.createHorizontalStrut(10));    smallPane.add(comboBox);    mainPane.add(smallPane);    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));    // Position interval X    smallPane = new JPanel();    smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);    smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));    label = new JLabel("Position interval");    label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));    smallPane.add(label);    smallPane.add(Box.createHorizontalStrut(10));    label = new JLabel("X ");    smallPane.add(label);    smallPane.add(Box.createHorizontalStrut(10));    numberField = new JFormattedTextField(doubleFormat);    numberField.setValue(new Double(0.0));    numberField.setColumns(4);    numberField.addPropertyChangeListener("value", myEventHandler);    startX = numberField;    smallPane.add(numberField);    smallPane.add(Box.createHorizontalStrut(10));    label = new JLabel("<->");    label.setPreferredSize(new Dimension(LABEL_WIDTH / 4, LABEL_HEIGHT));    smallPane.add(label);    numberField = new JFormattedTextField(doubleFormat);    numberField.setValue(new Double(100.0));    numberField.setColumns(4);    numberField.addPropertyChangeListener("value", myEventHandler);    endX = numberField;    smallPane.add(numberField);    smallPane.add(Box.createHorizontalStrut(10));    mainPane.add(smallPane);    mainPane.add(Box.createRigidArea(new Dimension(0, 5)));    // Position interval Y    smallPane = new JPanel();    smallPane.setAlignmentX(Component.LEFT_ALIGNMENT);    smallPane.setLayout(new BoxLayout(smallPane, BoxLayout.X_AXIS));    label = new JLabel("");    label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -