Search in sources :

Example 11 with MouseMoveListener

use of org.eclipse.swt.events.MouseMoveListener in project cubrid-manager by CUBRID.

the class SelectedLoactionComparator method bindListener.

/**
	 * 
	 * Bind the linsteners
	 */
private void bindListener() {
    tableCursor.addMouseListener(new MouseListener() {

        public void mouseUp(MouseEvent event) {
            handleMouseUp(event);
        }

        public void mouseDown(MouseEvent event) {
            handleMouseDown(event);
        }

        public void mouseDoubleClick(MouseEvent event) {
            handleMouseDoubleClick(event);
        }
    });
    tableCursor.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent event) {
            handleMouseMove(event);
        }
    });
    table.addMouseListener(new MouseListener() {

        public void mouseUp(MouseEvent event) {
            handleMouseUp(event);
        }

        public void mouseDown(MouseEvent event) {
            handleMouseDown(event);
        }

        public void mouseDoubleClick(MouseEvent event) {
            handleMouseDoubleClick(event);
        }
    });
    table.addMouseTrackListener(new MouseTrackAdapter() {

        public void mouseExit(MouseEvent e) {
            Rectangle bound = table.getClientArea();
            if (!bound.contains(e.x, e.y)) {
                handleMouseExit(e);
            }
        }
    });
    table.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent event) {
            handleMouseMove(event);
        }
    });
    table.addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent event) {
            handleKeyReleased(event);
        }

        public void keyPressed(KeyEvent event) {
            handleKeyPressed(event);
        }
    });
    tableCursor.addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent event) {
            handleKeyReleased(event);
        }

        public void keyPressed(KeyEvent event) {
            handleKeyPressed(event);
            if (ctrlPressed) {
                if (event.keyCode == SWT.ARROW_DOWN) {
                    int maxY = getMaxY();
                    int minX = getMinX();
                    int maxX = getMaxX();
                    int y = maxY + 1;
                    if (maxY > -1 && minX > -1 && maxX > -1 && y < table.getItemCount()) {
                        tableCursor.setSelection(y, maxX);
                        for (int x = minX; x <= maxX; x++) {
                            Point p = new Point(x, y);
                            addSelectPoint(p, true);
                            drawSelectedItem(p, true);
                        }
                    }
                } else if (event.keyCode == SWT.ARROW_UP) {
                    int maxY = getMaxY();
                    int minX = getMinX();
                    int maxX = getMaxX();
                    int y = maxY;
                    if (maxY > -1 && minX > -1 && maxX > -1 && y > 0) {
                        tableCursor.setSelection(y - 1, maxX);
                        for (int x = minX; x <= maxX; x++) {
                            Point p = new Point(x, y);
                            removeSelectPoint(p, true);
                            drawUnselectedItem(p, true);
                        }
                    }
                } else if (event.keyCode == SWT.ARROW_LEFT) {
                    int maxY = getMaxY();
                    int minY = getMinY();
                    int maxX = getMaxX();
                    if (maxY > -1 && minY > -1 && maxX > 0) {
                        tableCursor.setSelection(maxY, maxX - 1);
                        for (int y = minY; y <= maxY; y++) {
                            Point p = new Point(maxX, y);
                            removeSelectPoint(p, true);
                            drawUnselectedItem(p, true);
                        }
                    }
                } else if (event.keyCode == SWT.ARROW_RIGHT) {
                    int maxY = getMaxY();
                    int minY = getMinY();
                    int maxX = getMaxX();
                    int columnCount = table.getColumnCount();
                    if (maxY > -1 && minY > -1 && maxX + 1 < columnCount) {
                        int x = maxX + 1;
                        tableCursor.setSelection(maxY, x);
                        for (int y = minY; y <= maxY; y++) {
                            Point p = new Point(x, y);
                            addSelectPoint(p, true);
                            drawSelectedItem(p, true);
                        }
                    }
                }
            } else if (!ctrlPressed && !shiftPressed) {
                if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP || event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT) {
                    selectedList.clear();
                    int y = table.indexOf(tableCursor.getRow());
                    int x = tableCursor.getColumn();
                    Point p = new Point(x, y);
                    addSelectPoint(p, true);
                    drawSelectedItems(true);
                }
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 12 with MouseMoveListener

use of org.eclipse.swt.events.MouseMoveListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Control method test_addMouseMoveListenerLorg_eclipse_swt_events_MouseMoveListener.

@Test
public void test_addMouseMoveListenerLorg_eclipse_swt_events_MouseMoveListener() {
    MouseMoveListener listener = e -> eventOccurred = true;
    control.addMouseMoveListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.MouseMove, new Event());
    assertTrue(eventOccurred);
    control.removeMouseMoveListener(listener);
}
Also used : PaintListener(org.eclipse.swt.events.PaintListener) HelpListener(org.eclipse.swt.events.HelpListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Rectangle(org.eclipse.swt.graphics.Rectangle) ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) FocusListener(org.eclipse.swt.events.FocusListener) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) KeyEvent(org.eclipse.swt.events.KeyEvent) Assert.fail(org.junit.Assert.fail) Font(org.eclipse.swt.graphics.Font) Widget(org.eclipse.swt.widgets.Widget) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) Assert.assertNotNull(org.junit.Assert.assertNotNull) Monitor(org.eclipse.swt.widgets.Monitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TraverseListener(org.eclipse.swt.events.TraverseListener) Display(org.eclipse.swt.widgets.Display) Consumer(java.util.function.Consumer) MouseEvent(org.eclipse.swt.events.MouseEvent) List(java.util.List) MouseListener(org.eclipse.swt.events.MouseListener) Assert.assertNull(org.junit.Assert.assertNull) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) Color(org.eclipse.swt.graphics.Color) Assert.assertFalse(org.junit.Assert.assertFalse) SWT(org.eclipse.swt.SWT) Accessible(org.eclipse.swt.accessibility.Accessible) Assume.assumeTrue(org.junit.Assume.assumeTrue) KeyListener(org.eclipse.swt.events.KeyListener) Menu(org.eclipse.swt.widgets.Menu) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Control(org.eclipse.swt.widgets.Control) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Test(org.junit.Test)

Example 13 with MouseMoveListener

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

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

the class ProjectionRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    Control control = super.createControl(parentRuler, parentControl);
    // set background
    Color background = getCachedTextViewer().getTextWidget().getBackground();
    control.setBackground(background);
    // install hover listener
    control.addMouseTrackListener(new MouseTrackAdapter() {

        @Override
        public void mouseExit(MouseEvent e) {
            if (clearCurrentAnnotation())
                redraw();
        }
    });
    // install mouse move listener
    control.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            boolean redraw = false;
            ProjectionAnnotation annotation = findAnnotation(toDocumentLineNumber(e.y), false);
            if (annotation != fCurrentAnnotation) {
                if (fCurrentAnnotation != null) {
                    fCurrentAnnotation.setRangeIndication(false);
                    redraw = true;
                }
                fCurrentAnnotation = annotation;
                if (fCurrentAnnotation != null && !fCurrentAnnotation.isCollapsed()) {
                    fCurrentAnnotation.setRangeIndication(true);
                    redraw = true;
                }
            }
            if (redraw)
                redraw();
        }
    });
    return control;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Control(org.eclipse.swt.widgets.Control) MouseEvent(org.eclipse.swt.events.MouseEvent) Color(org.eclipse.swt.graphics.Color) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter)

Aggregations

MouseEvent (org.eclipse.swt.events.MouseEvent)14 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)14 PaintListener (org.eclipse.swt.events.PaintListener)8 Point (org.eclipse.swt.graphics.Point)8 PaintEvent (org.eclipse.swt.events.PaintEvent)7 MouseListener (org.eclipse.swt.events.MouseListener)6 MouseAdapter (org.eclipse.swt.events.MouseAdapter)5 KeyEvent (org.eclipse.swt.events.KeyEvent)4 MouseTrackAdapter (org.eclipse.swt.events.MouseTrackAdapter)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 Event (org.eclipse.swt.widgets.Event)4 StyledText (org.eclipse.swt.custom.StyledText)3 KeyListener (org.eclipse.swt.events.KeyListener)3 TraverseListener (org.eclipse.swt.events.TraverseListener)3 Canvas (org.eclipse.swt.widgets.Canvas)3 Listener (org.eclipse.swt.widgets.Listener)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)2