KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > themes > plugin > PlasticLookAndFeelConfigPlugin


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.themes.plugin;
17
18 import java.awt.BorderLayout JavaDoc;
19 import java.awt.Component JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.swing.DefaultListCellRenderer JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JList JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.JScrollPane JavaDoc;
27 import javax.swing.ListCellRenderer JavaDoc;
28
29 import org.columba.core.config.Config;
30 import org.columba.core.gui.plugin.AbstractConfigPlugin;
31 import org.columba.core.xml.XmlElement;
32
33 import com.jgoodies.looks.plastic.PlasticLookAndFeel;
34 import com.jgoodies.looks.plastic.PlasticTheme;
35
36
37 /**
38  * Asks the user which theme he wants to use.
39  *
40  * @author fdietz
41  */

42 public class PlasticLookAndFeelConfigPlugin extends AbstractConfigPlugin {
43     JList JavaDoc list;
44     XmlElement themeElement;
45
46     /**
47      *
48      */

49     public PlasticLookAndFeelConfigPlugin() {
50         super();
51
52         XmlElement options = Config.getInstance().get("options").getElement("/options");
53         XmlElement gui = options.getElement("gui");
54         themeElement = gui.getElement("theme");
55     }
56
57     /* (non-Javadoc)
58      * @see org.columba.core.gui.plugin.AbstractConfigPlugin#createPanel()
59      */

60     public JPanel JavaDoc createPanel() {
61         list = new JList JavaDoc(computeThemes());
62         list.setCellRenderer(createThemeRenderer());
63
64         JPanel JavaDoc panel = new JPanel JavaDoc();
65         panel.setLayout(new BorderLayout JavaDoc());
66
67         JScrollPane JavaDoc pane = new JScrollPane JavaDoc(list);
68         panel.add(pane, BorderLayout.NORTH);
69
70         return panel;
71     }
72
73     protected PlasticTheme[] computeThemes() {
74         List JavaDoc themes = PlasticLookAndFeel.getInstalledThemes();
75
76         return (PlasticTheme[]) themes.toArray(new PlasticTheme[themes.size()]);
77     }
78
79     protected PlasticTheme getTheme(String JavaDoc name) {
80         PlasticTheme[] themes = computeThemes();
81
82         for (int i = 0; i < themes.length; i++) {
83             String JavaDoc str = themes[i].getName();
84
85             if (name.equals(str)) {
86                 return themes[i];
87             }
88         }
89
90         return null;
91     }
92
93     /* (non-Javadoc)
94      * @see org.columba.core.gui.plugin.AbstractConfigPlugin#updateComponents(boolean)
95      */

96     public void updateComponents(boolean b) {
97         String JavaDoc theme = themeElement.getAttribute("theme");
98
99         if (b) {
100             if (theme != null) {
101                 PlasticTheme t = getTheme(theme);
102
103                 if (t != null) {
104                     list.setSelectedValue(t, true);
105                 }
106             }
107         } else {
108             PlasticTheme t = (PlasticTheme) list.getSelectedValue();
109
110             if (t != null) {
111                 themeElement.addAttribute("theme", t.getName());
112             }
113         }
114     }
115
116     
117     private ListCellRenderer JavaDoc createThemeRenderer() {
118         return new DefaultListCellRenderer JavaDoc() {
119                 public Component JavaDoc getListCellRendererComponent(JList JavaDoc list,
120                     Object JavaDoc value, int index, boolean isSelected,
121                     boolean cellHasFocus) {
122                     JLabel JavaDoc label = (JLabel JavaDoc) super.getListCellRendererComponent(list,
123                             value, index, isSelected, cellHasFocus);
124                     PlasticTheme theme = (PlasticTheme) value;
125                     label.setText(theme.getName());
126
127                     return label;
128                 }
129             };
130     }
131 }
132
Popular Tags