From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../classpath/java/awt/datatransfer/Clipboard.java | 213 ++++ .../java/awt/datatransfer/ClipboardOwner.java | 56 ++ .../java/awt/datatransfer/DataFlavor.java | 1026 ++++++++++++++++++++ .../java/awt/datatransfer/FlavorEvent.java | 57 ++ .../java/awt/datatransfer/FlavorListener.java | 54 ++ .../classpath/java/awt/datatransfer/FlavorMap.java | 75 ++ .../java/awt/datatransfer/FlavorTable.java | 73 ++ .../classpath/java/awt/datatransfer/MimeType.java | 283 ++++++ .../awt/datatransfer/MimeTypeParseException.java | 70 ++ .../java/awt/datatransfer/StringSelection.java | 157 +++ .../java/awt/datatransfer/SystemFlavorMap.java | 561 +++++++++++ .../java/awt/datatransfer/Transferable.java | 82 ++ .../datatransfer/UnsupportedFlavorException.java | 65 ++ .../classpath/java/awt/datatransfer/package.html | 47 + 14 files changed, 2819 insertions(+) create mode 100644 libjava/classpath/java/awt/datatransfer/Clipboard.java create mode 100644 libjava/classpath/java/awt/datatransfer/ClipboardOwner.java create mode 100644 libjava/classpath/java/awt/datatransfer/DataFlavor.java create mode 100644 libjava/classpath/java/awt/datatransfer/FlavorEvent.java create mode 100644 libjava/classpath/java/awt/datatransfer/FlavorListener.java create mode 100644 libjava/classpath/java/awt/datatransfer/FlavorMap.java create mode 100644 libjava/classpath/java/awt/datatransfer/FlavorTable.java create mode 100644 libjava/classpath/java/awt/datatransfer/MimeType.java create mode 100644 libjava/classpath/java/awt/datatransfer/MimeTypeParseException.java create mode 100644 libjava/classpath/java/awt/datatransfer/StringSelection.java create mode 100644 libjava/classpath/java/awt/datatransfer/SystemFlavorMap.java create mode 100644 libjava/classpath/java/awt/datatransfer/Transferable.java create mode 100644 libjava/classpath/java/awt/datatransfer/UnsupportedFlavorException.java create mode 100644 libjava/classpath/java/awt/datatransfer/package.html (limited to 'libjava/classpath/java/awt/datatransfer') diff --git a/libjava/classpath/java/awt/datatransfer/Clipboard.java b/libjava/classpath/java/awt/datatransfer/Clipboard.java new file mode 100644 index 000000000..d0a1d3a3f --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/Clipboard.java @@ -0,0 +1,213 @@ +/* Clipboard.java -- Class for transferring data via cut and paste. + Copyright (C) 1999, 2001, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * This class allows data to be transferred using a cut and paste type + * mechanism. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Mark J. Wielaard (mark@klomp.org) + */ +public class Clipboard +{ + /** + * The data currently on this clipboard. For use by + * subclasses. Also returned by the public method getContents(). + */ + protected Transferable contents; + + /** + * The owner of this clipboard. + */ + protected ClipboardOwner owner; + + // The clipboard name + private final String name; + + // The flavor listeners (most likely small). + private final ArrayList listeners = new ArrayList(3); + + /** + * Initializes a new instance of Clipboard with the + * specified name. + * + * @param name The clipboard name. + */ + public Clipboard(String name) + { + this.name = name; + } + + /** + * Returns the name of the clipboard. + */ + public String getName() + { + return name; + } + + /** + * Returns the contents of the clipboard. + * + * @param requestor The object requesting the contents. This + * implementation ignores this parameter. + * + * @exception IllegalStateException If the clipboard is currently unavailable + */ + public synchronized Transferable getContents(Object requestor) + { + return contents; + } + + /** + * Sets the content and owner of this clipboard. If the given owner + * is different from the current owner then lostOwnership() + * is called on the current owner with the old contents of the given + * clipboard. + * + * @param contents The new clipboard contents. + * @param owner The new clipboard owner + * + * @exception IllegalStateException If the clipboard is currently unavailable + */ + public synchronized void setContents(Transferable contents, + ClipboardOwner owner) + { + Transferable oldContents = getContents(null); + this.contents = contents; + if (this.owner != owner) + { + ClipboardOwner oldOwner = this.owner; + this.owner = owner; + if (oldOwner != null) + oldOwner.lostOwnership(this, oldContents); + } + + FlavorListener[] fs = getFlavorListeners(); + if (fs.length > 0) + { + // We are a bit optimistic here. We assume DataFlavors will be + // given in the same order. If the number of flavors is + // different or the order of the DataFlavors in the list then + // fire a change event. + boolean newFlavors = ((contents != null && oldContents == null) + || (contents == null && oldContents != null)); + if (!newFlavors && contents != null && oldContents != null) + { + DataFlavor[] df1 = contents.getTransferDataFlavors(); + DataFlavor[] df2 = oldContents.getTransferDataFlavors(); + newFlavors = df1.length != df2.length; + + for (int i = 0; !newFlavors && i < df1.length; i++) + newFlavors = !df1[i].equals(df2[i]); + } + + if (newFlavors) + { + FlavorEvent e = new FlavorEvent(this); + for (int i = 0; i < fs.length; i++) + fs[i].flavorsChanged(e); + } + } + } + + public DataFlavor[] getAvailableDataFlavors() + { + Transferable c = getContents(null); + if (c == null) + return new DataFlavor[0]; + else + return c.getTransferDataFlavors(); + } + + public boolean isDataFlavorAvailable(DataFlavor flavor) + { + DataFlavor[] fs = getAvailableDataFlavors(); + for (int i = 0; i < fs.length; i++) + if (flavor.equals(fs[i])) + return true; + + return false; + } + + public Object getData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException + { + Transferable c = getContents(null); + if (c == null) + throw new UnsupportedFlavorException(flavor); + else + return c.getTransferData(flavor); + } + + public void addFlavorListener(FlavorListener listener) + { + if (listener == null) + return; + + synchronized(listeners) + { + listeners.add(listener); + } + } + + public void removeFlavorListener(FlavorListener listener) + { + if (listener == null) + return; + + synchronized(listeners) + { + listeners.remove(listener); + } + } + + public FlavorListener[] getFlavorListeners() + { + synchronized(listeners) + { + return (FlavorListener[]) + listeners.toArray(new FlavorListener[listeners.size()]); + } + } +} diff --git a/libjava/classpath/java/awt/datatransfer/ClipboardOwner.java b/libjava/classpath/java/awt/datatransfer/ClipboardOwner.java new file mode 100644 index 000000000..b98059a0e --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/ClipboardOwner.java @@ -0,0 +1,56 @@ +/* ClipboardOwner.java -- Interface for clipboard providers + Copyright (C) 1999 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +/** + * This interface is for classes that will own a clipboard object. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface ClipboardOwner +{ + /** + * This method is called to notify this object that it no longer + * has ownership of the specified Clipboard. + * + * @param clipboard The clipboard for which ownership was lost. + * @param contents The contents of the clipboard which are no longer owned. + */ + void lostOwnership (Clipboard clipboard, Transferable contents); +} diff --git a/libjava/classpath/java/awt/datatransfer/DataFlavor.java b/libjava/classpath/java/awt/datatransfer/DataFlavor.java new file mode 100644 index 000000000..e54770434 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/DataFlavor.java @@ -0,0 +1,1026 @@ +/* DataFlavor.java -- A type of data to transfer via the clipboard. + Copyright (C) 1999, 2001, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.OptionalDataException; +import java.io.Reader; +import java.io.Serializable; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.rmi.Remote; + +/** + * This class represents a particular data format used for transferring + * data via the clipboard. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class DataFlavor implements java.io.Externalizable, Cloneable +{ + static final long serialVersionUID = 8367026044764648243L; + + // FIXME: Serialization: Need to write methods for. + + /** + * This is the data flavor used for tranferring plain text. The MIME + * type is "text/plain; charset=unicode". The representation class + * is java.io.InputStream. + * + * @deprecated The charset unicode is platform specific and InputStream + * deals with bytes not chars. Use getRederForText(). + */ + public static final DataFlavor plainTextFlavor = + new DataFlavor("text/plain; charset=unicode; class=java.io.InputStream", + "plain unicode text"); + + /** + * This is the data flavor used for transferring Java strings. The + * MIME type is "application/x-java-serialized-object" and the + * representation class is java.lang.String. + */ + public static final DataFlavor stringFlavor = + new DataFlavor(java.lang.String.class, "Java Unicode String"); + + /** + * This is a data flavor used for transferring lists of files. The + * representation type is a java.util.List, with each + * element of the list being a java.io.File. + */ + public static final DataFlavor javaFileListFlavor = + new DataFlavor("application/x-java-file-list; class=java.util.List", + "Java File List"); + + /** + * This is an image flavor used for transferring images. The + * representation type is a java.awt.Image. + */ + public static final DataFlavor imageFlavor = + new DataFlavor(java.awt.Image.class, "Java Image"); + + /** + * This is the MIME type used for transferring a serialized object. + * The representation class is the type of object be deserialized. + */ + public static final String javaSerializedObjectMimeType = + "application/x-java-serialized-object"; + + /** + * This is the MIME type used to transfer a Java object reference within + * the same JVM. The representation class is the class of the object + * being transferred. + */ + public static final String javaJVMLocalObjectMimeType = + "application/x-java-jvm-local-objectref"; + + /** + * This is the MIME type used to transfer a link to a remote object. + * The representation class is the type of object being linked to. + */ + public static final String javaRemoteObjectMimeType = + "application/x-java-remote-object"; + + /* + * Instance Variables + */ + + // The MIME type for this flavor + private MimeType mimeType; + + // The representation class for this flavor + private Class representationClass; + + // The human readable name of this flavor + private String humanPresentableName; + + /* + * Static Methods + */ + + /** + * This method attempts to load the named class. The following class + * loaders are searched in order: the bootstrap class loader, the + * system class loader, the context class loader (if it exists), and + * the specified fallback class loader. + * + * @param className The name of the class to load. + * @param classLoader The class loader to use if all others fail, which + * may be null. + * + * @exception ClassNotFoundException If the class cannot be loaded. + */ + protected static final Class tryToLoadClass(String className, + ClassLoader classLoader) + throws ClassNotFoundException + { + // Bootstrap + try + { + return Class.forName(className); + } + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + + // System + try + { + ClassLoader loader = ClassLoader.getSystemClassLoader(); + return Class.forName(className, true, loader); + } + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + + // Context + try + { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + return Class.forName(className, true, loader); + } + catch(ClassNotFoundException cnfe) + { + // Ignored. + } + + if (classLoader != null) + return Class.forName(className, true, classLoader); + + throw new ClassNotFoundException(className); + } + + /** + * XXX - Currently returns plainTextFlavor. + */ + public static final DataFlavor getTextPlainUnicodeFlavor() + { + return plainTextFlavor; + } + + /** + * Selects the best supported text flavor on this implementation. + * Returns null when none of the given flavors is liked. + * + * The DataFlavor returned the first data flavor in the + * array that has either a representation class which is (a subclass of) + * Reader or String, or has a representation + * class which is (a subclass of) InputStream and has a + * primary MIME type of "text" and has an supported encoding. + */ + public static final DataFlavor + selectBestTextFlavor(DataFlavor[] availableFlavors) + { + for(int i = 0; i < availableFlavors.length; i++) + { + DataFlavor df = availableFlavors[i]; + Class c = df.representationClass; + + // A Reader or String is good. + if ((Reader.class.isAssignableFrom(c)) + || (String.class.isAssignableFrom(c))) + return df; + + // A InputStream is good if the mime primary type is "text" + if ((InputStream.class.isAssignableFrom(c)) + && ("text".equals(df.getPrimaryType()))) + { + String encoding = availableFlavors[i].getParameter("charset"); + if (encoding == null) + encoding = "us-ascii"; + Reader r = null; + try + { + // Try to construct a dummy reader with the found encoding + r = new InputStreamReader + (new ByteArrayInputStream(new byte[0]), encoding); + } + catch(UnsupportedEncodingException uee) { /* ignore */ } + + if (r != null) + return df; + } + } + + // Nothing found + return null; + } + + + /* + * Constructors + */ + + /** + * Empty public constructor needed for externalization. + * Should not be used for normal instantiation. + */ + public DataFlavor() + { + // Used for deserialization only, nothing to do here. + } + + /** + * Initializes a new instance of DataFlavor. The class + * and human readable name are specified, the MIME type will be + * "application/x-java-serialized-object". If the human readable name + * is not specified (null) then the human readable name + * will be the same as the MIME type. + * + * @param representationClass The representation class for this object. + * @param humanPresentableName The display name of the object. + */ + public DataFlavor(Class representationClass, String humanPresentableName) + { + if (representationClass == null) + throw new NullPointerException("representationClass must not be null"); + try + { + mimeType = new MimeType(javaSerializedObjectMimeType); + } + catch (MimeTypeParseException ex) + { + // Must not happen as we use a constant string. + assert false; + } + if (humanPresentableName == null) + humanPresentableName = javaSerializedObjectMimeType; + this.humanPresentableName = humanPresentableName; + this.representationClass = representationClass; + } + + /** + * Initializes a new instance of DataFlavor with the + * specified MIME type and description. If the MIME type has a + * "class=<rep class>" parameter then the representation class will + * be the class name specified. Otherwise the class defaults to + * java.io.InputStream. If the human readable name + * is not specified (null) then the human readable name + * will be the same as the MIME type. + * + * @param mimeType The MIME type for this flavor. + * @param humanPresentableName The display name of this flavor. + * @param classLoader The class loader for finding classes if the default + * class loaders do not work. + * + * @exception IllegalArgumentException If the representation class + * specified cannot be loaded. + * @exception ClassNotFoundException If the class is not loaded. + */ + public DataFlavor(String mimeType, String humanPresentableName, + ClassLoader classLoader) + throws ClassNotFoundException + { + init(mimeType, humanPresentableName, classLoader); + } + + /** + * Initializes a new instance of DataFlavor with the + * specified MIME type and description. If the MIME type has a + * "class=<rep class>" parameter then the representation class will + * be the class name specified. Otherwise the class defaults to + * java.io.InputStream. If the human readable name + * is not specified (null) then the human readable name + * will be the same as the MIME type. This is the same as calling + * new DataFlavor(mimeType, humanPresentableName, null). + * + * @param mimeType The MIME type for this flavor. + * @param humanPresentableName The display name of this flavor. + * + * @exception IllegalArgumentException If the representation class + * specified cannot be loaded. + */ + public DataFlavor(String mimeType, String humanPresentableName) + { + try + { + init(mimeType, humanPresentableName, getClass().getClassLoader()); + } + catch (ClassNotFoundException ex) + { + IllegalArgumentException iae = + new IllegalArgumentException("Class not found: " + ex.getMessage()); + iae.initCause(ex); + throw iae; + } + } + + /** + * Initializes a new instance of DataFlavor with the specified + * MIME type. This type can have a "class=" parameter to specify the + * representation class, and then the class must exist or an exception will + * be thrown. If there is no "class=" parameter then the representation class + * will be java.io.InputStream. This is the same as calling + * new DataFlavor(mimeType, null). + * + * @param mimeType The MIME type for this flavor. + * + * @exception IllegalArgumentException If a class is not specified in + * the MIME type. + * @exception ClassNotFoundException If the class cannot be loaded. + */ + public DataFlavor(String mimeType) throws ClassNotFoundException + { + init(mimeType, null, getClass().getClassLoader()); + } + + /** + * Called by various constructors to initialize this object. + * + * @param mime the mime string + * @param humanPresentableName the human presentable name + * @param loader the class loader to use for loading the representation + * class + */ + private void init(String mime, String humanPresentableName, + ClassLoader loader) + throws ClassNotFoundException + { + if (mime == null) + throw new NullPointerException("The mime type must not be null"); + try + { + mimeType = new MimeType(mime); + } + catch (MimeTypeParseException ex) + { + IllegalArgumentException iae = + new IllegalArgumentException("Invalid mime type"); + iae.initCause(ex); + throw iae; + } + String className = mimeType.getParameter("class"); + if (className == null) + { + if (mimeType.getBaseType().equals(javaSerializedObjectMimeType)) + throw new IllegalArgumentException("Serialized object type must have" + + " a representation class parameter"); + else + representationClass = java.io.InputStream.class; + } + else + representationClass = tryToLoadClass(className, loader); + mimeType.addParameter("class", representationClass.getName()); + + if (humanPresentableName == null) + { + humanPresentableName = mimeType.getParameter("humanPresentableName"); + if (humanPresentableName == null) + humanPresentableName = mimeType.getBaseType(); + } + this.humanPresentableName = humanPresentableName; + } + + /** + * Returns the MIME type of this flavor. + * + * @return The MIME type for this flavor. + */ + public String getMimeType() + { + return(mimeType.toString()); + } + + /** + * Returns the representation class for this flavor. + * + * @return The representation class for this flavor. + */ + public Class getRepresentationClass() + { + return(representationClass); + } + + /** + * Returns the human presentable name for this flavor. + * + * @return The human presentable name for this flavor. + */ + public String getHumanPresentableName() + { + return(humanPresentableName); + } + + /** + * Returns the primary MIME type for this flavor. + * + * @return The primary MIME type for this flavor. + */ + public String getPrimaryType() + { + return(mimeType.getPrimaryType()); + } + + /** + * Returns the MIME subtype for this flavor. + * + * @return The MIME subtype for this flavor. + */ + public String getSubType() + { + return mimeType.getSubType(); + } + + /** + * Returns the value of the named MIME type parameter, or null + * if the parameter does not exist. + * + * @param paramName The name of the paramter. + * + * @return The value of the parameter. + */ + public String getParameter(String paramName) + { + if ("humanPresentableName".equals(paramName)) + return getHumanPresentableName(); + + return mimeType.getParameter(paramName); + } + + /** + * Sets the human presentable name to the specified value. + * + * @param humanPresentableName The new display name. + */ + public void setHumanPresentableName(String humanPresentableName) + { + this.humanPresentableName = humanPresentableName; + } + + /** + * Tests the MIME type of this object for equality against the specified + * MIME type. Ignores parameters. + * + * @param mimeType The MIME type to test against. + * + * @return true if the MIME type is equal to this object's + * MIME type (ignoring parameters), false otherwise. + * + * @exception NullPointerException If mimeType is null. + */ + public boolean isMimeTypeEqual(String mimeType) + { + if (mimeType == null) + throw new NullPointerException("mimeType must not be null"); + boolean equal = false; + try + { + if (this.mimeType != null) + { + MimeType other = new MimeType(mimeType); + equal = this.mimeType.matches(other); + } + } + catch (MimeTypeParseException ex) + { + // Return false in this case. + } + return equal; + } + + /** + * Tests the MIME type of this object for equality against the specified + * data flavor's MIME type + * + * @param flavor The flavor to test against. + * + * @return true if the flavor's MIME type is equal to this + * object's MIME type, false otherwise. + */ + public final boolean isMimeTypeEqual(DataFlavor flavor) + { + return isMimeTypeEqual(flavor.getMimeType()); + } + + /** + * Tests whether or not this flavor represents a serialized object. + * + * @return true if this flavor represents a serialized + * object, false otherwise. + */ + public boolean isMimeTypeSerializedObject() + { + return isMimeTypeEqual(javaSerializedObjectMimeType); + } + + /** + * Tests whether or not this flavor has a representation class of + * java.io.InputStream. + * + * @return true if the representation class of this flavor + * is java.io.InputStream, false otherwise. + */ + public boolean isRepresentationClassInputStream() + { + return InputStream.class.isAssignableFrom(representationClass); + } + + /** + * Tests whether the representation class for this flavor is + * serializable. + * + * @return true if the representation class is serializable, + * false otherwise. + */ + public boolean isRepresentationClassSerializable() + { + return Serializable.class.isAssignableFrom(representationClass); + } + + /** + * Tests whether the representation class for his flavor is remote. + * + * @return true if the representation class is remote, + * false otherwise. + */ + public boolean isRepresentationClassRemote() + { + return Remote.class.isAssignableFrom (representationClass); + } + + /** + * Tests whether or not this flavor represents a serialized object. + * + * @return true if this flavor represents a serialized + * object, false otherwise. + */ + public boolean isFlavorSerializedObjectType() + { + return isRepresentationClassSerializable() + && isMimeTypeEqual(javaSerializedObjectMimeType); + } + + /** + * Tests whether or not this flavor represents a remote object. + * + * @return true if this flavor represents a remote object, + * false otherwise. + */ + public boolean isFlavorRemoteObjectType() + { + return isRepresentationClassRemote() + && isRepresentationClassSerializable() + && isMimeTypeEqual(javaRemoteObjectMimeType); + } + + /** + * Tests whether or not this flavor represents a list of files. + * + * @return true if this flavor represents a list of files, + * false otherwise. + */ + public boolean isFlavorJavaFileListType() + { + if (getPrimaryType().equals(javaFileListFlavor.getPrimaryType()) + && getSubType().equals(javaFileListFlavor.getSubType()) + && javaFileListFlavor.representationClass + .isAssignableFrom(representationClass)) + return true; + + return false ; + } + + /** + * Returns a copy of this object. + * + * @return A copy of this object. + * + * @exception CloneNotSupportedException If the object's class does not support + * the Cloneable interface. Subclasses that override the clone method can also + * throw this exception to indicate that an instance cannot be cloned. + */ + public Object clone () throws CloneNotSupportedException + { + // FIXME - This cannot be right. + try + { + return super.clone(); + } + catch(Exception e) + { + return null; + } + } + + /** + * This method test the specified DataFlavor for equality + * against this object. This will be true if the MIME type and + * representation class are the equal. If the primary type is 'text' + * then also the value of the charset parameter is compared. In such a + * case when the charset parameter isn't given then the charset is + * assumed to be equal to the default charset of the platform. All + * other parameters are ignored. + * + * @param flavor The DataFlavor to test against. + * + * @return true if the flavor is equal to this object, + * false otherwise. + */ + public boolean equals(DataFlavor flavor) + { + if (flavor == null) + return false; + + String primary = getPrimaryType(); + if (! primary.equals(flavor.getPrimaryType())) + return false; + + String sub = getSubType(); + if (! sub.equals(flavor.getSubType())) + return false; + + if (! this.representationClass.equals(flavor.representationClass)) + return false; + + if (primary.equals("text")) + if (! isRepresentationClassCharBuffer() + && ! isRepresentationClassReader() + && representationClass != java.lang.String.class + && ! (representationClass.isArray() + && representationClass.getComponentType() == Character.TYPE)) + { + String charset = getParameter("charset"); + String otherset = flavor.getParameter("charset"); + String defaultset = Charset.defaultCharset().name(); + + if (charset == null || charset.equals(defaultset)) + return (otherset == null || otherset.equals(defaultset)); + + return charset.equals(otherset); + } + + return true; + } + + /** + * This method test the specified Object for equality + * against this object. This will be true if the following conditions + * are met: + *

+ *

+ * + * @param obj The Object to test against. + * + * @return true if the flavor is equal to this object, + * false otherwise. + */ + public boolean equals(Object obj) + { + if (! (obj instanceof DataFlavor)) + return false; + + return equals((DataFlavor) obj); + } + + /** + * Tests whether or not the specified string is equal to the MIME type + * of this object. + * + * @param str The string to test against. + * + * @return true if the string is equal to this object's MIME + * type, false otherwise. + * + * @deprecated Not compatible with hashCode(). + * Use isMimeTypeEqual() + */ + public boolean equals(String str) + { + return isMimeTypeEqual(str); + } + + /** + * Returns the hash code for this data flavor. + * The hash code is based on the (lower case) mime type and the + * representation class. + */ + public int hashCode() + { + return mimeType.toString().hashCode() ^ representationClass.hashCode(); + } + + /** + * Returns true when the given DataFlavor + * matches this one. + */ + public boolean match(DataFlavor dataFlavor) + { + // XXX - How is this different from equals? + return equals(dataFlavor); + } + + /** + * This method exists for backward compatibility. It simply returns + * the same name/value pair passed in. + * + * @param name The parameter name. + * @param value The parameter value. + * + * @return The name/value pair. + * + * @deprecated + */ + protected String normalizeMimeTypeParameter(String name, String value) + { + return name + "=" + value; + } + + /** + * This method exists for backward compatibility. It simply returns + * the MIME type string unchanged. + * + * @param type The MIME type. + * + * @return The MIME type. + * + * @deprecated + */ + protected String normalizeMimeType(String type) + { + return type; + } + + /** + * Serialize this class. + * + * @param stream The ObjectOutput stream to serialize to. + * + * @exception IOException If an error occurs. + */ + public void writeExternal(ObjectOutput stream) + throws IOException + { + if (mimeType != null) + { + mimeType.addParameter("humanPresentableName", humanPresentableName); + stream.writeObject(mimeType); + mimeType.removeParameter("humanPresentableName"); + } + else + stream.writeObject(null); + stream.writeObject(representationClass); + } + + + /** + * De-serialize this class. + * + * @param stream The ObjectInput stream to deserialize from. + * + * @exception IOException If an error ocurs. + * @exception ClassNotFoundException If the class for an object being restored + * cannot be found. + */ + public void readExternal(ObjectInput stream) + throws IOException, ClassNotFoundException + { + mimeType = (MimeType) stream.readObject(); + String className = null; + if (mimeType != null) + { + humanPresentableName = + mimeType.getParameter("humanPresentableName"); + mimeType.removeParameter("humanPresentableName"); + className = mimeType.getParameter("class"); + if (className == null) + throw new IOException("No class in mime type"); + } + try + { + representationClass = (Class) stream.readObject(); + } + catch (OptionalDataException ex) + { + if (ex.eof && ex.length == 0) + { + if (className != null) + representationClass = tryToLoadClass(className, + getClass().getClassLoader()); + } + else + throw ex; + } + } + + /** + * Returns a string representation of this DataFlavor. Including the + * representation class name, MIME type and human presentable name. + */ + public String toString() + { + return (getClass().getName() + + "[representationClass=" + getRepresentationClass().getName() + + ",mimeType=" + getMimeType() + + ",humanPresentableName=" + getHumanPresentableName() + + "]"); + } + + /** + * XXX - Currently returns java.io.InputStream. + * + * @since 1.3 + */ + public final Class getDefaultRepresentationClass() + { + return java.io.InputStream.class; + } + + /** + * XXX - Currently returns java.io.InputStream. + */ + public final String getDefaultRepresentationClassAsString() + { + return getDefaultRepresentationClass().getName(); + } + + /** + * Creates a Reader for a given Transferable. + * + * If the representation class is a (subclass of) Reader + * then an instance of the representation class is returned. If the + * representatation class is a String then a + * StringReader is returned. And if the representation class + * is a (subclass of) InputStream and the primary MIME type + * is "text" then a InputStreamReader for the correct charset + * encoding is returned. + * + * @param transferable The Transferable for which a text + * Reader is requested. + * + * @exception IllegalArgumentException If the representation class is not one + * of the seven listed above or the Transferable has null data. + * @exception NullPointerException If the Transferable is null. + * @exception UnsupportedFlavorException when the transferable doesn't + * support this DataFlavor. Or if the representable class + * isn't a (subclass of) Reader, String, + * InputStream and/or the primary MIME type isn't "text". + * @exception IOException when any IOException occurs. + * @exception UnsupportedEncodingException if the "charset" isn't supported + * on this platform. + */ + public Reader getReaderForText(Transferable transferable) + throws UnsupportedFlavorException, IOException + { + if (!transferable.isDataFlavorSupported(this)) + throw new UnsupportedFlavorException(this); + + if (Reader.class.isAssignableFrom(representationClass)) + return (Reader)transferable.getTransferData(this); + + if (String.class.isAssignableFrom(representationClass)) + return new StringReader((String)transferable.getTransferData(this)); + + if (InputStream.class.isAssignableFrom(representationClass) + && "text".equals(getPrimaryType())) + { + InputStream in = (InputStream)transferable.getTransferData(this); + String encoding = getParameter("charset"); + if (encoding == null) + encoding = "us-ascii"; + return new InputStreamReader(in, encoding); + } + + throw new UnsupportedFlavorException(this); + } + + /** + * Returns whether the representation class for this DataFlavor is + * @see java.nio.ByteBuffer or a subclass thereof. + * + * @since 1.4 + */ + public boolean isRepresentationClassByteBuffer() + { + return ByteBuffer.class.isAssignableFrom(representationClass); + } + + /** + * Returns whether the representation class for this DataFlavor is + * @see java.nio.CharBuffer or a subclass thereof. + * + * @since 1.4 + */ + public boolean isRepresentationClassCharBuffer() + { + return CharBuffer.class.isAssignableFrom(representationClass); + } + + /** + * Returns whether the representation class for this DataFlavor is + * @see java.io.Reader or a subclass thereof. + * + * @since 1.4 + */ + public boolean isRepresentationClassReader() + { + return Reader.class.isAssignableFrom(representationClass); + } + + /** + * Returns whether this DataFlavor is a valid text flavor for + * this implementation of the Java platform. Only flavors equivalent to + * DataFlavor.stringFlavor and DataFlavors with + * a primary MIME type of "text" can be valid text flavors. + *

+ * If this flavor supports the charset parameter, it must be equivalent to + * DataFlavor.stringFlavor, or its representation must be + * java.io.Reader, java.lang.String, + * java.nio.CharBuffer, java.io.InputStream or + * java.nio.ByteBuffer, + * If the representation is java.io.InputStream or + * java.nio.ByteBuffer, then this flavor's charset + * parameter must be supported by this implementation of the Java platform. + * If a charset is not specified, then the platform default charset, which + * is always supported, is assumed. + *

+ * If this flavor does not support the charset parameter, its + * representation must be java.io.InputStream, + * java.nio.ByteBuffer. + *

+ * See selectBestTextFlavor for a list of text flavors which + * support the charset parameter. + * + * @return true if this DataFlavor is a valid + * text flavor as described above; false otherwise + * @see #selectBestTextFlavor + * @since 1.4 + */ + public boolean isFlavorTextType() { + // FIXME: I'm not 100% sure if this implementation does the same like sun's does + if(equals(DataFlavor.stringFlavor) || getPrimaryType().equals("text")) + { + String charset = getParameter("charset"); + Class c = getRepresentationClass(); + if(charset != null) + { + if(Reader.class.isAssignableFrom(c) + || CharBuffer.class.isAssignableFrom(c) + || String.class.isAssignableFrom(c)) + { + return true; + } + else if(InputStream.class.isAssignableFrom(c) + || ByteBuffer.class.isAssignableFrom(c)) + { + return Charset.isSupported(charset); + } + } + else if(InputStream.class.isAssignableFrom(c) + || ByteBuffer.class.isAssignableFrom(c)) + { + return true; + } + } + return false; + } +} // class DataFlavor diff --git a/libjava/classpath/java/awt/datatransfer/FlavorEvent.java b/libjava/classpath/java/awt/datatransfer/FlavorEvent.java new file mode 100644 index 000000000..8a292f850 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/FlavorEvent.java @@ -0,0 +1,57 @@ +/* FlavorEvent -- Event indicating a ClipBoard has different flavors available. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.util.EventObject; + +/** + * Event indicating a Clipboard has different flavors available. + * Fired by a ClipBoard for registered FlavorListeners. + * + * @author Mark J. Wielaard (mark@klomp.org) + * + * @since 1.5 + */ +public class FlavorEvent extends EventObject +{ + public FlavorEvent(Clipboard board) + { + super(board); + } +} diff --git a/libjava/classpath/java/awt/datatransfer/FlavorListener.java b/libjava/classpath/java/awt/datatransfer/FlavorListener.java new file mode 100644 index 000000000..eb388aa84 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/FlavorListener.java @@ -0,0 +1,54 @@ +/* FlavorListener -- Interface for tagging an interest in FlavorEvents. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.util.EventListener; + +/** + * Interface for tagging an interest in FlavorEvents by a class. The + * flavorsChanged() method will be called with a FlavorEvent pointing + * to the Clipboard which has content in different Flavors available. + * + * @author Mark J. Wielaard (mark@klomp.org) + */ +public interface FlavorListener + extends EventListener +{ + void flavorsChanged(FlavorEvent event); +} diff --git a/libjava/classpath/java/awt/datatransfer/FlavorMap.java b/libjava/classpath/java/awt/datatransfer/FlavorMap.java new file mode 100644 index 000000000..8842c8e55 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/FlavorMap.java @@ -0,0 +1,75 @@ +/* FlavorMap.java -- Maps between flavor names and MIME types. + Copyright (C) 1999, 2001 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.util.Map; + +/** + * This interface maps between native platform type names and DataFlavors. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface FlavorMap +{ + /** + * Maps the specified DataFlavor objects to the native + * data type name. The returned Map has keys that are + * the data flavors and values that are strings. The returned map + * may be modified. This can be useful for implementing nested mappings. + * + * @param flavors An array of data flavors to map + * or null for all data flavors. + * + * @return A Map of native data types. + */ + Map getNativesForFlavors (DataFlavor[] flavors); + + /** + * Maps the specified native type names to DataFlavor's. + * The returned Map has keys that are strings and values + * that are DataFlavor's. The returned map may be + * modified. This can be useful for implementing nested mappings. + * + * @param natives An array of native types to map + * or null for all native types. + * + * @return A Map of data flavors. + */ + Map getFlavorsForNatives (String[] natives); +} diff --git a/libjava/classpath/java/awt/datatransfer/FlavorTable.java b/libjava/classpath/java/awt/datatransfer/FlavorTable.java new file mode 100644 index 000000000..f6c43af83 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/FlavorTable.java @@ -0,0 +1,73 @@ +/* FlavorTable.java -- A relaxed mapping between flavors + Copyright (C) 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.util.List; + +/** + * A FlavorMap which no longer requires a 1-to-1 mapping between flavors. Any + * native can map to multiple flavors, and any flavor can map to multiple + * natives; although the mappings are usually symmetric. + * + * @author Eric Blake (ebb9@email.byu.edu) + * @since 1.4 + * @status updated to 1.4 + */ +public interface FlavorTable extends FlavorMap +{ + /** + * Returns a list of String natives corresponding to the given flavor. The + * list should be sorted from best to worst. The list must be modifiable + * without affecting this table. + * + * @param flavor the flavor to look up, or null to return all natives + * @return the sorted list of natives + */ + List getNativesForFlavor(DataFlavor flavor); + + /** + * Returns a list of flavors corresponding to the given String native. The + * list should be sorted from best to worst. The list must be modifiable + * without affecting this table. + * + * @param name the native name to look up, or null to return all flavors + * @return the sorted list of flavors + */ + List getFlavorsForNative(String name); +} diff --git a/libjava/classpath/java/awt/datatransfer/MimeType.java b/libjava/classpath/java/awt/datatransfer/MimeType.java new file mode 100644 index 000000000..143e8700b --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/MimeType.java @@ -0,0 +1,283 @@ +/* MimeType.java -- A helper class for mime handling in DataFlavor + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import gnu.java.lang.CPStringBuilder; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.StringTokenizer; + +/** + * A helper class for mime handling in DataFlavor. + * + * A Mauve test for DataFlavor.writeExternal() shows that a non-public + * class java.awt.datatransfer.MimeType gets serialized. This class + * is mainly here for serialization compatibility. Of course, + * now that we have it here, we can just as well implement some + * mime handling facility here. + */ +class MimeType + implements Externalizable +{ + + /** + * The primary type. + */ + private String primaryType; + + /** + * The subtype. + */ + private String subType; + + /** + * Additional parameters to be appended to the mime string. + */ + private HashMap parameters; + + /** + * This is only here for deserialization. + */ + public MimeType() + { + parameters = new HashMap(); + } + + /** + * Creates a new MimeType object. + * + * @param mime the mime type + */ + MimeType(String mime) + throws MimeTypeParseException + { + this(); + parse(mime); + } + + /** + * Adds a mime parameter. + * + * @param param the parameter key + * @param value the parameter value + */ + void addParameter(String param, String value) + { + parameters.put(param, value); + } + + /** + * Removes the parameter with the specified key. + * + * @param param the parameter to remove + */ + void removeParameter(String param) + { + parameters.remove(param); + } + + /** + * Returns the parameter for the key. + * + * @param key the parameter key + * + * @return the parameter for the key + */ + String getParameter(String key) + { + return (String) parameters.get(key); + } + + /** + * Returns the primary type. + * + * @return the primary type + */ + String getPrimaryType() + { + return primaryType; + } + + String getSubType() + { + return subType; + } + + /** + * Returns the base type of this mime type. This is the primary + * type plus the subtype, separated by '/'. + * + * @return the base type of this mime type + */ + String getBaseType() + { + return primaryType + '/' + subType; + } + + /** + * Returns true if this mime type and another mime type + * match. This will be true when their primary types are equal, and their + * subtypes are equal (or when either subtype is * ). + * + * @param other the other mime type + * + * @return true if the mime types match, false + * otherwise + */ + boolean matches(MimeType other) + { + boolean match = false; + if (other != null) + { + match = primaryType.equals(other.primaryType) + && (subType.equals("*") || other.subType.equals("*") + || subType.equals(other.subType)); + } + return match; + } + + /** + * Serializes the mime type. + * + * @param in the input stream to read from + * + * @throws ClassNotFoundException not thrown here + * @throws IOException when something goes wrong on the input stream, + * or when the mime type can't be parsed + */ + public void readExternal(ObjectInput in) + throws ClassNotFoundException, IOException + { + String mime = in.readUTF(); + parameters.clear(); + try + { + parse(mime); + } + catch (MimeTypeParseException ex) + { + IOException ioEx = new IOException(); + ioEx.initCause(ex); + throw ioEx; + } + } + + /** + * Serializes this mime type. + * + * @param out the output stream + * + * @throws IOException when something goes wrong on the output stream + */ + public void writeExternal(ObjectOutput out) + throws IOException + { + out.writeUTF(toString()); + } + + /** + * Creates a string representation of this mime type. + * + * @return a string representation of this mime type + */ + public String toString() + { + CPStringBuilder s = new CPStringBuilder(); + s.append(primaryType); + s.append('/'); + s.append(subType); + if (parameters.size() > 0) + { + Set entries = parameters.entrySet(); + for (Iterator i = entries.iterator(); i.hasNext();) + { + s.append("; "); + Map.Entry entry = (Map.Entry) i.next(); + s.append(entry.getKey()); + s.append('='); + s.append(entry.getValue()); + } + } + return s.toString(); + } + + /** + * Parses the specified mime type string and initializes the fields + * of this object. + * + * @param mime the mime type string + */ + private void parse(String mime) + throws MimeTypeParseException + { + // FIXME: Maybe implement more sophisticated mime string parsing according + // to RFC 2045 and 2046. + StringTokenizer tokenizer = new StringTokenizer(mime); + try + { + primaryType = tokenizer.nextToken("/"); + subType = tokenizer.nextToken("/;"); + } + catch (NoSuchElementException ex) + { + throw new MimeTypeParseException("Expected / separator"); + } + + // Add any parameters. + while (tokenizer.hasMoreTokens()) + { + String keyValuePair = tokenizer.nextToken(";"); + int i = keyValuePair.indexOf('='); + if (i == -1) + throw new MimeTypeParseException("Expected = as parameter separator"); + String key = keyValuePair.substring(0, i).trim(); + String value = keyValuePair.substring(i + 1).trim(); + parameters.put(key, value); + } + } + +} diff --git a/libjava/classpath/java/awt/datatransfer/MimeTypeParseException.java b/libjava/classpath/java/awt/datatransfer/MimeTypeParseException.java new file mode 100644 index 000000000..6113ab760 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/MimeTypeParseException.java @@ -0,0 +1,70 @@ +/* MimeTypeParseException.java -- thrown when MIME string couldn't be parsed + Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +/** + * MIME string couldn't be parsed correctly. + * + * @author Mark Wielaard (mark@klomp.org) + * @status updated to 1.4 + */ +public class MimeTypeParseException extends Exception +{ + /** + * Compatible with JDK 1.1+. + */ + private static final long serialVersionUID = -5604407764691570741L; + + /** + * Create a new instance without any message. + */ + public MimeTypeParseException() + { + } + + /** + * Create a new instance with a specified detailed error message. + * + * @param message the message + */ + public MimeTypeParseException(String message) + { + super(message); + } +} // class MimeTypeParseException diff --git a/libjava/classpath/java/awt/datatransfer/StringSelection.java b/libjava/classpath/java/awt/datatransfer/StringSelection.java new file mode 100644 index 000000000..4b64cda57 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/StringSelection.java @@ -0,0 +1,157 @@ +/* StringSelection.java -- Clipboard handler for text. + Copyright (C) 1999, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.io.IOException; +import java.io.StringReader; + +/** + * This class transfers a string as plain text using the clipboard. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class StringSelection implements Transferable, ClipboardOwner +{ + +/* + * Class Variables + */ + +// List of flavors we support +// XXX: DataFlavor.plainTextFlavor is deprecated. +static final DataFlavor[] supported_flavors + = { DataFlavor.stringFlavor, + DataFlavor.plainTextFlavor }; + +/*************************************************************************/ + +/* + * Instance Variables + */ + +// This is the data to transfer +private String data; + + /** + * Transfer the specfied string as text. + * + * @param data the data for the string selection + */ + public StringSelection(String data) + { + this.data = data; + } + +/** + * Returns a list of supported data flavors. + * + * @return A list of supported data flavors. + */ +public DataFlavor[] +getTransferDataFlavors() +{ + return(supported_flavors); +} + +/*************************************************************************/ + +/** + * Tests whether or not the specified data flavor is supported. + * + * @param flavor The data flavor to test. + * + * @return true if the data flavor is supported, + * false otherwise. + */ +public boolean +isDataFlavorSupported(DataFlavor flavor) +{ + for (int i = 0; i < supported_flavors.length; i++) + if (supported_flavors[i].equals(flavor)) + return(true); + + return(false); +} + +/*************************************************************************/ + +/** + * This method returns the data in the requested format. + * + * @param flavor The desired data flavor. + * + * @return The transferred data. + * + * @exception UnsupportedFlavorException If the specified flavor is not + * supported. + * @exception IOException If any other error occurs. + */ +public Object +getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, + IOException +{ + if (!isDataFlavorSupported(flavor)) + throw new UnsupportedFlavorException(flavor); + + if (DataFlavor.plainTextFlavor == flavor) + /* The behavior of this method for DataFlavor.plainTextFlavor and + equivalent DataFlavors is inconsistent with the definition of + DataFlavor.plainTextFlavor. We choose to do like Sun's implementation + and return a Reader instead of an InputString. */ + /* return(new StringBufferInputStream(data)); */ + return(new StringReader(data)); + else // DataFlavor.stringFlavor + return data; +} + +/*************************************************************************/ + +/** + * Called when ownership of the clipboard object is lost. + * + * @param clipboard The affected clipboard. + * @param contents The clipboard contents. + */ +public void +lostOwnership(Clipboard clipboard, Transferable contents) +{ + // FIXME: What does this do? +} + +} // class StringSelection diff --git a/libjava/classpath/java/awt/datatransfer/SystemFlavorMap.java b/libjava/classpath/java/awt/datatransfer/SystemFlavorMap.java new file mode 100644 index 000000000..65c14c1ba --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/SystemFlavorMap.java @@ -0,0 +1,561 @@ +/* SystemFlavorMap.java -- Maps between native flavor names and MIME types. + Copyright (C) 2001, 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.awt.Toolkit; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.WeakHashMap; + +/** + * This class maps between native platform type names and DataFlavors. + * + * XXX - The current implementation does no mapping at all. + * + * @author Mark Wielaard (mark@klomp.org) + * + * @since 1.2 + */ +public final class SystemFlavorMap implements FlavorMap, FlavorTable +{ + /** + * The map which maps the thread's ClassLoaders to + * SystemFlavorMaps. + */ + private static final Map systemFlavorMaps = new WeakHashMap(); + + /** + * Constant which is used to prefix encode Java MIME types. + */ + private static final String GNU_JAVA_MIME_PREFIX = "gnu.java:"; + + /** + * This map maps native Strings to lists of + * DataFlavors + */ + private HashMap> nativeToFlavorMap = + new HashMap>(); + + /** + * This map maps DataFlavors to lists of native + * Strings + */ + private HashMap> flavorToNativeMap = + new HashMap>(); + + /** + * Private constructor. + */ + private SystemFlavorMap () + { + AccessController.doPrivileged + (new PrivilegedAction() + { + public Object run() + { + try + { + // Load installed flavormap.properties first. + String sep = File.separator; + File propsFile = + new File(System.getProperty("gnu.classpath.home.url") + + sep + "accessibility.properties"); + InputStream in = new FileInputStream(propsFile); + Properties props = new Properties(); + props.load(in); + in.close(); + + String augmented = Toolkit.getProperty("AWT.DnD.flavorMapFileURL", + null); + if (augmented != null) + { + URL url = new URL(augmented); + in = url.openStream(); + props.load(in); + } + setupMapping(props); + } + catch (IOException ex) + { + // Can't do anything about it. + } + return null; + } + }); + } + + /** + * Sets up the mapping from native to mime types and vice versa as specified + * in the flavormap.properties file. + * + * This is package private to avoid an accessor method. + * + * @param props the properties file + */ + void setupMapping(Properties props) + { + Enumeration propNames = props.propertyNames(); + while (propNames.hasMoreElements()) + { + try + { + String nat = (String) propNames.nextElement(); + String mime = (String) props.getProperty(nat); + // Check valid mime type. + MimeType type = new MimeType(mime); + DataFlavor flav = new DataFlavor(mime); + + List flavs = nativeToFlavorMap.get(nat); + if (flavs == null) + { + flavs = new ArrayList(); + nativeToFlavorMap.put(nat, flavs); + } + List nats = flavorToNativeMap.get(flav); + if (nats == null) + { + nats = new ArrayList(); + flavorToNativeMap.put(flav, nats); + } + flavs.add(flav); + nats.add(nat); + } + catch (ClassNotFoundException ex) + { + // Skip. + } + catch (MimeTypeParseException ex) + { + // Skip. + } + } + } + + /** + * Maps the specified DataFlavor objects to the native + * data type name. The returned Map has keys that are + * the data flavors and values that are strings. The returned map + * may be modified. This can be useful for implementing nested mappings. + * + * @param flavors An array of data flavors to map + * or null for all data flavors. + * + * @return A Map of native data types to data flavors. + */ + public Map getNativesForFlavors (DataFlavor[] flavors) + { + return new HashMap(); + } + + /** + * Maps the specified native type names to DataFlavor's. + * The returned Map has keys that are strings and values + * that are DataFlavor's. The returned map may be + * modified. This can be useful for implementing nested mappings. + * + * @param natives An array of native types to map + * or null for all native types. + * + * @return A Map of data flavors to native type names. + */ + public Map getFlavorsForNatives (String[] natives) + { + return new HashMap(); + } + + /** + * Returns the (System)FlavorMap for the current thread's + * ClassLoader. + */ + public static FlavorMap getDefaultFlavorMap () + { + ClassLoader classLoader = Thread.currentThread() + .getContextClassLoader(); + + //if ContextClassLoader not set, use system default + if (classLoader == null) + { + classLoader = ClassLoader.getSystemClassLoader(); + } + + synchronized(systemFlavorMaps) + { + FlavorMap map = (FlavorMap) + systemFlavorMaps.get(classLoader); + if (map == null) + { + map = new SystemFlavorMap(); + systemFlavorMaps.put(classLoader, map); + } + return map; + } + } + + /** + * Encodes a MIME type for use as a String native. The format + * of an encoded representation of a MIME type is implementation-dependent. + * The only restrictions are: + *
    + *
  • The encoded representation is null if and only if the + * MIME type String is null.
  • + *
  • The encoded representations for two non-null MIME type + * Strings are equal if and only if these Strings + * are equal according to String.equals(Object).
  • + *
+ *

+ * The present implementation of this method returns the specified MIME + * type String prefixed with gnu.java:. + * + * @param mime the MIME type to encode + * @return the encoded String, or null if + * mimeType is null + */ + public static String encodeJavaMIMEType (String mime) + { + if (mime != null) + return GNU_JAVA_MIME_PREFIX + mime; + else + return null; + } + + /** + * Encodes a DataFlavor for use as a String + * native. The format of an encoded DataFlavor is + * implementation-dependent. The only restrictions are: + *

    + *
  • The encoded representation is null if and only if the + * specified DataFlavor is null or its MIME type + * String is null.
  • + *
  • The encoded representations for two non-null + * DataFlavors with non-null MIME type + * Strings are equal if and only if the MIME type + * Strings of these DataFlavors are equal + * according to String.equals(Object).
  • + *
+ *

+ * The present implementation of this method returns the MIME type + * String of the specified DataFlavor prefixed + * with gnu.java:. + * + * @param df the DataFlavor to encode + * @return the encoded String, or null if + * flav is null or has a null MIME type + */ + public static String encodeDataFlavor (DataFlavor df) + { + if (df != null) + { + return encodeJavaMIMEType(df.getMimeType()); + } + else + return null; + } + + /** + * Returns true if the native type name can be represented as + * a java mime type. Returns false if parameter is + * null. + */ + public static boolean isJavaMIMEType (String name) + { + return (name != null && name.startsWith(GNU_JAVA_MIME_PREFIX)); + } + + /** + * Decodes a String native for use as a Java MIME type. + * + * @param name the String to decode + * @return the decoded Java MIME type, or null if nat + * is not an encoded String native + */ + public static String decodeJavaMIMEType (String name) + { + if (isJavaMIMEType(name)) + { + return name.substring(GNU_JAVA_MIME_PREFIX.length()); + } + else + return null; + } + + /** + * Returns the data flavor given the native type name + * or null when no such data flavor exists. + */ + public static DataFlavor decodeDataFlavor (String name) + throws ClassNotFoundException + { + String javaMIMEType = decodeJavaMIMEType (name); + + if (javaMIMEType != null) + return new DataFlavor (javaMIMEType); + else + return null; + } + + /** + * Returns a List of DataFlavors to which the specified + * String native can be translated by the data transfer + * subsystem. The List will be sorted from best + * DataFlavor to worst. That is, the first DataFlavor + * will best reflect data in the specified native to a Java + * application. + *

+ * If the specified native is previously unknown to the data transfer + * subsystem, and that native has been properly encoded, then invoking + * this method will establish a mapping in both directions between the + * specified native and a DataFlavor whose MIME type is a decoded + * version of the native. + */ + public List getFlavorsForNative(String nat) + { + List ret = new ArrayList(); + if (nat == null) + { + Collection> all = nativeToFlavorMap.values(); + for (List list : all) + { + for (DataFlavor flav : list) + { + if (! ret.contains(flav)) + ret.add(flav); + } + } + } + else + { + List list = nativeToFlavorMap.get(nat); + if (list != null) + ret.addAll(list); + } + return ret; + } + + public List getNativesForFlavor (DataFlavor flav) + { + List ret = new ArrayList(); + if (flav == null) + { + Collection> all = flavorToNativeMap.values(); + for (List list : all) + { + for (String nat : list) + { + if (! ret.contains(nat)) + ret.add(nat); + } + } + } + else + { + List list = flavorToNativeMap.get(flav); + if (list != null) + ret.addAll(list); + } + return ret; + } + + /** + * Adds a mapping from a single String native to a single + * DataFlavor. Unlike getFlavorsForNative, the + * mapping will only be established in one direction, and the native will + * not be encoded. To establish a two-way mapping, call + * addUnencodedNativeForFlavor as well. The new mapping will + * be of lower priority than any existing mapping. + * This method has no effect if a mapping from the specified + * String native to the specified or equal + * DataFlavor already exists. + * + * @param nativeStr the String native key for the mapping + * @param flavor the DataFlavor value for the mapping + * @throws NullPointerException if nat or flav is null + * + * @see #addUnencodedNativeForFlavor + * @since 1.4 + */ + public synchronized void addFlavorForUnencodedNative(String nativeStr, + DataFlavor flavor) + { + if ((nativeStr == null) || (flavor == null)) + throw new NullPointerException(); + List flavors = nativeToFlavorMap.get(nativeStr); + if (flavors == null) + { + flavors = new ArrayList(); + nativeToFlavorMap.put(nativeStr, flavors); + } + else + { + if (! flavors.contains(flavor)) + flavors.add(flavor); + } + } + + /** + * Adds a mapping from the specified DataFlavor (and all + * DataFlavors equal to the specified DataFlavor) + * to the specified String native. + * Unlike getNativesForFlavor, the mapping will only be + * established in one direction, and the native will not be encoded. To + * establish a two-way mapping, call + * addFlavorForUnencodedNative as well. The new mapping will + * be of lower priority than any existing mapping. + * This method has no effect if a mapping from the specified or equal + * DataFlavor to the specified String native + * already exists. + * + * @param flavor the DataFlavor key for the mapping + * @param nativeStr the String native value for the mapping + * @throws NullPointerException if flav or nat is null + * + * @see #addFlavorForUnencodedNative + * @since 1.4 + */ + public synchronized void addUnencodedNativeForFlavor(DataFlavor flavor, + String nativeStr) + { + if ((nativeStr == null) || (flavor == null)) + throw new NullPointerException(); + List natives = flavorToNativeMap.get(flavor); + if (natives == null) + { + natives = new ArrayList(); + flavorToNativeMap.put(flavor, natives); + } + else + { + if (! natives.contains(nativeStr)) + natives.add(nativeStr); + } + } + + /** + * Discards the current mappings for the specified DataFlavor + * and all DataFlavors equal to the specified + * DataFlavor, and creates new mappings to the + * specified String natives. + * Unlike getNativesForFlavor, the mappings will only be + * established in one direction, and the natives will not be encoded. To + * establish two-way mappings, call setFlavorsForNative + * as well. The first native in the array will represent the highest + * priority mapping. Subsequent natives will represent mappings of + * decreasing priority. + *

+ * If the array contains several elements that reference equal + * String natives, this method will establish new mappings + * for the first of those elements and ignore the rest of them. + *

+ * It is recommended that client code not reset mappings established by the + * data transfer subsystem. This method should only be used for + * application-level mappings. + * + * @param flavor the DataFlavor key for the mappings + * @param natives the String native values for the mappings + * @throws NullPointerException if flav or natives is null + * or if natives contains null elements + * + * @see #setFlavorsForNative + * @since 1.4 + */ + public synchronized void setNativesForFlavor(DataFlavor flavor, + String[] natives) + { + if ((natives == null) || (flavor == null)) + throw new NullPointerException(); + + flavorToNativeMap.remove(flavor); + for (int i = 0; i < natives.length; i++) + { + addUnencodedNativeForFlavor(flavor, natives[i]); + } + } + + /** + * Discards the current mappings for the specified String + * native, and creates new mappings to the specified + * DataFlavors. Unlike getFlavorsForNative, the + * mappings will only be established in one direction, and the natives need + * not be encoded. To establish two-way mappings, call + * setNativesForFlavor as well. The first + * DataFlavor in the array will represent the highest priority + * mapping. Subsequent DataFlavors will represent mappings of + * decreasing priority. + *

+ * If the array contains several elements that reference equal + * DataFlavors, this method will establish new mappings + * for the first of those elements and ignore the rest of them. + *

+ * It is recommended that client code not reset mappings established by the + * data transfer subsystem. This method should only be used for + * application-level mappings. + * + * @param nativeStr the String native key for the mappings + * @param flavors the DataFlavor values for the mappings + * @throws NullPointerException if nat or flavors is null + * or if flavors contains null elements + * + * @see #setNativesForFlavor + * @since 1.4 + */ + public synchronized void setFlavorsForNative(String nativeStr, + DataFlavor[] flavors) + { + if ((nativeStr == null) || (flavors == null)) + throw new NullPointerException(); + + nativeToFlavorMap.remove(nativeStr); + for (int i = 0; i < flavors.length; i++) + { + addFlavorForUnencodedNative(nativeStr, flavors[i]); + } + } + +} // class SystemFlavorMap diff --git a/libjava/classpath/java/awt/datatransfer/Transferable.java b/libjava/classpath/java/awt/datatransfer/Transferable.java new file mode 100644 index 000000000..99239fcc6 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/Transferable.java @@ -0,0 +1,82 @@ +/* Transferable.java -- Data transfer source + Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +import java.io.IOException; + +/** + * This interface is implemented by classes that can transfer data. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @since 1.1 + * @status updated to 1.4 + */ +public interface Transferable +{ + /** + * This method returns a list of available data flavors for the data being + * transferred. The array returned will be sorted from most preferred + * flavor at the beginning to least preferred at the end. + * + * @return adA list of data flavors for this data + */ + DataFlavor[] getTransferDataFlavors(); + + /** + * Tests whether or not this data can be delivered in the specified data + * flavor. + * + * @param flavor the data flavor to test + * @return true if the data flavor is supported + */ + boolean isDataFlavorSupported(DataFlavor flavor); + + /** + * Returns the data in the specified DataFlavor. + * + * @param flavor the data flavor to return + * @return the data in the appropriate flavor + * @throws UnsupportedFlavorException if the flavor is not supported + * @throws IOException if the data is not available + * @see DataFlavor#getRepresentationClass + */ + Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException; + +} // interface Transferable diff --git a/libjava/classpath/java/awt/datatransfer/UnsupportedFlavorException.java b/libjava/classpath/java/awt/datatransfer/UnsupportedFlavorException.java new file mode 100644 index 000000000..0ca17b2e9 --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/UnsupportedFlavorException.java @@ -0,0 +1,65 @@ +/* UnsupportedFlavorException.java -- ata flavor is not valid + Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.awt.datatransfer; + +/** + * The data flavor requested is not supported for the transfer data. + * + * @author Aaron M. Renn (arenn@urbanophile.com) + * @see Transferable#getTransferData(DataFlavor) + * @status updated to 1.4 + */ +public class UnsupportedFlavorException extends Exception +{ + /** + * Compatible with JDK 1.1+. + */ + private static final long serialVersionUID = 5383814944251665601L; + + /** + * Initializes a new instance of UnsupportedDataFlavor + * for the specified data flavor. + * + * @param flavor the data flavor that is not supported + */ + public UnsupportedFlavorException(DataFlavor flavor) + { + super(flavor == null ? null : flavor.getHumanPresentableName()); + } +} // class UnsupportedFlavorException diff --git a/libjava/classpath/java/awt/datatransfer/package.html b/libjava/classpath/java/awt/datatransfer/package.html new file mode 100644 index 000000000..5ab860cdc --- /dev/null +++ b/libjava/classpath/java/awt/datatransfer/package.html @@ -0,0 +1,47 @@ + + + + +GNU Classpath - java.awt.datatransfer + + +

Classes to represent different flavors of data for transferring native +and system types through for example a clipboard.

+ + + -- cgit v1.2.3