1 package jimm.datavision.field; 2 import jimm.datavision.Writeable; 3 import jimm.util.XMLWriter; 4 import java.util.Observable ; 5 6 11 public class Rectangle extends Observable implements Writeable { 12 13 17 public double x; 18 22 public double y; 23 27 public double width; 28 32 public double height; 33 34 37 public Rectangle() { this(0, 0, 0, 0); } 38 39 44 public Rectangle(java.awt.Rectangle r) { this(r.x, r.y, r.width, r.height); } 45 46 51 public Rectangle(Rectangle r) { this(r.x, r.y, r.width, r.height); } 52 53 61 public Rectangle(double x, double y, double width, double height) { 62 this.x = x; 63 this.y = y; 64 this.width = width; 65 this.height = height; 66 } 67 68 73 public double getX() { return x; } 74 75 80 public void setX(double newX) { 81 if (x != newX) { 82 x = newX; 83 setChanged(); 84 notifyObservers(); 85 } 86 } 87 88 93 public double getY() { return y; } 94 95 100 public void setY(double newY) { 101 if (y != newY) { 102 y = newY; 103 setChanged(); 104 notifyObservers(); 105 } 106 } 107 108 113 public double getWidth() { return width; } 114 115 120 public void setWidth(double newWidth) { 121 if (width != newWidth) { 122 width = newWidth; 123 setChanged(); 124 notifyObservers(); 125 } 126 } 127 128 133 public double getHeight() { return height; } 134 135 140 public void setHeight(double newHeight) { 141 if (height != newHeight) { 142 height = newHeight; 143 setChanged(); 144 notifyObservers(); 145 } 146 } 147 148 156 public void setBounds(double newX, double newY, double newWidth, 157 double newHeight) 158 { 159 boolean needsToNotify = false; 162 if (x != newX) { 163 x = newX; 164 needsToNotify = true; 165 } 166 if (y != newY) { 167 y = newY; 168 needsToNotify = true; 169 } 170 if (width != newWidth) { 171 width = newWidth; 172 needsToNotify = true; 173 } 174 if (height != newHeight) { 175 height = newHeight; 176 needsToNotify = true; 177 } 178 179 if (needsToNotify) { 180 setChanged(); 181 notifyObservers(); 182 } 183 } 184 185 190 public void setBounds(jimm.datavision.field.Rectangle r) { 191 setBounds(r.x, r.y, r.width, r.height); 192 } 193 194 199 public void setBounds(java.awt.Rectangle r) { 200 setBounds(r.x, r.y, r.width, r.height); 201 } 202 203 208 public String toString() { 209 return "[x=" + x + ", y=" + y + ", w=" + width + ", h=" + height + "]"; 210 } 211 212 217 public void writeXML(XMLWriter out) { 218 out.startElement("bounds"); 219 out.attr("x", x); 220 out.attr("y", y); 221 out.attr("width", width); 222 out.attr("height", height); 223 out.endElement(); 224 } 225 226 } 227 | Popular Tags |