Search in sources :

Example 41 with UnsupportedFlavorException

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

the class MainFrame method drop.

/**
 * Handler of Top level Dnd
 */
@Override
public void drop(DropTargetDropEvent dtde) {
    Transferable tr = dtde.getTransferable();
    boolean anyFlavourIsJavaFileList = Arrays.stream(tr.getTransferDataFlavors()).anyMatch(DataFlavor::isFlavorJavaFileListType);
    if (anyFlavourIsJavaFileList) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        try {
            openJmxFilesFromDragAndDrop(tr);
        } catch (UnsupportedFlavorException | IOException e) {
            log.warn("Dnd failed", e);
        } finally {
            dtde.dropComplete(true);
        }
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 42 with UnsupportedFlavorException

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

the class JMeterTreeNodeTransferable method getTransferData.

@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(flavor)) {
        throw new UnsupportedFlavorException(flavor);
    }
    if (data != null) {
        ObjectInput ois = null;
        try {
            ois = new ObjectInputStream(new ByteArrayInputStream(data));
            JMeterTreeNode[] nodes = (JMeterTreeNode[]) ois.readObject();
            return nodes;
        } catch (ClassNotFoundException cnfe) {
            throw new IOException("Failed to read object stream.", cnfe);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (Exception e) {
                // NOOP
                }
            }
        }
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) ObjectInput(java.io.ObjectInput) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 43 with UnsupportedFlavorException

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

the class ArgumentsPanel method addFromClipboard.

/**
 * Add values from the clipboard
 * @param lineDelimiter Delimiter string to split clipboard into lines
 * @param argDelimiter Delimiter string to split line into key-value pair
 */
protected void addFromClipboard(String lineDelimiter, String argDelimiter) {
    GuiUtils.stopTableEditing(table);
    int rowCount = table.getRowCount();
    try {
        String clipboardContent = GuiUtils.getPastedText();
        if (clipboardContent == null) {
            return;
        }
        String[] clipboardLines = clipboardContent.split(lineDelimiter);
        for (String clipboardLine : clipboardLines) {
            String[] clipboardCols = clipboardLine.split(argDelimiter);
            if (clipboardCols.length > 0) {
                Argument argument = createArgumentFromClipboard(clipboardCols);
                tableModel.addRow(argument);
            }
        }
        if (table.getRowCount() > rowCount) {
            checkButtonsStatus();
            // Highlight (select) and scroll to the appropriate rows.
            int rowToSelect = tableModel.getRowCount() - 1;
            table.setRowSelectionInterval(rowCount, rowToSelect);
            table.scrollRectToVisible(table.getCellRect(rowCount, 0, true));
        }
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(this, "Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (UnsupportedFlavorException ufe) {
        JOptionPane.showMessageDialog(this, "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : Argument(org.apache.jmeter.config.Argument) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 44 with UnsupportedFlavorException

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

the class DroppableFrame method drop.

@Override
public void drop(DropTargetDropEvent dropTargetDropEvent) {
    try {
        Transferable transferable = dropTargetDropEvent.getTransferable();
        if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
            List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            while (iterator.hasNext()) {
                File file = (File) iterator.next();
                if (file.isFile()) {
                    fileDropped(file);
                }
                if (file.isDirectory()) {
                    directoryDropped(file);
                }
            }
            dropTargetDropEvent.getDropTargetContext().dropComplete(true);
        } else {
            dropTargetDropEvent.rejectDrop();
        }
    } catch (IOException | UnsupportedFlavorException io) {
        io.printStackTrace();
        dropTargetDropEvent.rejectDrop();
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) Iterator(java.util.Iterator) List(java.util.List) IOException(java.io.IOException) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 45 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project java-swing-tips by aterai.

the class TablePopupMenu method importData.

@Override
public boolean importData(TransferHandler.TransferSupport support) {
    List<?> list;
    try {
        list = (List<?>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
    } catch (UnsupportedFlavorException | IOException ex) {
        return false;
    }
    DefaultTableModel model = (DefaultTableModel) ((JTable) support.getComponent()).getModel();
    list.stream().filter(File.class::isInstance).map(File.class::cast).map(f -> Collections.nCopies(3, f).toArray()).forEach(model::addRow);
    return true;
}
Also used : IntStream(java.util.stream.IntStream) ItemEvent(java.awt.event.ItemEvent) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) DataFlavor(java.awt.datatransfer.DataFlavor) DefaultTableModel(javax.swing.table.DefaultTableModel) IOException(java.io.IOException) TableRowSorter(javax.swing.table.TableRowSorter) File(java.io.File) Serializable(java.io.Serializable) java.awt(java.awt) List(java.util.List) FileSystemView(javax.swing.filechooser.FileSystemView) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Stream(java.util.stream.Stream) Comparator(java.util.Comparator) Collections(java.util.Collections) javax.swing(javax.swing) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) File(java.io.File)

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