home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / java / awt / Rectangle.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-20  |  4.0 KB  |  137 lines

  1. package java.awt;
  2.  
  3. public class Rectangle {
  4.    // $FF: renamed from: x int
  5.    public int field_0;
  6.    // $FF: renamed from: y int
  7.    public int field_1;
  8.    public int width;
  9.    public int height;
  10.  
  11.    public Rectangle() {
  12.    }
  13.  
  14.    public Rectangle(int x, int y, int width, int height) {
  15.       this.field_0 = x;
  16.       this.field_1 = y;
  17.       this.width = width;
  18.       this.height = height;
  19.    }
  20.  
  21.    public Rectangle(int width, int height) {
  22.       this(0, 0, width, height);
  23.    }
  24.  
  25.    public Rectangle(Point p, Dimension d) {
  26.       this(p.x, p.y, d.width, d.height);
  27.    }
  28.  
  29.    public Rectangle(Point p) {
  30.       this(p.x, p.y, 0, 0);
  31.    }
  32.  
  33.    public Rectangle(Dimension d) {
  34.       this(0, 0, d.width, d.height);
  35.    }
  36.  
  37.    public void reshape(int x, int y, int width, int height) {
  38.       this.field_0 = x;
  39.       this.field_1 = y;
  40.       this.width = width;
  41.       this.height = height;
  42.    }
  43.  
  44.    public void move(int x, int y) {
  45.       this.field_0 = x;
  46.       this.field_1 = y;
  47.    }
  48.  
  49.    public void translate(int x, int y) {
  50.       this.field_0 += x;
  51.       this.field_1 += y;
  52.    }
  53.  
  54.    public void resize(int width, int height) {
  55.       this.width = width;
  56.       this.height = height;
  57.    }
  58.  
  59.    public boolean inside(int x, int y) {
  60.       return x >= this.field_0 && x - this.field_0 < this.width && y >= this.field_1 && y - this.field_1 < this.height;
  61.    }
  62.  
  63.    public boolean intersects(Rectangle r) {
  64.       return r.field_0 + r.width >= this.field_0 && r.field_1 + r.height >= this.field_1 && r.field_0 < this.field_0 + this.width && r.field_1 < this.field_1 + this.height;
  65.    }
  66.  
  67.    public Rectangle intersection(Rectangle r) {
  68.       int x1 = Math.max(this.field_0, r.field_0);
  69.       int x2 = Math.min(this.field_0 + this.width, r.field_0 + r.width);
  70.       int y1 = Math.max(this.field_1, r.field_1);
  71.       int y2 = Math.min(this.field_1 + this.height, r.field_1 + r.height);
  72.       return new Rectangle(x1, y1, x2 - x1, y2 - y1);
  73.    }
  74.  
  75.    public Rectangle union(Rectangle r) {
  76.       int x1 = Math.min(this.field_0, r.field_0);
  77.       int x2 = Math.max(this.field_0 + this.width, r.field_0 + r.width);
  78.       int y1 = Math.min(this.field_1, r.field_1);
  79.       int y2 = Math.max(this.field_1 + this.height, r.field_1 + r.height);
  80.       return new Rectangle(x1, y1, x2 - x1, y2 - y1);
  81.    }
  82.  
  83.    public void add(int newx, int newy) {
  84.       int x1 = Math.min(this.field_0, newx);
  85.       int x2 = Math.max(this.field_0 + this.width, newx);
  86.       int y1 = Math.min(this.field_1, newy);
  87.       int y2 = Math.max(this.field_1 + this.height, newy);
  88.       this.field_0 = x1;
  89.       this.field_1 = y1;
  90.       this.width = x2 - x1;
  91.       this.height = y2 - y1;
  92.    }
  93.  
  94.    public void add(Point pt) {
  95.       this.add(pt.x, pt.y);
  96.    }
  97.  
  98.    public void add(Rectangle r) {
  99.       int x1 = Math.min(this.field_0, r.field_0);
  100.       int x2 = Math.max(this.field_0 + this.width, r.field_0 + r.width);
  101.       int y1 = Math.min(this.field_1, r.field_1);
  102.       int y2 = Math.max(this.field_1 + this.height, r.field_1 + r.height);
  103.       this.field_0 = x1;
  104.       this.field_1 = y1;
  105.       this.width = x2 - x1;
  106.       this.height = y2 - y1;
  107.    }
  108.  
  109.    public void grow(int h, int v) {
  110.       this.field_0 -= h;
  111.       this.field_1 -= v;
  112.       this.width += h * 2;
  113.       this.height += v * 2;
  114.    }
  115.  
  116.    public boolean isEmpty() {
  117.       return this.width <= 0 || this.height <= 0;
  118.    }
  119.  
  120.    public int hashCode() {
  121.       return this.field_0 ^ this.field_1 * 37 ^ this.width * 43 ^ this.height * 47;
  122.    }
  123.  
  124.    public boolean equals(Object obj) {
  125.       if (obj instanceof Rectangle) {
  126.          Rectangle r = (Rectangle)obj;
  127.          return this.field_0 == r.field_0 && this.field_1 == r.field_1 && this.width == r.width && this.height == r.height;
  128.       } else {
  129.          return false;
  130.       }
  131.    }
  132.  
  133.    public String toString() {
  134.       return this.getClass().getName() + "[x=" + this.field_0 + ",y=" + this.field_1 + ",width=" + this.width + ",height=" + this.height + "]";
  135.    }
  136. }
  137.