1 package net.suberic.util.gui.propedit; 2 import javax.swing.*; 3 import net.suberic.util.*; 4 import java.awt.FlowLayout ; 5 import java.awt.event.*; 6 import java.util.*; 7 8 12 public class DefaultBooleanEditorPane extends ListEditorPane { 13 14 17 protected JComboBox createComboBox() { 18 String originalValue = manager.getProperty(property, ""); 19 originalIndex=-1; 20 currentIndex = -1; 21 Vector items = new Vector(); 22 23 HashMap valueMap = new HashMap(); 24 valueMap.put("False", "False"); 25 valueMap.put("True", "True"); 26 valueMap.put("Default", ""); 27 28 Set keys = valueMap.keySet(); 29 Iterator keyIter = keys.iterator(); 30 for (int i = 0; keyIter.hasNext(); i++) { 31 String currentLabel = (String ) keyIter.next(); 32 String currentValue = (String ) valueMap.get(currentLabel); 33 if (currentValue.equals(originalValue)) { 34 originalIndex=i; 35 currentIndex=i; 36 } 37 items.add(currentLabel); 38 } 39 40 if (originalIndex == -1) { 41 items.add(originalValue); 42 labelToValueMap.put(originalValue, originalValue); 43 originalIndex = items.size() - 1; 44 } 45 46 JComboBox jcb = new JComboBox(items); 47 jcb.setSelectedIndex(originalIndex); 48 49 labelToValueMap = valueMap; 50 51 jcb.addItemListener(new ItemListener() { 52 public void itemStateChanged(ItemEvent e) { 53 int newIndex = inputField.getSelectedIndex(); 54 if (newIndex != currentIndex) { 55 String newValue = (String )labelToValueMap.get(inputField.getSelectedItem()); 56 try { 57 firePropertyChangingEvent(newValue); 58 firePropertyChangedEvent(newValue); 59 currentIndex = newIndex; 60 } catch (PropertyValueVetoException pvve) { 61 manager.getFactory().showError(inputField, "Error changing value " + label.getText() + " to " + newValue + ": " + pvve.getReason()); 62 inputField.setSelectedIndex(currentIndex); 63 } 64 } 65 } 66 }); 67 68 return jcb; 69 } 70 71 } 72 | Popular Tags |