1 Clazz.declarePackage ("swingjs");
\r
2 Clazz.load (["jssun.java2d.SunGraphics2D"], "swingjs.JSGraphics2D", ["java.util.HashMap", "java.awt.BasicStroke", "$.Rectangle", "$.RenderingHints", "$.Toolkit", "java.awt.geom.AffineTransform", "swingjs.JSToolkit", "swingjs.api.HTML5CanvasContext2D"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
6 this.windowWidth = 0;
\r
7 this.windowHeight = 0;
\r
11 this.paintState = 0;
\r
12 this.compositeState = -2147483648;
\r
13 this.strokeState = 0;
\r
14 this.$transformState = 0;
\r
16 this.isShifted = false;
\r
18 this.inPath = false;
\r
19 this.currentClip = null;
\r
20 Clazz.instantialize (this, arguments);
\r
21 }, swingjs, "JSGraphics2D", jssun.java2d.SunGraphics2D, Cloneable);
\r
22 Clazz.makeConstructor (c$,
\r
24 Clazz.superConstructor (this, swingjs.JSGraphics2D, []);
\r
25 this.hints = new java.awt.RenderingHints ( new java.util.HashMap ());
\r
26 this.canvas = canvas;
\r
27 this.ctx = this.canvas.getContext ("2d");
\r
28 this.$transform = new java.awt.geom.AffineTransform ();
\r
32 Clazz.overrideMethod (c$, "getDeviceConfiguration",
\r
36 Clazz.overrideMethod (c$, "drawLine",
\r
37 function (x0, y0, x1, y1) {
\r
38 var inPath = this.inPath;
\r
39 if (!inPath) this.ctx.beginPath ();
\r
40 this.ctx.moveTo (x0, y0);
\r
41 this.ctx.lineTo (x1, y1);
\r
42 if (!inPath) this.ctx.stroke ();
\r
44 Clazz.defineMethod (c$, "drawCircle",
\r
45 function (x, y, diameter) {
\r
46 this.drawArc (x, y, diameter, diameter, 0, 360);
\r
48 Clazz.overrideMethod (c$, "fillArc",
\r
49 function (x, y, width, height, startAngle, arcAngle) {
\r
50 this.doArc (x, y, width, height, startAngle, arcAngle, true);
\r
51 }, "~N,~N,~N,~N,~N,~N");
\r
52 Clazz.overrideMethod (c$, "drawArc",
\r
53 function (x, y, width, height, startAngle, arcAngle) {
\r
54 this.doArc (x, y, width, height, startAngle, arcAngle, false);
\r
55 }, "~N,~N,~N,~N,~N,~N");
\r
56 Clazz.defineMethod (c$, "save",
\r
60 Clazz.defineMethod (c$, "restore",
\r
62 this.ctx.restore ();
\r
64 Clazz.defineMethod (c$, "doArc",
\r
65 function (x, y, width, height, startAngle, arcAngle, fill) {
\r
66 var isCircle = (arcAngle - startAngle == 360);
\r
68 this.ctx.translate (x, y);
\r
69 this.ctx.scale (Clazz.doubleToInt (width / height), height);
\r
70 this.ctx.beginPath ();
\r
72 }this.ctx.arc (0.5, 0.5, 0.5, this.toRad (startAngle), this.toRad (arcAngle), false);
\r
73 if (isCircle) this.ctx.closePath ();
\r
76 }, "~N,~N,~N,~N,~N,~N,~B");
\r
77 Clazz.defineMethod (c$, "toRad",
\r
79 return a * 3.141592653589793 / 180;
\r
81 Clazz.defineMethod (c$, "drawPolygon",
\r
82 function (ayPoints, axPoints, nPoints) {
\r
83 this.doPoly (ayPoints, axPoints, nPoints, false);
\r
85 Clazz.defineMethod (c$, "doPoly",
\r
86 function (axPoints, ayPoints, nPoints, doFill) {
\r
87 this.ctx.beginPath ();
\r
88 this.ctx.moveTo (axPoints[0], ayPoints[0]);
\r
89 for (var i = 1; i < nPoints; i++) this.ctx.lineTo (axPoints[i], ayPoints[i]);
\r
91 if (doFill) this.ctx.fill ();
\r
92 else this.ctx.stroke ();
\r
94 Clazz.overrideMethod (c$, "drawRect",
\r
95 function (x, y, width, height) {
\r
96 this.ctx.beginPath ();
\r
97 this.ctx.rect (x, y, width, height);
\r
100 Clazz.defineMethod (c$, "drawString",
\r
101 function (s, x, y) {
\r
102 this.ctx.fillText (s, x, y);
\r
104 Clazz.defineMethod (c$, "background",
\r
105 function (bgcolor) {
\r
106 this.backgroundColor = bgcolor;
\r
107 if (bgcolor == null) {
\r
108 if (!this.isShifted) this.ctx.translate (-0.5, -0.5);
\r
109 this.isShifted = true;
\r
111 }this.ctx.clearRect (0, 0, this.windowWidth, this.windowHeight);
\r
112 this.setGraphicsColor (bgcolor);
\r
113 this.fillRect (0, 0, this.windowWidth, this.windowHeight);
\r
114 }, "java.awt.Color");
\r
115 Clazz.defineMethod (c$, "fillCircle",
\r
116 function (x, y, diameter) {
\r
117 var r = diameter / 2;
\r
118 this.ctx.beginPath ();
\r
119 this.ctx.arc (x + r, y + r, r, 0, 6.283185307179586, false);
\r
122 Clazz.defineMethod (c$, "fillPolygon",
\r
123 function (ayPoints, axPoints, nPoints) {
\r
124 this.doPoly (ayPoints, axPoints, nPoints, true);
\r
126 Clazz.overrideMethod (c$, "fillRect",
\r
127 function (x, y, width, height) {
\r
128 this.ctx.fillRect (x, y, width, height);
\r
130 Clazz.defineMethod (c$, "setGraphicsColor",
\r
132 var s = swingjs.JSToolkit.getCSSColor (c);
\r
134 this.ctx.fillStyle = s; this.ctx.strokeStyle = s;
\r
135 }}, "java.awt.Color");
\r
136 Clazz.overrideMethod (c$, "setFont",
\r
139 if (this.ctx == null) return;
\r
140 var s = swingjs.JSToolkit.getCanvasFont (font);
\r
143 }}, "java.awt.Font");
\r
144 Clazz.defineMethod (c$, "setStrokeBold",
\r
146 this.setLineWidth (tf ? 2. : 1.);
\r
148 Clazz.defineMethod (c$, "setLineWidth",
\r
151 this.ctx.lineWidth = d;
\r
153 Clazz.defineMethod (c$, "setWindowParameters",
\r
154 function (width, height) {
\r
155 this.windowWidth = width;
\r
156 this.windowHeight = height;
\r
158 Clazz.defineMethod (c$, "canDoLineTo",
\r
162 Clazz.defineMethod (c$, "doStroke",
\r
163 function (isBegin) {
\r
164 this.inPath = isBegin;
\r
166 this.ctx.beginPath ();
\r
168 this.ctx.stroke ();
\r
170 Clazz.defineMethod (c$, "lineTo",
\r
171 function (x2, y2) {
\r
172 this.ctx.lineTo (x2, y2);
\r
174 Clazz.overrideMethod (c$, "clip",
\r
178 }, "java.awt.Shape");
\r
179 Clazz.overrideMethod (c$, "draw",
\r
182 this.ctx.stroke ();
\r
183 }, "java.awt.Shape");
\r
184 Clazz.defineMethod (c$, "doShape",
\r
186 this.ctx.beginPath ();
\r
187 var pts = Clazz.newDoubleArray (6, 0);
\r
188 var pi = s.getPathIterator (null);
\r
189 while (!pi.isDone ()) {
\r
190 switch (pi.currentSegment (pts)) {
\r
192 this.ctx.moveTo (pts[0], pts[1]);
\r
195 this.ctx.lineTo (pts[0], pts[1]);
\r
198 this.ctx.quadraticCurveTo (pts[0], pts[1], pts[2], pts[3]);
\r
201 this.ctx.bezeierCurveTo (pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
\r
204 this.ctx.closePath ();
\r
209 return pi.getWindingRule ();
\r
210 }, "java.awt.Shape");
\r
211 Clazz.overrideMethod (c$, "fill",
\r
213 if (this.doShape (s) == 0) {
\r
214 this.ctx.fill("evenodd");
\r
215 } else this.ctx.fill ();
\r
216 }, "java.awt.Shape");
\r
217 Clazz.defineMethod (c$, "drawImage",
\r
218 function (img, x, y, observer) {
\r
222 var imgNode = this.getImageNode (img);
\r
223 if (imgNode != null) this.ctx.drawImage (imgNode, x, y, img.getWidth (observer), img.getHeight (observer));
\r
224 if (observer != null) this.observe (img, observer, imgNode != null);
\r
226 }, "java.awt.Image,~N,~N,java.awt.image.ImageObserver");
\r
227 Clazz.defineMethod (c$, "observe",
\r
228 function (img, observer, isOK) {
\r
229 observer.imageUpdate (img, (isOK ? 0 : 192), -1, -1, -1, -1);
\r
230 }, "java.awt.Image,java.awt.image.ImageObserver,~B");
\r
231 Clazz.defineMethod (c$, "drawImage",
\r
232 function (img, x, y, width, height, observer) {
\r
234 var imgNode = this.getImageNode (img);
\r
235 if (imgNode != null) this.ctx.drawImage (imgNode, x, y, width, height);
\r
236 if (observer != null) this.observe (img, observer, imgNode != null);
\r
238 }, "java.awt.Image,~N,~N,~N,~N,java.awt.image.ImageObserver");
\r
239 Clazz.defineMethod (c$, "drawImage",
\r
240 function (img, x, y, bgcolor, observer) {
\r
241 swingjs.JSToolkit.notImplemented (null);
\r
242 return this.drawImage (img, x, y, null);
\r
243 }, "java.awt.Image,~N,~N,java.awt.Color,java.awt.image.ImageObserver");
\r
244 Clazz.defineMethod (c$, "drawImage",
\r
245 function (img, x, y, width, height, bgcolor, observer) {
\r
246 swingjs.JSToolkit.notImplemented (null);
\r
247 return this.drawImage (img, x, y, width, height, null);
\r
248 }, "java.awt.Image,~N,~N,~N,~N,java.awt.Color,java.awt.image.ImageObserver");
\r
249 Clazz.defineMethod (c$, "drawImage",
\r
250 function (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer) {
\r
252 var imgNode = this.getImageNode (img);
\r
253 if (imgNode != null) swingjs.api.HTML5CanvasContext2D.stretchImage (this.ctx, imgNode, sx1, sy1, sx2 - sx1, sy2 - sy1, dx1, dy1, dx2 - dx1, dy2 - dy1);
\r
254 if (observer != null) this.observe (img, observer, imgNode != null);
\r
256 }, "java.awt.Image,~N,~N,~N,~N,~N,~N,~N,~N,java.awt.image.ImageObserver");
\r
257 Clazz.defineMethod (c$, "getImageNode",
\r
259 var imgNode = null;
\r
261 imgNode = img._imgNode || img._canvas;
\r
263 }if (imgNode == null) imgNode = swingjs.JSToolkit.getCompositor ().createImageNode (img);
\r
265 }, "java.awt.Image");
\r
266 Clazz.defineMethod (c$, "drawImage",
\r
267 function (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer) {
\r
268 swingjs.JSToolkit.notImplemented (null);
\r
269 return this.drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
\r
270 }, "java.awt.Image,~N,~N,~N,~N,~N,~N,~N,~N,java.awt.Color,java.awt.image.ImageObserver");
\r
271 Clazz.defineMethod (c$, "drawImage",
\r
272 function (img, xform, obs) {
\r
273 swingjs.JSToolkit.notImplemented (null);
\r
275 }, "java.awt.Image,java.awt.geom.AffineTransform,java.awt.image.ImageObserver");
\r
276 Clazz.overrideMethod (c$, "drawRenderedImage",
\r
277 function (img, xform) {
\r
278 swingjs.JSToolkit.notImplemented (null);
\r
279 }, "java.awt.image.RenderedImage,java.awt.geom.AffineTransform");
\r
280 Clazz.overrideMethod (c$, "drawRenderableImage",
\r
281 function (img, xform) {
\r
282 swingjs.JSToolkit.notImplemented (null);
\r
283 }, "java.awt.image.renderable.RenderableImage,java.awt.geom.AffineTransform");
\r
284 Clazz.overrideMethod (c$, "hit",
\r
285 function (rect, s, onStroke) {
\r
286 swingjs.JSToolkit.notImplemented (null);
\r
288 }, "java.awt.Rectangle,java.awt.Shape,~B");
\r
289 Clazz.overrideMethod (c$, "setPaint",
\r
291 swingjs.JSToolkit.notImplemented (null);
\r
292 }, "java.awt.Paint");
\r
293 Clazz.overrideMethod (c$, "setStroke",
\r
295 if (!(Clazz.instanceOf (s, java.awt.BasicStroke))) return;
\r
297 var dash = b.getDashArray ();
\r
298 var idash = Clazz.newIntArray (dash == null ? 0 : dash.length, 0);
\r
299 for (var i = idash.length; --i >= 0; ) idash[i] = Clazz.floatToInt (dash[i]);
\r
301 this.ctx.setLineDash (idash);
\r
302 this.setLineWidth (b.getLineWidth ());
\r
305 var miterLimit = -1;
\r
306 switch (b.getEndCap ()) {
\r
311 lineCap = "square";
\r
317 switch (b.getLineJoin ()) {
\r
319 lineJoin = "bevel";
\r
322 lineJoin = "miter";
\r
323 miterLimit = b.getMiterLimit ();
\r
326 lineJoin = "round";
\r
329 this.ctx.lineCap = lineCap; this.ctx.lineJoin = lineJoin; if
\r
330 (miterLimit >= 0) this.ctx.miterLimit = miterLimit;
\r
331 }}, "java.awt.Stroke");
\r
332 Clazz.overrideMethod (c$, "setRenderingHint",
\r
333 function (hintKey, hintValue) {
\r
334 this.hints.put (hintKey, hintValue);
\r
335 }, "java.awt.RenderingHints.Key,~O");
\r
336 Clazz.overrideMethod (c$, "getRenderingHint",
\r
337 function (hintKey) {
\r
338 return this.hints.get (hintKey);
\r
339 }, "java.awt.RenderingHints.Key");
\r
340 Clazz.overrideMethod (c$, "setRenderingHints",
\r
342 this.hints = new java.awt.RenderingHints (hints);
\r
343 }, "java.util.Map");
\r
344 Clazz.overrideMethod (c$, "addRenderingHints",
\r
346 for (var e, $e = hints.entrySet ().iterator (); $e.hasNext () && ((e = $e.next ()) || true);) this.hints.put (e.getKey (), e.getValue ());
\r
348 }, "java.util.Map");
\r
349 Clazz.overrideMethod (c$, "getRenderingHints",
\r
353 Clazz.defineMethod (c$, "translate",
\r
355 this.ctx.translate (x, y);
\r
357 Clazz.overrideMethod (c$, "scale",
\r
358 function (sx, sy) {
\r
359 this.ctx.scale (sx, sy);
\r
361 Clazz.overrideMethod (c$, "setBackground",
\r
363 this.background (color);
\r
364 }, "java.awt.Color");
\r
365 Clazz.overrideMethod (c$, "getBackground",
\r
367 return this.backgroundColor;
\r
369 Clazz.overrideMethod (c$, "createSwingJS",
\r
371 return this.clone ();
\r
373 Clazz.overrideMethod (c$, "clone",
\r
376 return this.clone0 ();
\r
378 Clazz.overrideMethod (c$, "dispose",
\r
380 if (this.compositeState >= 0) this.setComposite (null);
\r
383 Clazz.overrideMethod (c$, "getColor",
\r
385 return this.foregroundColor;
\r
387 Clazz.overrideMethod (c$, "setColor",
\r
389 this.foregroundColor = c;
\r
390 this.setGraphicsColor (c);
\r
391 }, "java.awt.Color");
\r
392 Clazz.overrideMethod (c$, "getFont",
\r
396 Clazz.defineMethod (c$, "getFontMetrics",
\r
398 return java.awt.Toolkit.getDefaultToolkit ().getFontMetrics (f);
\r
399 }, "java.awt.Font");
\r
400 Clazz.overrideMethod (c$, "clipRect",
\r
401 function (x, y, width, height) {
\r
402 this.ctx.beginPath ();
\r
403 this.ctx.rect (x, y, width, height);
\r
404 this.currentClip = new java.awt.Rectangle (x, y, width, height);
\r
407 Clazz.defineMethod (c$, "setClip",
\r
408 function (x, y, width, height) {
\r
409 this.currentClip = new java.awt.Rectangle (x, y, width, height);
\r
411 if (arguments.length == 1) { setClip1(x); return; }
\r
412 }this.ctx.beginPath ();
\r
413 this.ctx.rect (x, y, width, height);
\r
414 this.currentClip = new java.awt.Rectangle (x, y, width, height);
\r
417 Clazz.defineMethod (c$, "setClip1",
\r
419 this.ctx.beginPath ();
\r
420 this.doShape (clip);
\r
422 }, "java.awt.Shape");
\r
423 Clazz.overrideMethod (c$, "clearRect",
\r
424 function (x, y, width, height) {
\r
425 this.ctx.clearRect (x, y, width, height);
\r
427 Clazz.overrideMethod (c$, "drawPolyline",
\r
428 function (xPoints, yPoints, nPoints) {
\r
429 if (nPoints < 2) return;
\r
430 this.ctx.moveTo (xPoints[0], yPoints[0]);
\r
431 for (var i = 1; i < nPoints; i++) {
\r
432 this.ctx.lineTo (xPoints[i], yPoints[i]);
\r
435 Clazz.overrideMethod (c$, "copyArea",
\r
436 function (x, y, width, height, dx, dy) {
\r
437 swingjs.JSToolkit.notImplemented (null);
\r
438 }, "~N,~N,~N,~N,~N,~N");
\r
439 Clazz.overrideMethod (c$, "drawRoundRect",
\r
440 function (x, y, width, height, arcWidth, arcHeight) {
\r
441 swingjs.JSToolkit.notImplemented (null);
\r
442 this.drawRect (x, y, width, height);
\r
443 }, "~N,~N,~N,~N,~N,~N");
\r
444 Clazz.overrideMethod (c$, "fillRoundRect",
\r
445 function (x, y, width, height, arcWidth, arcHeight) {
\r
446 swingjs.JSToolkit.notImplemented (null);
\r
447 this.fillRect (x, y, width, height);
\r
448 }, "~N,~N,~N,~N,~N,~N");
\r
449 Clazz.overrideMethod (c$, "drawOval",
\r
450 function (x, y, width, height) {
\r
451 swingjs.JSToolkit.notImplemented (null);
\r
453 Clazz.overrideMethod (c$, "fillOval",
\r
454 function (x, y, width, height) {
\r
455 swingjs.JSToolkit.notImplemented (null);
\r
457 Clazz.overrideMethod (c$, "getClip",
\r
459 swingjs.JSToolkit.notImplemented (null);
\r
462 Clazz.overrideMethod (c$, "drawStringTrans",
\r
463 function (str, x, y) {
\r
464 swingjs.JSToolkit.notImplemented (null);
\r
466 Clazz.defineMethod (c$, "drawString",
\r
467 function (iterator, x, y) {
\r
468 swingjs.JSToolkit.notImplemented (null);
\r
469 }, "java.text.AttributedCharacterIterator,~N,~N");
\r
470 Clazz.overrideMethod (c$, "drawStringAttrTrans",
\r
471 function (iterator, x, y) {
\r
472 swingjs.JSToolkit.notImplemented (null);
\r
473 }, "java.text.AttributedCharacterIterator,~N,~N");
\r
474 Clazz.overrideMethod (c$, "translateTrans",
\r
475 function (tx, ty) {
\r
476 swingjs.JSToolkit.notImplemented (null);
\r
478 Clazz.defineMethod (c$, "rotate",
\r
480 swingjs.JSToolkit.notImplemented (null);
\r
482 Clazz.defineMethod (c$, "rotate",
\r
483 function (theta, x, y) {
\r
484 swingjs.JSToolkit.notImplemented (null);
\r
486 Clazz.overrideMethod (c$, "shear",
\r
487 function (shx, shy) {
\r
488 swingjs.JSToolkit.notImplemented (null);
\r
490 Clazz.overrideMethod (c$, "transform",
\r
492 swingjs.JSToolkit.notImplemented (null);
\r
493 }, "java.awt.geom.AffineTransform");
\r
494 Clazz.overrideMethod (c$, "setTransform",
\r
496 swingjs.JSToolkit.notImplemented (null);
\r
497 }, "java.awt.geom.AffineTransform");
\r
498 Clazz.overrideMethod (c$, "getTransform",
\r
500 swingjs.JSToolkit.notImplemented (null);
\r
503 Clazz.defineMethod (c$, "cloneTransform",
\r
505 swingjs.JSToolkit.notImplemented (null);
\r
508 Clazz.overrideMethod (c$, "getPaint",
\r
510 swingjs.JSToolkit.notImplemented (null);
\r
513 Clazz.overrideMethod (c$, "getStroke",
\r
515 swingjs.JSToolkit.notImplemented (null);
\r
518 Clazz.overrideMethod (c$, "getFontRenderContext",
\r
520 swingjs.JSToolkit.notImplemented (null);
\r
523 Clazz.overrideMethod (c$, "setPaintMode",
\r
525 swingjs.JSToolkit.notImplemented (null);
\r
527 Clazz.overrideMethod (c$, "setXORMode",
\r
529 swingjs.JSToolkit.notImplemented (null);
\r
530 }, "java.awt.Color");
\r
531 Clazz.defineMethod (c$, "getClipBounds",
\r
535 if (arguments.length == 1) r = arguments[0];
\r
536 }var clipRect = this.getClipBoundsImpl ();
\r
542 r.width = clipRect.width;
\r
543 r.height = clipRect.height;
\r
546 Clazz.defineMethod (c$, "getClipBoundsImpl",
\r
548 if (this.currentClip == null) {
\r
549 this.currentClip = new java.awt.Rectangle (0, 0, this.windowWidth, this.windowHeight);
\r
550 }return this.currentClip;
\r
552 Clazz.overrideMethod (c$, "setComposite",
\r
555 var isValid = (comp == null || (Clazz.instanceOf (comp, java.awt.AlphaComposite)) && (newRule = (comp).getRule ()) != this.compositeState);
\r
556 if (!isValid) return;
\r
557 if (swingjs.JSToolkit.setGraphicsCompositeAlpha (this, newRule)) this.compositeState = newRule;
\r
558 }, "java.awt.Composite");
\r
559 Clazz.defineMethod (c$, "drawImage",
\r
560 function (img, op, x, y) {
\r
561 swingjs.JSToolkit.drawImageOp (this, img, op, x, y);
\r
562 }, "java.awt.image.BufferedImage,java.awt.image.BufferedImageOp,~N,~N");
\r
563 Clazz.defineMethod (c$, "setAlpha",
\r
566 this.ctx.globalAlpha = f;
\r
568 Clazz.defineStatics (c$,
\r