1 44 45 package org.jfree.chart.block; 46 47 import java.awt.Graphics2D ; 48 import java.awt.geom.Rectangle2D ; 49 import java.io.Serializable ; 50 import java.util.List ; 51 52 import org.jfree.ui.Size2D; 53 54 57 public class CenterArrangement implements Arrangement, Serializable { 58 59 60 private static final long serialVersionUID = -353308149220382047L; 61 62 65 public CenterArrangement() { 66 } 67 68 76 public void add(Block block, Object key) { 77 } 80 81 93 public Size2D arrange(BlockContainer container, Graphics2D g2, 94 RectangleConstraint constraint) { 95 96 LengthConstraintType w = constraint.getWidthConstraintType(); 97 LengthConstraintType h = constraint.getHeightConstraintType(); 98 if (w == LengthConstraintType.NONE) { 99 if (h == LengthConstraintType.NONE) { 100 return arrangeNN(container, g2); 101 } 102 else if (h == LengthConstraintType.FIXED) { 103 throw new RuntimeException ("Not implemented."); 104 } 105 else if (h == LengthConstraintType.RANGE) { 106 throw new RuntimeException ("Not implemented."); 107 } 108 } 109 else if (w == LengthConstraintType.FIXED) { 110 if (h == LengthConstraintType.NONE) { 111 return arrangeFN(container, g2, constraint); 112 } 113 else if (h == LengthConstraintType.FIXED) { 114 throw new RuntimeException ("Not implemented."); 115 } 116 else if (h == LengthConstraintType.RANGE) { 117 throw new RuntimeException ("Not implemented."); 118 } 119 } 120 else if (w == LengthConstraintType.RANGE) { 121 if (h == LengthConstraintType.NONE) { 122 return arrangeRN(container, g2, constraint); 123 } 124 else if (h == LengthConstraintType.FIXED) { 125 return arrangeRF(container, g2, constraint); 126 } 127 else if (h == LengthConstraintType.RANGE) { 128 return arrangeRR(container, g2, constraint); 129 } 130 } 131 throw new IllegalArgumentException ("Unknown LengthConstraintType."); 132 133 } 134 135 145 protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, 146 RectangleConstraint constraint) { 147 148 List blocks = container.getBlocks(); 149 Block b = (Block) blocks.get(0); 150 Size2D s = b.arrange(g2, RectangleConstraint.NONE); 151 double width = constraint.getWidth(); 152 Rectangle2D bounds = new Rectangle2D.Double ((width - s.width) / 2.0, 153 0.0, s.width, s.height); 154 b.setBounds(bounds); 155 return new Size2D((width - s.width) / 2.0, s.height); 156 } 157 158 168 protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, 169 RectangleConstraint constraint) { 170 171 Size2D s = arrangeFN(container, g2, constraint); 172 if (constraint.getHeightRange().contains(s.height)) { 173 return s; 174 } 175 else { 176 RectangleConstraint c = constraint.toFixedHeight( 177 constraint.getHeightRange().constrain(s.getHeight())); 178 return arrangeFF(container, g2, c); 179 } 180 } 181 182 192 protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, 193 RectangleConstraint constraint) { 194 195 return arrangeFN(container, g2, constraint); 197 } 198 199 209 protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, 210 RectangleConstraint constraint) { 211 212 Size2D s1 = arrangeNN(container, g2); 215 if (constraint.getWidthRange().contains(s1.width)) { 216 return s1; } 218 else { 219 RectangleConstraint c = constraint.toFixedWidth( 220 constraint.getWidthRange().getUpperBound()); 221 return arrangeFR(container, g2, c); 222 } 223 } 224 225 235 protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, 236 RectangleConstraint constraint) { 237 238 Size2D s = arrangeNF(container, g2, constraint); 239 if (constraint.getWidthRange().contains(s.width)) { 240 return s; 241 } 242 else { 243 RectangleConstraint c = constraint.toFixedWidth( 244 constraint.getWidthRange().constrain(s.getWidth())); 245 return arrangeFF(container, g2, c); 246 } 247 } 248 249 259 protected Size2D arrangeRN(BlockContainer container, Graphics2D g2, 260 RectangleConstraint constraint) { 261 Size2D s1 = arrangeNN(container, g2); 264 if (constraint.getWidthRange().contains(s1.width)) { 265 return s1; 266 } 267 else { 268 RectangleConstraint c = constraint.toFixedWidth( 269 constraint.getWidthRange().getUpperBound()); 270 return arrangeFN(container, g2, c); 271 } 272 } 273 274 283 protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { 284 List blocks = container.getBlocks(); 285 Block b = (Block) blocks.get(0); 286 Size2D s = b.arrange(g2, RectangleConstraint.NONE); 287 b.setBounds(new Rectangle2D.Double (0.0, 0.0, s.width, s.height)); 288 return new Size2D(s.width, s.height); 289 } 290 291 301 protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, 302 RectangleConstraint constraint) { 303 return arrangeNN(container, g2); 305 } 306 307 310 public void clear() { 311 } 313 314 321 public boolean equals(Object obj) { 322 if (obj == this) { 323 return true; 324 } 325 if (!(obj instanceof CenterArrangement)) { 326 return false; 327 } 328 return true; 329 } 330 331 } 332 | Popular Tags |