/Users/lyon/j4p/src/ip/gui/EdgeElement.java

1    package ip.gui; 
2     
3    import java.awt.*; 
4     
5    public class EdgeElement { 
6        //private static final int OPEN = 1; 
7        //private static final int CLOSED = 0; 
8        private boolean open = true; 
9     
10    
11       private EdgeElement parent = null; 
12       public Point p1 = new Point(0, 0); 
13       public Point p2 = new Point(0, 0); 
14    
15       private int cost = 0; 
16    
17       public EdgeElement() { 
18       } 
19    
20       public EdgeElement(EdgeElement e) { 
21           p1.x = e.p1.x; 
22           p1.y = e.p1.y; 
23           p2.x = e.p2.x; 
24           p2.y = e.p2.y; 
25           cost = e.cost; 
26           e.setOpen(e.isOpen()); 
27       } 
28    
29       public void setCoordinates(Point _p1, Point _p2) { 
30           p1.x = _p1.x; 
31           p1.y = _p1.y; 
32           p2.x = _p2.x; 
33           p2.y = _p2.y; 
34       } 
35    
36       public void setOpen(boolean _open) { 
37           open = _open; 
38       } 
39    
40    
41       public boolean isOpen() { 
42           return open; 
43       } 
44    
45    
46       public void setParent(EdgeElement _parent) { 
47           parent = _parent; 
48       } 
49    
50       public EdgeElement getParent() { 
51           return parent; 
52       } 
53    
54       public void setCost(int _c) { 
55           if (parent == null) 
56               cost = _c; 
57           else 
58               cost = _c + parent.getCost(); 
59       } 
60    
61       public int getPly() { 
62           if (parent == null) 
63               return 0; 
64           return parent.getPly() + 1; 
65       } 
66    
67    
68       public int getCost() { 
69           return cost; 
70       } 
71    
72       public Polygon getPath() { 
73           EdgeElement pos = this; 
74           Polygon p = new Polygon(); 
75           while (pos != null) { 
76               p.addPoint(pos.p2.x, pos.p2.y); 
77               pos = pos.getParent(); 
78           } 
79           return p; 
80       } 
81    
82       public int distance(Point p) { 
83           return (int) p2.distance(p.x, p.y); 
84    
85       } 
86   } 
87