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.plugin.clipboard;
033:
034: import com.vividsolutions.jump.util.StringUtil;
035: import com.vividsolutions.jump.workbench.WorkbenchContext;
036: import com.vividsolutions.jump.workbench.model.Layer;
037: import com.vividsolutions.jump.workbench.model.Layerable;
038: import com.vividsolutions.jump.workbench.model.WMSLayer;
039: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
040: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
041: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
042:
043: import java.awt.Toolkit;
044:
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import java.util.Iterator;
048:
049: public class CopySelectedLayersPlugIn extends LayerableClipboardPlugIn {
050: //Note: Need to copy the data twice: once when the user hits Copy, so she is
051: //free to modify the original afterwards, and again when the user hits Paste,
052: //so she is free to modify the first copy then hit Paste again. [Jon Aquino]
053: public CopySelectedLayersPlugIn() {
054: }
055:
056: public String getNameWithMnemonic() {
057: return StringUtil.replace(getName(), "C", "&C", false);
058: }
059:
060: public boolean execute(PlugInContext context) throws Exception {
061: reportNothingToUndoYet(context);
062: Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
063: new CollectionOfLayerablesTransferable(clone((context
064: .getLayerNamePanel())
065: .selectedNodes(Layerable.class))),
066: new DummyClipboardOwner());
067:
068: return true;
069: }
070:
071: private Collection clone(Collection layerables) {
072: ArrayList clones = new ArrayList();
073:
074: for (Iterator i = layerables.iterator(); i.hasNext();) {
075: Layerable layerable = (Layerable) i.next();
076:
077: if (!(layerable instanceof Layer || layerable instanceof WMSLayer)) {
078: continue;
079: }
080:
081: clones.add(cloneLayerable(layerable));
082: }
083:
084: return clones;
085: }
086:
087: public MultiEnableCheck createEnableCheck(
088: WorkbenchContext workbenchContext) {
089: EnableCheckFactory checkFactory = new EnableCheckFactory(
090: workbenchContext);
091:
092: return new MultiEnableCheck()
093: .add(
094: checkFactory
095: .createWindowWithLayerNamePanelMustBeActiveCheck())
096: .add(
097: checkFactory
098: .createAtLeastNLayerablesMustBeSelectedCheck(
099: 1, Layerable.class));
100: }
101: }
|