List of usage examples for java.awt Desktop isDesktopSupported
public static boolean isDesktopSupported()
From source file:de.xirp.managers.PrintManager.java
/** * Prints the given {@link java.io.File} using the * {@link java.awt.Desktop} class./*from w w w . j a va 2 s. com*/ * * @param document * The file to print. * @throws IOException * if something went wrong printing. * @see java.awt.Desktop */ public static void print(final File document) throws IOException { // TODO: remove awt print stuff, use swt. Desktop desktop; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); try { desktop.print(document); } catch (IOException e) { throw e; } } else { logClass.error(I18n.getString("PrintManager.log.printingNotSupported") + Constants.LINE_SEPARATOR); //$NON-NLS-1$ } }
From source file:com.gameminers.mav.firstrun.GoogleScreen.java
@Override public void onKeyDown(int k, char c, long nanos) { if (k == Keyboard.KEY_RETURN) { String str = tf.getText(); if (Strings.similarity(str.toLowerCase(), "yes") > 0.6) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("https://mav.gameminers.com/using-google.html")); try { Mav.ttsInterface.say( "Okay, then I'll need you to get a Google API key. I've opened a page on my website explaining how to do this."); } catch (SynthesisException e) { // TODO e.printStackTrace(); }/*from w w w. j a v a 2s . com*/ return; } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } } try { Mav.ttsInterface.say( "Okay, then I'll need you to get a Google API key. I can't open your browser, so you'll need to go to my site yourself. Near the bottom is a link titled 'Using Google'. That page explains how to get an API key."); } catch (SynthesisException e) { // TODO e.printStackTrace(); } } else if (Strings.similarity(str.toLowerCase(), "no") > 0.6) { try { Mav.ttsInterface.say( "Okay. Next, I need to learn the sound of your voice. Read the sentences I show out loud."); } catch (SynthesisException e) { // TODO e.printStackTrace(); } Mav.currentScreen = new TeachSphinxScreen(); } else if (StringUtils.isBlank(str)) { try { Mav.ttsInterface.say("Please enter Yes or No."); } catch (SynthesisException e) { // TODO e.printStackTrace(); } } else { try { Mav.ttsInterface.say("Sorry, I don't understand."); } catch (SynthesisException e) { // TODO e.printStackTrace(); } } tf.setText(""); } }
From source file:vazkii.psi.client.core.helper.SharingHelper.java
public static void uploadAndOpen(String title, String export) { String url = uploadImage(title, export); try {//from w w w .j a v a 2s .co m if (Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI(url)); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jabref.gui.worker.SendAsEMailAction.java
@Override public void run() { if (!Desktop.isDesktopSupported()) { message = Localization.lang("Error creating email"); return;/*from ww w. j a v a 2 s . c o m*/ } BasePanel panel = frame.getCurrentBasePanel(); if (panel == null) { return; } if (panel.getSelectedEntries().isEmpty()) { message = Localization.lang("This operation requires one or more entries to be selected."); return; } StringWriter sw = new StringWriter(); List<BibEntry> bes = panel.getSelectedEntries(); // write the entries using sw, which is used later to form the email content BibEntryWriter bibtexEntryWriter = new BibEntryWriter( new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), true); for (BibEntry entry : bes) { try { bibtexEntryWriter.write(entry, sw, panel.getBibDatabaseContext().getMode()); } catch (IOException e) { LOGGER.warn("Problem creating BibTeX file for mailing.", e); } } List<String> attachments = new ArrayList<>(); // open folders is needed to indirectly support email programs, which cannot handle // the unofficial "mailto:attachment" property boolean openFolders = JabRefPreferences.getInstance() .getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES); List<File> fileList = FileUtil.getListOfLinkedFiles(bes, frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectory()); for (File f : fileList) { attachments.add(f.getPath()); if (openFolders) { try { JabRefDesktop.openFolderAndSelectFile(f.getAbsolutePath()); } catch (IOException e) { LOGGER.debug("Cannot open file", e); } } } String mailTo = "?Body=".concat(sw.getBuffer().toString()); mailTo = mailTo.concat("&Subject="); mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT)); for (String path : attachments) { mailTo = mailTo.concat("&Attachment=\"").concat(path); mailTo = mailTo.concat("\""); } URI uriMailTo; try { uriMailTo = new URI("mailto", mailTo, null); } catch (URISyntaxException e1) { message = Localization.lang("Error creating email"); LOGGER.warn(message, e1); return; } Desktop desktop = Desktop.getDesktop(); try { desktop.mail(uriMailTo); } catch (IOException e) { message = Localization.lang("Error creating email"); LOGGER.warn(message, e); return; } message = String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size()); }
From source file:ca.osmcanada.osvuploadr.Utils.Helper.java
public static Boolean OpenBrowser(URI uri) { try {/*from w w w.ja v a 2 s .c o m*/ boolean supportsBrowse = true; if (!Desktop.isDesktopSupported()) { supportsBrowse = false; if (!Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { supportsBrowse = false; } } if (supportsBrowse) { Desktop.getDesktop().browse(uri); } else { EnumOS os = getOs(); if (os.isLinux()) { if (runCommand("kde-open", "%s", uri.toString())) return true; if (runCommand("gnome-open", "%s", uri.toString())) return true; if (runCommand("xdg-open", "%s", uri.toString())) return true; } if (os.isMac()) { if (runCommand("open", "%s", uri.toString())) return true; } if (os.isWindows()) { if (runCommand("explorer.exe", "%s", uri.toString())) return true; } } } catch (Exception ex) { Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex); return false; } return false; }
From source file:de.micromata.mgc.javafx.SystemService.java
public void openUrlInBrowser(String url) { Desktop desktop = null;// w w w .ja v a 2s . co m if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } else { GLog.warn(GenomeLogCategory.System, "Launching Browser not supported"); return; } if (desktop != null) { try { desktop.browse(new URI(url)); } catch (final IOException ex) { GLog.error(GenomeLogCategory.System, "Can't launch browser: " + ex.getMessage(), new LogExceptionAttribute(ex)); } catch (final URISyntaxException ex) { GLog.error(GenomeLogCategory.System, "Can't launch browser: " + ex.getMessage(), new LogExceptionAttribute(ex)); } } }
From source file:by.iharkaratkou.TestServlet.java
public static void openWebpage(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {//from w ww . j a va 2 s. c o m desktop.browse(uri); } catch (Exception e) { e.printStackTrace(); } } }
From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java
@SuppressWarnings("unchecked") public AboutDialog(OpenBSTGUI parent) { super(parent); setTitle(Lang.get("about.title")); setModalityType(ModalityType.APPLICATION_MODAL); JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER)); banner.setBackground(OpenBSTGUI.OPENBST_BLUE); JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48))); lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); banner.add(lblOpenbst, "flowx,cell 0 0,alignx center"); getContentPane().add(banner, BorderLayout.NORTH); JPanel pan = new JPanel(); pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]")); getContentPane().add(pan, BorderLayout.CENTER); JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/"); Font f = lblWebsite.getFont(); @SuppressWarnings("rawtypes") Map attrs = f.getAttributes(); attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); lblWebsite.setFont(f.deriveFont(attrs)); lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE); lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); lblWebsite.addMouseListener(new MouseAdapter() { @Override//from w ww. j a va2 s . co m public void mouseClicked(MouseEvent e) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI()); } catch (IOException | URISyntaxException e1) { OpenBST.LOG.warn("Exception when trying to open website", e1); } } } }); pan.add(lblWebsite, "cell 0 0,alignx center"); JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION)); pan.add(lblVersion, "flowy,cell 0 1"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false)); pan.add(scrollPane, "cell 0 2,grow"); JTextArea textArea = new JTextArea(); textArea.setMargin(new Insets(5, 5, 5, 5)); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11))); try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) { textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8)); } catch (IOException ex) { OpenBST.LOG.warn("Loading about information failed", ex); } textArea.setEditable(false); textArea.setCaretPosition(0); scrollPane.setViewportView(textArea); JLabel lblTranslatedBy = new JLabel(Lang.get("author")); pan.add(lblTranslatedBy, "cell 0 1"); setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400)); setLocationRelativeTo(parent); }
From source file:xtrememp.update.SoftwareUpdate.java
public static void checkForUpdates(final boolean showDialogs) { checkForUpdatesWorker = new SwingWorker<Version, Void>() { @Override//from ww w. jav a2 s. com protected Version doInBackground() throws Exception { logger.debug("checkForUpdates: started..."); long startTime = System.currentTimeMillis(); Version version = getLastVersion(new URL(updatesURL)); if (showDialogs) { // Simulate (if needed) a delay of 2 sec max to let the user cancel the task. long delayTime = System.currentTimeMillis() - startTime - 2000; if (delayTime > 0) { Thread.sleep(delayTime); } } return version; } @Override protected void done() { logger.debug("checkForUpdates: done"); if (checkForUpdatesDialog != null && checkForUpdatesDialog.isVisible()) { checkForUpdatesDialog.dispose(); } if (!isCancelled()) { try { newerVersion = get(); if (newerVersion != null && newerVersion.compareTo(currentVersion) == 1) { logger.debug("checkForUpdates: currentVersion = {}", currentVersion); logger.debug("checkForUpdates: newerVersion = {}", newerVersion); logger.debug("SoftwareUpdate::checkForUpdates: updates found"); Object[] options = { tr("Button.Cancel") }; Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { options = new Object[] { tr("Button.Download"), tr("Button.Cancel") }; } } JPanel panel = new JPanel(new BorderLayout(0, 10)); panel.add(new JLabel("<html>" + tr("Dialog.SoftwareUpdate.UpdatesFound") + " (" + newerVersion + ")</html>"), BorderLayout.CENTER); JCheckBox hideCheckBox = null; if (Settings.isAutomaticUpdatesEnabled()) { hideCheckBox = new JCheckBox( tr("Dialog.SoftwareUpdate.DisableAutomaticCheckForUpdates")); panel.add(hideCheckBox, BorderLayout.SOUTH); } int option = JOptionPane.showOptionDialog(XtremeMP.getInstance().getMainFrame(), panel, tr("Dialog.SoftwareUpdate"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (hideCheckBox != null) { Settings.setAutomaticUpdatesEnabled(!hideCheckBox.isSelected()); } if ((options.length == 2) && (option == JOptionPane.OK_OPTION)) { try { URL url = new URL(newerVersion.getDownloadURL()); desktop.browse(url.toURI()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } } else { logger.debug("checkForUpdates: no updates found"); if (showDialogs) { JOptionPane.showMessageDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate.NoUpdatesFound"), tr("Dialog.SoftwareUpdate"), JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { logger.error(ex.getMessage(), ex); if (showDialogs) { JOptionPane.showMessageDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate.ConnectionFailure"), tr("Dialog.SoftwareUpdate"), JOptionPane.INFORMATION_MESSAGE); } } } } }; checkForUpdatesWorker.execute(); }
From source file:ch.cyberduck.cli.TerminalPreferences.java
@Override protected void setFactories() { super.setFactories(); defaults.put("factory.certificatestore.class", TerminalCertificateStore.class.getName()); defaults.put("factory.logincallback.class", TerminalLoginCallback.class.getName()); defaults.put("factory.passwordcallback.class", TerminalPasswordCallback.class.getName()); defaults.put("factory.alertcallback.class", TerminalAlertCallback.class.getName()); defaults.put("factory.hostkeycallback.class", TerminalHostKeyVerifier.class.getName()); defaults.put("factory.transfererrorcallback.class", TerminalTransferErrorCallback.class.getName()); defaults.put("factory.notification.class", TerminalNotification.class.getName()); for (Transfer.Type t : Transfer.Type.values()) { defaults.put(String.format("factory.transferpromptcallback.%s.class", t.name()), TerminalTransferPrompt.class.getName()); }//w w w . j a va2 s. c o m switch (Factory.Platform.getDefault()) { case mac: break; case windows: break; case linux: if (Desktop.isDesktopSupported()) { defaults.put("factory.browserlauncher.class", DesktopBrowserLauncher.class.getName()); } else { defaults.put("factory.browserlauncher.class", TerminalBrowserLauncher.class.getName()); } defaults.put("factory.supportdirectoryfinder.class", UserHomeSupportDirectoryFinder.class.getName()); defaults.put("factory.applicationresourcesfinder.class", StaticApplicationResourcesFinder.class.getName()); defaults.put("factory.locale.class", RegexLocale.class.getName()); defaults.put("factory.applicationlauncher.class", ExecApplicationLauncher.class.getName()); defaults.put("factory.editorfactory.class", DefaultEditorFactory.class.getName()); defaults.put("factory.proxy.class", EnvironmentVariableProxyFinder.class.getName()); defaults.put("factory.symlink.class", DefaultSymlinkFeature.class.getName()); break; } defaults.put("factory.vault.class", CryptoVault.class.getName()); defaults.put("factory.securerandom.class", FastSecureRandomProvider.class.getName()); }