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.handler;
16:
17: import net.refractions.udig.project.render.displayAdapter.IMapDisplay;
18: import net.refractions.udig.project.ui.AnimationUpdater;
19: import net.refractions.udig.tool.edit.internal.Messages;
20: import net.refractions.udig.tools.edit.animation.MessageBubble;
21: import net.refractions.udig.tools.edit.preferences.PreferenceUtil;
22:
23: import org.eclipse.core.commands.AbstractHandler;
24: import org.eclipse.core.commands.ExecutionEvent;
25: import org.eclipse.core.commands.ExecutionException;
26: import org.eclipse.core.commands.IHandler;
27: import org.eclipse.swt.graphics.Point;
28: import org.eclipse.swt.widgets.Control;
29: import org.eclipse.swt.widgets.Display;
30:
31: /**
32: * Toggles Advanced Editing on and off.
33: *
34: * @author Jesse
35: * @since 1.1.0
36: */
37: public class AdvancedBehaviourCommandHandler extends AbstractHandler
38: implements IHandler {
39:
40: private IMapDisplay mapDisplay;
41: private MessageBubble messageBubble;
42:
43: public AdvancedBehaviourCommandHandler(IMapDisplay mapDisplay) {
44: this .mapDisplay = mapDisplay;
45: }
46:
47: public Object execute(ExecutionEvent event)
48: throws ExecutionException {
49: PreferenceUtil.instance().setAdvancedEditingActive(
50: !PreferenceUtil.instance().isAdvancedEditingActive());
51:
52: displayNewStatus();
53: return null;
54: }
55:
56: private void displayNewStatus() {
57: Display display = Display.getCurrent();
58: String message = null;
59: boolean active = PreferenceUtil.instance()
60: .isAdvancedEditingActive();
61: if (active) {
62: message = Messages.AdvancedBehaviourCommandHandler_enabledLabel;
63: } else {
64: message = Messages.AdvancedBehaviourCommandHandler_disabledLabel;
65: }
66:
67: if (message != null) {
68: if (messageBubble != null && messageBubble.isValid())
69: messageBubble.setValid(false);
70: Control control = (Control) mapDisplay;
71: Point mouseLocation = control.toControl(display
72: .getCursorLocation());
73: messageBubble = new MessageBubble(mouseLocation.x,
74: mouseLocation.y, message, PreferenceUtil.instance()
75: .getMessageDisplayDelay());
76: AnimationUpdater.runTimer(mapDisplay, messageBubble);
77: }
78: }
79:
80: }
|