Example usage for javax.swing JFileChooser addChoosableFileFilter

List of usage examples for javax.swing JFileChooser addChoosableFileFilter

Introduction

In this page you can find the example usage for javax.swing JFileChooser addChoosableFileFilter.

Prototype

@BeanProperty(preferred = true, description = "Adds a filter to the list of user choosable file filters.")
public void addChoosableFileFilter(FileFilter filter) 

Source Link

Document

Adds a filter to the list of user choosable file filters.

Usage

From source file:xtrememp.PlaylistManager.java

public void openPlaylistDialog() {
    JFileChooser fileChooser = new JFileChooser(Settings.getLastDir());
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(playlistFileFilter);
    fileChooser.setMultiSelectionEnabled(false);
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        Settings.setLastDir(file.getPath());
        clearPlaylist();// w  w  w.  j  av a  2 s .  co  m
        loadPlaylist(file.getPath());
    }
}

From source file:xtrememp.PlaylistManager.java

public boolean savePlaylistDialog() {
    JFileChooser fileChooser = new JFileChooser(Settings.getLastDir());
    M3uPlaylistFileFilter m3uFileFilter = new M3uPlaylistFileFilter();
    XspfPlaylistFileFilter xspfFileFilter = new XspfPlaylistFileFilter();
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(m3uFileFilter);
    fileChooser.addChoosableFileFilter(xspfFileFilter);
    fileChooser.setMultiSelectionEnabled(false);
    if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        FileFilter fileFilter = fileChooser.getFileFilter();
        String fileName = file.getName().toLowerCase();
        if (fileFilter == m3uFileFilter) {
            if (!fileName.endsWith(".m3u")) {
                fileName = fileName.concat(".m3u");
            }//ww w . j av  a 2  s .  c  o m
            try {
                return PlaylistIO.saveM3U(playlist, file.getParent() + File.separator + fileName);
            } catch (PlaylistException ex) {
                logger.error("Can't save playlist in M3U format", ex);
            }
        }
        if (fileFilter == xspfFileFilter) {
            if (!fileName.endsWith(".xspf")) {
                fileName = fileName.concat(".xspf");
            }
            try {
                return PlaylistIO.saveXSPF(playlist, file.getParent() + File.separator + fileName);
            } catch (PlaylistException ex) {
                logger.error("Can't save playlist in XSPF format", ex);
            }
        }
        Settings.setLastDir(file.getParent());
    }
    return false;
}

From source file:xtrememp.PlaylistManager.java

public void addFilesDialog(boolean playFirst) {
    JFileChooser fileChooser = new JFileChooser(Settings.getLastDir());
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(audioFileFilter);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileChooser.setMultiSelectionEnabled(true);
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File[] selectedFiles = fileChooser.getSelectedFiles();
        Settings.setLastDir(selectedFiles[0].getParent());
        addFiles(Arrays.asList(selectedFiles), playFirst);
    }//  www  .java2 s . co  m
}