1.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/Main.java Sat Feb 08 10:07:55 2014 +0100
1.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/Main.java Tue Mar 04 08:24:11 2014 +0100
1.3 @@ -23,21 +23,61 @@
1.4 */
1.5 package org.apidesign.demo.minesweeper;
1.6
1.7 +import java.io.IOException;
1.8 +import java.net.URI;
1.9 +import java.util.Arrays;
1.10 +import java.util.logging.Level;
1.11 +import java.util.logging.Logger;
1.12 import net.java.html.boot.BrowserBuilder;
1.13 +import org.apidesign.html.dlvkbrwsr.XtrnlBrwsrPrsntr;
1.14
1.15
1.16 /** Bootstrap and initialization. */
1.17 public final class Main {
1.18 + private static final Logger LOG = Logger.getLogger(Main.class.getName());
1.19 private Main() {
1.20 }
1.21 +
1.22 + static Object[] showBrwsr(URI uri, String cmd) throws IOException {
1.23 + LOG.log(Level.INFO, "Showing {0}", uri);
1.24 + if (cmd == null) {
1.25 + try {
1.26 + LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[]{
1.27 + System.getProperty("java.vm.name"),
1.28 + System.getProperty("java.vm.vendor"),
1.29 + System.getProperty("java.vm.version"),});
1.30 + java.awt.Desktop.getDesktop().browse(uri);
1.31 + LOG.log(Level.INFO, "Desktop.browse successfully finished");
1.32 + return null;
1.33 + } catch (UnsupportedOperationException ex) {
1.34 + LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
1.35 + LOG.log(Level.FINE, null, ex);
1.36 + }
1.37 + }
1.38 + {
1.39 + String cmdName = cmd == null ? "xdg-open" : cmd;
1.40 + String[] cmdArr = {
1.41 + cmdName, uri.toString()
1.42 + };
1.43 + LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
1.44 + final Process process = Runtime.getRuntime().exec(cmdArr);
1.45 + return new Object[]{process, null};
1.46 + }
1.47 + }
1.48
1.49 /** Launches the browser */
1.50 public static void main(String... args) throws Exception {
1.51 - BrowserBuilder.newBrowser().
1.52 + BrowserBuilder.newBrowser(new XtrnlBrwsrPrsntr() {
1.53 + @Override
1.54 + protected void showBrwsr(URI page) throws IOException {
1.55 + Main.showBrwsr(page, null);
1.56 + }
1.57 + }).
1.58 loadPage("pages/index.html").
1.59 loadClass(Main.class).
1.60 invoke("onPageLoad", args).
1.61 showAndWait();
1.62 + System.in.read();
1.63 System.exit(0);
1.64 }
1.65