KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jface.resource.JFaceResources;
14 import org.eclipse.jface.resource.StringConverter;
15 import org.eclipse.swt.graphics.FontData;
16 import org.eclipse.ui.internal.Workbench;
17
18 /**
19  * The FontDefiniton is the representation of the fontDefinition
20  * from the plugin.xml of a type.
21  */

22 public class FontDefinition implements IHierarchalThemeElementDefinition,
23         ICategorizedThemeElementDefinition, IEditable {
24
25     private String JavaDoc label;
26
27     private String JavaDoc id;
28
29     private String JavaDoc defaultsTo;
30
31     private String JavaDoc categoryId;
32
33     private String JavaDoc description;
34
35     private String JavaDoc value;
36
37     private boolean isEditable;
38
39     private FontData[] parsedValue;
40
41     /**
42      * Create a new instance of the receiver.
43      *
44      * @param fontName The name display
45      * ed in the preference page.
46      * @param uniqueId The id used to refer to this definition.
47      * @param defaultsId The id of the font this defaults to.
48      * @param fontDescription The description of the font in the preference page.
49      */

50     public FontDefinition(String JavaDoc fontName, String JavaDoc uniqueId, String JavaDoc defaultsId,
51             String JavaDoc value, String JavaDoc categoryId, boolean isEditable,
52             String JavaDoc fontDescription) {
53         this.label = fontName;
54         this.id = uniqueId;
55         this.defaultsTo = defaultsId;
56         this.value = value;
57         this.categoryId = categoryId;
58         this.description = fontDescription;
59         this.isEditable = isEditable;
60     }
61
62     /**
63      * Create a new instance of the receiver.
64      *
65      * @param originalFont the original definition. This will be used to populate
66      * all fields except defaultsTo and value. defaultsTo will always be
67      * <code>null</code>.
68      * @param datas the FontData[] value
69      */

70     public FontDefinition(FontDefinition originalFont, FontData[] datas) {
71         this.label = originalFont.getName();
72         this.id = originalFont.getId();
73         this.categoryId = originalFont.getCategoryId();
74         this.description = originalFont.getDescription();
75         this.isEditable = originalFont.isEditable();
76         this.parsedValue = datas;
77     }
78
79     /**
80      * Returns the defaultsTo. This is the id of the text font
81      * that this font defualts to.
82      * @return String or <pre>null</pre>.
83      */

84     public String JavaDoc getDefaultsTo() {
85         return defaultsTo;
86     }
87
88     /**
89      * Returns the description.
90      * @return String or <pre>null</pre>.
91      */

92     public String JavaDoc getDescription() {
93         return description;
94     }
95
96     /**
97      * Returns the label.
98      * @return String
99      */

100     public String JavaDoc getName() {
101         return label;
102     }
103
104     /**
105      * Returns the id.
106      * @return String
107      */

108     public String JavaDoc getId() {
109         return id;
110     }
111
112     /**
113      * Returns the categoryId.
114      * @return String
115      */

116     public String JavaDoc getCategoryId() {
117         return categoryId;
118     }
119
120     /**
121      * Returns the value.
122      *
123      * @return FontData []
124      */

125     public FontData[] getValue() {
126         if (value == null) {
127             return null;
128         }
129         if (parsedValue == null) {
130             parsedValue = JFaceResources.getFontRegistry().filterData(
131                     StringConverter.asFontDataArray(value),
132                     Workbench.getInstance().getDisplay());
133         }
134
135         return parsedValue;
136     }
137
138     /* (non-Javadoc)
139      * @see org.eclipse.ui.internal.themes.IEditable#isEditable()
140      */

141     public boolean isEditable() {
142         return isEditable;
143     }
144     
145     /* (non-Javadoc)
146      * @see java.lang.Object#equals(java.lang.Object)
147      */

148     public boolean equals(Object JavaDoc obj) {
149         if (obj instanceof FontDefinition) {
150             return getId().equals(((FontDefinition)obj).getId());
151         }
152         return false;
153     }
154     
155     /* (non-Javadoc)
156      * @see java.lang.Object#hashCode()
157      */

158     public int hashCode() {
159         return id.hashCode();
160     }
161 }
162
Popular Tags