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;
16:
17: import net.refractions.udig.project.command.UndoableMapCommand;
18: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
19:
20: /**
21: * This is a Stategy object for the (@link net.refractions.udig.tools.edit.latest.EditToolHandler}
22: * behaviour. Each EventBehavior is valid in a particular context and will be run by the (@link
23: * net.refractions.udig.tools.edit.latest.EditToolHandler} if the isValid method returns true.
24: * <p>
25: * An example is a SelectGeometryBehaviour.
26: * <p>
27: * Context: EditState is MODIFYING, EventType is RELEASED, mouse button is button 1 and no keys are
28: * pressed.
29: * </p>
30: * <p>
31: * Action: If mouse is over a feature add the Geometry to the EditBlackBoard and set the
32: * EditToolHandler's current Geometry and Shape.
33: * </p>
34: * <p>
35: * Error handling: If exception occurs reset the EditBlackBoard and current Geometry and shape
36: * </p>
37: * </p>
38: *
39: * @author jones
40: * @since 1.1.0
41: */
42: public interface EventBehaviour {
43:
44: /**
45: * Called to determine whether this EventBehaviour is applicable and should be run.
46: *
47: * @param handler handler that calls this Behaviour
48: * @param e mouse event that just occurred.
49: * @param eventType the type of event that just occurred
50: * @return true if this mode is applicable and should be run.
51: */
52: public boolean isValid(EditToolHandler handler, MapMouseEvent e,
53: EventType eventType);
54:
55: /**
56: * The action to be performed by this EventBehaviour. This action takes place in the event thread so it must
57: * perform VERY quickly.
58: *
59: * @param handler handler that calls this Behaviour
60: * @param e Event that occurred.
61: * @param eventType The type of event that has occurred
62: * @return Command that will be executed in order to perform the behaviour
63: */
64: public UndoableMapCommand getCommand(EditToolHandler handler,
65: MapMouseEvent e, EventType eventType);
66:
67: /**
68: * This method is called if an exception occurs during the execution of the run method.
69: * <p>
70: * This method should
71: * <ol>
72: * <li>Rollback the changes made during the run method</li>
73: * <li>Log the error in the plugin's log</li>
74: * </ol>
75: *
76: * @param handler handler that calls this Behaviour
77: * @param error Error that occurred
78: * @param command Command retrieved from getCommandMethod. May be null if exception occurred while
79: * executing getCommand();
80: */
81: public void handleError(EditToolHandler handler, Throwable error,
82: UndoableMapCommand command);
83: }
|