| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright (c) 2005, 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 | * Created on Aug 15, 2005 | |
| 9 | */ | |
| 10 | ||
| 11 | package edu.uci.ics.jung.visualization.control; | |
| 12 | ||
| 13 | import java.awt.Color; | |
| 14 | import java.awt.Dimension; | |
| 15 | import java.awt.Graphics; | |
| 16 | import java.awt.Graphics2D; | |
| 17 | import java.awt.Shape; | |
| 18 | import java.awt.geom.AffineTransform; | |
| 19 | ||
| 20 | import edu.uci.ics.jung.visualization.DefaultVisualizationModel; | |
| 21 | import edu.uci.ics.jung.visualization.Layout; | |
| 22 | import edu.uci.ics.jung.visualization.Renderer; | |
| 23 | import edu.uci.ics.jung.visualization.ShapePickSupport; | |
| 24 | import edu.uci.ics.jung.visualization.VisualizationModel; | |
| 25 | import edu.uci.ics.jung.visualization.VisualizationViewer; | |
| 26 | import edu.uci.ics.jung.visualization.transform.MutableAffineTransformer; | |
| 27 | import edu.uci.ics.jung.visualization.transform.shape.ShapeTransformer; | |
| 28 | ||
| 29 | /** | |
| 30 | * A VisualizationViewer that can act as a satellite view for another | |
| 31 | * (master) VisualizationViewer. In this view, the full graph is always visible | |
| 32 | * and all mouse actions affect the graph in the master view. | |
| 33 | * | |
| 34 | * A rectangular shape in the satellite view shows the visible bounds of | |
| 35 | * the master view. | |
| 36 | * | |
| 37 | * @author Tom Nelson - RABA Technologies | |
| 38 | * | |
| 39 | * | |
| 40 | */ | |
| 41 | public class SatelliteVisualizationViewer extends VisualizationViewer { | |
| 42 | ||
| 43 | /** | |
| 44 | * the master VisualizationViewer that this is a satellite view for | |
| 45 | */ | |
| 46 | protected VisualizationViewer master; | |
| 47 | ||
| 48 | /** | |
| 49 | * @param layout | |
| 50 | * @param renderer | |
| 51 | */ | |
| 52 | public SatelliteVisualizationViewer(VisualizationViewer master, Layout layout, | |
| 53 | Renderer renderer) { | |
| 54 | 0 | this(master, new DefaultVisualizationModel(layout), renderer); |
| 55 | 0 | } |
| 56 | ||
| 57 | /** | |
| 58 | * @param layout | |
| 59 | * @param renderer | |
| 60 | * @param preferredSize | |
| 61 | */ | |
| 62 | public SatelliteVisualizationViewer(VisualizationViewer master, Layout layout, Renderer renderer, | |
| 63 | Dimension preferredSize) { | |
| 64 | 0 | this(master, new DefaultVisualizationModel(layout, preferredSize), renderer, preferredSize); |
| 65 | 0 | } |
| 66 | ||
| 67 | /** | |
| 68 | * @param model | |
| 69 | * @param renderer | |
| 70 | */ | |
| 71 | public SatelliteVisualizationViewer(VisualizationViewer master, VisualizationModel model, | |
| 72 | Renderer renderer) { | |
| 73 | 0 | this(master, model, renderer, new Dimension(300,300)); |
| 74 | 0 | } |
| 75 | ||
| 76 | /** | |
| 77 | * @param master the master view | |
| 78 | * @param model | |
| 79 | * @param renderer | |
| 80 | * @param preferredSize | |
| 81 | */ | |
| 82 | public SatelliteVisualizationViewer(VisualizationViewer master, VisualizationModel model, | |
| 83 | Renderer renderer, Dimension preferredSize) { | |
| 84 | 0 | super(model, renderer, preferredSize); |
| 85 | 0 | this.master = master; |
| 86 | ||
| 87 | // create a graph mouse with custom plugins to affect the master view | |
| 88 | 0 | ModalGraphMouse gm = new ModalSatelliteGraphMouse(); |
| 89 | 0 | setGraphMouse(gm); |
| 90 | ||
| 91 | // this adds the Lens to the satellite view | |
| 92 | 0 | addPreRenderPaintable(new ViewLens(this, master)); |
| 93 | ||
| 94 | // get a copy of the current layout transform | |
| 95 | // it may have been scaled to fit the graph | |
| 96 | 0 | AffineTransform modelLayoutTransform = |
| 97 | new AffineTransform(master.getLayoutTransformer().getTransform()); | |
| 98 | ||
| 99 | // I want no layout transformations in the satellite view | |
| 100 | // this resets the auto-scaling that occurs in the super constructor | |
| 101 | 0 | setLayoutTransformer(new MutableAffineTransformer(modelLayoutTransform)); |
| 102 | ||
| 103 | // make sure the satellite listens for changes in the master | |
| 104 | 0 | master.addChangeListener(this); |
| 105 | ||
| 106 | // share the picked state of the master | |
| 107 | 0 | setPickedState(master.getPickedState()); |
| 108 | 0 | setPickSupport(new ShapePickSupport()); |
| 109 | 0 | } |
| 110 | ||
| 111 | /** | |
| 112 | * @return Returns the master. | |
| 113 | */ | |
| 114 | public VisualizationViewer getMaster() { | |
| 115 | 0 | return master; |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * A four-sided shape that represents the visible part of the | |
| 120 | * master view and is drawn in the satellite view | |
| 121 | * | |
| 122 | * @author Tom Nelson - RABA Technologies | |
| 123 | * | |
| 124 | * | |
| 125 | */ | |
| 126 | static class ViewLens implements Paintable { | |
| 127 | ||
| 128 | VisualizationViewer master; | |
| 129 | VisualizationViewer vv; | |
| 130 | ||
| 131 | public ViewLens(VisualizationViewer vv, VisualizationViewer master) { | |
| 132 | this.vv = vv; | |
| 133 | this.master = master; | |
| 134 | } | |
| 135 | public void paint(Graphics g) { | |
| 136 | ShapeTransformer masterViewTransformer = master.getViewTransformer(); | |
| 137 | ShapeTransformer masterLayoutTransformer = master.getLayoutTransformer(); | |
| 138 | ShapeTransformer vvLayoutTransformer = vv.getLayoutTransformer(); | |
| 139 | ||
| 140 | Shape lens = master.getBounds(); | |
| 141 | lens = masterViewTransformer.inverseTransform(lens); | |
| 142 | lens = masterLayoutTransformer.inverseTransform(lens); | |
| 143 | lens = vvLayoutTransformer.transform(lens); | |
| 144 | Graphics2D g2d = (Graphics2D)g; | |
| 145 | Color old = g.getColor(); | |
| 146 | Color lensColor = master.getBackground(); | |
| 147 | vv.setBackground(lensColor.darker()); | |
| 148 | g.setColor(lensColor); | |
| 149 | g2d.fill(lens); | |
| 150 | g.setColor(Color.gray); | |
| 151 | g2d.draw(lens); | |
| 152 | g.setColor(old); | |
| 153 | } | |
| 154 | ||
| 155 | public boolean useTransform() { | |
| 156 | return true; | |
| 157 | } | |
| 158 | } | |
| 159 | ||
| 160 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |