PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/options/GutterOptionPane.java

#
Java | 290 lines | 178 code | 36 blank | 76 comment | 6 complexity | 30d2bea2db3a25e329d616503351bfd7 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 * 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 java.awt.*;
 29import org.gjt.sp.jedit.gui.*;
 30import org.gjt.sp.jedit.*;
 31//}}}
 32
 33public class GutterOptionPane extends AbstractOptionPane
 34{
 35	//{{{ GutterOptionPane constructor
 36	public GutterOptionPane()
 37	{
 38		super("gutter");
 39	} //}}}
 40
 41	//{{{ _init() method
 42	public void _init()
 43	{
 44		/* Line numbering */
 45		lineNumbersEnabled = new JCheckBox(jEdit.getProperty(
 46			"options.gutter.lineNumbers"));
 47		lineNumbersEnabled.setSelected(jEdit.getBooleanProperty(
 48			"view.gutter.lineNumbers"));
 49		addComponent(lineNumbersEnabled);
 50
 51		/* Text font */
 52		gutterFont = new FontSelector(
 53			jEdit.getFontProperty("view.gutter.font",
 54			new Font("Monospaced",Font.PLAIN,10)));
 55
 56		addComponent(jEdit.getProperty("options.gutter.font"),gutterFont);
 57
 58		/* Text color */
 59		addComponent(jEdit.getProperty("options.gutter.foreground"),
 60			gutterForeground = new ColorWellButton(
 61			jEdit.getColorProperty("view.gutter.fgColor")),
 62			GridBagConstraints.VERTICAL);
 63
 64		/* Background color */
 65		addComponent(jEdit.getProperty("options.gutter.background"),
 66			gutterBackground = new ColorWellButton(
 67			jEdit.getColorProperty("view.gutter.bgColor")),
 68			GridBagConstraints.VERTICAL);
 69
 70		/* Border width */
 71		/* gutterBorderWidth = new JTextField(jEdit.getProperty(
 72			"view.gutter.borderWidth"));
 73		addComponent(jEdit.getProperty("options.gutter.borderWidth"),
 74			gutterBorderWidth); */
 75
 76		/* Number alignment */
 77		/* String[] alignments = new String[] {
 78			"Left", "Center", "Right"
 79		};
 80		gutterNumberAlignment = new JComboBox(alignments);
 81		String alignment = jEdit.getProperty("view.gutter.numberAlignment");
 82		if("right".equals(alignment))
 83			gutterNumberAlignment.setSelectedIndex(2);
 84		else if("center".equals(alignment))
 85			gutterNumberAlignment.setSelectedIndex(1);
 86		else
 87			gutterNumberAlignment.setSelectedIndex(0);
 88		addComponent(jEdit.getProperty("options.gutter.numberAlignment"),
 89			gutterNumberAlignment); */
 90
 91		/* Current line highlight */
 92		gutterCurrentLineHighlightEnabled = new JCheckBox(jEdit.getProperty(
 93			"options.gutter.currentLineHighlight"));
 94		gutterCurrentLineHighlightEnabled.setSelected(jEdit.getBooleanProperty(
 95			"view.gutter.highlightCurrentLine"));
 96		addComponent(gutterCurrentLineHighlightEnabled,
 97			gutterCurrentLineHighlight = new ColorWellButton(
 98			jEdit.getColorProperty("view.gutter.currentLineColor")),
 99			GridBagConstraints.VERTICAL);
100
101		/* Highlight interval and color */
102		gutterHighlightInterval = new JTextField(jEdit.getProperty(
103			"view.gutter.highlightInterval"),3);
104
105		Box gutterHighlightBox = new Box(BoxLayout.X_AXIS);
106		gutterHighlightBox.add(new JLabel(jEdit.getProperty(
107			"options.gutter.interval-1")));
108		gutterHighlightBox.add(Box.createHorizontalStrut(3));
109		gutterHighlightBox.add(gutterHighlightInterval);
110		gutterHighlightBox.add(Box.createHorizontalStrut(3));
111		gutterHighlightBox.add(new JLabel(jEdit.getProperty(
112			"options.gutter.interval-2")));
113		gutterHighlightBox.add(Box.createHorizontalStrut(12));
114
115		addComponent(gutterHighlightBox,gutterHighlightColor
116			= new ColorWellButton(jEdit.getColorProperty(
117			"view.gutter.highlightColor")),
118			GridBagConstraints.VERTICAL);
119
120		/* Structure highlight */
121		gutterStructureHighlightEnabled = new JCheckBox(jEdit.getProperty(
122			"options.gutter.structureHighlight"));
123		gutterStructureHighlightEnabled.setSelected(jEdit.getBooleanProperty(
124			"view.gutter.structureHighlight"));
125		addComponent(gutterStructureHighlightEnabled,
126			gutterStructureHighlight = new ColorWellButton(
127			jEdit.getColorProperty("view.gutter.structureHighlightColor")),
128			GridBagConstraints.VERTICAL);
129
130		/* Marker highlight */
131		gutterMarkerHighlightEnabled = new JCheckBox(jEdit.getProperty(
132			"options.gutter.markerHighlight"));
133		gutterMarkerHighlightEnabled.setSelected(jEdit.getBooleanProperty(
134			"view.gutter.markerHighlight"));
135		addComponent(gutterMarkerHighlightEnabled,
136			gutterMarkerHighlight = new ColorWellButton(
137			jEdit.getColorProperty("view.gutter.markerColor")),
138			GridBagConstraints.VERTICAL);
139
140		/* Fold marker color */
141		addComponent(jEdit.getProperty("options.gutter.foldColor"),
142			gutterFoldMarkers = new ColorWellButton(
143			jEdit.getColorProperty("view.gutter.foldColor")),
144			GridBagConstraints.VERTICAL);
145
146		/* Focused border color */
147		addComponent(jEdit.getProperty("options.gutter.focusBorderColor"),
148			gutterFocusBorder = new ColorWellButton(
149			jEdit.getColorProperty("view.gutter.focusBorderColor")),
150			GridBagConstraints.VERTICAL);
151
152		/* unfocused border color */
153		addComponent(jEdit.getProperty("options.gutter.noFocusBorderColor"),
154			gutterNoFocusBorder = new ColorWellButton(
155			jEdit.getColorProperty("view.gutter.noFocusBorderColor")),
156			GridBagConstraints.VERTICAL);
157
158		/* Mouse actions */
159		addSeparator("options.gutter.actions");
160
161		int c = clickActionKeys.length;
162		String[] clickActionNames = new String[c];
163		for(int i = 0; i < c; i++)
164		{
165			clickActionNames[i] = jEdit.getProperty(
166				"options.gutter."+clickActionKeys[i]);
167		}
168
169		c = clickModifierKeys.length;
170		String[] clickModifierNames = new String[c];
171		for(int i = 0; i < c; i++)
172		{
173			clickModifierNames[i] = jEdit.getProperty(
174				"options.gutter."+clickModifierKeys[i]);
175		}
176
177		gutterClickActions = new JComboBox[c];
178
179		for(int i = 0; i < c; i++)
180		{
181			JComboBox cb = new JComboBox(clickActionNames);
182			gutterClickActions[i] = cb;
183
184			String val = jEdit.getProperty("view.gutter."+clickModifierKeys[i]);
185			for(int j = 0; j < clickActionKeys.length; j++)
186			{
187				if(val.equals(clickActionKeys[j]))
188				{
189					cb.setSelectedIndex(j);
190				}
191			}
192
193			addComponent(clickModifierNames[i],cb);
194		}
195	} //}}}
196
197	//{{{ _save() method
198	public void _save()
199	{
200		jEdit.setBooleanProperty("view.gutter.lineNumbers", lineNumbersEnabled
201			.isSelected());
202
203		jEdit.setFontProperty("view.gutter.font",gutterFont.getFont());
204		jEdit.setColorProperty("view.gutter.fgColor",gutterForeground
205			.getSelectedColor());
206		jEdit.setColorProperty("view.gutter.bgColor",gutterBackground
207			.getSelectedColor());
208
209		/* jEdit.setProperty("view.gutter.borderWidth",
210			gutterBorderWidth.getText());
211
212		String alignment = null;
213		switch(gutterNumberAlignment.getSelectedIndex())
214		{
215		case 2:
216			alignment = "right";
217			break;
218		case 1:
219			alignment = "center";
220			break;
221		case 0: default:
222			alignment = "left";
223		}
224		jEdit.setProperty("view.gutter.numberAlignment", alignment); */
225
226		jEdit.setBooleanProperty("view.gutter.highlightCurrentLine",
227			gutterCurrentLineHighlightEnabled.isSelected());
228		jEdit.setColorProperty("view.gutter.currentLineColor",
229			gutterCurrentLineHighlight.getSelectedColor());
230		jEdit.setProperty("view.gutter.highlightInterval",
231			gutterHighlightInterval.getText());
232		jEdit.setColorProperty("view.gutter.highlightColor",
233			gutterHighlightColor.getSelectedColor());
234
235		jEdit.setBooleanProperty("view.gutter.structureHighlight",
236			gutterStructureHighlightEnabled.isSelected());
237		jEdit.setColorProperty("view.gutter.structureHighlightColor",
238			gutterStructureHighlight.getSelectedColor());
239		jEdit.setBooleanProperty("view.gutter.markerHighlight",
240			gutterMarkerHighlightEnabled.isSelected());
241		jEdit.setColorProperty("view.gutter.markerColor",
242			gutterMarkerHighlight.getSelectedColor());
243		jEdit.setColorProperty("view.gutter.foldColor",
244			gutterFoldMarkers.getSelectedColor());
245		jEdit.setColorProperty("view.gutter.focusBorderColor",
246			gutterFocusBorder.getSelectedColor());
247		jEdit.setColorProperty("view.gutter.noFocusBorderColor",
248			gutterNoFocusBorder.getSelectedColor());
249
250		int c = clickModifierKeys.length;
251		for(int i = 0; i < c; i++)
252		{
253			int idx = gutterClickActions[i].getSelectedIndex();
254			jEdit.setProperty("view.gutter."+clickModifierKeys[i],
255				clickActionKeys[idx]);
256		}
257	} //}}}
258
259	//{{{ Private members
260	private FontSelector gutterFont;
261	private ColorWellButton gutterForeground;
262	private ColorWellButton gutterBackground;
263	private JTextField gutterBorderWidth;
264	private JTextField gutterHighlightInterval;
265	private ColorWellButton gutterHighlightColor;
266	private JComboBox gutterNumberAlignment;
267	private JCheckBox lineNumbersEnabled;
268	private JCheckBox gutterCurrentLineHighlightEnabled;
269	private ColorWellButton gutterCurrentLineHighlight;
270	private JCheckBox gutterStructureHighlightEnabled;
271	private ColorWellButton gutterStructureHighlight;
272	private JCheckBox gutterMarkerHighlightEnabled;
273	private ColorWellButton gutterMarkerHighlight;
274	private ColorWellButton gutterFoldMarkers;
275	private ColorWellButton gutterFocusBorder;
276	private ColorWellButton gutterNoFocusBorder;
277
278	private JComboBox[] gutterClickActions;
279
280	// simplified these settings a little...
281	private static final String[] clickActionKeys = new String[] {
282		"toggle-fold",
283		"toggle-fold-fully"
284	};
285	
286	private static final String[] clickModifierKeys = new String[] {
287		"foldClick",
288		"SfoldClick"
289	}; //}}}
290}