1 package gnu.kawa.models; 2 import java.awt.Dimension ; 3 import java.awt.geom.Dimension2D ; 4 5 6 7 public abstract class Box extends Model 8 implements Viewable, java.io.Serializable 9 { 10 Viewable[] components; 11 int numComponents; 12 13 Viewable cellSpacing; 14 15 public Viewable getCellSpacing () { return cellSpacing; } 16 17 public void setCellSpacing (Object cellSpacing) 18 { 19 if (cellSpacing instanceof gnu.math.IntNum 20 || cellSpacing instanceof java.lang.Integer ) 21 { 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 36 else 37 this.cellSpacing = (Viewable) cellSpacing; 38 } 39 40 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 where) 70 { 71 display.addBox(this, where); 72 } 73 } 74 | Popular Tags |