View Javadoc

1   package org.catacomb.dataview.formats;
2   
3   import java.io.File;
4   
5   import org.catacomb.datalish.Box;
6   import org.catacomb.dataview.display.ViewConfig;
7   import org.catacomb.graph.gui.Painter;
8   import org.catacomb.util.FileUtil;
9   
10  import java.util.StringTokenizer;
11  
12  
13  public class SWCDisplay implements DataHandler {
14  
15      Node[] nodes;
16  
17      static String[] viewOptions = {"lines", "boxes", "frame", "solid"};
18  
19      String viewStyle = "lines";
20  
21  
22      public String[] getViewOptions() {
23          return viewOptions;
24      }
25  
26      public void setViewStyle(String s) {
27          viewStyle = s;
28      }
29  
30  
31      public String getMagic() {
32          return "cctswc00";
33      }
34  
35  
36      public void read(File f) {
37  
38          String s = FileUtil.readStringFromFile(f);
39          StringTokenizer st = new StringTokenizer(s, "\n");
40          int npx = st.countTokens();
41          nodes = new Node[npx];
42  
43          while (st.hasMoreTokens()) {
44              String sl = st.nextToken();
45              StringTokenizer stl = new StringTokenizer(sl, " ");
46              if (stl.countTokens() >= 6) {
47                  int ip = nextInt(stl);
48                  double x = nextDouble(stl);
49                  double y = nextDouble(stl);
50                  double z = nextDouble(stl);
51                  double r = nextDouble(stl);
52                  int ipar = nextInt(stl);
53                  Node parent = null;
54                  if (ipar >= 0) {
55                      parent = nodes[ipar];
56                  }
57                  nodes[ip] = new Node(ip, x, y, z, r, parent);
58              }
59  
60          }
61  
62  
63      }
64  
65      private int nextInt(StringTokenizer stl) {
66          return Integer.parseInt(stl.nextToken());
67      }
68  
69      private double nextDouble(StringTokenizer stl) {
70          return Double.parseDouble(stl.nextToken());
71      }
72  
73  
74      public boolean antialias() {
75          return false;
76      }
77  
78  
79      public void instruct(Painter p) {
80  
81          if (viewStyle.equals("lines")) {
82              instructLines(p);
83  
84          } else if (viewStyle.equals("boxes")) {
85              instructBoxes(p);
86  
87          } else if (viewStyle.equals("frame")) {
88              instructFrame(p);
89  
90          } else if (viewStyle.equals("filled")) {
91              instructFilled(p);
92          }
93      }
94  
95  
96  
97      private void instructLines(Painter p) {
98          for (Node node : nodes) {
99              if (node != null) {
100                 Node pn = node.parent;
101                 if (pn != null) {
102                     p.setColorWhite();
103                     p.drawLine(node.x, node.y, pn.x, pn.y);
104 
105                 }
106                 p.fillIntCircle(node.x, node.y, 3);
107             }
108         }
109 
110     }
111 
112 
113     private void instructBoxes(Painter p) {
114         for (Node node : nodes) {
115             if (node != null) {
116                 Node pn = node.parent;
117                 if (pn != null) {
118                     p.setColorWhite();
119                     // need ends too
120                     p.drawCarrotSides(node.x, node.y, node.r, pn.x, pn.y, pn.r);
121                 }
122             }
123         }
124     }
125 
126     private void instructFrame(Painter p) {
127         for (Node node : nodes) {
128             if (node != null) {
129                 Node pn = node.parent;
130                 if (pn != null) {
131                     p.setColorWhite();
132                     p.drawCarrotSides(node.x, node.y, node.r, pn.x, pn.y, pn.r);
133 
134                 }
135                 p.drawCircle(node.x, node.y, node.r);
136             }
137         }
138 
139     }
140 
141     private void instructFilled(Painter p) {
142         for (Node node : nodes) {
143             if (node != null) {
144                 Node pn = node.parent;
145                 if (pn != null) {
146                     p.setColorWhite();
147                     p.drawLine(node.x, node.y, pn.x, pn.y);
148 
149                 }
150                 p.fillIntCircle(node.x, node.y, 3);
151             }
152         }
153 
154     }
155 
156 
157     public Box getLimitBox() {
158         return null;
159     }
160 
161 
162 
163 
164     class Node {
165         int index;
166         Node parent;
167         double x;
168         double y;
169         double z;
170         double r;
171 
172 
173         public Node(int i, double ax, double ay, double az, double ar, Node par) {
174             index = i;
175             x = ax;
176             y = ay;
177             z = az;
178             r = ar;
179             parent = par;
180         }
181     }
182 
183 
184 
185 
186     public String[] getPlotNames() {
187         // TODO Auto-generated method stub
188         return null;
189     }
190 
191     public double getMinValue() {
192         // TODO Auto-generated method stub
193         return 0;
194     }
195 
196     public double getMaxValue() {
197         // TODO Auto-generated method stub
198         return 0;
199     }
200 
201     public double[] getFrameValues() {
202         // TODO Auto-generated method stub
203         return null;
204     }
205 
206     public int getContentStyle() {
207         return STATIC;
208     }
209 
210     public void setFrame(int ifr) {
211         // TODO Auto-generated method stub
212 
213     }
214 
215     public void setPlot(String s) {
216         // TODO Auto-generated method stub
217 
218     }
219 
220     public DataHandler getCoHandler() {
221         return null;
222     }
223 
224     public boolean hasData() {
225         return true;
226     }
227 
228     public String getXAxisLabel() {
229         // TODO Auto-generated method stub
230         return null;
231     }
232 
233     public String getYAxisLabel() {
234         // TODO Auto-generated method stub
235         return null;
236     }
237 
238     public ViewConfig getViewConfig(String s) {
239         // TODO Auto-generated method stub
240         return null;
241     }
242 
243     public void setZValue(double d) {
244         // TODO Auto-generated method stub
245 
246     }
247 }
248 
249 
250