Example usage for java.awt Desktop browse

List of usage examples for java.awt Desktop browse

Introduction

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

Prototype

public void browse(URI uri) throws IOException 

Source Link

Document

Launches the default browser to display a URI .

Usage

From source file:com.codejumble.opentube.Main.java

/**
 * Opens http://www.codejumble.com at System's default browser
 *
 * @param evt Swing event/*from  ww  w  . ja v a2 s  .  co  m*/
 */
private void helpPagesItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpPagesItemActionPerformed
    try {
        URI uri = new URL("http://www.codejumble.com").toURI();
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(uri);
            } catch (Exception e) {
                createErrorDialog(this, e.getMessage(), "Error!");
            }
        }
    } catch (Exception ex) {
        createErrorDialog(this, ex.getMessage(), "Unexpected error");
    }
}

From source file:org.wandora.application.tools.extractors.palvelukartta_v2.PalvelukarttaSelector.java

private void openButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openButtonMouseReleased
    Desktop dt = Desktop.getDesktop();
    if (dt != null) {
        try {/*  ww w.java2 s  .  c  o m*/
            dt.browse(new URI("http://www.hel.fi/palvelukartta"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:xtrememp.update.SoftwareUpdate.java

public static void checkForUpdates(final boolean showDialogs) {
    checkForUpdatesWorker = new SwingWorker<Version, Void>() {

        @Override//from   w  ww.  ja  v  a2s  . c o  m
        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:AltiConsole.AltiConsoleMainScreen.java

/**
 * Handles all the actions./* w  ww . j  av a2  s  .c  o m*/
 * 
 * @param e
 *            the action event.
 */
public void actionPerformed(final ActionEvent e) {
    final Translator trans = Application.getTranslator();

    if (e.getActionCommand().equals("EXIT")) {
        System.out.println("exit and disconnecting\n");
        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.ClosingWindow"),
                trans.get("AltiConsoleMainScreen.ReallyClosing"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            DisconnectFromAlti();
            System.exit(0);
        }
    } else if (e.getActionCommand().equals("ABOUT")) {
        AboutDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // ERASE_FLIGHT
    else if (e.getActionCommand().equals("ERASE_FLIGHT")) {

        if (JOptionPane.showConfirmDialog(this, trans.get("AltiConsoleMainScreen.eraseAllflightData"),
                trans.get("AltiConsoleMainScreen.eraseAllflightDataTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            System.out.println("erasing flight\n");
            ErasingFlight();
        }

    } else if (e.getActionCommand().equals("RETRIEVE_FLIGHT")) {

        System.out.println("retrieving flight\n");
        RetrievingFlight();

    } else
    // SAVE_FLIGHT
    if (e.getActionCommand().equals("SAVE_FLIGHT")) {
        System.out.println("Saving current flight\n");
        SavingFlight();
    } else
    // RETRIEVE_ALTI_CFG
    if (e.getActionCommand().equals("RETRIEVE_ALTI_CFG")) {
        System.out.println("retrieving alti config\n");
        AltiConfigData pAlticonfig = retrieveAltiConfig();
        if (pAlticonfig != null)
            AltiConfigDlg.showPreferences(AltiConsoleMainScreen.this, pAlticonfig, Serial);

    }
    // LICENSE
    else if (e.getActionCommand().equals("LICENSE")) {

        LicenseDialog.showPreferences(AltiConsoleMainScreen.this);
    }
    // comPorts
    else if (e.getActionCommand().equals("comPorts")) {
        DisconnectFromAlti();
        String currentPort;
        //e.
        currentPort = (String) comPorts.getSelectedItem();
        if (Serial != null)
            Serial.searchForPorts();

        System.out.println("We have a new selected value for comport\n");
        comPorts.setSelectedItem(currentPort);
    }
    // UPLOAD_FIRMWARE
    else if (e.getActionCommand().equals("UPLOAD_FIRMWARE")) {
        System.out.println("upload firmware\n");
        //make sure to disconnect first
        DisconnectFromAlti();
        JFileChooser fc = new JFileChooser();
        String hexfile = null;
        File startFile = new File(System.getProperty("user.dir"));
        //FileNameExtensionFilter filter;

        fc.setDialogTitle("Select firmware");
        //fc.set
        fc.setCurrentDirectory(startFile);
        //fc.addChoosableFileFilter(new FileNameExtensionFilter("*.HEX", "hex"));
        fc.setFileFilter(new FileNameExtensionFilter("*.hex", "hex"));
        //fc.fil
        int action = fc.showOpenDialog(SwingUtilities.windowForComponent(this));
        if (action == JFileChooser.APPROVE_OPTION) {
            hexfile = fc.getSelectedFile().getAbsolutePath();
        }
        if (hexfile != null) {

            String exefile = UserPref.getAvrdudePath();

            String conffile = UserPref.getAvrdudeConfigPath();

            String opts = " -v -v -v -v -patmega328p -carduino -P\\\\.\\"
                    + (String) this.comPorts.getSelectedItem() + " -b115200 -D -V ";

            String cmd = exefile + " -C" + conffile + opts + " -Uflash:w:" + hexfile + ":i";
            System.out.println(cmd);

            try {
                Process p = Runtime.getRuntime().exec(cmd);
                AfficheurFlux fluxSortie = new AfficheurFlux(p.getInputStream(), this);
                AfficheurFlux fluxErreur = new AfficheurFlux(p.getErrorStream(), this);

                new Thread(fluxSortie).start();
                new Thread(fluxErreur).start();

                p.waitFor();
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                e2.printStackTrace();
            }
        }
    }
    // ON_LINE_HELP
    else if (e.getActionCommand().equals("ON_LINE_HELP")) {
        Desktop d = Desktop.getDesktop();
        System.out.println("Online help \n");
        try {
            d.browse(new URI(trans.get("help.url")));
        } catch (URISyntaxException e1) {

            System.out.println("Illegal URL:  " + trans.get("help.url") + " " + e1.getMessage());
        } catch (IOException e1) {
            System.out.println("Unable to launch browser: " + e1.getMessage());
        }

    }
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private void doOpenWiki() {
    try {//from  ww  w  . j  a  v  a 2 s . c  o m
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(new URI(WIKI_URL));
    } catch (URISyntaxException | IOException ex) {

    }
}

From source file:com._17od.upm.gui.AccountDialog.java

/**
 * Method that get(as input) the selected Account URL and open this URL via
 * the default browser of our platform.// ww  w .j  a  v  a 2  s . c  o  m
 * 
 * @param url
 */
private void LaunchSelectedURL(String url) {

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();

        try {
            desktop.browse(new URI(url));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    } else { // Linux and Mac specific code in order to launch url
        Runtime runtime = Runtime.getRuntime();

        try {
            runtime.exec("xdg-open " + url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com._17od.upm.gui.MainWindow.java

private void LaunchSelectedURL(String url) {

    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();

        try {/* ww w.  ja  v a2  s . c o m*/
            desktop.browse(new URI(url));

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        // Linux and Mac specific code in order to launch url
    } else {
        Runtime runtime = Runtime.getRuntime();

        try {
            runtime.exec("xdg-open " + url);

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private void initFX(final JFXPanel fxPanel) {
    Group group = new Group();
    Scene scene = new Scene(group);
    fxPanel.setScene(scene);/*from  w ww .jav  a 2  s.  c o  m*/

    webView = new WebView();

    if (javaFXVersionInt >= 8) {
        webView.setScaleX(1.0);
        webView.setScaleY(1.0);
        //webView.setFitToHeight(false);
        //webView.setFitToWidth(false);
        //webView.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96);
    }

    group.getChildren().add(webView);

    int w = this.getWidth();
    int h = this.getHeight() - 34;

    webView.setMinSize(w, h);
    webView.setMaxSize(w, h);
    webView.setPrefSize(w, h);

    // Obtain the webEngine to navigate
    webEngine = webView.getEngine();

    webEngine.locationProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue,
                final String newValue) {
            if (newValue.endsWith(".pdf")) {
                try {
                    int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(),
                            "Open PDF document in external application?",
                            "Open PDF document in external application?", WandoraOptionPane.YES_NO_OPTION);
                    if (a == WandoraOptionPane.YES_OPTION) {
                        Desktop dt = Desktop.getDesktop();
                        dt.browse(new URI(newValue));
                    }
                } catch (Exception e) {
                }
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        urlTextField.setText(newValue);
                    }
                });
            }
        }
    });
    webEngine.titleProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue,
                final String newValue) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    title = newValue;
                }
            });
        }
    });
    webEngine.setOnAlert(new EventHandler<WebEvent<java.lang.String>>() {
        @Override
        public void handle(WebEvent<String> t) {
            if (t != null) {
                String str = t.getData();
                if (str != null && str.length() > 0) {
                    WandoraOptionPane.showMessageDialog(Wandora.getWandora(), str, "Javascript Alert",
                            WandoraOptionPane.PLAIN_MESSAGE);
                }
            }
        }
    });
    webEngine.setConfirmHandler(new Callback<String, Boolean>() {
        @Override
        public Boolean call(String msg) {
            int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), msg, "Javascript Alert",
                    WandoraOptionPane.YES_NO_OPTION);
            return (a == WandoraOptionPane.YES_OPTION);
        }
    });
    webEngine.setPromptHandler(new Callback<PromptData, String>() {
        @Override
        public String call(PromptData data) {
            String a = WandoraOptionPane.showInputDialog(Wandora.getWandora(), data.getMessage(),
                    data.getDefaultValue(), "Javascript Alert", WandoraOptionPane.QUESTION_MESSAGE);
            return a;
        }
    });

    webEngine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
        @Override
        public WebEngine call(PopupFeatures features) {
            if (informPopupBlocking) {
                WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                        "A javascript popup has been blocked. Wandora doesn't allow javascript popups in Webview topic panel.",
                        "Javascript popup blocked", WandoraOptionPane.PLAIN_MESSAGE);
            }
            informPopupBlocking = false;
            return null;
        }
    });
    webEngine.setOnVisibilityChanged(new EventHandler<WebEvent<Boolean>>() {
        @Override
        public void handle(WebEvent<Boolean> t) {
            if (t != null) {
                Boolean b = t.getData();
                if (informVisibilityChanges) {
                    WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                            "A browser window visibility change has been blocked. Wandora doesn't allow visibility changes of windows in Webview topic panel.",
                            "Javascript visibility chnage blocked", WandoraOptionPane.PLAIN_MESSAGE);
                    informVisibilityChanges = false;
                }
            }
        }
    });
    webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == Worker.State.SCHEDULED) {
                //System.out.println("Scheduled!");
                startLoadingAnimation();
            }
            if (newState == Worker.State.SUCCEEDED) {
                Document doc = webEngine.getDocument();
                try {
                    Transformer transformer = TransformerFactory.newInstance().newTransformer();
                    //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

                    // transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));

                    StringWriter stringWriter = new StringWriter();
                    transformer.transform(new DOMSource(doc), new StreamResult(stringWriter));
                    webSource = stringWriter.toString();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                stopLoadingAnimation();
            } else if (newState == Worker.State.CANCELLED) {
                //System.out.println("Cancelled!");
                stopLoadingAnimation();
            } else if (newState == Worker.State.FAILED) {
                webEngine.loadContent(failedToOpenMessage);
                stopLoadingAnimation();
            }
        }
    });

}

From source file:org.wandora.application.gui.OccurrenceTableSingleType.java

@Override
public void openURLOccurrence() {
    try {//from  w w w .ja v a2s  . c om
        String errorMessage = null;
        Point p = getTableModelPoint();
        if (p != null) {
            String occurrence = topic.getData(type, langs[p.y]);
            if (occurrence != null) {
                occurrence = occurrence.trim();
                if (occurrence.length() > 0) {
                    try {
                        if (!DataURL.isDataURL(occurrence)) {
                            Desktop desktop = Desktop.getDesktop();
                            desktop.browse(new URI(occurrence));
                        } else {
                            errorMessage = "Due to security restrictions Wandora can't open data-urls with desktop browser. "
                                    + "Copy data-url to clipboard and paste it to browser's address field.";
                        }
                    } catch (IOException ioe) {
                        errorMessage = "IOException occurred while starting external browser for occurrence: "
                                + ioe.getMessage();
                    } catch (Exception e) {
                        if (occurrence.length() > 80)
                            occurrence = occurrence.substring(0, 80) + "...";
                        errorMessage = "Exception '" + e.getMessage()
                                + "' occurred while starting external browser for occurrence. Check if the occurrence text is a valid URL.";
                        e.printStackTrace();
                    }
                }
            }
        }
        if (errorMessage != null) {
            WandoraOptionPane.showMessageDialog(Wandora.getWandora(), errorMessage, "Error while opening URL");
        }
    } catch (Exception e) {
        if (wandora != null)
            wandora.handleError(e);
    }
}

From source file:convcao.com.agent.ConvcaoNeptusInteraction.java

private void jLabel1MouseClicked(MouseEvent evt) throws URISyntaxException, IOException {
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();

        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            URI uri = new URI("http://www.noptilus-fp7.eu/default.asp?node=page&id=321&lng=2");
            desktop.browse(uri);
        }//from   www.j a  va2  s . co  m
    }
}