1 33 34 package edu.rice.cs.drjava.ui.config; 35 36 import javax.swing.*; 37 import edu.rice.cs.drjava.ui.*; 38 import edu.rice.cs.drjava.config.*; 39 import edu.rice.cs.drjava.*; 40 import java.awt.*; 41 import java.awt.event.*; 42 import java.io.File ; 43 import javax.swing.filechooser.FileFilter ; 44 45 import java.util.ArrayList ; 46 47 50 public class VectorFileOptionComponent extends VectorOptionComponent<File > implements OptionConstants { 51 private FileFilter _fileFilter; 52 private JFileChooser _jfc; 53 54 55 public VectorFileOptionComponent (VectorOption<File > opt, String text, Frame parent) { 56 super(opt, text, parent); 58 File workDir = new File (System.getProperty("user.home")); 60 61 _jfc = new JFileChooser(workDir); 62 _jfc.setDialogTitle("Select"); 63 _jfc.setApproveButtonText("Select"); 64 _jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 65 _jfc.setMultiSelectionEnabled(true); 66 _fileFilter = ClassPathFilter.ONLY; 67 } 68 69 70 public VectorFileOptionComponent (VectorOption<File > opt, String text, Frame parent, String description) { 71 this(opt, text, parent); 72 setDescription(description); 73 } 74 75 76 protected void _addButtons() { 77 super._addButtons(); 78 _buttonPanel.add(_moveUpButton); 79 _buttonPanel.add(_moveDownButton); 80 } 81 82 83 public void setValue(ArrayList <File > files) { 84 _listModel.clear(); 85 for (File f: files) _listModel.addElement(f); 86 } 87 88 89 public void setFileFilter(FileFilter fileFilter) { 90 _fileFilter = fileFilter; 91 } 92 93 94 public void chooseFile() { 95 File selection = (File ) _list.getSelectedValue(); 96 if (selection != null) { 97 File parent = selection.getParentFile(); 98 if (parent != null) { 99 _jfc.setCurrentDirectory(parent); 100 } 101 } 102 103 _jfc.setFileFilter(_fileFilter); 104 105 File [] c = null; 106 int returnValue = _jfc.showDialog(_parent, null); 107 if (returnValue == JFileChooser.APPROVE_OPTION) { 108 c = _jfc.getSelectedFiles(); 109 } 110 if (c != null) { 111 for(int i = 0; i < c.length; i++) { 112 _listModel.addElement(c[i]); 113 } 114 } 115 } 116 117 protected Action _getAddAction() { 118 return new AbstractAction("Add") { 119 public void actionPerformed(ActionEvent ae) { 120 chooseFile(); 121 _list.setSelectedIndex(_listModel.getSize() - 1); 122 notifyChangeListeners(); 123 } 124 }; 125 } 126 } 127 | Popular Tags |