Source Code Cross Referenced for EditorOptions.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » editor » 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 » IDE Netbeans » cnd » org.netbeans.modules.cnd.editor.options 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         * 
024:         * If you wish your version of this file to be governed by only the CDDL
025:         * or only the GPL Version 2, indicate your decision by adding
026:         * "[Contributor] elects to include this software in this distribution
027:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
028:         * single choice of license, a recipient has the option to distribute
029:         * your version of this file under either the CDDL, the GPL Version 2 or
030:         * to extend the choice of license to its licensees as provided above.
031:         * However, if you add GPL Version 2 code and therefore, elected the GPL
032:         * Version 2 license, then the option applies only if the new code is
033:         * made subject to such option by the copyright holder.
034:         * 
035:         * Contributor(s):
036:         * 
037:         * Portions Copyrighted 2008 Sun Microsystems, Inc.
038:         */
039:
040:        package org.netbeans.modules.cnd.editor.options;
041:
042:        import java.util.HashMap;
043:        import java.util.Map;
044:        import java.util.prefs.Preferences;
045:        import javax.swing.text.EditorKit;
046:        import org.netbeans.api.editor.mimelookup.MimeLookup;
047:        import org.netbeans.api.editor.mimelookup.MimePath;
048:        import org.netbeans.editor.Formatter;
049:        import org.netbeans.editor.Settings;
050:        import org.netbeans.modules.cnd.editor.api.CodeStyle;
051:        import org.netbeans.modules.cnd.editor.api.CodeStyle.BracePlacement;
052:        import org.netbeans.modules.cnd.editor.api.CodeStyle.PreprocessorIndent;
053:        import org.openide.util.NbPreferences;
054:
055:        /**
056:         *
057:         * @author Alexander Simon
058:         */
059:        public class EditorOptions {
060:            public static CodeStyleFactory codeStyleFactory;
061:            static {
062:                Class c = CodeStyle.class;
063:                try {
064:                    Class.forName(c.getName(), true, c.getClassLoader());
065:                } catch (Exception ex) {
066:                    ex.printStackTrace();
067:                }
068:            }
069:            //indents
070:            /**
071:             * How many spaces should be added to the statement that continues
072:             * on the next line.
073:             */
074:            public static final String statementContinuationIndent = "statementContinuationIndent"; // NOI18N 
075:            public static final int statementContinuationIndentDefault = 8;
076:            /**
077:             * Whether to indent preprocessors positioned at start of line.
078:             * Those not starting at column 0 of the line will automatically be indented.
079:             * This setting is to prevent C/C++ code that is compiled with compilers that
080:             * require the processors to have '#' in column 0.
081:             * <B>Note:</B>This will not convert formatted preprocessors back to column 0.
082:             */
083:            public static final String indentPreprocessorDirectives = "indentPreprocessorDirectives"; //NOI18N
084:            public static final String indentPreprocessorDirectivesDefault = PreprocessorIndent.START_LINE
085:                    .name();
086:            public static final String sharpAtStartLine = "sharpAtStartLine"; //NOI18N
087:            public static final boolean sharpAtStartLineDefault = true;
088:            public static final String indentCasesFromSwitch = "indentCasesFromSwitch"; //NOI18N
089:            public static final boolean indentCasesFromSwitchDefault = true;
090:
091:            //BracesPlacement
092:            public static final String newLineBeforeBraceNamespace = "newLineBeforeBraceNamespace"; //NOI18N
093:            public static final String newLineBeforeBraceNamespaceDefault = BracePlacement.NEW_LINE
094:                    .name();
095:            public static final String newLineBeforeBraceClass = "newLineBeforeBraceClass"; //NOI18N
096:            public static final String newLineBeforeBraceClassDefault = BracePlacement.NEW_LINE
097:                    .name();
098:            /**
099:             * Whether insert extra new-line before the declaration or not.
100:             * Values: java.lang.Boolean instances
101:             * Effect: int foo() {
102:             *           function();
103:             *         }
104:             *           becomes (when set to true)
105:             *         int foo(test)
106:             *         {
107:             *           function();
108:             *         }
109:             */
110:            public static final String newLineBeforeBraceDeclaration = "newLineBeforeBraceDeclaration"; //NOI18N
111:            public static final String newLineBeforeBraceDeclarationDefault = BracePlacement.NEW_LINE
112:                    .name();
113:            /**
114:             * Whether insert extra new-line before the compound bracket or not.
115:             * Values: java.lang.Boolean instances
116:             * Effect: if (test) {
117:             *           function();
118:             *         }
119:             *           becomes (when set to true)
120:             *         if (test)
121:             *         {
122:             *           function();
123:             *         }
124:             */
125:            public static final String newLineBeforeBrace = "newLineBeforeBrace"; //NOI18N
126:            public static final String newLineBeforeBraceDefault = BracePlacement.SAME_LINE
127:                    .name();
128:
129:            //MultilineAlignment
130:            public static final String alignMultilineArrayInit = "alignMultilineArrayInit"; //NOI18N
131:            public static final boolean alignMultilineArrayInitDefault = false;
132:            public static final String alignMultilineCallArgs = "alignMultilineCallArgs"; //NOI18N
133:            public static final boolean alignMultilineCallArgsDefault = false;
134:            public static final String alignMultilineMethodParams = "alignMultilineMethodParams"; //NOI18N
135:            public static final boolean alignMultilineMethodParamsDefault = false;
136:
137:            //NewLine
138:            public static final String newLineCatch = "newLineCatch"; //NOI18N
139:            public static final boolean newLineCatchDefault = false;
140:            public static final String newLineElse = "newLineElse"; //NOI18N
141:            public static final boolean newLineElseDefault = false;
142:            public static final String newLineWhile = "newLineWhile"; //NOI18N
143:            public static final boolean newLineWhileDefault = false;
144:
145:            //SpacesBeforeKeywords
146:            public static final String spaceBeforeWhile = "spaceBeforeWhile"; //NOI18N
147:            public static final boolean spaceBeforeWhileDefault = true;
148:            public static final String spaceBeforeElse = "spaceBeforeElse"; //NOI18N
149:            public static final boolean spaceBeforeElseDefault = true;
150:            public static final String spaceBeforeCatch = "spaceBeforeCatch"; //NOI18N
151:            public static final boolean spaceBeforeCatchDefault = true;
152:
153:            //SpacesBeforeParentheses
154:            public static final String spaceBeforeMethodDeclParen = "spaceBeforeMethodDeclParen"; //NOI18N
155:            public static final boolean spaceBeforeMethodDeclParenDefault = false;
156:            public static final String spaceBeforeMethodCallParen = "spaceBeforeMethodCallParen"; //NOI18N
157:            public static final boolean spaceBeforeMethodCallParenDefault = false;
158:            public static final String spaceBeforeIfParen = "spaceBeforeIfParen"; //NOI18N
159:            public static final boolean spaceBeforeIfParenDefault = true;
160:            public static final String spaceBeforeForParen = "spaceBeforeForParen"; //NOI18N
161:            public static final boolean spaceBeforeForParenDefault = true;
162:            public static final String spaceBeforeWhileParen = "spaceBeforeWhileParen"; //NOI18N
163:            public static final boolean spaceBeforeWhileParenDefault = true;
164:            public static final String spaceBeforeCatchParen = "spaceBeforeCatchParen"; //NOI18N
165:            public static final boolean spaceBeforeCatchParenDefault = true;
166:            public static final String spaceBeforeSwitchParen = "spaceBeforeSwitchParen"; //NOI18N
167:            public static final boolean spaceBeforeSwitchParenDefault = true;
168:
169:            //SpacesAroundOperators
170:            public static final String spaceAroundUnaryOps = "spaceAroundUnaryOps"; //NOI18N
171:            public static final boolean spaceAroundUnaryOpsDefault = false;
172:            public static final String spaceAroundBinaryOps = "spaceAroundBinaryOps"; //NOI18N
173:            public static final boolean spaceAroundBinaryOpsDefault = true;
174:            public static final String spaceAroundTernaryOps = "spaceAroundTernaryOps"; //NOI18N
175:            public static final boolean spaceAroundTernaryOpsDefault = true;
176:            public static final String spaceAroundAssignOps = "spaceAroundAssignOps"; //NOI18N
177:            public static final boolean spaceAroundAssignOpsDefault = true;
178:
179:            //SpacesBeforeLeftBraces
180:            public static final String spaceBeforeClassDeclLeftBrace = "spaceBeforeClassDeclLeftBrace"; //NOI18N
181:            public static final boolean spaceBeforeClassDeclLeftBraceDefault = true;
182:            public static final String spaceBeforeMethodDeclLeftBrace = "spaceBeforeMethodDeclLeftBrace"; //NOI18N
183:            public static final boolean spaceBeforeMethodDeclLeftBraceDefault = true;
184:            public static final String spaceBeforeIfLeftBrace = "spaceBeforeIfLeftBrace"; //NOI18N
185:            public static final boolean spaceBeforeIfLeftBraceDefault = true;
186:            public static final String spaceBeforeElseLeftBrace = "spaceBeforeElseLeftBrace"; //NOI18N
187:            public static final boolean spaceBeforeElseLeftBraceDefault = true;
188:            public static final String spaceBeforeWhileLeftBrace = "spaceBeforeWhileLeftBrace"; //NOI18N
189:            public static final boolean spaceBeforeWhileLeftBraceDefault = true;
190:            public static final String spaceBeforeForLeftBrace = "spaceBeforeForLeftBrace"; //NOI18N
191:            public static final boolean spaceBeforeForLeftBraceDefault = true;
192:            public static final String spaceBeforeDoLeftBrace = "spaceBeforeDoLeftBrace"; //NOI18N
193:            public static final boolean spaceBeforeDoLeftBraceDefault = true;
194:            public static final String spaceBeforeSwitchLeftBrace = "spaceBeforeSwitchLeftBrace"; //NOI18N
195:            public static final boolean spaceBeforeSwitchLeftBraceDefault = true;
196:            public static final String spaceBeforeTryLeftBrace = "spaceBeforeTryLeftBrace"; //NOI18N
197:            public static final boolean spaceBeforeTryLeftBraceDefault = true;
198:            public static final String spaceBeforeCatchLeftBrace = "spaceBeforeCatchLeftBrace"; //NOI18N
199:            public static final boolean spaceBeforeCatchLeftBraceDefault = true;
200:            public static final String spaceBeforeArrayInitLeftBrace = "spaceBeforeArrayInitLeftBrace"; //NOI18N
201:            public static final boolean spaceBeforeArrayInitLeftBraceDefault = false;
202:
203:            //SpacesWithinParentheses
204:            public static final String spaceWithinParens = "spaceWithinParens"; //NOI18N
205:            public static final boolean spaceWithinParensDefault = false;
206:            public static final String spaceWithinMethodDeclParens = "spaceWithinMethodDeclParens"; //NOI18N
207:            public static final boolean spaceWithinMethodDeclParensDefault = false;
208:            public static final String spaceWithinMethodCallParens = "spaceWithinMethodCallParens"; //NOI18N
209:            public static final boolean spaceWithinMethodCallParensDefault = false;
210:            public static final String spaceWithinIfParens = "spaceWithinIfParens"; //NOI18N
211:            public static final boolean spaceWithinIfParensDefault = false;
212:            public static final String spaceWithinForParens = "spaceWithinForParens"; //NOI18N
213:            public static final boolean spaceWithinForParensDefault = false;
214:            public static final String spaceWithinWhileParens = "spaceWithinWhileParens"; //NOI18N
215:            public static final boolean spaceWithinWhileParensDefault = false;
216:            public static final String spaceWithinSwitchParens = "spaceWithinSwitchParens"; //NOI18N
217:            public static final boolean spaceWithinSwitchParensDefault = false;
218:            public static final String spaceWithinCatchParens = "spaceWithinCatchParens"; //NOI18N
219:            public static final boolean spaceWithinCatchParensDefault = false;
220:            public static final String spaceWithinTypeCastParens = "spaceWithinTypeCastParens"; //NOI18N
221:            public static final boolean spaceWithinTypeCastParensDefault = false;
222:            public static final String spaceWithinBraces = "spaceWithinBraces"; //NOI18N
223:            public static final boolean spaceWithinBracesDefault = false;
224:            public static final String spaceWithinArrayInitBrackets = "spaceWithinArrayInitBrackets"; //NOI18N
225:            public static final boolean spaceWithinArrayInitBracketsDefault = false;
226:
227:            //SpacesOther
228:            public static final String spaceBeforeComma = "spaceBeforeComma"; //NOI18N
229:            public static final boolean spaceBeforeCommaDefault = false;
230:            public static final String spaceAfterComma = "spaceAfterComma"; //NOI18N
231:            public static final boolean spaceAfterCommaDefault = true;
232:            public static final String spaceBeforeSemi = "spaceBeforeSemi"; //NOI18N
233:            public static final boolean spaceBeforeSemiDefault = false;
234:            public static final String spaceAfterSemi = "spaceAfterSemi"; //NOI18N
235:            public static final boolean spaceAfterSemiDefault = true;
236:            public static final String spaceBeforeColon = "spaceBeforeColon"; //NOI18N
237:            public static final boolean spaceBeforeColonDefault = true;
238:            public static final String spaceAfterColon = "spaceAfterColon"; //NOI18N
239:            public static final boolean spaceAfterColonDefault = true;
240:            public static final String spaceAfterTypeCast = "spaceAfterTypeCast"; //NOI18N
241:            public static final boolean spaceAfterTypeCastDefault = true;
242:
243:            //BlankLines
244:            public static final String blankLinesBeforeClass = "blankLinesBeforeClass"; //NOI18N
245:            public static final int blankLinesBeforeClassDefault = 1;
246:            public static final String blankLinesAfterClass = "blankLinesAfterClass"; //NOI18N
247:            public static final int blankLinesAfterClassDefault = 0;
248:            public static final String blankLinesAfterClassHeader = "blankLinesAfterClassHeader"; //NOI18N
249:            public static final int blankLinesAfterClassHeaderDefault = 0;
250:            public static final String blankLinesBeforeFields = "blankLinesBeforeFields"; //NOI18N
251:            public static final int blankLinesBeforeFieldsDefault = 0;
252:            public static final String blankLinesAfterFields = "blankLinesAfterFields"; //NOI18N
253:            public static final int blankLinesAfterFieldsDefault = 0;
254:            public static final String blankLinesBeforeMethods = "blankLinesBeforeMethods"; //NOI18N
255:            public static final int blankLinesBeforeMethodsDefault = 1;
256:            public static final String blankLinesAfterMethods = "blankLinesAfterMethods"; //NOI18N
257:            public static final int blankLinesAfterMethodsDefault = 0;
258:
259:            //Other
260:            /** Whether the '*' should be added at the new line * in comment */
261:            public static final String addLeadingStarInComment = "addLeadingStarInComment"; // NOI18N
262:            public static final Boolean addLeadingStarInCommentDefault = true;
263:
264:            private static final String APACHE_PROFILE = "Apache"; // NOI18N
265:            private static final String CUSTOM_PROFILE = "Custom"; // NOI18N
266:            private static final String DEFAULT_PROFILE = "Default"; // NOI18N
267:
268:            public static final String[] PREDEFINED_STYLES = new String[] {
269:                    DEFAULT_PROFILE, APACHE_PROFILE, CUSTOM_PROFILE };
270:
271:            private static Map<String, Object> defaults;
272:            private static Map<String, Map<String, Object>> namedDefaults;
273:
274:            static {
275:                createDefaults();
276:            }
277:
278:            private static void createDefaults() {
279:                defaults = new HashMap<String, Object>();
280:                // Indents
281:                defaults.put(statementContinuationIndent,
282:                        statementContinuationIndentDefault);
283:                defaults.put(indentPreprocessorDirectives,
284:                        indentPreprocessorDirectivesDefault);
285:                defaults.put(sharpAtStartLine, sharpAtStartLineDefault);
286:                defaults.put(indentCasesFromSwitch,
287:                        indentCasesFromSwitchDefault);
288:                //BracesPlacement
289:                defaults.put(newLineBeforeBraceNamespace,
290:                        newLineBeforeBraceNamespaceDefault);
291:                defaults.put(newLineBeforeBraceClass,
292:                        newLineBeforeBraceClassDefault);
293:                defaults.put(newLineBeforeBraceDeclaration,
294:                        newLineBeforeBraceDeclarationDefault);
295:                defaults.put(newLineBeforeBrace, newLineBeforeBraceDefault);
296:                //MultilineAlignment
297:                defaults.put(alignMultilineArrayInit,
298:                        alignMultilineArrayInitDefault);
299:                defaults.put(alignMultilineCallArgs,
300:                        alignMultilineCallArgsDefault);
301:                defaults.put(alignMultilineMethodParams,
302:                        alignMultilineMethodParamsDefault);
303:                //NewLine
304:                defaults.put(newLineCatch, newLineCatchDefault);
305:                defaults.put(newLineElse, newLineElseDefault);
306:                defaults.put(newLineWhile, newLineWhileDefault);
307:                //SpacesBeforeKeywords
308:                defaults.put(spaceBeforeWhile, spaceBeforeWhileDefault);
309:                defaults.put(spaceBeforeElse, spaceBeforeElseDefault);
310:                defaults.put(spaceBeforeCatch, spaceBeforeCatchDefault);
311:                //SpacesBeforeParentheses
312:                defaults.put(spaceBeforeMethodDeclParen,
313:                        spaceBeforeMethodDeclParenDefault);
314:                defaults.put(spaceBeforeMethodCallParen,
315:                        spaceBeforeMethodCallParenDefault);
316:                defaults.put(spaceBeforeIfParen, spaceBeforeIfParenDefault);
317:                defaults.put(spaceBeforeForParen, spaceBeforeForParenDefault);
318:                defaults.put(spaceBeforeWhileParen,
319:                        spaceBeforeWhileParenDefault);
320:                defaults.put(spaceBeforeCatchParen,
321:                        spaceBeforeCatchParenDefault);
322:                defaults.put(spaceBeforeSwitchParen,
323:                        spaceBeforeSwitchParenDefault);
324:                //SpacesAroundOperators
325:                defaults.put(spaceAroundUnaryOps, spaceAroundUnaryOpsDefault);
326:                defaults.put(spaceAroundBinaryOps, spaceAroundBinaryOpsDefault);
327:                defaults.put(spaceAroundTernaryOps,
328:                        spaceAroundTernaryOpsDefault);
329:                defaults.put(spaceAroundAssignOps, spaceAroundAssignOpsDefault);
330:                //SpacesBeforeLeftBraces
331:                defaults.put(spaceBeforeClassDeclLeftBrace,
332:                        spaceBeforeClassDeclLeftBraceDefault);
333:                defaults.put(spaceBeforeMethodDeclLeftBrace,
334:                        spaceBeforeMethodDeclLeftBraceDefault);
335:                defaults.put(spaceBeforeIfLeftBrace,
336:                        spaceBeforeIfLeftBraceDefault);
337:                defaults.put(spaceBeforeElseLeftBrace,
338:                        spaceBeforeElseLeftBraceDefault);
339:                defaults.put(spaceBeforeWhileLeftBrace,
340:                        spaceBeforeWhileLeftBraceDefault);
341:                defaults.put(spaceBeforeForLeftBrace,
342:                        spaceBeforeForLeftBraceDefault);
343:                defaults.put(spaceBeforeDoLeftBrace,
344:                        spaceBeforeDoLeftBraceDefault);
345:                defaults.put(spaceBeforeSwitchLeftBrace,
346:                        spaceBeforeSwitchLeftBraceDefault);
347:                defaults.put(spaceBeforeTryLeftBrace,
348:                        spaceBeforeTryLeftBraceDefault);
349:                defaults.put(spaceBeforeCatchLeftBrace,
350:                        spaceBeforeCatchLeftBraceDefault);
351:                defaults.put(spaceBeforeArrayInitLeftBrace,
352:                        spaceBeforeArrayInitLeftBraceDefault);
353:                //SpacesWithinParentheses
354:                defaults.put(spaceWithinParens, spaceWithinParensDefault);
355:                defaults.put(spaceWithinMethodDeclParens,
356:                        spaceWithinMethodDeclParensDefault);
357:                defaults.put(spaceWithinMethodCallParens,
358:                        spaceWithinMethodCallParensDefault);
359:                defaults.put(spaceWithinIfParens, spaceWithinIfParensDefault);
360:                defaults.put(spaceWithinForParens, spaceWithinForParensDefault);
361:                defaults.put(spaceWithinWhileParens,
362:                        spaceWithinWhileParensDefault);
363:                defaults.put(spaceWithinSwitchParens,
364:                        spaceWithinSwitchParensDefault);
365:                defaults.put(spaceWithinCatchParens,
366:                        spaceWithinCatchParensDefault);
367:                defaults.put(spaceWithinTypeCastParens,
368:                        spaceWithinTypeCastParensDefault);
369:                defaults.put(spaceWithinBraces, spaceWithinBracesDefault);
370:                defaults.put(spaceWithinArrayInitBrackets,
371:                        spaceWithinArrayInitBracketsDefault);
372:                //SpacesOther
373:                defaults.put(spaceBeforeComma, spaceBeforeCommaDefault);
374:                defaults.put(spaceAfterComma, spaceAfterCommaDefault);
375:                defaults.put(spaceBeforeSemi, spaceBeforeSemiDefault);
376:                defaults.put(spaceAfterSemi, spaceAfterSemiDefault);
377:                defaults.put(spaceBeforeColon, spaceBeforeColonDefault);
378:                defaults.put(spaceAfterColon, spaceAfterColonDefault);
379:                defaults.put(spaceAfterTypeCast, spaceAfterTypeCastDefault);
380:                //BlankLines
381:                defaults.put(blankLinesBeforeClass,
382:                        blankLinesBeforeClassDefault);
383:                defaults.put(blankLinesAfterClass, blankLinesAfterClassDefault);
384:                defaults.put(blankLinesAfterClassHeader,
385:                        blankLinesAfterClassHeaderDefault);
386:                defaults.put(blankLinesBeforeFields,
387:                        blankLinesBeforeFieldsDefault);
388:                defaults.put(blankLinesAfterFields,
389:                        blankLinesAfterFieldsDefault);
390:                defaults.put(blankLinesBeforeMethods,
391:                        blankLinesBeforeMethodsDefault);
392:                defaults.put(blankLinesAfterMethods,
393:                        blankLinesAfterMethodsDefault);
394:                //Other
395:                defaults.put(addLeadingStarInComment,
396:                        addLeadingStarInCommentDefault);
397:
398:                namedDefaults = new HashMap<String, Map<String, Object>>();
399:                //Apache style
400:                //This style can be generated with the following arguments to GNU indent:
401:                //    -i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1 -nut
402:                //The Guidelines
403:                //        * Opening braces are given on the same lines as statements,
404:                //          or on the following line at the start of a function definition.
405:                //        * Code inside a block (whether surrounded by braces or not) is indented by four space characters.
406:                //          Tab characters are not used. Comments are indented to the same level as the surrounding code.
407:                //        * Closing braces are always on a separate line from surrounding code,
408:                //          and are indented to line up with the start of the text on the line containing the corresponding
409:                //          opening brace.
410:                //        * Functions are declared with ANSI-style arguments.
411:                //        * There is no space between the function name and the opening bracket of the arguments to the function.
412:                //          There is a single space following commas in argument lists and the semi-colons in for statements.
413:                //        * Inside a switch() statement, the case keywords are indented to the same level as the switch line.
414:                //        * Operators in expressions should be surrounded by a single space before and after,
415:                //          except for unary increment (++), decrement (--), and negation (!) operators.
416:                //        * There is no whitespace between a cast and the item modified (e.g., "(int)j" and not "(int) j").
417:                //        * If a cast is to a pointer type, there is a space between the type and
418:                //          the * character (e.g., "(char *)i" instead of "(char*)i")
419:                Map<String, Object> apache = new HashMap<String, Object>();
420:                namedDefaults.put(APACHE_PROFILE, apache);
421:                apache.put(indentCasesFromSwitch, false);
422:                // Placeholder for custom style        
423:                Map<String, Object> custom = new HashMap<String, Object>();
424:                namedDefaults.put(CUSTOM_PROFILE, custom);
425:            }
426:
427:            public static Object getDefault(CodeStyle.Language language,
428:                    String styleId, String id) {
429:                Map<String, Object> map = namedDefaults.get(styleId);
430:                if (map != null) {
431:                    Object res = map.get(id);
432:                    if (res != null) {
433:                        return res;
434:                    }
435:                }
436:                return defaults.get(id);
437:            }
438:
439:            public static String getCurrentProfileId(CodeStyle.Language language) {
440:                switch (language) {
441:                case C:
442:                    return NbPreferences.forModule(CodeStyle.class).node(
443:                            "CodeStyle").get("C_Style", DEFAULT_PROFILE); // NOI18N
444:                case CPP:
445:                default:
446:                    return NbPreferences.forModule(CodeStyle.class).node(
447:                            "CodeStyle").get("CPP_Style", DEFAULT_PROFILE); // NOI18N
448:                }
449:            }
450:
451:            public static void setCurrentProfileId(CodeStyle.Language language,
452:                    String style) {
453:                switch (language) {
454:                case C:
455:                    NbPreferences.forModule(CodeStyle.class).node("CodeStyle")
456:                            .put("C_Style", style); // NOI18N
457:                    break;
458:                case CPP:
459:                default:
460:                    NbPreferences.forModule(CodeStyle.class).node("CodeStyle")
461:                            .put("CPP_Style", style); // NOI18N
462:                    break;
463:                }
464:            }
465:
466:            public static Preferences getPreferences(
467:                    CodeStyle.Language language, String profileId) {
468:                switch (language) {
469:                case C:
470:                    return NbPreferences.forModule(CodeStyle.class).node(
471:                            "C_CodeStyles").node(profileId); // NOI18N
472:                case CPP:
473:                default:
474:                    return NbPreferences.forModule(CodeStyle.class).node(
475:                            "CPP_CodeStyles").node(profileId); // NOI18N
476:                }
477:            }
478:
479:            public static int getGlobalIndentSize(CodeStyle.Language language) {
480:                Formatter f = (Formatter) Settings.getValue(
481:                        getKitClass(language), "formatter"); // NOI18N
482:                if (f != null) {
483:                    return f.getShiftWidth();
484:                }
485:                return 4;
486:            }
487:
488:            public static int getGlobalTabSize(CodeStyle.Language language) {
489:                Formatter f = (Formatter) Settings.getValue(
490:                        getKitClass(language), "formatter"); // NOI18N
491:                if (f != null) {
492:                    return f.getTabSize();
493:                }
494:                return 4;
495:            }
496:
497:            private static Class<? extends EditorKit> cKitClass;
498:            private static Class<? extends EditorKit> cppKitClass;
499:
500:            private static Class<? extends EditorKit> getKitClass(
501:                    CodeStyle.Language language) {
502:                if (language == CodeStyle.Language.C) {
503:                    if (cKitClass == null) {
504:                        EditorKit kit = MimeLookup.getLookup(
505:                                MimePath.get("text/x-c")).lookup(
506:                                EditorKit.class); //NOI18N
507:                        cKitClass = kit != null ? kit.getClass()
508:                                : EditorKit.class;
509:                    }
510:                    return cKitClass;
511:                } else {
512:                    if (cppKitClass == null) {
513:                        EditorKit kit = MimeLookup.getLookup(
514:                                MimePath.get("text/x-c++")).lookup(
515:                                EditorKit.class); //NOI18N
516:                        cppKitClass = kit != null ? kit.getClass()
517:                                : EditorKit.class;
518:                    }
519:                    return cppKitClass;
520:                }
521:            }
522:
523:            public static CodeStyle createCodeStyle(
524:                    CodeStyle.Language language, Preferences p) {
525:                CodeStyle.getDefault(language);
526:                return codeStyleFactory.create(language, p);
527:            }
528:
529:            public static Preferences getPreferences(CodeStyle codeStyle) {
530:                return codeStyleFactory.getPreferences(codeStyle);
531:            }
532:
533:            public static void resetToDefault(CodeStyle codeStyle) {
534:                Preferences preferences = getPreferences(codeStyle);
535:                for (Map.Entry<String, Object> entry : defaults.entrySet()) {
536:                    if (entry.getValue() instanceof  Boolean) {
537:                        preferences.putBoolean(entry.getKey(), (Boolean) entry
538:                                .getValue());
539:                    } else if (entry.getValue() instanceof  Integer) {
540:                        preferences.putInt(entry.getKey(), (Integer) entry
541:                                .getValue());
542:                    } else {
543:                        preferences.put(entry.getKey(), entry.getValue()
544:                                .toString());
545:                    }
546:                }
547:            }
548:
549:            public static void setPreferences(CodeStyle codeStyle,
550:                    Preferences preferences) {
551:                codeStyleFactory.setPreferences(codeStyle, preferences);
552:            }
553:
554:            public static interface CodeStyleFactory {
555:                CodeStyle create(CodeStyle.Language language,
556:                        Preferences preferences);
557:
558:                Preferences getPreferences(CodeStyle codeStyle);
559:
560:                void setPreferences(CodeStyle codeStyle, Preferences preferences);
561:            }
562:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.