Line | Hits | Source |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2005, 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 | * Created on Mar 8, 2005 | |
10 | * | |
11 | */ | |
12 | package edu.uci.ics.jung.visualization.control; | |
13 | ||
14 | import java.awt.event.MouseEvent; | |
15 | import java.awt.event.MouseWheelEvent; | |
16 | import java.awt.event.MouseWheelListener; | |
17 | import java.awt.geom.Point2D; | |
18 | ||
19 | import edu.uci.ics.jung.visualization.VisualizationViewer; | |
20 | ||
21 | /** | |
22 | * ScalingGraphMouse applies a scaling transformation to the graph layout. | |
23 | * The Vertices get closer or farther apart, but do not themselves change | |
24 | * size. ScalingGraphMouse uses MouseWheelEvents to apply the scaling. | |
25 | * | |
26 | * @author Tom Nelson | |
27 | */ | |
28 | public class ScalingGraphMousePlugin extends AbstractGraphMousePlugin | |
29 | implements MouseWheelListener { | |
30 | ||
31 | /** | |
32 | * the amount to zoom in by | |
33 | */ | |
34 | 0 | protected float in = 1.1f; |
35 | /** | |
36 | * the amount to zoom out by | |
37 | */ | |
38 | 0 | protected float out = 1/1.1f; |
39 | ||
40 | /** | |
41 | * whether to center the zoom at the current mouse position | |
42 | */ | |
43 | 0 | protected boolean zoomAtMouse = true; |
44 | ||
45 | /** | |
46 | * controls scaling operations | |
47 | */ | |
48 | protected ScalingControl scaler; | |
49 | ||
50 | public ScalingGraphMousePlugin(ScalingControl scaler, int modifiers) { | |
51 | 0 | this(scaler, modifiers, 1.1f, 1/1.1f); |
52 | 0 | } |
53 | ||
54 | public ScalingGraphMousePlugin(ScalingControl scaler, int modifiers, float in, float out) { | |
55 | 0 | super(modifiers); |
56 | 0 | this.scaler = scaler; |
57 | 0 | this.in = in; |
58 | 0 | this.out = out; |
59 | 0 | } |
60 | /** | |
61 | * @param zoomAtMouse The zoomAtMouse to set. | |
62 | */ | |
63 | public void setZoomAtMouse(boolean zoomAtMouse) { | |
64 | 0 | this.zoomAtMouse = zoomAtMouse; |
65 | 0 | } |
66 | ||
67 | public boolean checkModifiers(MouseEvent e) { | |
68 | 0 | return e.getModifiers() == modifiers || (e.getModifiers() & modifiers) != 0; |
69 | } | |
70 | ||
71 | /** | |
72 | * zoom the display in or out, depending on the direction of the | |
73 | * mouse wheel motion. | |
74 | */ | |
75 | public void mouseWheelMoved(MouseWheelEvent e) { | |
76 | 0 | boolean accepted = checkModifiers(e); |
77 | 0 | if(accepted == true) { |
78 | 0 | VisualizationViewer vv = (VisualizationViewer)e.getSource(); |
79 | 0 | Point2D mouse = e.getPoint(); |
80 | 0 | Point2D center = vv.getCenter(); |
81 | 0 | int amount = e.getWheelRotation(); |
82 | 0 | if(zoomAtMouse) { |
83 | 0 | if(amount > 0) { |
84 | 0 | scaler.scale(vv, in, mouse); |
85 | 0 | } else if(amount < 0) { |
86 | 0 | scaler.scale(vv, out, mouse); |
87 | } | |
88 | } else { | |
89 | 0 | if(amount > 0) { |
90 | 0 | scaler.scale(vv, in, center); |
91 | 0 | } else if(amount < 0) { |
92 | 0 | scaler.scale(vv, out, center); |
93 | } | |
94 | } | |
95 | 0 | e.consume(); |
96 | 0 | vv.repaint(); |
97 | } | |
98 | 0 | } |
99 | /** | |
100 | * @return Returns the zoom in value. | |
101 | */ | |
102 | public float getIn() { | |
103 | 0 | return in; |
104 | } | |
105 | /** | |
106 | * @param in The zoom in value to set. | |
107 | */ | |
108 | public void setIn(float in) { | |
109 | 0 | this.in = in; |
110 | 0 | } |
111 | /** | |
112 | * @return Returns the zoom out value. | |
113 | */ | |
114 | public float getOut() { | |
115 | 0 | return out; |
116 | } | |
117 | /** | |
118 | * @param out The zoom out value to set. | |
119 | */ | |
120 | public void setOut(float out) { | |
121 | 0 | this.out = out; |
122 | 0 | } |
123 | ||
124 | public ScalingControl getScaler() { | |
125 | 0 | return scaler; |
126 | } | |
127 | ||
128 | public void setScaler(ScalingControl scaler) { | |
129 | 0 | this.scaler = scaler; |
130 | 0 | } |
131 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |