001package horstmann.ch08_graphed2;
002import java.awt.Graphics2D;
003import java.awt.Stroke;
004import java.awt.geom.Point2D;
005
006/**
007   An edge that is shaped like a straight line.
008 */
009@SuppressWarnings("serial")
010public class LineEdge extends AbstractEdge
011{
012        public LineEdge()
013        {
014                lineStyle = LineStyle.SOLID;
015        }
016
017        public void draw(Graphics2D g2)
018        {
019                Stroke oldStroke = g2.getStroke();
020                g2.setStroke(lineStyle.getStroke());
021                g2.draw(getConnectionPoints());
022                g2.setStroke(oldStroke);
023        }
024
025        public boolean contains(Point2D aPoint)
026        {
027                final double MAX_DIST = 2;
028                return getConnectionPoints().ptSegDist(aPoint)
029                                < MAX_DIST;
030        }
031
032        /**
033      Sets the line style property.
034      @param newValue the new value
035         */
036        public void setLineStyle(LineStyle newValue) { lineStyle = newValue; }
037
038        /**
039      Gets the line style property.
040      @return the line style
041         */
042        public LineStyle getLineStyle() { return lineStyle; }
043
044        private LineStyle lineStyle;
045}