Java Code Examples for java.awt.dnd.DropTargetDropEvent#rejectDrop()

The following examples show how to use java.awt.dnd.DropTargetDropEvent#rejectDrop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractReportElementDragHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected Band getInsertionBand( final DropTargetDropEvent event,
                                 final ReportElementEditorContext dragContext,
                                 final Point2D point ) {
  final Element elementForLocation = dragContext.getElementForLocation( point, false );
  Band band;
  if ( elementForLocation instanceof Band ) {
    band = (Band) elementForLocation;
  } else if ( elementForLocation != null ) {
    band = elementForLocation.getParent();
  } else {
    band = null;
  }

  if ( band == null ) {
    final Element defaultEntry = dragContext.getDefaultElement();
    if ( defaultEntry instanceof Band == false ) {
      event.rejectDrop();
      dragContext.getRepresentationContainer().removeAll();
      return null;
    }
    band = (Band) defaultEntry;
  }
  return band;
}
 
Example 2
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void drop(DropTargetDropEvent e) {
  try {
    if (e.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      e.acceptDrop(DnDConstants.ACTION_COPY);
      Transferable transferable = e.getTransferable();
      ((List<?>) transferable.getTransferData(DataFlavor.javaFileListFlavor))
          .stream().filter(File.class::isInstance).map(File.class::cast)
          .map(File::toPath)
          .forEach(MainPanel.this::addImage);
      e.dropComplete(true);
    } else {
      e.rejectDrop();
    }
  } catch (UnsupportedFlavorException | IOException ex) {
    e.rejectDrop();
  }
}
 
Example 3
Source File: DnDTree.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void drop(@Nonnull final DropTargetDropEvent dtde) {
  if (this.dragAcceptableType) {

    final Point dragPoint = dtde.getLocation();

    final TreePath path = getPathForLocation(dragPoint.x, dragPoint.y);

    if (path != null) {
      final Object dropTargetNode = path.getLastPathComponent();
      if (dropTargetNode instanceof NodeFileOrFolder) {
        final NodeFileOrFolder node = (NodeFileOrFolder) dropTargetNode;
        if (!node.isLeaf()) {
          //TODO processing of file drag in tree
          System.out.println("Not implemented yet!"); //NOI18N
        } else {
          dtde.rejectDrop();
        }
      }
    }

    repaint();
  }
}
 
Example 4
Source File: MainDropTarget.java    From jadx with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void drop(DropTargetDropEvent dtde) {
	if (!dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
		dtde.rejectDrop();
		return;
	}
	dtde.acceptDrop(dtde.getDropAction());
	try {
		Transferable transferable = dtde.getTransferable();
		List<File> transferData = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
		if (!transferData.isEmpty()) {
			dtde.dropComplete(true);
			// load first file
			mainWindow.open(transferData.get(0).toPath());
		}
	} catch (Exception e) {
		LOG.error("File drop operation failed", e);
	}
}
 
Example 5
Source File: AbstractDSWorkbenchFrame.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        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) {
    }
}
 
Example 6
Source File: FileDragLabel.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
       try {
           final Transferable transferable = dropTargetDropEvent.getTransferable();
           if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
               dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY);
               dropTargetDropEvent.getDropTargetContext().dropComplete(true);
           }
           else {
               dropTargetDropEvent.rejectDrop();
           }
       }
       catch (Exception ex) {
           Log.error(ex);
           dropTargetDropEvent.rejectDrop();
       }
   }
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void drop(DropTargetDropEvent dtde) {
  try {
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      dtde.acceptDrop(DnDConstants.ACTION_COPY);
      Transferable t = dtde.getTransferable();
      List<?> list = (List<?>) t.getTransferData(DataFlavor.javaFileListFlavor);
      for (Object o: list) {
        if (o instanceof File) {
          File f = (File) o;
          System.out.println(f.getAbsolutePath());
        }
      }
      dtde.dropComplete(true);
    } else {
      dtde.rejectDrop();
    }
  } catch (UnsupportedFlavorException | IOException ex) {
    dtde.rejectDrop();
  }
}
 
Example 8
Source File: ProductExplorerTopComponent.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    try {
        final Transferable transferable = dtde.getTransferable();
        if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
            final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
            if (fileList.size() > 0) {
                final OpenProductAction open = new OpenProductAction();
                open.setFiles(fileList.toArray(new File[fileList.size()]));
                dtde.dropComplete(Boolean.TRUE.equals(open.execute()));
            }
        } else {
            dtde.rejectDrop();
        }
    } catch (UnsupportedFlavorException | IOException e) {
        SystemUtils.LOG.log(Level.SEVERE, "Exception during drag-and-drop operation", e);
        dtde.rejectDrop();
    }
}
 
Example 9
Source File: JTreeUtil.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public final void drop(DropTargetDropEvent dtde) {
	try {
		if (drawImage) {
			clearImage();
		}
		int action = dtde.getDropAction();
		Transferable transferable = dtde.getTransferable();
		Point pt = dtde.getLocation();
		if (transferable.isDataFlavorSupported(NODE_FLAVOR)
				&& controller.canPerformAction(tree, draggedNode, action, pt)) {
			TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
			Object node = transferable.getTransferData(NODE_FLAVOR);
			Object newParentNode = pathTarget.getLastPathComponent();
			if (controller.executeDrop(tree, node, newParentNode, action)) {
				dtde.acceptDrop(action);
				dtde.dropComplete(true);
				return;
			}
		}
		dtde.rejectDrop();
		dtde.dropComplete(false);
	} catch (Exception e) {
		dtde.rejectDrop();
		dtde.dropComplete(false);
	}
}
 
Example 10
Source File: ImageTransferTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
 
Example 11
Source File: CustomizedToolbar.java    From pumpernickel with MIT License 5 votes vote down vote up
public void drop(DropTargetDropEvent dtde) {
	if (draggingComponent == null) {
		dtde.rejectDrop();
	} else {

		if (draggingDefaults) {
			setContents(getDefaultContents());
		} else {
			Point p = dtde.getLocation();
			p = SwingUtilities.convertPoint(
					((DropTarget) dtde.getSource()).getComponent(), p,
					CustomizedToolbar.this);

			String[] contents = getContents(p);
			setContents(contents);
			dtde.acceptDrop(DnDConstants.ACTION_MOVE);
			JComponent theComponent = getComponent(draggingComponent);
			Rectangle r = getLayout().getDestinationMap(
					CustomizedToolbar.this).get(theComponent);
			if (r != null) {
				theComponent.setBounds(r);
			}
			if (hideActiveComponents)
				theComponent.setVisible(true);
		}
	}
	dtde.dropComplete(true);
}
 
Example 12
Source File: ImageTransferTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
 
Example 13
Source File: DockHeader.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    if (mDragDockable != null && mDragInsertIndex != -1) {
        getDockContainer().stack(mDragDockable, mDragInsertIndex);
        dtde.acceptDrop(DnDConstants.ACTION_MOVE);
        dtde.dropComplete(true);
    } else {
        dtde.rejectDrop();
        dtde.dropComplete(false);
    }
    clearDragState();
}
 
Example 14
Source File: TreePanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent event) {
    if (mDragState != null) {
        event.acceptDrop(event.getDropAction());
        mDropReceived = true;
        event.dropComplete(mDragState.drop(event));
    } else if (mAlternateDragDestination != null) {
        UIUtilities.convertPoint(event.getLocation(), this, mAlternateDragDestination);
        mAlternateDragDestination.drop(event);
    } else {
        mDropReceived = false;
        event.rejectDrop();
    }
    clearDragState();
}
 
Example 15
Source File: DropListener.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent e) {
    Transferable transferable = e.getTransferable();
    DataFlavor[] flavors = transferable.getTransferDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (flavor.equals(DataFlavor.imageFlavor)) {
            // it is unclear how this could be used
            e.rejectDrop();
            return;
        }
        if (flavor.isFlavorJavaFileListType()) {
            // this is where we get after dropping a file or directory
            e.acceptDrop(DnDConstants.ACTION_COPY);

            try {
                @SuppressWarnings("unchecked")
                List<File> list = (List<File>) transferable.getTransferData(flavor);
                destination.handleDrop(list);
            } catch (UnsupportedFlavorException | IOException ex) {
                Messages.showException(ex);
                e.rejectDrop();
            }
            e.dropComplete(true);
            return;
        }
    }

    // DataFlavor not recognized
    e.rejectDrop();
}
 
Example 16
Source File: PaletteDropTarget.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    if (dtde.getTransferable().isDataFlavorSupported(WidgetData.EFFECTFLAVOR)){
       GEffectDropEvent(dtde);
    }else if(dtde.isDataFlavorSupported(WidgetData.FLAVOR)){
        GElementDropEvent(dtde);
    }else{
       dtde.rejectDrop(); 
    }
}
 
Example 17
Source File: ImageTransferTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
 
Example 18
Source File: ImageTransferTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
 
Example 19
Source File: ReportDesignerFrame.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void drop( final DropTargetDropEvent dtde ) {
  final DropTarget dropTarget = (DropTarget) dtde.getSource();
  dropTarget.getComponent().setCursor( Cursor.getDefaultCursor() );
  dtde.rejectDrop();
}
 
Example 20
Source File: GenericDNDHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Called when the drag operation has terminated with a drop on the operable part of the drop site for the
 * <code>DropTarget</code> registered with this listener.
 * <p/>
 * This method is responsible for undertaking the transfer of the data associated with the gesture. The
 * <code>DropTargetDropEvent</code> provides a means to obtain a <code>Transferable</code> object that represents the
 * data object(s) to be transfered.<P> From this method, the <code>DropTargetListener</code> shall accept or reject
 * the drop via the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent</code>
 * parameter.
 * <p/>
 * Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s getTransferable() method may be
 * invoked, and data transfer may be performed via the returned <code>Transferable</code>'s getTransferData() method.
 * <p/>
 * At the completion of a drop, an implementation of this method is required to signal the success/failure of the drop
 * by passing an appropriate <code>boolean</code> to the <code>DropTargetDropEvent</code>'s dropComplete(boolean
 * success) method.
 * <p/>
 * Note: The data transfer should be completed before the call  to the <code>DropTargetDropEvent</code>'s
 * dropComplete(boolean success) method. After that, a call to the getTransferData() method of the
 * <code>Transferable</code> returned by <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to succeed
 * only if the data transfer is local; that is, only if <code>DropTargetDropEvent.isLocalTransfer()</code> returns
 * <code>true</code>. Otherwise, the behavior of the call is implementation-dependent.
 * <p/>
 *
 * @param dtde the <code>DropTargetDropEvent</code>
 */

public void drop( final DropTargetDropEvent dtde ) {
  dtde.rejectDrop();
  transferData = null;
  position = null;
  flavor = null;
}