All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.siegmann.epublib.util.DesktopUtil Maven / Gradle / Ivy

The newest version!

package nl.siegmann.epublib.util;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Level;
import nl.siegmann.epublib.viewer.ContentPane;

public class DesktopUtil {
    
    /**
     * Open a URL in the default web browser.
     * 
     * @param url a URL to open in a web browser.
     * @return true if a browser has been launched.
     */
    public static boolean launchBrowser(URL url) throws BrowserLaunchException {
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().browse(url.toURI());
                return true;
            } catch (Exception ex) {
                throw new BrowserLaunchException("Browser could not be launched for "+url, ex);
            }
        }
        return false;
    }
    
    public static class BrowserLaunchException extends Exception {

        private BrowserLaunchException(String message, Throwable cause) {
            super(message, cause);
        }
        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy