List of usage examples for java.awt Desktop browse
public void browse(URI uri) throws IOException
From source file:com.ssn.ws.rest.service.LoginWithInstagram.java
public void login() { try {/*from w w w. j av a 2 s. c om*/ server = SSNHttpServer.createSSNHttpServer("Instagram", loginModel, homeForm); if (server != null) { connectionFactory = new InstagramConnectionFactory(SSNConstants.SSN_INSTAGRAM_CLIENT_ID, SSNConstants.SSN_INSTAGRAM_CLIENT_SECRET); oauthOperations = connectionFactory.getOAuthOperations(); OAuth2Parameters params = new OAuth2Parameters(); params.setRedirectUri(redirectUri); String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, params); java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { System.exit(1); } java.net.URI uri = new java.net.URI(authorizeUrl); desktop.browse(uri); } } catch (Exception e) { logger.error(e.getMessage()); } }
From source file:dk.dma.epd.common.prototype.gui.notification.MsiNmNotificationPanel.java
/** * {@inheritDoc}//from w w w . jav a 2s. co m */ @Override public void hyperlinkUpdate(HyperlinkEvent hle) { if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { try { URL url = hle.getURL(); if (url.getHost().equals("msinm") && url.getPath().length() > 1) { String msinmId = url.getPath().substring(1); for (MsiNmNotification notification : notificationPanel.getNotifications()) { if (notification.getSeriesId().equals(msinmId)) { EPD.getInstance().getNotificationCenter().openNotification(NotificationType.MSI_NM, notification.getId(), false); return; } Toolkit.getDefaultToolkit().beep(); } } else { Desktop desktop = Desktop.getDesktop(); desktop.browse(new URI(hle.getURL().toString())); } } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:com.diversityarrays.update.UpdateDialog.java
private void openWebpage(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {/*from w w w. j a v a 2 s.c o m*/ desktop.browse(uri); } catch (IOException e) { JOptionPane.showMessageDialog(new JFrame(), e.getMessage(), Msg.ERRTITLE_BROWSER_OPEN_ERROR(getTitle()), JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }
From source file:com.t3.client.TabletopTool.java
/** * Launch the platform's web browser and ask it to open the given URL. Note * that this should not be called from any uncontrolled macros as there are * both security and denial-of-service attacks possible. * /* www . j a v a 2s. c om*/ * @param url */ public static void showDocument(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); URI uri = null; try { uri = new URI(url); desktop.browse(uri); } catch (Exception e) { TabletopTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e); } } else { String errorMessage = "msg.error.browser.notFound"; Exception exception = null; String[] envvars = { "T3_BROWSER", "BROWSER" }; String param = envvars[0]; boolean apparentlyItWorked = false; for (String var : envvars) { String browser = System.getenv(var); if (browser != null) { try { param = var + "=\"" + browser + "\""; Runtime.getRuntime().exec(new String[] { browser, url }); apparentlyItWorked = true; } catch (Exception e) { errorMessage = "msg.error.browser.cannotStart"; exception = e; } } } if (apparentlyItWorked == false) { TabletopTool.showError(I18N.getText(errorMessage, param), exception); } } }
From source file:org.apache.marmotta.splash.startup.StartupListener.java
/** * React on the AFTER_START_EVENT of Tomcat and startup the browser to point to the Marmotta installation. Depending * on the state of the Marmotta installation, the following actions are carried out: * <ul>// ww w .j ava2 s . c o m * <li>in case the Marmotta is started for the first time, show a dialog box with options to select which IP-address to use for * configuring the Marmotta; the IP address will be stored in a separate properties file in MARMOTTA_HOME</li> * <li>in case the Marmotta has already been configured but the IP address that was used is no longer existing on the server, * show a warning dialog (this can happen e.g. for laptops with dynamically changing network configurations)</li> * <li>otherwise, open a browser using the network address that was used previously</li> * </ul> * * @param event LifecycleEvent that has occurred */ @Override public void lifecycleEvent(LifecycleEvent event) { if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) { if (!GraphicsEnvironment.isHeadless()) { String serverName = null; int serverPort = 0; // open browser window if (Desktop.isDesktopSupported()) { Properties startupProperties = getStartupProperties(); if (startupProperties.getProperty("startup.host") != null && startupProperties.getProperty("startup.port") != null) { serverName = startupProperties.getProperty("startup.host"); serverPort = Integer.parseInt(startupProperties.getProperty("startup.port")); if (!checkServerName(serverName) || serverPort != getServerPort()) { MessageDialog.show("Warning", "Configured server name not found", "The host name (" + serverName + ") that has been used to configure this \n" + "installation is no longer available on this server. The system \n" + "might behave unexpectedly. Please consider using a localhost configuration \n" + "for systems with dynamic IP addresses!"); } } else { // show a dialog listing all available addresses of this server and allowing the user to // chose List<Option> choices = new ArrayList<>(); Map<String, List<InetAddress>> addressList = listHostAddresses(); List<String> hostNames = new ArrayList<String>(addressList.keySet()); Collections.sort(hostNames); int loopback = -1; for (int i = 0; i < hostNames.size(); i++) { String hostName = hostNames.get(i); List<InetAddress> addresses = addressList.get(hostName); String label = hostName + " \n("; for (Iterator<InetAddress> it = addresses.iterator(); it.hasNext();) { label += it.next().getHostAddress(); if (it.hasNext()) { label += ", "; } } label += ")"; String text; if (addresses.get(0).isLoopbackAddress()) { text = "Local IP-Address. Recommended for Laptop use or Demonstration purposes"; loopback = loopback < 0 ? i : loopback; } else { text = "Public IP-Address. Recommended for Workstation or Server use"; } choices.add(new Option(label, text)); } int choice = SelectionDialog.select("Select Server Address", "Select host address to use for configuring the\nApache Marmotta Platform.", WordUtils.wrap( "For demonstration purposes or laptop installations it is recommended to select \"" + (loopback < 0 ? "localhost" : hostNames.get(loopback)) + "\" below. For server and workstation installations, please select a public IP address.", 60), choices, loopback); if (choice < 0) { log.error("No Server Address selected, server will shut down."); throw new IllegalArgumentException("No Server Addess was selected"); } serverName = hostNames.get(choice); serverPort = getServerPort(); startupProperties.setProperty("startup.host", serverName); startupProperties.setProperty("startup.port", serverPort + ""); storeStartupProperties(startupProperties); } final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE) && serverName != null && serverPort > 0) { try { URI uri = new URI("http", null, serverName, serverPort, "/", null, null); desktop.browse(uri); } catch (Exception e1) { System.err.println("could not open browser window, message was: " + e1.getMessage()); } } } } } }
From source file:com.konifar.material_icon_generator.MaterialDesignIconGenerateDialog.java
private void initLabelLink(JLabel label, final String url) { label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); label.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (event.getClickCount() > 0) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); try { URI uri = new URI(url); desktop.browse(uri); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }//from ww w .j av a 2 s .c o m } } } }); }
From source file:fr.vdl.android.holocolors.HoloColorsDialog.java
private void openWebpage(String url) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {//from www. ja v a2 s . c o m desktop.browse(new URL(url).toURI()); } catch (Exception e) { // no matter, nothing to do e.printStackTrace(); } } }
From source file:net.rptools.maptool.client.MapTool.java
/** * Launch the platform's web browser and ask it to open the given URL. Note * that this should not be called from any uncontrolled macros as there are * both security and denial-of-service attacks possible. * //from w w w. ja v a 2s .c o m * @param url */ public static void showDocument(String url) { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); URI uri = null; try { uri = new URI(url); desktop.browse(uri); } catch (Exception e) { MapTool.showError(I18N.getText("msg.error.browser.cannotStart", uri), e); } } else { String errorMessage = "msg.error.browser.notFound"; Exception exception = null; String[] envvars = { "MAPTOOL_BROWSER", "BROWSER" }; String param = envvars[0]; boolean apparentlyItWorked = false; for (String var : envvars) { String browser = System.getenv(var); if (browser != null) { try { param = var + "=\"" + browser + "\""; Runtime.getRuntime().exec(new String[] { browser, url }); apparentlyItWorked = true; } catch (Exception e) { errorMessage = "msg.error.browser.cannotStart"; exception = e; } } } if (apparentlyItWorked == false) { MapTool.showError(I18N.getText(errorMessage, param), exception); } } }
From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.ContentExists.java
private void btnViewContentActionPerformed(final java.awt.event.ActionEvent evt) { final Desktop desktop = Desktop.getDesktop(); try {/* w w w. java2 s . c o m*/ final StringBuilder url = new StringBuilder(); url.append(theContentAggregatorURL); if (!theContentAggregatorURL.endsWith("?")) { url.append("?"); } url.append("system="); url.append(cmsSystem); url.append("&id="); url.append(theCmsID); desktop.browse(new URI(url.toString())); } catch (IOException ex) { //This error can occur if the default browser isn't set up properly. //It mostly occurs when the URL has been successfully opened, but it // can also happen when the URL has NOT been opened. // This makes it hard to determine whether it is actually an error or not // As the more common occurrence is a successful outcome we don't // want to pop up a message box, so just log the error instead. LOG.error("Error loading form parameters", ex); } catch (Exception ex) { final String header = "Error occurred"; final String message = "An error occurred when viewing content\n" + ex.getMessage(); JOptionPane.showMessageDialog(this, message, header, JOptionPane.ERROR_MESSAGE); } }
From source file:de.pixida.logtest.designer.MainWindow.java
private void createAndAppendHelpMenuItems(final Menu help) { final MenuItem visitDocumentation = new MenuItem("Visit Online Documentation"); visitDocumentation.setGraphic(Icons.getIconGraphics("help")); visitDocumentation.setOnAction(event -> { Exception ex = null;//from w ww . j a v a 2s .com final String url = "https://github.com/Pixida/logtest/wiki"; final Desktop desktop = java.awt.Desktop.getDesktop(); if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) { try { desktop.browse(new URI(url)); } catch (final Exception e) { ex = e; } } else { ex = new Exception("Browsing not supported."); } if (ex != null) { ExceptionDialog.showFatalException("Failed to open browser", "Visit us at " + url, ex); } }); final MenuItem about = new MenuItem("About " + APP_TITLE); about.setGraphic(Icons.getIconGraphics(APP_ICON)); about.setOnAction(event -> { final Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.initStyle(StageStyle.UTILITY); alert.setTitle(about.getText()); alert.setHeaderText(APP_TITLE); alert.setContentText("Copyright (C) " + Calendar.getInstance().get(Calendar.YEAR) + " Pixida GmbH\n" + "\n" + "This application includes FAMFAMFAM icons (http://www.famfamfam.com)."); alert.showAndWait(); }); help.getItems().addAll(visitDocumentation, about); }