1 7 package org.jdesktop.demo; 8 9 import java.awt.Color ; 10 import java.awt.EventQueue ; 11 import java.awt.Font ; 12 import java.util.HashMap ; 13 import java.util.Iterator ; 14 import java.util.List ; 15 import java.util.Map ; 16 17 import javax.swing.JFrame ; 18 import javax.swing.UIManager ; 19 import javax.swing.plaf.ColorUIResource ; 20 import javax.swing.plaf.metal.MetalLookAndFeel ; 21 import javax.swing.plaf.metal.MetalTheme ; 22 23 24 import com.jgoodies.looks.plastic.PlasticLookAndFeel; 25 import com.jgoodies.looks.plastic.PlasticTheme; 26 27 31 public class Main { 32 35 private static Map <String ,MetalTheme > THEMES = null; 36 37 public static void main(String [] args) { 38 CmdLineParser parser = new CmdLineParser(); 39 CmdLineParser.Option wOption = parser.addStringOption('w', "MainWindow"); 40 try { 41 parser.parse(args); 42 } catch (CmdLineParser.UnknownOptionException ex) { 43 ex.printStackTrace(); 44 printUsage(); 45 System.exit(1); 46 } catch (CmdLineParser.IllegalOptionValueException ex) { 47 ex.printStackTrace(); 48 printUsage(); 49 System.exit(2); 50 } 51 final String wValue = (String )parser.getOptionValue(wOption); 53 54 setAppLookAndFeel(); 55 EventQueue.invokeLater(new Runnable () { 56 public void run() { 57 try { 58 JFrame mainWindow = (JFrame )Class.forName(wValue).newInstance(); 59 mainWindow.setVisible(true); 60 } catch (Exception e) { 61 System.err.println("Failed to find, create, and open the MainWindow. " + 62 "The MainWindow class was '" + wValue + "'"); 63 e.printStackTrace(); 64 printUsage(); 65 System.exit(3); 66 } 67 } 68 }); 69 } 70 71 private static void printUsage() { 72 System.out.println("Pass in the name of the JFrame that is to be the main window " + 73 "for this app, like so:\n" + 74 "-w org.jdesktop.binding.demo.blar.BlarWindow"); 75 } 76 77 82 private static void setAppLookAndFeel() { 83 try { 85 if (THEMES == null) { 87 initThemes(); 88 } 89 String defaultClassName = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"; 92 String defaultThemeName = "com.jgoodies.looks.plastic.theme.ExperienceBlue"; 93 String className = System.getProperty("org.jdesktop.demo.LookAndFeel", defaultClassName); 94 String themeName = System.getProperty("org.jdesktop.demo.Theme", defaultThemeName); 95 96 Object theme = THEMES.get(themeName); 98 if (theme == null) { 99 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 100 } else if (theme instanceof PlasticTheme){ 101 PlasticLookAndFeel.setMyCurrentTheme((PlasticTheme)THEMES.get(themeName)); 102 UIManager.setLookAndFeel(className); 103 } else if (theme instanceof MetalTheme ) { 104 MetalLookAndFeel.setCurrentTheme((MetalTheme )THEMES.get(themeName)); 105 UIManager.setLookAndFeel(className); 106 } 107 108 if (className.equals("com.jgoodies.plaf.windows.ExtWindowsLookAndFeel")) { 110 UIManager.put("JTitledPanel.title.foreground", new ColorUIResource (Color.WHITE)); 111 UIManager.put("JTitledPanel.title.darkBackground", UIManager.getColor("InternalFrame.activeTitleBackground")); 112 UIManager.put("JTitledPanel.title.lightBackground", UIManager.getColor("InternalFrame.activeTitleGradient")); 113 UIManager.put("JScrollUp.background", UIManager.getColor("InternalFrame.activeTitleGradient")); 114 UIManager.put("JTitledPanel.title.font", UIManager.getFont("Button.font").deriveFont(Font.BOLD)); 115 } else if (className.equals("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")) { 116 UIManager.put("JTitledPanel.title.foreground", new ColorUIResource (Color.WHITE)); 117 UIManager.put("JTitledPanel.title.darkBackground", UIManager.getColor("InternalFrame.activeTitleBackground")); 118 UIManager.put("JTitledPanel.title.lightBackground", UIManager.getColor("InternalFrame.activeTitleGradient")); 119 UIManager.put("JScrollUp.background", UIManager.getColor("InternalFrame.activeTitleGradient")); 120 UIManager.put("JTitledPanel.title.font", UIManager.getFont("Button.font").deriveFont(Font.BOLD)); 121 UIManager.put("JHyperLink.unclickedColor", new ColorUIResource (Color.WHITE)); 122 UIManager.put("JHyperLink.clickedColor", new ColorUIResource (Color.WHITE)); 123 } else if (className.equals("com.jgoodies.looks.plastic.PlasticXPLookAndFeel")) { 124 UIManager.put("JTitledPanel.title.foreground", new ColorUIResource (Color.WHITE)); 125 UIManager.put("JScrollUp.background", UIManager.getColor("InternalFrame.activeTitleGradient")); 126 UIManager.put("JTitledPanel.title.font", UIManager.getFont("Button.font").deriveFont(Font.BOLD)); 127 UIManager.put("JHyperLink.unclickedColor", new ColorUIResource (Color.WHITE)); 128 UIManager.put("JHyperLink.clickedColor", new ColorUIResource (Color.WHITE)); 129 } 130 131 } catch (Exception e) { 132 e.printStackTrace(); 133 } 134 135 } 136 137 140 private static void initThemes() { 141 THEMES = new HashMap <String ,MetalTheme >(); 142 List list = PlasticLookAndFeel.getInstalledThemes(); 143 for (Iterator itr = list.iterator(); itr.hasNext();) { 144 PlasticTheme element = (PlasticTheme) itr.next(); 145 THEMES.put(element.getClass().getName(), element); 146 } 147 THEMES.put("javax.swing.plaf.metal.DefaultMetalTheme", new javax.swing.plaf.metal.DefaultMetalTheme ()); 149 THEMES.put("javax.swing.plaf.metal.OceanTheme", new javax.swing.plaf.metal.OceanTheme ()); 150 } 151 } | Popular Tags |