Example usage for java.awt Desktop isDesktopSupported

List of usage examples for java.awt Desktop isDesktopSupported

Introduction

In this page you can find the example usage for java.awt Desktop isDesktopSupported.

Prototype

public static boolean isDesktopSupported() 

Source Link

Document

Tests whether this class is supported on the current platform.

Usage

From source file:org.astrojournal.gui.AJMainGUI.java

/**
 * Visualise the astro journals./* w  ww  .j a  v  a  2 s .c  o m*/
 */
public void openJournals() {
    ArrayList<File> files = new ArrayList<File>();
    File journalByTarget = new File(config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey())
            + File.separator + config.getProperty(AJPropertyConstants.LATEX_REPORT_BY_TARGET_FILENAME.getKey())
                    .replace(".tex", ".pdf"));
    files.add(journalByTarget);
    File journalByConstellation = new File(
            config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey()) + File.separator
                    + config.getProperty(AJPropertyConstants.LATEX_REPORT_BY_CONSTELLATION_FILENAME.getKey())
                            .replace(".tex", ".pdf"));
    files.add(journalByConstellation);
    File journalByDate = new File(config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey())
            + File.separator + config.getProperty(AJPropertyConstants.LATEX_REPORT_BY_DATE_FILENAME.getKey())
                    .replace(".tex", ".pdf"));
    files.add(journalByDate);
    File journalByDateTXT = new File(config.getProperty(AJPropertyConstants.FILES_LOCATION.getKey())
            + File.separator + config.getProperty(AJPropertyConstants.TXT_REPORT_BY_DATE_FILENAME.getKey()));
    files.add(journalByDateTXT);

    for (File file : files) {
        if (file.exists()) {
            try {
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(file);
                    log.debug("Open file : " + file.getAbsolutePath());
                } else {
                    log.error("Awt Desktop is not supported!");
                }
            } catch (Exception ex) {
                log.warn(ex);
                log.debug(ex, ex);
            }
        } else {
            log.error("File is not exists!");
        }
    }
}

From source file:org.tinymediamanager.ui.TmmUIHelper.java

public static void browseUrl(String url) throws Exception {
    if (Desktop.isDesktopSupported()) {
        Desktop.getDesktop().browse(new URI(url));
    } else if (SystemUtils.IS_OS_LINUX) {
        // try all different starters
        boolean started = false;
        try {/*  w  w w.jav a2 s .  com*/
            Runtime.getRuntime().exec(new String[] { "gnome-open", url });
            started = true;
        } catch (IOException e) {
        }

        if (!started) {
            try {
                Runtime.getRuntime().exec(new String[] { "kde-open", url });
                started = true;
            } catch (IOException e) {
            }
        }

        if (!started) {
            try {
                Runtime.getRuntime().exec(new String[] { "xdg-open", url });
                started = true;
            } catch (IOException e) {
            }
        }
    } else {
        throw new UnsupportedOperationException();
    }
}

From source file:org.sikuli.script.App.java

public static boolean openLink(String url) {
    if (!Desktop.isDesktopSupported()) {
        return false;
    }//from w  w w.  j av  a 2s .c  o m
    try {
        Desktop.getDesktop().browse(new URI(url));
    } catch (Exception ex) {
        return false;
    }
    return true;
}

From source file:org.languagetool.gui.Tools.java

/**
 * Launches the default browser to display a URL.
 * //w  ww.jav  a  2  s  .  co  m
 * @param url the URL to be displayed
 * @since 4.1
 */
static void openURL(URL url) {
    if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
        try {
            Desktop.getDesktop().browse(url.toURI());
        } catch (Exception ex) {
            Tools.showError(ex);
        }
    } else if (SystemUtils.IS_OS_LINUX) {
        //handle the case where Desktop.browse() is not supported, e.g. kubuntu
        //without libgnome
        try {
            Runtime.getRuntime().exec(new String[] { "xdg-open", url.toString() });
        } catch (Exception ex) {
            Tools.showError(ex);
        }
    }
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

public static void openInSystemViewer(@Nonnull final File file) {
    final Runnable startEdit = new Runnable() {
        @Override/*from   w  w w .  j a  v a 2  s .  co m*/
        public void run() {
            boolean ok = false;
            if (Desktop.isDesktopSupported()) {
                final Desktop dsk = Desktop.getDesktop();
                if (dsk.isSupported(Desktop.Action.OPEN)) {
                    try {
                        dsk.open(file);
                        ok = true;
                    } catch (Throwable ex) {
                        LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N
                    }
                }
            }
            if (!ok) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        DialogProviderManager.getInstance().getDialogProvider()
                                .msgError("Can't open file in system viewer! See the log!");//NOI18N
                        Toolkit.getDefaultToolkit().beep();
                    }
                });
            }
        }
    };
    final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N
    thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
            LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e);
        }
    });

    thr.setDaemon(true);
    thr.start();
}

From source file:com.github.cric.app.ui.SettingPanel.java

private Component helpLabel() {

    JLabel help = new JLabel(HELP_TEXT);
    help.addMouseListener(new MouseAdapter() {

        @Override/*  w w  w .j  a v  a  2 s .  com*/
        public void mouseEntered(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

        @Override
        public void mouseExited(MouseEvent e) {

            help.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(HELP_PAGE);
                } catch (Exception ex) {
                    LOG.warn("unable to open link", ex);
                }
            }
        }
    });
    return help;
}

From source file:org.mhisoft.common.util.FileUtils.java

public static void launchAppOpenFile(String pathToFile) {
    if (Desktop.isDesktopSupported()) {
        try {/*from  w  ww. j av a2 s.c  o m*/
            File myFile = new File(pathToFile);
            Desktop.getDesktop().open(myFile);
        } catch (IOException ex) {
            // no application registered for PDFs
            ex.printStackTrace();
        }
    }
}

From source file:com.mirth.connect.client.ui.NotificationDialog.java

private void initComponents() {
    setLayout(new MigLayout("insets 12", "[]", "[fill][]"));

    notificationPanel = new JPanel();
    notificationPanel.setLayout(new MigLayout("insets 0 0 0 0, fill", "[200!][]", "[25!]0[]"));
    notificationPanel.setBackground(UIConstants.BACKGROUND_COLOR);

    archiveAll = new JLabel("Archive All");
    archiveAll.setForeground(java.awt.Color.blue);
    archiveAll.setText("<html><u>Archive All</u></html>");
    archiveAll.setToolTipText("Archive all notifications below.");
    archiveAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

    newNotificationsLabel = new JLabel();
    newNotificationsLabel.setFont(newNotificationsLabel.getFont().deriveFont(Font.BOLD));
    headerListPanel = new JPanel();
    headerListPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR);
    headerListPanel.setLayout(new MigLayout("insets 2, fill"));
    headerListPanel.setBorder(BorderFactory.createLineBorder(borderColor));

    list = new JList();
    list.setCellRenderer(new NotificationListCellRenderer());
    list.addListSelectionListener(new ListSelectionListener() {
        @Override//from  w w  w.j a v a  2  s.  c o m
        public void valueChanged(ListSelectionEvent event) {
            if (!event.getValueIsAdjusting()) {
                currentNotification = (Notification) list.getSelectedValue();
                if (currentNotification != null) {
                    notificationNameTextField.setText(currentNotification.getName());
                    contentTextPane.setText(currentNotification.getContent());
                    archiveSelected();
                }
            }
        }
    });
    listScrollPane = new JScrollPane();
    listScrollPane.setBackground(UIConstants.BACKGROUND_COLOR);
    listScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor));
    listScrollPane.setViewportView(list);
    listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    archiveLabel = new JLabel();
    archiveLabel.setForeground(java.awt.Color.blue);
    archiveLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

    notificationNameTextField = new JTextField();
    notificationNameTextField.setFont(notificationNameTextField.getFont().deriveFont(Font.BOLD));
    notificationNameTextField.setEditable(false);
    notificationNameTextField.setFocusable(false);
    notificationNameTextField.setBorder(BorderFactory.createEmptyBorder());
    notificationNameTextField.setBackground(UIConstants.HIGHLIGHTER_COLOR);
    DefaultCaret nameCaret = (DefaultCaret) notificationNameTextField.getCaret();
    nameCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    headerContentPanel = new JPanel();
    headerContentPanel.setLayout(new MigLayout("insets 2, fill"));
    headerContentPanel.setBorder(BorderFactory.createLineBorder(borderColor));
    headerContentPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR);

    contentTextPane = new JTextPane();
    contentTextPane.setContentType("text/html");
    contentTextPane.setEditable(false);
    contentTextPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) {
                try {
                    if (Desktop.isDesktopSupported()) {
                        Desktop.getDesktop().browse(evt.getURL().toURI());
                    } else {
                        BareBonesBrowserLaunch.openURL(evt.getURL().toString());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });
    DefaultCaret contentCaret = (DefaultCaret) contentTextPane.getCaret();
    contentCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    contentScrollPane = new JScrollPane();
    contentScrollPane.setViewportView(contentTextPane);
    contentScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor));

    archiveLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            int index = list.getSelectedIndex();
            if (currentNotification.isArchived()) {
                notificationModel.setArchived(false, index);
                unarchivedCount++;
            } else {
                notificationModel.setArchived(true, index);
                unarchivedCount--;
            }
            archiveSelected();
            updateUnarchivedCountLabel();
        }
    });

    archiveAll.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            for (int i = 0; i < notificationModel.getSize(); i++) {
                notificationModel.setArchived(true, i);
            }
            unarchivedCount = 0;
            archiveSelected();
            updateUnarchivedCountLabel();
        }
    });

    notificationCheckBox = new JCheckBox("Show new notifications on login");
    notificationCheckBox.setBackground(UIConstants.BACKGROUND_COLOR);

    if (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications)) {
        checkForNotificationsSetting = true;
        if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) {
            notificationCheckBox.setSelected(true);
        } else {
            notificationCheckBox.setSelected(false);
        }
    } else {
        notificationCheckBox.setSelected(false);
    }

    notificationCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (notificationCheckBox.isSelected() && !checkForNotificationsSetting) {
                alertSettingsChange();
            }
        }
    });

    closeButton = new JButton("Close");
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSave();
        }
    });

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doSave();
        }
    });
}

From source file:org.parosproxy.paros.control.Control.java

public void exit(boolean noPrompt, final File openOnExit) {
    boolean isNewState = model.getSession().isNewState();
    int rootCount = 0;
    if (!Constant.isLowMemoryOptionSet()) {
        rootCount = model.getSession().getSiteTree().getChildCount(model.getSession().getSiteTree().getRoot());
    }/*from ww w.j  a  va  2 s  .  co m*/
    boolean askOnExit = view != null
            && Model.getSingleton().getOptionsParam().getViewParam().getAskOnExitOption() > 0;
    boolean sessionUnsaved = isNewState && rootCount > 0;

    if (!noPrompt) {
        List<String> list = getExtensionLoader().getUnsavedResources();
        if (sessionUnsaved && askOnExit) {
            list.add(0, Constant.messages.getString("menu.file.exit.message.sessionResNotSaved"));
        }

        String message = null;
        String activeActions = wrapEntriesInLiTags(getExtensionLoader().getActiveActions());
        if (list.size() > 0) {
            String unsavedResources = wrapEntriesInLiTags(list);

            if (activeActions.isEmpty()) {
                message = MessageFormat.format(
                        Constant.messages.getString("menu.file.exit.message.resourcesNotSaved"),
                        unsavedResources);
            } else {
                message = MessageFormat.format(
                        Constant.messages.getString("menu.file.exit.message.resourcesNotSavedAndActiveActions"),
                        unsavedResources, activeActions);
            }
        } else if (!activeActions.isEmpty()) {
            message = MessageFormat.format(Constant.messages.getString("menu.file.exit.message.activeActions"),
                    activeActions);
        }

        if (message != null && view.showConfirmDialog(message) != JOptionPane.OK_OPTION) {
            return;
        }
    }

    if (sessionUnsaved) {
        control.discardSession();
    }

    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            // ZAP: Changed to use the option compact database.
            control.shutdown(Model.getSingleton().getOptionsParam().getDatabaseParam().isCompactDatabase());
            log.info(Constant.PROGRAM_TITLE + " terminated.");

            if (openOnExit != null && Desktop.isDesktopSupported()) {
                try {
                    log.info("Openning file " + openOnExit.getAbsolutePath());
                    Desktop.getDesktop().open(openOnExit);
                } catch (IOException e) {
                    log.error("Failed to open file " + openOnExit.getAbsolutePath(), e);
                }
            }
            System.exit(0);
        }
    });

    if (view != null) {
        WaitMessageDialog dialog = view
                .getWaitMessageDialog(Constant.messages.getString("menu.file.shuttingDown")); // ZAP: i18n
        t.start();
        dialog.setVisible(true);
    } else {
        t.start();
    }
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

private static void showURLExternal(@Nonnull final URL url) {
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(url.toURI());
            } catch (Exception x) {
                LOGGER.error("Can't browse URL in Desktop", x);
            }//from   w  w w  . j  a v  a  2  s. co  m
        } else if (SystemUtils.IS_OS_LINUX) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("xdg-open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL under Linux", e);
            }
        } else if (SystemUtils.IS_OS_MAC) {
            final Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("open " + url);
            } catch (IOException e) {
                LOGGER.error("Can't browse URL on MAC", e);
            }
        }
    }

}