01: /*
02: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
03: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
04: * under the terms of the GNU Lesser General Public License as published by the Free Software
05: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
06: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
07: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
08: */
09: package net.refractions.udig.project.internal.command.navigation;
10:
11: import net.refractions.udig.project.command.MapCommand;
12: import net.refractions.udig.project.command.NavCommand;
13: import net.refractions.udig.project.internal.Messages;
14:
15: import org.eclipse.core.runtime.IProgressMonitor;
16:
17: /**
18: * A command that pans the viewport. The command can be defined in terms of pixels on the screen or
19: * in terms of world units.
20: *
21: * @author jeichar
22: * @since 0.3
23: */
24: public class PanCommand extends AbstractNavCommand implements
25: NavCommand {
26:
27: double worldx;
28: double worldy;
29:
30: int pixelx;
31: int pixely;
32:
33: boolean inPixel;
34:
35: /**
36: * Creates a new instance of PanCommand
37: *
38: * @param pixelx The amount to pan in the x direction
39: * @param pixely The amount to pan in the y direction
40: */
41: public PanCommand(int pixelx, int pixely) {
42: this .pixelx = pixelx;
43: this .pixely = pixely;
44: inPixel = true;
45: }
46:
47: /**
48: * Creates a new instance of PanCommand
49: *
50: * @param worldx The amount to pan in the x direction
51: * @param worldy The amount to pan in the y direction
52: */
53: public PanCommand(double worldx, double worldy) {
54: this .worldx = worldx;
55: this .worldy = worldy;
56: inPixel = false;
57: }
58:
59: /**
60: * @see net.refractions.udig.project.internal.command.navigation.AbstractNavCommand#runImpl()
61: */
62: protected void runImpl(IProgressMonitor monitor) throws Exception {
63: if (inPixel)
64: model.panUsingScreenCoords(pixelx, pixely);
65: else
66: model.panUsingWorldCoords(worldx, worldy);
67: }
68:
69: /**
70: * @see net.refractions.udig.project.internal.command.MapCommand#copy()
71: */
72: public MapCommand copy() {
73: if (inPixel)
74: return new PanCommand(pixelx, pixely);
75:
76: return new PanCommand(worldx, worldy);
77: }
78:
79: /**
80: * @see net.refractions.udig.project.command.MapCommand#getName()
81: */
82: public String getName() {
83: return Messages.PanCommand_pan;
84: }
85:
86: }
|