01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.project.ui.internal.commands.draw;
18:
19: import java.awt.Rectangle;
20: import java.awt.geom.AffineTransform;
21:
22: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
23: import net.refractions.udig.project.ui.commands.IMapTransformCommand;
24: import net.refractions.udig.project.ui.commands.IPreMapDrawCommand;
25: import net.refractions.udig.project.ui.render.displayAdapter.ViewportPane;
26:
27: import org.eclipse.core.runtime.IProgressMonitor;
28:
29: /**
30: * Sets the affine transform of the graphics to a zoom level.
31: *
32: * @author jeichar
33: * @since 0.3
34: */
35: public class ZoomDrawCommand extends AbstractDrawCommand implements
36: IMapTransformCommand, IPreMapDrawCommand {
37:
38: private AffineTransform transform;
39: private int centerx;
40: private int centery;
41:
42: /**
43: * Construct <code>TranslateCommand</code>.
44: *
45: * @param centerx the x-coord of the point the zoom centers around
46: * @param centery the y-coord of the point the zoom centers around
47: * @param zoom The amount of zoom
48: */
49: public ZoomDrawCommand(int centerx, int centery, double zoom) {
50: setZoom(centerx, centery, zoom);
51: }
52:
53: /**
54: * @see net.refractions.udig.project.internal.command.MapCommand#open()
55: */
56: public void run(IProgressMonitor monitor) throws Exception {
57: AffineTransform t = new AffineTransform(transform);
58: t.concatenate(graphics.getTransform());
59: graphics.setTransform(t);
60: }
61:
62: /**
63: * Sets the amount of zoom and where the center of the zoom will be when this command is called.
64: *
65: * @param centerx
66: * @param centery
67: * @param amount
68: */
69: public void setZoom(int centerx, int centery, double amount) {
70: this .centerx = centerx;
71: this .centery = centery;
72: transform = AffineTransform.getTranslateInstance(centerx,
73: centery);
74: transform.scale(amount, amount);
75: transform.translate(-centerx, -centery);
76: }
77:
78: /**
79: * Sets the amount the command will translate during the next paint phase
80: * <ul>
81: * <li>Sets the amount of zoom</li>
82: * <li>repaints the display if the display is an instance of viewportPane</li>
83: * </ul>
84: *
85: * @param amount the amount of zoom
86: */
87: public void setZoom(double amount) {
88: setZoom(centerx, centery, amount);
89: if (display instanceof ViewportPane)
90: ((ViewportPane) display).repaint();
91: }
92:
93: public Rectangle getValidArea() {
94: return null;
95: }
96: }
|