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


Java DragSourceAdapter类代码示例

本文整理汇总了Java中java.awt.dnd.DragSourceAdapter的典型用法代码示例。如果您正苦于以下问题:Java DragSourceAdapter类的具体用法?Java DragSourceAdapter怎么用?Java DragSourceAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ImageDragSource

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ImageTransferTest.java

示例2: installDragGestureHandler

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
 * 
 */
protected void installDragGestureHandler() {
  DragGestureListener dragGestureListener = new DragGestureListener() {
    public void dragGestureRecognized(DragGestureEvent e) {
      if (graphComponent.isDragEnabled() && first != null) {
        final TransferHandler th = graphComponent.getTransferHandler();

        if (th instanceof mxGraphTransferHandler) {
          final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
              .createTransferable(graphComponent);

          if (t != null) {
            e.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t,
                new DragSourceAdapter() {

                  /**
                   * 
                   */
                  public void dragDropEnd(DragSourceDropEvent dsde) {
                    ((mxGraphTransferHandler) th).exportDone(graphComponent, t,
                        TransferHandler.NONE);
                    first = null;
                  }
                });
          }
        }
      }
    }
  };

  DragSource dragSource = new DragSource();
  dragSource.createDefaultDragGestureRecognizer(graphComponent.getGraphControl(),
      (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE : DnDConstants.ACTION_MOVE,
      dragGestureListener);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:38,代码来源:mxGraphHandler.java

示例3: dragGestureRecognized

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.getSourceAsDragGestureRecognizer().setSourceActions(DnDConstants.ACTION_COPY);
    JTree t = (JTree) dge.getComponent();
    List<Object> selectedNodes = new ArrayList<Object>();
    if (t.getSelectionPaths() == null) return;
    for (TreePath path : t.getSelectionPaths()) {
    	selectedNodes.add(path.getLastPathComponent());
    }
    dge.getDragSource().startDrag(dge, null, 
            new OlapMetadataTransferable(selectedNodes.toArray()), 
            new DragSourceAdapter() {//just need a default adapter
            }
    );
}
 
开发者ID:SQLPower,项目名称:wabit,代码行数:15,代码来源:OlapQueryPanel.java

示例4: installDragGestureHandler

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
 * 
 */
protected void installDragGestureHandler()
{
	DragGestureListener dragGestureListener = new DragGestureListener()
	{
		public void dragGestureRecognized(DragGestureEvent e)
		{
			if (graphComponent.isDragEnabled() && first != null)
			{
				final TransferHandler th = graphComponent
						.getTransferHandler();

				if (th instanceof mxGraphTransferHandler)
				{
					final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
							.createTransferable(graphComponent);

					if (t != null)
					{
						e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
								new Point(), t, new DragSourceAdapter()
								{

									/**
									 * 
									 */
									public void dragDropEnd(
											DragSourceDropEvent dsde)
									{
										((mxGraphTransferHandler) th)
												.exportDone(
														graphComponent,
														t,
														TransferHandler.NONE);
										first = null;
									}
								});
					}
				}
			}
		}
	};

	DragSource dragSource = new DragSource();
	dragSource.createDefaultDragGestureRecognizer(graphComponent
			.getGraphControl(),
			(isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
					: DnDConstants.ACTION_MOVE, dragGestureListener);
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:52,代码来源:mxGraphHandler.java

示例5: run

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
public void run() {
    frame = new Frame();

    final DragSourceListener dragSourceListener = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            dropSuccess = e.getDropSuccess();
            System.err.println("Drop was successful: " + dropSuccess);
        }
    };
    DragGestureListener dragGestureListener = new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
        }
    };
    new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
                                                        dragGestureListener);

    DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_MOVE);
            dtde.dropComplete(true);
            System.err.println("Drop");
        }
    };
    new DropTarget(frame, dropTargetListener);

    //What would normally go into main() will probably go here.
    //Use System.out.println for diagnostic messages that you want
    //to read after the test is done.
    frame.setUndecorated(true);
    frame.setBounds(100, 100, 200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    Robot robot = Util.createRobot();

    Util.waitForIdle(robot);

    Point startPoint = frame.getLocationOnScreen();
    Point endPoint = new Point(startPoint);
    startPoint.translate(50, 50);
    endPoint.translate(150, 150);

    Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);

    Util.waitForIdle(robot);
    robot.delay(500);

    if (dropSuccess) {
        System.err.println("test passed");
    } else {
        throw new RuntimeException("test failed: drop was not successful");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:Button2DragTest.java

示例6: makeDraggable

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
private void makeDraggable(final JButton b, final Class codenameOneClass, final String namePrefix, final CustomComponent custom) {
    DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(b,
            TransferHandler.MOVE, new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            lockForDragging = true;
            try {
                com.codename1.ui.Component cmp;
                if(custom != null && custom.isUiResource()) {
                    UIBuilderOverride u = new UIBuilderOverride();
                    cmp = u.createContainer(res, custom.getType());
                    if(b.getIcon() != null) {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                                ((ImageIcon)b.getIcon()).getImage(), new Point(0, 0),
                                new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    } else {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                            new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    }
                    return;
                }
                if(codenameOneClass == com.codename1.ui.Component.class) {
                    // special case for custom component which has a protected constructor
                    cmp = new com.codename1.ui.Component() {};
                } else {
                    cmp = (com.codename1.ui.Component)codenameOneClass.newInstance();
                }
                cmp.putClientProperty(TYPE_KEY, namePrefix);
                cmp.setName(findUniqueName(namePrefix));
                initializeComponentText(cmp);
                if(custom != null) {
                    cmp.putClientProperty("CustomComponent", custom);
                    cmp.putClientProperty(TYPE_KEY, custom.getType());
                }
                DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                        new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                        });
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:45,代码来源:UserInterfaceEditor.java

示例7: installDragGestureHandler

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
 * 
 */
protected void installDragGestureHandler()
{
	DragGestureListener dragGestureListener = new DragGestureListener()
	{
		public void dragGestureRecognized(DragGestureEvent e)
		{
			if (graphComponent.isDragEnabled() && first != null)
			{
				final TransferHandler th = graphComponent
						.getTransferHandler();

				if (th instanceof mxGraphTransferHandler)
				{
					final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
							.createTransferable(graphComponent);

					if (t != null)
					{
						e.startDrag(null, mxConstants.EMPTY_IMAGE,
								new Point(), t, new DragSourceAdapter()
								{

									/**
									 * 
									 */
									public void dragDropEnd(
											DragSourceDropEvent dsde)
									{
										((mxGraphTransferHandler) th)
												.exportDone(
														graphComponent,
														t,
														TransferHandler.NONE);
										first = null;
									}
								});
					}
				}
			}
		}
	};

	DragSource dragSource = new DragSource();
	dragSource.createDefaultDragGestureRecognizer(
			graphComponent.getGraphControl(),
			DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}
 
开发者ID:alect,项目名称:Puzzledice,代码行数:51,代码来源:mxGraphHandler.java

示例8: installDragGestureHandler

import java.awt.dnd.DragSourceAdapter; //导入依赖的package包/类
/**
 * 
 */
protected void installDragGestureHandler()
{
	DragGestureListener dragGestureListener = new DragGestureListener()
	{
		public void dragGestureRecognized(DragGestureEvent e)
		{
			if (graphComponent.isDragEnabled() && first != null)
			{
				final TransferHandler th = graphComponent
						.getTransferHandler();

				if (th instanceof mxGraphTransferHandler)
				{
					final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
							.createTransferable(graphComponent);

					if (t != null)
					{
						e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
								new Point(), t, new DragSourceAdapter()
								{

									/**
									 * 
									 */
									public void dragDropEnd(
											DragSourceDropEvent dsde)
									{
										((mxGraphTransferHandler) th)
												.exportDone(
														graphComponent,
														t,
														TransferHandler.NONE);
										first = null;
									}
								});
					}
				}
			}
		}
	};

	DragSource dragSource = new DragSource();
	dragSource.createDefaultDragGestureRecognizer(
			graphComponent.getGraphControl(),
			DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}
 
开发者ID:luartmg,项目名称:WMA,代码行数:51,代码来源:mxGraphHandler.java


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