fc8f00e0b0e99fbb2968fb05ba1ba19030df043d
[jalviewjs.git] / site / j2s / swingjs / plaf / JSComponentUI.js
1 Clazz.declarePackage ("swingjs.plaf");\r
2 Clazz.load (["javax.swing.plaf.ComponentUI", "swingjs.plaf.JSEventHandler"], "swingjs.plaf.JSComponentUI", ["java.lang.IllegalArgumentException", "$.NullPointerException", "java.awt.Color", "$.Component", "$.Dimension", "$.Point", "$.Toolkit", "java.awt.event.FocusEvent", "swingjs.JSToolkit", "swingjs.api.DOMNode"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.id = null;\r
5 this.c = null;\r
6 this.outerNode = null;\r
7 this.domNode = null;\r
8 this.enableNode = null;\r
9 this.textNode = null;\r
10 this.valueNode = null;\r
11 this.scrollNode = null;\r
12 this.focusNode = null;\r
13 this.components = null;\r
14 this.num = 0;\r
15 this.isTainted = true;\r
16 this.x = 0;\r
17 this.y = 0;\r
18 this.preferredSize = null;\r
19 this.isContainer = false;\r
20 this.parent = null;\r
21 this.currentText = null;\r
22 this.scrollerNode = null;\r
23 this.classID = null;\r
24 this.document = null;\r
25 this.body = null;\r
26 this.needPreferred = false;\r
27 Clazz.instantialize (this, arguments);\r
28 }, swingjs.plaf, "JSComponentUI", javax.swing.plaf.ComponentUI, swingjs.plaf.JSEventHandler);\r
29 Clazz.makeConstructor (c$, \r
30 function () {\r
31 Clazz.superConstructor (this, swingjs.plaf.JSComponentUI, []);\r
32 this.setDoc ();\r
33 });\r
34 Clazz.defineMethod (c$, "setDoc", \r
35 function () {\r
36 {\r
37 this.document = document;\r
38 this.body = document.body;\r
39 }});\r
40 Clazz.overrideMethod (c$, "installUI", \r
41 function (c) {\r
42 }, "javax.swing.JComponent");\r
43 Clazz.overrideMethod (c$, "uninstallUI", \r
44 function (c) {\r
45 this.uninstallJSUI ();\r
46 }, "javax.swing.JComponent");\r
47 Clazz.defineMethod (c$, "$", \r
48 function (node) {\r
49 return swingjs.JSToolkit.getJQuery ().$ (node);\r
50 }, "swingjs.api.DOMNode");\r
51 Clazz.defineMethod (c$, "setTainted", \r
52 function () {\r
53 this.isTainted = true;\r
54 });\r
55 Clazz.defineMethod (c$, "set", \r
56 function (target) {\r
57 this.c = target;\r
58 this.newID ();\r
59 if (this.needPreferred) this.getPreferredSize (this.c);\r
60 this.installJSUI ();\r
61 return this;\r
62 }, "javax.swing.JComponent");\r
63 Clazz.defineMethod (c$, "newID", \r
64 function () {\r
65 this.classID = this.c.getUIClassID ();\r
66 if (this.id == null) {\r
67 this.num = ++swingjs.plaf.JSComponentUI.incr;\r
68 this.id = this.c.getHTMLName (this.classID) + "_" + this.num;\r
69 }});\r
70 Clazz.defineMethod (c$, "setCssFont", \r
71 function (obj, font) {\r
72 if (font != null) {\r
73 var istyle = font.getStyle ();\r
74 var name = font.getFamily ();\r
75 if (name === "Dialog") name = "Arial";\r
76 swingjs.api.DOMNode.setStyles (obj, ["font-family", name, "font-size", font.getSize () + "px", "font-style", ((istyle & 2) == 0 ? "normal" : "italic"), "font-weight", ((istyle & 1) == 0 ? "normal" : "bold")]);\r
77 }if (this.c.isBackgroundSet ()) this.setBackground (this.c.getBackground ());\r
78 this.setForeground (this.c.getForeground ());\r
79 return obj;\r
80 }, "swingjs.api.DOMNode,java.awt.Font");\r
81 Clazz.defineMethod (c$, "createDOMObject", \r
82 function (key, id, attr) {\r
83 var obj = swingjs.api.DOMNode.createElement (key, id);\r
84 for (var i = 0; i < attr.length; ) swingjs.api.DOMNode.setAttr (obj, attr[i++], attr[i++]);\r
85 \r
86 if (!this.c.isEnabled ()) this.setEnabled (false);\r
87 return obj;\r
88 }, "~S,~S,~A");\r
89 Clazz.defineMethod (c$, "bindMouse", \r
90 function (node) {\r
91 swingjs.api.DOMNode.setAttr (node, "data-UI", this);\r
92 }, "swingjs.api.DOMNode");\r
93 Clazz.overrideMethod (c$, "handleJSEvent", \r
94 function (target, eventType, jQueryEvent) {\r
95 return false;\r
96 }, "~O,~N,~O");\r
97 Clazz.defineMethod (c$, "wrap", \r
98 function (type, id, elements) {\r
99 return this.append (this.createDOMObject (type, id + type, []), elements);\r
100 }, "~S,~S,~A");\r
101 Clazz.defineMethod (c$, "append", \r
102 function (obj, elements) {\r
103 for (var i = 0; i < elements.length; i++) {\r
104 obj.appendChild (elements[i]);\r
105 }\r
106 return obj;\r
107 }, "swingjs.api.DOMNode,~A");\r
108 Clazz.defineMethod (c$, "debugDump", \r
109 function (d) {\r
110 System.out.println (swingjs.api.DOMNode.getAttr (d, "outerHTML"));\r
111 }, "swingjs.api.DOMNode");\r
112 c$.vCenter = Clazz.defineMethod (c$, "vCenter", \r
113 function (obj, offset) {\r
114 swingjs.api.DOMNode.setStyles (obj, ["top", "50%", "transform", "translateY(" + offset + "%)"]);\r
115 }, "swingjs.api.DOMNode,~N");\r
116 Clazz.defineMethod (c$, "setHTMLSize", \r
117 function (obj, addCSS) {\r
118 return this.setHTMLSize1 (obj, addCSS, true);\r
119 }, "swingjs.api.DOMNode,~B");\r
120 Clazz.defineMethod (c$, "setHTMLSize1", \r
121 function (node, addCSS, usePreferred) {\r
122 if (node == null) return null;\r
123 var h;\r
124 var w;\r
125 var w0 = null;\r
126 var h0 = null;\r
127 var parentNode = null;\r
128 if (this.scrollerNode != null) {\r
129 w = this.scrollerNode.c.getWidth ();\r
130 h = this.scrollerNode.c.getHeight ();\r
131 } else if (usePreferred && this.preferredSize != null) {\r
132 w = this.preferredSize.width;\r
133 h = this.preferredSize.height;\r
134 } else {\r
135 parentNode = swingjs.api.DOMNode.remove (node);\r
136 {\r
137 w0 = node.style.width;\r
138 h0 = node.style.height;\r
139 }swingjs.api.DOMNode.setStyles (node, ["position", null, "width", null, "height", null]);\r
140 var div;\r
141 if (swingjs.api.DOMNode.getAttr (node, "tagName") === "DIV") div = node;\r
142  else div = this.wrap ("div", this.id + "_temp", [node]);\r
143 swingjs.api.DOMNode.setStyles (div, ["position", "absolute"]);\r
144 this.body.appendChild (div);\r
145 w = Clazz.doubleToInt (Math.ceil (this.$ (div).width () + 0.5));\r
146 h = Clazz.doubleToInt (Math.ceil (this.$ (div).height () + 0.5));\r
147 this.body.removeChild (div);\r
148 }var size = this.getCSSDimension (w, h);\r
149 if (addCSS) {\r
150 swingjs.api.DOMNode.setStyles (node, ["position", "absolute"]);\r
151 swingjs.api.DOMNode.setSize (node, size.width, size.height);\r
152 } else {\r
153 swingjs.api.DOMNode.setStyles (node, ["position", null]);\r
154 if (w0 != null) swingjs.api.DOMNode.setStyles (node, ["width", w0, "height", h0]);\r
155 }if (parentNode != null) parentNode.appendChild (node);\r
156 return size;\r
157 }, "swingjs.api.DOMNode,~B,~B");\r
158 Clazz.defineMethod (c$, "getCSSDimension", \r
159 function (w, h) {\r
160 return  new java.awt.Dimension (w, h);\r
161 }, "~N,~N");\r
162 Clazz.defineMethod (c$, "setHTMLElement", \r
163 function () {\r
164 if (!this.isTainted) return this.outerNode;\r
165 var root = (this.isContainer ? this.c.getRootPane () : null);\r
166 if (this.c === root) {\r
167 this.isTainted = false;\r
168 return this.outerNode;\r
169 }this.domNode = this.getDOMObject ();\r
170 if (this.outerNode == null) {\r
171 this.outerNode = this.wrap ("div", this.id, [this.domNode]);\r
172 if (root != null && root.getContentPane () === this.c) swingjs.JSToolkit.getHTML5Applet (this.c)._getContentLayer ().appendChild (this.outerNode);\r
173 }swingjs.api.DOMNode.setStyles (this.outerNode, ["position", "absolute", "left", (this.x = this.c.getX ()) + "px", "top", (this.y = this.c.getY ()) + "px"]);\r
174 if (this.isContainer) {\r
175 System.out.println ("JSComponentUI container " + this.id + " " + this.c.getBounds ());\r
176 swingjs.api.DOMNode.setSize (this.outerNode, this.c.getWidth (), this.c.getHeight ());\r
177 var children = (this.components == null ? this.c.getComponents () : this.components);\r
178 for (var i = children.length; --i >= 0; ) {\r
179 var ui = swingjs.JSToolkit.getUI (children[i], false);\r
180 if (ui == null) {\r
181 continue;\r
182 }if (ui.outerNode == null) ui.setHTMLElement ();\r
183 if (ui.outerNode == null) {\r
184 System.out.println ("JSCUI could not add " + ui.c.getName () + " to " + this.c.getName ());\r
185 } else {\r
186 this.outerNode.appendChild (ui.outerNode);\r
187 }ui.parent = this;\r
188 }\r
189 }this.isTainted = false;\r
190 return this.outerNode;\r
191 });\r
192 Clazz.defineMethod (c$, "getPreferredSize", \r
193 function (c) {\r
194 var d = this.setHTMLSize (this.getDOMObject (), false);\r
195 return d;\r
196 }, "javax.swing.JComponent");\r
197 Clazz.defineMethod (c$, "paint", \r
198 function (g, c) {\r
199 if (c.isOpaque ()) {\r
200 g.setColor (c.getBackground ());\r
201 g.fillRect (0, 0, c.getWidth (), c.getHeight ());\r
202 }}, "java.awt.Graphics,javax.swing.JComponent");\r
203 Clazz.overrideMethod (c$, "update", \r
204 function (g, c) {\r
205 var testing = false;\r
206 if (testing) {\r
207 g.setColor (java.awt.Color.red);\r
208 g.drawRect (0, 0, c.getWidth (), c.getHeight ());\r
209 System.out.println ("drawing " + c.getWidth () + " " + c.getHeight ());\r
210 }this.setHTMLElement ();\r
211 this.paint (g, c);\r
212 }, "java.awt.Graphics,javax.swing.JComponent");\r
213 Clazz.defineMethod (c$, "getMinimumSize", \r
214 function (c) {\r
215 return this.getPreferredSize (c);\r
216 }, "javax.swing.JComponent");\r
217 Clazz.overrideMethod (c$, "getMaximumSize", \r
218 function (c) {\r
219 return null;\r
220 }, "javax.swing.JComponent");\r
221 Clazz.overrideMethod (c$, "contains", \r
222 function (c, x, y) {\r
223 return c.inside (x, y);\r
224 }, "javax.swing.JComponent,~N,~N");\r
225 c$.createUI = Clazz.overrideMethod (c$, "createUI", \r
226 function (c) {\r
227 return null;\r
228 }, "javax.swing.JComponent");\r
229 Clazz.overrideMethod (c$, "getBaseline", \r
230 function (c, width, height) {\r
231 if (c == null) {\r
232 throw  new NullPointerException ("Component must be non-null");\r
233 }if (width < 0 || height < 0) {\r
234 throw  new IllegalArgumentException ("Width and height must be >= 0");\r
235 }return -1;\r
236 }, "javax.swing.JComponent,~N,~N");\r
237 Clazz.overrideMethod (c$, "getBaselineResizeBehavior", \r
238 function (c) {\r
239 if (c == null) {\r
240 throw  new NullPointerException ("Component must be non-null");\r
241 }return java.awt.Component.BaselineResizeBehavior.OTHER;\r
242 }, "javax.swing.JComponent");\r
243 Clazz.defineMethod (c$, "getJSTextValue", \r
244 function () {\r
245 return swingjs.api.DOMNode.getAttr (this.domNode, this.valueNode == null ? "innerHTML" : "value");\r
246 });\r
247 Clazz.defineMethod (c$, "notifyPropertyChanged", \r
248 function (prop) {\r
249 var obj = null;\r
250 var val = null;\r
251 if (prop === "text") {\r
252 val = (this.c).getText ();\r
253 if (val.equals (this.currentText)) return;\r
254 this.currentText = val;\r
255 if (this.textNode != null) {\r
256 prop = "innerHTML";\r
257 obj = this.textNode;\r
258 } else if (this.valueNode != null) {\r
259 prop = "value";\r
260 obj = this.valueNode;\r
261 }} else if (prop === "preferredSize") {\r
262 this.preferredSize = this.c.getPreferredSize ();\r
263 this.getPreferredSize ();\r
264 return;\r
265 }if (obj == null) {\r
266 System.out.println ("JSComponentUI: unrecognized prop: " + prop);\r
267 } else {\r
268 System.out.println ("JSComponentUI: setting " + this.id + " " + prop);\r
269 this.setProp (obj, prop, val);\r
270 }}, "~S");\r
271 Clazz.defineMethod (c$, "setProp", \r
272 function (obj, prop, val) {\r
273 return swingjs.api.DOMNode.setAttr (obj, prop, val);\r
274 }, "swingjs.api.DOMNode,~S,~S");\r
275 Clazz.overrideMethod (c$, "isObscured", \r
276 function () {\r
277 swingjs.JSToolkit.notImplemented ("");\r
278 return false;\r
279 });\r
280 Clazz.overrideMethod (c$, "canDetermineObscurity", \r
281 function () {\r
282 swingjs.JSToolkit.notImplemented ("");\r
283 return false;\r
284 });\r
285 Clazz.overrideMethod (c$, "setVisible", \r
286 function (b) {\r
287 swingjs.api.DOMNode.setStyles (this.outerNode, ["display", b ? "block" : "none"]);\r
288 }, "~B");\r
289 Clazz.overrideMethod (c$, "setEnabled", \r
290 function (b) {\r
291 if (this.enableNode != null) swingjs.api.DOMNode.setAttr (this.enableNode, "disabled", (b ? null : "TRUE"));\r
292 }, "~B");\r
293 Clazz.defineMethod (c$, "paint", \r
294 function (g) {\r
295 }, "java.awt.Graphics");\r
296 Clazz.overrideMethod (c$, "repaint", \r
297 function (tm, x, y, width, height) {\r
298 }, "~N,~N,~N,~N,~N");\r
299 Clazz.overrideMethod (c$, "print", \r
300 function (g) {\r
301 swingjs.JSToolkit.notImplemented ("");\r
302 }, "java.awt.Graphics");\r
303 Clazz.overrideMethod (c$, "setBounds", \r
304 function (x, y, width, height, op) {\r
305 switch (op) {\r
306 case 2:\r
307 case 3:\r
308 case 4:\r
309 if (this.scrollerNode != null) {\r
310 width = Math.min (width, this.scrollerNode.c.getWidth ());\r
311 height = Math.min (height, this.scrollerNode.c.getHeight ());\r
312 }System.out.println (this.id + " setBounds " + x + " " + y + " " + width + " " + height + " op=" + op);\r
313 if (this.domNode != null) swingjs.api.DOMNode.setSize (this.domNode, width, height);\r
314 break;\r
315 }\r
316 }, "~N,~N,~N,~N,~N");\r
317 Clazz.overrideMethod (c$, "handleEvent", \r
318 function (e) {\r
319 swingjs.JSToolkit.notImplemented ("");\r
320 }, "java.awt.AWTEvent");\r
321 Clazz.overrideMethod (c$, "coalescePaintEvent", \r
322 function (e) {\r
323 swingjs.JSToolkit.notImplemented ("");\r
324 }, "java.awt.event.PaintEvent");\r
325 Clazz.overrideMethod (c$, "getLocationOnScreen", \r
326 function () {\r
327 var offset = this.$ (this.outerNode).offset ();\r
328 return  new java.awt.Point (offset.left, offset.top);\r
329 });\r
330 Clazz.defineMethod (c$, "getPreferredSize", \r
331 function () {\r
332 return this.getPreferredSize (this.c);\r
333 });\r
334 Clazz.defineMethod (c$, "getMinimumSize", \r
335 function () {\r
336 swingjs.JSToolkit.notImplemented ("");\r
337 return this.getPreferredSize (this.c);\r
338 });\r
339 Clazz.overrideMethod (c$, "getColorModel", \r
340 function () {\r
341 return java.awt.Toolkit.getDefaultToolkit ().getColorModel ();\r
342 });\r
343 Clazz.overrideMethod (c$, "getToolkit", \r
344 function () {\r
345 return java.awt.Toolkit.getDefaultToolkit ();\r
346 });\r
347 Clazz.overrideMethod (c$, "getGraphics", \r
348 function () {\r
349 return null;\r
350 });\r
351 Clazz.overrideMethod (c$, "getFontMetrics", \r
352 function (font) {\r
353 return this.c.getFontMetrics (font);\r
354 }, "java.awt.Font");\r
355 Clazz.overrideMethod (c$, "dispose", \r
356 function () {\r
357 swingjs.JSToolkit.notImplemented ("");\r
358 });\r
359 Clazz.overrideMethod (c$, "setForeground", \r
360 function (color) {\r
361 if (this.domNode != null) swingjs.api.DOMNode.setStyles (this.domNode, ["color", swingjs.JSToolkit.getCSSColor (color == null ? java.awt.Color.black : color)]);\r
362 }, "java.awt.Color");\r
363 Clazz.overrideMethod (c$, "setBackground", \r
364 function (color) {\r
365 if (this.domNode != null) swingjs.api.DOMNode.setStyles (this.domNode, ["background-color", swingjs.JSToolkit.getCSSColor (color == null ? java.awt.Color.white : color)]);\r
366 }, "java.awt.Color");\r
367 Clazz.overrideMethod (c$, "setFont", \r
368 function (f) {\r
369 if (this.domNode != null) this.setCssFont (this.domNode, f);\r
370 }, "java.awt.Font");\r
371 Clazz.overrideMethod (c$, "updateCursorImmediately", \r
372 function () {\r
373 swingjs.JSToolkit.notImplemented ("");\r
374 });\r
375 Clazz.overrideMethod (c$, "requestFocus", \r
376 function (lightweightChild, temporary, focusedWindowChangeAllowed, time, cause) {\r
377 if (this.focusNode == null) return false;\r
378 this.$ (this.focusNode).focus ();\r
379 if (this.textNode != null) this.$ (this.textNode).select ();\r
380 return true;\r
381 }, "java.awt.Component,~B,~B,~N,jssun.awt.CausedFocusEvent.Cause");\r
382 Clazz.overrideMethod (c$, "isFocusable", \r
383 function () {\r
384 return (this.focusNode != null);\r
385 });\r
386 Clazz.defineMethod (c$, "createImage", \r
387 function (producer) {\r
388 swingjs.JSToolkit.notImplemented ("");\r
389 return null;\r
390 }, "java.awt.image.ImageProducer");\r
391 Clazz.defineMethod (c$, "createImage", \r
392 function (width, height) {\r
393 swingjs.JSToolkit.notImplemented ("");\r
394 return null;\r
395 }, "~N,~N");\r
396 Clazz.overrideMethod (c$, "createVolatileImage", \r
397 function (width, height) {\r
398 swingjs.JSToolkit.notImplemented ("");\r
399 return null;\r
400 }, "~N,~N");\r
401 Clazz.overrideMethod (c$, "prepareImage", \r
402 function (img, w, h, o) {\r
403 swingjs.JSToolkit.notImplemented ("");\r
404 return false;\r
405 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");\r
406 Clazz.overrideMethod (c$, "checkImage", \r
407 function (img, w, h, o) {\r
408 swingjs.JSToolkit.notImplemented ("");\r
409 return 0;\r
410 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");\r
411 Clazz.overrideMethod (c$, "getGraphicsConfiguration", \r
412 function () {\r
413 swingjs.JSToolkit.notImplemented ("");\r
414 return null;\r
415 });\r
416 Clazz.overrideMethod (c$, "handlesWheelScrolling", \r
417 function () {\r
418 swingjs.JSToolkit.notImplemented ("");\r
419 return false;\r
420 });\r
421 Clazz.overrideMethod (c$, "getBackBuffer", \r
422 function () {\r
423 swingjs.JSToolkit.notImplemented ("");\r
424 return null;\r
425 });\r
426 Clazz.overrideMethod (c$, "destroyBuffers", \r
427 function () {\r
428 swingjs.JSToolkit.notImplemented ("");\r
429 });\r
430 Clazz.overrideMethod (c$, "reparent", \r
431 function (newContainer) {\r
432 swingjs.JSToolkit.notImplemented ("");\r
433 }, "java.awt.peer.ContainerPeer");\r
434 Clazz.overrideMethod (c$, "isReparentSupported", \r
435 function () {\r
436 swingjs.JSToolkit.notImplemented ("");\r
437 return false;\r
438 });\r
439 Clazz.overrideMethod (c$, "layout", \r
440 function () {\r
441 swingjs.JSToolkit.notImplemented ("");\r
442 });\r
443 Clazz.overrideMethod (c$, "getBounds", \r
444 function () {\r
445 swingjs.JSToolkit.notImplemented ("");\r
446 return null;\r
447 });\r
448 Clazz.defineMethod (c$, "hasFocus", \r
449 function () {\r
450 return this.focusNode != null && this.focusNode === swingjs.api.DOMNode.getAttr (this.document, "activeElement");\r
451 });\r
452 Clazz.defineMethod (c$, "notifyFocus", \r
453 function (focusGained) {\r
454 java.awt.Toolkit.getEventQueue ().postEvent ( new java.awt.event.FocusEvent (this.c, focusGained ? 1004 : 1005));\r
455 }, "~B");\r
456 Clazz.defineStatics (c$,\r
457 "incr", 0);\r
458 });\r