/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */

/*

The glass.jar in this example is in /Volumes/work/jfx/artifacts/sdk/build/lib/desktop/
The libglass.dylib in this example is in /Volumes/work/jfx/artifacts/sdk/rt/bin/

Adjust those paths below as needed

To compile:

javac -classpath /Volumes/work/jfx/artifacts/sdk/build/lib/desktop/glass.jar Simple.java

To run:

java -Djava.library.path=/Volumes/work/jfx/artifacts/sdk/rt/bin/ -classpath /Volumes/work/jfx/artifacts/sdk/build/lib/desktop/glass.jar:. Simple

*/

import com.sun.glass.ui.*;
import com.sun.glass.events.*;

import java.util.Map;
import java.util.HashMap;

public class Simple implements Launchable
{
    public static void main(String args[])
    {
        Application.Run(args, new Simple());
    }
    
    public void finishLaunching(String[] args)
    {
        try
        {
            Application app = Application.GetApplication();
            app.setTerminateWhenLastWindowClosed(true);
            app.setEventHandler(new Application.EventHandler()
            {
                @Override
                public void handleQuitAction(Application app, long time)
                {
                    app.terminate();
                }
            });
            
            Window window = app.createWindow(Screen.getMainScreen(), Window.TITLED|Window.CLOSABLE);
            window.setEventHandler(new CloseEventHandler());
            
            MenuBar menuBar = app.createMenuBar();
            app.installDefaultMenus(menuBar);
            window.setMenuBar(menuBar);
            
            View view = app.createView(new NullGraphics());
            window.setView(view);
            
            window.setBackground(1, 0, 0);
            window.setTitle("simple red Glass window");
            window.setPosition(101, 102);
            window.setContentSize(514, 514);
            window.setVisible(true);
        }
        catch (Throwable t)
        {
            System.err.println(t);
        }
    }
    
    class CloseEventHandler extends Window.EventHandler
    {
        @Override
        public void handleWindowEvent(Window window, long time, int type)
        {
            if (type == WindowEvent.CLOSE)
            {
                Application.GetApplication().terminate();
            }
        }
    }
    
    class NullGraphics extends Pen
    {
        @Override
        public Map getCapabilities()
        {
            return new HashMap();
        }
        
        @Override
        public void paint(long time, int width, int height)
        {
            // NOP
        }
    }
}
