1:
42:
43: package ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
57: public class LCBLayout implements LayoutManager, Serializable {
58:
59:
60: private static final long serialVersionUID = -2531780832406163833L;
61:
62:
63: private static final int COLUMNS = 3;
64:
65:
66: private int[] colWidth;
67:
68:
69: private int[] rowHeight;
70:
71:
72: private int labelGap;
73:
74:
75: private int buttonGap;
76:
77:
78: private int vGap;
79:
80:
85: public LCBLayout(final int maxrows) {
86: this.labelGap = 10;
87: this.buttonGap = 6;
88: this.vGap = 2;
89: this.colWidth = new int[COLUMNS];
90: this.rowHeight = new int[maxrows];
91: }
92:
93:
100: public Dimension preferredLayoutSize(final Container parent) {
101:
102: synchronized (parent.getTreeLock()) {
103: final Insets insets = parent.getInsets();
104: final int ncomponents = parent.getComponentCount();
105: final int nrows = ncomponents / COLUMNS;
106: for (int c = 0; c < COLUMNS; c++) {
107: for (int r = 0; r < nrows; r++) {
108: final Component component
109: = parent.getComponent(r * COLUMNS + c);
110: final Dimension d = component.getPreferredSize();
111: if (this.colWidth[c] < d.width) {
112: this.colWidth[c] = d.width;
113: }
114: if (this.rowHeight[r] < d.height) {
115: this.rowHeight[r] = d.height;
116: }
117: }
118: }
119: int totalHeight = this.vGap * (nrows - 1);
120: for (int r = 0; r < nrows; r++) {
121: totalHeight = totalHeight + this.rowHeight[r];
122: }
123: final int totalWidth = this.colWidth[0] + this.labelGap
124: + this.colWidth[1] + this.buttonGap + this.colWidth[2];
125: return new Dimension(
126: insets.left + insets.right + totalWidth + this.labelGap
127: + this.buttonGap,
128: insets.top + insets.bottom + totalHeight + this.vGap
129: );
130: }
131:
132: }
133:
134:
141: public Dimension minimumLayoutSize(final Container parent) {
142:
143: synchronized (parent.getTreeLock()) {
144: final Insets insets = parent.getInsets();
145: final int ncomponents = parent.getComponentCount();
146: final int nrows = ncomponents / COLUMNS;
147: for (int c = 0; c < COLUMNS; c++) {
148: for (int r = 0; r < nrows; r++) {
149: final Component component
150: = parent.getComponent(r * COLUMNS + c);
151: final Dimension d = component.getMinimumSize();
152: if (this.colWidth[c] < d.width) {
153: this.colWidth[c] = d.width;
154: }
155: if (this.rowHeight[r] < d.height) {
156: this.rowHeight[r] = d.height;
157: }
158: }
159: }
160: int totalHeight = this.vGap * (nrows - 1);
161: for (int r = 0; r < nrows; r++) {
162: totalHeight = totalHeight + this.rowHeight[r];
163: }
164: final int totalWidth = this.colWidth[0] + this.labelGap
165: + this.colWidth[1] + this.buttonGap + this.colWidth[2];
166: return new Dimension(
167: insets.left + insets.right + totalWidth + this.labelGap
168: + this.buttonGap,
169: insets.top + insets.bottom + totalHeight + this.vGap
170: );
171: }
172:
173: }
174:
175:
180: public void layoutContainer(final Container parent) {
181:
182: synchronized (parent.getTreeLock()) {
183: final Insets insets = parent.getInsets();
184: final int ncomponents = parent.getComponentCount();
185: final int nrows = ncomponents / COLUMNS;
186: for (int c = 0; c < COLUMNS; c++) {
187: for (int r = 0; r < nrows; r++) {
188: final Component component
189: = parent.getComponent(r * COLUMNS + c);
190: final Dimension d = component.getPreferredSize();
191: if (this.colWidth[c] < d.width) {
192: this.colWidth[c] = d.width;
193: }
194: if (this.rowHeight[r] < d.height) {
195: this.rowHeight[r] = d.height;
196: }
197: }
198: }
199: int totalHeight = this.vGap * (nrows - 1);
200: for (int r = 0; r < nrows; r++) {
201: totalHeight = totalHeight + this.rowHeight[r];
202: }
203: final int totalWidth = this.colWidth[0] + this.colWidth[1]
204: + this.colWidth[2];
205:
206:
207: final int available = parent.getWidth() - insets.left
208: - insets.right - this.labelGap - this.buttonGap;
209: this.colWidth[1] = this.colWidth[1] + (available - totalWidth);
210:
211:
212: int x = insets.left;
213: for (int c = 0; c < COLUMNS; c++) {
214: int y = insets.top;
215: for (int r = 0; r < nrows; r++) {
216: final int i = r * COLUMNS + c;
217: if (i < ncomponents) {
218: final Component component = parent.getComponent(i);
219: final Dimension d = component.getPreferredSize();
220: final int h = d.height;
221: final int adjust = (this.rowHeight[r] - h) / 2;
222: parent.getComponent(i).setBounds(x, y + adjust,
223: this.colWidth[c], h);
224: }
225: y = y + this.rowHeight[r] + this.vGap;
226: }
227: x = x + this.colWidth[c];
228: if (c == 0) {
229: x = x + this.labelGap;
230: }
231: if (c == 1) {
232: x = x + this.buttonGap;
233: }
234: }
235:
236: }
237:
238: }
239:
240:
245: public void addLayoutComponent(final Component comp) {
246:
247: }
248:
249:
254: public void removeLayoutComponent(final Component comp) {
255:
256: }
257:
258:
264: public void addLayoutComponent(final String name, final Component comp) {
265:
266: }
267:
268:
274: public void removeLayoutComponent(final String name, final Component comp) {
275:
276: }
277:
278: }