1
2
3
4
5
6
7
8
9 package edu.uci.ics.jung.visualization.transform.shape;
10
11 import java.awt.Dimension;
12
13 import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
14 import edu.uci.ics.jung.visualization.Layer;
15 import edu.uci.ics.jung.visualization.RenderContext;
16 import edu.uci.ics.jung.visualization.VisualizationViewer;
17 import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
18 import edu.uci.ics.jung.visualization.picking.ViewLensShapePickSupport;
19 import edu.uci.ics.jung.visualization.renderers.Renderer;
20 import edu.uci.ics.jung.visualization.renderers.ReshapingEdgeRenderer;
21 import edu.uci.ics.jung.visualization.transform.AbstractLensSupport;
22 import edu.uci.ics.jung.visualization.transform.LensSupport;
23 import edu.uci.ics.jung.visualization.transform.LensTransformer;
24
25
26
27
28
29
30
31
32
33 public class ViewLensSupport<V,E> extends AbstractLensSupport<V,E>
34 implements LensSupport {
35
36 protected RenderContext<V,E> renderContext;
37 protected GraphicsDecorator lensGraphicsDecorator;
38 protected GraphicsDecorator savedGraphicsDecorator;
39 protected GraphElementAccessor<V,E> pickSupport;
40 protected Renderer.Edge<V,E> savedEdgeRenderer;
41 protected Renderer.Edge<V,E> reshapingEdgeRenderer;
42
43 public ViewLensSupport(VisualizationViewer<V,E> vv,
44 LensTransformer lensTransformer,
45 ModalGraphMouse lensGraphMouse) {
46 super(vv, lensGraphMouse);
47 this.renderContext = vv.getRenderContext();
48 this.pickSupport = renderContext.getPickSupport();
49 this.savedGraphicsDecorator = renderContext.getGraphicsContext();
50 this.lensTransformer = lensTransformer;
51 Dimension d = vv.getSize();
52 lensTransformer.setViewRadius(d.width/5);
53 this.lensGraphicsDecorator = new TransformingFlatnessGraphics(lensTransformer);
54 this.savedEdgeRenderer = vv.getRenderer().getEdgeRenderer();
55 this.reshapingEdgeRenderer = new ReshapingEdgeRenderer<V,E>();
56 this.reshapingEdgeRenderer.setEdgeArrowRenderingSupport(savedEdgeRenderer.getEdgeArrowRenderingSupport());
57
58 }
59 public void activate() {
60 lensTransformer.setDelegate(vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW));
61 if(lens == null) {
62 lens = new Lens(lensTransformer);
63 }
64 if(lensControls == null) {
65 lensControls = new LensControls(lensTransformer);
66 }
67 renderContext.setPickSupport(new ViewLensShapePickSupport<V,E>(vv));
68 lensTransformer.setDelegate(vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW));
69 vv.getRenderContext().getMultiLayerTransformer().setTransformer(Layer.VIEW, lensTransformer);
70 this.renderContext.setGraphicsContext(lensGraphicsDecorator);
71 vv.getRenderer().setEdgeRenderer(reshapingEdgeRenderer);
72 vv.prependPreRenderPaintable(lens);
73 vv.addPostRenderPaintable(lensControls);
74 vv.setGraphMouse(lensGraphMouse);
75 vv.setToolTipText(instructions);
76 vv.repaint();
77 }
78
79 public void deactivate() {
80
81
82 renderContext.setPickSupport(pickSupport);
83 vv.getRenderContext().getMultiLayerTransformer().setTransformer(Layer.VIEW, lensTransformer.getDelegate());
84 vv.removePreRenderPaintable(lens);
85 vv.removePostRenderPaintable(lensControls);
86 this.renderContext.setGraphicsContext(savedGraphicsDecorator);
87 vv.setRenderContext(renderContext);
88 vv.setToolTipText(defaultToolTipText);
89 vv.setGraphMouse(graphMouse);
90 vv.getRenderer().setEdgeRenderer(savedEdgeRenderer);
91 vv.repaint();
92 }
93 }