PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/options/ErrorsOptionPane.java

#
Java | 282 lines | 180 code | 44 blank | 58 comment | 21 complexity | 1d7ade80bed545887c1a2a3e00591739 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * ErrorsOptionPane.java - Error pattern option pane
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999, 2003, 2005 Slava Pestov, Alan Ezust
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package console.options;
  23. //{{{ Imports
  24. import java.awt.BorderLayout;
  25. import java.awt.Dimension;
  26. import java.awt.event.ActionEvent;
  27. import java.awt.event.ActionListener;
  28. import java.awt.event.MouseAdapter;
  29. import java.awt.event.MouseEvent;
  30. import javax.swing.Box;
  31. import javax.swing.BoxLayout;
  32. import javax.swing.JButton;
  33. import javax.swing.JList;
  34. import javax.swing.JOptionPane;
  35. import javax.swing.JPanel;
  36. import javax.swing.JScrollPane;
  37. import javax.swing.ListSelectionModel;
  38. import javax.swing.border.EmptyBorder;
  39. import javax.swing.border.TitledBorder;
  40. import javax.swing.event.ListSelectionEvent;
  41. import javax.swing.event.ListSelectionListener;
  42. import org.gjt.sp.jedit.AbstractOptionPane;
  43. import org.gjt.sp.jedit.GUIUtilities;
  44. import org.gjt.sp.jedit.jEdit;
  45. import org.gjt.sp.jedit.gui.RolloverButton;
  46. import console.ErrorListModel;
  47. import console.ErrorMatcher;
  48. import console.gui.PanelStack;
  49. //}}}
  50. //{{{ ErrorsOptionPane class
  51. /**
  52. * A view/editor for an ErrorListModel.
  53. *
  54. * Shows a list of the current ErrorMatchers which can be used, and permits the easy
  55. * editing of them.
  56. */
  57. public class ErrorsOptionPane extends AbstractOptionPane
  58. {
  59. //{{{ Instance variables
  60. // Model for storing all of the ErrorMatchers
  61. private ErrorListModel errorListModel;
  62. // View for the list of errors
  63. private JList errorList;
  64. PanelStack panelStack;
  65. private JButton add;
  66. private JButton remove;
  67. private JButton reset;
  68. private JButton up;
  69. private JButton down;
  70. //}}}
  71. // {{{ Public members
  72. //{{{ ErrorsOptionPane constructor
  73. public ErrorsOptionPane()
  74. {
  75. super("console.errors");
  76. } //}}}
  77. // }}}
  78. //{{{ Protected members
  79. //{{{ _init() method
  80. protected void _init()
  81. {
  82. setLayout(new BorderLayout());
  83. addComponent(Box.createVerticalStrut(6));
  84. errorListModel = ErrorListModel.load();
  85. errorList = new JList();
  86. errorList.setModel(errorListModel);
  87. JScrollPane jsp =new JScrollPane(errorList);
  88. jsp.setMinimumSize(new Dimension(125, 300));
  89. errorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  90. errorList.addListSelectionListener(new ListHandler());
  91. errorList.addMouseListener(new MouseHandler());
  92. errorList.setVisibleRowCount(5);
  93. // JSplitPane errors = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  94. // errors.add(jsp);
  95. String title = jEdit.getProperty("options.console.errors.caption");
  96. jsp.setBorder(new TitledBorder(title));
  97. Box westBox = new Box(BoxLayout.Y_AXIS);
  98. westBox.add(jsp);
  99. // add(jsp, BorderLayout.WEST);
  100. panelStack = new PanelStack();
  101. // errors.add(panelStack);
  102. //add(errors, BorderLayout.CENTER);
  103. add(panelStack, BorderLayout.CENTER);
  104. JPanel buttons = new JPanel();
  105. buttons.setBorder(new EmptyBorder(6,0,0,0));
  106. buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
  107. /* buttons.add(add = new JButton(jEdit.getProperty(
  108. "options.console.errors.add")));
  109. buttons.add(remove = new JButton(jEdit.getProperty(
  110. "options.console.errors.remove"))); */
  111. add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
  112. add.setToolTipText(jEdit.getProperty("common.add"));
  113. buttons.add(add);
  114. remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
  115. remove.setToolTipText(jEdit.getProperty("common.remove"));
  116. buttons.add(remove);
  117. up = new RolloverButton(GUIUtilities.loadIcon("ArrowU.png"));
  118. up.setToolTipText(jEdit.getProperty("common.moveUp"));
  119. buttons.add(up);
  120. down= new RolloverButton(GUIUtilities.loadIcon("ArrowD.png"));
  121. down.setToolTipText(jEdit.getProperty("common.moveDown"));
  122. buttons.add(down);
  123. reset = new RolloverButton(GUIUtilities.loadIcon("Reload.png"));
  124. reset.setToolTipText(jEdit.getProperty("options.console.errors.reload.tooltip"));
  125. buttons.add(reset);
  126. ActionHandler handler = new ActionHandler();
  127. add.addActionListener(handler);
  128. remove.addActionListener(handler);
  129. up.addActionListener(handler);
  130. down.addActionListener(handler);
  131. reset.addActionListener(handler);
  132. westBox.add(buttons);
  133. // add(buttons, BorderLayout.SOUTH);
  134. add(westBox, BorderLayout.WEST);
  135. errorList.setSelectedIndex(0);
  136. updateButtons();
  137. } //}}}
  138. protected void _load()
  139. {
  140. errorListModel = ErrorListModel.load();
  141. }
  142. //{{{ _save() method
  143. protected void _save()
  144. {
  145. errorListModel.save();
  146. } //}}}
  147. //}}}
  148. //{{{ Private members
  149. //{{{ updateButtons() method
  150. private void updateButtons()
  151. {
  152. ErrorMatcher matcher = (ErrorMatcher)errorList.getSelectedValue();
  153. if (matcher != null)
  154. {
  155. String internalName = matcher.internalName();
  156. if (!panelStack.raise(internalName)) {
  157. ErrorMatcherPanel panel = new ErrorMatcherPanel(internalName, matcher);
  158. panelStack.add(internalName, panel);
  159. panelStack.raise(internalName);
  160. validateTree();
  161. }
  162. }
  163. } //}}}
  164. //}}}
  165. //{{{ ActionHandler class
  166. class ActionHandler implements ActionListener
  167. {
  168. public void actionPerformed(ActionEvent evt)
  169. {
  170. Object source = evt.getSource();
  171. if (source == reset) {
  172. errorListModel.reset();
  173. errorList.setModel(errorListModel);
  174. errorList.repaint();
  175. }
  176. if(source == add)
  177. {
  178. /* Open a dialog and ask for the name: */
  179. String matcherNamePrompt = jEdit.getProperty("options.console.errors.name");
  180. String matcherName = JOptionPane.showInputDialog(matcherNamePrompt);
  181. ErrorMatcher matcher = new ErrorMatcher(matcherName);
  182. matcher.name = matcherName;
  183. matcher.user = true;
  184. int index = errorList.getSelectedIndex() + 1;
  185. errorListModel.insertElementAt(matcher,index);
  186. errorList.setSelectedIndex(index);
  187. errorList.repaint();
  188. }
  189. else if(source == remove)
  190. {
  191. int index = errorList.getSelectedIndex();
  192. errorListModel.removeElementAt(index);
  193. if (errorListModel.size() > index)
  194. errorList.setSelectedIndex(index);
  195. else if (! errorListModel.isEmpty())
  196. errorList.setSelectedIndex(errorListModel.size() - 1);
  197. errorList.repaint();
  198. }
  199. else if(source == up)
  200. {
  201. int index = errorList.getSelectedIndex();
  202. ErrorMatcher selected = errorListModel.get(index);
  203. errorListModel.removeElementAt(index);
  204. errorListModel.insertElementAt(selected,index-1);
  205. errorList.setSelectedIndex(index-1);
  206. errorList.repaint();
  207. }
  208. else if(source == down)
  209. {
  210. int index = errorList.getSelectedIndex();
  211. ErrorMatcher matcher = errorListModel.get(index);
  212. errorListModel.removeElementAt(index);
  213. errorListModel.insertElementAt(matcher, index+1);
  214. errorList.setSelectedIndex(index+1);
  215. errorList.repaint();
  216. }
  217. }
  218. } //}}}
  219. //{{{ ListHandler class
  220. class ListHandler implements ListSelectionListener
  221. {
  222. public void valueChanged(ListSelectionEvent evt)
  223. {
  224. updateButtons();
  225. }
  226. } //}}}
  227. //{{{ MouseHandler class
  228. class MouseHandler extends MouseAdapter
  229. {
  230. public void mouseClicked(MouseEvent evt)
  231. {
  232. if(evt.getClickCount() == 2)
  233. {
  234. updateButtons();
  235. }
  236. }
  237. } //}}}
  238. } //}}}