styled_text = new StyledText(comp,SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
styled_text.setWordWrap(true);
styled_text.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
if (links.size() == 0) {
return;
}
try {
int ofs = styled_text.getOffsetAtLocation(new Point(event.x, event.y));
for (int i = 0; i < links.size(); i++) {
linkInfo linkInfo = (linkInfo)links.get(i);
if (ofs >= linkInfo.ofsStart && ofs <= linkInfo.ofsEnd) {
Utils.launch(linkInfo.url);
break;
}
}
} catch (Exception e) {
}
}
});
final Cursor handCursor = new Cursor(comp.getDisplay(), SWT.CURSOR_HAND);
styled_text.addListener(SWT.MouseMove, new Listener() {
Cursor curCursor = null;
public void handleEvent(Event event) {
if (links.size() == 0) {
return;
}
boolean onLink = false;
try {
int ofs = styled_text.getOffsetAtLocation(new Point(event.x, event.y));
for (int i = 0; i < links.size(); i++) {
linkInfo linkInfo = (linkInfo)links.get(i);
if (ofs >= linkInfo.ofsStart && ofs <= linkInfo.ofsEnd) {
onLink = true;
break;
}
}
} catch (Exception e) {
}
try {
Cursor cursor = onLink ? handCursor : null;
if (curCursor != cursor) {
styled_text.setCursor(cursor);
curCursor = cursor;
}
} catch (Exception e) {
}
}
});
styled_text.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
styled_text.setCursor(null);
handCursor.dispose();
}
});