@Override
public void actionPerformed(ActionEvent e) {
ArrayList<Track> tracks = getSelectedSongs();
if (!tracks.isEmpty()) {
player.open(tracks.get(0));
PlaybackOrder order = player.getPlaybackOrder();
order.setLastPlayed(null);
app.getPlaylistManager().setActivePlaylist(playlist);
}
}
});
aMap.put("showProperties", new AbstractAction("Properties") {
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<Track> tracks = getSelectedSongs();
if (tracks.isEmpty())
return;
showProperties(tracks);
}
});
aMap.put("showNowPlaying", new AbstractAction("Scroll to Now Playing") {
@Override
public void actionPerformed(ActionEvent e) {
scrollToSong(player.getTrack());
}
});
aMap.put("removeSelected", new AbstractAction("Remove") {
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<Track> songs = getSelectedSongs();
playlist.removeAll(songs);
adjustLastSongAfterDelete(songs);
clearSelection();
playlist.firePlaylistChanged();
model.fireTableDataChanged();
}
});
aMap.put("enqueue", new AbstractAction("Add to Queue ") {
@Override
public void actionPerformed(ActionEvent e) {
for (Track track : getSelectedSongs()) {
PlaybackOrder order = player.getPlaybackOrder();
order.enqueue(track, playlist);
update();
}
}
});
aMap.put("clearQueue", new AbstractAction("Clear Playback Queue") {
@Override
public void actionPerformed(ActionEvent e) {
PlaybackOrder order = player.getPlaybackOrder();
order.flushQueue();
update();
}
});
iMap.put(KeyStroke.getKeyStroke("B"), "next");
iMap.put(KeyStroke.getKeyStroke("V"), "stop");
iMap.put(KeyStroke.getKeyStroke("C"), "pause");
iMap.put(KeyStroke.getKeyStroke("X"), "play");
iMap.put(KeyStroke.getKeyStroke("Z"), "prev");
iMap.put(KeyStroke.getKeyStroke("ENTER"), "playSelected");
iMap.put(KeyStroke.getKeyStroke("alt ENTER"), "showProperties");
iMap.put(KeyStroke.getKeyStroke("SPACE"), "showNowPlaying");
iMap.put(KeyStroke.getKeyStroke("DELETE"), "removeSelected");
iMap.put(KeyStroke.getKeyStroke("Q"), "enqueue");
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
runAction("playSelected");
}
}
});
playerListener = new PlayerListener() {
public void onEvent(PlayerEvent e) {
update();
switch (e.getEventCode()) {
case FILE_OPENED:
if (config.getBoolean("playlists.cursorFollowsPlayback", true)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
runAction("showNowPlaying");
}
});
}
if (config.getBoolean("playlists.playbackFollowsCursor", false)) {
PlaybackOrder order = player.getPlaybackOrder();
order.setLastPlayed(null);
}
break;
case STOPPED:
int index = playlist.indexOf(player.getTrack());
if (index != -1)
setRowSelectionInterval(index, index);
break;
}
}
};
player.addListener(playerListener);
getTableHeader().addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
TableColumnModel model = getTableHeader().getColumnModel();
int index = model.getColumnIndexAtX(e.getX());
if (index != -1) {
final int col = model.getColumn(index).getModelIndex();
final PlaylistColumn pc = columns.get(col);
playlist.sort(pc.getExpression(), true);
playlist.firePlaylistChanged();
}
}
}
});
getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
ArrayList<Track> tracks = getSelectedSongs();
if (tracks.isEmpty())
return;
Track track = tracks.get(0);
config.put("playlist.selectedTrack", track);
if (config.getBoolean("playlists.playbackFollowsCursor", false)) {
PlaybackOrder order = player.getPlaybackOrder();
order.setLastPlayed(track);
}
}
});
autoResizeChangeListener = new PropertyChangeListener() {