Revision: 7139
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7139&view=rev
Author:   dnaber
Date:     2012-06-01 08:33:27 +0000 (Fri, 01 Jun 2012)
Log Message:
-----------
use rule URL with more information in the GUI

Modified Paths:
--------------
    trunk/JLanguageTool/CHANGES.txt
    trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java

Modified: trunk/JLanguageTool/CHANGES.txt
===================================================================
--- trunk/JLanguageTool/CHANGES.txt     2012-06-01 04:30:21 UTC (rev 7138)
+++ trunk/JLanguageTool/CHANGES.txt     2012-06-01 08:33:27 UTC (rev 7139)
@@ -43,9 +43,10 @@
 
  -If a LanguageTool rule has an URL with more information, the
   grammar checking dialog in LibreOffice will now offer a "More..." link
-  to that URL in LibreOffice, as well as on the command line as "More info:", 
-  and as "url" attribute of the <error> element in the XML API format. 
-  This makes possible to have external documentation about rules.
+  to that URL in LibreOffice, as well as on the command line and
+  user interface as "More info:", and as "url" attribute of the <error>
+  element in the XML API format. This makes possible to have external
+  documentation about rules.
 
  -LibreOffice / OpenOffice integration: SingletonFactory now implements
   XServiceInfo (Stephan Bergmann) - Sourceforge bug #3526635

Modified: trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java 2012-06-01 
04:30:21 UTC (rev 7138)
+++ trunk/JLanguageTool/src/java/org/languagetool/gui/Main.java 2012-06-01 
08:33:27 UTC (rev 7139)
@@ -18,6 +18,7 @@
  */
 package org.languagetool.gui;
 
+import org.apache.commons.lang.StringUtils;
 import org.languagetool.JLanguageTool;
 import org.languagetool.Language;
 import org.languagetool.language.RuleFilenameException;
@@ -32,6 +33,8 @@
 import org.apache.tika.language.*;
 
 import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
 import javax.swing.filechooser.FileFilter;
 import java.awt.*;
 import java.awt.datatransfer.Clipboard;
@@ -109,6 +112,7 @@
     resultArea.setContentType("text/html");
     resultArea.setText(HTML_GREY_FONT_START + 
messages.getString("resultAreaText") + HTML_FONT_END);
     resultArea.setEditable(false);
+    resultArea.addHyperlinkListener(new MyHyperlinkListener());
     final JButton button = new 
JButton(StringTools.getLabel(messages.getString("checkText")));
     
button.setMnemonic(StringTools.getMnemonic(messages.getString("checkText")));
     button.addActionListener(this);
@@ -556,15 +560,13 @@
           .getToPos(), text);
       sb.append("<b>" + messages.getString("errorContext") + "</b> " + 
context);
       sb.append("<br>\n");
-            
-      /* too much hassle getting hyperlinks work in JTextPane
-       * especially when we want to replace it soon with sth nicer... 
-      if (match.getRule().getUrl() != null) {
-         sb.append("<a href=\"");
-         sb.append(match.getRule().getUrl().toString());
-         sb.append("\">More info...</a><br>\n");
+      if (match.getRule().getUrl() != null && Desktop.isDesktopSupported()) {
+         sb.append("<b>More info:</b> <a href=\"");
+        final String url = match.getRule().getUrl().toString();
+        sb.append(url);
+        final String shortUrl = StringUtils.abbreviate(url, 60);
+         sb.append("\">" + shortUrl +"</a><br>\n");
       }
-      */
       i++;
     }
     final long endTime = System.currentTimeMillis();
@@ -622,6 +624,20 @@
     }
   }
 
+  private class MyHyperlinkListener implements HyperlinkListener {
+    @Override
+    public void hyperlinkUpdate(HyperlinkEvent e) {
+      if (Desktop.isDesktopSupported() && e.getEventType() == 
HyperlinkEvent.EventType.ACTIVATED) {
+        final Desktop desktop = java.awt.Desktop.getDesktop();
+        try {
+          desktop.browse(e.getURL().toURI());
+        } catch (Exception ex) {
+          throw new RuntimeException("Could not open URL: " + e.getURL(), ex);
+        }
+      }
+    }
+  }
+
   private class ControlReturnTextCheckingListener implements KeyListener {
 
     @Override

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
Languagetool-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to