Java Code Examples for org.eclipse.swt.SWT#UNDERLINE_LINK

The following examples show how to use org.eclipse.swt.SWT#UNDERLINE_LINK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UrlFormatRule.java    From hop with Apache License 2.0 6 votes vote down vote up
public Format execute( String value ) {
  Format format = new Format();
  Matcher matcher = parse( value );
  List<StyleRange> styleRanges = new ArrayList<>();
  while ( matcher.find() ) {
    StyleRange styleRange = new StyleRange();
    styleRange.start = value.indexOf( matcher.group( 0 ) );
    styleRange.length = matcher.group( 1 ).length();
    styleRange.data = matcher.group( 2 );
    styleRange.underlineStyle = SWT.UNDERLINE_LINK;
    styleRange.underline = true;
    styleRanges.add( styleRange );
    value = value.replace( matcher.group( LINK_TEXT ), matcher.group( LINK_URL ) );
  }
  format.setStyleRanges( styleRanges );
  format.setText( value );
  return format;
}
 
Example 2
Source File: TLCUIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Creates a hyperlink style range that begins at start and ends at end.
 * Sets the data field of the hyperlink to location.
 * 
 * The data field can be used to jump to the location when the link
 * is opened. Use {@link TLCUIHelper#openTLCLocationHyperlink(StyledText, MouseEvent, ILaunchConfiguration)}
 * to open such links.
 * 
 * @param location
 * @param start
 * @param end
 * @return
 */
public static StyleRange getHyperlinkStyleRange(Location location, int start, int end)
{
    /*
     * To create the link, we follow the instructions
     * found here:
     * 
     * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83408
     */
    // create the style for the link
    StyleRange style = new StyleRange(start, end - start, null, null);
    style.underlineStyle = SWT.UNDERLINE_LINK;
    style.underline = true;
    // set the data field of the style range to store the location
    // this can be used for jumping to the location when
    // the hyperlink is opened
    style.data = location;
    return style;
}
 
Example 3
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addLink(IHyperlink link, int offset, int length) {
    if (testOutputText == null) {
        return;
    }
    StyleRangeWithCustomData range = new StyleRangeWithCustomData();
    range.underline = true;
    try {
        range.underlineStyle = SWT.UNDERLINE_LINK;
    } catch (Throwable e) {
        //Ignore (not available on earlier versions of eclipse)
    }

    //Set the proper color if it's available.
    TextAttribute textAttribute = ColorManager.getDefault().getHyperlinkTextAttribute();
    if (textAttribute != null) {
        range.foreground = textAttribute.getForeground();
    } else {
        range.foreground = JFaceColors.getHyperlinkText(Display.getDefault());
    }
    range.start = offset;
    range.length = length + 1;
    range.customData = link;
    testOutputText.setStyleRange(range);
}
 
Example 4
Source File: UrlFormatRule.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public Format execute( String value ) {
  Format format = new Format();
  Matcher matcher = parse( value );
  List<StyleRange> styleRanges = new ArrayList<>();
  while ( matcher.find() ) {
    StyleRange styleRange = new StyleRange();
    styleRange.start = value.indexOf( matcher.group( 0 ) );
    styleRange.length = matcher.group( 1 ).length();
    styleRange.data = matcher.group( 2 );
    styleRange.underlineStyle = SWT.UNDERLINE_LINK;
    styleRange.underline = true;
    styleRanges.add( styleRange );
    value = value.replace( matcher.group( LINK_TEXT ), matcher.group( LINK_URL ) );
  }
  format.setStyleRanges( styleRanges );
  format.setText( value );
  return format;
}
 
Example 5
Source File: AboutDialog.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
private StyleRange createLinkStyle(String fullText, String word, String link) {
	StyleRange style = new StyleRange();
	style.underline = true;
	style.underlineStyle = SWT.UNDERLINE_LINK;
	style.data = link;
	style.start = fullText.indexOf(word);
	style.length = word.length();
	return style;
}
 
Example 6
Source File: SWTFactory.java    From tlaplus with MIT License 5 votes vote down vote up
public static Link createLink(Composite parent, String text, Font font, int hspan, int fill) {
	Link l = new Link(parent, SWT.UNDERLINE_LINK);
	l.setFont(font);
	l.setText(text);
	GridData gd = new GridData(fill);
	gd.horizontalSpan = hspan;
	l.setLayoutData(gd);
	return l;
}
 
Example 7
Source File: ExecutionStatisticsDialog.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
  protected Control createCustomArea(Composite parent) {
final Composite c = new Composite(parent, SWT.BORDER);
c.setLayout(new GridLayout());
c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

//NOTE: Take care of ExecutionStatisticsCollector.md when updating!!!
final String txt = String.format("%s"
		+ "* Total number of cores and cores assigned to TLC\n"
		+ "* Heap and off-heap memory allocated to TLC\n"
		+ "* TLC's version (git commit SHA)\n"
		+ "* If breadth-first search, depth-first search or simulation mode is active\n"
		+ "* TLC's implementation for the sets of seen and unseen states\n"
		+ "* If TLC has been launched from the TLA Toolbox\n"
		+ "* Name, version, and architecture of your operating system\n"
		+ "* Vendor, version, and architecture of your Java virtual machine\n"
		+ "* The current date and time\n"
		+ "* An installation identifier which allows us to group execution statistics\n\n"
		+ "The execution statistics do not contain personal information. If you wish to revoke\n"
		+ "your consent to share execution statistics at a later point, please chose \n"
		+ "\"Never Share Execution Statistics\" below by re-opening this dialog via\n"
		+ "Help > Opt In/Out Execution Statistics accessible from the Toolbox's main menu.", prettyPrintSelection2(esc));

final StyledText st = new StyledText(c, SWT.SHADOW_NONE | SWT.WRAP);
st.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

st.setEnabled(true);
st.setEditable(false);
st.setText(txt);

final StyleRange[] ranges = new StyleRange[3];
ranges[0] = new StyleRange(txt.indexOf("(TLC) execution statistics"), "(TLC) execution statistics".length(), null, null);
ranges[0].underline = true;
ranges[0].underlineStyle = SWT.UNDERLINE_LINK;
ranges[0].data = "https://exec-stats.tlapl.us";

ranges[1] = new StyleRange(txt.indexOf("publicly available"), "publicly available".length(), null, null);
ranges[1].underline = true;
ranges[1].underlineStyle = SWT.UNDERLINE_LINK;
ranges[1].data = "https://exec-stats.tlapl.us/tlaplus.csv";
		
ranges[2] = new StyleRange(txt.indexOf("git commit SHA"), "git commit SHA".length(), null, null);
ranges[2].underline = true;
ranges[2].underlineStyle = SWT.UNDERLINE_LINK;
ranges[2].data = "https://git-scm.com/book/en/v2/Git-Internals-Git-Objects";

st.setStyleRanges(ranges);
st.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseUp(final MouseEvent event) {
              final int offset = st.getOffsetAtPoint(new Point(event.x, event.y));
              if (offset < 0 || offset >= st.getCharCount()) {
              	return;
              }
		final StyleRange style = st.getStyleRangeAtOffset(offset);
              if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK && style.data instanceof String) {
                  try {
				PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL((String) style.data));
			} catch (PartInitException | MalformedURLException notExpectedToHappen) {
				notExpectedToHappen.printStackTrace();
			}
              }
	}
});
	
      return c;
  }
 
Example 8
Source File: PyInformationPresenter.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private String handleLinks(List<PyStyleRange> lst, String str, FastStringBuffer buf, String tag,
        boolean addLinkUnderline) {
    int lastIndex = 0;

    String startTag = "<" + tag;

    String endTag = "</" + tag + ">";
    int endTagLen = endTag.length();

    while (true) {
        int start = str.indexOf(startTag, lastIndex);
        if (start == -1) {
            break;
        }
        int startTagLen = str.indexOf(">", start) - start + 1;
        int end = str.indexOf(endTag, start + startTagLen);
        if (end == -1 || end == start) {
            break;
        }
        int initialIndex = lastIndex;
        lastIndex = end + endTagLen;

        buf.append(str.substring(initialIndex, start));
        int startRange = buf.length();

        buf.append(str.substring(start + startTagLen, end));
        int endRange = buf.length();

        PyStyleRange styleRange = new PyStyleRange(startRange, endRange - startRange,
                JFaceColors.getHyperlinkText(Display.getDefault()), null, SWT.BOLD);
        styleRange.tagReplaced = str.substring(start, start + startTagLen);
        if (addLinkUnderline) {
            styleRange.underline = true;
            try {
                styleRange.underlineStyle = SWT.UNDERLINE_LINK;
            } catch (Throwable e) {
                //Ignore (not available on earlier versions of eclipse)
            }
        }
        lst.add(styleRange);
    }

    buf.append(str.substring(lastIndex, str.length()));
    String newString = buf.toString();
    return newString;
}
 
Example 9
Source File: SWTFactory.java    From tlaplus with MIT License 3 votes vote down vote up
/**
 * Creates a new link widget
 * 
 * @param parent the parent composite to add this label widget to
 * @param text the text for the label
 * @param font the font for the label
 * @param hspan the horizontal span to take up in the parent composite
 * @return the new label
 */
public static Link createLink(Composite parent, String text, Font font, int hspan) {
	Link l = new Link(parent, SWT.UNDERLINE_LINK);
	l.setFont(font);
	l.setText(text);
	GridData gd = new GridData(GridData.BEGINNING, GridData.VERTICAL_ALIGN_CENTER, true, false, hspan, 1);
	l.setLayoutData(gd);
	return l;
}