blob: a28e21da9fd68758e80c12ae229a8cedf65e6d8d [file] [log] [blame]
nitind958d79a2004-11-23 19:23:00 +00001/*******************************************************************************
2 * Copyright (c) 2004 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 *******************************************************************************/
11package org.eclipse.wst.css.core.internal.contentmodel;
12
13
14
15import java.util.Collection;
16import java.util.Enumeration;
17import java.util.HashSet;
18import java.util.Hashtable;
19import java.util.Iterator;
20import java.util.List;
21import java.util.Vector;
22
23/**
24 *
25 */
26public class PropCMFontProperty extends PropCMProperty {
27
28 // static fields
29 private static java.util.Hashtable instances = null;
30 private static java.util.Hashtable cachedIdMap = null;
31 // selecting properties
32 public final static String PF_FONT_FAMILY = "font-family";//$NON-NLS-1$
33 public final static String PF_FONT_STYLE = "font-style";//$NON-NLS-1$
34 public final static String PF_FONT_VARIANT = "font-variant";//$NON-NLS-1$
35 public final static String PF_FONT_WEIGHT = "font-weight";//$NON-NLS-1$
36 public final static String PF_FONT_STRETCH = "font-stretch";//$NON-NLS-1$
37 public final static String PF_FONT_SIZE = "font-size";//$NON-NLS-1$
38 // qualification properties
39 public final static String PF_UNICODE_RANGE = "unicode-range";//$NON-NLS-1$
40 // numeric properties
41 public final static String PF_UNITS_PER_EM = "units-per-em";//$NON-NLS-1$
42 // referencing properties
43 public final static String PF_SRC = "src";//$NON-NLS-1$
44 // matching properties
45 public final static String PF_PANOSE_1 = "panose-1";//$NON-NLS-1$
46 public final static String PF_STEMV = "stemv";//$NON-NLS-1$
47 public final static String PF_STEMH = "stemh";//$NON-NLS-1$
48 public final static String PF_SLOPE = "slope";//$NON-NLS-1$
49 public final static String PF_CAP_HEIGHT = "cap-height";//$NON-NLS-1$
50 public final static String PF_X_HEIGHT = "x-height";//$NON-NLS-1$
51 public final static String PF_ASCENT = "ascent";//$NON-NLS-1$
52 public final static String PF_DESCENT = "descent";//$NON-NLS-1$
53 // synthesis properties
54 public final static String PF_WIDTHS = "widths";//$NON-NLS-1$
55 public final static String PF_BBOX = "bbox";//$NON-NLS-1$
56 public final static String PF_DEFINITION_SRC = "definition-src";//$NON-NLS-1$
57 // alignment properties
58 public final static String PF_BASELINE = "baseline";//$NON-NLS-1$
59 public final static String PF_CENTERLINE = "centerline";//$NON-NLS-1$
60 public final static String PF_MATHLINE = "mathline";//$NON-NLS-1$
61 public final static String PF_TOPLINE = "topline";//$NON-NLS-1$
62
63 /**
64 *
65 */
66 protected PropCMFontProperty(String name) {
67 super(name);
68 }
69
70 /**
71 *
72 */
73 public static PropCMProperty getInstanceOf(String name) {
74 // initialize
75 if (instances == null)
76 instances = new Hashtable(10);
77
78 // Initialize of DB
79 if (isNeedInitialize())
80 PropCMNode.initPropertyCM();
81
82 // query
83 Object node = instances.get(name);
84 if (node != null)
85 return (PropCMProperty) node;
86
87 // register
88 if (PropCMNode.isLoading()) {
89 node = new PropCMFontProperty(name);
90 instances.put(name, node);
91 }
92
93 return (PropCMProperty) node;
94 }
95
96 /**
97 *
98 */
99 public static Enumeration getNameEnum() {
100 // Initialize of DB
101 if (isNeedInitialize())
102 PropCMNode.initPropertyCM();
103
104 return instances.keys();
105 }
106
107 /**
108 *
109 */
110 public static Enumeration getPropertyEnum() {
111 // Initialize of DB
112 if (isNeedInitialize())
113 PropCMNode.initPropertyCM();
114
115 return instances.elements();
116 }
117
118 /**
119 *
120 */
121 public short getType() {
122 return VAL_FONTPROPERTY;
123 }
124
125 /**
126 *
127 */
128 public static Vector names() {
129 // Initialize of DB
130 if (isNeedInitialize())
131 PropCMNode.initPropertyCM();
132
133 return new Vector(instances.keySet());
134 }
135
136 /**
137 *
138 */
139 public static List names(Object mediaGroup) {
140 if (mediaGroup == null)
141 return names();
142
143 // Initialize of DB
144 if (isNeedInitialize())
145 PropCMNode.initPropertyCM();
146
147 Vector properties = new Vector();
148
149 Iterator it = instances.values().iterator();
150 while (it.hasNext()) {
151 PropCMProperty prop = (PropCMProperty) it.next();
152 if (prop.getMediaGroups().contains(mediaGroup))
153 properties.add(prop.getName());
154 }
155
156 return properties;
157 }
158
159 /**
160 * If itentifier is null, get all properties
161 */
162 public static Vector propertiesFor(String identifier, boolean shorthands) {
163 // Initialize of DB
164 if (isNeedInitialize())
165 PropCMNode.initPropertyCM();
166
167 // if identifier is null, get all properties
168 if (identifier == null)
169 return new Vector(instances.values());
170
171 if (cachedIdMap == null) {
172 // start cacheing
173 cachedIdMap = new Hashtable();
174 }
175 else {
176 // search cached
177 Object ret = cachedIdMap.get(identifier + String.valueOf(shorthands));
178 if (ret != null)
179 return new Vector((Collection) ret);
180 }
181
182 // create
183 Enumeration properties = getPropertyEnum();
184 HashSet set = new HashSet();
185 while (properties.hasMoreElements()) {
186 PropCMProperty prop = (PropCMProperty) properties.nextElement();
187 if (!shorthands && prop.isShorthand())
188 continue;
189 if (prop.canHave(identifier))
190 set.add(prop);
191 }
192
193 // cache
194 cachedIdMap.put(identifier + String.valueOf(shorthands), set);
195
196 return new Vector(set);
197 }
198}