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.awt.Color;
036:
037: import com.vividsolutions.jump.feature.AttributeType;
038: import com.vividsolutions.jump.feature.FeatureCollection;
039: import com.vividsolutions.jump.feature.FeatureDataset;
040: import com.vividsolutions.jump.feature.FeatureSchema;
041:
042: /**
043: * A "system-maintained layer" has a fixed set of styles and is identified by
044: * name. For example, the vector layer has blue features with arrowheads and is
045: * named "Warping Vectors". A SystemLayerFinder class will find a particular
046: * system-maintained layer, and can create it if necessary.
047: */
048: public abstract class SystemLayerFinder {
049: private String layerName;
050: private LayerManagerProxy layerManagerProxy;
051:
052: public SystemLayerFinder(String layerName,
053: LayerManagerProxy layerManagerProxy) {
054: this .layerManagerProxy = layerManagerProxy;
055: this .layerName = layerName;
056: }
057:
058: public String getLayerName() {
059: return layerName;
060: }
061:
062: public static class NonSavePromptingLayer extends Layer {
063: public NonSavePromptingLayer() {
064: super ();
065: }
066:
067: public NonSavePromptingLayer(String name, Color fillColor,
068: FeatureCollection featureCollection,
069: LayerManager layerManager) {
070: super (name, fillColor, featureCollection, layerManager);
071: }
072:
073: public boolean isFeatureCollectionModified() {
074: //Prevent save prompt. [Jon Aquino]
075: return false;
076: }
077: }
078:
079: public Layer createLayer() {
080: FeatureSchema schema = new FeatureSchema();
081: schema.addAttribute("GEOMETRY", AttributeType.GEOMETRY);
082:
083: FeatureDataset dataset = new FeatureDataset(schema);
084: Layer layer = new NonSavePromptingLayer(layerName, Color.blue,
085: dataset, layerManagerProxy.getLayerManager());
086: boolean firingEvents = layerManagerProxy.getLayerManager()
087: .isFiringEvents();
088: //Can't fire events because this Layerable hasn't been added to the
089: //LayerManager yet. [Jon Aquino]
090: layerManagerProxy.getLayerManager().setFiringEvents(false);
091:
092: try {
093: applyStyles(layer);
094: } finally {
095: layerManagerProxy.getLayerManager().setFiringEvents(
096: firingEvents);
097: }
098:
099: layerManagerProxy.getLayerManager().addLayer(
100: StandardCategoryNames.SYSTEM, layer);
101:
102: return layer;
103: }
104:
105: /**
106: * @return the layer, or null if there is no layer
107: */
108: public Layer getLayer() {
109: Layer layer = layerManagerProxy.getLayerManager().getLayer(
110: layerName);
111:
112: if (layer == null) {
113: // Don't automatically create the layer. For example, #getLayer may
114: // be called by an EnableCheck; we wouldn't want the layer to get
115: // created in this case. [Jon Aquino]
116: return null;
117: }
118:
119: return layer;
120: }
121:
122: protected abstract void applyStyles(Layer layer);
123: }
|