java类java.awt.dnd.DropTargetDragEvent的实例源码

CssExternalDropHandler.java 文件源码 项目:incubator-netbeans 阅读 19 收藏 0 点赞 0 评论 0
@Override
public boolean canDrop(DropTargetDragEvent 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;
    } else {
        //update the caret as the user drags the object
        //needs to be done explicitly here as QuietEditorPane doesn't call
        //the original Swings DropTarget which does this
        pane.setCaretPosition(offset);

        pane.requestFocusInWindow(); //pity we need to call this all the time when dragging, but  ExternalDropHandler don't handle dragEnter event

        return canDrop(e.getCurrentDataFlavors());
    }

}
LocallDownloadDnD.java 文件源码 项目:incubator-netbeans 阅读 27 收藏 0 点赞 0 评论 0
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    accept = null;
    value = null;
    for (DataFlavor dataFlavor : dtde.getCurrentDataFlavors()) {
        Object obj = null;
        try {
            obj = dtde.getTransferable().getTransferData(dataFlavor);
        } catch (Exception ex) {
            continue;
        }
        if (dataFlavor.isFlavorJavaFileListType()) {
            accept = dataFlavor;
            value = obj;
            break;
        }
        if ("text".equals(dataFlavor.getPrimaryType()) && "uri-list".equals(dataFlavor.getSubType()) && dataFlavor.getRepresentationClass() == String.class) {
            accept = dataFlavor;
            value = (String) obj;
            break;
        }
    }
    if (accept != null) {
        dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    }
}
HtmlExternalDropHandler.java 文件源码 项目:incubator-netbeans 阅读 20 收藏 0 点赞 0 评论 0
@Override
public boolean canDrop(DropTargetDragEvent 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;
    } else {
        //update the caret as the user drags the object
        //needs to be done explicitly here as QuietEditorPane doesn't call
        //the original Swings DropTarget which does this
        pane.setCaretPosition(offset);

        pane.requestFocusInWindow(); //pity we need to call this all the time when dragging, but  ExternalDropHandler don't handle dragEnter event

        return canDrop(e.getCurrentDataFlavors());
    }

}
TrashDropTargetListener.java 文件源码 项目:pdfjumbler 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    if (
        ((dtde.getDropAction() & DnDConstants.ACTION_MOVE) != 0) &&
        (dtde.getTransferable().isDataFlavorSupported(JDDLTransferData.DATA_FLAVOR))
    ) {
        dtde.acceptDrag(DnDConstants.ACTION_MOVE);
    } else {
        dtde.rejectDrag();
    }
}
WidgetAction.java 文件源码 项目:incubator-netbeans 阅读 62 收藏 0 点赞 0 评论 0
/**
 * Creates a drop target drag event.
 * @param id the event id
 * @param event the Swing event
 */
public WidgetDropTargetDragEvent (long id, DropTargetDragEvent event) {
    this.id = id;
    this.event = event;
    Point location = event.getLocation ();
    x = location.x;
    y = location.y;
}
MenuEditLayer.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
private boolean shouldRedispatchDnDToHandle(DropTargetDragEvent dtde) {
    RADComponent rad = formDesigner.getHandleLayer().getMetaComponentAt(dtde.getLocation(), HandleLayer.COMP_DEEPEST);
    if(rad != null && isMenuRelatedComponentClass(rad.getBeanClass())) {
        return false;
    }
    if(!USE_JSEPARATOR_FIX) return false;
    PaletteItem item = PaletteUtils.getSelectedItem();
    if(item != null && JSeparator.class.isAssignableFrom(item.getComponentClass())) {
        return true;
    }
    return false;
}
MenuEditLayer.java 文件源码 项目:incubator-netbeans 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    if(shouldRedispatchDnDToHandle(dtde)) {
        dragProxying = true;
        formDesigner.getHandleLayer().getNewComponentDropListener().dragEnter(dtde);
        return;
    }
    if(!dragop.isStarted()) {
        start(dtde);
    }
}
MenuEditLayer.java 文件源码 项目:incubator-netbeans 阅读 33 收藏 0 点赞 0 评论 0
@Override
public void dragOver(DropTargetDragEvent dtde) {
    // look at the rad component under the cursor first
    if(dragProxying && shouldRedispatchDnDToHandle(dtde)) {
        formDesigner.getHandleLayer().getNewComponentDropListener().dragOver(dtde);
        return;
    }
    dragProxying = false;
    if(dragop.isStarted()) {
        dragop.move(dtde.getLocation());
    } else {
        start(dtde);
    }
}
QuietEditorPane.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void dragEnter(DropTargetDragEvent dtde) {
    Collection<? extends ExternalDropHandler> handlers = Lookup.getDefault().lookupAll(ExternalDropHandler.class);
    for (ExternalDropHandler handler : handlers) {
        if (handler.canDrop(dtde)) {
            dtde.acceptDrag(DnDConstants.ACTION_COPY);
            isDragging = false;
            return;
        }
    }

    orig.dragEnter(dtde);
    isDragging = true;
}
mxGraphHandler.java 文件源码 项目:Tarski 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 
 */
protected MouseEvent createEvent(DropTargetEvent e) {
  JComponent component = getDropTarget(e);
  Point location = null;
  int action = 0;

  if (e instanceof DropTargetDropEvent) {
    location = ((DropTargetDropEvent) e).getLocation();
    action = ((DropTargetDropEvent) e).getDropAction();
  } else if (e instanceof DropTargetDragEvent) {
    location = ((DropTargetDragEvent) e).getLocation();
    action = ((DropTargetDragEvent) e).getDropAction();
  }

  if (location != null) {
    location = convertPoint(location);
    Rectangle r = graphComponent.getViewport().getViewRect();
    location.translate(r.x, r.y);
  }

  // LATER: Fetch state of modifier keys from event or via global
  // key listener using Toolkit.getDefaultToolkit().addAWTEventListener(
  // new AWTEventListener() {...}, AWTEvent.KEY_EVENT_MASK). Problem
  // is the event does not contain the modifier keys and the global
  // handler is not called during drag and drop.
  int mod = (action == TransferHandler.COPY) ? InputEvent.CTRL_MASK : 0;

  return new MouseEvent(component, 0, System.currentTimeMillis(), mod, location.x, location.y, 1,
      false, MouseEvent.BUTTON1);
}
DnDSupport.java 文件源码 项目:incubator-netbeans 阅读 25 收藏 0 点赞 0 评论 0
private void setupDropLine( DropTargetDragEvent dtde, CategoryList list, int dropIndex ) {
    boolean verticalDropBar = list.getColumnCount() > 1;
    Rectangle rect = list.getCellBounds( dropIndex, dropIndex );
    if( verticalDropBar )
        dropBefore = dtde.getLocation().x < (rect.x + rect.width/2);
    else
        dropBefore = dtde.getLocation().y < (rect.y + rect.height/2);
    Point p1 = rect.getLocation();
    Point p2 = rect.getLocation();
    if( verticalDropBar ) {
        p2.y += rect.height;
        if( !dropBefore ) {
            p1.x += rect.width;
            p2.x += rect.width;
        }
    } else {
        p2.x += rect.width;
        if( !dropBefore ) {
            p1.y += rect.height;
            p2.y += rect.height;
        }
    }
    p1 = SwingUtilities.convertPoint( list, p1, palette.getRootPane() );
    p2 = SwingUtilities.convertPoint( list, p2, palette.getRootPane() );
    Line2D line = new Line2D.Double( p1.x, p1.y, p2.x, p2.y );
    dropPane.setDropLine( line );
    targetItem = (Item)list.getModel().getElementAt( dropIndex );
}
DnDSupport.java 文件源码 项目:incubator-netbeans 阅读 20 收藏 0 点赞 0 评论 0
public void dragEnter(DropTargetDragEvent e) {
    if( e.isDataFlavorSupported( buttonDataFlavor ) || e.isDataFlavorSupported( actionDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
        isButtonDrag = true; //in case use is dragging something from the customizer window
    } else if( e.isDataFlavorSupported( toolbarDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        e.rejectDrag();
    }
}
DnDSupport.java 文件源码 项目:incubator-netbeans 阅读 23 收藏 0 点赞 0 评论 0
public void dragOver(DropTargetDragEvent e) {
    if( e.isDataFlavorSupported( buttonDataFlavor ) || e.isDataFlavorSupported( actionDataFlavor ) ) {
        updateDropGesture( e );
        if( !validateDropPosition() ) {
            e.rejectDrag();
        } else {
            e.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE );
        }
    } else if( e.isDataFlavorSupported( toolbarDataFlavor ) ) {
        e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    } else {
        e.rejectDrag();
    }
}
IndexedCustomizer.java 文件源码 项目:incubator-netbeans 阅读 28 收藏 0 点赞 0 评论 0
/** User is starting to drag over us */
public void dragEnter(DropTargetDragEvent dtde) {
    if (!checkConditions(dtde)) {
        dtde.rejectDrag();
    } else {
        lastIndex = comp.locationToIndex(dtde.getLocation());
        cellRenderer.draggingEnter(lastIndex, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation());
        comp.repaint(comp.getCellBounds(lastIndex, lastIndex));
    }
}
IndexedCustomizer.java 文件源码 项目:incubator-netbeans 阅读 18 收藏 0 点赞 0 评论 0
/** User drag over us */
public void dragOver(DropTargetDragEvent dtde) {
    if (!checkConditions(dtde)) {
        dtde.rejectDrag();

        if (lastIndex >= 0) {
            cellRenderer.draggingExit();
            comp.repaint(comp.getCellBounds(lastIndex, lastIndex));
            lastIndex = -1;
        }
    } else {
        dtde.acceptDrag(DnDConstants.ACTION_MOVE);

        int index = comp.locationToIndex(dtde.getLocation());

        if (lastIndex == index) {
            cellRenderer.draggingOver(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation());
        } else {
            if (lastIndex < 0) {
                lastIndex = index;
            }

            cellRenderer.draggingExit();
            cellRenderer.draggingEnter(index, ids.getDragGestureEvent().getDragOrigin(), dtde.getLocation());
            comp.repaint(comp.getCellBounds(lastIndex, index));
            lastIndex = index;
        }
    }
}
DBTableDrop.java 文件源码 项目:incubator-netbeans 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Returns <code>JTable</code> palette item.
 *
 * @param dtde corresponding drop target drag event.
 * @return <code>JTable</code> palette item.
 */
@Override
public PaletteItem getPaletteItem(DropTargetDragEvent dtde) {
    if (!assistantInitialized) {
        initAssistant();
    }
    PaletteItem pItem;
    if (!J2EEUtils.hasPrimaryKey(table.getDatabaseConnection(), table.getTableName())) {
        FormEditor.getAssistantModel(model).setContext("tableWithoutPK"); // NOI18N
        return null;
    }
    if (FormJavaSource.isInDefaultPackage(model)) {
        // 97982: default package
        FormEditor.getAssistantModel(model).setContext("tableDefaultPackage"); // NOI18N
        return null;
    }
    setBindingOnly(dtde.getDropAction() == DnDConstants.ACTION_MOVE);
    if (isBindingOnly()) {
        FormEditor.getAssistantModel(model).setContext("tableDropBinding", "tableDropComponent"); // NOI18N
        pItem = new PaletteItem(new ClassSource("javax.persistence.EntityManager", // NOI18N
                    new ClassSourceResolver.LibraryEntry(LibraryManager.getDefault().getLibrary("eclipselink"))), // NOI18N
                    null);
        pItem.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/j2ee/resources/binding.gif", false).getImage()); // NOI18N
    } else {
        pItem = new PaletteItem(new ClassSource("javax.swing.JTable"), null); // NOI18N
    }
    return pItem;
}
DBConnectionDrop.java 文件源码 项目:incubator-netbeans 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Returns <code>EntityManager</code> palette item.
 *
 * @param dtde corresponding drop target drag event.
 * @return <code>EntityManager</code> palette item.
 */
@Override
public PaletteItem getPaletteItem(DropTargetDragEvent dtde) {
    PaletteItem pItem = new PaletteItem(new ClassSource("javax.persistence.EntityManager", // NOI18N
            new ClassSourceResolver.LibraryEntry(LibraryManager.getDefault().getLibrary("eclipselink"))), // NOI18N
            null);
    pItem.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/j2ee/resources/EntityManager.png", false).getImage()); // NOI18N
    return pItem;
}
DBColumnDrop.java 文件源码 项目:incubator-netbeans 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Returns <code>JTextField</code> palette item.
 *
 * @param dtde corresponding drop target drag event.
 * @return <code>JTextField</code> palette item.
 */
@Override
public PaletteItem getPaletteItem(DropTargetDragEvent dtde) {
    PaletteItem pItem;
    if (!assistantInitialized) {
        initAssistant();
    }
    if (!J2EEUtils.hasPrimaryKey(column.getDatabaseConnection(), column.getTableName())) {
        FormEditor.getAssistantModel(model).setContext("tableWithoutPK"); // NOI18N
        return null;
    }
    if (FormJavaSource.isInDefaultPackage(model)) {
        // 97982: default package
        FormEditor.getAssistantModel(model).setContext("columnDefaultPackage"); // NOI18N
        return null;
    }
    setBindingOnly(dtde.getDropAction() == DnDConstants.ACTION_MOVE);
    if (isBindingOnly()) {
        FormEditor.getAssistantModel(model).setContext("columnDropBinding", "columnDropComponent"); // NOI18N
        pItem = new PaletteItem(new ClassSource("javax.persistence.EntityManager", // NOI18N
                    new ClassSourceResolver.LibraryEntry(LibraryManager.getDefault().getLibrary("eclipselink"))), // NOI18N
                    null);
        pItem.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/form/j2ee/resources/binding.gif", false).getImage()); // NOI18N
    } else {
        pItem = new PaletteItem(new ClassSource("javax.swing.JTextField"), null); // NOI18N
    }
    return pItem;
}
ProcessRendererDropTarget.java 文件源码 项目:rapidminer 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void dragEnter(final DropTargetDragEvent e) {
    super.dragEnter(e);
    if (dropTragetListenerList != null) {
        Object[] listeners = dropTragetListenerList.getListenerList();
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == DropTargetListener.class) {
                ((DropTargetListener) listeners[i + 1]).dragEnter(e);
            }
        }
    }
}
ProcessRendererDropTarget.java 文件源码 项目:rapidminer 阅读 32 收藏 0 点赞 0 评论 0
@Override
public void dragOver(final DropTargetDragEvent e) {
    super.dragOver(e);
    if (dropTragetListenerList != null) {
        Object[] listeners = dropTragetListenerList.getListenerList();
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == DropTargetListener.class) {
                ((DropTargetListener) listeners[i + 1]).dragOver(e);
            }
        }
    }
}
ProcessRendererDropTarget.java 文件源码 项目:rapidminer 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void dropActionChanged(final DropTargetDragEvent e) {
    super.dropActionChanged(e);
    if (dropTragetListenerList != null) {
        Object[] listeners = dropTragetListenerList.getListenerList();
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == DropTargetListener.class) {
                ((DropTargetListener) listeners[i + 1]).dropActionChanged(e);
            }
        }
    }
}
JTreeUtil.java 文件源码 项目:Logisim 阅读 31 收藏 0 点赞 0 评论 0
@Override
public final void dragOver(DropTargetDragEvent dtde) {
    Point pt = dtde.getLocation();
    int action = dtde.getDropAction();
    autoscroll(tree, pt);
    if (drawImage) {
        paintImage(pt);
    }
    if (controller.canPerformAction(tree, draggedNode, action, pt)) {
        dtde.acceptDrag(action);
    } else {
        dtde.rejectDrag();
    }
}
PieceMover.java 文件源码 项目:VASSAL-src 阅读 17 收藏 0 点赞 0 评论 0
public void dragEnter(DropTargetDragEvent e) {
  final Component newDropWin = e.getDropTargetContext().getComponent();
  if (newDropWin != dropWin) {
    final double newZoom = newDropWin instanceof Map.View
      ? ((Map.View) newDropWin).getMap().getZoom() : 1.0;
    if (Math.abs(newZoom - dragCursorZoom) > 0.01) {
      makeDragCursor(newZoom);
    }
    setDrawWinToOwnerOf(e.getDropTargetContext().getComponent());
    dropWin = newDropWin;
  }
  super.dragEnter(e);
}
JTreeUtil.java 文件源码 项目:Logisim 阅读 22 收藏 0 点赞 0 评论 0
@Override
public final void dragEnter(DropTargetDragEvent dtde) {
    Point pt = dtde.getLocation();
    int action = dtde.getDropAction();
    if (drawImage) {
        paintImage(pt);
    }
    if (controller.canPerformAction(tree, draggedNode, action, pt)) {
        dtde.acceptDrag(action);
    } else {
        dtde.rejectDrag();
    }
}
FileListPanel.java 文件源码 项目:Equella 阅读 31 收藏 0 点赞 0 评论 0
private void registerDndHandlers()
{
    new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, new DragGestureListener()
    {
        @Override
        public void dragGestureRecognized(DragGestureEvent dge)
        {
            Transferable t = new FileInfoTransferable(getSelectedFile());
            dge.startDrag(DragSource.DefaultMoveDrop, t);
        }
    });

    DnDUtils.registerDropHandler(this, dropHandlers, new HoverHandler()
    {
        @Override
        public void hovering(DropTargetDragEvent e)
        {
            FileInfo fi = getFileUnderMouseCursor();
            if( fi == null )
            {
                int i = getListIndexUnderPoint(e.getLocation());
                if( i >= 0 )
                {
                    fi = model.get(i);
                }
            }

            if( fi != null && fi.isDirectory() )
            {
                list.setSelectedValue(fi, true);
            }
            else
            {
                list.getSelectionModel().clearSelection();
            }
        }
    });
}
DnDUtils.java 文件源码 项目:Equella 阅读 21 收藏 0 点赞 0 评论 0
public static boolean supportsNativeFileDrop(DropTargetDragEvent e)
{
    for( DataFlavor flavor : e.getCurrentDataFlavors() )
    {
        if( flavor.equals(DataFlavor.javaFileListFlavor) || flavor.isRepresentationClassReader() )
        {
            return true;
        }
    }
    return false;
}
JTreeUtil.java 文件源码 项目:Logisim 阅读 25 收藏 0 点赞 0 评论 0
@Override
public final void dropActionChanged(DropTargetDragEvent dtde) {
    Point pt = dtde.getLocation();
    int action = dtde.getDropAction();
    if (drawImage) {
        paintImage(pt);
    }
    if (controller.canPerformAction(tree, draggedNode, action, pt)) {
        dtde.acceptDrag(action);
    } else {
        dtde.rejectDrag();
    }
}
SunDropTargetContextPeer.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
/**
 * actual processing on EventQueue Thread
 */

protected void processEnterMessage(SunDropTargetEvent event) {
    Component  c    = (Component)event.getSource();
    DropTarget dt   = c.getDropTarget();
    Point      hots = event.getPoint();

    local = getJVMLocalSourceTransferable();

    if (currentDTC != null) { // some wreckage from last time
        currentDTC.removeNotify();
        currentDTC = null;
    }

    if (c.isShowing() && dt != null && dt.isActive()) {
        currentDT  = dt;
        currentDTC = currentDT.getDropTargetContext();

        currentDTC.addNotify(this);

        currentA   = dt.getDefaultActions();

        try {
            ((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
                                                                       hots,
                                                                       currentDA,
                                                                       currentSA));
        } catch (Exception e) {
            e.printStackTrace();
            currentDA = DnDConstants.ACTION_NONE;
        }
    } else {
        currentDT  = null;
        currentDTC = null;
        currentDA   = DnDConstants.ACTION_NONE;
        currentSA   = DnDConstants.ACTION_NONE;
        currentA   = DnDConstants.ACTION_NONE;
    }

}
JTableRenderer.java 文件源码 项目:Tarski 阅读 31 收藏 0 点赞 0 评论 0
public void dragOver(DropTargetDragEvent e)
{
    if (!((mxGraphTransferHandler) graphContainer.getTransferHandler())
            .isLocalDrag()
            && JTableRenderer.this != dragSource)
    {
        Point p = e.getLocation();
        int row = rowAtPoint(p);
        getSelectionModel().setSelectionInterval(row, row);
    }
}
JTableRenderer.java 文件源码 项目:Tarski 阅读 26 收藏 0 点赞 0 评论 0
public void dragOver(DropTargetDragEvent e) {
  if (!((mxGraphTransferHandler) graphContainer.getTransferHandler()).isLocalDrag()
      && JTableRenderer.this != dragSource) {
    Point p = e.getLocation();
    int row = rowAtPoint(p);
    getSelectionModel().setSelectionInterval(row, row);
  }
}


问题


面经


文章

微信
公众号

扫码关注公众号