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.geom.GeneralPath;
18:
19: import net.refractions.udig.project.command.AbstractCommand;
20: import net.refractions.udig.project.command.PostDeterminedEffectCommand;
21: import net.refractions.udig.project.command.UndoableMapCommand;
22: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
23: import net.refractions.udig.tools.edit.EditToolHandler;
24: import net.refractions.udig.tools.edit.support.PrimitiveShape;
25: import net.refractions.udig.tools.edit.support.PrimitiveShapeIterator;
26:
27: import org.eclipse.core.runtime.IProgressMonitor;
28:
29: /**
30: * Selects the hole (sets the handler's current shape) that the mouse is over or
31: * nothing if mouse is not over a hole.
32: *
33: * @author jones
34: * @since 1.1.0
35: */
36: public class SelectHoleCommand extends AbstractCommand implements
37: UndoableMapCommand, PostDeterminedEffectCommand {
38:
39: private MapMouseEvent event;
40: private EditToolHandler handler;
41: private PrimitiveShape currentShape;
42:
43: public SelectHoleCommand(EditToolHandler handler, MapMouseEvent e) {
44: this .handler = handler;
45: this .event = e;
46: }
47:
48: public String getName() {
49: return "Select Hole"; //$NON-NLS-1$
50: }
51:
52: public void run(IProgressMonitor monitor) throws Exception {
53: execute(monitor);
54: }
55:
56: public void rollback(IProgressMonitor monitor) throws Exception {
57: handler.setCurrentShape(currentShape);
58: }
59:
60: public boolean execute(IProgressMonitor monitor) throws Exception {
61: this .currentShape = handler.getCurrentShape();
62:
63: if (currentShape == null)
64: return false;
65:
66: for (PrimitiveShape shape : currentShape.getEditGeom()) {
67: if (shape == currentShape
68: || currentShape.getEditGeom().getShell() == shape)
69: continue;
70:
71: GeneralPath path = new GeneralPath();
72: path.append(PrimitiveShapeIterator.getPathIterator(shape),
73: false);
74:
75: if (path.contains(event.x, event.y)) {
76: handler.setCurrentShape(shape);
77: break;
78: }
79: }
80: return true;
81: }
82:
83: }
|