KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > ColorFactory


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.core.gui.base;
18
19 import java.awt.Color JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Factory class that creates <code>Color</code> objects.
25  * The factory returns a <code>Color</code> object that should not
26  * be altered.
27  *
28  * @author redsolo
29  */

30 public class ColorFactory {
31     private static Map JavaDoc colors = new Hashtable JavaDoc();
32
33     /**
34  * Returns a <code>Color</code> object for the specified rgb value.
35  * The method returns the same object if it is accessed with the same
36  * rgb value.
37  * @param rgb the rgb value.
38  * @return a <code>Color</code> object.
39  */

40     public static Color JavaDoc getColor(int rgb) {
41         Integer JavaDoc key = new Integer JavaDoc(rgb);
42         Color JavaDoc color = (Color JavaDoc) colors.get(key);
43
44         if (color == null) {
45             color = new Color JavaDoc(rgb);
46             colors.put(key, color);
47         }
48
49         return color;
50     }
51
52     /**
53  * Clears all Colors from this factory.
54  */

55     public static void clear() {
56         colors.clear();
57     }
58 }
59
Popular Tags