package com.srbenoit.ui;

import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import com.srbenoit.log.LoggedObject;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.BusinessSkin;

/**
 * A convenience class to house the static code to change to the Nimbus UI.
 */
public final class ChangeUI extends LoggedObject implements Runnable {

    /** the class name of the look and feel to use */
    public static final String NIMBUS = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";

    /** the class name of the look and feel to use */
    public static final String SUBSTANCE = "org.pushingpixels.substance.api.SubstanceLookAndFeel";

    /**
     * Private constructor to prevent instantiation.
     */
    private ChangeUI() {

        super();
    }

    /**
     * Sets the UI to the Nimbus UI.
     */
    static public void changeUI() {

        try {
            UIManager.setLookAndFeel(NIMBUS);
        } catch (Exception e) {
            LOG.log(Level.WARNING, "Failed to set look-and-feel", e);
        }
    }

    /**
     * Sets the UI to the Substance UI.
     */
    static public void changeUISubstance() {

        try {
            SwingUtilities.invokeAndWait(new ChangeUI());
        } catch (InterruptedException e) {
            LOG.log(Level.WARNING, "Failed to set look-and-feel", e);
        } catch (InvocationTargetException e) {
            LOG.log(Level.WARNING, "Failed to set look-and-feel", e);
        }
    }

    /**
     */
    public void run() {

        SubstanceLookAndFeel.setSkin(new BusinessSkin());
    }
}
