arahman22

LineNode.java

Feb 21st, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.awt.Graphics2D;
  2. import java.awt.geom.Line2D;
  3. import java.awt.geom.Point2D;
  4.  
  5.  
  6. public class LineNode extends GraphElement
  7. {
  8.     private Point2D.Double p1, p2;
  9.     Line2D line;
  10.     private boolean selected;
  11.     public LineNode()
  12.     {
  13.         p1 = new Point2D.Double (0, 0);
  14.         p2 = new Point2D.Double (0, 0);
  15.         line = new Line2D.Double(p1, p2);
  16.     }
  17.    
  18.     public LineNode(double x1, double y1, double x2, double y2)
  19.     {
  20.         line = new Line2D.Double(x1, y1, x2, y2);
  21.         selected = false;
  22.     }
  23.    
  24.     public LineNode(Point2D.Double p1, Point2D.Double p2)
  25.     {
  26.         line = new Line2D.Double(p1, p2);
  27.     }
  28.    
  29.     public void draw (Graphics2D g2)
  30.     {
  31.         if (line != null)
  32.             g2.draw(line);
  33.     }
  34.  
  35.     @Override
  36.     void setSelected(double x, double y)
  37.     {
  38.         if (isSelected (x, y))
  39.             selected = true;
  40.         else
  41.             selected = false;
  42.     }
  43.  
  44.     @Override
  45.     double getWidth()
  46.     {
  47.         return 0;
  48.     }
  49.  
  50.     @Override
  51.     double getHeight()
  52.     {
  53.         return 0;
  54.     }
  55.    
  56.     @Override
  57.     boolean isSelected(double x, double y)
  58.     {
  59.         if (line.contains(x, y))
  60.         {
  61.             System.out.println("In line");
  62.             return true;
  63.         }
  64.         return false;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment