ch.randelshofer.quaqua.datatransfer.CompositeTransferable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Quaqua Show documentation
Show all versions of Quaqua Show documentation
A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library)
Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer.
Mavenisation by Matt Gumbley, DevZendo.org - for problems with
Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page.
For full license details, see http://randelshofer.ch/quaqua/license.html
The newest version!
/*
* @(#)CompositeTransferable.java
*
* Copyright (c) 2001-2010 Werner Randelshofer, Immensee, Switzerland.
* All rights reserved.
*
* You may not use, copy or modify this file, except in compliance with the
* license agreement you entered into with Werner Randelshofer.
* For details see accompanying license terms.
*/
package ch.randelshofer.quaqua.datatransfer;
import java.awt.datatransfer.*;
import java.util.*;
import java.io.*;
/**
* CompositeTransferable.
*
* @author Werner Randelshofer
* @version $Id: CompositeTransferable.java 363 2010-11-21 17:41:04Z wrandelshofer $
*/
public class CompositeTransferable implements java.awt.datatransfer.Transferable {
private HashMap transferables = new HashMap();
private LinkedList flavors = new LinkedList();
/** Creates a new instance of CompositeTransferable */
public CompositeTransferable() {
}
public void add(Transferable t) {
DataFlavor[] f = t.getTransferDataFlavors();
for (int i=0; i < f.length; i++) {
if (! transferables.containsKey(f[i])) flavors.add(f[i]);
transferables.put(f[i], t);
}
}
/**
* Returns an object which represents the data to be transferred. The class
* of the object returned is defined by the representation class of the flavor.
*
* @param flavor the requested flavor for the data
* @see DataFlavor#getRepresentationClass
* @exception IOException if the data is no longer available
* in the requested flavor.
* @exception UnsupportedFlavorException if the requested data flavor is
* not supported.
*/
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
Transferable t = (Transferable) transferables.get(flavor);
if (t == null) throw new UnsupportedFlavorException(flavor);
return t.getTransferData(flavor);
}
/**
* Returns an array of DataFlavor objects indicating the flavors the data
* can be provided in. The array should be ordered according to preference
* for providing the data (from most richly descriptive to least descriptive).
* @return an array of data flavors in which this data can be transferred
*/
public DataFlavor[] getTransferDataFlavors() {
return (DataFlavor[]) flavors.toArray(new DataFlavor[transferables.size()]);
}
/**
* Returns whether or not the specified data flavor is supported for
* this object.
* @param flavor the requested flavor for the data
* @return boolean indicating wjether or not the data flavor is supported
*/
public boolean isDataFlavorSupported(DataFlavor flavor) {
return transferables.containsKey(flavor);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy