Search in sources :

Example 51 with Transferable

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

the class RootNode method getDropType.

@Override
public PasteType getDropType(Transferable t, int action, int index) {
    final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
    if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
        try {
            final FilterBuilder fb = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
            return new PasteType() {

                @Override
                public Transferable paste() throws IOException {
                    FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                    Query f = filterController.createQuery(fb);
                    filterController.add(f);
                    return null;
                }
            };
        } catch (UnsupportedFlavorException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    } else if (dropNode != null && dropNode instanceof SavedQueryNode) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                SavedQueryNode node = (SavedQueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.add(node.getQuery());
                return null;
            }
        };
    } else if (dropNode != null && dropNode instanceof QueryNode && ((QueryNode) dropNode).getQuery().getParent() != null) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                QueryNode queryNode = (QueryNode) dropNode;
                FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                filterController.removeSubQuery(queryNode.getQuery(), queryNode.getQuery().getParent());
                filterController.add(queryNode.getQuery());
                return null;
            }
        };
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) FilterBuilder(org.gephi.filters.spi.FilterBuilder) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) Node(org.openide.nodes.Node) SavedQueryNode(org.gephi.desktop.filters.library.SavedQueryNode) FilterBuilderNode(org.gephi.desktop.filters.library.FilterBuilderNode) AbstractNode(org.openide.nodes.AbstractNode) PasteType(org.openide.util.datatransfer.PasteType) Transferable(java.awt.datatransfer.Transferable) FilterController(org.gephi.filters.api.FilterController) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 52 with Transferable

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

the class SlotNode method getDropType.

@Override
public PasteType getDropType(final Transferable t, int action, int index) {
    final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
    if (dropNode != null && dropNode instanceof QueryNode) {
        Query q = ((QueryNode) dropNode).getQuery();
        if (!Arrays.asList(q.getDescendantsAndSelf()).contains(parent)) {
            //Check if not parent
            return new PasteType() {

                @Override
                public Transferable paste() throws IOException {
                    QueryNode queryNode = (QueryNode) dropNode;
                    FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                    filterController.setSubQuery(parent, queryNode.getQuery());
                    return null;
                }
            };
        }
    } else if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
        return new PasteType() {

            @Override
            public Transferable paste() throws IOException {
                try {
                    FilterBuilder builder = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
                    FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
                    Query query = filterController.createQuery(builder);
                    filterController.setSubQuery(parent, query);
                } catch (UnsupportedFlavorException ex) {
                    Exceptions.printStackTrace(ex);
                }
                return null;
            }
        };
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) FilterBuilder(org.gephi.filters.spi.FilterBuilder) Node(org.openide.nodes.Node) FilterBuilderNode(org.gephi.desktop.filters.library.FilterBuilderNode) AbstractNode(org.openide.nodes.AbstractNode) PasteType(org.openide.util.datatransfer.PasteType) Transferable(java.awt.datatransfer.Transferable) FilterController(org.gephi.filters.api.FilterController) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 53 with Transferable

use of java.awt.datatransfer.Transferable in project languagetool by languagetool-org.

the class Main method getClipboardText.

private String getClipboardText() {
    // get text from clipboard or selection:
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
    if (clipboard == null) {
        // on Windows
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    String s;
    Transferable data = clipboard.getContents(this);
    try {
        if (data != null && data.isDataFlavorSupported(DataFlavor.getTextPlainUnicodeFlavor())) {
            DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
            try (Reader sr = df.getReaderForText(data)) {
                s = StringTools.readerToString(sr);
            }
        } else {
            s = "";
        }
    } catch (Exception ex) {
        s = data.toString();
    }
    return s;
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) PortBindingException(org.languagetool.server.PortBindingException) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 54 with Transferable

use of java.awt.datatransfer.Transferable in project AozoraEpub3 by hmdev.

the class JCoverImagePanel method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    Transferable transfer = dtde.getTransferable();
    try {
        if (transfer.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            @SuppressWarnings("unchecked") List<File> files = (List<File>) transfer.getTransferData(DataFlavor.javaFileListFlavor);
            if (files.size() > 0) {
                bookInfo.coverFileName = files.get(0).getAbsolutePath();
                bookInfo.loadCoverImage(bookInfo.coverFileName);
                bookInfo.coverImageIndex = -1;
                this.fitType = FIT_ZOOM;
                this.setFitType(FIT_ALL, true);
                repaint();
                if (this.linstener != null)
                    this.linstener.actionPerformed(this.changeAction);
                return;
            }
        }
        if (transfer.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            bookInfo.coverFileName = transfer.getTransferData(DataFlavor.stringFlavor).toString();
            if (bookInfo.coverFileName.startsWith("file://"))
                bookInfo.coverFileName = URLDecoder.decode(bookInfo.coverFileName.substring(0, bookInfo.coverFileName.indexOf('\n') - 1).substring(7).trim(), "UTF-8");
            bookInfo.loadCoverImage(bookInfo.coverFileName);
            bookInfo.coverImageIndex = -1;
            this.setFitType(FIT_ALL, true);
            repaint();
            if (this.linstener != null)
                this.linstener.actionPerformed(changeAction);
            return;
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
    this.requestFocus();
}
Also used : Transferable(java.awt.datatransfer.Transferable) List(java.util.List) File(java.io.File)

Example 55 with Transferable

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

the class JglfwClipboard method getContents.

public String getContents() {
    try {
        java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable contents = clipboard.getContents(null);
        if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            return (String) contents.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (Exception ignored) {
    // Ignore JDK crashes sorting data flavors.
    }
    return "";
}
Also used : Transferable(java.awt.datatransfer.Transferable)

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