Search in sources :

Example 1 with LineStyleListener

use of org.eclipse.swt.custom.LineStyleListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_LineStyleListener method test_lineGetStyleLorg_eclipse_swt_custom_LineStyleEvent.

@Test
public void test_lineGetStyleLorg_eclipse_swt_custom_LineStyleEvent() {
    styledText.setText("0123456789");
    LineStyleListener listener = event -> {
        assertEquals(0, event.lineOffset);
        assertEquals("0123456789", event.lineText);
    };
    styledText.addLineStyleListener(listener);
    // force get line styles callback
    styledText.getLocationAtOffset(5);
    styledText.removeLineStyleListener(listener);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) SWT(org.eclipse.swt.SWT) Test(org.junit.Test) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) Test(org.junit.Test)

Example 2 with LineStyleListener

use of org.eclipse.swt.custom.LineStyleListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText method rtfCopy.

/**
 * Regression test for bug 19985
 */
protected void rtfCopy() {
    String lines = "Line0\nLine1\nLine2\nLine3\nLine4\nLine5";
    final int[] linesCalled = new int[] { 0 };
    LineStyleListener listener = event -> {
        Display display = Display.getDefault();
        Color red = display.getSystemColor(SWT.COLOR_RED);
        StyledText styledText = (StyledText) event.widget;
        int lineIndex = styledText.getLineAtOffset(event.lineOffset);
        int lineStart = event.lineOffset;
        int lineEnd = lineStart + event.lineText.length();
        StyleRange goodRange = new StyleRange(0, 1, red, red);
        event.styles = new StyleRange[2];
        switch(lineIndex % 6) {
            case 0:
                event.styles[0] = goodRange;
                event.styles[1] = new StyleRange(lineEnd, 1, red, red);
                linesCalled[0]++;
                break;
            case 1:
                event.styles[0] = goodRange;
                event.styles[1] = new StyleRange(lineEnd, -1, red, red);
                linesCalled[0]++;
                break;
            case 2:
                event.styles[0] = goodRange;
                event.styles[1] = new StyleRange(lineEnd - 1, -1, red, red);
                linesCalled[0]++;
                break;
            case 3:
                event.styles[0] = goodRange;
                event.styles[1] = new StyleRange(lineStart, -1, red, red);
                linesCalled[0]++;
                break;
            case 4:
                event.styles[0] = new StyleRange(lineStart, 1, red, red);
                event.styles[1] = new StyleRange(lineStart, -1, red, red);
                linesCalled[0]++;
                break;
            case 5:
                event.styles[0] = new StyleRange(lineEnd / 2, 1, red, red);
                event.styles[1] = new StyleRange(lineEnd / 2, -1, red, red);
                linesCalled[0]++;
                break;
        }
    };
    text.setText(lines);
    // cause StyledText to call the listener.
    text.setSelection(0, text.getCharCount());
    text.addLineStyleListener(listener);
    linesCalled[0] = 0;
    text.copy();
    assertTrue("not all lines tested for RTF copy", linesCalled[0] == text.getLineCount());
    Clipboard clipboard = new Clipboard(text.getDisplay());
    RTFTransfer rtfTranfer = RTFTransfer.getInstance();
    String clipboardText = (String) clipboard.getContents(rtfTranfer);
    assertTrue("RTF copy failed", clipboardText.length() > 0);
    clipboard.dispose();
    text.removeLineStyleListener(listener);
}
Also used : Printer(org.eclipse.swt.printing.Printer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledTextContent(org.eclipse.swt.custom.StyledTextContent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) MovementEvent(org.eclipse.swt.custom.MovementEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Event(org.eclipse.swt.widgets.Event) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer) After(org.junit.After) RGB(org.eclipse.swt.graphics.RGB) Assert.fail(org.junit.Assert.fail) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Font(org.eclipse.swt.graphics.Font) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Before(org.junit.Before) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Assert.assertNotNull(org.junit.Assert.assertNotNull) MovementListener(org.eclipse.swt.custom.MovementListener) Assert.assertTrue(org.junit.Assert.assertTrue) StyleRange(org.eclipse.swt.custom.StyleRange) Caret(org.eclipse.swt.widgets.Caret) Test(org.junit.Test) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) CaretListener(org.eclipse.swt.custom.CaretListener) Transfer(org.eclipse.swt.dnd.Transfer) Assert.assertNull(org.junit.Assert.assertNull) Color(org.eclipse.swt.graphics.Color) BidiUtil(org.eclipse.swt.internal.BidiUtil) Assert.assertFalse(org.junit.Assert.assertFalse) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) StyledText(org.eclipse.swt.custom.StyledText) Color(org.eclipse.swt.graphics.Color) StyleRange(org.eclipse.swt.custom.StyleRange) Clipboard(org.eclipse.swt.dnd.Clipboard) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) Display(org.eclipse.swt.widgets.Display)

Example 3 with LineStyleListener

use of org.eclipse.swt.custom.LineStyleListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText method test_addLineStyleListenerLorg_eclipse_swt_custom_LineStyleListener.

@Test
public void test_addLineStyleListenerLorg_eclipse_swt_custom_LineStyleListener() {
    String line = "Line1";
    boolean exceptionThrown = false;
    LineStyleListener listener = event -> listenerCalled = true;
    try {
        text.addLineStyleListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
    listenerCalled = false;
    text.setText(line);
    text.addLineStyleListener(listener);
    // cause StyledText to call the listener.
    text.setSelection(0, text.getCharCount());
    text.copy();
    assertTrue("Listener not called", listenerCalled);
    listenerCalled = false;
    text.removeLineStyleListener(listener);
    // cause StyledText to call the listener.
    text.setText(line);
    text.setSelection(0, text.getCharCount());
    text.copy();
    assertFalse("Listener not removed", listenerCalled);
}
Also used : Printer(org.eclipse.swt.printing.Printer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledTextContent(org.eclipse.swt.custom.StyledTextContent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) MovementEvent(org.eclipse.swt.custom.MovementEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Event(org.eclipse.swt.widgets.Event) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer) After(org.junit.After) RGB(org.eclipse.swt.graphics.RGB) Assert.fail(org.junit.Assert.fail) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Font(org.eclipse.swt.graphics.Font) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Before(org.junit.Before) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Assert.assertNotNull(org.junit.Assert.assertNotNull) MovementListener(org.eclipse.swt.custom.MovementListener) Assert.assertTrue(org.junit.Assert.assertTrue) StyleRange(org.eclipse.swt.custom.StyleRange) Caret(org.eclipse.swt.widgets.Caret) Test(org.junit.Test) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) CaretListener(org.eclipse.swt.custom.CaretListener) Transfer(org.eclipse.swt.dnd.Transfer) Assert.assertNull(org.junit.Assert.assertNull) Color(org.eclipse.swt.graphics.Color) BidiUtil(org.eclipse.swt.internal.BidiUtil) Assert.assertFalse(org.junit.Assert.assertFalse) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) Test(org.junit.Test)

Aggregations

SWT (org.eclipse.swt.SWT)3 LineStyleListener (org.eclipse.swt.custom.LineStyleListener)3 StyledText (org.eclipse.swt.custom.StyledText)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BidiSegmentListener (org.eclipse.swt.custom.BidiSegmentListener)2 CaretListener (org.eclipse.swt.custom.CaretListener)2 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)2 LineBackgroundListener (org.eclipse.swt.custom.LineBackgroundListener)2 MovementEvent (org.eclipse.swt.custom.MovementEvent)2 MovementListener (org.eclipse.swt.custom.MovementListener)2 ST (org.eclipse.swt.custom.ST)2 StyleRange (org.eclipse.swt.custom.StyleRange)2 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)2 TextChangeListener (org.eclipse.swt.custom.TextChangeListener)2 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)2 Clipboard (org.eclipse.swt.dnd.Clipboard)2 RTFTransfer (org.eclipse.swt.dnd.RTFTransfer)2 TextTransfer (org.eclipse.swt.dnd.TextTransfer)2 Transfer (org.eclipse.swt.dnd.Transfer)2