KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > models > Box


1 package gnu.kawa.models;
2 import java.awt.Dimension JavaDoc;
3 import java.awt.geom.Dimension2D JavaDoc;
4
5 /** A container that lays out its components in a column or row. */
6
7 public abstract class Box extends Model
8   implements Viewable, java.io.Serializable JavaDoc
9 {
10   Viewable[] components;
11   int numComponents;
12
13   Viewable cellSpacing;
14
15   public Viewable getCellSpacing () { return cellSpacing; }
16
17   public void setCellSpacing (Object JavaDoc cellSpacing)
18   {
19     if (cellSpacing instanceof gnu.math.IntNum
20         || cellSpacing instanceof java.lang.Integer JavaDoc)
21       {
22         int size = ((Number JavaDoc) cellSpacing).intValue();
23         Dimension JavaDoc dim = getAxis() == 0 ? new Dimension JavaDoc(size, 0)
24           : new Dimension JavaDoc(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   {
45     return numComponents;
46   }
47
48   public final Viewable getComponent (int i)
49   {
50     return components[i];
51   }
52
53   public void add (Viewable component)
54   {
55     Viewable[] arr = components;
56     int n = numComponents;
57     if (n == 0)
58       components = arr = new Viewable[4];
59     else if (arr.length <= n)
60       {
61         components = new Viewable[2 * n];
62         System.arraycopy(arr, 0, components, 0, n);
63         arr = components;
64       }
65     components[n] = component;
66     numComponents = n + 1;
67   }
68
69   public void makeView (Display display, Object JavaDoc where)
70   {
71     display.addBox(this, where);
72   }
73 }
74
Popular Tags