01: /*
02: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
03: * for visualizing and manipulating spatial features with geometry and attributes.
04: *
05: * Copyright (C) 2003 Vivid Solutions
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: *
21: * For more information, contact:
22: *
23: * Vivid Solutions
24: * Suite #1A
25: * 2328 Government Street
26: * Victoria BC V8T 5G5
27: * Canada
28: *
29: * (250)385-6040
30: * www.vividsolutions.com
31: */
32:
33: package com.vividsolutions.jump.workbench.ui.plugin.clipboard;
34:
35: import java.util.Iterator;
36:
37: import com.vividsolutions.jts.util.Assert;
38: import com.vividsolutions.jump.feature.Feature;
39: import com.vividsolutions.jump.feature.FeatureCollection;
40: import com.vividsolutions.jump.feature.FeatureDataset;
41: import com.vividsolutions.jump.workbench.model.Layer;
42: import com.vividsolutions.jump.workbench.model.LayerManager;
43: import com.vividsolutions.jump.workbench.model.Layerable;
44: import com.vividsolutions.jump.workbench.model.WMSLayer;
45: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
46:
47: public abstract class LayerableClipboardPlugIn extends AbstractPlugIn {
48: public LayerableClipboardPlugIn() {
49: }
50:
51: protected Layerable cloneLayerable(Layerable layerable) {
52: if (layerable instanceof Layer) {
53: return cloneLayer((Layer) layerable);
54: }
55:
56: if (layerable instanceof WMSLayer) {
57: try {
58: return (Layerable) ((WMSLayer) layerable).clone();
59: } catch (CloneNotSupportedException e) {
60: Assert.shouldNeverReachHere();
61: }
62: }
63:
64: Assert.shouldNeverReachHere();
65:
66: return null;
67: }
68:
69: protected Layer cloneLayer(Layer layer) {
70: LayerManager dummyLayerManager = new LayerManager();
71: dummyLayerManager.setFiringEvents(false);
72:
73: Layer clone = new Layer();
74: clone.setLayerManager(dummyLayerManager);
75:
76: //If this is the fence layer, #setName will call #applyStyles, which requires
77: //that the clone have a BasicStyle. So set the styles before setting the
78: //name. [Jon Aquino]
79: clone.setStyles(layer.cloneStyles());
80: clone.setName(layer.getName());
81: clone.setFeatureCollection(cloneFeatureCollection(layer
82: .getFeatureCollectionWrapper()));
83:
84: return clone;
85: }
86:
87: private FeatureCollection cloneFeatureCollection(
88: FeatureCollection featureCollection) {
89: FeatureDataset d = new FeatureDataset(featureCollection
90: .getFeatureSchema());
91:
92: for (Iterator i = featureCollection.iterator(); i.hasNext();) {
93: Feature f = (Feature) i.next();
94: d.add((Feature) f.clone());
95: }
96:
97: return d;
98: }
99: }
|