| 1 package rero.dck.items; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 import javax.swing.*; 7 import javax.swing.event.*; 8 9 import java.io.*; 10 11 import rero.dck.*; 12 import rero.config.*; 13 14 public class DirectoryInput extends SuperInput implements ActionListener 15 { 16 protected JLabel label; 17 protected FileLink text; 18 protected String value; 19 protected JFileChooser chooser; 20 21 protected boolean directory; 22 23 public DirectoryInput(String _variable, String _value, String _label, char mnemonic, int inset) 24 { 25 text = new FileLink(); 26 label = new JLabel(_label); 27 28 text.addActionListener(this); 29 30 setLayout(new BorderLayout(2, 2)); 31 32 add(label, BorderLayout.WEST); 33 add(text, BorderLayout.CENTER); 34 35 label.setDisplayedMnemonic(mnemonic); 36 37 variable = _variable; 38 value = _value; 39 40 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, inset)); 41 } 42 43 public void actionPerformed(ActionEvent ev) 44 { 45 if (chooser == null) 46 { 47 chooser = new JFileChooser(); 48 } 49 50 chooser.setApproveButtonText("Select Directory"); 51 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 52 53 if (chooser.showDialog(this, null) == JFileChooser.APPROVE_OPTION) 54 { 55 text.setText(chooser.getSelectedFile().getAbsolutePath()); 56 } 57 58 notifyParent(); 59 } 60 61 public void save() 62 { 63 ClientState.getClientState().setString(getVariable(), text.getText()); 64 } 65 66 public int getEstimatedWidth() 67 { 68 return (int)label.getPreferredSize().getWidth(); 69 } 70 71 public void setAlignWidth(int width) 72 { 73 label.setPreferredSize(new Dimension(width, 0)); 74 revalidate(); 75 } 76 77 public JComponent getComponent() 78 { 79 return this; 80 } 81 82 public void refresh() 83 { 84 text.setText(ClientState.getClientState().getString(getVariable(), value)); 85 } 86 } 87 88 89 | Popular Tags |