| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
package edu.uci.ics.jung.visualization.jai; |
| 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.Rectangle2D; |
| 19 | |
|
| 20 | |
import edu.uci.ics.jung.visualization.VisualizationViewer; |
| 21 | |
import edu.uci.ics.jung.visualization.VisualizationServer.Paintable; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public abstract class AbstractPerspectiveTransformSupport<V,E> implements PerspectiveTransformSupport { |
| 34 | |
|
| 35 | |
protected VisualizationViewer<V,E> vv; |
| 36 | |
protected PerspectiveShapeTransformer perspectiveTransformer; |
| 37 | |
protected Lens lens; |
| 38 | |
protected String defaultToolTipText; |
| 39 | |
|
| 40 | |
protected static final String instructions = |
| 41 | |
"<html><center>The mouse mode button is<p>"+ |
| 42 | |
"in the lower-right corner<p>"+ |
| 43 | |
"of the scroll-pane.</center></html>"; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 0 | public AbstractPerspectiveTransformSupport(VisualizationViewer<V,E> vv) { |
| 51 | 0 | this.vv = vv; |
| 52 | 0 | this.defaultToolTipText = vv.getToolTipText(); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public void activate(boolean state) { |
| 56 | 0 | if(state) activate(); |
| 57 | 0 | else deactivate(); |
| 58 | 0 | } |
| 59 | |
|
| 60 | |
public PerspectiveShapeTransformer getPerspectiveTransformer() { |
| 61 | 0 | return perspectiveTransformer; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public void setPerspectiveTransformer( |
| 65 | |
PerspectiveShapeTransformer perspectiveTransformer) { |
| 66 | 0 | this.perspectiveTransformer = perspectiveTransformer; |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public static class Lens implements Paintable { |
| 76 | |
PerspectiveShapeTransformer perspectiveTransformer; |
| 77 | |
Rectangle2D rectangle; |
| 78 | |
|
| 79 | 0 | public Lens(PerspectiveShapeTransformer perspectiveTransformer, Dimension d) { |
| 80 | 0 | this.perspectiveTransformer = perspectiveTransformer; |
| 81 | 0 | this.rectangle = |
| 82 | |
new Rectangle2D.Float(d.width/8,d.height/8, |
| 83 | |
3*d.width/4,3*d.height/4); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public void paint(Graphics g) { |
| 91 | |
|
| 92 | 0 | Graphics2D g2d = (Graphics2D)g; |
| 93 | 0 | g.setColor(Color.decode("0xdddddd")); |
| 94 | 0 | Shape shape = perspectiveTransformer.perspectiveTransform(rectangle); |
| 95 | 0 | g2d.fill(shape); |
| 96 | 0 | g.setColor(Color.gray); |
| 97 | 0 | g2d.draw(shape); |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
public boolean useTransform() { |
| 101 | 0 | return true; |
| 102 | |
} |
| 103 | |
} |
| 104 | |
} |