1 Clazz.declarePackage ("swingjs.plaf");
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 () {
3 c$ = Clazz.decorateAsClass (function () {
8 this.enableNode = null;
10 this.valueNode = null;
11 this.scrollNode = null;
12 this.focusNode = null;
13 this.components = null;
15 this.isTainted = true;
18 this.preferredSize = null;
19 this.isContainer = false;
21 this.currentText = null;
22 this.scrollerNode = null;
26 this.needPreferred = false;
27 Clazz.instantialize (this, arguments);
28 }, swingjs.plaf, "JSComponentUI", javax.swing.plaf.ComponentUI, swingjs.plaf.JSEventHandler);
29 Clazz.makeConstructor (c$,
31 Clazz.superConstructor (this, swingjs.plaf.JSComponentUI, []);
34 Clazz.defineMethod (c$, "setDoc",
37 this.document = document;
38 this.body = document.body;
40 Clazz.overrideMethod (c$, "installUI",
42 }, "javax.swing.JComponent");
43 Clazz.overrideMethod (c$, "uninstallUI",
45 this.uninstallJSUI ();
46 }, "javax.swing.JComponent");
47 Clazz.defineMethod (c$, "$",
49 return swingjs.JSToolkit.getJQuery ().$ (node);
50 }, "swingjs.api.DOMNode");
51 Clazz.defineMethod (c$, "setTainted",
53 this.isTainted = true;
55 Clazz.defineMethod (c$, "set",
59 if (this.needPreferred) this.getPreferredSize (this.c);
62 }, "javax.swing.JComponent");
63 Clazz.defineMethod (c$, "newID",
65 this.classID = this.c.getUIClassID ();
66 if (this.id == null) {
67 this.num = ++swingjs.plaf.JSComponentUI.incr;
68 this.id = this.c.getHTMLName (this.classID) + "_" + this.num;
70 Clazz.defineMethod (c$, "setCssFont",
71 function (obj, font) {
73 var istyle = font.getStyle ();
74 var name = font.getFamily ();
75 if (name === "Dialog") name = "Arial";
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")]);
77 }if (this.c.isBackgroundSet ()) this.setBackground (this.c.getBackground ());
78 this.setForeground (this.c.getForeground ());
80 }, "swingjs.api.DOMNode,java.awt.Font");
81 Clazz.defineMethod (c$, "createDOMObject",
82 function (key, id, attr) {
83 var obj = swingjs.api.DOMNode.createElement (key, id);
84 for (var i = 0; i < attr.length; ) swingjs.api.DOMNode.setAttr (obj, attr[i++], attr[i++]);
86 if (!this.c.isEnabled ()) this.setEnabled (false);
89 Clazz.defineMethod (c$, "bindMouse",
91 swingjs.api.DOMNode.setAttr (node, "data-UI", this);
92 }, "swingjs.api.DOMNode");
93 Clazz.overrideMethod (c$, "handleJSEvent",
94 function (target, eventType, jQueryEvent) {
97 Clazz.defineMethod (c$, "wrap",
98 function (type, id, elements) {
99 return this.append (this.createDOMObject (type, id + type, []), elements);
101 Clazz.defineMethod (c$, "append",
102 function (obj, elements) {
103 for (var i = 0; i < elements.length; i++) {
104 obj.appendChild (elements[i]);
107 }, "swingjs.api.DOMNode,~A");
108 Clazz.defineMethod (c$, "debugDump",
110 System.out.println (swingjs.api.DOMNode.getAttr (d, "outerHTML"));
111 }, "swingjs.api.DOMNode");
112 c$.vCenter = Clazz.defineMethod (c$, "vCenter",
113 function (obj, offset) {
114 swingjs.api.DOMNode.setStyles (obj, ["top", "50%", "transform", "translateY(" + offset + "%)"]);
115 }, "swingjs.api.DOMNode,~N");
116 Clazz.defineMethod (c$, "setHTMLSize",
117 function (obj, addCSS) {
118 return this.setHTMLSize1 (obj, addCSS, true);
119 }, "swingjs.api.DOMNode,~B");
120 Clazz.defineMethod (c$, "setHTMLSize1",
121 function (node, addCSS, usePreferred) {
122 if (node == null) return null;
127 var parentNode = null;
128 if (this.scrollerNode != null) {
129 w = this.scrollerNode.c.getWidth ();
130 h = this.scrollerNode.c.getHeight ();
131 } else if (usePreferred && this.preferredSize != null) {
132 w = this.preferredSize.width;
133 h = this.preferredSize.height;
135 parentNode = swingjs.api.DOMNode.remove (node);
137 w0 = node.style.width;
138 h0 = node.style.height;
139 }swingjs.api.DOMNode.setStyles (node, ["position", null, "width", null, "height", null]);
141 if (swingjs.api.DOMNode.getAttr (node, "tagName") === "DIV") div = node;
142 else div = this.wrap ("div", this.id + "_temp", [node]);
143 swingjs.api.DOMNode.setStyles (div, ["position", "absolute"]);
144 this.body.appendChild (div);
145 w = Clazz.doubleToInt (Math.ceil (this.$ (div).width () + 0.5));
146 h = Clazz.doubleToInt (Math.ceil (this.$ (div).height () + 0.5));
147 this.body.removeChild (div);
148 }var size = this.getCSSDimension (w, h);
150 swingjs.api.DOMNode.setStyles (node, ["position", "absolute"]);
151 swingjs.api.DOMNode.setSize (node, size.width, size.height);
153 swingjs.api.DOMNode.setStyles (node, ["position", null]);
154 if (w0 != null) swingjs.api.DOMNode.setStyles (node, ["width", w0, "height", h0]);
155 }if (parentNode != null) parentNode.appendChild (node);
157 }, "swingjs.api.DOMNode,~B,~B");
158 Clazz.defineMethod (c$, "getCSSDimension",
160 return new java.awt.Dimension (w, h);
162 Clazz.defineMethod (c$, "setHTMLElement",
164 if (!this.isTainted) return this.outerNode;
165 var root = (this.isContainer ? this.c.getRootPane () : null);
166 if (this.c === root) {
167 this.isTainted = false;
168 return this.outerNode;
169 }this.domNode = this.getDOMObject ();
170 if (this.outerNode == null) {
171 this.outerNode = this.wrap ("div", this.id, [this.domNode]);
172 if (root != null && root.getContentPane () === this.c) swingjs.JSToolkit.getHTML5Applet (this.c)._getContentLayer ().appendChild (this.outerNode);
173 }swingjs.api.DOMNode.setStyles (this.outerNode, ["position", "absolute", "left", (this.x = this.c.getX ()) + "px", "top", (this.y = this.c.getY ()) + "px"]);
174 if (this.isContainer) {
175 System.out.println ("JSComponentUI container " + this.id + " " + this.c.getBounds ());
176 swingjs.api.DOMNode.setSize (this.outerNode, this.c.getWidth (), this.c.getHeight ());
177 var children = (this.components == null ? this.c.getComponents () : this.components);
178 for (var i = children.length; --i >= 0; ) {
179 var ui = swingjs.JSToolkit.getUI (children[i], false);
182 }if (ui.outerNode == null) ui.setHTMLElement ();
183 if (ui.outerNode == null) {
184 System.out.println ("JSCUI could not add " + ui.c.getName () + " to " + this.c.getName ());
186 this.outerNode.appendChild (ui.outerNode);
189 }this.isTainted = false;
190 return this.outerNode;
192 Clazz.defineMethod (c$, "getPreferredSize",
194 var d = this.setHTMLSize (this.getDOMObject (), false);
196 }, "javax.swing.JComponent");
197 Clazz.defineMethod (c$, "paint",
200 g.setColor (c.getBackground ());
201 g.fillRect (0, 0, c.getWidth (), c.getHeight ());
202 }}, "java.awt.Graphics,javax.swing.JComponent");
203 Clazz.overrideMethod (c$, "update",
207 g.setColor (java.awt.Color.red);
208 g.drawRect (0, 0, c.getWidth (), c.getHeight ());
209 System.out.println ("drawing " + c.getWidth () + " " + c.getHeight ());
210 }this.setHTMLElement ();
212 }, "java.awt.Graphics,javax.swing.JComponent");
213 Clazz.defineMethod (c$, "getMinimumSize",
215 return this.getPreferredSize (c);
216 }, "javax.swing.JComponent");
217 Clazz.overrideMethod (c$, "getMaximumSize",
220 }, "javax.swing.JComponent");
221 Clazz.overrideMethod (c$, "contains",
223 return c.inside (x, y);
224 }, "javax.swing.JComponent,~N,~N");
225 c$.createUI = Clazz.overrideMethod (c$, "createUI",
228 }, "javax.swing.JComponent");
229 Clazz.overrideMethod (c$, "getBaseline",
230 function (c, width, height) {
232 throw new NullPointerException ("Component must be non-null");
233 }if (width < 0 || height < 0) {
234 throw new IllegalArgumentException ("Width and height must be >= 0");
236 }, "javax.swing.JComponent,~N,~N");
237 Clazz.overrideMethod (c$, "getBaselineResizeBehavior",
240 throw new NullPointerException ("Component must be non-null");
241 }return java.awt.Component.BaselineResizeBehavior.OTHER;
242 }, "javax.swing.JComponent");
243 Clazz.defineMethod (c$, "getJSTextValue",
245 return swingjs.api.DOMNode.getAttr (this.domNode, this.valueNode == null ? "innerHTML" : "value");
247 Clazz.defineMethod (c$, "notifyPropertyChanged",
251 if (prop === "text") {
252 val = (this.c).getText ();
253 if (val.equals (this.currentText)) return;
254 this.currentText = val;
255 if (this.textNode != null) {
258 } else if (this.valueNode != null) {
260 obj = this.valueNode;
261 }} else if (prop === "preferredSize") {
262 this.preferredSize = this.c.getPreferredSize ();
263 this.getPreferredSize ();
266 System.out.println ("JSComponentUI: unrecognized prop: " + prop);
268 System.out.println ("JSComponentUI: setting " + this.id + " " + prop);
269 this.setProp (obj, prop, val);
271 Clazz.defineMethod (c$, "setProp",
272 function (obj, prop, val) {
273 return swingjs.api.DOMNode.setAttr (obj, prop, val);
274 }, "swingjs.api.DOMNode,~S,~S");
275 Clazz.overrideMethod (c$, "isObscured",
277 swingjs.JSToolkit.notImplemented ("");
280 Clazz.overrideMethod (c$, "canDetermineObscurity",
282 swingjs.JSToolkit.notImplemented ("");
285 Clazz.overrideMethod (c$, "setVisible",
287 swingjs.api.DOMNode.setStyles (this.outerNode, ["display", b ? "block" : "none"]);
289 Clazz.overrideMethod (c$, "setEnabled",
291 if (this.enableNode != null) swingjs.api.DOMNode.setAttr (this.enableNode, "disabled", (b ? null : "TRUE"));
293 Clazz.defineMethod (c$, "paint",
295 }, "java.awt.Graphics");
296 Clazz.overrideMethod (c$, "repaint",
297 function (tm, x, y, width, height) {
298 }, "~N,~N,~N,~N,~N");
299 Clazz.overrideMethod (c$, "print",
301 swingjs.JSToolkit.notImplemented ("");
302 }, "java.awt.Graphics");
303 Clazz.overrideMethod (c$, "setBounds",
304 function (x, y, width, height, op) {
309 if (this.scrollerNode != null) {
310 width = Math.min (width, this.scrollerNode.c.getWidth ());
311 height = Math.min (height, this.scrollerNode.c.getHeight ());
312 }System.out.println (this.id + " setBounds " + x + " " + y + " " + width + " " + height + " op=" + op);
313 if (this.domNode != null) swingjs.api.DOMNode.setSize (this.domNode, width, height);
316 }, "~N,~N,~N,~N,~N");
317 Clazz.overrideMethod (c$, "handleEvent",
319 swingjs.JSToolkit.notImplemented ("");
320 }, "java.awt.AWTEvent");
321 Clazz.overrideMethod (c$, "coalescePaintEvent",
323 swingjs.JSToolkit.notImplemented ("");
324 }, "java.awt.event.PaintEvent");
325 Clazz.overrideMethod (c$, "getLocationOnScreen",
327 var offset = this.$ (this.outerNode).offset ();
328 return new java.awt.Point (offset.left, offset.top);
330 Clazz.defineMethod (c$, "getPreferredSize",
332 return this.getPreferredSize (this.c);
334 Clazz.defineMethod (c$, "getMinimumSize",
336 swingjs.JSToolkit.notImplemented ("");
337 return this.getPreferredSize (this.c);
339 Clazz.overrideMethod (c$, "getColorModel",
341 return java.awt.Toolkit.getDefaultToolkit ().getColorModel ();
343 Clazz.overrideMethod (c$, "getToolkit",
345 return java.awt.Toolkit.getDefaultToolkit ();
347 Clazz.overrideMethod (c$, "getGraphics",
351 Clazz.overrideMethod (c$, "getFontMetrics",
353 return this.c.getFontMetrics (font);
355 Clazz.overrideMethod (c$, "dispose",
357 swingjs.JSToolkit.notImplemented ("");
359 Clazz.overrideMethod (c$, "setForeground",
361 if (this.domNode != null) swingjs.api.DOMNode.setStyles (this.domNode, ["color", swingjs.JSToolkit.getCSSColor (color == null ? java.awt.Color.black : color)]);
362 }, "java.awt.Color");
363 Clazz.overrideMethod (c$, "setBackground",
365 if (this.domNode != null) swingjs.api.DOMNode.setStyles (this.domNode, ["background-color", swingjs.JSToolkit.getCSSColor (color == null ? java.awt.Color.white : color)]);
366 }, "java.awt.Color");
367 Clazz.overrideMethod (c$, "setFont",
369 if (this.domNode != null) this.setCssFont (this.domNode, f);
371 Clazz.overrideMethod (c$, "updateCursorImmediately",
373 swingjs.JSToolkit.notImplemented ("");
375 Clazz.overrideMethod (c$, "requestFocus",
376 function (lightweightChild, temporary, focusedWindowChangeAllowed, time, cause) {
377 if (this.focusNode == null) return false;
378 this.$ (this.focusNode).focus ();
379 if (this.textNode != null) this.$ (this.textNode).select ();
381 }, "java.awt.Component,~B,~B,~N,jssun.awt.CausedFocusEvent.Cause");
382 Clazz.overrideMethod (c$, "isFocusable",
384 return (this.focusNode != null);
386 Clazz.defineMethod (c$, "createImage",
387 function (producer) {
388 swingjs.JSToolkit.notImplemented ("");
390 }, "java.awt.image.ImageProducer");
391 Clazz.defineMethod (c$, "createImage",
392 function (width, height) {
393 swingjs.JSToolkit.notImplemented ("");
396 Clazz.overrideMethod (c$, "createVolatileImage",
397 function (width, height) {
398 swingjs.JSToolkit.notImplemented ("");
401 Clazz.overrideMethod (c$, "prepareImage",
402 function (img, w, h, o) {
403 swingjs.JSToolkit.notImplemented ("");
405 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");
406 Clazz.overrideMethod (c$, "checkImage",
407 function (img, w, h, o) {
408 swingjs.JSToolkit.notImplemented ("");
410 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");
411 Clazz.overrideMethod (c$, "getGraphicsConfiguration",
413 swingjs.JSToolkit.notImplemented ("");
416 Clazz.overrideMethod (c$, "handlesWheelScrolling",
418 swingjs.JSToolkit.notImplemented ("");
421 Clazz.overrideMethod (c$, "getBackBuffer",
423 swingjs.JSToolkit.notImplemented ("");
426 Clazz.overrideMethod (c$, "destroyBuffers",
428 swingjs.JSToolkit.notImplemented ("");
430 Clazz.overrideMethod (c$, "reparent",
431 function (newContainer) {
432 swingjs.JSToolkit.notImplemented ("");
433 }, "java.awt.peer.ContainerPeer");
434 Clazz.overrideMethod (c$, "isReparentSupported",
436 swingjs.JSToolkit.notImplemented ("");
439 Clazz.overrideMethod (c$, "layout",
441 swingjs.JSToolkit.notImplemented ("");
443 Clazz.overrideMethod (c$, "getBounds",
445 swingjs.JSToolkit.notImplemented ("");
448 Clazz.defineMethod (c$, "hasFocus",
450 return this.focusNode != null && this.focusNode === swingjs.api.DOMNode.getAttr (this.document, "activeElement");
452 Clazz.defineMethod (c$, "notifyFocus",
453 function (focusGained) {
454 java.awt.Toolkit.getEventQueue ().postEvent ( new java.awt.event.FocusEvent (this.c, focusGained ? 1004 : 1005));
456 Clazz.defineStatics (c$,