Example usage for javax.swing.filechooser FileFilter accept

List of usage examples for javax.swing.filechooser FileFilter accept

Introduction

In this page you can find the example usage for javax.swing.filechooser FileFilter accept.

Prototype

public abstract boolean accept(File f);

Source Link

Document

Whether the given file is accepted by this filter.

Usage

From source file:org.opencms.applet.upload.FileUploadApplet.java

/**
 * Puts all given files (and all files in subtree of given potential "folder" file) into the given 
 * list (as {@link File} instances) with respect to the current file filter in the file chooser. 
 * <p>/*from   w ww . j a  v  a 2  s .  c  o  m*/
 * 
 * 
 * @param file the file or folder to collect all subfiles of with respect to the current file chooser. 
 * 
 * @param fileNames all given files (and all files in subtree of given potential "folder" file) into the given 
 *      list (as {@link File} instances) with respect to the current file filter in the file chooser 
 */
private void getFilesInTree(final File file, final List fileNames) {

    if (file.isDirectory()) {
        File[] children = file.listFiles();
        for (int i = 0; i < children.length; i++) {
            getFilesInTree(children[i], fileNames);

        }
    } else {
        FileFilter filter = m_fileSelector.getFileFilter();
        if (filter.accept(file)) {
            fileNames.add(file);
        }
    }
}

From source file:org.opencms.applet.upload.FileUploadApplet.java

/**
 * Puts the path of the given file in relation to the current root directory of the intenal 
 * file chooser with support for folder-recursion. <p>
 * /*  w w  w .  jav a2s. c  o  m*/
 * 
 * @param file the file to put into relation to the root directory of the internal file chooser or a folder 
 *      of files to do this. 
 * 
 * @param fileNames will contain the result. 
 */
private void getRelativeFilePaths(final File file, final List fileNames) {

    if (file.isDirectory()) {
        File[] children = file.listFiles();
        for (int i = 0; i < children.length; i++) {
            getRelativeFilePaths(children[i], fileNames);

        }
    } else {
        FileFilter filter = m_fileSelector.getFileFilter();
        if (filter.accept(file)) {
            String rootDir = m_fileSelector.getCurrentDirectory().getAbsolutePath();
            int rootDirLength = rootDir.length();
            String filePath = file.getAbsolutePath();
            filePath = filePath.substring(rootDirLength);
            filePath = filePath.replace('\\', '/');
            fileNames.add(filePath);
        }
    }
}

From source file:org.orbisgis.core.ui.plugins.editors.mapEditor.AddFromFolderPlugIn.java

/**
 * the method that actually process the content of a directory, or a file.
 * If the file is acceptable by the FileFilter, it is processed
 *
 * @param file/*w ww  .ja  v  a  2  s  .c o m*/
 * @param pm
 */
private void processFolder(File file, FileFilter filter, MapContext mc, ProgressMonitor pm) {
    if (file.isDirectory()) {
        pm.startTask(file.getName(), 100);
        for (File content : file.listFiles()) {
            if (pm.isCancelled()) {
                break;
            }
            processFolder(content, filter, mc, pm);
        }
        pm.endTask();
    } else {
        if (filter.accept(file) && OrbisConfiguration.isFileEligible(file)) {
            DataManager dm = (DataManager) Services.getService(DataManager.class);
            SourceManager sourceManager = dm.getSourceManager();
            try {
                String name = sourceManager.getUniqueName(FilenameUtils.removeExtension(file.getName()));
                sourceManager.register(name, file);
                if (mc != null) {
                    mc.getLayerModel().addLayer(dm.createLayer(name));
                }
            } catch (LayerException e) {
                Services.getErrorManager()
                        .warning(I18N.getString("orbisgis.org.orbisgis.core.model.source.file.noSpatial") + "n/"
                                + I18N.getString("orbisgis.org.orbisgis.core.geocatalog.sourceAdded"));

            } catch (SourceAlreadyExistsException e) {
                ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e);
            }
        }
    }
}

From source file:org.orbisgis.core.ui.plugins.views.geocatalog.NewGeocatalogFolderPlugIn.java

/**
 * the method that actually process the content of a directory, or a file.
 * If the file is acceptable by the FileFilter, it is processed
 *
 * @param file/* w w w  .  j  a  v  a 2  s  . co  m*/
 * @param pm
 */
private void processFolder(File file, FileFilter filter, ProgressMonitor pm) {
    if (file.isDirectory()) {
        pm.startTask(file.getName(), 100);
        for (File content : file.listFiles()) {
            if (pm.isCancelled()) {
                break;
            }
            processFolder(content, filter, pm);
        }
        pm.endTask();
    } else {
        if (filter.accept(file) && OrbisConfiguration.isFileEligible(file)) {
            DataManager dm = (DataManager) Services.getService(DataManager.class);
            SourceManager sourceManager = dm.getSourceManager();
            try {
                String name = sourceManager.getUniqueName(FilenameUtils.removeExtension(file.getName()));
                sourceManager.register(name, file);
            } catch (SourceAlreadyExistsException e) {
                ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e);
            }
        }
    }
}

From source file:org.orbisgis.view.geocatalog.Catalog.java

/**
 * the method that actually process the content of a directory, or a
 * file. If the file is acceptable by the FileFilter, it is processed
 *
 * @param file File or Folder to register
 * @param pm Progress manager//from   w ww.  j  a  v a 2 s .com
 */
private void processFolder(File file, FileFilter filter, org.orbisgis.progress.ProgressMonitor pm) {
    if (file.isDirectory()) {
        pm.startTask(file.getName(), 100);
        File[] files = file.listFiles();
        if (files != null) {
            for (File content : files) {
                if (pm.isCancelled()) {
                    break;
                }
                processFolder(content, filter, pm);
            }
        }
        pm.endTask();
    } else {
        DataManager dm = Services.getService(DataManager.class);
        DriverManager dr = dm.getSourceManager().getDriverManager();
        if (filter.accept(file) && dr.isDriverFileSupported(file)) {
            SourceManager sourceManager = dm.getSourceManager();
            try {
                String name = sourceManager.getUniqueName(FilenameUtils.removeExtension(file.getName()));
                sourceManager.register(name, file);
            } catch (SourceAlreadyExistsException e) {
                LOGGER.error(I18N.tr("The source is already registered : "), e);
            }
        }
    }
}