1 49 50 package org.jfree.chart.block; 51 52 import java.awt.Graphics2D ; 53 import java.awt.geom.Rectangle2D ; 54 import java.io.Serializable ; 55 import java.util.ArrayList ; 56 import java.util.Collections ; 57 import java.util.Iterator ; 58 import java.util.List ; 59 60 import org.jfree.chart.entity.EntityCollection; 61 import org.jfree.chart.entity.StandardEntityCollection; 62 import org.jfree.ui.Size2D; 63 import org.jfree.util.PublicCloneable; 64 65 69 public class BlockContainer extends AbstractBlock 70 implements Block, 71 Cloneable , PublicCloneable, 72 Serializable { 73 74 75 private static final long serialVersionUID = 8199508075695195293L; 76 77 78 private List blocks; 79 80 81 private Arrangement arrangement; 82 83 86 public BlockContainer() { 87 this(new BorderArrangement()); 88 } 89 90 96 public BlockContainer(Arrangement arrangement) { 97 if (arrangement == null) { 98 throw new IllegalArgumentException ("Null 'arrangement' argument."); 99 } 100 this.arrangement = arrangement; 101 this.blocks = new ArrayList (); 102 } 103 104 109 public Arrangement getArrangement() { 110 return this.arrangement; 111 } 112 113 118 public void setArrangement(Arrangement arrangement) { 119 if (arrangement == null) { 120 throw new IllegalArgumentException ("Null 'arrangement' argument."); 121 } 122 this.arrangement = arrangement; 123 } 124 125 131 public boolean isEmpty() { 132 return this.blocks.isEmpty(); 133 } 134 135 141 public List getBlocks() { 142 return Collections.unmodifiableList(this.blocks); 143 } 144 145 150 public void add(Block block) { 151 add(block, null); 152 } 153 154 160 public void add(Block block, Object key) { 161 this.blocks.add(block); 162 this.arrangement.add(block, key); 163 } 164 165 168 public void clear() { 169 this.blocks.clear(); 170 this.arrangement.clear(); 171 } 172 173 182 public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { 183 return this.arrangement.arrange(this, g2, constraint); 184 } 185 186 192 public void draw(Graphics2D g2, Rectangle2D area) { 193 draw(g2, area, null); 194 } 195 196 206 public Object draw(Graphics2D g2, Rectangle2D area, Object params) { 207 EntityBlockParams ebp = null; 209 StandardEntityCollection sec = null; 210 if (params instanceof EntityBlockParams) { 211 ebp = (EntityBlockParams) params; 212 if (ebp.getGenerateEntities()) { 213 sec = new StandardEntityCollection(); 214 } 215 } 216 Rectangle2D contentArea = (Rectangle2D ) area.clone(); 217 contentArea = trimMargin(contentArea); 218 drawBorder(g2, contentArea); 219 contentArea = trimBorder(contentArea); 220 contentArea = trimPadding(contentArea); 221 Iterator iterator = this.blocks.iterator(); 222 while (iterator.hasNext()) { 223 Block block = (Block) iterator.next(); 224 Rectangle2D bounds = block.getBounds(); 225 Rectangle2D drawArea = new Rectangle2D.Double (bounds.getX() 226 + area.getX(), bounds.getY() + area.getY(), 227 bounds.getWidth(), bounds.getHeight()); 228 Object r = block.draw(g2, drawArea, params); 229 if (sec != null) { 230 if (r instanceof EntityBlockResult) { 231 EntityBlockResult ebr = (EntityBlockResult) r; 232 EntityCollection ec = ebr.getEntityCollection(); 233 sec.addAll(ec); 234 } 235 } 236 } 237 BlockResult result = null; 238 if (sec != null) { 239 result = new BlockResult(); 240 result.setEntityCollection(sec); 241 } 242 return result; 243 } 244 245 252 public boolean equals(Object obj) { 253 if (obj == this) { 254 return true; 255 } 256 if (!(obj instanceof BlockContainer)) { 257 return false; 258 } 259 if (!super.equals(obj)) { 260 return false; 261 } 262 BlockContainer that = (BlockContainer) obj; 263 if (!this.arrangement.equals(that.arrangement)) { 264 return false; 265 } 266 if (!this.blocks.equals(that.blocks)) { 267 return false; 268 } 269 return true; 270 } 271 272 279 public Object clone() throws CloneNotSupportedException { 280 Object clone = (BlockContainer) super.clone(); 281 return clone; 283 } 284 285 } 286 | Popular Tags |