home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / Polygon.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  2.5 KB  |  95 lines

  1. package netscape.application;
  2.  
  3. import java.awt.Rectangle;
  4. import netscape.util.ClassInfo;
  5. import netscape.util.Codable;
  6. import netscape.util.CodingException;
  7. import netscape.util.Decoder;
  8. import netscape.util.Encoder;
  9.  
  10. public class Polygon implements Codable {
  11.    public int numPoints;
  12.    public int[] xPoints;
  13.    public int[] yPoints;
  14.    java.awt.Polygon awtPolygon;
  15.    static final String XPOINTS = "xPoints";
  16.    static final String YPOINTS = "yPoints";
  17.  
  18.    public Polygon() {
  19.       this.awtPolygon = new java.awt.Polygon();
  20.       this.update();
  21.    }
  22.  
  23.    public Polygon(int[] var1, int[] var2, int var3) {
  24.       this.awtPolygon = new java.awt.Polygon(var1, var2, var3);
  25.       this.update();
  26.    }
  27.  
  28.    public void addPoint(int var1, int var2) {
  29.       this.awtPolygon.addPoint(var1, var2);
  30.       this.update();
  31.    }
  32.  
  33.    public Rect boundingRect() {
  34.       Rectangle var1 = this.awtPolygon.getBoundingBox();
  35.       Rect var2 = new Rect(var1.x, var1.y, var1.width, var1.height);
  36.       this.update();
  37.       return var2;
  38.    }
  39.  
  40.    public boolean containsPoint(int var1, int var2) {
  41.       boolean var3 = this.awtPolygon.inside(var1, var2);
  42.       this.update();
  43.       return var3;
  44.    }
  45.  
  46.    public boolean containsPoint(Point var1) {
  47.       return this.containsPoint(var1.x, var1.y);
  48.    }
  49.  
  50.    public void moveBy(int var1, int var2) {
  51.       int[] var5;
  52.       for(int var3 = this.awtPolygon.npoints; var3-- > 0; var5[var3] += var2) {
  53.          var5 = this.awtPolygon.xpoints;
  54.          var5[var3] += var1;
  55.          var5 = this.awtPolygon.ypoints;
  56.       }
  57.  
  58.    }
  59.  
  60.    private void update() {
  61.       this.numPoints = this.awtPolygon.npoints;
  62.       this.xPoints = this.awtPolygon.xpoints;
  63.       this.yPoints = this.awtPolygon.ypoints;
  64.    }
  65.  
  66.    public void describeClassInfo(ClassInfo var1) {
  67.       var1.addClass("netscape.application.Polygon", 1);
  68.       var1.addField("xPoints", (byte)9);
  69.       var1.addField("yPoints", (byte)9);
  70.    }
  71.  
  72.    public void encode(Encoder var1) throws CodingException {
  73.       if (this.numPoints != 0) {
  74.          var1.encodeIntArray("xPoints", this.xPoints, 0, this.numPoints);
  75.          var1.encodeIntArray("yPoints", this.yPoints, 0, this.numPoints);
  76.       }
  77.    }
  78.  
  79.    public void decode(Decoder var1) throws CodingException {
  80.       int[] var3 = var1.decodeIntArray("xPoints");
  81.       int[] var4 = var1.decodeIntArray("yPoints");
  82.       if (var3 != null && var3.length != 0) {
  83.          this.numPoints = var3.length;
  84.  
  85.          for(int var2 = 0; var2 < var3.length; ++var2) {
  86.             this.addPoint(var3[var2], var4[var2]);
  87.          }
  88.  
  89.       }
  90.    }
  91.  
  92.    public void finishDecoding() throws CodingException {
  93.    }
  94. }
  95.