Enhance browser support. Use java.awt.Desktop in case his desktop supports it.

This commit is contained in:
Masaki Muranaka 2012-12-01 13:36:54 +09:00 committed by Dale Schultz
parent 589ee639f4
commit 632c736db5
1 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,8 @@ package com.romraider.net;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
public class BrowserControl {
private static final Logger LOGGER = Logger.getLogger(BrowserControl.class);
@ -30,6 +32,18 @@ public class BrowserControl {
}
public static void displayURL(String url) {
try {
Class<?> display = Class.forName("java.awt.Desktop");
Object getDesktopMethod = display.getDeclaredMethod("getDesktop").invoke(null);
Method browseMethod = display.getDeclaredMethod("browse", java.net.URI.class);
browseMethod.invoke(getDesktopMethod, new URI(url));
} catch (Exception e) {
LOGGER.debug("Failed to display URL via java.awt.Desktop. Calling by OS depended method.", e);
displayURLtraditional(url);
}
}
private static void displayURLtraditional(String url) {
boolean windows = isWindowsPlatform();
String cmd = null;
try {
@ -72,4 +86,4 @@ public class BrowserControl {
private static final String WIN_FLAG = "url.dll,FileProtocolHandler";
private static final String UNIX_PATH = "netscape";
private static final String UNIX_FLAG = "-remote openURL";
}
}