当前位置: 首页>>代码示例>>Java>>正文


Java JComponent.getTransferHandler方法代码示例

本文整理汇总了Java中javax.swing.JComponent.getTransferHandler方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.getTransferHandler方法的具体用法?Java JComponent.getTransferHandler怎么用?Java JComponent.getTransferHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComponent的用法示例。


在下文中一共展示了JComponent.getTransferHandler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dragGestureRecognized

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void dragGestureRecognized(DragGestureEvent dge) {
    JComponent c = (JComponent)dge.getComponent();
    DefaultTransferHandler th
        = (DefaultTransferHandler)c.getTransferHandler();
    Transferable t = th.createTransferable(c);
    if (t == null) {
        logger.warning("Unable to create transferable for: " + dge);
        th.exportDone(c, null, NONE);
        return;
    }

    this.scrolls = c.getAutoscrolls();
    c.setAutoscrolls(false);
    try {
        Cursor cursor = getCursor(c);
        dge.startDrag(cursor, t, this);
    } catch (RuntimeException re) {
        c.setAutoscrolls(this.scrolls);
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:24,代码来源:DefaultTransferHandler.java

示例2: isDragPossible

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Determines if the following are true:
 * <ul>
 * <li>the press event is located over a selection
 * <li>the dragEnabled property is true
 * <li>A TranferHandler is installed
 * </ul>
 * <p>
 * This is implemented to check for a TransferHandler.
 * Subclasses should perform the remaining conditions.
 */
protected boolean isDragPossible(MouseEvent e) {
    JComponent comp = getEventComponent(e);
    boolean possible =  (comp == null) ? false : (comp.getTransferHandler() != null);
    if (possible) {
        JTextComponent c = (JTextComponent) getEventComponent(e);
        if (c.getDragEnabled()) {
            Caret caret = c.getCaret();
            int dot = caret.getDot();
            int mark = caret.getMark();
            if (dot != mark) {
                Point p = new Point(e.getX(), e.getY());
                int pos = c.viewToModel(p);

                int p0 = Math.min(dot, mark);
                int p1 = Math.max(dot, mark);
                if ((pos >= p0) && (pos < p1)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:BaseCaret.java

示例3: isDragPossible

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
    * Determines if the following are true:
    * <ul>
    * <li>the press event is located over a selection
    * <li>the dragEnabled property is true
    * <li>A TranferHandler is installed
    * </ul>
    * <p>
    * This is implemented to check for a TransferHandler.
    * Subclasses should perform the remaining conditions.
    */
   private boolean isDragPossible(MouseEvent e) {
Object src = e.getSource();
if (src instanceof JComponent) {
    JComponent comp = (JComponent) src;
           boolean possible =  (comp == null) ? false : (comp.getTransferHandler() != null);
           if (possible && comp instanceof JTextComponent) {
               JTextComponent c = (JTextComponent) comp;
               if (c.getDragEnabled()) {
                   Caret caret = c.getCaret();
                   int dot = caret.getDot();
                   int mark = caret.getMark();
                   if (dot != mark) {
                       Point p = new Point(e.getX(), e.getY());
                       int pos = c.viewToModel(p);

                       int p0 = Math.min(dot, mark);
                       int p1 = Math.max(dot, mark);
                       if ((pos >= p0) && (pos < p1)) {
                           return true;
                       }
                   }
               }
           }
       }
       return false;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:EditorCaret.java

示例4: mouseReleased

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:19,代码来源:DropListener.java

示例5: getGraphTransferHandler

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Helper method to return the component for a drop target event.
 */
protected static final mxGraphTransferHandler getGraphTransferHandler(
		DropTargetEvent e)
{
	JComponent component = getDropTarget(e);
	TransferHandler transferHandler = component.getTransferHandler();

	if (transferHandler instanceof mxGraphTransferHandler)
	{
		return (mxGraphTransferHandler) transferHandler;
	}

	return null;
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:17,代码来源:mxGraphHandler.java

示例6: getGraphTransferHandler

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Helper method to return the component for a drop target event.
 */
protected static final mxGraphTransferHandler getGraphTransferHandler(DropTargetEvent e) {
  JComponent component = getDropTarget(e);
  TransferHandler transferHandler = component.getTransferHandler();

  if (transferHandler instanceof mxGraphTransferHandler) {
    return (mxGraphTransferHandler) transferHandler;
  }

  return null;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:14,代码来源:mxGraphHandler.java

示例7: mouseDragged

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e) 
{
	JComponent c = (JComponent)e.getSource();
	TransferHandler th = c.getTransferHandler();
	th.exportAsDrag(c, e, TransferHandler.MOVE);
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:8,代码来源:BracketPane.java

示例8: dragEnter

import javax.swing.JComponent; //导入方法依赖的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


注:本文中的javax.swing.JComponent.getTransferHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。