1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.transform;
12
13 import java.awt.Color;
14 import java.awt.Graphics;
15 import java.awt.Graphics2D;
16 import java.awt.Paint;
17 import java.awt.geom.RectangularShape;
18
19 import edu.uci.ics.jung.visualization.VisualizationViewer;
20 import edu.uci.ics.jung.visualization.VisualizationServer.Paintable;
21 import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
22
23
24
25
26
27
28
29
30 public abstract class AbstractLensSupport<V,E> implements LensSupport {
31
32 protected VisualizationViewer<V,E> vv;
33 protected VisualizationViewer.GraphMouse graphMouse;
34 protected LensTransformer lensTransformer;
35 protected ModalGraphMouse lensGraphMouse;
36 protected Lens lens;
37 protected LensControls lensControls;
38 protected String defaultToolTipText;
39
40 protected static final String instructions =
41 "<html><center>Mouse-Drag the Lens center to move it<p>"+
42 "Mouse-Drag the Lens edge to resize it<p>"+
43 "Ctrl+MouseWheel to change magnification</center></html>";
44
45
46
47
48
49
50
51 public AbstractLensSupport(VisualizationViewer<V,E> vv, ModalGraphMouse lensGraphMouse) {
52 this.vv = vv;
53 this.graphMouse = vv.getGraphMouse();
54 this.defaultToolTipText = vv.getToolTipText();
55 this.lensGraphMouse = lensGraphMouse;
56 }
57
58 public void activate(boolean state) {
59 if(state) activate();
60 else deactivate();
61 }
62
63 public LensTransformer getLensTransformer() {
64 return lensTransformer;
65 }
66
67
68
69
70 public ModalGraphMouse getGraphMouse() {
71 return lensGraphMouse;
72 }
73
74
75
76
77
78 public static class Lens implements Paintable {
79 LensTransformer lensTransformer;
80 RectangularShape lensShape;
81 Paint paint = Color.decode("0xdddddd");
82
83 public Lens(LensTransformer lensTransformer) {
84 this.lensTransformer = lensTransformer;
85 this.lensShape = lensTransformer.getLensShape();
86 }
87
88
89
90
91 public Paint getPaint() {
92 return paint;
93 }
94
95
96
97
98 public void setPaint(Paint paint) {
99 this.paint = paint;
100 }
101
102 public void paint(Graphics g) {
103 Graphics2D g2d = (Graphics2D)g;
104 g2d.setPaint(paint);
105 g2d.fill(lensShape);
106 }
107
108 public boolean useTransform() {
109 return true;
110 }
111 }
112
113
114
115
116
117
118
119 public static class LensControls implements Paintable {
120 LensTransformer lensTransformer;
121 RectangularShape lensShape;
122 Paint paint = Color.gray;
123
124 public LensControls(LensTransformer lensTransformer) {
125 this.lensTransformer = lensTransformer;
126 this.lensShape = lensTransformer.getLensShape();
127 }
128
129
130
131
132 public Paint getPaint() {
133 return paint;
134 }
135
136
137
138
139 public void setPaint(Paint paint) {
140 this.paint = paint;
141 }
142
143 public void paint(Graphics g) {
144
145 Graphics2D g2d = (Graphics2D)g;
146 g2d.setPaint(paint);
147 g2d.draw(lensShape);
148 int centerX = (int)Math.round(lensShape.getCenterX());
149 int centerY = (int)Math.round(lensShape.getCenterY());
150 g.drawOval(centerX-10, centerY-10, 20, 20);
151 }
152
153 public boolean useTransform() {
154 return true;
155 }
156 }
157
158
159
160
161 public Lens getLens() {
162 return lens;
163 }
164
165
166
167
168 public void setLens(Lens lens) {
169 this.lens = lens;
170 }
171
172
173
174
175 public LensControls getLensControls() {
176 return lensControls;
177 }
178
179
180
181
182 public void setLensControls(LensControls lensControls) {
183 this.lensControls = lensControls;
184 }
185 }