FileDocCategorySizeDatePackage
ShortcutFileView.javaAPI DocExample1848Mon Jan 09 11:01:58 GMT 2006None

ShortcutFileView

public class ShortcutFileView extends FileView

Fields Summary
Constructors Summary
Methods Summary
public javax.swing.IcongetIcon(java.io.File f)

        if(isDirLink(f)) {
            /* all of this nonsense is to get to the 
            default file view */
            System.out.println("get icon for: " + f);
            JFileChooser chooser = new JFileChooser();
            ComponentUI ui = UIManager.getUI(chooser);
            System.out.println("got : " + ui);
            FileChooserUI fcui = (FileChooserUI)ui;
            fcui.installUI(chooser);
            FileView def = fcui.getFileView(chooser);
            
            // get the standard icon for a folder
            File tmp = new File("C:\\windows");
            Icon folder = def.getIcon(tmp);
            int w = folder.getIconWidth();
            int h = folder.getIconHeight();
            
            // create a buffered image the same size as the icon
            Image img = new BufferedImage(w,h,BufferedImage.TYPE_4BYTE_ABGR);
            Graphics g = img.getGraphics();
            
            // draw the normal icon
            folder.paintIcon(chooser,g,0,0);
            // draw the shortcut image on top of the icon
            Image shortcut = new ImageIcon("shortcut.png").getImage();
            g.drawImage(shortcut,0,0,null);
            g.dispose();
            return new ImageIcon(img);
        } 
        return super.getIcon(f);
    
public booleanisDirLink(java.io.File f)

        if(f.getName().toLowerCase().endsWith(".lnk")) {
            return true;
        }
        return false;
    
public java.lang.BooleanisTraversable(java.io.File f)

        if(isDirLink(f)) {
            return new Boolean(true);
        }
        return null;