package javax.swing;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import java.util.Locale;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalLookAndFeel;
public class UIManager implements Serializable
{
public static class LookAndFeelInfo
{
String name, clazz;
public LookAndFeelInfo(String name,
String clazz)
{
this.name = name;
this.clazz = clazz;
}
public String getName()
{
return name;
}
public String getClassName()
{
return clazz;
}
}
private static final long serialVersionUID = -5547433830339189365L;
static LookAndFeelInfo [] installed = {
new LookAndFeelInfo ("Metal", "javax.swing.plaf.metal.MetalLookAndFeel")
};
static LookAndFeel[] aux_installed;
static LookAndFeel look_and_feel = new MetalLookAndFeel();
public UIManager()
{
}
public static void addPropertyChangeListener(PropertyChangeListener listener)
{
}
public static void removePropertyChangeListener(PropertyChangeListener listener)
{
}
public static PropertyChangeListener[] getPropertyChangeListeners()
{
throw new Error ("Not implemented");
}
public static void addAuxiliaryLookAndFeel (LookAndFeel l)
{
if (aux_installed == null)
{
aux_installed = new LookAndFeel[1];
aux_installed[0] = l;
return;
}
LookAndFeel[] T = new LookAndFeel[ aux_installed.length+1 ];
System.arraycopy(aux_installed, 0, T, 0, aux_installed.length);
aux_installed = T;
aux_installed[aux_installed.length-1] = l;
}
public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
{
if (aux_installed == null)
return false;
for (int i=0;i<aux_installed.length;i++)
{
if (aux_installed[i] == laf)
{
aux_installed[ i ] = aux_installed[aux_installed.length-1];
LookAndFeel[] T = new LookAndFeel[ aux_installed.length-1 ];
System.arraycopy (aux_installed, 0, T, 0, aux_installed.length-1);
aux_installed = T;
return true;
}
}
return false;
}
public static LookAndFeel[] getAuxiliaryLookAndFeels()
{
return aux_installed;
}
public static Object get(Object key)
{
return getLookAndFeel().getDefaults().get(key);
}
public static Object get(Object key, Locale locale)
{
return getLookAndFeel().getDefaults().get(key ,locale);
}
public static boolean getBoolean(Object key)
{
Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key);
return value != null ? value.booleanValue() : false;
}
public static boolean getBoolean(Object key, Locale locale)
{
Boolean value = (Boolean) getLookAndFeel().getDefaults().get(key, locale);
return value != null ? value.booleanValue() : false;
}
public static Border getBorder(Object key)
{
return (Border) getLookAndFeel().getDefaults().get(key);
}
public static Border getBorder(Object key, Locale locale)
{
return (Border) getLookAndFeel().getDefaults().get(key, locale);
}
public static Color getColor(Object key)
{
return (Color) getLookAndFeel().getDefaults().get(key);
}
public static Color getColor(Object key, Locale locale)
{
return (Color) getLookAndFeel().getDefaults().get(key);
}
public static String getCrossPlatformLookAndFeelClassName()
{
return "javax.swing.plaf.metal.MetalLookAndFeel";
}
public static UIDefaults getDefaults()
{
return getLookAndFeel().getDefaults();
}
public static Dimension getDimension(Object key)
{
return (Dimension) getLookAndFeel().getDefaults().get(key);
}
public static Dimension getDimension(Object key, Locale locale)
{
return (Dimension) getLookAndFeel().getDefaults().get(key, locale);
}
public static Font getFont(Object key)
{
return (Font) getLookAndFeel().getDefaults().get(key);
}
public static Font getFont(Object key, Locale locale)
{
return (Font) getLookAndFeel().getDefaults().get(key ,locale);
}
public static Icon getIcon(Object key)
{
return (Icon) getLookAndFeel().getDefaults().get(key);
}
public static Icon getIcon(Object key, Locale locale)
{
return (Icon) getLookAndFeel().getDefaults().get(key, locale);
}
public static Insets getInsets(Object key)
{
return (Insets) getLookAndFeel().getDefaults().getInsets(key);
}
public static Insets getInsets(Object key, Locale locale)
{
return (Insets) getLookAndFeel().getDefaults().getInsets(key, locale);
}
public static LookAndFeelInfo[] getInstalledLookAndFeels()
{
return installed;
}
public static int getInt(Object key)
{
Integer x = (Integer) getLookAndFeel().getDefaults().get(key);
if (x == null)
return 0;
return x.intValue();
}
public static int getInt(Object key, Locale locale)
{
Integer x = (Integer) getLookAndFeel().getDefaults().get(key, locale);
if (x == null)
return 0;
return x.intValue();
}
public static LookAndFeel getLookAndFeel()
{
return look_and_feel;
}
public static UIDefaults getLookAndFeelDefaults()
{
return getLookAndFeel().getDefaults();
}
public static String getString(Object key)
{
return (String) getLookAndFeel().getDefaults().get(key);
}
public static String getString(Object key, Locale locale)
{
return (String) getLookAndFeel().getDefaults().get(key, locale);
}
public static String getSystemLookAndFeelClassName()
{
return getCrossPlatformLookAndFeelClassName();
}
public static ComponentUI getUI(JComponent target)
{
return getDefaults().getUI(target);
}
public static void installLookAndFeel(String name, String className)
{
}
public static void installLookAndFeel(LookAndFeelInfo info)
{
}
public static Object put(Object key, Object value)
{
return getLookAndFeel().getDefaults().put(key,value);
}
public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
{
}
public static void setLookAndFeel(LookAndFeel newLookAndFeel)
throws UnsupportedLookAndFeelException
{
if (! newLookAndFeel.isSupportedLookAndFeel())
throw new UnsupportedLookAndFeelException(newLookAndFeel.getName());
if (look_and_feel != null)
look_and_feel.uninitialize();
look_and_feel = newLookAndFeel;
look_and_feel.initialize();
}
public static void setLookAndFeel (String className)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException
{
Class c = Class.forName(className);
LookAndFeel a = (LookAndFeel) c.newInstance(); setLookAndFeel(a);
}
}