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.tools.edit.commands;
16:
17: import java.awt.Rectangle;
18:
19: import net.refractions.udig.core.IProvider;
20: import net.refractions.udig.project.ui.commands.AbstractDrawCommand;
21: import net.refractions.udig.tools.edit.preferences.PreferenceUtil;
22: import net.refractions.udig.tools.edit.support.Point;
23:
24: import org.eclipse.core.runtime.IProgressMonitor;
25:
26: public class DrawSnapAreaCommand extends AbstractDrawCommand {
27:
28: /** DrawSnapArea behaviour field */
29: private IProvider<Point> tracker;
30: private Rectangle lastArea;
31:
32: public DrawSnapAreaCommand(IProvider<Point> tracker) {
33: this .tracker = tracker;
34: }
35:
36: public void run(IProgressMonitor monitor) throws Exception {
37: graphics.setColor(PreferenceUtil.instance().getFeedbackColor());
38: int radius = PreferenceUtil.instance().getSnappingRadius();
39: Point point = tracker.get();
40: int y = point.getY() - radius;
41: int x = point.getX() - radius;
42: graphics.drawOval(x, y, radius * 2, radius * 2);
43: lastArea = new Rectangle(x - 4, y - 4, radius * 2 + 8,
44: radius * 2 + 8);
45: }
46:
47: public Rectangle getValidArea() {
48: int radius = PreferenceUtil.instance().getSnappingRadius();
49: Point point = tracker.get();
50: int y = point.getY() - radius;
51: int x = point.getX() - radius;
52: Rectangle rectangle = new Rectangle(x - 4, y - 4,
53: radius * 2 + 8, radius * 2 + 8);
54: if (lastArea != null)
55: return rectangle.union(lastArea);
56: else
57: return rectangle;
58:
59: }
60:
61: }
|