PageRenderTime 208ms CodeModel.GetById 200ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 153 lines | 98 code | 19 blank | 36 comment | 6 complexity | bfdd2235ac8be3f462c2e6c4f23a67d0 MD5 | raw file
  1/*
  2 * MouseOptionPane.java - Editor window options
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2003 Slava Pestov
  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 org.gjt.sp.jedit.options;
 24
 25//{{{ Imports
 26import javax.swing.border.*;
 27import javax.swing.*;
 28import java.awt.event.*;
 29import java.awt.*;
 30import java.io.*;
 31import org.gjt.sp.jedit.*;
 32import org.gjt.sp.util.Log;
 33//}}}
 34
 35public class MouseOptionPane extends AbstractOptionPane
 36{
 37	//{{{ MouseOptionPane constructor
 38	public MouseOptionPane()
 39	{
 40		super("mouse");
 41	} //}}}
 42
 43	//{{{ _init() method
 44	protected void _init()
 45	{
 46		/* Text drag and drop */
 47		dragAndDrop = new JCheckBox(jEdit.getProperty(
 48			"options.mouse.dragAndDrop"));
 49		dragAndDrop.setSelected(jEdit.getBooleanProperty(
 50			"view.dragAndDrop"));
 51		addComponent(dragAndDrop);
 52
 53		/* Non word character selection behavior */
 54		joinNonWordChars = new JCheckBox(jEdit.getProperty(
 55			"options.mouse.joinNonWordChars"));
 56		joinNonWordChars.setSelected(jEdit.getBooleanProperty(
 57			"view.joinNonWordChars"));
 58		addComponent(joinNonWordChars);
 59
 60		/* Middle mouse button click pastes % register */
 61		middleMousePaste = new JCheckBox(jEdit.getProperty("options.mouse"
 62			+ ".middleMousePaste"));
 63		middleMousePaste.setSelected(jEdit.getBooleanProperty(
 64			"view.middleMousePaste"));
 65		addComponent(middleMousePaste);
 66
 67		/*
 68		 * Pressing Ctrl while mouse actions makes them as if
 69		 * selection mode were rectangular mode
 70		 */
 71		ctrlForRectangularSelection = new JCheckBox(jEdit.getProperty(
 72			"options.mouse.ctrlForRectangularSelection"));
 73		ctrlForRectangularSelection.setSelected(jEdit.getBooleanProperty(
 74			"view.ctrlForRectangularSelection"));
 75		addComponent(ctrlForRectangularSelection);
 76
 77		/* Gutter mouse actions */
 78		int c = clickActionKeys.length;
 79		String[] clickActionNames = new String[c];
 80		for(int i = 0; i < c; i++)
 81		{
 82			clickActionNames[i] = jEdit.getProperty(
 83				"options.mouse.gutter."+clickActionKeys[i]);
 84		}
 85
 86		c = clickModifierKeys.length;
 87		String[] clickModifierNames = new String[c];
 88		for(int i = 0; i < c; i++)
 89		{
 90			clickModifierNames[i] = jEdit.getProperty(
 91				"options.mouse.gutter."+clickModifierKeys[i]);
 92		}
 93
 94		gutterClickActions = new JComboBox[c];
 95
 96		for(int i = 0; i < c; i++)
 97		{
 98			JComboBox cb = new JComboBox(clickActionNames);
 99			gutterClickActions[i] = cb;
100
101			String val = jEdit.getProperty("view.gutter."+clickModifierKeys[i]);
102			for(int j = 0; j < clickActionKeys.length; j++)
103			{
104				if(val.equals(clickActionKeys[j]))
105				{
106					cb.setSelectedIndex(j);
107				}
108			}
109
110			addComponent(clickModifierNames[i],cb);
111		}
112	} //}}}
113
114	//{{{ _save() method
115	public void _save()
116	{
117		jEdit.setBooleanProperty("view.dragAndDrop",
118					 dragAndDrop.isSelected());
119		jEdit.setBooleanProperty("view.joinNonWordChars",
120					 joinNonWordChars.isSelected());
121		jEdit.setBooleanProperty("view.middleMousePaste",
122					 middleMousePaste.isSelected());
123		jEdit.setBooleanProperty("view.ctrlForRectangularSelection",
124					 ctrlForRectangularSelection.isSelected());
125
126		int c = clickModifierKeys.length;
127		for(int i = 0; i < c; i++)
128		{
129			int idx = gutterClickActions[i].getSelectedIndex();
130			jEdit.setProperty("view.gutter."+clickModifierKeys[i],
131				clickActionKeys[idx]);
132		}
133	} //}}}
134
135	//{{{ Private members
136	private JCheckBox dragAndDrop;
137	private JCheckBox joinNonWordChars;
138	private JCheckBox middleMousePaste;
139	private JCheckBox ctrlForRectangularSelection;
140
141	private JComboBox[] gutterClickActions;
142
143	// simplified these settings a little...
144	private static final String[] clickActionKeys = new String[] {
145		"toggle-fold",
146		"toggle-fold-fully"
147	};
148	
149	private static final String[] clickModifierKeys = new String[] {
150		"foldClick",
151		"SfoldClick"
152	}; //}}}
153}