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 java.util.List;
18:
19: import net.refractions.udig.project.command.UndoableMapCommand;
20: import net.refractions.udig.project.ui.render.displayAdapter.MapMouseEvent;
21: import net.refractions.udig.tools.edit.preferences.PreferenceUtil;
22:
23: /**
24: * Behaviour is valid only when the advanced preference is set.
25: *
26: * @author Jesse
27: * @since 1.1.0
28: */
29: public class AdvancedFeaturesEventBehavior implements EventBehaviour,
30: LockingBehaviour {
31:
32: private OrderedCompositeEventBehavior composite;
33: private OrderedCompositeEventBehavior elseList;
34:
35: public AdvancedFeaturesEventBehavior(List<EventBehaviour> behaviours) {
36: composite = new OrderedCompositeEventBehavior(behaviours, false);
37: }
38:
39: public boolean isValid(EditToolHandler handler, MapMouseEvent e,
40: EventType eventType) {
41: if (!PreferenceUtil.instance().isAdvancedEditingActive()) {
42: return elseList != null
43: && elseList.isValid(handler, e, eventType);
44: }
45:
46: return composite.isValid(handler, e, eventType);
47:
48: }
49:
50: public UndoableMapCommand getCommand(EditToolHandler handler,
51: MapMouseEvent e, EventType eventType) {
52:
53: if (!PreferenceUtil.instance().isAdvancedEditingActive())
54: return elseList.getCommand(handler, e, eventType);
55: return composite.getCommand(handler, e, eventType);
56: }
57:
58: public void handleError(EditToolHandler handler, Throwable error,
59: UndoableMapCommand command) {
60: composite.handleError(handler, error, command);
61: }
62:
63: public Object getKey(EditToolHandler handler) {
64: return composite.getKey(handler);
65: }
66:
67: @Override
68: public String toString() {
69: return "Advanced Mode:" + composite.toString(); //$NON-NLS-1$
70: }
71:
72: public void setElse(List<EventBehaviour> elseList) {
73: this .elseList = new OrderedCompositeEventBehavior(elseList,
74: false);
75: }
76: }
|