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.behaviour;
16:
17: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
18: import net.refractions.udig.tools.edit.EditState;
19: import net.refractions.udig.tools.edit.EditToolHandler;
20: import net.refractions.udig.tools.edit.EventType;
21: import net.refractions.udig.tools.edit.support.EditBlackboard;
22: import net.refractions.udig.tools.edit.support.Point;
23: import net.refractions.udig.tools.edit.support.PrimitiveShape;
24: import net.refractions.udig.tools.edit.support.Selection;
25:
26: /**
27: * <p>
28: * Requirements:
29: * <ul>
30: * <li>Current Geom != null</li>
31: * <li>Cursor within geom</li>
32: * <li>ctrl-alt keys are down (unless all vertices are selected)</li>
33: * </ul>
34: * </p>
35: * <p>
36: * Action:
37: * <ul>
38: * <li>Move entire Geometry</li>
39: * <li>Locks the EditTool handler until mouse is released so other behaviours won't interfere</li>
40: * </ul>
41: * </p>
42: *
43: * @author jones
44: * @since 1.1.0
45: */
46: public class MoveGeometryBehaviour extends MoveVertexBehaviour {
47:
48: @Override
49: public boolean isValid(EditToolHandler handler, MapMouseEvent e,
50: EventType eventType) {
51: boolean isLegalState = handler.getCurrentState() == EditState.MODIFYING
52: || handler.getCurrentState() == EditState.NONE
53: || handler.getCurrentState() == EditState.MOVING;
54: boolean isEventDragged = eventType == EventType.DRAGGED;
55: boolean onlyButton1IsDown = (e.buttons ^ MapMouseEvent.BUTTON1) == 0;
56: boolean currentGeomNotNull = handler.getCurrentGeom() != null;
57:
58: if (!(isLegalState && isEventDragged && onlyButton1IsDown && currentGeomNotNull))
59: return false;
60:
61: boolean altDown = e.isAltDown() && e.isControlDown()
62: || allVerticesSelectedAndWithinGeom(handler)
63: || handler.isLockOwner(this );
64:
65: return altDown
66: && (handler.isLockOwner(this ) || handler
67: .getCurrentShape().contains(
68: Point.valueOf(e.x, e.y), true));
69: }
70:
71: private boolean allVerticesSelectedAndWithinGeom(
72: EditToolHandler handler) {
73: PrimitiveShape currentShape = handler.getCurrentShape();
74: Selection selection = handler.getCurrentGeom()
75: .getEditBlackboard().getSelection();
76:
77: Point dragStarted = handler.getMouseTracker().getDragStarted();
78: if (dragStarted == null)
79: return false;
80: for (Point point : currentShape) {
81: if (!selection.contains(point))
82: return false;
83: }
84:
85: return currentShape.contains(dragStarted, true);
86:
87: }
88:
89: @Override
90: protected Selection getPointsToMove(EditToolHandler handler,
91: EditBlackboard blackboard) {
92: return handler.getCurrentGeom().createSelection();
93: }
94:
95: @Override
96: protected boolean isSnappingValid() {
97: return false;
98: }
99: }
|