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