Search in sources :

Example 81 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project keystore-explorer by kaikramer.

the class KeyStoreEntryTransferable method getTransferData.

/**
 * Get transfer data.
 *
 * @param dataFlavor
 *            Data flavor
 * @return Transfer data
 * @throws UnsupportedFlavorException
 *             If the requested data flavor is not supported
 * @throws IOException
 *             If an I/O problem occurred
 */
@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException, IOException {
    if (!isDataFlavorSupported(dataFlavor)) {
        throw new UnsupportedFlavorException(dataFlavor);
    }
    if (dataFlavor == DataFlavor.javaFileListFlavor) {
        String tempDir = System.getProperty("java.io.tmpdir");
        File tmpFile = new File(tempDir, dragEntry.getFileName());
        tmpFile.deleteOnExit();
        try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
            fos.write(dragEntry.getContent());
            fos.flush();
        }
        List<File> list = new ArrayList<File>();
        list.add(tmpFile);
        return list;
    } else {
        return dragEntry.getContentString();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) File(java.io.File)

Example 82 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project openchemlib by Actelion.

the class MoleculeDragAdapter method drawDragImage.

public Image drawDragImage(Transferable transferable, int width, int height) {
    if (transferable instanceof MoleculeTransferable) {
        try {
            MoleculeTransferable t = (MoleculeTransferable) transferable;
            Object o = t.getTransferData(MoleculeFlavors.DF_SERIALIZEDOBJECT);
            if (o instanceof StereoMolecule) {
                StereoMolecule mol = (StereoMolecule) o;
                Depictor2D depict = new Depictor2D(mol);
                BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
                depict.validateView(g, new Rectangle2D.Double(0, 0, width, height), AbstractDepictor.cModeInflateToMaxAVBL);
                depict.paint(g);
                return img;
            }
        } catch (IOException e1) {
            System.err.println(e1);
        } catch (UnsupportedFlavorException e1) {
            System.err.println(e1);
        }
    }
    return null;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Depictor2D(com.actelion.research.chem.Depictor2D) IOException(java.io.IOException) StereoMolecule(com.actelion.research.chem.StereoMolecule) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BufferedImage(java.awt.image.BufferedImage)

Example 83 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.

the class ListTransfertHandler method importData.

@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport support) {
    if (!this.canImport(support)) {
        return false;
    }
    DnDList list = (DnDList) support.getComponent();
    DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) list.getModel();
    // This is a drop
    if (support.isDrop()) {
        if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
            int childIndex = dl.getIndex();
            List<Integer> selectAfterDrop = new ArrayList<>();
            // DnD from list
            if (this.dragPaths != null && !this.dragPaths.isEmpty()) {
                for (ItemList value : this.dragPaths) {
                    if (!"".equals(value.toString())) {
                        // ! FUUuu
                        ItemList newValue = new ItemList(value.toString().replace("\\", "/"));
                        selectAfterDrop.add(childIndex);
                        listModel.add(childIndex++, newValue);
                    }
                }
            } else {
                // DnD from outside
                try {
                    String importString = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
                    for (String value : importString.split("\\n")) {
                        if (!"".equals(value)) {
                            selectAfterDrop.add(childIndex);
                            listModel.add(childIndex++, new ItemList(value.replace("\\", "/")));
                        }
                    }
                } catch (UnsupportedFlavorException | IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
            int[] selectedIndices = new int[selectAfterDrop.size()];
            int i = 0;
            for (Integer integer : selectAfterDrop) {
                selectedIndices[i] = integer.intValue();
                i++;
            }
            list.setSelectedIndices(selectedIndices);
        } else if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
            int childIndex = dl.getIndex();
            try {
                list.dropPasteFile((List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor), childIndex);
            } catch (UnsupportedFlavorException | IOException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    } else {
        // This is a paste
        Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
        if (transferableFromClipboard != null) {
            if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                try {
                    String clipboardText = (String) transferableFromClipboard.getTransferData(DataFlavor.stringFlavor);
                    int selectedIndex = 0;
                    if (list.getSelectedIndex() > 0) {
                        selectedIndex = list.getSelectedIndex();
                    }
                    list.clearSelection();
                    List<Integer> selectedIndexes = new ArrayList<>();
                    for (String line : clipboardText.split("\\n")) {
                        if (!"".equals(line)) {
                            String newLine = line.replace("\\", "/");
                            ItemList newItem = new ItemList(newLine);
                            selectedIndexes.add(selectedIndex);
                            listModel.add(selectedIndex++, newItem);
                        }
                    }
                    int[] selectedIndexesPasted = new int[selectedIndexes.size()];
                    int i = 0;
                    for (Integer integer : selectedIndexes) {
                        selectedIndexesPasted[i] = integer.intValue();
                        i++;
                    }
                    list.setSelectedIndices(selectedIndexesPasted);
                    list.scrollRectToVisible(list.getCellBounds(list.getMinSelectionIndex(), list.getMaxSelectionIndex()));
                } catch (NullPointerException | UnsupportedFlavorException | IOException e) {
                    // Fix #8831: Multiple Exception on scrollRectToVisible()
                    LOGGER.error(e.getMessage(), e);
                }
            } else if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                try {
                    int selectedIndex = 0;
                    if (list.getSelectedIndex() > 0) {
                        selectedIndex = list.getSelectedIndex();
                    }
                    list.clearSelection();
                    list.dropPasteFile((List<File>) transferableFromClipboard.getTransferData(DataFlavor.javaFileListFlavor), selectedIndex);
                } catch (UnsupportedFlavorException | IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Transferable(java.awt.datatransfer.Transferable) DefaultListModel(javax.swing.DefaultListModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) JList(javax.swing.JList) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList)

Example 84 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.

the class ListTransfertHandlerScan method importData.

@SuppressWarnings("unchecked")
@Override
public boolean importData(TransferSupport support) {
    if (!this.canImport(support)) {
        return false;
    }
    DnDList list = (DnDList) support.getComponent();
    DefaultListModel<ItemList> listModel = (DefaultListModel<ItemList>) list.getModel();
    // This is a drop
    if (support.isDrop()) {
        if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            JList.DropLocation dropLocation = (JList.DropLocation) support.getDropLocation();
            int indexDropLocation = dropLocation.getIndex();
            List<Integer> listSelectedIndices = new ArrayList<>();
            // DnD from list
            if (this.dragPaths != null && !this.dragPaths.isEmpty()) {
                for (ItemList itemPath : this.dragPaths) {
                    if (!"".equals(itemPath.toString())) {
                        // ! FUUuu
                        ItemListScan itemDrag = (ItemListScan) itemPath;
                        ItemListScan itemDrop = new ItemListScan(itemDrag.getBeanInjection());
                        listSelectedIndices.add(indexDropLocation);
                        listModel.add(indexDropLocation++, itemDrop);
                    }
                }
            } else {
                // DnD from outside
                try {
                    String importString = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
                    for (ItemListScan itemListScan : ListTransfertHandlerScan.parse(importString)) {
                        listSelectedIndices.add(indexDropLocation);
                        listModel.add(indexDropLocation++, itemListScan);
                    }
                } catch (UnsupportedFlavorException | IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
            int[] selectedIndices = new int[listSelectedIndices.size()];
            int i = 0;
            for (Integer integer : listSelectedIndices) {
                selectedIndices[i] = integer.intValue();
                i++;
            }
            list.setSelectedIndices(selectedIndices);
        } else if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
            int childIndex = dl.getIndex();
            try {
                list.dropPasteFile((List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor), childIndex);
            } catch (UnsupportedFlavorException | IOException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    } else {
        // This is a paste
        Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
        if (transferableFromClipboard != null) {
            if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                try {
                    String clipboardText = (String) transferableFromClipboard.getTransferData(DataFlavor.stringFlavor);
                    int selectedIndex = 0;
                    if (list.getSelectedIndex() > 0) {
                        selectedIndex = list.getSelectedIndex();
                    }
                    list.clearSelection();
                    List<Integer> selectedIndexes = new ArrayList<>();
                    for (ItemListScan itemListScan : ListTransfertHandlerScan.parse(clipboardText)) {
                        selectedIndexes.add(selectedIndex);
                        listModel.add(selectedIndex++, itemListScan);
                    }
                    int[] selectedIndexesPasted = new int[selectedIndexes.size()];
                    int i = 0;
                    for (Integer integer : selectedIndexes) {
                        selectedIndexesPasted[i] = integer.intValue();
                        i++;
                    }
                    list.setSelectedIndices(selectedIndexesPasted);
                    list.scrollRectToVisible(list.getCellBounds(list.getMinSelectionIndex(), list.getMaxSelectionIndex()));
                } catch (NullPointerException | UnsupportedFlavorException | IOException e) {
                    // Fix #8831: Multiple Exception on scrollRectToVisible()
                    LOGGER.error(e.getMessage(), e);
                }
            } else if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                try {
                    int selectedIndex = 0;
                    if (list.getSelectedIndex() > 0) {
                        selectedIndex = list.getSelectedIndex();
                    }
                    list.clearSelection();
                    list.dropPasteFile((List<File>) transferableFromClipboard.getTransferData(DataFlavor.javaFileListFlavor), selectedIndex);
                } catch (UnsupportedFlavorException | IOException e) {
                    LOGGER.error(e.getMessage(), e);
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Transferable(java.awt.datatransfer.Transferable) DefaultListModel(javax.swing.DefaultListModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) JList(javax.swing.JList) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList)

Example 85 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project jsql-injection by ron190.

the class TabTransferHandler method importData.

@Override
public boolean importData(TransferHandler.TransferSupport support) {
    System.out.println("importData");
    if (!this.canImport(support)) {
        return false;
    }
    DnDTabbedPane target = (DnDTabbedPane) support.getComponent();
    DnDTabbedPane.DropLocation dl = target.getDropLocation();
    try {
        DnDTabData data = (DnDTabData) support.getTransferable().getTransferData(this.localObjectFlavor);
        DnDTabbedPane src = data.tabbedPane;
        // boolean insert = dl.isInsert();
        int index = dl.getIndex();
        if (target.equals(src)) {
            // getTargetTabIndex(e.getLocation()));
            src.convertTab(src.dragTabIndex, index);
        } else {
            src.exportTab(src.dragTabIndex, target, index);
        }
        return true;
    } catch (UnsupportedFlavorException | IOException ex) {
        ex.printStackTrace();
    }
    return false;
}
Also used : IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point)

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