本文整理汇总了Java中java.awt.Desktop.isDesktopSupported方法的典型用法代码示例。如果您正苦于以下问题:Java Desktop.isDesktopSupported方法的具体用法?Java Desktop.isDesktopSupported怎么用?Java Desktop.isDesktopSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Desktop
的用法示例。
在下文中一共展示了Desktop.isDesktopSupported方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import java.awt.Desktop; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
JTable table = (JTable) e.getSource();
Point pt = e.getPoint();
int ccol = table.columnAtPoint(pt);
int crow = table.rowAtPoint(pt);
Object value = table.getValueAt(crow, ccol);
if (value instanceof URL) {
URL url = (URL) value;
Desktop desktop = null;
try {
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
if (desktop != null) {
try {
desktop.browse(url.toURI());
} catch (Exception exc) {
// browsing failed; just don't do anything
}
}
}
}
示例2: run
import java.awt.Desktop; //导入方法依赖的package包/类
public static void run(String file){
try {
File f = new File(file);
if (f.exists())
{
if (Desktop.isDesktopSupported())
{
Desktop.getDesktop().open(f);
}
else
{
System.out.println("File does not exists!");
}
} else {
System.out.println("File does not exists!");
}
}
catch(Exception ert)
{}
}
示例3: editDESKTOP
import java.awt.Desktop; //导入方法依赖的package包/类
private static boolean editDESKTOP(File file) {
logOut("Trying to use Desktop.getDesktop().edit() with " + file);
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) {
logErr("EDIT is not supported.");
return false;
}
Desktop.getDesktop().edit(file);
return true;
} catch (Throwable t) {
logErr("Error using desktop edit.", t);
return false;
}
}
示例4: run
import java.awt.Desktop; //导入方法依赖的package包/类
public static void run(){
try {
File f = select.getSelectedFile();
if (f.exists())
{
if (Desktop.isDesktopSupported())
{
Desktop.getDesktop().open(f);
}
else
{
System.out.println("File does not exists!");
}
} else {
System.out.println("File does not exists!");
}
}
catch(Exception ert)
{}
}
示例5: openWebPage
import java.awt.Desktop; //导入方法依赖的package包/类
private void openWebPage(String webAddress)
{
try
{
if (Desktop.isDesktopSupported())
{
URI location = new URI(webAddress);
Desktop.getDesktop().browse(location);
}
else
{
String cause = "This JVM does not support Desktop. Try updating Java to the latest version.";
throw new Exception(cause);
}
}
catch (Exception exception)
{
String recoveryMessage = "There was a problem opening the following webpage:"
+ "\n" + webAddress;
Dialogues.showAlertDialogue(exception, recoveryMessage);
}
}
示例6: jMenuHelpGuide_actionPerformed
import java.awt.Desktop; //导入方法依赖的package包/类
protected void jMenuHelpGuide_actionPerformed(ActionEvent e) throws IOException, URISyntaxException {
//Util.runBrowser(App.GUIDE_URL);
if(Desktop.isDesktopSupported())
{
Desktop.getDesktop().browse(new URI(App.GUIDE_URL));
}
}
示例7: browse
import java.awt.Desktop; //导入方法依赖的package包/类
/**
* On systems where Desktop.getDesktop().browse() does not work for http://, creates an HTML
* page which redirects to the given URI and calls Desktop.browse() with this file through the
* file:// url which seems to work better, at least for KDE.
*/
public static void browse(URI uri) throws IOException {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(uri);
} catch (IOException e) {
File tempFile = File.createTempFile("rmredirect", ".html");
tempFile.deleteOnExit();
FileWriter out = new FileWriter(tempFile);
try {
out.write(String.format(
"<!DOCTYPE html>\n"
+ "<html><meta http-equiv=\"refresh\" content=\"0; URL=%s\"><body>You are redirected to %s</body></html>",
uri.toString(), uri.toString()));
} finally {
out.close();
}
Desktop.getDesktop().browse(tempFile.toURI());
} catch (UnsupportedOperationException e1) {
throw new IOException(e1);
}
} else {
LOGGER.log(Level.SEVERE, "Failed to open web page in browser, browsing is not supported on this platform.");
SwingTools.showVerySimpleErrorMessage("url_handler.unsupported", uri.toString());
}
}
示例8: openWebPage
import java.awt.Desktop; //导入方法依赖的package包/类
/**
* Apre la pagina web indicata dal parametro uri nel browser predefinito
* @param uri pagina web da aprire.
* @throws Exception se l'uri non è valido.
*/
private static void openWebPage(URI uri)
throws Exception {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri);
}
}
示例9: handleEvent
import java.awt.Desktop; //导入方法依赖的package包/类
@Override public void handleEvent(Event event) {
HTMLAnchorElement anchorElement = (HTMLAnchorElement) event.getCurrentTarget();
String href = anchorElement.getHref();
if (Desktop.isDesktopSupported()) {
openLinkInSystemBrowser(href);
} else {
LOGGER.warning("OS does not support desktop operations like browsing. Cannot open link '{" + href + "}'.");
}
event.preventDefault();
}
示例10: showInBrowser
import java.awt.Desktop; //导入方法依赖的package包/类
private void showInBrowser(String url) {
if (!Desktop.isDesktopSupported()) {
log.warning("No Desktop support, can't show help from " + url);
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception ex) {
log.warning("Couldn't show " + url + "; caught " + ex);
}
}
示例11: openHarComapareInBrowser
import java.awt.Desktop; //导入方法依赖的package包/类
public void openHarComapareInBrowser() {
String add = server().url() + "/dashboard/harCompare/home.html";
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URL(add).toURI());
} catch (URISyntaxException | IOException ex) {
Logger.getLogger(DashBoardManager.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
示例12: openInBrowser
import java.awt.Desktop; //导入方法依赖的package包/类
@Override
public void openInBrowser(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (IOException e) {
}
}
}
示例13: runBrowser
import java.awt.Desktop; //导入方法依赖的package包/类
/**
* Calls computer's default browser to open a URL. If unable to find a default,
* or Java's awt.Desktop library is unsupported for a machine, the user will be
* asked to find their preferred browser executable in their files the first time
* they open a browswer. After finding an executable, the browser is launched.
* @param url String
*/
public static void runBrowser(String url) {
//if (!checkBrowser())
// return;
//String commandLine = MimeTypesList.getAppList().getBrowserExec()+" "+url;
//Util.debug("Run: " + commandLine);
String commandLine = "";
try {
/*DEBUG*/
//Runtime.getRuntime().exec(commandLine);
if(Desktop.isDesktopSupported()){
Desktop.getDesktop().browse(new URI(url));
}
else {
if (checkBrowser()){ //Original code just moved here
commandLine = MimeTypesList.getAppList().getBrowserExec()+" "+url;
Util.debug("Run: " + commandLine);
Runtime.getRuntime().exec(commandLine);
}
}
}
catch (Exception ex) {
new ExceptionDialog(ex, "Failed to run an external web-browser application with commandline<br><code>"
+commandLine+"</code>", "Check the application path and command line parameters " +
"(File->Preferences->Resource types).");
}
}
示例14: showInBrowser
import java.awt.Desktop; //导入方法依赖的package包/类
private void showInBrowser(String url) {
if (!Desktop.isDesktopSupported()) {
log.warning("No Desktop support, can't show help from " + url);
return;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException | URISyntaxException ex) {
log.warning("Couldn't show " + url + "; caught " + ex);
}
}
示例15: openLink
import java.awt.Desktop; //导入方法依赖的package包/类
@FXML
void openLink(ActionEvent event) {
if (Desktop.isDesktopSupported()) {
try {
Desktop d = Desktop.getDesktop();
d.browse(new URI("https://github.com/dainesch/HueSense"));
} catch (IOException | URISyntaxException ex) {
LOG.error("Error opening url", ex);
}
}
}