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.model;
033:
034: import com.vividsolutions.jts.util.Assert;
035: import com.vividsolutions.jump.util.LangUtil;
036:
037: /**
038: * Default implementation of the Layerable interface.
039: *
040: * @see Layerable
041: */
042: public abstract class AbstractLayerable implements Layerable {
043: private LayerManager layerManager;
044:
045: private String name;
046:
047: private boolean visible = true;
048:
049: private boolean scaleDependentRenderingEnabled = false;
050:
051: // When working with scale, the max is less than the min. [Jon Aquino
052: // 2005-03-01]
053: private Double minScale = null;
054:
055: private Double maxScale = null;
056:
057: /**
058: * Called by Java2XML
059: */
060: public AbstractLayerable() {
061: }
062:
063: public AbstractLayerable(String name, LayerManager layerManager) {
064: Assert.isTrue(name != null);
065: Assert.isTrue(layerManager != null);
066: setLayerManager(layerManager);
067:
068: //Can't fire events because this Layerable hasn't been added to the
069: //LayerManager yet. [Jon Aquino]
070: boolean firingEvents = layerManager.isFiringEvents();
071: layerManager.setFiringEvents(false);
072:
073: try {
074: setName(layerManager.uniqueLayerName(name));
075: } finally {
076: layerManager.setFiringEvents(firingEvents);
077: }
078: }
079:
080: public void setLayerManager(LayerManager layerManager) {
081: this .layerManager = layerManager;
082: }
083:
084: public LayerManager getLayerManager() {
085: return layerManager;
086: }
087:
088: public void fireLayerChanged(LayerEventType type) {
089: if (getLayerManager() == null) {
090: //layerManager is null when Java2XML creates the object. [Jon
091: // Aquino]
092: return;
093: }
094:
095: getLayerManager().fireLayerChanged(this , type);
096: }
097:
098: /**
099: * The only time #fireAppearanceChanged must be called is when a party
100: * modifies an attribute of one of the Styles, because Styles don't notify
101: * their layer when they change. But if a party adds or removes a feature,
102: * or applies an EditTransaction to a feature, #fireAppearanceChanged will
103: * be called automatically. This event will be ignored if
104: * LayerManager#isFiringEvents is false
105: */
106: public void fireAppearanceChanged() {
107: fireLayerChanged(LayerEventType.APPEARANCE_CHANGED);
108: }
109:
110: public String getName() {
111: return name;
112: }
113:
114: public void setName(String name) {
115: this .name = name;
116: fireLayerChanged(LayerEventType.METADATA_CHANGED);
117: }
118:
119: public void setVisible(boolean visible) {
120: if (this .visible == visible) {
121: return;
122: }
123:
124: this .visible = visible;
125: fireLayerChanged(LayerEventType.VISIBILITY_CHANGED);
126: }
127:
128: //<<TODO:REFACTORING>> Move Visible to LayerSelection, since it should be a
129: // property
130: //of the view, not the model [Jon Aquino]
131: public boolean isVisible() {
132: return visible;
133: }
134:
135: public String toString() {
136: return getName();
137: }
138:
139: public Double getMaxScale() {
140: return maxScale;
141: }
142:
143: public Layerable setMaxScale(Double maxScale) {
144: if (LangUtil.bothNullOrEqual(this .maxScale, maxScale)) {
145: return this ;
146: }
147: this .maxScale = maxScale;
148: fireAppearanceChanged();
149: return this ;
150: }
151:
152: public Double getMinScale() {
153: return minScale;
154: }
155:
156: public Layerable setMinScale(Double minScale) {
157: if (LangUtil.bothNullOrEqual(this .minScale, minScale)) {
158: return this ;
159: }
160: this .minScale = minScale;
161: fireAppearanceChanged();
162: return this ;
163: }
164:
165: public boolean isScaleDependentRenderingEnabled() {
166: return scaleDependentRenderingEnabled;
167: }
168:
169: public Layerable setScaleDependentRenderingEnabled(
170: boolean scaleDependentRenderingEnabled) {
171: if (this.scaleDependentRenderingEnabled == scaleDependentRenderingEnabled) {
172: return this;
173: }
174: this.scaleDependentRenderingEnabled = scaleDependentRenderingEnabled;
175: fireAppearanceChanged();
176: return this;
177: }
178: }
|