1 18 package org.apache.batik.swing.gvt; 19 20 import java.awt.Cursor ; 21 import java.awt.event.MouseEvent ; 22 import java.awt.geom.AffineTransform ; 23 24 32 public abstract class AbstractPanInteractor extends InteractorAdapter { 33 34 37 public final static Cursor PAN_CURSOR = new Cursor (Cursor.MOVE_CURSOR); 38 39 42 protected boolean finished = true; 43 44 47 protected int xStart; 48 49 52 protected int yStart; 53 54 57 protected int xCurrent; 58 59 62 protected int yCurrent; 63 64 67 protected Cursor previousCursor; 68 69 72 public boolean endInteraction() { 73 return finished; 74 } 75 76 78 81 public void mousePressed(MouseEvent e) { 82 if (!finished) { 83 mouseExited(e); 84 return; 85 } 86 87 finished = false; 88 89 xStart = e.getX(); 90 yStart = e.getY(); 91 92 JGVTComponent c = (JGVTComponent)e.getSource(); 93 94 previousCursor = c.getCursor(); 95 c.setCursor(PAN_CURSOR); 96 } 97 98 101 public void mouseReleased(MouseEvent e) { 102 if (finished) { 103 return; 104 } 105 finished = true; 106 107 JGVTComponent c = (JGVTComponent)e.getSource(); 108 109 xCurrent = e.getX(); 110 yCurrent = e.getY(); 111 112 AffineTransform at = 113 AffineTransform.getTranslateInstance(xCurrent - xStart, 114 yCurrent - yStart); 115 AffineTransform rt = 116 (AffineTransform )c.getRenderingTransform().clone(); 117 rt.preConcatenate(at); 118 c.setRenderingTransform(rt); 119 120 if (c.getCursor() == PAN_CURSOR) { 121 c.setCursor(previousCursor); 122 } 123 } 124 125 128 public void mouseExited(MouseEvent e) { 129 finished = true; 130 131 JGVTComponent c = (JGVTComponent)e.getSource(); 132 c.setPaintingTransform(null); 133 if (c.getCursor() == PAN_CURSOR) { 134 c.setCursor(previousCursor); 135 } 136 } 137 138 140 147 public void mouseDragged(MouseEvent e) { 148 JGVTComponent c = (JGVTComponent)e.getSource(); 149 150 xCurrent = e.getX(); 151 yCurrent = e.getY(); 152 153 AffineTransform at = 154 AffineTransform.getTranslateInstance(xCurrent - xStart, 155 yCurrent - yStart); 156 c.setPaintingTransform(at); 157 } 158 } 159 | Popular Tags |