Updated JavaDoc.

This commit is contained in:
neviyn 2016-04-02 19:28:39 +01:00
parent ccee051cb4
commit 62fbb9e9fc
3 changed files with 115 additions and 4 deletions

View File

@ -84,6 +84,9 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
}
}
/**
* Display a message in the Library area to tell the user that the library is empty.
*/
private void showEmpty(){
DefaultTreeModel failedModel = new DefaultTreeModel(new DefaultMutableTreeNode());
DefaultMutableTreeNode failedParentNode = (DefaultMutableTreeNode) failedModel.getRoot();
@ -92,6 +95,9 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
libraryTree.setModel(failedModel);
}
/**
* Show a list of all songs in the library area.
*/
@Override
public void showSongs() {
Optional<List<Song>> dbQuery = database.listAllT(Song.class);
@ -106,6 +112,11 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
showEmpty();
}
/**
* Show a list of all songs in the library area, grouped by a certain related type.
* @param grouping Type by which songs will be grouped.
* @param <T> Type by which songs will be grouped.
*/
@Override
public <T extends HasSongs & Comparable<T>> void showGroupedSongs(Class<T> grouping) {
Optional<List<T>> dbQuery = database.listAllT(grouping);
@ -125,6 +136,9 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
}
/**
* Set the library to updating mode and start processing songs in library folders.
*/
@Override
public void updateLibrary() {
if(!libraryUpdating.get()) {
@ -141,6 +155,9 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
}
}
/**
* Refresh the content currently displayed in the library view.
*/
@Override
public void refreshLibrary() {
if(!libraryUpdating.get()) { // Don't try to refresh while updating!!
@ -160,23 +177,37 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
}
}
/**
* The library was updated but there was an error (partial update may have occurred).
* @param message Error message.
*/
@Override
public void libraryUpdated(String message) {
JOptionPane.showMessageDialog(this, message, "Update Error", JOptionPane.ERROR_MESSAGE);
libraryUpdated();
}
/**
* Library updated successfully.
*/
public void libraryUpdated() {
libraryUpdating.set(false);
refreshLibrary();
}
/**
* Show data on the current update item being indexed.
* @param name Data about the file/folder to be shown to the user.
*/
@Override
public void currentlyUpdating(String name) {
updatingNode.setUserObject(name);
((DefaultTreeModel)libraryTree.getModel()).nodeChanged(updatingNode);
}
/**
* Double click a library item to add it to the playlist.
*/
private class LibraryMouseAdapter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
@ -197,6 +228,9 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt
}
}
/**
* Renderer for showing album art next to library album items.
*/
private class LibraryTreeCellRenderer implements TreeCellRenderer {
private final JLabel label;

View File

@ -77,15 +77,27 @@ public class GStreamerPlayer implements IPlayer{
setVolume(ConfigManager.getLastVolume());
}
/**
* Reset the position of the seekbar.
*/
private void resetSeek(){
if(callbackInterface != null)
callbackInterface.setSeekBarPosition(0);
}
/**
* Play the currently active song in the playlist.
* @throws StartPlayingException
*/
public void play() throws StartPlayingException {
playSong(playlist.getActive());
}
/**
* Play a song
* @param inputSong Song to play.
* @throws StartPlayingException
*/
private void playSong(Song inputSong) throws StartPlayingException {
if (playBin.getState() == State.PLAYING)
stop();
@ -186,8 +198,10 @@ public class GStreamerPlayer implements IPlayer{
* @param volume New volume in percent.
*/
public void setVolume(int volume){
currentVolume = volume;
playBin.setVolumePercent(volume);
if(volume >= 0 && volume <= 100) {
currentVolume = volume;
playBin.setVolumePercent(volume);
}
}
/**

View File

@ -66,11 +66,20 @@ public class VLCPlayer implements IPlayer {
libvlcArgs.add("--aout=dummy");
}
/**
* Play the currently active song in the playlist.
* @throws StartPlayingException
*/
@Override
public void play() throws StartPlayingException {
playSong(playlist.getActive());
}
/**
* Play a song
* @param inputSong Song to play.
* @throws StartPlayingException
*/
@Override
public void playSong(Optional<Song> inputSong) throws StartPlayingException {
if(inputSong.isPresent()) {
@ -78,6 +87,11 @@ public class VLCPlayer implements IPlayer {
}
}
/**
* Play a song
* @param inputSong Song to play.
* @throws StartPlayingException
*/
private void playSong(Song inputSong) throws StartPlayingException {
resetSeek();
if(inputSong == currentSong && mediaPlayer.getTime() > 0 && mediaPlayer.getTime() <= mediaPlayer.getLength()) { // Song ~should~ already be loaded, unpause instead?
@ -97,22 +111,34 @@ public class VLCPlayer implements IPlayer {
throw new StartPlayingException(inputSong);
}
/**
* Reset the position of the seekbar.
*/
private void resetSeek(){
if(callbackInterface != null)
callbackInterface.setSeekBarPosition(0);
}
/**
* Stop playback.
*/
@Override
public void stop() {
resetSeek();
mediaPlayer.stop();
}
/**
* Resume playback.
*/
@Override
public void resume() {
mediaPlayer.setPause(false);
}
/**
* Pause playback.
*/
@Override
public void pause() {
mediaPlayer.setPause(true);
@ -123,52 +149,89 @@ public class VLCPlayer implements IPlayer {
}
}
/**
* Play the next song in the playlist.
* @throws StartPlayingException
*/
@Override
public void next() throws StartPlayingException {
playSong(playlist.getNext(currentSong));
}
/**
* Play the previous song in the playlist.
* @throws StartPlayingException
*/
@Override
public void previous() throws StartPlayingException {
playSong(playlist.getPrevious(currentSong));
}
/**
* @return The song currently playing (or set as ready to play)
*/
@Override
public Song getCurrentSong() {
return currentSong;
}
/**
* @return Current playback position in seconds.
*/
@Override
public int currentSongPosition() {
return (int)(mediaPlayer.getTime() / 1000);
}
/**
* Set playback volume.
* @param volume Volume value between 0 & 100.
*/
@Override
public void setVolume(int volume) {
currentVolume = volume;
mediaPlayer.setVolume(volume);
if(volume >= 0 && volume <= 100) {
currentVolume = volume;
mediaPlayer.setVolume(volume);
}
}
/**
* @return Current playback volume.
*/
@Override
public int getVolume() {
return (mediaPlayer.getVolume() >= 0) ? mediaPlayer.getVolume() : currentVolume;
}
/**
* Move to desired position in playback.
* @param position Time to move to in seconds.
*/
@Override
public void seek(int position) {
mediaPlayer.setTime(position * 1000);
}
/**
* @return Is the player currently playing.
*/
@Override
public boolean isPlaying() {
return mediaPlayer.isPlaying();
}
/**
* Set the player to single song repeat mode.
* @param repeatMode Repeat one song?
*/
@Override
public void setRepeat(boolean repeatMode) {
this.repeatMode = repeatMode;
}
/**
* @return Is the player set to repeat one song.
*/
@Override
public boolean isRepeating() {
return repeatMode;