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: package com.vividsolutions.jump.workbench.ui;
033:
034: import java.util.ArrayList;
035: import java.util.Iterator;
036:
037: import javax.swing.event.TreeModelEvent;
038: import javax.swing.event.TreeModelListener;
039: import javax.swing.tree.TreeModel;
040: import javax.swing.tree.TreePath;
041:
042: public class FirableTreeModelWrapper implements TreeModel {
043: private TreeModel model;
044: private ArrayList listeners = new ArrayList();
045:
046: public FirableTreeModelWrapper(TreeModel model) {
047: this .model = model;
048: }
049:
050: public Object getRoot() {
051: return model.getRoot();
052: }
053:
054: public Object getChild(Object parent, int index) {
055: return model.getChild(parent, index);
056: }
057:
058: public int getChildCount(Object parent) {
059: return model.getChildCount(parent);
060: }
061:
062: public boolean isLeaf(Object node) {
063: return model.isLeaf(node);
064: }
065:
066: public void valueForPathChanged(TreePath path, Object newValue) {
067: model.valueForPathChanged(path, newValue);
068: }
069:
070: public int getIndexOfChild(Object parent, Object child) {
071: return model.getIndexOfChild(parent, child);
072: }
073:
074: public void addTreeModelListener(TreeModelListener l) {
075: listeners.add(l);
076: model.addTreeModelListener(l);
077: }
078:
079: public void removeTreeModelListener(TreeModelListener l) {
080: listeners.remove(l);
081: model.removeTreeModelListener(l);
082: }
083:
084: public void fireTreeNodesChanged(TreeModelEvent e) {
085: starting();
086:
087: try {
088: for (Iterator i = listeners.iterator(); i.hasNext();) {
089: TreeModelListener l = (TreeModelListener) i.next();
090: l.treeNodesChanged(e);
091: }
092: } finally {
093: finishing();
094: }
095: }
096:
097: public void fireTreeNodesInserted(TreeModelEvent e) {
098: starting();
099:
100: try {
101: for (Iterator i = listeners.iterator(); i.hasNext();) {
102: TreeModelListener l = (TreeModelListener) i.next();
103: l.treeNodesInserted(e);
104: }
105: } finally {
106: finishing();
107: }
108: }
109:
110: public void fireTreeNodesRemoved(TreeModelEvent e) {
111: starting();
112:
113: try {
114: for (Iterator i = listeners.iterator(); i.hasNext();) {
115: TreeModelListener l = (TreeModelListener) i.next();
116: l.treeNodesRemoved(e);
117: }
118: } finally {
119: finishing();
120: }
121: }
122:
123: public void fireTreeStructureChanged(TreeModelEvent e) {
124: starting();
125:
126: try {
127: for (Iterator i = listeners.iterator(); i.hasNext();) {
128: TreeModelListener l = (TreeModelListener) i.next();
129: l.treeStructureChanged(e);
130: }
131: } finally {
132: finishing();
133: }
134: }
135:
136: protected void finishing() {
137: }
138:
139: protected void starting() {
140: }
141:
142: public TreeModel getModel() {
143: return model;
144: }
145: }
|