# Coverage details for edu.uci.ics.jung.visualization.BirdsEyeVisualizationViewer

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2003, the JUNG Project and the Regents of the University`
3 |  | `* of California`
4 |  | `* All rights reserved.`
5 |  | `*`
6 |  | `* This software is open-source under the BSD license; see either`
7 |  | `* "license.txt" or`
8 |  | `* http://jung.sourceforge.net/license.txt for a description.`
9 |  | `*/`
10 |  | `package edu.uci.ics.jung.visualization;`
11 |  | ``
12 |  | `import java.awt.Color;`
13 |  | `import java.awt.Dimension;`
14 |  | `import java.awt.Graphics;`
15 |  | `import java.awt.Graphics2D;`
16 |  | `import java.awt.RenderingHints;`
17 |  | `import java.awt.geom.AffineTransform;`
18 |  | `import java.awt.geom.Point2D;`
19 |  | `import java.util.HashMap;`
20 |  | `import java.util.Iterator;`
21 |  | `import java.util.Map;`
22 |  | ``
23 |  | `import javax.swing.JPanel;`
24 |  | `import javax.swing.event.ChangeEvent;`
25 |  | `import javax.swing.event.ChangeListener;`
26 |  | ``
27 |  | `import edu.uci.ics.jung.graph.Edge;`
28 |  | `import edu.uci.ics.jung.graph.Vertex;`
29 |  | `import edu.uci.ics.jung.visualization.transform.MutableAffineTransformer;`
30 |  | `import edu.uci.ics.jung.visualization.transform.MutableTransformer;`
31 |  | ``
32 |  | `/**`
33 |  | `* BirdsEyeVisualizationViewer is intended to be an additional display of a`
34 |  | `* graph and layout that is being manipulated elsewhere. This class makes no`
35 |  | `* calls that mutate the graph or layout`
36 |  | `*`
37 |  | `* @deprecated Use the SatelliteVisualizationViewer instead`
38 |  | `* @author Tom Nelson - RABA Technologies`
39 |  | `*`
40 |  | `*`
41 |  | `*/`
42 |  | `public class BirdsEyeVisualizationViewer extends JPanel {`
43 |  | ``
44 |  | `protected VisualizationViewer vv;`
45 |  | ``
46 |  | `protected Renderer renderer;`
47 |  | ``
48 |  | `protected VisualizationModel model;`
49 |  | ``
50 | 0 | `protected Map renderingHints = new HashMap();`
51 |  | ``
52 | 0 | `protected float scalex = 1.0f;`
53 |  | ``
54 | 0 | `protected float scaley = 1.0f;`
55 |  | ``
56 |  | `protected Lens lens;`
57 |  | ``
58 | 0 | `protected MutableTransformer layoutTransformer =`
59 |  | `new MutableAffineTransformer(new AffineTransform());`
60 |  | ``
61 |  | `/**`
62 |  | `* create an instance with passed values`
63 |  | `* @param layout the layout to use`
64 |  | `* @param r the renderer to use`
65 |  | `* @param scalex the scale in the horizontal direction`
66 |  | `* @param scaley the scale in the vertical direction`
67 |  | `*/`
68 |  | `public BirdsEyeVisualizationViewer(VisualizationViewer vv,`
69 | 0 | `float scalex, float scaley) {`
70 | 0 | `this.vv = vv;`
71 | 0 | `this.model = vv.getModel();`
72 | 0 | `this.model.setRelaxerThreadSleepTime(200);`
73 | 0 | `this.renderer = vv.getRenderer();`
74 | 0 | `this.scalex = scalex;`
75 | 0 | `this.scaley = scaley;`
76 | 0 | `renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);`
77 | 0 | `setLayoutTransformer(vv.getLayoutTransformer());`
78 | 0 | `}`
79 |  | ``
80 |  | ``
81 |  | ``
82 |  | `/**`
83 |  | `* @return Returns the layoutTransformer.`
84 |  | `*/`
85 |  | `public MutableTransformer getLayoutTransformer() {`
86 | 0 | `return layoutTransformer;`
87 |  | `}`
88 |  | ``
89 |  | ``
90 |  | ``
91 |  | `/**`
92 |  | `* @param layoutTransformer The layoutTransformer to set.`
93 |  | `*/`
94 |  | `public void setLayoutTransformer(MutableTransformer layoutTransformer) {`
95 | 0 | `this.layoutTransformer = layoutTransformer;`
96 | 0 | `}`
97 |  | ``
98 |  | ``
99 |  | ``
100 |  | `/**`
101 |  | `* reset the Lens to no zoom/no offset.`
102 |  | `* passes call to Lens`
103 |  | `*`
104 |  | `*/`
105 |  | `public void resetLens() {`
106 | 0 | `if(lens != null) {`
107 | 0 | `lens.reset();`
108 |  | `}`
109 | 0 | `}`
110 |  | ``
111 |  | `/**`
112 |  | `* set the initial values for the Lens`
113 |  | `* (50% zoom centered in display)`
114 |  | `*`
115 |  | `*/`
116 |  | `public void initLens() {`
117 | 0 | `if(lens != null) {`
118 | 0 | `lens.init();`
119 |  | `}`
120 | 0 | `}`
121 |  | ``
122 |  | `/**`
123 |  | `* proportionally zoom the Lens`
124 |  | `* @param percent`
125 |  | `*/`
126 |  | `public void zoom(float percent) {`
127 | 0 | `vv.getViewTransformer().scale(percent, percent, vv.getCenter());`
128 | 0 | `}`
129 |  | ``
130 |  | `/**`
131 |  | `* defers setting the perferred size until the component is`
132 |  | `* live and the layout size is known`
133 |  | `* Adds the mouse clicker at that time.`
134 |  | `*/`
135 |  | `public void addNotify() {`
136 | 0 | `super.addNotify();`
137 | 0 | `Dimension layoutSize = model.getGraphLayout().getCurrentSize();`
138 | 0 | `if (layoutSize != null) {`
139 | 0 | `Dimension mySize = new Dimension((int) (layoutSize.width * scalex),`
140 |  | `(int) (layoutSize.height * scaley));`
141 | 0 | `setPreferredSize(mySize);`
142 | 0 | `initMouseClicker();`
143 |  | `}`
144 | 0 | `}`
145 |  | ``
146 |  | `/**`
147 |  | `* Creates and adds the Lens to control zoom/pan functions`
148 |  | `*/`
149 |  | `protected void initMouseClicker() {`
150 | 0 | `Dimension layoutSize = model.getGraphLayout().getCurrentSize();`
151 | 0 | `if (layoutSize != null) {`
152 | 0 | `lens = new Lens(vv, scalex, scaley);`
153 |  | `}`
154 | 0 | `vv.addChangeListener(new ChangeListener() {`
155 |  | ``
156 |  | `public void stateChanged(ChangeEvent e) {`
157 |  | `VisualizationViewer vv =`
158 |  | `(VisualizationViewer)e.getSource();`
159 |  | `lens.setFrame(vv);`
160 |  | `repaint();`
161 |  | `}`
162 |  | `});`
163 | 0 | `addMouseListener(lens);`
164 | 0 | `addMouseMotionListener(lens);`
165 | 0 | `}`
166 |  | ``
167 |  | `/**`
168 |  | `* UNTESTED.`
169 |  | `*/`
170 |  | `public void setRenderer(Renderer r) {`
171 | 0 | `this.renderer = r;`
172 | 0 | `repaint();`
173 | 0 | `}`
174 |  | ``
175 |  | `/**`
176 |  | `* setter for layout`
177 |  | `* @param v the layout`
178 |  | `*/`
179 |  | `public void setGraphLayout(Layout layout) {`
180 | 0 | `model.setGraphLayout(layout);`
181 | 0 | `}`
182 |  | ``
183 |  | `/**`
184 |  | `* getter for graph layout`
185 |  | `* @return the layout`
186 |  | `*/`
187 |  | `public Layout getGraphLayout() {`
188 | 0 | `return model.getGraphLayout();`
189 |  | `}`
190 |  | ``
191 |  | `/**`
192 |  | `* paint the graph components. The Graphics will have been transformed`
193 |  | `* by scalex and scaley prior to calling this method`
194 |  | `* @param g`
195 |  | `*/`
196 |  | `private void paintGraph(Graphics g) {`
197 | 0 | `Layout layout = model.getGraphLayout();`
198 |  | `// paint all the Edges`
199 | 0 | `for (Iterator iter = layout.getGraph().getEdges().iterator(); iter`
200 | 0 | `.hasNext();) {`
201 | 0 | `Edge e = (Edge) iter.next();`
202 | 0 | `Vertex v1 = (Vertex) e.getEndpoints().getFirst();`
203 | 0 | `Vertex v2 = (Vertex) e.getEndpoints().getSecond();`
204 | 0 | `Point2D p1 = layout.getLocation(v1);`
205 | 0 | `Point2D p2 = layout.getLocation(v2);`
206 | 0 | `p1 = layoutTransformer.transform(p1);`
207 | 0 | `p2 = layoutTransformer.transform(p2);`
208 | 0 | `renderer.paintEdge(g, e, (int) p1.getX(),`
209 |  | `(int) p1.getY(), (int) p2.getX(), (int) p2.getY());`
210 |  | `}`
211 |  | `// Paint all the Vertices`
212 | 0 | `for (Iterator iter = layout.getGraph().getVertices().iterator(); iter`
213 | 0 | `.hasNext();) {`
214 | 0 | `Vertex v = (Vertex) iter.next();`
215 | 0 | `Point2D p = layout.getLocation(v);`
216 | 0 | `p = layoutTransformer.transform(p);`
217 | 0 | `renderer.paintVertex(g, v, (int) p.getX(),`
218 |  | `(int) p.getY());`
219 |  | `}`
220 | 0 | `}`
221 |  | ``
222 |  | `/**`
223 |  | `* paint the graph, transforming with the scalex and scaley`
224 |  | `*/`
225 |  | `protected synchronized void paintComponent(Graphics g) {`
226 |  | ``
227 | 0 | `super.paintComponent(g);`
228 |  | ``
229 | 0 | `Graphics2D g2d = (Graphics2D) g;`
230 | 0 | `g2d.setRenderingHints(renderingHints);`
231 |  | ``
232 | 0 | `AffineTransform oldXform = g2d.getTransform();`
233 | 0 | `AffineTransform newXform = new AffineTransform(oldXform);`
234 | 0 | `newXform.scale(scalex, scaley);`
235 | 0 | `g2d.setTransform(newXform);`
236 |  | ``
237 | 0 | `paintGraph(g);`
238 |  | ``
239 | 0 | `Color oldColor = g.getColor();`
240 |  | `// the Lens will be cyan`
241 | 0 | `g2d.setColor(Color.cyan);`
242 |  | ``
243 |  | `// put the old transform back (not scaled) to draw the Lens`
244 | 0 | `g2d.setTransform(oldXform);`
245 | 0 | `if (lens != null) {`
246 | 0 | `g2d.draw(lens);`
247 |  | `}`
248 |  | `// restore old paint after drawing the Lens`
249 | 0 | `g.setColor(oldColor);`
250 | 0 | `}`
251 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.