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

LineHitsSource
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     
500    protected Map renderingHints = new HashMap();
51  
520    protected float scalex = 1.0f;
53  
540    protected float scaley = 1.0f;
55  
56     protected Lens lens;
57     
580    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,
690            float scalex, float scaley) {
700        this.vv = vv;
710        this.model = vv.getModel();
720        this.model.setRelaxerThreadSleepTime(200);
730        this.renderer = vv.getRenderer();
740        this.scalex = scalex;
750        this.scaley = scaley;
760        renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
770        setLayoutTransformer(vv.getLayoutTransformer());
780    }
79     
80     
81  
82     /**
83      * @return Returns the layoutTransformer.
84      */
85     public MutableTransformer getLayoutTransformer() {
860        return layoutTransformer;
87     }
88  
89  
90  
91     /**
92      * @param layoutTransformer The layoutTransformer to set.
93      */
94     public void setLayoutTransformer(MutableTransformer layoutTransformer) {
950        this.layoutTransformer = layoutTransformer;
960    }
97  
98  
99  
100     /**
101      * reset the Lens to no zoom/no offset.
102      * passes call to Lens
103      *
104      */
105     public void resetLens() {
1060        if(lens != null) {
1070            lens.reset();
108         }
1090    }
110     
111     /**
112      * set the initial values for the Lens
113      * (50% zoom centered in display)
114      *
115      */
116     public void initLens() {
1170        if(lens != null) {
1180            lens.init();
119         }
1200    }
121     
122     /**
123      * proportionally zoom the Lens
124      * @param percent
125      */
126     public void zoom(float percent) {
1270        vv.getViewTransformer().scale(percent, percent, vv.getCenter());
1280    }
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() {
1360        super.addNotify();
1370        Dimension layoutSize = model.getGraphLayout().getCurrentSize();
1380        if (layoutSize != null) {
1390            Dimension mySize = new Dimension((int) (layoutSize.width * scalex),
140                     (int) (layoutSize.height * scaley));
1410            setPreferredSize(mySize);
1420            initMouseClicker();
143         }
1440    }
145  
146     /**
147      * Creates and adds the Lens to control zoom/pan functions
148      */
149     protected void initMouseClicker() {
1500        Dimension layoutSize = model.getGraphLayout().getCurrentSize();
1510        if (layoutSize != null) {
1520            lens = new Lens(vv, scalex, scaley);
153         }
1540        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         });
1630        addMouseListener(lens);
1640        addMouseMotionListener(lens);
1650    }
166  
167     /**
168      * UNTESTED.
169      */
170     public void setRenderer(Renderer r) {
1710        this.renderer = r;
1720        repaint();
1730    }
174  
175     /**
176      * setter for layout
177      * @param v the layout
178      */
179     public void setGraphLayout(Layout layout) {
1800        model.setGraphLayout(layout);
1810    }
182  
183     /**
184      * getter for graph layout
185      * @return the layout
186      */
187     public Layout getGraphLayout() {
1880        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) {
1970        Layout layout = model.getGraphLayout();
198         // paint all the Edges
1990        for (Iterator iter = layout.getGraph().getEdges().iterator(); iter
2000                .hasNext();) {
2010            Edge e = (Edge) iter.next();
2020            Vertex v1 = (Vertex) e.getEndpoints().getFirst();
2030            Vertex v2 = (Vertex) e.getEndpoints().getSecond();
2040            Point2D p1 = layout.getLocation(v1);
2050            Point2D p2 = layout.getLocation(v2);
2060            p1 = layoutTransformer.transform(p1);
2070            p2 = layoutTransformer.transform(p2);
2080            renderer.paintEdge(g, e, (int) p1.getX(),
209                     (int) p1.getY(), (int) p2.getX(), (int) p2.getY());
210         }
211         // Paint all the Vertices
2120        for (Iterator iter = layout.getGraph().getVertices().iterator(); iter
2130                .hasNext();) {
2140            Vertex v = (Vertex) iter.next();
2150            Point2D p = layout.getLocation(v);
2160            p = layoutTransformer.transform(p);
2170            renderer.paintVertex(g, v, (int) p.getX(),
218                     (int) p.getY());
219         }
2200    }
221  
222     /**
223      * paint the graph, transforming with the scalex and scaley
224      */
225     protected synchronized void paintComponent(Graphics g) {
226  
2270        super.paintComponent(g);
228  
2290        Graphics2D g2d = (Graphics2D) g;
2300        g2d.setRenderingHints(renderingHints);
231  
2320        AffineTransform oldXform = g2d.getTransform();
2330        AffineTransform newXform = new AffineTransform(oldXform);
2340        newXform.scale(scalex, scaley);
2350        g2d.setTransform(newXform);
236  
2370        paintGraph(g);
238  
2390        Color oldColor = g.getColor();
240         // the Lens will be cyan
2410        g2d.setColor(Color.cyan);
242         
243         // put the old transform back (not scaled) to draw the Lens
2440        g2d.setTransform(oldXform);
2450        if (lens != null) {
2460            g2d.draw(lens);
247         }
248         // restore old paint after drawing the Lens
2490        g.setColor(oldColor);
2500    }
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.