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.command.UndoableMapCommand;
18: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
19: import net.refractions.udig.tools.edit.EditState;
20: import net.refractions.udig.tools.edit.EditToolHandler;
21: import net.refractions.udig.tools.edit.EventBehaviour;
22: import net.refractions.udig.tools.edit.EventType;
23: import net.refractions.udig.tools.edit.commands.SelectHoleCommand;
24: import net.refractions.udig.tools.edit.support.ShapeType;
25:
26: /**
27: * <p>Requirements:
28: * <ul>
29: * <li>event type == RELEASE</li>
30: * <li>edit state == MODIFYING </li>
31: * <li>no modifiers down</li>
32: * <li>button 1 released</li>
33: * <li>no buttons down</li>
34: * <li>current shape and geom are set and shape is the shell of the geom</li>
35: * </ul>
36: * </p>
37: * <p>Action:
38: * <ul>
39: * <li>Selects the clicked hole or nothing</li>
40: * </ul>
41: * </p>
42: * @author jones
43: * @since 1.1.0
44: */
45: public class SelectHoleBehaviour implements EventBehaviour {
46:
47: public boolean isValid(EditToolHandler handler, MapMouseEvent e,
48: EventType eventType) {
49: boolean legalState = handler.getCurrentState() == EditState.MODIFYING;
50: boolean legalEventType = eventType == EventType.RELEASED;
51: boolean shapeAndGeomNotNull = handler.getCurrentShape() != null;
52: boolean button1Released = e.button == MapMouseEvent.BUTTON1;
53: if (!legalState || !legalEventType || !shapeAndGeomNotNull
54: || !button1Released)
55: return false;
56: if (!shapeAndGeomNotNull)
57: return false;
58: boolean selectedShapeIsPolygon = handler.getCurrentGeom()
59: .getShapeType() == ShapeType.POLYGON
60: || handler.getCurrentGeom().getShapeType() == ShapeType.UNKNOWN;
61:
62: return !e.buttonsDown() && !e.modifiersDown()
63: && selectedShapeIsPolygon;
64: }
65:
66: public UndoableMapCommand getCommand(EditToolHandler handler,
67: MapMouseEvent e, EventType eventType) {
68: if (!isValid(handler, e, eventType)) {
69: throw new IllegalArgumentException(
70: "Current state is not legal. This command" + //$NON-NLS-1$
71: "should not be ran"); //$NON-NLS-1$
72: }
73: return new SelectHoleCommand(handler, e);
74: }
75:
76: public void handleError(EditToolHandler handler, Throwable error,
77: UndoableMapCommand command) {
78: }
79:
80: }
|