From 74adb6f30c1f6b92d8b0a39e5ac5c270c9de51e0 Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Wed, 10 Jun 2020 05:34:21 -0400 Subject: [PATCH] #849 Resolves issue with frequency table column not updating after saving new channel configuration. (#850) Co-authored-by: Denny --- .../dsheirer/controller/channel/Channel.java | 44 ++++++++++++++++++- .../gui/playlist/channel/ChannelEditor.java | 25 ++++------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/github/dsheirer/controller/channel/Channel.java b/src/main/java/io/github/dsheirer/controller/channel/Channel.java index 34c59a94..aa00a7d8 100644 --- a/src/main/java/io/github/dsheirer/controller/channel/Channel.java +++ b/src/main/java/io/github/dsheirer/controller/channel/Channel.java @@ -39,6 +39,7 @@ import io.github.dsheirer.source.SourceType; import io.github.dsheirer.source.config.SourceConfigFactory; import io.github.dsheirer.source.config.SourceConfigRecording; import io.github.dsheirer.source.config.SourceConfigTuner; +import io.github.dsheirer.source.config.SourceConfigTunerMultipleFrequency; import io.github.dsheirer.source.config.SourceConfiguration; import io.github.dsheirer.source.tuner.channel.TunerChannel; import javafx.beans.Observable; @@ -48,10 +49,13 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.util.Callback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.beans.Transient; import java.util.Objects; @JacksonXmlRootElement(localName = "channel") @@ -78,6 +82,7 @@ public class Channel extends Configuration implements Listener private StringProperty mSystem = new SimpleStringProperty(); private StringProperty mSite = new SimpleStringProperty(); private StringProperty mName = new SimpleStringProperty(); + private ObservableList mFrequencyList; private BooleanProperty mProcessing = new SimpleBooleanProperty(); private BooleanProperty mAutoStart = new SimpleBooleanProperty(); @@ -178,6 +183,23 @@ public class Channel extends Configuration implements Listener return channel; } + /** + * Updates the frequencies property as the source configuration changes or is initialized. + */ + private void updateFrequencies() + { + getFrequencyList().clear(); + + if(mSourceConfiguration instanceof SourceConfigTuner) + { + getFrequencyList().add(((SourceConfigTuner)mSourceConfiguration).getFrequency()); + } + else if(mSourceConfiguration instanceof SourceConfigTunerMultipleFrequency) + { + getFrequencyList().addAll(((SourceConfigTunerMultipleFrequency)mSourceConfiguration).getFrequencies()); + } + } + /** * Alias list name property */ @@ -243,6 +265,23 @@ public class Channel extends Configuration implements Listener return mChannelID; } + /** + * List of frequencies extracted from the source configuration. This method only exists to support JavaFX + * monitoring of frequency list changes. Use the source configuration to manage frequencies. + */ + @JsonIgnore + @Transient + public ObservableList getFrequencyList() + { + if(mFrequencyList == null) + { + mFrequencyList = FXCollections.observableArrayList(); + updateFrequencies(); + } + + return mFrequencyList; + } + /** * Indicates if this channel has been selected for prioritized audio output * and display of processing chain products @@ -529,6 +568,8 @@ public class Channel extends Configuration implements Listener mSourceConfiguration = config; } + updateFrequencies(); + //Clear the tune channel object so that it can be recreated if the //source configuration changes mTunerChannel = null; @@ -676,6 +717,7 @@ public class Channel extends Configuration implements Listener public static Callback extractor() { return (Channel c) -> new Observable[] {c.processingProperty(), c.nameProperty(), c.aliasListNameProperty(), - c.autoStartOrderProperty(), c.autoStartProperty(), c.siteProperty(), c.systemProperty()}; + c.autoStartOrderProperty(), c.autoStartProperty(), c.siteProperty(), c.systemProperty(), + c.getFrequencyList()}; } } diff --git a/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelEditor.java b/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelEditor.java index 0d084fe2..3c785544 100644 --- a/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelEditor.java +++ b/src/main/java/io/github/dsheirer/gui/playlist/channel/ChannelEditor.java @@ -28,11 +28,10 @@ import io.github.dsheirer.module.decode.DecoderFactory; import io.github.dsheirer.module.decode.DecoderType; import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.preference.UserPreferences; -import io.github.dsheirer.source.config.SourceConfigTuner; -import io.github.dsheirer.source.config.SourceConfigTunerMultipleFrequency; import javafx.application.Platform; import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; +import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.SortedList; import javafx.geometry.Insets; @@ -642,6 +641,7 @@ public class ChannelEditor extends SplitPane } } + /** * Channel tuner channel source frequencies value factory */ @@ -653,26 +653,17 @@ public class ChannelEditor extends SplitPane @Override public ObservableValue call(TableColumn.CellDataFeatures param) { - Channel channel = param.getValue(); + ObservableList frequencies = param.getValue().getFrequencyList(); - if(channel != null) + if(frequencies != null) { - if(channel.getSourceConfiguration() instanceof SourceConfigTuner) + List freqsMHz = new ArrayList<>(); + for(Long frequency: frequencies) { - long frequency = ((SourceConfigTuner)channel.getSourceConfiguration()).getFrequency(); - mFrequency.set(String.valueOf(frequency / 1E6)); + freqsMHz.add(String.valueOf(frequency / 1E6)); } - else if(channel.getSourceConfiguration() instanceof SourceConfigTunerMultipleFrequency) - { - List frequencies = ((SourceConfigTunerMultipleFrequency)channel.getSourceConfiguration()).getFrequencies(); - List formatted = new ArrayList<>(); - for(Long frequency: frequencies) - { - formatted.add(String.valueOf(frequency / 1E6)); - } - mFrequency.set(Joiner.on(",").join(formatted)); - } + mFrequency.set(Joiner.on(", ").join(freqsMHz)); } else {