3ea6d1be5462cbdcf745cf0488b44b8418a7053c
[jalviewjs.git] / site / swingjs / j2s / javax / swing / UIDefaults.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.util.Hashtable", "java.util.Locale"], "javax.swing.UIDefaults", ["java.lang.Boolean", "$.Error", "java.util.HashMap", "$.Vector", "java.awt.Color", "$.Dimension", "$.Font", "$.Insets", "javax.swing.Icon", "$.SwingUtilities", "javax.swing.border.Border", "javax.swing.event.SwingPropertyChangeSupport", "swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.changeSupport = null;
5 this.resourceBundles = null;
6 this.defaultLocale = null;
7 this.resourceCache = null;
8 Clazz.instantialize (this, arguments);
9 }, javax.swing, "UIDefaults", java.util.Hashtable);
10 Clazz.prepareFields (c$, function () {
11 this.defaultLocale = java.util.Locale.getDefault ();
12 });
13 Clazz.makeConstructor (c$, 
14 function () {
15 this.construct (700, .75);
16 });
17 Clazz.makeConstructor (c$, 
18 function (initialCapacity, loadFactor) {
19 Clazz.superConstructor (this, javax.swing.UIDefaults, [initialCapacity, loadFactor]);
20 this.resourceCache =  new java.util.HashMap ();
21 }, "~N,~N");
22 Clazz.makeConstructor (c$, 
23 function (keyValueList) {
24 Clazz.superConstructor (this, javax.swing.UIDefaults, [Clazz.doubleToInt (keyValueList.length / 2)]);
25 for (var i = 0; i < keyValueList.length; i += 2) {
26 Clazz.superCall (this, javax.swing.UIDefaults, "put", [keyValueList[i], keyValueList[i + 1]]);
27 }
28 }, "~A");
29 Clazz.defineMethod (c$, "get", 
30 function (key) {
31 var value = this.getFromHashtable (key);
32 return (value != null) ? value : this.getFromResourceBundle (key, null);
33 }, "~O");
34 Clazz.defineMethod (c$, "getFromHashtable", 
35  function (key) {
36 var value = Clazz.superCall (this, javax.swing.UIDefaults, "get", [key]);
37 if (value == null && (Clazz.instanceOf (key, String))) {
38 var skey = key;
39 if (skey.endsWith (".font") || skey.endsWith (".background") || skey.endsWith (".foreground")) value = Clazz.superCall (this, javax.swing.UIDefaults, "get", ["*" + skey.substring (skey.lastIndexOf ("."))]);
40 }if ((value !== javax.swing.UIDefaults.PENDING) && !(Clazz.instanceOf (value, javax.swing.UIDefaults.ActiveValue)) && !(Clazz.instanceOf (value, javax.swing.UIDefaults.LazyValue))) {
41 return value;
42 }if (!(Clazz.instanceOf (value, javax.swing.UIDefaults.ActiveValue))) {
43 return value;
44 }if (Clazz.instanceOf (value, javax.swing.UIDefaults.LazyValue)) {
45 try {
46 value = (value).createValue (this);
47 } finally {
48 if (value == null) {
49 Clazz.superCall (this, javax.swing.UIDefaults, "remove", [key]);
50 } else {
51 Clazz.superCall (this, javax.swing.UIDefaults, "put", [key, value]);
52 }}
53 } else {
54 value = (value).createValue (this);
55 }return value;
56 }, "~O");
57 Clazz.defineMethod (c$, "get", 
58 function (key, l) {
59 var value = this.getFromHashtable (key);
60 return (value != null) ? value : this.getFromResourceBundle (key, l);
61 }, "~O,java.util.Locale");
62 Clazz.defineMethod (c$, "getFromResourceBundle", 
63  function (key, l) {
64 if (this.resourceBundles == null || this.resourceBundles.isEmpty () || !(Clazz.instanceOf (key, String))) {
65 return null;
66 }if (l == null) {
67 if (this.defaultLocale == null) return null;
68  else l = this.defaultLocale;
69 }{
70 return this.getResourceCache (l).get (key);
71 }}, "~O,java.util.Locale");
72 Clazz.defineMethod (c$, "getResourceCache", 
73  function (l) {
74 return null;
75 }, "java.util.Locale");
76 Clazz.defineMethod (c$, "put", 
77 function (key, value) {
78 var oldValue = (value == null) ? Clazz.superCall (this, javax.swing.UIDefaults, "remove", [key]) : Clazz.superCall (this, javax.swing.UIDefaults, "put", [key, value]);
79 if (Clazz.instanceOf (key, String)) {
80 this.firePropertyChange (key, oldValue, value);
81 }return oldValue;
82 }, "~O,~O");
83 Clazz.defineMethod (c$, "putDefaults", 
84 function (keyValueList) {
85 for (var i = 0, max = keyValueList.length; i < max; i += 2) {
86 var value = keyValueList[i + 1];
87 if (value == null) {
88 Clazz.superCall (this, javax.swing.UIDefaults, "remove", [keyValueList[i]]);
89 } else {
90 Clazz.superCall (this, javax.swing.UIDefaults, "put", [keyValueList[i], value]);
91 }}
92 this.firePropertyChange ("UIDefaults", null, null);
93 }, "~A");
94 Clazz.defineMethod (c$, "getFont", 
95 function (key) {
96 var value = this.get (key);
97 return (Clazz.instanceOf (value, java.awt.Font)) ? value : null;
98 }, "~O");
99 Clazz.defineMethod (c$, "getFont", 
100 function (key, l) {
101 var value = this.get (key, l);
102 return (Clazz.instanceOf (value, java.awt.Font)) ? value : null;
103 }, "~O,java.util.Locale");
104 Clazz.defineMethod (c$, "getColor", 
105 function (key) {
106 var value = this.get (key);
107 return (Clazz.instanceOf (value, java.awt.Color)) ? value : null;
108 }, "~O");
109 Clazz.defineMethod (c$, "getColor", 
110 function (key, l) {
111 var value = this.get (key, l);
112 return (Clazz.instanceOf (value, java.awt.Color)) ? value : null;
113 }, "~O,java.util.Locale");
114 Clazz.defineMethod (c$, "getIcon", 
115 function (key) {
116 var value = this.get (key);
117 return (Clazz.instanceOf (value, javax.swing.Icon)) ? value : null;
118 }, "~O");
119 Clazz.defineMethod (c$, "getIcon", 
120 function (key, l) {
121 var value = this.get (key, l);
122 return (Clazz.instanceOf (value, javax.swing.Icon)) ? value : null;
123 }, "~O,java.util.Locale");
124 Clazz.defineMethod (c$, "getBorder", 
125 function (key) {
126 var value = this.get (key);
127 return (Clazz.instanceOf (value, javax.swing.border.Border)) ? value : null;
128 }, "~O");
129 Clazz.defineMethod (c$, "getBorder", 
130 function (key, l) {
131 var value = this.get (key, l);
132 return (Clazz.instanceOf (value, javax.swing.border.Border)) ? value : null;
133 }, "~O,java.util.Locale");
134 Clazz.defineMethod (c$, "getString", 
135 function (key) {
136 var value = this.get (key);
137 return (Clazz.instanceOf (value, String)) ? value : null;
138 }, "~O");
139 Clazz.defineMethod (c$, "getString", 
140 function (key, l) {
141 var value = this.get (key, l);
142 return (Clazz.instanceOf (value, String)) ? value : null;
143 }, "~O,java.util.Locale");
144 Clazz.defineMethod (c$, "getInt", 
145 function (key) {
146 var value = this.get (key);
147 return (Clazz.instanceOf (value, Integer)) ? (value).intValue () : 0;
148 }, "~O");
149 Clazz.defineMethod (c$, "getInt", 
150 function (key, l) {
151 var value = this.get (key, l);
152 return (Clazz.instanceOf (value, Integer)) ? (value).intValue () : 0;
153 }, "~O,java.util.Locale");
154 Clazz.defineMethod (c$, "getBoolean", 
155 function (key) {
156 var value = this.get (key);
157 return (Clazz.instanceOf (value, Boolean)) ? (value).booleanValue () : false;
158 }, "~O");
159 Clazz.defineMethod (c$, "getBoolean", 
160 function (key, l) {
161 var value = this.get (key, l);
162 return (Clazz.instanceOf (value, Boolean)) ? (value).booleanValue () : false;
163 }, "~O,java.util.Locale");
164 Clazz.defineMethod (c$, "getInsets", 
165 function (key) {
166 var value = this.get (key);
167 return (Clazz.instanceOf (value, java.awt.Insets)) ? value : null;
168 }, "~O");
169 Clazz.defineMethod (c$, "getInsets", 
170 function (key, l) {
171 var value = this.get (key, l);
172 return (Clazz.instanceOf (value, java.awt.Insets)) ? value : null;
173 }, "~O,java.util.Locale");
174 Clazz.defineMethod (c$, "getDimension", 
175 function (key) {
176 var value = this.get (key);
177 return (Clazz.instanceOf (value, java.awt.Dimension)) ? value : null;
178 }, "~O");
179 Clazz.defineMethod (c$, "getDimension", 
180 function (key, l) {
181 var value = this.get (key, l);
182 return (Clazz.instanceOf (value, java.awt.Dimension)) ? value : null;
183 }, "~O,java.util.Locale");
184 Clazz.defineMethod (c$, "getUIClass", 
185 function (uiClassID, uiClassLoader) {
186 try {
187 var className = this.get (uiClassID);
188 if (className != null) {
189 var cls = this.get (className);
190 if (cls == null) {
191 if (uiClassLoader == null) {
192 cls = javax.swing.SwingUtilities.loadSystemClass (className);
193 } else {
194 cls = uiClassLoader.loadClass (className);
195 }if (cls != null) {
196 this.put (className, cls);
197 }}return cls;
198 }} catch (e$$) {
199 if (Clazz.exceptionOf (e$$, ClassNotFoundException)) {
200 var e = e$$;
201 {
202 return null;
203 }
204 } else if (Clazz.exceptionOf (e$$, ClassCastException)) {
205 var e = e$$;
206 {
207 return null;
208 }
209 } else {
210 throw e$$;
211 }
212 }
213 return null;
214 }, "~S,ClassLoader");
215 Clazz.defineMethod (c$, "getUIClass", 
216 function (uiClassID) {
217 return this.getUIClass (uiClassID, null);
218 }, "~S");
219 Clazz.defineMethod (c$, "getUIError", 
220 function (msg) {
221 System.err.println ("UIDefaults.getUI() failed: " + msg);
222 try {
223 throw  new Error ();
224 } catch (e) {
225 e.printStackTrace ();
226 }
227 }, "~S");
228 Clazz.defineMethod (c$, "getUI", 
229 function (target) {
230 return swingjs.JSToolkit.getComponentUI (target);
231 }, "javax.swing.JComponent");
232 Clazz.defineMethod (c$, "addPropertyChangeListener", 
233 function (listener) {
234 if (this.changeSupport == null) {
235 this.changeSupport =  new javax.swing.event.SwingPropertyChangeSupport (this);
236 }this.changeSupport.addPropertyChangeListener (listener);
237 }, "java.beans.PropertyChangeListener");
238 Clazz.defineMethod (c$, "removePropertyChangeListener", 
239 function (listener) {
240 if (this.changeSupport != null) {
241 this.changeSupport.removePropertyChangeListener (listener);
242 }}, "java.beans.PropertyChangeListener");
243 Clazz.defineMethod (c$, "getPropertyChangeListeners", 
244 function () {
245 if (this.changeSupport == null) {
246 return  new Array (0);
247 }return this.changeSupport.getPropertyChangeListeners ();
248 });
249 Clazz.defineMethod (c$, "firePropertyChange", 
250 function (propertyName, oldValue, newValue) {
251 if (this.changeSupport != null) {
252 this.changeSupport.firePropertyChange (propertyName, oldValue, newValue);
253 }}, "~S,~O,~O");
254 Clazz.defineMethod (c$, "addResourceBundle", 
255 function (bundleName) {
256 if (bundleName == null) {
257 return;
258 }if (this.resourceBundles == null) {
259 this.resourceBundles =  new java.util.Vector (5);
260 }if (!this.resourceBundles.contains (bundleName)) {
261 this.resourceBundles.add (bundleName);
262 this.resourceCache.clear ();
263 }}, "~S");
264 Clazz.defineMethod (c$, "removeResourceBundle", 
265 function (bundleName) {
266 if (this.resourceBundles != null) {
267 this.resourceBundles.remove (bundleName);
268 }this.resourceCache.clear ();
269 }, "~S");
270 Clazz.defineMethod (c$, "setDefaultLocale", 
271 function (l) {
272 this.defaultLocale = l;
273 }, "java.util.Locale");
274 Clazz.defineMethod (c$, "getDefaultLocale", 
275 function () {
276 return this.defaultLocale;
277 });
278 Clazz.declareInterface (javax.swing.UIDefaults, "LazyValue");
279 Clazz.declareInterface (javax.swing.UIDefaults, "ActiveValue");
280 c$.PENDING = c$.prototype.PENDING =  String.instantialize ("Pending");
281 });