Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Thoms2017-10-13 19:12:33 +0000
committerLakshmi Shanmugam2017-12-20 04:46:26 +0000
commit28768d0b1cc69abfdab02792b0c35db97f056b65 (patch)
treec7653ea781b5a719019b312d3c9f010625e58eb6 /examples
parent2017b24cda76ff73069db41157336099d046164f (diff)
downloadeclipse.platform.swt-28768d0b1cc69abfdab02792b0c35db97f056b65.tar.gz
eclipse.platform.swt-28768d0b1cc69abfdab02792b0c35db97f056b65.tar.xz
eclipse.platform.swt-28768d0b1cc69abfdab02792b0c35db97f056b65.zip
Bug 528746 - [performance] Added getOffsetAtPoint(Point)
The IAE thrown in getOffsetAtLocation(Point) can degrade performance when occurring too often. The new method will return -1 when no character is at the specified location, which performs better. Deprecated getOffsetAtLocation(Point) in favor to getOffsetAtPoint(Point). Change-Id: Ia6bc87d4fb5d2c00330b5efa1ed523169da360a8 Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet356.java14
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet356.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet356.java
index 2b0c225ed4..4d0517651e 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet356.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet356.java
@@ -48,16 +48,18 @@ public class Snippet356 {
// It is up to the application to determine when and how a link should be activated.
// In this snippet links are activated on mouse down when the control key is held down
if ((event.stateMask & SWT.MOD1) != 0) {
- try {
- int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
- StyleRange style1 = styledText.getStyleRangeAtOffset(offset);
+ int offset = styledText.getOffsetAtPoint(new Point (event.x, event.y));
+ if (offset != -1) {
+ StyleRange style1 = null;
+ try {
+ style1 = styledText.getStyleRangeAtOffset(offset);
+ } catch (IllegalArgumentException e) {
+ // no character under event.x, event.y
+ }
if (style1 != null && style1.underline && style1.underlineStyle == SWT.UNDERLINE_LINK) {
System.out.println("Click on a Link");
}
- } catch (IllegalArgumentException e) {
- // no character under event.x, event.y
}
-
}
});
shell.setSize (600, 400);

Back to the top