001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.internal.commands.draw;
018:
019: import java.awt.Point;
020: import java.awt.Rectangle;
021:
022: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
023: import net.refractions.udig.project.ui.commands.IMapTransformCommand;
024: import net.refractions.udig.project.ui.commands.IPreMapDrawCommand;
025:
026: import org.eclipse.core.runtime.IProgressMonitor;
027:
028: /**
029: * Sets the ViewportGraphics object translate its 0,0 coordinate by -x,-y. IE. shapes are drawn down
030: * and right if x,y are both positive.
031: *
032: * @author jeichar
033: * @since 0.3
034: */
035: public class TranslateCommand extends AbstractDrawCommand implements
036: IMapTransformCommand, IPreMapDrawCommand {
037:
038: private Point offset;
039:
040: /**
041: * Construct <code>TranslateCommand</code>.
042: *
043: * @param offset The amount of offset
044: */
045: public TranslateCommand(Point offset) {
046: this .offset = offset;
047: }
048:
049: /**
050: * Construct <code>TranslateCommand</code>.
051: *
052: * @param x The amount of offset in the x-direction
053: * @param y The amount of offset in the y-direction
054: */
055: public TranslateCommand(int x, int y) {
056: this .offset = new Point(x, y);
057: }
058:
059: /**
060: * @see net.refractions.udig.project.internal.command.MapCommand#open()
061: */
062: public void run(IProgressMonitor monitor) throws Exception {
063: if (offset.x > 0) {
064: graphics.clearRect(0, 0, offset.x, display.getHeight());
065: } else {
066: graphics.clearRect(display.getWidth(), 0, -offset.x,
067: display.getHeight());
068: }
069: if (offset.y > 0) {
070: graphics.clearRect(0, 0, display.getWidth(), offset.y);
071: } else {
072: graphics.clearRect(0, display.getHeight(), display
073: .getWidth(), -offset.y);
074: }
075: graphics.translate(offset);
076: }
077:
078: /**
079: * Sets the amount the command will translate during the next paint phase
080: *
081: * @param x x-translation
082: * @param y y-translation
083: */
084: public void setTranslation(int x, int y) {
085: offset.x = x;
086: offset.y = y;
087: }
088:
089: /**
090: * Sets the amount the command will translate during the next paint phase
091: *
092: * @param offset The amount of translation
093: */
094: public void setTranslation(Point offset) {
095: this .offset = offset;
096: }
097:
098: public Rectangle getValidArea() {
099: return null;
100: }
101:
102: }
|