com.sangupta.jerry.util.DesktopUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jerry-core Show documentation
Show all versions of jerry-core Show documentation
Common Java functionality for core functionality
/**
*
* jerry - Common Java Functionality
* Copyright (c) 2012-2015, Sandeep Gupta
*
* http://sangupta.com/projects/jerry
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.sangupta.jerry.util;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.io.IOException;
import java.net.URI;
/**
* Utility methods around the {@link Desktop} class like
* open a URL in the system browser etc.
*
* @author sangupta
*
*/
public class DesktopUtils {
/**
* Open the given URL in the system web browser.
*
* @param uri
* the {@link URI} to be opened
*
* @return true
if call to open was successfully made,
* false
otherwise. A value of true
DOES
* NOT guarantee that the {@link URI} was opened, but only that the
* call was successfully made.
*/
public static boolean openURL(URI uri) {
if(!Desktop.isDesktopSupported()) {
return false;
}
Desktop d = Desktop.getDesktop();
if(!d.isSupported(Action.BROWSE)) {
return false;
}
try {
d.browse(uri);
return true;
} catch (IOException e) {
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy