Search in sources :

Example 46 with DisposeListener

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

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

the class DefaultRangeIndicator method getImage.

/**
 * Returns the image of this range indicator.
 *
 * @param control the control
 * @param rangeIndicatorColor the color to be used to paint the range indicator
 * @return an image
 */
private Image getImage(Control control, Color rangeIndicatorColor) {
    if (fImage == null) {
        fImage = createImage(control.getDisplay(), control.getSize(), rangeIndicatorColor);
        control.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (fImage != null && !fImage.isDisposed()) {
                    fImage.dispose();
                    fImage = null;
                }
            }
        });
    } else {
        Rectangle imageRectangle = fImage.getBounds();
        Point controlSize = control.getSize();
        if (imageRectangle.width < controlSize.x || imageRectangle.height < controlSize.y || !rangeIndicatorColor.equals(fLastRangeIndicatorColor)) {
            fImage.dispose();
            fImage = createImage(control.getDisplay(), controlSize, rangeIndicatorColor);
        }
    }
    return fImage;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 48 with DisposeListener

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

the class TextViewer method createControl.

/**
 * Creates the viewer's SWT control. The viewer's text widget either is
 * the control or is a child of the control.
 *
 * @param parent the parent of the viewer's control
 * @param styles the SWT style bits for the viewer's control
 */
protected void createControl(Composite parent, int styles) {
    fTextWidget = createTextWidget(parent, styles);
    // Support scroll page upon MOD1+MouseWheel
    fTextWidget.addListener(SWT.MouseVerticalWheel, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (((event.stateMask & SWT.MOD1) == 0))
                return;
            int topIndex = fTextWidget.getTopIndex();
            int bottomIndex = JFaceTextUtil.getBottomIndex(fTextWidget);
            if (event.count > 0)
                fTextWidget.setTopIndex(2 * topIndex - bottomIndex);
            else
                fTextWidget.setTopIndex(bottomIndex);
            updateViewportListeners(INTERNAL);
        }
    });
    fTextWidget.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            fDisposedControl = getControl();
            handleDispose();
        }
    });
    fTextWidget.setFont(parent.getFont());
    fTextWidget.setDoubleClickEnabled(true);
    /*
		 * Disable SWT Shift+TAB traversal in this viewer
		 * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
		 */
    fTextWidget.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
                e.doit = !fTextWidget.getEditable();
        }
    });
    // where does the first line start
    fTopInset = -fTextWidget.computeTrim(0, 0, 0, 0).y;
    fVerifyListener.forward(true);
    fTextWidget.addVerifyListener(fVerifyListener);
    fTextWidget.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            selectionChanged(event.x, event.y - event.x);
        }

        @Override
        public void widgetSelected(SelectionEvent event) {
            selectionChanged(event.x, event.y - event.x);
        }
    });
    fCursorListener = new CursorListener();
    fCursorListener.install();
    initializeViewportUpdate();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) MouseListener(org.eclipse.swt.events.MouseListener) SelectionListener(org.eclipse.swt.events.SelectionListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) MovementListener(org.eclipse.swt.custom.MovementListener) KeyListener(org.eclipse.swt.events.KeyListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MovementEvent(org.eclipse.swt.custom.MovementEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) LineBackgroundEvent(org.eclipse.swt.custom.LineBackgroundEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 49 with DisposeListener

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

the class RevisionPainter method connectIfNeeded.

/**
 * Ensures that the column is fully instantiated, i.e. has a control, and that the viewer is
 * visible.
 */
private void connectIfNeeded() {
    if (isConnected() || fParentRuler == null)
        return;
    fViewer = fParentRuler.getTextViewer();
    if (fViewer == null)
        return;
    fWidget = fViewer.getTextWidget();
    if (fWidget == null)
        return;
    fControl = fColumn.getControl();
    if (fControl == null)
        return;
    fControl.addMouseTrackListener(fMouseHandler);
    fControl.addMouseMoveListener(fMouseHandler);
    fControl.addListener(SWT.MouseUp, fMouseHandler);
    fControl.addListener(SWT.MouseDown, fMouseHandler);
    fControl.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
        }
    });
    fRevisionSelectionProvider.install(fViewer);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 50 with DisposeListener

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

the class DiffPainter method connectIfNeeded.

/**
 * Ensures that the column is fully instantiated, i.e. has a control, and that the viewer is
 * visible.
 */
private void connectIfNeeded() {
    if (isConnected() || fParentRuler == null)
        return;
    fViewer = fParentRuler.getTextViewer();
    if (fViewer == null)
        return;
    fWidget = fViewer.getTextWidget();
    if (fWidget == null)
        return;
    fControl = fColumn.getControl();
    if (fControl == null)
        return;
    fControl.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

DisposeListener (org.eclipse.swt.events.DisposeListener)118 DisposeEvent (org.eclipse.swt.events.DisposeEvent)117 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 GridData (org.eclipse.swt.layout.GridData)38 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)33 Image (org.eclipse.swt.graphics.Image)29 Cursor (org.eclipse.swt.graphics.Cursor)26 ToolBar (org.eclipse.swt.widgets.ToolBar)25 ToolItem (org.eclipse.swt.widgets.ToolItem)23 Composite (org.eclipse.swt.widgets.Composite)19 Color (org.eclipse.swt.graphics.Color)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Point (org.eclipse.swt.graphics.Point)16 ControlEvent (org.eclipse.swt.events.ControlEvent)11 SelectionListener (org.eclipse.swt.events.SelectionListener)10 Control (org.eclipse.swt.widgets.Control)10 TextLayout (org.eclipse.swt.graphics.TextLayout)9 Listener (org.eclipse.swt.widgets.Listener)9 ControlListener (org.eclipse.swt.events.ControlListener)8 MouseEvent (org.eclipse.swt.events.MouseEvent)8