當前位置: 首頁>>代碼示例>>Java>>正文


Java DropTargetDragEvent.getTransferable方法代碼示例

本文整理匯總了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();
  }
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:74,代碼來源:mxGraphHandler.java


注:本文中的java.awt.dnd.DropTargetDragEvent.getTransferable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。