java.awt.Desktop#isDesktopSupported ( )源码实例Demo

下面列出了java.awt.Desktop#isDesktopSupported ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MeteoInfo   文件: FrmAbout.java
private void jLabel_webMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_webMouseClicked
    // TODO add your handling code here:
    try {
        URI uri = new URI("http://www.meteothink.org");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }
        if (desktop != null) {
            desktop.browse(uri);
        }
    } catch (URISyntaxException ex) {
        Logger.getLogger(FrmAbout.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ioe) {
    }
}
 
源代码2 项目: aurous-app   文件: Utils.java
/**
 * Open a file using {@link Desktop} if supported, or a manual
 * platform-specific method if not.
 *
 * @param file
 *            The file to open.
 * @throws Exception
 *             if the file could not be opened.
 */
public static void openFile(final File file) throws Exception {
	final Desktop desktop = Desktop.isDesktopSupported() ? Desktop
			.getDesktop() : null;
	if ((desktop != null) && desktop.isSupported(Desktop.Action.OPEN)) {
		desktop.open(file);
	} else {
		final OperatingSystem system = Utils.getPlatform();
		switch (system) {
		case MAC:
		case WINDOWS:
			Utils.openURL(file.toURI().toURL());
			break;
		default:
			final String fileManager = Utils.findSupportedProgram(
					"file manager", Utils.FILE_MANAGERS);
			Runtime.getRuntime().exec(
					new String[] { fileManager, file.getAbsolutePath() });
			break;
		}
	}
}
 
源代码3 项目: opsu   文件: Utils.java
/**
 * Opens the file manager to the given location.
 * If the location is a file, it will be highlighted if possible.
 * @param file the file or directory
 */
public static void openInFileManager(File file) throws IOException {
	File f = file;

	// try to highlight the file (platform-specific)
	if (f.isFile()) {
		String osName = System.getProperty("os.name");
		if (osName.startsWith("Win")) {
			// windows: select in Explorer
			Runtime.getRuntime().exec("explorer.exe /select," + f.getAbsolutePath());
			return;
		} else if (osName.startsWith("Mac")) {
			// mac: reveal in Finder
			Runtime.getRuntime().exec("open -R " + f.getAbsolutePath());
			return;
		}
		f = f.getParentFile();
	}

	// open directory using Desktop API
	if (f.isDirectory()) {
		if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN))
			Desktop.getDesktop().open(f);
	}
}
 
源代码4 项目: magarena   文件: UiExceptionHandler.java
/**
 * Displays a message to user in the event an unexpected exception occurs.
 * User can open logs folder and/or Issue tracker directly from this dialog.
 */
private static void doNotifyUser() {
    try {

        // By specifying a frame the JOptionPane will be shown in the taskbar.
        // Otherwise if the dialog is hidden it is easy to forget it is still open.
        final JFrame frame = new JFrame(MText.get(_S1));
        frame.setUndecorated(true);
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);

        String prompt = MText.get(_S2);
        if (Desktop.isDesktopSupported()) {
            prompt += String.format("\n\n%s\n%s", MText.get(_S3), MText.get(_S4));
            final int action = JOptionPane.showConfirmDialog(frame, prompt, MText.get(_S1), JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null);
            if (action == JOptionPane.YES_OPTION) {
                DesktopHelper.tryOpen(MagicFileSystem.getDataPath(MagicFileSystem.DataPath.LOGS).toFile());
            }
        } else {
            JOptionPane.showMessageDialog(frame, prompt, MText.get(_S1), JOptionPane.ERROR_MESSAGE);
        }

    } catch (Exception e) {
        // do nothing - crash report has already been generated and app is about to exit anyway.
    }
}
 
源代码5 项目: Open-Lowcode   文件: DesktopServices.java
/**
 * Tries to open a web page in the desktop default browser. In its current
 * version, it will likely only work correctly on windows.
 * 
 * @param uri a valid URI / URL for the browser (e.g. https://openlowcode.com/
 *            ).
 */
public static void launchBrowser(String uri) {
	if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
		try {
			Desktop.getDesktop().browse(new URI(uri));
		} catch (Exception e) {
			logger.severe("Exception while trying to open site " + uri + " " + e.getClass().toString() + " "
					+ e.getMessage());
		}
	} else {
		logger.severe("Java Desktop services not supported on this platform");
	}
}
 
源代码6 项目: neembuu-uploader   文件: NotifyUpdate.java
/**
 * Open the homepage when the label is clicked.
 * @param evt 
 */
private void clickLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clickLabelMouseClicked
    if(!Desktop.isDesktopSupported())
        return;
    try {
        NULogger.getLogger().log(Level.INFO, "{0}: Link clicked.. Opening the homepage..", getClass().getName());
        Desktop.getDesktop().browse(new URI("http://neembuu.com/uploader/downloads.html"));
        // http://neembuuuploader.sourceforge.net/
    } catch (Exception ex) {
        NULogger.getLogger().severe(ex.toString());
    }
}
 
源代码7 项目: pcgen   文件: DesktopHandler.java
/**
 * Initialize the Mac-specific properties.
 * Create an ApplicationAdapter to listen for Help, Prefs, and Quit.
 */
public static void initialize()
{
	if (initialized)
	{
		return;
	}
	initialized = true;

	if (!Desktop.isDesktopSupported())
	{
		return;
	}

	Desktop theDesktop = Desktop.getDesktop();
	if (theDesktop.isSupported(Action.APP_ABOUT))
	{
		theDesktop.setAboutHandler(new AboutHandler());
	}
	if (theDesktop.isSupported(Action.APP_PREFERENCES))
	{
		theDesktop.setPreferencesHandler(new PreferencesHandler());
	}
	if (theDesktop.isSupported(Action.APP_QUIT_HANDLER))
	{
		theDesktop.setQuitHandler(new QuitHandler());
	}
}
 
源代码8 项目: RepoSense   文件: ReportServer.java
/**
 * Launches the default browser with {@code url}.
 */
private static void launchBrowser(String url) throws IOException {
    try {
        if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
            Desktop.getDesktop().browse(new URI(url));
            logger.info("Loading " + url + " on the default browser...");
        } else {
            logger.severe("Browser could not be launched. Please refer to the user guide to"
                    + " manually view the report");
        }
    } catch (URISyntaxException ue) {
        logger.log(Level.SEVERE, ue.getMessage(), ue);
    }
}
 
源代码9 项目: megabasterd   文件: DownloadView.java
private void open_folder_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_open_folder_buttonActionPerformed

        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File(_download.getDownload_path() + "/" + _download.getFile_name()).getParentFile());
            } catch (Exception ex) {
                LOG.log(Level.INFO, ex.getMessage());
            }
        }

    }
 
源代码10 项目: 07kit   文件: FakeAppletContext.java
@Override
public void showDocument(URL url, String target) {
    if (Desktop.isDesktopSupported()) {
        try {
            Desktop.getDesktop().browse(url.toURI());
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}
 
源代码11 项目: beast-mcmc   文件: Utils.java
public static boolean isBrowsingSupported() {
	if (!Desktop.isDesktopSupported()) {
		return false;
	}
	boolean result = false;
	Desktop desktop = java.awt.Desktop.getDesktop();
	if (desktop.isSupported(Desktop.Action.BROWSE)) {
		result = true;
	}
	return result;

}
 
源代码12 项目: collect-earth   文件: CollectEarthUtils.java
public static void openFolderInExplorer(String folder) throws IOException {
	if (Desktop.isDesktopSupported()) {
		Desktop.getDesktop().open(new File(folder));
	}else{
		if (SystemUtils.IS_OS_WINDOWS){
			new ProcessBuilder("explorer.exe", "/open," + folder).start(); //$NON-NLS-1$ //$NON-NLS-2$
		}else if (SystemUtils.IS_OS_MAC){
			new ProcessBuilder("usr/bin/open", folder).start(); //$NON-NLS-1$ //$NON-NLS-2$
		}else if ( SystemUtils.IS_OS_UNIX){
			tryUnixFileExplorers(folder);
		}
	}
}
 
源代码13 项目: oim-fx   文件: HttpUrlUtil.java
public static boolean open(String url) {
	boolean mark = true;
	try {
		java.net.URI uri = new java.net.URI(url);
		java.awt.Desktop d = java.awt.Desktop.getDesktop();
		if (Desktop.isDesktopSupported() && d.isSupported(java.awt.Desktop.Action.BROWSE)) {
			java.awt.Desktop.getDesktop().browse(uri);
		} else {
			browse(url);
		}
	} catch (Exception e) {
		mark = false;
	}
	return mark;
}
 
源代码14 项目: PolyGlot   文件: HelpHandler.java
public static void openHelpLocal() throws IOException {
    File readmeDir = IOHandler.unzipResourceToTempLocation(PGTUtil.HELP_FILE_ARCHIVE_LOCATION);
    File readmeFile = new File(readmeDir.getAbsolutePath() + File.separator + PGTUtil.HELP_FILE_NAME);

    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
        Desktop.getDesktop().browse(readmeFile.toURI());
    } else if (PGTUtil.IS_LINUX) {
        Desktop.getDesktop().open(readmeFile);
    } else {
        InfoBox.warning("Menu Warning", "Unable to open browser. Please load manually at:\n"
                + "http://draquet.github.io/PolyGlot/readme.html\n(copied to clipboard for convenience)", null);
        new ClipboardHandler().setClipboardContents("http://draquet.github.io/PolyGlot/readme.html");
    }
}
 
源代码15 项目: aurous-app   文件: Utils.java
/**
 * Open a URL using java.awt.Desktop or a couple different manual methods
 *
 * @param url
 *            The URL to open
 * @throws Exception
 *             If an error occurs attempting to open the url
 */
public static void openURL(final URL url) throws Exception {
	final Desktop desktop = Desktop.isDesktopSupported() ? Desktop
			.getDesktop() : null;
	if ((desktop != null) && desktop.isSupported(Desktop.Action.BROWSE)) {
		desktop.browse(url.toURI());
	} else {
		final OperatingSystem system = Utils.getPlatform();
		switch (system) {
		case MAC:
			Class.forName("com.apple.eio.FileManager")
					.getDeclaredMethod("openURL",
							new Class[] { String.class })
					.invoke(null, new Object[] { url.toString() });
			break;
		case WINDOWS:
			Runtime.getRuntime()
					.exec(new String[] { "rundll32",
							"url.dll,FileProtocolHandler", url.toString() });
			break;
		default:
			final String browser = Utils.findSupportedProgram("browser",
					Utils.BROWSERS);
			Runtime.getRuntime().exec(
					new String[] { browser, url.toString() });
			break;
		}
	}
}
 
源代码16 项目: jeveassets   文件: DesktopUtil.java
private static boolean isSupported(final Desktop.Action action) {
	if (Desktop.isDesktopSupported()) {
		Desktop desktop = Desktop.getDesktop();
		if (desktop.isSupported(action)) {
			return true;
		}
	}
	return false;
}
 
源代码17 项目: proxyee-down   文件: OsUtil.java
public static void openBrowse(String url) throws Exception {
  Desktop desktop = Desktop.getDesktop();
  boolean flag = Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE);
  if (flag) {
    try {
      URI uri = new URI(url);
      desktop.browse(uri);
    } catch (Exception e) {
      throw new Exception("can't open browse", e);
    }
  } else {
    throw new Exception("don't support browse");
  }
}
 
源代码18 项目: CPE552-Java   文件: LinktoURL.java
public static void main(String[] args) throws Exception {
    URI uri = new URI("http://www.nytimes.com");
    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        desktop.browse(uri);
    }
}
 
源代码19 项目: symja_android_library   文件: IOFunctions.java
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
	if (Desktop.isDesktopSupported()) {
		IAST dialogNoteBook = null;
		if (ast.isAST2() && ast.arg2().isAST(F.DialogNotebook, 2)) {
			dialogNoteBook = (IAST) ast.arg2();
		} else if (ast.isAST1() && ast.arg1().isAST(F.DialogNotebook, 2)) {
			dialogNoteBook = (IAST) ast.arg1();
		}

		IAST list;
		if (dialogNoteBook == null) {
			if (ast.isAST1()) {
				if (ast.arg1().isList()) {
					list = (IAST) ast.arg1();
				} else {
					list = F.List(ast.arg1());
				}
			} else {
				return F.NIL;
			}
		} else {
			if (dialogNoteBook.arg1().isList()) {
				list = (IAST) dialogNoteBook.arg1();
			} else {
				list = F.List(dialogNoteBook.arg1());
			}
		}

		JDialog dialog = new JDialog();
		dialog.setTitle("DialogInput");
		dialog.setSize(320, 200);
		dialog.setModal(true);
		// dialog.setLayout(new FlowLayout(FlowLayout.LEFT));
		// dialog.setLayout(new GridLayout(list.argSize(), 1));
		IExpr[] result = new IExpr[] { F.NIL };
		if (addComponents(dialog, list, dialog, engine, result)) {
			dialog.setVisible(true);
			if (result[0].isPresent()) {
				return result[0];
			}
		}
	}
	return F.NIL;
}
 
源代码20 项目: Recaf   文件: ExceptionAlert.java
private ExceptionAlert(Throwable t, String msg) {
	super(AlertType.ERROR);
	setTitle("An error occurred");
	String header = t.getMessage();
	if(header == null)
		header = "(" + translate("ui.noerrormsg") + ")";
	setHeaderText(header);
	setContentText(msg);
	// Get exception text
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);
	t.printStackTrace(pw);
	String exText = sw.toString();
	// Create expandable Exception.
	Label lbl = new Label("Exception stacktrace:");
	TextArea txt = new TextArea(exText);
	txt.setEditable(false);
	txt.setWrapText(false);
	txt.setMaxWidth(Double.MAX_VALUE);
	txt.setMaxHeight(Double.MAX_VALUE);
	Hyperlink link = new Hyperlink("[Bug report]");
	link.setOnAction(e -> {
		try {
			// Append suffix to bug report url for the issue title
			String suffix = t.getClass().getSimpleName();
			if (t.getMessage() != null)
				suffix = suffix + ": " + t.getMessage();
			suffix = URLEncoder.encode(suffix, "UTF-8");
			// Open link in default browser
			Desktop.getDesktop().browse(URI.create(BUG_REPORT_LINK + suffix));
		} catch(IOException exx) {
			error(exx, "Failed to open bug report link");
			show(exx, "Failed to open bug report link.");
		}
	});
	TextFlow prompt = new TextFlow(new Text(translate("ui.openissue")), link);
	GridPane.setVgrow(txt, Priority.ALWAYS);
	GridPane.setHgrow(txt, Priority.ALWAYS);
	GridPane grid = new GridPane();
	grid.setMaxWidth(Double.MAX_VALUE);
	grid.add(lbl, 0, 0);
	grid.add(txt, 0, 1);
	// If desktop is supported, allow click-able bug report link
	if (Desktop.isDesktopSupported())
		grid.add(prompt, 0, 2);
	getDialogPane().setExpandableContent(grid);
	getDialogPane().setExpanded(true);
	// Set icon
	Stage stage = (Stage) getDialogPane().getScene().getWindow();
	stage.getIcons().add(new Image(resource("icons/error.png")));
}