1 package org.columba.core.gui.themes; 20 21 import javax.swing.JFrame ; 22 import javax.swing.JOptionPane ; 23 import javax.swing.SwingUtilities ; 24 import javax.swing.UIManager ; 25 26 import org.columba.api.plugin.IExtension; 27 import org.columba.api.plugin.IExtensionHandler; 28 import org.columba.api.plugin.IExtensionHandlerKeys; 29 import org.columba.core.base.OSInfo; 30 import org.columba.core.config.Config; 31 import org.columba.core.gui.frame.FrameManager; 32 import org.columba.core.gui.themes.plugin.AbstractThemePlugin; 33 import org.columba.core.logging.Logging; 34 import org.columba.core.plugin.PluginManager; 35 import org.columba.core.xml.XmlElement; 36 37 48 public class ThemeSwitcher { 49 50 private static final String QUAQUA_LF = "Quaqua"; 51 private static final String DEFAULT_LF = "Plastic"; 52 53 public static void setTheme() { 54 XmlElement themeConfig = Config.getInstance().get("options") 56 .getElement("/options/gui/theme"); 57 58 if (themeConfig == null) { 59 XmlElement themeParent = Config.getInstance().get("options") 60 .getElement("/options/gui"); 61 themeConfig = new XmlElement("theme"); 62 themeParent.addElement(themeConfig); 63 } 64 65 String pluginName = null; 66 try { 67 IExtensionHandler handler = PluginManager 69 .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_THEME); 70 71 pluginName = themeConfig.getAttribute("name"); 72 73 if (pluginName == null) { 75 pluginName = ThemeSwitcher.getPlatformDefaultTheme(); 76 themeConfig.addAttribute("name", DEFAULT_LF); 77 themeConfig.addAttribute("theme", "Experience Blue"); 78 } 79 80 AbstractThemePlugin theme = null; 81 82 IExtension extension = handler.getExtension(pluginName); 83 84 theme = (AbstractThemePlugin) extension.instanciateExtension(null); 86 87 theme.setLookAndFeel(); 89 } catch (Exception ex) { 90 91 if (Logging.DEBUG) 92 ex.printStackTrace(); 93 94 JOptionPane.showMessageDialog(FrameManager.getInstance() 95 .getActiveFrame(), "Error while trying to load " 96 + pluginName 97 + " Look and Feel.\nSwitching back to default."); 98 99 try { 100 UIManager.setLookAndFeel(UIManager 102 .getCrossPlatformLookAndFeelClassName()); 103 } catch (Exception e) { 104 e.printStackTrace(); 105 } 106 } 107 } 112 113 public static String getPlatformDefaultTheme() { 114 if (OSInfo.isMac()) { 115 return QUAQUA_LF; 116 } else { 117 return DEFAULT_LF; 118 } 119 } 120 121 public static void updateFrame(JFrame frame) { 122 final JFrame f = frame; 123 124 SwingUtilities.invokeLater(new Runnable () { 125 126 public void run() { 127 SwingUtilities.updateComponentTreeUI(f); 128 } 129 }); 130 } 131 } | Popular Tags |