001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.themes;
011:
012: import org.eclipse.jface.resource.JFaceResources;
013: import org.eclipse.jface.resource.StringConverter;
014: import org.eclipse.swt.graphics.FontData;
015: import org.eclipse.ui.internal.Workbench;
016:
017: /**
018: * The FontDefiniton is the representation of the fontDefinition
019: * from the plugin.xml of a type.
020: */
021: public class FontDefinition implements
022: IHierarchalThemeElementDefinition,
023: ICategorizedThemeElementDefinition, IEditable {
024:
025: private String label;
026:
027: private String id;
028:
029: private String defaultsTo;
030:
031: private String categoryId;
032:
033: private String description;
034:
035: private String value;
036:
037: private boolean isEditable;
038:
039: private FontData[] parsedValue;
040:
041: /**
042: * Create a new instance of the receiver.
043: *
044: * @param fontName The name display
045: * ed in the preference page.
046: * @param uniqueId The id used to refer to this definition.
047: * @param defaultsId The id of the font this defaults to.
048: * @param fontDescription The description of the font in the preference page.
049: */
050: public FontDefinition(String fontName, String uniqueId,
051: String defaultsId, String value, String categoryId,
052: boolean isEditable, String fontDescription) {
053: this .label = fontName;
054: this .id = uniqueId;
055: this .defaultsTo = defaultsId;
056: this .value = value;
057: this .categoryId = categoryId;
058: this .description = fontDescription;
059: this .isEditable = isEditable;
060: }
061:
062: /**
063: * Create a new instance of the receiver.
064: *
065: * @param originalFont the original definition. This will be used to populate
066: * all fields except defaultsTo and value. defaultsTo will always be
067: * <code>null</code>.
068: * @param datas the FontData[] value
069: */
070: public FontDefinition(FontDefinition originalFont, FontData[] datas) {
071: this .label = originalFont.getName();
072: this .id = originalFont.getId();
073: this .categoryId = originalFont.getCategoryId();
074: this .description = originalFont.getDescription();
075: this .isEditable = originalFont.isEditable();
076: this .parsedValue = datas;
077: }
078:
079: /**
080: * Returns the defaultsTo. This is the id of the text font
081: * that this font defualts to.
082: * @return String or <pre>null</pre>.
083: */
084: public String getDefaultsTo() {
085: return defaultsTo;
086: }
087:
088: /**
089: * Returns the description.
090: * @return String or <pre>null</pre>.
091: */
092: public String getDescription() {
093: return description;
094: }
095:
096: /**
097: * Returns the label.
098: * @return String
099: */
100: public String getName() {
101: return label;
102: }
103:
104: /**
105: * Returns the id.
106: * @return String
107: */
108: public String getId() {
109: return id;
110: }
111:
112: /**
113: * Returns the categoryId.
114: * @return String
115: */
116: public String 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 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: }
|