01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.ui.commands;
16:
17: import java.awt.Rectangle;
18: import java.awt.geom.AffineTransform;
19:
20: import org.eclipse.core.runtime.IProgressMonitor;
21:
22: /**
23: * Tranforms the Viewport's graphics current transform.
24: *
25: * @author Jesse
26: * @since 1.1.0
27: */
28: public class TransformDrawCommand extends AbstractDrawCommand implements
29: IMapTransformCommand, IPreMapDrawCommand {
30:
31: private double scaleFactorY = 1;
32: private double scaleFactorX = 1;
33: private int translateY;
34: private int translateX;
35: private double rotation;
36:
37: public Rectangle getValidArea() {
38: return null;
39: }
40:
41: public synchronized void run(IProgressMonitor monitor)
42: throws Exception {
43: AffineTransform t = new AffineTransform();
44: t.translate((double) display.getWidth() / (double) 2,
45: (double) display.getHeight() / (double) 2);
46: t.rotate(rotation);
47: t.scale(scaleFactorX, scaleFactorY);
48: t.translate((double) -display.getWidth() / (double) 2,
49: (double) -display.getHeight() / (double) 2);
50: t.translate(translateX, translateY);
51: t.concatenate(graphics.getTransform());
52: graphics.setTransform(t);
53: }
54:
55: public synchronized void zoom(double scaleFactorX,
56: double scaleFactorY) {
57: this .scaleFactorX = scaleFactorX;
58: this .scaleFactorY = scaleFactorY;
59: }
60:
61: public synchronized void pan(int x, int y) {
62: this .translateX = x;
63: this .translateY = y;
64: }
65:
66: public synchronized void rotate(double theta) {
67: this .rotation = theta;
68: }
69:
70: public synchronized AffineTransform getTransform() {
71: AffineTransform t = new AffineTransform();
72: t.translate((double) display.getWidth() / (double) 2,
73: (double) display.getHeight() / (double) 2);
74: t.rotate(rotation);
75: t.scale(scaleFactorX, scaleFactorY);
76: t.translate((double) -display.getWidth() / (double) 2,
77: (double) -display.getHeight() / (double) 2);
78: t.translate(translateX, translateY);
79: return t;
80: }
81:
82: }
|