diff --git a/src/ch/hevs/isc/slopify_v2/GUI.scala b/src/ch/hevs/isc/slopify_v2/GUI.scala index 7d9b8dd..faefe30 100644 --- a/src/ch/hevs/isc/slopify_v2/GUI.scala +++ b/src/ch/hevs/isc/slopify_v2/GUI.scala @@ -1,5 +1,6 @@ package ch.hevs.isc.slopify_v2 +import java.awt.{GridBagConstraints, GridBagLayout, LayoutManager} import java.util import javax.swing._ import javax.swing.table.{DefaultTableModel, TableModel, TableRowSorter} @@ -12,7 +13,11 @@ class GUI extends JFrame { val artistsListModel: DefaultListModel[String] = new DefaultListModel[String]() val artistsList: JList[String] = new JList(artistsListModel) artistsList.setLayoutOrientation(JList.VERTICAL) - val col1: JScrollPane = new JScrollPane(artistsList) + val col1: JPanel = new JPanel() + val col1Layout: GridBagLayout = new GridBagLayout() + col1.setLayout(col1Layout) + + val artistsPane: JScrollPane = new JScrollPane(artistsList) artistsList.addListSelectionListener(_ => { val artistName: String = artistsList.getSelectedValue val artist: Option[Artist] = db.getArtistByName(artistName) @@ -23,6 +28,23 @@ class GUI extends JFrame { } }) + val artistsSearchBar: JTextField = new JTextField() + artistsSearchBar.addActionListener(_ => updateArtistsSearch()) + + val col1Constraints: GridBagConstraints = new GridBagConstraints() + col1Constraints.fill = GridBagConstraints.BOTH + col1Constraints.gridx = 0 + col1Constraints.gridy = 0 + col1Constraints.weightx = 1 + col1Constraints.weighty = 1 + col1.add(artistsPane, col1Constraints) + + col1Constraints.fill = GridBagConstraints.HORIZONTAL + col1Constraints.gridx = 0 + col1Constraints.gridy = 1 + col1Constraints.weighty = 0 + col1.add(artistsSearchBar, col1Constraints) + // Albums val albumsListModel: DefaultListModel[String] = new DefaultListModel[String]() val albumsList: JList[String] = new JList(albumsListModel) @@ -162,6 +184,21 @@ class GUI extends JFrame { def selectSong(song: Song): Unit = { curSong = Some(song) } + + def updateArtistsSearch(): Unit = { + val search: String = artistsSearchBar.getText.toLowerCase + + clearArtists() + clearAlbums() + clearSongs() + var artists: Array[Artist] = db.getArtists().sortBy(_.name) + if (search.nonEmpty) { + artists = artists.filter(_.name.toLowerCase.contains(search)) + } + for (artist: Artist <- artists) { + addArtist(artist) + } + } } object GUI {