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

📄 gui.java

📁 Contiki is an open source, highly portable, multi-tasking operating system for memory-constrained n
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // logger.info(">> Found and added: " + coreInterfaceInfo[1] + " (" +        // coreInterfaceInfo[0] + ")");        coreInterfaces.add(coreInterfaceInfo[1]);      }    }    // Scan for mote interfaces    logger.info("> Loading mote interfaces");    String[] moteInterfaces = gui.getProjectConfig().getStringArrayValue(        ContikiMoteType.class, "MOTE_INTERFACES");    Vector<Class<? extends MoteInterface>> moteIntfClasses = new Vector<Class<? extends MoteInterface>>();    for (String moteInterface : moteInterfaces) {      try {        Class<? extends MoteInterface> newMoteInterfaceClass = gui            .tryLoadClass(gui, MoteInterface.class, moteInterface);        moteIntfClasses.add(newMoteInterfaceClass);        // logger.info(">> Loaded mote interface: " + newMoteInterfaceClass);      } catch (Exception e) {        logger.fatal(">> Failed to load mote interface, aborting: "            + moteInterface + ", " + e.getMessage());        return false;      }    }    // Scan for processes    if (userProcesses == null) {      logger.info("> Scanning for user processes");      userProcesses = new Vector<String>();      Vector<String> autostartProcesses = new Vector<String>();      Vector<String[]> scannedProcessInfo = ContikiMoteTypeDialog          .scanForProcesses(contikiCoreDir);      for (String projectDir : projectDirs)        // project directories        scannedProcessInfo.addAll(ContikiMoteTypeDialog            .scanForProcesses(new File(projectDir)));      for (String[] processInfo : scannedProcessInfo) {        if (processInfo[0].equals(mainProcessFile.getName())) {          logger.info(">> Found and added: " + processInfo[1] + " ("              + processInfo[0] + ")");          userProcesses.add(processInfo[1]);          if (addAutostartProcesses) {            // Parse any autostart processes            try {              // logger.info(">>> Parsing " + processInfo[0] + " for autostart              // processes");              Vector<String> autostarters = ContikiMoteTypeDialog                  .parseAutostartProcesses(mainProcessFile);              if (autostarters != null)                autostartProcesses.addAll(autostarters);            } catch (Exception e) {              logger                  .fatal(">>> Error when parsing autostart processes, aborting: "                      + e);              return false;            }          }        } else {          // logger.info(">> Found and ignored: " + processInfo[1] + " (" +          // processInfo[0] + ")");        }      }      if (addAutostartProcesses) {        // Add autostart process sources if found        logger.info("> Adding autostart processes");        for (String autostartProcess : autostartProcesses) {          boolean alreadyExists = false;          for (String existingProcess : userProcesses) {            if (existingProcess.equals(autostartProcess)) {              alreadyExists = true;              break;            }          }          if (!alreadyExists) {            userProcesses.add(autostartProcess);            logger.info(">> Added autostart process: " + autostartProcess);          }        }      }    }    // Generate Contiki main source file    logger.info("> Generating Contiki main source file");    if (!ContikiMoteType.tempOutputDirectory.exists())      ContikiMoteType.tempOutputDirectory.mkdir();    if (!ContikiMoteType.tempOutputDirectory.exists()) {      logger.fatal(">> Could not create output directory: "          + ContikiMoteType.tempOutputDirectory);      return false;    }    try {      String generatedFilename = ContikiMoteTypeDialog.generateSourceFile(          moteTypeID, sensors, coreInterfaces, userProcesses);      // logger.info(">> Generated source file: " + generatedFilename);    } catch (Exception e) {      logger.fatal(">> Error during file generation, aborting: "          + e.getMessage());      return false;    }    // Compile library    logger.info("> Compiling library");    boolean compilationSucceded = ContikiMoteTypeDialog.compileLibrary(        moteTypeID, contikiBaseDir, filesToCompile, false, null, System.err);    if (!libFile.exists() || !depFile.exists() || !mapFile.exists())      compilationSucceded = false;    if (compilationSucceded) {      // logger.info(">> Compilation complete");    } else {      logger.fatal(">> Error during compilation, aborting");      return false;    }    // Create mote type    logger.info("> Creating mote type");    ContikiMoteType moteType;    try {      moteType = new ContikiMoteType(moteTypeID);    } catch (MoteTypeCreationException e) {      logger.fatal("Exception when creating mote type: " + e);      return false;    }    moteType.setDescription("Mote type: " + filename);    moteType.setContikiBaseDir(contikiBaseDir.getPath());    moteType.setContikiCoreDir(contikiCoreDir.getPath());    moteType.setProjectDirs(new Vector<File>());    moteType.setCompilationFiles(filesToCompile);    moteType.setConfig(gui.getProjectConfig());    moteType.setProcesses(userProcesses);    moteType.setSensors(sensors);    moteType.setCoreInterfaces(coreInterfaces);    moteType.setMoteInterfaces(moteIntfClasses);    // Create simulation    logger.info("> Creating simulation");    Simulation simulation = new Simulation(gui);    simulation.setTitle("Quickstarted: " + filename);    simulation.setDelayTime(delayTime);    simulation.setSimulationTime(0);    simulation.setTickTime(1);    String radioMediumClassName = null;    try {      radioMediumClassName = gui.getProjectConfig().getStringArrayValue(          GUI.class, "RADIOMEDIUMS")[0];      Class<? extends RadioMedium> radioMediumClass = gui.tryLoadClass(gui,          RadioMedium.class, radioMediumClassName);      RadioMedium radioMedium = RadioMedium.generateRadioMedium(          radioMediumClass, simulation);      simulation.setRadioMedium(radioMedium);    } catch (Exception e) {      logger.fatal(">> Failed to load radio medium, aborting: "          + radioMediumClassName + ", " + e);      return false;    }    // Create nodes    logger.info("> Creating motes");    Vector<ContikiMote> motes = new Vector<ContikiMote>();    Random random = new Random();    int nextMoteID = 1;    int nextIP = 0;    for (int i = 0; i < numberOfNodes; i++) {      ContikiMote mote = (ContikiMote) moteType.generateMote(simulation);      // Set random position      if (mote.getInterfaces().getPosition() != null)        mote.getInterfaces().getPosition().setCoordinates(            random.nextDouble() * areaSideLength,            random.nextDouble() * areaSideLength, 0);      // Set unique mote ID's      if (mote.getInterfaces().getMoteID() != null)        mote.getInterfaces().getMoteID().setMoteID(nextMoteID++);      // Set unique IP address      if (mote.getInterfaces().getIPAddress() != null) {        mote.getInterfaces().getIPAddress().setIPNumber((char) 10,            (char) ((nextIP / (254 * 255)) % 255),            (char) ((nextIP / 254) % 255), (char) (nextIP % 254 + 1));        nextIP++;      }      motes.add(mote);    }    // Add mote type and motes to simulation    logger.info("> Adding motes and mote type to simulation");    simulation.addMoteType(moteType);    for (Mote mote : motes) {      simulation.addMote(mote);    }    // Add simulation to GUI    logger.info("> Adding simulation to GUI");    gui.setSimulation(simulation);    // Start plugins and try to place them wisely    logger.info("> Starting plugin and showing GUI");    VisPlugin plugin = (VisPlugin) gui.startPlugin(VisState.class, gui, simulation, null);    plugin.setLocation(350, 20);    plugin = (VisPlugin) gui.startPlugin(VisTraffic.class, gui, simulation, null);    plugin.setLocation(350, 340);    plugin = (VisPlugin) gui.startPlugin(LogListener.class, gui, simulation, null);    plugin.setLocation(20, 420);    // Finally show GUI    frame.setVisible(true);    if (simulationStarting) {      simulation.startSimulation();    }    return true;  }  //// PROJECT CONFIG AND EXTENDABLE PARTS METHODS ////  /**   * Register new mote type class.   *    * @param moteTypeClass   *          Class to register   */  public void registerMoteType(Class<? extends MoteType> moteTypeClass) {    moteTypeClasses.add(moteTypeClass);  }  /**   * Unregister all mote type classes.   */  public void unregisterMoteTypes() {    moteTypeClasses.clear();  }  /**   * @return All registered mote type classes   */  public Vector<Class<? extends MoteType>> getRegisteredMoteTypes() {    return moteTypeClasses;  }  /**   * Register new IP distributor class   *    * @param ipDistributorClass   *          Class to register   * @return True if class was registered   */  public boolean registerIPDistributor(      Class<? extends IPDistributor> ipDistributorClass) {    // Check that vector constructor exists    try {      ipDistributorClass.getConstructor(new Class[] { Vector.class });    } catch (Exception e) {      logger.fatal("No vector constructor found of IP distributor: "          + ipDistributorClass);      return false;    }    ipDistributorClasses.add(ipDistributorClass);    return true;  }  /**   * Unregister all IP distributors.   */  public void unregisterIPDistributors() {    ipDistributorClasses.clear();  }  /**   * @return All registered IP distributors   */  public Vector<Class<? extends IPDistributor>> getRegisteredIPDistributors() {    return ipDistributorClasses;  }  /**   * Register new positioner class.   *    * @param positionerClass   *          Class to register   * @return True if class was registered   */  public boolean registerPositioner(Class<? extends Positioner> positionerClass) {    // Check that interval constructor exists    try {      positionerClass          .getConstructor(new Class[] { int.class, double.class, double.class,              double.class, double.class, double.class, double.class });    } catch (Exception e) {      logger.fatal("No interval constructor found of positioner: "          + positionerClass);      return false;    }    positionerClasses.add(positionerClass);    return true;  }  /**   * Unregister all positioner classes.   */  public void unregisterPositioners() {    positionerClasses.clear();  }  /**   * @return All registered positioner classes   */  public Vector<Class<? extends Positioner>> getRegisteredPositioners() {    return positionerClasses;  }  /**   * Register new radio medium class.   *    * @param radioMediumClass   *          Class to register   * @return True if class was registered   */  public boolean registerRadioMedium(      Class<? extends RadioMedium> radioMediumClass) {    // Check that simulation constructor exists    try {      radioMediumClass.getConstructor(new Class[] { Simulation.class });    } catch (Exception e) {      logger.fatal("No simulation constructor found of radio medium: "          + radioMediumClass);      return false;    }    radioMediumClasses.add(radioMediumClass);    return true;  }  /**   * Unregister all radio medium classes.   */  public void unregisterRadioMediums() {    radioMediumClasses.clear();  }  /**   * @return All registered radio medium classes   */  public Vector<Class<? extends RadioMedium>> getRegisteredRadioMediums() {    return radioMediumClasses;  }  /**   * Builds new project configuration using current project directories settings.   * Reregisters mote types, plugins, IP distributors, positioners and radio   * mediums. This method may still return true even if all classes could not be   * registered, but always returns false if all project directory configuration   * files were not parsed correctly.   *    * Any registered temporary plugins will be saved and reregistered.   *    * @return True if external configuration files were found and parsed OK   */  public boolean reparseProjectConfig() {    // Backup temporary plugins    Vector<Class<? extends Plugin>> oldTempPlugins = (Vector<Class<? extends Plugin>>) pluginClassesTemporary        .clone();    // Reset current configuration    unregisterMoteTypes();    unregisterPlugins();    unregisterIPDistributors();    unregisterPositioners();    unregisterRadioMediums();    try {      // Read default configuration      projectConfig = new ProjectConfig(true);    } catch (FileNotFoundException e) {      logger.fatal("Could not find default project config file: "          + PROJECT_DEFAULT_CONFIG_FILENAME);      return false;    } catch (IOException e) {      logger.fatal("Error when reading default project config file: "          + PROJECT_DEFAULT_CONFIG_FILENAME);      return false;    }

⌨️ 快捷键说明

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