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);
}
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);
}
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);
}
Aggregations