<commit_before>package com.twelvemonkeys.swing.filechooser;

import com.twelvemonkeys.lang.Platform;
import com.twelvemonkeys.lang.Validate;

import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.FileChooserUI;
import java.io.File;
import java.io.IOException;

/**
 * FileSystemViews
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author last modified by $Author: haraldk$
 * @version $Id: FileSystemViews.java,v 1.0 Jan 14, 2010 3:19:51 PM haraldk Exp$
 */
public final class FileSystemViews {

    public static FileSystemView getFileSystemView() {
        if (Platform.os() == Platform.OperatingSystem.MacOS) {
            return ProxyFileSystemView.instance;
        }

        return FileSystemView.getFileSystemView();
    }

    private static class ProxyFileSystemView extends FileSystemView {

        private static final FileSystemView instance = createFSV();

        private static FileSystemView createFSV() {
            FileSystemView view = FileSystemView.getFileSystemView();

            try {
                FileChooserUI ui = null;
/* NOTE: The following is faster, but does not work reliably, as getSystemTypeDescription will return null...

                // The below is really a lot of hassle to avoid creating a JFileChooser. Maybe not a good idea?
                String uiClassName = UIManager.getString("FileChooserUI");
                try {
                    @SuppressWarnings({"unchecked"})
                    Class<FileChooserUI> uiClass = (Class<FileChooserUI>) Class.forName(uiClassName);
                    @SuppressWarnings({"unchecked"})
                    Constructor<FileChooserUI>[] constructors = uiClass.getDeclaredConstructors();
                    for (Constructor constructor : constructors) {
                        if (!constructor.isAccessible()) {
                            constructor.setAccessible(true);
                        }

                        Class[] parameterTypes = constructor.getParameterTypes();

                        // Test the two most likely constructors
                        if (parameterTypes.length == 0) {
                            ui = (FileChooserUI) constructor.newInstance();
                            break;
                        }
                        else if (parameterTypes.length == 1 && parameterTypes[0] == JFileChooser.class) {
                            ui = (FileChooserUI) constructor.newInstance((JFileChooser) null);
                            break;
                        }
                    }
                }
                catch (Exception ignore) {
                    ignore.printStackTrace();
                }

                if (ui == null) {
*/
                    // Somewhat slower, but should work even if constructors change
                    ui = new JFileChooser().getUI();
//                }

                return new ProxyFileSystemView(ui.getFileView(null), view);
            }
            catch (Throwable ignore) {
            }

            // Fall back to default view
            return view;
        }

        private final FileView mUIView;
        private final FileSystemView mDefaultView;

        public ProxyFileSystemView(final FileView pUIView, final FileSystemView pDefaultView) {
            Validate.notNull(pUIView, "uiView");
            Validate.notNull(pDefaultView, "defaultFileSystemView");

            mUIView = pUIView;
            mDefaultView = pDefaultView;
        }

        @Override
        public Boolean isTraversable(File f) {
            return mUIView.isTraversable(f);
        }

        @Override
        public String getSystemDisplayName(File f) {
            return mUIView.getName(f);
        }

        @Override
        public String getSystemTypeDescription(File f) {
            return mUIView.getTypeDescription(f);
        }

        @Override
        public Icon getSystemIcon(File f) {
            return mUIView.getIcon(f);
        }

        @Override
        public boolean isRoot(File f) {
            return mDefaultView.isRoot(f);
        }

        @Override
        public boolean isParent(File folder, File file) {
            return mDefaultView.isParent(folder, file);
        }

        @Override
        public File getChild(File parent, String fileName) {
            return mDefaultView.getChild(parent, fileName);
        }

        @Override
        public boolean isFileSystem(File f) {
            return mDefaultView.isFileSystem(f);
        }

        @Override
        public boolean isHiddenFile(File f) {<commit_msg>Added a TODO for missing functionality.<commit_after>package com.twelvemonkeys.swing.filechooser;

import com.twelvemonkeys.lang.Platform;
import com.twelvemonkeys.lang.Validate;

import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.FileChooserUI;
import java.io.File;
import java.io.IOException;

/**
 * FileSystemViews
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author last modified by $Author: haraldk$
 * @version $Id: FileSystemViews.java,v 1.0 Jan 14, 2010 3:19:51 PM haraldk Exp$
 */
public final class FileSystemViews {

    public static FileSystemView getFileSystemView() {
        if (Platform.os() == Platform.OperatingSystem.MacOS) {
            return ProxyFileSystemView.instance;
        }

        return FileSystemView.getFileSystemView();
    }

    private static class ProxyFileSystemView extends FileSystemView {

        private static final FileSystemView instance = createFSV();

        private static FileSystemView createFSV() {
            FileSystemView view = FileSystemView.getFileSystemView();

            try {
                FileChooserUI ui = null;
/* NOTE: The following is faster, but does not work reliably, as getSystemTypeDescription will return null...

                // The below is really a lot of hassle to avoid creating a JFileChooser. Maybe not a good idea?
                String uiClassName = UIManager.getString("FileChooserUI");
                try {
                    @SuppressWarnings({"unchecked"})
                    Class<FileChooserUI> uiClass = (Class<FileChooserUI>) Class.forName(uiClassName);
                    @SuppressWarnings({"unchecked"})
                    Constructor<FileChooserUI>[] constructors = uiClass.getDeclaredConstructors();
                    for (Constructor constructor : constructors) {
                        if (!constructor.isAccessible()) {
                            constructor.setAccessible(true);
                        }

                        Class[] parameterTypes = constructor.getParameterTypes();

                        // Test the two most likely constructors
                        if (parameterTypes.length == 0) {
                            ui = (FileChooserUI) constructor.newInstance();
                            break;
                        }
                        else if (parameterTypes.length == 1 && parameterTypes[0] == JFileChooser.class) {
                            ui = (FileChooserUI) constructor.newInstance((JFileChooser) null);
                            break;
                        }
                    }
                }
                catch (Exception ignore) {
                    ignore.printStackTrace();
                }

                if (ui == null) {
*/
                    // Somewhat slower, but should work even if constructors change
                    ui = new JFileChooser().getUI();
//                }

                return new ProxyFileSystemView(ui.getFileView(null), view);
            }
            catch (Throwable ignore) {
            }

            // Fall back to default view
            return view;
        }

        private final FileView mUIView;
        private final FileSystemView mDefaultView;

        public ProxyFileSystemView(final FileView pUIView, final FileSystemView pDefaultView) {
            Validate.notNull(pUIView, "uiView");
            Validate.notNull(pDefaultView, "defaultFileSystemView");

            mUIView = pUIView;
            mDefaultView = pDefaultView;
        }

        @Override
        public Boolean isTraversable(File f) {
            return mUIView.isTraversable(f);
        }

        @Override
        public String getSystemDisplayName(File f) {
            return mUIView.getName(f);
        }

        @Override
        public String getSystemTypeDescription(File f) {
            // TODO: Create something that gives a proper description here on the Mac...
            return mUIView.getTypeDescription(f);
        }

        @Override
        public Icon getSystemIcon(File f) {
            return mUIView.getIcon(f);
        }

        @Override
        public boolean isRoot(File f) {
            return mDefaultView.isRoot(f);
        }

        @Override
        public boolean isParent(File folder, File file) {
            return mDefaultView.isParent(folder, file);
        }

        @Override
        public File getChild(File parent, String fileName) {
            return mDefaultView.getChild(parent, fileName);
        }

        @Override
        public boolean isFileSystem(File f) {
            return mDefaultView.isFileSystem(f);
        }

        @Override
        public boolean isHiddenFile(File f) {
{'fraction_non_alphanumeric': 0.08215237080447522, 'fraction_numerical': 0.0034096963239211506, 'mean_word_length': 1.769548539392151, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1378556', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2280, 'n_words': 577}