Example usage for java.awt.datatransfer UnsupportedFlavorException UnsupportedFlavorException

List of usage examples for java.awt.datatransfer UnsupportedFlavorException UnsupportedFlavorException

Introduction

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

Prototype

public UnsupportedFlavorException(DataFlavor flavor) 

Source Link

Document

Constructs an UnsupportedFlavorException.

Usage

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!flavorSet.contains(flavor))
        throw new UnsupportedFlavorException(flavor);
    if (nodeListDataFlavor.equals(flavor)) {
        NodeModel model = ((CommonSpreadSheetModel) spreadsheet.getModel()).getCache().getModel();
        //         ArrayList nl=nodeList;
        //         nodeList=new ArrayList(nl.size());
        //         nodeList.addAll(model.copy(nl,NodeModel.SILENT));
        return model.copy(nodeList, NodeModel.SILENT);
    } else if (DataFlavor.stringFlavor.equals(flavor))
        return selectionToString(spreadsheet, rows, cols);
    //          return (sdata==null)?nodeListToString(nodeList,spreadsheet,fields):sdata;
    else if (DataFlavor.getTextPlainUnicodeFlavor().equals(flavor))
        return new StringReader(selectionToString(spreadsheet, rows, cols));
    //return new StringReader((sdata==null)?nodeListToString(nodeList,spreadsheet,fields):sdata);
    else/*from w w w  .  j  a v  a  2  s .  c  o m*/
        throw new UnsupportedFlavorException(flavor);
}

From source file:TreeDragTest.java

public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (isDataFlavorSupported(flavor)) {
        return (Object) path;
    } else {/*  w  ww  . j a  v a2s . c o m*/
        throw new UnsupportedFlavorException(flavor);
    }
}

From source file:TreeTester.java

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    Object returnObject;/*from  w  w w.  ja v  a2  s  .  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:com.haulmont.yarg.formatters.impl.DocFormatter.java

protected static void clearClipboard() {
    try {//  w ww  . j  a  v a 2  s.  c o m
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new Transferable() {
            public DataFlavor[] getTransferDataFlavors() {
                return new DataFlavor[0];
            }

            public boolean isDataFlavorSupported(DataFlavor flavor) {
                return false;
            }

            public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
                throw new UnsupportedFlavorException(flavor);
            }
        }, null);
    } catch (IllegalStateException ignored) {
        //ignore exception
    }
}

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
 *//*  w w w  .ja v a2  s . c om*/
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: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  w  ww  . java2  s. c  om*/
}

From source file:de.tor.tribes.ui.algo.AttackTimePanel.java

@Override
public void drop(DropTargetDropEvent dtde) {
    if (dtde.getDropTargetContext().getComponent().equals(jTimeFrameList)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        try {/*from w w  w. j  av a  2 s  . c o  m*/
            String data = (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor);
            TimeSpan s = TimeSpan.fromPropertyString(data);
            if (s == null) {
                throw new UnsupportedFlavorException(DataFlavor.stringFlavor);
            }
            addTimeSpan(s);
        } catch (UnsupportedFlavorException | IOException usfe) {
            //invalid data
        }
    }
}

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  ww w . j av a 2s. c om*/
 */
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);
    }
}

From source file:org.gephi.ui.components.ReportSelection.java

/**
 *
 * @param flavor//  w  w  w  . j av a 2  s. c om
 * @return
 * @throws java.awt.datatransfer.UnsupportedFlavorException
 */
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
    if (String.class.equals(flavor.getRepresentationClass())) {
        return html;
    }
    throw new UnsupportedFlavorException(flavor);
}

From source file:org.nuclos.client.explorer.ExplorerNode.java

/**
 * imports data from a drop or paste operation. The default implementation throws an
 * UnsupportedFlavorException to indicate that drag&drop is not supported by default.
 * @see javax.swing.TransferHandler#importData
 * @param transferable//  ww  w.  j a  v a  2 s .c  o m
 * @param tree
 * @return Was the data imported? <code>false</code> may be returned if the drop action requires
 * additional user input, and the user cancels the operation.
 * @throws UnsupportedFlavorException
 */
public boolean importTransferData(Component parent, Transferable transferable, JTree tree)
        throws IOException, UnsupportedFlavorException {
    throw new UnsupportedFlavorException(null);
}