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

📄 contikimotetypedialog.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * 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: ContikiMoteTypeDialog.java,v 1.49 2008/11/03 18:32:22 fros4943 Exp $ */package se.sics.cooja.contikimote;import java.awt.*;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.StringSelection;import java.awt.event.*;import java.io.*;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.*;import java.util.regex.*;import javax.swing.*;import javax.swing.event.*;import org.apache.log4j.Logger;import se.sics.cooja.*;import se.sics.cooja.MoteType.MoteTypeCreationException;import se.sics.cooja.contikimote.ContikiMoteType.CommunicationStack;import se.sics.cooja.dialogs.MessageList;import se.sics.cooja.dialogs.ProjectDirectoriesDialog;/** * A dialog for configuring Contiki mote types and compiling Contiki mote type * libraries. Allows user to change mote type specific data such as * descriptions, which processes should be started at mote initialization and * which interfaces the type should support. * * The dialog takes a Contiki mote type as argument and pre-selects the values * already set in that mote type before showing the dialog. Any changes made to * the settings are written to the mote type if the compilation is successful * and the user presses OK. * * This dialog uses external tools to scan for sources and compile libraries. * * @author Fredrik Osterlind */public class ContikiMoteTypeDialog extends JDialog {  private static final long serialVersionUID = 1L;  private static Logger logger = Logger.getLogger(ContikiMoteTypeDialog.class);  private MoteTypeEventHandler myEventHandler = new MoteTypeEventHandler();  private Thread compilationThread;  /**   * Suggested mote type identifier prefix   */  public static final String ID_PREFIX = "mtype";  private final static int LABEL_WIDTH = 170;  private final static int LABEL_HEIGHT = 15;  private ContikiMoteType myMoteType = null;  private JTextField textID, textOutputFiles, textDescription, textContikiDir,      textCoreDir, textProjectDirs;  private JButton createButton, testButton, rescanButton;  private JCheckBox symbolsCheckBox;  private JComboBox commStackComboBox;  private JPanel processPanel; // Holds process checkboxes  private JPanel sensorPanel; // Holds sensor checkboxes  private JPanel moteInterfacePanel; // Holds mote interface checkboxes  private JPanel coreInterfacePanel; // Holds core interface checkboxes  private JPanel entireSensorPane; // Holds entire sensor pane (can be hidden)  private JPanel entireCoreInterfacePane; // Holds entire core interface pane  // (can be hidden)  private boolean settingsOK = false; // Do all settings seem correct?  private boolean compilationSucceded = false; // Did compilation succeed?  private boolean libraryCreatedOK = false; // Was a library created?  private ProjectConfig newMoteTypeConfig = null; // Mote type project config  private Vector<File> moteTypeProjectDirs = new Vector<File>(); // Mote type project directories  private Vector<File> compilationFiles = null;  private Vector<MoteType> allOtherTypes = null; // Used to check for  // conflicting parameters  private GUI myGUI = null;  private ContikiMoteTypeDialog myDialog;  /**   * Shows a dialog for configuring a Contiki mote type and compiling the shared   * library it uses.   *   * @param parentContainer   *          Parent container for dialog   * @param simulation   *          Simulation holding (or that will hold) mote type   * @param moteTypeToConfigure   *          Mote type to configure   * @return True if compilation succeeded and library is ready to be loaded   */  public static boolean showDialog(Container parentContainer, Simulation simulation,      ContikiMoteType moteTypeToConfigure) {    ContikiMoteTypeDialog myDialog = null;    if (parentContainer instanceof Window) {      myDialog = new ContikiMoteTypeDialog((Window) parentContainer);    } else if (parentContainer instanceof Dialog) {      myDialog = new ContikiMoteTypeDialog((Dialog) parentContainer);    } else if (parentContainer instanceof Frame) {      myDialog = new ContikiMoteTypeDialog((Frame) parentContainer);    } else {      logger.fatal("Unknown parent container type: " + parentContainer);      return false;    }    myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);    myDialog.myMoteType = moteTypeToConfigure;    myDialog.myGUI = simulation.getGUI();    myDialog.allOtherTypes = simulation.getMoteTypes();    // Set identifier of mote type    if (moteTypeToConfigure.getIdentifier() != null) {      // Identifier already preset, assuming recompilation of mote type library      // Use preset identifier (read-only)      myDialog.textID.setText(moteTypeToConfigure.getIdentifier());      myDialog.textID.setEditable(false);      myDialog.textID.setEnabled(false);      // Change title to indicate this is a recompilation      myDialog.setTitle("Recreate Mote Type");    } else {      // Suggest new identifier      String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(myDialog.allOtherTypes, null);      myDialog.textID.setText(suggestedID);    }    // Set preset description of mote type    if (moteTypeToConfigure.getDescription() != null) {      myDialog.textDescription.setText(moteTypeToConfigure.getDescription());    } else {      // Suggest unique description      int counter = 0;      String testDescription = "";      boolean descriptionOK = false;      while (!descriptionOK) {        counter++;        testDescription = "Contiki Mote #" + counter;        descriptionOK = true;        // Check if identifier is already used by some other type        for (MoteType existingMoteType : myDialog.allOtherTypes) {          if (existingMoteType != myDialog.myMoteType              && existingMoteType.getDescription().equals(testDescription)) {            descriptionOK = false;            break;          }        }      }      myDialog.textDescription.setText(testDescription);    }    // Set preset Contiki base directory of mote type    if (moteTypeToConfigure.getContikiBaseDir() != null) {      myDialog.textContikiDir.setText(moteTypeToConfigure.getContikiBaseDir());    }    // Set preset Contiki core directory of mote type    if (moteTypeToConfigure.getContikiCoreDir() != null) {      myDialog.textCoreDir.setText(moteTypeToConfigure.getContikiCoreDir());    }    // Set preset project directories of mote type    if (moteTypeToConfigure.getProjectDirs() != null) {      myDialog.moteTypeProjectDirs = moteTypeToConfigure          .getProjectDirs();      String projectText = null;      for (File projectDir : myDialog.moteTypeProjectDirs) {        if (projectText == null) {          projectText = "'" + projectDir.getPath() + "'";        } else {          projectText += ", '" + projectDir.getPath() + "'";        }      }      myDialog.textProjectDirs.setText(projectText);    }    // Set preset "use symbols"    if (moteTypeToConfigure.hasSystemSymbols()) {      myDialog.symbolsCheckBox.setSelected(true);    }    // Set preset communication stack    myDialog.commStackComboBox.setSelectedItem(moteTypeToConfigure.getCommunicationStack());    // Scan directories for processes, sensors and core interfaces    // TODO Really do this without starting a separate thread?    myDialog.updateVisualFields();    myDialog.rescanDirectories();    // Select preset processes of mote type    if (moteTypeToConfigure.getProcesses() != null) {      for (String presetProcess : moteTypeToConfigure.getProcesses()) {        // Try to find process in current list        boolean foundAndSelectedProcess = false;        for (Component processCheckBox : myDialog.processPanel.getComponents()) {          boolean inCompileFile = false;          ContikiProcess process = (ContikiProcess) ((JCheckBox) processCheckBox).getClientProperty("process");          for (File compileFile: moteTypeToConfigure.getCompilationFiles()) {            if (process != null && compileFile.getName().equals(process.getSourceFile().getName())) {              inCompileFile = true;              break;            }          }          if (inCompileFile &&              presetProcess.equals(process.getProcessName())) {            ((JCheckBox) processCheckBox).setSelected(true);            foundAndSelectedProcess = true;            break;          }        }        // Warn if not found        if (!foundAndSelectedProcess) {          // Let user choose whether to add process          Object[] options = { "Add", "Cancel" };          String question = "The configuration file contains a process "            + "(" + presetProcess + ") not found during scan."            + "\nDo you want to include this anyway?";          String title = "Add process?";          int answer = JOptionPane.showOptionDialog(myDialog, question, title,              JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,              options, options[0]);          if (answer == JOptionPane.YES_OPTION) {            // Create new check box            JCheckBox newCheckBox = new JCheckBox(presetProcess, true);            myDialog.processPanel.add(newCheckBox);          }        }      }    }    // Select preset sensors    if (moteTypeToConfigure.getSensors() != null) {      // Deselect all sensors already automatically selected      for (Component coreInterfaceCheckBox : myDialog.sensorPanel          .getComponents()) {        ((JCheckBox) coreInterfaceCheckBox).setSelected(false);      }      for (String presetSensor : moteTypeToConfigure.getSensors()) {        // Try to find sensor in current list        boolean foundAndSelectedSensor = false;        for (Component sensorCheckBox : myDialog.sensorPanel.getComponents()) {          if (presetSensor.equals(((JCheckBox) sensorCheckBox).getText())) {            ((JCheckBox) sensorCheckBox).setSelected(true);            foundAndSelectedSensor = true;            break;          }        }        // Warn if not found        if (!foundAndSelectedSensor) {          // Let user choose whether to add sensor          Object[] options = { "Add", "Cancel" };          String question = "The configuration file contains a sensor "            + "(" + presetSensor + ") not found during scan."            + "\nDo you want to include this anyway?";          String title = "Add sensor?";          int answer = JOptionPane.showOptionDialog(myDialog, question, title,              JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,              options, options[0]);          if (answer == JOptionPane.YES_OPTION) {            // Create new check box            JCheckBox newCheckBox = new JCheckBox(presetSensor, true);            myDialog.sensorPanel.add(newCheckBox);          }        }      }    }    // Select preset core interfaces    if (moteTypeToConfigure.getCoreInterfaces() != null) {      // Deselect all core interfaces already automatically selected      for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel          .getComponents()) {        ((JCheckBox) coreInterfaceCheckBox).setSelected(false);      }      for (String presetCoreInterface : moteTypeToConfigure.getCoreInterfaces()) {        // Try to find core interface in current list        boolean foundAndSelectedCoreInterface = false;        for (Component coreInterfaceCheckBox : myDialog.coreInterfacePanel            .getComponents()) {          if (presetCoreInterface.equals(((JCheckBox) coreInterfaceCheckBox)              .getText())) {            ((JCheckBox) coreInterfaceCheckBox).setSelected(true);            foundAndSelectedCoreInterface = true;            break;          }        }        // Warn if not found        if (!foundAndSelectedCoreInterface) {          // Let user choose whether to add interface          Object[] options = { "Add", "Cancel" };          String question = "The configuration file contains a core interface "            + "(" + presetCoreInterface + ") not found during scan."            + "\nDo you want to include this anyway?";          String title = "Add core interface?";          int answer = JOptionPane.showOptionDialog(myDialog, question, title,              JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,              options, options[0]);          if (answer == JOptionPane.YES_OPTION) {            // Create new check box            JCheckBox newCheckBox = new JCheckBox(presetCoreInterface, true);            myDialog.coreInterfacePanel.add(newCheckBox);          }        }      }    }    // Select preset mote interfaces    if (moteTypeToConfigure.getMoteInterfaces() != null) {      // Deselect all mote interfaces already automatically selected      for (Component moteInterfaceCheckBox : myDialog.moteInterfacePanel          .getComponents()) {        ((JCheckBox) moteInterfaceCheckBox).setSelected(false);

⌨️ 快捷键说明

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