KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > themes > ColorDefinition


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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.ui.internal.themes;
12
13 import org.eclipse.swt.graphics.RGB;
14 import org.eclipse.ui.IPluginContribution;
15 import org.eclipse.ui.themes.ColorUtil;
16
17 /**
18  * A <code>ColorDefiniton </code> is the representation of the extensions
19  * defined by the <code>org.eclipse.ui.colorDefinitions</code> extension point.
20  *
21  * @since 3.0
22  */

23 public class ColorDefinition implements IPluginContribution,
24         IHierarchalThemeElementDefinition, ICategorizedThemeElementDefinition,
25         IEditable {
26     private String JavaDoc defaultsTo;
27
28     private String JavaDoc description;
29
30     private String JavaDoc id;
31
32     private String JavaDoc label;
33
34     private String JavaDoc pluginId;
35
36     private String JavaDoc rawValue;
37
38     private String JavaDoc categoryId;
39
40     boolean isEditable;
41
42     private RGB parsedValue;
43
44     /**
45      * Create a new instance of the receiver.
46      *
47      * @param label the label for this definition
48      * @param id the identifier for this definition
49      * @param defaultsTo the id of a definition that this definition will
50      * default to.
51      * @param value the default value of this definition, either in the form
52      * rrr,ggg,bbb or the name of an SWT color constant.
53      * @param description the description for this definition.
54      * @param pluginId the identifier of the plugin that contributed this
55      * definition.
56      */

57     public ColorDefinition(String JavaDoc label, String JavaDoc id, String JavaDoc defaultsTo,
58             String JavaDoc value, String JavaDoc categoryId, boolean isEditable,
59             String JavaDoc description, String JavaDoc pluginId) {
60
61         this.label = label;
62         this.id = id;
63         this.defaultsTo = defaultsTo;
64         this.rawValue = value;
65         this.categoryId = categoryId;
66         this.description = description;
67         this.isEditable = isEditable;
68         this.pluginId = pluginId;
69     }
70
71     /**
72      * Create a new instance of the receiver.
73      *
74      * @param original the original definition. This will be used to populate
75      * all fields except defaultsTo and value. defaultsTo will always be
76      * <code>null</code>.
77      * @param value the RGB value
78      */

79     public ColorDefinition(ColorDefinition original, RGB value) {
80
81         this.label = original.getName();
82         this.id = original.getId();
83         this.categoryId = original.getCategoryId();
84         this.description = original.getDescription();
85         this.isEditable = original.isEditable();
86         this.pluginId = original.getPluginId();
87
88         this.parsedValue = value;
89     }
90
91     /**
92      * @return the categoryId, or <code>null</code> if none was supplied.
93      */

94     public String JavaDoc getCategoryId() {
95         return categoryId;
96     }
97
98     /**
99      * @return the defaultsTo value, or <code>null</code> if none was supplied.
100      */

101     public String JavaDoc getDefaultsTo() {
102         return defaultsTo;
103     }
104
105     /**
106      * @return the description text, or <code>null</code> if none was supplied.
107      */

108     public String JavaDoc getDescription() {
109         return description;
110     }
111
112     /**
113      * @return the id of this definition. Should not be <code>null</code>.
114      */

115     public String JavaDoc getId() {
116         return id;
117     }
118
119     /**
120      * @return the label text. Should not be <code>null</code>.
121      */

122     public String JavaDoc getName() {
123         return label;
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.ui.IPluginContribution#getLocalId()
128      */

129     public String JavaDoc getLocalId() {
130         return getId();
131     }
132
133     /* (non-Javadoc)
134      * @see org.eclipse.ui.IPluginContribution#getPluginId()
135      */

136     public String JavaDoc getPluginId() {
137         return pluginId;
138     }
139
140     /**
141      * @return the value. Any SWT constants supplied to the constructor will be
142      * evaluated and converted into their RGB value.
143      */

144     public RGB getValue() {
145         if (parsedValue == null) {
146             parsedValue = ColorUtil.getColorValue(rawValue);
147         }
148         return parsedValue;
149     }
150
151     /* (non-Javadoc)
152      * @see java.lang.Object#toString()
153      */

154     public String JavaDoc toString() {
155         return getId();
156     }
157
158     /* (non-Javadoc)
159      * @see org.eclipse.ui.internal.themes.IEditable#isEditable()
160      */

161     public boolean isEditable() {
162         return isEditable;
163     }
164     
165     /* (non-Javadoc)
166      * @see java.lang.Object#equals(java.lang.Object)
167      */

168     public boolean equals(Object JavaDoc obj) {
169         if (obj instanceof ColorDefinition) {
170             return getId().equals(((ColorDefinition)obj).getId());
171         }
172         return false;
173     }
174     
175     /* (non-Javadoc)
176      * @see java.lang.Object#hashCode()
177      */

178     public int hashCode() {
179         return id.hashCode();
180     }
181 }
182
Popular Tags