Source of LineEdge.java


  1: import java.awt.*;
  2: import java.awt.geom.*;

  4: /**
  5:    An edge that is shaped like a straight line.
  6: */
  7: public class LineEdge extends AbstractEdge
  8: {
  9:    public LineEdge()
 10:    {
 11:       lineStyle = LineStyle.SOLID;
 12:    }

 14:    public void draw(Graphics2D g2)
 15:    {
 16:       Stroke oldStroke = g2.getStroke();
 17:       g2.setStroke(lineStyle.getStroke());
 18:       g2.draw(getConnectionPoints());
 19:       g2.setStroke(oldStroke);
 20:    }

 22:    public boolean contains(Point2D aPoint)
 23:    {
 24:       final double MAX_DIST = 2;
 25:       return getConnectionPoints().ptSegDist(aPoint) 
 26:          < MAX_DIST;
 27:    }

 29:    /**
 30:       Sets the line style property.
 31:       @param newValue the new value
 32:    */
 33:    public void setLineStyle(LineStyle newValue) { lineStyle = newValue; }

 35:    /**
 36:       Gets the line style property.
 37:       @return the line style
 38:    */
 39:    public LineStyle getLineStyle() { return lineStyle; }
 40:    
 41:    private LineStyle lineStyle;
 42: }