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
8 Clazz.instantialize (this, arguments);
\r
9 }, java.awt, "GridLayout", null, [java.awt.LayoutManager, java.io.Serializable]);
\r
10 Clazz.makeConstructor (c$,
\r
12 this.construct (1, 0, 0, 0);
\r
14 Clazz.makeConstructor (c$,
\r
15 function (rows, cols) {
\r
16 this.construct (rows, cols, 0, 0);
\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
27 Clazz.defineMethod (c$, "getRows",
\r
31 Clazz.defineMethod (c$, "setRows",
\r
33 if ((rows == 0) && (this.cols == 0)) {
\r
34 throw new IllegalArgumentException ("rows and cols cannot both be zero");
\r
37 Clazz.defineMethod (c$, "getColumns",
\r
41 Clazz.defineMethod (c$, "setColumns",
\r
43 if ((cols == 0) && (this.rows == 0)) {
\r
44 throw new IllegalArgumentException ("rows and cols cannot both be zero");
\r
47 Clazz.defineMethod (c$, "getHgap",
\r
51 Clazz.defineMethod (c$, "setHgap",
\r
55 Clazz.defineMethod (c$, "getVgap",
\r
59 Clazz.defineMethod (c$, "setVgap",
\r
63 Clazz.overrideMethod (c$, "addLayoutComponent",
\r
64 function (name, comp) {
\r
65 }, "~S,java.awt.Component");
\r
66 Clazz.overrideMethod (c$, "removeLayoutComponent",
\r
68 }, "java.awt.Component");
\r
69 Clazz.overrideMethod (c$, "preferredLayoutSize",
\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
77 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
\r
79 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);
\r
82 for (var i = 0; i < ncomponents; i++) {
\r
83 var comp = parent.getComponent (i);
\r
84 var d = comp.getPreferredSize ();
\r
87 }if (h < d.height) {
\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
95 var insets = parent.getInsets ();
\r
96 var ncomponents = parent.getComponentCount ();
\r
97 var nrows = this.rows;
\r
98 var ncols = this.cols;
\r
100 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
\r
102 nrows = Clazz.doubleToInt ((ncomponents + ncols - 1) / ncols);
\r
105 for (var i = 0; i < ncomponents; i++) {
\r
106 var comp = parent.getComponent (i);
\r
107 var d = comp.getMinimumSize ();
\r
110 }if (h < d.height) {
\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
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
126 ncols = Clazz.doubleToInt ((ncomponents + nrows - 1) / nrows);
\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
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
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
153 }}}, "java.awt.Container");
\r
154 Clazz.overrideMethod (c$, "toString",
\r
156 return this.getClass ().getName () + "[hgap=" + this.hgap + ",vgap=" + this.vgap + ",rows=" + this.rows + ",cols=" + this.cols + "]";
\r