Search in sources :

Example 1 with LineBackgroundListener

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

the class Test_org_eclipse_swt_custom_LineBackgroundListener method test_lineGetBackgroundLorg_eclipse_swt_custom_LineBackgroundEvent.

@Test
public void test_lineGetBackgroundLorg_eclipse_swt_custom_LineBackgroundEvent() {
    LineBackgroundListener listener = event -> {
        assertTrue(":1:", event.lineOffset == 0);
        assertTrue(":2:", event.lineText.equals("0123456789"));
    };
    styledText.addLineBackgroundListener(listener);
    styledText.setText("0123456789");
    // force get line bg callback
    styledText.selectAll();
    styledText.copy();
    styledText.removeLineBackgroundListener(listener);
}
Also used : LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) SWT(org.eclipse.swt.SWT) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Before(org.junit.Before) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) Test(org.junit.Test)

Example 2 with LineBackgroundListener

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

the class Test_org_eclipse_swt_custom_StyledText method test_addLineBackgroundListenerLorg_eclipse_swt_custom_LineBackgroundListener.

@Test
public void test_addLineBackgroundListenerLorg_eclipse_swt_custom_LineBackgroundListener() {
    String line = "Line1";
    boolean exceptionThrown = false;
    LineBackgroundListener listener = event -> listenerCalled = true;
    try {
        text.addLineBackgroundListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
    listenerCalled = false;
    text.setText(line);
    text.addLineBackgroundListener(listener);
    // cause StyledText to call the listener.
    text.setSelection(0, text.getCharCount());
    text.copy();
    assertTrue("Listener not called", listenerCalled);
    listenerCalled = false;
    text.removeLineBackgroundListener(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) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) Test(org.junit.Test)

Aggregations

SWT (org.eclipse.swt.SWT)2 LineBackgroundListener (org.eclipse.swt.custom.LineBackgroundListener)2 StyledText (org.eclipse.swt.custom.StyledText)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BidiSegmentListener (org.eclipse.swt.custom.BidiSegmentListener)1 CaretListener (org.eclipse.swt.custom.CaretListener)1 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)1 LineStyleListener (org.eclipse.swt.custom.LineStyleListener)1 MovementEvent (org.eclipse.swt.custom.MovementEvent)1 MovementListener (org.eclipse.swt.custom.MovementListener)1 ST (org.eclipse.swt.custom.ST)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)1 TextChangeListener (org.eclipse.swt.custom.TextChangeListener)1 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1