当前位置: 首页>>代码示例>>Java>>正文


Java DataFlavor.getRepresentationClass方法代码示例

本文整理汇总了Java中java.awt.datatransfer.DataFlavor.getRepresentationClass方法的典型用法代码示例。如果您正苦于以下问题:Java DataFlavor.getRepresentationClass方法的具体用法?Java DataFlavor.getRepresentationClass怎么用?Java DataFlavor.getRepresentationClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.datatransfer.DataFlavor的用法示例。


在下文中一共展示了DataFlavor.getRepresentationClass方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dragEnter

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    accept = null;
    value = null;
    for (DataFlavor dataFlavor : dtde.getCurrentDataFlavors()) {
        Object obj = null;
        try {
            obj = dtde.getTransferable().getTransferData(dataFlavor);
        } catch (Exception ex) {
            continue;
        }
        if (dataFlavor.isFlavorJavaFileListType()) {
            accept = dataFlavor;
            value = obj;
            break;
        }
        if ("text".equals(dataFlavor.getPrimaryType()) && "uri-list".equals(dataFlavor.getSubType()) && dataFlavor.getRepresentationClass() == String.class) {
            accept = dataFlavor;
            value = (String) obj;
            break;
        }
    }
    if (accept != null) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:LocallDownloadDnD.java

示例2: isFlavorCharsetTextType

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * Returns whether this flavor is a text type which supports the
 * 'charset' parameter.
 */
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
    // Although stringFlavor doesn't actually support the charset
    // parameter (because its primary MIME type is not "text"), it should
    // be treated as though it does. stringFlavor is semantically
    // equivalent to "text/plain" data.
    if (DataFlavor.stringFlavor.equals(flavor)) {
        return true;
    }

    if (!"text".equals(flavor.getPrimaryType()) ||
        !doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    Class rep_class = flavor.getRepresentationClass();

    if (flavor.isRepresentationClassReader() ||
        String.class.equals(rep_class) ||
        flavor.isRepresentationClassCharBuffer() ||
        char[].class.equals(rep_class))
    {
        return true;
    }

    if (!(flavor.isRepresentationClassInputStream() ||
          flavor.isRepresentationClassByteBuffer() ||
          byte[].class.equals(rep_class))) {
        return false;
    }

    String charset = flavor.getParameter("charset");

    return (charset != null)
        ? DataTransferer.isEncodingSupported(charset)
        : true; // null equals default encoding which is always supported
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:DataTransferer.java

示例3: constructFlavoredObject

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * We support representations which are exactly of the specified Class,
 * and also arbitrary Objects which have a constructor which takes an
 * instance of the Class as its sole parameter.
 */
private Object constructFlavoredObject(Object arg, DataFlavor flavor,
                                       Class<?> clazz)
    throws IOException
{
    final Class<?> dfrc = flavor.getRepresentationClass();

    if (clazz.equals(dfrc)) {
        return arg; // simple case
    } else {
        Constructor<?>[] constructors;

        try {
            constructors = AccessController.doPrivileged(
                    (PrivilegedAction<Constructor<?>[]>) dfrc::getConstructors);
        } catch (SecurityException se) {
            throw new IOException(se.getMessage());
        }

        Constructor<?> constructor = Stream.of(constructors)
                .filter(c -> Modifier.isPublic(c.getModifiers()))
                .filter(c -> {
                    Class<?>[] ptypes = c.getParameterTypes();
                    return ptypes != null
                            && ptypes.length == 1
                            && clazz.equals(ptypes[0]);
                })
                .findFirst()
                .orElseThrow(() ->
                        new IOException("can't find <init>(L"+ clazz + ";)V for class: " + dfrc.getName()));

        try {
            return constructor.newInstance(arg);
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:DataTransferer.java

示例4: isFlavorCharsetTextType

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * Returns whether this flavor is a text type which supports the 'charset'
 * parameter.
 */
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
    // Although stringFlavor doesn't actually support the charset
    // parameter (because its primary MIME type is not "text"), it should
    // be treated as though it does. stringFlavor is semantically
    // equivalent to "text/plain" data.
    if (DataFlavor.stringFlavor.equals(flavor)) {
        return true;
    }

    if (!"text".equals(flavor.getPrimaryType()) ||
            !doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    Class<?> rep_class = flavor.getRepresentationClass();

    if (flavor.isRepresentationClassReader() ||
            String.class.equals(rep_class) ||
            flavor.isRepresentationClassCharBuffer() ||
            char[].class.equals(rep_class))
    {
        return true;
    }

    if (!(flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            byte[].class.equals(rep_class))) {
        return false;
    }

    String charset = flavor.getParameter("charset");

    // null equals default encoding which is always supported
    return (charset == null) || isEncodingSupported(charset);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:DataFlavorUtil.java

示例5: constructFlavoredObject

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * We support representations which are exactly of the specified Class,
 * and also arbitrary Objects which have a constructor which takes an
 * instance of the Class as its sole parameter.
 */
private Object constructFlavoredObject(Object arg, DataFlavor flavor,
                                       Class clazz)
    throws IOException
{
    final Class dfrc = flavor.getRepresentationClass();

    if (clazz.equals(dfrc)) {
        return arg; // simple case
    } else {
        Constructor[] constructors = null;

        try {
            constructors = (Constructor[])
                AccessController.doPrivileged(new PrivilegedAction() {
                        public Object run() {
                            return dfrc.getConstructors();
                        }
                    });
        } catch (SecurityException se) {
            throw new IOException(se.getMessage());
        }

        Constructor constructor = null;

        for (int j = 0; j < constructors.length; j++) {
            if (!Modifier.isPublic(constructors[j].getModifiers())) {
                continue;
            }

            Class[] ptypes = constructors[j].getParameterTypes();

            if (ptypes != null && ptypes.length == 1 &&
                clazz.equals(ptypes[0])) {
                constructor = constructors[j];
                break;
            }
        }

        if (constructor == null) {
            throw new IOException("can't find <init>(L"+ clazz +
                                  ";)V for class: " + dfrc.getName());
        }

        try {
            return constructor.newInstance(new Object[] { arg } );
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:56,代码来源:DataTransferer.java

示例6: getPlatformMappingsForFlavor

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (int i = 0; i < mimeTypes.length; i++) {
                Iterator writers =
                    ImageIO.getImageWritersByMIMEType(mimeTypes[i]);

                while (writers.hasNext()) {
                    ImageWriter imageWriter = (ImageWriter)writers.next();
                    ImageWriterSpi writerSpi =
                        imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                        writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mimeTypes[i]);
                        break;
                    }
                }
            }
        }
    } else if (DataTransferer.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataTransferer.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:XDataTransferer.java

示例7: getPlatformMappingsForFlavor

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
@Override
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataFlavorUtil.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (String mime : mimeTypes) {
                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mime);
                while (writers.hasNext()) {
                    ImageWriter imageWriter = writers.next();
                    ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                            writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mime);
                        break;
                    }
                }
            }
        }
    } else if (DataFlavorUtil.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataFlavorUtil.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:XDataTransferer.java

示例8: equals

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * Compares the DataFlavor passed in with this DataFlavor; calls
 * the <code>isMimeTypeEqual</code> method.
 *
 * @param dataFlavor        the DataFlavor to compare with
 * @return                  true if the MIME type and representation class
 *                          are the same
 */
public boolean equals(DataFlavor dataFlavor) {
    return (isMimeTypeEqual(dataFlavor) &&
            dataFlavor.getRepresentationClass() == representationClass);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:ActivationDataFlavor.java

示例9: equals

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * Compares the DataFlavor passed in with this DataFlavor; calls
 * the {@code isMimeTypeEqual} method.
 *
 * @param dataFlavor        the DataFlavor to compare with
 * @return                  true if the MIME type and representation class
 *                          are the same
 */
public boolean equals(DataFlavor dataFlavor) {
    return (isMimeTypeEqual(dataFlavor) &&
            dataFlavor.getRepresentationClass() == representationClass);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ActivationDataFlavor.java


注:本文中的java.awt.datatransfer.DataFlavor.getRepresentationClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。