JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / GridLayout.js
1 Clazz.declarePackage ("java.awt");\r
2 Clazz.load (["java.awt.LayoutManager"], "java.awt.GridLayout", ["java.lang.IllegalArgumentException", "java.awt.Dimension"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.hgap = 0;\r
5 this.vgap = 0;\r
6 this.rows = 0;\r
7 this.cols = 0;\r
8 Clazz.instantialize (this, arguments);\r
9 }, java.awt, "GridLayout", null, [java.awt.LayoutManager, java.io.Serializable]);\r
10 Clazz.makeConstructor (c$, \r
11 function () {\r
12 this.construct (1, 0, 0, 0);\r
13 });\r
14 Clazz.makeConstructor (c$, \r
15 function (rows, cols) {\r
16 this.construct (rows, cols, 0, 0);\r
17 }, "~N,~N");\r
18 Clazz.makeConstructor (c$, \r
19 function (rows, cols, hgap, vgap) {\r
20 if ((rows == 0) && (cols == 0)) {\r
21 throw  new IllegalArgumentException ("rows and cols cannot both be zero");\r
22 }this.rows = rows;\r
23 this.cols = cols;\r
24 this.hgap = hgap;\r
25 this.vgap = vgap;\r
26 }, "~N,~N,~N,~N");\r
27 Clazz.defineMethod (c$, "getRows", \r
28 function () {\r
29 return this.rows;\r
30 });\r
31 Clazz.defineMethod (c$, "setRows", \r
32 function (rows) {\r
33 if ((rows == 0) && (this.cols == 0)) {\r
34 throw  new IllegalArgumentException ("rows and cols cannot both be zero");\r
35 }this.rows = rows;\r
36 }, "~N");\r
37 Clazz.defineMethod (c$, "getColumns", \r
38 function () {\r
39 return this.cols;\r
40 });\r
41 Clazz.defineMethod (c$, "setColumns", \r
42 function (cols) {\r
43 if ((cols == 0) && (this.rows == 0)) {\r
44 throw  new IllegalArgumentException ("rows and cols cannot both be zero");\r
45 }this.cols = cols;\r
46 }, "~N");\r
47 Clazz.defineMethod (c$, "getHgap", \r
48 function () {\r
49 return this.hgap;\r
50 });\r
51 Clazz.defineMethod (c$, "setHgap", \r
52 function (hgap) {\r
53 this.hgap = hgap;\r
54 }, "~N");\r
55 Clazz.defineMethod (c$, "getVgap", \r
56 function () {\r
57 return this.vgap;\r
58 });\r
59 Clazz.defineMethod (c$, "setVgap", \r
60 function (vgap) {\r
61 this.vgap = vgap;\r
62 }, "~N");\r
63 Clazz.overrideMethod (c$, "addLayoutComponent", \r
64 function (name, comp) {\r
65 }, "~S,java.awt.Component");\r
66 Clazz.overrideMethod (c$, "removeLayoutComponent", \r
67 function (comp) {\r
68 }, "java.awt.Component");\r
69 Clazz.overrideMethod (c$, "preferredLayoutSize", \r
70 function (parent) {\r
71 {\r
72 var insets = parent.getInsets ();\r
73 var ncomponents = parent.getComponentCount ();\r
74 var nrows = this.rows;\r
75 var ncols = this.cols;\r
76 if (nrows > 0) {\r
77 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);\r
78 } else {\r
79 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);\r
80 }var w = 0;\r
81 var h = 0;\r
82 for (var i = 0; i < ncomponents; i++) {\r
83 var comp = parent.getComponent (i);\r
84 var d = comp.getPreferredSize ();\r
85 if (w < d.width) {\r
86 w = d.width;\r
87 }if (h < d.height) {\r
88 h = d.height;\r
89 }}\r
90 return  new java.awt.Dimension (insets.left + insets.right + ncols * w + (ncols - 1) * this.hgap, insets.top + insets.bottom + nrows * h + (nrows - 1) * this.vgap);\r
91 }}, "java.awt.Container");\r
92 Clazz.overrideMethod (c$, "minimumLayoutSize", \r
93 function (parent) {\r
94 {\r
95 var insets = parent.getInsets ();\r
96 var ncomponents = parent.getComponentCount ();\r
97 var nrows = this.rows;\r
98 var ncols = this.cols;\r
99 if (nrows > 0) {\r
100 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);\r
101 } else {\r
102 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);\r
103 }var w = 0;\r
104 var h = 0;\r
105 for (var i = 0; i < ncomponents; i++) {\r
106 var comp = parent.getComponent (i);\r
107 var d = comp.getMinimumSize ();\r
108 if (w < d.width) {\r
109 w = d.width;\r
110 }if (h < d.height) {\r
111 h = d.height;\r
112 }}\r
113 return  new java.awt.Dimension (insets.left + insets.right + ncols * w + (ncols - 1) * this.hgap, insets.top + insets.bottom + nrows * h + (nrows - 1) * this.vgap);\r
114 }}, "java.awt.Container");\r
115 Clazz.overrideMethod (c$, "layoutContainer", \r
116 function (parent) {\r
117 {\r
118 var insets = parent.getInsets ();\r
119 var ncomponents = parent.getComponentCount ();\r
120 var nrows = this.rows;\r
121 var ncols = this.cols;\r
122 var ltr = parent.getComponentOrientation ().isLeftToRight ();\r
123 if (ncomponents == 0) {\r
124 return;\r
125 }if (nrows > 0) {\r
126 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);\r
127 } else {\r
128 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);\r
129 }var totalGapsWidth = (ncols - 1) * this.hgap;\r
130 var widthWOInsets = parent.width - (insets.left + insets.right);\r
131 var widthOnComponent = Clazz.doubleToInt ((widthWOInsets - totalGapsWidth) / ncols);\r
132 var extraWidthAvailable = Clazz.doubleToInt ((widthWOInsets - (widthOnComponent * ncols + totalGapsWidth)) / 2);\r
133 var totalGapsHeight = (nrows - 1) * this.vgap;\r
134 var heightWOInsets = parent.height - (insets.top + insets.bottom);\r
135 var heightOnComponent = Clazz.doubleToInt ((heightWOInsets - totalGapsHeight) / nrows);\r
136 var extraHeightAvailable = Clazz.doubleToInt ((heightWOInsets - (heightOnComponent * nrows + totalGapsHeight)) / 2);\r
137 if (ltr) {\r
138 for (var c = 0, x = insets.left + extraWidthAvailable; c < ncols; c++, x += widthOnComponent + this.hgap) {\r
139 for (var r = 0, y = insets.top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + this.vgap) {\r
140 var i = r * ncols + c;\r
141 if (i < ncomponents) {\r
142 parent.getComponent (i).setBounds (x, y, widthOnComponent, heightOnComponent);\r
143 }}\r
144 }\r
145 } else {\r
146 for (var c = 0, x = (parent.width - insets.right - widthOnComponent) - extraWidthAvailable; c < ncols; c++, x -= widthOnComponent + this.hgap) {\r
147 for (var r = 0, y = insets.top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + this.vgap) {\r
148 var i = r * ncols + c;\r
149 if (i < ncomponents) {\r
150 parent.getComponent (i).setBounds (x, y, widthOnComponent, heightOnComponent);\r
151 }}\r
152 }\r
153 }}}, "java.awt.Container");\r
154 Clazz.overrideMethod (c$, "toString", \r
155 function () {\r
156 return this.getClass ().getName () + "[hgap=" + this.hgap + ",vgap=" + this.vgap + ",rows=" + this.rows + ",cols=" + this.cols + "]";\r
157 });\r
158 });\r