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.ui.plugin.clipboard;
034:
035: import java.awt.datatransfer.DataFlavor;
036: import java.awt.datatransfer.UnsupportedFlavorException;
037: import java.io.StringReader;
038: import java.util.ArrayList;
039: import java.util.Collection;
040: import java.util.Collections;
041: import java.util.List;
042:
043: import com.vividsolutions.jump.workbench.model.Layerable;
044:
045: public class CollectionOfLayerablesTransferable extends
046: AbstractTransferable {
047: public static final DataFlavor COLLECTION_OF_LAYERABLES_FLAVOR = new DataFlavor(
048: Collection.class, "Collection of Layerables") {
049: public boolean equals(DataFlavor that) {
050: //Needed so #equals will return false for COLLECTION_OF_FEATURES_FLAVOR. [Jon Aquino]
051: return super .equals(that)
052: && getHumanPresentableName().equals(
053: that.getHumanPresentableName());
054: }
055: };
056:
057: private static final DataFlavor[] flavors = {
058: DataFlavor.stringFlavor,
059: //plainTextFlavor is deprecated, but JDK 1.3 needs it to paste to
060: //non-Java apps (like Notepad). [Jon Aquino]
061: DataFlavor.plainTextFlavor, COLLECTION_OF_LAYERABLES_FLAVOR };
062: private Collection layerables;
063:
064: public CollectionOfLayerablesTransferable(Collection layerables) {
065: super (flavors);
066: this .layerables = new ArrayList(layerables);
067: }
068:
069: public Object getTransferData(DataFlavor flavor)
070: throws UnsupportedFlavorException {
071: if (flavor.equals(COLLECTION_OF_LAYERABLES_FLAVOR)) {
072: return Collections.unmodifiableCollection(layerables);
073: }
074:
075: if (flavor.equals(DataFlavor.stringFlavor)) {
076: return toString(new ArrayList(layerables));
077: }
078:
079: if (flavor.equals(DataFlavor.plainTextFlavor)) {
080: return new StringReader(toString(new ArrayList(layerables)));
081: }
082:
083: throw new UnsupportedFlavorException(flavor);
084: }
085:
086: private String toString(List layerables) {
087: StringBuffer b = new StringBuffer();
088:
089: for (int i = 0; i < layerables.size(); i++) {
090: Layerable layerable = (Layerable) layerables.get(i);
091:
092: if (i != 0) {
093: b.append(", ");
094: }
095:
096: b.append(layerable.getName());
097: }
098:
099: return b.toString();
100: }
101: }
|