Search in sources :

Example 41 with StyleRange

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

the class TextPresentationTest method testMergeStyleRange6.

/**
 * Merge range at start of existing non-default range.
 */
@Test
public void testMergeStyleRange6() {
    StyleRange range = createStyleRange(47, 49, 1, -1, NORMAL);
    fTextPresentation.mergeStyleRange(range);
    StyleRange[] expectedAllRanges = new StyleRange[] { createStyleRange(0, 4, NORMAL), createStyleRange(4, 20, BOLD), createStyleRange(20, 47, NORMAL), createStyleRange(47, 49, 1, -1, BOLD), createStyleRange(49, 54, BOLD), createStyleRange(54, 96, NORMAL), createStyleRange(96, 102, BOLD), createStyleRange(102, 140, NORMAL) };
    StyleRange[] expectedNonDefaultRanges = new StyleRange[] { createStyleRange(4, 20, BOLD), createStyleRange(47, 49, 1, -1, BOLD), createStyleRange(49, 54, BOLD), createStyleRange(96, 102, BOLD) };
    checkRegions(expectedAllRanges, expectedNonDefaultRanges);
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Test(org.junit.Test)

Example 42 with StyleRange

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

the class TextPresentationTest method testMergeStyleRange4.

/**
 * Merge range within existing default range.
 */
@Test
public void testMergeStyleRange4() {
    StyleRange range = createStyleRange(22, 24, 1, -1, NORMAL);
    fTextPresentation.mergeStyleRange(range);
    StyleRange[] expectedAllRanges = new StyleRange[] { createStyleRange(0, 4, NORMAL), createStyleRange(4, 20, BOLD), createStyleRange(20, 22, NORMAL), createStyleRange(22, 24, 1, -1, NORMAL), createStyleRange(24, 47, NORMAL), createStyleRange(47, 54, BOLD), createStyleRange(54, 96, NORMAL), createStyleRange(96, 102, BOLD), createStyleRange(102, 140, NORMAL) };
    StyleRange[] expectedNonDefaultRanges = new StyleRange[] { createStyleRange(4, 20, BOLD), createStyleRange(22, 24, 1, -1, NORMAL), createStyleRange(47, 54, BOLD), createStyleRange(96, 102, BOLD) };
    checkRegions(expectedAllRanges, expectedNonDefaultRanges);
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Test(org.junit.Test)

Example 43 with StyleRange

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

the class TextPresentationTest method testClippedRegions2.

@Test
public void testClippedRegions2() {
    fTextPresentation.setResultWindow(new Region(30, 70));
    StyleRange[] expectedAllRanges = new StyleRange[] { createStyleRange(0, 17, NORMAL), createStyleRange(17, 24, BOLD), createStyleRange(24, 66, NORMAL), createStyleRange(66, 70, BOLD) };
    StyleRange[] expectedNonDefaultRanges = new StyleRange[] { createStyleRange(17, 24, BOLD), createStyleRange(66, 70, BOLD) };
    checkRegions(expectedAllRanges, expectedNonDefaultRanges);
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Region(org.eclipse.jface.text.Region) Test(org.junit.Test)

Example 44 with StyleRange

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

the class TextPresentationTest method testMergeStyleRange7.

/**
 * Merge range within existing non-default range.
 */
@Test
public void testMergeStyleRange7() {
    StyleRange range = createStyleRange(49, 51, 1, -1, NORMAL);
    fTextPresentation.mergeStyleRange(range);
    StyleRange[] expectedAllRanges = new StyleRange[] { createStyleRange(0, 4, NORMAL), createStyleRange(4, 20, BOLD), createStyleRange(20, 47, NORMAL), createStyleRange(47, 49, BOLD), createStyleRange(49, 51, 1, -1, BOLD), createStyleRange(51, 54, BOLD), createStyleRange(54, 96, NORMAL), createStyleRange(96, 102, BOLD), createStyleRange(102, 140, NORMAL) };
    StyleRange[] expectedNonDefaultRanges = new StyleRange[] { createStyleRange(4, 20, BOLD), createStyleRange(47, 49, BOLD), createStyleRange(49, 51, 1, -1, BOLD), createStyleRange(51, 54, BOLD), createStyleRange(96, 102, BOLD) };
    checkRegions(expectedAllRanges, expectedNonDefaultRanges);
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange) Test(org.junit.Test)

Example 45 with StyleRange

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

the class TextPresentation method getFirstIndexInWindow.

/**
 * Returns the index of the first range which overlaps with the
 * specified window.
 *
 * @param window the window to be used for searching
 * @return the index of the first range overlapping with the window
 */
private int getFirstIndexInWindow(IRegion window) {
    if (window != null) {
        int start = window.getOffset();
        int i = -1, j = fRanges.size();
        while (j - i > 1) {
            int k = (i + j) >> 1;
            StyleRange r = fRanges.get(k);
            if (r.start + r.length > start)
                j = k;
            else
                i = k;
        }
        return j;
    }
    return 0;
}
Also used : StyleRange(org.eclipse.swt.custom.StyleRange)

Aggregations

StyleRange (org.eclipse.swt.custom.StyleRange)145 Point (org.eclipse.swt.graphics.Point)52 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)25 Color (org.eclipse.swt.graphics.Color)22 StyledText (org.eclipse.swt.custom.StyledText)13 Font (org.eclipse.swt.graphics.Font)10 GlyphMetrics (org.eclipse.swt.graphics.GlyphMetrics)10 Matcher (java.util.regex.Matcher)9 FontData (org.eclipse.swt.graphics.FontData)8 RGB (org.eclipse.swt.graphics.RGB)8 Rectangle (org.eclipse.swt.graphics.Rectangle)7 IOException (java.io.IOException)5 TextPresentation (org.eclipse.jface.text.TextPresentation)5 Image (org.eclipse.swt.graphics.Image)5 Control (org.eclipse.swt.widgets.Control)5 Position (org.eclipse.jface.text.Position)4 TextStyle (org.eclipse.swt.graphics.TextStyle)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3