import java.awt.*; import java.awt.geom.*; /** * * Implementation of Shape as a Text, plus some Text-specific methods. For * geometric shape purposes, it extends Rectangle. * * @author Gene Fisher (gfisher@calpoly.edu) * */ public class Text extends Rectangle { public int x; public int y; public String s; public int width; public int height; /** Java's version of this' x coord. */ public int jx; /** Java's version of this' y coord. */ public int jy; /** * Construct this by intializing the data fields to the values of given * parameters. */ public Text(String s, int width, int height, int x, int y, Color color, boolean filled) { super(width, height, new Point(x, y), color, filled); this.width = width; this.height = height; this.x = x; this.y = y; this.s = s; } /** * Do a custom version of move, since granddad's version doesn't work for * doo-doo. */ public void move(Point delta) { x += delta.x; y -= delta.y; } /** * Return the Java AWT representation of this, as a Rectangle2D.Double. */ public java.awt.Shape getAwtRep(int canvas_height) { int height_fudge = 3; /* * This is what DrawingCanvas.drawText does. Attempts to rely on the * parent Rectangle implmentation of this method failed miserably. */ return new Rectangle2D.Double( x, /*canvas_height -*/ y, width, height + height_fudge); } /** * Return true if super.equals is true, and all of the other data fields * the other text are the same as this text. */ public boolean equals(Object other) { if (super.equals(other) == false) { return false; } /* * Note that this cast and subsequent code are safe, since super.equals * checks that other is not null and is the same class as this. */ Text t = (Text) other; return super.equals(t) && x == t.x && y == t.y && s.equals(t.s) && width == t.width && height == t.height; } public double getArea() { return width * height; } }