Example usage for java.awt.datatransfer DataFlavor equals

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

Introduction

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

Prototype

@Deprecated
public boolean equals(String s) 

Source Link

Document

Compares only the mimeType against the passed in String and representationClass is not considered in the comparison.

Usage

From source file:TreeTester.java

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    Object returnObject;//from ww w  .j  a  v a 2s .c  o  m
    if (flavor.equals(flavors[TREE])) {
        Object userObject = data.getUserObject();
        if (userObject == null) {
            returnObject = data;
        } else {
            returnObject = userObject;
        }
    } else if (flavor.equals(flavors[STRING])) {
        Object userObject = data.getUserObject();
        if (userObject == null) {
            returnObject = data.toString();
        } else {
            returnObject = userObject.toString();
        }
    } else if (flavor.equals(flavors[PLAIN_TEXT])) {
        Object userObject = data.getUserObject();
        String string;
        if (userObject == null) {
            string = data.toString();
        } else {
            string = userObject.toString();
        }
        returnObject = new ByteArrayInputStream(string.getBytes("Unicode"));
    } else {
        throw new UnsupportedFlavorException(flavor);
    }
    return returnObject;
}

From source file:TreeTester.java

public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean returnValue = false;
    for (int i = 0, n = flavors.length; i < n; i++) {
        if (flavor.equals(flavors[i])) {
            returnValue = true;//from   w w w . j  a va 2  s  .  co  m
            break;
        }
    }
    return returnValue;
}

From source file:FileTreeDragSource.java

public boolean isDataFlavorSupported(DataFlavor fl) {
    return fl.equals(DataFlavor.javaFileListFlavor);
}

From source file:EditorDropTarget3.java

protected boolean dropContent(Transferable transferable, DropTargetDropEvent dtde) {
    if (!pane.isEditable()) {
        // Can't drop content on a read-only text control
        return false;
    }/*from w  ww  .  j a  va  2s  .c o  m*/

    try {
        // Check for a match with the current content type
        DataFlavor[] flavors = dtde.getCurrentDataFlavors();

        DataFlavor selectedFlavor = null;

        // Look for either plain text or a String.
        for (int i = 0; i < flavors.length; i++) {
            DataFlavor flavor = flavors[i];
            DnDUtils.debugPrintln("Drop MIME type " + flavor.getMimeType() + " is available");
            if (flavor.equals(DataFlavor.plainTextFlavor) || flavor.equals(DataFlavor.stringFlavor)) {
                selectedFlavor = flavor;
                break;
            }
        }

        if (selectedFlavor == null) {
            // No compatible flavor - should never happen
            return false;

        }

        DnDUtils.debugPrintln("Selected flavor is " + selectedFlavor.getHumanPresentableName());

        // Get the transferable and then obtain the data
        Object data = transferable.getTransferData(selectedFlavor);

        DnDUtils.debugPrintln("Transfer data type is " + data.getClass().getName());

        String insertData = null;
        if (data instanceof InputStream) {
            // Plain text flavor
            String charSet = selectedFlavor.getParameter("charset");
            InputStream is = (InputStream) data;
            byte[] bytes = new byte[is.available()];
            is.read(bytes);
            try {
                insertData = new String(bytes, charSet);
            } catch (UnsupportedEncodingException e) {
                // Use the platform default encoding
                insertData = new String(bytes);
            }
        } else if (data instanceof String) {
            // String flavor
            insertData = (String) data;
        }

        if (insertData != null) {
            int selectionStart = pane.getCaretPosition();
            pane.replaceSelection(insertData);
            pane.select(selectionStart, selectionStart + insertData.length());
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:EditorDropTarget4.java

protected boolean dropContent(Transferable transferable, DropTargetDropEvent dtde) {
    if (!pane.isEditable()) {
        // Can't drop content on a read-only text control
        return false;
    }// w ww  .  j a  v a  2  s .  c  o m

    try {
        // Check for a match with the current content type
        DataFlavor[] flavors = dtde.getCurrentDataFlavors();

        DataFlavor selectedFlavor = null;

        // Look for either plain text or a String.
        for (int i = 0; i < flavors.length; i++) {
            DataFlavor flavor = flavors[i];
            DnDUtils.debugPrintln("Drop MIME type " + flavor.getMimeType() + " is available");
            if (flavor.equals(DataFlavor.plainTextFlavor) || flavor.equals(DataFlavor.stringFlavor)) {
                selectedFlavor = flavor;
                break;
            }
        }

        if (selectedFlavor == null) {
            // No compatible flavor - should never happen
            return false;
        }

        DnDUtils.debugPrintln("Selected flavor is " + selectedFlavor.getHumanPresentableName());

        // Get the transferable and then obtain the data
        Object data = transferable.getTransferData(selectedFlavor);

        DnDUtils.debugPrintln("Transfer data type is " + data.getClass().getName());

        String insertData = null;
        if (data instanceof InputStream) {
            // Plain text flavor
            String charSet = selectedFlavor.getParameter("charset");
            InputStream is = (InputStream) data;
            byte[] bytes = new byte[is.available()];
            is.read(bytes);
            try {
                insertData = new String(bytes, charSet);
            } catch (UnsupportedEncodingException e) {
                // Use the platform default encoding
                insertData = new String(bytes);
            }
        } else if (data instanceof String) {
            // String flavor
            insertData = (String) data;
        }

        if (insertData != null) {
            int selectionStart = pane.getCaretPosition();
            pane.replaceSelection(insertData);
            pane.select(selectionStart, selectionStart + insertData.length());
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:TransferableScribblePane.java

/** Check for the one flavor we support */
public boolean isDataFlavorSupported(DataFlavor f) {
    return f.equals(FLAVOR);
}

From source file:ScribbleDragAndDrop.java

/** Check whether we support a given flavor */
public boolean isDataFlavorSupported(DataFlavor flavor) {
    return (flavor.equals(scribbleDataFlavor) || flavor.equals(DataFlavor.stringFlavor));
}

From source file:TransferableScribblePane.java

/** Return the wrapped PolyLine, if the flavor is right */
public Object getTransferData(DataFlavor f) throws UnsupportedFlavorException {
    if (!f.equals(FLAVOR))
        throw new UnsupportedFlavorException(f);
    return line;/*from  ww  w .ja  va2s  . c om*/
}

From source file:ScribbleDragAndDrop.java

/**
 * Return the scribble data in the requested format, or throw an exception
 * if we don't support the requested format
 *///from   w  w  w.ja  v  a2s.c o  m
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
    if (flavor.equals(scribbleDataFlavor)) {
        return this;
    } else if (flavor.equals(DataFlavor.stringFlavor)) {
        return toString();
    } else
        throw new UnsupportedFlavorException(flavor);
}

From source file:org.feistymeow.dragdrop.ListTransferable.java

/**
 * using the set of files that we've been handed, we can do transfers using our two supported
 * flavors./*from   w w  w .j  av  a 2  s  .  com*/
 */
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, java.io.IOException {
    if (flavor == null)
        return null;
    if (size() == 0) {
        logger.debug("size was zero, so loading data just in time");
        boolean worked = loadDataJustInTime(flavor);
        if (!worked || (size() == 0)) {
            logger.warn("failed to retrieve data just in time for getTransferData.");
            return null;
        }
    }
    // help from workaround at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516
    logger.debug("responding to flavor: " + flavor.toString());
    if (flavor.equals(DataFlavor.javaFileListFlavor)) {
        logger.debug("java file list flavor...");
        List<Object> data = new java.util.ArrayList<Object>();
        data.addAll(this);
        return data;
    } else if (flavor.equals(URIListFlavor) || flavor.equals(AltURIListFlavor)) {
        logger.debug("uri list flavor...");
        StringBuilder data = new StringBuilder();
        Iterator<Object> iter = iterator();
        while (iter.hasNext()) {
            Object x = iter.next();
            if (x instanceof File) {
                File elem = (File) x;
                data.append(elem.toURI() + "\r\n");
            } else if (x instanceof String) {
                data.append((String) x + "\r\n");
            } else {
                logger.debug("did not know how to handle type in transfer: " + x.toString());
            }
        }
        logger.debug("returning URI string: " + data.toString());
        return data.toString();
    } else {
        logger.debug("getTransferData: didn't know how to handle the requested flavor.");
        throw new UnsupportedFlavorException(flavor);
    }
}