1:
41:
42: package ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52: import ;
53:
54:
57: public class ColumnArrangement implements Arrangement, Serializable {
58:
59:
60: private static final long serialVersionUID = -5315388482898581555L;
61:
62:
63: private HorizontalAlignment horizontalAlignment;
64:
65:
66: private VerticalAlignment verticalAlignment;
67:
68:
69: private double horizontalGap;
70:
71:
72: private double verticalGap;
73:
74:
77: public ColumnArrangement() {
78: }
79:
80:
88: public ColumnArrangement(HorizontalAlignment hAlign,
89: VerticalAlignment vAlign,
90: double hGap, double vGap) {
91: this.horizontalAlignment = hAlign;
92: this.verticalAlignment = vAlign;
93: this.horizontalGap = hGap;
94: this.verticalGap = vGap;
95: }
96:
97:
105: public void add(Block block, Object key) {
106:
107:
108: }
109:
110:
122: public Size2D arrange(BlockContainer container, Graphics2D g2,
123: RectangleConstraint constraint) {
124:
125: LengthConstraintType w = constraint.getWidthConstraintType();
126: LengthConstraintType h = constraint.getHeightConstraintType();
127: if (w == LengthConstraintType.NONE) {
128: if (h == LengthConstraintType.NONE) {
129: return arrangeNN(container, g2);
130: }
131: else if (h == LengthConstraintType.FIXED) {
132: throw new RuntimeException("Not implemented.");
133: }
134: else if (h == LengthConstraintType.RANGE) {
135: throw new RuntimeException("Not implemented.");
136: }
137: }
138: else if (w == LengthConstraintType.FIXED) {
139: if (h == LengthConstraintType.NONE) {
140: throw new RuntimeException("Not implemented.");
141: }
142: else if (h == LengthConstraintType.FIXED) {
143: return arrangeFF(container, g2, constraint);
144: }
145: else if (h == LengthConstraintType.RANGE) {
146: throw new RuntimeException("Not implemented.");
147: }
148: }
149: else if (w == LengthConstraintType.RANGE) {
150: if (h == LengthConstraintType.NONE) {
151: throw new RuntimeException("Not implemented.");
152: }
153: else if (h == LengthConstraintType.FIXED) {
154: return arrangeRF(container, g2, constraint);
155: }
156: else if (h == LengthConstraintType.RANGE) {
157: return arrangeRR(container, g2, constraint);
158: }
159: }
160: return new Size2D();
161:
162: }
163:
164:
176: protected Size2D arrangeFF(BlockContainer container, Graphics2D g2,
177: RectangleConstraint constraint) {
178:
179: return arrangeNF(container, g2, constraint);
180: }
181:
182:
194: protected Size2D arrangeNF(BlockContainer container, Graphics2D g2,
195: RectangleConstraint constraint) {
196:
197: List blocks = container.getBlocks();
198:
199: double height = constraint.getHeight();
200: if (height <= 0.0) {
201: height = Double.POSITIVE_INFINITY;
202: }
203:
204: double x = 0.0;
205: double y = 0.0;
206: double maxWidth = 0.0;
207: List itemsInColumn = new ArrayList();
208: for (int i = 0; i < blocks.size(); i++) {
209: Block block = (Block) blocks.get(i);
210: Size2D size = block.arrange(g2, RectangleConstraint.NONE);
211: if (y + size.height <= height) {
212: itemsInColumn.add(block);
213: block.setBounds(
214: new Rectangle2D.Double(x, y, size.width, size.height)
215: );
216: y = y + size.height + this.verticalGap;
217: maxWidth = Math.max(maxWidth, size.width);
218: }
219: else {
220: if (itemsInColumn.isEmpty()) {
221:
222: block.setBounds(
223: new Rectangle2D.Double(
224: x, y, size.width, Math.min(size.height, height - y)
225: )
226: );
227: y = 0.0;
228: x = x + size.width + this.horizontalGap;
229: }
230: else {
231:
232: itemsInColumn.clear();
233: x = x + maxWidth + this.horizontalGap;
234: y = 0.0;
235: maxWidth = size.width;
236: block.setBounds(
237: new Rectangle2D.Double(
238: x, y, size.width, Math.min(size.height, height)
239: )
240: );
241: y = size.height + this.verticalGap;
242: itemsInColumn.add(block);
243: }
244: }
245: }
246: return new Size2D(x + maxWidth, constraint.getHeight());
247: }
248:
249: protected Size2D arrangeRR(BlockContainer container, Graphics2D g2,
250: RectangleConstraint constraint) {
251:
252:
253:
254: Size2D s1 = arrangeNN(container, g2);
255: if (constraint.getHeightRange().contains(s1.height)) {
256: return s1;
257: }
258: else {
259: RectangleConstraint c = constraint.toFixedHeight(
260: constraint.getHeightRange().getUpperBound()
261: );
262: return arrangeRF(container, g2, c);
263: }
264: }
265:
266:
276: protected Size2D arrangeRF(BlockContainer container, Graphics2D g2,
277: RectangleConstraint constraint) {
278:
279: Size2D s = arrangeNF(container, g2, constraint);
280: if (constraint.getWidthRange().contains(s.width)) {
281: return s;
282: }
283: else {
284: RectangleConstraint c = constraint.toFixedWidth(
285: constraint.getWidthRange().constrain(s.getWidth())
286: );
287: return arrangeFF(container, g2, c);
288: }
289: }
290:
291:
300: protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
301: double y = 0.0;
302: double height = 0.0;
303: double maxWidth = 0.0;
304: List blocks = container.getBlocks();
305: int blockCount = blocks.size();
306: if (blockCount > 0) {
307: Size2D[] sizes = new Size2D[blocks.size()];
308: for (int i = 0; i < blocks.size(); i++) {
309: Block block = (Block) blocks.get(i);
310: sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
311: height = height + sizes[i].getHeight();
312: maxWidth = Math.max(sizes[i].width, maxWidth);
313: block.setBounds(
314: new Rectangle2D.Double(
315: 0.0, y, sizes[i].width, sizes[i].height
316: )
317: );
318: y = y + sizes[i].height + this.verticalGap;
319: }
320: if (blockCount > 1) {
321: height = height + this.verticalGap * (blockCount - 1);
322: }
323: if (this.horizontalAlignment != HorizontalAlignment.LEFT) {
324: for (int i = 0; i < blocks.size(); i++) {
325:
326: if (this.horizontalAlignment
327: == HorizontalAlignment.CENTER) {
328:
329: }
330: else if (this.horizontalAlignment
331: == HorizontalAlignment.RIGHT) {
332:
333: }
334: }
335: }
336: }
337: return new Size2D(maxWidth, height);
338: }
339:
340:
343: public void clear() {
344:
345: }
346:
347:
354: public boolean equals(Object obj) {
355: if (obj == this) {
356: return true;
357: }
358: if (!(obj instanceof ColumnArrangement)) {
359: return false;
360: }
361: ColumnArrangement that = (ColumnArrangement) obj;
362: if (this.horizontalAlignment != that.horizontalAlignment) {
363: return false;
364: }
365: if (this.verticalAlignment != that.verticalAlignment) {
366: return false;
367: }
368: if (this.horizontalGap != that.horizontalGap) {
369: return false;
370: }
371: if (this.verticalGap != that.verticalGap) {
372: return false;
373: }
374: return true;
375: }
376:
377:
378: }