001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.cursortool;
034:
035: import java.awt.Cursor;
036: import java.awt.event.MouseEvent;
037:
038: import javax.swing.Icon;
039:
040: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
041:
042: /**
043: * Enables the behaviour of a CursorTool instance to be overridden.
044: */
045: public abstract class DelegatingTool implements CursorTool {
046: private CursorTool delegate = new DummyTool();
047: private boolean active = false;
048: private LayerViewPanel layerViewPanel;
049:
050: public CursorTool getDelegate() {
051: return delegate;
052: }
053:
054: public DelegatingTool(CursorTool cursorTool) {
055: setDelegate(cursorTool);
056: }
057:
058: public void setDelegate(CursorTool delegate) {
059: if (this .delegate == delegate) {
060: //Don't activate/deactivate. [Jon Aquino]
061: return;
062: }
063:
064: // if (active) {
065: // this.delegate.deactivate();
066: // }
067:
068: this .delegate = delegate;
069:
070: if (active) {
071: this .delegate.activate(layerViewPanel);
072: }
073: }
074:
075: public String getName() {
076: return delegate.getName();
077: }
078:
079: public Icon getIcon() {
080: return delegate.getIcon();
081: }
082:
083: public boolean isGestureInProgress() {
084: return delegate.isGestureInProgress();
085: }
086:
087: public void cancelGesture() {
088: delegate.cancelGesture();
089: }
090:
091: public void mousePressed(MouseEvent e) {
092: delegate.mousePressed(e);
093: }
094:
095: public void mouseClicked(MouseEvent e) {
096: delegate.mouseClicked(e);
097: }
098:
099: public void activate(LayerViewPanel layerViewPanel) {
100: this .layerViewPanel = layerViewPanel;
101: delegate.activate(layerViewPanel);
102: active = true;
103: }
104:
105: public Cursor getCursor() {
106: return delegate.getCursor();
107: }
108:
109: public void deactivate() {
110: delegate.deactivate();
111: active = false;
112: }
113:
114: public void mouseReleased(MouseEvent e) {
115: delegate.mouseReleased(e);
116: }
117:
118: public void mouseEntered(MouseEvent e) {
119: delegate.mouseEntered(e);
120: }
121:
122: public void mouseExited(MouseEvent e) {
123: delegate.mouseExited(e);
124: }
125:
126: public void mouseDragged(MouseEvent e) {
127: delegate.mouseDragged(e);
128: }
129:
130: public void mouseMoved(MouseEvent e) {
131: delegate.mouseMoved(e);
132: }
133:
134: public boolean isRightMouseButtonUsed() {
135: return delegate.isRightMouseButtonUsed();
136: }
137: }
|