On Tue, 2005-12-27 at 14:33 -0500, Chris Lansdown wrote: > Hi, > > The following is a class I've developed to be added as an ActionListener to > the fileTextField component in a MetalFileChooserUI's ui for JFileChooser. > It implements the same (or at least very similar, right now) behavior to > Sun's file text field. > > Please note: while I've sent my copyright assignment form in, I haven't > heard back from Jonas yet (understandable; I sent it in on friday). > > I'm hoping for comments, suggestions, etc. > > The code: > > > private class FileTextFieldListener implements ActionListener > { > public void actionPerformed(ActionEvent ev) > { > try { > JFileChooser fc = getFileChooser(); > int type = fc.getDialogType(); > File f = new File(fileTextField.getText()); > if(!f.isAbsolute()) > { > f = new File(fc.getCurrentDirectory(), fileTextField.getText()) ; > } > f = f.getCanonicalFile(); > if(type == JFileChooser.OPEN_DIALOG) > { > if(f.isDirectory() && f.exists()) > { > fc.setCurrentDirectory(f); > fc.rescanCurrentDirectory(); > fileTextField.setText(""); > } > else if(f.isFile() && f.exists()) > { > fc.setCurrentDirectory(f.getParentFile().getCanonicalFile()); > fc.setSelectedFile(f); > fc.approveSelection(); > closeDialog(); > } > else > { > while(!f.exists()) > f = f.getParentFile().getCanonicalFile(); > fc.setCurrentDirectory(f); > fc.rescanCurrentDirectory(); > fc.setSelectedFile(null); > fileTextField.setText(""); > } > } > else > { > if(f.isDirectory()) > { > fc.setCurrentDirectory(f); > fc.rescanCurrentDirectory(); > fileTextField.setText(""); > } > else > { > fc.setCurrentDirectory(f.getParentFile().getCanonicalFile()); > fc.setSelectedFile(f); > fc.approveSelection(); > closeDialog(); > } > } > } > catch(IOException ex) > { > fileTextField.setText(""); > } > } > } > > /** > * Closes the dialog. > */ > void closeDialog() > { > Window owner = SwingUtilities.windowForComponent(getFileChooser()); > if (owner instanceof JDialog) > ((JDialog) owner).dispose(); > } >
This seems fine. Thanks for implementing it. Lillian _______________________________________________ Classpath mailing list Classpath@gnu.org http://lists.gnu.org/mailman/listinfo/classpath