Package MediaPlayer

Class PlaylistController


  • public class PlaylistController
    extends java.lang.Object
    Controller class that manages the playlist using a LinkedList data structure. Handles operations like adding, removing, reordering, and sorting songs.
    • Constructor Summary

      Constructors 
      Constructor Description
      PlaylistController​(javax.swing.table.DefaultTableModel tableModel, javax.swing.JFrame parentFrame)
      Creates a new PlaylistController.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSong​(Song song)
      Adds a song to the end of the playlist.
      void clearPlaylist()
      Clears all songs from the playlist.
      LinkedList<Song> getAllSongs()
      Gets all songs in the playlist.
      int getSize()
      Gets the current size of the playlist.
      Song getSongAt​(int index)
      Gets a song from the playlist at a specific index.
      int moveSongDown​(int index)
      Moves a song down one position in the playlist.
      int moveSongUp​(int index)
      Moves a song up one position in the playlist.
      boolean removeSong​(int index)
      Removes a song from the playlist at the given index.
      void sortByTitle()
      Sorts the playlist alphabetically by song title.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PlaylistController

        public PlaylistController​(javax.swing.table.DefaultTableModel tableModel,
                                  javax.swing.JFrame parentFrame)
        Creates a new PlaylistController.
        Parameters:
        tableModel - The table model to update with playlist data
        parentFrame - The parent frame for displaying dialogs
    • Method Detail

      • addSong

        public void addSong​(Song song)
        Adds a song to the end of the playlist.
        Parameters:
        song - The song to add to the playlist
      • removeSong

        public boolean removeSong​(int index)
        Removes a song from the playlist at the given index.
        Parameters:
        index - The index of the song to remove
        Returns:
        true if removal was successful, false otherwise
      • moveSongUp

        public int moveSongUp​(int index)
        Moves a song up one position in the playlist.
        Parameters:
        index - The index of the song to move
        Returns:
        The new index of the song, or -1 if move failed
      • moveSongDown

        public int moveSongDown​(int index)
        Moves a song down one position in the playlist.
        Parameters:
        index - The index of the song to move
        Returns:
        The new index of the song, or -1 if move failed
      • sortByTitle

        public void sortByTitle()
        Sorts the playlist alphabetically by song title.
      • getSize

        public int getSize()
        Gets the current size of the playlist.
        Returns:
        The number of songs in the playlist
      • getSongAt

        public Song getSongAt​(int index)
        Gets a song from the playlist at a specific index.
        Parameters:
        index - The index of the song to retrieve
        Returns:
        The song at the specified index, or null if index is invalid
      • getAllSongs

        public LinkedList<Song> getAllSongs()
        Gets all songs in the playlist.
        Returns:
        An unmodifiable list of all songs in the playlist
      • clearPlaylist

        public void clearPlaylist()
        Clears all songs from the playlist.