1 Clazz.declarePackage ("java.awt");
2 Clazz.load (["java.awt.LayoutManager"], "java.awt.GridLayout", ["java.lang.IllegalArgumentException", "java.awt.Dimension"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 Clazz.instantialize (this, arguments);
9 }, java.awt, "GridLayout", null, [java.awt.LayoutManager, java.io.Serializable]);
10 Clazz.makeConstructor (c$,
12 this.construct (1, 0, 0, 0);
14 Clazz.makeConstructor (c$,
15 function (rows, cols) {
16 this.construct (rows, cols, 0, 0);
18 Clazz.makeConstructor (c$,
19 function (rows, cols, hgap, vgap) {
20 if ((rows == 0) && (cols == 0)) {
21 throw new IllegalArgumentException ("rows and cols cannot both be zero");
27 Clazz.defineMethod (c$, "getRows",
31 Clazz.defineMethod (c$, "setRows",
33 if ((rows == 0) && (this.cols == 0)) {
34 throw new IllegalArgumentException ("rows and cols cannot both be zero");
37 Clazz.defineMethod (c$, "getColumns",
41 Clazz.defineMethod (c$, "setColumns",
43 if ((cols == 0) && (this.rows == 0)) {
44 throw new IllegalArgumentException ("rows and cols cannot both be zero");
47 Clazz.defineMethod (c$, "getHgap",
51 Clazz.defineMethod (c$, "setHgap",
55 Clazz.defineMethod (c$, "getVgap",
59 Clazz.defineMethod (c$, "setVgap",
63 Clazz.overrideMethod (c$, "addLayoutComponent",
64 function (name, comp) {
65 }, "~S,java.awt.Component");
66 Clazz.overrideMethod (c$, "removeLayoutComponent",
68 }, "java.awt.Component");
69 Clazz.overrideMethod (c$, "preferredLayoutSize",
72 var insets = parent.getInsets ();
73 var ncomponents = parent.getComponentCount ();
74 var nrows = this.rows;
75 var ncols = this.cols;
77 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
79 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);
82 for (var i = 0; i < ncomponents; i++) {
83 var comp = parent.getComponent (i);
84 var d = comp.getPreferredSize ();
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);
91 }}, "java.awt.Container");
92 Clazz.overrideMethod (c$, "minimumLayoutSize",
95 var insets = parent.getInsets ();
96 var ncomponents = parent.getComponentCount ();
97 var nrows = this.rows;
98 var ncols = this.cols;
100 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
102 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);
105 for (var i = 0; i < ncomponents; i++) {
106 var comp = parent.getComponent (i);
107 var d = comp.getMinimumSize ();
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);
114 }}, "java.awt.Container");
115 Clazz.overrideMethod (c$, "layoutContainer",
118 var insets = parent.getInsets ();
119 var ncomponents = parent.getComponentCount ();
120 var nrows = this.rows;
121 var ncols = this.cols;
122 var ltr = parent.getComponentOrientation ().isLeftToRight ();
123 if (ncomponents == 0) {
126 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
128 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);
129 }var totalGapsWidth = (ncols - 1) * this.hgap;
130 var widthWOInsets = parent.width - (insets.left + insets.right);
131 var widthOnComponent = Clazz.doubleToInt ((widthWOInsets - totalGapsWidth) / ncols);
132 var extraWidthAvailable = Clazz.doubleToInt ((widthWOInsets - (widthOnComponent * ncols + totalGapsWidth)) / 2);
133 var totalGapsHeight = (nrows - 1) * this.vgap;
134 var heightWOInsets = parent.height - (insets.top + insets.bottom);
135 var heightOnComponent = Clazz.doubleToInt ((heightWOInsets - totalGapsHeight) / nrows);
136 var extraHeightAvailable = Clazz.doubleToInt ((heightWOInsets - (heightOnComponent * nrows + totalGapsHeight)) / 2);
138 for (var c = 0, x = insets.left + extraWidthAvailable; c < ncols; c++, x += widthOnComponent + this.hgap) {
139 for (var r = 0, y = insets.top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + this.vgap) {
140 var i = r * ncols + c;
141 if (i < ncomponents) {
142 parent.getComponent (i).setBounds (x, y, widthOnComponent, heightOnComponent);
146 for (var c = 0, x = (parent.width - insets.right - widthOnComponent) - extraWidthAvailable; c < ncols; c++, x -= widthOnComponent + this.hgap) {
147 for (var r = 0, y = insets.top + extraHeightAvailable; r < nrows; r++, y += heightOnComponent + this.vgap) {
148 var i = r * ncols + c;
149 if (i < ncomponents) {
150 parent.getComponent (i).setBounds (x, y, widthOnComponent, heightOnComponent);
153 }}}, "java.awt.Container");
154 Clazz.overrideMethod (c$, "toString",
156 return this.getClass ().getName () + "[hgap=" + this.hgap + ",vgap=" + this.vgap + ",rows=" + this.rows + ",cols=" + this.cols + "]";