KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > options > GeneralOptionPane


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
23 package org.gjt.sp.jedit.options;
24
25 //{{{ Imports
26
import javax.swing.*;
27 import java.awt.event.*;
28 import java.util.Arrays JavaDoc;
29 import org.gjt.sp.jedit.*;
30 //}}}
31

32
33
34 public class GeneralOptionPane extends AbstractOptionPane
35 {
36     //{{{ GeneralOptionPane constructor
37
public GeneralOptionPane()
38     {
39         super("general");
40     } //}}}
41

42     //{{{ _init() method
43
protected void _init()
44     {
45         
46         /* Line separator */
47         String JavaDoc[] lineSeps = { jEdit.getProperty("lineSep.unix"),
48             jEdit.getProperty("lineSep.windows"),
49             jEdit.getProperty("lineSep.mac") };
50         lineSeparator = new JComboBox(lineSeps);
51         String JavaDoc lineSep = jEdit.getProperty("buffer.lineSeparator",
52             System.getProperty("line.separator"));
53         if("\n".equals(lineSep))
54             lineSeparator.setSelectedIndex(0);
55         else if("\r\n".equals(lineSep))
56             lineSeparator.setSelectedIndex(1);
57         else if("\r".equals(lineSep))
58             lineSeparator.setSelectedIndex(2);
59         addComponent(jEdit.getProperty("options.general.lineSeparator"),
60             lineSeparator);
61
62         /* Default file encoding */
63         String JavaDoc[] encodings = MiscUtilities.getEncodings(true);
64         Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
65         encoding = new JComboBox(encodings);
66         encoding.setEditable(true);
67         encoding.setSelectedItem(jEdit.getProperty("buffer.encoding",
68             System.getProperty("file.encoding")));
69         addComponent(jEdit.getProperty("options.general.encoding"),encoding);
70
71         /* Auto detect encoding */
72         encodingAutodetect = new JCheckBox(jEdit.getProperty(
73             "options.general.encodingAutodetect"));
74         encodingAutodetect.setSelected(jEdit.getBooleanProperty("buffer.encodingAutodetect"));
75         addComponent(encodingAutodetect);
76
77         /* Check mod status on focus */
78         String JavaDoc[] modCheckOptions = {
79             jEdit.getProperty("options.general.checkModStatus.nothing"),
80             jEdit.getProperty("options.general.checkModStatus.prompt"),
81             jEdit.getProperty("options.general.checkModStatus.reload"),
82             jEdit.getProperty("options.general.checkModStatus.silentreload")
83         };
84         checkModStatus = new JComboBox(modCheckOptions);
85         if(jEdit.getBooleanProperty("autoReload")) {
86             if(jEdit.getBooleanProperty("autoReloadDialog"))
87                 // reload and notify
88
checkModStatus.setSelectedIndex(2);
89             else // reload silently
90
checkModStatus.setSelectedIndex(3);
91             }
92         else {
93             if(jEdit.getBooleanProperty("autoReloadDialog"))
94                 // prompt
95
checkModStatus.setSelectedIndex(1);
96             else // do nothing
97
checkModStatus.setSelectedIndex(0);
98             }
99         addComponent(jEdit.getProperty("options.general.checkModStatus"),
100             checkModStatus);
101
102         /* Recent file list size */
103         recentFiles = new JTextField(jEdit.getProperty(
104             "options.general.recentFiles"));
105         recentFiles.setText(jEdit.getProperty("recentFiles"));
106         addComponent(jEdit.getProperty("options.general.recentFiles"),
107             recentFiles);
108
109         /* Sort recent file list */
110         sortRecent = new JCheckBox(jEdit.getProperty(
111             "options.general.sortRecent"));
112         sortRecent.setSelected(jEdit.getBooleanProperty("sortRecent"));
113         addComponent(sortRecent);
114
115         /* Save caret positions */
116         saveCaret = new JCheckBox(jEdit.getProperty(
117             "options.general.saveCaret"));
118         saveCaret.setSelected(jEdit.getBooleanProperty("saveCaret"));
119         addComponent(saveCaret);
120
121         /* Persistent markers */
122         persistentMarkers = new JCheckBox(jEdit.getProperty(
123             "options.general.persistentMarkers"));
124         persistentMarkers.setSelected(jEdit.getBooleanProperty(
125             "persistentMarkers"));
126         addComponent(persistentMarkers);
127
128         /* Session management */
129         restore = new JCheckBox(jEdit.getProperty(
130             "options.general.restore"));
131         restore.setSelected(jEdit.getBooleanProperty("restore"));
132         restore.addActionListener(new ActionListener()
133         {
134             public void actionPerformed(ActionEvent evt)
135             {
136                 restoreCLI.setEnabled(restore.isSelected());
137             }
138         });
139
140         addComponent(restore);
141         restoreCLI = new JCheckBox(jEdit.getProperty(
142             "options.general.restore.cli"));
143         restoreCLI.setSelected(jEdit.getBooleanProperty("restore.cli"));
144         restoreCLI.setEnabled(restore.isSelected());
145         addComponent(restoreCLI);
146
147         /* Sort buffers */
148         sortBuffers = new JCheckBox(jEdit.getProperty(
149             "options.general.sortBuffers"));
150         sortBuffers.setSelected(jEdit.getBooleanProperty("sortBuffers"));
151         sortBuffers.addActionListener(new ActionListener()
152         {
153             public void actionPerformed(ActionEvent evt)
154             {
155                 sortByName.setEnabled(sortBuffers.isSelected());
156             }
157         });
158
159         addComponent(sortBuffers);
160
161         /* Sort buffers by names */
162         sortByName = new JCheckBox(jEdit.getProperty(
163             "options.general.sortByName"));
164         sortByName.setSelected(jEdit.getBooleanProperty("sortByName"));
165         sortByName.setEnabled(sortBuffers.isSelected());
166         addComponent(sortByName);
167         
168         newKeyboardHandling = new JCheckBox(jEdit.getProperty("options.general.newkeyhandling"));
169         newKeyboardHandling.setSelected(jEdit.getBooleanProperty("newkeyhandling"));
170         addComponent(newKeyboardHandling);
171         
172
173     } //}}}
174

175     //{{{ _save() method
176
protected void _save()
177     {
178         
179         String JavaDoc lineSep = null;
180         switch(lineSeparator.getSelectedIndex())
181         {
182         case 0:
183             lineSep = "\n";
184             break;
185         case 1:
186             lineSep = "\r\n";
187             break;
188         case 2:
189             lineSep = "\r";
190             break;
191         }
192         jEdit.setProperty("buffer.lineSeparator",lineSep);
193         jEdit.setProperty("buffer.encoding",(String JavaDoc)
194             encoding.getSelectedItem());
195         jEdit.setBooleanProperty("buffer.encodingAutodetect",
196             encodingAutodetect.isSelected());
197         switch(checkModStatus.getSelectedIndex())
198         {
199         case 0:
200             jEdit.setBooleanProperty("autoReloadDialog",false);
201             jEdit.setBooleanProperty("autoReload",false);
202             break;
203         case 1:
204             jEdit.setBooleanProperty("autoReloadDialog",true);
205             jEdit.setBooleanProperty("autoReload",false);
206             break;
207         case 2:
208             jEdit.setBooleanProperty("autoReloadDialog",true);
209             jEdit.setBooleanProperty("autoReload",true);
210             break;
211         case 3:
212             jEdit.setBooleanProperty("autoReloadDialog",false);
213             jEdit.setBooleanProperty("autoReload",true);
214             break;
215         }
216         jEdit.setProperty("recentFiles",recentFiles.getText());
217         jEdit.setBooleanProperty("sortRecent",sortRecent.isSelected());
218         boolean nkh = newKeyboardHandling.isSelected();
219         jEdit.setBooleanProperty("newkeyhandling", nkh);
220         Options.SIMPLIFIED_KEY_HANDLING = nkh;
221         jEdit.setBooleanProperty("saveCaret",saveCaret.isSelected());
222         jEdit.setBooleanProperty("persistentMarkers",
223             persistentMarkers.isSelected());
224         jEdit.setBooleanProperty("restore",restore.isSelected());
225         jEdit.setBooleanProperty("restore.cli",restoreCLI.isSelected());
226         jEdit.setBooleanProperty("sortBuffers",sortBuffers.isSelected());
227         jEdit.setBooleanProperty("sortByName",sortByName.isSelected());
228     } //}}}
229

230     //{{{ Private members
231
private JComboBox lineSeparator;
232     private JComboBox encoding;
233     private JCheckBox encodingAutodetect;
234     private JComboBox checkModStatus;
235     private JTextField recentFiles;
236     private JCheckBox saveCaret;
237     private JCheckBox sortRecent;
238     private JCheckBox persistentMarkers;
239     private JCheckBox restore;
240     private JCheckBox restoreCLI;
241     private JCheckBox sortBuffers;
242     private JCheckBox sortByName;
243     private JCheckBox newKeyboardHandling;
244     //}}}
245
}
246
Popular Tags