All Downloads are FREE. Search and download functionalities are using the official Maven repository.

freeseawind.lf.basic.filechooser.LuckFileChooserUI Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package freeseawind.lf.basic.filechooser;

import java.io.File;

import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.metal.MetalFileChooserUI;

/**
 * FileChooserUI实现类, 使用系统默认图标来展示。
 *
 * @author freeseawind@github
 * @version 1.0
 *
 */
public class LuckFileChooserUI extends MetalFileChooserUI
{
    private BasicFileView fileView = new LuckFileView();

    public LuckFileChooserUI(JFileChooser filechooser)
    {
        super(filechooser);
    }

    public static ComponentUI createUI(JComponent c)
    {
        return new LuckFileChooserUI((JFileChooser) c);
    }

    public FileView getFileView(JFileChooser fc)
    {
        return fileView;
    }

    /**
     * 参考WindowsFileView实现
     * @author freeseawind@github
     * @version 1.0
     *
     */
    protected class LuckFileView extends BasicFileView
    {
        public Icon getIcon(File f)
        {
            Icon icon = getCachedIcon(f);

            if (icon != null)
            {
                return icon;
            }

            if (f != null)
            {
                icon = getFileChooser().getFileSystemView().getSystemIcon(f);
            }

            if (icon == null)
            {
                icon = super.getIcon(f);
            }

            cacheIcon(f, icon);

            return icon;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy