Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / GridBagLayout.js
1 Clazz.declarePackage ("java.awt");
2 Clazz.load (["java.awt.LayoutManager2"], "java.awt.GridBagLayout", ["java.lang.IllegalArgumentException", "java.util.Arrays", "$.Hashtable", "java.awt.Component", "$.Dimension", "$.GridBagConstraints", "$.GridBagLayoutInfo", "$.Point", "$.Rectangle"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.comptable = null;
5 this.defaultConstraints = null;
6 this.layoutInfo = null;
7 this.columnWidths = null;
8 this.rowHeights = null;
9 this.columnWeights = null;
10 this.rowWeights = null;
11 this.componentAdjusting = null;
12 this.rightToLeft = false;
13 Clazz.instantialize (this, arguments);
14 }, java.awt, "GridBagLayout", null, [java.awt.LayoutManager2, java.io.Serializable]);
15 Clazz.makeConstructor (c$, 
16 function () {
17 this.comptable =  new java.util.Hashtable ();
18 this.defaultConstraints =  new java.awt.GridBagConstraints ();
19 });
20 Clazz.defineMethod (c$, "setConstraints", 
21 function (comp, constraints) {
22 this.comptable.put (comp, constraints.clone ());
23 }, "java.awt.Component,java.awt.GridBagConstraints");
24 Clazz.defineMethod (c$, "getConstraints", 
25 function (comp) {
26 var constraints = this.comptable.get (comp);
27 if (constraints == null) {
28 this.setConstraints (comp, this.defaultConstraints);
29 constraints = this.comptable.get (comp);
30 }return constraints.clone ();
31 }, "java.awt.Component");
32 Clazz.defineMethod (c$, "lookupConstraints", 
33 function (comp) {
34 var constraints = this.comptable.get (comp);
35 if (constraints == null) {
36 this.setConstraints (comp, this.defaultConstraints);
37 constraints = this.comptable.get (comp);
38 }return constraints;
39 }, "java.awt.Component");
40 Clazz.defineMethod (c$, "removeConstraints", 
41  function (comp) {
42 this.comptable.remove (comp);
43 }, "java.awt.Component");
44 Clazz.defineMethod (c$, "getLayoutOrigin", 
45 function () {
46 var origin =  new java.awt.Point (0, 0);
47 if (this.layoutInfo != null) {
48 origin.x = this.layoutInfo.startx;
49 origin.y = this.layoutInfo.starty;
50 }return origin;
51 });
52 Clazz.defineMethod (c$, "getLayoutDimensions", 
53 function () {
54 if (this.layoutInfo == null) return  Clazz.newIntArray (2, 0, 0);
55 var dim =  Clazz.newIntArray (2, 0);
56 dim[0] =  Clazz.newIntArray (this.layoutInfo.width, 0);
57 dim[1] =  Clazz.newIntArray (this.layoutInfo.height, 0);
58 System.arraycopy (this.layoutInfo.minWidth, 0, dim[0], 0, this.layoutInfo.width);
59 System.arraycopy (this.layoutInfo.minHeight, 0, dim[1], 0, this.layoutInfo.height);
60 return dim;
61 });
62 Clazz.defineMethod (c$, "getLayoutWeights", 
63 function () {
64 if (this.layoutInfo == null) return  Clazz.newDoubleArray (2, 0, 0);
65 var weights =  Clazz.newDoubleArray (2, 0);
66 weights[0] =  Clazz.newDoubleArray (this.layoutInfo.width, 0);
67 weights[1] =  Clazz.newDoubleArray (this.layoutInfo.height, 0);
68 System.arraycopy (this.layoutInfo.weightX, 0, weights[0], 0, this.layoutInfo.width);
69 System.arraycopy (this.layoutInfo.weightY, 0, weights[1], 0, this.layoutInfo.height);
70 return weights;
71 });
72 Clazz.defineMethod (c$, "location", 
73 function (x, y) {
74 var loc =  new java.awt.Point (0, 0);
75 var i;
76 var d;
77 if (this.layoutInfo == null) return loc;
78 d = this.layoutInfo.startx;
79 if (!this.rightToLeft) {
80 for (i = 0; i < this.layoutInfo.width; i++) {
81 d += this.layoutInfo.minWidth[i];
82 if (d > x) break;
83 }
84 } else {
85 for (i = this.layoutInfo.width - 1; i >= 0; i--) {
86 if (d > x) break;
87 d += this.layoutInfo.minWidth[i];
88 }
89 i++;
90 }loc.x = i;
91 d = this.layoutInfo.starty;
92 for (i = 0; i < this.layoutInfo.height; i++) {
93 d += this.layoutInfo.minHeight[i];
94 if (d > y) break;
95 }
96 loc.y = i;
97 return loc;
98 }, "~N,~N");
99 Clazz.defineMethod (c$, "addLayoutComponent", 
100 function (name, comp) {
101 }, "~S,java.awt.Component");
102 Clazz.defineMethod (c$, "addLayoutComponent", 
103 function (comp, constraints) {
104 if (Clazz.instanceOf (constraints, java.awt.GridBagConstraints)) {
105 this.setConstraints (comp, constraints);
106 } else if (constraints != null) {
107 throw  new IllegalArgumentException ("cannot add to layout: constraints must be a GridBagConstraint");
108 }}, "java.awt.Component,~O");
109 Clazz.overrideMethod (c$, "removeLayoutComponent", 
110 function (comp) {
111 this.removeConstraints (comp);
112 }, "java.awt.Component");
113 Clazz.overrideMethod (c$, "preferredLayoutSize", 
114 function (parent) {
115 var info = this.getLayoutInfo (parent, 2);
116 return this.getMinSize (parent, info);
117 }, "java.awt.Container");
118 Clazz.overrideMethod (c$, "minimumLayoutSize", 
119 function (parent) {
120 var info = this.getLayoutInfo (parent, 1);
121 return this.getMinSize (parent, info);
122 }, "java.awt.Container");
123 Clazz.overrideMethod (c$, "maximumLayoutSize", 
124 function (target) {
125 return  new java.awt.Dimension (2147483647, 2147483647);
126 }, "java.awt.Container");
127 Clazz.overrideMethod (c$, "getLayoutAlignmentX", 
128 function (parent) {
129 return 0.5;
130 }, "java.awt.Container");
131 Clazz.overrideMethod (c$, "getLayoutAlignmentY", 
132 function (parent) {
133 return 0.5;
134 }, "java.awt.Container");
135 Clazz.overrideMethod (c$, "invalidateLayout", 
136 function (target) {
137 }, "java.awt.Container");
138 Clazz.overrideMethod (c$, "layoutContainer", 
139 function (parent) {
140 System.out.println ("GridBagLayout laying out " + parent);
141 this.arrangeGrid (parent);
142 }, "java.awt.Container");
143 Clazz.overrideMethod (c$, "toString", 
144 function () {
145 return this.getClass ().getName ();
146 });
147 Clazz.defineMethod (c$, "getLayoutInfo", 
148 function (parent, sizeflag) {
149 return this.GetLayoutInfo (parent, sizeflag);
150 }, "java.awt.Container,~N");
151 Clazz.defineMethod (c$, "preInitMaximumArraySizes", 
152  function (parent) {
153 var components = parent.getComponents ();
154 var comp;
155 var constraints;
156 var curX;
157 var curY;
158 var curWidth;
159 var curHeight;
160 var preMaximumArrayXIndex = 0;
161 var preMaximumArrayYIndex = 0;
162 var returnArray =  Clazz.newLongArray (2, 0);
163 for (var compId = 0; compId < components.length; compId++) {
164 comp = components[compId];
165 if (!comp.isVisible ()) {
166 continue;
167 }constraints = this.lookupConstraints (comp);
168 curX = constraints.gridx;
169 curY = constraints.gridy;
170 curWidth = constraints.gridwidth;
171 curHeight = constraints.gridheight;
172 if (curX < 0) {
173 curX = ++preMaximumArrayYIndex;
174 }if (curY < 0) {
175 curY = ++preMaximumArrayXIndex;
176 }if (curWidth <= 0) {
177 curWidth = 1;
178 }if (curHeight <= 0) {
179 curHeight = 1;
180 }preMaximumArrayXIndex = Math.max (curY + curHeight, preMaximumArrayXIndex);
181 preMaximumArrayYIndex = Math.max (curX + curWidth, preMaximumArrayYIndex);
182 }
183 returnArray[0] = preMaximumArrayXIndex;
184 returnArray[1] = preMaximumArrayYIndex;
185 return returnArray;
186 }, "java.awt.Container");
187 Clazz.defineMethod (c$, "GetLayoutInfo", 
188 function (parent, sizeflag) {
189 {
190 var r;
191 var comp;
192 var constraints;
193 var d;
194 var components = parent.getComponents ();
195 var layoutWidth;
196 var layoutHeight;
197 var xMaxArray;
198 var yMaxArray;
199 var compindex;
200 var i;
201 var k;
202 var px;
203 var py;
204 var pixels_diff;
205 var nextSize;
206 var curX = 0;
207 var curY = 0;
208 var curWidth = 1;
209 var curHeight = 1;
210 var curRow;
211 var curCol;
212 var weight_diff;
213 var weight;
214 var maximumArrayXIndex = 0;
215 var maximumArrayYIndex = 0;
216 var anchor;
217 layoutWidth = layoutHeight = 0;
218 curRow = curCol = -1;
219 var arraySizes = this.preInitMaximumArraySizes (parent);
220 maximumArrayXIndex = (2 * arraySizes[0] > 2147483647) ? 2147483647 : 2 * arraySizes[0];
221 maximumArrayYIndex = (2 * arraySizes[1] > 2147483647) ? 2147483647 : 2 * arraySizes[1];
222 if (this.rowHeights != null) {
223 maximumArrayXIndex = Math.max (maximumArrayXIndex, this.rowHeights.length);
224 }if (this.columnWidths != null) {
225 maximumArrayYIndex = Math.max (maximumArrayYIndex, this.columnWidths.length);
226 }xMaxArray =  Clazz.newIntArray (maximumArrayXIndex, 0);
227 yMaxArray =  Clazz.newIntArray (maximumArrayYIndex, 0);
228 var hasBaseline = false;
229 for (compindex = 0; compindex < components.length; compindex++) {
230 comp = components[compindex];
231 if (!comp.isVisible ()) continue;
232 constraints = this.lookupConstraints (comp);
233 curX = constraints.gridx;
234 curY = constraints.gridy;
235 curWidth = constraints.gridwidth;
236 if (curWidth <= 0) curWidth = 1;
237 curHeight = constraints.gridheight;
238 if (curHeight <= 0) curHeight = 1;
239 if (curX < 0 && curY < 0) {
240 if (curRow >= 0) curY = curRow;
241  else if (curCol >= 0) curX = curCol;
242  else curY = 0;
243 }if (curX < 0) {
244 px = 0;
245 for (i = curY; i < (curY + curHeight); i++) {
246 px = Math.max (px, xMaxArray[i]);
247 }
248 curX = px - curX - 1;
249 if (curX < 0) curX = 0;
250 } else if (curY < 0) {
251 py = 0;
252 for (i = curX; i < (curX + curWidth); i++) {
253 py = Math.max (py, yMaxArray[i]);
254 }
255 curY = py - curY - 1;
256 if (curY < 0) curY = 0;
257 }px = curX + curWidth;
258 if (layoutWidth < px) {
259 layoutWidth = px;
260 }py = curY + curHeight;
261 if (layoutHeight < py) {
262 layoutHeight = py;
263 }for (i = curX; i < (curX + curWidth); i++) {
264 yMaxArray[i] = py;
265 }
266 for (i = curY; i < (curY + curHeight); i++) {
267 xMaxArray[i] = px;
268 }
269 if (sizeflag == 2) d = comp.getPreferredSize ();
270  else d = comp.getMinimumSize ();
271 constraints.minWidth = d.width;
272 constraints.minHeight = d.height;
273 if (this.calculateBaseline (comp, constraints, d)) {
274 hasBaseline = true;
275 }if (constraints.gridheight == 0 && constraints.gridwidth == 0) curRow = curCol = -1;
276 if (constraints.gridheight == 0 && curRow < 0) curCol = curX + curWidth;
277  else if (constraints.gridwidth == 0 && curCol < 0) curRow = curY + curHeight;
278 }
279 if (this.columnWidths != null && layoutWidth < this.columnWidths.length) layoutWidth = this.columnWidths.length;
280 if (this.rowHeights != null && layoutHeight < this.rowHeights.length) layoutHeight = this.rowHeights.length;
281 r =  new java.awt.GridBagLayoutInfo (layoutWidth, layoutHeight);
282 curRow = curCol = -1;
283 java.util.Arrays.fill (xMaxArray, 0);
284 java.util.Arrays.fill (yMaxArray, 0);
285 var maxAscent = null;
286 var maxDescent = null;
287 var baselineType = null;
288 if (hasBaseline) {
289 r.maxAscent = maxAscent =  Clazz.newIntArray (layoutHeight, 0);
290 r.maxDescent = maxDescent =  Clazz.newIntArray (layoutHeight, 0);
291 r.baselineType = baselineType =  Clazz.newShortArray (layoutHeight, 0);
292 r.$hasBaseline = true;
293 }for (compindex = 0; compindex < components.length; compindex++) {
294 comp = components[compindex];
295 if (!comp.isVisible ()) continue;
296 constraints = this.lookupConstraints (comp);
297 curX = constraints.gridx;
298 curY = constraints.gridy;
299 curWidth = constraints.gridwidth;
300 curHeight = constraints.gridheight;
301 if (curX < 0 && curY < 0) {
302 if (curRow >= 0) curY = curRow;
303  else if (curCol >= 0) curX = curCol;
304  else curY = 0;
305 }if (curX < 0) {
306 if (curHeight <= 0) {
307 curHeight += r.height - curY;
308 if (curHeight < 1) curHeight = 1;
309 }px = 0;
310 for (i = curY; i < (curY + curHeight); i++) px = Math.max (px, xMaxArray[i]);
311
312 curX = px - curX - 1;
313 if (curX < 0) curX = 0;
314 } else if (curY < 0) {
315 if (curWidth <= 0) {
316 curWidth += r.width - curX;
317 if (curWidth < 1) curWidth = 1;
318 }py = 0;
319 for (i = curX; i < (curX + curWidth); i++) {
320 py = Math.max (py, yMaxArray[i]);
321 }
322 curY = py - curY - 1;
323 if (curY < 0) curY = 0;
324 }if (curWidth <= 0) {
325 curWidth += r.width - curX;
326 if (curWidth < 1) curWidth = 1;
327 }if (curHeight <= 0) {
328 curHeight += r.height - curY;
329 if (curHeight < 1) curHeight = 1;
330 }px = curX + curWidth;
331 py = curY + curHeight;
332 for (i = curX; i < (curX + curWidth); i++) {
333 yMaxArray[i] = py;
334 }
335 for (i = curY; i < (curY + curHeight); i++) {
336 xMaxArray[i] = px;
337 }
338 if (constraints.gridheight == 0 && constraints.gridwidth == 0) curRow = curCol = -1;
339 if (constraints.gridheight == 0 && curRow < 0) curCol = curX + curWidth;
340  else if (constraints.gridwidth == 0 && curCol < 0) curRow = curY + curHeight;
341 constraints.tempX = curX;
342 constraints.tempY = curY;
343 constraints.tempWidth = curWidth;
344 constraints.tempHeight = curHeight;
345 anchor = constraints.anchor;
346 if (hasBaseline) {
347 switch (anchor) {
348 case 256:
349 case 512:
350 case 768:
351 if (constraints.ascent >= 0) {
352 if (curHeight == 1) {
353 maxAscent[curY] = Math.max (maxAscent[curY], constraints.ascent);
354 maxDescent[curY] = Math.max (maxDescent[curY], constraints.descent);
355 } else {
356 if (constraints.baselineResizeBehavior === java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT) {
357 maxDescent[curY + curHeight - 1] = Math.max (maxDescent[curY + curHeight - 1], constraints.descent);
358 } else {
359 maxAscent[curY] = Math.max (maxAscent[curY], constraints.ascent);
360 }}if (constraints.baselineResizeBehavior === java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT) {
361 baselineType[curY + curHeight - 1] |= (1 << constraints.baselineResizeBehavior.ordinal ());
362 } else {
363 baselineType[curY] |= (1 << constraints.baselineResizeBehavior.ordinal ());
364 }}break;
365 case 1024:
366 case 1280:
367 case 1536:
368 pixels_diff = constraints.minHeight + constraints.insets.top + constraints.ipady;
369 maxAscent[curY] = Math.max (maxAscent[curY], pixels_diff);
370 maxDescent[curY] = Math.max (maxDescent[curY], constraints.insets.bottom);
371 break;
372 case 1792:
373 case 2048:
374 case 2304:
375 pixels_diff = constraints.minHeight + constraints.insets.bottom + constraints.ipady;
376 maxDescent[curY] = Math.max (maxDescent[curY], pixels_diff);
377 maxAscent[curY] = Math.max (maxAscent[curY], constraints.insets.top);
378 break;
379 }
380 }}
381 r.weightX =  Clazz.newDoubleArray (maximumArrayYIndex, 0);
382 r.weightY =  Clazz.newDoubleArray (maximumArrayXIndex, 0);
383 r.minWidth =  Clazz.newIntArray (maximumArrayYIndex, 0);
384 r.minHeight =  Clazz.newIntArray (maximumArrayXIndex, 0);
385 if (this.columnWidths != null) System.arraycopy (this.columnWidths, 0, r.minWidth, 0, this.columnWidths.length);
386 if (this.rowHeights != null) System.arraycopy (this.rowHeights, 0, r.minHeight, 0, this.rowHeights.length);
387 if (this.columnWeights != null) System.arraycopy (this.columnWeights, 0, r.weightX, 0, Math.min (r.weightX.length, this.columnWeights.length));
388 if (this.rowWeights != null) System.arraycopy (this.rowWeights, 0, r.weightY, 0, Math.min (r.weightY.length, this.rowWeights.length));
389 nextSize = 2147483647;
390 for (i = 1; i != 2147483647; i = nextSize, nextSize = 2147483647) {
391 for (compindex = 0; compindex < components.length; compindex++) {
392 comp = components[compindex];
393 if (!comp.isVisible ()) continue;
394 constraints = this.lookupConstraints (comp);
395 if (constraints.tempWidth == i) {
396 px = constraints.tempX + constraints.tempWidth;
397 weight_diff = constraints.weightx;
398 for (k = constraints.tempX; k < px; k++) weight_diff -= r.weightX[k];
399
400 if (weight_diff > 0.0) {
401 weight = 0.0;
402 for (k = constraints.tempX; k < px; k++) weight += r.weightX[k];
403
404 for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
405 var wt = r.weightX[k];
406 var dx = (wt * weight_diff) / weight;
407 r.weightX[k] += dx;
408 weight_diff -= dx;
409 weight -= wt;
410 }
411 r.weightX[px - 1] += weight_diff;
412 }pixels_diff = constraints.minWidth + constraints.ipadx + constraints.insets.left + constraints.insets.right;
413 for (k = constraints.tempX; k < px; k++) pixels_diff -= r.minWidth[k];
414
415 if (pixels_diff > 0) {
416 weight = 0.0;
417 for (k = constraints.tempX; k < px; k++) weight += r.weightX[k];
418
419 for (k = constraints.tempX; weight > 0.0 && k < px; k++) {
420 var wt = r.weightX[k];
421 var dx = Clazz.doubleToInt ((wt * (pixels_diff)) / weight);
422 r.minWidth[k] += dx;
423 pixels_diff -= dx;
424 weight -= wt;
425 }
426 r.minWidth[px - 1] += pixels_diff;
427 }} else if (constraints.tempWidth > i && constraints.tempWidth < nextSize) nextSize = constraints.tempWidth;
428 if (constraints.tempHeight == i) {
429 py = constraints.tempY + constraints.tempHeight;
430 weight_diff = constraints.weighty;
431 for (k = constraints.tempY; k < py; k++) weight_diff -= r.weightY[k];
432
433 if (weight_diff > 0.0) {
434 weight = 0.0;
435 for (k = constraints.tempY; k < py; k++) weight += r.weightY[k];
436
437 for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
438 var wt = r.weightY[k];
439 var dy = (wt * weight_diff) / weight;
440 r.weightY[k] += dy;
441 weight_diff -= dy;
442 weight -= wt;
443 }
444 r.weightY[py - 1] += weight_diff;
445 }pixels_diff = -1;
446 if (hasBaseline) {
447 switch (constraints.anchor) {
448 case 256:
449 case 512:
450 case 768:
451 if (constraints.ascent >= 0) {
452 if (constraints.tempHeight == 1) {
453 pixels_diff = maxAscent[constraints.tempY] + maxDescent[constraints.tempY];
454 } else if (constraints.baselineResizeBehavior !== java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT) {
455 pixels_diff = maxAscent[constraints.tempY] + constraints.descent;
456 } else {
457 pixels_diff = constraints.ascent + maxDescent[constraints.tempY + constraints.tempHeight - 1];
458 }}break;
459 case 1024:
460 case 1280:
461 case 1536:
462 pixels_diff = constraints.insets.top + constraints.minHeight + constraints.ipady + maxDescent[constraints.tempY];
463 break;
464 case 1792:
465 case 2048:
466 case 2304:
467 pixels_diff = maxAscent[constraints.tempY] + constraints.minHeight + constraints.insets.bottom + constraints.ipady;
468 break;
469 }
470 }if (pixels_diff == -1) {
471 pixels_diff = constraints.minHeight + constraints.ipady + constraints.insets.top + constraints.insets.bottom;
472 }for (k = constraints.tempY; k < py; k++) pixels_diff -= r.minHeight[k];
473
474 if (pixels_diff > 0) {
475 weight = 0.0;
476 for (k = constraints.tempY; k < py; k++) weight += r.weightY[k];
477
478 for (k = constraints.tempY; weight > 0.0 && k < py; k++) {
479 var wt = r.weightY[k];
480 var dy = Clazz.doubleToInt ((wt * (pixels_diff)) / weight);
481 r.minHeight[k] += dy;
482 pixels_diff -= dy;
483 weight -= wt;
484 }
485 r.minHeight[py - 1] += pixels_diff;
486 }} else if (constraints.tempHeight > i && constraints.tempHeight < nextSize) nextSize = constraints.tempHeight;
487 }
488 }
489 return r;
490 }}, "java.awt.Container,~N");
491 Clazz.defineMethod (c$, "calculateBaseline", 
492  function (c, constraints, size) {
493 var anchor = constraints.anchor;
494 if (anchor == 256 || anchor == 512 || anchor == 768) {
495 var w = size.width + constraints.ipadx;
496 var h = size.height + constraints.ipady;
497 constraints.ascent = c.getBaseline (w, h);
498 if (constraints.ascent >= 0) {
499 var baseline = constraints.ascent;
500 constraints.descent = h - constraints.ascent + constraints.insets.bottom;
501 constraints.ascent += constraints.insets.top;
502 constraints.baselineResizeBehavior = c.getBaselineResizeBehavior ();
503 constraints.centerPadding = 0;
504 if (constraints.baselineResizeBehavior === java.awt.Component.BaselineResizeBehavior.CENTER_OFFSET) {
505 var nextBaseline = c.getBaseline (w, h + 1);
506 constraints.centerOffset = baseline - Clazz.doubleToInt (h / 2);
507 if (h % 2 == 0) {
508 if (baseline != nextBaseline) {
509 constraints.centerPadding = 1;
510 }} else if (baseline == nextBaseline) {
511 constraints.centerOffset--;
512 constraints.centerPadding = 1;
513 }}}return true;
514 } else {
515 constraints.ascent = -1;
516 return false;
517 }}, "java.awt.Component,java.awt.GridBagConstraints,java.awt.Dimension");
518 Clazz.defineMethod (c$, "adjustForGravity", 
519 function (constraints, r) {
520 this.AdjustForGravity (constraints, r);
521 }, "java.awt.GridBagConstraints,java.awt.Rectangle");
522 Clazz.defineMethod (c$, "AdjustForGravity", 
523 function (constraints, r) {
524 var diffx;
525 var diffy;
526 var cellY = r.y;
527 var cellHeight = r.height;
528 if (!this.rightToLeft) {
529 r.x += constraints.insets.left;
530 } else {
531 r.x -= r.width - constraints.insets.right;
532 }r.width -= (constraints.insets.left + constraints.insets.right);
533 r.y += constraints.insets.top;
534 r.height -= (constraints.insets.top + constraints.insets.bottom);
535 diffx = 0;
536 if ((constraints.fill != 2 && constraints.fill != 1) && (r.width > (constraints.minWidth + constraints.ipadx))) {
537 diffx = r.width - (constraints.minWidth + constraints.ipadx);
538 r.width = constraints.minWidth + constraints.ipadx;
539 }diffy = 0;
540 if ((constraints.fill != 3 && constraints.fill != 1) && (r.height > (constraints.minHeight + constraints.ipady))) {
541 diffy = r.height - (constraints.minHeight + constraints.ipady);
542 r.height = constraints.minHeight + constraints.ipady;
543 }switch (constraints.anchor) {
544 case 256:
545 r.x += Clazz.doubleToInt (diffx / 2);
546 this.alignOnBaseline (constraints, r, cellY, cellHeight);
547 break;
548 case 512:
549 if (this.rightToLeft) {
550 r.x += diffx;
551 }this.alignOnBaseline (constraints, r, cellY, cellHeight);
552 break;
553 case 768:
554 if (!this.rightToLeft) {
555 r.x += diffx;
556 }this.alignOnBaseline (constraints, r, cellY, cellHeight);
557 break;
558 case 1024:
559 r.x += Clazz.doubleToInt (diffx / 2);
560 this.alignAboveBaseline (constraints, r, cellY, cellHeight);
561 break;
562 case 1280:
563 if (this.rightToLeft) {
564 r.x += diffx;
565 }this.alignAboveBaseline (constraints, r, cellY, cellHeight);
566 break;
567 case 1536:
568 if (!this.rightToLeft) {
569 r.x += diffx;
570 }this.alignAboveBaseline (constraints, r, cellY, cellHeight);
571 break;
572 case 1792:
573 r.x += Clazz.doubleToInt (diffx / 2);
574 this.alignBelowBaseline (constraints, r, cellY, cellHeight);
575 break;
576 case 2048:
577 if (this.rightToLeft) {
578 r.x += diffx;
579 }this.alignBelowBaseline (constraints, r, cellY, cellHeight);
580 break;
581 case 2304:
582 if (!this.rightToLeft) {
583 r.x += diffx;
584 }this.alignBelowBaseline (constraints, r, cellY, cellHeight);
585 break;
586 case 10:
587 r.x += Clazz.doubleToInt (diffx / 2);
588 r.y += Clazz.doubleToInt (diffy / 2);
589 break;
590 case 19:
591 case 11:
592 r.x += Clazz.doubleToInt (diffx / 2);
593 break;
594 case 12:
595 r.x += diffx;
596 break;
597 case 13:
598 r.x += diffx;
599 r.y += Clazz.doubleToInt (diffy / 2);
600 break;
601 case 14:
602 r.x += diffx;
603 r.y += diffy;
604 break;
605 case 20:
606 case 15:
607 r.x += Clazz.doubleToInt (diffx / 2);
608 r.y += diffy;
609 break;
610 case 16:
611 r.y += diffy;
612 break;
613 case 17:
614 r.y += Clazz.doubleToInt (diffy / 2);
615 break;
616 case 18:
617 break;
618 case 21:
619 if (this.rightToLeft) {
620 r.x += diffx;
621 }r.y += Clazz.doubleToInt (diffy / 2);
622 break;
623 case 22:
624 if (!this.rightToLeft) {
625 r.x += diffx;
626 }r.y += Clazz.doubleToInt (diffy / 2);
627 break;
628 case 23:
629 if (this.rightToLeft) {
630 r.x += diffx;
631 }break;
632 case 24:
633 if (!this.rightToLeft) {
634 r.x += diffx;
635 }break;
636 case 25:
637 if (this.rightToLeft) {
638 r.x += diffx;
639 }r.y += diffy;
640 break;
641 case 26:
642 if (!this.rightToLeft) {
643 r.x += diffx;
644 }r.y += diffy;
645 break;
646 default:
647 throw  new IllegalArgumentException ("illegal anchor value");
648 }
649 }, "java.awt.GridBagConstraints,java.awt.Rectangle");
650 Clazz.defineMethod (c$, "alignOnBaseline", 
651  function (cons, r, cellY, cellHeight) {
652 if (cons.ascent >= 0) {
653 if (cons.baselineResizeBehavior === java.awt.Component.BaselineResizeBehavior.CONSTANT_DESCENT) {
654 var maxY = cellY + cellHeight - this.layoutInfo.maxDescent[cons.tempY + cons.tempHeight - 1] + cons.descent - cons.insets.bottom;
655 if (!cons.isVerticallyResizable ()) {
656 r.y = maxY - cons.minHeight;
657 r.height = cons.minHeight;
658 } else {
659 r.height = maxY - cellY - cons.insets.top;
660 }} else {
661 var baseline;
662 var ascent = cons.ascent;
663 if (this.layoutInfo.hasConstantDescent (cons.tempY)) {
664 baseline = cellHeight - this.layoutInfo.maxDescent[cons.tempY];
665 } else {
666 baseline = this.layoutInfo.maxAscent[cons.tempY];
667 }if (cons.baselineResizeBehavior === java.awt.Component.BaselineResizeBehavior.OTHER) {
668 var fits = false;
669 ascent = this.componentAdjusting.getBaseline (r.width, r.height);
670 if (ascent >= 0) {
671 ascent += cons.insets.top;
672 }if (ascent >= 0 && ascent <= baseline) {
673 if (baseline + (r.height - ascent - cons.insets.top) <= cellHeight - cons.insets.bottom) {
674 fits = true;
675 } else if (cons.isVerticallyResizable ()) {
676 var ascent2 = this.componentAdjusting.getBaseline (r.width, cellHeight - cons.insets.bottom - baseline + ascent);
677 if (ascent2 >= 0) {
678 ascent2 += cons.insets.top;
679 }if (ascent2 >= 0 && ascent2 <= ascent) {
680 r.height = cellHeight - cons.insets.bottom - baseline + ascent;
681 ascent = ascent2;
682 fits = true;
683 }}}if (!fits) {
684 ascent = cons.ascent;
685 r.width = cons.minWidth;
686 r.height = cons.minHeight;
687 }}r.y = cellY + baseline - ascent + cons.insets.top;
688 if (cons.isVerticallyResizable ()) {
689 switch (cons.baselineResizeBehavior) {
690 case java.awt.Component.BaselineResizeBehavior.CONSTANT_ASCENT:
691 r.height = Math.max (cons.minHeight, cellY + cellHeight - r.y - cons.insets.bottom);
692 break;
693 case java.awt.Component.BaselineResizeBehavior.CENTER_OFFSET:
694 {
695 var upper = r.y - cellY - cons.insets.top;
696 var lower = cellY + cellHeight - r.y - cons.minHeight - cons.insets.bottom;
697 var delta = Math.min (upper, lower);
698 delta += delta;
699 if (delta > 0 && Clazz.doubleToInt ((cons.minHeight + cons.centerPadding + delta) / 2) + cons.centerOffset != baseline) {
700 delta--;
701 }r.height = cons.minHeight + delta;
702 r.y = cellY + baseline - Clazz.doubleToInt ((r.height + cons.centerPadding) / 2) - cons.centerOffset;
703 }break;
704 case java.awt.Component.BaselineResizeBehavior.OTHER:
705 break;
706 default:
707 break;
708 }
709 }}} else {
710 this.centerVertically (cons, r, cellHeight);
711 }}, "java.awt.GridBagConstraints,java.awt.Rectangle,~N,~N");
712 Clazz.defineMethod (c$, "alignAboveBaseline", 
713  function (cons, r, cellY, cellHeight) {
714 if (this.layoutInfo.hasBaseline (cons.tempY)) {
715 var maxY;
716 if (this.layoutInfo.hasConstantDescent (cons.tempY)) {
717 maxY = cellY + cellHeight - this.layoutInfo.maxDescent[cons.tempY];
718 } else {
719 maxY = cellY + this.layoutInfo.maxAscent[cons.tempY];
720 }if (cons.isVerticallyResizable ()) {
721 r.y = cellY + cons.insets.top;
722 r.height = maxY - r.y;
723 } else {
724 r.height = cons.minHeight + cons.ipady;
725 r.y = maxY - r.height;
726 }} else {
727 this.centerVertically (cons, r, cellHeight);
728 }}, "java.awt.GridBagConstraints,java.awt.Rectangle,~N,~N");
729 Clazz.defineMethod (c$, "alignBelowBaseline", 
730  function (cons, r, cellY, cellHeight) {
731 if (this.layoutInfo.hasBaseline (cons.tempY)) {
732 if (this.layoutInfo.hasConstantDescent (cons.tempY)) {
733 r.y = cellY + cellHeight - this.layoutInfo.maxDescent[cons.tempY];
734 } else {
735 r.y = cellY + this.layoutInfo.maxAscent[cons.tempY];
736 }if (cons.isVerticallyResizable ()) {
737 r.height = cellY + cellHeight - r.y - cons.insets.bottom;
738 }} else {
739 this.centerVertically (cons, r, cellHeight);
740 }}, "java.awt.GridBagConstraints,java.awt.Rectangle,~N,~N");
741 Clazz.defineMethod (c$, "centerVertically", 
742  function (cons, r, cellHeight) {
743 if (!cons.isVerticallyResizable ()) {
744 r.y += Math.max (0, Clazz.doubleToInt ((cellHeight - cons.insets.top - cons.insets.bottom - cons.minHeight - cons.ipady) / 2));
745 }}, "java.awt.GridBagConstraints,java.awt.Rectangle,~N");
746 Clazz.defineMethod (c$, "getMinSize", 
747 function (parent, info) {
748 return this.GetMinSize (parent, info);
749 }, "java.awt.Container,java.awt.GridBagLayoutInfo");
750 Clazz.defineMethod (c$, "GetMinSize", 
751 function (parent, info) {
752 var d =  new java.awt.Dimension ();
753 var i;
754 var t;
755 var insets = parent.getInsets ();
756 t = 0;
757 for (i = 0; i < info.width; i++) t += info.minWidth[i];
758
759 d.width = t + insets.left + insets.right;
760 t = 0;
761 for (i = 0; i < info.height; i++) t += info.minHeight[i];
762
763 d.height = t + insets.top + insets.bottom;
764 return d;
765 }, "java.awt.Container,java.awt.GridBagLayoutInfo");
766 Clazz.defineMethod (c$, "arrangeGrid", 
767 function (parent) {
768 this.ArrangeGrid (parent);
769 }, "java.awt.Container");
770 Clazz.defineMethod (c$, "ArrangeGrid", 
771 function (parent) {
772 var comp;
773 var compindex;
774 var constraints;
775 var insets = parent.getInsets ();
776 var components = parent.getComponents ();
777 var d;
778 var r =  new java.awt.Rectangle ();
779 var i;
780 var diffw;
781 var diffh;
782 var weight;
783 var info;
784 this.rightToLeft = !parent.getComponentOrientation ().isLeftToRight ();
785 if (components.length == 0 && (this.columnWidths == null || this.columnWidths.length == 0) && (this.rowHeights == null || this.rowHeights.length == 0)) {
786 return;
787 }info = this.getLayoutInfo (parent, 2);
788 d = this.getMinSize (parent, info);
789 if (parent.width < d.width || parent.height < d.height) {
790 info = this.getLayoutInfo (parent, 1);
791 d = this.getMinSize (parent, info);
792 }this.layoutInfo = info;
793 r.width = d.width;
794 r.height = d.height;
795 diffw = parent.width - r.width;
796 if (diffw != 0) {
797 weight = 0.0;
798 for (i = 0; i < info.width; i++) weight += info.weightX[i];
799
800 if (weight > 0.0) {
801 for (i = 0; i < info.width; i++) {
802 var dx = Clazz.doubleToInt (((diffw) * info.weightX[i]) / weight);
803 info.minWidth[i] += dx;
804 r.width += dx;
805 if (info.minWidth[i] < 0) {
806 r.width -= info.minWidth[i];
807 info.minWidth[i] = 0;
808 }}
809 }diffw = parent.width - r.width;
810 } else {
811 diffw = 0;
812 }diffh = parent.height - r.height;
813 if (diffh != 0) {
814 weight = 0.0;
815 for (i = 0; i < info.height; i++) weight += info.weightY[i];
816
817 if (weight > 0.0) {
818 for (i = 0; i < info.height; i++) {
819 var dy = Clazz.doubleToInt (((diffh) * info.weightY[i]) / weight);
820 info.minHeight[i] += dy;
821 r.height += dy;
822 if (info.minHeight[i] < 0) {
823 r.height -= info.minHeight[i];
824 info.minHeight[i] = 0;
825 }}
826 }diffh = parent.height - r.height;
827 } else {
828 diffh = 0;
829 }info.startx = Clazz.doubleToInt (diffw / 2) + insets.left;
830 info.starty = Clazz.doubleToInt (diffh / 2) + insets.top;
831 for (compindex = 0; compindex < components.length; compindex++) {
832 comp = components[compindex];
833 if (!comp.isVisible ()) {
834 continue;
835 }constraints = this.lookupConstraints (comp);
836 if (!this.rightToLeft) {
837 r.x = info.startx;
838 for (i = 0; i < constraints.tempX; i++) r.x += info.minWidth[i];
839
840 } else {
841 r.x = parent.width - (Clazz.doubleToInt (diffw / 2) + insets.right);
842 for (i = 0; i < constraints.tempX; i++) r.x -= info.minWidth[i];
843
844 }r.y = info.starty;
845 for (i = 0; i < constraints.tempY; i++) r.y += info.minHeight[i];
846
847 r.width = 0;
848 for (i = constraints.tempX; i < (constraints.tempX + constraints.tempWidth); i++) {
849 r.width += info.minWidth[i];
850 }
851 r.height = 0;
852 for (i = constraints.tempY; i < (constraints.tempY + constraints.tempHeight); i++) {
853 r.height += info.minHeight[i];
854 }
855 this.componentAdjusting = comp;
856 this.adjustForGravity (constraints, r);
857 if (r.x < 0) {
858 r.width += r.x;
859 r.x = 0;
860 }if (r.y < 0) {
861 r.height += r.y;
862 r.y = 0;
863 }if ((r.width <= 0) || (r.height <= 0)) {
864 comp.setBounds (0, 0, 0, 0);
865 } else {
866 if (comp.x != r.x || comp.y != r.y || comp.width != r.width || comp.height != r.height) {
867 comp.setBounds (r.x, r.y, r.width, r.height);
868 }}}
869 }, "java.awt.Container");
870 Clazz.defineStatics (c$,
871 "EMPIRICMULTIPLIER", 2,
872 "MAXGRIDSIZE", 512,
873 "MINSIZE", 1,
874 "PREFERREDSIZE", 2);
875 });