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


Java DragSourceListener类代码示例

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


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

示例1: ImageDragSource

import java.awt.dnd.DragSourceListener; //导入依赖的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: startDragAction

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Invoked on dragGestureRecognized in the ComponentDragGestureListener
 * class.
 * 
 */
public void startDragAction(DragGestureEvent dge, DragSourceListener dsl) {

    // create a Transferable object here.

    // Create a location object that can be dropped on a layer.

    // dragSource.startDrag(dge,
    // getCursor(DragSource.DefaultMoveDrop), new
    // DefaultTransferableObject(new BasicLocation()), dsl);

    // SinkGraphic is a singleton object used as sample. No action
    // on a layer will be done at drop.
    dragSource.startDrag(dge,
            getCursor(DragSource.DefaultMoveDrop),
            new DefaultTransferableObject(SinkGraphic.getSharedInstance()),
            dsl);
}
 
开发者ID:d2fn,项目名称:passage,代码行数:23,代码来源:DefaultDnDCatcher.java

示例3: dragEnter

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Calls <code>dragEnter</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dragEnter(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragEnter(dsde);
       }
       getDragSource().processDragEnter(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), ENTER);
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:19,代码来源:DragSourceContext.java

示例4: dragOver

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Calls <code>dragOver</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dragOver(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragOver(dsde);
       }
       getDragSource().processDragOver(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), OVER);
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:19,代码来源:DragSourceContext.java

示例5: dragExit

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Calls <code>dragExit</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceEvent</code>.
    *
    * @param dse the <code>DragSourceEvent</code>
    */
   public void dragExit(DragSourceEvent dse) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragExit(dse);
       }
       getDragSource().processDragExit(dse);

updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT);
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:19,代码来源:DragSourceContext.java

示例6: dropActionChanged

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Calls <code>dropActionChanged</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dropActionChanged(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dropActionChanged(dsde);
       }
       getDragSource().processDropActionChanged(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), CHANGED);
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:19,代码来源:DragSourceContext.java

示例7: readObject

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Deserializes this <code>DragSourceContext</code>. This method first
 * performs default deserialization for all non-<code>transient</code>
 * fields. This object's <code>Transferable</code> and
 * <code>DragSourceListener</code> are then deserialized as well by using
 * the next two objects in the stream. If the resulting
 * <code>Transferable</code> is <code>null</code>, this object's
 * <code>Transferable</code> is set to a dummy <code>Transferable</code>
 * which supports no <code>DataFlavor</code>s.
 *
 * @since 1.4
 */
private void readObject(ObjectInputStream s)
    throws ClassNotFoundException, IOException
{
    s.defaultReadObject();

    transferable = (Transferable)s.readObject();
    listener = (DragSourceListener)s.readObject();

    // Implementation assumes 'transferable' is never null.
    if (transferable == null) {
        if (emptyTransferable == null) {
            emptyTransferable = new Transferable() {
                    public DataFlavor[] getTransferDataFlavors() {
                        return new DataFlavor[0];
                    }
                    public boolean isDataFlavorSupported(DataFlavor flavor)
                    {
                        return false;
                    }
                    public Object getTransferData(DataFlavor flavor)
                        throws UnsupportedFlavorException
                    {
                        throw new UnsupportedFlavorException(flavor);
                    }
                };
        }
        transferable = emptyTransferable;
    }
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:42,代码来源:DragSourceContext.java

示例8: ComponentDragGestureListener

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Note that DefaultDnDCatcher is a DragSourceListener itself, so
 * dndCatcher and dsl can be the same object.
 */

public ComponentDragGestureListener(DefaultDnDCatcher dndCatcher,
        DragSourceListener dsl) {
    this.dndCatcher = dndCatcher;
    this.dsl = dsl;
    Debug.message("draggesturelistener",
            "Created> ComponentDragGestureListener");
    Debug.message("draggesturelistener", "dndCatcher=" + dndCatcher);
}
 
开发者ID:d2fn,项目名称:passage,代码行数:14,代码来源:ComponentDragGestureListener.java

示例9: run

import java.awt.dnd.DragSourceListener; //导入依赖的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

示例10: startDragAction

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Invoked on dragGestureRecognized
 */
public void startDragAction(DragGestureEvent dge, DragSourceListener dsl) {
    if (Debug.debugging("beanbox"))
        Debug.output("Enter> startDragAction");

    Object selectedBean = null;
    BeanBox selectedBeanBox = null;
    Layer selectedLayer = null;

    Point srcLocation = dge.getDragOrigin();

    Enumeration keys = layers.keys();
    while (keys.hasMoreElements()) {
        String layerName = keys.nextElement().toString();
        Layer omLayer = (Layer) layers.get(layerName);
        BeanBox beanBox = ((BeanBoxHandler) omLayer).getBeanBox();
        selectedBean = beanBox.getBeanAtLocation(srcLocation);
        if (selectedBean != null) {
            selectedBeanBox = beanBox;
            selectedLayer = omLayer;
            break;
        }
    }

    if (Debug.debugging("beanbox"))
        Debug.output("selectedBean=" + selectedBean);

    if (selectedBean == null || selectedBeanBox == null
            || selectedLayer == null) {
        if (Debug.debugging("beanbox"))
            Debug.output("Exit> startDragAction, selected bean/beanbox/layer is null");
        return;
    }

    Image dragImage = selectedBeanBox.getDragImage(selectedBean);

    super.setCursor(dragImage, DragSource.DefaultMoveDrop);

    BeanInfo beanInfo = selectedBeanBox.getBeanInfoForBean(selectedBean.getClass()
            .getName());

    Vector beanTransferData = new Vector();
    beanTransferData.add(selectedBean);
    beanTransferData.add(beanInfo);
    beanTransferData.add(new Boolean(true));
    beanTransferData.add(selectedLayer.getName());

    dragSource.startDrag(dge,
            super.getCursor(DragSource.DefaultMoveDrop),
            new DefaultTransferableObject(beanTransferData),
            dsl);

    if (Debug.debugging("beanbox"))
        Debug.output("Exit> startDragAction");
}
 
开发者ID:d2fn,项目名称:passage,代码行数:58,代码来源:BeanBoxDnDCatcher.java

示例11: addDragSourceListener

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Add a <code>DragSourceListener</code> to this
    * <code>DragSourceContext</code> if one has not already been added.
    * If a <code>DragSourceListener</code> already exists, 
    * this method throws a <code>TooManyListenersException</code>.
    * <P>
    * @param dsl the <code>DragSourceListener</code> to add.
    * Note that while <code>null</code> is not prohibited,
    * it is not acceptable as a parameter.
    * <P>
    * @throws <code>TooManyListenersException</code> if
    * a <code>DragSourceListener</code> has already been added
    */

   public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException {
if (dsl == null) return;

if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener");

if (listener != null)
    throw new TooManyListenersException();
else
    listener = dsl;
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:25,代码来源:DragSourceContext.java

示例12: removeDragSourceListener

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
    * Removes the specified <code>DragSourceListener</code>
    * from  this <code>DragSourceContext</code>.
    * 
    * @param dsl the <code>DragSourceListener</code> to remove;
    *     note that while <code>null</code> is not prohibited,
    *     it is not acceptable as a parameter
    */

   public synchronized void removeDragSourceListener(DragSourceListener dsl) {
if (listener != null && listener.equals(dsl)) {
    listener = null;
} else
    throw new IllegalArgumentException();
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:16,代码来源:DragSourceContext.java

示例13: dragDropEnd

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Calls <code>dragDropEnd</code> on the
 * <code>DragSourceListener</code>s registered with this
 * <code>DragSourceContext</code> and with the associated
 * <code>DragSource</code>, and passes them the specified
 * <code>DragSourceDropEvent</code>.
 *
 * @param dsde the <code>DragSourceDropEvent</code>
 */
public void dragDropEnd(DragSourceDropEvent dsde) {
    DragSourceListener dsl = listener;
    if (dsl != null) {
        dsl.dragDropEnd(dsde);
    }
    getDragSource().processDragDropEnd(dsde);
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:17,代码来源:DragSourceContext.java

示例14: getDragSourceListener

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Called by the DragGestureAdapter in dragGestureRecognized. This
 * is the listener that is registered with the drag source in the
 * startDrag method.
 *
 * @return usually the DragSourceAdapter
 */
public DragSourceListener getDragSourceListener();
 
开发者ID:NCIP,项目名称:caadapter,代码行数:9,代码来源:DragCompatibleComponent.java

示例15: getDragSourceListener

import java.awt.dnd.DragSourceListener; //导入依赖的package包/类
/**
 * Called by the DragGestureAdapter in dragGestureRecognized. This
 * is the listener that is registered with the drag source in the
 * startDrag method.
 *
 * @return usually the DragSourceAdapter
 */
public DragSourceListener getDragSourceListener()
{
	return this.dragSourceAdapter;
}
 
开发者ID:NCIP,项目名称:caadapter,代码行数:12,代码来源:TreeDefaultDragTransferHandler.java


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