1 45 46 package org.jfree.chart.block; 47 48 import java.awt.Color ; 49 import java.awt.Graphics2D ; 50 import java.awt.Paint ; 51 import java.awt.geom.Rectangle2D ; 52 import java.io.IOException ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutputStream ; 55 import java.io.Serializable ; 56 57 import org.jfree.io.SerialUtilities; 58 import org.jfree.ui.RectangleInsets; 59 import org.jfree.util.PaintUtilities; 60 61 64 public class BlockBorder implements Serializable { 65 66 67 private static final long serialVersionUID = 4961579220410228283L; 68 69 70 public static final BlockBorder NONE 71 = new BlockBorder(RectangleInsets.ZERO_INSETS, Color.white); 72 73 74 private RectangleInsets insets; 75 76 77 private transient Paint paint; 78 79 82 public BlockBorder() { 83 this(Color.black); 84 } 85 86 91 public BlockBorder(Paint paint) { 92 this(new RectangleInsets(1, 1, 1, 1), paint); 93 } 94 95 103 public BlockBorder(double top, double left, double bottom, double right) { 104 this(new RectangleInsets(top, left, bottom, right), Color.black); 105 } 106 107 116 public BlockBorder(double top, double left, double bottom, double right, 117 Paint paint) { 118 this(new RectangleInsets(top, left, bottom, right), paint); 119 } 120 121 127 public BlockBorder(RectangleInsets insets, Paint paint) { 128 if (insets == null) { 129 throw new IllegalArgumentException ("Null 'insets' argument."); 130 } 131 if (paint == null) { 132 throw new IllegalArgumentException ("Null 'paint' argument."); 133 } 134 this.insets = insets; 135 this.paint = paint; 136 } 137 138 143 public RectangleInsets getInsets() { 144 return this.insets; 145 } 146 147 152 public Paint getPaint() { 153 return this.paint; 154 } 155 156 162 public void draw(Graphics2D g2, Rectangle2D area) { 163 double t = this.insets.calculateTopInset(area.getHeight()); 166 double b = this.insets.calculateBottomInset(area.getHeight()); 167 double l = this.insets.calculateLeftInset(area.getWidth()); 168 double r = this.insets.calculateRightInset(area.getWidth()); 169 double x = area.getX(); 170 double y = area.getY(); 171 double w = area.getWidth(); 172 double h = area.getHeight(); 173 g2.setPaint(this.paint); 174 Rectangle2D rect = new Rectangle2D.Double (); 175 if (t > 0.0) { 176 rect.setRect(x, y, w, t); 177 g2.fill(rect); 178 } 179 if (b > 0.0) { 180 rect.setRect(x, y + h - b, w, b); 181 g2.fill(rect); 182 } 183 if (l > 0.0) { 184 rect.setRect(x, y, l, h); 185 g2.fill(rect); 186 } 187 if (r > 0.0) { 188 rect.setRect(x + w - r, y, r, h); 189 g2.fill(rect); 190 } 191 } 192 193 200 public boolean equals(Object obj) { 201 if (obj == this) { 202 return true; 203 } 204 if (!(obj instanceof BlockBorder)) { 205 return false; 206 } 207 BlockBorder that = (BlockBorder) obj; 208 if (!this.insets.equals(that.insets)) { 209 return false; 210 } 211 if (!PaintUtilities.equal(this.paint, that.paint)) { 212 return false; 213 } 214 return true; 215 } 216 217 224 private void writeObject(ObjectOutputStream stream) throws IOException { 225 stream.defaultWriteObject(); 226 SerialUtilities.writePaint(this.paint, stream); 227 } 228 229 237 private void readObject(ObjectInputStream stream) 238 throws IOException , ClassNotFoundException { 239 stream.defaultReadObject(); 240 this.paint = SerialUtilities.readPaint(stream); 241 } 242 243 } 244 | Popular Tags |