1 package org.columba.core.gui.themes.plugin; 17 18 import java.awt.BorderLayout ; 19 import java.awt.Component ; 20 import java.util.List ; 21 22 import javax.swing.DefaultListCellRenderer ; 23 import javax.swing.JLabel ; 24 import javax.swing.JList ; 25 import javax.swing.JPanel ; 26 import javax.swing.JScrollPane ; 27 import javax.swing.ListCellRenderer ; 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 42 public class PlasticLookAndFeelConfigPlugin extends AbstractConfigPlugin { 43 JList list; 44 XmlElement themeElement; 45 46 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 60 public JPanel createPanel() { 61 list = new JList (computeThemes()); 62 list.setCellRenderer(createThemeRenderer()); 63 64 JPanel panel = new JPanel (); 65 panel.setLayout(new BorderLayout ()); 66 67 JScrollPane pane = new JScrollPane (list); 68 panel.add(pane, BorderLayout.NORTH); 69 70 return panel; 71 } 72 73 protected PlasticTheme[] computeThemes() { 74 List themes = PlasticLookAndFeel.getInstalledThemes(); 75 76 return (PlasticTheme[]) themes.toArray(new PlasticTheme[themes.size()]); 77 } 78 79 protected PlasticTheme getTheme(String name) { 80 PlasticTheme[] themes = computeThemes(); 81 82 for (int i = 0; i < themes.length; i++) { 83 String str = themes[i].getName(); 84 85 if (name.equals(str)) { 86 return themes[i]; 87 } 88 } 89 90 return null; 91 } 92 93 96 public void updateComponents(boolean b) { 97 String 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 createThemeRenderer() { 118 return new DefaultListCellRenderer () { 119 public Component getListCellRendererComponent(JList list, 120 Object value, int index, boolean isSelected, 121 boolean cellHasFocus) { 122 JLabel label = (JLabel ) 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 |