diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index b8f74a1..6f61e1c 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -4,9 +4,7 @@ import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; import musicplayer.callbacks.PlayerCallbackInterface; -import musicplayer.db.IDatabase; import musicplayer.library.ILibrary; -import musicplayer.model.Song; import musicplayer.player.IPlayer; import musicplayer.playlist.IPlaylist; import musicplayer.util.ConfigManager; diff --git a/src/main/java/musicplayer/SwingUIModule.java b/src/main/java/musicplayer/SwingUIModule.java index 9acc9bd..76e3f88 100644 --- a/src/main/java/musicplayer/SwingUIModule.java +++ b/src/main/java/musicplayer/SwingUIModule.java @@ -11,7 +11,7 @@ import musicplayer.player.IPlayer; import musicplayer.playlist.IPlaylist; import musicplayer.playlist.JTablePlaylist; -public class SwingUIModule extends AbstractModule { +class SwingUIModule extends AbstractModule { @Override protected void configure() { diff --git a/src/main/java/musicplayer/callbacks/PlayerCallbackInterface.java b/src/main/java/musicplayer/callbacks/PlayerCallbackInterface.java index a0ad802..c8a562f 100644 --- a/src/main/java/musicplayer/callbacks/PlayerCallbackInterface.java +++ b/src/main/java/musicplayer/callbacks/PlayerCallbackInterface.java @@ -2,7 +2,6 @@ package musicplayer.callbacks; import com.google.inject.ImplementedBy; import musicplayer.PlayerGUI; -import musicplayer.model.Song; @ImplementedBy(PlayerGUI.class) public interface PlayerCallbackInterface { diff --git a/src/main/java/musicplayer/db/HibernateDatabase.java b/src/main/java/musicplayer/db/HibernateDatabase.java index d14b672..cbc6f3b 100644 --- a/src/main/java/musicplayer/db/HibernateDatabase.java +++ b/src/main/java/musicplayer/db/HibernateDatabase.java @@ -20,7 +20,7 @@ import java.util.Properties; */ public class HibernateDatabase implements IDatabase{ - private static SessionFactory sessionFactory; + private SessionFactory sessionFactory; /** * Create a database connection. @@ -57,6 +57,8 @@ public class HibernateDatabase implements IDatabase{ .addAnnotatedClass(Artist.class) .addAnnotatedClass(Song.class) .buildSessionFactory(); + Thread hookShutdown = new Thread(sessionFactory::close); + Runtime.getRuntime().addShutdownHook(hookShutdown); } /** diff --git a/src/main/java/musicplayer/library/JTreeLibrary.java b/src/main/java/musicplayer/library/JTreeLibrary.java index 5465ac6..34b653e 100644 --- a/src/main/java/musicplayer/library/JTreeLibrary.java +++ b/src/main/java/musicplayer/library/JTreeLibrary.java @@ -29,8 +29,8 @@ import java.util.stream.Collectors; public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInterface{ - IDatabase database; - IPlaylist playlist; + private IDatabase database; + private IPlaylist playlist; private static final DefaultMutableTreeNode updatingNode = new DefaultMutableTreeNode(); private final AtomicBoolean libraryUpdating = new AtomicBoolean(false); private final JComboBox libraryDisplayType = new JComboBox<>(); @@ -182,7 +182,8 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt int selRow = libraryTree.getRowForLocation(e.getX(), e.getY()); if(e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2 && selRow != -1) try { - Object selectedItem = ((DefaultMutableTreeNode) libraryTree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent()).getUserObject(); + @SuppressWarnings("ConstantConditions") Object selectedItem = + ((DefaultMutableTreeNode) libraryTree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent()).getUserObject(); if (selectedItem != null) { if (selectedItem instanceof Song) { playlist.addSong((Song) selectedItem); @@ -198,6 +199,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt private class LibraryTreeCellRenderer implements TreeCellRenderer { private final JLabel label; + @SuppressWarnings("ConstantConditions") private final Icon missingIcon = new ImageIcon(JTreeLibrary.class.getClassLoader().getResource("missing.gif")); LibraryTreeCellRenderer() { diff --git a/src/main/java/musicplayer/model/Song.java b/src/main/java/musicplayer/model/Song.java index 0610c4f..b621b26 100644 --- a/src/main/java/musicplayer/model/Song.java +++ b/src/main/java/musicplayer/model/Song.java @@ -1,16 +1,7 @@ package musicplayer.model; -import javax.imageio.ImageIO; import javax.persistence.*; -import java.awt.image.BufferedImage; import java.io.File; -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.NoSuchElementException; -import java.util.Optional; @Entity public class Song implements Comparable, IDBType {