Back to index

moin  1.9.0~rc2
DiamondFigure.java
Go to the documentation of this file.
00001 /*
00002  * Hacked together by Doug lea
00003  * Tue Feb 25 17:39:44 1997  Doug Lea  (dl at gee)
00004  *
00005  */
00006 
00007 package CH.ifa.draw.contrib;
00008 
00009 import java.awt.*;
00010 import java.util.*;
00011 import java.io.IOException;
00012 import CH.ifa.draw.framework.*;
00013 import CH.ifa.draw.util.*;
00014 import CH.ifa.draw.standard.*;
00015 import CH.ifa.draw.figures.*;
00016 
00020 public  class DiamondFigure extends RectangleFigure {
00021 
00022   public DiamondFigure() {
00023     super(new Point(0,0), new Point(0,0));
00024   }
00025 
00026   public DiamondFigure(Point origin, Point corner) {
00027     super(origin,corner);
00028   }
00029 
00031   protected Polygon polygon() {
00032     Rectangle r = displayBox();
00033     Polygon p = new Polygon();
00034     p.addPoint(r.x, r.y+r.height/2);
00035     p.addPoint(r.x+r.width/2, r.y);
00036     p.addPoint(r.x+r.width, r.y+r.height/2);
00037     p.addPoint(r.x+r.width/2, r.y+r.height);
00038     return p;
00039   }
00040 
00041   public void draw(Graphics g) {
00042     Polygon p = polygon();
00043     g.setColor(getFillColor());
00044     g.fillPolygon(p);
00045     g.setColor(getFrameColor());
00046     g.drawPolygon(p);
00047   }
00048 
00049   public Insets connectionInsets() {
00050     Rectangle r = displayBox();
00051     return new Insets(r.height/2, r.width/2, r.height/2, r.width/2);
00052   }
00053 
00054   public boolean containsPoint(int x, int y) {
00055     return polygon().contains(x, y);
00056   }
00057 
00058   /*public Point chop(Point p) {
00059     return PolygonFigure.chop(polygon(), p);
00060   }*/
00061 
00062 }