Skip to content

Commit

Permalink
Change links in AboutDialog to Markdown-like hyperlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
buchen committed Nov 11, 2017
1 parent 1edd03a commit 0f990bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ private Control createAboutText(Composite parent)
imageLabel.setImage(Images.LOGO_128.image());

List<StyleRange> styles = new ArrayList<>();
aboutText = addContributorHyperlinks(aboutText, styles);
aboutText = addMarkdownLikeHyperlinks(aboutText, styles);
addBoldFirstLine(aboutText, styles);
addHyperlinks(aboutText, styles);

Collections.sort(styles, (o1, o2) -> Integer.compare(o1.start, o2.start));

Expand Down Expand Up @@ -153,34 +152,36 @@ protected void buttonPressed(int buttonId)
}
}

private String addContributorHyperlinks(String aboutText, List<StyleRange> styles)
private String addMarkdownLikeHyperlinks(String aboutText, List<StyleRange> styles)
{
Pattern pattern = Pattern.compile("\\[([\\w]*)\\]"); //$NON-NLS-1$
Pattern pattern = Pattern.compile("\\[(?<text>[^\\]]*)\\]\\((?<link>[^\\)]*)\\)"); //$NON-NLS-1$
Matcher matcher = pattern.matcher(aboutText);

StringBuilder answer = new StringBuilder(aboutText.length());
int pointer = 0;
int found = 0;

while (matcher.find())
{
int start = matcher.start();
int end = matcher.end();

answer.append(aboutText.substring(pointer, start));

String text = matcher.group("text"); //$NON-NLS-1$
String link = matcher.group("link"); //$NON-NLS-1$

StyleRange styleRange = new StyleRange();
styleRange.underline = true;
styleRange.underlineStyle = SWT.UNDERLINE_LINK;
styleRange.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_BLUE);
styleRange.data = "https://github.com/" + matcher.group(1); //$NON-NLS-1$
styleRange.start = start - (2 * found);
styleRange.length = end - start - 2;
styleRange.data = link;
styleRange.start = answer.length();
styleRange.length = text.length();
styles.add(styleRange);

answer.append(aboutText.substring(pointer, start));
answer.append(aboutText.substring(start + 1, end - 1));
answer.append(text);

pointer = end;
found++;
}

if (pointer < aboutText.length())
Expand All @@ -198,26 +199,6 @@ private void addBoldFirstLine(String aboutText, List<StyleRange> ranges)
ranges.add(styleRange);
}

private void addHyperlinks(String aboutText, List<StyleRange> ranges)
{
Pattern pattern = Pattern.compile("https?://[^ \n]*"); //$NON-NLS-1$
Matcher matcher = pattern.matcher(aboutText);
while (matcher.find())
{
int start = matcher.start();
int end = matcher.end();

StyleRange styleRange = new StyleRange();
styleRange.underline = true;
styleRange.underlineStyle = SWT.UNDERLINE_LINK;
styleRange.underlineColor = Display.getDefault().getSystemColor(SWT.COLOR_DARK_BLUE);
styleRange.data = matcher.group();
styleRange.start = start;
styleRange.length = end - start;
ranges.add(styleRange);
}
}

private void openBrowser(Event event)
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

AboutText = Portfolio Performance\n\nVersion {0} ({1}, {2})\n\n(c) Copyright Andreas Buchen 2012 - 2017. All rights reserved.\n\nDeveloped by [buchen] with contributions by [simpsus], [jahzoo], [gynngr],\n [nistude], [mwhesse], [derari], [necoro], [alani1], [sebasbaumh], [juelicher],\n [wsteitz], [beluk], [hjbflyer], [ZfT2], [etzelc], [flobjective], [akoch],\n [bbrach], [tobsen987], [gubwe], [cmaoling], [es86de], [DominikHolzapfel],\n [sunnylars], [jklw], [Ragas13], and [stephanmunich].\n\nThis product includes software developed by the\n Eclipse Foundation http://eclipse.org/\n Apache Software Foundation http://apache.org/\n SWT Chart Project http://www.swtchart.org/\n Tree Map Library http://code.google.com/p/treemaplib/\n jsoup Java HTML Parser http://jsoup.org\n JSON.simple https://code.google.com/p/json-simple/\n D3.js http://d3js.org\n\nIcons taken from iconmonstr http://iconmonstr.com\n\nThis product is published under the Eclipse Public License\nhttp://www.eclipse.org/legal/epl-v10.html
AboutText = Portfolio Performance\n\nVersion {0} ({1}, {2})\n\n(c) Copyright [Andreas Buchen](https://github.com/buchen) 2012 - 2017. All rights reserved.\n\nDeveloped with contributions by [simpsus](https://github.com/simpsus), [jahzoo](https://github.com/jahzoo), [gynngr](https://github.com/gynngr),\n [nistude](https://github.com/nistude), [mwhesse](https://github.com/mwhesse), [derari](https://github.com/derari), [necoro](https://github.com/necoro), [alani1](https://github.com/alani1), [sebasbaumh](https://github.com/sebasbaumh), [juelicher](https://github.com/juelicher),\n [wsteitz](https://github.com/wsteitz), [beluk](https://github.com/beluk), [hjbflyer](https://github.com/hjbflyer), [ZfT2](https://github.com/ZfT2), [etzelc](https://github.com/etzelc), [flobjective](https://github.com/flobjective), [akoch](https://github.com/akoch),\n [bbrach](https://github.com/bbrach), [tobsen987](https://github.com/tobsen987), [gubwe](https://github.com/gubwe), [cmaoling](https://github.com/cmaoling), [es86de](https://github.com/es86de), [DominikHolzapfel](https://github.com/DominikHolzapfel),\n [sunnylars](https://github.com/sunnylars), [jklw](https://github.com/jklw), [Ragas13](https://github.com/Ragas13), and [stephanmunich](https://github.com/stephanmunich).\n\n[Portfolio Performance Forum](https://forum.portfolio-performance.info) run by [@Thomas](https://forum.portfolio-performance.info/u/thomas)\n\nThis product includes software developed by the\n [Eclipse Foundation](http://eclipse.org/)\n [Apache Software Foundation](http://apache.org/)\n [SWT Chart Project](http://www.swtchart.org/)\n [Tree Map Library](http://code.google.com/p/treemaplib/)\n [jsoup Java HTML Parser](http://jsoup.org)\n [JSON.simple](https://code.google.com/p/json-simple/)\n [D3.js](http://d3js.org)\n\nIcons taken from [iconmonstr](http://iconmonstr.com)\n\nThis product is published under the [Eclipse Public License](http://www.eclipse.org/legal/epl-v10.html)

AccountFilterRetiredAccounts = Hide inactive accounts

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

AboutText = Portfolio Performance\n\nVersion {0} ({1}, {2})\n\n(c) Copyright Andreas Buchen 2012 - 2017. All rights reserved.\n\nDeveloped by [buchen] with contributions by [simpsus], [jahzoo], [gynngr],\n [nistude], [mwhesse], [derari], [necoro], [alani1], [sebasbaumh], [juelicher],\n [wsteitz], [beluk], [hjbflyer], [ZfT2], [etzelc], [flobjective], [akoch],\n [bbrach], [tobsen987], [gubwe], [cmaoling], [es86de], [DominikHolzapfel],\n [sunnylars], [jklw], [Ragas13], and [stephanmunich].\n\nThis product includes software developed by the\n Eclipse Foundation http://eclipse.org/\n Apache Software Foundation http://apache.org/\n SWT Chart Project http://www.swtchart.org/\n Tree Map Library http://code.google.com/p/treemaplib/\n jsoup Java HTML Parser http://jsoup.org\n JSON.simple https://code.google.com/p/json-simple/\n D3.js http://d3js.org\n\nIcons taken from iconmonstr http://iconmonstr.com\n\nThis product is published under the Eclipse Public License\nhttp://www.eclipse.org/legal/epl-v10.html
AboutText = Portfolio Performance\n\nVersion {0} ({1}, {2})\n\n(c) Copyright [Andreas Buchen](https://github.com/buchen) 2012 - 2017. All rights reserved.\n\nDeveloped with contributions by [simpsus](https://github.com/simpsus), [jahzoo](https://github.com/jahzoo), [gynngr](https://github.com/gynngr),\n [nistude](https://github.com/nistude), [mwhesse](https://github.com/mwhesse), [derari](https://github.com/derari), [necoro](https://github.com/necoro), [alani1](https://github.com/alani1), [sebasbaumh](https://github.com/sebasbaumh), [juelicher](https://github.com/juelicher),\n [wsteitz](https://github.com/wsteitz), [beluk](https://github.com/beluk), [hjbflyer](https://github.com/hjbflyer), [ZfT2](https://github.com/ZfT2), [etzelc](https://github.com/etzelc), [flobjective](https://github.com/flobjective), [akoch](https://github.com/akoch),\n [bbrach](https://github.com/bbrach), [tobsen987](https://github.com/tobsen987), [gubwe](https://github.com/gubwe), [cmaoling](https://github.com/cmaoling), [es86de](https://github.com/es86de), [DominikHolzapfel](https://github.com/DominikHolzapfel),\n [sunnylars](https://github.com/sunnylars), [jklw](https://github.com/jklw), [Ragas13](https://github.com/Ragas13), and [stephanmunich](https://github.com/stephanmunich).\n\n[Portfolio Performance Forum](https://forum.portfolio-performance.info) run by [@Thomas](https://forum.portfolio-performance.info/u/thomas)\n\nThis product includes software developed by the\n [Eclipse Foundation](http://eclipse.org/)\n [Apache Software Foundation](http://apache.org/)\n [SWT Chart Project](http://www.swtchart.org/)\n [Tree Map Library](http://code.google.com/p/treemaplib/)\n [jsoup Java HTML Parser](http://jsoup.org)\n [JSON.simple](https://code.google.com/p/json-simple/)\n [D3.js](http://d3js.org)\n\nIcons taken from [iconmonstr](http://iconmonstr.com)\n\nThis product is published under the [Eclipse Public License](http://www.eclipse.org/legal/epl-v10.html)

AccountFilterRetiredAccounts = Inaktive Konten verbergen

Expand Down

0 comments on commit 0f990bd

Please sign in to comment.