From afce1a8628f4648cde88542860b157f753b18bf4 Mon Sep 17 00:00:00 2001 From: Markil3 <75867393+Markil3@users.noreply.github.com> Date: Sun, 31 Oct 2021 16:01:07 -0600 Subject: [PATCH] Moves some interface activities to the Swing thread. We really should be doing this anyway. --- .../regis/universeplayer/gui/Interface.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java b/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java index 3e8f5b3..cbf593c 100644 --- a/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java +++ b/interface/src/main/java/edu/regis/universeplayer/gui/Interface.java @@ -244,7 +244,7 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL .showMessageDialog(Interface.this, command.getException(), command.getException() - .getMessage(), + .getMessage(), JOptionPane.ERROR_MESSAGE); } return null; @@ -461,7 +461,7 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL this.setFocusCycleRoot(true); this.getContentPane() - .add(this.collectionTypes, BorderLayout.LINE_START); + .add(this.collectionTypes, BorderLayout.LINE_START); this.collectionTypes.addFocusListener(this); this.collectionTypes.addSongDisplayListener(this); @@ -562,18 +562,24 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL @Override public void updateSongs(Collection songs) { - this.songList.listAlbums(songs); - this.centerView.setViewportView(this.songList); - this.centerView.revalidate(); + SwingUtilities.invokeLater(() -> + { + this.songList.listAlbums(songs); + this.centerView.setViewportView(this.songList); + this.centerView.revalidate(); + }); } @Override public void updateCollections(CollectionType type, Collection collections) { - this.collectionList.listCollection(type, collections); - this.centerView.setViewportView(this.collectionList); - this.collectionList.revalidate(); - this.centerView.revalidate(); + SwingUtilities.invokeLater(() -> + { + this.collectionList.listCollection(type, collections); + this.centerView.setViewportView(this.collectionList); + this.collectionList.revalidate(); + this.centerView.revalidate(); + }); } @Override @@ -644,18 +650,21 @@ public class Interface extends JFrame implements SongDisplayListener, ComponentL public void onUpdate(DataProvider provider, int updated, int totalUpdate, String updating) { - this.controls.setUpdateProgress(updated, totalUpdate, updating); - if (updated == totalUpdate || totalUpdate == 0) + SwingUtilities.invokeLater(() -> { - Collection songs = - PlayerEnvironment.getSongs().getSongs(); - logger.debug("Resetting the song provider with {} songs.", - songs.size()); - /* - * TODO - Add some way to get back to the current view, just updated - */ - this.updateSongs(songs); - } + this.controls.setUpdateProgress(updated, totalUpdate, updating); + if (updated == totalUpdate || totalUpdate == 0) + { + Collection songs = + PlayerEnvironment.getSongs().getSongs(); + logger.debug("Resetting the song provider with {} songs.", + songs.size()); + /* + * TODO - Add some way to get back to the current view, just updated + */ + this.updateSongs(songs); + } + }); } @Override