Source Code Cross Referenced for EditingOptionPane.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » options » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jEdit » org.gjt.sp.jedit.options 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EditingOptionPane.java - Mode-specific options panel
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1998, 2002 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:        import javax.swing.*;
027:
028:        import java.awt.event.*;
029:        import java.util.Arrays;
030:
031:        import org.gjt.sp.jedit.*;
032:        import org.gjt.sp.jedit.buffer.FoldHandler;
033:        import org.gjt.sp.util.StandardUtilities;
034:
035:        //}}}
036:
037:        /**
038:         * @version $Id: EditingOptionPane.java 9465 2007-04-24 16:35:38Z ezust $
039:         */
040:        public class EditingOptionPane extends AbstractOptionPane {
041:            //{{{ EditingOptionPane constructor
042:            public EditingOptionPane() {
043:                super ("editing");
044:            } //}}}
045:
046:            //{{{ _init() method
047:            protected void _init() {
048:                Mode[] modes = jEdit.getModes();
049:                Arrays.sort(modes, new MiscUtilities.StringICaseCompare());
050:
051:                global = new ModeProperties();
052:                modeProps = new ModeProperties[modes.length];
053:
054:                String[] modeNames = new String[modes.length + 1];
055:                modeNames[0] = jEdit.getProperty("options.editing.global");
056:
057:                for (int i = 0; i < modes.length; i++) {
058:                    modeProps[i] = new ModeProperties(modes[i]);
059:                    modeNames[i + 1] = modes[i].getName();
060:                }
061:
062:                mode = new JComboBox(modeNames);
063:                mode.addActionListener(new ActionHandler());
064:
065:                captionBox = new Box(BoxLayout.X_AXIS);
066:                addComponent(captionBox);
067:
068:                addComponent(jEdit.getProperty("options.editing.mode"), mode);
069:
070:                useDefaults = new JCheckBox(jEdit
071:                        .getProperty("options.editing.useDefaults"));
072:                useDefaults.addActionListener(new ActionHandler());
073:                addComponent(useDefaults);
074:
075:                addComponent(jEdit.getProperty("options.editing.noWordSep"),
076:                        noWordSep = new JTextField());
077:
078:                addComponent(camelCasedWords = new JCheckBox(jEdit
079:                        .getProperty("options.editing.camelCasedWords")));
080:
081:                String[] foldModes = FoldHandler.getFoldModes();
082:                addComponent(jEdit.getProperty("options.editing.folding"),
083:                        folding = new JComboBox(foldModes));
084:
085:                addComponent(
086:                        jEdit.getProperty("options.editing.collapseFolds"),
087:                        collapseFolds = new JTextField());
088:
089:                String[] wrapModes = { "none", "soft", "hard" };
090:                addComponent(jEdit.getProperty("options.editing.wrap"),
091:                        wrap = new JComboBox(wrapModes));
092:
093:                String[] lineLens = { "0", "72", "76", "80" };
094:                maxLineLen = new JComboBox(lineLens);
095:                maxLineLen.setToolTipText(jEdit
096:                        .getProperty("options.editing.maxLineLen.tooltip"));
097:                addComponent(jEdit.getProperty("options.editing.maxLineLen"),
098:                        maxLineLen);
099:                maxLineLen.setEditable(true);
100:
101:                String[] tabSizes = { "2", "4", "8" };
102:                addComponent(jEdit.getProperty("options.editing.tabSize"),
103:                        tabSize = new JComboBox(tabSizes));
104:                tabSize.setEditable(true);
105:
106:                addComponent(jEdit.getProperty("options.editing.indentSize"),
107:                        indentSize = new JComboBox(tabSizes));
108:                indentSize.setEditable(true);
109:
110:                addComponent(noTabs = new JCheckBox(jEdit
111:                        .getProperty("options.editing.noTabs")));
112:
113:                addComponent(deepIndent = new JCheckBox(jEdit
114:                        .getProperty("options.editing.deepIndent")));
115:
116:                filenameGlob = new JTextField();
117:                filenameGlob.setToolTipText(jEdit.getProperty("glob.tooltip"));
118:                addComponent(jEdit.getProperty("options.editing.filenameGlob"),
119:                        filenameGlob);
120:
121:                addComponent(
122:                        jEdit.getProperty("options.editing.firstlineGlob"),
123:                        firstlineGlob = new JTextField());
124:
125:                selectMode();
126:
127:                addSeparator();
128:
129:                defaultMode = new JComboBox(modes);
130:                defaultMode.setSelectedItem(jEdit.getMode(jEdit
131:                        .getProperty("buffer.defaultMode")));
132:                addComponent(jEdit.getProperty("options.editing.defaultMode"),
133:                        defaultMode);
134:
135:                undoCount = new JTextField(jEdit
136:                        .getProperty("buffer.undoCount"));
137:                addComponent(jEdit.getProperty("options.editing.undoCount"),
138:                        undoCount);
139:
140:                //{{{ Reset Undo Manager On Save
141:                resetUndoOnSave = new JCheckBox(jEdit
142:                        .getProperty("options.general.resetUndo"));
143:                resetUndoOnSave.setSelected(jEdit
144:                        .getBooleanProperty("resetUndoOnSave"));
145:                addComponent(resetUndoOnSave);
146:                //}}}
147:
148:            } //}}}
149:
150:            //{{{ _save() method
151:            protected void _save() {
152:                jEdit.setProperty("buffer.defaultMode", ((Mode) defaultMode
153:                        .getSelectedItem()).getName());
154:                jEdit.setProperty("buffer.undoCount", undoCount.getText());
155:                jEdit.setBooleanProperty("resetUndoOnSave", resetUndoOnSave
156:                        .isSelected());
157:
158:                saveMode();
159:
160:                global.save();
161:
162:                for (int i = 0; i < modeProps.length; i++) {
163:                    modeProps[i].save();
164:                }
165:            } //}}}
166:
167:            //{{{ Private members
168:
169:            //{{{ Instance variables
170:            private JComboBox defaultMode;
171:            private JTextField undoCount;
172:            private JCheckBox resetUndoOnSave;
173:            private ModeProperties global;
174:            private ModeProperties[] modeProps;
175:            private ModeProperties current;
176:            private Box captionBox;
177:            private JComboBox mode;
178:            private JCheckBox useDefaults;
179:            private JTextField filenameGlob;
180:            private JTextField firstlineGlob;
181:            private JTextField noWordSep;
182:            private JCheckBox camelCasedWords;
183:            private JComboBox folding;
184:            private JTextField collapseFolds;
185:            private JComboBox wrap;
186:            private JComboBox maxLineLen;
187:            private JComboBox tabSize;
188:            private JComboBox indentSize;
189:            private JCheckBox noTabs;
190:            private JCheckBox deepIndent;
191:
192:            //}}}
193:
194:            //{{{ saveMode() method
195:            private void saveMode() {
196:                current.useDefaults = useDefaults.isSelected();
197:                current.filenameGlob = filenameGlob.getText();
198:                current.firstlineGlob = firstlineGlob.getText();
199:                current.noWordSep = noWordSep.getText();
200:                current.camelCasedWords = camelCasedWords.isSelected();
201:                current.folding = (String) folding.getSelectedItem();
202:                current.collapseFolds = collapseFolds.getText();
203:                current.wrap = (String) wrap.getSelectedItem();
204:                current.maxLineLen = (String) maxLineLen.getSelectedItem();
205:                current.tabSize = (String) tabSize.getSelectedItem();
206:                current.indentSize = (String) indentSize.getSelectedItem();
207:                current.noTabs = noTabs.isSelected();
208:                current.deepIndent = deepIndent.isSelected();
209:            } //}}}
210:
211:            //{{{ selectMode() method
212:            private void selectMode() {
213:                int index = mode.getSelectedIndex();
214:                current = index == 0 ? global : modeProps[index - 1];
215:                current.edited = true;
216:                current.load();
217:
218:                captionBox.removeAll();
219:                captionBox.add(GUIUtilities.createMultilineLabel(jEdit
220:                        .getProperty("options.editing.caption-"
221:                                + (index == 0 ? "0" : "1"))));
222:
223:                useDefaults.setSelected(current.useDefaults);
224:                filenameGlob.setText(current.filenameGlob);
225:                firstlineGlob.setText(current.firstlineGlob);
226:                noWordSep.setText(current.noWordSep);
227:                camelCasedWords.setSelected(current.camelCasedWords);
228:                folding.setSelectedItem(current.folding);
229:                collapseFolds.setText(current.collapseFolds);
230:                wrap.setSelectedItem(current.wrap);
231:                maxLineLen.setSelectedItem(current.maxLineLen);
232:                tabSize.setSelectedItem(current.tabSize);
233:                indentSize.setSelectedItem(current.indentSize);
234:                noTabs.setSelected(current.noTabs);
235:                deepIndent.setSelected(current.deepIndent);
236:
237:                updateEnabled();
238:                revalidate();
239:            } //}}}
240:
241:            //{{{ updateEnabled() method
242:            private void updateEnabled() {
243:                boolean enabled;
244:                if (current == global) {
245:                    enabled = true;
246:                    useDefaults.setEnabled(false);
247:                    filenameGlob.setEnabled(false);
248:                    firstlineGlob.setEnabled(false);
249:                } else {
250:                    enabled = !modeProps[mode.getSelectedIndex() - 1].useDefaults;
251:                    useDefaults.setEnabled(true);
252:                    filenameGlob.setEnabled(enabled);
253:                    firstlineGlob.setEnabled(enabled);
254:                }
255:
256:                noWordSep.setEnabled(enabled);
257:                camelCasedWords.setEnabled(enabled);
258:                folding.setEnabled(enabled);
259:                collapseFolds.setEnabled(enabled);
260:                wrap.setEnabled(enabled);
261:                maxLineLen.setEnabled(enabled);
262:                tabSize.setEnabled(enabled);
263:                indentSize.setEnabled(enabled);
264:                noTabs.setEnabled(enabled);
265:                deepIndent.setEnabled(enabled);
266:            } //}}}
267:
268:            //}}}
269:
270:            //{{{ ActionHandler class
271:            class ActionHandler implements  ActionListener {
272:                public void actionPerformed(ActionEvent evt) {
273:                    Object source = evt.getSource();
274:                    if (source == mode) {
275:                        saveMode();
276:                        selectMode();
277:                    } else if (source == useDefaults) {
278:                        modeProps[mode.getSelectedIndex() - 1].useDefaults = useDefaults
279:                                .isSelected();
280:                        updateEnabled();
281:                    }
282:                }
283:            } //}}}
284:
285:            //{{{ ModeProperties class
286:            static class ModeProperties {
287:                //{{{ Instance variables
288:                Mode mode;
289:                boolean edited;
290:                boolean loaded;
291:
292:                boolean useDefaults;
293:                String filenameGlob;
294:                String firstlineGlob;
295:                String noWordSep;
296:                boolean camelCasedWords;
297:                String folding;
298:                String collapseFolds;
299:                String wrap;
300:                String maxLineLen;
301:                String tabSize;
302:                String indentSize;
303:                boolean noTabs;
304:                boolean deepIndent;
305:
306:                //}}}
307:
308:                //{{{ ModeProperties constructor
309:                ModeProperties() {
310:                } //}}}
311:
312:                //{{{ ModeProperties constructor
313:                ModeProperties(Mode mode) {
314:                    this .mode = mode;
315:                } //}}}
316:
317:                //{{{ load() method
318:                void load() {
319:                    if (loaded)
320:                        return;
321:
322:                    loaded = true;
323:
324:                    if (mode != null) {
325:                        mode.loadIfNecessary();
326:
327:                        useDefaults = !jEdit.getBooleanProperty("mode."
328:                                + mode.getName() + ".customSettings");
329:                        filenameGlob = (String) mode
330:                                .getProperty("filenameGlob");
331:                        firstlineGlob = (String) mode
332:                                .getProperty("firstlineGlob");
333:                        noWordSep = (String) mode.getProperty("noWordSep");
334:                        camelCasedWords = mode
335:                                .getBooleanProperty("camelCasedWords");
336:                        folding = mode.getProperty("folding").toString();
337:                        collapseFolds = mode.getProperty("collapseFolds")
338:                                .toString();
339:                        wrap = mode.getProperty("wrap").toString();
340:                        maxLineLen = mode.getProperty("maxLineLen").toString();
341:                        tabSize = mode.getProperty("tabSize").toString();
342:                        indentSize = mode.getProperty("indentSize").toString();
343:                        noTabs = mode.getBooleanProperty("noTabs");
344:                        deepIndent = mode.getBooleanProperty("deepIndent");
345:                    } else {
346:                        noWordSep = jEdit.getProperty("buffer.noWordSep");
347:                        camelCasedWords = jEdit
348:                                .getBooleanProperty("buffer.camelCasedWords");
349:                        folding = jEdit.getProperty("buffer.folding");
350:                        collapseFolds = jEdit
351:                                .getProperty("buffer.collapseFolds");
352:                        wrap = jEdit.getProperty("buffer.wrap");
353:                        maxLineLen = jEdit.getProperty("buffer.maxLineLen");
354:                        tabSize = jEdit.getProperty("buffer.tabSize");
355:                        indentSize = jEdit.getProperty("buffer.indentSize");
356:                        noTabs = jEdit.getBooleanProperty("buffer.noTabs");
357:                        deepIndent = jEdit
358:                                .getBooleanProperty("buffer.deepIndent");
359:                    }
360:                } //}}}
361:
362:                //{{{ save() method
363:                void save() {
364:                    // don't do anything if the user didn't change
365:                    // any settings
366:                    if (!edited)
367:                        return;
368:
369:                    String prefix;
370:                    if (mode != null) {
371:                        prefix = "mode." + mode.getName() + '.';
372:                        jEdit.setBooleanProperty(prefix + "customSettings",
373:                                !useDefaults);
374:
375:                        // need to call Mode.init() if the file name or first line
376:                        // globs change
377:                        String oldFilenameGlob = (String) mode
378:                                .getProperty("filenameGlob");
379:                        String oldFirstlineGlob = (String) mode
380:                                .getProperty("firstlineGlob");
381:                        if (useDefaults) {
382:                            jEdit.resetProperty(prefix + "filenameGlob");
383:                            jEdit.resetProperty(prefix + "firstlineGlob");
384:                            jEdit.resetProperty(prefix + "noWordSep");
385:                            jEdit.resetProperty(prefix + "camelCasedWords");
386:                            jEdit.resetProperty(prefix + "folding");
387:                            jEdit.resetProperty(prefix + "collapseFolds");
388:                            jEdit.resetProperty(prefix + "wrap");
389:                            jEdit.resetProperty(prefix + "maxLineLen");
390:                            jEdit.resetProperty(prefix + "tabSize");
391:                            jEdit.resetProperty(prefix + "indentSize");
392:                            jEdit.resetProperty(prefix + "noTabs");
393:                            jEdit.resetProperty(prefix + "deepIndent");
394:
395:                            if (!(StandardUtilities.objectsEqual(
396:                                    oldFilenameGlob, mode
397:                                            .getProperty("filenameGlob")) && StandardUtilities
398:                                    .objectsEqual(oldFirstlineGlob, mode
399:                                            .getProperty("firstlineGlob")))) {
400:                                mode.init();
401:                            }
402:
403:                            return;
404:                        } else {
405:                            jEdit.setProperty(prefix + "filenameGlob",
406:                                    filenameGlob);
407:                            jEdit.setProperty(prefix + "firstlineGlob",
408:                                    firstlineGlob);
409:
410:                            if (!(StandardUtilities.objectsEqual(
411:                                    oldFilenameGlob, filenameGlob) && StandardUtilities
412:                                    .objectsEqual(oldFirstlineGlob,
413:                                            firstlineGlob))) {
414:                                mode.init();
415:                            }
416:                        }
417:                    } else {
418:                        prefix = "buffer.";
419:                    }
420:
421:                    jEdit.setProperty(prefix + "noWordSep", noWordSep);
422:                    jEdit.setBooleanProperty(prefix + "camelCasedWords",
423:                            camelCasedWords);
424:                    jEdit.setProperty(prefix + "folding", folding);
425:                    jEdit.setProperty(prefix + "collapseFolds", collapseFolds);
426:                    jEdit.setProperty(prefix + "wrap", wrap);
427:                    jEdit.setProperty(prefix + "maxLineLen", maxLineLen);
428:                    jEdit.setProperty(prefix + "tabSize", tabSize);
429:                    jEdit.setProperty(prefix + "indentSize", indentSize);
430:                    jEdit.setBooleanProperty(prefix + "noTabs", noTabs);
431:                    jEdit.setBooleanProperty(prefix + "deepIndent", deepIndent);
432:                } //}}}
433:            } //}}}
434:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.