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

The following examples show how to use java.awt.dnd.DropTargetDragEvent#getDropAction() . 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 dragEnter(DropTargetDragEvent event) {
    DataFlavor[] dataFlavors = event.getCurrentDataFlavors();
    JComponent c = (JComponent) event.getDropTargetContext().getComponent();
    TransferHandler transferHandler = c.getTransferHandler();

    if ((transferHandler != null) && transferHandler.canImport(c, dataFlavors)) {
        canImport = true;
    } else {
        canImport = false;
    }

    int dropAction = event.getDropAction();

    if (canImport && actionSupported(dropAction)) {
        event.acceptDrag(dropAction);
    } else {
        event.rejectDrag();
    }
}
 
Example 2
Source File: DockHeader.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private Dockable getDockableInDrag(DropTargetDragEvent dtde) {
    if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
        try {
            if (dtde.isDataFlavorSupported(DockableTransferable.DATA_FLAVOR)) {
                Dockable      dockable = (Dockable) dtde.getTransferable().getTransferData(DockableTransferable.DATA_FLAVOR);
                DockContainer dc       = dockable.getDockContainer();
                if (dc != null && dc.getDock() == getDockContainer().getDock()) {
                    return dockable;
                }
            }
        } catch (Exception exception) {
            Log.error(exception);
        }
    }
    return null;
}
 
Example 3
Source File: Dock.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
private Dockable getDockableInDrag(DropTargetDragEvent dtde) {
    if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
        try {
            if (dtde.isDataFlavorSupported(DockableTransferable.DATA_FLAVOR)) {
                Dockable      dockable = (Dockable) dtde.getTransferable().getTransferData(DockableTransferable.DATA_FLAVOR);
                DockContainer dc       = dockable.getDockContainer();
                if (dc != null && dc.getDock() == this) {
                    return dockable;
                }
            }
        } catch (Exception exception) {
            Log.error(exception);
        }
    }
    return null;
}
 
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void dropActionChanged(DropTargetDragEvent event) {
    int dropAction = event.getDropAction();
    if (canImport && actionSupported(dropAction)) {
        event.acceptDrag(dropAction);
    } else {
        event.rejectDrag();
    }
}
 
Example 11
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void dragOver(DropTargetDragEvent event) {
    int dropAction = event.getDropAction();
    if (canImport && actionSupported(dropAction)) {
        JTable table = (JTable) event.getDropTargetContext().getComponent();
        int row = table.rowAtPoint(event.getLocation());
        table.getSelectionModel().setSelectionInterval(row, row);
        event.acceptDrag(dropAction);
    } else {
        event.rejectDrag();
    }
}
 
Example 12
Source File: PaletteDropTarget.java    From niftyeditor with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void dragOver(DropTargetDragEvent dtde){
    super.dragOver(dtde);
    J2DNiftyView comp = (J2DNiftyView) this.getComponent();
   
    if(dtde.getDropAction() == DnDConstants.ACTION_MOVE 
            && dtde.getTransferable().isDataFlavorSupported(WidgetData.POINTFLAVOR)){
        comp.moveRect(dtde.getLocation().x, dtde.getLocation().y);
       comp.getDDManager().dragAround(dtde.getLocation().x, dtde.getLocation().y);
    }
    
}
 
Example 13
Source File: MMDGraphEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
protected boolean acceptOrRejectDragging(final DropTargetDragEvent dtde) {
  final int dropAction = dtde.getDropAction();

  boolean result = false;

  if (this.dragAcceptableType && (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) != 0 && this.mindMapPanel.findTopicUnderPoint(dtde.getLocation()) != null) {
    result = true;
  }

  return result;
}
 
Example 14
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
protected boolean acceptOrRejectDragging(final DropTargetDragEvent dtde) {
  final int dropAction = dtde.getDropAction();

  boolean result = false;

  if (this.dragAcceptableType && (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) != 0 && this.mindMapPanel.findTopicUnderPoint(dtde.getLocation()) != null) {
    result = true;
  }

  return result;
}
 
Example 15
Source File: MMDEditor.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
protected boolean acceptOrRejectDragging(@Nonnull final DropTargetDragEvent dtde) {
  final int dropAction = dtde.getDropAction();

  boolean result = false;

  if (this.dragAcceptableType && (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) != 0 && this.mindMapPanel.findTopicUnderPoint(dtde.getLocation()) != null) {
    result = true;
  }

  return result;
}
 
Example 16
Source File: TreeRowDragState.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private boolean acceptDrag(DropTargetDragEvent event) {
    int allowed = getPanel().getAllowedRowDropTypes();
    if ((allowed & event.getDropAction()) == 0) {
        if ((allowed & DnDConstants.ACTION_MOVE) != 0) {
            event.acceptDrag(DnDConstants.ACTION_MOVE);
        } else if ((allowed & DnDConstants.ACTION_COPY) != 0) {
            event.acceptDrag(DnDConstants.ACTION_COPY);
        } else {
            event.acceptDrag(DnDConstants.ACTION_NONE);
            return false;
        }
    }
    return true;
}
 
Example 17
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 18
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 19
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 20
Source File: IndexedCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** @return True if conditions to continue with DnD
* operation were satisfied */
boolean checkConditions(DropTargetDragEvent dtde) {
    int index = comp.locationToIndex(dtde.getLocation());

    return (DnDConstants.ACTION_MOVE == dtde.getDropAction()) && (index >= 0);
}