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

📄 projectdirectoriesdialog.java

📁 是瑞典科学院开发的世界最小的嵌入式操作系统,并且包括了TCP/IP协议,是最新版本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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 : changableProjectsList.getItems()) {          try {            config.appendProjectDir(new File(projectDir));          } catch (Exception ex) {            logger.fatal("Error when merging configurations: " + ex);            return;          }        }        // Show merged configuration        if (myParentFrame != null)          ConfigViewer.showDialog(myParentFrame, config);        else          ConfigViewer.showDialog(myParentDialog, 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) {        String newProjectPath = JOptionPane.showInputDialog(myDialog,            "Enter path to project directory", "Enter path",            JOptionPane.QUESTION_MESSAGE);        if (newProjectPath != null) {          addProjectDir(new File(newProjectPath));        }      }    });    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("."));        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);        fc.setDialogTitle("Select project directory");        if (fc.showOpenDialog(myDialog) == JFileChooser.APPROVE_OPTION) {          addProjectDir(fc.getSelectedFile());        }      }    });    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 : changablePlatforms) {      addProjectDir(projectDir);    }    pack();  }  private void addProjectDir(File projectDir) {    addProjectDir(projectDir, changableProjectsList.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;      }    }    changableProjectsList.add(projectDir.getPath(), index);  }  private void removeProjectDir(int index) {    changableProjectsList.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();  }}

⌨️ 快捷键说明

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