Source Code Cross Referenced for SettingsUtil.java in  » IDE-Netbeans » editor » org » netbeans » editor » 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 » editor » org.netbeans.editor 
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:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.editor;
043:
044:        import java.awt.Color;
045:        import java.awt.Font;
046:        import java.util.Map;
047:        import java.util.List;
048:        import java.util.HashMap;
049:        import java.util.ArrayList;
050:        import java.util.Arrays;
051:        import java.util.HashSet;
052:        import java.util.Iterator;
053:        import org.netbeans.modules.editor.lib.ColoringMap;
054:
055:        /**
056:         * Utility methods for managing settings
057:         *
058:         * @author Miloslav Metelka
059:         * @version 1.00
060:         */
061:
062:        public class SettingsUtil {
063:
064:            public static final String TOKEN_COLORING_INITIALIZER_NAME_SUFFIX = "token-coloring-initializer"; // NOI18N
065:
066:            public static final PrintColoringEvaluator defaultPrintColoringEvaluator = new PrintColoringEvaluator();
067:
068:            private static final float defaultPrintFontSize = 10;
069:
070:            /** Get either the cloned list or new list if the old
071:             * one was null.
072:             * @param l list to check
073:             * @return the cloned list if it was non-null or the new list
074:             */
075:            public static List getClonedList(List l) {
076:                return (l != null) ? new ArrayList(l) : new ArrayList();
077:            }
078:
079:            public static List getClonedList(Class kitClass, String settingName) {
080:                return getClonedList((List) Settings.getValue(kitClass,
081:                        settingName));
082:            }
083:
084:            /** Useful for initializers */
085:            public static List getClonedList(Map settingsMap, String settingName) {
086:                if (settingsMap != null) {
087:                    return getClonedList((List) settingsMap.get(settingName));
088:                } else {
089:                    return null;
090:                }
091:            }
092:
093:            public static Map getClonedMap(Map m) {
094:                return (m != null) ? new HashMap(m) : new HashMap();
095:            }
096:
097:            public static Map getClonedMap(Class kitClass, String settingName) {
098:                return getClonedMap((Map) Settings.getValue(kitClass,
099:                        settingName));
100:            }
101:
102:            /** Useful for initializers */
103:            public static Map getClonedMap(Map settingsMap, String settingName) {
104:                if (settingsMap != null) {
105:                    return getClonedMap((Map) settingsMap.get(settingName));
106:                } else {
107:                    return null;
108:                }
109:            }
110:
111:            public static Object getValue(Class kitClass, String settingName,
112:                    Object defaultValue) {
113:                Object value = Settings.getValue(kitClass, settingName);
114:                return (value != null) ? value : defaultValue;
115:            }
116:
117:            public static int getInteger(Class kitClass, String settingName,
118:                    int defaultValue) {
119:                Object value = Settings.getValue(kitClass, settingName);
120:                return (value instanceof  Integer) ? ((Integer) value)
121:                        .intValue() : defaultValue;
122:            }
123:
124:            public static int getInteger(Class kitClass, String settingName,
125:                    Integer defaultValue) {
126:                return getInteger(kitClass, settingName, defaultValue
127:                        .intValue());
128:            }
129:
130:            public static int getPositiveInteger(Class kitClass,
131:                    String settingName, int defaultValue) {
132:                int ret = getInteger(kitClass, settingName, defaultValue);
133:                if (ret <= 0) {
134:                    ret = defaultValue;
135:                }
136:                return ret;
137:            }
138:
139:            public static int getPositiveInteger(Class kitClass,
140:                    String settingName, Integer defaultValue) {
141:                return getPositiveInteger(kitClass, settingName, defaultValue
142:                        .intValue());
143:            }
144:
145:            public static int getNonNegativeInteger(Class kitClass,
146:                    String settingName, int defaultValue) {
147:                int ret = getInteger(kitClass, settingName, defaultValue);
148:                if (ret < 0) {
149:                    ret = defaultValue;
150:                }
151:                return ret;
152:            }
153:
154:            public static int getNonNegativeInteger(Class kitClass,
155:                    String settingName, Integer defaultValue) {
156:                return getNonNegativeInteger(kitClass, settingName,
157:                        defaultValue.intValue());
158:            }
159:
160:            public static boolean getBoolean(Class kitClass,
161:                    String settingName, boolean defaultValue) {
162:                Object value = Settings.getValue(kitClass, settingName);
163:                return (value instanceof  Boolean) ? ((Boolean) value)
164:                        .booleanValue() : defaultValue;
165:            }
166:
167:            public static boolean getBoolean(Class kitClass,
168:                    String settingName, Boolean defaultValue) {
169:                return getBoolean(kitClass, settingName, defaultValue
170:                        .booleanValue());
171:            }
172:
173:            public static String getString(Class kitClass, String settingName,
174:                    String defaultValue) {
175:                Object value = Settings.getValue(kitClass, settingName);
176:                return (value instanceof  String) ? (String) value
177:                        : defaultValue;
178:            }
179:
180:            public static Acceptor getAcceptor(Class kitClass,
181:                    String settingName, Acceptor defaultValue) {
182:                Object value = Settings.getValue(kitClass, settingName);
183:                return (value instanceof  Acceptor) ? (Acceptor) value
184:                        : defaultValue;
185:            }
186:
187:            public static List getList(Class kitClass, String settingName,
188:                    List defaultValue) {
189:                Object value = Settings.getValue(kitClass, settingName);
190:                return (value instanceof  List) ? (List) value : defaultValue;
191:            }
192:
193:            public static List getCumulativeList(Class kitClass,
194:                    String settingName, List defaultValue) {
195:                Settings.KitAndValue[] kva = Settings.getValueHierarchy(
196:                        kitClass, settingName);
197:                if (kva != null && kva.length > 0) {
198:                    List l = new ArrayList();
199:                    for (int i = 0; i < kva.length; i++) {
200:                        if (kva[i].value instanceof  List) {
201:                            l.addAll((List) kva[i].value);
202:                        }
203:                    }
204:                    return l;
205:                } else {
206:                    return defaultValue;
207:                }
208:            }
209:
210:            public static Map getMap(Class kitClass, String settingName,
211:                    Map defaultValue) {
212:                Object value = Settings.getValue(kitClass, settingName);
213:                return (value instanceof  Map) ? (Map) value : defaultValue;
214:            }
215:
216:            public static void updateListSetting(Class kitClass,
217:                    String settingName, Object[] addToList) {
218:                if (addToList != null && addToList.length > 0) {
219:                    List l = getClonedList(kitClass, settingName);
220:                    l.addAll(Arrays.asList(addToList));
221:                    Settings.setValue(kitClass, settingName, l);
222:                }
223:            }
224:
225:            public static void updateListSetting(Map settingsMap,
226:                    String settingName, Object[] addToList) {
227:                if (settingsMap != null && addToList != null
228:                        && addToList.length > 0) {
229:                    List l = getClonedList(settingsMap, settingName);
230:                    l.addAll(Arrays.asList(addToList));
231:                    settingsMap.put(settingName, l);
232:                }
233:            }
234:
235:            private static String getColoringSettingName(String coloringName,
236:                    boolean printingSet) {
237:                return (coloringName + (printingSet ? SettingsNames.COLORING_NAME_PRINT_SUFFIX
238:                        : SettingsNames.COLORING_NAME_SUFFIX)).intern();
239:            }
240:
241:            /**
242:             * @deprecated Use Editor Settings API instead.
243:             */
244:            public static Coloring getColoring(Class kitClass,
245:                    String coloringName, boolean printingSet) {
246:                return (Coloring) getColoring(kitClass, coloringName,
247:                        printingSet, true);
248:            }
249:
250:            /**
251:             * @deprecated Use Editor Settings API instead.
252:             */
253:            public static Object getColoring(Class kitClass,
254:                    String coloringName, boolean printingSet,
255:                    boolean evaluateEvaluators) {
256:                return Settings.getValue(kitClass, getColoringSettingName(
257:                        coloringName, printingSet), evaluateEvaluators);
258:            }
259:
260:            /**
261:             * @deprecated Use Editor Settings API instead.
262:             */
263:            public static Coloring getTokenColoring(TokenContextPath tcp,
264:                    TokenCategory tokenIDOrCategory, boolean printingSet) {
265:                return (Coloring) getTokenColoring(tcp, tokenIDOrCategory,
266:                        printingSet, true);
267:            }
268:
269:            /**
270:             * @deprecated Use Editor Settings API instead.
271:             */
272:            public static Object getTokenColoring(TokenContextPath tcp,
273:                    TokenCategory tokenIDOrCategory, boolean printingSet,
274:                    boolean evaluateEvaluators) {
275:                return getColoring(BaseKit.class, tcp
276:                        .getFullTokenName(tokenIDOrCategory), printingSet,
277:                        evaluateEvaluators);
278:            }
279:
280:            /** 
281:             * Get the coloring setting from the map that holds the settings values
282:             * for the particular kit.
283:             * 
284:             * @param settingsMap map that holds the [setting-name, setting-value] pairs
285:             *  for some kit-class.
286:             * @param coloringName name of the coloring to retrieve
287:             * @param printingSet retrieve the value of printing coloring
288:             *  instead of component coloring.
289:             */
290:            public static Object getColoring(Map settingsMap,
291:                    String coloringName, boolean printingSet) {
292:                return settingsMap.get(getColoringSettingName(coloringName,
293:                        printingSet));
294:            }
295:
296:            /**
297:             * @deprecated Use Editor Settings Storage API instead.
298:             */
299:            public static void setColoring(Class kitClass, String coloringName,
300:                    Object newValue, boolean printingSet) {
301:                // XXX: try harder to preserve backwards compatibility of this call
302:                //        Settings.setValue(kitClass, getColoringSettingName(coloringName, printingSet), newValue);
303:            }
304:
305:            /**
306:             * @deprecated Use Editor Settings Storage API instead.
307:             */
308:            public static void setColoring(Class kitClass, String coloringName,
309:                    Object componentColoringNewValue) {
310:                setColoring(kitClass, coloringName, componentColoringNewValue,
311:                        false);
312:                //         setColoring(kitClass, coloringName, defaultPrintColoringEvaluator, true);
313:            }
314:
315:            /**
316:             * @deprecated Use Editor Settings Storage API instead.
317:             */
318:            public static void setColoring(Class kitClass, String coloringName,
319:                    Object componentColoringNewValue,
320:                    Object printColoringNewValue) {
321:                setColoring(kitClass, coloringName, componentColoringNewValue,
322:                        false);
323:                //        setColoring(kitClass, coloringName, printColoringNewValue, true);
324:            }
325:
326:            /** 
327:             * Put the coloring into a map holding the settings for the particular kit.
328:             */
329:            public static void setColoring(Map settingsMap,
330:                    String coloringName, Object newValue, boolean printingSet) {
331:                settingsMap.put(getColoringSettingName(coloringName,
332:                        printingSet), newValue);
333:            }
334:
335:            /** 
336:             * Put the coloring into a map holding the settings for the particular kit and assign
337:             * a default print coloring Evaluator to the print coloring setting.
338:             */
339:            public static void setColoring(Map settingsMap,
340:                    String coloringName, Object componentColoringNewValue) {
341:                setColoring(settingsMap, coloringName,
342:                        componentColoringNewValue, false);
343:                //        setColoring(settingsMap, coloringName, defaultPrintColoringEvaluator, true);
344:            }
345:
346:            /**
347:             */
348:            public static void setColoring(Map settingsMap,
349:                    String coloringName, Object componentColoringNewValue,
350:                    Object printColoringNewValue) {
351:                setColoring(settingsMap, coloringName,
352:                        componentColoringNewValue, false);
353:                //        setColoring(settingsMap, coloringName, printColoringNewValue, true);
354:            }
355:
356:            /**
357:             * Tries to gather all colorings defined for the kit's mime type. If the
358:             * mime type can't be determined from the editor kit's class passed in, this
359:             * method will try to load colorings defined for the empty mime path (ie. all
360:             * languages).
361:             * 
362:             * @param kitClass The kit class for which the colorings should be loaded.
363:             * @param printingSet Ignored.
364:             * @param evaluateEvaluators Ignored.
365:             * 
366:             * @return The map with all colorings defined for the mime type of the editor
367:             *   kit class passed in. The returned map may be inaccurate, please use 
368:             *   the new Editor Settings API and its <code>FontColorSettings</code> class.
369:             * 
370:             * @deprecated Use Editor Settings API instead.
371:             */
372:            public static Map<String, Coloring> getColoringMap(Class kitClass,
373:                    boolean printingSet, boolean evaluateEvaluators) {
374:                String mimeType = BaseKit.kitsTracker_FindMimeType(kitClass);
375:                Map<String, Coloring> cm = ColoringMap.get(mimeType).getMap();
376:                return new HashMap<String, Coloring>(cm);
377:            }
378:
379:            /** 
380:             * Update the settings according to the changes provided in the coloringMap.
381:             * 
382:             * @param kitClass class of the kit for which the colorings are being updated.
383:             *   Only the colorings with the names contained in <code>COLORING_NAME_LIST</code>
384:             *   will be updated for the kitClass settings. The rest is considered
385:             *   to be the token colorings so they are updated in BaseKit settings.
386:             * @param coloringMap map containing [coloring-name, coloring-value] pairs.
387:             * @param printingSet whether printing colorings should be updated instead
388:             *   of component colorings.
389:             * 
390:             * @deprecated Use Editor Settings Storage API instead.
391:             */
392:            public static void setColoringMap(Class kitClass, Map coloringMap,
393:                    boolean printingSet) {
394:                // XXX: try harder to preserve backwards compatibility of this call
395:                //
396:                //        List colNameList = getCumulativeList(kitClass, SettingsNames.COLORING_NAME_LIST, null);
397:                //        if (colNameList != null && coloringMap != null && coloringMap.size() > 0) {
398:                //            HashSet nameSet = new HashSet(colNameList);
399:                //
400:                //            for( Iterator i = coloringMap.keySet().iterator(); i.hasNext(); ) {
401:                //                String name = (String)i.next();
402:                //                Object coloring = coloringMap.get( name );
403:                //                if( nameSet.contains( name ) ) {
404:                //                    setColoring( kitClass, name, coloring, printingSet );
405:                //                } else {
406:                //                    setColoring( BaseKit.class, name, coloring, printingSet );
407:                //                }
408:                //            }
409:                //        }
410:            }
411:
412:            /** 
413:             * Create initializer that reflects the colorings given by the coloring map.
414:             * 
415:             * @param kitClass class of the kit for which the colorings will be updated
416:             *   by the initializer.
417:             *   Only the colorings with the names contained in <code>COLORING_NAME_LIST</code>
418:             *   will be updated for the kitClass settings. The rest is considered
419:             *   to be the token colorings so they are updated in BaseKit settings
420:             *   by the initializer.
421:             * @param coloringMap map containing [coloring-name, coloring-value] pairs.
422:             * @param printingSet whether printing colorings should be updated instead
423:             *   of component colorings.
424:             * @param initializerName name that will be assigned to the initializer.
425:             * 
426:             * @deprecated Use Editor Settings and Editor Settings Storage API instead.
427:             */
428:            public static Settings.Initializer getColoringMapInitializer(
429:                    Class kitClass, Map coloringMap, boolean printingSet,
430:                    String initializerName) {
431:                return new ColoringMapInitializer(kitClass, coloringMap,
432:                        printingSet, initializerName);
433:            }
434:
435:            /** 
436:             * Evaluator that translates the regular coloring to the print coloring
437:             * by the default black-and-white rules.
438:             * 
439:             * @deprecated Fonts and colors for printing are the same as those on screen.
440:             *   Use Editor Settings and Editor Settings Storage API instead.
441:             */
442:            public static class PrintColoringEvaluator implements 
443:                    Settings.Evaluator {
444:
445:                /** Translates the regular coloring to the print coloring
446:                 * @param kitClass kit class for which the coloring is being retrieved
447:                 * @param coloringName name of the coloring without the suffix
448:                 * @param componentColoring component coloring retrieved from the settings. It's provided
449:                 *   for convenience because the majority of Evaluator will derive
450:                 *   the particular print coloring from the given component coloring.
451:                 */
452:                protected Coloring getPrintColoring(Class kitClass,
453:                        String coloringName, Coloring componentColoring) {
454:                    Coloring printColoring = componentColoring;
455:                    if (printColoring != null) {
456:                        // Make the background color white
457:                        if (printColoring.getBackColor() != null) {
458:                            printColoring = Coloring.changeBackColor(
459:                                    printColoring, Color.white);
460:                        }
461:                        // Make the foreground color black
462:                        if (printColoring.getForeColor() != null) {
463:                            printColoring = Coloring.changeForeColor(
464:                                    printColoring, Color.black);
465:                        }
466:                        // Update the font height
467:                        float pfh = getPrintFontSize();
468:                        if (pfh >= 0) {
469:                            Font f = printColoring.getFont();
470:                            if (f != null) {
471:                                printColoring = Coloring.changeFont(
472:                                        printColoring, f.deriveFont(pfh));
473:                            }
474:                        }
475:                    }
476:                    return printColoring;
477:                }
478:
479:                /** Return the font size to which the coloring font should be updated.
480:                 * Negative value means not to update the coloring font.
481:                 */
482:                protected float getPrintFontSize() {
483:                    return defaultPrintFontSize;
484:                }
485:
486:                public Object getValue(Class kitClass, String settingName) {
487:                    if (settingName
488:                            .endsWith(SettingsNames.COLORING_NAME_PRINT_SUFFIX)) {
489:                        String coloringName = settingName
490:                                .substring(
491:                                        0,
492:                                        settingName.length()
493:                                                - SettingsNames.COLORING_NAME_PRINT_SUFFIX
494:                                                        .length());
495:                        Coloring c = getColoring(kitClass, coloringName, false);
496:                        return getPrintColoring(kitClass, coloringName, c);
497:                    }
498:                    return null;
499:                }
500:
501:            }
502:
503:            /** 
504:             * Print coloring Evaluator that changes the font style. It's available here
505:             * because it's often used.
506:             * 
507:             * @deprecated Fonts and colors for printing are the same as those on screen.
508:             *   Use Editor Settings and Editor Settings Storage API instead.
509:             */
510:            public static class FontStylePrintColoringEvaluator extends
511:                    PrintColoringEvaluator {
512:
513:                private int fontStyle;
514:
515:                public FontStylePrintColoringEvaluator(int fontStyle) {
516:                    this .fontStyle = fontStyle;
517:                }
518:
519:                protected Coloring getPrintColoring(Class kitClass,
520:                        String coloringName, Coloring componentColoring) {
521:                    Coloring printColoring = super .getPrintColoring(kitClass,
522:                            coloringName, componentColoring);
523:                    Font f = printColoring.getFont();
524:                    if (f != null) {
525:                        printColoring = Coloring.changeFont(printColoring, f
526:                                .deriveFont(fontStyle));
527:                    }
528:                    return printColoring;
529:                }
530:
531:            }
532:
533:            /** 
534:             * Print coloring Evaluator that changes the foreground color to the color given
535:             * in the constructor. It's available here because it's often used.
536:             * 
537:             * @deprecated Fonts and colors for printing are the same as those on screen.
538:             *   Use Editor Settings and Editor Settings Storage API instead.
539:             */
540:            public static class ForeColorPrintColoringEvaluator extends
541:                    PrintColoringEvaluator {
542:
543:                private Color foreColor;
544:
545:                public ForeColorPrintColoringEvaluator(Color foreColor) {
546:                    this .foreColor = foreColor;
547:                }
548:
549:                protected Coloring getPrintColoring(Class kitClass,
550:                        String coloringName, Coloring componentColoring) {
551:                    return Coloring.changeForeColor(super .getPrintColoring(
552:                            kitClass, coloringName, componentColoring),
553:                            foreColor);
554:                }
555:
556:            }
557:
558:            /** 
559:             * Evaluator for the token coloring. 
560:             * 
561:             * @deprecated Use Editor Settings and Editor Settings Storage API instead.
562:             */
563:            public static class TokenColoringEvaluator implements 
564:                    Settings.Evaluator, java.io.Serializable {
565:
566:                private String parentFullTokenIDName;
567:
568:                private Coloring coloring;
569:
570:                private boolean printingSet;
571:
572:                /** Create new token-coloring evaluator.
573:                 * @param tokenContextPath token-context path for which the evaluator
574:                 *  is being created. The parent path is retrieved and full token name
575:                 *  will be got on it for the token-id or category provided.
576:                 * @param tokenIDOrCategory token-id or category for which the evaluator
577:                 *  is being created.
578:                 * @param coloring additional coloring that, if non-null will be applied
579:                 *  to the coloring of the parentTokenID to form the resulting coloring.
580:                 * @param printingSet whether this evaluator is for component or printing set coloring
581:                 */
582:                public TokenColoringEvaluator(
583:                        TokenContextPath tokenContextPath,
584:                        TokenCategory tokenIDOrCategory, Coloring coloring,
585:                        boolean printingSet) {
586:                    this (tokenContextPath.getParent().getFullTokenName(
587:                            tokenIDOrCategory), coloring, printingSet);
588:                }
589:
590:                /** Create new token-coloring evaluator.
591:                 * @param parentFullTokenIDName name of the token from which is this token (for which
592:                 *  is this evaluator created) derived.
593:                 * @param coloring additional coloring that, if non-null will be applied
594:                 *  to the coloring of the parentTokenID to form the resulting coloring.
595:                 * @param printingSet whether this evaluator is for component or printing set coloring
596:                 */
597:                public TokenColoringEvaluator(String parentFullTokenIDName,
598:                        Coloring coloring, boolean printingSet) {
599:                    this .parentFullTokenIDName = parentFullTokenIDName;
600:                    this .coloring = coloring;
601:                    this .printingSet = printingSet;
602:                }
603:
604:                public Object getValue(Class kitClass, String settingName) {
605:                    Coloring ret;
606:                    ret = getColoring(BaseKit.class, parentFullTokenIDName,
607:                            printingSet);
608:
609:                    if (coloring != null) { // make change only if coloring is non-null
610:                        if (ret != null) { // parent is non-null
611:                            ret = coloring.apply(ret); // apply to parent
612:                        }
613:                    }
614:
615:                    return ret;
616:                }
617:
618:            }
619:
620:            /** 
621:             * Initializer for the token-coloring settings.
622:             * 
623:             * @deprecated Use Editor Settings and Editor Settings Storage API instead.
624:             */
625:            public static abstract class TokenColoringInitializer extends
626:                    Settings.AbstractInitializer {
627:
628:                /** Token context for which the colorings are being initialized. */
629:                private TokenContext tokenContext;
630:
631:                /** Create settings-initializer for the colorings of the tokens
632:                 * in the given context and all its context-paths. The name for the new
633:                 * initializer is composed from the prefix of the tokenContext.
634:                 * @param tokenContext context for which the colorings are being
635:                 *   initialized.
636:                 */
637:                public TokenColoringInitializer(TokenContext tokenContext) {
638:                    this (tokenContext, tokenContext.getNamePrefix()
639:                            + TOKEN_COLORING_INITIALIZER_NAME_SUFFIX);
640:                }
641:
642:                /** Create settings-initializer for the colorings of the tokens
643:                 * in the given context and all its context-paths.
644:                 * @param tokenContext context for which the colorings are being
645:                 *   initialized.
646:                 * @param initializerName name that will be given to the initializer.
647:                 */
648:                public TokenColoringInitializer(TokenContext tokenContext,
649:                        String initializerName) {
650:                    super (initializerName);
651:                    this .tokenContext = tokenContext;
652:                }
653:
654:                public void updateSettingsMap(Class kitClass, Map settingsMap) {
655:
656:                    if (kitClass == BaseKit.class) { // all token colorings on base-kit level
657:
658:                        TokenContextPath[] allPaths = tokenContext
659:                                .getAllContextPaths();
660:                        for (int i = 0; i < allPaths.length; i++) {
661:                            TokenContextPath tcp = allPaths[i]; // current path
662:
663:                            boolean printingSet = false; // process both sets
664:                            do {
665:
666:                                TokenContext firstContext = tcp.getContexts()[0];
667:                                TokenCategory[] tokenCategories = firstContext
668:                                        .getTokenCategories();
669:                                for (int j = 0; j < tokenCategories.length; j++) {
670:                                    Object catColoring = getTokenColoring(tcp,
671:                                            tokenCategories[j], printingSet);
672:                                    if (catColoring != null) {
673:                                        String fullName = tcp
674:                                                .getFullTokenName(tokenCategories[j]);
675:                                        SettingsUtil.setColoring(settingsMap,
676:                                                fullName, catColoring,
677:                                                printingSet);
678:                                    }
679:                                }
680:
681:                                // Add token-ids
682:                                TokenID[] tokenIDs = firstContext.getTokenIDs();
683:                                for (int j = 0; j < tokenIDs.length; j++) {
684:                                    Object tokenColoring = getTokenColoring(
685:                                            tcp, tokenIDs[j], printingSet);
686:                                    if (tokenColoring != null) {
687:                                        String fullName = tcp
688:                                                .getFullTokenName(tokenIDs[j]);
689:                                        SettingsUtil.setColoring(settingsMap,
690:                                                fullName, tokenColoring,
691:                                                printingSet);
692:                                    }
693:                                }
694:
695:                                printingSet = !printingSet;
696:
697:                            } while (printingSet);
698:                        }
699:                    }
700:
701:                }
702:
703:                /** Get either coloring or settings evaluator for the given target token-id.
704:                 * @param tokenContextPath token-context-path for which the coloring
705:                 *  is being created. All the context paths for the given token-context
706:                 *  are processed.
707:                 * @param tokenIDOrCategory token-id or token-category for which
708:                 *  the coloring or evaluator is being created.
709:                 * @param printingSet whether the set of the colorings used for printing
710:                 *  is created instead of the colorings used for the component coloring.
711:                 * @return either Coloring instance or an evaluator that returns a coloring.
712:                 */
713:                public abstract Object getTokenColoring(
714:                        TokenContextPath tokenContextPath,
715:                        TokenCategory tokenIDOrCategory, boolean printingSet);
716:
717:            }
718:
719:            /** 
720:             * Coloring map initializer is used when coloring map is given
721:             * and it's necessary to provide the same settings through initializer.
722:             */
723:            static class ColoringMapInitializer extends
724:                    Settings.AbstractInitializer {
725:
726:                private Class kitClass;
727:
728:                private HashMap baseKitMap;
729:
730:                private HashMap kitClassMap;
731:
732:                ColoringMapInitializer(Class kitClass, Map coloringMap,
733:                        boolean printingSet, String initializerName) {
734:
735:                    super (initializerName);
736:                    this .kitClass = kitClass;
737:                    baseKitMap = new HashMap(31);
738:                    kitClassMap = new HashMap(37);
739:
740:                    List colNameList = getCumulativeList(kitClass,
741:                            SettingsNames.COLORING_NAME_LIST, null);
742:                    if (colNameList != null && coloringMap != null
743:                            && coloringMap.size() > 0) {
744:                        HashSet nameSet = new HashSet(colNameList);
745:
746:                        for (Iterator i = coloringMap.keySet().iterator(); i
747:                                .hasNext();) {
748:                            String name = (String) i.next();
749:                            Object coloring = coloringMap.get(name);
750:                            if (nameSet.contains(name)) {
751:                                setColoring(kitClassMap, name, coloring,
752:                                        printingSet);
753:                            } else {
754:                                setColoring(baseKitMap, name, coloring,
755:                                        printingSet);
756:                            }
757:                        }
758:                    }
759:                }
760:
761:                public void updateSettingsMap(Class kitClass, Map settingsMap) {
762:
763:                    if (kitClass == BaseKit.class) {
764:                        settingsMap.putAll(baseKitMap);
765:
766:                    } else if (kitClass == this.kitClass) {
767:                        settingsMap.putAll(kitClassMap);
768:                    }
769:
770:                }
771:
772:            }
773:
774:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.