Changeset 4578 in josm


Ignore:
Timestamp:
2011-11-05T23:28:16+01:00 (8 years ago)
Author:
Don-vip
Message:

see #5805 - Java Desktop API Fallback on unsupported-but-said-supported platforms such as KDE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java

    r3524 r4578  
    88import java.net.MalformedURLException;
    99import java.net.URI;
    10 import java.net.URL;
    1110
    1211import javax.swing.JApplet;
     
    2322public class OpenBrowser {
    2423
     24    private static void displayUrlFallback(URI uri) throws IOException {
     25        if (Main.platform == null)
     26            throw new IllegalStateException(tr("Failed to open URL. There is currently no platform set. Please set a platform first."));
     27        Main.platform.openUrl(uri.toString());
     28    }
     29   
    2530    /**
    2631     * @return <code>null</code> for success or a string in case of an error.
     
    4146        if (Desktop.isDesktopSupported()) {
    4247            try {
    43                 Desktop.getDesktop().browse(uri);
     48                try {
     49                    Desktop.getDesktop().browse(uri);
     50                } catch (IOException e) {
     51                    // Workaround for KDE (Desktop API is severely flawed)
     52                    // see http://bugs.sun.com/view_bug.do?bug_id=6486393
     53                    System.err.println("Warning: Desktop class failed. Platform dependent fall back for open url in browser.");
     54                    displayUrlFallback(uri);
     55                }
    4456            } catch (Exception e) {
    4557                e.printStackTrace();
     
    4759            }
    4860        } else {
    49             System.err.println("Warning: Desktop class is not supported. Platform dependent fall back for open url in browser.");
    50 
    51             if (Main.platform == null)
    52                 throw new IllegalStateException(tr("Failed to open URL. There is currently no platform set. Please set a platform first."));
    5361            try {
    54                 Main.platform.openUrl(uri.toString());
     62                System.err.println("Warning: Desktop class is not supported. Platform dependent fall back for open url in browser.");
     63                displayUrlFallback(uri);
    5564            } catch (IOException e) {
    5665                return e.getMessage();
Note: See TracChangeset for help on using the changeset viewer.