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.model;
034:
035: import java.util.ArrayList;
036: import java.util.Collections;
037: import java.util.Iterator;
038: import java.util.List;
039:
040: import com.vividsolutions.jts.util.Assert;
041:
042: /**
043: * A folder containing Layers.
044: */
045: public class Category {
046: private ArrayList layerables = new ArrayList();
047: private String name;
048: private LayerManager layerManager;
049:
050: public Category() {
051: }
052:
053: public void setName(String name) {
054: this .name = name;
055: fireCategoryChanged(CategoryEventType.METADATA_CHANGED);
056: }
057:
058: public void setLayerManager(LayerManager layerManager) {
059: this .layerManager = layerManager;
060: }
061:
062: public void fireCategoryChanged(CategoryEventType type) {
063: if (getLayerManager() == null) {
064: //layerManager is null when Java2XML creates the object. [Jon Aquino]
065: return;
066: }
067:
068: getLayerManager().fireCategoryChanged(this , type);
069: }
070:
071: public LayerManager getLayerManager() {
072: return layerManager;
073: }
074:
075: /**
076: * Called by Java2XML
077: * @return Layerables with enough information to be saved to a project file
078: */
079: public List getPersistentLayerables() {
080: ArrayList persistentLayerables = new ArrayList();
081:
082: for (Iterator i = layerables.iterator(); i.hasNext();) {
083: Layerable layerable = (Layerable) i.next();
084:
085: if (layerable instanceof Layer
086: && !((Layer) layerable).hasReadableDataSource()) {
087: continue;
088: }
089:
090: persistentLayerables.add(layerable);
091: }
092:
093: return persistentLayerables;
094: }
095:
096: public List getLayerables() {
097: return Collections.unmodifiableList(layerables);
098: }
099:
100: public void remove(Layerable layerable) {
101: Assert.isTrue(contains(layerable));
102: layerables.remove(layerable);
103: }
104:
105: /**
106: * @return -1 if the category does not contain the layerable
107: */
108: public int indexOf(Layerable layerable) {
109: return layerables.indexOf(layerable);
110: }
111:
112: public boolean contains(Layerable layerable) {
113: return layerables.contains(layerable);
114: }
115:
116: /**
117: * @param index 0 to add to the top
118: */
119: public void add(int index, Layerable layerable) {
120: layerables.add(index, layerable);
121: if (getLayerManager() != null) {
122: //layerManager is null when Java2XML creates the object. [Jon Aquino]
123: getLayerManager().fireLayerChanged(layerable,
124: LayerEventType.ADDED);
125: }
126: }
127:
128: /**
129: * Called by Java2XML
130: */
131: public void addPersistentLayerable(Layerable layerable) {
132: add(layerables.size(), layerable);
133: }
134:
135: public boolean isEmpty() {
136: return layerables.isEmpty();
137: }
138:
139: public String getName() {
140: return name;
141: }
142:
143: public String toString() {
144: return getName();
145: }
146: }
|