/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in 
 * compliance with the License.  You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is Protege-2000.
 *
 * The Initial Developer of the Original Code is Stanford University. Portions
 * created by Stanford University are Copyright (C) 2007.  All Rights Reserved.
 *
 * Protege was developed by Stanford Medical Informatics
 * (http://www.smi.stanford.edu) at the Stanford University School of Medicine
 * with support from the National Library of Medicine, the National Science
 * Foundation, and the Defense Advanced Research Projects Agency.  Current
 * information about Protege can be obtained at http://protege.stanford.edu.
 *
 */

package edu.stanford.smi.protege.util;

import javax.swing.JTree;
import javax.swing.PopupFactory;

import com.jgoodies.looks.FontPolicies;
import com.jgoodies.looks.FontPolicy;
import com.jgoodies.looks.FontSet;
import com.jgoodies.looks.FontSets;
import com.jgoodies.looks.Options;
import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import com.jgoodies.looks.plastic.PlasticTheme;

public class LookAndFeelUtil {

	public static void setUpPlasticLF() {
		try {
			 PopupFactory.setSharedInstance(new PopupFactory());
	         PlasticLookAndFeel.setCurrentTheme(PlasticHack.createTheme());
	         PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE);

	         FontSet fontSet = FontSets.createDefaultFontSet(ProtegePlasticTheme.DEFAULT_FONT);
	         FontPolicy fixedPolicy = FontPolicies.createFixedPolicy(fontSet);
	         PlasticLookAndFeel.setFontPolicy(fixedPolicy);

		} catch (Throwable t) {
			Log.getLogger().warning("Could not load Plastic Look and Feel. " +
					"Probably looks.jar is not on the classpath. Error message: " + t.getMessage());
		}
	}


	public static void setTreeLineStyle(JTree comp) {
		try {
			comp.putClientProperty(Options.TREE_LINE_STYLE_KEY, Options.TREE_LINE_STYLE_NONE_VALUE);
		} catch (Throwable t) {
			Log.getLogger().warning("Could not set tree line style. Probably looks.jar is not on the classpath.");
		}
	}


	// This hack gets around a classloader problem if the looks jar is not on the classpath
	static class PlasticHack {
	    public static PlasticTheme createTheme() {
	        return new ProtegePlasticTheme();
	    }
	}

}
