public boolean isNativeFormatAvailable(String nativeFormat) {
if (nativeFormat == null) {
return false;
}
if (nativeFormat.equals(FORMAT_TEXT)) {
return (text != null);
}
if (nativeFormat.equals(FORMAT_FILE_LIST)) {
return (fileList != null);
}
if (nativeFormat.equals(FORMAT_URL)) {
return (url != null);
}
if (nativeFormat.equals(FORMAT_HTML)) {
return (html != null);
}
if (nativeFormat.equals(FORMAT_IMAGE)) {
return (rawBitmap != null);
}
try {
DataFlavor df = SystemFlavorMap.decodeDataFlavor(nativeFormat);
return serializedObjects.containsKey(df.getRepresentationClass());
} catch (Exception e) {
return false;
}
}
java类java.awt.datatransfer.SystemFlavorMap的实例源码
DataSnapshot.java 文件源码
项目:freeVM
阅读 20
收藏 0
点赞 0
评论 0
DataProxy.java 文件源码
项目:freeVM
阅读 20
收藏 0
点赞 0
评论 0
private Object getSerializedObject(DataFlavor f)
throws IOException, UnsupportedFlavorException {
String nativeFormat = SystemFlavorMap.encodeDataFlavor(f);
if ((nativeFormat == null) ||
!data.isNativeFormatAvailable(nativeFormat)) {
throw new UnsupportedFlavorException(f);
}
byte bytes[] = data.getSerializedObject(f.getRepresentationClass());
if (bytes == null) {
// awt.4F=Data is not available
throw new IOException(Messages.getString("awt.4F")); //$NON-NLS-1$
}
ByteArrayInputStream str = new ByteArrayInputStream(bytes);
try {
return new ObjectInputStream(str).readObject();
} catch (ClassNotFoundException ex) {
throw new IOException(ex.getMessage());
}
}
FileCopyPasteUtil.java 文件源码
项目:consulo
阅读 20
收藏 0
点赞 0
评论 0
public static DataFlavor createDataFlavor(@Nonnull final String mimeType, @Nullable final Class<?> klass, final boolean register) {
try {
final DataFlavor flavor =
klass != null ? new DataFlavor(mimeType + ";class=" + klass.getName(), null, klass.getClassLoader()) : new DataFlavor(mimeType);
if (register) {
final FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
if (map instanceof SystemFlavorMap) {
((SystemFlavorMap)map).addUnencodedNativeForFlavor(flavor, mimeType);
}
}
return flavor;
}
catch (ClassNotFoundException e) {
LOG.error(e);
//noinspection ConstantConditions
return null;
}
}
DropTarget.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
DragSource.java 文件源码
项目:OpenJSharp
阅读 20
收藏 0
点赞 0
评论 0
/**
* Deserializes this <code>DragSource</code>. This method first performs
* default deserialization. Next, this object's <code>FlavorMap</code> is
* deserialized by using the next object in the stream.
* If the resulting <code>FlavorMap</code> is <code>null</code>, this
* object's <code>FlavorMap</code> is set to the default FlavorMap for
* this thread's <code>ClassLoader</code>.
* Next, this object's listeners are deserialized by reading a
* <code>null</code>-terminated sequence of 0 or more key/value pairs
* from the stream:
* <ul>
* <li>If a key object is a <code>String</code> equal to
* <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is
* deserialized using the corresponding value object and added to this
* <code>DragSource</code>.
* <li>If a key object is a <code>String</code> equal to
* <code>dragSourceMotionListenerK</code>, a
* <code>DragSourceMotionListener</code> is deserialized using the
* corresponding value object and added to this <code>DragSource</code>.
* <li>Otherwise, the key/value pair is skipped.
* </ul>
*
* @see java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap
* @since 1.4
*/
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException {
s.defaultReadObject();
// 'flavorMap' was written explicitly
flavorMap = (FlavorMap)s.readObject();
// Implementation assumes 'flavorMap' is never null.
if (flavorMap == null) {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
Object keyOrNull;
while (null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (dragSourceListenerK == key) {
addDragSourceListener((DragSourceListener)(s.readObject()));
} else if (dragSourceMotionListenerK == key) {
addDragSourceMotionListener(
(DragSourceMotionListener)(s.readObject()));
} else {
// skip value for unrecognized key
s.readObject();
}
}
}
DropTarget.java 文件源码
项目:jdk8u-jdk
阅读 20
收藏 0
点赞 0
评论 0
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
DragSource.java 文件源码
项目:jdk8u-jdk
阅读 19
收藏 0
点赞 0
评论 0
/**
* Deserializes this <code>DragSource</code>. This method first performs
* default deserialization. Next, this object's <code>FlavorMap</code> is
* deserialized by using the next object in the stream.
* If the resulting <code>FlavorMap</code> is <code>null</code>, this
* object's <code>FlavorMap</code> is set to the default FlavorMap for
* this thread's <code>ClassLoader</code>.
* Next, this object's listeners are deserialized by reading a
* <code>null</code>-terminated sequence of 0 or more key/value pairs
* from the stream:
* <ul>
* <li>If a key object is a <code>String</code> equal to
* <code>dragSourceListenerK</code>, a <code>DragSourceListener</code> is
* deserialized using the corresponding value object and added to this
* <code>DragSource</code>.
* <li>If a key object is a <code>String</code> equal to
* <code>dragSourceMotionListenerK</code>, a
* <code>DragSourceMotionListener</code> is deserialized using the
* corresponding value object and added to this <code>DragSource</code>.
* <li>Otherwise, the key/value pair is skipped.
* </ul>
*
* @see java.awt.datatransfer.SystemFlavorMap#getDefaultFlavorMap
* @since 1.4
*/
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException {
s.defaultReadObject();
// 'flavorMap' was written explicitly
flavorMap = (FlavorMap)s.readObject();
// Implementation assumes 'flavorMap' is never null.
if (flavorMap == null) {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
Object keyOrNull;
while (null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (dragSourceListenerK == key) {
addDragSourceListener((DragSourceListener)(s.readObject()));
} else if (dragSourceMotionListenerK == key) {
addDragSourceMotionListener(
(DragSourceMotionListener)(s.readObject()));
} else {
// skip value for unrecognized key
s.readObject();
}
}
}
ImageTransferTest.java 文件源码
项目:jdk8u-jdk
阅读 25
收藏 0
点赞 0
评论 0
static String[] retrieveFormatsToTest() {
SystemFlavorMap sfm = (SystemFlavorMap) SystemFlavorMap.getDefaultFlavorMap();
java.util.List<String> ln = sfm.getNativesForFlavor(DataFlavor.imageFlavor);
if (OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType()) && !ln.contains("METAFILEPICT")) {
// for test failing on JDK without this fix
ln.add("METAFILEPICT");
}
return ln.toArray(new String[ln.size()]);
}
DataFlavorSearcher.java 文件源码
项目:jdk8u-jdk
阅读 25
收藏 0
点赞 0
评论 0
static public DataFlavor getByteDataFlavorForNative(String[] nats) {
FlavorTable flavorTable = (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
for (String nat : nats) {
java.util.List<DataFlavor> flavors = flavorTable.getFlavorsForNative(nat);
for (DataFlavor flavor : flavors) {
if (flavor != null
&& flavor.getRepresentationClass().equals(byte[].class)) {
return flavor;
}
}
}
throw new RuntimeException("No data flavor was found for natives: " + Arrays.toString(nats));
}
DropTarget.java 文件源码
项目:openjdk-jdk10
阅读 28
收藏 0
点赞 0
评论 0
/**
* Creates a new DropTarget given the {@code Component}
* to associate itself with, an {@code int} representing
* the default acceptable action(s) to
* support, a {@code DropTargetListener}
* to handle event processing, a {@code boolean} indicating
* if the {@code DropTarget} is currently accepting drops, and
* a {@code FlavorMap} to use (or null for the default {@code FlavorMap}).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The {@code Component} with which this {@code DropTarget} is associated
* @param ops The default acceptable actions for this {@code DropTarget}
* @param dtl The {@code DropTargetListener} for this {@code DropTarget}
* @param act Is the {@code DropTarget} accepting drops.
* @param fm The {@code FlavorMap} to use, or null for the default {@code FlavorMap}
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}