PageRenderTime 108ms CodeModel.GetById 73ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/SideKick/sidekick/SideKickOptionPane.java

#
Java | 302 lines | 235 code | 36 blank | 31 comment | 9 complexity | 546a747dcf817ed287ad83bfaa503eff MD5 | raw file
  1/*
  2 * SideKickOptionPane.java - SideKick options panel
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2001, 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 sidekick;
 24
 25//{{{ Imports
 26import javax.swing.*;
 27import javax.swing.border.TitledBorder;
 28
 29import java.awt.event.*;
 30import java.awt.*;
 31import java.util.Hashtable;
 32import org.gjt.sp.jedit.*;
 33//}}}
 34
 35public class SideKickOptionPane extends AbstractOptionPane
 36{
 37	public static final String SHOW_TOOL_BAR = "sidekick.showToolBar";
 38	public static final String SPLIT_COMBO = "sidekick.splitCombo";
 39	public static final String SINGLE_ICON_IN_COMBO = "sidekick.singleIconInCombo";
 40
 41	//{{{ SideKickOptionPane constructor
 42	public SideKickOptionPane()
 43	{
 44		super("sidekick");
 45	} //}}}
 46
 47	//{{{ _init() method
 48	protected void _init()
 49	{
 50		JPanel toolbarPanel = new JPanel(new GridLayout(0, 1));
 51		toolbarPanel.setBorder(new TitledBorder(jEdit.getProperty(
 52			"options.sidekick.toolBar.label")));
 53		addComponent(toolbarPanel);
 54		showToolBar = new JCheckBox(jEdit.getProperty(
 55			"options.sidekick.showToolBar.label"));
 56		showToolBar.setSelected(jEdit.getBooleanProperty(SHOW_TOOL_BAR));
 57		toolbarPanel.add(showToolBar);
 58		splitCombo = new JCheckBox(jEdit.getProperty(
 59			"options.sidekick.splitCombo.label"));
 60		splitCombo.setSelected(jEdit.getBooleanProperty(SPLIT_COMBO));
 61		toolbarPanel.add(splitCombo);
 62		singleIconInCombo = new JCheckBox(jEdit.getProperty(
 63			"options.sidekick.singleIconInCombo.label"));
 64		singleIconInCombo.setSelected(jEdit.getBooleanProperty(SINGLE_ICON_IN_COMBO));
 65		toolbarPanel.add(singleIconInCombo);
 66		addComponent(showToolTips = new JCheckBox(jEdit.getProperty(
 67			"options.sidekick.showToolTips.label")));
 68		showToolTips.setSelected(jEdit.getBooleanProperty(
 69			"sidekick.showToolTips"));
 70		addComponent(showStatusWindow = new JCheckBox(jEdit.getProperty(
 71			"options.sidekick.showStatusWindow.label")));
 72		showStatusWindow.setSelected(jEdit.getBooleanProperty("sidekick.showStatusWindow"));
 73		addComponent(treeFollowsCaret = new JCheckBox(jEdit.getProperty(
 74			"options.sidekick.tree-follows-caret")));
 75		treeFollowsCaret.setSelected(SideKick.isGlobalFollowCaret());
 76		
 77		treeFollowsCaret.addActionListener(new ActionHandler());
 78
 79		addComponent(scrollToVisible = new JCheckBox(jEdit.getProperty(
 80			"options.sidekick.scrollToVisible.label")));
 81		scrollToVisible.setSelected(jEdit.getBooleanProperty(
 82			"sidekick.scrollToVisible"));
 83		
 84		// checkbox to show/hide filter, indent next 2 checkboxes
 85		addComponent(showFilter = 
 86			     new JCheckBox(jEdit.getProperty("options.sidekick.showFilter.label", "Show filter text box")));
 87		showFilter.setSelected(jEdit.getBooleanProperty(SideKick.SHOW_FILTER, true));
 88		
 89		JPanel filterOptionPanel = new JPanel(new GridLayout(2, 1));
 90		filterOptionPanel.setBorder(BorderFactory.createEmptyBorder(0, 21, 0, 0));
 91		filterOptionPanel.add(persistentFilter = 
 92			     new JCheckBox(jEdit.getProperty("options.sidekick.persistentFilter.label")));
 93		persistentFilter.setSelected(jEdit.getBooleanProperty("sidekick.persistentFilter"));
 94		filterOptionPanel.add(filterVisibleAssets = 
 95			     new JCheckBox(jEdit.getProperty("options.sidekick.filter-visible-assets.label")));
 96		filterVisibleAssets.setSelected(jEdit.getBooleanProperty("sidekick.filter-visible-assets"));
 97		addComponent(filterOptionPanel);
 98		
 99		showFilter.addActionListener( 
100			new ActionListener() {
101				public void actionPerformed( ActionEvent ae ) {
102					persistentFilter.setEnabled(showFilter.isSelected());
103					filterVisibleAssets.setEnabled(showFilter.isSelected());
104				}
105			}
106		);
107		
108		addComponent(jEdit.getProperty("options.sidekick.auto-expand-tree-depth"),
109			autoExpandTreeDepth = new JComboBox());
110		autoExpandTreeDepth.addActionListener(new ActionHandler());
111		autoExpandTreeDepth.addItem(jEdit.getProperty("options.sidekick.all", "All"));
112		for (int i = 0; i <= 10; i++)
113			autoExpandTreeDepth.addItem(String.valueOf(i));
114		String depth = String.valueOf(jEdit.getIntegerProperty(
115			"sidekick-tree.auto-expand-tree-depth", 1));
116		autoExpandTreeDepth.setSelectedItem(depth);
117
118
119
120		JPanel parsingSettings = new JPanel();
121		parsingSettings.setBorder(new TitledBorder("Auto parsing Settings"));
122		parsingSettings.setLayout(new BorderLayout());
123		JPanel buttonPanel = new JPanel();
124		buttonPanel.setLayout(new FlowLayout());
125		parsingSettings.add(buttonPanel, BorderLayout.NORTH);
126		
127		buttonPanel.add(bufferChangeParse = new JCheckBox(jEdit.getProperty(
128			"options.sidekick.buffer-change-parse")));
129		bufferChangeParse.setSelected(SideKick.isParseOnChange());
130		bufferChangeParse.addActionListener(new ActionHandler());
131
132		buttonPanel.add(bufferSaveParse = new JCheckBox(jEdit.getProperty(
133			"options.sidekick.buffer-save-parse")));
134		bufferSaveParse.setSelected(SideKick.isParseOnSave());
135		bufferSaveParse.addActionListener(new ActionHandler());
136		
137		buttonPanel.add(keystrokeParse = new JCheckBox(jEdit.getProperty(
138			"options.sidekick.keystroke-parse")));
139		keystrokeParse.setSelected(jEdit.getBooleanProperty(
140			"buffer.sidekick.keystroke-parse"));
141		keystrokeParse.addActionListener(new ActionHandler());
142
143		int autoParseDelayValue;
144		try
145		{
146			autoParseDelayValue = Integer.parseInt(jEdit.getProperty("sidekick.auto-parse-delay"));
147		}
148		catch(NumberFormatException nf)
149		{
150			autoParseDelayValue = 1500;
151		}
152
153		parsingSettings.add(new JLabel(jEdit.getProperty("options.sidekick.auto-parse-delay")), BorderLayout.CENTER);
154		parsingSettings.add(autoParseDelay = new JSlider(200,3000,autoParseDelayValue), BorderLayout.SOUTH);
155		addComponent(parsingSettings);
156		Hashtable labelTable = new Hashtable();
157		for(int i = 500; i <= 3000; i += 500)
158		{
159			labelTable.put(new Integer(i),new JLabel(
160				String.valueOf((double)i / 1000.0)));
161		}
162		autoParseDelay.setLabelTable(labelTable);
163		autoParseDelay.setPaintLabels(true);
164		autoParseDelay.setMajorTickSpacing(500);
165		autoParseDelay.setPaintTicks(true);
166
167		autoParseDelay.setEnabled(keystrokeParse.isSelected());
168
169		
170		JPanel codeCompletionsPanel = new JPanel();
171		codeCompletionsPanel.setBorder(new TitledBorder(jEdit.getProperty(
172			"options.sidekick.code-completion.label")));
173		codeCompletionsPanel.setLayout(new BorderLayout()); 
174		
175		// addSeparator("options.sidekick.code-completion.label");
176		JPanel completionsCheckboxes = new JPanel();
177		completionsCheckboxes.setLayout(new FlowLayout());
178		completionsCheckboxes.add(completeInstantToggle = new JCheckBox(jEdit.getProperty(
179			"options.sidekick.complete-instant.toggle")));
180		completeInstantToggle.setSelected(jEdit.getBooleanProperty("sidekick.complete-instant.toggle"));
181		completeInstantToggle.addActionListener(new ActionHandler());
182
183		completionsCheckboxes.add(completeDelayToggle = new JCheckBox(jEdit.getProperty(
184			"options.sidekick.complete-delay.toggle")));
185		completeDelayToggle.setSelected(jEdit.getBooleanProperty("sidekick.complete-delay.toggle"));
186		completeDelayToggle.addActionListener(new ActionHandler());
187		codeCompletionsPanel.add(completionsCheckboxes, BorderLayout.NORTH);
188		
189		int completeDelayValue = jEdit.getIntegerProperty("sidekick.complete-delay",500);
190
191		codeCompletionsPanel.add(new JLabel(jEdit.getProperty("options.sidekick.complete-delay")), BorderLayout.CENTER);
192		codeCompletionsPanel.add(completeDelay = new JSlider(0,1500,completeDelayValue), BorderLayout.SOUTH);
193		addComponent(codeCompletionsPanel);
194
195		autoCompletePopupGetFocus = new JCheckBox(
196			jEdit.getProperty("options.sidekick.auto-complete-popup-get-focus"),
197			jEdit.getBooleanProperty("sidekick.auto-complete-popup-get-focus"));
198		addComponent(autoCompletePopupGetFocus);
199
200		labelTable = new Hashtable();
201		for(int i = 0; i <= 1500; i += 250)
202		{
203			labelTable.put(new Integer(i),new JLabel(
204				String.valueOf((double)i / 1000.0)));
205		}
206		completeDelay.setLabelTable(labelTable);
207		completeDelay.setPaintLabels(true);
208		completeDelay.setMajorTickSpacing(250);
209		completeDelay.setPaintTicks(true);
210
211		completeDelay.setEnabled(completeDelayToggle.isSelected());
212		
213		addComponent(jEdit.getProperty("options.sidekick.complete-popup.accept-characters"),
214			acceptChars = new JTextField(
215				jEdit.getProperty("sidekick.complete-popup.accept-characters")));
216
217		addComponent(jEdit.getProperty("options.sidekick.complete-popup.insert-characters"),
218			insertChars = new JTextField(
219				jEdit.getProperty("sidekick.complete-popup.insert-characters")));
220		
221	} //}}}
222
223	//{{{ _save() method
224	protected void _save()
225	{
226		SideKick.setParseOnSave(bufferSaveParse.isSelected());
227		SideKick.setParseOnChange(bufferChangeParse.isSelected());
228		jEdit.setBooleanProperty("buffer.sidekick.keystroke-parse",
229			keystrokeParse.isSelected());
230		jEdit.setProperty("sidekick.auto-parse-delay",String.valueOf(
231			autoParseDelay.getValue()));
232		SideKick.setGlobalFollowCaret(treeFollowsCaret.isSelected());
233		jEdit.setBooleanProperty(SHOW_TOOL_BAR, showToolBar.isSelected());
234		jEdit.setBooleanProperty(SPLIT_COMBO, splitCombo.isSelected());
235		jEdit.setBooleanProperty(SINGLE_ICON_IN_COMBO, singleIconInCombo.isSelected());
236		jEdit.setBooleanProperty("sidekick.showToolTips", showToolTips.isSelected());
237		jEdit.setBooleanProperty("sidekick.showStatusWindow", showStatusWindow.isSelected());
238		jEdit.setBooleanProperty("sidekick.scrollToVisible", scrollToVisible.isSelected());
239		jEdit.setBooleanProperty(SideKick.SHOW_FILTER, showFilter.isSelected());
240		jEdit.setBooleanProperty("sidekick.persistentFilter", persistentFilter.isSelected());
241		jEdit.setBooleanProperty("sidekick.filter-visible-assets", filterVisibleAssets.isSelected());
242		int depth = 0;
243		String value = (String)autoExpandTreeDepth.getSelectedItem();
244		depth = value.equals(jEdit.getProperty("options.sidekick.all", "All")) ? -1 : Integer.parseInt(value);
245		jEdit.setIntegerProperty("sidekick-tree.auto-expand-tree-depth",
246			depth);
247		jEdit.setBooleanProperty("sidekick.complete-instant.toggle",
248			completeInstantToggle.isSelected());
249		jEdit.setBooleanProperty("sidekick.complete-delay.toggle",
250			completeDelayToggle.isSelected());
251		jEdit.setIntegerProperty("sidekick.complete-delay",
252			completeDelay.getValue());
253		jEdit.setBooleanProperty("sidekick.auto-complete-popup-get-focus",
254			autoCompletePopupGetFocus.isSelected());
255		jEdit.setProperty("sidekick.complete-popup.accept-characters",acceptChars.getText());
256		jEdit.setProperty("sidekick.complete-popup.insert-characters",insertChars.getText());
257	} //}}}
258
259	//{{{ Private members
260	private JCheckBox bufferChangeParse;
261	private JCheckBox bufferSaveParse;
262	private JCheckBox keystrokeParse;
263	private JSlider autoParseDelay;
264	private JCheckBox treeFollowsCaret;
265	private JCheckBox scrollToVisible;
266	private JComboBox autoExpandTreeDepth;
267	private JCheckBox completeInstantToggle;
268	private JCheckBox completeDelayToggle;
269	private JSlider completeDelay;
270	private JCheckBox autoCompletePopupGetFocus;
271	private JCheckBox showToolBar;
272	private JCheckBox splitCombo;
273	private JCheckBox singleIconInCombo;
274	private JCheckBox showToolTips;
275	private JCheckBox showStatusWindow;
276	private JTextField acceptChars;
277	private JTextField insertChars;
278	private JCheckBox persistentFilter;
279	private JCheckBox showFilter;
280	private JCheckBox filterVisibleAssets;
281	//}}}
282
283	//{{{ ActionHandler class
284	class ActionHandler implements ActionListener
285	{
286		public void actionPerformed(ActionEvent evt)
287		{
288			Object source = evt.getSource();
289			if(source == keystrokeParse)
290			{
291				autoParseDelay.setEnabled(keystrokeParse.isSelected());
292				if(keystrokeParse.isSelected())
293					bufferChangeParse.setSelected(true);
294					bufferSaveParse.setSelected(true);
295			}
296			else if(source == completeDelayToggle)
297			{
298				completeDelay.setEnabled(completeDelayToggle.isSelected());
299			}
300		}
301	} //}}}
302}