コード例 #1
0
  /** 读取project目录并完成初始化 */
  private void init() {
    contentBox.removeAll(); // clear
    projectPanels.clear(); // clear
    publicLibraries.clear(); // clear

    File projectsDir = new File("projects");
    if (!projectsDir.exists()) projectsDir.mkdir();
    File libraryDir = new File("libProjects");
    if (!libraryDir.exists()) libraryDir.mkdir();

    syncProjectConfig();

    File[] libFiles = libraryDir.listFiles(new ProjectFileFilter());
    File[] projectFiles = projectsDir.listFiles(new ProjectFileFilter());

    List<File> projects = new ArrayList<File>();
    if (projectFiles != null) projects.addAll(Arrays.asList(projectFiles));
    if (libFiles != null) projects.addAll(Arrays.asList(libFiles));

    EditProjectHandler editHandler = new EditProjectHandler();
    for (File projectFile : projects) {
      if (projectFile.getName().equals(".project")) continue; // 加强容错性
      BatchPack pack = new BatchPack(projectFile.getAbsolutePath());
      String fullName = projectFile.getName();
      String fileName = fullName.substring(0, fullName.lastIndexOf('.'));
      if (pack.needImport()) {
        batchButton.setEnabled(false);
        progressBar.setString("正在同步导入" + fileName);
        progressBar.setIndeterminate(true);
        pack.importFromSVN();
        records.setProjectVersion(
            projectFile.getAbsolutePath(), pack.getSVNVersion()); // ensure latest version
        records.saveRecords();
        progressBar.setIndeterminate(false);
        progressBar.setString("");
        batchButton.setEnabled(true);
      }
      ProjectPanel projectPanel = new ProjectPanel(pack, fileName);
      projectPanel.setEditProjectListener(editHandler);
      projectPanel.updateUI();
      projectPanels.add(projectPanel);
      contentBox.add(projectPanel);
    }

    // prepare library
    for (ProjectPanel panel : projectPanels) {
      BatchPack pack = panel.getProjectBatch();
      if (!pack.isLibrary()) continue;
      Attributes attributes = pack.getAttributes();
      String projectPath = attributes.getProperty("projectPath");
      String projectName = new File(projectPath).getName();
      publicLibraries.put(projectName, projectPath);
    }
    // modify project to reference public library
    for (ProjectPanel panel : projectPanels) {
      prepareProjectPanel(panel);
    }
    contentBox.updateUI();
  }
コード例 #2
0
 @Override
 public void keyReleased(KeyEvent e) {
   // do the quick search
   for (ProjectPanel projectPanel : projectPanels) {
     String name = projectPanel.getProjectName();
     if (name.toLowerCase().contains(quickFilter.getText().toLowerCase())) {
       projectPanel.setVisible(true);
     } else {
       projectPanel.setVisible(false);
     }
   }
 }
コード例 #3
0
 public static void prepareProjectPanel(ProjectPanel panel) {
   BatchPack pack = panel.getProjectBatch();
   if (pack.isLibrary() || pack.isDebugMode()) return;
   AndroidProject project = pack.getAttributes().getAndroidProject();
   ArrayList<String> libPaths = PackManager.getRelativeLibraryPaths(project.projectPath);
   for (String libPath : libPaths) {
     String configer =
         Files.readTextFile(new File(project.projectPath, "project.properties"), true);
     String keyName = new File(libPath).getName();
     String libraryPath = publicLibraries.get(keyName);
     if (libraryPath == null) {
       System.err.println("error: not found dependency library " + keyName);
       continue;
     }
     libraryPath = Files.convert2AbsolutePath("", libraryPath);
     try {
       String relativePath =
           Files.toRelativePath(new File(project.projectPath), new File(libraryPath));
       configer = configer.replace(libPath, relativePath);
       Files.saveTextFile(new File(project.projectPath, "project.properties"), configer);
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
コード例 #4
0
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == clearButton) {
      for (ProjectPanel panel : projectPanels) {
        panel.init();
      }
    }

    if (e.getSource() == batchButton) {
      runBatch();
    }

    if (e.getSource() == selectAll) {
      for (ProjectPanel projectPanel : projectPanels) {
        projectPanel.wantBatch.setSelected(selectAll.isSelected());
      }
    }
  }
コード例 #5
0
    @Override
    public void editProject(
        ProjectPanel projectSource,
        MacroPanel macroSource,
        String editValue,
        int macroPanelIndex,
        int macroNameIndex) {
      if (!isBatchAdd.isSelected()) return;
      // 标记所有其它的Project的为影子(非编辑)状态
      for (ProjectPanel projectPanel : projectPanels) projectPanel.isShadow = true;
      projectSource.isShadow = false;

      // synchronize shadow
      for (ProjectPanel projectPanel : projectPanels) {
        if (projectPanel.isShadow && projectPanel.wantBatch() && projectPanel.isVisible()) {
          projectPanel.shadowMacro(macroPanelIndex, macroNameIndex, editValue);
        }
      }
    }
コード例 #6
0
  /**
   * A private constructor to create a new editor frame based on the specified prefs configuration.
   *
   * @param prefs: the configuration to use.
   */
  private PreferencesGUIEditorFrame(final ClientPreferences prefs) {
    super("Crystal Configuration Editor");
    Assert.assertNotNull(prefs);

    final ClientPreferences copyPrefs = prefs.clone();
    final Map<JComponent, Boolean> changedComponents = new HashMap<JComponent, Boolean>();
    final Map<JTextField, Boolean> validEditorText = new HashMap<JTextField, Boolean>();
    final Map<ProjectPreferences, Map<JTextField, Boolean>> validTextSet =
        new HashMap<ProjectPreferences, Map<JTextField, Boolean>>();
    final JFrame frame = this;
    frame.setIconImage(
        (new ImageIcon(
                Constants.class.getResource("/crystal/client/images/crystal-ball_blue_128.png")))
            .getImage());

    if (copyPrefs.getProjectPreference().isEmpty()) {
      // ClientPreferences client = new ClientPreferences("/usr/bin/hg/", "/tmp/crystalClient/");
      ProjectPreferences newGuy =
          new ProjectPreferences(
              new DataSource("", "", DataSource.RepoKind.HG, false, null), copyPrefs);
      try {
        copyPrefs.addProjectPreferences(newGuy);
        copyPrefs.setChanged(true);
      } catch (DuplicateProjectNameException e) {
        // Just ignore the duplicate project name
      }
    }

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

    //		getContentPane().add(new JLabel("Closing this window will save the configuraion
    // settings."));

    //		JPanel hgPanel = new JPanel();
    //		hgPanel.setLayout(new BoxLayout(hgPanel, BoxLayout.X_AXIS));
    //		hgPanel.add(new JLabel("Path to hg executable:"));
    //		final JTextField hgPath = new JTextField(prefs.getHgPath());
    // hgPath.setSize(hgPath.getWidth(), 16);
    //		hgPanel.add(hgPath);
    //		hgPath.addKeyListener(new KeyListener() {
    //			public void keyPressed(KeyEvent arg0) {
    //			}
    //
    //			public void keyTyped(KeyEvent arg0) {
    //			}
    //
    //			public void keyReleased(KeyEvent arg0) {
    //				prefs.setHgPath(hgPath.getText());
    //				prefs.setChanged(true);
    //				frame.pack();
    //			}
    //		});
    //
    //		JButton hgButton = new JButton("find");
    //		hgPanel.add(hgButton);
    //		hgButton.addActionListener(new ActionListener() {
    //			public void actionPerformed(ActionEvent e) {
    //				new MyPathChooser("Path to hg executable", hgPath, JFileChooser.FILES_ONLY);
    //				prefs.setChanged(true);
    //			}
    //		});
    //		getContentPane().add(hgPanel);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new SpringLayout());

    for (int i = 0; i < 2; i++) {
      topPanel.add(new JLabel());
    }

    topPanel.add(new JLabel("Valid?"));

    JPanel tempPanel = new JPanel();
    tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.X_AXIS));
    topPanel.add(new JLabel("Path to scratch space: "));

    final JTextField tempPath = new JTextField(copyPrefs.getTempDirectory());
    final JLabel tempPathState = new JLabel();
    tempPanel.add(tempPath);

    changedComponents.put(tempPath, false);
    boolean pathValid =
        ValidInputChecker.checkDirectoryPath(tempPath.getText())
            || ValidInputChecker.checkUrl(tempPath.getText());
    if (pathValid) {
      tempPathState.setText("  valid");
      tempPathState.setForeground(Color.GREEN.darker());
    } else {
      tempPathState.setText("invalid");
      tempPathState.setForeground(Color.RED.darker());
    }
    validEditorText.put(tempPath, pathValid);

    tempPath.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent arg0) {}

          public void keyTyped(KeyEvent arg0) {}

          public void keyReleased(KeyEvent arg0) {
            // TODO check if text is valid text
            copyPrefs.setTempDirectory(tempPath.getText());
            changedComponents.put(tempPath, !prefs.getTempDirectory().equals(tempPath.getText()));

            boolean pathValid =
                ValidInputChecker.checkDirectoryPath(tempPath.getText())
                    || ValidInputChecker.checkUrl(tempPath.getText());
            validEditorText.put(tempPath, pathValid);
            if (pathValid) {
              tempPathState.setText("  valid");
              tempPathState.setForeground(Color.GREEN.darker());
            } else {
              tempPathState.setText("invalid");
              tempPathState.setForeground(Color.RED.darker());
            }
            // copyPrefs.setChanged(true);
            frame.pack();
          }
        });

    tempPath.addFocusListener(
        new FocusListener() {

          @Override
          public void focusGained(FocusEvent arg0) {
            tempPath.selectAll();
          }

          @Override
          public void focusLost(FocusEvent arg0) {}
        });
    JButton tempButton = new JButton("find");
    tempPanel.add(tempButton);
    tempButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MyPathChooser("Path to scratch directory", tempPath, JFileChooser.DIRECTORIES_ONLY);
            // copyPrefs.setChanged(true);
          }
        });

    topPanel.add(tempPanel);
    topPanel.add(tempPathState);

    topPanel.add(new JLabel("Refresh rate: "));

    final JTextField refreshRate = new JTextField(String.valueOf(copyPrefs.getRefresh()));
    final JLabel rateState = new JLabel("  valid");
    rateState.setForeground(Color.GREEN.darker());
    topPanel.add(refreshRate);
    topPanel.add(rateState);
    changedComponents.put(refreshRate, false);
    validEditorText.put(refreshRate, true);

    refreshRate.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent arg0) {}

          public void keyTyped(KeyEvent arg0) {}

          public void keyReleased(KeyEvent arg0) {

            changedComponents.put(
                refreshRate, !String.valueOf(prefs.getRefresh()).equals(refreshRate.getText()));
            try {
              copyPrefs.setRefresh(Long.valueOf(refreshRate.getText()));
            } catch (Exception e) {

            }
            boolean valid = ValidInputChecker.checkStringToLong(refreshRate.getText());
            validEditorText.put(refreshRate, valid);

            if (valid) {
              rateState.setText("  valid");
              rateState.setForeground(Color.GREEN.darker());
            } else {
              rateState.setText("invalid");
              rateState.setForeground(Color.RED.darker());
            }
            // copyPrefs.setChanged(true);
          }
        });

    SpringLayoutUtility.formGridInColumn(topPanel, 3, 3);
    getContentPane().add(topPanel);

    final JTabbedPane projectsTabs =
        new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    /*
     * projectsTabs.addChangeListener(new ChangeListener() {
     *
     * @Override public void stateChanged(ChangeEvent e) { frame.pack(); System.out.println("Tabs changed"); } });
     */

    for (final ProjectPreferences copyPref : copyPrefs.getProjectPreference()) {
      ProjectPanel current;
      try {
        Map<JTextField, Boolean> validPanel = new HashMap<JTextField, Boolean>();
        validTextSet.put(copyPref, validPanel);
        current =
            new ProjectPanel(
                copyPref,
                copyPrefs,
                frame,
                projectsTabs,
                changedComponents,
                prefs.getProjectPreferences(copyPref.getName()),
                validPanel);
        projectsTabs.addTab(current.getName(), current);
        JPanel pnl = new JPanel();
        JLabel tabName = new JLabel(current.getName());
        pnl.setOpaque(false);
        pnl.add(tabName);
        pnl.add(
            new DeleteProjectButton(
                copyPrefs, projectsTabs, frame, current, copyPref, validTextSet));
        projectsTabs.setTabComponentAt(projectsTabs.getTabCount() - 1, pnl);
        // projectsTabs.setTitleAt(projectsTabs.getTabCount() - 1, current.getName());
      } catch (NonexistentProjectException e1) {
        // never happens
      }
    }

    final JButton newProjectButton = new JButton("Add New Project");
    // final JButton deleteProjectButton = new JButton("Delete This Project");

    newProjectButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // deleteProjectButton.setEnabled(true);
            HashSet<String> shortNameLookup = new HashSet<String>();
            for (ProjectPreferences current : copyPrefs.getProjectPreference()) {
              shortNameLookup.add(current.getName());
            }
            int count = 1;
            while (shortNameLookup.contains("New_Project_" + count++)) ;

            final ProjectPreferences newGuy =
                new ProjectPreferences(
                    new DataSource(
                        "New_Project_" + --count, "", DataSource.RepoKind.HG, false, null),
                    copyPrefs);
            try {
              copyPrefs.addProjectPreferences(newGuy);
            } catch (DuplicateProjectNameException e1) {
              // This should never happen because we just found a clean project name to use.
              throw new RuntimeException(
                  "When I tried to create a new project, I found a nice, clean, unused name:\n"
                      + "New_Project_"
                      + count
                      + "\nbut then the preferences told me that name was in use.  \n"
                      + "This should never happen!");
            }
            Map<JTextField, Boolean> validPanel = new HashMap<JTextField, Boolean>();
            validTextSet.put(newGuy, validPanel);
            final ProjectPanel newGuyPanel =
                new ProjectPanel(
                    newGuy, copyPrefs, frame, projectsTabs, changedComponents, null, validPanel);
            projectsTabs.addTab("New_Project_" + count, newGuyPanel);
            JPanel pnl = new JPanel();
            JLabel tabName = new JLabel(newGuy.getName());

            pnl.setOpaque(false);
            pnl.add(tabName);
            pnl.add(
                new DeleteProjectButton(
                    copyPrefs, projectsTabs, frame, newGuyPanel, newGuy, validTextSet));
            projectsTabs.setTabComponentAt(projectsTabs.getTabCount() - 1, pnl);
            projectsTabs.setSelectedIndex(projectsTabs.getTabCount() - 1);
            copyPrefs.setChanged(true);
            frame.pack();
          }
        });

    /*
    deleteProjectButton.addActionListener(new ActionListener() {
    	public void actionPerformed(ActionEvent e) {
    		int current = projectsTabs.getSelectedIndex();
    		int option = JOptionPane.showConfirmDialog(null, "Do you want to delete project \"" + projectsTabs.getTitleAt(current) + "\"?",
    				"Empty cache", JOptionPane.YES_NO_OPTION);
    		// TODO wait for the current refresh to finish or kill it
    		if(option == JOptionPane.YES_OPTION) {
    			prefs.removeProjectPreferencesAtIndex(current);
    			projectsTabs.remove(current);
    			if (prefs.getProjectPreference().isEmpty())
    				deleteProjectButton.setEnabled(false);
    			prefs.setChanged(true);
    			frame.pack();
    		}
    	}
    });
    */

    getContentPane().add(newProjectButton);
    getContentPane().add(projectsTabs);
    // getContentPane().add(deleteProjectButton);

    JPanel savePanel = new JPanel();
    savePanel.setLayout(new FlowLayout());
    final JButton saveButton = new JButton("Save");
    final JButton cancelButton = new JButton("Cancel");
    savePanel.add(saveButton);
    savePanel.add(cancelButton);
    getContentPane().add(savePanel);

    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (copyPrefs.hasChanged() || changedComponents.values().contains(true)) {
              boolean validPanelText = true;
              for (Map<JTextField, Boolean> map : validTextSet.values()) {
                if (map.values().contains(false)) {
                  validPanelText = false;
                }
              }
              if (!validEditorText.values().contains(false) && validPanelText) {
                try {
                  ClientPreferences.savePreferencesToDefaultXML(copyPrefs);
                } catch (FileNotFoundException fnfe) {
                  _log.error("Could not write to the configuration file. " + fnfe);
                }
                // TODO
                copyPrefs.setChanged(false);
                frame.setVisible(false);
              } else {
                JOptionPane.showMessageDialog(
                    null, "You have invalid input.", "Warning", JOptionPane.ERROR_MESSAGE);
              }
            } else {

              frame.setVisible(false);
            }
          }
        });

    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            editorFrame = new PreferencesGUIEditorFrame(prefs);
            copyPrefs.setChanged(false);
            frame.setVisible(false);
          }
        });

    addWindowListener(
        new WindowListener() {
          public void windowClosing(WindowEvent arg0) {
            setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
            if (copyPrefs.hasChanged() || changedComponents.values().contains(true)) {
              int n =
                  JOptionPane.showConfirmDialog(
                      null,
                      "Do you want to save your data?",
                      "Saving data",
                      JOptionPane.YES_NO_CANCEL_OPTION);
              if (n == JOptionPane.YES_OPTION) {

                boolean validPanelText = true;
                for (Map<JTextField, Boolean> map : validTextSet.values()) {
                  if (map.values().contains(false)) {
                    validPanelText = false;
                  }
                }
                if (!validEditorText.values().contains(false) && validPanelText) {
                  try {
                    ClientPreferences.savePreferencesToDefaultXML(copyPrefs);
                  } catch (FileNotFoundException fnfe) {
                    _log.error("Could not write to the configuration file. " + fnfe);
                  }
                  // TODO
                  copyPrefs.setChanged(false);
                } else {
                  JOptionPane.showMessageDialog(
                      null, "You have invalid input.", "Warning", JOptionPane.ERROR_MESSAGE);
                  setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                }
              } else if (n == JOptionPane.CANCEL_OPTION) {
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
              } else { // option is no
                editorFrame = new PreferencesGUIEditorFrame(prefs);
                copyPrefs.setChanged(false);
              }
            }
          }

          public void windowActivated(WindowEvent arg0) {}

          public void windowClosed(WindowEvent arg0) {}

          public void windowDeactivated(WindowEvent arg0) {
            // Reload the preferences
            ConflictSystemTray.getInstance().loadPreferences();
          }

          public void windowDeiconified(WindowEvent arg0) {}

          public void windowIconified(WindowEvent arg0) {}

          public void windowOpened(WindowEvent arg0) {}
        });

    pack();
    // setVisible(true);
  }
コード例 #7
0
 /**
  * Loads the data from a file
  *
  * @param urlString Absolute path to the file to be loaded.
  */
 private void loadGroupFromFile(String urlString)
     throws java.io.IOException, java.net.MalformedURLException, java.text.ParseException {
   URL url = new URL(urlString);
   FileStorage storage = new FileStorage();
   projectPanel.setModel(new PersonListModel(storage.load(url), url));
 }