1 47 48 package org.jfree.chart.axis; 49 50 import java.awt.geom.Rectangle2D ; 51 import java.io.Serializable ; 52 53 import org.jfree.ui.RectangleEdge; 54 import org.jfree.util.PublicCloneable; 55 56 59 public class AxisSpace implements Cloneable , PublicCloneable, Serializable { 60 61 62 private static final long serialVersionUID = -2490732595134766305L; 63 64 65 private double top; 66 67 68 private double bottom; 69 70 71 private double left; 72 73 74 private double right; 75 76 79 public AxisSpace() { 80 this.top = 0.0; 81 this.bottom = 0.0; 82 this.left = 0.0; 83 this.right = 0.0; 84 } 85 86 91 public double getTop() { 92 return this.top; 93 } 94 95 100 public void setTop(double space) { 101 this.top = space; 102 } 103 104 109 public double getBottom() { 110 return this.bottom; 111 } 112 113 118 public void setBottom(double space) { 119 this.bottom = space; 120 } 121 122 127 public double getLeft() { 128 return this.left; 129 } 130 131 136 public void setLeft(double space) { 137 this.left = space; 138 } 139 140 145 public double getRight() { 146 return this.right; 147 } 148 149 154 public void setRight(double space) { 155 this.right = space; 156 } 157 158 164 public void add(double space, RectangleEdge edge) { 165 if (edge == null) { 166 throw new IllegalArgumentException ("Null 'edge' argument."); 167 } 168 if (edge == RectangleEdge.TOP) { 169 this.top += space; 170 } 171 else if (edge == RectangleEdge.BOTTOM) { 172 this.bottom += space; 173 } 174 else if (edge == RectangleEdge.LEFT) { 175 this.left += space; 176 } 177 else if (edge == RectangleEdge.RIGHT) { 178 this.right += space; 179 } 180 else { 181 throw new IllegalStateException ("Unrecognised 'edge' argument."); 182 } 183 } 184 185 190 public void ensureAtLeast(AxisSpace space) { 191 this.top = Math.max(this.top, space.top); 192 this.bottom = Math.max(this.bottom, space.bottom); 193 this.left = Math.max(this.left, space.left); 194 this.right = Math.max(this.right, space.right); 195 } 196 197 204 public void ensureAtLeast(double space, RectangleEdge edge) { 205 if (edge == RectangleEdge.TOP) { 206 if (this.top < space) { 207 this.top = space; 208 } 209 } 210 else if (edge == RectangleEdge.BOTTOM) { 211 if (this.bottom < space) { 212 this.bottom = space; 213 } 214 } 215 else if (edge == RectangleEdge.LEFT) { 216 if (this.left < space) { 217 this.left = space; 218 } 219 } 220 else if (edge == RectangleEdge.RIGHT) { 221 if (this.right < space) { 222 this.right = space; 223 } 224 } 225 else { 226 throw new IllegalStateException ( 227 "AxisSpace.ensureAtLeast(): unrecognised AxisLocation." 228 ); 229 } 230 } 231 232 240 public Rectangle2D shrink(Rectangle2D area, Rectangle2D result) { 241 if (result == null) { 242 result = new Rectangle2D.Double (); 243 } 244 result.setRect( 245 area.getX() + this.left, 246 area.getY() + this.top, 247 area.getWidth() - this.left - this.right, 248 area.getHeight() - this.top - this.bottom 249 ); 250 return result; 251 } 252 253 261 public Rectangle2D expand(Rectangle2D area, Rectangle2D result) { 262 if (result == null) { 263 result = new Rectangle2D.Double (); 264 } 265 result.setRect( 266 area.getX() - this.left, 267 area.getY() - this.top, 268 area.getWidth() + this.left + this.right, 269 area.getHeight() + this.top + this.bottom 270 ); 271 return result; 272 } 273 274 282 public Rectangle2D reserved(Rectangle2D area, RectangleEdge edge) { 283 Rectangle2D result = null; 284 if (edge == RectangleEdge.TOP) { 285 result = new Rectangle2D.Double ( 286 area.getX(), area.getY(), area.getWidth(), this.top 287 ); 288 } 289 else if (edge == RectangleEdge.BOTTOM) { 290 result = new Rectangle2D.Double ( 291 area.getX(), area.getMaxY() - this.top, 292 area.getWidth(), this.bottom 293 ); 294 } 295 else if (edge == RectangleEdge.LEFT) { 296 result = new Rectangle2D.Double ( 297 area.getX(), area.getY(), this.left, area.getHeight() 298 ); 299 } 300 else if (edge == RectangleEdge.RIGHT) { 301 result = new Rectangle2D.Double ( 302 area.getMaxX() - this.right, area.getY(), 303 this.right, area.getHeight() 304 ); 305 } 306 return result; 307 } 308 309 317 public Object clone() throws CloneNotSupportedException { 318 return super.clone(); 319 } 320 321 328 public boolean equals(Object obj) { 329 if (obj == this) { 330 return true; 331 } 332 if (!(obj instanceof AxisSpace)) { 333 return false; 334 } 335 AxisSpace that = (AxisSpace) obj; 336 if (this.top != that.top) { 337 return false; 338 } 339 if (this.bottom != that.bottom) { 340 return false; 341 } 342 if (this.left != that.left) { 343 return false; 344 } 345 if (this.right != that.right) { 346 return false; 347 } 348 return true; 349 } 350 351 356 public int hashCode() { 357 int result = 23; 358 long l = Double.doubleToLongBits(this.top); 359 result = 37 * result + (int) (l ^ (l >>> 32)); 360 l = Double.doubleToLongBits(this.bottom); 361 result = 37 * result + (int) (l ^ (l >>> 32)); 362 l = Double.doubleToLongBits(this.left); 363 result = 37 * result + (int) (l ^ (l >>> 32)); 364 l = Double.doubleToLongBits(this.right); 365 result = 37 * result + (int) (l ^ (l >>> 32)); 366 return result; 367 } 368 369 374 public String toString() { 375 return super.toString() + "[left=" + this.left + ",right=" + this.right 376 + ",top=" + this.top + ",bottom=" + this.bottom + "]"; 377 } 378 379 } 380 | Popular Tags |