KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > semantic > ColoringManager


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.editor.semantic;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.EnumSet JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27 import org.netbeans.editor.Coloring;
28 import org.netbeans.editor.SettingsDefaults;
29
30 /**
31  *
32  * @author Jan Lahoda
33  */

34 public final class ColoringManager {
35
36     private static Map JavaDoc<ColoringAttributes, Coloring> type2Coloring;
37
38     private static final Font JavaDoc ITALIC = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
39     private static final Font JavaDoc BOLD = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
40     private static final Font JavaDoc BOLDITALIC = SettingsDefaults.defaultFont.deriveFont(Font.BOLD | Font.ITALIC);
41     
42     static {
43         type2Coloring = new HashMap JavaDoc<ColoringAttributes, Coloring>();
44         
45         type2Coloring.put(ColoringAttributes.UNUSED, new Coloring(null, 0, Color.GRAY, null));
46         type2Coloring.put(ColoringAttributes.ABSTRACT, new Coloring(null, 0, null, null));
47         type2Coloring.put(ColoringAttributes.FIELD, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, new Color JavaDoc(9, 134, 24), null));
48         type2Coloring.put(ColoringAttributes.LOCAL_VARIABLE, new Coloring(null, 0, null, null));
49         type2Coloring.put(ColoringAttributes.PARAMETER, new Coloring(null, Coloring.FONT_MODE_APPLY_STYLE, new Color JavaDoc(160, 96, 1), null));
50         type2Coloring.put(ColoringAttributes.METHOD, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, null, null));
51         type2Coloring.put(ColoringAttributes.CONSTRUCTOR, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, null, null));
52         type2Coloring.put(ColoringAttributes.CLASS, new Coloring(null, 0, null, null));
53         type2Coloring.put(ColoringAttributes.DEPRECATED, new Coloring(null, 0, null, null, null, new Color JavaDoc(64, 64, 64)));
54         type2Coloring.put(ColoringAttributes.STATIC, new Coloring(ITALIC, Coloring.FONT_MODE_APPLY_STYLE, null, null));
55         
56         type2Coloring.put(ColoringAttributes.PRIVATE, new Coloring(null, 0, null, null));
57         type2Coloring.put(ColoringAttributes.PACKAGE_PRIVATE, new Coloring(null, 0, null, null));
58         type2Coloring.put(ColoringAttributes.PROTECTED, new Coloring(null, 0, null, null));
59         type2Coloring.put(ColoringAttributes.PUBLIC, new Coloring(null, 0, null, null));
60         
61         type2Coloring.put(ColoringAttributes.TYPE_PARAMETER_DECLARATION, new Coloring(null, 0, null, Color.LIGHT_GRAY));
62         type2Coloring.put(ColoringAttributes.TYPE_PARAMETER_USE, new Coloring(null, 0, null, Color.GREEN));
63             
64         type2Coloring.put(ColoringAttributes.UNDEFINED, new Coloring(null, 0, Color.RED, null));
65         
66         type2Coloring.put(ColoringAttributes.MARK_OCCURRENCES, new Coloring(null, 0, null, new Color JavaDoc( 236, 235, 163 )));
67     }
68     
69     public static Coloring getColoring(Collection JavaDoc<ColoringAttributes> colorings) {
70         colorings = EnumSet.copyOf(colorings);
71 // System.err.println("getColoring(" + colorings + ")");
72
if (colorings.contains(ColoringAttributes.UNUSED)) {
73             colorings.removeAll(EnumSet.of(ColoringAttributes.ABSTRACT, ColoringAttributes.FIELD, ColoringAttributes.LOCAL_VARIABLE, ColoringAttributes.PARAMETER, ColoringAttributes.CLASS, ColoringAttributes.PRIVATE, ColoringAttributes.PACKAGE_PRIVATE, ColoringAttributes.PROTECTED, ColoringAttributes.PUBLIC, ColoringAttributes.UNDEFINED));
74         }
75         
76         if (colorings.contains(ColoringAttributes.UNDEFINED)) {
77             colorings.removeAll(EnumSet.of(ColoringAttributes.ABSTRACT, ColoringAttributes.FIELD, ColoringAttributes.LOCAL_VARIABLE, ColoringAttributes.PARAMETER, ColoringAttributes.CLASS, ColoringAttributes.PRIVATE, ColoringAttributes.PACKAGE_PRIVATE, ColoringAttributes.PROTECTED, ColoringAttributes.PUBLIC));
78         }
79         
80         Coloring c = new Coloring(null, 0, null, null);
81         
82         for (ColoringAttributes type : ColoringAttributes.values()) {
83 // System.err.println("type = " + type );
84
if (colorings.contains(type)) {
85 // System.err.println("type2Coloring.get(type)=" + type2Coloring.get(type));
86
Coloring remote = type2Coloring.get(type);
87                 Coloring nue = remote.apply(c);
88 // System.err.println("nue = " + nue );
89
// System.err.println("remote = " + remote );
90
// System.err.println("c = " + c );
91

92                 Font JavaDoc myFont = c.getFont();
93                 Font JavaDoc remoteFont = remote.getFont();
94                                 Font JavaDoc nueFont = null;
95                 
96                 if (myFont == null) {
97                     nueFont = remoteFont;
98                 } else {
99                     if (remoteFont == null) {
100                         nueFont = myFont;
101                     } else {
102                         int style = myFont.getStyle() | remoteFont.getStyle();
103                         
104                         nueFont = myFont.deriveFont(style);
105                     }
106                 }
107                 
108                 c = new Coloring(nueFont, Coloring.FONT_MODE_APPLY_STYLE, nue.getForeColor(), nue.getBackColor(), nue.getUnderlineColor(), nue.getStrikeThroughColor(), nue.getWaveUnderlineColor());
109                 
110 // System.err.println("c = " + c );
111
}
112         }
113         
114 // System.err.println("c = " + c );
115
return c;
116     }
117     
118 }
119
Popular Tags