List of usage examples for java.awt Desktop browse
public void browse(URI uri) throws IOException
From source file:Main.java
public static void main(String[] argv) { JEditorPane jep = new JEditorPane(); jep.setContentType("text/html"); StringBuilder sb = new StringBuilder(); sb.append("<b>Welcome</b>:<br><hr>"); for (int i = 1; i <= 3; i++) { sb.append(create(i));//from w w w . j a v a 2s.c om } sb.append("<hr>"); jep.setText(sb.toString()); jep.setEditable(false); jep.addHyperlinkListener(e -> { if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { System.out.println(e.getURL()); Desktop desktop = Desktop.getDesktop(); try { desktop.browse(e.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(jep); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { try {//from w w w.ja v a 2s. com URI uri = new URI("http://www.java2s.com"); Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } if (desktop != null) desktop.browse(uri); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } }
From source file:Main.java
public static void main(String[] a) { try {// ww w.j ava 2s. c o m URI uri = new URI("http://www.java2s.com"); Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); desktop.isSupported(Desktop.Action.PRINT); } if (desktop != null) desktop.browse(uri); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } }
From source file:org.meerkat.MeerkatMonitor.java
/** * main/*from www . j a v a 2s . com*/ * * @param args */ public static void main(String[] args) { int numberStepsToProgress = 14; double percentIncrease = 100 / numberStepsToProgress; double currProgress = 0; PropertiesLoader pL = new PropertiesLoader(propertiesFile); pL.validateProperties(); // validate present properties properties = pL.getPropetiesFromFile(); try { splashScreen = new SplashScreen(version); } catch (Exception e) { log.warn("No Graphical interface available: " + e.getMessage()); } // Show splash screen if available SwingUtilities.invokeLater(new Runnable() { public void run() { try { splashScreen.showScreen(); isSplashSupported = true; } catch (Exception e) { log.info("Desktop environment not available. [Running in console mode]"); } } }); if (isSplashSupported) { splashScreen.setProgress("Meekat-Monitor v." + version + " starting...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Meekat-Monitor v." + version + " starting..."); try { Thread.sleep(1000); } catch (InterruptedException e1) { log.error("Faile to sleep thread! " + e1.getMessage()); } // Try to ping meerkat-monitor.org if (Boolean.parseBoolean(properties.getProperty("meerkat.mma.usage.stats"))) { // Auto-configure java proxy based on system settings ProxySystemSettings proxySettings = new ProxySystemSettings(); proxySettings.setProxyAutoDetectSystemSettings(); MMA_PostInfo pInfo = new MMA_PostInfo(); try { pInfo.postInfo(); log.info("Anonymous usage statistics enabled."); } catch (Exception e2) { log.warn("Unable to ping: meerkat-monitor.org"); } } else { log.info("Send anonymous usage statistics is: Disabled."); } // Setup general log settings if (isSplashSupported) { splashScreen.setProgress("Loading settings...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Updating log setting..."); LogSettings ls = new LogSettings(); ls.setupLogGeneralOptions(); // Set up apache cxf log through log4j java.util.logging.Logger jlog = java.util.logging.Logger.getLogger("org.apache.cxf"); jlog.setLevel(Level.WARNING); // Set httpclient log to error only System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "error"); System.setProperty("derby.locks.deadlockTrace", "true"); // Load SQL Drivers if (isSplashSupported) { splashScreen.setProgress("Loading JDBC Drivers and DB...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Loading JDBC Drivers..."); SQLDriverLoader sqlDL = new SQLDriverLoader(); sqlDL.loadDrivers(); // Setup embedded Database if (isSplashSupported) { splashScreen.setProgress("Setting up embedded database...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Setting up embedded database..."); EmbeddedDB ebd = new EmbeddedDB(); // Load the driver first time ebd.loadDriver(); ebd.initializeDB(); /** if(isSplashSupported){ splashScreen.setProgress("Executing database maintenance...", (int)Math.round(currProgress)); currProgress += percentIncrease; } ebd.executeDBMaintenance(); */ // Prepare applications settings if (isSplashSupported) { splashScreen.setProgress("Loading application settings...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Loading application settings..."); // Prepare temporary working directory if (isSplashSupported) { splashScreen.setProgress("Creating applications...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Setting temporary dir: "); mgo = new MeerkatGeneralOperations(configFile, version); String tempWorkingDir = mgo.getTmpWorkingDir(); // Loading / Creating applications WebAppCollection webAppsCollection = mgo.loadWebAppsXML(); // Create the password manager MasterKeyManager mkm = new MasterKeyManager(propertiesFile, webAppsCollection); // Generate applications groups if (isSplashSupported) { splashScreen.setProgress("Creating groups...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Creating applications groups..."); AppGroupCollection appGroupCollection = new AppGroupCollection(); appGroupCollection.populateGroups(webAppsCollection); appGroupCollection.printLogGroupMembers(); webAppsCollection.setGroupCollection(appGroupCollection); // Set group to app collection // Setup email settings if (isSplashSupported) { splashScreen.setProgress("Setting up email settings...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Setting up email settings..."); MailManager mailManager = new MailManager(propertiesFile); boolean sendEmails = Boolean.parseBoolean(properties.getProperty("meerkat.email.send.emails")); boolean testEmailSending = Boolean.parseBoolean(properties.getProperty("meerkat.email.sending.test")); if (sendEmails && testEmailSending) { mailManager.sendTestEmail(); } // Create the RSS Feed if (isSplashSupported) { splashScreen.setProgress("Setting up RSS...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Creating RSS service..."); rssFeed = new RSS("Meerkat Monitor", "Meerkat Monitor RSS Alerts", "", new File(mgo.getTmpWorkingDir()).getAbsolutePath()); rssFeed.refreshRSSFeed(); webserverPort = Integer.parseInt(properties.getProperty("meerkat.webserver.port")); rssFeed.setServerPort(webserverPort); // Extract needed resources if (isSplashSupported) { splashScreen.setProgress("Extracting resources...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Extracting resources..."); mgo.extractWebResourcesResources(); // Link DB to app webAppsCollection.setDB(ebd); // Setup web server if (isSplashSupported) { splashScreen.setProgress("Setting up embedded server...", (int) Math.round(currProgress)); currProgress += percentIncrease; } log.info("Setting up embedded server..."); String wsdlEndpoint = "http://" + hostname + ":" + (webserverPort + 1) + webServiceRoot; String wsdlUrl = wsdlEndpoint + "?wsdl"; webServicesWSDL = wsdlUrl; httpWebServer = new HttpServer(webserverPort, version, wsdlUrl, tempWorkingDir); httpWebServer.setDataSources(webAppsCollection, appGroupCollection); // publish web services Endpoint.publish(wsdlEndpoint, new MeerkatWebService(mkm, webAppsCollection, httpWebServer)); // set the httpServer to webapp collection webAppsCollection.setHttpServer(httpWebServer); // Open Dashboard in default browser if available if (isSplashSupported) { splashScreen.setProgress("Finalizing...", (int) Math.round(currProgress)); currProgress += percentIncrease; } try { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); java.net.URI uri = new java.net.URI("http://" + hostname + ":" + webserverPort); desktop.browse(uri); } catch (Exception e) { log.info("[Console mode] Please open URL manually: http://" + hostname + ":" + webserverPort + ")"); } // Start monitor log.info("Setting up monitor..."); Monitor monitor = new Monitor(ebd, webAppsCollection, appGroupCollection, httpWebServer, rssFeed, propertiesFile); if (isSplashSupported) { splashScreen.setProgress("Done!", (int) Math.round(currProgress)); currProgress += percentIncrease; splashScreen.close(); } monitor.startMonitor(); }
From source file:Main.java
private static void openWebpage(URI uri) throws IOException { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); }//from w w w . j a va 2 s . c o m }
From source file:VASSAL.tools.BrowserSupport.java
public static void openURL(String url) { ///*ww w. j av a 2 s.c o m*/ // This method is irritatingly complex, because: // * There is no java.awt.Desktop in Java 1.5. // * java.awt.Desktop seems not to work sometimes on Windows. // * BrowserLauncher failes sometimes on Linux, and isn't supported // anymore. // if (!SystemUtils.IS_JAVA_1_5) { if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(new URI(url)); return; } catch (IOException e) { // We ignore this on Windows, because Desktop seems flaky if (!SystemUtils.IS_OS_WINDOWS) { ReadErrorDialog.error(e, url); return; } } catch (IllegalArgumentException e) { ErrorDialog.bug(e); return; } catch (URISyntaxException e) { ErrorDialog.bug(e); return; } } } } if (browserLauncher != null) { browserLauncher.openURLinBrowser(url); } else { ErrorDialog.show("BrowserSupport.unable_to_launch", url); } }
From source file:org.apache.http.examples.me.ClientMultiThreadedExecution.java
public static void runBroswer(String webSite) { try {//from ww w .j a va 2 s. c om Desktop desktop = Desktop.getDesktop(); if (desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) { URI uri = new URI(webSite); desktop.browse(uri); } } catch (IOException ex) { ex.printStackTrace(); } catch (URISyntaxException ex) { ex.printStackTrace(); } }
From source file:org.planetcrypto.bitcoin.PlanetCryptoNetworkMethods.java
/** * /*from ww w . java 2s. c o m*/ * @param uri URL of Eligius user stats */ public static void openWebpage(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(uri); } catch (IOException e) { e.printStackTrace(); } } }
From source file:by.iharkaratkou.TestServlet.java
public static void openWebpage(URI uri) { Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try {// w w w . j av a 2s.c om desktop.browse(uri); } catch (Exception e) { e.printStackTrace(); } } }
From source file:context.ui.misc.FileHandler.java
/** * * @param url// w w w. jav a 2 s . c om */ public static void openWebpage(String url) { try { URI uri = new URI(url); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }