Search in sources :

Example 91 with MouseEvent

use of org.eclipse.swt.events.MouseEvent 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 92 with MouseEvent

use of org.eclipse.swt.events.MouseEvent 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)

Example 93 with MouseEvent

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

the class SearchHistorySelectionDialog method createDialogArea.

/*
	 * Overrides method from Dialog
	 */
@Override
protected Control createDialogArea(Composite container) {
    Composite ancestor = (Composite) super.createDialogArea(container);
    createMessageArea(ancestor);
    Composite parent = new Composite(ancestor, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));
    fViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fViewer.setContentProvider(new ArrayContentProvider());
    final Table table = fViewer.getTable();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            okPressed();
        }
    });
    fViewer.setLabelProvider(new SearchesLabelProvider());
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = convertHeightInCharsToPixels(15);
    gd.widthHint = convertWidthInCharsToPixels(WIDTH_IN_CHARACTERS);
    table.setLayoutData(gd);
    fRemoveButton = new Button(parent, SWT.PUSH);
    fRemoveButton.setText(SearchMessages.SearchesDialog_remove_label);
    fRemoveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            buttonPressed(REMOVE_ID);
        }
    });
    fRemoveButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
    SWTUtil.setButtonDimensionHint(fRemoveButton);
    fViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validateDialogState();
        }
    });
    fLink = new Link(parent, SWT.NONE);
    configureHistoryLink();
    fLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            HistoryConfigurationDialog dialog = new HistoryConfigurationDialog(getShell(), fInput, fRemovedEntries);
            if (dialog.open() == Window.OK) {
                fViewer.refresh();
                configureHistoryLink();
            }
        }
    });
    fLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    applyDialogFont(ancestor);
    // set input & selections last, so all the widgets are created.
    fViewer.setInput(fInput);
    fViewer.getTable().setFocus();
    return ancestor;
}
Also used : Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Link(org.eclipse.swt.widgets.Link)

Example 94 with MouseEvent

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

the class AbstractInformationControl method addResizeSupportIfNecessary.

private void addResizeSupportIfNecessary(final Composite bars) {
    // XXX: workarounds for
    // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=219139 : API to add resize grip / grow box in lower right corner of shell
    // - https://bugs.eclipse.org/bugs/show_bug.cgi?id=23980 : platform specific shell resize behavior
    String platform = SWT.getPlatform();
    // $NON-NLS-1$
    final boolean isWin = platform.equals("win32");
    if (// $NON-NLS-1$
    !isWin && !platform.equals("gtk"))
        return;
    final Canvas resizer = new Canvas(bars, SWT.NONE);
    int size = getResizeHandleSize(bars);
    GridData data = new GridData(SWT.END, SWT.END, false, true);
    data.widthHint = size;
    data.heightHint = size;
    resizer.setLayoutData(data);
    resizer.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            Point s = resizer.getSize();
            int x = s.x - 2;
            int y = s.y - 2;
            int min = Math.min(x, y);
            if (isWin) {
                // draw dots
                e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                int end = min - 1;
                for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
                end--;
                e.gc.setBackground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
                for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2 - i; j++) e.gc.fillRectangle(end - 4 * i, end - 4 * j, 2, 2);
            } else {
                // draw diagonal lines
                e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
                for (int i = 1; i < min; i += 4) {
                    e.gc.drawLine(i, y, x, i);
                }
                e.gc.setForeground(resizer.getDisplay().getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
                for (int i = 2; i < min; i += 4) {
                    e.gc.drawLine(i, y, x, i);
                }
            }
        }
    });
    final boolean isRTL = (resizer.getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
    resizer.setCursor(resizer.getDisplay().getSystemCursor(isRTL ? SWT.CURSOR_SIZESW : SWT.CURSOR_SIZESE));
    MouseAdapter resizeSupport = new MouseAdapter() {

        private MouseMoveListener fResizeListener;

        @Override
        public void mouseDown(MouseEvent e) {
            Rectangle shellBounds = fShell.getBounds();
            final int shellX = shellBounds.x;
            final int shellY = shellBounds.y;
            final int shellWidth = shellBounds.width;
            final int shellHeight = shellBounds.height;
            Point mouseLoc = resizer.toDisplay(e.x, e.y);
            final int mouseX = mouseLoc.x;
            final int mouseY = mouseLoc.y;
            fResizeListener = new MouseMoveListener() {

                @Override
                public void mouseMove(MouseEvent e2) {
                    Point mouseLoc2 = resizer.toDisplay(e2.x, e2.y);
                    int dx = mouseLoc2.x - mouseX;
                    int dy = mouseLoc2.y - mouseY;
                    if (isRTL) {
                        setLocation(new Point(shellX + dx, shellY));
                        setSize(shellWidth - dx, shellHeight + dy);
                    } else {
                        setSize(shellWidth + dx, shellHeight + dy);
                    }
                }
            };
            resizer.addMouseMoveListener(fResizeListener);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            resizer.removeMouseMoveListener(fResizeListener);
            fResizeListener = null;
        }
    };
    resizer.addMouseListener(resizeSupport);
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) GridData(org.eclipse.swt.layout.GridData)

Example 95 with MouseEvent

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

the class AnnotationBarHoverManager method computeInformation.

@Override
protected void computeInformation() {
    fAllowMouseExit = false;
    MouseEvent event = getHoverEvent();
    if ((event.stateMask & SWT.BUTTON_MASK) != 0) {
        setInformation(null, null);
        return;
    }
    IAnnotationHover hover = getHover(event);
    if (hover == null) {
        setInformation(null, null);
        return;
    }
    int line = getHoverLine(event);
    if (hover instanceof IAnnotationHoverExtension) {
        IAnnotationHoverExtension extension = (IAnnotationHoverExtension) hover;
        ILineRange range = extension.getHoverLineRange(fSourceViewer, line);
        setCustomInformationControlCreator(extension.getHoverControlCreator());
        range = adaptLineRange(range, line);
        if (range != null)
            setInformation(extension.getHoverInfo(fSourceViewer, range, computeNumberOfVisibleLines()), computeArea(range));
        else
            setInformation(null, null);
    } else {
        setCustomInformationControlCreator(null);
        setInformation(hover.getHoverInfo(fSourceViewer, line), computeArea(line));
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Point(org.eclipse.swt.graphics.Point)

Aggregations

MouseEvent (org.eclipse.swt.events.MouseEvent)100 MouseAdapter (org.eclipse.swt.events.MouseAdapter)50 GridData (org.eclipse.swt.layout.GridData)37 MouseListener (org.eclipse.swt.events.MouseListener)32 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Point (org.eclipse.swt.graphics.Point)32 KeyEvent (org.eclipse.swt.events.KeyEvent)27 Composite (org.eclipse.swt.widgets.Composite)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 Button (org.eclipse.swt.widgets.Button)20 FocusEvent (org.eclipse.swt.events.FocusEvent)18 PaintEvent (org.eclipse.swt.events.PaintEvent)18 Event (org.eclipse.swt.widgets.Event)15 Label (org.eclipse.swt.widgets.Label)15 Text (org.eclipse.swt.widgets.Text)14 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)13 PaintListener (org.eclipse.swt.events.PaintListener)13 KeyListener (org.eclipse.swt.events.KeyListener)12 ModifyEvent (org.eclipse.swt.events.ModifyEvent)12