Search in sources :

Example 1 with AbstractFilenameFilter

use of com.mucommander.commons.file.filter.AbstractFilenameFilter in project mucommander by mucommander.

the class MarkExtensionAction method getFilter.

// - Action code ---------------------------------------------------------------------
// -----------------------------------------------------------------------------------
/**
 * Creates a {@link com.mucommander.commons.file.filter.FilenameFilter} that should be applied to all current files.
 * <p>
 * If the action has been configured using the <code>file.extension</code> property, the returned filter
 * will match that extension. Otherwise, the currently selected file's extension will be used. If it doesn't
 * have one, the returned filter will match all files such that
 * <code>file.getExtension() == null</code>.
 * </p>
 * @param  file currently selected file.
 * @return      the filter that should be applied by this action.
 */
private FilenameFilter getFilter(AbstractFile file) {
    String ext;
    ExtensionFilenameFilter filter;
    // If no extension has been configured, analyse the current selection.
    if ((ext = getExtension()) == null) {
        // If there is no current selection, abort.
        if (file == null)
            return null;
        // match null extensions.
        if ((ext = file.getExtension()) == null)
            return new AbstractFilenameFilter() {

                public boolean accept(String name) {
                    return AbstractFile.getExtension(name) == null;
                }
            };
    }
    // At this point, ext contains the extension that should be matched.
    filter = new ExtensionFilenameFilter("." + ext);
    // Initialises the filter's case-sensitivy depending on the action's propeties.
    filter.setCaseSensitive(isCaseSensitive());
    return filter;
}
Also used : AbstractFilenameFilter(com.mucommander.commons.file.filter.AbstractFilenameFilter) ExtensionFilenameFilter(com.mucommander.commons.file.filter.ExtensionFilenameFilter)

Aggregations

AbstractFilenameFilter (com.mucommander.commons.file.filter.AbstractFilenameFilter)1 ExtensionFilenameFilter (com.mucommander.commons.file.filter.ExtensionFilenameFilter)1