Skip to content

Commit

Permalink
Keep player settings and window position
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenni0451 committed Mar 22, 2024
1 parent 7849920 commit 3c938b4
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ public class SongPlayerFrame extends JFrame implements ISongPlayerCallback {
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
private static SongPlayerFrame instance;
private static SoundSystem forcedSoundSystem;
private static Point lastPosition;
private static int lastMaxSounds = 256;
private static int lastVolume = 50;

public static void open(final ListFrame.LoadedSong song) {
open(song, song.getSong().getView());
}

public static void open(final ListFrame.LoadedSong song, final SongView<?> view) {
if (instance != null) instance.dispose();
if (instance != null && instance.isVisible()) {
lastPosition = instance.getLocation();
lastMaxSounds = (int) instance.maxSoundsSpinner.getValue();
lastVolume = instance.volumeSlider.getValue();
instance.dispose();
}
instance = new SongPlayerFrame(song, view);
if (lastPosition != null) instance.setLocation(lastPosition);
instance.maxSoundsSpinner.setValue(lastMaxSounds);
instance.volumeSlider.setValue(lastVolume);
instance.setVisible(true);
}


Expand All @@ -63,7 +75,7 @@ public static void open(final ListFrame.LoadedSong song, final SongView<?> view)
private final Timer updateTimer;
private final JComboBox<String> soundSystemComboBox = new JComboBox<>(new String[]{SoundSystem.OPENAL.getName(), SoundSystem.JAVAX.getName()});
private final JSpinner maxSoundsSpinner = new JSpinner(new SpinnerNumberModel(256, 64, 8192, 64));
private final JSlider volumeSlider = new JSlider(0, 100, 100);
private final JSlider volumeSlider = new JSlider(0, 100, 50);
private final JButton playStopButton = new JButton("Play");
private final JButton pauseResumeButton = new JButton("Pause");
private final JSlider progressSlider = new JSlider(0, 100, 0);
Expand Down Expand Up @@ -94,7 +106,6 @@ private SongPlayerFrame(final ListFrame.LoadedSong song, final SongView<?> view)
this.playStopButton.doClick();

this.setMinimumSize(this.getSize());
this.setVisible(true);
}

private SongView<?> getSongView(final SongView<?> view) {
Expand All @@ -119,7 +130,11 @@ private void initComponents() {
GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.soundSystemComboBox);

GBC.create(northPanel).grid(0, gridy).insets(5, 5, 0, 5).anchor(GBC.LINE_START).add(new JLabel("Max Sounds:"));
GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.maxSoundsSpinner);
GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 0, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.maxSoundsSpinner, () -> {
this.maxSoundsSpinner.addChangeListener(e -> {
lastMaxSounds = (int) this.maxSoundsSpinner.getValue();
});
});

GBC.create(northPanel).grid(0, gridy).insets(5, 5, 5, 5).anchor(GBC.LINE_START).add(new JLabel("Volume:"));
GBC.create(northPanel).grid(1, gridy++).insets(5, 0, 5, 5).weightx(1).fill(GBC.HORIZONTAL).add(this.volumeSlider, () -> {
Expand All @@ -130,6 +145,7 @@ private void initComponents() {
this.volumeSlider.addChangeListener(e -> {
this.volume = this.volumeSlider.getValue() / 100F;
if (this.soundSystem.equals(SoundSystem.OPENAL)) OpenALSoundSystem.setMasterVolume(this.volume);
lastVolume = this.volumeSlider.getValue();
});
});
}
Expand Down Expand Up @@ -237,6 +253,7 @@ private void initFrameHandler() {
@Override
public void windowClosing(WindowEvent e) {
SongPlayerFrame.this.dispose();
lastPosition = SongPlayerFrame.this.getLocation();
}

@Override
Expand Down

0 comments on commit 3c938b4

Please sign in to comment.