1 33 34 package edu.rice.cs.drjava.ui.config; 35 36 import javax.swing.*; 37 import javax.swing.event.*; 38 import edu.rice.cs.drjava.config.*; 39 import edu.rice.cs.drjava.*; 40 import java.awt.*; 41 42 43 46 public class StringOptionComponent extends OptionComponent<String > { 47 private JTextField _jtf; 48 49 public StringOptionComponent(StringOption opt, String text, Frame parent) { 50 super(opt, text, parent); 51 _jtf = new JTextField(); 52 _jtf.setText(_option.format(DrJava.getConfig().getSetting(_option))); 53 _jtf.getDocument().addDocumentListener(new DocumentListener() { 54 public void insertUpdate(DocumentEvent e) { notifyChangeListeners(); } 55 public void removeUpdate(DocumentEvent e) { notifyChangeListeners(); } 56 public void changedUpdate(DocumentEvent e) { notifyChangeListeners(); } 57 }); 58 } 59 60 61 public StringOptionComponent (StringOption opt, String text, Frame parent, String description) { 62 this(opt, text, parent); 63 setDescription(description); 64 } 65 66 69 public void setDescription(String description) { 70 _jtf.setToolTipText(description); 71 _label.setToolTipText(description); 72 } 73 74 77 public boolean updateConfig() { 78 String oldValue = DrJava.getConfig().getSetting(_option); 79 String newValue = _option.parse(_jtf.getText().trim()); 80 81 if (!oldValue.equals(newValue)) { 82 DrJava.getConfig().setSetting(_option, newValue); 83 } 84 return true; 85 } 86 87 88 public void setValue(String value) { 89 _jtf.setText(value); 90 } 91 92 95 public JComponent getComponent() { return _jtf; } 96 } | Popular Tags |