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.activator;
16:
17: import net.refractions.udig.core.IProvider;
18: import net.refractions.udig.tools.edit.Activator;
19: import net.refractions.udig.tools.edit.EditPlugin;
20: import net.refractions.udig.tools.edit.EditToolHandler;
21: import net.refractions.udig.tools.edit.commands.DrawEndPointsCommand;
22: import net.refractions.udig.tools.edit.support.PrimitiveShape;
23:
24: /**
25: * Adds a draw command to the viewport model that will draw the end points of the
26: * current shape if the current shape is a LINE
27: *
28: * @author jones
29: * @since 1.1.0
30: */
31: public class DrawEndPointsActivator implements Activator {
32:
33: private DrawEndPointsCommand drawEndPoints;
34:
35: public void activate(final EditToolHandler handler) {
36:
37: drawEndPoints = new DrawEndPointsCommand(handler
38: .getMouseTracker(), new CurrentProvider(handler));
39: handler.getDrawCommands().add(drawEndPoints);
40: handler.getContext().sendASyncCommand(drawEndPoints);
41: }
42:
43: public void deactivate(EditToolHandler handler) {
44: drawEndPoints.setValid(false);
45: drawEndPoints = null;
46: }
47:
48: public void handleActivateError(EditToolHandler handler,
49: Throwable error) {
50: EditPlugin.log("", error); //$NON-NLS-1$
51: }
52:
53: public void handleDeactivateError(EditToolHandler handler,
54: Throwable error) {
55: EditPlugin.log("", error); //$NON-NLS-1$
56: }
57:
58: private static class CurrentProvider implements
59: IProvider<PrimitiveShape> {
60: private final EditToolHandler handler;
61:
62: public CurrentProvider(final EditToolHandler handler) {
63: this .handler = handler;
64: }
65:
66: public PrimitiveShape get() {
67: return handler.getCurrentShape();
68: }
69:
70: }
71:
72: }
|