本文整理汇总了Java中java.awt.dnd.DropTargetDragEvent.getTransferable方法的典型用法代码示例。如果您正苦于以下问题:Java DropTargetDragEvent.getTransferable方法的具体用法?Java DropTargetDragEvent.getTransferable怎么用?Java DropTargetDragEvent.getTransferable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.dnd.DropTargetDragEvent
的用法示例。
在下文中一共展示了DropTargetDragEvent.getTransferable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dragEnter
import java.awt.dnd.DropTargetDragEvent; //导入方法依赖的package包/类
/**
*
*/
public void dragEnter(DropTargetDragEvent e) {
JComponent component = getDropTarget(e);
TransferHandler th = component.getTransferHandler();
boolean isLocal =
th instanceof mxGraphTransferHandler && ((mxGraphTransferHandler) th).isLocalDrag();
if (isLocal) {
canImport = true;
} else {
canImport =
graphComponent.isImportEnabled() && th.canImport(component, e.getCurrentDataFlavors());
}
if (canImport) {
transferBounds = null;
setVisible(false);
try {
Transferable t = e.getTransferable();
if (t.isDataFlavorSupported(mxGraphTransferable.dataFlavor)) {
mxGraphTransferable gt =
(mxGraphTransferable) t.getTransferData(mxGraphTransferable.dataFlavor);
dragCells = gt.getCells();
if (gt.getBounds() != null) {
mxGraph graph = graphComponent.getGraph();
double scale = graph.getView().getScale();
transferBounds = gt.getBounds();
int w = (int) Math.ceil((transferBounds.getWidth() + 1) * scale);
int h = (int) Math.ceil((transferBounds.getHeight() + 1) * scale);
setPreviewBounds(
new Rectangle((int) transferBounds.getX(), (int) transferBounds.getY(), w, h));
if (imagePreview) {
// Does not render fixed cells for local preview
// but ignores movable state for non-local previews
if (isLocal) {
if (!isLivePreview()) {
updateDragImage(graph.getMovableCells(dragCells));
}
} else {
Object[] tmp = graphComponent.getImportableCells(dragCells);
updateDragImage(tmp);
// Shows no drag icon if import is allowed but none
// of the cells can be imported
if (tmp == null || tmp.length == 0) {
canImport = false;
e.rejectDrag();
return;
}
}
}
setVisible(true);
}
}
e.acceptDrag(TransferHandler.COPY_OR_MOVE);
} catch (Exception ex) {
// do nothing
ex.printStackTrace();
}
} else {
e.rejectDrag();
}
}