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

import java.security.AccessController;
import java.security.PrivilegedAction;

public class Platform {
    public static final String MAC = "Mac";
    public static final String WINDOWS = "Win";
    public static final String X11 = "X11";
    public static final String GTK = "Gtk";
    public static final String UNKNOWN = "unknown";
 
    static private String type = null;

    static public synchronized String DeterminePlatform() {
        if (type == null) {

            // Provide for a runtime override, allowing X11 or EGL for example
            String userPlatform =
                AccessController.doPrivileged(new PrivilegedAction<String>() {
                    public String run() {
                        return System.getProperty("glass.platform");
                    }
                });

            if (userPlatform != null) {
                if (userPlatform.equals("macosx"))
                   type = MAC;
                else if (userPlatform.equals("windows"))
                   type = WINDOWS;
                else if (userPlatform.equals("linux"))
                   type = GTK;
                else if (userPlatform.equals("x11"))
                   type = X11;
                else if (userPlatform.equals("gtk"))
                   type = GTK;
                else
                   type = userPlatform;
                return type;
            }

            String osName = System.getProperty("os.name");
            String osNameLowerCase = osName.toLowerCase();
            if (osNameLowerCase.startsWith("mac") || osNameLowerCase.startsWith("darwin")) {
                type = MAC;
            } else if (osNameLowerCase.startsWith("wind")) {
                type = WINDOWS;
            } else if (osNameLowerCase.startsWith("linux")) {
                type = GTK;
            }
        }

        return type;
    }
}
