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