java.awt.dnd.DropTargetDropEvent Java Examples

The following examples show how to use java.awt.dnd.DropTargetDropEvent. 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: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public void drop(DropTargetDropEvent event) {
    int dropAction = event.getDropAction();
    JComponent c = (JComponent) event.getDropTargetContext().getComponent();
    DataObjectTransferHandler transferHandler = (DataObjectTransferHandler) c.getTransferHandler();

    if (canImport && (transferHandler != null) && actionSupported(dropAction)) {
        event.acceptDrop(dropAction);
        try {
            Transferable transferable = event.getTransferable();
            transferHandler.setDropPoint(event.getLocation());
            transferHandler.setDropComponent(c);
            event.dropComplete(transferHandler.importData(c, transferable));
        } catch (RuntimeException e) {
            event.dropComplete(false);
        }
    } else {
        event.rejectDrop();
    }
}
 
Example #2
Source File: RecentFilesController.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
private ArrayList<DefaultMutableTreeNode> onCreatePasteTreeNodesFromExternalTransfer(DropTargetDropEvent dtde, TreePath targetPath)
{
   List<File> files = DropedFileExtractor.getFiles(dtde, _app);

   ArrayList<DefaultMutableTreeNode> ret = new ArrayList<DefaultMutableTreeNode>();

   DefaultMutableTreeNode parent = findParent(targetPath);
   for (File file : files)
   {
      if (false == parentContainsFile(parent, file))
      {
         ret.add(new DefaultMutableTreeNode(file));
      }
   }

   return ret;

}
 
Example #3
Source File: LocalVersionInfoHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(PluginTool tool, Object obj, DropTargetDropEvent e, DataFlavor f) {
	VersionInfo info = (VersionInfo) obj;

	DomainFile file = tool.getProject().getProjectData().getFile(info.getDomainFilePath());
	GetVersionedObjectTask task =
		new GetVersionedObjectTask(this, file, info.getVersionNumber());
	tool.execute(task, 250);
	DomainObject versionedObj = task.getVersionedObject();

	if (versionedObj != null) {
		DomainFile vfile = versionedObj.getDomainFile();
		tool.acceptDomainFiles(new DomainFile[] { vfile });
		versionedObj.release(this);
	}
}
 
Example #4
Source File: DnDSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void drop(DropTargetDropEvent dtde) {
    boolean res = false;
    try {
        if( isButtonDrag ) {
            if( validateDropPosition() ) {
                res = handleDrop( dtde.getTransferable() );
            }
        } else if( isToolbarDrag ) {
            res = true;
            //taken care of in dragDropEnd()
        }
    } finally {
        dtde.dropComplete(res);
    }
    resetDropGesture();
}
 
Example #5
Source File: ExportPanel.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
	for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
		if (dataFlover.isFlavorJavaFileListType()) {
			try {
				dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

				for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)) {
					if (file.isFile() && file.canRead()) {
						browseText.setText(file.getCanonicalPath());
						break;
					}
				}

				dtde.getDropTargetContext().dropComplete(true);	
			} catch (UnsupportedFlavorException | IOException e) {
				//
			}
		}
	}
}
 
Example #6
Source File: TableDropAdapter.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void drop(DropTargetDropEvent e) {
  DropTargetContext targetContext = e.getDropTargetContext();

  if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0)
    e.acceptDrop(DnDConstants.ACTION_COPY);
  else {
    e.rejectDrop();
    return;
  }

  // We know drag is coming from tree so just get selection:
  String typeName = annotationFeaturesViewer.getSelection();
  edit.addRow(typeName);
  targetContext.dropComplete(true);
}
 
Example #7
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 #8
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 #9
Source File: DBTableInternalFrame.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public void drop(DropTargetDropEvent dtde) {
    gestureStarted = false;
    if ((dtde.getDropAction() & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) {
        dtde.acceptDrop(DnDConstants.ACTION_MOVE);
        Transferable t = dtde.getTransferable();

        try {
            DBTableInternalFrame iFrame = (DBTableInternalFrame) t
                    .getTransferData(InternalFrameTransferable.DATA_FLAVOR);
            if (iFrame != DBTableInternalFrame.this) {
                JoinLine joinLine = new JoinLine(iFrame, iFrame
                        .getSelectedRow(), DBTableInternalFrame.this,
                        columnsListBox.getSelectedIndex());
                desktop.addJoinLine(joinLine);
                desktop.repaint();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        dtde.dropComplete(true);
    }
}
 
Example #10
Source File: FileEditorDropTargetListener.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
/**
 * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
 */
public void drop(DropTargetDropEvent dtde) {
    try {
       File fileToOpen = DropedFileExtractor.getFile(dtde, _session.getApplication());

       if (fileToOpen != null) {
            if (s_log.isInfoEnabled()) {
                s_log.info("drop: path="+fileToOpen.getAbsolutePath());
            }            
            ISQLPanelAPI api = 
                _session.getSQLPanelAPIOfActiveSessionWindow(); 
            api.fileOpen(fileToOpen);
        }            
    } catch (Exception e) {
        s_log.error("drop: Unexpected exception "+e.getMessage(),e);
    }

}
 
Example #11
Source File: JTableRenderer.java    From blog-codes with Apache License 2.0 6 votes vote down vote up
public void drop(DropTargetDropEvent e)
{
	if (dragSource != null)
	{
		e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
		Point p = e.getLocation();
		int targetRow = rowAtPoint(p);

		Object edge = graph.insertEdge(null, null, null,
				dragSource.cell, JTableRenderer.this.cell, "sourceRow="
						+ sourceRow + ";targetRow=" + targetRow);
		graph.setSelectionCell(edge);

		// System.out.println("clearing drag source");
		dragSource = null;
		e.dropComplete(true);
	}
	else
	{
		e.rejectDrop();
	}
}
 
Example #12
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 #13
Source File: MissingDragExitEventTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drop(final DropTargetDropEvent dtde) {
    if (!inside) {
        FAILED = true;
        Thread.dumpStack();
    }
    inside = false;
}
 
Example #14
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
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(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
                        TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
                        DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode)pathTarget.getLastPathComponent();
                        if (executeDrop(tree, node, newParentNode, action)) {
                                dtde.acceptDrop(action);
                                dtde.dropComplete(true);
                                return;                                 
                        }
                }
                dtde.rejectDrop();
                dtde.dropComplete(false);
        }
        catch (Exception e) {   
                System.out.println(e);
                dtde.rejectDrop();
                dtde.dropComplete(false);
        }
}
 
Example #15
Source File: ImageTransferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #16
Source File: MissingDragExitEventTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drop(final DropTargetDropEvent dtde) {
    if (!inside) {
        FAILED = true;
        Thread.dumpStack();
    }
    inside = false;
}
 
Example #17
Source File: MissingDragExitEventTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drop(final DropTargetDropEvent dtde) {
    if (!inside) {
        FAILED = true;
        Thread.dumpStack();
    }
    inside = false;
}
 
Example #18
Source File: Trace.java    From Method_Trace_Tool with Apache License 2.0 5 votes vote down vote up
public static void drag()//定义的拖拽方法
{
    //panel表示要接受拖拽的控件
    new DropTarget(JlPath, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde)//重写适配器的drop方法
        {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))//如果拖入的文件格式受支持
                {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);//接收拖拽来的数据
                    List<File> list = (List<File>) (dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
                    String temp = "";
                    for (File file : list) {
                        temp = file.getAbsolutePath();
                        JlPath.setText(temp);
                        break;
                    }
                    //JOptionPane.showMessageDialog(null, temp);
                    dtde.dropComplete(true);//指示拖拽操作已完成
                } else {
                    dtde.rejectDrop();//否则拒绝拖拽来的数据
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #19
Source File: ImageTransferTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
ImageDropTarget() throws AWTException {
    DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetDropEvent dtde) {
            checkImage(dtde);
            startImageDrag();
        }
    };
    new DropTarget(frame, dropTargetAdapter);
    robot = new Robot();
}
 
Example #20
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 #21
Source File: FileDropTargetListener.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void doDropAction(final DropTargetDropEvent event) {

        event.acceptDrop(DnDConstants.ACTION_COPY);

        final Optional<File> file = getDroppedFile(event.getTransferable());
        if (file.isPresent()) {
            doFileAction(file.get());
        } else {
            MagicSound.ALERT.play();
        }

        // Inform that the drop is complete
        event.dropComplete(true);
    }
 
Example #22
Source File: MenuEditLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    //if(shouldRedispatchDnDToHandle()) {
    if(dragProxying) {
        formDesigner.getHandleLayer().getNewComponentDropListener().drop(dtde);
        dragProxying = false;
        return;
    }
    if(dragop.isStarted()) {
        dragop.end(dtde);
        dragProxying = false;
        return;
    }
}
 
Example #23
Source File: WidgetAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a drop target drop event.
 * @param id the event id
 * @param event the Swing event
 */
public WidgetDropTargetDropEvent (long id, DropTargetDropEvent event) {
    this.id = id;
    this.event = event;
    Point location = event.getLocation ();
    x = location.x;
    y = location.y;
}
 
Example #24
Source File: DndTabbedPaneDropTargetListener.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent e)
{
   if (isDropAcceptable(e))
   {
      if (null != _outwardDndTabbedPaneChanel && null != _outwardDndTabbedPaneChanel.getDndTabbedPaneData() && _outwardDndTabbedPaneChanel.getDndTabbedPaneData() != _dnDTabbedPaneData)
      {
         int targetTabIndex = DndTabUtils.getTargetTabIndex(e.getLocation(), _glassPane, _dnDTabbedPaneData.getTabbedPane());
         if(-1 == targetTabIndex)
         {
            targetTabIndex = _dnDTabbedPaneData.getTabbedPane().getTabCount();
         }

         _outwardDndTabbedPaneChanel.moveDraggedTabTo(_dnDTabbedPaneData.getTabbedPane(), targetTabIndex);
      }
      else
      {
         convertTab(_dnDTabbedPaneData.getDragTabIndex(), DndTabUtils.getTargetTabIndex(e.getLocation(), _glassPane, _dnDTabbedPaneData.getTabbedPane()));
      }
      e.dropComplete(true);
   }
   else
   {
      e.dropComplete(false);
   }
   _dnDTabbedPaneData.getTabbedPane().repaint();
}
 
Example #25
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 #26
Source File: LocallDownloadDnD.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    if (accept == null) {
        dtde.dropComplete(false);
        return;
    }
    try {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        List<File> files = null;
        if (value instanceof String) {
            files = new ArrayList<File>();
            for (String v : ((String) value).split("\n")) {
                File f = Utilities.toFile(new URI(((String) v).trim()));
                assert f.exists() : "File shall exist: " + f;
                files.add(f);
            }
        }
        if (value instanceof List) {
            files = NbCollections.checkedListByCopy((List) value, File.class, true);
        }
        if (files != null) {
            UnitTab lt = outer.findTabForModel(model);
            assert lt != null;
            final Map<String, Boolean> state = UnitCategoryTableModel.captureState(model.getUnits());
            localDownloadSupport.addUpdateUnits(files.toArray(new File[0]));
            lt.updateTab(state);
            outer.setSelectedTab(lt);
        }
        dtde.dropComplete(true);
    } catch (Exception ex) {
        dtde.dropComplete(false);
        Exceptions.printStackTrace(ex);
    }
}
 
Example #27
Source File: GenericDialogPlus.java    From ij-ridgedetection with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent event) {
	try {
		text.setText(getString(event));
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #28
Source File: HtmlExternalDropHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canDrop(DropTargetDropEvent e) {
    //check if the JEditorPane contains html document
    JEditorPane pane = findPane(e.getDropTargetContext().getComponent());
    if (pane == null) {
        return false;
    }
    int offset = getLineEndOffset(pane, e.getLocation());
    if (!containsLanguageAtOffset(pane.getDocument(), offset)) {
        return false;
    }

    //check if the dropped target is supported
    return canDrop(e.getCurrentDataFlavors());
}
 
Example #29
Source File: ImageTransferTest.java    From openjdk-jdk8u-backup 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 #30
Source File: Dock.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void drop(DropTargetDropEvent dtde) {
    if (mDragDockable != null) {
        if (mDragOverNode != null) {
            dock(mDragDockable, mDragOverNode, mDragOverLocation);
            revalidate();
        }
        dtde.acceptDrop(DnDConstants.ACTION_MOVE);
        dtde.dropComplete(true);
    } else {
        dtde.dropComplete(false);
    }
    clearDragState();
}