1 package net.suberic.pooka.gui.propedit; 2 3 import net.suberic.util.gui.propedit.*; 4 import javax.swing.*; 5 import net.suberic.util.*; 6 import java.awt.FlowLayout ; 7 import java.awt.event.*; 8 import java.util.*; 9 10 13 public class LookAndFeelEditor extends ListEditorPane { 14 15 18 protected JComboBox createComboBox() { 19 originalValue = manager.getProperty(property, ""); 20 21 Vector items = loadLnF(); 22 23 JComboBox jcb = new JComboBox(items); 24 25 if (debug) 26 System.out.println("setting to original index " + originalIndex); 27 28 jcb.setSelectedIndex(originalIndex); 29 30 jcb.addItemListener(new ItemListener() { 31 public void itemStateChanged(ItemEvent e) { 32 int newIndex = inputField.getSelectedIndex(); 33 if (newIndex != currentIndex) { 34 String newValue = (String )labelToValueMap.get(inputField.getSelectedItem()); 35 try { 36 firePropertyChangingEvent(newValue); 37 firePropertyChangedEvent(newValue); 38 currentIndex = newIndex; 39 } catch (PropertyValueVetoException pvve) { 40 manager.getFactory().showError(inputField, "Error changing value " + label.getText() + " to " + newValue + ": " + pvve.getReason()); 41 inputField.setSelectedIndex(currentIndex); 42 } 43 } 44 } 45 }); 46 47 return jcb; 48 } 49 50 57 public Vector loadLnF() { 58 HashMap foundLnfs = new HashMap(); 59 Vector items = new Vector(); 60 61 UIManager.LookAndFeelInfo[] feels = UIManager.getInstalledLookAndFeels(); 63 64 for (int i = 0; i < feels.length; i++) { 65 String itemLabel = feels[i].getName(); 66 String itemValue = feels[i].getClassName(); 67 68 try { 69 70 LookAndFeel currentLnf = (LookAndFeel) Class.forName(itemValue).newInstance(); 71 if (currentLnf.isSupportedLookAndFeel()) { 72 if (debug) 73 System.out.println("instantiated " + itemValue + "; adding " + itemLabel); 74 75 if (itemValue.equals(originalValue)) { 76 if (debug) 77 System.out.println("matching " + itemValue + "; settingin originalIndex to " + i); 78 originalIndex=items.size(); 79 currentIndex=items.size(); 80 } 81 items.add(itemLabel); 82 labelToValueMap.put(itemLabel, itemValue); 83 84 foundLnfs.put(itemValue, null); 85 } else { 86 if (debug) 87 System.out.println("not adding " + itemLabel + "; not supported look and feel."); 88 } 89 } catch (Exception e) { 90 if (debug) 92 System.out.println("error instantiating " + itemLabel + "; not adding."); 93 } 94 } 95 96 StringTokenizer tokens; 98 99 String allowedValuesString = manager.getProperty(editorTemplate + ".allowedValues", ""); 100 if (manager.getProperty(allowedValuesString, "") != "") { 101 tokens = new StringTokenizer(manager.getProperty(allowedValuesString, ""), ":"); 102 manager.addPropertyEditorListener(allowedValuesString, new ListEditorListener()); 103 } else { 104 tokens = new StringTokenizer(manager.getProperty(editorTemplate + ".allowedValues", ""), ":"); 105 } 106 107 while (tokens.hasMoreTokens()) { 108 String currentItem = tokens.nextToken(); 109 110 String itemLabel = manager.getProperty(editorTemplate + ".listMapping." + currentItem.toString() + ".label", ""); 111 if (itemLabel.equals("")) 112 itemLabel = currentItem.toString(); 113 114 String itemValue = manager.getProperty(editorTemplate + ".listMapping." + currentItem.toString() + ".value", ""); 115 if (itemValue.equals("")) 116 itemValue = currentItem.toString(); 117 118 if (! foundLnfs.containsKey(itemValue)) { 119 try { 121 LookAndFeel currentLnf = (LookAndFeel) Class.forName(itemValue).newInstance(); 122 if (currentLnf.isSupportedLookAndFeel()) { 123 if (debug) 124 System.out.println("instantiated; adding " + itemLabel); 125 if (itemValue.equals(originalValue)) { 126 if (debug) 127 System.out.println("setting originalIndex to " + items.size()); 128 originalIndex=items.size(); 129 currentIndex=items.size(); 130 } 131 items.add(itemLabel); 132 labelToValueMap.put(itemLabel, itemValue); 133 } else { 134 if (debug) 135 System.out.println("not adding " + itemLabel + "; not supported look and feel."); 136 } 137 } catch (Exception e) { 138 if (debug) 140 System.out.println("error instantiating " + itemLabel + "; not adding."); 141 142 } 143 } 144 } 145 146 if (originalIndex == -1) { 147 items.add(originalValue); 148 labelToValueMap.put(originalValue, originalValue); 149 originalIndex = items.size() - 1; 150 } 151 152 return items; 153 } 154 } 155 | Popular Tags |