PageRenderTime 89ms CodeModel.GetById 79ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/Sessions/sessions/SessionsOptionPane.java

#
Java | 206 lines | 147 code | 34 blank | 25 comment | 8 complexity | 7ddb24cbbfd148fa0e871bb6a3baec1b MD5 | raw file
  1/*
  2 * SessionsOptionPane.java - plugin options pane for Sessions plugin
  3 * Copyright (c) 2000,2001 Dirk Moebius
  4 *
  5 * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License
  9 * as published by the Free Software Foundation; either version 2
 10 * of the License, or any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20 */
 21
 22
 23package sessions;
 24
 25
 26import java.awt.event.ActionEvent;
 27import java.awt.event.ActionListener;
 28import javax.swing.Box;
 29import javax.swing.BoxLayout;
 30import javax.swing.ButtonGroup;
 31import javax.swing.JCheckBox;
 32import javax.swing.JLabel;
 33import javax.swing.JPanel;
 34import javax.swing.JRadioButton;
 35import javax.swing.JSpinner;
 36import javax.swing.SpinnerNumberModel;
 37import org.gjt.sp.jedit.jEdit;
 38import org.gjt.sp.jedit.AbstractOptionPane;
 39
 40
 41/**
 42 * This is the option pane that jEdit displays for Session plugin's options.
 43 */
 44public class SessionsOptionPane extends AbstractOptionPane implements ActionListener
 45{
 46
 47	private JCheckBox bAutoSave;
 48	private JCheckBox bAskSave;
 49	private JCheckBox bCloseAll;
 50	private JCheckBox bShowToolBar;
 51	private JRadioButton bShowBelowToolBar;
 52	private JRadioButton bShowJEditToolBar;
 53	private JRadioButton bShowInsideBufferList;
 54	private JCheckBox bShowTitle;
 55	private JCheckBox bChangeFSBDirectory;
 56	private JCheckBox bShowSessionNameInTitleBar;
 57	private JCheckBox bShowSessionPrefixInTitleBar;
 58	private SpinnerNumberModel maxSessionListSizeModel;
 59	private JSpinner  maxSessionListSize;
 60
 61
 62	public SessionsOptionPane()
 63	{
 64		super("sessions");
 65	}
 66
 67
 68	public void _init()
 69	{
 70		bAutoSave = new JCheckBox(
 71			jEdit.getProperty("options.sessions.switcher.autoSave"),
 72			jEdit.getBooleanProperty("sessions.switcher.autoSave", true)
 73		);
 74		bAutoSave.addActionListener(this);
 75		
 76		boolean askSave = jEdit.getBooleanProperty("sessions.switcher.askSave", false);
 77		bAskSave = new JCheckBox(jEdit.getProperty("options.sessions.switcher.askSave"), askSave);
 78		bAskSave.setEnabled(bAutoSave.isSelected());
 79		
 80		bCloseAll = new JCheckBox(
 81			jEdit.getProperty("options.sessions.switcher.closeAll"),
 82			jEdit.getBooleanProperty("sessions.switcher.closeAll", true)
 83		);
 84
 85		bShowToolBar = new JCheckBox(
 86			jEdit.getProperty("options.sessions.switcher.showToolBar"),
 87			jEdit.getBooleanProperty("sessions.switcher.showToolBar", false)
 88		);
 89		bShowToolBar.addActionListener(this);
 90
 91		boolean showJEditToolBar = jEdit.getBooleanProperty("sessions.switcher.showJEditToolBar", false);
 92		boolean showInsideBufferList = jEdit.getBooleanProperty("sessions.switcher.showInsideBufferList", false);
 93		boolean showBelowToolBar = !(showJEditToolBar || showInsideBufferList);
 94
 95		bShowJEditToolBar = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showJEditToolBar"), showJEditToolBar);
 96		bShowJEditToolBar.setEnabled(bShowToolBar.isSelected());
 97
 98		bShowInsideBufferList = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showInsideBufferList"), showInsideBufferList);
 99		bShowInsideBufferList.setEnabled(bShowToolBar.isSelected() && isBufferListAvailable());
100
101		bShowBelowToolBar = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showBelowToolBar"), showBelowToolBar);
102		bShowBelowToolBar.setEnabled(bShowToolBar.isSelected());
103
104		ButtonGroup group = new ButtonGroup();
105		group.add(bShowJEditToolBar);
106		group.add(bShowInsideBufferList);
107		group.add(bShowBelowToolBar);
108
109		bShowTitle = new JCheckBox(
110			jEdit.getProperty("options.sessions.switcher.showTitle"),
111			jEdit.getBooleanProperty("sessions.switcher.showTitle", true)
112		);
113		bShowTitle.setEnabled(bShowToolBar.isSelected());
114
115		bChangeFSBDirectory = new JCheckBox(
116			jEdit.getProperty("options.sessions.switcher.changeFSBDirectory"),
117			jEdit.getBooleanProperty("sessions.switcher.changeFSBDirectory", false)
118		);
119		
120		bShowSessionNameInTitleBar = new JCheckBox(
121			jEdit.getProperty("options.sessions.switcher.showSessionNameInTitleBar"),
122			jEdit.getBooleanProperty("sessions.switcher.showSessionNameInTitleBar", true)
123		);
124		bShowSessionNameInTitleBar.addActionListener(this);
125		
126		bShowSessionPrefixInTitleBar = new JCheckBox(
127			jEdit.getProperty("options.sessions.switcher.showSessionPrefixInTitleBar"),
128			jEdit.getBooleanProperty("sessions.switcher.showSessionPrefixInTitleBar", true)
129		);
130		
131		// Max list size for session switcher combo
132		Box maxSessListSizePanel = new Box(BoxLayout.X_AXIS);
133		maxSessListSizePanel.add(new JLabel(
134			jEdit.getProperty("options.sessions.switcher.maxListSize.label"))
135		);
136		Integer maxListSize = 
137			jEdit.getIntegerProperty("options.sessions.switcher.maxListSize", 8);
138		maxSessionListSizeModel = new SpinnerNumberModel(
139			maxListSize,
140			new Integer(5),
141			new Integer(50), 
142			new Integer(1)
143		);
144		maxSessionListSize = new JSpinner(maxSessionListSizeModel);
145		maxSessionListSize.setMaximumSize(maxSessionListSize.getPreferredSize());
146		maxSessListSizePanel.add(maxSessionListSize);
147		maxSessListSizePanel.add(maxSessListSizePanel.createHorizontalGlue());
148		
149		addComponent(bAutoSave);
150		addComponent("    ", bAskSave);
151		addComponent(bCloseAll);
152		addComponent(bShowToolBar);
153		addComponent("    ", bShowBelowToolBar);
154		addComponent("    ", bShowJEditToolBar);
155		addComponent("    ", bShowInsideBufferList);
156		addComponent("    ", bShowTitle);
157		addComponent("    ", maxSessListSizePanel);
158		addComponent(bChangeFSBDirectory);
159		addComponent(bShowSessionNameInTitleBar);
160		addComponent("    ", bShowSessionPrefixInTitleBar);
161	}
162
163
164	public void _save()
165	{
166		jEdit.setBooleanProperty("sessions.switcher.autoSave", bAutoSave.isSelected());
167		jEdit.setBooleanProperty("sessions.switcher.askSave", bAskSave.isSelected());
168		jEdit.setBooleanProperty("sessions.switcher.closeAll", bCloseAll.isSelected());
169		jEdit.setBooleanProperty("sessions.switcher.showToolBar", bShowToolBar.isSelected());
170		jEdit.setBooleanProperty("sessions.switcher.showJEditToolBar", bShowJEditToolBar.isSelected());
171		jEdit.setBooleanProperty("sessions.switcher.showInsideBufferList", bShowInsideBufferList.isSelected());
172		jEdit.setBooleanProperty("sessions.switcher.showTitle", bShowTitle.isSelected());
173		jEdit.setBooleanProperty("sessions.switcher.changeFSBDirectory", bChangeFSBDirectory.isSelected());
174		jEdit.setBooleanProperty("sessions.switcher.showSessionNameInTitleBar", bShowSessionNameInTitleBar.isSelected());
175		jEdit.setBooleanProperty("sessions.switcher.showSessionPrefixInTitleBar", bShowSessionPrefixInTitleBar.isSelected());
176		jEdit.setIntegerProperty("options.sessions.switcher.maxListSize", (Integer)maxSessionListSizeModel.getNumber());
177	}
178
179
180	public void actionPerformed(ActionEvent e)
181	{
182		
183		if (e.getSource() == bShowToolBar)
184		{
185			bShowBelowToolBar.setEnabled(bShowToolBar.isSelected());
186			bShowJEditToolBar.setEnabled(bShowToolBar.isSelected());
187			bShowInsideBufferList.setEnabled(bShowToolBar.isSelected() && isBufferListAvailable());
188			bShowTitle.setEnabled(bShowToolBar.isSelected());
189			
190			bShowSessionPrefixInTitleBar.setEnabled(bShowSessionNameInTitleBar.isSelected());
191		}
192		else if (e.getSource() == bAutoSave)
193		{
194			bAskSave.setEnabled(bAutoSave.isSelected());
195			bAskSave.setSelected(false);
196		}
197		
198	}
199
200
201	private boolean isBufferListAvailable()
202	{
203		// FIXME: is it sufficient to check only first view?!?
204		return SessionsPlugin.isBufferListAvailable(jEdit.getFirstView());
205	}
206}