Example usage for java.awt.dnd DropTargetDropEvent rejectDrop

List of usage examples for java.awt.dnd DropTargetDropEvent rejectDrop

Introduction

In this page you can find the example usage for java.awt.dnd DropTargetDropEvent rejectDrop.

Prototype


public void rejectDrop() 

Source Link

Document

reject the Drop.

Usage

From source file:de.tor.tribes.ui.windows.AbstractDSWorkbenchFrame.java

@Override
public void drop(DropTargetDropEvent dtde) {
    if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor)
            || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {/*w w  w . ja  v a  2s  . c o m*/
        dtde.rejectDrop();
        return;
    }

    Transferable t = dtde.getTransferable();
    List<Village> v;
    MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor());
    try {
        v = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor);
        fireVillagesDraggedEvent(v, dtde.getLocation());
    } catch (Exception ignored) {
    }
}

From source file:Main.java

public void drop(DropTargetDropEvent e) {
    System.out.println("Dropping");

    try {/*from www  . j av  a  2 s . com*/
        Transferable t = e.getTransferable();

        if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            e.acceptDrop(e.getDropAction());

            String s;
            s = (String) t.getTransferData(DataFlavor.stringFlavor);

            target.setText(s);

            e.dropComplete(true);
        } else
            e.rejectDrop();
    } catch (java.io.IOException e2) {
    } catch (UnsupportedFlavorException e2) {
    }
}

From source file:TreeDragTest.java

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);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();
    if (parent.isLeaf()) {
        dtde.rejectDrop();
        return;/*  www. ja  va  2s. c  om*/
    }

    try {
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            if (tr.isDataFlavorSupported(flavors[i])) {
                dtde.acceptDrop(dtde.getDropAction());
                TreePath p = (TreePath) tr.getTransferData(flavors[i]);
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent();
                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
                model.insertNodeInto(node, parent, 0);
                dtde.dropComplete(true);
                return;
            }
        }
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}

From source file:DNDList.java

/**
 * a drop has occurred//  ww  w  .  j a  v  a 2  s  . c o  m
 * 
 */

public void drop(DropTargetDropEvent event) {

    try {
        Transferable transferable = event.getTransferable();

        // we accept only Strings
        if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {

            event.acceptDrop(DnDConstants.ACTION_MOVE);
            String s = (String) transferable.getTransferData(DataFlavor.stringFlavor);
            addElement(s);
            event.getDropTargetContext().dropComplete(true);
        } else {
            event.rejectDrop();
        }
    } catch (Exception exception) {
        System.err.println("Exception" + exception.getMessage());
        event.rejectDrop();
    }
}

From source file:net.sf.nmedit.nordmodular.NMSynthDeviceContext.java

protected void dropTransfer(SlotObject<NordModular> s, DropTargetDropEvent dtde) {
    if (!acceptsDropData(s, dtde.getCurrentDataFlavors())) {
        dtde.rejectDrop();
        return;/*from www  .j av  a  2  s .  c o m*/
    }

    if (!dtde.isLocalTransfer()) {
        dtde.rejectDrop();
        return;
    }

    try {
        NMPatch patch = (NMPatch) dtde.getTransferable().getTransferData(JTNMPatch.nmPatchFlavor);

        if (patch.getSlot() != null)
            patch.setSlot(null);

        (new StorePatchInSlotWorker((NmSlot) s.getSlot(), patch)).store();
    } catch (IOException e) {
        dtde.rejectDrop();
    } catch (UnsupportedFlavorException e) {
        dtde.rejectDrop();
    }
}

From source file:DropTest.java

public void drop(DropTargetDropEvent dtde) {
    try {/*from   ww  w .  j a v  a 2s.  com*/
        Transferable tr = dtde.getTransferable();
        DataFlavor[] flavors = tr.getTransferDataFlavors();
        for (int i = 0; i < flavors.length; i++) {
            System.out.println("Possible flavor: " + flavors[i].getMimeType());
            if (flavors[i].isFlavorJavaFileListType()) {
                dtde.acceptDrop(DnDConstants.ACTION_COPY);
                ta.setText("Successful file list drop.\n\n");

                java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
                for (int j = 0; j < list.size(); j++) {
                    ta.append(list.get(j) + "\n");
                }
                dtde.dropComplete(true);
                return;
            }
        }
        System.out.println("Drop failed: " + dtde);
        dtde.rejectDrop();
    } catch (Exception e) {
        e.printStackTrace();
        dtde.rejectDrop();
    }
}

From source file:com.mirth.connect.client.ui.editors.JavaScriptEditorDialog.java

public void drop(DropTargetDropEvent dtde) {
    try {/*ww w .  ja v a  2 s .  c  om*/
        Transferable tr = dtde.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            java.util.List fileList = (java.util.List) tr.getTransferData(DataFlavor.javaFileListFlavor);
            Iterator iterator = fileList.iterator();
            while (iterator.hasNext()) {
                File file = (File) iterator.next();

                scriptContent.setText(
                        scriptContent.getText() + FileUtils.readFileToString(file, UIConstants.CHARSET));
            }
        }
    } catch (Exception e) {
        dtde.rejectDrop();
    }
}

From source file:EditorDropTarget.java

public void drop(DropTargetDropEvent dtde) {
    DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Check the drop action
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
        // Accept the drop and get the transfer data
        dtde.acceptDrop(dtde.getDropAction());
        Transferable transferable = dtde.getTransferable();

        try {/*from  w ww  .j  a v a  2 s  . c o  m*/
            boolean result = dropFile(transferable);

            dtde.dropComplete(result);
            DnDUtils.debugPrintln("Drop completed, success: " + result);
        } catch (Exception e) {
            DnDUtils.debugPrintln("Exception while handling drop " + e);
            dtde.dropComplete(false);
        }
    } else {
        DnDUtils.debugPrintln("Drop target rejected drop");
        dtde.rejectDrop();
    }
}

From source file:PanelDropTarget.java

public void drop(DropTargetDropEvent dtde) {
    DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction()));

    // Check the drop action
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
        // Accept the drop and get the transfer data
        dtde.acceptDrop(dtde.getDropAction());
        Transferable transferable = dtde.getTransferable();

        try {//w w  w. java  2  s . com
            boolean result = dropComponent(transferable);

            dtde.dropComplete(result);
            DnDUtils.debugPrintln("Drop completed, success: " + result);
        } catch (Exception e) {
            DnDUtils.debugPrintln("Exception while handling drop " + e);
            dtde.dropComplete(false);
        }
    } else {
        DnDUtils.debugPrintln("Drop target rejected drop");
        dtde.rejectDrop();
    }
}

From source file:net.sf.nmedit.jtheme.component.JTModuleContainer.java

public void dropNewModule(DropTargetDropEvent dtde) {
    PModuleContainer mc = getModuleContainer();
    PModuleDescriptor md = PDragDrop.getModuleDescriptor(dtde.getTransferable());
    if (md == null || mc == null) {
        dtde.rejectDrop();
        return;/*from  w  w  w  .  ja  v a2 s  .  c o m*/
    }

    Point l = dtde.getLocation();

    PModule module;
    try {
        module = mc.createModule(md);
        module.setScreenLocation(l.x, l.y);
    } catch (InvalidDescriptorException e) {
        if (log.isErrorEnabled()) {
            log.error("could not create module: " + md, e);
        }
        dtde.rejectDrop();
        return;
    }
    boolean moduleAdded = mc.add(module);

    if (!moduleAdded) {

        dtde.rejectDrop();
        return;
    }

    // TODO short after dropping a new module and then moving it
    // causes a NullPointerException in the next line
    PModuleContainer parent = module.getParentComponent();
    if (parent != null) {
        JTCableManager cm = getCableManager();
        try {
            cm.setAutoRepaintDisabled();
            MoveOperation move = parent.createMoveOperation();
            move.setScreenOffset(0, 0);
            move.add(module);
            move.move();
        } finally {
            cm.clearAutoRepaintDisabled();
        }
    } else {
        // XXX concurrency problems probably ?!
        throw new RuntimeException("Drop problem on illegal modules: for example 2 midi globals");
    }

    dtde.acceptDrop(DnDConstants.ACTION_COPY);

    // compute dimensions of container
    revalidate();
    repaint();
    dtde.dropComplete(true);
}