Search in sources :

Example 76 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class GotoLineTest method goToLine.

private void goToLine(int line, int expectedResult) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart part = IDE.openEditor(page, fFile);
        if (part instanceof ITextEditor) {
            ITextEditor editor = (ITextEditor) part;
            IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
            Accessor accessor = new Accessor(action, GotoLineAction.class);
            accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
            Control control = part.getAdapter(Control.class);
            if (control instanceof StyledText) {
                int caretLine = -1;
                StyledText styledText = (StyledText) control;
                int caret = styledText.getCaretOffset();
                try {
                    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                    caretLine = document.getLineOfOffset(caret);
                } catch (BadLocationException e1) {
                    fail();
                }
                assertEquals(expectedResult, caretLine);
            } else
                fail();
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 77 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class SegmentedModeTest method testShowNothing.

/*
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465684
	 */
@Test
public void testShowNothing() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        while (Display.getDefault().readAndDispatch()) {
        }
        IEditorPart part = IDE.openEditor(page, fFile);
        try {
            if (part instanceof ITextEditor) {
                ITextEditor editor = (ITextEditor) part;
                editor.showHighlightRangeOnly(true);
                editor.setHighlightRange(0, 0, true);
                Control control = part.getAdapter(Control.class);
                if (control instanceof StyledText) {
                    StyledText styledText = (StyledText) control;
                    String text = styledText.getText();
                    assertEquals("", text);
                }
            }
        } finally {
            page.saveEditor(part, false);
        }
    } catch (PartInitException e) {
        assertTrue(false);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 78 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class RetrieverAction method extractSearchTextFromWidget.

protected final String extractSearchTextFromWidget(Control control) {
    String sel = null;
    if (control instanceof Combo) {
        Combo combo = (Combo) control;
        sel = combo.getText();
        Point selection = combo.getSelection();
        sel = sel.substring(selection.x, selection.y);
    }
    if (control instanceof CCombo) {
        CCombo combo = (CCombo) control;
        sel = combo.getText();
        Point selection = combo.getSelection();
        sel = sel.substring(selection.x, selection.y);
    } else if (control instanceof Text) {
        Text text = (Text) control;
        sel = text.getSelectionText();
    } else if (control instanceof FormText) {
        FormText text = (FormText) control;
        sel = text.getSelectionText();
    } else if (control instanceof StyledText) {
        StyledText text = (StyledText) control;
        sel = text.getSelectionText();
    } else if (control instanceof Tree) {
        Tree tree = (Tree) control;
        TreeItem[] s = tree.getSelection();
        if (s.length > 0) {
            sel = s[0].getText();
        }
    } else if (control instanceof Table) {
        Table tree = (Table) control;
        TableItem[] s = tree.getSelection();
        if (s.length > 0) {
            sel = s[0].getText();
        }
    } else if (control instanceof List) {
        List list = (List) control;
        String[] s = list.getSelection();
        if (s.length > 0) {
            sel = s[0];
        }
    }
    if (sel != null) {
        sel = trimSearchString(sel);
    }
    return sel;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) TreeItem(org.eclipse.swt.widgets.TreeItem) FormText(org.eclipse.ui.forms.widgets.FormText) CCombo(org.eclipse.swt.custom.CCombo) Combo(org.eclipse.swt.widgets.Combo) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) FormText(org.eclipse.ui.forms.widgets.FormText) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) Tree(org.eclipse.swt.widgets.Tree) List(org.eclipse.swt.widgets.List)

Example 79 with StyledText

use of org.eclipse.swt.custom.StyledText 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 80 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class OverviewRuler method doPaint.

/**
 * Draws this overview ruler.
 *
 * @param gc the GC to draw into
 */
private void doPaint(GC gc) {
    Rectangle r = new Rectangle(0, 0, 0, 0);
    int yy, hh = ANNOTATION_HEIGHT;
    IDocument document = fTextViewer.getDocument();
    StyledText textWidget = fTextViewer.getTextWidget();
    ITextViewerExtension5 extension = null;
    IRegion visible = null;
    if (fTextViewer instanceof ITextViewerExtension5)
        extension = (ITextViewerExtension5) fTextViewer;
    else
        // legacy support
        visible = fTextViewer.getVisibleRegion();
    WidgetInfos infos = null;
    for (Object annotationType : fAnnotationsSortedByLayer) {
        if (skip(annotationType))
            continue;
        int[] style = new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY };
        for (int element : style) {
            boolean areColorsComputed = false;
            Color fill = null;
            Color stroke = null;
            Iterator<Annotation> e = new FilterIterator(annotationType, element, fCachedAnnotations.iterator());
            while (e.hasNext()) {
                Annotation a = e.next();
                Position p = fModel.getPosition(a);
                if (p == null)
                    continue;
                if (visible != null && !p.overlapsWith(visible.getOffset(), visible.getLength()))
                    continue;
                int annotationOffset = p.getOffset();
                int annotationLength = p.getLength();
                IRegion widgetRegion = null;
                if (visible != null) {
                    annotationOffset = Math.max(p.getOffset(), visible.getOffset());
                    int annotationEnd = Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength());
                    annotationLength = annotationEnd - annotationOffset;
                } else {
                    widgetRegion = extension.modelRange2WidgetRange(new Region(annotationOffset, annotationLength));
                    if (widgetRegion == null)
                        continue;
                }
                if (infos == null) {
                    infos = new WidgetInfos(textWidget, fCanvas);
                    r.x = INSET;
                    r.width = infos.bounds.width - (2 * INSET);
                }
                try {
                    int startOffset = visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset();
                    int startLine = textWidget.getLineAtOffset(startOffset);
                    yy = computeY(startLine, infos);
                    if (ANNOTATION_HEIGHT_SCALABLE) {
                        int numberOfLines = document.getNumberOfLines(annotationOffset, annotationLength);
                        // don't count empty trailing line
                        IRegion lastLine = document.getLineInformationOfOffset(annotationOffset + annotationLength);
                        if (lastLine.getOffset() == annotationOffset + annotationLength) {
                            numberOfLines--;
                        }
                        if (numberOfLines > 1) {
                            int yy2 = computeY(startLine + numberOfLines - 1, infos);
                            hh = Math.max(yy2 - yy, ANNOTATION_HEIGHT);
                        } else {
                            hh = ANNOTATION_HEIGHT;
                        }
                    }
                    fAnnotationHeight = hh;
                    if (!areColorsComputed) {
                        stroke = getStrokeColor(annotationType, element == FilterIterator.TEMPORARY);
                        fill = fUseSaturatedColors ? stroke : getFillColor(annotationType, element == FilterIterator.TEMPORARY);
                        areColorsComputed = true;
                    }
                    if (fill != null) {
                        gc.setBackground(fill);
                        gc.fillRectangle(INSET, yy, infos.bounds.width - (2 * INSET), hh);
                    }
                    if (stroke != null) {
                        gc.setForeground(stroke);
                        r.y = yy;
                        if (yy + hh == infos.bounds.height)
                            r.y--;
                        r.height = hh;
                        // NOTE: 0 means width is 1 but with optimized performance
                        gc.setLineWidth(0);
                        gc.drawRectangle(r);
                    }
                } catch (BadLocationException x) {
                }
            }
        }
    }
    if (DEBUG_DRAW) {
        // draw debugging guides (boundaries):
        if (infos == null)
            infos = new WidgetInfos(textWidget, fCanvas);
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_MAGENTA));
        yy = infos.thumbHeight / 2;
        gc.drawLine(0, yy, infos.bounds.x / 2, yy);
        yy = infos.bounds.height - infos.thumbHeight / 2;
        gc.drawLine(0, yy, infos.bounds.x / 2, yy);
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
        yy = 0;
        gc.drawLine(0, yy, infos.bounds.x / 2, yy);
        yy = infos.bounds.height - 1;
        gc.drawLine(0, yy, infos.bounds.x / 2, yy);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Position(org.eclipse.jface.text.Position) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20