PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/options/GutterOptionPane.java

#
Java | 394 lines | 262 code | 44 blank | 88 comment | 6 complexity | 6b0dd6e094fef51630fb7551f10936bd MD5 | raw file
  1/*
  2 * GutterOptionPane.java - Gutter options panel
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2000 mike dillon
  7 * Portions copyright (C) 2001, 2002 Slava Pestov
  8 *
  9 * This program is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU General Public License
 11 * as published by the Free Software Foundation; either version 2
 12 * of the License, or any later version.
 13 *
 14 * This program is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 * GNU General Public License for more details.
 18 *
 19 * You should have received a copy of the GNU General Public License
 20 * along with this program; if not, write to the Free Software
 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 22 */
 23
 24package org.gjt.sp.jedit.options;
 25
 26//{{{ Imports
 27import javax.swing.*;
 28import javax.swing.event.ChangeEvent;
 29import javax.swing.event.ChangeListener;
 30
 31import java.awt.*;
 32
 33import org.gjt.sp.jedit.gui.*;
 34import org.gjt.sp.jedit.textarea.JEditTextArea;
 35import org.gjt.sp.jedit.*;
 36//}}}
 37import org.gjt.sp.util.SyntaxUtilities;
 38
 39public class GutterOptionPane extends AbstractOptionPane
 40{
 41	//{{{ GutterOptionPane constructor
 42	public GutterOptionPane()
 43	{
 44		super("gutter");
 45	} //}}}
 46
 47	//{{{ _init() method
 48	public void _init()
 49	{
 50		/* Gutter enable */
 51		gutterEnabled = new JCheckBox(jEdit.getProperty(
 52			"options.gutter.enabled"));
 53		gutterEnabled.setSelected(isGutterEnabled());
 54		addComponent(gutterEnabled);
 55
 56		/* Gutter components frame */
 57		GridBagConstraints cons = new GridBagConstraints();
 58		cons.gridheight = 1;
 59		cons.gridwidth = GridBagConstraints.REMAINDER;
 60		cons.fill = GridBagConstraints.HORIZONTAL;
 61		cons.anchor = GridBagConstraints.WEST;
 62		cons.weightx = 1.0f;
 63		cons.ipadx = 0;
 64		cons.ipady = 0;
 65		cons.insets = new Insets(0,0,0,0);
 66		gutterComponents = new JPanel(new GridBagLayout());
 67		gutterComponents.setBorder(BorderFactory.createTitledBorder(
 68			jEdit.getProperty("options.gutter.optionalComponents")));
 69		
 70		IntegerInputVerifier integerInputVerifier = new IntegerInputVerifier();
 71
 72		/* Line numbering */
 73		lineNumbersEnabled = new JCheckBox(jEdit.getProperty(
 74			"options.gutter.lineNumbers"));
 75		lineNumbersEnabled.setSelected(jEdit.getBooleanProperty(
 76			"view.gutter.lineNumbers"));
 77		gutterComponents.add(lineNumbersEnabled, cons);
 78
 79		minLineNumberDigits = new JTextField(String.valueOf(
 80				getMinLineNumberDigits()),1);
 81		minLineNumberDigits.setInputVerifier(integerInputVerifier);
 82		JPanel minLineNumberDigitsPanel = new JPanel();
 83		minLineNumberDigitsPanel.add(new JLabel(
 84			jEdit.getProperty("options.gutter.minLineNumberDigits")));
 85		minLineNumberDigitsPanel.add(minLineNumberDigits);
 86		cons.gridy = 1;
 87		gutterComponents.add(minLineNumberDigitsPanel, cons);
 88
 89		/* Selection area enable */
 90		selectionAreaEnabled = new JCheckBox(jEdit.getProperty(
 91			"options.gutter.selectionAreaEnabled"));
 92		selectionAreaEnabled.setSelected(isSelectionAreaEnabled());
 93		cons.gridy = 2;
 94		gutterComponents.add(selectionAreaEnabled, cons);
 95
 96		addComponent(gutterComponents);
 97		// Disable gutter components when 'show gutter' is unchecked
 98		setGutterComponentsEnabledState();
 99		gutterEnabled.addChangeListener(new ChangeListener()
100		{
101			public void stateChanged(ChangeEvent e)
102			{
103				setGutterComponentsEnabledState();
104			}
105		});
106
107		/* Selection area background color */
108		addComponent(jEdit.getProperty("options.gutter.selectionAreaBgColor"),
109			selectionAreaBgColor = new ColorWellButton(
110				getSelectionAreaBackground()), GridBagConstraints.VERTICAL);
111
112		/* Selection area width */
113		selectionAreaWidth = new JTextField(String.valueOf(
114			getSelectionAreaWidth()),DEFAULT_SELECTION_GUTTER_WIDTH);
115		selectionAreaWidth.setInputVerifier(integerInputVerifier);
116		addComponent(jEdit.getProperty("options.gutter.selectionAreaWidth"),
117			selectionAreaWidth);
118
119		/* Text font */
120		gutterFont = new FontSelector(
121			jEdit.getFontProperty("view.gutter.font",
122			new Font("Monospaced",Font.PLAIN,10)));
123
124		addComponent(jEdit.getProperty("options.gutter.font"),gutterFont);
125
126		/* Text color */
127		addComponent(jEdit.getProperty("options.gutter.foreground"),
128			gutterForeground = new ColorWellButton(
129			jEdit.getColorProperty("view.gutter.fgColor")),
130			GridBagConstraints.VERTICAL);
131
132		/* Background color */
133		addComponent(jEdit.getProperty("options.gutter.background"),
134			gutterBackground = new ColorWellButton(
135			jEdit.getColorProperty("view.gutter.bgColor")),
136			GridBagConstraints.VERTICAL);
137
138		/* Border width */
139		/* gutterBorderWidth = new JTextField(jEdit.getProperty(
140			"view.gutter.borderWidth"));
141		addComponent(jEdit.getProperty("options.gutter.borderWidth"),
142			gutterBorderWidth); */
143
144		/* Number alignment */
145		/* String[] alignments = new String[] {
146			"Left", "Center", "Right"
147		};
148		gutterNumberAlignment = new JComboBox(alignments);
149		String alignment = jEdit.getProperty("view.gutter.numberAlignment");
150		if("right".equals(alignment))
151			gutterNumberAlignment.setSelectedIndex(2);
152		else if("center".equals(alignment))
153			gutterNumberAlignment.setSelectedIndex(1);
154		else
155			gutterNumberAlignment.setSelectedIndex(0);
156		addComponent(jEdit.getProperty("options.gutter.numberAlignment"),
157			gutterNumberAlignment); */
158
159		/* Current line highlight */
160		gutterCurrentLineHighlightEnabled = new JCheckBox(jEdit.getProperty(
161			"options.gutter.currentLineHighlight"));
162		gutterCurrentLineHighlightEnabled.setSelected(jEdit.getBooleanProperty(
163			"view.gutter.highlightCurrentLine"));
164		addComponent(gutterCurrentLineHighlightEnabled,
165			gutterCurrentLineHighlight = new ColorWellButton(
166			jEdit.getColorProperty("view.gutter.currentLineColor")),
167			GridBagConstraints.VERTICAL);
168
169		/* Highlight interval and color */
170		gutterHighlightInterval = new JTextField(jEdit.getProperty(
171			"view.gutter.highlightInterval"),3);
172
173		Box gutterHighlightBox = new Box(BoxLayout.X_AXIS);
174		gutterHighlightBox.add(new JLabel(jEdit.getProperty(
175			"options.gutter.interval-1")));
176		gutterHighlightBox.add(Box.createHorizontalStrut(3));
177		gutterHighlightBox.add(gutterHighlightInterval);
178		gutterHighlightBox.add(Box.createHorizontalStrut(3));
179		gutterHighlightBox.add(new JLabel(jEdit.getProperty(
180			"options.gutter.interval-2")));
181		gutterHighlightBox.add(Box.createHorizontalStrut(12));
182
183		addComponent(gutterHighlightBox,gutterHighlightColor
184			= new ColorWellButton(jEdit.getColorProperty(
185			"view.gutter.highlightColor")),
186			GridBagConstraints.VERTICAL);
187
188		/* Structure highlight */
189		gutterStructureHighlightEnabled = new JCheckBox(jEdit.getProperty(
190			"options.gutter.structureHighlight"));
191		gutterStructureHighlightEnabled.setSelected(jEdit.getBooleanProperty(
192			"view.gutter.structureHighlight"));
193		addComponent(gutterStructureHighlightEnabled,
194			gutterStructureHighlight = new ColorWellButton(
195			jEdit.getColorProperty("view.gutter.structureHighlightColor")),
196			GridBagConstraints.VERTICAL);
197
198		/* Marker highlight */
199		gutterMarkerHighlightEnabled = new JCheckBox(jEdit.getProperty(
200			"options.gutter.markerHighlight"));
201		gutterMarkerHighlightEnabled.setSelected(jEdit.getBooleanProperty(
202			"view.gutter.markerHighlight"));
203		addComponent(gutterMarkerHighlightEnabled,
204			gutterMarkerHighlight = new ColorWellButton(
205			jEdit.getColorProperty("view.gutter.markerColor")),
206			GridBagConstraints.VERTICAL);
207
208		/* Fold marker color */
209		addComponent(jEdit.getProperty("options.gutter.foldColor"),
210			gutterFoldMarkers = new ColorWellButton(
211			jEdit.getColorProperty("view.gutter.foldColor")),
212			GridBagConstraints.VERTICAL);
213
214		/* Focused border color */
215		addComponent(jEdit.getProperty("options.gutter.focusBorderColor"),
216			gutterFocusBorder = new ColorWellButton(
217			jEdit.getColorProperty("view.gutter.focusBorderColor")),
218			GridBagConstraints.VERTICAL);
219
220		/* unfocused border color */
221		addComponent(jEdit.getProperty("options.gutter.noFocusBorderColor"),
222			gutterNoFocusBorder = new ColorWellButton(
223			jEdit.getColorProperty("view.gutter.noFocusBorderColor")),
224			GridBagConstraints.VERTICAL);
225		
226		addFoldStyleChooser();
227	} //}}}
228
229	//{{{ _save() method
230	public void _save()
231	{
232		jEdit.setBooleanProperty("view.gutter.lineNumbers", lineNumbersEnabled
233			.isSelected());
234		jEdit.setIntegerProperty("view.gutter.minDigitCount",
235			Integer.valueOf(minLineNumberDigits.getText()));
236
237		jEdit.setFontProperty("view.gutter.font",gutterFont.getFont());
238		jEdit.setColorProperty("view.gutter.fgColor",gutterForeground
239			.getSelectedColor());
240		jEdit.setColorProperty("view.gutter.bgColor",gutterBackground
241			.getSelectedColor());
242
243		/* jEdit.setProperty("view.gutter.borderWidth",
244			gutterBorderWidth.getText());
245
246		String alignment = null;
247		switch(gutterNumberAlignment.getSelectedIndex())
248		{
249		case 2:
250			alignment = "right";
251			break;
252		case 1:
253			alignment = "center";
254			break;
255		case 0: default:
256			alignment = "left";
257		}
258		jEdit.setProperty("view.gutter.numberAlignment", alignment); */
259
260		jEdit.setBooleanProperty("view.gutter.highlightCurrentLine",
261			gutterCurrentLineHighlightEnabled.isSelected());
262		jEdit.setColorProperty("view.gutter.currentLineColor",
263			gutterCurrentLineHighlight.getSelectedColor());
264		jEdit.setProperty("view.gutter.highlightInterval",
265			gutterHighlightInterval.getText());
266		jEdit.setColorProperty("view.gutter.highlightColor",
267			gutterHighlightColor.getSelectedColor());
268
269		jEdit.setBooleanProperty("view.gutter.structureHighlight",
270			gutterStructureHighlightEnabled.isSelected());
271		jEdit.setColorProperty("view.gutter.structureHighlightColor",
272			gutterStructureHighlight.getSelectedColor());
273		jEdit.setBooleanProperty("view.gutter.markerHighlight",
274			gutterMarkerHighlightEnabled.isSelected());
275		jEdit.setColorProperty("view.gutter.markerColor",
276			gutterMarkerHighlight.getSelectedColor());
277		jEdit.setColorProperty("view.gutter.foldColor",
278			gutterFoldMarkers.getSelectedColor());
279		jEdit.setProperty(JEditTextArea.FOLD_PAINTER_PROPERTY,
280			painters[foldPainter.getSelectedIndex()]);
281		jEdit.setColorProperty("view.gutter.focusBorderColor",
282			gutterFocusBorder.getSelectedColor());
283		jEdit.setColorProperty("view.gutter.noFocusBorderColor",
284			gutterNoFocusBorder.getSelectedColor());
285		jEdit.setBooleanProperty(GUTTER_ENABLED_PROPERTY,
286			gutterEnabled.isSelected());
287		jEdit.setBooleanProperty(SELECTION_AREA_ENABLED_PROPERTY,
288			selectionAreaEnabled.isSelected());
289		jEdit.setColorProperty(SELECTION_AREA_BGCOLOR_PROPERTY,
290			selectionAreaBgColor.getSelectedColor());
291		jEdit.setIntegerProperty("view.gutter.selectionAreaWidth",
292			Integer.valueOf(selectionAreaWidth.getText()));
293	} //}}}
294
295	//{{{ setGutterComponentsEnabledState
296	private void setGutterComponentsEnabledState()
297	{
298		GUIUtilities.setEnabledRecursively(gutterComponents,
299			gutterEnabled.isSelected());
300	} //}}}
301
302	//{{{ addFoldStyleChooser() method
303	private void addFoldStyleChooser()
304	{
305		painters = ServiceManager.getServiceNames(JEditTextArea.FOLD_PAINTER_SERVICE);
306		foldPainter = new JComboBox();
307		String current = JEditTextArea.getFoldPainterName();
308		int selected = 0;
309		for (int i = 0; i < painters.length; i++)
310		{
311			String painter = painters[i];
312			foldPainter.addItem(jEdit.getProperty(
313				"options.gutter.foldStyleNames." + painter, painter));
314			if (painter.equals(current))
315				selected = i;
316		}
317		foldPainter.setSelectedIndex(selected);
318		addComponent(new JLabel(jEdit.getProperty("options.gutter.foldStyle.label")), foldPainter);
319	} //}}}
320
321	//{{{ isGutterEnabled() method
322	public static boolean isGutterEnabled()
323	{
324		return jEdit.getBooleanProperty(GUTTER_ENABLED_PROPERTY);
325	} //}}}
326
327	//{{{ getMinLineNumberDigits() method
328	public static int getMinLineNumberDigits()
329	{
330		int n = jEdit.getIntegerProperty("view.gutter.minDigitCount", 2);
331		if (n < 0)
332			n = 2;
333		return n;
334	} //}}}
335
336	//{{{ isSelectionAreaEnabled() method
337	public static boolean isSelectionAreaEnabled()
338	{
339		return jEdit.getBooleanProperty(SELECTION_AREA_ENABLED_PROPERTY);
340	} //}}}
341
342	//{{{ getSelectionAreaBgColor() method
343	public static Color getSelectionAreaBackground()
344	{
345		String color = jEdit.getProperty(SELECTION_AREA_BGCOLOR_PROPERTY);
346		if (color == null)
347			return jEdit.getColorProperty("view.gutter.bgColor");
348		return SyntaxUtilities.parseColor(color, Color.black);
349	} //}}}
350
351	//{{{ getSelectionAreaWidth() method
352	public static int getSelectionAreaWidth()
353	{
354		int n = jEdit.getIntegerProperty("view.gutter.selectionAreaWidth",
355			DEFAULT_SELECTION_GUTTER_WIDTH);
356		if (n < 0)
357			n = DEFAULT_SELECTION_GUTTER_WIDTH;
358		return n;
359	} //}}}
360
361	//{{{ Private members
362	private static final String GUTTER_ENABLED_PROPERTY =
363		"view.gutter.enabled";
364	private static final String SELECTION_AREA_ENABLED_PROPERTY =
365		"view.gutter.selectionAreaEnabled";
366	private static final String SELECTION_AREA_BGCOLOR_PROPERTY =
367		"view.gutter.selectionAreaBgColor";
368	private static final int DEFAULT_SELECTION_GUTTER_WIDTH = 12;
369
370	private FontSelector gutterFont;
371	private ColorWellButton gutterForeground;
372	private ColorWellButton gutterBackground;
373	private JTextField gutterHighlightInterval;
374	private ColorWellButton gutterHighlightColor;
375	private JCheckBox lineNumbersEnabled;
376	private JCheckBox gutterCurrentLineHighlightEnabled;
377	private ColorWellButton gutterCurrentLineHighlight;
378	private JCheckBox gutterStructureHighlightEnabled;
379	private ColorWellButton gutterStructureHighlight;
380	private JCheckBox gutterMarkerHighlightEnabled;
381	private ColorWellButton gutterMarkerHighlight;
382	private ColorWellButton gutterFoldMarkers;
383	private JComboBox foldPainter;
384	private ColorWellButton gutterFocusBorder;
385	private ColorWellButton gutterNoFocusBorder;
386	private String [] painters;
387	private JCheckBox gutterEnabled;
388	private JPanel gutterComponents;
389	private JTextField minLineNumberDigits;
390	private JCheckBox selectionAreaEnabled;
391	private ColorWellButton selectionAreaBgColor;
392	private JTextField selectionAreaWidth;
393	//}}}
394}