Search in sources :

Example 1 with EqualsFilenameFilter

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

the class CombineFilesDialog method searchParts.

/**
 * Searches for parts of a file.
 *
 * @param part1 first part of a file
 */
private void searchParts(AbstractFile part1) {
    AbstractFile parent = part1.getParent();
    if (parent == null) {
        return;
    }
    String ext = part1.getExtension();
    int firstIndex;
    try {
        firstIndex = Integer.parseInt(ext);
    } catch (NumberFormatException e) {
        return;
    }
    AndFileFilter filter = new AndFileFilter(new StartsWithFilenameFilter(part1.getNameWithoutExtension(), false), new AttributeFileFilter(FileAttribute.FILE), new EqualsFilenameFilter(part1.getName(), false, true));
    try {
        AbstractFile[] otherParts = parent.ls(filter);
        for (AbstractFile otherPart : otherParts) {
            String ext2 = otherPart.getExtension();
            try {
                int partIdx = Integer.parseInt(ext2);
                if (partIdx > firstIndex)
                    files.add(otherPart);
            } catch (NumberFormatException e) {
            // nothing
            }
        }
    } catch (IOException e) {
        LOGGER.debug("Caught exception", e);
    }
    setFiles(files);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) StartsWithFilenameFilter(com.mucommander.commons.file.filter.StartsWithFilenameFilter) IOException(java.io.IOException)

Example 2 with EqualsFilenameFilter

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

the class FileSelectionDialog method actionPerformed.

// //////////////////////////
// ActionListener methods //
// //////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    FileTable activeTable = mainFrame.getActiveTable();
    // Action coming from the selection dialog
    if ((source == okButton || source == selectionField)) {
        // Save values for next time this dialog is invoked
        caseSensitive = caseSensitiveCheckBox.isSelected();
        includeFolders = includeFoldersCheckBox.isSelected();
        comparison = comparisonComboBox.getSelectedIndex();
        String testString;
        keywordString = selectionField.getText();
        if (comparison != REGEXP) {
            // Remove '*' characters
            testString = keywordString.replace("*", "");
        } else {
            testString = keywordString;
        }
        // Instantiate the main file filter
        FileFilter filter;
        switch(comparison) {
            case CONTAINS:
                filter = new ContainsFilenameFilter(testString, caseSensitive);
                break;
            case STARTS_WITH:
                filter = new StartsWithFilenameFilter(testString, caseSensitive);
                break;
            case ENDS_WIDTH:
                filter = new EndsWithFilenameFilter(testString, caseSensitive);
                break;
            case IS:
                filter = new EqualsFilenameFilter(testString, caseSensitive);
                break;
            case REGEXP:
            default:
                try {
                    filter = new RegexpFilenameFilter(testString, caseSensitive);
                } catch (PatternSyntaxException ex) {
                    // Todo: let the user know the regexp is invalid
                    LOGGER.debug("Invalid regexp", ex);
                    // This filter does match any file
                    filter = new PassThroughFileFilter(false);
                }
                break;
        }
        // If folders are excluded, add a regular file filter and chain it with an AndFileFilter
        if (!includeFolders) {
            filter = new AndFileFilter(new AttributeFileFilter(FileAttribute.FILE), filter);
        }
        // Mark/unmark the files using the filter
        activeTable.getFileTableModel().setFilesMarked(filter, addToSelection);
        // Notify registered listeners that currently marked files have changed on this FileTable
        activeTable.fireMarkedFilesChangedEvent();
        activeTable.repaint();
    }
    dispose();
}
Also used : AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileTable(com.mucommander.ui.main.table.FileTable) EndsWithFilenameFilter(com.mucommander.commons.file.filter.EndsWithFilenameFilter) ContainsFilenameFilter(com.mucommander.commons.file.filter.ContainsFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) StartsWithFilenameFilter(com.mucommander.commons.file.filter.StartsWithFilenameFilter) RegexpFilenameFilter(com.mucommander.commons.file.filter.RegexpFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 3 with EqualsFilenameFilter

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

the class SelfUpdateJob method jobCompleted.

@Override
protected void jobCompleted() {
    try {
        AbstractFile parent;
        // Mac OS X
        if (OsFamily.MAC_OS.isCurrent()) {
            parent = destJar.getParent();
            // Look for an .app container that encloses the JAR file
            if (parent.getName().equals("Java") && (parent = parent.getParent()) != null && parent.getName().equals("Resources") && (parent = parent.getParent()) != null && parent.getName().equals("Contents") && (parent = parent.getParent()) != null && "app".equals(parent.getExtension())) {
                String appPath = parent.getAbsolutePath();
                LOGGER.debug("Opening " + appPath);
                // Open -W wait for the current muCommander .app to terminate, before re-opening it
                ProcessRunner.execute(new String[] { "/bin/sh", "-c", "open -W " + appPath + " && open " + appPath });
                return;
            }
        } else {
            parent = destJar.getParent();
            EqualsFilenameFilter launcherFilter;
            // Windows
            if (OsFamily.WINDOWS.isCurrent()) {
                // Look for a muCommander.exe launcher located in the same folder as the JAR file
                launcherFilter = new EqualsFilenameFilter("muCommander.exe", false);
            } else // Other platforms, possibly Unix/Linux
            {
                // Look for a mucommander.sh located in the same folder as the JAR file
                launcherFilter = new EqualsFilenameFilter("mucommander.sh", false);
            }
            AbstractFile[] launcherFile = parent.ls(launcherFilter);
            // If a launcher file was found, execute it
            if (launcherFile != null && launcherFile.length == 1) {
                DesktopManager.open(launcherFile[0]);
                return;
            }
        }
        // No platform-specific launcher found, launch the Jar directly
        ProcessRunner.execute(new String[] { "java", "-jar", destJar.getAbsolutePath() });
    } catch (IOException e) {
        LOGGER.debug("Caught exception", e);
    // Todo: we might want to do something about this
    } finally {
        Application.initiateShutdown();
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) IOException(java.io.IOException)

Aggregations

EqualsFilenameFilter (com.mucommander.commons.file.filter.EqualsFilenameFilter)3 AbstractFile (com.mucommander.commons.file.AbstractFile)2 AndFileFilter (com.mucommander.commons.file.filter.AndFileFilter)2 AttributeFileFilter (com.mucommander.commons.file.filter.AttributeFileFilter)2 StartsWithFilenameFilter (com.mucommander.commons.file.filter.StartsWithFilenameFilter)2 IOException (java.io.IOException)2 ContainsFilenameFilter (com.mucommander.commons.file.filter.ContainsFilenameFilter)1 EndsWithFilenameFilter (com.mucommander.commons.file.filter.EndsWithFilenameFilter)1 FileFilter (com.mucommander.commons.file.filter.FileFilter)1 PassThroughFileFilter (com.mucommander.commons.file.filter.PassThroughFileFilter)1 RegexpFilenameFilter (com.mucommander.commons.file.filter.RegexpFilenameFilter)1 FileTable (com.mucommander.ui.main.table.FileTable)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1