JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / BorderLayout.js
1 Clazz.declarePackage ("java.awt");\r
2 Clazz.load (["java.awt.LayoutManager2"], "java.awt.BorderLayout", ["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.north = null;\r
7 this.west = null;\r
8 this.east = null;\r
9 this.south = null;\r
10 this.center = null;\r
11 this.firstLine = null;\r
12 this.lastLine = null;\r
13 this.firstItem = null;\r
14 this.lastItem = null;\r
15 Clazz.instantialize (this, arguments);\r
16 }, java.awt, "BorderLayout", null, [java.awt.LayoutManager2, java.io.Serializable]);\r
17 Clazz.makeConstructor (c$, \r
18 function () {\r
19 this.construct (0, 0);\r
20 });\r
21 Clazz.makeConstructor (c$, \r
22 function (hgap, vgap) {\r
23 this.hgap = hgap;\r
24 this.vgap = vgap;\r
25 }, "~N,~N");\r
26 Clazz.defineMethod (c$, "getHgap", \r
27 function () {\r
28 return this.hgap;\r
29 });\r
30 Clazz.defineMethod (c$, "setHgap", \r
31 function (hgap) {\r
32 this.hgap = hgap;\r
33 }, "~N");\r
34 Clazz.defineMethod (c$, "getVgap", \r
35 function () {\r
36 return this.vgap;\r
37 });\r
38 Clazz.defineMethod (c$, "setVgap", \r
39 function (vgap) {\r
40 this.vgap = vgap;\r
41 }, "~N");\r
42 Clazz.defineMethod (c$, "addLayoutComponent", \r
43 function (comp, constraints) {\r
44 {\r
45 if ((constraints == null) || (Clazz.instanceOf (constraints, String))) {\r
46 this.addLayoutComponent (constraints, comp);\r
47 } else {\r
48 throw  new IllegalArgumentException ("cannot add to layout: constraint must be a string (or null)");\r
49 }}}, "java.awt.Component,~O");\r
50 Clazz.defineMethod (c$, "addLayoutComponent", \r
51 function (name, comp) {\r
52 {\r
53 if (name == null) {\r
54 name = "Center";\r
55 }System.out.println ("BorderLayout adding " + name + " " + comp);\r
56 if ("Center".equals (name)) {\r
57 this.center = comp;\r
58 } else if ("North".equals (name)) {\r
59 this.north = comp;\r
60 } else if ("South".equals (name)) {\r
61 this.south = comp;\r
62 } else if ("East".equals (name)) {\r
63 this.east = comp;\r
64 } else if ("West".equals (name)) {\r
65 this.west = comp;\r
66 } else if ("First".equals (name)) {\r
67 this.firstLine = comp;\r
68 } else if ("Last".equals (name)) {\r
69 this.lastLine = comp;\r
70 } else if ("Before".equals (name)) {\r
71 this.firstItem = comp;\r
72 } else if ("After".equals (name)) {\r
73 this.lastItem = comp;\r
74 } else {\r
75 throw  new IllegalArgumentException ("cannot add to layout: unknown constraint: " + name);\r
76 }}}, "~S,java.awt.Component");\r
77 Clazz.overrideMethod (c$, "removeLayoutComponent", \r
78 function (comp) {\r
79 {\r
80 if (comp === this.center) {\r
81 this.center = null;\r
82 } else if (comp === this.north) {\r
83 this.north = null;\r
84 } else if (comp === this.south) {\r
85 this.south = null;\r
86 } else if (comp === this.east) {\r
87 this.east = null;\r
88 } else if (comp === this.west) {\r
89 this.west = null;\r
90 }if (comp === this.firstLine) {\r
91 this.firstLine = null;\r
92 } else if (comp === this.lastLine) {\r
93 this.lastLine = null;\r
94 } else if (comp === this.firstItem) {\r
95 this.firstItem = null;\r
96 } else if (comp === this.lastItem) {\r
97 this.lastItem = null;\r
98 }}}, "java.awt.Component");\r
99 Clazz.defineMethod (c$, "getLayoutComponent", \r
100 function (constraints) {\r
101 if ("Center".equals (constraints)) {\r
102 return this.center;\r
103 } else if ("North".equals (constraints)) {\r
104 return this.north;\r
105 } else if ("South".equals (constraints)) {\r
106 return this.south;\r
107 } else if ("West".equals (constraints)) {\r
108 return this.west;\r
109 } else if ("East".equals (constraints)) {\r
110 return this.east;\r
111 } else if ("First".equals (constraints)) {\r
112 return this.firstLine;\r
113 } else if ("Last".equals (constraints)) {\r
114 return this.lastLine;\r
115 } else if ("Before".equals (constraints)) {\r
116 return this.firstItem;\r
117 } else if ("After".equals (constraints)) {\r
118 return this.lastItem;\r
119 } else {\r
120 throw  new IllegalArgumentException ("cannot get component: unknown constraint: " + constraints);\r
121 }}, "~O");\r
122 Clazz.defineMethod (c$, "getLayoutComponent", \r
123 function (target, constraints) {\r
124 var ltr = target.getComponentOrientation ().isLeftToRight ();\r
125 var result = null;\r
126 if ("North".equals (constraints)) {\r
127 result = (this.firstLine != null) ? this.firstLine : this.north;\r
128 } else if ("South".equals (constraints)) {\r
129 result = (this.lastLine != null) ? this.lastLine : this.south;\r
130 } else if ("West".equals (constraints)) {\r
131 result = ltr ? this.firstItem : this.lastItem;\r
132 if (result == null) {\r
133 result = this.west;\r
134 }} else if ("East".equals (constraints)) {\r
135 result = ltr ? this.lastItem : this.firstItem;\r
136 if (result == null) {\r
137 result = this.east;\r
138 }} else if ("Center".equals (constraints)) {\r
139 result = this.center;\r
140 } else {\r
141 throw  new IllegalArgumentException ("cannot get component: invalid constraint: " + constraints);\r
142 }return result;\r
143 }, "java.awt.Container,~O");\r
144 Clazz.defineMethod (c$, "getConstraints", \r
145 function (comp) {\r
146 if (comp == null) {\r
147 return null;\r
148 }if (comp === this.center) {\r
149 return "Center";\r
150 } else if (comp === this.north) {\r
151 return "North";\r
152 } else if (comp === this.south) {\r
153 return "South";\r
154 } else if (comp === this.west) {\r
155 return "West";\r
156 } else if (comp === this.east) {\r
157 return "East";\r
158 } else if (comp === this.firstLine) {\r
159 return "First";\r
160 } else if (comp === this.lastLine) {\r
161 return "Last";\r
162 } else if (comp === this.firstItem) {\r
163 return "Before";\r
164 } else if (comp === this.lastItem) {\r
165 return "After";\r
166 }return null;\r
167 }, "java.awt.Component");\r
168 Clazz.overrideMethod (c$, "minimumLayoutSize", \r
169 function (target) {\r
170 {\r
171 var dim =  new java.awt.Dimension (0, 0);\r
172 var ltr = target.getComponentOrientation ().isLeftToRight ();\r
173 var c = null;\r
174 if ((c = this.getChild ("East", ltr)) != null) {\r
175 var d = c.getMinimumSize ();\r
176 dim.width += d.width + this.hgap;\r
177 dim.height = Math.max (d.height, dim.height);\r
178 }if ((c = this.getChild ("West", ltr)) != null) {\r
179 var d = c.getMinimumSize ();\r
180 dim.width += d.width + this.hgap;\r
181 dim.height = Math.max (d.height, dim.height);\r
182 }if ((c = this.getChild ("Center", ltr)) != null) {\r
183 var d = c.getMinimumSize ();\r
184 dim.width += d.width;\r
185 dim.height = Math.max (d.height, dim.height);\r
186 }if ((c = this.getChild ("North", ltr)) != null) {\r
187 var d = c.getMinimumSize ();\r
188 dim.width = Math.max (d.width, dim.width);\r
189 dim.height += d.height + this.vgap;\r
190 }if ((c = this.getChild ("South", ltr)) != null) {\r
191 var d = c.getMinimumSize ();\r
192 dim.width = Math.max (d.width, dim.width);\r
193 dim.height += d.height + this.vgap;\r
194 }var insets = target.getInsets ();\r
195 dim.width += insets.left + insets.right;\r
196 dim.height += insets.top + insets.bottom;\r
197 return dim;\r
198 }}, "java.awt.Container");\r
199 Clazz.overrideMethod (c$, "preferredLayoutSize", \r
200 function (target) {\r
201 {\r
202 var dim =  new java.awt.Dimension (0, 0);\r
203 var ltr = target.getComponentOrientation ().isLeftToRight ();\r
204 var c = null;\r
205 if ((c = this.getChild ("East", ltr)) != null) {\r
206 var d = c.getPreferredSize ();\r
207 dim.width += d.width + this.hgap;\r
208 dim.height = Math.max (d.height, dim.height);\r
209 }if ((c = this.getChild ("West", ltr)) != null) {\r
210 var d = c.getPreferredSize ();\r
211 dim.width += d.width + this.hgap;\r
212 dim.height = Math.max (d.height, dim.height);\r
213 }if ((c = this.getChild ("Center", ltr)) != null) {\r
214 var d = c.getPreferredSize ();\r
215 dim.width += d.width;\r
216 dim.height = Math.max (d.height, dim.height);\r
217 }if ((c = this.getChild ("North", ltr)) != null) {\r
218 var d = c.getPreferredSize ();\r
219 dim.width = Math.max (d.width, dim.width);\r
220 dim.height += d.height + this.vgap;\r
221 }if ((c = this.getChild ("South", ltr)) != null) {\r
222 var d = c.getPreferredSize ();\r
223 dim.width = Math.max (d.width, dim.width);\r
224 dim.height += d.height + this.vgap;\r
225 }var insets = target.getInsets ();\r
226 dim.width += insets.left + insets.right;\r
227 dim.height += insets.top + insets.bottom;\r
228 return dim;\r
229 }}, "java.awt.Container");\r
230 Clazz.overrideMethod (c$, "maximumLayoutSize", \r
231 function (target) {\r
232 return  new java.awt.Dimension (2147483647, 2147483647);\r
233 }, "java.awt.Container");\r
234 Clazz.overrideMethod (c$, "getLayoutAlignmentX", \r
235 function (parent) {\r
236 return 0.5;\r
237 }, "java.awt.Container");\r
238 Clazz.overrideMethod (c$, "getLayoutAlignmentY", \r
239 function (parent) {\r
240 return 0.5;\r
241 }, "java.awt.Container");\r
242 Clazz.overrideMethod (c$, "invalidateLayout", \r
243 function (target) {\r
244 }, "java.awt.Container");\r
245 Clazz.overrideMethod (c$, "layoutContainer", \r
246 function (target) {\r
247 System.out.println ("BorderLayout laying out " + target);\r
248 {\r
249 var insets = target.getInsets ();\r
250 var top = insets.top;\r
251 var bottom = target.height - insets.bottom;\r
252 var left = insets.left;\r
253 var right = target.width - insets.right;\r
254 var ltr = target.getComponentOrientation ().isLeftToRight ();\r
255 var c = null;\r
256 if ((c = this.getChild ("North", ltr)) != null) {\r
257 c.setSize (right - left, c.height);\r
258 var d = c.getPreferredSize ();\r
259 c.setBounds (left, top, right - left, d.height);\r
260 top += d.height + this.vgap;\r
261 }if ((c = this.getChild ("South", ltr)) != null) {\r
262 c.setSize (right - left, c.height);\r
263 var d = c.getPreferredSize ();\r
264 c.setBounds (left, bottom - d.height, right - left, d.height);\r
265 bottom -= d.height + this.vgap;\r
266 }if ((c = this.getChild ("East", ltr)) != null) {\r
267 c.setSize (c.width, bottom - top);\r
268 var d = c.getPreferredSize ();\r
269 c.setBounds (right - d.width, top, d.width, bottom - top);\r
270 right -= d.width + this.hgap;\r
271 }if ((c = this.getChild ("West", ltr)) != null) {\r
272 c.setSize (c.width, bottom - top);\r
273 var d = c.getPreferredSize ();\r
274 c.setBounds (left, top, d.width, bottom - top);\r
275 left += d.width + this.hgap;\r
276 }if ((c = this.getChild ("Center", ltr)) != null) {\r
277 c.setBounds (left, top, right - left, bottom - top);\r
278 }}}, "java.awt.Container");\r
279 Clazz.defineMethod (c$, "getChild", \r
280  function (key, ltr) {\r
281 var result = null;\r
282 if (key === "North") {\r
283 result = (this.firstLine != null) ? this.firstLine : this.north;\r
284 } else if (key === "South") {\r
285 result = (this.lastLine != null) ? this.lastLine : this.south;\r
286 } else if (key === "West") {\r
287 result = ltr ? this.firstItem : this.lastItem;\r
288 if (result == null) {\r
289 result = this.west;\r
290 }} else if (key === "East") {\r
291 result = ltr ? this.lastItem : this.firstItem;\r
292 if (result == null) {\r
293 result = this.east;\r
294 }} else if (key === "Center") {\r
295 result = this.center;\r
296 }if (result != null && !result.visible) {\r
297 result = null;\r
298 }return result;\r
299 }, "~S,~B");\r
300 Clazz.overrideMethod (c$, "toString", \r
301 function () {\r
302 return this.getClass ().getName () + "[hgap=" + this.hgap + ",vgap=" + this.vgap + "]";\r
303 });\r
304 Clazz.defineStatics (c$,\r
305 "NORTH", "North",\r
306 "SOUTH", "South",\r
307 "EAST", "East",\r
308 "WEST", "West",\r
309 "CENTER", "Center",\r
310 "BEFORE_FIRST_LINE", "First",\r
311 "AFTER_LAST_LINE", "Last",\r
312 "BEFORE_LINE_BEGINS", "Before",\r
313 "AFTER_LINE_ENDS", "After");\r
314 c$.PAGE_START = c$.prototype.PAGE_START = "First";\r
315 c$.PAGE_END = c$.prototype.PAGE_END = "Last";\r
316 c$.LINE_START = c$.prototype.LINE_START = "Before";\r
317 c$.LINE_END = c$.prototype.LINE_END = "After";\r
318 });\r