Search in sources :

Example 71 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException in project blue by kunstmusik.

the class InstrumentTreeDropTarget method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    Object node = parentpath.getLastPathComponent();
    if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_CAT_FLAVOR)) {
        if (!(node instanceof InstrumentCategory)) {
            dtde.rejectDrop();
            return;
        }
        if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable tr = dtde.getTransferable();
            try {
                Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_CAT_FLAVOR);
                InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
                InstrumentCategory parentNode = (InstrumentCategory) node;
                InstrumentCategory instrumentCategory = (InstrumentCategory) transferNode;
                // iLibrary.removeCategory(instrumentCategory);
                iLibrary.addCategory(parentNode, instrumentCategory);
                dtde.dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                dtde.dropComplete(false);
            }
        } else {
            dtde.rejectDrop();
        }
    } else if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_FLAVOR)) {
        dtde.acceptDrop(dtde.getDropAction());
        try {
            Transferable tr = dtde.getTransferable();
            Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_FLAVOR);
            Instrument instrument = (Instrument) transferNode;
            InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
            if (instrument instanceof BlueSynthBuilder) {
                ((BlueSynthBuilder) instrument).clearParameters();
            }
            // iLibrary.removeInstrument(instrument);
            if (node instanceof InstrumentCategory) {
                InstrumentCategory parentNode = (InstrumentCategory) node;
                iLibrary.addInstrument(parentNode, instrument);
            } else if (node instanceof Instrument) {
                InstrumentCategory parentNode = (InstrumentCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
                int index = ListUtil.indexOfByRef(parentNode.getInstruments(), node);
                int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
                Rectangle bounds = tree.getRowBounds(closestRow);
                if (pt.y > bounds.y + bounds.height) {
                    iLibrary.addInstrument(parentNode, instrument);
                } else {
                    iLibrary.addInstrument(parentNode, index, instrument);
                }
            }
            dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
            dtde.dropComplete(false);
        }
    } else {
        dtde.rejectDrop();
    }
}
Also used : DropTargetContext(java.awt.dnd.DropTargetContext) Transferable(java.awt.datatransfer.Transferable) Rectangle(java.awt.Rectangle) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) InstrumentLibrary(blue.InstrumentLibrary) Instrument(blue.orchestra.Instrument) InstrumentCategory(blue.orchestra.InstrumentCategory)

Example 72 with UnsupportedFlavorException

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

the class PvTransferHandler method exportDone.

/* (non-Javadoc)
	   * @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
	   */
@Override
protected void exportDone(JComponent c, Transferable t, int action) {
    try {
        if (action == MOVE) {
            ProcessVar pv = (ProcessVar) t.getTransferData(processVarFlavor);
            pv.firePvChanged(new PvChangeEvent(pv, pv.getKeyAttribute(), pv, PvChangeEvent.PV_ELIMINATED));
        }
    } catch (UnsupportedFlavorException e) {
        ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
    } catch (IOException e) {
        ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
    }
}
Also used : ProcessVar(com.fr3ts0n.pvs.ProcessVar) PvChangeEvent(com.fr3ts0n.pvs.PvChangeEvent) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 73 with UnsupportedFlavorException

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

the class DragNDropFrameAdapter method register.

public static void register() {
    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    frame.setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferHandler.TransferSupport support) {
            if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                return false;
            }
            // Impossible to get data here and look if compatible format
            return true;
        }

        @Override
        public boolean importData(TransferHandler.TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            try {
                List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                File file = (File) data.get(0);
                FileObject fileObject = FileUtil.toFileObject(file);
                if (!file.exists()) {
                    return false;
                }
                if (fileObject.hasExt(GEPHI_EXTENSION)) {
                    ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                    try {
                        pc.openProject(file);
                    } catch (Exception ew) {
                        Exceptions.printStackTrace(ew);
                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                        DialogDisplayer.getDefault().notify(msg);
                    }
                } else {
                    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                    if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                        importController.importFile(fileObject);
                    } else {
                        return false;
                    }
                }
                return true;
            } catch (UnsupportedFlavorException ex) {
                Exceptions.printStackTrace(ex);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
            return false;
        }
    });
}
Also used : IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) JFrame(javax.swing.JFrame) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) TransferHandler(javax.swing.TransferHandler) List(java.util.List) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 74 with UnsupportedFlavorException

use of java.awt.datatransfer.UnsupportedFlavorException 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 75 with UnsupportedFlavorException

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

the class LocalManifestAdapter method getTransferData.

@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException {
    Object transferData = null;
    int index = transferDataFlavors.indexOf(dataFlavor);
    if (index == -1) {
        throw new UnsupportedFlavorException(dataFlavor);
    }
    if (dataFlavor.equals(DataFlavor.stringFlavor)) {
        transferData = localManifest.getText();
    } else if (dataFlavor.equals(DataFlavor.imageFlavor)) {
        Picture picture = (Picture) localManifest.getImage();
        transferData = picture.getBufferedImage();
    } else if (dataFlavor.equals(DataFlavor.javaFileListFlavor)) {
        FileList fileList = localManifest.getFileList();
        transferData = fileList.getList();
    } else if (dataFlavor.getMimeType().equals(URI_LIST_MIME_TYPE)) {
        FileList fileList = localManifest.getFileList();
        StringBuilder buf = new StringBuilder();
        for (File file : fileList) {
            buf.append(file.toURI().toString()).append("\r\n");
        }
        transferData = buf.toString();
    }
    return transferData;
}
Also used : FileList(org.apache.pivot.io.FileList) Picture(org.apache.pivot.wtk.media.Picture) 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