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

📄 gui.java

📁 Contiki is an open source, highly portable, multi-tasking operating system for memory-constrained n
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    menu.addSeparator();    menuItem = new JMenuItem("Exit");    menuItem.setMnemonic(KeyEvent.VK_X);    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,        ActionEvent.CTRL_MASK));    menuItem.setActionCommand("quit");    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    // Simulation menu    menu = new JMenu("Simulation");    menu.setMnemonic(KeyEvent.VK_S);    menuBar.add(menu);    menuItem = new JMenuItem("Open Control");    menuItem.setMnemonic(KeyEvent.VK_C);    menuItem.setActionCommand("start plugin");    menuItem.putClientProperty("class", SimControl.class);    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    menuItem = new JMenuItem("Information");    menuItem.setMnemonic(KeyEvent.VK_I);    menuItem.setActionCommand("start plugin");    menuItem.putClientProperty("class", SimInformation.class);    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    // Mote type menu    menu = new JMenu("Mote Types");    menu.setMnemonic(KeyEvent.VK_T);    menuBar.add(menu);    // Mote type classes sub menu    menuMoteTypeClasses = new JMenu("Create mote type");    menuMoteTypeClasses.setMnemonic(KeyEvent.VK_C);    menuMoteTypeClasses.addMenuListener(new MenuListener() {      public void menuSelected(MenuEvent e) {        // Clear menu        menuMoteTypeClasses.removeAll();        // Recreate menu items        JMenuItem menuItem;        for (Class<? extends MoteType> moteTypeClass : moteTypeClasses) {          String description = GUI.getDescriptionOf(moteTypeClass);          menuItem = new JMenuItem(description);          menuItem.setActionCommand("create mote type");          menuItem.putClientProperty("class", moteTypeClass);          menuItem.addActionListener(guiEventHandler);          menuMoteTypeClasses.add(menuItem);        }      }      public void menuDeselected(MenuEvent e) {      }      public void menuCanceled(MenuEvent e) {      }    });    menu.add(menuMoteTypeClasses);    menuItem = new JMenuItem("Information");    menuItem.setActionCommand("start plugin");    menuItem.putClientProperty("class", MoteTypeInformation.class);    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    // Mote menu    menu = new JMenu("Motes");    menu.setMnemonic(KeyEvent.VK_M);    menuBar.add(menu);    // Mote types sub menu    menuMoteTypes = new JMenu("Add motes of type");    menuMoteTypes.setMnemonic(KeyEvent.VK_A);    menuMoteTypes.addMenuListener(new MenuListener() {      public void menuSelected(MenuEvent e) {        // Clear menu        menuMoteTypes.removeAll();        if (mySimulation == null) {          return;        }        // Recreate menu items        JMenuItem menuItem;        for (MoteType moteType : mySimulation.getMoteTypes()) {          menuItem = new JMenuItem(moteType.getDescription());          menuItem.setActionCommand("add motes");          menuItem.setToolTipText(getDescriptionOf(moteType.getClass()));          menuItem.putClientProperty("motetype", moteType);          menuItem.addActionListener(guiEventHandler);          menuMoteTypes.add(menuItem);        }      }      public void menuDeselected(MenuEvent e) {      }      public void menuCanceled(MenuEvent e) {      }    });    menu.add(menuMoteTypes);    menuItem = new JMenuItem("Remove all motes");    menuItem.setActionCommand("remove all motes");    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    // Plugins menu    menuPlugins = new JMenu("Plugins");    menuPlugins.setMnemonic(KeyEvent.VK_P);    menuBar.add(menuPlugins);    // Settings menu    menu = new JMenu("Settings");    menuBar.add(menu);    menuItem = new JMenuItem("External tools paths");    menuItem.setActionCommand("edit paths");    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    menuItem = new JMenuItem("Manage project directories");    menuItem.setActionCommand("manage projects");    menuItem.addActionListener(guiEventHandler);    menu.add(menuItem);    // Mote plugins popup menu (not available via menu bar)    menuMotePluginClasses = new Vector<Class<? extends Plugin>>();    return menuBar;  }  private static void createAndShowGUI() {    // Make sure we have nice window decorations.    JFrame.setDefaultLookAndFeelDecorated(true);    JDialog.setDefaultLookAndFeelDecorated(true);    // Create and set up the window.    frame = new JFrame("COOJA Simulator");    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);    // Create and set up the content pane.    JDesktopPane desktop = new JDesktopPane();    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);    GUI gui = new GUI(desktop, true);    JComponent newContentPane = gui.getDesktopPane();    newContentPane.setOpaque(true);    frame.setContentPane(newContentPane);    frame.setSize(700, 700);    frame.setLocationRelativeTo(null);    frame.addWindowListener(gui.guiEventHandler);    // Restore last frame size and position    if (frame != null) {      int framePosX = Integer.parseInt(getExternalToolsSetting("FRAME_POS_X", "-1"));      int framePosY = Integer.parseInt(getExternalToolsSetting("FRAME_POS_Y", "-1"));      int frameWidth = Integer.parseInt(getExternalToolsSetting("FRAME_WIDTH", "-1"));      int frameHeight = Integer.parseInt(getExternalToolsSetting("FRAME_HEIGHT", "-1"));      if (framePosX >= 0 && framePosY >= 0 && frameWidth > 0 && frameHeight > 0) {        frame.setLocation(framePosX, framePosY);        frame.setSize(frameWidth, frameHeight);      }    }    // Display the window.    frame.setVisible(true);  }  /**   * @return Current desktop pane (simulator visualizer)   */  public JDesktopPane getDesktopPane() {    return myDesktopPane;  }  /**   * Quick-starts a simulation using given parameters. TODO Experimental code   *    * @param moteTypeID   *          Mote type ID (if null "mtype1" will be used)   * @param projectDirs   *          GUI project directories   * @param sensors   *          Contiki sensors (if null sensors will be scanned for)   * @param coreInterfaces   *          COOJA core interfaces (if null interfaces will be scanned for)   * @param userProcesses   *          Contiki user processes (if null processes all in given main file   *          will be added)   * @param addAutostartProcesses   *          Should autostart processes automatically be added?   * @param numberOfNodes   *          Number of nodes to add   * @param areaSideLength   *          Side of node positioning square   * @param delayTime   *          Initial delay time   * @param simulationStartinge   *          Simulation automatically started?   * @param filename   *          Main Contiki process file   * @param contikiPath   *          Contiki path   * @return True if simulation was quickstarted correctly   */  private static boolean quickStartSimulation(String moteTypeID,      Vector<String> projectDirs, Vector<String> sensors,      Vector<String> coreInterfaces, Vector<String> userProcesses,      boolean addAutostartProcesses, int numberOfNodes, double areaSideLength,      int delayTime, boolean simulationStarting, String filename,      String contikiPath) {    // Create GUI and GUI frame (not visible yet)    JFrame.setDefaultLookAndFeelDecorated(true);    JDialog.setDefaultLookAndFeelDecorated(true);    logger.info("> Creating GUI and main frame (invisible)");    frame = new JFrame("COOJA Simulator");    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);    // Create and set up the content pane.    JDesktopPane desktop = new JDesktopPane();    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);    GUI gui = new GUI(desktop, false); // loads external settings and creates initial    // project config    // Add menu bar    frame.setSize(700, 700);    frame.addWindowListener(gui.guiEventHandler);    JComponent newContentPane = gui.getDesktopPane();    newContentPane.setOpaque(true);    frame.setContentPane(newContentPane);    frame.setLocationRelativeTo(null);    // Set manual Contiki path if specified    if (contikiPath != null)      setExternalToolsSetting("PATH_CONTIKI", contikiPath);    // Parse project directories and create config    if (projectDirs == null) {      projectDirs = new Vector<String>();      projectDirs.add(".");    }    // TODO Should add user prop projects as well here...    logger.info("> Reparsing project directories and creating config");    for (String projectDir : projectDirs) {      logger.info(">> Adding: " + projectDir);            // Check if config file exists      File configFile = new File(projectDir + File.separatorChar + PROJECT_CONFIG_FILENAME);      if (!configFile.exists()) {        logger.debug(">>> Creating empty cooja.config file");        try {          configFile.createNewFile();        } catch (IOException e) {          logger.fatal(">> Error when creating cooja.config file, aborting");          return false;        }      }      gui.currentProjectDirs.add(new File(projectDir));    }    boolean parsedProjects = gui.reparseProjectConfig();    if (!parsedProjects) {      logger.fatal(">> Error when parsing project directories, aborting");      return false;    }    // Check file permissions and paths    logger.info("> Checking paths and file permissions");    if (moteTypeID == null)      moteTypeID = "mtype1";    File contikiBaseDir = new File(getExternalToolsSetting("PATH_CONTIKI"));    File contikiCoreDir = new File(contikiBaseDir,        getExternalToolsSetting("PATH_COOJA_CORE_RELATIVE"));    File libFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID        + ContikiMoteType.librarySuffix);    File mapFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID        + ContikiMoteType.mapSuffix);    File depFile = new File(ContikiMoteType.tempOutputDirectory, moteTypeID        + ContikiMoteType.dependSuffix);    if (libFile.exists())      libFile.delete();    if (depFile.exists())      depFile.delete();    if (mapFile.exists())      mapFile.delete();    if (libFile.exists()) {      logger.fatal(">> Can't delete output file, aborting: " + libFile);      return false;    }    if (depFile.exists()) {      logger.fatal(">> Can't delete output file, aborting: " + depFile);      return false;    }    if (mapFile.exists()) {      logger.fatal(">> Can't delete output file, aborting: " + mapFile);      return false;    }    // Search for main file in current directory (or arg)    File mainProcessFile = new File(filename);    logger.info(">> Searching main process file: "        + mainProcessFile.getAbsolutePath());    if (!mainProcessFile.exists()) {      logger.info(">> Searching main process file: "          + mainProcessFile.getAbsolutePath());      boolean foundFile = false;      for (String projectDir : projectDirs) {        mainProcessFile = new File(projectDir, filename);        logger.info(">> Searching main process file: "            + mainProcessFile.getAbsolutePath());        if (mainProcessFile.exists()) {          foundFile = true;          break;        }      }      if (!foundFile) {        logger.fatal(">> Could not locate main process file, aborting");        return false;      }    }    // Setup compilation arguments    logger.info("> Setting up compilation arguments");    Vector<File> filesToCompile = new Vector<File>();    filesToCompile.add(mainProcessFile); // main process file    for (String projectDir : projectDirs)      // project directories      filesToCompile.add(new File(projectDir));    String[] projectSources = // project config sources    gui.getProjectConfig().getStringArrayValue(ContikiMoteType.class,        "C_SOURCES");    for (String projectSource : projectSources) {      if (!projectSource.equals("")) {        File file = new File(projectSource);        if (file.getParent() != null) {          // Find which project directory added this file          File projectDir = gui.getProjectConfig().getUserProjectDefining(              ContikiMoteType.class, "C_SOURCES", projectSource);          if (projectDir != null) {            // We found a project directory - Add it            filesToCompile.add(new File(projectDir.getPath(), file                .getParent()));          }        }        filesToCompile.add(new File(file.getName()));      }    }    // Scan for sensors    if (sensors == null) {      logger.info("> Scanning for sensors");      sensors = new Vector<String>();      Vector<String[]> scannedSensorInfo = ContikiMoteTypeDialog          .scanForSensors(contikiCoreDir);      for (String projectDir : projectDirs)        // project directories        scannedSensorInfo.addAll(ContikiMoteTypeDialog.scanForSensors(new File(            projectDir)));      for (String[] sensorInfo : scannedSensorInfo) {        // logger.info(">> Found and added: " + sensorInfo[1] + " (" +        // sensorInfo[0] + ")");        sensors.add(sensorInfo[1]);      }    }    // Scan for core interfaces    if (coreInterfaces == null) {      logger.info("> Scanning for core interfaces");      coreInterfaces = new Vector<String>();      Vector<String[]> scannedCoreInterfaceInfo = ContikiMoteTypeDialog          .scanForInterfaces(contikiCoreDir);      for (String projectDir : projectDirs)        // project directories        scannedCoreInterfaceInfo.addAll(ContikiMoteTypeDialog            .scanForInterfaces(new File(projectDir)));      for (String[] coreInterfaceInfo : scannedCoreInterfaceInfo) {

⌨️ 快捷键说明

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