1 Clazz.declarePackage ("javax.swing.colorchooser");
2 Clazz.load (["java.awt.LayoutManager"], "javax.swing.colorchooser.SmartGridLayout", ["java.awt.Dimension"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 this.componentCount = 0;
9 this.layoutGrid = null;
10 Clazz.instantialize (this, arguments);
11 }, javax.swing.colorchooser, "SmartGridLayout", null, java.awt.LayoutManager);
12 Clazz.makeConstructor (c$,
13 function (numColumns, numRows) {
15 this.columns = numColumns;
16 this.layoutGrid = Clazz.newArray (numColumns, numRows, null);
18 Clazz.overrideMethod (c$, "layoutContainer",
20 this.buildLayoutGrid (c);
21 var rowHeights = Clazz.newIntArray (this.rows, 0);
22 var columnWidths = Clazz.newIntArray (this.columns, 0);
23 for (var row = 0; row < this.rows; row++) {
24 rowHeights[row] = this.computeRowHeight (row);
26 for (var column = 0; column < this.columns; column++) {
27 columnWidths[column] = this.computeColumnWidth (column);
29 var insets = c.getInsets ();
30 if (c.getComponentOrientation ().isLeftToRight ()) {
31 var horizLoc = insets.left;
32 for (var column = 0; column < this.columns; column++) {
33 var vertLoc = insets.top;
34 for (var row = 0; row < this.rows; row++) {
35 var current = this.layoutGrid[column][row];
36 current.setBounds (horizLoc, vertLoc, columnWidths[column], rowHeights[row]);
37 vertLoc += (rowHeights[row] + this.yGap);
39 horizLoc += (columnWidths[column] + this.xGap);
42 var horizLoc = c.getWidth () - insets.right;
43 for (var column = 0; column < this.columns; column++) {
44 var vertLoc = insets.top;
45 horizLoc -= columnWidths[column];
46 for (var row = 0; row < this.rows; row++) {
47 var current = this.layoutGrid[column][row];
48 current.setBounds (horizLoc, vertLoc, columnWidths[column], rowHeights[row]);
49 vertLoc += (rowHeights[row] + this.yGap);
51 horizLoc -= this.xGap;
53 }}, "java.awt.Container");
54 Clazz.overrideMethod (c$, "minimumLayoutSize",
56 this.buildLayoutGrid (c);
57 var insets = c.getInsets ();
60 for (var row = 0; row < this.rows; row++) {
61 height += this.computeRowHeight (row);
63 for (var column = 0; column < this.columns; column++) {
64 width += this.computeColumnWidth (column);
66 height += (this.yGap * (this.rows - 1)) + insets.top + insets.bottom;
67 width += (this.xGap * (this.columns - 1)) + insets.right + insets.left;
68 return new java.awt.Dimension (width, height);
69 }, "java.awt.Container");
70 Clazz.overrideMethod (c$, "preferredLayoutSize",
72 return this.minimumLayoutSize (c);
73 }, "java.awt.Container");
74 Clazz.overrideMethod (c$, "addLayoutComponent",
76 }, "~S,java.awt.Component");
77 Clazz.overrideMethod (c$, "removeLayoutComponent",
79 }, "java.awt.Component");
80 Clazz.defineMethod (c$, "buildLayoutGrid",
82 var children = c.getComponents ();
83 for (var componentCount = 0; componentCount < children.length; componentCount++) {
86 if (componentCount != 0) {
87 column = componentCount % this.columns;
88 row = Clazz.doubleToInt ((componentCount - column) / this.columns);
89 }this.layoutGrid[column][row] = children[componentCount];
91 }, "java.awt.Container");
92 Clazz.defineMethod (c$, "computeColumnWidth",
93 function (columnNum) {
95 for (var row = 0; row < this.rows; row++) {
96 var width = this.layoutGrid[columnNum][row].getPreferredSize ().width;
97 if (width > maxWidth) {
102 Clazz.defineMethod (c$, "computeRowHeight",
105 for (var column = 0; column < this.columns; column++) {
106 var height = this.layoutGrid[column][rowNum].getPreferredSize ().height;
107 if (height > maxHeight) {