1 33 34 package edu.rice.cs.drjava.ui.config; 35 36 import javax.swing.*; 37 import edu.rice.cs.drjava.config.*; 38 import edu.rice.cs.drjava.*; 39 import java.awt.*; 40 import java.awt.event.*; 41 import java.util.Iterator ; 42 43 49 public class ForcedChoiceOptionComponent extends OptionComponent<String > { 50 private JComboBox _comboBox; 51 52 56 public ForcedChoiceOptionComponent(ForcedChoiceOption option, String labelText, Frame parent) { 57 super(option, labelText, parent); 58 59 Iterator <String > values = option.getLegalValues(); 61 _comboBox = new JComboBox(); 62 63 _comboBox.addActionListener(new ActionListener() { 64 public void actionPerformed(ActionEvent e) { 65 notifyChangeListeners(); 66 } 67 }); 68 69 while(values.hasNext()) { 70 String currValue = values.next(); 71 _comboBox.addItem(currValue); 72 } 73 74 resetToCurrent(DrJava.getConfig().getSetting(_option)); 75 } 76 77 80 public ForcedChoiceOptionComponent(ForcedChoiceOption option, String labelText, 81 Frame parent, String description) { 82 this(option, labelText, parent); 83 setDescription(description); 84 } 85 86 90 public void setDescription(String description) { 91 _comboBox.setToolTipText(description); 92 _label.setToolTipText(description); 93 } 94 95 98 public void resetToCurrent(String current) { 99 _comboBox.setSelectedItem(current); 100 101 } 113 114 117 public JComponent getComponent() { 118 return _comboBox; 119 } 120 121 125 public boolean updateConfig() { 126 String oldValue = DrJava.getConfig().getSetting(_option); 127 String newValue = _comboBox.getSelectedItem().toString(); 128 129 if (!newValue.equals(oldValue)) { 130 DrJava.getConfig().setSetting(_option, newValue); 131 } 132 133 return true; 134 } 135 136 139 public void setValue(String value) { 140 resetToCurrent(value); 141 } 142 } | Popular Tags |