01: package gnu.kawa.models;
02:
03: import java.awt.Dimension;
04: import java.awt.geom.Dimension2D;
05:
06: /** A container that lays out its components in a column or row. */
07:
08: public abstract class Box extends Model implements Viewable,
09: java.io.Serializable {
10: Viewable[] components;
11: int numComponents;
12:
13: Viewable cellSpacing;
14:
15: public Viewable getCellSpacing() {
16: return cellSpacing;
17: }
18:
19: public void setCellSpacing(Object cellSpacing) {
20: if (cellSpacing instanceof gnu.math.IntNum
21: || cellSpacing instanceof java.lang.Integer) {
22: int size = ((Number) cellSpacing).intValue();
23: Dimension dim = getAxis() == 0 ? new Dimension(size, 0)
24: : new Dimension(0, size);
25: this .cellSpacing = Spacer.rigidArea(dim);
26: }
27: /*
28: else if (cellSpacing instanceof gnu.math.DFloNum)
29: {
30: double size = ((Number) cellSpacing).doubleValue();
31: Dimension2D dim = getAxis() == 0 ? new Dimension2D(size, 0)
32: : new Dimension2D(0, size);
33: this.cellSpacing = Space.rigidArea(dim);
34: }
35: */
36: else
37: this .cellSpacing = (Viewable) cellSpacing;
38: }
39:
40: /** Return 0 for a horizontal box; 1 for a vertical box. */
41: public abstract int getAxis();
42:
43: public final int getComponentCount() {
44: return numComponents;
45: }
46:
47: public final Viewable getComponent(int i) {
48: return components[i];
49: }
50:
51: public void add(Viewable component) {
52: Viewable[] arr = components;
53: int n = numComponents;
54: if (n == 0)
55: components = arr = new Viewable[4];
56: else if (arr.length <= n) {
57: components = new Viewable[2 * n];
58: System.arraycopy(arr, 0, components, 0, n);
59: arr = components;
60: }
61: components[n] = component;
62: numComponents = n + 1;
63: }
64:
65: public void makeView(Display display, Object where) {
66: display.addBox(this, where);
67: }
68: }
|