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 46 public class IntegerOptionComponent extends OptionComponent<Integer > { 47 private JTextField _jtf; 48 49 public IntegerOptionComponent (IntegerOption 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 63 public IntegerOptionComponent (IntegerOption opt, String text, 64 Frame parent, String description) { 65 this(opt, text, parent); 66 setDescription(description); 67 } 68 69 73 public void setDescription(String description) { 74 _jtf.setToolTipText(description); 75 _label.setToolTipText(description); 76 } 77 78 82 public boolean updateConfig() { 83 84 Integer currentValue = DrJava.getConfig().getSetting(_option); 85 String enteredString = _jtf.getText().trim(); 86 if (currentValue.toString().equals(enteredString)) { 88 return true; 89 } 90 91 Integer enteredValue; 92 try { 93 enteredValue = _option.parse(enteredString); 94 } 95 catch (OptionParseException ope) { 96 showErrorMessage("Invalid Integer!", ope); 97 return false; 98 } 99 100 DrJava.getConfig().setSetting(_option, enteredValue); 101 return true; 102 } 103 104 107 public void setValue(Integer value) { 108 _jtf.setText(_option.format(value)); 109 } 110 111 114 public JComponent getComponent() { return _jtf; } 115 116 } | Popular Tags |