View Javadoc

1   package net.sf.mmapps.applications.developer.plaf;
2   
3   import java.awt.event.*;
4   import java.util.*;
5   
6   import javax.swing.*;
7   import javax.swing.plaf.metal.*;
8   import org.apache.commons.logging.*;
9   
10  public class ThemeManager extends DefaultMetalTheme implements ActionListener {
11      private static Log log = LogFactory.getLog(ThemeManager.class);
12      Hashtable themes;
13      ButtonGroup group;
14  
15      public ThemeManager() {
16          themes = new Hashtable();
17          themes.put("Helix", new HelixTheme());
18          themes.put("Charcoal", new CharcoalTheme());
19          themes.put("Developer", new DeveloperTheme());
20          themes.put("MMBase", new MMBaseTheme());
21  
22      }
23  
24      public void setTheme(String name) {
25          MetalTheme t = (MetalTheme) themes.get(name);
26          MetalLookAndFeel.setCurrentTheme(t);
27          try {
28              UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
29          } catch (Exception e) {
30              log.warn(e);
31          }
32      }
33  
34      public JMenu getMenu() {
35          JMenu lookAndFeel = new JMenu("Look & feel");
36          group = new ButtonGroup();
37  
38          Enumeration enumT = themes.keys();
39  
40          while (enumT.hasMoreElements()) {
41              group.add(new JRadioButtonMenuItem((String) enumT.nextElement()));
42          }
43  
44          Enumeration enum = group.getElements();
45          while (enum.hasMoreElements()) {
46              JRadioButtonMenuItem i = (JRadioButtonMenuItem) enum.nextElement();
47              i.addActionListener(this);
48              lookAndFeel.add(i);
49          }
50          return lookAndFeel;
51      }
52  
53      public void actionPerformed(ActionEvent actionEvent) {
54          setTheme(actionEvent.getActionCommand());
55      }
56  }