Java Code Examples for javax.swing.filechooser.FileNameExtensionFilter.getExtensions()

The following are Jave code examples for showing how to use getExtensions() of the javax.swing.filechooser.FileNameExtensionFilter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: NativeJFileChooser   File: NativeJFileChooser.java   Source Code and License Vote up 6 votes
@Override
public void addChoosableFileFilter(FileFilter filter) {
    super.addChoosableFileFilter(filter);
    if (!FX_AVAILABLE || filter == null) {
        return;
    }
    if (filter.getClass().equals(FileNameExtensionFilter.class)) {
        FileNameExtensionFilter f = (FileNameExtensionFilter) filter;

        List<String> ext = new ArrayList<>();
        for (String extension : f.getExtensions()) {
            ext.add(extension.replaceAll("^\\*?\\.?(.*)$", "*.$1"));
        }
        fileChooser.getExtensionFilters()
                .add(new FileChooser.ExtensionFilter(f.getDescription(), ext));
    }
}
 
Example 2
Project: VISNode   File: FileChooserFactory.java   Source Code and License Vote up 5 votes
/**
 * Adds the extension to the file if required
 *
 * @param file
 * @param fileFilter
 * @return File
 */
private File addExtensionIfRequired(File file, FileFilter fileFilter) {
    String name = file.getName();
    // If there is an extension
    if (name.indexOf('.', name.length() - 4) >= 0) {
        return file;
    }
    if (fileFilter instanceof FileNameExtensionFilter) {
        FileNameExtensionFilter extensions = (FileNameExtensionFilter) fileFilter;
        return new File(file.getAbsolutePath() + '.' + extensions.getExtensions()[0]);
    }
    return file;
}
 
Example 3
Project: featurea   File: FSFileChooser.java   Source Code and License Vote up 5 votes
@Override
public void setFileFilter(FileFilter filter) {
    super.setFileFilter(filter);
    removeImagePreview();
    if (filter instanceof FileNameExtensionFilter) {
        FileNameExtensionFilter fileNameExtensionFilter = (FileNameExtensionFilter) filter;
        String[] extensions = fileNameExtensionFilter.getExtensions();
        for (String extension : extensions) {
            if (FileUtil.hasTextureExtension(extension)) {
                addImagePreview();
            }
        }
    }
}