001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.themes.plugin;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Component;
020: import java.util.List;
021:
022: import javax.swing.DefaultListCellRenderer;
023: import javax.swing.JLabel;
024: import javax.swing.JList;
025: import javax.swing.JPanel;
026: import javax.swing.JScrollPane;
027: import javax.swing.ListCellRenderer;
028:
029: import org.columba.core.config.Config;
030: import org.columba.core.gui.plugin.AbstractConfigPlugin;
031: import org.columba.core.xml.XmlElement;
032:
033: import com.jgoodies.looks.plastic.PlasticLookAndFeel;
034: import com.jgoodies.looks.plastic.PlasticTheme;
035:
036: /**
037: * Asks the user which theme he wants to use.
038: *
039: * @author fdietz
040: */
041: public class PlasticLookAndFeelConfigPlugin extends
042: AbstractConfigPlugin {
043: JList list;
044: XmlElement themeElement;
045:
046: /**
047: *
048: */
049: public PlasticLookAndFeelConfigPlugin() {
050: super ();
051:
052: XmlElement options = Config.getInstance().get("options")
053: .getElement("/options");
054: XmlElement gui = options.getElement("gui");
055: themeElement = gui.getElement("theme");
056: }
057:
058: /* (non-Javadoc)
059: * @see org.columba.core.gui.plugin.AbstractConfigPlugin#createPanel()
060: */
061: public JPanel createPanel() {
062: list = new JList(computeThemes());
063: list.setCellRenderer(createThemeRenderer());
064:
065: JPanel panel = new JPanel();
066: panel.setLayout(new BorderLayout());
067:
068: JScrollPane pane = new JScrollPane(list);
069: panel.add(pane, BorderLayout.NORTH);
070:
071: return panel;
072: }
073:
074: protected PlasticTheme[] computeThemes() {
075: List themes = PlasticLookAndFeel.getInstalledThemes();
076:
077: return (PlasticTheme[]) themes.toArray(new PlasticTheme[themes
078: .size()]);
079: }
080:
081: protected PlasticTheme getTheme(String name) {
082: PlasticTheme[] themes = computeThemes();
083:
084: for (int i = 0; i < themes.length; i++) {
085: String str = themes[i].getName();
086:
087: if (name.equals(str)) {
088: return themes[i];
089: }
090: }
091:
092: return null;
093: }
094:
095: /* (non-Javadoc)
096: * @see org.columba.core.gui.plugin.AbstractConfigPlugin#updateComponents(boolean)
097: */
098: public void updateComponents(boolean b) {
099: String theme = themeElement.getAttribute("theme");
100:
101: if (b) {
102: if (theme != null) {
103: PlasticTheme t = getTheme(theme);
104:
105: if (t != null) {
106: list.setSelectedValue(t, true);
107: }
108: }
109: } else {
110: PlasticTheme t = (PlasticTheme) list.getSelectedValue();
111:
112: if (t != null) {
113: themeElement.addAttribute("theme", t.getName());
114: }
115: }
116: }
117:
118: private ListCellRenderer createThemeRenderer() {
119: return new DefaultListCellRenderer() {
120: public Component getListCellRendererComponent(JList list,
121: Object value, int index, boolean isSelected,
122: boolean cellHasFocus) {
123: JLabel label = (JLabel) super
124: .getListCellRendererComponent(list, value,
125: index, isSelected, cellHasFocus);
126: PlasticTheme theme = (PlasticTheme) value;
127: label.setText(theme.getName());
128:
129: return label;
130: }
131: };
132: }
133: }
|