df9ac2c1c0957416e9e3d46e5a3e1cd8c572a49b
[jalviewjs.git] / site / swingjs / j2s / javax / swing / colorchooser / SmartGridLayout.js
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 () {
4 this.rows = 2;
5 this.columns = 2;
6 this.xGap = 2;
7 this.yGap = 2;
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) {
14 this.rows = numRows;
15 this.columns = numColumns;
16 this.layoutGrid =  Clazz.newArray (numColumns, numRows, null);
17 }, "~N,~N");
18 Clazz.overrideMethod (c$, "layoutContainer", 
19 function (c) {
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);
25 }
26 for (var column = 0; column < this.columns; column++) {
27 columnWidths[column] = this.computeColumnWidth (column);
28 }
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);
38 }
39 horizLoc += (columnWidths[column] + this.xGap);
40 }
41 } else {
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);
50 }
51 horizLoc -= this.xGap;
52 }
53 }}, "java.awt.Container");
54 Clazz.overrideMethod (c$, "minimumLayoutSize", 
55 function (c) {
56 this.buildLayoutGrid (c);
57 var insets = c.getInsets ();
58 var height = 0;
59 var width = 0;
60 for (var row = 0; row < this.rows; row++) {
61 height += this.computeRowHeight (row);
62 }
63 for (var column = 0; column < this.columns; column++) {
64 width += this.computeColumnWidth (column);
65 }
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", 
71 function (c) {
72 return this.minimumLayoutSize (c);
73 }, "java.awt.Container");
74 Clazz.overrideMethod (c$, "addLayoutComponent", 
75 function (s, c) {
76 }, "~S,java.awt.Component");
77 Clazz.overrideMethod (c$, "removeLayoutComponent", 
78 function (c) {
79 }, "java.awt.Component");
80 Clazz.defineMethod (c$, "buildLayoutGrid", 
81  function (c) {
82 var children = c.getComponents ();
83 for (var componentCount = 0; componentCount < children.length; componentCount++) {
84 var row = 0;
85 var column = 0;
86 if (componentCount != 0) {
87 column = componentCount % this.columns;
88 row = Clazz.doubleToInt ((componentCount - column) / this.columns);
89 }this.layoutGrid[column][row] = children[componentCount];
90 }
91 }, "java.awt.Container");
92 Clazz.defineMethod (c$, "computeColumnWidth", 
93  function (columnNum) {
94 var maxWidth = 1;
95 for (var row = 0; row < this.rows; row++) {
96 var width = this.layoutGrid[columnNum][row].getPreferredSize ().width;
97 if (width > maxWidth) {
98 maxWidth = width;
99 }}
100 return maxWidth;
101 }, "~N");
102 Clazz.defineMethod (c$, "computeRowHeight", 
103  function (rowNum) {
104 var maxHeight = 1;
105 for (var column = 0; column < this.columns; column++) {
106 var height = this.layoutGrid[column][rowNum].getPreferredSize ().height;
107 if (height > maxHeight) {
108 maxHeight = height;
109 }}
110 return maxHeight;
111 }, "~N");
112 });