Search in sources :

Example 81 with Transferable

use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.

the class TargetPanel method drop.

public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    if (dtde.isDataFlavorSupported(dataFlavor)) {
        String result = null;
        try {
            Transferable t = dtde.getTransferable();
            byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
            result = new String(data, "UTF-16");
            repaint();
        } catch (UnsupportedFlavorException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        dtde.dropComplete(true);
        if (result != null && result.contains(MyTransferable.TEST_DATA)) {
            System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
            Timer t = new Timer();
            t.schedule(new TimerTask() {

                @Override
                public void run() {
                    System.exit(0);
                }
            }, 2000);
            return;
        }
    }
    dtde.rejectDrop();
    System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
    System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 82 with Transferable

use of java.awt.datatransfer.Transferable in project jabref by JabRef.

the class ClipBoardManager method getClipboardContents.

/**
     * Get the String residing on the clipboard.
     *
     * @return any text found on the Clipboard; if none found, return an
     * empty String.
     */
public String getClipboardContents() {
    String result = "";
    //odd: the Object param of getContents is not currently used
    Transferable contents = CLIPBOARD.getContents(null);
    if ((contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException e) {
            //highly unlikely since we are using a standard DataFlavor
            LOGGER.info("problem with getting clipboard contents", e);
        }
    }
    return result;
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 83 with Transferable

use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.

the class DragSourceContext method readObject.

/**
     * Deserializes this <code>DragSourceContext</code>. This method first
     * performs default deserialization for all non-<code>transient</code>
     * fields. This object's <code>Transferable</code> and
     * <code>DragSourceListener</code> are then deserialized as well by using
     * the next two objects in the stream. If the resulting
     * <code>Transferable</code> is <code>null</code>, this object's
     * <code>Transferable</code> is set to a dummy <code>Transferable</code>
     * which supports no <code>DataFlavor</code>s.
     *
     * @since 1.4
     */
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    ObjectInputStream.GetField f = s.readFields();
    DragGestureEvent newTrigger = (DragGestureEvent) f.get("trigger", null);
    if (newTrigger == null) {
        throw new InvalidObjectException("Null trigger");
    }
    if (newTrigger.getDragSource() == null) {
        throw new InvalidObjectException("Null DragSource");
    }
    if (newTrigger.getComponent() == null) {
        throw new InvalidObjectException("Null trigger component");
    }
    int newSourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
    if (newSourceActions == DnDConstants.ACTION_NONE) {
        throw new InvalidObjectException("Invalid source actions");
    }
    int triggerActions = newTrigger.getDragAction();
    if (triggerActions != DnDConstants.ACTION_COPY && triggerActions != DnDConstants.ACTION_MOVE && triggerActions != DnDConstants.ACTION_LINK) {
        throw new InvalidObjectException("No drag action");
    }
    trigger = newTrigger;
    cursor = (Cursor) f.get("cursor", null);
    useCustomCursor = f.get("useCustomCursor", false);
    sourceActions = newSourceActions;
    transferable = (Transferable) s.readObject();
    listener = (DragSourceListener) s.readObject();
    // Implementation assumes 'transferable' is never null.
    if (transferable == null) {
        if (emptyTransferable == null) {
            emptyTransferable = 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);
                }
            };
        }
        transferable = emptyTransferable;
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) InvalidObjectException(java.io.InvalidObjectException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) ObjectInputStream(java.io.ObjectInputStream) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 84 with Transferable

use of java.awt.datatransfer.Transferable in project jdk8u_jdk by JetBrains.

the class DropTargetContext method getTransferable.

/**
     * get the Transferable (proxy) operand of this operation
     * <P>
     * @throws InvalidDnDOperationException if a drag is not outstanding/extant
     * <P>
     * @return the <code>Transferable</code>
     */
protected Transferable getTransferable() throws InvalidDnDOperationException {
    DropTargetContextPeer peer = getDropTargetContextPeer();
    if (peer == null) {
        throw new InvalidDnDOperationException();
    } else {
        if (transferable == null) {
            Transferable t = peer.getTransferable();
            boolean isLocal = peer.isTransferableJVMLocal();
            synchronized (this) {
                if (transferable == null) {
                    transferable = createTransferableProxy(t, isLocal);
                }
            }
        }
        return transferable;
    }
}
Also used : DropTargetContextPeer(java.awt.dnd.peer.DropTargetContextPeer) Transferable(java.awt.datatransfer.Transferable)

Example 85 with Transferable

use of java.awt.datatransfer.Transferable in project JMRI by JMRI.

the class DropJLabel method drop.

@Override
public void drop(DropTargetDropEvent e) {
    try {
        Transferable tr = e.getTransferable();
        if (e.isDataFlavorSupported(_dataFlavor)) {
            NamedIcon newIcon = new NamedIcon((NamedIcon) tr.getTransferData(_dataFlavor));
            accept(e, newIcon);
        } else if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String) tr.getTransferData(DataFlavor.stringFlavor);
            if (log.isDebugEnabled()) {
                log.debug("drop for stringFlavor " + text);
            }
            NamedIcon newIcon = new NamedIcon(text, text);
            accept(e, newIcon);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("DropJLabel.drop REJECTED!");
            }
            e.rejectDrop();
        }
    } catch (IOException ioe) {
        if (log.isDebugEnabled()) {
            log.debug("DropPanel.drop REJECTED!");
        }
        e.rejectDrop();
    } catch (UnsupportedFlavorException ufe) {
        if (log.isDebugEnabled()) {
            log.debug("DropJLabel.drop REJECTED!");
        }
        e.rejectDrop();
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Aggregations

Transferable (java.awt.datatransfer.Transferable)96 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)30 IOException (java.io.IOException)30 List (java.util.List)18 DataFlavor (java.awt.datatransfer.DataFlavor)14 ArrayList (java.util.ArrayList)14 File (java.io.File)13 Clipboard (java.awt.datatransfer.Clipboard)12 Point (java.awt.Point)9 StringSelection (java.awt.datatransfer.StringSelection)5 Project (com.intellij.openapi.project.Project)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 TransferHandler (javax.swing.TransferHandler)4 Editor (com.intellij.openapi.editor.Editor)3 ActionEvent (java.awt.event.ActionEvent)3 JComponent (javax.swing.JComponent)3 TreePath (javax.swing.tree.TreePath)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2