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
6 this.outerNode = 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
15 this.isTainted = true;
\r
18 this.preferredSize = null;
\r
19 this.isContainer = false;
\r
21 this.currentText = null;
\r
22 this.scrollerNode = null;
\r
23 this.classID = null;
\r
24 this.document = 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
31 Clazz.superConstructor (this, swingjs.plaf.JSComponentUI, []);
\r
34 Clazz.defineMethod (c$, "setDoc",
\r
37 this.document = document;
\r
38 this.body = document.body;
\r
40 Clazz.overrideMethod (c$, "installUI",
\r
42 }, "javax.swing.JComponent");
\r
43 Clazz.overrideMethod (c$, "uninstallUI",
\r
45 this.uninstallJSUI ();
\r
46 }, "javax.swing.JComponent");
\r
47 Clazz.defineMethod (c$, "$",
\r
49 return swingjs.JSToolkit.getJQuery ().$ (node);
\r
50 }, "swingjs.api.DOMNode");
\r
51 Clazz.defineMethod (c$, "setTainted",
\r
53 this.isTainted = true;
\r
55 Clazz.defineMethod (c$, "set",
\r
59 if (this.needPreferred) this.getPreferredSize (this.c);
\r
60 this.installJSUI ();
\r
62 }, "javax.swing.JComponent");
\r
63 Clazz.defineMethod (c$, "newID",
\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
70 Clazz.defineMethod (c$, "setCssFont",
\r
71 function (obj, font) {
\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
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
86 if (!this.c.isEnabled ()) this.setEnabled (false);
\r
89 Clazz.defineMethod (c$, "bindMouse",
\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
97 Clazz.defineMethod (c$, "wrap",
\r
98 function (type, id, elements) {
\r
99 return this.append (this.createDOMObject (type, id + type, []), elements);
\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
107 }, "swingjs.api.DOMNode,~A");
\r
108 Clazz.defineMethod (c$, "debugDump",
\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
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
135 parentNode = swingjs.api.DOMNode.remove (node);
\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
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
150 swingjs.api.DOMNode.setStyles (node, ["position", "absolute"]);
\r
151 swingjs.api.DOMNode.setSize (node, size.width, size.height);
\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
157 }, "swingjs.api.DOMNode,~B,~B");
\r
158 Clazz.defineMethod (c$, "getCSSDimension",
\r
160 return new java.awt.Dimension (w, h);
\r
162 Clazz.defineMethod (c$, "setHTMLElement",
\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
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
186 this.outerNode.appendChild (ui.outerNode);
\r
189 }this.isTainted = false;
\r
190 return this.outerNode;
\r
192 Clazz.defineMethod (c$, "getPreferredSize",
\r
194 var d = this.setHTMLSize (this.getDOMObject (), false);
\r
196 }, "javax.swing.JComponent");
\r
197 Clazz.defineMethod (c$, "paint",
\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
205 var testing = false;
\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
212 }, "java.awt.Graphics,javax.swing.JComponent");
\r
213 Clazz.defineMethod (c$, "getMinimumSize",
\r
215 return this.getPreferredSize (c);
\r
216 }, "javax.swing.JComponent");
\r
217 Clazz.overrideMethod (c$, "getMaximumSize",
\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
228 }, "javax.swing.JComponent");
\r
229 Clazz.overrideMethod (c$, "getBaseline",
\r
230 function (c, width, height) {
\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
236 }, "javax.swing.JComponent,~N,~N");
\r
237 Clazz.overrideMethod (c$, "getBaselineResizeBehavior",
\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
245 return swingjs.api.DOMNode.getAttr (this.domNode, this.valueNode == null ? "innerHTML" : "value");
\r
247 Clazz.defineMethod (c$, "notifyPropertyChanged",
\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
260 obj = this.valueNode;
\r
261 }} else if (prop === "preferredSize") {
\r
262 this.preferredSize = this.c.getPreferredSize ();
\r
263 this.getPreferredSize ();
\r
265 }if (obj == null) {
\r
266 System.out.println ("JSComponentUI: unrecognized prop: " + prop);
\r
268 System.out.println ("JSComponentUI: setting " + this.id + " " + prop);
\r
269 this.setProp (obj, prop, val);
\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
277 swingjs.JSToolkit.notImplemented ("");
\r
280 Clazz.overrideMethod (c$, "canDetermineObscurity",
\r
282 swingjs.JSToolkit.notImplemented ("");
\r
285 Clazz.overrideMethod (c$, "setVisible",
\r
287 swingjs.api.DOMNode.setStyles (this.outerNode, ["display", b ? "block" : "none"]);
\r
289 Clazz.overrideMethod (c$, "setEnabled",
\r
291 if (this.enableNode != null) swingjs.api.DOMNode.setAttr (this.enableNode, "disabled", (b ? null : "TRUE"));
\r
293 Clazz.defineMethod (c$, "paint",
\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
301 swingjs.JSToolkit.notImplemented ("");
\r
302 }, "java.awt.Graphics");
\r
303 Clazz.overrideMethod (c$, "setBounds",
\r
304 function (x, y, width, height, op) {
\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
316 }, "~N,~N,~N,~N,~N");
\r
317 Clazz.overrideMethod (c$, "handleEvent",
\r
319 swingjs.JSToolkit.notImplemented ("");
\r
320 }, "java.awt.AWTEvent");
\r
321 Clazz.overrideMethod (c$, "coalescePaintEvent",
\r
323 swingjs.JSToolkit.notImplemented ("");
\r
324 }, "java.awt.event.PaintEvent");
\r
325 Clazz.overrideMethod (c$, "getLocationOnScreen",
\r
327 var offset = this.$ (this.outerNode).offset ();
\r
328 return new java.awt.Point (offset.left, offset.top);
\r
330 Clazz.defineMethod (c$, "getPreferredSize",
\r
332 return this.getPreferredSize (this.c);
\r
334 Clazz.defineMethod (c$, "getMinimumSize",
\r
336 swingjs.JSToolkit.notImplemented ("");
\r
337 return this.getPreferredSize (this.c);
\r
339 Clazz.overrideMethod (c$, "getColorModel",
\r
341 return java.awt.Toolkit.getDefaultToolkit ().getColorModel ();
\r
343 Clazz.overrideMethod (c$, "getToolkit",
\r
345 return java.awt.Toolkit.getDefaultToolkit ();
\r
347 Clazz.overrideMethod (c$, "getGraphics",
\r
351 Clazz.overrideMethod (c$, "getFontMetrics",
\r
353 return this.c.getFontMetrics (font);
\r
354 }, "java.awt.Font");
\r
355 Clazz.overrideMethod (c$, "dispose",
\r
357 swingjs.JSToolkit.notImplemented ("");
\r
359 Clazz.overrideMethod (c$, "setForeground",
\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
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
369 if (this.domNode != null) this.setCssFont (this.domNode, f);
\r
370 }, "java.awt.Font");
\r
371 Clazz.overrideMethod (c$, "updateCursorImmediately",
\r
373 swingjs.JSToolkit.notImplemented ("");
\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
381 }, "java.awt.Component,~B,~B,~N,jssun.awt.CausedFocusEvent.Cause");
\r
382 Clazz.overrideMethod (c$, "isFocusable",
\r
384 return (this.focusNode != null);
\r
386 Clazz.defineMethod (c$, "createImage",
\r
387 function (producer) {
\r
388 swingjs.JSToolkit.notImplemented ("");
\r
390 }, "java.awt.image.ImageProducer");
\r
391 Clazz.defineMethod (c$, "createImage",
\r
392 function (width, height) {
\r
393 swingjs.JSToolkit.notImplemented ("");
\r
396 Clazz.overrideMethod (c$, "createVolatileImage",
\r
397 function (width, height) {
\r
398 swingjs.JSToolkit.notImplemented ("");
\r
401 Clazz.overrideMethod (c$, "prepareImage",
\r
402 function (img, w, h, o) {
\r
403 swingjs.JSToolkit.notImplemented ("");
\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
410 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");
\r
411 Clazz.overrideMethod (c$, "getGraphicsConfiguration",
\r
413 swingjs.JSToolkit.notImplemented ("");
\r
416 Clazz.overrideMethod (c$, "handlesWheelScrolling",
\r
418 swingjs.JSToolkit.notImplemented ("");
\r
421 Clazz.overrideMethod (c$, "getBackBuffer",
\r
423 swingjs.JSToolkit.notImplemented ("");
\r
426 Clazz.overrideMethod (c$, "destroyBuffers",
\r
428 swingjs.JSToolkit.notImplemented ("");
\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
436 swingjs.JSToolkit.notImplemented ("");
\r
439 Clazz.overrideMethod (c$, "layout",
\r
441 swingjs.JSToolkit.notImplemented ("");
\r
443 Clazz.overrideMethod (c$, "getBounds",
\r
445 swingjs.JSToolkit.notImplemented ("");
\r
448 Clazz.defineMethod (c$, "hasFocus",
\r
450 return this.focusNode != null && this.focusNode === swingjs.api.DOMNode.getAttr (this.document, "activeElement");
\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
456 Clazz.defineStatics (c$,
\r