Search in sources :

Example 31 with MouseListener

use of org.eclipse.swt.events.MouseListener in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method getRulerMouseListener.

/**
 * Creates and returns the listener on this editor's vertical ruler.
 *
 * @return the mouse listener
 */
protected final MouseListener getRulerMouseListener() {
    if (fMouseListener == null) {
        fMouseListener = new MouseListener() {

            private boolean fDoubleClicked = false;

            private final int fDoubleClickTime = getSite().getShell().getDisplay().getDoubleClickTime();

            private long fMouseUpDelta = 0;

            private void triggerAction(String actionID, MouseEvent e) {
                IAction action = getAction(actionID);
                if (action != null) {
                    if (action instanceof IUpdate)
                        ((IUpdate) action).update();
                    if (action.isEnabled()) {
                        Event event = new Event();
                        event.type = fDoubleClicked ? SWT.MouseDoubleClick : SWT.MouseUp;
                        event.display = e.display;
                        event.widget = e.widget;
                        event.time = e.time;
                        event.data = e.data;
                        event.x = e.x;
                        event.y = e.y;
                        event.button = e.button;
                        event.stateMask = e.stateMask;
                        event.count = e.count;
                        action.runWithEvent(event);
                    }
                }
            }

            @Override
            public void mouseUp(final MouseEvent e) {
                setFocus();
                final int delay = fMouseUpDelta == 0 ? 0 : fDoubleClickTime - (int) (System.currentTimeMillis() - fMouseUpDelta);
                if (1 != e.button)
                    return;
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (!fDoubleClicked)
                            triggerAction(ITextEditorActionConstants.RULER_CLICK, e);
                    }
                };
                if (delay <= 0)
                    runnable.run();
                else
                    e.widget.getDisplay().timerExec(delay, runnable);
            }

            @Override
            public void mouseDoubleClick(MouseEvent e) {
                if (1 == e.button) {
                    fDoubleClicked = true;
                    triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, e);
                }
            }

            @Override
            public void mouseDown(MouseEvent e) {
                fMouseUpDelta = System.currentTimeMillis();
                fDoubleClicked = false;
                if (fRulerContextMenu != null && !fRulerContextMenu.isDisposed()) {
                    Display display = fRulerContextMenu.getDisplay();
                    Point location = display.getCursorLocation();
                    fRulerContextMenu.setLocation(location.x, location.y);
                }
            }
        };
    }
    return fMouseListener;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) IAction(org.eclipse.jface.action.IAction) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) MouseListener(org.eclipse.swt.events.MouseListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TextEvent(org.eclipse.jface.text.TextEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) GestureEvent(org.eclipse.swt.events.GestureEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Display(org.eclipse.swt.widgets.Display)

Example 32 with MouseListener

use of org.eclipse.swt.events.MouseListener in project eclipse.platform.text by eclipse.

the class VerticalRuler method createControl.

@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
    fTextViewer = textViewer;
    fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            if (fTextViewer != null)
                doubleBufferPaint(event.gc);
        }
    });
    fCanvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fTextViewer = null;
        }
    });
    fCanvas.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent event) {
        }

        @Override
        public void mouseDown(MouseEvent event) {
            fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            fLastMouseButtonActivityLine = toDocumentLineNumber(event.y);
        }
    });
    if (fTextViewer != null) {
        fTextViewer.addViewportListener(fInternalListener);
        fTextViewer.addTextListener(fInternalListener);
    }
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

MouseListener (org.eclipse.swt.events.MouseListener)32 MouseEvent (org.eclipse.swt.events.MouseEvent)31 KeyEvent (org.eclipse.swt.events.KeyEvent)11 KeyListener (org.eclipse.swt.events.KeyListener)9 Point (org.eclipse.swt.graphics.Point)9 GridData (org.eclipse.swt.layout.GridData)9 GridLayout (org.eclipse.swt.layout.GridLayout)7 ControlEvent (org.eclipse.swt.events.ControlEvent)6 FocusEvent (org.eclipse.swt.events.FocusEvent)6 ModifyEvent (org.eclipse.swt.events.ModifyEvent)6 ModifyListener (org.eclipse.swt.events.ModifyListener)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 Composite (org.eclipse.swt.widgets.Composite)6 FocusListener (org.eclipse.swt.events.FocusListener)5 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)5 PaintEvent (org.eclipse.swt.events.PaintEvent)5 PaintListener (org.eclipse.swt.events.PaintListener)5 Button (org.eclipse.swt.widgets.Button)5 VerifyEvent (org.eclipse.swt.events.VerifyEvent)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4