Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / Graphics.js
1 Clazz.declarePackage ("java.awt");
2 c$ = Clazz.declareType (java.awt, "Graphics");
3 Clazz.makeConstructor (c$, 
4 function () {
5 });
6 Clazz.defineMethod (c$, "create", 
7 function () {
8 return this.createSwingJS ();
9 });
10 Clazz.defineMethod (c$, "create", 
11 function (x, y, width, height) {
12 return this.create4 (x, y, width, height);
13 }, "~N,~N,~N,~N");
14 Clazz.defineMethod (c$, "create4", 
15 function (x, y, width, height) {
16 var g = this.createSwingJS ();
17 if (g == null) return null;
18 g.translate (x, y);
19 g.clipRect (0, 0, width, height);
20 return g;
21 }, "~N,~N,~N,~N");
22 Clazz.defineMethod (c$, "getFontMetrics", 
23 function () {
24 return this.getFontMetrics (this.getFont ());
25 });
26 Clazz.defineMethod (c$, "drawRect", 
27 function (x, y, width, height) {
28 if ((width < 0) || (height < 0)) {
29 return;
30 }if (height == 0 || width == 0) {
31 this.drawLine (x, y, x + width, y + height);
32 } else {
33 this.drawLine (x, y, x + width - 1, y);
34 this.drawLine (x + width, y, x + width, y + height - 1);
35 this.drawLine (x + width, y + height, x + 1, y + height);
36 this.drawLine (x, y + height, x, y + 1);
37 }}, "~N,~N,~N,~N");
38 Clazz.defineMethod (c$, "draw3DRect", 
39 function (x, y, width, height, raised) {
40 var c = this.getColor ();
41 var brighter = c.brighter ();
42 var darker = c.darker ();
43 this.setColor (raised ? brighter : darker);
44 this.drawLine (x, y, x, y + height);
45 this.drawLine (x + 1, y, x + width - 1, y);
46 this.setColor (raised ? darker : brighter);
47 this.drawLine (x + 1, y + height, x + width, y + height);
48 this.drawLine (x + width, y, x + width, y + height - 1);
49 this.setColor (c);
50 }, "~N,~N,~N,~N,~B");
51 Clazz.defineMethod (c$, "fill3DRect", 
52 function (x, y, width, height, raised) {
53 var c = this.getColor ();
54 var brighter = c.brighter ();
55 var darker = c.darker ();
56 if (!raised) {
57 this.setColor (darker);
58 }this.fillRect (x + 1, y + 1, width - 2, height - 2);
59 this.setColor (raised ? brighter : darker);
60 this.drawLine (x, y, x, y + height - 1);
61 this.drawLine (x + 1, y, x + width - 2, y);
62 this.setColor (raised ? darker : brighter);
63 this.drawLine (x + 1, y + height - 1, x + width - 1, y + height - 1);
64 this.drawLine (x + width - 1, y, x + width - 1, y + height - 2);
65 this.setColor (c);
66 }, "~N,~N,~N,~N,~B");
67 Clazz.defineMethod (c$, "drawPolygon", 
68 function (p) {
69 this.drawPolygon (p.xpoints, p.ypoints, p.npoints);
70 }, "java.awt.Polygon");
71 Clazz.defineMethod (c$, "fillPolygon", 
72 function (p) {
73 this.fillPolygon (p.xpoints, p.ypoints, p.npoints);
74 }, "java.awt.Polygon");
75 Clazz.defineMethod (c$, "drawChars", 
76 function (data, offset, length, x, y) {
77 this.drawString ( String.instantialize (data, offset, length), x, y);
78 }, "~A,~N,~N,~N,~N");
79 Clazz.defineMethod (c$, "drawBytes", 
80 function (data, offset, length, x, y) {
81 this.drawString ( String.instantialize (data, 0, offset, length), x, y);
82 }, "~A,~N,~N,~N,~N");
83 Clazz.overrideMethod (c$, "finalize", 
84 function () {
85 this.dispose ();
86 });
87 Clazz.overrideMethod (c$, "toString", 
88 function () {
89 return this.getClass ().getName () + "[font=" + this.getFont () + ",color=" + this.getColor () + "]";
90 });
91 Clazz.defineMethod (c$, "getClipRect", 
92 function () {
93 return this.getClipBounds ();
94 });
95 Clazz.defineMethod (c$, "hitClip", 
96 function (x, y, width, height) {
97 var clipRect = this.getClipBounds ();
98 if (clipRect == null) {
99 return true;
100 }return clipRect.intersects (x, y, width, height);
101 }, "~N,~N,~N,~N");