1 26 package org.objectweb.openccm.explorer.menu; 27 28 29 import javax.swing.JFileChooser ; 30 import javax.swing.JTextField ; 31 import javax.swing.JLabel ; 32 import javax.swing.JButton ; 33 import javax.swing.AbstractAction ; 34 import javax.swing.Box ; 35 import javax.swing.BoxLayout ; 36 import javax.swing.SwingConstants ; 37 38 import java.awt.Component ; 39 import java.awt.Dimension ; 40 import java.io.File ; 41 42 49 public class FileChooserBox extends Box { 50 51 53 54 protected JFileChooser fileChooser_; 55 56 57 protected File file_; 58 59 62 public FileChooserBox(String label, int fileFilterType) { 63 super(BoxLayout.X_AXIS); 64 fileChooser_ = JFileChooserSingleton.getInstance(fileFilterType); 65 add(Box.createHorizontalGlue()); 66 JLabel browserLabel = new JLabel (label, SwingConstants.RIGHT); 67 browserLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); 68 browserLabel.setAlignmentY(Component.CENTER_ALIGNMENT); 69 add(browserLabel); 70 add(Box.createHorizontalStrut(5)); 71 JTextField fileName = new JTextField (); 72 fileName.setEditable(false); 73 fileName.setPreferredSize(new Dimension (200, 20)); 74 fileName.setMaximumSize(new Dimension (200, 20)); 75 add(fileName); 76 add(Box.createHorizontalStrut(5)); 77 JButton browseButton = new JButton (new BrowseAction(this, fileName)); 78 browseButton.setPreferredSize(new Dimension (20, 20)); 79 browseButton.setMaximumSize(new Dimension (20, 20)); 80 add(browseButton); 81 } 82 83 84 public File getFile() { 85 return file_; 86 } 87 88 91 protected class BrowseAction extends AbstractAction { 92 93 94 protected Component parent_; 95 96 97 protected JTextField textField_; 98 99 102 protected BrowseAction(Component parent, JTextField textField) { 103 super("...", null); 104 parent_ = parent; 105 textField_ = textField; 106 } 107 108 public void actionPerformed(java.awt.event.ActionEvent ae) { 109 int returnVal = fileChooser_.showOpenDialog(parent_); 110 if (returnVal == JFileChooser.APPROVE_OPTION) { 111 file_ = fileChooser_.getSelectedFile(); 112 textField_.setText(fileChooser_.getSelectedFile().toString()); 113 } 114 } 115 116 } 117 118 } 119 | Popular Tags |