Java 类org.eclipse.swt.events.DragDetectListener 实例源码

项目:Notepad4e    文件:NotepadView.java   
/**
 * Swaps two tabs and corresponding notes when a user drags one to another.
 */
private void addSwapTabListener() {
    tabFolder.addDragDetectListener(new DragDetectListener() {
        @Override
        public void dragDetected(DragDetectEvent dragDetectedEvent) {
            final Rectangle viewRectangle = Geometry.toDisplay(tabFolder.getParent(), tabFolder.getBounds());
            final Tracker tracker = new Tracker(tabFolder, SWT.NONE);
            tracker.setStippled(true);
            tracker.addListener(SWT.Move, new Listener() {
                @Override
                public void handleEvent(Event event) {
                    Point location = new Point(event.x - viewRectangle.x, event.y - viewRectangle.y);
                    CTabItem tabAtLocation = tabFolder.getItem(location);
                    if (tabAtLocation != null) {
                        // Move tracker to follow mouse cursor.
                        tracker.setRectangles(new Rectangle[] { tabAtLocation.getBounds() });
                    } else {
                        // Mouse cursor no longer above any tab in the action bar, hide tacker.
                        tracker.setRectangles(new Rectangle[0]);
                    }
                }
            });
            if (tracker.open()) {
                Rectangle[] rectangles = tracker.getRectangles();
                if (rectangles.length > 0) {
                    CTabItem tabToSwap = tabFolder.getItem(new Point(rectangles[0].x, rectangles[0].y));
                    // Swap selected tab with the one situated at the mouse cursor's position.
                    if (tabToSwap != null) {
                        swapNoteTabs(tabFolder.indexOf(tabToSwap));
                    }
                }
            }
            tracker.close();
            tracker.dispose();
        }
    });
}
项目:astor    文件:ChartComposite.java   
/**
 * Hook an SWT listener on the canvas where the chart is drawn.
 * The purpose of this method is to allow some degree of customization.
 *
 * @param listener The SWT listener to attach to the canvas.
 */
public void addSWTListener(EventListener listener) {
    if (listener instanceof ControlListener) {
        this.canvas.addControlListener((ControlListener) listener);
    }
    else if (listener instanceof DisposeListener) {
        this.canvas.addDisposeListener((DisposeListener) listener);
    }
    else if (listener instanceof DragDetectListener) {
        this.canvas.addDragDetectListener((DragDetectListener) listener);
    }
    else if (listener instanceof FocusListener) {
        this.canvas.addFocusListener((FocusListener) listener);
    }
    else if (listener instanceof HelpListener) {
        this.canvas.addHelpListener((HelpListener) listener);
    }
    else if (listener instanceof KeyListener) {
        this.canvas.addKeyListener((KeyListener) listener);
    }
    else if (listener instanceof MenuDetectListener) {
        this.canvas.addMenuDetectListener((MenuDetectListener) listener);
    }
    else if (listener instanceof MouseListener) {
        this.canvas.addMouseListener((MouseListener) listener);
    }
    else if (listener instanceof MouseMoveListener) {
        this.canvas.addMouseMoveListener((MouseMoveListener) listener);
    }
    else if (listener instanceof MouseTrackListener) {
        this.canvas.addMouseTrackListener((MouseTrackListener) listener);
    }
    else if (listener instanceof MouseWheelListener) {
        this.canvas.addMouseWheelListener((MouseWheelListener) listener);
    }
    else if (listener instanceof PaintListener) {
        this.canvas.addPaintListener((PaintListener) listener);
    }
    else if (listener instanceof TraverseListener) {
        this.canvas.addTraverseListener((TraverseListener) listener);
    }
}
项目:elexis-3-base    文件:AbstractBrowseText.java   
public void addDragDetectListener(DragDetectListener listener){
    this.text.addDragDetectListener(listener);
}
项目:elexis-3-base    文件:AbstractBrowseText.java   
public void removeDragDetectListener(DragDetectListener listener){
    this.text.removeDragDetectListener(listener);
}
项目:gef-gwt    文件:Control.java   
/**
 * Adds the listener to the collection of listeners who will be notified
 * when a drag gesture occurs, by sending it one of the messages defined in
 * the <code>DragDetectListener</code> interface.
 * 
 * @param listener
 *            the listener which should be notified
 * 
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 * 
 * @see DragDetectListener
 * @see #removeDragDetectListener
 * 
 * @since 3.3
 */
public void addDragDetectListener(DragDetectListener listener) {
    checkWidget();
    if (listener == null)
        error(SWT.ERROR_NULL_ARGUMENT);
    TypedListener typedListener = new TypedListener(listener);
    addListener(SWT.DragDetect, typedListener);
}
项目:gef-gwt    文件:Control.java   
/**
 * Removes the listener from the collection of listeners who will be
 * notified when a drag gesture occurs.
 * 
 * @param listener
 *            the listener which should no longer be notified
 * 
 * @exception IllegalArgumentException
 *                <ul>
 *                <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
 *                </ul>
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 * 
 * @see DragDetectListener
 * @see #addDragDetectListener
 * 
 * @since 3.3
 */
public void removeDragDetectListener(DragDetectListener listener) {
    checkWidget();
    if (listener == null)
        error(SWT.ERROR_NULL_ARGUMENT);
    if (eventTable == null)
        return;
    eventTable.unhook(SWT.DragDetect, listener);
}
项目:convertigo-eclipse    文件:TreeWrapper.java   
public void addDragDetectListener(DragDetectListener listener) {

    tree.addDragDetectListener(listener);
}
项目:convertigo-eclipse    文件:TreeWrapper.java   
public void removeDragDetectListener(DragDetectListener listener) {

    tree.removeDragDetectListener(listener);
}