001: /*
002: * GeneralOptionPane.java - General options panel
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 1998, 2003 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.options;
024:
025: //{{{ Imports
026:
027: import org.gjt.sp.jedit.AbstractOptionPane;
028: import org.gjt.sp.jedit.Buffer;
029: import org.gjt.sp.jedit.Options;
030: import org.gjt.sp.jedit.jEdit;
031: import org.gjt.sp.util.Log;
032:
033: import javax.swing.*;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: //}}}
038:
039: /**
040: * jEdit's General Options Pane
041: */
042:
043: public class GeneralOptionPane extends AbstractOptionPane {
044: //{{{ Private members
045: private JComboBox lineSeparator;
046: private JComboBox checkModStatus;
047: private JComboBox checkModStatusUpon;
048: private JTextField recentFiles;
049: private JTextField hypersearchResultsWarning;
050: private JCheckBox saveCaret;
051: private JCheckBox sortRecent;
052: private JCheckBox persistentMarkers;
053: private JCheckBox restore;
054: private JCheckBox restoreRemote;
055: private JCheckBox restoreCLI;
056: private JCheckBox sortBuffers;
057: private JCheckBox sortByName;
058: private JCheckBox newKeyboardHandling;
059:
060: //}}}
061:
062: //{{{ GeneralOptionPane constructor
063: public GeneralOptionPane() {
064: super ("general");
065: } //}}}
066:
067: //{{{ _init() method
068: protected void _init() {
069:
070: /* Line separator */
071: String[] lineSeps = { jEdit.getProperty("lineSep.unix"),
072: jEdit.getProperty("lineSep.windows"),
073: jEdit.getProperty("lineSep.mac") };
074: lineSeparator = new JComboBox(lineSeps);
075: String lineSep = jEdit.getProperty("buffer." + Buffer.LINESEP,
076: System.getProperty("line.separator"));
077: if ("\n".equals(lineSep))
078: lineSeparator.setSelectedIndex(0);
079: else if ("\r\n".equals(lineSep))
080: lineSeparator.setSelectedIndex(1);
081: else if ("\r".equals(lineSep))
082: lineSeparator.setSelectedIndex(2);
083: addComponent(
084: jEdit.getProperty("options.general.lineSeparator"),
085: lineSeparator);
086:
087: /* Check mod status */
088: String[] modCheckOptions = {
089: jEdit
090: .getProperty("options.general.checkModStatus.nothing"),
091: jEdit
092: .getProperty("options.general.checkModStatus.prompt"),
093: jEdit
094: .getProperty("options.general.checkModStatus.reload"),
095: jEdit
096: .getProperty("options.general.checkModStatus.silentReload") };
097: checkModStatus = new JComboBox(modCheckOptions);
098: if (jEdit.getBooleanProperty("autoReload")) {
099: if (jEdit.getBooleanProperty("autoReloadDialog"))
100: // reload and notify
101: checkModStatus.setSelectedIndex(2);
102: else
103: // reload silently
104: checkModStatus.setSelectedIndex(3);
105: } else {
106: if (jEdit.getBooleanProperty("autoReloadDialog"))
107: // prompt
108: checkModStatus.setSelectedIndex(1);
109: else
110: // do nothing
111: checkModStatus.setSelectedIndex(0);
112: }
113: addComponent(jEdit
114: .getProperty("options.general.checkModStatus"),
115: checkModStatus);
116:
117: /* Check mod status upon */
118: String[] modCheckUponOptions = {
119: jEdit
120: .getProperty("options.general.checkModStatusUpon.focus"),
121: jEdit
122: .getProperty("options.general.checkModStatusUpon.all"),
123: jEdit
124: .getProperty("options.general.checkModStatusUpon.operations"),
125: jEdit
126: .getProperty("options.general.checkModStatusUpon.focusBuffer"),
127: jEdit
128: .getProperty("options.general.checkModStatusUpon.none") };
129: checkModStatusUpon = new JComboBox(modCheckUponOptions);
130: checkModStatusUpon.setSelectedIndex(jEdit
131: .getIntegerProperty("checkFileStatus"));
132: addComponent(jEdit
133: .getProperty("options.general.checkModStatusUpon"),
134: checkModStatusUpon);
135:
136: /* Recent file list size */
137: recentFiles = new JTextField(jEdit
138: .getProperty("options.general.recentFiles"));
139: recentFiles.setText(jEdit.getProperty("recentFiles"));
140: addComponent(jEdit.getProperty("options.general.recentFiles"),
141: recentFiles);
142:
143: /* Sort recent file list */
144: sortRecent = new JCheckBox(jEdit
145: .getProperty("options.general.sortRecent"));
146: sortRecent.setSelected(jEdit.getBooleanProperty("sortRecent"));
147: addComponent(sortRecent);
148:
149: /* Save caret positions */
150: saveCaret = new JCheckBox(jEdit
151: .getProperty("options.general.saveCaret"));
152: saveCaret.setSelected(jEdit.getBooleanProperty("saveCaret"));
153: addComponent(saveCaret);
154:
155: /* Persistent markers */
156: persistentMarkers = new JCheckBox(jEdit
157: .getProperty("options.general.persistentMarkers"));
158: persistentMarkers.setSelected(jEdit
159: .getBooleanProperty("persistentMarkers"));
160: addComponent(persistentMarkers);
161:
162: /* Session management */
163: restore = new JCheckBox(jEdit
164: .getProperty("options.general.restore"));
165:
166: restore.setSelected(jEdit.getBooleanProperty("restore"));
167: restore.addActionListener(new ActionListener() {
168: public void actionPerformed(ActionEvent evt) {
169: restoreCLI.setEnabled(restore.isSelected());
170: restoreRemote.setEnabled(restore.isSelected());
171: }
172: });
173:
174: addComponent(restore);
175:
176: restoreRemote = new JCheckBox(jEdit
177: .getProperty("options.general.restore.remote"));
178: restoreRemote.setSelected(jEdit.getBooleanProperty(
179: "restore.remote", false));
180: restoreRemote.setEnabled(restore.isSelected());
181: addComponent(restoreRemote);
182:
183: restoreCLI = new JCheckBox(jEdit
184: .getProperty("options.general.restore.cli"));
185: restoreCLI.setSelected(jEdit.getBooleanProperty("restore.cli"));
186: restoreCLI.setEnabled(restore.isSelected());
187: addComponent(restoreCLI);
188:
189: /* Sort buffers */
190: sortBuffers = new JCheckBox(jEdit
191: .getProperty("options.general.sortBuffers"));
192: sortBuffers
193: .setSelected(jEdit.getBooleanProperty("sortBuffers"));
194: sortBuffers.addActionListener(new ActionListener() {
195: public void actionPerformed(ActionEvent evt) {
196: sortByName.setEnabled(sortBuffers.isSelected());
197: }
198: });
199:
200: addComponent(sortBuffers);
201:
202: /* Sort buffers by names */
203: sortByName = new JCheckBox(jEdit
204: .getProperty("options.general.sortByName"));
205: sortByName.setSelected(jEdit.getBooleanProperty("sortByName"));
206: sortByName.setEnabled(sortBuffers.isSelected());
207: addComponent(sortByName);
208:
209: newKeyboardHandling = new JCheckBox(jEdit
210: .getProperty("options.general.newkeyhandling"));
211: newKeyboardHandling.setToolTipText(jEdit
212: .getProperty("options.general.newkeyhandling.tooltip"));
213: newKeyboardHandling.setSelected(jEdit
214: .getBooleanProperty("newkeyhandling"));
215: addComponent(newKeyboardHandling);
216:
217: hypersearchResultsWarning = new JTextField(jEdit
218: .getProperty("hypersearch.maxWarningResults"));
219: addComponent(
220: jEdit
221: .getProperty("options.general.hypersearch.maxWarningResults"),
222: hypersearchResultsWarning);
223:
224: } //}}}
225:
226: //{{{ _save() method
227: protected void _save() {
228:
229: String lineSep = null;
230: switch (lineSeparator.getSelectedIndex()) {
231: case 0:
232: lineSep = "\n";
233: break;
234: case 1:
235: lineSep = "\r\n";
236: break;
237: case 2:
238: lineSep = "\r";
239: break;
240: }
241: jEdit.setProperty("buffer." + Buffer.LINESEP, lineSep);
242: switch (checkModStatus.getSelectedIndex()) {
243: case 0:
244: jEdit.setBooleanProperty("autoReloadDialog", false);
245: jEdit.setBooleanProperty("autoReload", false);
246: break;
247: case 1:
248: jEdit.setBooleanProperty("autoReloadDialog", true);
249: jEdit.setBooleanProperty("autoReload", false);
250: break;
251: case 2:
252: jEdit.setBooleanProperty("autoReloadDialog", true);
253: jEdit.setBooleanProperty("autoReload", true);
254: break;
255: case 3:
256: jEdit.setBooleanProperty("autoReloadDialog", false);
257: jEdit.setBooleanProperty("autoReload", true);
258: break;
259: }
260: jEdit.setIntegerProperty("checkFileStatus", checkModStatusUpon
261: .getSelectedIndex());
262: jEdit.setProperty("recentFiles", recentFiles.getText());
263: jEdit.setBooleanProperty("sortRecent", sortRecent.isSelected());
264: boolean nkh = newKeyboardHandling.isSelected();
265: jEdit.setBooleanProperty("newkeyhandling", nkh);
266: Options.SIMPLIFIED_KEY_HANDLING = nkh;
267: jEdit.setBooleanProperty("saveCaret", saveCaret.isSelected());
268: jEdit.setBooleanProperty("persistentMarkers", persistentMarkers
269: .isSelected());
270: jEdit.setBooleanProperty("restore", restore.isSelected());
271: jEdit
272: .setBooleanProperty("restore.cli", restoreCLI
273: .isSelected());
274: jEdit.setBooleanProperty("restore.remote", restoreRemote
275: .isSelected());
276: jEdit.setBooleanProperty("sortBuffers", sortBuffers
277: .isSelected());
278: jEdit.setBooleanProperty("sortByName", sortByName.isSelected());
279: try {
280: jEdit.setIntegerProperty("hypersearch.maxWarningResults",
281: Integer.parseInt(hypersearchResultsWarning
282: .getText()));
283: } catch (NumberFormatException e) {
284: Log.log(Log.WARNING, this , "hypersearchResultsWarning: "
285: + hypersearchResultsWarning.getText()
286: + " is not a valid value for this option");
287: }
288: } //}}}
289:
290: }
|