java.awt.datatransfer
Class DataFlavor
- Cloneable, Externalizable, Serializable
This class represents a particular data format used for transferring
data via the clipboard.
DataFlavor() - Empty public constructor needed for externalization.
|
DataFlavor(Class> representationClass, String humanPresentableName) - Initializes a new instance of
DataFlavor .
|
DataFlavor(String mimeType) - Initializes a new instance of
DataFlavor with the specified
MIME type.
|
DataFlavor(String mimeType, String humanPresentableName) - Initializes a new instance of
DataFlavor with the
specified MIME type and description.
|
DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) - Initializes a new instance of
DataFlavor with the
specified MIME type and description.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
imageFlavor
public static final DataFlavor imageFlavor
This is an image flavor used for transferring images. The
representation type is a java.awt.Image
.
javaFileListFlavor
public static final DataFlavor javaFileListFlavor
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
.
javaJVMLocalObjectMimeType
public static final String javaJVMLocalObjectMimeType
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.
- "application/x-java-jvm-local-objectref"
javaRemoteObjectMimeType
public static final String javaRemoteObjectMimeType
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.
- "application/x-java-remote-object"
javaSerializedObjectMimeType
public static final String javaSerializedObjectMimeType
This is the MIME type used for transferring a serialized object.
The representation class is the type of object be deserialized.
- "application/x-java-serialized-object"
plainTextFlavor
public static final DataFlavor plainTextFlavor
The charset unicode is platform specific and InputStream
deals with bytes not chars. Use getRederForText()
.
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
.
stringFlavor
public static final DataFlavor stringFlavor
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
.
DataFlavor
public DataFlavor()
Empty public constructor needed for externalization.
Should not be used for normal instantiation.
DataFlavor
public DataFlavor(Class> representationClass,
String humanPresentableName)
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.
representationClass
- The representation class for this object.humanPresentableName
- The display name of the object.
DataFlavor
public DataFlavor(String mimeType)
throws ClassNotFoundException
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)
.
mimeType
- The MIME type for this flavor.
DataFlavor
public DataFlavor(String mimeType,
String humanPresentableName)
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)
.
mimeType
- The MIME type for this flavor.humanPresentableName
- The display name of this flavor.
DataFlavor
public DataFlavor(String mimeType,
String humanPresentableName,
ClassLoader classLoader)
throws ClassNotFoundException
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.
mimeType
- The MIME type for this flavor.humanPresentableName
- The display name of this flavor.classLoader
- The class loader for finding classes if the default
class loaders do not work.
equals
public boolean equals(DataFlavor flavor)
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.
flavor
- The DataFlavor
to test against.
true
if the flavor is equal to this object,
false
otherwise.
equals
public boolean equals(Object obj)
This method test the specified
Object
for equality
against this object. This will be true if the following conditions
are met:
- The object is not
null
. - The object is an instance of
DataFlavor
. - The object's MIME type and representation class are equal to
this object's.
- equals in interface Object
obj
- The Object
to test against.
true
if the flavor is equal to this object,
false
otherwise.
equals
public boolean equals(String str)
Not compatible with hashCode()
.
Use isMimeTypeEqual()
Tests whether or not the specified string is equal to the MIME type
of this object.
str
- The string to test against.
true
if the string is equal to this object's MIME
type, false
otherwise.
getHumanPresentableName
public String getHumanPresentableName()
Returns the human presentable name for this flavor.
- The human presentable name for this flavor.
getMimeType
public String getMimeType()
Returns the MIME type of this flavor.
- The MIME type for this flavor.
getParameter
public String getParameter(String paramName)
Returns the value of the named MIME type parameter, or null
if the parameter does not exist.
paramName
- The name of the paramter.
- The value of the parameter.
getPrimaryType
public String getPrimaryType()
Returns the primary MIME type for this flavor.
- The primary MIME type for this flavor.
getReaderForText
public Reader getReaderForText(Transferable transferable)
throws UnsupportedFlavorException,
IOException
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.
transferable
- The Transferable
for which a text
Reader
is requested.
IllegalArgumentException
- If the representation class is not one
of the seven listed above or the Transferable has null data.NullPointerException
- If the Transferable is null.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".IOException
- when any IOException occurs.
getRepresentationClass
public Class> getRepresentationClass()
Returns the representation class for this flavor.
- The representation class for this flavor.
getSubType
public String getSubType()
Returns the MIME subtype for this flavor.
- The MIME subtype for this flavor.
hashCode
public int hashCode()
Returns the hash code for this data flavor.
The hash code is based on the (lower case) mime type and the
representation class.
- hashCode in interface Object
isFlavorJavaFileListType
public boolean isFlavorJavaFileListType()
Tests whether or not this flavor represents a list of files.
true
if this flavor represents a list of files,
false
otherwise.
isFlavorRemoteObjectType
public boolean isFlavorRemoteObjectType()
Tests whether or not this flavor represents a remote object.
true
if this flavor represents a remote object,
false
otherwise.
isFlavorSerializedObjectType
public boolean isFlavorSerializedObjectType()
Tests whether or not this flavor represents a serialized object.
true
if this flavor represents a serialized
object, false
otherwise.
isFlavorTextType
public boolean isFlavorTextType()
Returns whether this
DataFlavor
is a valid text flavor for
this implementation of the Java platform. Only flavors equivalent to
DataFlavor.stringFlavor
and
DataFlavor
s 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.
true
if this DataFlavor
is a valid
text flavor as described above; false
otherwise
isMimeTypeEqual
public final boolean isMimeTypeEqual(DataFlavor flavor)
Tests the MIME type of this object for equality against the specified
data flavor's MIME type
flavor
- The flavor to test against.
true
if the flavor's MIME type is equal to this
object's MIME type, false
otherwise.
isMimeTypeEqual
public boolean isMimeTypeEqual(String mimeType)
Tests the MIME type of this object for equality against the specified
MIME type. Ignores parameters.
mimeType
- The MIME type to test against.
true
if the MIME type is equal to this object's
MIME type (ignoring parameters), false
otherwise.
isMimeTypeSerializedObject
public boolean isMimeTypeSerializedObject()
Tests whether or not this flavor represents a serialized object.
true
if this flavor represents a serialized
object, false
otherwise.
isRepresentationClassInputStream
public boolean isRepresentationClassInputStream()
Tests whether or not this flavor has a representation class of
java.io.InputStream
.
true
if the representation class of this flavor
is java.io.InputStream
, false
otherwise.
isRepresentationClassReader
public boolean isRepresentationClassReader()
Returns whether the representation class for this DataFlavor is
isRepresentationClassRemote
public boolean isRepresentationClassRemote()
Tests whether the representation class for his flavor is remote.
true
if the representation class is remote,
false
otherwise.
isRepresentationClassSerializable
public boolean isRepresentationClassSerializable()
Tests whether the representation class for this flavor is
serializable.
true
if the representation class is serializable,
false
otherwise.
match
public boolean match(DataFlavor dataFlavor)
Returns true
when the given DataFlavor
matches this one.
normalizeMimeType
protected String normalizeMimeType(String type)
This method exists for backward compatibility. It simply returns
the MIME type string unchanged.
normalizeMimeTypeParameter
protected String normalizeMimeTypeParameter(String name,
String value)
This method exists for backward compatibility. It simply returns
the same name/value pair passed in.
name
- The parameter name.value
- The parameter value.
selectBestTextFlavor
public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)
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.
setHumanPresentableName
public void setHumanPresentableName(String humanPresentableName)
Sets the human presentable name to the specified value.
humanPresentableName
- The new display name.
toString
public String toString()
Returns a string representation of this DataFlavor. Including the
representation class name, MIME type and human presentable name.
- toString in interface Object
tryToLoadClass
protected static final Class> tryToLoadClass(String className,
ClassLoader classLoader)
throws ClassNotFoundException
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.
className
- The name of the class to load.classLoader
- The class loader to use if all others fail, which
may be null
.
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.