KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > 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.retouche.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.api.gsf.ColoringAttributes;
28 import org.netbeans.editor.Coloring;
29 import org.netbeans.editor.SettingsDefaults;
30
31 /**
32  * This file is originally from Retouche, the Java Support
33  * infrastructure in NetBeans. I have modified the file as little
34  * as possible to make merging Retouche fixes back as simple as
35  * possible.
36  *
37  *
38  * @author Jan Lahoda
39  */

40 public final class ColoringManager {
41
42     private static Map JavaDoc<ColoringAttributes, Coloring> type2Coloring;
43
44     private static final Font JavaDoc ITALIC = SettingsDefaults.defaultFont.deriveFont(Font.ITALIC);
45     private static final Font JavaDoc BOLD = SettingsDefaults.defaultFont.deriveFont(Font.BOLD);
46     //private static final Font BOLDITALIC = SettingsDefaults.defaultFont.deriveFont(Font.BOLD | Font.ITALIC);
47

48     static {
49         type2Coloring = new HashMap JavaDoc<ColoringAttributes, Coloring>();
50         
51         type2Coloring.put(ColoringAttributes.UNUSED, new Coloring(null, 0, Color.GRAY, null));
52         type2Coloring.put(ColoringAttributes.ABSTRACT, new Coloring(null, 0, null, null));
53         type2Coloring.put(ColoringAttributes.FIELD, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, new Color JavaDoc(9, 134, 24), null));
54         type2Coloring.put(ColoringAttributes.LOCAL_VARIABLE, new Coloring(null, 0, null, null));
55         type2Coloring.put(ColoringAttributes.PARAMETER, new Coloring(null, Coloring.FONT_MODE_APPLY_STYLE, new Color JavaDoc(160, 96, 1), null));
56         type2Coloring.put(ColoringAttributes.METHOD, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, null, null));
57         type2Coloring.put(ColoringAttributes.CONSTRUCTOR, new Coloring(BOLD, Coloring.FONT_MODE_APPLY_STYLE, null, null));
58         type2Coloring.put(ColoringAttributes.CLASS, new Coloring(null, 0, null, null));
59         type2Coloring.put(ColoringAttributes.DEPRECATED, new Coloring(null, 0, null, null, null, new Color JavaDoc(64, 64, 64)));
60         type2Coloring.put(ColoringAttributes.STATIC, new Coloring(ITALIC, Coloring.FONT_MODE_APPLY_STYLE, null, null));
61         
62         type2Coloring.put(ColoringAttributes.PRIVATE, new Coloring(null, 0, null, null));
63         type2Coloring.put(ColoringAttributes.PACKAGE_PRIVATE, new Coloring(null, 0, null, null));
64         type2Coloring.put(ColoringAttributes.PROTECTED, new Coloring(null, 0, null, null));
65         type2Coloring.put(ColoringAttributes.PUBLIC, new Coloring(null, 0, null, null));
66         
67         type2Coloring.put(ColoringAttributes.TYPE_PARAMETER_DECLARATION, new Coloring(null, 0, null, Color.LIGHT_GRAY));
68         type2Coloring.put(ColoringAttributes.TYPE_PARAMETER_USE, new Coloring(null, 0, null, Color.GREEN));
69             
70         type2Coloring.put(ColoringAttributes.UNDEFINED, new Coloring(null, 0, Color.RED, null));
71         
72         type2Coloring.put(ColoringAttributes.MARK_OCCURRENCES, new Coloring(null, 0, null, new Color JavaDoc( 236, 235, 163 )));
73     }
74     
75     public static Coloring getColoring(Collection JavaDoc<ColoringAttributes> colorings) {
76         colorings = EnumSet.copyOf(colorings);
77 // System.err.println("getColoring(" + colorings + ")");
78
if (colorings.contains(ColoringAttributes.UNUSED)) {
79             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));
80         }
81         
82         if (colorings.contains(ColoringAttributes.UNDEFINED)) {
83             colorings.removeAll(EnumSet.of(ColoringAttributes.ABSTRACT, ColoringAttributes.FIELD, ColoringAttributes.LOCAL_VARIABLE, ColoringAttributes.PARAMETER, ColoringAttributes.CLASS, ColoringAttributes.PRIVATE, ColoringAttributes.PACKAGE_PRIVATE, ColoringAttributes.PROTECTED, ColoringAttributes.PUBLIC));
84         }
85         
86         Coloring c = new Coloring(null, 0, null, null);
87         
88         for (ColoringAttributes type : ColoringAttributes.values()) {
89 // System.err.println("type = " + type );
90
if (colorings.contains(type)) {
91 // System.err.println("type2Coloring.get(type)=" + type2Coloring.get(type));
92
Coloring remote = type2Coloring.get(type);
93                 Coloring nue = remote.apply(c);
94 // System.err.println("nue = " + nue );
95
// System.err.println("remote = " + remote );
96
// System.err.println("c = " + c );
97

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