View Javadoc

1   package org.catacomb.graph.arbor;
2   
3   
4   import org.catacomb.be.Position;
5   import org.catacomb.datalish.Box;
6   import org.catacomb.graph.gui.BuildPaintInstructor;
7   import org.catacomb.graph.gui.Builder;
8   import org.catacomb.graph.gui.Painter;
9   
10  import java.awt.Color;
11  
12  
13  // REFAC SegmentGraphVE should use this.
14  
15  
16  
17  public class SegmentGraphPainter implements BuildPaintInstructor {
18  
19      SegmentGraph graph;
20  
21      boolean b_antialias;
22  
23      SegmentGraphPoint sgp1;
24      SegmentGraphPoint sgp2;
25  
26  
27      boolean b_live;
28  
29      public SegmentGraphPainter() {
30          b_antialias = false;
31          b_live = true;
32      }
33  
34  
35      public void setSegmentGraph(SegmentGraph sg) {
36          graph = sg;
37      }
38  
39  
40      public void setBuildPoints(boolean b) {
41          b_live = b;
42      }
43  
44  
45      public void setAntialias(boolean b) {
46          b_antialias = b;
47      }
48  
49  
50      public boolean antialias() {
51          return b_antialias;
52      }
53  
54  
55  
56  
57  
58      public void instruct(Painter painter, Builder builder) {
59          if (graph == null) {
60              return;
61          }
62  
63          // paint the protos first;
64  
65          for (SegmentGraphPoint sgp : graph.getPoints()) {
66              paintReal(sgp, painter, builder);
67          }
68  
69      }
70  
71  
72  
73  
74      public void paintReal(SegmentGraphPoint sgp,
75                            Painter painter, Builder builder) {
76  
77          if (b_live) {
78              builder.addPoint(sgp);
79          }
80  
81          SegmentGraphPoint[] nbrs = sgp.getNeighbors();
82          int index = sgp.getIndex();
83  
84  
85          painter.setColor(Color.white);
86          painter.drawCircle(sgp.getPosition(), sgp.getRadius());
87  
88  
89          for (int i = 0; i < nbrs.length; i++) {
90              if (nbrs[i].getIndex() > index) {
91                  painter.setColor(Color.white);
92                  drawSegment(painter, sgp, nbrs[i]);
93              }
94          }
95      }
96  
97  
98      public void drawSegment(Painter painter,
99                              SegmentGraphPoint sgpa, SegmentGraphPoint sgpb) {
100         Position posa = sgpa.getPosition();
101         double x1 = posa.getX();
102         double y1 = posa.getY();
103         double r1 = sgpa.getRadius();
104 
105         Position posb = sgpb.getPosition();
106         double x2 = posb.getX();
107         double y2 = posb.getY();
108         double r2 = sgpb.getRadius();
109 
110 
111         painter.drawCarrotSides(x1, y1, r1,  x2, y2, r2);
112     }
113 
114 
115     public Box getLimitBox() {
116         // TODO Auto-generated method stub
117         return null;
118     }
119 
120 
121     public Box getLimitBox(Painter p) {
122         // TODO Auto-generated method stub
123         return null;
124     }
125 
126 
127 
128 
129 
130 
131 
132 }