////////////////////////////
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();
}