1 19 package jcckit.graphic; 20 21 import java.util.Vector ; 22 23 28 public class GraphicalComposite implements GraphicalElement { 29 private final Vector _elements = new Vector (); 30 private final ClippingShape _clippingShape; 31 32 36 public GraphicalComposite(ClippingShape clippingShape) { 37 _clippingShape = clippingShape; 38 } 39 40 44 public ClippingShape getClippingShape() { 45 return _clippingShape; 46 } 47 48 53 public void addElement(GraphicalElement element) { 54 if (element == null) { 55 throwNullPointerException(); 56 } else { 57 _elements.addElement(element); 58 } 59 } 60 61 62 public void removeAllElements() { 63 _elements.removeAllElements(); 64 } 65 66 72 public void replaceElementAt(int index, GraphicalElement element) { 73 if (element == null) { 74 throwNullPointerException(); 75 } else { 76 _elements.setElementAt(element, index); 77 } 78 } 79 80 private void throwNullPointerException() { 81 throw new NullPointerException ( 82 "A null as an GraphicalElement is not allowed"); 83 } 84 85 93 public void renderWith(Renderer renderer) { 94 if (renderer instanceof GraphicalCompositeRenderer) { 95 GraphicalCompositeRenderer r = (GraphicalCompositeRenderer) renderer; 96 r.startRendering(this); 97 for (int i = 0, n = _elements.size(); i < n; i++) { 98 ((GraphicalElement) _elements.elementAt(i)).renderWith(r); 99 } 100 r.finishRendering(this); 101 } else { 102 throw new IllegalArgumentException (renderer 103 + " does not implements GraphicalCompositeRenderer."); 104 } 105 } 106 } 107 | Popular Tags |