Back to index

moin  1.9.0~rc2
ArrowTip.java
Go to the documentation of this file.
00001 /*
00002  * @(#)ArrowTip.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.io.*;
00009 import java.awt.*;
00010 
00011 import CH.ifa.draw.framework.*;
00012 import CH.ifa.draw.standard.*;
00013 import CH.ifa.draw.util.*;
00014 
00019 public  class ArrowTip implements LineDecoration {
00020 
00021     private double  fAngle;         // pointiness of arrow
00022     private double  fOuterRadius;
00023     private double  fInnerRadius;
00024 
00025     /*
00026      * Serialization support.
00027      */
00028     private static final long serialVersionUID = -3459171428373823638L;
00029     private int arrowTipSerializedDataVersion = 1;
00030 
00031        public ArrowTip() {
00032            fAngle = 0.40;//0.35;
00033            fOuterRadius = 8;//15;
00034            fInnerRadius = 8;//12;
00035        }
00036 
00040        public ArrowTip(double angle, double outerRadius, double innerRadius) {
00041            fAngle = angle;
00042            fOuterRadius = outerRadius;
00043            fInnerRadius = innerRadius;
00044        }
00045 
00050     public void draw(Graphics g, int x1, int y1, int x2, int y2) {
00051         // TBD: reuse the Polygon object
00052         Polygon p = outline(x1, y1, x2, y2);
00053         g.fillPolygon(p.xpoints, p.ypoints, p.npoints);
00054     }
00055 
00059     public Polygon outline(int x1, int y1, int x2, int y2) {
00060         double dir = Math.PI/2 - Math.atan2(x2-x1, y1-y2);
00061         return outline(x1, y1, dir);
00062     }
00063 
00064     private Polygon outline(int x, int y, double direction) {
00065         Polygon shape = new Polygon();
00066 
00067         shape.addPoint(x, y);
00068         addPointRelative(shape, x, y, fOuterRadius, direction - fAngle);
00069         addPointRelative(shape, x, y, fInnerRadius, direction);
00070         addPointRelative(shape, x, y, fOuterRadius, direction + fAngle);
00071         shape.addPoint(x,y); // Closing the polygon (TEG 97-04-23)
00072         return shape;
00073     }
00074 
00075     private void addPointRelative(Polygon shape, int x, int y, double radius, double angle) {
00076         shape.addPoint(
00077             x + (int) (radius * Math.cos(angle)),
00078             y - (int) (radius * Math.sin(angle)));
00079     }
00080 
00084     public void write(StorableOutput dw) {
00085     }
00086 
00087     public String getMap() {
00088        return "";
00089     }
00090 
00094     public void read(StorableInput dr) throws IOException {
00095     }
00096 
00097 }