2bb4be39c26e557986f3f27f34feaceec9a8e2d5
[jalviewjs.git] / site / swingjs / j2s / javax / swing / border / MatteBorder.js
1 Clazz.declarePackage ("javax.swing.border");
2 Clazz.load (["javax.swing.border.EmptyBorder"], "javax.swing.border.MatteBorder", ["java.awt.Color", "$.Insets"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.color = null;
5 this.tileIcon = null;
6 Clazz.instantialize (this, arguments);
7 }, javax.swing.border, "MatteBorder", javax.swing.border.EmptyBorder);
8 Clazz.makeConstructor (c$, 
9 function (top, left, bottom, right, matteColor) {
10 Clazz.superConstructor (this, javax.swing.border.MatteBorder, [top, left, bottom, right]);
11 this.color = matteColor;
12 }, "~N,~N,~N,~N,java.awt.Color");
13 Clazz.makeConstructor (c$, 
14 function (borderInsets, matteColor) {
15 Clazz.superConstructor (this, javax.swing.border.MatteBorder, [borderInsets]);
16 this.color = matteColor;
17 }, "java.awt.Insets,java.awt.Color");
18 Clazz.makeConstructor (c$, 
19 function (top, left, bottom, right, tileIcon) {
20 Clazz.superConstructor (this, javax.swing.border.MatteBorder, [top, left, bottom, right]);
21 this.tileIcon = tileIcon;
22 }, "~N,~N,~N,~N,javax.swing.Icon");
23 Clazz.makeConstructor (c$, 
24 function (borderInsets, tileIcon) {
25 Clazz.superConstructor (this, javax.swing.border.MatteBorder, [borderInsets]);
26 this.tileIcon = tileIcon;
27 }, "java.awt.Insets,javax.swing.Icon");
28 Clazz.makeConstructor (c$, 
29 function (tileIcon) {
30 this.construct (-1, -1, -1, -1, tileIcon);
31 }, "javax.swing.Icon");
32 Clazz.overrideMethod (c$, "paintBorder", 
33 function (c, g, x, y, width, height) {
34 var insets = this.getBorderInsets (c);
35 var oldColor = g.getColor ();
36 g.translate (x, y);
37 if (this.tileIcon != null) {
38 this.color = (this.tileIcon.getIconWidth () == -1) ? java.awt.Color.gray : null;
39 }if (this.color != null) {
40 g.setColor (this.color);
41 g.fillRect (0, 0, width - insets.right, insets.top);
42 g.fillRect (0, insets.top, insets.left, height - insets.top);
43 g.fillRect (insets.left, height - insets.bottom, width - insets.left, insets.bottom);
44 g.fillRect (width - insets.right, 0, insets.right, height - insets.bottom);
45 } else if (this.tileIcon != null) {
46 var tileW = this.tileIcon.getIconWidth ();
47 var tileH = this.tileIcon.getIconHeight ();
48 var xpos;
49 var ypos;
50 var startx;
51 var starty;
52 var cg;
53 cg = g.createSwingJS ();
54 cg.setClip (0, 0, width, insets.top);
55 for (ypos = 0; insets.top - ypos > 0; ypos += tileH) {
56 for (xpos = 0; width - xpos > 0; xpos += tileW) {
57 this.tileIcon.paintIcon (c, cg, xpos, ypos);
58 }
59 }
60 cg.dispose ();
61 cg = g.createSwingJS ();
62 cg.setClip (0, insets.top, insets.left, height - insets.top);
63 starty = insets.top - (insets.top % tileH);
64 startx = 0;
65 for (ypos = starty; height - ypos > 0; ypos += tileH) {
66 for (xpos = startx; insets.left - xpos > 0; xpos += tileW) {
67 this.tileIcon.paintIcon (c, cg, xpos, ypos);
68 }
69 }
70 cg.dispose ();
71 cg = g.createSwingJS ();
72 cg.setClip (insets.left, height - insets.bottom, width - insets.left, insets.bottom);
73 starty = (height - insets.bottom) - ((height - insets.bottom) % tileH);
74 startx = insets.left - (insets.left % tileW);
75 for (ypos = starty; height - ypos > 0; ypos += tileH) {
76 for (xpos = startx; width - xpos > 0; xpos += tileW) {
77 this.tileIcon.paintIcon (c, cg, xpos, ypos);
78 }
79 }
80 cg.dispose ();
81 cg = g.createSwingJS ();
82 cg.setClip (width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
83 starty = insets.top - (insets.top % tileH);
84 startx = width - insets.right - ((width - insets.right) % tileW);
85 for (ypos = starty; height - ypos > 0; ypos += tileH) {
86 for (xpos = startx; width - xpos > 0; xpos += tileW) {
87 this.tileIcon.paintIcon (c, cg, xpos, ypos);
88 }
89 }
90 cg.dispose ();
91 }g.translate (-x, -y);
92 g.setColor (oldColor);
93 }, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N");
94 Clazz.defineMethod (c$, "getBorderInsets", 
95 function (c) {
96 return this.getBorderInsets ();
97 }, "java.awt.Component");
98 Clazz.defineMethod (c$, "getBorderInsets", 
99 function (c, insets) {
100 return this.computeInsets (insets);
101 }, "java.awt.Component,java.awt.Insets");
102 Clazz.defineMethod (c$, "getBorderInsets", 
103 function () {
104 return this.computeInsets ( new java.awt.Insets (0, 0, 0, 0));
105 });
106 Clazz.defineMethod (c$, "computeInsets", 
107  function (insets) {
108 if (this.tileIcon != null && this.top == -1 && this.bottom == -1 && this.left == -1 && this.right == -1) {
109 var w = this.tileIcon.getIconWidth ();
110 var h = this.tileIcon.getIconHeight ();
111 insets.top = h;
112 insets.right = w;
113 insets.bottom = h;
114 insets.left = w;
115 } else {
116 insets.left = this.left;
117 insets.top = this.top;
118 insets.right = this.right;
119 insets.bottom = this.bottom;
120 }return insets;
121 }, "java.awt.Insets");
122 Clazz.defineMethod (c$, "getMatteColor", 
123 function () {
124 return this.color;
125 });
126 Clazz.defineMethod (c$, "getTileIcon", 
127 function () {
128 return this.tileIcon;
129 });
130 Clazz.overrideMethod (c$, "isBorderOpaque", 
131 function () {
132 return this.color != null;
133 });
134 });