Java Code Examples for java.awt.dnd.DropTargetDragEvent#getLocation()

The following examples show how to use java.awt.dnd.DropTargetDragEvent#getLocation() . 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: AbstractTreeTransferHandler.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Override
public final void dragEnter(final DropTargetDragEvent dtde) {
  final Point pt = dtde.getLocation();
  final int action = dtde.getDropAction();
  if (drawImage) {
    paintImage(pt);
  }

  final Transferable transferable = dtde.getTransferable();

  if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) {
    if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(),
        action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  } else {
    if (canPerformAction(tree, draggedNode, action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  }
}
 
Example 2
Source File: AbstractReportElementDragHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public int dragStarted( final DropTargetDragEvent event,
                        final ReportElementEditorContext dragContext,
                        final ElementMetaData elementMetaData,
                        final String fieldName ) {
  final Container representationContainer = dragContext.getRepresentationContainer();
  final ReportDocumentContext renderContext = dragContext.getRenderContext();
  final Point pos = event.getLocation();
  final Point2D point = dragContext.normalize( pos );
  if ( point.getX() < 0 || point.getY() < 0 ) {
    representationContainer.removeAll();
    return DnDConstants.ACTION_NONE;
  }

  if ( isFilteredDropZone( event, dragContext, elementMetaData, point ) ) {
    representationContainer.removeAll();
    return DnDConstants.ACTION_NONE;
  }
  representation.setZoom( renderContext.getZoomModel().getZoomAsPercentage() );
  representation.setVisible( true );
  representation.setText( elementMetaData.getDisplayName( Locale.getDefault() ) );
  representation.setLocation( pos.x, pos.y );
  representation.setSize( 100, 20 );
  representationContainer.removeAll();
  representationContainer.add( representation );
  return DnDConstants.ACTION_COPY;
}
 
Example 3
Source File: CalculationTree.java    From swing_library with MIT License 6 votes vote down vote up
/**
 * acceptDrag. Can only be an empty node at this stage. In the future we may
 * want to be able to drag and drop to replace nodes rather than just drag
 * onto empty nodes.
 * 
 * @param dtde
 * @return is acceptable
 */
private boolean acceptDrag(DropTargetDragEvent dtde) {
	Point location = dtde.getLocation();

	TreePath path = this.getPathForLocation(location.x, location.y);

	if (path != null) {
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
				.getLastPathComponent();

		if ((CalculationObject) node.getUserObject() instanceof EmptyNode
				&& node.isLeaf()) {
			return true;
		}
	}
	return false;
	// DataFlavor[] flavors = dtde.getCurrentDataFlavors();
}
 
Example 4
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private boolean isDropAcceptable(DropTargetDragEvent e) {
  DropTargetContext c = e.getDropTargetContext();
  Transferable t = e.getTransferable();
  DataFlavor[] f = t.getTransferDataFlavors();
  Point pt = e.getLocation();
  targetTabIndex = -1;
  Component o = c.getComponent();
  if (o instanceof JTabbedPane) {
    JTabbedPane jtp = (JTabbedPane) o;
    for (int i = 0; i < jtp.getTabCount(); i++) {
      if (jtp.getBoundsAt(i).contains(pt)) {
        targetTabIndex = i;
        break;
      }
    }
    return targetTabIndex >= 0 && targetTabIndex != jtp.getSelectedIndex() && t.isDataFlavorSupported(f[0]);
  }
  return false;
}
 
Example 5
Source File: GanttTree2.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void dragOver(DropTargetDragEvent dtde) {
  Point pt = dtde.getLocation();
  if (pt.equals(lastEventPoint)) {
    return;
  }
  lastEventPoint = pt;
  TreePath path = getTreeTable().getTree().getPathForLocation(pt.x, pt.y);
  myOverRow = getTreeTable().getRowForPath(path);
  if (path != lastPath) {
    getTreeTable().removeHighlighter(myDragHighlighter);
    lastPath = path;
    hoverTimer.restart();
    getTreeTable().addHighlighter(myDragHighlighter);
  }
}
 
Example 6
Source File: DndTabbedPaneDropTargetListener.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
@Override
public void dragOver(final DropTargetDragEvent e)
{
   Point glassPt = e.getLocation();

   if (_dnDTabbedPaneData.getTabbedPane().getTabPlacement() == JTabbedPane.TOP || _dnDTabbedPaneData.getTabbedPane().getTabPlacement() == JTabbedPane.BOTTOM)
   {
      initTargetLeftRightLine(DndTabUtils.getTargetTabIndex(glassPt, _glassPane, _dnDTabbedPaneData.getTabbedPane()));
   }
   else
   {
      initTargetTopBottomLine(DndTabUtils.getTargetTabIndex(glassPt, _glassPane, _dnDTabbedPaneData.getTabbedPane()));
   }
   if (_dnDTabbedPaneData.isHasGhost())
   {
      _glassPane.setPoint(glassPt);
   }
   if (!_glassPt.equals(glassPt)) _glassPane.repaint();
   _glassPt = glassPt;
   autoScrollTest(glassPt);
}
 
Example 7
Source File: AbstractTreeTransferHandler.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Override
public final void dropActionChanged(final DropTargetDragEvent dtde) {
  final Point pt = dtde.getLocation();
  final int action = dtde.getDropAction();
  if (drawImage) {
    paintImage(pt);
  }
  if (draggedNode == null) {
    if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(),
        action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  } else {
    if (canPerformAction(tree, draggedNode, action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  }
}
 
Example 8
Source File: AbstractTreeTransferHandler.java    From binnavi with Apache License 2.0 6 votes vote down vote up
@Override
public final void dragOver(final DropTargetDragEvent dtde) {
  final Point pt = dtde.getLocation();
  final int action = dtde.getDropAction();
  tree.autoscroll(pt);
  if (drawImage) {
    paintImage(pt);
  }

  final Transferable transferable = dtde.getTransferable();

  if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) {
    if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(),
        action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  } else {
    if (canPerformAction(tree, draggedNode, action, pt)) {
      dtde.acceptDrag(action);
    } else {
      dtde.rejectDrag();
    }
  }
}
 
Example 9
Source File: CustomizedToolbar.java    From pumpernickel with MIT License 5 votes vote down vote up
public void dragOver(DropTargetDragEvent dtde) {
	if (draggingComponent == null) {
		dtde.rejectDrag();
	} else {
		Point p = dtde.getLocation();
		p = SwingUtilities.convertPoint(
				((DropTarget) dtde.getSource()).getComponent(), p,
				CustomizedToolbar.this);
		String[] contents = getContents(p);
		updateContents(contents);
		dtde.acceptDrag(DnDConstants.ACTION_MOVE);
	}
}
 
Example 10
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public final void dropActionChanged(DropTargetDragEvent dtde) {
        Point pt = dtde.getLocation();
        int action = dtde.getDropAction();
        if (drawImage) {
                paintImage(pt);
        }
        if (canPerformAction(tree, draggedNode, action, pt)) {
                dtde.acceptDrag(action);                        
        }
        else {
                dtde.rejectDrag();
        }
}
 
Example 11
Source File: JTreeUtil.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@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();
	}
}
 
Example 12
Source File: JTreeUtil.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@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();
	}
}
 
Example 13
Source File: JTreeUtil.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@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();
	}
}
 
Example 14
Source File: DnDSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 );
}
 
Example 15
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public final void dragOver(DropTargetDragEvent dtde) {
        Point pt = dtde.getLocation();
        int action = dtde.getDropAction();
        tree.autoscroll(pt);
        if (drawImage) {
                paintImage(pt);
        }
        if (canPerformAction(tree, draggedNode, action, pt)) {
                dtde.acceptDrag(action);                        
        }
        else {
                dtde.rejectDrag();
        }
}
 
Example 16
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public final void dragEnter(DropTargetDragEvent dtde) {
        Point pt = dtde.getLocation();
        int action = dtde.getDropAction();
        if (drawImage) {
                paintImage(pt);
        }
        if (canPerformAction(tree, draggedNode, action, pt)) {
                dtde.acceptDrag(action);                        
        }
        else {
                dtde.rejectDrag();
        }
}
 
Example 17
Source File: GenericDNDHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site
 * for the <code>DropTarget</code> registered with this listener.
 *
 * @param dtde the <code>DropTargetDragEvent</code>
 */

public void dragOver( final DropTargetDragEvent dtde ) {
  final Transferable transferable = dtde.getTransferable();

  for ( int i = 0; i < acceptedFlavors.length; i++ ) {
    final DataFlavor acceptedFlavor = acceptedFlavors[ i ];
    if ( transferable.isDataFlavorSupported( acceptedFlavor ) ) {
      // a transfer from the palette.
      try {
        transferData = transferable.getTransferData( acceptedFlavor );
        position = dtde.getLocation();
        flavor = acceptedFlavor;
        final int result = updateDragOver( dtde );
        if ( result > 0 ) {
          dtde.acceptDrag( DnDConstants.ACTION_COPY );
        } else {
          transferData = null;
          position = null;
          flavor = null;
          dtde.rejectDrag();
        }
        break;
      } catch ( Exception e ) {
        if ( logger.isDebugEnabled() ) {
          logger.debug( "ReportPanel.dragOver ", e ); // NON-NLS
        }
        transferData = null;
        position = null;
        flavor = null;
        dtde.rejectDrag();
      }
    }
  }
}
 
Example 18
Source File: JTableRenderer.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 19
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
public static Point convertDropTargetDragPointTo(DropTargetDragEvent dtde, Component comp) {
    Point pt = dtde.getLocation();
    convertPoint(pt, dtde.getDropTargetContext().getComponent(), comp);
    return pt;
}
 
Example 20
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
@Override public void dragOver(DropTargetDragEvent dtde) {
  DataFlavor[] f = dtde.getCurrentDataFlavors();
  boolean isDataFlavorSupported = f[0].getHumanPresentableName().equals(TreeNodeTransferable.NAME);
  if (!isDataFlavorSupported) {
    // This DataFlavor is not supported(e.g. files from the desktop)
    rejectDrag(dtde);
    return;
  }

  // figure out which cell it's over, no drag to self
  Point pt = dtde.getLocation();
  TreePath path = getPathForLocation(pt.x, pt.y);
  if (Objects.isNull(path)) {
    // Dropped into the non-node locations(e.g. margin area of JTree)
    rejectDrag(dtde);
    return;
  }
  // Object draggingObject;
  // if (!isWebStart()) {
  //   try {
  //     draggingObject = dtde.getTransferable().getTransferData(FLAVOR);
  //   } catch (Exception ex) {
  //     rejectDrag(dtde);
  //     return;
  //   }
  // } else {
  //   draggingObject = getSelectionPath().getLastPathComponent();
  // }
  // MutableTreeNode draggingNode = (MutableTreeNode) draggingObject;

  MutableTreeNode draggingNode = (MutableTreeNode) getSelectionPath().getLastPathComponent();
  DefaultMutableTreeNode targetNode = (DefaultMutableTreeNode) path.getLastPathComponent();

  TreeNode parent = targetNode.getParent();
  if (parent instanceof DefaultMutableTreeNode) {
    DefaultMutableTreeNode ancestor = (DefaultMutableTreeNode) parent;
    if (Arrays.asList(ancestor.getPath()).contains(draggingNode)) {
      // Trying to drop a parent node to a child node
      rejectDrag(dtde);
      return;
    }
  }
  dropTargetNode = targetNode; // (TreeNode) path.getLastPathComponent();
  dtde.acceptDrag(dtde.getDropAction());
  repaint();
}