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

LineHitsSource
1 /*
2  * Copyright (c) 2003, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  *
9  */
10 package edu.uci.ics.jung.visualization;
11  
12 import java.awt.Dimension;
13 import java.awt.Point;
14 import java.awt.event.MouseEvent;
15 import java.awt.event.MouseListener;
16 import java.awt.event.MouseMotionListener;
17 import java.awt.geom.AffineTransform;
18 import java.awt.geom.Line2D;
19 import java.awt.geom.Point2D;
20 import java.awt.geom.Rectangle2D;
21 import java.beans.PropertyChangeSupport;
22  
23 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
24  
25  
26 /**
27  * Lens is intended to be used as an overlay on the
28  * BirdsEyeVisualizationViewer. It is a Rectangle that
29  * acts as a MouseListener (for moving and resizing the
30  * Rectangle).
31  *
32  * @deprecated use the SatelliteVisualizationViewer instead
33  *
34  * @author Tom Nelson - RABA Technologies
35  *
36  *
37  */
38 public class Lens extends Rectangle2D.Float implements MouseListener,
39         MouseMotionListener {
40  
41     /**
42      * true if we are dragging the Rectangle around
43      */
44     protected boolean pan;
45  
46     /**
47      * true if we are dragging the right leg
48      */
49     protected boolean dragRightLeg;
50  
51     /**
52      * true if we are dragging the base
53      */
54     protected boolean dragBase;
55  
56     /**
57      * true if we are dragging the left leg
58      */
59     protected boolean dragLeftLeg;
60  
61     /**
62      * true if we are dragging the top
63      */
64     protected boolean dragTop;
65  
66     /**
67      * true if the mouse pointer is outside the window
68      */
69     protected boolean outside;
70  
71     /**
72      * the offset in the x direction, as a percentage of width
73      */
74     protected float offx;
75  
76     /**
77      * the offset in the y direction, as a percentage of height
78      */
79     protected float offy;
80  
81     /**
82      * the left leg of the rectangle
83      */
84     protected Line2D leftLeg;
85  
86     /**
87      * the right leg of the rectangle
88      */
89     protected Line2D rightLeg;
90  
91     /**
92      * the base of the rectangle
93      */
94     protected Line2D base;
95  
96     /**
97      * the top of the rectangle
98      */
99     protected Line2D top;
100  
101     /**
102      * the scale of the BirdsEyeVisualizationViewer compared to
103      * the graph display
104      */
105     protected float scalex;
106  
107     /**
108      * the scale of the BirdsEyeVisualizationViewer compared to
109      * the graph display
110      */
111     protected float scaley;
112  
113     /**
114      * the layout being used by the BirdsEye
115      */
116     protected Layout layout;
117     
118     /**
119      * the VisualizationViewer that is scaled and translated
120      * by this Lens
121      */
122     protected VisualizationViewer vv;
123  
124     /**
125      * support for property changes
126      */
127     protected PropertyChangeSupport support;
128  
129     /**
130      * ratio of width to height
131      */
132     protected float aspectRatio;
133     
134     protected Point down;
135     
136     protected AffineTransform lensXform;
137  
138     /**
139      * Create a Lens that is centered in the
140      * BirdsEyeVisualizationViewer
141      *
142      */
143     public Lens(VisualizationViewer vv, float scalex, float scaley) {
1440        super(vv.getGraphLayout().getCurrentSize().width * scalex / 4,
145                 vv.getGraphLayout().getCurrentSize().height * scaley / 4,
146                 vv.getGraphLayout().getCurrentSize().width * scalex / 2,
147                 vv.getGraphLayout().getCurrentSize().height * scaley / 2);
1480        this.vv = vv;
1490        this.layout = vv.getGraphLayout();
1500        this.scalex = scalex;
1510        this.scaley = scaley;
1520        lensXform = AffineTransform.getScaleInstance(1/scalex, 1/scaley);
1530        this.aspectRatio = (float)((getMaxX() - getMinX()) / (getMaxY() - getMinY()));
1540        rightLeg = new Line2D.Float((float)getMaxX(), (float)getMinY(), (float)getMaxX(), (float)getMaxY());
1550        leftLeg = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMinX(), (float)getMaxY());
1560        base = new Line2D.Float((float)getMinX(), (float)getMaxY(), (float)getMaxX(), (float)getMaxY());
1570        top = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMaxX(), (float)getMinY());
1580    }
159  
160     /**
161      * reset the rectangle to the full size of the BirdsEyeVisualizationViewer
162      * This will result in no zoom or pan of the main display
163      *
164      */
165     public void reset() {
1660        Dimension d = vv.getSize();
1670        Dimension ld = vv.getGraphLayout().getCurrentSize();
1680        vv.getViewTransformer().setScale((float)d.width/ld.width, (float)d.height/ld.height, new Point2D.Float());
1690    }
170     
171     public void setFrame(VisualizationViewer vv) {
1720        MutableTransformer viewTransformer = vv.getViewTransformer();
1730        Dimension d = new Dimension(
174               (int) (vv.getSize().width * scalex ),
175               (int) (vv.getSize().height * scaley ));
1760        float width = (float) (d.width/(viewTransformer.getScaleX()));
1770        float height = (float) (d.height/(viewTransformer.getScaleY()));
1780        float x = -(float) (viewTransformer.getTranslateX()*scalex/(viewTransformer.getScaleX()));
1790        float y = -(float) (viewTransformer.getTranslateY()*scaley/(viewTransformer.getScaleY()));
1800        setFrame(x,y,width,height);
1810    }
182     
183     /**
184      * set the Rectangle to be centered in the BirdsEyeVisualizationViewer
185      *
186      */
187     public void init() {
1880        vv.getViewTransformer().setScale(2.0f, 2.0f, vv.getCenter());
1890    }
190  
191     /*
192      * (non-Javadoc)
193      *
194      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
195      */
196     public void mouseClicked(MouseEvent e) {
1970    }
198  
199     /*
200      * (non-Javadoc)
201      *
202      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
203      */
204     public void mousePressed(MouseEvent e) {
205  
2060        down = e.getPoint();
207         
2080        if (leftLeg.ptLineDist(down) < 5) {
2090            dragLeftLeg = true;
2100        } else if (rightLeg.ptLineDist(down) < 5) {
2110            dragRightLeg = true;
2120        } else if (base.ptLineDist(down) < 5) {
2130            dragBase = true;
2140        } else if (top.ptLineDist(down) < 5) {
2150            dragTop = true;
2160        } else if (contains(down)) {
2170            pan = true;
218         } else {
2190            pan = dragLeftLeg = dragRightLeg = dragBase = dragTop = false;
220         }
2210    }
222  
223     /*
224      * (non-Javadoc)
225      *
226      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
227      */
228     public void mouseReleased(MouseEvent e) {
2290        pan = dragLeftLeg = dragRightLeg = dragTop = dragBase = false;
2300    }
231  
232     /*
233      * (non-Javadoc)
234      *
235      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
236      */
237     public void mouseEntered(MouseEvent e) {
2380        outside = false;
2390    }
240  
241     /*
242      * (non-Javadoc)
243      *
244      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
245      */
246     public void mouseExited(MouseEvent e) {
2470        outside = true;
2480    }
249  
250     /*
251      * (non-Javadoc)
252      *
253      * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
254      */
255     public void mouseDragged(MouseEvent e) {
2560        if (outside)
2570            return;
258  
2590        Point2D q = down;
2600        Point2D p = e.getPoint();
2610        if (pan) {
2620            vv.getViewTransformer().translate((q.getX()-p.getX())/scalex, (q.getY()-p.getY())/scaley);
263         } else {
2640            float dw = 0.0f;
2650            float dh = 0.0f;
266  
2670            if (dragRightLeg) {
2680                dw = (float) (p.getX()-q.getX());
2690                dh = dw / aspectRatio;
270  
2710            } else if (dragLeftLeg) {
2720                dw = (float) (q.getX()-p.getX());
2730                dh = dw / aspectRatio;
274  
2750            } else if (dragBase) {
2760                dh = (float) (p.getY()-q.getY());
2770                dw = dh * aspectRatio;
278  
2790            } else if (dragTop) {
2800                dh = (float) (q.getY()-p.getY());
2810                dw = dh * aspectRatio;
282             }
2830            float pwidth = (float)getMaxX() - (float)getMinX();
2840            float pheight = (float)getMaxY() - (float)getMinY();
2850            float newWidth = pwidth + 2 * dw;
2860            float newHeight = pheight + 2 * dh;
2870            if (newWidth < 3 || newHeight < 3)
2880                return;
2890            vv.getViewTransformer().scale(pwidth/newWidth, pheight/newHeight, vv.getCenter());
290         }
2910        down = e.getPoint();
292  
2930        rightLeg = new Line2D.Float((float)getMaxX(), (float)getMinY(), (float)getMaxX(), (float)getMaxY());
2940        leftLeg = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMinX(), (float)getMaxY());
2950        base = new Line2D.Float((float)getMinX(), (float)getMaxY(), (float)getMaxX(), (float)getMaxY());
2960        top = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMaxX(), (float)getMinY());
2970    }
298  
299     /*
300      * (non-Javadoc)
301      *
302      * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
303      */
304     public void mouseMoved(MouseEvent e) {
3050    }
306 }

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.