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.util.ArrayList;
037: import java.util.Arrays;
038: import java.util.Iterator;
039:
040: import javax.swing.Icon;
041:
042: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
043:
044: public abstract class CompositeTool implements CursorTool {
045: protected ArrayList cursorTools = new ArrayList();
046:
047: public CompositeTool(CursorTool[] cursorTools) {
048: this .cursorTools = new ArrayList(Arrays.asList(cursorTools));
049: }
050:
051: public void deactivate() {
052: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
053: CursorTool tool = (CursorTool) i.next();
054: tool.deactivate();
055: }
056: }
057:
058: public Cursor getCursor() {
059: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
060: CursorTool cursorTool = (CursorTool) i.next();
061:
062: //Prefer cursors other than the default cursor. [Jon Aquino]
063: if (cursorTool.getCursor() != Cursor.getDefaultCursor()) {
064: return cursorTool.getCursor();
065: }
066: }
067:
068: return Cursor.getDefaultCursor();
069: }
070:
071: public boolean isRightMouseButtonUsed() {
072: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
073: CursorTool cursorTool = (CursorTool) i.next();
074:
075: if (cursorTool.isRightMouseButtonUsed()) {
076: return true;
077: }
078: }
079:
080: return false;
081: }
082:
083: protected CursorTool firstCursorTool() {
084: return (CursorTool) cursorTools.get(0);
085: }
086:
087: private LayerViewPanel panel = null;
088:
089: public void activate(LayerViewPanel layerViewPanel) {
090: this .panel = layerViewPanel;
091: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
092: CursorTool tool = (CursorTool) i.next();
093: tool.activate(layerViewPanel);
094: }
095: }
096:
097: public CompositeTool add(CursorTool tool) {
098: cursorTools.add(tool);
099: return this ;
100: }
101:
102: public void cancelGesture() {
103: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
104: CursorTool tool = (CursorTool) i.next();
105: tool.cancelGesture();
106: }
107: }
108:
109: public Icon getIcon() {
110: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
111: CursorTool tool = (CursorTool) i.next();
112:
113: if (tool.getIcon() != null) {
114: return tool.getIcon();
115: }
116: }
117:
118: return null;
119: }
120:
121: protected String getName(String delimiter) {
122: String name = "";
123:
124: for (int i = 0; i < cursorTools.size(); i++) {
125: if (i > 0) {
126: name += (" " + delimiter + " ");
127: }
128:
129: name += ((CursorTool) cursorTools.get(i)).getName();
130: }
131:
132: return name;
133: }
134:
135: public boolean isGestureInProgress() {
136: for (Iterator i = cursorTools.iterator(); i.hasNext();) {
137: CursorTool tool = (CursorTool) i.next();
138:
139: if (tool.isGestureInProgress()) {
140: return true;
141: }
142: }
143:
144: return false;
145: }
146:
147: public LayerViewPanel getPanel() {
148: return panel;
149: }
150:
151: }
|