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