KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > SemanticHighlighting


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.javaeditor;
12
13 import org.eclipse.swt.graphics.RGB;
14
15 import org.eclipse.jface.resource.ColorRegistry;
16
17 import org.eclipse.ui.PlatformUI;
18
19 import org.eclipse.jdt.ui.JavaUI;
20
21
22 /**
23  * Semantic highlighting
24  */

25 public abstract class SemanticHighlighting {
26
27     /**
28      * @return the preference key, will be augmented by a prefix and a suffix for each preference
29      */

30     public abstract String JavaDoc getPreferenceKey();
31
32     /**
33      * @return the default default text color
34      * @since 3.3
35      */

36     public abstract RGB getDefaultDefaultTextColor();
37     
38     /**
39      * @return the default default text color
40      */

41     public RGB getDefaultTextColor() {
42         return findRGB(getThemeColorKey(), getDefaultDefaultTextColor());
43     }
44
45     /**
46      * @return <code>true</code> if the text attribute bold is set by default
47      */

48     public abstract boolean isBoldByDefault();
49
50     /**
51      * @return <code>true</code> if the text attribute italic is set by default
52      */

53     public abstract boolean isItalicByDefault();
54
55     /**
56      * @return <code>true</code> if the text attribute strikethrough is set by default
57      * @since 3.1
58      */

59     public boolean isStrikethroughByDefault() {
60         return false;
61     }
62
63     /**
64      * @return <code>true</code> if the text attribute underline is set by default
65      * @since 3.1
66      */

67     public boolean isUnderlineByDefault() {
68         return false;
69     }
70
71     /**
72      * @return <code>true</code> if the text attribute italic is enabled by default
73      */

74     public abstract boolean isEnabledByDefault();
75
76     /**
77      * @return the display name
78      */

79     public abstract String JavaDoc getDisplayName();
80
81     /**
82      * Returns <code>true</code> iff the semantic highlighting consumes the semantic token.
83      * <p>
84      * NOTE: Implementors are not allowed to keep a reference on the token or on any object
85      * retrieved from the token.
86      * </p>
87      *
88      * @param token the semantic token for a {@link org.eclipse.jdt.core.dom.SimpleName}
89      * @return <code>true</code> iff the semantic highlighting consumes the semantic token
90      */

91     public abstract boolean consumes(SemanticToken token);
92     
93     /**
94      * Returns <code>true</code> iff the semantic highlighting consumes the
95      * semantic token.
96      * <p>
97      * NOTE: Implementors are not allowed to keep a reference on the token or on
98      * any object retrieved from the token.
99      * </p>
100      * @param token the semantic token for a
101      * {@link org.eclipse.jdt.core.dom.NumberLiteral},
102      * {@link org.eclipse.jdt.core.dom.BooleanLiteral} or
103      * {@link org.eclipse.jdt.core.dom.CharacterLiteral}
104      * @return <code>true</code> iff the semantic highlighting consumes the
105      * semantic token
106      */

107     public boolean consumesLiteral(SemanticToken token) {
108         return false;
109     }
110     
111     private String JavaDoc getThemeColorKey() {
112         return JavaUI.ID_PLUGIN + "." + getPreferenceKey() + "Highlighting"; //$NON-NLS-1$//$NON-NLS-2$
113
}
114     
115     /**
116      * Returns the RGB for the given key in the given color registry.
117      *
118      * @param key the key for the constant in the registry
119      * @param defaultRGB the default RGB if no entry is found
120      * @return RGB the RGB
121      * @since 3.3
122      */

123     private static RGB findRGB(String JavaDoc key, RGB defaultRGB) {
124         if (!PlatformUI.isWorkbenchRunning())
125             return defaultRGB;
126         
127         ColorRegistry registry= PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
128         RGB rgb= registry.getRGB(key);
129         if (rgb != null)
130             return rgb;
131         return defaultRGB;
132     }
133     
134 }
135
Popular Tags