PageRenderTime 120ms CodeModel.GetById 109ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/options/GeneralOptionPane.java

#
Java | 245 lines | 181 code | 22 blank | 42 comment | 8 complexity | b8103d0be2db741c95c7e82ca848e1c3 MD5 | raw file
  1/*
  2 * GeneralOptionPane.java - General options panel
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 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.*;
 27import java.awt.event.*;
 28import java.util.Arrays;
 29import org.gjt.sp.jedit.*;
 30//}}}
 31
 32public class GeneralOptionPane extends AbstractOptionPane
 33{
 34	//{{{ GeneralOptionPane constructor
 35	public GeneralOptionPane()
 36	{
 37		super("general");
 38	} //}}}
 39
 40	//{{{ _init() method
 41	protected void _init()
 42	{
 43		/* Line separator */
 44		String[] lineSeps = { jEdit.getProperty("lineSep.unix"),
 45			jEdit.getProperty("lineSep.windows"),
 46			jEdit.getProperty("lineSep.mac") };
 47		lineSeparator = new JComboBox(lineSeps);
 48		String lineSep = jEdit.getProperty("buffer.lineSeparator",
 49			System.getProperty("line.separator"));
 50		if("\n".equals(lineSep))
 51			lineSeparator.setSelectedIndex(0);
 52		else if("\r\n".equals(lineSep))
 53			lineSeparator.setSelectedIndex(1);
 54		else if("\r".equals(lineSep))
 55			lineSeparator.setSelectedIndex(2);
 56		addComponent(jEdit.getProperty("options.general.lineSeparator"),
 57			lineSeparator);
 58
 59		/* Default file encoding */
 60		String[] encodings = MiscUtilities.getEncodings();
 61		Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
 62		encoding = new JComboBox(encodings);
 63		encoding.setEditable(true);
 64		encoding.setSelectedItem(jEdit.getProperty("buffer.encoding",
 65			System.getProperty("file.encoding")));
 66		addComponent(jEdit.getProperty("options.general.encoding"),encoding);
 67
 68		/* Auto detect encoding */
 69		encodingAutodetect = new JCheckBox(jEdit.getProperty(
 70			"options.general.encodingAutodetect"));
 71		encodingAutodetect.setSelected(jEdit.getBooleanProperty("buffer.encodingAutodetect"));
 72		addComponent(encodingAutodetect);
 73
 74		/* Check mod status on focus */
 75		String[] modCheckOptions = {
 76			jEdit.getProperty("options.general.checkModStatus.nothing"),
 77			jEdit.getProperty("options.general.checkModStatus.prompt"),
 78			jEdit.getProperty("options.general.checkModStatus.reload")
 79		};
 80		checkModStatus = new JComboBox(modCheckOptions);
 81		if(jEdit.getBooleanProperty("autoReload"))
 82			checkModStatus.setSelectedIndex(2);
 83		else if(jEdit.getBooleanProperty("autoReloadDialog"))
 84			checkModStatus.setSelectedIndex(1);
 85		else
 86			checkModStatus.setSelectedIndex(0);
 87		addComponent(jEdit.getProperty("options.general.checkModStatus"),
 88			checkModStatus);
 89
 90		/* Recent file list size */
 91		recentFiles = new JTextField(jEdit.getProperty(
 92			"options.general.recentFiles"));
 93		recentFiles.setText(jEdit.getProperty("recentFiles"));
 94		addComponent(jEdit.getProperty("options.general.recentFiles"),
 95			recentFiles);
 96
 97		/* Sort recent file list */
 98		sortRecent = new JCheckBox(jEdit.getProperty(
 99			"options.general.sortRecent"));
100		sortRecent.setSelected(jEdit.getBooleanProperty("sortRecent"));
101		addComponent(sortRecent);
102
103		/* Save caret positions */
104		saveCaret = new JCheckBox(jEdit.getProperty(
105			"options.general.saveCaret"));
106		saveCaret.setSelected(jEdit.getBooleanProperty("saveCaret"));
107		addComponent(saveCaret);
108
109		/* Persistent markers */
110		persistentMarkers = new JCheckBox(jEdit.getProperty(
111			"options.general.persistentMarkers"));
112		persistentMarkers.setSelected(jEdit.getBooleanProperty(
113			"persistentMarkers"));
114		addComponent(persistentMarkers);
115
116		/* Session management */
117		restore = new JCheckBox(jEdit.getProperty(
118			"options.general.restore"));
119		restore.setSelected(jEdit.getBooleanProperty("restore"));
120		restore.addActionListener(new ActionListener()
121		{
122			public void actionPerformed(ActionEvent evt)
123			{
124				restoreCLI.setEnabled(restore.isSelected());
125			}
126		});
127
128		addComponent(restore);
129		restoreCLI = new JCheckBox(jEdit.getProperty(
130			"options.general.restore.cli"));
131		restoreCLI.setSelected(jEdit.getBooleanProperty("restore.cli"));
132		restoreCLI.setEnabled(restore.isSelected());
133		addComponent(restoreCLI);
134
135		/* Sort buffers */
136		sortBuffers = new JCheckBox(jEdit.getProperty(
137			"options.general.sortBuffers"));
138		sortBuffers.setSelected(jEdit.getBooleanProperty("sortBuffers"));
139		sortBuffers.addActionListener(new ActionListener()
140		{
141			public void actionPerformed(ActionEvent evt)
142			{
143				sortByName.setEnabled(sortBuffers.isSelected());
144			}
145		});
146
147		addComponent(sortBuffers);
148
149		/* Sort buffers by names */
150		sortByName = new JCheckBox(jEdit.getProperty(
151			"options.general.sortByName"));
152		sortByName.setSelected(jEdit.getBooleanProperty("sortByName"));
153		sortByName.setEnabled(sortBuffers.isSelected());
154		addComponent(sortByName);
155
156		/* Two-stage save */
157		twoStageSave = new JCheckBox(jEdit.getProperty(
158			"options.general.twoStageSave"));
159		twoStageSave.setSelected(jEdit.getBooleanProperty(
160			"twoStageSave"));
161		addComponent(twoStageSave);
162
163		/* Confirm save all */
164		confirmSaveAll = new JCheckBox(jEdit.getProperty(
165			"options.general.confirmSaveAll"));
166		confirmSaveAll.setSelected(jEdit.getBooleanProperty(
167			"confirmSaveAll"));
168		addComponent(confirmSaveAll);
169
170		/* Strip trailing EOL */
171		stripTrailingEOL = new JCheckBox(jEdit.getProperty(
172			"options.general.stripTrailingEOL"));
173		stripTrailingEOL.setSelected(jEdit.getBooleanProperty("stripTrailingEOL"));
174		addComponent(stripTrailingEOL);
175
176	} //}}}
177
178	//{{{ _save() method
179	protected void _save()
180	{
181		String lineSep = null;
182		switch(lineSeparator.getSelectedIndex())
183		{
184		case 0:
185			lineSep = "\n";
186			break;
187		case 1:
188			lineSep = "\r\n";
189			break;
190		case 2:
191			lineSep = "\r";
192			break;
193		}
194		jEdit.setProperty("buffer.lineSeparator",lineSep);
195		jEdit.setProperty("buffer.encoding",(String)
196			encoding.getSelectedItem());
197		jEdit.setBooleanProperty("buffer.encodingAutodetect",
198			encodingAutodetect.isSelected());
199		switch(checkModStatus.getSelectedIndex())
200		{
201		case 0:
202			jEdit.setBooleanProperty("autoReloadDialog",false);
203			jEdit.setBooleanProperty("autoReload",false);
204			break;
205		case 1:
206			jEdit.setBooleanProperty("autoReloadDialog",true);
207			jEdit.setBooleanProperty("autoReload",false);
208			break;
209		case 2:
210			jEdit.setBooleanProperty("autoReloadDialog",true);
211			jEdit.setBooleanProperty("autoReload",true);
212			break;
213		}
214		jEdit.setProperty("recentFiles",recentFiles.getText());
215		jEdit.setBooleanProperty("sortRecent",sortRecent.isSelected());
216		jEdit.setBooleanProperty("saveCaret",saveCaret.isSelected());
217		jEdit.setBooleanProperty("persistentMarkers",
218			persistentMarkers.isSelected());
219		jEdit.setBooleanProperty("restore",restore.isSelected());
220		jEdit.setBooleanProperty("restore.cli",restoreCLI.isSelected());
221		jEdit.setBooleanProperty("sortBuffers",sortBuffers.isSelected());
222		jEdit.setBooleanProperty("sortByName",sortByName.isSelected());
223		jEdit.setBooleanProperty("twoStageSave",twoStageSave.isSelected());
224		jEdit.setBooleanProperty("confirmSaveAll",confirmSaveAll.isSelected());
225		jEdit.setBooleanProperty("stripTrailingEOL", stripTrailingEOL.isSelected());
226	} //}}}
227
228	//{{{ Private members
229	private JComboBox lineSeparator;
230	private JComboBox encoding;
231	private JCheckBox encodingAutodetect;
232	private JComboBox checkModStatus;
233	private JTextField recentFiles;
234	private JCheckBox saveCaret;
235	private JCheckBox sortRecent;
236	private JCheckBox persistentMarkers;
237	private JCheckBox restore;
238	private JCheckBox restoreCLI;
239	private JCheckBox sortBuffers;
240	private JCheckBox sortByName;
241	private JCheckBox twoStageSave;
242	private JCheckBox confirmSaveAll;
243	private JCheckBox stripTrailingEOL;
244	//}}}
245}