Class ReArrangePlayListAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- com.tagtraum.core.app.ApplicationAction
-
- com.tagtraum.beatunes.action.BaseAction
-
- com.tagtraum.beatunes.action.standard.ReArrangePlayListAction
-
- All Implemented Interfaces:
ApplicationComponent<BeaTunes>
,ActionListener
,Serializable
,Cloneable
,EventListener
,Action
- Direct Known Subclasses:
MatchSortAction
,SortByPropertyAction
public abstract class ReArrangePlayListAction extends BaseAction
Abstract superclass for actions that re-arrange/manipulate the order of songs (or anything else) in playlists. The easiest way to create a custom order is to provide a
reArrangeFunction
via either the constructor orsetReArrangeFunction(BiFunction)
. For a minimal implementation, you must at least implement theApplicationAction.getId()
method.See
reArrangePlayList(PlayList, long[])
for more implementation details.- Author:
- Hendrik Schreiber
- See Also:
NewPlayListAction
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.tagtraum.beatunes.action.BaseAction
BaseAction.EnabledView, BaseAction.Location, BaseAction.SelectionCount
-
Nested classes/interfaces inherited from class com.tagtraum.core.app.ApplicationAction
ApplicationAction.ApplicationActionFacade
-
-
Field Summary
-
Fields inherited from class com.tagtraum.beatunes.action.BaseAction
ITEMS_EDITABLE
-
Fields inherited from class com.tagtraum.core.app.ApplicationAction
BUTTON_MODEL, DISABLED_ICON, DISABLED_SELECTED_ICON, PRESSED_ICON, ROLLOVER_ICON, SELECTED_ICON, SHORT_NAME
-
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
-
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
-
-
Constructor Summary
Constructors Constructor Description ReArrangePlayListAction(BeaTunes application)
ReArrangePlayListAction(BeaTunes application, BiFunction<PlayList,List<AudioSong>,List<AudioSong>> reArrangeFunction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(ActionEvent e)
BiFunction<PlayList,List<AudioSong>,List<AudioSong>>
getReArrangeFunction()
Returns thereArrangeFunction
, aBiFunction
that takes both the playlist and its songs as arguments and returns the songs in a new order.boolean
isRequiresSelectedSongs()
Indicates whether beaTunes should provide the ids of the selected songs inreArrangePlayList(PlayList, long[])
.protected void
loadResources()
Installs enabled/disabled listeners that turn the action on and off, depending on whether the current playlist is editable at all (some lists, like Music are not editable).void
reArrangePlayList(PlayList playList, long[] selectedSongIds)
You may override this method to provide a custom implementation for playlist re-arrangement.void
setReArrangeFunction(BiFunction<PlayList,List<AudioSong>,List<AudioSong>> reArrangeFunction)
void
setRequiresSelectedSongs(boolean requiresSelectedSongs)
Call this from the constructor to determine, whetherreArrangePlayList(PlayList, long[])
should be called with the ids of selected songs.-
Methods inherited from class com.tagtraum.beatunes.action.BaseAction
bindListeners, bindListeners, getApplication, getFocusedPlayList, getFocusOwner, getMostRecentlyFocused, getPlayListTreeNode, getSelectedPlayList, getSelectedPlayListTreeNode, getSelectedSong, getSelectedSongCount, getSelectedSongIds, getSelectedSongs, getSelectedSongs, init, isAnalysisQueueFocused, isMatchTableFocused, isPlayListTreeFocused, isSimpleSongTableFocused, isSongTableFocused, numberOfSelectedSongs, numberOfSelectedSongs, setApplication, shutdown
-
Methods inherited from class com.tagtraum.core.app.ApplicationAction
getActionLocations, getButtonModel, getIconButtonFacade, getId, getMenuFacade, getToolbarButtonFacade, isVisible, register, setButtonModel, setVisible
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.tagtraum.core.app.ApplicationComponent
getId
-
-
-
-
Method Detail
-
reArrangePlayList
public void reArrangePlayList(PlayList playList, long[] selectedSongIds)
You may override this method to provide a custom implementation for playlist re-arrangement. But instead of overriding, you might want to opt for the much simple approach of providing a custom function via
setReArrangeFunction(BiFunction)
or the corresponding constructor.This method is called by the action as part of its
actionPerformed(ActionEvent)
method. You are given an existing playlist and the ids of the currently selected songs, ifisRequiresSelectedSongs()
istrue
.Note that the most efficient way to move stuff around is to create a new order of
ids
and then simply set thoseids
usingPlayList.setSongIds(java.util.List)
. Alternatively, load all songs from the playlist, re-arrange them in memory and set them withPlayList.setSongs(List)
— this is essentially what happens when using the re-arrangement function.You may also modify the playlist object itself, e.g. change the default name programmatically.
Note that you are not called from either the EDT or the default database thread, but an independent thread. This means, that you may block this thread indefinitely (of course you shouldn't though!). It also means, that from this thread you should invoke UI code using
SwingUtilities.invokeAndWait(Runnable)
.The default implementation of this method uses the set
reArrangeFunction
to create a new order. If no custom function is set, identity is used.- Parameters:
playList
- existing playlistselectedSongIds
- selected song ids or an empty array, ifisRequiresSelectedSongs()
isfalse
-
getReArrangeFunction
public BiFunction<PlayList,List<AudioSong>,List<AudioSong>> getReArrangeFunction()
Returns thereArrangeFunction
, aBiFunction
that takes both the playlist and its songs as arguments and returns the songs in a new order.- Returns:
- function
-
setReArrangeFunction
public void setReArrangeFunction(BiFunction<PlayList,List<AudioSong>,List<AudioSong>> reArrangeFunction)
-
isRequiresSelectedSongs
public boolean isRequiresSelectedSongs()
Indicates whether beaTunes should provide the ids of the selected songs inreArrangePlayList(PlayList, long[])
.- Returns:
true
(default) orfalse
-
setRequiresSelectedSongs
public void setRequiresSelectedSongs(boolean requiresSelectedSongs)
Call this from the constructor to determine, whetherreArrangePlayList(PlayList, long[])
should be called with the ids of selected songs.- Parameters:
requiresSelectedSongs
-true
orfalse
-
loadResources
protected void loadResources()
Installs enabled/disabled listeners that turn the action on and off, depending on whether the current playlist is editable at all (some lists, like Music are not editable). Override this method, if you desire a different enable/disable behavior.- Overrides:
loadResources
in classBaseAction
-
actionPerformed
public void actionPerformed(ActionEvent e)
-
-