PageRenderTime 34ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 1ms 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
  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
 23package console.options;
 24
 25//{{{ Imports
 26import java.awt.BorderLayout;
 27import java.awt.Dimension;
 28import java.awt.event.ActionEvent;
 29import java.awt.event.ActionListener;
 30import java.awt.event.MouseAdapter;
 31import java.awt.event.MouseEvent;
 32
 33import javax.swing.Box;
 34import javax.swing.BoxLayout;
 35import javax.swing.JButton;
 36import javax.swing.JList;
 37import javax.swing.JOptionPane;
 38import javax.swing.JPanel;
 39import javax.swing.JScrollPane;
 40import javax.swing.ListSelectionModel;
 41import javax.swing.border.EmptyBorder;
 42import javax.swing.border.TitledBorder;
 43import javax.swing.event.ListSelectionEvent;
 44import javax.swing.event.ListSelectionListener;
 45
 46import org.gjt.sp.jedit.AbstractOptionPane;
 47import org.gjt.sp.jedit.GUIUtilities;
 48import org.gjt.sp.jedit.jEdit;
 49import org.gjt.sp.jedit.gui.RolloverButton;
 50
 51import console.ErrorListModel;
 52import console.ErrorMatcher;
 53import console.gui.PanelStack;
 54//}}}
 55
 56//{{{ ErrorsOptionPane class
 57/**
 58 * A view/editor for an ErrorListModel.
 59 * 
 60 * Shows a list of the current ErrorMatchers which can be used, and permits the easy
 61 * editing of them.
 62 */
 63public class ErrorsOptionPane extends AbstractOptionPane
 64{
 65	//{{{ Instance variables
 66	
 67	// Model for storing all of the ErrorMatchers
 68	private ErrorListModel errorListModel;
 69
 70	// View for the list of errors
 71	private JList errorList;
 72
 73	PanelStack panelStack;
 74	
 75	private JButton add;
 76	private JButton remove;
 77	private JButton reset;
 78	private JButton up;
 79	private JButton down;
 80	//}}}
 81
 82	
 83	// {{{ Public members
 84	
 85	//{{{ ErrorsOptionPane constructor
 86	public ErrorsOptionPane()
 87	{
 88		super("console.errors");
 89	} //}}}
 90	
 91	// }}}
 92	
 93	//{{{ Protected members
 94
 95	//{{{ _init() method
 96	protected void _init()
 97	{
 98
 99		setLayout(new BorderLayout());
100		addComponent(Box.createVerticalStrut(6));
101
102		errorListModel = ErrorListModel.load();
103		errorList = new JList();
104		errorList.setModel(errorListModel);
105		JScrollPane jsp =new JScrollPane(errorList); 
106		jsp.setMinimumSize(new Dimension(125, 300));
107		errorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
108		errorList.addListSelectionListener(new ListHandler());
109		errorList.addMouseListener(new MouseHandler());
110		errorList.setVisibleRowCount(5);
111
112		// JSplitPane errors = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
113		// errors.add(jsp);
114		String title = jEdit.getProperty("options.console.errors.caption");
115		jsp.setBorder(new TitledBorder(title));
116		
117		Box westBox = new Box(BoxLayout.Y_AXIS);
118		westBox.add(jsp);
119		// add(jsp, BorderLayout.WEST);
120
121		
122		panelStack = new PanelStack();
123//		errors.add(panelStack);
124		//add(errors, BorderLayout.CENTER);
125		add(panelStack, BorderLayout.CENTER);
126		
127		JPanel buttons = new JPanel();
128		buttons.setBorder(new EmptyBorder(6,0,0,0));
129		buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
130
131/*		buttons.add(add = new JButton(jEdit.getProperty(
132			"options.console.errors.add")));
133		buttons.add(remove = new JButton(jEdit.getProperty(
134			"options.console.errors.remove"))); */
135		add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
136		add.setToolTipText(jEdit.getProperty("common.add"));
137		buttons.add(add);
138		remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
139		remove.setToolTipText(jEdit.getProperty("common.remove"));
140		buttons.add(remove);
141		up = new RolloverButton(GUIUtilities.loadIcon("ArrowU.png"));
142		up.setToolTipText(jEdit.getProperty("common.moveUp"));
143		buttons.add(up);
144		down= new RolloverButton(GUIUtilities.loadIcon("ArrowD.png"));
145		down.setToolTipText(jEdit.getProperty("common.moveDown"));
146		buttons.add(down);
147		reset = new RolloverButton(GUIUtilities.loadIcon("Reload.png"));
148		reset.setToolTipText(jEdit.getProperty("options.console.errors.reload.tooltip"));
149		buttons.add(reset);
150
151	        ActionHandler handler = new ActionHandler();
152	        add.addActionListener(handler);
153		remove.addActionListener(handler);
154		up.addActionListener(handler);
155		down.addActionListener(handler);
156		reset.addActionListener(handler);
157		westBox.add(buttons);
158//		add(buttons, BorderLayout.SOUTH);
159		add(westBox, BorderLayout.WEST);
160		errorList.setSelectedIndex(0);
161		updateButtons();
162
163
164	} //}}}
165
166	protected void _load()
167	{
168		errorListModel = ErrorListModel.load();
169	}
170	
171	//{{{ _save() method
172	protected void _save()
173	{
174		errorListModel.save();
175	} //}}}
176
177	//}}}
178	
179	//{{{ Private members
180
181	//{{{ updateButtons() method
182	
183	private void updateButtons()
184	{
185		ErrorMatcher matcher = (ErrorMatcher)errorList.getSelectedValue();
186		if (matcher != null)
187		{
188			String internalName = matcher.internalName();
189			if (!panelStack.raise(internalName)) {
190				ErrorMatcherPanel panel = new ErrorMatcherPanel(internalName, matcher);
191				
192				panelStack.add(internalName, panel);
193				panelStack.raise(internalName);
194				validateTree();
195			}
196		}
197	} //}}}
198
199	//}}}
200
201	//{{{ ActionHandler class
202	class ActionHandler implements ActionListener
203	{
204		
205		public void actionPerformed(ActionEvent evt)
206		{
207			Object source = evt.getSource();
208			
209			if (source == reset) {
210				errorListModel.reset();
211				errorList.setModel(errorListModel);
212				errorList.repaint();
213			}
214			
215			if(source == add)
216			{
217				/* Open a dialog and ask for the name: */
218				String matcherNamePrompt = jEdit.getProperty("options.console.errors.name");
219				String matcherName = JOptionPane.showInputDialog(matcherNamePrompt);
220				ErrorMatcher matcher = new ErrorMatcher(matcherName);
221				matcher.name = matcherName;
222				matcher.user = true;
223				int index = errorList.getSelectedIndex() + 1;
224				errorListModel.insertElementAt(matcher,index);
225				errorList.setSelectedIndex(index);
226				errorList.repaint();
227			}
228			else if(source == remove)
229			{
230				int index = errorList.getSelectedIndex();
231				errorListModel.removeElementAt(index);
232				if (errorListModel.size() > index)
233					errorList.setSelectedIndex(index);
234				else if (! errorListModel.isEmpty())
235					errorList.setSelectedIndex(errorListModel.size() - 1);
236				errorList.repaint();
237			}
238			
239			else if(source == up)
240			{
241				int index = errorList.getSelectedIndex();
242				ErrorMatcher selected = errorListModel.get(index);
243				errorListModel.removeElementAt(index);
244				errorListModel.insertElementAt(selected,index-1);
245				errorList.setSelectedIndex(index-1);
246				errorList.repaint();
247			}
248			else if(source == down)
249			{
250				int index = errorList.getSelectedIndex();
251				ErrorMatcher matcher = errorListModel.get(index);
252				errorListModel.removeElementAt(index);
253				errorListModel.insertElementAt(matcher, index+1);
254				errorList.setSelectedIndex(index+1);
255				errorList.repaint();
256			} 
257
258		}
259	} //}}}
260
261	//{{{ ListHandler class
262	class ListHandler implements ListSelectionListener
263	{
264		public void valueChanged(ListSelectionEvent evt)
265		{
266			updateButtons();
267		}
268	} //}}}
269
270	//{{{ MouseHandler class
271	class MouseHandler extends MouseAdapter
272	{
273		public void mouseClicked(MouseEvent evt)
274		{
275			if(evt.getClickCount() == 2)
276			{
277				updateButtons();
278			}
279		}
280	} //}}}
281} //}}}
282