Search in sources :

Example 11 with PaintListener

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

the class OverviewRuler method createControl.

@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
    fTextViewer = textViewer;
    fHitDetectionCursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
    fHeader = new Canvas(parent, SWT.NONE);
    if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
        fHeader.addMouseTrackListener(new MouseTrackAdapter() {

            /*
				 * @see org.eclipse.swt.events.MouseTrackAdapter#mouseHover(org.eclipse.swt.events.MouseEvent)
				 * @since 3.3
				 */
            @Override
            public void mouseEnter(MouseEvent e) {
                updateHeaderToolTipText();
            }
        });
    }
    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 event) {
            handleDispose();
            fTextViewer = null;
        }
    });
    fCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            handleMouseDown(event);
        }
    });
    fCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent event) {
            handleMouseMove(event);
        }
    });
    fCanvas.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseScrolled(MouseEvent e) {
            handleMouseScrolled(e);
        }
    });
    if (fTextViewer != null) {
        fTextViewer.addTextListener(fInternalListener);
        // on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
        fTextViewer.getTextWidget().addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                if (fTextViewer == null) {
                    return;
                }
                StyledText textWidget = fTextViewer.getTextWidget();
                if (textWidget != null && textWidget.getWordWrap()) {
                    redraw();
                }
            }
        });
    }
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) StyledText(org.eclipse.swt.custom.StyledText) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) MouseTrackAdapter(org.eclipse.swt.events.MouseTrackAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 12 with PaintListener

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

the class AnnotationRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    fParentRuler = parentRuler;
    fCachedTextViewer = parentRuler.getTextViewer();
    fCachedTextWidget = fCachedTextViewer.getTextWidget();
    fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
    fCanvas = createCanvas(parentControl);
    fCanvas.addPaintListener(new PaintListener() {

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

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fCachedTextViewer = null;
            fCachedTextWidget = null;
        }
    });
    fMouseListener = new MouseListener() {

        @Override
        public void mouseUp(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                mouseClicked(lineNumber);
        }

        @Override
        public void mouseDown(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                AnnotationRulerColumn.this.mouseDown(lineNumber);
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            int lineNumber;
            if (isPropagatingMouseListener()) {
                fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
                lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
            } else
                lineNumber = fParentRuler.toDocumentLineNumber(event.y);
            if (1 == event.button)
                mouseDoubleClicked(lineNumber);
        }
    };
    fCanvas.addMouseListener(fMouseListener);
    fCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            handleMouseMove(e);
        }
    });
    fCanvas.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseScrolled(MouseEvent e) {
            handleMouseScrolled(e);
        }
    });
    if (fCachedTextViewer != null) {
        VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
        fCachedTextViewer.addTextListener(fLineListener);
        // on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
        fCachedTextWidget.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
                    redraw();
                }
            }
        });
    }
    return fCanvas;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) MouseWheelListener(org.eclipse.swt.events.MouseWheelListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 13 with PaintListener

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

the class LineNumberRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    fParentRuler = parentRuler;
    fCachedTextViewer = parentRuler.getTextViewer();
    fCachedTextWidget = fCachedTextViewer.getTextWidget();
    // on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
    fCachedTextWidget.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
                postRedraw();
            }
        }
    });
    // track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
    // to draw line number with well height.
    VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
    fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {

        @Override
        public void addMouseListener(MouseListener listener) {
            // see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
            if (listener == fMouseHandler)
                super.addMouseListener(listener);
            else {
                TypedListener typedListener = null;
                if (listener != null)
                    typedListener = new TypedListener(listener);
                addListener(SWT.MouseDoubleClick, typedListener);
            }
        }
    };
    fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
    fCanvas.setForeground(fForeground);
    fCanvas.addPaintListener(new PaintListener() {

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

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
            fCachedTextViewer = null;
            fCachedTextWidget = null;
        }
    });
    fMouseHandler = new MouseHandler();
    fCanvas.addMouseListener(fMouseHandler);
    fCanvas.addMouseMoveListener(fMouseHandler);
    fCanvas.addMouseWheelListener(fMouseHandler);
    if (fCachedTextViewer != null) {
        VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
        fCachedTextViewer.addTextListener(fInternalListener);
        if (fFont == null) {
            if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
                fFont = fCachedTextWidget.getFont();
        }
    }
    if (fFont != null)
        fCanvas.setFont(fFont);
    updateNumberOfDigits();
    computeIndentations();
    return fCanvas;
}
Also used : TypedListener(org.eclipse.swt.widgets.TypedListener) DisposeListener(org.eclipse.swt.events.DisposeListener) MouseListener(org.eclipse.swt.events.MouseListener) PaintEvent(org.eclipse.swt.events.PaintEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) ControlEvent(org.eclipse.swt.events.ControlEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 14 with PaintListener

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

the class AbstractRulerColumn method createControl.

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
    Assert.isLegal(parentControl != null);
    Assert.isLegal(parentRuler != null);
    // only call when not yet initialized!
    Assert.isLegal(fParentRuler == null);
    fParentRuler = parentRuler;
    fTextViewer = getParentRuler().getTextViewer();
    fTextViewer.addViewportListener(fInternalListener);
    fTextViewer.addTextListener(fInternalListener);
    fStyledText = fTextViewer.getTextWidget();
    fCanvas = new Canvas(parentControl, getCanvasStyle());
    fCanvas.setBackground(getDefaultBackground());
    fCanvas.setFont(getFont());
    fCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent event) {
            AbstractRulerColumn.this.paintControl(event);
        }
    });
    fCanvas.addMouseListener(fMouseHandler);
    fCanvas.addMouseMoveListener(fMouseHandler);
    return fCanvas;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas)

Example 15 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by dbeaver.

the class DBeaverSplashHandler method initVisualization.

private void initVisualization() {
    String progressRectString = null, messageRectString = null, foregroundColorString = null, versionCoordString = null, versionInfoSizeString = null, versionInfoColorString = null;
    final IProduct product = Platform.getProduct();
    if (product != null) {
        progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
        messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
        foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
        versionCoordString = product.getProperty("versionInfoCoord");
        versionInfoSizeString = product.getProperty("versionInfoSize");
        versionInfoColorString = product.getProperty("versionInfoColor");
    }
    setProgressRect(StringConverter.asRectangle(progressRectString, new Rectangle(275, 300, 280, 10)));
    setMessageRect(StringConverter.asRectangle(messageRectString, new Rectangle(275, 275, 280, 25)));
    final Point versionCoord = StringConverter.asPoint(versionCoordString, new Point(485, 215));
    final int versionInfoSize = StringConverter.asInt(versionInfoSizeString, 22);
    final RGB versionInfoRGB = StringConverter.asRGB(versionInfoColorString, new RGB(255, 255, 255));
    int foregroundColorInteger = 0xD2D7FF;
    try {
        if (foregroundColorString != null) {
            foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
        }
    } catch (Exception ex) {
    // ignore
    }
    setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
    normalFont = getContent().getFont();
    // boldFont = UIUtils.makeBoldFont(normalFont);
    FontData[] fontData = normalFont.getFontData();
    fontData[0].setStyle(fontData[0].getStyle() | SWT.BOLD);
    fontData[0].setHeight(versionInfoSize);
    boldFont = new Font(normalFont.getDevice(), fontData[0]);
    final Color versionColor = new Color(getContent().getDisplay(), versionInfoRGB);
    getContent().addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            String productVersion = "";
            if (product != null) {
                productVersion = GeneralUtils.getProductVersion().toString();
            }
            // String osVersion = Platform.getOS() + " " + Platform.getOSArch();
            if (boldFont != null) {
                e.gc.setFont(boldFont);
            }
            e.gc.setForeground(versionColor);
            e.gc.drawText(productVersion, versionCoord.x, versionCoord.y, true);
            // e.gc.drawText(osVersion, 115, 200, true);
            e.gc.setFont(normalFont);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) IProduct(org.eclipse.core.runtime.IProduct)

Aggregations

PaintListener (org.eclipse.swt.events.PaintListener)89 PaintEvent (org.eclipse.swt.events.PaintEvent)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)29 MouseEvent (org.eclipse.swt.events.MouseEvent)26 GridData (org.eclipse.swt.layout.GridData)26 Rectangle (org.eclipse.swt.graphics.Rectangle)25 Point (org.eclipse.swt.graphics.Point)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 DisposeEvent (org.eclipse.swt.events.DisposeEvent)14 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Control (org.eclipse.swt.widgets.Control)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Event (org.eclipse.swt.widgets.Event)11 GC (org.eclipse.swt.graphics.GC)10 Button (org.eclipse.swt.widgets.Button)10