Search in sources :

Example 56 with DisposeEvent

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

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

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

Example 59 with DisposeEvent

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

the class AbstractInformationControlManager method getInformationControl.

/**
 * Returns the information control. If the information control has not been created yet,
 * it is automatically created.
 *
 * @return the information control
 */
protected IInformationControl getInformationControl() {
    if (fDisposed)
        return fInformationControl;
    IInformationControlCreator creator = null;
    if (fCustomInformationControlCreator == null) {
        creator = fInformationControlCreator;
        if (fIsCustomInformationControl && fInformationControl != null) {
            if (fInformationControl instanceof IInformationControlExtension5)
                fSizeConstraints = null;
            fInformationControl.dispose();
            fInformationControl = null;
        }
        fIsCustomInformationControl = false;
    } else {
        creator = fCustomInformationControlCreator;
        if (creator instanceof IInformationControlCreatorExtension) {
            IInformationControlCreatorExtension extension = (IInformationControlCreatorExtension) creator;
            if (fInformationControl != null && extension.canReuse(fInformationControl))
                return fInformationControl;
        }
        if (fInformationControl != null) {
            if (fInformationControl instanceof IInformationControlExtension5)
                fSizeConstraints = null;
            fInformationControl.dispose();
            fInformationControl = null;
        }
        fIsCustomInformationControl = true;
    }
    if (fInformationControl == null) {
        fInformationControl = creator.createInformationControl(fSubjectControl.getShell());
        fInformationControl.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                handleInformationControlDisposed();
            }
        });
        if (fInformationControlCloser != null)
            fInformationControlCloser.setInformationControl(fInformationControl);
    }
    return fInformationControl;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 60 with DisposeEvent

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

Aggregations

DisposeEvent (org.eclipse.swt.events.DisposeEvent)366 DisposeListener (org.eclipse.swt.events.DisposeListener)363 GridData (org.eclipse.swt.layout.GridData)103 Composite (org.eclipse.swt.widgets.Composite)91 SelectionEvent (org.eclipse.swt.events.SelectionEvent)87 GridLayout (org.eclipse.swt.layout.GridLayout)75 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)70 Image (org.eclipse.swt.graphics.Image)53 Cursor (org.eclipse.swt.graphics.Cursor)49 Label (org.eclipse.swt.widgets.Label)42 ToolBar (org.eclipse.swt.widgets.ToolBar)42 Point (org.eclipse.swt.graphics.Point)38 Control (org.eclipse.swt.widgets.Control)38 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)37 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 FillLayout (org.eclipse.swt.layout.FillLayout)35 Event (org.eclipse.swt.widgets.Event)35 Color (org.eclipse.swt.graphics.Color)34 MouseEvent (org.eclipse.swt.events.MouseEvent)32 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31