/plugins/PHPParser/tags/PHPParser-1.4.1/src/gatchan/phpparser/project/dockablepanel/ProjectOptionsPanel.java

#
Java | 192 lines | 160 code | 21 blank | 11 comment | 27 complexity | 803cb73428589345f13c46507edbf6bc MD5 | raw file

✨ Summary
  1. package gatchan.phpparser.project.dockablepanel;
  2. import gatchan.phpparser.project.Project;
  3. import org.gjt.sp.jedit.GUIUtilities;
  4. import org.gjt.sp.jedit.browser.VFSBrowser;
  5. import javax.swing.*;
  6. import java.awt.*;
  7. import java.awt.event.*;
  8. /**
  9. * The option panel that will be shown for each project.
  10. *
  11. * @author Matthieu Casanova
  12. * @author $Id: ProjectOptionsPanel.java 8551 2006-03-15 10:01:12Z kpouer $
  13. */
  14. public class ProjectOptionsPanel extends JPanel {
  15. private Project project;
  16. private final JTextField rootField = new JTextField();
  17. private final JButton browse = new JButton("...");
  18. private final JButton excludedBrowse = new JButton("...");
  19. private final JButton save = new JButton(GUIUtilities.loadIcon("Save.png"));
  20. private final JButton reparse = new JButton(GUIUtilities.loadIcon("Parse.png"));
  21. private final ProjectStatsPanel projectStatsPanel = new ProjectStatsPanel();
  22. private final DefaultListModel excludedListModel;
  23. private JPopupMenu menu;
  24. public ProjectOptionsPanel() {
  25. super(new GridBagLayout());
  26. rootField.setEditable(false);
  27. JLabel rootLabel = new JLabel("root : ");
  28. JLabel excludedLabel = new JLabel("excluded : ");
  29. MyActionListener actionListener = new MyActionListener();
  30. rootField.addKeyListener(new MyKeyAdapter());
  31. rootField.setEditable(false);
  32. browse.addActionListener(actionListener);
  33. browse.setToolTipText("Browse to find the root of your project");
  34. excludedListModel = new DefaultListModel();
  35. final JList excludedList = new JList(excludedListModel);
  36. excludedList.addMouseListener(new MouseAdapter() {
  37. public void mouseClicked(MouseEvent e) {
  38. if (GUIUtilities.isRightButton(e.getModifiers())) {
  39. if (menu == null) {
  40. menu = new JPopupMenu();
  41. JMenuItem menuItem = new JMenuItem("remove");
  42. menuItem.addActionListener(new ActionListener() {
  43. public void actionPerformed(ActionEvent e) {
  44. Object[] selectedValues = excludedList.getSelectedValues();
  45. if (selectedValues != null) {
  46. for (int i = 0; i < selectedValues.length; i++) {
  47. project.removeExcludedFolder((String) selectedValues[i]);
  48. excludedListModel.removeElement(selectedValues[i]);
  49. }
  50. }
  51. }
  52. });
  53. menu.add(menuItem);
  54. }
  55. GUIUtilities.showPopupMenu(menu, excludedList, e.getX(), e.getY());
  56. }
  57. }
  58. });
  59. excludedBrowse.addActionListener(actionListener);
  60. excludedBrowse.setToolTipText("Browse to find the root of your project");
  61. save.setEnabled(false);
  62. save.addActionListener(actionListener);
  63. save.setToolTipText("Save the project");
  64. reparse.setToolTipText("reparse project");
  65. reparse.addActionListener(actionListener);
  66. GridBagConstraints cons = new GridBagConstraints();
  67. cons.anchor = GridBagConstraints.NORTHWEST;
  68. add(rootLabel, cons);
  69. cons.fill = GridBagConstraints.BOTH;
  70. cons.weightx = 1.0;
  71. add(rootField, cons);
  72. cons.fill = GridBagConstraints.NONE;
  73. cons.weightx = 0.0;
  74. add(browse, cons);
  75. int visibleRows = 3;
  76. cons.gridheight = visibleRows;
  77. cons.weighty = 1.0;
  78. int line = 0;
  79. cons.gridy = ++line;
  80. add(excludedLabel, cons);
  81. cons.fill = GridBagConstraints.BOTH;
  82. cons.weightx = 1.0;
  83. add(new JScrollPane(excludedList), cons);
  84. cons.fill = GridBagConstraints.NONE;
  85. cons.weightx = 0.0;
  86. add(excludedBrowse, cons);
  87. cons.gridheight = 1;
  88. cons.weighty = 0.0;
  89. line += visibleRows;
  90. cons.gridy = line;
  91. JToolBar toolBar = new JToolBar();
  92. toolBar.add(save);
  93. toolBar.add(reparse);
  94. toolBar.setFloatable(false);
  95. toolBar.setBorderPainted(false);
  96. cons.gridwidth = GridBagConstraints.REMAINDER;
  97. add(toolBar, cons);
  98. cons.gridy = ++line;
  99. add(Box.createVerticalStrut(3), cons);
  100. cons.gridy = ++line;
  101. cons.fill = GridBagConstraints.HORIZONTAL;
  102. add(projectStatsPanel, cons);
  103. cons.gridy = 99;
  104. cons.weighty = 1.0;
  105. add(Box.createGlue(), cons);
  106. }
  107. /**
  108. * This method is called by {@link ProjectTabbedPane#setProject(Project)}
  109. *
  110. * @param project the project
  111. */
  112. public void setProject(Project project) {
  113. this.project = project;
  114. excludedListModel.removeAllElements();
  115. if (project == null) {
  116. rootField.setText(null);
  117. setEnabled(false);
  118. } else {
  119. rootField.setText(project.getRoot());
  120. Object[] excludedFolders = project.getExcludedFolders();
  121. for (int i = 0; i < excludedFolders.length; i++) {
  122. excludedListModel.addElement(excludedFolders[i]);
  123. }
  124. setEnabled(true);
  125. }
  126. projectStatsPanel.updateProject(project);
  127. }
  128. public void setEnabled(boolean enabled) {
  129. super.setEnabled(enabled);
  130. browse.setEnabled(enabled);
  131. excludedBrowse.setEnabled(enabled);
  132. rootField.setEditable(enabled);
  133. save.setEnabled(enabled);
  134. reparse.setEnabled(enabled);
  135. }
  136. private class MyActionListener implements ActionListener {
  137. public void actionPerformed(ActionEvent e) {
  138. String currentPath = rootField.getText();
  139. if (e.getSource() == reparse) {
  140. project.rebuildProject();
  141. } else if (e.getSource() == browse) {
  142. String[] choosenFolder = GUIUtilities.showVFSFileDialog(null, currentPath, VFSBrowser.CHOOSE_DIRECTORY_DIALOG, false);
  143. if (choosenFolder != null) {
  144. rootField.setText(choosenFolder[0]);
  145. project.setRoot(choosenFolder[0]);
  146. save.setEnabled(true);
  147. }
  148. } else if (e.getSource() == excludedBrowse) {
  149. String[] choosenFolder = GUIUtilities.showVFSFileDialog(null, currentPath, VFSBrowser.CHOOSE_DIRECTORY_DIALOG, true);
  150. if (choosenFolder != null) {
  151. for (int i = 0; i < choosenFolder.length; i++) {
  152. String path = choosenFolder[i];
  153. if (project.addExcludedFolder(path)) {
  154. excludedListModel.addElement(path);
  155. }
  156. }
  157. save.setEnabled(true);
  158. }
  159. } else if (e.getSource() == save) {
  160. project.setRoot(currentPath);
  161. project.save();
  162. save.setEnabled(false);
  163. }
  164. }
  165. }
  166. private class MyKeyAdapter extends KeyAdapter {
  167. public void keyTyped(KeyEvent e) {
  168. save.setEnabled(true);
  169. }
  170. }
  171. }