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

📄 projectdirectoriesdialog.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        removeProjectDir(changeableProjectsList.getSelectedIndex());      }    });    smallPane.add(button);    listPane.add(smallPane);    // ADD/REMOVE PART    JPanel addRemovePane = new JPanel();    addRemovePane.setLayout(new BoxLayout(addRemovePane, BoxLayout.X_AXIS));    addRemovePane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));    button = new JButton("View resulting config");    button.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        ProjectConfig config;        try {          // Create default configuration          config = new ProjectConfig(true);        } catch (FileNotFoundException ex) {          logger.fatal("Could not find default project config file: "              + GUI.PROJECT_DEFAULT_CONFIG_FILENAME);          return;        } catch (IOException ex) {          logger.fatal("Error when reading default project config file: "              + GUI.PROJECT_DEFAULT_CONFIG_FILENAME);          return;        }        // Add the fixed project configurations        if (fixedProjectsList != null) {          for (String projectDir : fixedProjectsList.getItems()) {            try {              config.appendProjectDir(new File(projectDir));            } catch (Exception ex) {              logger.fatal("Error when merging configurations: " + ex);              return;            }          }        }        // Add the project directory configurations        for (String projectDir : changeableProjectsList.getItems()) {          try {            config.appendProjectDir(new File(projectDir));          } catch (Exception ex) {            logger.fatal("Error when merging configurations: " + ex);            return;          }        }        // Show merged configuration        ConfigViewer.showDialog(ProjectDirectoriesDialog.this, config);      }    });    addRemovePane.add(button);    addRemovePane.add(Box.createRigidArea(new Dimension(10, 0)));    button = new JButton("Add manually");    button.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        ProjectDirectoryInputDialog pathDialog = new ProjectDirectoryInputDialog(ProjectDirectoriesDialog.this);        pathDialog.pack();        pathDialog.setLocationRelativeTo(ProjectDirectoriesDialog.this);        pathDialog.setVisible(true);        File projectPath = pathDialog.getProjectDirectory();        if (projectPath != null) {          addProjectDir(projectPath);        }      }    });    addRemovePane.add(button);    addRemovePane.add(Box.createRigidArea(new Dimension(10, 0)));    button = new JButton("Browse");    button.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        JFileChooser fc = new JFileChooser();        fc.setCurrentDirectory(new java.io.File(GUI.getExternalToolsSetting("PATH_CONTIKI")));        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);        fc.setDialogTitle("Select project directory");        if (fc.showOpenDialog(myDialog) == JFileChooser.APPROVE_OPTION) {          File dir = fc.getSelectedFile();          String selectedPath = null;          try {            selectedPath = dir.getCanonicalPath().replace('\\', '/');            String contikiPath =              new File(GUI.getExternalToolsSetting("PATH_CONTIKI", null)).              getCanonicalPath().replace('\\', '/');            if (contikiPath != null && selectedPath.startsWith(contikiPath)) {              selectedPath = selectedPath.replaceFirst(                  contikiPath, GUI.getExternalToolsSetting("PATH_CONTIKI"));            }            addProjectDir(new File(selectedPath));          } catch (IOException ex) {            logger.fatal("Error in path extraction: " + ex);          }        }      }    });    addRemovePane.add(button);    // Add components    Container contentPane = getContentPane();    mainPane.add(listPane);    mainPane.add(addRemovePane);    contentPane.add(mainPane, BorderLayout.CENTER);    contentPane.add(buttonPane, BorderLayout.SOUTH);    // Add fixed project directories if any    if (fixedProjects != null) {      for (File projectDir : fixedProjects) {        fixedProjectsList.add(projectDir.getPath());      }    }    // Add already existing project directories    for (File projectDir : changeablePlatforms) {      addProjectDir(projectDir);    }    pack();  }  private void addProjectDir(File projectDir) {    addProjectDir(projectDir, changeableProjectsList.getItemCount());  }  private void addProjectDir(File projectDir, int index) {    // Check that file exists, is a directory and contains the correct files    if (!projectDir.exists()) {      logger.fatal("Can't find project directory: " + projectDir);      return;    }    if (!projectDir.isDirectory()) {      logger.fatal("Specified path is not a directory: " + projectDir);      return;    }//    File projectConfigFile = new File(projectDir.getPath(),//        GUI.PROJECT_CONFIG_FILENAME);//    if (!projectConfigFile.exists()) {////      Object[] options = {"Create",//                          "Cancel"};////      int n = JOptionPane.showOptionDialog(//          this,//          "No " + GUI.PROJECT_CONFIG_FILENAME + " file exists in specified directory!"//          + "\nCreate an empty " + GUI.PROJECT_CONFIG_FILENAME + " file?",//          "Create project directory configuration?",//          JOptionPane.YES_NO_OPTION,//          JOptionPane.QUESTION_MESSAGE,//          null, options, options[1]);////      if (n == JOptionPane.NO_OPTION) {//        return;//      }////      try {//        projectConfigFile.createNewFile();//      } catch (IOException e) {//        logger.fatal("Could not create project directory configuration file: "//            + projectConfigFile);//        return;//      }//    }    changeableProjectsList.add(projectDir.getPath(), index);  }  private void removeProjectDir(int index) {    changeableProjectsList.remove(index);  }}/** * Modal frame that shows all keys with their respective values of a given class * configuration. * * @author Fredrik Osterlind */class ConfigViewer extends JDialog {  private static final long serialVersionUID = 1L;  private static Logger logger = Logger.getLogger(ConfigViewer.class);  public static void showDialog(Frame parentFrame, ProjectConfig config) {    ConfigViewer myDialog = new ConfigViewer(parentFrame, config);    myDialog.setLocationRelativeTo(parentFrame);    myDialog.setAlwaysOnTop(true);    Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();    if (maxSize != null &&        (myDialog.getSize().getWidth() > maxSize.getWidth()            || myDialog.getSize().getHeight() > maxSize.getHeight())) {      Dimension newSize = new Dimension();      newSize.height = Math.min((int) maxSize.getHeight(), (int) myDialog.getSize().getHeight());      newSize.width = Math.min((int) maxSize.getWidth(), (int) myDialog.getSize().getWidth());      myDialog.setSize(newSize);    }    if (myDialog != null) {      myDialog.setVisible(true);    }  }  public static void showDialog(Dialog parentDialog, ProjectConfig config) {    ConfigViewer myDialog = new ConfigViewer(parentDialog, config);    myDialog.setLocationRelativeTo(parentDialog);    myDialog.setAlwaysOnTop(true);    if (myDialog != null) {      myDialog.setVisible(true);    }  }  private ConfigViewer(Dialog dialog, ProjectConfig config) {    super(dialog, "Current class configuration", true);    init(config);  }  private ConfigViewer(Frame frame, ProjectConfig config) {    super(frame, "Current class configuration", true);    init(config);  }  private void init(ProjectConfig config) {    JPanel mainPane = new JPanel(new BorderLayout());    JLabel label;    JButton button;    // 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("Close");    button.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        dispose();      }    });    buttonPane.add(button);    // LIST PART    JPanel keyPane = new JPanel();    keyPane.setLayout(new BoxLayout(keyPane, BoxLayout.Y_AXIS));    mainPane.add(keyPane, BorderLayout.WEST);    JPanel valuePane = new JPanel();    valuePane.setLayout(new BoxLayout(valuePane, BoxLayout.Y_AXIS));    mainPane.add(valuePane, BorderLayout.CENTER);    label = new JLabel("KEY");    label.setForeground(Color.RED);    keyPane.add(label);    label = new JLabel("VALUE");    label.setForeground(Color.RED);    valuePane.add(label);    Enumeration<String> allPropertyNames = config.getPropertyNames();    while (allPropertyNames.hasMoreElements()) {      String propertyName = allPropertyNames.nextElement();      keyPane.add(new JLabel(propertyName));      if (config.getStringValue(propertyName).equals("")) {        valuePane.add(new JLabel(" "));      } else {        valuePane.add(new JLabel(config.getStringValue(propertyName)));      }    }    // Add components    Container contentPane = getContentPane();    contentPane.add(new JScrollPane(mainPane), BorderLayout.CENTER);    contentPane.add(buttonPane, BorderLayout.SOUTH);    pack();    /* Respect screen size */    Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();    if (maxSize != null && (getSize().width > maxSize.width)) {      setSize(maxSize.width, getSize().height);    }    if (maxSize != null && (getSize().height > maxSize.height)) {      setSize(getSize().width, maxSize.height);    }  }}

⌨️ 快捷键说明

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