Example usage for java.awt Desktop isSupported

List of usage examples for java.awt Desktop isSupported

Introduction

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

Prototype

public boolean isSupported(Action action) 

Source Link

Document

Tests whether an action is supported on the current platform.

Usage

From source file:homenetapp.HomeNetAppGui.java

private void menuHelpOnlineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuHelpOnlineActionPerformed

    if (!java.awt.Desktop.isDesktopSupported()) {
        System.err.println("Desktop is not supported (fatal)");
        //  System.exit(1);
    }/*from   w  ww.j  a va 2s.  c o  m*/

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
        System.err.println("Desktop doesn't support the browse action (fatal)");
        // System.exit(1);
    }

    try {
        java.net.URI uri = new java.net.URI("http://homenet.me");
        desktop.browse(uri);
    } catch (Exception e) {

        System.err.println(e.getMessage());
    }
}

From source file:com.freedomotic.jfrontend.MainWindow.java

/**
 * //  www.j  a  v  a 2 s. c o  m
 */
private void openGoogleForm() {//GEN-FIRST:event_jMenuItem1ActionPerformed
    // TODO add your handling code here:
    String url = "https://goo.gl/CC65By";
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
            try {
                URI uri = new URI(url); // url is a string containing the URL
                desktop.browse(uri);
            } catch (IOException | URISyntaxException ex) {
                LOG.error(ex.getLocalizedMessage());
            }
        }
    } else {
        //open popup with link
        JOptionPane.showMessageDialog(this, i18n.msg("goto") + url);
    }
}

From source file:com.nbt.TreeFrame.java

private void createActions() {
    newAction = new NBTAction("New", "New", "New", KeyEvent.VK_N) {

        {/*from   w  ww .ja  va 2s .com*/
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            updateTreeTable(new CompoundTag(""));
        }

    };

    browseAction = new NBTAction("Browse...", "Open", "Browse...", KeyEvent.VK_O) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = createFileChooser();
            switch (fc.showOpenDialog(TreeFrame.this)) {
            case JFileChooser.APPROVE_OPTION:
                File file = fc.getSelectedFile();
                Preferences prefs = getPreferences();
                prefs.put(KEY_FILE, file.getAbsolutePath());
                doImport(file);
                break;
            }
        }

    };

    saveAction = new NBTAction("Save", "Save", "Save", KeyEvent.VK_S) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            String path = textFile.getText();
            File file = new File(path);
            if (file.canWrite()) {
                doExport(file);
            } else {
                saveAsAction.actionPerformed(e);
            }
        }

    };

    saveAsAction = new NBTAction("Save As...", "SaveAs", "Save As...", KeyEvent.VK_UNDEFINED) {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = createFileChooser();
            switch (fc.showSaveDialog(TreeFrame.this)) {
            case JFileChooser.APPROVE_OPTION:
                File file = fc.getSelectedFile();
                Preferences prefs = getPreferences();
                prefs.put(KEY_FILE, file.getAbsolutePath());
                doExport(file);
                break;
            }
        }

    };

    refreshAction = new NBTAction("Refresh", "Refresh", "Refresh", KeyEvent.VK_F5) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F5"));
        }

        public void actionPerformed(ActionEvent e) {
            String path = textFile.getText();
            File file = new File(path);
            if (file.canRead())
                doImport(file);
            else
                showErrorDialog("The file could not be read.");
        }

    };

    exitAction = new NBTAction("Exit", "Exit", KeyEvent.VK_ESCAPE) {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO: this should check to see if any changes have been made
            // before exiting
            System.exit(0);
        }

    };

    cutAction = new DefaultEditorKit.CutAction() {

        {
            String name = "Cut";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_X);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('X', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    copyAction = new DefaultEditorKit.CopyAction() {

        {
            String name = "Copy";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_C);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('C', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    pasteAction = new DefaultEditorKit.CutAction() {

        {
            String name = "Paste";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_V);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('V', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };

    deleteAction = new NBTAction("Delete", "Delete", "Delete", KeyEvent.VK_DELETE) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE"));
        }

        public void actionPerformed(ActionEvent e) {
            int row = treeTable.getSelectedRow();
            TreePath path = treeTable.getPathForRow(row);
            Object last = path.getLastPathComponent();

            if (last instanceof NBTFileBranch) {
                NBTFileBranch branch = (NBTFileBranch) last;
                File file = branch.getFile();
                String name = file.getName();
                String message = "Are you sure you want to delete " + name + "?";
                String title = "Continue?";
                int option = JOptionPane.showConfirmDialog(TreeFrame.this, message, title,
                        JOptionPane.OK_CANCEL_OPTION);
                switch (option) {
                case JOptionPane.CANCEL_OPTION:
                    return;
                }
                if (!FileUtils.deleteQuietly(file)) {
                    showErrorDialog(name + " could not be deleted.");
                    return;
                }
            }

            TreePath parentPath = path.getParentPath();
            Object parentLast = parentPath.getLastPathComponent();
            NBTTreeTableModel model = treeTable.getTreeTableModel();
            int index = model.getIndexOfChild(parentLast, last);
            if (parentLast instanceof Mutable<?>) {
                Mutable<?> mutable = (Mutable<?>) parentLast;
                if (last instanceof ByteWrapper) {
                    ByteWrapper wrapper = (ByteWrapper) last;
                    index = wrapper.getIndex();
                }
                mutable.remove(index);
            } else {
                System.err.println(last.getClass());
                return;
            }

            updateTreeTable();
            treeTable.expandPath(parentPath);
            scrollTo(parentLast);
            treeTable.setRowSelectionInterval(row, row);
        }

    };

    openAction = new NBTAction("Open...", "Open...", KeyEvent.VK_T) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('T', Event.CTRL_MASK));

            final int diamondPickaxe = 278;
            SpriteRecord record = NBTTreeTable.register.getRecord(diamondPickaxe);
            BufferedImage image = record.getImage();
            setSmallIcon(image);

            int width = 24, height = 24;
            Dimension size = new Dimension(width, height);
            Map<RenderingHints.Key, ?> hints = Thumbnail.createRenderingHints(Thumbnail.QUALITY);
            BufferedImage largeImage = Thumbnail.createThumbnail(image, size, hints);
            setLargeIcon(largeImage);
        }

        public void actionPerformed(ActionEvent e) {
            TreePath path = treeTable.getPath();
            if (path == null)
                return;

            Object last = path.getLastPathComponent();
            if (last instanceof Region) {
                Region region = (Region) last;
                createAndShowTileCanvas(new TileCanvas.TileWorld(region));
                return;
            } else if (last instanceof World) {
                World world = (World) last;
                createAndShowTileCanvas(world);
                return;
            }

            if (last instanceof NBTFileBranch) {
                NBTFileBranch fileBranch = (NBTFileBranch) last;
                File file = fileBranch.getFile();
                try {
                    open(file);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    showErrorDialog(ex.getMessage());
                }
            }
        }

        private void open(File file) throws IOException {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Desktop.Action.OPEN)) {
                    desktop.open(file);
                }
            }
        }

    };

    addByteAction = new NBTAction("Add Byte", NBTConstants.TYPE_BYTE, "Add Byte", KeyEvent.VK_1) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('1', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ByteTag("new byte", (byte) 0));
        }

    };

    addShortAction = new NBTAction("Add Short", NBTConstants.TYPE_SHORT, "Add Short", KeyEvent.VK_2) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('2', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ShortTag("new short", (short) 0));
        }

    };

    addIntAction = new NBTAction("Add Integer", NBTConstants.TYPE_INT, "Add Integer", KeyEvent.VK_3) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('3', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new IntTag("new int", 0));
        }

    };

    addLongAction = new NBTAction("Add Long", NBTConstants.TYPE_LONG, "Add Long", KeyEvent.VK_4) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('4', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new LongTag("new long", 0));
        }

    };

    addFloatAction = new NBTAction("Add Float", NBTConstants.TYPE_FLOAT, "Add Float", KeyEvent.VK_5) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('5', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new FloatTag("new float", 0));
        }

    };

    addDoubleAction = new NBTAction("Add Double", NBTConstants.TYPE_DOUBLE, "Add Double", KeyEvent.VK_6) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('6', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new DoubleTag("new double", 0));
        }

    };

    addByteArrayAction = new NBTAction("Add Byte Array", NBTConstants.TYPE_BYTE_ARRAY, "Add Byte Array",
            KeyEvent.VK_7) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('7', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ByteArrayTag("new byte array"));
        }

    };

    addStringAction = new NBTAction("Add String", NBTConstants.TYPE_STRING, "Add String", KeyEvent.VK_8) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('8', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new StringTag("new string", "..."));
        }

    };

    addListAction = new NBTAction("Add List Tag", NBTConstants.TYPE_LIST, "Add List Tag", KeyEvent.VK_9) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('9', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            Class<? extends Tag> type = queryType();
            if (type != null)
                addTag(new ListTag("new list", null, type));
        }

        private Class<? extends Tag> queryType() {
            Object[] items = { NBTConstants.TYPE_BYTE, NBTConstants.TYPE_SHORT, NBTConstants.TYPE_INT,
                    NBTConstants.TYPE_LONG, NBTConstants.TYPE_FLOAT, NBTConstants.TYPE_DOUBLE,
                    NBTConstants.TYPE_BYTE_ARRAY, NBTConstants.TYPE_STRING, NBTConstants.TYPE_LIST,
                    NBTConstants.TYPE_COMPOUND };
            JComboBox comboBox = new JComboBox(new DefaultComboBoxModel(items));
            comboBox.setRenderer(new DefaultListCellRenderer() {

                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index,
                        boolean isSelected, boolean cellHasFocus) {
                    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

                    if (value instanceof Integer) {
                        Integer i = (Integer) value;
                        Class<? extends Tag> c = NBTUtils.getTypeClass(i);
                        String name = NBTUtils.getTypeName(c);
                        setText(name);
                    }

                    return this;
                }

            });
            Object[] message = { new JLabel("Please select a type."), comboBox };
            String title = "Title goes here";
            int result = JOptionPane.showOptionDialog(TreeFrame.this, message, title,
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
            switch (result) {
            case JOptionPane.OK_OPTION:
                ComboBoxModel model = comboBox.getModel();
                Object item = model.getSelectedItem();
                if (item instanceof Integer) {
                    Integer i = (Integer) item;
                    return NBTUtils.getTypeClass(i);
                }
            }
            return null;
        }

    };

    addCompoundAction = new NBTAction("Add Compound Tag", NBTConstants.TYPE_COMPOUND, "Add Compound Tag",
            KeyEvent.VK_0) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('0', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new CompoundTag());
        }

    };

    String name = "About " + TITLE;
    helpAction = new NBTAction(name, "Help", name, KeyEvent.VK_F1) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F1"));
        }

        public void actionPerformed(ActionEvent e) {
            Object[] message = { new JLabel(TITLE + " " + VERSION),
                    new JLabel("\u00A9 Copyright Taggart Spilman 2011.  All rights reserved."),
                    new Hyperlink("<html><a href=\"#\">NamedBinaryTag.com</a></html>",
                            "http://www.namedbinarytag.com"),
                    new Hyperlink("<html><a href=\"#\">Contact</a></html>", "mailto:tagadvance@gmail.com"),
                    new JLabel(" "),
                    new Hyperlink("<html><a href=\"#\">JNBT was written by Graham Edgecombe</a></html>",
                            "http://jnbt.sf.net"),
                    new Hyperlink("<html><a href=\"#\">Available open-source under the BSD license</a></html>",
                            "http://jnbt.sourceforge.net/LICENSE.TXT"),
                    new JLabel(" "), new JLabel("This product includes software developed by"),
                    new Hyperlink("<html><a href=\"#\">The Apache Software Foundation</a>.</html>",
                            "http://www.apache.org"),
                    new JLabel(" "), new JLabel("Default texture pack:"),
                    new Hyperlink("<html><a href=\"#\">SOLID COLOUR. SOLID STYLE.</a></html>",
                            "http://www.minecraftforum.net/topic/72253-solid-colour-solid-style/"),
                    new JLabel("Bundled with the permission of Trigger_Proximity."),

            };
            String title = "About";
            JOptionPane.showMessageDialog(TreeFrame.this, message, title, JOptionPane.INFORMATION_MESSAGE);
        }

    };

}

From source file:org.yccheok.jstock.gui.Utils.java

public static void launchWebBrowser(String address) {
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            URL url = null;//from  ww w. j  a  v a  2s.com
            String string = address;
            try {
                url = new URL(string);
            } catch (MalformedURLException ex) {
                return;
            }
            try {
                desktop.browse(url.toURI());
            } catch (URISyntaxException ex) {
            } catch (IOException ex) {
            }
        }
    }
}

From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java

private void showHelpContent() {

    try {//w w w .  j a  v a  2s  . c o  m
        URI helpLink = new URI("https://github.com/bigwiv/BlastGraph/blob/master/doc/BlastGraph_Manual.md");
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            desktop.browse(helpLink);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.yccheok.jstock.gui.Utils.java

public static void launchWebBrowser(javax.swing.event.HyperlinkEvent evt) {
    if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) {
        URL url = evt.getURL();//from   w w w  . j  av a  2 s  .  com
        if (Desktop.isDesktopSupported()) {
            final Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.BROWSE)) {
                if (url == null) {
                    // www.yahoo.com considered an invalid URL. Hence, evt.getURL() returns null.
                    String string = "http://" + evt.getDescription();
                    try {
                        url = new URL(string);
                    } catch (MalformedURLException ex) {
                        return;
                    }
                }
                try {
                    desktop.browse(url.toURI());
                } catch (URISyntaxException ex) {
                } catch (IOException ex) {
                }
            }
        }
    }
}

From source file:mesquite.lib.MesquiteModule.java

public static void showWebPage(String path, boolean autoCompose, boolean removePastNumberSign) {
    if (path != null) {
        if (MesquiteTrunk.isApplet()) {
            //TODO: FILL THIS IN
        } else {/*from  www  .  j a va  2  s.c  om*/
            String pathToCheck = path;
            if (path.indexOf("#") > 0 && removePastNumberSign)
                pathToCheck = StringUtil.getAllButLastItem(path, "#");
            path = pathToCheck; //Todo: this is temporary, as the launching methods don't seem to handle within-page anchors
            String[] browserCommand = null;
            boolean remote = path.indexOf(":/") >= 0;

            boolean useDesktop = false;
            if (MesquiteTrunk.getJavaVersionAsDouble() >= 1.6) { // let's check to see if this will work first
                try {
                    if (Desktop.isDesktopSupported()) {
                        Desktop desktop = Desktop.getDesktop();
                        if (desktop.isSupported(Desktop.Action.BROWSE)) {
                            useDesktop = true;
                        }
                    }
                } catch (Exception e) {
                }
            }

            if (useDesktop) {
                Desktop d = Desktop.getDesktop();
                try {
                    URI uri = null;
                    if (path.indexOf("http:/") < 0 && path.indexOf("https:/") < 0) { // it's a local reference
                        File file = new File(path);
                        uri = file.toURI();
                    } else
                        uri = new URI(path);
                    if (!remote && !CommandChecker.documentationComposed && autoCompose) {
                        CommandChecker checker = new CommandChecker();
                        checker.composeDocumentation();
                    }
                    d.browse(uri);
                } catch (IOException e) {
                    browserString = null;
                    MesquiteTrunk.mesquiteTrunk.alert(
                            "The requested page could not be shown, because the web browser could not be used properly.  There may be a problem with insufficient memory or the location of the web page or browser.");
                } catch (URISyntaxException e) {
                    MesquiteTrunk.mesquiteTrunk.alert(
                            "The requested page could not be shown, because the address was not interpretable.");
                }
            } else if (MesquiteTrunk.isMacOSX()) { //Mac OS X
                if (remote) { //remote OSX file, use browser laucher
                    try {
                        BrowserLauncher.openURL(path);
                    } catch (IOException e) {
                        browserString = null;
                        MesquiteTrunk.mesquiteTrunk.alert(
                                "The requested page could not be shown, because the web browser could not be used properly.  There may be a problem with insufficient memory or the location of the web page or browser.");
                    }
                    return;
                } else {
                    if (!remote && !CommandChecker.documentationComposed && autoCompose) {
                        CommandChecker checker = new CommandChecker();
                        checker.composeDocumentation();
                    }
                    File testing = new File(pathToCheck);
                    if (!testing.exists()) {
                        MesquiteTrunk.mesquiteTrunk.alert(
                                "The requested page could not be shown, because the file could not be found. ("
                                        + pathToCheck + ")");
                        return;
                    }
                    if (!CommandChecker.documentationComposed && autoCompose) {
                        CommandChecker checker = new CommandChecker();
                        checker.composeDocumentation();
                    }
                    browserString = "open";
                    String brs = "Safari.app";
                    File br = new File("/Applications/Safari.app");
                    if (!br.exists())
                        brs = "Firefox.app";
                    if (!br.exists())
                        brs = "Internet Explorer.app";

                    String[] b = { browserString, "-a", brs, path };

                    browserCommand = b;
                    try {
                        //String[] browserCommand = {browserString, arg1, arg2, arg3};
                        //if (MesquiteTrunk.isMacOSXLeopard())  //bug in 10.5 occasionally prevented Safari from starting
                        //   Runtime.getRuntime().exec(new String[]{browserString, "-a", brs});
                        Runtime.getRuntime().exec(browserCommand);
                    } catch (IOException e) {
                        browserString = null;
                        MesquiteTrunk.mesquiteTrunk.alert(
                                "The requested page could not be shown, because the web browser could not be used properly.  There may be a problem with insufficient memory or the location of the web page or browser.");
                    }
                }
            } else {

                try {
                    BrowserLauncher.openURL(path);
                    return;
                } catch (IOException e) {
                }
                if (!remote) {//local file
                    File testing = new File(pathToCheck);
                    if (!testing.exists()) {
                        MesquiteTrunk.mesquiteTrunk.alert(
                                "The requested page could not be shown, because the file could not be found.");
                        return;
                    }
                    path = MesquiteFile.massageFilePathToURL(path);
                }
                browserString = MesquiteFile.checkFilePath(browserString, "Please select a web browser.");
                if (StringUtil.blank(browserString)) {
                    browserString = MesquiteString.queryString(mesquiteTrunk.containerOfModule(),
                            "Enter browser path",
                            "If you wish, enter the path to the browser (E.g., /hard_disk/programs/myBrowser.exe)",
                            "");
                    if (StringUtil.blank(browserString))
                        return;
                }
                String[] b = { browserString, path };
                browserCommand = b;
                try {
                    //String[] browserCommand = {browserString, arg1, arg2, arg3};

                    Runtime.getRuntime().exec(browserCommand);
                } catch (IOException e) {
                    browserString = null;
                    MesquiteTrunk.mesquiteTrunk.alert(
                            "The requested page could not be shown, because the web browser could not be used properly.  There may be a problem with insufficient memory or the location of the web page or browser.");
                }
            }
        }
    }
}

From source file:gui.GW2EventerGui.java

private void jLabelNewVersionMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelNewVersionMousePressed

    Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;

    if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
        try {/*from   ww w .j  a v  a  2 s . c  o m*/
            desktop.browse(new URI("https://sourceforge.net/projects/gw2eventer/files/latest/download"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private boolean isBrowserSupported() {
    if (!java.awt.Desktop.isDesktopSupported()) {
        return false;
    }//w ww . j a  va2 s . c o m

    java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

    if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
        return false;
    }

    return true;
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemUserGuideActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemUserGuideActionPerformed
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
        File file = new File("docs/Users Manual ver" + version + ".html");
        try {// www .  j  a v  a 2s  .  c  om
            desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(file);
            }
        } catch (Exception ex) {
            if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
                int res = JOptionPane.showConfirmDialog(this,
                        "<html><p>Online user's guide requires internet access.</p><p>Please click 'Yes' to open it in a browser. </p></html>",
                        "Cannot find User Guide", JOptionPane.YES_NO_OPTION);
                if (res == JOptionPane.YES_OPTION) {
                    URI uri;
                    try {
                        uri = new URI("http://www.jeplus.org/wiki/doku.php?id=docs:manual" + version_ps);
                        //uri = new URI("http://www.jeplus.org/docs_html/Users%20Manual%20ver" + version + ".html");
                        desktop.browse(uri);
                    } catch (URISyntaxException | IOException ex1) {
                        JOptionPane.showMessageDialog(this, "http://www.jeplus.org/wiki/doku.php?id=docs:manual"
                                + version_ps
                                + " is not accessible. Please try locate the page manually on the jEPlus website.");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(this, "Cannot find or open " + file.getPath()
                        + ". Please locate the User Guide manually on the jEPlus website.");
            }
        }
    }
}