use of org.eclipse.swt.custom.BidiSegmentListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_BidiSegmentListener method testListener.
private void testListener(final String message, final int[] segments, boolean exceptionExpected) {
boolean exceptionThrown = false;
BidiSegmentListener listener = event -> {
assertEquals(message + " incorrect BidiSegmentEvent", 0, event.lineOffset);
assertEquals(message + " incorrect BidiSegmentEvent", line, event.lineText);
event.segments = segments;
listenerCalled = true;
};
listenerCalled = false;
try {
text.addBidiSegmentListener(listener);
text.getLocationAtOffset(0);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
} finally {
text.removeBidiSegmentListener(listener);
}
if (exceptionExpected) {
assertTrue(message + " expected exception not thrown", exceptionThrown);
} else {
assertFalse(message + " unexpected exception thrown", exceptionThrown);
}
if (SwtTestUtil.isBidi()) {
assertTrue(message + " listener not called", listenerCalled);
} else {
assertFalse(message + " listener called when it shouldn't be", listenerCalled);
}
}
use of org.eclipse.swt.custom.BidiSegmentListener in project egit by eclipse.
the class SpellcheckableMessageArea method configureHardWrap.
private void configureHardWrap() {
if (shouldHardWrap()) {
if (hardWrapSegmentListener == null) {
final StyledText textWidget = getTextWidget();
hardWrapSegmentListener = new BidiSegmentListener() {
@Override
public void lineGetSegments(BidiSegmentEvent e) {
if (e.widget == textWidget) {
int footerOffset = CommonUtils.getFooterOffset(textWidget.getText());
if (footerOffset >= 0 && e.lineOffset >= footerOffset) {
return;
}
}
int[] segments = calculateWrapOffsets(e.lineText, MAX_LINE_WIDTH);
if (segments != null) {
char[] segmentsChars = new char[segments.length];
Arrays.fill(segmentsChars, '\n');
e.segments = segments;
e.segmentsChars = segmentsChars;
}
}
};
textWidget.addBidiSegmentListener(hardWrapSegmentListener);
// XXX: workaround for https://bugs.eclipse.org/384886
textWidget.setText(textWidget.getText());
if (brokenBidiPlatformTextWidth != -1) {
Layout restrictedWidthLayout = new Layout() {
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
Point size = SpellcheckableMessageArea.this.getSize();
Rectangle trim = SpellcheckableMessageArea.this.computeTrim(0, 0, 0, 0);
size.x -= trim.width;
size.y -= trim.height;
if (size.x > brokenBidiPlatformTextWidth)
size.x = brokenBidiPlatformTextWidth;
return size;
}
@Override
protected void layout(Composite composite, boolean flushCache) {
Point size = computeSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache);
textWidget.setBounds(0, 0, size.x, size.y);
}
};
setLayout(restrictedWidthLayout);
}
}
} else if (hardWrapSegmentListener != null) {
StyledText textWidget = getTextWidget();
textWidget.removeBidiSegmentListener(hardWrapSegmentListener);
// XXX: workaround for https://bugs.eclipse.org/384886
textWidget.setText(textWidget.getText());
hardWrapSegmentListener = null;
if (brokenBidiPlatformTextWidth != -1)
setLayout(new FillLayout());
}
}
use of org.eclipse.swt.custom.BidiSegmentListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_BidiSegmentListener method testStyleRangeSegmenting.
private void testStyleRangeSegmenting(final int[] segments, int[] boldRanges) {
boolean exceptionThrown = false;
BidiSegmentListener listener = event -> {
assertEquals(" incorrect BidiSegmentEvent", 0, event.lineOffset);
assertEquals(" incorrect BidiSegmentEvent", line, event.lineText);
event.segments = segments;
listenerCalled = true;
};
listenerCalled = false;
try {
text.addBidiSegmentListener(listener);
text.setStyleRange(null);
for (int i = 0; i < boldRanges.length; i += 2) {
StyleRange styleRange = new StyleRange(boldRanges[i], boldRanges[i + 1], null, null, SWT.BOLD);
text.setStyleRange(styleRange);
}
text.getLocationAtOffset(0);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
} finally {
text.removeBidiSegmentListener(listener);
}
assertFalse(" unexpected exception thrown", exceptionThrown);
if (SwtTestUtil.isBidi()) {
assertTrue(" listener not called", listenerCalled);
} else {
assertFalse(" listener called when it shouldn't be", listenerCalled);
}
}
use of org.eclipse.swt.custom.BidiSegmentListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText method test_addBidiSegmentListenerLorg_eclipse_swt_custom_BidiSegmentListener.
@Test
public void test_addBidiSegmentListenerLorg_eclipse_swt_custom_BidiSegmentListener() {
String line = "Line1";
boolean exceptionThrown = false;
BidiSegmentListener listener = event -> listenerCalled = true;
try {
text.addBidiSegmentListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
listenerCalled = false;
text.setText(line);
text.addBidiSegmentListener(listener);
// cause StyledText to call the BidiSegmentListener.
text.getLocationAtOffset(0);
if (SwtTestUtil.isBidi()) {
assertTrue("Listener not called", listenerCalled);
} else {
assertFalse("Listener called when it shouldn't be", listenerCalled);
}
listenerCalled = false;
text.removeBidiSegmentListener(listener);
// cause StyledText to call the BidiSegmentListener.
text.getLocationAtOffset(0);
assertFalse("Listener not removed", listenerCalled);
}
use of org.eclipse.swt.custom.BidiSegmentListener in project egit by eclipse.
the class SpellcheckableMessageArea method computeBrokenBidiPlatformTextWidth.
private void computeBrokenBidiPlatformTextWidth(int textWidth) {
class BidiSegmentListenerTester implements BidiSegmentListener {
boolean called;
@Override
public void lineGetSegments(BidiSegmentEvent event) {
called = true;
}
}
BidiSegmentListenerTester tester = new BidiSegmentListenerTester();
StyledText textWidget = getTextWidget();
textWidget.addBidiSegmentListener(tester);
// $NON-NLS-1$
textWidget.setText(" ");
textWidget.computeSize(SWT.DEFAULT, SWT.DEFAULT);
textWidget.removeBidiSegmentListener(tester);
brokenBidiPlatformTextWidth = tester.called ? -1 : textWidth;
}
Aggregations