KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > operations > CommitterColors


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.team.internal.ccvs.ui.operations;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.swt.graphics.RGB;
17
18
19 /**
20  * Default implementation, assigns random colors to revisions based on committer id.
21  *
22  * @since 3.2
23  */

24 final class CommitterColors {
25     
26     private static CommitterColors fInstance;
27     
28     // Fixed committer color RGBs provided by the UI Designer
29
private static final RGB[] COMMITTER_RGBs= new RGB[] {
30         new RGB(131, 150, 98), new RGB(132, 164, 118), new RGB(221, 205, 93), new RGB(199, 134, 57), new RGB(197, 123, 127),
31         new RGB(133, 166, 214), new RGB(143, 163, 54), new RGB(180, 148, 74), new RGB(139, 136, 140), new RGB(48, 135, 144),
32         new RGB(190, 93, 66), new RGB(101, 101, 217), new RGB(23, 101, 160), new RGB(72, 153, 119),
33         
34         new RGB(136, 176, 70), new RGB(123, 187, 95), new RGB(255, 230, 59), new RGB(255, 138, 1), new RGB(233, 88, 98),
35         new RGB(93, 158, 254), new RGB(175, 215, 0), new RGB(232, 168, 21), new RGB(140, 134, 142), new RGB(0, 172, 191),
36         new RGB(251, 58, 4), new RGB(63, 64, 255), new RGB(0, 104, 183), new RGB(27, 194, 130)
37     };
38     
39
40     /**
41      * Returns the committer color singleton.
42      *
43      * @return the committer color singleton
44      */

45     public static CommitterColors getDefault() {
46         if (fInstance == null)
47             fInstance= new CommitterColors();
48         return fInstance;
49     }
50
51     /** The color map. */
52     private Map JavaDoc fColors= new HashMap JavaDoc();
53
54     /** The number of colors that have been issued. */
55     private int fCount= 0;
56
57     private CommitterColors() {
58     }
59
60     /**
61      * Returns a unique color description for each string passed in. Colors for new committers are
62      * allocated to be as different as possible from the existing colors.
63      *
64      * @param committer the committers unique name
65      * @return the corresponding color
66      */

67     public RGB getCommitterRGB(String JavaDoc committer) {
68         RGB rgb= (RGB) fColors.get(committer);
69         if (rgb == null) {
70             rgb= COMMITTER_RGBs[fCount++ % COMMITTER_RGBs.length];
71             fColors.put(committer, rgb);
72         }
73         return rgb;
74     }
75
76 }
77
Popular Tags