PageRenderTime 59ms CodeModel.GetById 43ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 176 lines | 108 code | 33 blank | 35 comment | 4 complexity | ed34b3646c16add597ee3b6cfe690977 MD5 | raw file
  1/*
  2 * SideKickModeOptionsPane.java - 
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2006 Alan Ezust
  7 * Copyright (c) 2007 Shlomy Reinstein
  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
 24
 25package sidekick;
 26
 27
 28import javax.swing.DefaultComboBoxModel;
 29import javax.swing.JCheckBox;
 30import javax.swing.JComboBox;
 31import javax.swing.JComponent;
 32
 33import org.gjt.sp.jedit.jEdit;
 34
 35import sidekick.ModeOptionPaneController.ModeOptionPaneDelegate;
 36
 37// {{{ SideKickModeOptionsPane
 38/**
 39 * 
 40 * Mode-Specific options for SideKick - a custom ModeOptionPane which 
 41 * includes 3 questions for the user, and provides an example of
 42 * how to extend ModeOptionPane and set/reset the mode options.
 43 * 
 44 * @author Alan Ezust
 45 *
 46 */
 47@SuppressWarnings("serial")
 48public class SideKickModeOptionsPane extends AbstractModeOptionPane implements ModeOptionPaneDelegate
 49{
 50	ModeOptionPaneController controller;
 51	
 52	JCheckBox showStatusWindow;
 53	JCheckBox treeFollowsCaret;
 54	JComboBox autoExpandTreeDepth;
 55	JComboBox defaultParser;
 56
 57	// {{{ SideKickModeOptionsPane ctor
 58	public SideKickModeOptionsPane() 
 59	{
 60		super("sidekick.mode");
 61		controller = new ModeOptionPaneController(this);
 62		
 63		showStatusWindow = new JCheckBox(jEdit.getProperty("options." + SideKick.SHOW_STATUS));
 64		addComponent(showStatusWindow);
 65		
 66		treeFollowsCaret = new JCheckBox(jEdit.getProperty("options.sidekick.tree-follows-caret"));
 67		addComponent(treeFollowsCaret);
 68
 69		autoExpandTreeDepth = new JComboBox();
 70		addComponent(jEdit.getProperty("options.sidekick.auto-expand-tree-depth"), autoExpandTreeDepth);
 71//		autoExpandTreeDepth.addActionListener(new ActionHandler());
 72		autoExpandTreeDepth.addItem(ModeOptionsDialog.ALL);
 73		for (int i = 0; i <= 10; i++)
 74			autoExpandTreeDepth.addItem(String.valueOf(i));
 75		addComponent(autoExpandTreeDepth);
 76		defaultParser = new JComboBox();
 77		defaultParser.setModel(new DefaultComboBoxModel(SideKickTree.parserList().toArray()));
 78		
 79		addComponent(jEdit.getProperty("options.sidekick.parser.parser"), defaultParser);
 80		
 81	} // }}}
 82	
 83
 84	// {{{ init()
 85	protected void _init() {
 86	} // }}}
 87	
 88	class Props {
 89		boolean treeFollowsCaret;
 90		boolean showStatusWindow;
 91		int autoExpandTreeDepth;
 92		String parser;
 93	}
 94	
 95	public Object createModeProps(String mode) {
 96		Props p = new Props();
 97		p.treeFollowsCaret = getBooleanProperty(mode, SideKick.FOLLOW_CARET);
 98		p.showStatusWindow = getBooleanProperty(mode, SideKick.SHOW_STATUS);
 99		p.autoExpandTreeDepth = getIntegerProperty(mode, SideKick.AUTO_EXPAND_DEPTH, 1);
100		p.parser = getProperty(mode, SideKickPlugin.PARSER_PROPERTY);
101		return p;
102	}
103
104	public void resetModeProps(String mode) {
105		clearModeProperty(mode, SideKick.FOLLOW_CARET);
106		clearModeProperty(mode, SideKick.AUTO_EXPAND_DEPTH);
107		clearModeProperty(mode, SideKick.SHOW_STATUS);
108		clearModeProperty(mode, SideKickPlugin.PARSER_PROPERTY);
109	}
110
111	public void saveModeProps(String mode, Object props) {
112		Props p = (Props) props;
113		setBooleanProperty(mode, SideKick.FOLLOW_CARET, p.treeFollowsCaret);
114		setBooleanProperty(mode, SideKick.SHOW_STATUS, p.showStatusWindow);
115		setIntegerProperty(mode, SideKick.AUTO_EXPAND_DEPTH, p.autoExpandTreeDepth);
116		if (p.parser == SideKickPlugin.DEFAULT)
117			clearModeProperty(mode, SideKickPlugin.PARSER_PROPERTY);
118		else
119			setProperty(mode, SideKickPlugin.PARSER_PROPERTY, p.parser);
120	}
121
122	public void updatePropsFromUI(Object props) {
123		Props p = (Props) props;
124		p.treeFollowsCaret = treeFollowsCaret.isSelected();
125		p.showStatusWindow = showStatusWindow.isSelected();
126		String value = (String)autoExpandTreeDepth.getSelectedItem();
127		String depth = value.equals(ModeOptionsDialog.ALL) ? "-1" : value;
128		p.autoExpandTreeDepth = Integer.valueOf(depth); 
129		Object parser = defaultParser.getSelectedItem();
130		p.parser = (parser == null) ? null : parser.toString();
131	}
132
133	public void updateUIFromProps(Object props) {
134		Props p = (Props) props;
135		treeFollowsCaret.setSelected(p.treeFollowsCaret);
136		showStatusWindow.setSelected(p.showStatusWindow);
137		autoExpandTreeDepth.setSelectedIndex(p.autoExpandTreeDepth + 1);
138		defaultParser.setSelectedItem(p.parser);
139	}
140
141	public void modeSelected(String mode) {
142		controller.modeSelected(mode);
143	}
144
145	public void cancel() {
146		controller.cancel();
147	}
148	
149	public void setUseDefaults(boolean b) {
150		controller.setUseDefaults(b);
151	}
152
153	public boolean getUseDefaults(String mode) {
154		return controller.getUseDefaults(mode);
155	}
156
157	public JComponent getUIComponent() {
158		return this;
159	}
160
161
162	public boolean hasModeProps(String mode) {
163		return modePropertyExists(mode, SideKick.FOLLOW_CARET) ||
164			modePropertyExists(mode, SideKick.AUTO_EXPAND_DEPTH) ||
165			modePropertyExists(mode, SideKick.SHOW_STATUS) ||
166			modePropertyExists(mode, SideKickPlugin.PARSER_PROPERTY);
167	}
168
169	@Override
170	public void _save() {
171		controller.save();
172	}
173
174
175} // }}}
176