import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class SimpleBrowser extends Application {
    public static void main(String[] args) {
        if (args.length != 1) {
            System.err.println("Usage: java SimpleBrowser HTML_file_or_URL");
            System.exit(1);
        }
            
        launch(args);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX SimpleBrowser");

        WebView webView = new WebView();

        com.sun.javafx.webkit.WebConsoleListener.setDefaultListener(
            (aWebView, message, lineNumber, sourceId) ->
            System.err.println("WebConsoleListener: " + message +
                               "[" + aWebView.getEngine().getLocation() +
                               ":" + lineNumber + "]"));

        String location = getParameters().getRaw().get(0);
        if (location.indexOf(":/") < 0) {
            File file = new File(location);
            if (file.isFile()) {
                location = file.toURI().toASCIIString();
            }
        }
        
        webView.getEngine().load(location);

        VBox vBox = new VBox(webView);
        Scene scene = new Scene(vBox, 960, 600);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
} 