package pdp.scrabble.utility;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.OceanTheme;
/** Theme selection, for swing appearence.
*/
public class Theme {
private Theme() {
}
/** Set the java frame theme.
* @param theme main theme (Metal, System, Motif, GTK).
* @param subTheme (for Metal, DefaultMetal, Ocean).
*/
public static void initLookAndFeel(String theme, String subTheme) {
String lookAndFeel = null;
if (theme.equals("Metal")) {
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
}
else if (theme.equals("System")) {
lookAndFeel = UIManager.getSystemLookAndFeelClassName();
}
else if (theme.equals("Motif")) {
lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
}
else if (theme.equals("GTK")) {
lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
}
else {
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
}
try {
UIManager.setLookAndFeel(lookAndFeel);
if (theme.equals("Metal")) {
if (subTheme.equals("DefaultMetal")) {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
}
else if (subTheme.equals("Ocean")) {
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
}
else {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
}
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
}
catch (ClassNotFoundException e) {
Display.fatal("Theme selection", "Theme not found !");
}
catch (UnsupportedLookAndFeelException e) {
Display.fatal("Theme selection", "Unsupported theme !");
}
catch (Exception e) {
Display.fatal("Theme selection",
"An error occured during theme selection !");
}
}
}