});
aMap.put("renamePlaylist", new AbstractAction("Rename") {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedTable != null) {
Playlist playlist = selectedTable.getPlaylist();
String name = JOptionPane.showInputDialog("Rename", playlist.getName());
if (!Util.isEmpty(name)) {
playlist.setName(name);
tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), center(name));
}
}
}
});
aMap.put("removePlaylist", new AbstractAction("Remove Playlist") {
@Override
public void actionPerformed(ActionEvent e) {
if (selectedTable != null) {
playlistManager.removePlaylist(selectedTable.getPlaylist());
checkTabCount();
}
}
});
aMap.put("savePlaylist", new AbstractAction("Save Playlist") {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
String path = config.getString("playlists.lastDir", "");
if (!path.isEmpty()) fc.setCurrentDirectory(new File(path));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
FileNameExtensionFilter musFiler = new FileNameExtensionFilter("Musique Playlist", "mus");
FileNameExtensionFilter m3uFilter = new FileNameExtensionFilter("M3U Playlist", "m3u", "m3u8");
FileNameExtensionFilter plsFiler = new FileNameExtensionFilter("PLS Playlist", "pls");
fc.addChoosableFileFilter(musFiler);
fc.addChoosableFileFilter(m3uFilter);
fc.addChoosableFileFilter(plsFiler);
Playlist playlist = selectedTable.getPlaylist();
String fileName = playlist.getName().toLowerCase().replaceAll("\\s+", "_");
fc.setSelectedFile(new File(fileName));
int ret = fc.showSaveDialog(getRootPane());
if (ret == JFileChooser.APPROVE_OPTION) {
FileNameExtensionFilter filter = (FileNameExtensionFilter) fc.getFileFilter();
File file = fc.getSelectedFile();
String suffix = filter.getExtensions()[0];
if (!file.getName().endsWith(suffix)) {
file = new File(file.getParent(),
Util.removeExt(file.getName()) + "." + suffix);
}
if (filter == musFiler) {
playlist.save(file);
} else if (filter == m3uFilter) {
playlist.saveM3U(file);
} else if (filter == plsFiler) {
playlist.savePLS(file);
}
config.setString("playlists.lastDir", fc.getCurrentDirectory().getAbsolutePath());
}
}
});
aMap.put("loadPlaylist", new AbstractAction("Load Playlist") {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
String path = config.getString("playlists.lastDir", "");
if (!path.isEmpty()) fc.setCurrentDirectory(new File(path));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(new FileNameExtensionFilter("All supported formats", "mus", "m3u", "m3u8", "pls"));
fc.addChoosableFileFilter(new FileNameExtensionFilter("Musique Playlist", "mus"));
fc.addChoosableFileFilter(new FileNameExtensionFilter("M3U Playlist", "m3u", "m3u8"));
fc.addChoosableFileFilter(new FileNameExtensionFilter("PLS Playlist", "pls"));
int ret = fc.showOpenDialog(getRootPane());
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
Playlist playlist = addPlaylist(Util.capitalize(Util.removeExt(file.getName()), " "));
ProgressDialog dialog = new ProgressDialog(tabbedPane, "Adding Files");
dialog.show(new Task.FileAddingTask(playlist, new File[]{fc.getSelectedFile()}, -1));
config.setString("playlists.lastDir", fc.getCurrentDirectory().getAbsolutePath());
}
}