// Copyright 1996, Marimba Inc. All Rights Reserved.


// @(#)Environment.java, 1.5, 11/29/96





package marimba.util;





import java.net.*;


import java.applet.AppletContext;





import marimba.desktop.Desktop;





/**


 * An interface to some of the native Desktop facilities.


 *


 * @author	Arthur van Hoff


 * @version 	1.5, 11/29/96


 */


public abstract class Environment {


    static Desktop desktop;


    static AppletContext context;


    static boolean nativeDesktop = true;


    static Object clipboard;





    /**


     * Try to get the native desktop


     */


    static {


	try {


	    desktop = Desktop.getDesktop();


	} catch (Throwable e) {


	}


    }





    /**


     * Set the context in case of an applet


     */


    public static void setAppletContext(AppletContext context) {


	Environment.context = context;


    }





    /**


     * Show a URL (specified as a string)


     */


    public static boolean showURL(String url) {


	if (desktop != null) {


	    return desktop.showURL(url);


	}


	if (context != null) {


	    try {


		context.showDocument(new URL(url));


		return true;


	    } catch (MalformedURLException e) {


	    }


	}


	return false;


    }





    /**


     * Show a URL.


     */


    public static boolean showURL(URL url) {


	if (desktop != null) {


	    return desktop.showURL(url);


	}


	if (context != null) {


	    context.showDocument(url);


	    return true;


	}


	return false;


    }





    /**


     * Show a URL in a frame. This currently only works


     * inside applets.


     */


    public static boolean showURL(URL url, String frame) {


	if (desktop != null) {


	    return desktop.showURL(url);


	}


	if (context != null) {


	    context.showDocument(url, frame);


	    return true;


	}


	return false;


    }





    /**


     * Put something on the clipboard


     */


    public static void setClipboard(Object arg) {


	if (desktop != null) {


	    desktop.setClipboard(arg);


	    return;


	}


	clipboard = arg;


    }





    /**


     * Get something from the clipboard.


     */


    public static Object getClipboard() {


	if (desktop != null) {


	    return desktop.getClipboard();


	}


	return clipboard;


    }


}


