/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 */
package com.sun.glass.ui;

public class Applet extends ApplicationBase {
    private static Applet applet;

    private long ptr;
    private View view;

    static public void Run(String args[], final String name, final Launchable launchable) {
        Applet.applet = new Applet();
        Applet.applet.platform = Platform.DeterminePlatform();
        Applet.applet.args = args;
        Applet.applet.name = name;
        Applet.applet.launchable = launchable;
        Applet.applet.run();
    }

    private void run() {
        this.ptr =  Long.parseLong(System.getProperty("sparkle.plugin", "0"));
        System.err.println("Applet.plugin: "+this.ptr);
        if (this.ptr != 0) {
            this.launchable.finishLaunching(this.args);
        } else {
            System.err.println("Applet could not start: no valid plugin found.");
        }
    }

    static public Applet GetApplet() {
        return Applet.applet;
    }

    public long getNativePlugin() {
        return this.ptr;
    }

    native private void _setView(long pluginPtr, long viewPtr);
    public void setView(View view) {
        _setView(this.ptr, view.getNativeView());
        view.setVisible(true);
    }

    public View getView() {
        return this.view;
    }
}
