01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.examples.javaeditor.util;
11:
12: import java.util.*;
13:
14: import org.eclipse.swt.graphics.Color;
15: import org.eclipse.swt.graphics.RGB;
16: import org.eclipse.swt.widgets.Display;
17:
18: /**
19: * Manager for colors used in the Java editor
20: */
21: public class JavaColorProvider {
22:
23: public static final RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0);
24: public static final RGB SINGLE_LINE_COMMENT = new RGB(128, 128, 0);
25: public static final RGB KEYWORD = new RGB(0, 0, 128);
26: public static final RGB TYPE = new RGB(0, 0, 128);
27: public static final RGB STRING = new RGB(0, 128, 0);
28: public static final RGB DEFAULT = new RGB(0, 0, 0);
29: public static final RGB JAVADOC_KEYWORD = new RGB(0, 128, 0);
30: public static final RGB JAVADOC_TAG = new RGB(128, 128, 128);
31: public static final RGB JAVADOC_LINK = new RGB(128, 128, 128);
32: public static final RGB JAVADOC_DEFAULT = new RGB(0, 128, 128);
33:
34: protected Map fColorTable = new HashMap(10);
35:
36: /**
37: * Release all of the color resources held onto by the receiver.
38: */
39: public void dispose() {
40: Iterator e = fColorTable.values().iterator();
41: while (e.hasNext())
42: ((Color) e.next()).dispose();
43: }
44:
45: /**
46: * Return the color that is stored in the color table under the given RGB
47: * value.
48: *
49: * @param rgb the RGB value
50: * @return the color stored in the color table for the given RGB value
51: */
52: public Color getColor(RGB rgb) {
53: Color color = (Color) fColorTable.get(rgb);
54: if (color == null) {
55: color = new Color(Display.getCurrent(), rgb);
56: fColorTable.put(rgb, color);
57: }
58: return color;
59: }
60: }
|