#849 Resolves issue with frequency table column not updating after saving new channel configuration. (#850)

Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
Denny Sheirer
2020-06-10 05:34:21 -04:00
committed by GitHub
parent 421abe5768
commit 74adb6f30c
2 changed files with 51 additions and 18 deletions

View File

@@ -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<SourceEvent>
private StringProperty mSystem = new SimpleStringProperty();
private StringProperty mSite = new SimpleStringProperty();
private StringProperty mName = new SimpleStringProperty();
private ObservableList<Long> mFrequencyList;
private BooleanProperty mProcessing = new SimpleBooleanProperty();
private BooleanProperty mAutoStart = new SimpleBooleanProperty();
@@ -178,6 +183,23 @@ public class Channel extends Configuration implements Listener<SourceEvent>
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<SourceEvent>
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<Long> 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<SourceEvent>
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<SourceEvent>
public static Callback<Channel,Observable[]> 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()};
}
}

View File

@@ -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<String> call(TableColumn.CellDataFeatures<Channel, String> param)
{
Channel channel = param.getValue();
ObservableList<Long> frequencies = param.getValue().getFrequencyList();
if(channel != null)
if(frequencies != null)
{
if(channel.getSourceConfiguration() instanceof SourceConfigTuner)
List<String> 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<Long> frequencies = ((SourceConfigTunerMultipleFrequency)channel.getSourceConfiguration()).getFrequencies();
List<String> 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
{