home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Graphics;
- import java.awt.Polygon;
- import java.util.NoSuchElementException;
- import java.util.StringTokenizer;
-
- public class Poly extends Area {
- private static final int MINDIST = 8;
- private int _npts;
- private int[] _xpt = new int[16];
- private int[] _ypt = new int[16];
- private int _grabIndex;
-
- public Poly(int var1, int var2) {
- this.addPoint(var1, var2);
- this._grabIndex = this._npts;
- }
-
- public Poly(String var1) {
- StringTokenizer var2 = new StringTokenizer(var1, ", \t\n");
-
- try {
- while(var2.hasMoreTokens()) {
- int var3 = Integer.parseInt(var2.nextToken());
- int var4 = Integer.parseInt(var2.nextToken());
- this.addPoint(var3, var4);
- }
- } catch (NoSuchElementException var5) {
- } catch (NumberFormatException var6) {
- }
-
- this.close();
- }
-
- private Poly() {
- }
-
- public void resize(int var1, int var2) {
- if (this._grabIndex == this._npts) {
- this.addPoint(var1, var2);
- } else if (this._grabIndex == 0) {
- this.setPoint(0, var1, var2);
- this.setPoint(this._npts - 1, var1, var2);
- } else if (this._grabIndex == this._npts - 1) {
- if (Math.abs(var1 - this._xpt[0]) <= 8 && Math.abs(var2 - this._ypt[0]) <= 8) {
- this.setPoint(this._npts - 1, this._xpt[0], this._ypt[0]);
- } else {
- this.setPoint(this._npts - 1, var1, var2);
- }
- } else {
- this.setPoint(this._grabIndex, var1, var2);
- }
- }
-
- public void translate(int var1, int var2) {
- for(int var3 = 0; var3 < this._npts; ++var3) {
- int[] var10000 = this._xpt;
- var10000[var3] += var1;
- var10000 = this._ypt;
- var10000[var3] += var2;
- }
-
- }
-
- public boolean isGrab(int var1, int var2) {
- for(int var3 = 0; var3 < this._npts - 1; ++var3) {
- if (((Area)this).grabPoint(this._xpt[var3], this._ypt[var3], var1, var2)) {
- this._grabIndex = var3;
- return true;
- }
- }
-
- return false;
- }
-
- public boolean isSelect(int var1, int var2) {
- for(int var3 = 0; var3 < this._npts - 1; ++var3) {
- if (((Area)this).grabLine(this._xpt[var3], this._ypt[var3], this._xpt[var3 + 1], this._ypt[var3 + 1], var1, var2)) {
- return true;
- }
- }
-
- return false;
- }
-
- public boolean inside(int var1, int var2) {
- Polygon var3 = new Polygon(this._xpt, this._ypt, this._npts);
- return var3.inside(var1, var2);
- }
-
- public boolean isValid() {
- return !this.isClosed() || this._npts >= 4;
- }
-
- public boolean isComplete() {
- return this.isValid() && this.isClosed();
- }
-
- public void advance() {
- this._grabIndex = this._npts;
- }
-
- public void draw(Graphics var1) {
- if (this.isValid()) {
- for(int var2 = 1; var2 < this._npts; ++var2) {
- var1.drawLine(this._xpt[var2 - 1], this._ypt[var2 - 1], this._xpt[var2], this._ypt[var2]);
- }
-
- if (!this.isClosed()) {
- ((Area)this).drawAnchor(var1, this._xpt[0], this._ypt[0]);
- }
-
- if (super._selected) {
- for(int var3 = 1; var3 < this._npts; ++var3) {
- ((Area)this).drawPoint(var1, this._xpt[var3], this._ypt[var3]);
- }
- }
- }
-
- }
-
- public String getShape() {
- return "POLY";
- }
-
- public String getCoords() {
- StringBuffer var1 = new StringBuffer();
-
- for(int var2 = 0; var2 < this._npts; ++var2) {
- if (var2 > 0) {
- var1.append(",");
- }
-
- var1.append(this._xpt[var2] + "," + this._ypt[var2]);
- }
-
- return var1.toString();
- }
-
- public synchronized Object clone() {
- Poly var1 = new Poly();
- var1._npts = this._npts;
- var1._xpt = new int[this._xpt.length];
- var1._ypt = new int[this._ypt.length];
- System.arraycopy(this._xpt, 0, var1._xpt, 0, this._npts);
- System.arraycopy(this._ypt, 0, var1._ypt, 0, this._npts);
- var1._grabIndex = this._grabIndex;
- return var1;
- }
-
- private void addPoint(int var1, int var2) {
- if (this._npts == this._xpt.length) {
- int[] var3 = new int[this._xpt.length * 2];
- System.arraycopy(this._xpt, 0, var3, 0, this._npts);
- this._xpt = var3;
- }
-
- if (this._npts == this._ypt.length) {
- int[] var4 = new int[this._ypt.length * 2];
- System.arraycopy(this._ypt, 0, var4, 0, this._npts);
- this._ypt = var4;
- }
-
- this._xpt[this._npts] = var1;
- this._ypt[this._npts] = var2;
- ++this._npts;
- }
-
- private void setPoint(int var1, int var2, int var3) {
- if (var1 < this._npts) {
- this._xpt[var1] = var2;
- this._ypt[var1] = var3;
- }
-
- }
-
- private boolean isClosed() {
- return this._npts > 1 && this._xpt[0] == this._xpt[this._npts - 1] && this._ypt[0] == this._ypt[this._npts - 1];
- }
-
- public void close() {
- if (!this.isClosed()) {
- this.addPoint(this._xpt[0], this._ypt[0]);
- }
-
- }
- }
-