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

📄 gui.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
          // logger.info("Loaded radio medium class: " + radioMediumClassName);        } else {          logger.warn("Could not load radio medium class: "              + radioMediumClassName);        }      }    }  }  /**   * Returns the current project configuration common to the entire simulator.   *   * @return Current project configuration   */  public ProjectConfig getProjectConfig() {    return projectConfig;  }  /**   * Returns the current project directories common to the entire simulator.   *   * @return Current project directories.   */  public Vector<File> getProjectDirs() {    return currentProjectDirs;  }  // // PLUGIN METHODS ////  /**   * Show a started plugin in working area.   *   * @param plugin   *          Internal frame to add   */  public void showPlugin(final VisPlugin plugin) {    new RunnableInEDT<Boolean>() {      public Boolean work() {        int nrFrames = myDesktopPane.getAllFrames().length;        myDesktopPane.add(plugin);        // Set standard size if not specified by plugin itself        if (plugin.getWidth() <= 0 || plugin.getHeight() <= 0) {          plugin.setSize(FRAME_STANDARD_WIDTH, FRAME_STANDARD_HEIGHT);        }        // Set location if not already visible        if (plugin.getLocation().x <= 0 && plugin.getLocation().y <= 0) {          plugin.setLocation(              nrFrames * FRAME_NEW_OFFSET,              nrFrames * FRAME_NEW_OFFSET);        }        plugin.setVisible(true);        // Deselect all other plugins before selecting the new one        try {          for (JInternalFrame existingPlugin : myDesktopPane.getAllFrames()) {            existingPlugin.setSelected(false);          }          plugin.setSelected(true);        } catch (Exception e) {          // Ignore        }        // Mote plugin to front        myDesktopPane.moveToFront(plugin);        return true;      }    }.invokeAndWait();  }  /**   * Close all mote plugins for given mote.   *   * @param mote Mote   */  public void closeMotePlugins(Mote mote) {    Vector<Plugin> pluginsToRemove = new Vector<Plugin>();    for (Plugin startedPlugin : startedPlugins) {      int pluginType = startedPlugin.getClass().getAnnotation(PluginType.class).value();      if (pluginType != PluginType.MOTE_PLUGIN) {        continue;      }      Mote pluginMote = (Mote) startedPlugin.getTag();      if (pluginMote == mote) {        pluginsToRemove.add(startedPlugin);      }    }    for (Plugin pluginToRemove: pluginsToRemove) {      removePlugin(pluginToRemove, false);    }  }  /**   * Remove a plugin from working area.   *   * @param plugin   *          Plugin to remove   * @param askUser   *          If plugin is the last one, ask user if we should remove current   *          simulation also?   */  public void removePlugin(final Plugin plugin, final boolean askUser) {    new RunnableInEDT<Boolean>() {      public Boolean work() {        /* Free resources */        plugin.closePlugin();        startedPlugins.remove(plugin);        /* Dispose visualized components */        if (plugin instanceof VisPlugin) {          ((VisPlugin) plugin).dispose();        }        /* (OPTIONAL) Remove simulation if all plugins are closed */        if (getSimulation() != null && askUser && startedPlugins.isEmpty()) {          doRemoveSimulation(true);        }        return true;      }    }.invokeAndWait();  }  /**   * Starts a plugin of given plugin class with given arguments.   *   * @param pluginClass   *          Plugin class   * @param gui   *          GUI passed as argument to all plugins   * @param simulation   *          Simulation passed as argument to mote and simulation plugins   * @param mote   *          Mote passed as argument to mote plugins   * @return Start plugin if any   */  public Plugin startPlugin(final Class<? extends Plugin> pluginClass,      final GUI gui, final Simulation simulation, final Mote mote) {    // Check that plugin class is registered    if (!pluginClasses.contains(pluginClass)) {      logger.fatal("Plugin class not registered: " + pluginClass);      return null;    }    // Check that visualizer plugin is not started without GUI    if (!isVisualized()) {      try {        pluginClass.asSubclass(VisPlugin.class);        // Cast succeded, plugin is visualizer plugin!        logger.warn("Can't start visualizer plugin (no GUI): " + pluginClass);        return null;      } catch (ClassCastException e) {      }    }    // Construct plugin depending on plugin type    Plugin newPlugin = new RunnableInEDT<Plugin>() {      public Plugin work() {        int pluginType = pluginClass.getAnnotation(PluginType.class).value();        Plugin plugin = null;        try {          if (pluginType == PluginType.MOTE_PLUGIN) {            if (mote == null) {              logger.fatal("Can't start mote plugin (no mote selected)");              return null;            }            plugin = pluginClass.getConstructor(                new Class[] { Mote.class, Simulation.class, GUI.class })                .newInstance(mote, simulation, gui);            // Tag plugin with mote            plugin.tagWithObject(mote);          } else if (pluginType == PluginType.SIM_PLUGIN              || pluginType == PluginType.SIM_STANDARD_PLUGIN) {            if (simulation == null) {              logger.fatal("Can't start simulation plugin (no simulation)");              return null;            }            plugin = pluginClass.getConstructor(                new Class[] { Simulation.class, GUI.class }).newInstance(                simulation, gui);          } else if (pluginType == PluginType.COOJA_PLUGIN              || pluginType == PluginType.COOJA_STANDARD_PLUGIN) {            if (gui == null) {              logger.fatal("Can't start COOJA plugin (no GUI)");              return null;            }            plugin = pluginClass.getConstructor(new Class[] { GUI.class }).newInstance(gui);          }        } catch (Exception e) {          logger.fatal("Exception thrown when starting plugin: " + e);          e.printStackTrace();          return null;        }        return plugin;      }    }.invokeAndWait();    if (newPlugin == null) {      return null;    }    // Add to active plugins list    startedPlugins.add(newPlugin);    // Show plugin if visualizer type    if (newPlugin instanceof VisPlugin) {      myGUI.showPlugin((VisPlugin) newPlugin);    }    return newPlugin;  }  /**   * Register a plugin to be included in the GUI. The plugin will be visible in   * the menubar.   *   * @param newPluginClass   *          New plugin to register   * @return True if this plugin was registered ok, false otherwise   */  public boolean registerPlugin(Class<? extends Plugin> newPluginClass) {    return registerPlugin(newPluginClass, true);  }  /**   * Register a temporary plugin to be included in the GUI. The plugin will be   * visible in the menubar. This plugin will automatically be unregistered if   * the current simulation is removed.   *   * @param newPluginClass   *          New plugin to register   * @return True if this plugin was registered ok, false otherwise   */  public boolean registerTemporaryPlugin(Class<? extends Plugin> newPluginClass) {    if (pluginClasses.contains(newPluginClass)) {      return false;    }    boolean returnVal = registerPlugin(newPluginClass, true);    if (!returnVal) {      return false;    }    pluginClassesTemporary.add(newPluginClass);    return true;  }  /**   * Unregister a plugin class. Removes any plugin menu items links as well.   *   * @param pluginClass   *          Plugin class to unregister   */  public void unregisterPlugin(Class<? extends Plugin> pluginClass) {    // Remove (if existing) plugin class menu items    for (Component menuComponent : menuPlugins.getMenuComponents()) {      if (menuComponent.getClass().isAssignableFrom(JMenuItem.class)) {        JMenuItem menuItem = (JMenuItem) menuComponent;        if (menuItem.getClientProperty("class").equals(pluginClass)) {          menuPlugins.remove(menuItem);        }      }    }    if (menuMotePluginClasses.contains(pluginClass)) {      menuMotePluginClasses.remove(pluginClass);    }    // Remove from plugin vectors (including temporary)    if (pluginClasses.contains(pluginClass)) {      pluginClasses.remove(pluginClass);    }    if (pluginClassesTemporary.contains(pluginClass)) {      pluginClassesTemporary.remove(pluginClass);    }  }  /**   * Register a plugin to be included in the GUI.   *   * @param newPluginClass   *          New plugin to register   * @param addToMenu   *          Should this plugin be added to the dedicated plugins menubar?   * @return True if this plugin was registered ok, false otherwise   */  private boolean registerPlugin(final Class<? extends Plugin> newPluginClass,      boolean addToMenu) {    // Get description annotation (if any)    final String description = getDescriptionOf(newPluginClass);    // Get plugin type annotation (required)    final int pluginType;    if (newPluginClass.isAnnotationPresent(PluginType.class)) {      pluginType = newPluginClass.getAnnotation(PluginType.class).value();    } else {      pluginType = PluginType.UNDEFINED_PLUGIN;    }    // Check that plugin type is valid and constructor exists    try {      if (pluginType == PluginType.MOTE_PLUGIN) {        newPluginClass.getConstructor(new Class[] { Mote.class,            Simulation.class, GUI.class });      } else if (pluginType == PluginType.SIM_PLUGIN          || pluginType == PluginType.SIM_STANDARD_PLUGIN) {        newPluginClass.getConstructor(new Class[] { Simulation.class, GUI.class });      } else if (pluginType == PluginType.COOJA_PLUGIN          || pluginType == PluginType.COOJA_STANDARD_PLUGIN) {        newPluginClass.getConstructor(new Class[] { GUI.class });      } else {        logger.fatal("Could not find valid plugin type annotation in class " + newPluginClass);        return false;      }    } catch (NoSuchMethodException e) {      logger.fatal("Could not find valid constructor in class " + newPluginClass + ": " + e);      return false;    }    if (addToMenu && menuPlugins != null) {      new RunnableInEDT<Boolean>() {        public Boolean work() {          // Create 'start plugin'-menu item          JMenuItem menuItem = new JMenuItem(description);          menuItem.setActionCommand("start plugin");          menuItem.putClientProperty("class", newPluginClass);          menuItem.addActionListener(guiEventHandler);          menuPlugins.add(menuItem);          if (pluginType == PluginType.MOTE_PLUGIN) {            // Disable previous menu item and add new item to mote plugins menu            menuItem.setEnabled(false);            menuItem.setToolTipText("Mote plugin");            menuMotePluginClasses.add(newPluginClass);          }          return true;        }      }.invokeAndWait();    }    pluginClasses.add(newPluginClass);    return true;  }  /**   * Unregister all plugin classes, including temporary plugins.   */  public void unregisterPlugins() {    if (menuPlugins != null) {      menuPlugins.removeAll();    }    if (menuMotePluginClasses != null) {      menuMotePluginClasses.clear();    }    pluginClasses.clear();    pluginClassesTemporary.clear();  }  /**   * Return a mote plugins submenu for given mote.   *   * @param mote Mote   * @return Mote plugins menu   */  public JMenu createMotePluginsSubmenu(Mote mote) {    JMenu menuMotePlugins = new JMenu("Open mote plugin for " + mote);    for (Class<? extends Plugin> motePluginClass: menuMotePluginClasses) {      JMenuItem menuItem = new JMenuItem(getDescriptionOf(motePluginClass));      menuItem.setActionCommand("start plugin");      menuItem.putClientProperty("class", motePluginClass);      menuItem.putClientProperty("mote", mote);      menuItem.addActionListener(guiEventHandler);      menuMotePlugins.add(menuItem);    }    return menuMotePlugins

⌨️ 快捷键说明

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