KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * BufferOptionPane.java -
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1998, 2003 Slava Pestov
7  * Portions copyright (C) 1999 mike dillon
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 package org.gjt.sp.jedit.options;
25
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 import javax.swing.JCheckBox JavaDoc;
31 import javax.swing.JComboBox JavaDoc;
32
33 import org.gjt.sp.jedit.AbstractOptionPane;
34 import org.gjt.sp.jedit.Buffer;
35 import org.gjt.sp.jedit.GUIUtilities;
36 import org.gjt.sp.jedit.MiscUtilities;
37 import org.gjt.sp.jedit.Mode;
38 import org.gjt.sp.jedit.jEdit;
39 import org.gjt.sp.jedit.buffer.FoldHandler;
40 import org.gjt.sp.jedit.buffer.JEditBuffer;
41
42 /**
43  * @version $Id: MiscUtilities.java 7183 2006-10-07 04:46:25Z ezust $
44  */

45 public class BufferOptionPane extends AbstractOptionPane
46 {
47     JComboBox JavaDoc encoding;
48     JComboBox JavaDoc lineSeparator;
49     JCheckBox JavaDoc gzipped;
50     Mode[] modes;
51     JComboBox JavaDoc mode;
52     JComboBox JavaDoc folding;
53     JComboBox JavaDoc wrap;
54     JComboBox JavaDoc maxLineLen;
55     JComboBox JavaDoc tabSize;
56     JComboBox JavaDoc indentSize;
57     JComboBox JavaDoc checkModStatus;
58     JCheckBox JavaDoc noTabs;
59     Buffer buffer;
60     
61     
62     public BufferOptionPane()
63     {
64         super("Buffer Options");
65         init();
66     }
67     
68     protected void _init()
69     {
70         
71         
72         buffer = jEdit.getActiveView().getBuffer();
73         String JavaDoc filename = buffer.getName();
74         setName("Buffer: " + filename);
75         addComponent(GUIUtilities.createMultilineLabel(
76             jEdit.getProperty("buffer-options.caption")));
77
78         addSeparator("buffer-options.loading-saving");
79
80         //{{{ Line separator
81
String JavaDoc[] lineSeps = { jEdit.getProperty("lineSep.unix"),
82             jEdit.getProperty("lineSep.windows"),
83             jEdit.getProperty("lineSep.mac") };
84         lineSeparator = new JComboBox JavaDoc(lineSeps);
85         String JavaDoc lineSep = buffer.getStringProperty(JEditBuffer.LINESEP);
86         if(lineSep == null)
87             lineSep = System.getProperty("line.separator");
88         if("\n".equals(lineSep))
89             lineSeparator.setSelectedIndex(0);
90         else if("\r\n".equals(lineSep))
91             lineSeparator.setSelectedIndex(1);
92         else if("\r".equals(lineSep))
93             lineSeparator.setSelectedIndex(2);
94         addComponent(jEdit.getProperty("buffer-options.lineSeparator"),
95             lineSeparator);
96         //}}}
97

98         //{{{ Encoding
99
String JavaDoc[] encodings = MiscUtilities.getEncodings(true);
100         Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
101         encoding = new JComboBox JavaDoc(encodings);
102         encoding.setEditable(true);
103         encoding.setSelectedItem(buffer.getStringProperty(JEditBuffer.ENCODING));
104         addComponent(jEdit.getProperty("buffer-options.encoding"),
105             encoding);
106         //}}}
107

108         //{{{ GZipped setting
109
gzipped = new JCheckBox JavaDoc(jEdit.getProperty(
110             "buffer-options.gzipped"));
111         gzipped.setSelected(buffer.getBooleanProperty(Buffer.GZIPPED));
112         addComponent(gzipped);
113         //}}}
114

115         //{{{ Autoreload settings
116
/* Check mod status on focus */
117         String JavaDoc[] modCheckOptions = {
118             jEdit.getProperty("options.general.checkModStatus.nothing"),
119             jEdit.getProperty("options.general.checkModStatus.prompt"),
120             jEdit.getProperty("options.general.checkModStatus.reload"),
121             jEdit.getProperty("options.general.checkModStatus.silentReload")
122         };
123         checkModStatus = new JComboBox JavaDoc(modCheckOptions);
124         if(buffer.getAutoReload()) {
125             if(buffer.getAutoReloadDialog())
126                 // reload and notify
127
checkModStatus.setSelectedIndex(2);
128             else // reload silently
129
checkModStatus.setSelectedIndex(3);
130             }
131         else {
132             if(buffer.getAutoReloadDialog())
133                 // prompt
134
checkModStatus.setSelectedIndex(1);
135             else // do nothing
136
checkModStatus.setSelectedIndex(0);
137             }
138         addComponent(jEdit.getProperty("options.general.checkModStatus"),
139             checkModStatus);
140
141         // }}}
142

143         addSeparator("buffer-options.editing");
144
145         //{{{ Edit mode
146
modes = jEdit.getModes();
147         Arrays.sort(modes,new MiscUtilities.StringICaseCompare());
148         mode = new JComboBox JavaDoc(modes);
149         mode.setSelectedItem(buffer.getMode());
150         ActionHandler actionListener = new ActionHandler();
151         mode.addActionListener(actionListener);
152         addComponent(jEdit.getProperty("buffer-options.mode"),mode);
153         //}}}
154

155         //{{{ Fold mode
156
String JavaDoc[] foldModes = FoldHandler.getFoldModes();
157
158         folding = new JComboBox JavaDoc(foldModes);
159         folding.setSelectedItem(buffer.getStringProperty("folding"));
160         addComponent(jEdit.getProperty("options.editing.folding"),
161             folding);
162         //}}}
163

164         //{{{ Wrap mode
165
String JavaDoc[] wrapModes = {
166             "none",
167             "soft",
168             "hard"
169         };
170
171         wrap = new JComboBox JavaDoc(wrapModes);
172         wrap.setSelectedItem(buffer.getStringProperty("wrap"));
173         addComponent(jEdit.getProperty("options.editing.wrap"),
174             wrap);
175         //}}}
176

177         //{{{ Max line length
178
String JavaDoc[] lineLengths = { "0", "72", "76", "80" };
179
180         maxLineLen = new JComboBox JavaDoc(lineLengths);
181         maxLineLen.setEditable(true);
182         maxLineLen.setSelectedItem(buffer.getStringProperty("maxLineLen"));
183         addComponent(jEdit.getProperty("options.editing.maxLineLen"),
184             maxLineLen);
185         //}}}
186

187         //{{{ Tab size
188
String JavaDoc[] tabSizes = { "2", "4", "8" };
189         tabSize = new JComboBox JavaDoc(tabSizes);
190         tabSize.setEditable(true);
191         tabSize.setSelectedItem(buffer.getStringProperty("tabSize"));
192         addComponent(jEdit.getProperty("options.editing.tabSize"),tabSize);
193         //}}}
194

195         //{{{ Indent size
196
indentSize = new JComboBox JavaDoc(tabSizes);
197         indentSize.setEditable(true);
198         indentSize.setSelectedItem(buffer.getStringProperty("indentSize"));
199         addComponent(jEdit.getProperty("options.editing.indentSize"),
200             indentSize);
201         //}}}
202

203         //{{{ Soft tabs
204
noTabs = new JCheckBox JavaDoc(jEdit.getProperty(
205             "options.editing.noTabs"));
206         noTabs.setSelected(buffer.getBooleanProperty("noTabs"));
207         addComponent(noTabs);
208
209     }
210     
211
212     protected void _save()
213     {
214         int index = lineSeparator.getSelectedIndex();
215         String JavaDoc lineSep;
216         if(index == 0)
217             lineSep = "\n";
218         else if(index == 1)
219             lineSep = "\r\n";
220         else if(index == 2)
221             lineSep = "\r";
222         else
223             throw new InternalError JavaDoc();
224
225         String JavaDoc oldLineSep = buffer.getStringProperty(JEditBuffer.LINESEP);
226         if(oldLineSep == null)
227             oldLineSep = System.getProperty("line.separator");
228         if(!oldLineSep.equals(lineSep))
229         {
230             buffer.setStringProperty("lineSeparator",lineSep);
231             buffer.setDirty(true);
232         }
233
234         String JavaDoc encoding = (String JavaDoc)this.encoding.getSelectedItem();
235         String JavaDoc oldEncoding = buffer.getStringProperty(JEditBuffer.ENCODING);
236         if(!oldEncoding.equals(encoding))
237         {
238             buffer.setStringProperty(JEditBuffer.ENCODING,encoding);
239             buffer.setDirty(true);
240         }
241
242         boolean gzippedValue = gzipped.isSelected();
243         boolean oldGzipped = buffer.getBooleanProperty(
244             Buffer.GZIPPED);
245         if(gzippedValue != oldGzipped)
246         {
247             buffer.setBooleanProperty(Buffer.GZIPPED,gzippedValue);
248             buffer.setDirty(true);
249         }
250
251         buffer.setStringProperty("folding",(String JavaDoc)folding.getSelectedItem());
252
253         buffer.setStringProperty("wrap",(String JavaDoc)wrap.getSelectedItem());
254
255         try
256         {
257             buffer.setProperty("maxLineLen",new Integer JavaDoc(
258                 maxLineLen.getSelectedItem().toString()));
259         }
260         catch(NumberFormatException JavaDoc nf)
261         {
262         }
263
264         try
265         {
266             buffer.setProperty("tabSize",new Integer JavaDoc(
267                 tabSize.getSelectedItem().toString()));
268         }
269         catch(NumberFormatException JavaDoc nf)
270         {
271         }
272
273         try
274         {
275             buffer.setProperty("indentSize",new Integer JavaDoc(
276                 indentSize.getSelectedItem().toString()));
277         }
278         catch(NumberFormatException JavaDoc nf)
279         {
280         }
281
282         buffer.setBooleanProperty("noTabs",noTabs.isSelected());
283
284         index = mode.getSelectedIndex();
285         buffer.setMode(modes[index]);
286         switch(checkModStatus.getSelectedIndex())
287         {
288         case 0:
289             buffer.setAutoReloadDialog(false);
290             buffer.setAutoReload(false);
291             break;
292         case 1:
293             buffer.setAutoReloadDialog(true);
294             buffer.setAutoReload(false);
295             break;
296         case 2:
297             buffer.setAutoReloadDialog(true);
298             buffer.setAutoReload(true);
299             break;
300         case 3:
301             buffer.setAutoReloadDialog(false);
302             buffer.setAutoReload(true);
303             break;
304         }
305     }
306
307     
308     class ActionHandler implements ActionListener JavaDoc
309     {
310         //{{{ actionPerformed() method
311
public void actionPerformed(ActionEvent JavaDoc evt)
312         {
313             Object JavaDoc source = evt.getSource();
314             if(source == mode)
315             {
316                 Mode _mode = (Mode)mode.getSelectedItem();
317                 folding.setSelectedItem(_mode.getProperty(
318                     "folding"));
319                 wrap.setSelectedItem(_mode.getProperty(
320                     "wrap"));
321                 maxLineLen.setSelectedItem(_mode.getProperty(
322                     "maxLineLen"));
323                 tabSize.setSelectedItem(_mode.getProperty(
324                     "tabSize"));
325                 indentSize.setSelectedItem(_mode.getProperty(
326                     "indentSize"));
327                 noTabs.setSelected(_mode.getBooleanProperty(
328                     "noTabs"));
329             }
330         } //}}}
331
} //}}}
332

333 }
334
Popular Tags