1 18 package org.apache.batik.swing.gvt; 19 20 import java.awt.event.MouseEvent ; 21 import java.awt.geom.AffineTransform ; 22 23 31 public class AbstractImageZoomInteractor extends InteractorAdapter { 32 33 36 protected boolean finished = true; 37 38 41 protected int xStart; 42 43 46 protected int yStart; 47 48 51 protected int xCurrent; 52 53 56 protected int yCurrent; 57 58 61 public boolean endInteraction() { 62 return finished; 63 } 64 65 67 70 public void mousePressed(MouseEvent e) { 71 if (!finished) { 72 JGVTComponent c = (JGVTComponent)e.getSource(); 73 c.setPaintingTransform(null); 74 return; 75 } 76 77 finished = false; 78 79 xStart = e.getX(); 80 yStart = e.getY(); 81 } 82 83 86 public void mouseReleased(MouseEvent e) { 87 finished = true; 88 89 JGVTComponent c = (JGVTComponent)e.getSource(); 90 91 AffineTransform pt = c.getPaintingTransform(); 92 if (pt != null) { 93 AffineTransform rt = (AffineTransform )c.getRenderingTransform().clone(); 94 rt.preConcatenate(pt); 95 c.setRenderingTransform(rt); 96 } 97 } 98 99 101 108 public void mouseDragged(MouseEvent e) { 109 JGVTComponent c = (JGVTComponent)e.getSource(); 110 111 xCurrent = e.getX(); 112 yCurrent = e.getY(); 113 114 AffineTransform at = AffineTransform.getTranslateInstance(xStart, yStart); 115 int dy = yCurrent - yStart; 116 if (dy < 0) { 117 dy = (dy > -5) ? 15 : dy - 10; 118 } else { 119 dy = (dy < 5) ? 15 : dy + 10; 120 } 121 double s = dy / 15.0; 122 s = (s > 0) ? s : -1 / s; 123 124 at.scale(s, s); 125 at.translate(-xStart, -yStart); 126 c.setPaintingTransform(at); 127 } 128 } 129 | Popular Tags |