Example usage for java.awt.datatransfer DataFlavor match

List of usage examples for java.awt.datatransfer DataFlavor match

Introduction

In this page you can find the example usage for java.awt.datatransfer DataFlavor match.

Prototype

public boolean match(DataFlavor that) 

Source Link

Document

Identical to #equals(DataFlavor) .

Usage

From source file:Main.java

public static void main(String[] args) {

    DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");

    DataFlavor df2 = new DataFlavor(java.awt.Button.class, "AWT Button");

    System.out.println("df1 equals df2: " + df1.match(df2));
}

From source file:net.sf.jabref.gui.fieldeditors.FileListEditorTransferHandler.java

/**
 * This method is called to query whether the transfer can be imported.
 *
 * Will return true for urls, strings, javaFileLists
 *//* w  w  w  . j  a  v a 2  s . c  o  m*/
@Override
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {

    // accept this if any input flavor matches any of our supported flavors
    for (DataFlavor inflav : transferFlavors) {
        if (inflav.match(urlFlavor) || inflav.match(stringFlavor)
                || inflav.match(DataFlavor.javaFileListFlavor)) {
            return true;
        }
    }

    // nope, never heard of this type
    return false;
}

From source file:net.sf.jabref.groups.EntryTableTransferHandler.java

/**
 * This method is called to query whether the transfer can be imported.
 *
 * Will return true for urls, strings, javaFileLists
 */// w  ww . j a v a2s  .co  m
@Override
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
    if (!EntryTableTransferHandler.DROP_ALLOWED) {
        return false;
    }

    // accept this if any input flavor matches any of our supported flavors
    for (DataFlavor inflav : transferFlavors) {
        if (inflav.match(urlFlavor) || inflav.match(stringFlavor)
                || inflav.match(DataFlavor.javaFileListFlavor)) {
            return true;
        }
    }

    // System.out.println("drop type forbidden");
    // nope, never heard of this type
    return false;
}

From source file:unikn.dbis.univis.navigation.tree.VTree.java

/**
 * A <code>DragGestureRecognizer</code> has detected
 * a platform-dependent drag initiating gesture and
 * is notifying this listener/*from   w w  w.j  a va 2 s.  co  m*/
 * in order for it to initiate the action for the user.
 * <p/>
 *
 * @param dge the <code>DragGestureEvent</code> describing
 *            the gesture that has just occurred
 */
public void dragGestureRecognized(DragGestureEvent dge) {

    // Gets the selected tree node.
    Object o = getLastSelectedPathComponent();

    if (o instanceof DefaultMutableTreeNode) {

        // Gets the user object of the tree node.
        Object userObject = ((DefaultMutableTreeNode) o).getUserObject();

        if (userObject instanceof VDimension) {

            final VDimension dimension = (VDimension) userObject;

            // Whether the selected dimension allows drag and drop
            // or not.
            if (dimension.isDragable() && !dimension.isDropped()) {
                dge.startDrag(DragSource.DefaultMoveDrop, new 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() {
                        return new DataFlavor[] { VDataReferenceFlavor.COMBINATION_FLAVOR,
                                VDataReferenceFlavor.DIMENSION_FLAVOR };
                    }

                    /**
                     * 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) {
                        for (DataFlavor dataFlavor : getTransferDataFlavors()) {
                            if (dataFlavor.match(flavor)) {
                                return true;
                            }
                        }
                        return false;
                    }

                    /**
                     * 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
                     * @throws java.awt.datatransfer.UnsupportedFlavorException
                     *          if the requested data flavor is
                     *          not supported.
                     * @see java.awt.datatransfer.DataFlavor#getRepresentationClass
                     */
                    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
                        if (VDataReferenceFlavor.COMBINATION_FLAVOR.match(flavor)) {

                            VCube cube = null;
                            for (VDataReference dataReference = dimension; dataReference != null; dataReference = dataReference
                                    .getParent()) {
                                if (dataReference instanceof VCube) {
                                    //                                        cube = (VCube) dataReference;
                                    break;
                                }
                            }

                            VCombination combination = new VCombinationImpl();
                            combination.setCube(cube);
                            combination.setDimension(dimension);
                            combination.setMeasure(measure);
                            combination.setFunction(function);

                            return combination;
                        } else if (VDataReferenceFlavor.DIMENSION_FLAVOR.match(flavor)) {
                            return dimension;
                        }
                        throw new UnsupportedFlavorException(flavor);
                    }
                });
            } else {
                if (LOG.isInfoEnabled()) {
                    LOG.info("The dimension node isn't summable or has been drag and dropped in the past.");
                }
            }
        } else if (userObject instanceof VMeasure) {

            final VMeasure measure = (VMeasure) userObject;

            dge.startDrag(DragSource.DefaultMoveDrop, new 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() {
                    return new DataFlavor[] { VDataReferenceFlavor.MEASURE_FLAVOR };
                }

                /**
                 * 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) {
                    for (DataFlavor dataFlavor : getTransferDataFlavors()) {
                        if (dataFlavor.match(flavor)) {
                            return true;
                        }
                    }
                    return false;
                }

                /**
                 * 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
                 * @throws java.awt.datatransfer.UnsupportedFlavorException
                 *          if the requested data flavor is
                 *          not supported.
                 * @see java.awt.datatransfer.DataFlavor#getRepresentationClass
                 */
                public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
                    if (VDataReferenceFlavor.MEASURE_FLAVOR.match(flavor)) {
                        return measure;
                    }
                    throw new UnsupportedFlavorException(flavor);
                }
            });
        }
    }
}