List of usage examples for java.awt Desktop browse
public void browse(URI uri) throws IOException
From source file:de.hybris.platform.marketplaceintegrationbackoffice.utils.MarketplaceintegrationbackofficeHttpClientImpl.java
@Override public boolean redirectRequest(final String requestUrl) throws IOException { final boolean result = true; final RestTemplate restTemplate = new RestTemplate(); final java.net.URI uri = java.net.URI.create(requestUrl); final java.awt.Desktop dp = java.awt.Desktop.getDesktop(); if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) { dp.browse(uri); }/*w ww . j a v a 2 s .c o m*/ restTemplate.execute(requestUrl, HttpMethod.GET, new RequestCallback() { @Override public void doWithRequest(final ClientHttpRequest request) throws IOException { // empty block should be documented } }, new ResponseExtractor<Object>() { @Override public Object extractData(final ClientHttpResponse response) throws IOException { final HttpStatus statusCode = response.getStatusCode(); LOG.debug("Response status: " + statusCode.toString()); return response.getStatusCode(); } }); return result; }
From source file:processing.app.macosx.Platform.java
@Override public void openURL(String url) throws Exception { Desktop desktop = Desktop.getDesktop(); if (url.startsWith("http") || url.startsWith("file:")) { desktop.browse(new URI(url)); } else {// w w w. j a v a 2 s . c o m desktop.open(new File(url)); } }
From source file:com.tag.Hyperlink.java
private void init() { setHorizontalAlignment(SwingConstants.LEFT); setBackground(Color.WHITE);//from w ww. j a va2 s. c o m setBorder(null); setBorderPainted(false); setOpaque(false); String toolTip = getUri().toString(); setToolTipText(toolTip); addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Desktop desktop = Desktop.getDesktop(); boolean mail = desktop.isSupported(Action.BROWSE); if (mail) { try { desktop.browse(uri); } catch (IOException ex) { ex.printStackTrace(); } } } }); }
From source file:org.sonarlint.intellij.ui.SonarLintRulePanel.java
private JEditorPane createEditor() { JEditorPane newEditor = new JEditorPane(); newEditor.setEditorKit(kit);//ww w. j a va2s .c om newEditor.setBorder(new EmptyBorder(10, 10, 10, 10)); newEditor.setEditable(false); newEditor.setContentType("text/html"); newEditor.addHyperlinkListener(e -> { if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(e.getURL().toURI()); } catch (Exception ex) { SonarLintConsole.get(project).error("Error opening browser: " + e.getURL(), ex); } } }); return newEditor; }
From source file:op.system.DlgLogin.java
private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); try {//from w ww . j a va 2s .co m desktop.browse(new URI("http://www.offene-pflege.de")); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } } }
From source file:org.brickred.tools.GenerateToken.java
private void getAccessToken() throws Exception { SocialAuthConfig config = SocialAuthConfig.getDefault(); config.load();/*from w w w . j a v a2 s .co m*/ SocialAuthManager manager = new SocialAuthManager(); manager.setSocialAuthConfig(config); URL aURL = new URL(successURL); host = aURL.getHost(); port = aURL.getPort(); port = port == -1 ? 80 : port; callbackPath = aURL.getPath(); if (tokenFilePath == null) { tokenFilePath = System.getProperty("user.home"); } startServer(); String url = manager.getAuthenticationUrl(providerId, successURL); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { try { desktop.browse(URI.create(url)); // return; } catch (IOException e) { // handled below } } } lock.lock(); try { while (code == null && error == null) { gotAuthorizationResponse.awaitUninterruptibly(); } if (error != null) { throw new IOException("User authorization failed (" + error + ")"); } } finally { lock.unlock(); } stop(); manager.getAuthenticationUrl(providerId, successURL); AccessGrant accessGrant = manager.createAccessGrant(providerId, code, successURL); Exporter.exportAccessGrant(accessGrant, tokenFilePath); LOG.info("Access Grant Object saved in a file :: " + tokenFilePath + File.separatorChar + accessGrant.getProviderId() + "_accessGrant_file.txt"); }
From source file:de.micromata.mgc.javafx.SystemService.java
public void openUrlInBrowser(String url) { Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } else {//from ww w.j ava2s . c o m 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:org.echocat.velma.dialogs.AboutDialog.java
protected void createIntroduction(@Nonnull Resources resources) { final URL iconUrl = resources.getIconUrl(48); final StringBuilder body = new StringBuilder(); body.append("<html>"); body.append("<head><style>" + "td { margin-right: 10px; }" + "</style></head>"); body.append("<body style='font-family: sans; font-size: 1em'><table><tr>"); body.append("<td valign='top'><img src='").append(iconUrl).append("' /></td>"); body.append("<td valign='top'>"); body.append("<h2>").append(escapeHtml4(resources.getApplicationName())); final String version = resources.getVersion(); if (!isEmpty(version)) { body.append("<br/><span style='font-size: 0.6em'>") .append(resources.formatEscaped("versionText", version)).append("</span>"); }//w w w . j a v a 2 s. c o m body.append("</h2>"); body.append("<p>Copyright 2011-2012 <a href='https://echocat.org'>echocat</a></p>"); body.append("<p><a href='http://mozilla.org/MPL/2.0/'>") .append(resources.formatEscaped("licensedUnder", "MPL 2.0")).append("</a></p>"); body.append("<p><table cellpadding='0' cellspacing='0'>"); body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "echocat")) .append(":</td><td><a href='https://echocat.org'>echocat.org</a></td></tr>"); body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "Velma")) .append(":</td><td><a href='https://velma.echocat.org'>velma.echocat.org</a></td></tr>"); body.append("</table></p>"); body.append("<h4>").append(resources.formatEscaped("developers")) .append("</h4><table cellpadding='0' cellspacing='0'>"); body.append( "<tr><td>Gregor Noczinski</td><td><a href='mailto:gregor@noczinski.eu'>gregor@noczinski.eu</a></td><td><a href='https://github.com/blaubaer'>github.com/blaubaer</a></td></tr>"); body.append("</table>"); body.append("</td>"); body.append("</tr></table></body></html>"); final JTextPane text = new JTextPane(); text.setMargin(new Insets(0, 0, 0, 0)); text.setContentType("text/html"); text.setText(body.toString()); text.setFont(new Font(DIALOG, PLAIN, 12)); text.setBackground(new Color(255, 255, 255, 0)); text.setEditable(false); text.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == ACTIVATED && isDesktopSupported()) { final Desktop desktop = getDesktop(); if (desktop.isSupported(BROWSE)) { try { desktop.browse(e.getURL().toURI()); } catch (IOException | URISyntaxException exception) { LOG.error("Could not open " + e.getURL() + " because of an exception.", exception); } } else { LOG.error("Could not open " + e.getURL() + " because browse is not supported by desktop."); } } repaint(); } }); text.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { repaint(); } @Override public void mousePressed(MouseEvent e) { repaint(); } @Override public void mouseReleased(MouseEvent e) { repaint(); } @Override public void mouseEntered(MouseEvent e) { repaint(); } @Override public void mouseExited(MouseEvent e) { repaint(); } }); add(text, new CC().spanX(2).growX().minWidth("10px")); }
From source file:org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.help.HelpManager.java
public void openInBrowser(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {/* w w w .j a va2s. c o m*/ desktop.browse(uri); } catch (IOException e) { System.err.println(e.getMessage()); } } else { System.err.println("Desktop not supported, cannout open browser"); } }
From source file:org.wandora.application.tools.server.HTTPServerTool.java
@Override public void execute(Wandora wandora, Context context) throws TopicMapException { if ((mode & CONFIGURE) != 0) { WandoraModulesServer server = wandora.getHTTPServer(); String u = null; //s.getLoginUser(); String p = null; //s.getLoginPassword(); if (u == null) u = ""; if (p == null) p = ""; String[] logLevels = { "trace", "debug", "info", "warn", "error", "fatal", "none" }; GenericOptionsDialog god = new GenericOptionsDialog(wandora, "Wandora HTTP server settings", "Wandora HTTP server settings", true, new String[][] { new String[] { "Auto start", "boolean", "" + server.isAutoStart(), "Start server automatically when you start Wandora" }, new String[] { "Port", "string", "" + server.getPort(), "Port the server is listening to" }, new String[] { "Local only", "boolean", "" + server.isLocalOnly(), "Allow only local connections" }, new String[] { "Use SSL", "boolean", "" + server.isUseSSL(), "Should server use SSL" }, new String[] { "Keystore location", "string", "" + server.getKeystoreFile(), "Where SSL keystore file locates? Keystore is used only if you have selected to use SLL." }, new String[] { "Keystore password", "string", "" + server.getKeystorePassword(), "Keystore's password. Keystore is used only if you have selected to use SLL." }, // new String[]{"User name","string",u,"User name. Leave empty for anonymous login"}, // new String[]{"Password","password",p,"Password for the user if user name field is used"}, new String[] { "Server path", "string", server.getServerPath(), "Path where Wandora web apps are deployed" }, // new String[]{"Static content path","string",s.getStaticPath(),"Path where static files are located"}, // new String[]{"Template path","string",s.getTemplatePath(),"Path where Velocity templates are located"}, // new String[]{"Template","string",s.getTemplateFile(),"Template file used to create a topic page"}, new String[] { "Log level", "combo:" + StringUtils.join(logLevels, ";"), logLevels[server.getLogLevel()], "Lowest level of log messages that are printed" }, }, wandora);/*w w w.j ava2s . c om*/ god.setSize(800, 400); if (wandora != null) wandora.centerWindow(god); god.setVisible(true); if (god.wasCancelled()) return; boolean running = server.isRunning(); if (running) server.stopServer(); Map<String, String> values = god.getValues(); server.setAutoStart(Boolean.parseBoolean(values.get("Auto start"))); server.setPort(Integer.parseInt(values.get("Port"))); server.setLocalOnly(Boolean.parseBoolean(values.get("Local only"))); server.setUseSSL(Boolean.parseBoolean(values.get("Use SSL"))); server.setKeystoreFile(values.get("Keystore location")); server.setKeystorePassword(values.get("Keystore password")); // server.setLogin(values.get("User name"),values.get("Password")); // server.setStaticPath(values.get("Static content path")); // server.setTemplatePath(values.get("Template path")); // server.setTemplateFile(values.get("Template")); server.setServerPath(values.get("Server path")); server.setLogLevel(ArrayUtils.indexOf(logLevels, values.get("Log level"))); server.writeOptions(wandora.getOptions()); server.initModuleManager(); server.readBundleDirectories(); if (running) server.start(); wandora.menuManager.refreshServerMenu(); } if ((mode & START) != 0) { wandora.startHTTPServer(); } else if ((mode & STOP) != 0) { wandora.stopHTTPServer(); } if ((mode & UPDATE_MENU) != 0) { wandora.menuManager.refreshServerMenu(); } if ((mode & OPEN_PAGE) != 0) { try { if (!wandora.getHTTPServer().isRunning()) { int a = WandoraOptionPane.showConfirmDialog(wandora, "HTTP server is not running at the moment. Would you like to start the server first?", "Start HTTP server?", WandoraOptionPane.OK_CANCEL_OPTION); if (a == WandoraOptionPane.OK_OPTION) { wandora.startHTTPServer(); wandora.menuManager.refreshServerMenu(); } else if (a == WandoraOptionPane.CANCEL_OPTION) { return; } } WandoraModulesServer s = wandora.getHTTPServer(); String uri = (s.isUseSSL() ? "https" : "http") + "://127.0.0.1:" + s.getPort() + "/topic"; if (forceUrl != null) uri = forceUrl; else if (webApp != null) { uri = webApp.getAppStartPage(); if (uri == null) { WandoraOptionPane.showMessageDialog(wandora, "Can't launch selected webapp. Webapp says it's URI is null."); return; } } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(new URI(uri)); } catch (Exception e) { log(e); } } catch (Exception e) { wandora.handleError(e); } } if ((mode & OPEN_PAGE_IN_BROWSER_TOPIC_PANEL) != 0) { try { if (!wandora.getHTTPServer().isRunning()) { int a = WandoraOptionPane.showConfirmDialog(wandora, "HTTP server is not running at the moment. Would you like to start the server first?", "Start HTTP server?", WandoraOptionPane.OK_CANCEL_OPTION); if (a == WandoraOptionPane.OK_OPTION) { wandora.startHTTPServer(); wandora.menuManager.refreshServerMenu(); } } WandoraModulesServer s = wandora.getHTTPServer(); String uri = (s.isUseSSL() ? "https" : "http") + "://127.0.0.1:" + s.getPort() + "/topic"; if (forceUrl != null) uri = forceUrl; else if (webApp != null) { uri = webApp.getAppStartPage(); if (uri == null) { WandoraOptionPane.showMessageDialog(wandora, "Can't launch selected webapp. Webapp says it's URI is null."); return; } } try { if (param2 != null) { if (param2 instanceof WebViewPanel) { WebViewPanel browserTopicPanel = (WebViewPanel) param2; browserTopicPanel.browse(uri); } } } catch (Exception e) { log(e); } } catch (Exception e) { wandora.handleError(e); } } }