feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
353
jdkSrc/jdk8/java/awt/datatransfer/Clipboard.java
Normal file
353
jdkSrc/jdk8/java/awt/datatransfer/Clipboard.java
Normal file
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import sun.awt.EventListenerAggregate;
|
||||
|
||||
/**
|
||||
* A class that implements a mechanism to transfer data using
|
||||
* cut/copy/paste operations.
|
||||
* <p>
|
||||
* {@link FlavorListener}s may be registered on an instance of the
|
||||
* Clipboard class to be notified about changes to the set of
|
||||
* {@link DataFlavor}s available on this clipboard (see
|
||||
* {@link #addFlavorListener}).
|
||||
*
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
* @see java.awt.Toolkit#getSystemSelection
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @author Alexander Gerasimov
|
||||
*/
|
||||
public class Clipboard {
|
||||
|
||||
String name;
|
||||
|
||||
protected ClipboardOwner owner;
|
||||
protected Transferable contents;
|
||||
|
||||
/**
|
||||
* An aggregate of flavor listeners registered on this local clipboard.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private EventListenerAggregate flavorListeners;
|
||||
|
||||
/**
|
||||
* A set of <code>DataFlavor</code>s that is available on
|
||||
* this local clipboard. It is used for tracking changes
|
||||
* of <code>DataFlavor</code>s available on this clipboard.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private Set<DataFlavor> currentDataFlavors;
|
||||
|
||||
/**
|
||||
* Creates a clipboard object.
|
||||
*
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public Clipboard(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this clipboard object.
|
||||
*
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current contents of the clipboard to the specified
|
||||
* transferable object and registers the specified clipboard owner
|
||||
* as the owner of the new contents.
|
||||
* <p>
|
||||
* If there is an existing owner different from the argument
|
||||
* <code>owner</code>, that owner is notified that it no longer
|
||||
* holds ownership of the clipboard contents via an invocation
|
||||
* of <code>ClipboardOwner.lostOwnership()</code> on that owner.
|
||||
* An implementation of <code>setContents()</code> is free not
|
||||
* to invoke <code>lostOwnership()</code> directly from this method.
|
||||
* For example, <code>lostOwnership()</code> may be invoked later on
|
||||
* a different thread. The same applies to <code>FlavorListener</code>s
|
||||
* registered on this clipboard.
|
||||
* <p>
|
||||
* The method throws <code>IllegalStateException</code> if the clipboard
|
||||
* is currently unavailable. For example, on some platforms, the system
|
||||
* clipboard is unavailable while it is accessed by another application.
|
||||
*
|
||||
* @param contents the transferable object representing the
|
||||
* clipboard content
|
||||
* @param owner the object which owns the clipboard content
|
||||
* @throws IllegalStateException if the clipboard is currently unavailable
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public synchronized void setContents(Transferable contents, ClipboardOwner owner) {
|
||||
final ClipboardOwner oldOwner = this.owner;
|
||||
final Transferable oldContents = this.contents;
|
||||
|
||||
this.owner = owner;
|
||||
this.contents = contents;
|
||||
|
||||
if (oldOwner != null && oldOwner != owner) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
oldOwner.lostOwnership(Clipboard.this, oldContents);
|
||||
}
|
||||
});
|
||||
}
|
||||
fireFlavorsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a transferable object representing the current contents
|
||||
* of the clipboard. If the clipboard currently has no contents,
|
||||
* it returns <code>null</code>. The parameter Object requestor is
|
||||
* not currently used. The method throws
|
||||
* <code>IllegalStateException</code> if the clipboard is currently
|
||||
* unavailable. For example, on some platforms, the system clipboard is
|
||||
* unavailable while it is accessed by another application.
|
||||
*
|
||||
* @param requestor the object requesting the clip data (not used)
|
||||
* @return the current transferable object on the clipboard
|
||||
* @throws IllegalStateException if the clipboard is currently unavailable
|
||||
* @see java.awt.Toolkit#getSystemClipboard
|
||||
*/
|
||||
public synchronized Transferable getContents(Object requestor) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of <code>DataFlavor</code>s in which the current
|
||||
* contents of this clipboard can be provided. If there are no
|
||||
* <code>DataFlavor</code>s available, this method returns a zero-length
|
||||
* array.
|
||||
*
|
||||
* @return an array of <code>DataFlavor</code>s in which the current
|
||||
* contents of this clipboard can be provided
|
||||
*
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public DataFlavor[] getAvailableDataFlavors() {
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
return new DataFlavor[0];
|
||||
}
|
||||
return cntnts.getTransferDataFlavors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the current contents of this clipboard can be
|
||||
* provided in the specified <code>DataFlavor</code>.
|
||||
*
|
||||
* @param flavor the requested <code>DataFlavor</code> for the contents
|
||||
*
|
||||
* @return <code>true</code> if the current contents of this clipboard
|
||||
* can be provided in the specified <code>DataFlavor</code>;
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
* @throws NullPointerException if <code>flavor</code> is <code>null</code>
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public boolean isDataFlavorAvailable(DataFlavor flavor) {
|
||||
if (flavor == null) {
|
||||
throw new NullPointerException("flavor");
|
||||
}
|
||||
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
return false;
|
||||
}
|
||||
return cntnts.isDataFlavorSupported(flavor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object representing the current contents of this clipboard
|
||||
* in the specified <code>DataFlavor</code>.
|
||||
* The class of the object returned is defined by the representation
|
||||
* class of <code>flavor</code>.
|
||||
*
|
||||
* @param flavor the requested <code>DataFlavor</code> for the contents
|
||||
*
|
||||
* @return an object representing the current contents of this clipboard
|
||||
* in the specified <code>DataFlavor</code>
|
||||
*
|
||||
* @throws NullPointerException if <code>flavor</code> is <code>null</code>
|
||||
* @throws IllegalStateException if this clipboard is currently unavailable
|
||||
* @throws UnsupportedFlavorException if the requested <code>DataFlavor</code>
|
||||
* is not available
|
||||
* @throws IOException if the data in the requested <code>DataFlavor</code>
|
||||
* can not be retrieved
|
||||
*
|
||||
* @see DataFlavor#getRepresentationClass
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public Object getData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException, IOException {
|
||||
if (flavor == null) {
|
||||
throw new NullPointerException("flavor");
|
||||
}
|
||||
|
||||
Transferable cntnts = getContents(null);
|
||||
if (cntnts == null) {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
return cntnts.getTransferData(flavor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers the specified <code>FlavorListener</code> to receive
|
||||
* <code>FlavorEvent</code>s from this clipboard.
|
||||
* If <code>listener</code> is <code>null</code>, no exception
|
||||
* is thrown and no action is performed.
|
||||
*
|
||||
* @param listener the listener to be added
|
||||
*
|
||||
* @see #removeFlavorListener
|
||||
* @see #getFlavorListeners
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized void addFlavorListener(FlavorListener listener) {
|
||||
if (listener == null) {
|
||||
return;
|
||||
}
|
||||
if (flavorListeners == null) {
|
||||
currentDataFlavors = getAvailableDataFlavorSet();
|
||||
flavorListeners = new EventListenerAggregate(FlavorListener.class);
|
||||
}
|
||||
flavorListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified <code>FlavorListener</code> so that it no longer
|
||||
* receives <code>FlavorEvent</code>s from this <code>Clipboard</code>.
|
||||
* This method performs no function, nor does it throw an exception, if
|
||||
* the listener specified by the argument was not previously added to this
|
||||
* <code>Clipboard</code>.
|
||||
* If <code>listener</code> is <code>null</code>, no exception
|
||||
* is thrown and no action is performed.
|
||||
*
|
||||
* @param listener the listener to be removed
|
||||
*
|
||||
* @see #addFlavorListener
|
||||
* @see #getFlavorListeners
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized void removeFlavorListener(FlavorListener listener) {
|
||||
if (listener == null || flavorListeners == null) {
|
||||
return;
|
||||
}
|
||||
flavorListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the <code>FlavorListener</code>s currently
|
||||
* registered on this <code>Clipboard</code>.
|
||||
*
|
||||
* @return all of this clipboard's <code>FlavorListener</code>s or an empty
|
||||
* array if no listeners are currently registered
|
||||
* @see #addFlavorListener
|
||||
* @see #removeFlavorListener
|
||||
* @see FlavorListener
|
||||
* @see FlavorEvent
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized FlavorListener[] getFlavorListeners() {
|
||||
return flavorListeners == null ? new FlavorListener[0] :
|
||||
(FlavorListener[])flavorListeners.getListenersCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks change of the <code>DataFlavor</code>s and, if necessary,
|
||||
* notifies all listeners that have registered interest for notification
|
||||
* on <code>FlavorEvent</code>s.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private void fireFlavorsChanged() {
|
||||
if (flavorListeners == null) {
|
||||
return;
|
||||
}
|
||||
Set<DataFlavor> prevDataFlavors = currentDataFlavors;
|
||||
currentDataFlavors = getAvailableDataFlavorSet();
|
||||
if (prevDataFlavors.equals(currentDataFlavors)) {
|
||||
return;
|
||||
}
|
||||
FlavorListener[] flavorListenerArray =
|
||||
(FlavorListener[])flavorListeners.getListenersInternal();
|
||||
for (int i = 0; i < flavorListenerArray.length; i++) {
|
||||
final FlavorListener listener = flavorListenerArray[i];
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
listener.flavorsChanged(new FlavorEvent(Clipboard.this));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of <code>DataFlavor</code>s currently available
|
||||
* on this clipboard.
|
||||
*
|
||||
* @return a set of <code>DataFlavor</code>s currently available
|
||||
* on this clipboard
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
private Set<DataFlavor> getAvailableDataFlavorSet() {
|
||||
Set<DataFlavor> set = new HashSet<>();
|
||||
Transferable contents = getContents(null);
|
||||
if (contents != null) {
|
||||
DataFlavor[] flavors = contents.getTransferDataFlavors();
|
||||
if (flavors != null) {
|
||||
set.addAll(Arrays.asList(flavors));
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
}
|
||||
56
jdkSrc/jdk8/java/awt/datatransfer/ClipboardOwner.java
Normal file
56
jdkSrc/jdk8/java/awt/datatransfer/ClipboardOwner.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
/**
|
||||
* Defines the interface for classes that will provide data to
|
||||
* a clipboard. An instance of this interface becomes the owner
|
||||
* of the contents of a clipboard (clipboard owner) if it is
|
||||
* passed as an argument to
|
||||
* {@link java.awt.datatransfer.Clipboard#setContents} method of
|
||||
* the clipboard and this method returns successfully.
|
||||
* The instance remains the clipboard owner until another application
|
||||
* or another object within this application asserts ownership
|
||||
* of this clipboard.
|
||||
*
|
||||
* @see java.awt.datatransfer.Clipboard
|
||||
*
|
||||
* @author Amy Fowler
|
||||
*/
|
||||
|
||||
public interface ClipboardOwner {
|
||||
|
||||
/**
|
||||
* Notifies this object that it is no longer the clipboard owner.
|
||||
* This method will be called when another application or another
|
||||
* object within this application asserts ownership of the clipboard.
|
||||
*
|
||||
* @param clipboard the clipboard that is no longer owned
|
||||
* @param contents the contents which this owner had placed on the clipboard
|
||||
*/
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents);
|
||||
|
||||
}
|
||||
1465
jdkSrc/jdk8/java/awt/datatransfer/DataFlavor.java
Normal file
1465
jdkSrc/jdk8/java/awt/datatransfer/DataFlavor.java
Normal file
File diff suppressed because it is too large
Load Diff
51
jdkSrc/jdk8/java/awt/datatransfer/FlavorEvent.java
Normal file
51
jdkSrc/jdk8/java/awt/datatransfer/FlavorEvent.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
|
||||
/**
|
||||
* <code>FlavorEvent</code> is used to notify interested parties
|
||||
* that available {@link DataFlavor}s have changed in the
|
||||
* {@link Clipboard} (the event source).
|
||||
*
|
||||
* @see FlavorListener
|
||||
*
|
||||
* @author Alexander Gerasimov
|
||||
* @since 1.5
|
||||
*/
|
||||
public class FlavorEvent extends EventObject {
|
||||
/**
|
||||
* Constructs a <code>FlavorEvent</code> object.
|
||||
*
|
||||
* @param source the <code>Clipboard</code> that is the source of the event
|
||||
*
|
||||
* @throws IllegalArgumentException if the {@code source} is {@code null}
|
||||
*/
|
||||
public FlavorEvent(Clipboard source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
55
jdkSrc/jdk8/java/awt/datatransfer/FlavorListener.java
Normal file
55
jdkSrc/jdk8/java/awt/datatransfer/FlavorListener.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
|
||||
/**
|
||||
* Defines an object which listens for {@link FlavorEvent}s.
|
||||
*
|
||||
* @author Alexander Gerasimov
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface FlavorListener extends EventListener {
|
||||
/**
|
||||
* Invoked when the target {@link Clipboard} of the listener
|
||||
* has changed its available {@link DataFlavor}s.
|
||||
* <p>
|
||||
* Some notifications may be redundant — they are not
|
||||
* caused by a change of the set of DataFlavors available
|
||||
* on the clipboard.
|
||||
* For example, if the clipboard subsystem supposes that
|
||||
* the system clipboard's contents has been changed but it
|
||||
* can't ascertain whether its DataFlavors have been changed
|
||||
* because of some exceptional condition when accessing the
|
||||
* clipboard, the notification is sent to ensure from omitting
|
||||
* a significant notification. Ordinarily, those redundant
|
||||
* notifications should be occasional.
|
||||
*
|
||||
* @param e a <code>FlavorEvent</code> object
|
||||
*/
|
||||
void flavorsChanged(FlavorEvent e);
|
||||
}
|
||||
75
jdkSrc/jdk8/java/awt/datatransfer/FlavorMap.java
Normal file
75
jdkSrc/jdk8/java/awt/datatransfer/FlavorMap.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* A two-way Map between "natives" (Strings), which correspond to platform-
|
||||
* specific data formats, and "flavors" (DataFlavors), which correspond to
|
||||
* platform-independent MIME types. FlavorMaps need not be symmetric, but
|
||||
* typically are.
|
||||
*
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public interface FlavorMap {
|
||||
|
||||
/**
|
||||
* Returns a <code>Map</code> of the specified <code>DataFlavor</code>s to
|
||||
* their corresponding <code>String</code> native. The returned
|
||||
* <code>Map</code> is a modifiable copy of this <code>FlavorMap</code>'s
|
||||
* internal data. Client code is free to modify the <code>Map</code>
|
||||
* without affecting this object.
|
||||
*
|
||||
* @param flavors an array of <code>DataFlavor</code>s which will be the
|
||||
* key set of the returned <code>Map</code>. If <code>null</code> is
|
||||
* specified, a mapping of all <code>DataFlavor</code>s currently
|
||||
* known to this <code>FlavorMap</code> to their corresponding
|
||||
* <code>String</code> natives will be returned.
|
||||
* @return a <code>java.util.Map</code> of <code>DataFlavor</code>s to
|
||||
* <code>String</code> natives
|
||||
*/
|
||||
Map<DataFlavor,String> getNativesForFlavors(DataFlavor[] flavors);
|
||||
|
||||
/**
|
||||
* Returns a <code>Map</code> of the specified <code>String</code> natives
|
||||
* to their corresponding <code>DataFlavor</code>. The returned
|
||||
* <code>Map</code> is a modifiable copy of this <code>FlavorMap</code>'s
|
||||
* internal data. Client code is free to modify the <code>Map</code>
|
||||
* without affecting this object.
|
||||
*
|
||||
* @param natives an array of <code>String</code>s which will be the
|
||||
* key set of the returned <code>Map</code>. If <code>null</code> is
|
||||
* specified, a mapping of all <code>String</code> natives currently
|
||||
* known to this <code>FlavorMap</code> to their corresponding
|
||||
* <code>DataFlavor</code>s will be returned.
|
||||
* @return a <code>java.util.Map</code> of <code>String</code> natives to
|
||||
* <code>DataFlavor</code>s
|
||||
*/
|
||||
Map<String,DataFlavor> getFlavorsForNatives(String[] natives);
|
||||
}
|
||||
82
jdkSrc/jdk8/java/awt/datatransfer/FlavorTable.java
Normal file
82
jdkSrc/jdk8/java/awt/datatransfer/FlavorTable.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A FlavorMap which relaxes the traditional 1-to-1 restriction of a Map. A
|
||||
* flavor is permitted to map to any number of natives, and likewise a native
|
||||
* is permitted to map to any number of flavors. FlavorTables need not be
|
||||
* symmetric, but typically are.
|
||||
*
|
||||
* @author David Mendenhall
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface FlavorTable extends FlavorMap {
|
||||
|
||||
/**
|
||||
* Returns a <code>List</code> of <code>String</code> natives to which the
|
||||
* specified <code>DataFlavor</code> corresponds. The <code>List</code>
|
||||
* will be sorted from best native to worst. That is, the first native will
|
||||
* best reflect data in the specified flavor to the underlying native
|
||||
* platform. The returned <code>List</code> is a modifiable copy of this
|
||||
* <code>FlavorTable</code>'s internal data. Client code is free to modify
|
||||
* the <code>List</code> without affecting this object.
|
||||
*
|
||||
* @param flav the <code>DataFlavor</code> whose corresponding natives
|
||||
* should be returned. If <code>null</code> is specified, all
|
||||
* natives currently known to this <code>FlavorTable</code> are
|
||||
* returned in a non-deterministic order.
|
||||
* @return a <code>java.util.List</code> of <code>java.lang.String</code>
|
||||
* objects which are platform-specific representations of platform-
|
||||
* specific data formats
|
||||
*/
|
||||
List<String> getNativesForFlavor(DataFlavor flav);
|
||||
|
||||
/**
|
||||
* Returns a <code>List</code> of <code>DataFlavor</code>s to which the
|
||||
* specified <code>String</code> corresponds. The <code>List</code> will be
|
||||
* sorted from best <code>DataFlavor</code> to worst. That is, the first
|
||||
* <code>DataFlavor</code> will best reflect data in the specified
|
||||
* native to a Java application. The returned <code>List</code> is a
|
||||
* modifiable copy of this <code>FlavorTable</code>'s internal data.
|
||||
* Client code is free to modify the <code>List</code> without affecting
|
||||
* this object.
|
||||
*
|
||||
* @param nat the native whose corresponding <code>DataFlavor</code>s
|
||||
* should be returned. If <code>null</code> is specified, all
|
||||
* <code>DataFlavor</code>s currently known to this
|
||||
* <code>FlavorTable</code> are returned in a non-deterministic
|
||||
* order.
|
||||
* @return a <code>java.util.List</code> of <code>DataFlavor</code>
|
||||
* objects into which platform-specific data in the specified,
|
||||
* platform-specific native can be translated
|
||||
*/
|
||||
List<DataFlavor> getFlavorsForNative(String nat);
|
||||
}
|
||||
398
jdkSrc/jdk8/java/awt/datatransfer/MimeType.java
Normal file
398
jdkSrc/jdk8/java/awt/datatransfer/MimeType.java
Normal file
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
* A Multipurpose Internet Mail Extension (MIME) type, as defined
|
||||
* in RFC 2045 and 2046.
|
||||
*
|
||||
* THIS IS *NOT* - REPEAT *NOT* - A PUBLIC CLASS! DataFlavor IS
|
||||
* THE PUBLIC INTERFACE, AND THIS IS PROVIDED AS A ***PRIVATE***
|
||||
* (THAT IS AS IN *NOT* PUBLIC) HELPER CLASS!
|
||||
*/
|
||||
class MimeType implements Externalizable, Cloneable {
|
||||
|
||||
/*
|
||||
* serialization support
|
||||
*/
|
||||
|
||||
static final long serialVersionUID = -6568722458793895906L;
|
||||
|
||||
/**
|
||||
* Constructor for externalization; this constructor should not be
|
||||
* called directly by an application, since the result will be an
|
||||
* uninitialized, immutable <code>MimeType</code> object.
|
||||
*/
|
||||
public MimeType() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a <code>MimeType</code> from a <code>String</code>.
|
||||
*
|
||||
* @param rawdata text used to initialize the <code>MimeType</code>
|
||||
* @throws NullPointerException if <code>rawdata</code> is null
|
||||
*/
|
||||
public MimeType(String rawdata) throws MimeTypeParseException {
|
||||
parse(rawdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a <code>MimeType</code> with the given primary and sub
|
||||
* type but has an empty parameter list.
|
||||
*
|
||||
* @param primary the primary type of this <code>MimeType</code>
|
||||
* @param sub the subtype of this <code>MimeType</code>
|
||||
* @throws NullPointerException if either <code>primary</code> or
|
||||
* <code>sub</code> is null
|
||||
*/
|
||||
public MimeType(String primary, String sub) throws MimeTypeParseException {
|
||||
this(primary, sub, new MimeTypeParameterList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a <code>MimeType</code> with a pre-defined
|
||||
* and valid (or empty) parameter list.
|
||||
*
|
||||
* @param primary the primary type of this <code>MimeType</code>
|
||||
* @param sub the subtype of this <code>MimeType</code>
|
||||
* @param mtpl the requested parameter list
|
||||
* @throws NullPointerException if either <code>primary</code>,
|
||||
* <code>sub</code> or <code>mtpl</code> is null
|
||||
*/
|
||||
public MimeType(String primary, String sub, MimeTypeParameterList mtpl) throws
|
||||
MimeTypeParseException {
|
||||
// check to see if primary is valid
|
||||
if(isValidToken(primary)) {
|
||||
primaryType = primary.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
}
|
||||
|
||||
// check to see if sub is valid
|
||||
if(isValidToken(sub)) {
|
||||
subType = sub.toLowerCase(Locale.ENGLISH);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
|
||||
parameters = (MimeTypeParameterList)mtpl.clone();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
// We sum up the hash codes for all of the strings. This
|
||||
// way, the order of the strings is irrelevant
|
||||
int code = 0;
|
||||
code += primaryType.hashCode();
|
||||
code += subType.hashCode();
|
||||
code += parameters.hashCode();
|
||||
return code;
|
||||
} // hashCode()
|
||||
|
||||
/**
|
||||
* <code>MimeType</code>s are equal if their primary types,
|
||||
* subtypes, and parameters are all equal. No default values
|
||||
* are taken into account.
|
||||
* @param thatObject the object to be evaluated as a
|
||||
* <code>MimeType</code>
|
||||
* @return <code>true</code> if <code>thatObject</code> is
|
||||
* a <code>MimeType</code>; otherwise returns <code>false</code>
|
||||
*/
|
||||
public boolean equals(Object thatObject) {
|
||||
if (!(thatObject instanceof MimeType)) {
|
||||
return false;
|
||||
}
|
||||
MimeType that = (MimeType)thatObject;
|
||||
boolean isIt =
|
||||
((this.primaryType.equals(that.primaryType)) &&
|
||||
(this.subType.equals(that.subType)) &&
|
||||
(this.parameters.equals(that.parameters)));
|
||||
return isIt;
|
||||
} // equals()
|
||||
|
||||
/**
|
||||
* A routine for parsing the MIME type out of a String.
|
||||
*
|
||||
* @throws NullPointerException if <code>rawdata</code> is null
|
||||
*/
|
||||
private void parse(String rawdata) throws MimeTypeParseException {
|
||||
int slashIndex = rawdata.indexOf('/');
|
||||
int semIndex = rawdata.indexOf(';');
|
||||
if((slashIndex < 0) && (semIndex < 0)) {
|
||||
// neither character is present, so treat it
|
||||
// as an error
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
} else if((slashIndex < 0) && (semIndex >= 0)) {
|
||||
// we have a ';' (and therefore a parameter list),
|
||||
// but no '/' indicating a sub type is present
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
} else if((slashIndex >= 0) && (semIndex < 0)) {
|
||||
// we have a primary and sub type but no parameter list
|
||||
primaryType = rawdata.substring(0,slashIndex).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
subType = rawdata.substring(slashIndex + 1).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
parameters = new MimeTypeParameterList();
|
||||
} else if (slashIndex < semIndex) {
|
||||
// we have all three items in the proper sequence
|
||||
primaryType = rawdata.substring(0, slashIndex).
|
||||
trim().toLowerCase(Locale.ENGLISH);
|
||||
subType = rawdata.substring(slashIndex + 1,
|
||||
semIndex).trim().toLowerCase(Locale.ENGLISH);
|
||||
parameters = new
|
||||
MimeTypeParameterList(rawdata.substring(semIndex));
|
||||
} else {
|
||||
// we have a ';' lexically before a '/' which means we have a primary type
|
||||
// & a parameter list but no sub type
|
||||
throw new MimeTypeParseException("Unable to find a sub type.");
|
||||
}
|
||||
|
||||
// now validate the primary and sub types
|
||||
|
||||
// check to see if primary is valid
|
||||
if(!isValidToken(primaryType)) {
|
||||
throw new MimeTypeParseException("Primary type is invalid.");
|
||||
}
|
||||
|
||||
// check to see if sub is valid
|
||||
if(!isValidToken(subType)) {
|
||||
throw new MimeTypeParseException("Sub type is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the primary type of this object.
|
||||
*/
|
||||
public String getPrimaryType() {
|
||||
return primaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the sub type of this object.
|
||||
*/
|
||||
public String getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a copy of this object's parameter list.
|
||||
*/
|
||||
public MimeTypeParameterList getParameters() {
|
||||
return (MimeTypeParameterList)parameters.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value associated with the given name, or null if there
|
||||
* is no current association.
|
||||
*/
|
||||
public String getParameter(String name) {
|
||||
return parameters.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to be associated with the given name, replacing
|
||||
* any previous association.
|
||||
*
|
||||
* @throw IllegalArgumentException if parameter or value is illegal
|
||||
*/
|
||||
public void setParameter(String name, String value) {
|
||||
parameters.set(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any value associated with the given name.
|
||||
*
|
||||
* @throw IllegalArgumentExcpetion if parameter may not be deleted
|
||||
*/
|
||||
public void removeParameter(String name) {
|
||||
parameters.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
return getBaseType() + parameters.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a String representation of this object
|
||||
* without the parameter list.
|
||||
*/
|
||||
public String getBaseType() {
|
||||
return primaryType + "/" + subType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the primary type and the
|
||||
* subtype of this object are the same as the specified
|
||||
* <code>type</code>; otherwise returns <code>false</code>.
|
||||
*
|
||||
* @param type the type to compare to <code>this</code>'s type
|
||||
* @return <code>true</code> if the primary type and the
|
||||
* subtype of this object are the same as the
|
||||
* specified <code>type</code>; otherwise returns
|
||||
* <code>false</code>
|
||||
*/
|
||||
public boolean match(MimeType type) {
|
||||
if (type == null)
|
||||
return false;
|
||||
return primaryType.equals(type.getPrimaryType())
|
||||
&& (subType.equals("*")
|
||||
|| type.getSubType().equals("*")
|
||||
|| (subType.equals(type.getSubType())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the primary type and the
|
||||
* subtype of this object are the same as the content type
|
||||
* described in <code>rawdata</code>; otherwise returns
|
||||
* <code>false</code>.
|
||||
*
|
||||
* @param rawdata the raw data to be examined
|
||||
* @return <code>true</code> if the primary type and the
|
||||
* subtype of this object are the same as the content type
|
||||
* described in <code>rawdata</code>; otherwise returns
|
||||
* <code>false</code>; if <code>rawdata</code> is
|
||||
* <code>null</code>, returns <code>false</code>
|
||||
*/
|
||||
public boolean match(String rawdata) throws MimeTypeParseException {
|
||||
if (rawdata == null)
|
||||
return false;
|
||||
return match(new MimeType(rawdata));
|
||||
}
|
||||
|
||||
/**
|
||||
* The object implements the writeExternal method to save its contents
|
||||
* by calling the methods of DataOutput for its primitive values or
|
||||
* calling the writeObject method of ObjectOutput for objects, strings
|
||||
* and arrays.
|
||||
* @exception IOException Includes any I/O exceptions that may occur
|
||||
*/
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
String s = toString(); // contains ASCII chars only
|
||||
// one-to-one correspondence between ASCII char and byte in UTF string
|
||||
if (s.length() <= 65535) { // 65535 is max length of UTF string
|
||||
out.writeUTF(s);
|
||||
} else {
|
||||
out.writeByte(0);
|
||||
out.writeByte(0);
|
||||
out.writeInt(s.length());
|
||||
out.write(s.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The object implements the readExternal method to restore its
|
||||
* contents by calling the methods of DataInput for primitive
|
||||
* types and readObject for objects, strings and arrays. The
|
||||
* readExternal method must read the values in the same sequence
|
||||
* and with the same types as were written by writeExternal.
|
||||
* @exception ClassNotFoundException If the class for an object being
|
||||
* restored cannot be found.
|
||||
*/
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
String s = in.readUTF();
|
||||
if (s == null || s.length() == 0) { // long mime type
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
int len = in.readInt();
|
||||
while (len-- > 0) {
|
||||
baos.write(in.readByte());
|
||||
}
|
||||
s = baos.toString();
|
||||
}
|
||||
try {
|
||||
parse(s);
|
||||
} catch(MimeTypeParseException e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of this object.
|
||||
* @return a clone of this object
|
||||
*/
|
||||
|
||||
public Object clone() {
|
||||
MimeType newObj = null;
|
||||
try {
|
||||
newObj = (MimeType)super.clone();
|
||||
} catch (CloneNotSupportedException cannotHappen) {
|
||||
}
|
||||
newObj.parameters = (MimeTypeParameterList)parameters.clone();
|
||||
return newObj;
|
||||
}
|
||||
|
||||
private String primaryType;
|
||||
private String subType;
|
||||
private MimeTypeParameterList parameters;
|
||||
|
||||
// below here be scary parsing related things
|
||||
|
||||
/**
|
||||
* Determines whether or not a given character belongs to a legal token.
|
||||
*/
|
||||
private static boolean isTokenChar(char c) {
|
||||
return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not a given string is a legal token.
|
||||
*
|
||||
* @throws NullPointerException if <code>s</code> is null
|
||||
*/
|
||||
private boolean isValidToken(String s) {
|
||||
int len = s.length();
|
||||
if(len > 0) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char c = s.charAt(i);
|
||||
if (!isTokenChar(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A string that holds all the special chars.
|
||||
*/
|
||||
|
||||
private static final String TSPECIALS = "()<>@,;:\\\"/[]?=";
|
||||
|
||||
} // class MimeType
|
||||
404
jdkSrc/jdk8/java/awt/datatransfer/MimeTypeParameterList.java
Normal file
404
jdkSrc/jdk8/java/awt/datatransfer/MimeTypeParameterList.java
Normal file
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* An object that encapsulates the parameter list of a MimeType
|
||||
* as defined in RFC 2045 and 2046.
|
||||
*
|
||||
* @author jeff.dunn@eng.sun.com
|
||||
*/
|
||||
class MimeTypeParameterList implements Cloneable {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public MimeTypeParameterList() {
|
||||
parameters = new Hashtable<>();
|
||||
}
|
||||
|
||||
public MimeTypeParameterList(String rawdata)
|
||||
throws MimeTypeParseException
|
||||
{
|
||||
parameters = new Hashtable<>();
|
||||
|
||||
// now parse rawdata
|
||||
parse(rawdata);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int code = Integer.MAX_VALUE/45; // "random" value for empty lists
|
||||
String paramName = null;
|
||||
Enumeration<String> enum_ = this.getNames();
|
||||
|
||||
while (enum_.hasMoreElements()) {
|
||||
paramName = enum_.nextElement();
|
||||
code += paramName.hashCode();
|
||||
code += this.get(paramName).hashCode();
|
||||
}
|
||||
|
||||
return code;
|
||||
} // hashCode()
|
||||
|
||||
/**
|
||||
* Two parameter lists are considered equal if they have exactly
|
||||
* the same set of parameter names and associated values. The
|
||||
* order of the parameters is not considered.
|
||||
*/
|
||||
public boolean equals(Object thatObject) {
|
||||
//System.out.println("MimeTypeParameterList.equals("+this+","+thatObject+")");
|
||||
if (!(thatObject instanceof MimeTypeParameterList)) {
|
||||
return false;
|
||||
}
|
||||
MimeTypeParameterList that = (MimeTypeParameterList)thatObject;
|
||||
if (this.size() != that.size()) {
|
||||
return false;
|
||||
}
|
||||
String name = null;
|
||||
String thisValue = null;
|
||||
String thatValue = null;
|
||||
Set<Map.Entry<String, String>> entries = parameters.entrySet();
|
||||
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
|
||||
Map.Entry<String, String> entry = null;
|
||||
while (iterator.hasNext()) {
|
||||
entry = iterator.next();
|
||||
name = entry.getKey();
|
||||
thisValue = entry.getValue();
|
||||
thatValue = that.parameters.get(name);
|
||||
if ((thisValue == null) || (thatValue == null)) {
|
||||
// both null -> equal, only one null -> not equal
|
||||
if (thisValue != thatValue) {
|
||||
return false;
|
||||
}
|
||||
} else if (!thisValue.equals(thatValue)) {
|
||||
return false;
|
||||
}
|
||||
} // while iterator
|
||||
|
||||
return true;
|
||||
} // equals()
|
||||
|
||||
/**
|
||||
* A routine for parsing the parameter list out of a String.
|
||||
*/
|
||||
protected void parse(String rawdata) throws MimeTypeParseException {
|
||||
int length = rawdata.length();
|
||||
if(length > 0) {
|
||||
int currentIndex = skipWhiteSpace(rawdata, 0);
|
||||
int lastIndex = 0;
|
||||
|
||||
if(currentIndex < length) {
|
||||
char currentChar = rawdata.charAt(currentIndex);
|
||||
while ((currentIndex < length) && (currentChar == ';')) {
|
||||
String name;
|
||||
String value;
|
||||
boolean foundit;
|
||||
|
||||
// eat the ';'
|
||||
++currentIndex;
|
||||
|
||||
// now parse the parameter name
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if(currentIndex < length) {
|
||||
// find the end of the token char run
|
||||
lastIndex = currentIndex;
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
while((currentIndex < length) && isTokenChar(currentChar)) {
|
||||
++currentIndex;
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
}
|
||||
name = rawdata.substring(lastIndex, currentIndex).toLowerCase();
|
||||
|
||||
// now parse the '=' that separates the name from the value
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if((currentIndex < length) && (rawdata.charAt(currentIndex) == '=')) {
|
||||
// eat it and parse the parameter value
|
||||
++currentIndex;
|
||||
|
||||
// skip whitespace
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
|
||||
if(currentIndex < length) {
|
||||
// now find out whether or not we have a quoted value
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
if(currentChar == '"') {
|
||||
// yup it's quoted so eat it and capture the quoted string
|
||||
++currentIndex;
|
||||
lastIndex = currentIndex;
|
||||
|
||||
if(currentIndex < length) {
|
||||
// find the next unescqped quote
|
||||
foundit = false;
|
||||
while((currentIndex < length) && !foundit) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
if(currentChar == '\\') {
|
||||
// found an escape sequence so pass this and the next character
|
||||
currentIndex += 2;
|
||||
} else if(currentChar == '"') {
|
||||
// foundit!
|
||||
foundit = true;
|
||||
} else {
|
||||
++currentIndex;
|
||||
}
|
||||
}
|
||||
if(currentChar == '"') {
|
||||
value = unquote(rawdata.substring(lastIndex, currentIndex));
|
||||
// eat the quote
|
||||
++currentIndex;
|
||||
} else {
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Encountered unterminated quoted parameter value.");
|
||||
}
|
||||
} else if(isTokenChar(currentChar)) {
|
||||
// nope it's an ordinary token so it ends with a non-token char
|
||||
lastIndex = currentIndex;
|
||||
foundit = false;
|
||||
while((currentIndex < length) && !foundit) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
|
||||
if(isTokenChar(currentChar)) {
|
||||
++currentIndex;
|
||||
} else {
|
||||
foundit = true;
|
||||
}
|
||||
}
|
||||
value = rawdata.substring(lastIndex, currentIndex);
|
||||
} else {
|
||||
// it ain't a value
|
||||
throw new MimeTypeParseException("Unexpected character encountered at index " + currentIndex);
|
||||
}
|
||||
|
||||
// now put the data into the hashtable
|
||||
parameters.put(name, value);
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find a value for parameter named " + name);
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find the '=' that separates a parameter name from its value.");
|
||||
}
|
||||
} else {
|
||||
throw new MimeTypeParseException("Couldn't find parameter name");
|
||||
}
|
||||
|
||||
// setup the next iteration
|
||||
currentIndex = skipWhiteSpace(rawdata, currentIndex);
|
||||
if(currentIndex < length) {
|
||||
currentChar = rawdata.charAt(currentIndex);
|
||||
}
|
||||
}
|
||||
if(currentIndex < length) {
|
||||
throw new MimeTypeParseException("More characters encountered in input than expected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the number of name-value pairs in this list.
|
||||
*/
|
||||
public int size() {
|
||||
return parameters.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this list is empty.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return parameters.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value associated with the given name, or null if there
|
||||
* is no current association.
|
||||
*/
|
||||
public String get(String name) {
|
||||
return parameters.get(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to be associated with the given name, replacing
|
||||
* any previous association.
|
||||
*/
|
||||
public void set(String name, String value) {
|
||||
parameters.put(name.trim().toLowerCase(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any value associated with the given name.
|
||||
*/
|
||||
public void remove(String name) {
|
||||
parameters.remove(name.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an enumeration of all the names in this list.
|
||||
*/
|
||||
public Enumeration<String> getNames() {
|
||||
return parameters.keys();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
// Heuristic: 8 characters per field
|
||||
StringBuilder buffer = new StringBuilder(parameters.size() * 16);
|
||||
|
||||
Enumeration<String> keys = parameters.keys();
|
||||
while(keys.hasMoreElements())
|
||||
{
|
||||
buffer.append("; ");
|
||||
|
||||
String key = keys.nextElement();
|
||||
buffer.append(key);
|
||||
buffer.append('=');
|
||||
buffer.append(quote(parameters.get(key)));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a clone of this object
|
||||
*/
|
||||
|
||||
public Object clone() {
|
||||
MimeTypeParameterList newObj = null;
|
||||
try {
|
||||
newObj = (MimeTypeParameterList)super.clone();
|
||||
} catch (CloneNotSupportedException cannotHappen) {
|
||||
}
|
||||
newObj.parameters = (Hashtable)parameters.clone();
|
||||
return newObj;
|
||||
}
|
||||
|
||||
private Hashtable<String, String> parameters;
|
||||
|
||||
// below here be scary parsing related things
|
||||
|
||||
/**
|
||||
* Determine whether or not a given character belongs to a legal token.
|
||||
*/
|
||||
private static boolean isTokenChar(char c) {
|
||||
return ((c > 040) && (c < 0177)) && (TSPECIALS.indexOf(c) < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the index of the first non white space character in
|
||||
* rawdata at or after index i.
|
||||
*/
|
||||
private static int skipWhiteSpace(String rawdata, int i) {
|
||||
int length = rawdata.length();
|
||||
if (i < length) {
|
||||
char c = rawdata.charAt(i);
|
||||
while ((i < length) && Character.isWhitespace(c)) {
|
||||
++i;
|
||||
c = rawdata.charAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* A routine that knows how and when to quote and escape the given value.
|
||||
*/
|
||||
private static String quote(String value) {
|
||||
boolean needsQuotes = false;
|
||||
|
||||
// check to see if we actually have to quote this thing
|
||||
int length = value.length();
|
||||
for(int i = 0; (i < length) && !needsQuotes; ++i) {
|
||||
needsQuotes = !isTokenChar(value.charAt(i));
|
||||
}
|
||||
|
||||
if(needsQuotes) {
|
||||
StringBuilder buffer = new StringBuilder((int)(length * 1.5));
|
||||
|
||||
// add the initial quote
|
||||
buffer.append('"');
|
||||
|
||||
// add the properly escaped text
|
||||
for(int i = 0; i < length; ++i) {
|
||||
char c = value.charAt(i);
|
||||
if((c == '\\') || (c == '"')) {
|
||||
buffer.append('\\');
|
||||
}
|
||||
buffer.append(c);
|
||||
}
|
||||
|
||||
// add the closing quote
|
||||
buffer.append('"');
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A routine that knows how to strip the quotes and escape sequences from the given value.
|
||||
*/
|
||||
private static String unquote(String value) {
|
||||
int valueLength = value.length();
|
||||
StringBuilder buffer = new StringBuilder(valueLength);
|
||||
|
||||
boolean escaped = false;
|
||||
for(int i = 0; i < valueLength; ++i) {
|
||||
char currentChar = value.charAt(i);
|
||||
if(!escaped && (currentChar != '\\')) {
|
||||
buffer.append(currentChar);
|
||||
} else if(escaped) {
|
||||
buffer.append(currentChar);
|
||||
escaped = false;
|
||||
} else {
|
||||
escaped = true;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A string that holds all the special chars.
|
||||
*/
|
||||
private static final String TSPECIALS = "()<>@,;:\\\"/[]?=";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
|
||||
/**
|
||||
* A class to encapsulate MimeType parsing related exceptions
|
||||
*
|
||||
* @serial exclude
|
||||
* @since 1.3
|
||||
*/
|
||||
public class MimeTypeParseException extends Exception {
|
||||
|
||||
// use serialVersionUID from JDK 1.2.2 for interoperability
|
||||
private static final long serialVersionUID = -5604407764691570741L;
|
||||
|
||||
/**
|
||||
* Constructs a MimeTypeParseException with no specified detail message.
|
||||
*/
|
||||
public MimeTypeParseException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a MimeTypeParseException with the specified detail message.
|
||||
*
|
||||
* @param s the detail message.
|
||||
*/
|
||||
public MimeTypeParseException(String s) {
|
||||
super(s);
|
||||
}
|
||||
} // class MimeTypeParseException
|
||||
141
jdkSrc/jdk8/java/awt/datatransfer/StringSelection.java
Normal file
141
jdkSrc/jdk8/java/awt/datatransfer/StringSelection.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* A <code>Transferable</code> which implements the capability required
|
||||
* to transfer a <code>String</code>.
|
||||
*
|
||||
* This <code>Transferable</code> properly supports
|
||||
* <code>DataFlavor.stringFlavor</code>
|
||||
* and all equivalent flavors. Support for
|
||||
* <code>DataFlavor.plainTextFlavor</code>
|
||||
* and all equivalent flavors is <b>deprecated</b>. No other
|
||||
* <code>DataFlavor</code>s are supported.
|
||||
*
|
||||
* @see java.awt.datatransfer.DataFlavor#stringFlavor
|
||||
* @see java.awt.datatransfer.DataFlavor#plainTextFlavor
|
||||
*/
|
||||
public class StringSelection implements Transferable, ClipboardOwner {
|
||||
|
||||
private static final int STRING = 0;
|
||||
private static final int PLAIN_TEXT = 1;
|
||||
|
||||
private static final DataFlavor[] flavors = {
|
||||
DataFlavor.stringFlavor,
|
||||
DataFlavor.plainTextFlavor // deprecated
|
||||
};
|
||||
|
||||
private String data;
|
||||
|
||||
/**
|
||||
* Creates a <code>Transferable</code> capable of transferring
|
||||
* the specified <code>String</code>.
|
||||
*/
|
||||
public StringSelection(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of flavors in which this <code>Transferable</code>
|
||||
* can provide the data. <code>DataFlavor.stringFlavor</code>
|
||||
* is properly supported.
|
||||
* Support for <code>DataFlavor.plainTextFlavor</code> is
|
||||
* <b>deprecated</b>.
|
||||
*
|
||||
* @return an array of length two, whose elements are <code>DataFlavor.
|
||||
* stringFlavor</code> and <code>DataFlavor.plainTextFlavor</code>
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
// returning flavors itself would allow client code to modify
|
||||
// our internal behavior
|
||||
return (DataFlavor[])flavors.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the requested flavor is supported by this
|
||||
* <code>Transferable</code>.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return true if <code>flavor</code> is equal to
|
||||
* <code>DataFlavor.stringFlavor</code> or
|
||||
* <code>DataFlavor.plainTextFlavor</code>; false if <code>flavor</code>
|
||||
* is not one of the above flavors
|
||||
* @throws NullPointerException if flavor is <code>null</code>
|
||||
*/
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
// JCK Test StringSelection0003: if 'flavor' is null, throw NPE
|
||||
for (int i = 0; i < flavors.length; i++) {
|
||||
if (flavor.equals(flavors[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>Transferable</code>'s data in the requested
|
||||
* <code>DataFlavor</code> if possible. If the desired flavor is
|
||||
* <code>DataFlavor.stringFlavor</code>, or an equivalent flavor,
|
||||
* the <code>String</code> representing the selection is
|
||||
* returned. If the desired flavor is
|
||||
* <code>DataFlavor.plainTextFlavor</code>,
|
||||
* or an equivalent flavor, a <code>Reader</code> is returned.
|
||||
* <b>Note:</b> The behavior of this method for
|
||||
* <code>DataFlavor.plainTextFlavor</code>
|
||||
* and equivalent <code>DataFlavor</code>s is inconsistent with the
|
||||
* definition of <code>DataFlavor.plainTextFlavor</code>.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return the data in the requested flavor, as outlined above
|
||||
* @throws UnsupportedFlavorException if the requested data flavor is
|
||||
* not equivalent to either <code>DataFlavor.stringFlavor</code>
|
||||
* or <code>DataFlavor.plainTextFlavor</code>
|
||||
* @throws IOException if an IOException occurs while retrieving the data.
|
||||
* By default, StringSelection never throws this exception, but a
|
||||
* subclass may.
|
||||
* @throws NullPointerException if flavor is <code>null</code>
|
||||
* @see java.io.Reader
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor)
|
||||
throws UnsupportedFlavorException, IOException
|
||||
{
|
||||
// JCK Test StringSelection0007: if 'flavor' is null, throw NPE
|
||||
if (flavor.equals(flavors[STRING])) {
|
||||
return (Object)data;
|
||||
} else if (flavor.equals(flavors[PLAIN_TEXT])) {
|
||||
return new StringReader(data == null ? "" : data);
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
|
||||
public void lostOwnership(Clipboard clipboard, Transferable contents) {
|
||||
}
|
||||
}
|
||||
1265
jdkSrc/jdk8/java/awt/datatransfer/SystemFlavorMap.java
Normal file
1265
jdkSrc/jdk8/java/awt/datatransfer/SystemFlavorMap.java
Normal file
File diff suppressed because it is too large
Load Diff
73
jdkSrc/jdk8/java/awt/datatransfer/Transferable.java
Normal file
73
jdkSrc/jdk8/java/awt/datatransfer/Transferable.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Defines the interface for classes that can be used to provide data
|
||||
* for a transfer operation.
|
||||
* <p>
|
||||
* For information on using data transfer with Swing, see
|
||||
* <a href="https://docs.oracle.com/javase/tutorial/uiswing/dnd/index.html">
|
||||
* How to Use Drag and Drop and Data Transfer</a>,
|
||||
* a section in <em>The Java Tutorial</em>, for more information.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
*/
|
||||
|
||||
public interface Transferable {
|
||||
|
||||
/**
|
||||
* Returns an array of DataFlavor objects indicating the flavors the data
|
||||
* can be provided in. The array should be ordered according to preference
|
||||
* for providing the data (from most richly descriptive to least descriptive).
|
||||
* @return an array of data flavors in which this data can be transferred
|
||||
*/
|
||||
public DataFlavor[] getTransferDataFlavors();
|
||||
|
||||
/**
|
||||
* Returns whether or not the specified data flavor is supported for
|
||||
* this object.
|
||||
* @param flavor the requested flavor for the data
|
||||
* @return boolean indicating whether or not the data flavor is supported
|
||||
*/
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor);
|
||||
|
||||
/**
|
||||
* Returns an object which represents the data to be transferred. The class
|
||||
* of the object returned is defined by the representation class of the flavor.
|
||||
*
|
||||
* @param flavor the requested flavor for the data
|
||||
* @see DataFlavor#getRepresentationClass
|
||||
* @exception IOException if the data is no longer available
|
||||
* in the requested flavor.
|
||||
* @exception UnsupportedFlavorException if the requested data flavor is
|
||||
* not supported.
|
||||
*/
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package java.awt.datatransfer;
|
||||
|
||||
/**
|
||||
* Signals that the requested data is not supported in this flavor.
|
||||
* @see Transferable#getTransferData
|
||||
*
|
||||
* @author Amy Fowler
|
||||
*/
|
||||
public class UnsupportedFlavorException extends Exception {
|
||||
|
||||
/*
|
||||
* JDK 1.1 serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = 5383814944251665601L;
|
||||
|
||||
/**
|
||||
* Constructs an UnsupportedFlavorException.
|
||||
*
|
||||
* @param flavor the flavor object which caused the exception. May
|
||||
* be <code>null</code>.
|
||||
*/
|
||||
public UnsupportedFlavorException(DataFlavor flavor) {
|
||||
super((flavor != null) ? flavor.getHumanPresentableName() : null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user