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 edu.rice.cs.util.swing.FileSelectorComponent; 41 import java.awt.*; 42 import java.io.File ; 43 import javax.swing.filechooser.FileFilter ; 44 45 51 public class FileOptionComponent extends OptionComponent<File > implements OptionConstants { 52 53 private FileSelectorComponent _component; 59 60 public FileOptionComponent (FileOption opt, String text, Frame parent, JFileChooser jfc) { 61 super(opt, text, parent); 62 _component = new FileSelectorComponent(parent, jfc, 30, 10f); 94 File setting = DrJava.getConfig().getSetting(_option); 95 if (setting != _option.getDefault()) { 96 _component.setFileField(setting); 97 } 98 _component.getFileField().getDocument().addDocumentListener(new DocumentListener() { 99 public void insertUpdate(DocumentEvent e) { notifyChangeListeners(); } 100 public void removeUpdate(DocumentEvent e) { notifyChangeListeners(); } 101 public void changedUpdate(DocumentEvent e) { notifyChangeListeners(); } 102 }); 103 } 104 105 106 public FileOptionComponent (FileOption opt, String text, Frame parent, String description, JFileChooser jfc) { 107 this(opt, text, parent, jfc); 108 setDescription(description); 109 } 110 111 114 public void setDescription(String description) { 115 _component.setToolTipText(description); 116 _label.setToolTipText(description); 119 } 120 121 125 public boolean updateConfig() { 126 File componentFile = _component.getFileFromField(); 127 File currentFile = DrJava.getConfig().getSetting(_option); 128 129 if (componentFile != null && !componentFile.equals(currentFile)) { 130 DrJava.getConfig().setSetting(_option, componentFile); 131 } 132 else if (componentFile == null) { 133 DrJava.getConfig().setSetting(_option, _option.getDefault()); 134 } 135 136 return true; 137 } 138 139 140 public void setValue(File value) { 141 _component.setFileField(value); 144 } 145 146 149 public JComponent getComponent() { 150 return _component; 151 } 152 153 161 164 public void setFileFilter(FileFilter fileFilter) { 165 _component.setFileFilter(fileFilter); 167 } 168 169 191 } 220 | Popular Tags |