Skip to content

Commit

Permalink
#1723 wip trying to fix the repaint when switching between playback c…
Browse files Browse the repository at this point in the history
…hannel view styles.
  • Loading branch information
Dennis Sheirer committed Jan 9, 2024
1 parent e596447 commit 0691437
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class AudioPlaybackChannelsView extends HBox implements IPreferenceUpdate
private List<AudioPlaybackChannelView> mAudioPlaybackChannelViews = new ArrayList<>();
private GridPane mGridPane;
private PlaybackView mPlaybackView;
private IPanelRevalidationRequestListener mListener;

/**
* Constructs an instance
Expand All @@ -58,6 +59,15 @@ public AudioPlaybackChannelsView()
widthProperty().addListener((observable, oldValue, newValue) -> resetWidth());
}

/**
* Registers a listener to receive requests from this view for Swing revalidation
* @param listener to receive request.
*/
public void setPanelRevalidationRequestListener(IPanelRevalidationRequestListener listener)
{
mListener = listener;
}

/**
* Implements preference type update listener to be notified if the user changes the playback view preference.
* @param preferenceType that was updated
Expand All @@ -69,10 +79,17 @@ public void preferenceUpdated(PreferenceType preferenceType)
{
PlaybackView preferred = mUserPreferences.getPlaybackPreference().getPlaybackView();

System.out.println("Preferred: " + preferred + " Current: " + mPlaybackView);
if(mPlaybackView != preferred)
{
mPlaybackView = preferred;
updatePlaybackViews();

if(mListener != null)
{
System.out.println("Calling listener ...");
mListener.revalidatePanel();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/

package io.github.dsheirer.audio.playbackfx;

/**
* Interface to receive request for a Swing UI revaliation request from within JavaFX.
*/
public interface IPanelRevalidationRequestListener
{
void revalidatePanel();
}
30 changes: 28 additions & 2 deletions src/main/java/io/github/dsheirer/controller/ControllerPanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -22,6 +22,7 @@
import io.github.dsheirer.audio.call.CallView;
import io.github.dsheirer.audio.playback.AudioPanel;
import io.github.dsheirer.audio.playbackfx.AudioPlaybackChannelsView;
import io.github.dsheirer.audio.playbackfx.IPanelRevalidationRequestListener;
import io.github.dsheirer.channel.metadata.NowPlayingPanel;
import io.github.dsheirer.eventbus.MyEventBus;
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
Expand All @@ -31,6 +32,7 @@
import jakarta.annotation.Resource;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
Expand All @@ -44,7 +46,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ControllerPanel extends JPanel
public class ControllerPanel extends JPanel implements IPanelRevalidationRequestListener
{
private final static Logger mLog = LoggerFactory.getLogger(ControllerPanel.class);
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -80,6 +82,7 @@ public void postConstruct()

// add(mAudioPanel, "wrap");
add(getAudioPlaybackViewPanel(), "wrap");
mAudioPlaybackChannelsView.setPanelRevalidationRequestListener(this);

mTabbedPane = new JideTabbedPane()
{
Expand Down Expand Up @@ -113,6 +116,29 @@ public void setSelectedIndex(int index)
add(mTabbedPane, "wrap");
}

/**
* Implements listener interface to revalidate JavaFX panel when the audio channel view style has changed.
*/
@Override
public void revalidatePanel()
{
System.out.println("Revalidating layout");

//TODO: fix this??
EventQueue.invokeLater(() -> {
getAudioPlaybackViewPanel().invalidate();
});

// Platform.runLater(new Runnable()
// {
// @Override
// public void run()
// {
// mJFXAudioPlaybackViewPanel.setScene(new Scene(mAudioPlaybackChannelsView));
// }
// });
}

/**
* Now playing panel.
*/
Expand Down

0 comments on commit 0691437

Please sign in to comment.