Search in sources :

Example 21 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project cytoscape-impl by cytoscape.

the class DragHandler method drop.

@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent event) {
    JComponent target = getPrimaryView(view);
    setCursor(null, view);
    try {
        List<Integer> path = (List<Integer>) event.getTransferable().getTransferData(PathDataFlavor.instance);
        JComponent sourceView = controller.getChild(parent, path);
        if (sourceView == target) {
            event.rejectDrop();
            return;
        }
        List<Integer> targetPath = controller.getPath(parent, target);
        if (targetPath == null) {
            event.rejectDrop();
            return;
        }
        if (!controller.supportsDrop(parent, path, sourceView, targetPath, target) || isEquivalentLocation(path, targetPath, target)) {
            event.rejectDrop();
            return;
        }
        controller.handleDrop(parent, sourceView, path, target, targetPath);
        event.acceptDrop(DnDConstants.ACTION_LINK);
        event.dropComplete(true);
    } catch (UnsupportedFlavorException e) {
        logger.error("Unexpected error", e);
    } catch (IOException e) {
        logger.error("Unexpected error", e);
    }
}
Also used : JComponent(javax.swing.JComponent) List(java.util.List) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 22 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project Spark by igniterealtime.

the class ContactGroupTransferHandler method importData.

public boolean importData(JComponent comp, Transferable t) {
    if (comp instanceof JList) {
        JList list = (JList) comp;
        ContactGroup group = getContactGroup(list);
        if (t.isDataFlavorSupported(flavors[0])) {
            try {
                ContactItem item = (ContactItem) t.getTransferData(flavors[0]);
                DefaultListModel model = (DefaultListModel) list.getModel();
                int size = model.getSize();
                for (int i = 0; i < size; i++) {
                    ContactItem it = (ContactItem) model.getElementAt(i);
                    if (it.getDisplayName().equals(item.getDisplayName())) {
                        return false;
                    }
                }
                addContactItem(group, item);
                return true;
            } catch (UnsupportedFlavorException ignored) {
            } catch (IOException ignored) {
            }
        } else if (t.isDataFlavorSupported(flavors[1])) {
            try {
                Object o = t.getTransferData(flavors[1]);
                if (o instanceof java.util.Collection) {
                    Collection<File> files = (Collection<File>) o;
                    ContactItem source = (ContactItem) list.getSelectedValue();
                    if (source == null || source.getJID() == null) {
                        return false;
                    }
                    // Otherwise fire files dropped event.
                    SparkManager.getWorkspace().getContactList().fireFilesDropped(files, source);
                }
            } catch (UnsupportedFlavorException e) {
                Log.error(e);
            } catch (IOException e) {
                Log.error(e);
            }
        }
    }
    return false;
}
Also used : Collection(java.util.Collection) DefaultListModel(javax.swing.DefaultListModel) Collection(java.util.Collection) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) File(java.io.File) JList(javax.swing.JList)

Example 23 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project financial by greatkendy123.

the class ClipBoardUtil method setClipboardImage.

/**
 * 复制图片到剪切板。
 */
public static void setClipboardImage(final Image image) {
    Transferable trans = new Transferable() {

        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[] { DataFlavor.imageFlavor };
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return DataFlavor.imageFlavor.equals(flavor);
        }

        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            if (isDataFlavorSupported(flavor))
                return image;
            throw new UnsupportedFlavorException(flavor);
        }
    };
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trans, null);
}
Also used : Transferable(java.awt.datatransfer.Transferable) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 24 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project tetrad by cmu-phil.

the class SubsessionSelection method getTransferData.

/**
 * @return 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 IOException                if the data is no longer available in
 *                                    the requested flavor.
 * @throws UnsupportedFlavorException if the requested data flavor is not
 *                                    supported.
 * @see DataFlavor#getRepresentationClass
 */
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(flavor)) {
        throw new UnsupportedFlavorException(flavor);
    }
    try {
        List returnList = (List) new MarshalledObject(sessionElements).get();
        Point point = EditorUtils.getTopLeftPoint(returnList);
        point.translate(50, 50);
        // List returnList = this.sessionElements;
        // this.sessionElements = null;
        numPastes++;
        return returnList;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : MarshalledObject(java.rmi.MarshalledObject) List(java.util.List) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 25 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project blue by kunstmusik.

the class CodeRepositoryDropTarget method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();
    ElementHolder elem = (ElementHolder) parent.getUserObject();
    if (!elem.isGroup) {
        dtde.rejectDrop();
        return;
    }
    try {
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            if (tr.isDataFlavorSupported(flavors[i])) {
                dtde.acceptDrop(dtde.getDropAction());
                TreePath p = (TreePath) tr.getTransferData(flavors[i]);
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent();
                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                model.insertNodeInto(node, parent, 0);
                dtde.dropComplete(true);
                return;
            }
        }
        dtde.rejectDrop();
    } catch (UnsupportedFlavorException | IOException e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DropTargetContext(java.awt.dnd.DropTargetContext) Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath)

Aggregations

UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)106 IOException (java.io.IOException)92 Transferable (java.awt.datatransfer.Transferable)55 List (java.util.List)32 DataFlavor (java.awt.datatransfer.DataFlavor)26 File (java.io.File)25 Point (java.awt.Point)18 ArrayList (java.util.ArrayList)15 Clipboard (java.awt.datatransfer.Clipboard)14 JTree (javax.swing.JTree)9 TreePath (javax.swing.tree.TreePath)9 JComponent (javax.swing.JComponent)7 TransferHandler (javax.swing.TransferHandler)7 DropTargetContext (java.awt.dnd.DropTargetContext)6 URL (java.net.URL)5 DefaultTableModel (javax.swing.table.DefaultTableModel)5 Image (java.awt.Image)4 ActionEvent (java.awt.event.ActionEvent)4 MouseEvent (java.awt.event.MouseEvent)4 NodeInterface (com.sldeditor.common.NodeInterface)3