Search in sources :

Example 36 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project AndrOBD by fr3ts0n.

the class PvTransferHandler method importData.

/* (non-Javadoc)
	   * @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
	   */
@Override
public boolean importData(TransferSupport support) {
    try {
        if (support.getComponent() instanceof JTree) {
            JTree tree = (JTree) support.getComponent();
            Point dropPoint = support.getDropLocation().getDropPoint();
            TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
            Object node = path.getLastPathComponent();
            if (support.isDataFlavorSupported(processVarFlavor)) {
                ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
                ProcessVar chldPv = (ProcessVar) support.getTransferable().getTransferData(processVarFlavor);
                Object chldKey = chldPv.getKeyValue();
                tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                model.nodeStructureChanged((TreeNode) model.getRoot());
                return true;
            }
        }
    } catch (UnsupportedFlavorException e) {
        ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
    } catch (IOException e) {
        ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
    }
    // anything else is handled by superclass
    return super.importData(support);
}
Also used : JTree(javax.swing.JTree) ProcessVar(com.fr3ts0n.pvs.ProcessVar) TreePath(javax.swing.tree.TreePath) Point(java.awt.Point) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 37 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project freeplane by freeplane.

the class MClipboardController method getFlavorHandler.

private IDataFlavorHandler getFlavorHandler(final Transferable t) {
    if (t.isDataFlavorSupported(MindMapNodesSelection.mindMapNodesFlavor)) {
        try {
            final String textFromClipboard = t.getTransferData(MindMapNodesSelection.mindMapNodesFlavor).toString();
            return new MindMapNodesFlavorHandler(textFromClipboard);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    final ResourceController resourceController = ResourceController.getResourceController();
    DataFlavor supportedHtmlFlavor = getSupportedHtmlFlavor(t);
    if (supportedHtmlFlavor != null) {
        try {
            final String textFromClipboard = t.getTransferData(supportedHtmlFlavor).toString();
            if (textFromClipboard.charAt(0) != 65533) {
                if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                    final MTextController textController = (MTextController) TextController.getController();
                    final boolean richText = textController.useRichTextInEditor(RESOURCES_REMIND_USE_RICH_TEXT_IN_NEW_NODES);
                    if (richText) {
                        final boolean structuredHtmlImport = resourceController.getBooleanProperty("structured_html_import");
                        final IDataFlavorHandler htmlFlavorHandler;
                        if (structuredHtmlImport) {
                            htmlFlavorHandler = new StructuredHtmlFlavorHandler(textFromClipboard);
                        } else {
                            htmlFlavorHandler = new DirectHtmlFlavorHandler(textFromClipboard);
                        }
                        return htmlFlavorHandler;
                    }
                }
            }
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(MindMapNodesSelection.fileListFlavor)) {
        try {
            final List<File> fileList = castToFileList(t.getTransferData(MindMapNodesSelection.fileListFlavor));
            if (!shouldIgnoreFileListFlavor(fileList))
                return new FileListFlavorHandler(fileList);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            final String plainTextFromClipboard = t.getTransferData(DataFlavor.stringFlavor).toString();
            return new StringFlavorHandler(plainTextFromClipboard);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        try {
            Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
            return new ImageFlavorHandler(image);
        } catch (final UnsupportedFlavorException e) {
        } catch (final IOException e) {
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) Image(java.awt.Image) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataFlavor(java.awt.datatransfer.DataFlavor) ResourceController(org.freeplane.core.resources.ResourceController) MTextController(org.freeplane.features.text.mindmapmode.MTextController) File(java.io.File)

Example 38 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project zaproxy by zaproxy.

the class ExtensionStdMenus method getClipboardContents.

private String getClipboardContents() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clipboard.getContents(null);
    if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            return (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException e) {
            log.error("Unable to get data from clipboard");
        }
    }
    return "";
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 39 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project binnavi by google.

the class AbstractTreeTransferHandler method drop.

@Override
public final void drop(final DropTargetDropEvent dtde) {
    if (drawImage) {
        clearImage();
    }
    final int action = dtde.getDropAction();
    final Transferable transferable = dtde.getTransferable();
    final Point pt = dtde.getLocation();
    if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
        boolean gotData = false;
        DefaultMutableTreeNode node = null;
        try {
            node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
            gotData = true;
        } catch (final IOException e) {
            // TODO: This should be properly logged
            System.out.println(e);
        } catch (final UnsupportedFlavorException e) {
            // TODO: This should be properly logged
            System.out.println(e);
        }
        if (gotData) {
            final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
            final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
            if (executeDrop(tree, node, newParentNode, action)) {
                dtde.acceptDrop(action);
                dtde.dropComplete(true);
                return;
            }
        }
    } else if (canPerformAction(tree, dtde.getCurrentDataFlavors()[0], dtde.getTransferable(), action, pt)) {
        final TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
        final DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode) pathTarget.getLastPathComponent();
        if (executeDrop(tree, dtde.getTransferable(), newParentNode, action)) {
            dtde.acceptDrop(action);
            dtde.dropComplete(true);
            return;
        }
    }
    dtde.rejectDrop();
    dtde.dropComplete(false);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point)

Example 40 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jmeter by apache.

the class ProxyControlGui method addFromClipboard.

/**
 * Add values from the clipboard to table
 * @param table {@link JTable}
 */
protected void addFromClipboard(JTable table) {
    GuiUtils.stopTableEditing(table);
    int rowCount = table.getRowCount();
    try {
        String clipboardContent = GuiUtils.getPastedText();
        if (clipboardContent != null) {
            PowerTableModel model = null;
            String[] clipboardLines = clipboardContent.split(NEW_LINE);
            for (String clipboardLine : clipboardLines) {
                model = (PowerTableModel) table.getModel();
                model.addRow(new Object[] { clipboardLine });
            }
            if (model != null && table.getRowCount() > rowCount) {
                // Highlight (select) the appropriate rows.
                int rowToSelect = model.getRowCount() - 1;
                table.setRowSelectionInterval(rowCount, rowToSelect);
            }
        }
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(this, // $NON-NLS-1$
        JMeterUtils.getResString("proxy_daemon_error_read_args") + "\n" + // $NON-NLS-1$  $NON-NLS-2$
        ioe.getLocalizedMessage(), // $NON-NLS-1$  $NON-NLS-2$
        JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
    } catch (UnsupportedFlavorException ufe) {
        JOptionPane.showMessageDialog(this, // $NON-NLS-1$
        JMeterUtils.getResString("proxy_daemon_error_not_retrieve") + SPACE + DataFlavor.stringFlavor.getHumanPresentableName() + SPACE + // $NON-NLS-1$
        JMeterUtils.getResString("proxy_daemon_error_from_clipboard") + // $NON-NLS-1$
        ufe.getLocalizedMessage(), // $NON-NLS-1$
        JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : PowerTableModel(org.apache.jmeter.gui.util.PowerTableModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

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