
Real Windows Shortcut Support #30
Chapter 4, File Choosers
|
163
HACK
public boolean isDirLink(File f) {
try {
if(f.getName().toLowerCase( ).endsWith(".lnk")) {
LnkParser parser = new LnkParser(f);
if(parser.isDirectory( )) {
return true;
}
}
} catch (Exception ex) {
System.out.println("exception: " + ex.getMessage( ));
ex.printStackTrace( );
}
return false;
}
And finally, here’s a test class that will build a new shortcut enabled file
chooser. It creates a normal file chooser, and then sets the
FileSystemView to
the new shortcut subclass. It also sets the modified version of the
ShortcutFileView:
public class ShortcutTest {
public static void main(String[] args) throws Exception {
FileSystemView fsv = new ShortcutFileSystemView( );
JFileChooser chooser = new JFileChooser( );
chooser.setFileSystemView(fsv);
chooser.setFileView(new ShortcutFileView( ));
chooser.showOpenDialog(null);
}
}
Figure 4-5 shows the JFileChooser displaying a shortcut that will behave like
a real Windows shortcut when clicked.
Figure 4-5. A JFileChooser with a live shortcut