Search in sources :

Example 11 with UnsupportedFlavorException

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

the class DnDTableImportExportHandler method importData.

@Override
public boolean importData(TransferHandler.TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    if (log.isDebugEnabled()) {
        JTable.DropLocation loc = (JTable.DropLocation) support.getDropLocation();
        log.debug("importData: isDrop= {} location= {} row= {} col= {}", support.isDrop(), loc.getDropPoint(), loc.getRow(), loc.getColumn());
    }
    if (!support.isDrop()) {
        return false;
    }
    TransferHandler.DropLocation loc = support.getDropLocation();
    if (!(loc instanceof JTable.DropLocation)) {
        return false;
    }
    Component comp = support.getComponent();
    if (!(comp instanceof JTable)) {
        return false;
    }
    JTable.DropLocation location = (JTable.DropLocation) loc;
    JTable table = (JTable) comp;
    int row = location.getRow();
    int col = location.getColumn();
    row = table.convertRowIndexToModel(row);
    col = table.convertColumnIndexToModel(col);
    for (int i = 0; i < _skipColumns.length; i++) {
        if (_skipColumns[i] == col) {
            return false;
        }
    }
    try {
        Transferable trans = support.getTransferable();
        Object obj = trans.getTransferData(DataFlavor.stringFlavor);
        table.getModel().setValueAt(obj, row, col);
        return true;
    } catch (UnsupportedFlavorException ufe) {
        log.warn("DnDStringImportHandler.importData: " + ufe.getMessage());
    } catch (IOException ioe) {
        log.warn("DnDStringImportHandler.importData: " + ioe.getMessage());
    }
    return false;
}
Also used : JTable(javax.swing.JTable) Transferable(java.awt.datatransfer.Transferable) TransferHandler(javax.swing.TransferHandler) IOException(java.io.IOException) Component(java.awt.Component) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 12 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project android by JetBrains.

the class PTable method performPaste.

@Override
public void performPaste(@NotNull DataContext dataContext) {
    PTableItem item = getSelectedNonGroupItem();
    if (item == null) {
        return;
    }
    Transferable transferable = myCopyPasteManager.getContents();
    if (transferable == null || !transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        return;
    }
    try {
        item.setValue(transferable.getTransferData(DataFlavor.stringFlavor));
    } catch (IOException | UnsupportedFlavorException exception) {
        Logger.getInstance(PTable.class).warn(exception);
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 13 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project knime-core by knime.

the class SelectionPanel method drop.

/**
 * {@inheritDoc}
 */
@Override
public void drop(final DropTargetDropEvent dtde) {
    if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
        dtde.acceptDrop(dtde.getDropAction());
        Transferable t = dtde.getTransferable();
        String s = "default";
        try {
            s = (String) t.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException e) {
        // TODO Auto-generated catch block
        } catch (IOException e) {
        // TODO Auto-generated catch block
        }
        int i = m_config.drop(s);
        Pane dp = getNewPane(m_includePanel, m_config, i);
        m_includePanel.add(dp.getComponentPanel(), m_gbc);
        m_gbc.gridy++;
        m_includePanel.setBackground(UIManager.getColor("Panel.background"));
        m_scrollPane.revalidate();
        dtde.dropComplete(true);
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) JSplitPane(javax.swing.JSplitPane) Pane(org.knime.base.node.preproc.draganddroppanel.droppanes.Pane) JScrollPane(javax.swing.JScrollPane)

Example 14 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project Terasology by MovingBlocks.

the class AbstractEditorScreen method pasteJson.

/**
 * Attempts to serialize the system clipboard's contents - if successful,
 * sets the current state of the editor to the serialized {@link JsonTree}.
 */
protected void pasteJson() {
    // Get the clipboard contents.
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = clipboard.getContents(null);
    // Attempt to convert them to a string.
    String clipboardContents = null;
    try {
        if (t != null) {
            clipboardContents = (String) t.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (UnsupportedFlavorException | IOException e) {
        logger.warn("Could not fetch clipboard contents.", e);
    }
    if (clipboardContents != null) {
        try {
            // Attempt to serialize them to a JsonTree and reset the editor state.
            JsonElement json = new JsonParser().parse(clipboardContents);
            JsonTree node = JsonTreeConverter.serialize(json);
            resetState(node);
        } catch (JsonSyntaxException | NullPointerException e) {
            logger.warn("Could not construct a valid tree from clipboard contents.", e);
        }
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) JsonElement(com.google.gson.JsonElement) Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) JsonParser(com.google.gson.JsonParser)

Example 15 with UnsupportedFlavorException

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

the class PDFDebugger method initComponents.

/**
 * This method is called from within the constructor to initialize the form.
 */
private void initComponents() {
    jSplitPane1 = new javax.swing.JSplitPane();
    jScrollPane1 = new JScrollPane();
    tree = new Tree(this);
    jScrollPane2 = new JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    tree.setCellRenderer(new PDFTreeCellRenderer());
    tree.setModel(null);
    setTitle("Apache PDFBox Debugger");
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent windowEvent) {
            tree.requestFocusInWindow();
            super.windowOpened(windowEvent);
        }

        @Override
        public void windowClosing(WindowEvent evt) {
            exitForm(evt);
        }
    });
    jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
    jScrollPane1.setPreferredSize(new Dimension(350, 500));
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            jTree1ValueChanged(evt);
        }
    });
    jScrollPane1.setViewportView(tree);
    jSplitPane1.setRightComponent(jScrollPane2);
    jSplitPane1.setDividerSize(3);
    jScrollPane2.setPreferredSize(new Dimension(300, 500));
    jScrollPane2.setViewportView(jTextPane1);
    jSplitPane1.setLeftComponent(jScrollPane1);
    JScrollPane documentScroller = new JScrollPane();
    documentScroller.setViewportView(documentPanel);
    statusPane = new TreeStatusPane(tree);
    statusPane.getPanel().setBorder(new BevelBorder(BevelBorder.RAISED));
    statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
    getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);
    getContentPane().add(jSplitPane1, BorderLayout.CENTER);
    statusBar = new ReaderBottomPanel();
    getContentPane().add(statusBar, BorderLayout.SOUTH);
    // create menus
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createFileMenu());
    menuBar.add(createEditMenu());
    ViewMenu viewMenu = ViewMenu.getInstance(this);
    menuBar.add(viewMenu.getMenu());
    setJMenuBar(menuBar);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = 1000;
    int height = 970;
    setBounds((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);
    // drag and drop to open files
    setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferSupport transferSupport) {
            return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
        }

        @Override
        @SuppressWarnings("unchecked")
        public boolean importData(TransferSupport transferSupport) {
            try {
                Transferable transferable = transferSupport.getTransferable();
                List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                readPDFFile(files.get(0), "");
                return true;
            } catch (IOException e) {
                new ErrorDialog(e).setVisible(true);
                return true;
            } catch (UnsupportedFlavorException e) {
                throw new RuntimeException(e);
            }
        }
    });
    // Mac OS X file open/quit handler
    if (IS_MAC_OS && !isMinJdk9()) {
        // TODO this needs to be rewritten for JDK9, see PDFBOX-4013
        try {
            Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
            osxOpenFiles.setAccessible(true);
            OSXAdapter.setFileHandler(this, osxOpenFiles);
            Method osxQuit = getClass().getDeclaredMethod("osxQuit");
            osxQuit.setAccessible(true);
            OSXAdapter.setQuitHandler(this, osxQuit);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : BevelBorder(javax.swing.border.BevelBorder) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeStatusPane(org.apache.pdfbox.debugger.treestatus.TreeStatusPane) PDFTreeCellRenderer(org.apache.pdfbox.debugger.ui.PDFTreeCellRenderer) Tree(org.apache.pdfbox.debugger.ui.Tree) ViewMenu(org.apache.pdfbox.debugger.ui.ViewMenu) List(java.util.List) JScrollPane(javax.swing.JScrollPane) Transferable(java.awt.datatransfer.Transferable) ErrorDialog(org.apache.pdfbox.debugger.ui.ErrorDialog) Dimension(java.awt.Dimension) IOException(java.io.IOException) Method(java.lang.reflect.Method) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) WindowEvent(java.awt.event.WindowEvent) TransferHandler(javax.swing.TransferHandler) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ReaderBottomPanel(org.apache.pdfbox.debugger.ui.ReaderBottomPanel) File(java.io.File) JMenuBar(javax.swing.JMenuBar)

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