mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-17 11:07:35 -05:00
Compare commits
5 Commits
2672-dispa
...
DSheirer-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f7e37f9ec | ||
|
|
7f1e7d9cd2 | ||
|
|
7a7364839b | ||
|
|
2213544eec | ||
|
|
feeedb7c29 |
@@ -4,6 +4,7 @@
|
|||||||
[](https://github.com/DSheirer/sdrtrunk/releases)
|
[](https://github.com/DSheirer/sdrtrunk/releases)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://discord.gg/HJQaKYE)
|
[](https://discord.gg/HJQaKYE)
|
||||||
|
[](https://groups.google.com/g/sdrtrunk)
|
||||||
|
|
||||||
# sdrtrunk
|
# sdrtrunk
|
||||||
A cross-platform java application for decoding, monitoring, recording and streaming trunked mobile and related radio protocols using Software Defined Radios (SDR).
|
A cross-platform java application for decoding, monitoring, recording and streaming trunked mobile and related radio protocols using Software Defined Radios (SDR).
|
||||||
|
|||||||
@@ -0,0 +1,269 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.alias;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||||
|
import javafx.beans.Observable;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.IntegerProperty;
|
||||||
|
import javafx.beans.property.LongProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleLongProperty;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persisted settings for an alias list. Alias lists are otherwise identified only by the list name that each alias
|
||||||
|
* carries, so settings that belong to the list itself, like tracking a Radio Reference system, are stored here and
|
||||||
|
* saved in the playlist.
|
||||||
|
*
|
||||||
|
* Radio Reference tracking uses two timestamps from the Radio Reference system's last updated value: the last updated
|
||||||
|
* value seen by the most recent check, and the last updated value that the aliases were synchronized to. When the
|
||||||
|
* seen value is newer than the synchronized value, the system changed on Radio Reference and the aliases haven't
|
||||||
|
* been updated yet.
|
||||||
|
*/
|
||||||
|
public class AliasListConfiguration
|
||||||
|
{
|
||||||
|
public static final int NO_SYSTEM = 0;
|
||||||
|
|
||||||
|
private StringProperty mName = new SimpleStringProperty();
|
||||||
|
private IntegerProperty mRadioReferenceSystemId = new SimpleIntegerProperty(NO_SYSTEM);
|
||||||
|
private StringProperty mRadioReferenceSystemName = new SimpleStringProperty();
|
||||||
|
private BooleanProperty mAutoUpdate = new SimpleBooleanProperty();
|
||||||
|
private LongProperty mRadioReferenceLastUpdated = new SimpleLongProperty();
|
||||||
|
private LongProperty mSynchronizedLastUpdated = new SimpleLongProperty();
|
||||||
|
private LongProperty mLastChecked = new SimpleLongProperty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson constructor
|
||||||
|
*/
|
||||||
|
public AliasListConfiguration()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
* @param name of the alias list
|
||||||
|
*/
|
||||||
|
public AliasListConfiguration(String name)
|
||||||
|
{
|
||||||
|
setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extractor so that observable lists of configurations report changes to the persisted properties.
|
||||||
|
*/
|
||||||
|
public static Callback<AliasListConfiguration,Observable[]> extractor()
|
||||||
|
{
|
||||||
|
return (AliasListConfiguration c) -> new Observable[] {c.mName, c.mRadioReferenceSystemId,
|
||||||
|
c.mRadioReferenceSystemName, c.mAutoUpdate, c.mRadioReferenceLastUpdated, c.mSynchronizedLastUpdated,
|
||||||
|
c.mLastChecked};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias list name
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "name")
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return mName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name)
|
||||||
|
{
|
||||||
|
mName.set(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public StringProperty nameProperty()
|
||||||
|
{
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if this alias list tracks a Radio Reference system.
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isTrackingRadioReferenceSystem()
|
||||||
|
{
|
||||||
|
return getRadioReferenceSystemId() > NO_SYSTEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if this alias list tracks the specified Radio Reference system.
|
||||||
|
*/
|
||||||
|
public boolean isTracking(int systemId)
|
||||||
|
{
|
||||||
|
return systemId > NO_SYSTEM && getRadioReferenceSystemId() == systemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio Reference system ID tracked by this alias list, or NO_SYSTEM (0).
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_system_id")
|
||||||
|
public int getRadioReferenceSystemId()
|
||||||
|
{
|
||||||
|
return mRadioReferenceSystemId.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadioReferenceSystemId(int systemId)
|
||||||
|
{
|
||||||
|
mRadioReferenceSystemId.set(systemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public IntegerProperty radioReferenceSystemIdProperty()
|
||||||
|
{
|
||||||
|
return mRadioReferenceSystemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio Reference system name, for display.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_system_name")
|
||||||
|
public String getRadioReferenceSystemName()
|
||||||
|
{
|
||||||
|
return mRadioReferenceSystemName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadioReferenceSystemName(String name)
|
||||||
|
{
|
||||||
|
mRadioReferenceSystemName.set(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public StringProperty radioReferenceSystemNameProperty()
|
||||||
|
{
|
||||||
|
return mRadioReferenceSystemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if talkgroups are automatically added or updated as aliases when the system changes on Radio Reference.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_auto_update")
|
||||||
|
public boolean isAutoUpdate()
|
||||||
|
{
|
||||||
|
return mAutoUpdate.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoUpdate(boolean autoUpdate)
|
||||||
|
{
|
||||||
|
mAutoUpdate.set(autoUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public BooleanProperty autoUpdateProperty()
|
||||||
|
{
|
||||||
|
return mAutoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio Reference last updated timestamp (ms since epoch) for the system, as seen by the most recent check.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_last_updated")
|
||||||
|
public long getRadioReferenceLastUpdated()
|
||||||
|
{
|
||||||
|
return mRadioReferenceLastUpdated.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadioReferenceLastUpdated(long timestamp)
|
||||||
|
{
|
||||||
|
mRadioReferenceLastUpdated.set(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public LongProperty radioReferenceLastUpdatedProperty()
|
||||||
|
{
|
||||||
|
return mRadioReferenceLastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio Reference last updated timestamp (ms since epoch) that the aliases were last synchronized to.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_synchronized")
|
||||||
|
public long getSynchronizedLastUpdated()
|
||||||
|
{
|
||||||
|
return mSynchronizedLastUpdated.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSynchronizedLastUpdated(long timestamp)
|
||||||
|
{
|
||||||
|
mSynchronizedLastUpdated.set(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public LongProperty synchronizedLastUpdatedProperty()
|
||||||
|
{
|
||||||
|
return mSynchronizedLastUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time (ms since epoch) of the most recent successful check of the system on Radio Reference.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "rr_last_checked")
|
||||||
|
public long getLastChecked()
|
||||||
|
{
|
||||||
|
return mLastChecked.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastChecked(long timestamp)
|
||||||
|
{
|
||||||
|
mLastChecked.set(timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public LongProperty lastCheckedProperty()
|
||||||
|
{
|
||||||
|
return mLastChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the most recent check saw a system change on Radio Reference that the aliases don't include yet.
|
||||||
|
*/
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isUpdateAvailable()
|
||||||
|
{
|
||||||
|
return isTrackingRadioReferenceSystem() && getRadioReferenceLastUpdated() > getSynchronizedLastUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts tracking the Radio Reference system. Clears timestamps so that the next refresh synchronizes.
|
||||||
|
*/
|
||||||
|
public void track(int systemId, String systemName)
|
||||||
|
{
|
||||||
|
setRadioReferenceSystemId(systemId);
|
||||||
|
setRadioReferenceSystemName(systemName);
|
||||||
|
setRadioReferenceLastUpdated(0);
|
||||||
|
setSynchronizedLastUpdated(0);
|
||||||
|
setLastChecked(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops tracking any Radio Reference system.
|
||||||
|
*/
|
||||||
|
public void stopTracking()
|
||||||
|
{
|
||||||
|
track(NO_SYSTEM, null);
|
||||||
|
setAutoUpdate(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,8 @@ public class AliasModel
|
|||||||
private ObservableList<Alias> mAliases = FXCollections.observableArrayList(Alias.extractor());
|
private ObservableList<Alias> mAliases = FXCollections.observableArrayList(Alias.extractor());
|
||||||
private ObservableList<String> mAliasListNames = FXCollections.observableArrayList();
|
private ObservableList<String> mAliasListNames = FXCollections.observableArrayList();
|
||||||
private Map<String,AliasList> mAliasListMap = new HashMap<>();
|
private Map<String,AliasList> mAliasListMap = new HashMap<>();
|
||||||
|
private ObservableList<AliasListConfiguration> mAliasListConfigurations =
|
||||||
|
FXCollections.observableArrayList(AliasListConfiguration.extractor());
|
||||||
|
|
||||||
public AliasModel()
|
public AliasModel()
|
||||||
{
|
{
|
||||||
@@ -63,6 +65,99 @@ public class AliasModel
|
|||||||
return mAliasListNames;
|
return mAliasListNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Observable list of persisted alias list configurations. Only alias lists with settings, like Radio Reference
|
||||||
|
* system tracking, have a configuration.
|
||||||
|
*/
|
||||||
|
public ObservableList<AliasListConfiguration> aliasListConfigurations()
|
||||||
|
{
|
||||||
|
return mAliasListConfigurations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk loading of alias list configurations from a playlist. Ignores configurations without a name and
|
||||||
|
* duplicates of an earlier configuration's name.
|
||||||
|
*/
|
||||||
|
public void addAliasListConfigurations(List<AliasListConfiguration> configurations)
|
||||||
|
{
|
||||||
|
if(configurations != null)
|
||||||
|
{
|
||||||
|
for(AliasListConfiguration configuration: configurations)
|
||||||
|
{
|
||||||
|
String name = configuration.getName();
|
||||||
|
|
||||||
|
if(name != null && !name.isEmpty() && getAliasListConfiguration(name) == null)
|
||||||
|
{
|
||||||
|
mAliasListConfigurations.add(configuration);
|
||||||
|
addAliasList(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the named alias list.
|
||||||
|
* @param aliasListName to find
|
||||||
|
* @return configuration or null if the alias list doesn't have one
|
||||||
|
*/
|
||||||
|
public AliasListConfiguration getAliasListConfiguration(String aliasListName)
|
||||||
|
{
|
||||||
|
if(aliasListName != null)
|
||||||
|
{
|
||||||
|
for(AliasListConfiguration configuration: mAliasListConfigurations)
|
||||||
|
{
|
||||||
|
if(aliasListName.equals(configuration.getName()))
|
||||||
|
{
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the named alias list, created when the alias list doesn't have one.
|
||||||
|
* @param aliasListName for the configuration, not null or the (No Alias List) name
|
||||||
|
* @return configuration
|
||||||
|
*/
|
||||||
|
public AliasListConfiguration getOrCreateAliasListConfiguration(String aliasListName)
|
||||||
|
{
|
||||||
|
if(aliasListName == null || aliasListName.isEmpty() || aliasListName.equals(NO_ALIAS_LIST))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid alias list name [" + aliasListName + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
AliasListConfiguration configuration = getAliasListConfiguration(aliasListName);
|
||||||
|
|
||||||
|
if(configuration == null)
|
||||||
|
{
|
||||||
|
configuration = new AliasListConfiguration(aliasListName);
|
||||||
|
mAliasListConfigurations.add(configuration);
|
||||||
|
addAliasList(aliasListName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the first alias list that tracks the Radio Reference system.
|
||||||
|
* @param systemId of the Radio Reference system
|
||||||
|
* @return alias list name or null
|
||||||
|
*/
|
||||||
|
public String getAliasListNameTracking(int systemId)
|
||||||
|
{
|
||||||
|
for(AliasListConfiguration configuration: mAliasListConfigurations)
|
||||||
|
{
|
||||||
|
if(configuration.isTracking(systemId))
|
||||||
|
{
|
||||||
|
return configuration.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears and reloads the list of alias list names from the current set of aliases.
|
* Clears and reloads the list of alias list names from the current set of aliases.
|
||||||
*/
|
*/
|
||||||
@@ -79,6 +174,15 @@ public class AliasModel
|
|||||||
mAliasListNames.add(aliasListName);
|
mAliasListNames.add(aliasListName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Alias lists with a configuration exist even before they have any aliases
|
||||||
|
for(AliasListConfiguration configuration: mAliasListConfigurations)
|
||||||
|
{
|
||||||
|
if(!mAliasListNames.contains(configuration.getName()))
|
||||||
|
{
|
||||||
|
mAliasListNames.add(configuration.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +197,22 @@ public class AliasModel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mAliases.stream().filter(alias -> alias.getAliasListName().equals(oldName)).forEach(alias -> alias.setAliasListName(newName));
|
mAliases.stream().filter(alias -> oldName.equals(alias.getAliasListName())).forEach(alias -> alias.setAliasListName(newName));
|
||||||
|
|
||||||
|
AliasListConfiguration configuration = getAliasListConfiguration(oldName);
|
||||||
|
|
||||||
|
if(configuration != null)
|
||||||
|
{
|
||||||
|
//Merging into an existing list keeps that list's configuration
|
||||||
|
if(getAliasListConfiguration(newName) == null)
|
||||||
|
{
|
||||||
|
configuration.setName(newName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mAliasListConfigurations.remove(configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +228,7 @@ public class AliasModel
|
|||||||
|
|
||||||
mAliases.removeIf(alias -> alias.getAliasListName().equals(aliasListName));
|
mAliases.removeIf(alias -> alias.getAliasListName().equals(aliasListName));
|
||||||
mAliasListMap.remove(aliasListName);
|
mAliasListMap.remove(aliasListName);
|
||||||
|
mAliasListConfigurations.removeIf(configuration -> aliasListName.equals(configuration.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,6 +266,7 @@ public class AliasModel
|
|||||||
removeAlias(alias);
|
removeAlias(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAliasListConfigurations.clear();
|
||||||
mAliasListNames.clear();
|
mAliasListNames.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
455
src/main/java/io/github/dsheirer/alias/TalkerAliasAutoAdder.java
Normal file
455
src/main/java/io/github/dsheirer/alias/TalkerAliasAutoAdder.java
Normal file
@@ -0,0 +1,455 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.alias;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import io.github.dsheirer.alias.id.AliasID;
|
||||||
|
import io.github.dsheirer.alias.id.radio.NXDNTypeDRadio;
|
||||||
|
import io.github.dsheirer.alias.id.radio.P25FullyQualifiedRadio;
|
||||||
|
import io.github.dsheirer.alias.id.radio.Radio;
|
||||||
|
import io.github.dsheirer.identifier.alias.TalkerAliasIdentifier;
|
||||||
|
import io.github.dsheirer.identifier.radio.FullyQualifiedRadioIdentifier;
|
||||||
|
import io.github.dsheirer.identifier.radio.RadioIdentifier;
|
||||||
|
import io.github.dsheirer.module.decode.nxdn.identifier.NXDNRadioIdentifier;
|
||||||
|
import io.github.dsheirer.protocol.Protocol;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically adds decoded talker aliases to an alias list as radio aliases, using the talker alias as the alias name,
|
||||||
|
* and renames a stored radio alias when the radio's talker alias changes.
|
||||||
|
*
|
||||||
|
* Talker aliases span up to 4 messages, so a decoded talker alias can be a fragment (the leading characters) of the
|
||||||
|
* full alias, even when the decoder reports it as complete. To avoid replacing a full alias with a fragment:
|
||||||
|
* <ul>
|
||||||
|
* <li>A decoded alias that is the start of the stored alias name is a fragment and never replaces it.</li>
|
||||||
|
* <li>A decoded alias that starts with the stored alias name is a longer version of a stored fragment and
|
||||||
|
* replaces it.</li>
|
||||||
|
* <li>Any other decoded alias that differs from the stored alias name replaces it only after it is decoded
|
||||||
|
* {@link #CONFIRMATIONS_REQUIRED} times in a row for the radio.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* Only aliases whose only identifier is the radio are created or renamed. An alias that combines the radio with other
|
||||||
|
* identifiers (e.g. several radios or talkgroups) is left alone.
|
||||||
|
*
|
||||||
|
* This class is thread safe. Talker aliases are received on decoder threads and the alias model is updated on the
|
||||||
|
* JavaFX application thread.
|
||||||
|
*/
|
||||||
|
public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAliasIdentifier>
|
||||||
|
{
|
||||||
|
private static final Logger mLog = LoggerFactory.getLogger(TalkerAliasAutoAdder.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Group assigned to aliases created from talker aliases.
|
||||||
|
*/
|
||||||
|
public static final String ALIAS_GROUP = "Talker Alias";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of consecutive times a different talker alias must be decoded for a radio before it replaces the stored
|
||||||
|
* alias name.
|
||||||
|
*/
|
||||||
|
public static final int CONFIRMATIONS_REQUIRED = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval for re-checking the stored alias for a talker alias that was already checked, so that a renamed or
|
||||||
|
* deleted alias is restored without checking the alias list for every decoded talker alias.
|
||||||
|
*/
|
||||||
|
private static final long RECHECK_INTERVAL_MS = 30_000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outcome of comparing a decoded talker alias with the stored alias name.
|
||||||
|
*/
|
||||||
|
public enum Decision
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The stored alias name matches the talker alias.
|
||||||
|
*/
|
||||||
|
UNCHANGED,
|
||||||
|
/**
|
||||||
|
* The talker alias is a fragment of the stored alias name.
|
||||||
|
*/
|
||||||
|
FRAGMENT,
|
||||||
|
/**
|
||||||
|
* The talker alias differs from the stored alias name and is waiting for more decodes.
|
||||||
|
*/
|
||||||
|
AWAIT_CONFIRMATION,
|
||||||
|
/**
|
||||||
|
* The talker alias replaces the stored alias name.
|
||||||
|
*/
|
||||||
|
UPDATE
|
||||||
|
}
|
||||||
|
|
||||||
|
private final AliasModel mAliasModel;
|
||||||
|
private final String mAliasListName;
|
||||||
|
//Guarded by this
|
||||||
|
private final Map<String,Candidate> mCandidates = new HashMap<>();
|
||||||
|
private final Map<String,Checked> mChecked = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
* @param aliasModel to add aliases to
|
||||||
|
* @param aliasListName of the alias list to add aliases to
|
||||||
|
*/
|
||||||
|
public TalkerAliasAutoAdder(AliasModel aliasModel, String aliasListName)
|
||||||
|
{
|
||||||
|
mAliasModel = aliasModel;
|
||||||
|
mAliasListName = aliasListName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the alias list that talker aliases are added to.
|
||||||
|
*/
|
||||||
|
public String getAliasListName()
|
||||||
|
{
|
||||||
|
return mAliasListName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a talker alias that is assigned to a radio.
|
||||||
|
* @param radio that the talker alias belongs to
|
||||||
|
* @param talkerAlias for the radio
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void accept(RadioIdentifier radio, TalkerAliasIdentifier talkerAlias)
|
||||||
|
{
|
||||||
|
if(radio == null || talkerAlias == null || mAliasListName == null || mAliasListName.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = normalize(talkerAlias.getValue());
|
||||||
|
Radio aliasId = createAliasId(radio);
|
||||||
|
|
||||||
|
if(value == null || aliasId == null || !aliasId.isValid())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = getKey(aliasId);
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
int confirmations;
|
||||||
|
|
||||||
|
synchronized(this)
|
||||||
|
{
|
||||||
|
Checked checked = mChecked.get(key);
|
||||||
|
|
||||||
|
if(checked != null && checked.value().equals(value) && (now - checked.timestamp()) < RECHECK_INTERVAL_MS)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmations = confirm(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
runOnFxThread(() -> apply(radio, aliasId, key, value, confirmations));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the consecutive decodes of the talker alias for the radio. A fragment of the talker alias that is
|
||||||
|
* waiting for confirmation doesn't interrupt the count, because fragments are decoded while the full alias is
|
||||||
|
* assembled.
|
||||||
|
* @return number of consecutive decodes of the value, including this one.
|
||||||
|
*/
|
||||||
|
private int confirm(String key, String value)
|
||||||
|
{
|
||||||
|
Candidate candidate = mCandidates.get(key);
|
||||||
|
|
||||||
|
if(candidate != null && candidate.value().equals(value))
|
||||||
|
{
|
||||||
|
candidate = new Candidate(value, candidate.count() + 1);
|
||||||
|
mCandidates.put(key, candidate);
|
||||||
|
return candidate.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(candidate != null && isFragment(value, candidate.value()))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mCandidates.put(key, new Candidate(value, 1));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates or updates the alias for the radio. Runs on the JavaFX application thread.
|
||||||
|
*/
|
||||||
|
private synchronized void apply(RadioIdentifier radio, Radio aliasId, String key, String value, int confirmations)
|
||||||
|
{
|
||||||
|
AliasList aliasList = mAliasModel.getAliasList(mAliasListName);
|
||||||
|
Alias existing = findExactMatch(aliasList.getAliases(radio), aliasId);
|
||||||
|
|
||||||
|
if(existing == null)
|
||||||
|
{
|
||||||
|
Alias alias = new Alias(value);
|
||||||
|
alias.setAliasListName(mAliasListName);
|
||||||
|
alias.setGroup(ALIAS_GROUP);
|
||||||
|
alias.addAliasID(aliasId);
|
||||||
|
mAliasModel.addAlias(alias);
|
||||||
|
markChecked(key, value);
|
||||||
|
mLog.info("Talker alias [" + value + "] added for radio [" + aliasId + "] to alias list [" +
|
||||||
|
mAliasListName + "]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getIdentityCount(existing) > 1)
|
||||||
|
{
|
||||||
|
//The alias also identifies other radios or talkgroups - leave it alone.
|
||||||
|
markChecked(key, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String stored = normalize(existing.getName());
|
||||||
|
|
||||||
|
switch(decide(stored, value, confirmations))
|
||||||
|
{
|
||||||
|
case UPDATE:
|
||||||
|
existing.setName(value);
|
||||||
|
markChecked(key, value);
|
||||||
|
mLog.info("Talker alias for radio [" + aliasId + "] in alias list [" + mAliasListName +
|
||||||
|
"] changed from [" + stored + "] to [" + value + "]");
|
||||||
|
break;
|
||||||
|
case UNCHANGED:
|
||||||
|
case FRAGMENT:
|
||||||
|
markChecked(key, value);
|
||||||
|
break;
|
||||||
|
case AWAIT_CONFIRMATION:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markChecked(String key, String value)
|
||||||
|
{
|
||||||
|
mChecked.put(key, new Checked(value, System.currentTimeMillis()));
|
||||||
|
mCandidates.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares the decoded talker alias with the stored alias name.
|
||||||
|
* @param stored alias name, normalized, or null
|
||||||
|
* @param decoded talker alias, normalized
|
||||||
|
* @param confirmations number of consecutive decodes of the talker alias
|
||||||
|
* @return decision
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static Decision decide(String stored, String decoded, int confirmations)
|
||||||
|
{
|
||||||
|
if(stored == null || stored.isEmpty())
|
||||||
|
{
|
||||||
|
return Decision.UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stored.equals(decoded))
|
||||||
|
{
|
||||||
|
return Decision.UNCHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isFragment(decoded, stored))
|
||||||
|
{
|
||||||
|
return Decision.FRAGMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//A longer version of a stored fragment.
|
||||||
|
if(isFragment(stored, decoded) && !hasUndecodableCharacters(decoded))
|
||||||
|
{
|
||||||
|
return Decision.UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//A different alias that may be a corrupted or mis-assembled alias. It's replaced only once confirmed, and an
|
||||||
|
//alias that has undecodable characters (e.g. a partial multi-byte character) never replaces a stored alias.
|
||||||
|
if(confirmations >= CONFIRMATIONS_REQUIRED && !hasUndecodableCharacters(decoded))
|
||||||
|
{
|
||||||
|
return Decision.UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Decision.AWAIT_CONFIRMATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the value is a fragment (the leading characters) of the full value.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static boolean isFragment(String value, String full)
|
||||||
|
{
|
||||||
|
return value != null && full != null && value.length() < full.length() && full.startsWith(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasUndecodableCharacters(String value)
|
||||||
|
{
|
||||||
|
return value.indexOf('<27>') >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes padding, control characters and trailing undecodable characters (e.g. from a partial multi-byte
|
||||||
|
* character at the end of an alias fragment) from the talker alias.
|
||||||
|
* @param value to normalize
|
||||||
|
* @return normalized value or null if the value is empty.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static String normalize(String value)
|
||||||
|
{
|
||||||
|
if(value == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(value.length());
|
||||||
|
|
||||||
|
for(int i = 0; i < value.length(); i++)
|
||||||
|
{
|
||||||
|
char c = value.charAt(i);
|
||||||
|
|
||||||
|
if(!Character.isISOControl(c))
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int end = sb.length();
|
||||||
|
|
||||||
|
while(end > 0 && (sb.charAt(end - 1) == '<27>' || Character.isWhitespace(sb.charAt(end - 1))))
|
||||||
|
{
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normalized = sb.substring(0, end).trim();
|
||||||
|
return normalized.isEmpty() ? null : normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a radio alias identifier that exactly matches the radio.
|
||||||
|
* @param radio identifier
|
||||||
|
* @return alias identifier or null if the radio protocol isn't known.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static Radio createAliasId(RadioIdentifier radio)
|
||||||
|
{
|
||||||
|
if(radio instanceof FullyQualifiedRadioIdentifier fqri && fqri.getProtocol() == Protocol.APCO25)
|
||||||
|
{
|
||||||
|
return new P25FullyQualifiedRadio(fqri.getWacn(), fqri.getSystem(), fqri.getRadio());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(radio instanceof NXDNRadioIdentifier nxdn && nxdn.isTypeD())
|
||||||
|
{
|
||||||
|
return new NXDNTypeDRadio(nxdn.getTypeDHomeRepeater(), nxdn.getTypeDRadio());
|
||||||
|
}
|
||||||
|
|
||||||
|
Protocol protocol = radio.getProtocol();
|
||||||
|
|
||||||
|
if(protocol == null || protocol == Protocol.UNKNOWN || radio.getValue() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Radio(protocol, radio.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the alias that has an identifier that exactly matches the radio (i.e. not a radio range).
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static Alias findExactMatch(List<Alias> aliases, Radio aliasId)
|
||||||
|
{
|
||||||
|
if(aliases != null)
|
||||||
|
{
|
||||||
|
for(Alias alias: aliases)
|
||||||
|
{
|
||||||
|
for(AliasID id: alias.getAliasIdentifiers())
|
||||||
|
{
|
||||||
|
if(isExactMatch(id, aliasId))
|
||||||
|
{
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isExactMatch(AliasID id, Radio aliasId)
|
||||||
|
{
|
||||||
|
if(aliasId instanceof P25FullyQualifiedRadio target)
|
||||||
|
{
|
||||||
|
return id instanceof P25FullyQualifiedRadio fqr && fqr.getHashKey().equals(target.getHashKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
return id instanceof Radio radio && !(id instanceof P25FullyQualifiedRadio) &&
|
||||||
|
radio.getProtocol() == aliasId.getProtocol() && radio.getValue() == aliasId.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of identifiers (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
||||||
|
* streaming.
|
||||||
|
*/
|
||||||
|
private static int getIdentityCount(Alias alias)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for(AliasID id: alias.getAliasIdentifiers())
|
||||||
|
{
|
||||||
|
if(!id.isAudioIdentifier())
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getKey(Radio aliasId)
|
||||||
|
{
|
||||||
|
if(aliasId instanceof P25FullyQualifiedRadio fqr)
|
||||||
|
{
|
||||||
|
return aliasId.getProtocol() + ":" + fqr.getHashKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
return aliasId.getProtocol() + ":" + aliasId.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs on the FX thread, or on this thread when the FX toolkit isn't running (headless).
|
||||||
|
*/
|
||||||
|
private static void runOnFxThread(Runnable runnable)
|
||||||
|
{
|
||||||
|
if(Platform.isFxApplicationThread())
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Platform.runLater(runnable);
|
||||||
|
}
|
||||||
|
catch(IllegalStateException ise)
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Candidate(String value, int count) {}
|
||||||
|
private record Checked(String value, long timestamp) {}
|
||||||
|
}
|
||||||
@@ -49,6 +49,7 @@ public class ChannelMetadata implements Listener<IdentifierUpdateNotification>,
|
|||||||
{
|
{
|
||||||
private final static Logger mLog = LoggerFactory.getLogger(ChannelMetadata.class);
|
private final static Logger mLog = LoggerFactory.getLogger(ChannelMetadata.class);
|
||||||
|
|
||||||
|
private AliasListConfigurationIdentifier mAliasListConfigurationIdentifier;
|
||||||
private SystemConfigurationIdentifier mSystemConfigurationIdentifier;
|
private SystemConfigurationIdentifier mSystemConfigurationIdentifier;
|
||||||
private SiteConfigurationIdentifier mSiteConfigurationIdentifier;
|
private SiteConfigurationIdentifier mSiteConfigurationIdentifier;
|
||||||
private ChannelNameConfigurationIdentifier mChannelNameConfigurationIdentifier;
|
private ChannelNameConfigurationIdentifier mChannelNameConfigurationIdentifier;
|
||||||
@@ -128,6 +129,19 @@ public class ChannelMetadata implements Listener<IdentifierUpdateNotification>,
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias list configuration identifier
|
||||||
|
*/
|
||||||
|
public AliasListConfigurationIdentifier getAliasListConfigurationIdentifier()
|
||||||
|
{
|
||||||
|
return mAliasListConfigurationIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAliasListConfigurationIdentifier()
|
||||||
|
{
|
||||||
|
return mAliasListConfigurationIdentifier != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System configuration identifier
|
* System configuration identifier
|
||||||
*/
|
*/
|
||||||
@@ -323,6 +337,15 @@ public class ChannelMetadata implements Listener<IdentifierUpdateNotification>,
|
|||||||
switch(identifier.getForm())
|
switch(identifier.getForm())
|
||||||
{
|
{
|
||||||
case ALIAS_LIST:
|
case ALIAS_LIST:
|
||||||
|
if(identifier instanceof AliasListConfigurationIdentifier && (update.isAdd() || update.isSilentAdd()))
|
||||||
|
{
|
||||||
|
mAliasListConfigurationIdentifier = (AliasListConfigurationIdentifier)identifier;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mAliasListConfigurationIdentifier = null;
|
||||||
|
}
|
||||||
|
|
||||||
if(update.isAdd())
|
if(update.isAdd())
|
||||||
{
|
{
|
||||||
mAliasList = mAliasModel.getAliasList((AliasListConfigurationIdentifier)identifier);
|
mAliasList = mAliasModel.getAliasList((AliasListConfigurationIdentifier)identifier);
|
||||||
@@ -339,6 +362,7 @@ public class ChannelMetadata implements Listener<IdentifierUpdateNotification>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
broadcastUpdate(ChannelMetadataField.CONFIGURATION_ALIAS_LIST);
|
||||||
break;
|
break;
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
if(identifier instanceof ChannelNameConfigurationIdentifier && (update.isAdd() || update.isSilentAdd()))
|
if(identifier instanceof ChannelNameConfigurationIdentifier && (update.isAdd() || update.isSilentAdd()))
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package io.github.dsheirer.channel.metadata;
|
|||||||
|
|
||||||
public enum ChannelMetadataField
|
public enum ChannelMetadataField
|
||||||
{
|
{
|
||||||
|
CONFIGURATION_ALIAS_LIST,
|
||||||
CONFIGURATION_CHANNEL,
|
CONFIGURATION_CHANNEL,
|
||||||
CONFIGURATION_FREQUENCY,
|
CONFIGURATION_FREQUENCY,
|
||||||
CONFIGURATION_SITE,
|
CONFIGURATION_SITE,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.dsheirer.controller.channel;
|
package io.github.dsheirer.controller.channel;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||||
@@ -83,6 +84,8 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
|||||||
|
|
||||||
private BooleanProperty mProcessing = new SimpleBooleanProperty();
|
private BooleanProperty mProcessing = new SimpleBooleanProperty();
|
||||||
private BooleanProperty mAutoStart = new SimpleBooleanProperty();
|
private BooleanProperty mAutoStart = new SimpleBooleanProperty();
|
||||||
|
//Enabled for new channels. Channels loaded from a playlist without the setting keep it disabled, see fromXml().
|
||||||
|
private BooleanProperty mAutoAddTalkerAliases = new SimpleBooleanProperty(true);
|
||||||
private IntegerProperty mAutoStartOrder = new SimpleIntegerProperty();
|
private IntegerProperty mAutoStartOrder = new SimpleIntegerProperty();
|
||||||
private boolean mSelected;
|
private boolean mSelected;
|
||||||
private List<TunerChannel> mTunerChannels = null;
|
private List<TunerChannel> mTunerChannels = null;
|
||||||
@@ -123,6 +126,19 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
|||||||
mChannelID = UNIQUE_ID++;
|
mChannelID = UNIQUE_ID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a channel for deserialization from a playlist. Settings added after a channel was saved take their
|
||||||
|
* legacy (disabled) value when the playlist doesn't specify them, instead of the default for new channels, so that
|
||||||
|
* existing channels don't change behavior.
|
||||||
|
*/
|
||||||
|
@JsonCreator
|
||||||
|
private static Channel fromXml()
|
||||||
|
{
|
||||||
|
Channel channel = new Channel();
|
||||||
|
channel.setAutoAddTalkerAliases(false);
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a (new) deep copy of this channel
|
* Creates a (new) deep copy of this channel
|
||||||
*/
|
*/
|
||||||
@@ -134,6 +150,7 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
|||||||
channel.setAliasListName(mAliasListName.get());
|
channel.setAliasListName(mAliasListName.get());
|
||||||
channel.setAutoStart(mAutoStart.get());
|
channel.setAutoStart(mAutoStart.get());
|
||||||
channel.setAutoStartOrder(mAutoStartOrder.get());
|
channel.setAutoStartOrder(mAutoStartOrder.get());
|
||||||
|
channel.setAutoAddTalkerAliases(mAutoAddTalkerAliases.get());
|
||||||
|
|
||||||
AuxDecodeConfiguration auxCopy = new AuxDecodeConfiguration();
|
AuxDecodeConfiguration auxCopy = new AuxDecodeConfiguration();
|
||||||
|
|
||||||
@@ -509,6 +526,36 @@ public class Channel extends Configuration implements Listener<SourceEvent>
|
|||||||
mAutoStart.set(autoStart);
|
mAutoStart.set(autoStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-add talker aliases property
|
||||||
|
*/
|
||||||
|
public BooleanProperty autoAddTalkerAliasesProperty()
|
||||||
|
{
|
||||||
|
return mAutoAddTalkerAliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if decoded talker aliases are automatically added to the channel's alias list as radio aliases, using
|
||||||
|
* the talker alias as the alias name.
|
||||||
|
*
|
||||||
|
* @return true if talker aliases are automatically added to the alias list
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = true, localName = "auto_add_talker_aliases")
|
||||||
|
public boolean isAutoAddTalkerAliases()
|
||||||
|
{
|
||||||
|
return mAutoAddTalkerAliases.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets automatically adding decoded talker aliases to the channel's alias list.
|
||||||
|
*
|
||||||
|
* @param autoAdd true to automatically add talker aliases to the alias list
|
||||||
|
*/
|
||||||
|
public void setAutoAddTalkerAliases(boolean autoAdd)
|
||||||
|
{
|
||||||
|
mAutoAddTalkerAliases.set(autoAdd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto-start order. Specifies an optional ordering for channels so that when the application starts up,
|
* Auto-start order. Specifies an optional ordering for channels so that when the application starts up,
|
||||||
* the channels can be started in a user-specified order.
|
* the channels can be started in a user-specified order.
|
||||||
|
|||||||
@@ -68,12 +68,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
|||||||
private final static Logger mLog = LoggerFactory.getLogger(PolyphaseChannelManager.class);
|
private final static Logger mLog = LoggerFactory.getLogger(PolyphaseChannelManager.class);
|
||||||
private static final double CHANNEL_OVERSAMPLING = 2.0;
|
private static final double CHANNEL_OVERSAMPLING = 2.0;
|
||||||
private static final int POLYPHASE_CHANNELIZER_TAPS_PER_CHANNEL = 9;
|
private static final int POLYPHASE_CHANNELIZER_TAPS_PER_CHANNEL = 9;
|
||||||
/**
|
private static final int MAXIMUM_QUEUED_NATIVE_BUFFERS = 500;
|
||||||
* Maximum duration of queued native buffers awaiting the channelizer. The queue is bounded by sample count instead
|
|
||||||
* of buffer count because tuner buffer sizes vary widely, for example about 1,000 samples per RSP buffer and 32,768
|
|
||||||
* samples per RTL-SDR buffer, so that each tuner can absorb a processing delay of the same duration.
|
|
||||||
*/
|
|
||||||
private static final double MAXIMUM_QUEUED_SECONDS = 1.0;
|
|
||||||
|
|
||||||
private Broadcaster<SourceEvent> mSourceEventBroadcaster = new Broadcaster<>();
|
private Broadcaster<SourceEvent> mSourceEventBroadcaster = new Broadcaster<>();
|
||||||
private TunerController mTunerController;
|
private TunerController mTunerController;
|
||||||
@@ -83,7 +78,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
|||||||
private ComplexPolyphaseChannelizerM2 mPolyphaseChannelizer;
|
private ComplexPolyphaseChannelizerM2 mPolyphaseChannelizer;
|
||||||
private ChannelSourceEventListener mChannelSourceEventListener = new ChannelSourceEventListener();
|
private ChannelSourceEventListener mChannelSourceEventListener = new ChannelSourceEventListener();
|
||||||
private NativeBufferReceiver mNativeBufferReceiver = new NativeBufferReceiver();
|
private NativeBufferReceiver mNativeBufferReceiver = new NativeBufferReceiver();
|
||||||
private Dispatcher<INativeBuffer> mBufferDispatcher;
|
private Dispatcher mBufferDispatcher;
|
||||||
private boolean mRunning = true;
|
private boolean mRunning = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,21 +99,10 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
|||||||
|
|
||||||
mChannelCalculator = new ChannelCalculator(tunerController.getSampleRate(), channelCount,
|
mChannelCalculator = new ChannelCalculator(tunerController.getSampleRate(), channelCount,
|
||||||
tunerController.getFrequency(), CHANNEL_OVERSAMPLING);
|
tunerController.getFrequency(), CHANNEL_OVERSAMPLING);
|
||||||
mBufferDispatcher = new Dispatcher<>("sdrtrunk polyphase buffer processor", 10, INativeBuffer::sampleCount,
|
mBufferDispatcher = new Dispatcher("sdrtrunk polyphase buffer processor", 10, MAXIMUM_QUEUED_NATIVE_BUFFERS);
|
||||||
getMaximumQueuedSamples(tunerController.getSampleRate()));
|
|
||||||
mBufferDispatcher.setListener(mNativeBufferReceiver);
|
mBufferDispatcher.setListener(mNativeBufferReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the maximum number of queued samples for the buffer dispatcher.
|
|
||||||
* @param sampleRate of the tuner
|
|
||||||
* @return maximum queued samples, at least one
|
|
||||||
*/
|
|
||||||
private static long getMaximumQueuedSamples(double sampleRate)
|
|
||||||
{
|
|
||||||
return Math.max(1, (long)(sampleRate * MAXIMUM_QUEUED_SECONDS));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a description of the state of this manager.
|
* Provides a description of the state of this manager.
|
||||||
*/
|
*/
|
||||||
@@ -294,7 +278,6 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
|||||||
double sampleRate = sourceEvent.getValue().doubleValue();
|
double sampleRate = sourceEvent.getValue().doubleValue();
|
||||||
int channelCount = ComplexPolyphaseChannelizerM2.getChannelCount(sampleRate);
|
int channelCount = ComplexPolyphaseChannelizerM2.getChannelCount(sampleRate);
|
||||||
mChannelCalculator.setRates(sampleRate, channelCount);
|
mChannelCalculator.setRates(sampleRate, channelCount);
|
||||||
mBufferDispatcher.setMaximumQueuedWeight(getMaximumQueuedSamples(sampleRate));
|
|
||||||
break;
|
break;
|
||||||
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED:
|
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED:
|
||||||
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED:
|
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED:
|
||||||
|
|||||||
@@ -375,14 +375,18 @@ public class ChannelMetadataView extends VBox implements ChannelMetadataModel.Li
|
|||||||
columns.add(NowPlayingCells.column("channel.name", "Channel Name", null, Pos.CENTER,
|
columns.add(NowPlayingCells.column("channel.name", "Channel Name", null, Pos.CENTER,
|
||||||
row -> toText(row.getChannelMetadata().getChannelNameConfigurationIdentifier()), Row::revisionProperty));
|
row -> toText(row.getChannelMetadata().getChannelNameConfigurationIdentifier()), Row::revisionProperty));
|
||||||
|
|
||||||
|
//Alias list from the channel configuration
|
||||||
|
columns.add(NowPlayingCells.column("alias.list", "Alias List", null, Pos.CENTER,
|
||||||
|
row -> toText(row.getChannelMetadata().getAliasListConfigurationIdentifier()), Row::revisionProperty));
|
||||||
|
|
||||||
//The channel rows are in channel start order, the same as the Swing version of the table
|
//The channel rows are in channel start order, the same as the Swing version of the table
|
||||||
for(TableColumn<Row,?> column: columns)
|
for(TableColumn<Row,?> column: columns)
|
||||||
{
|
{
|
||||||
column.setSortable(false);
|
column.setSortable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Column numbers in the Swing version of the table, for its stored column widths. Talker, Tuner, System and Site are new
|
//Column numbers in the Swing version of the table, for its stored column widths. Talker, Tuner, System, Site and Alias
|
||||||
//columns.
|
//List are new columns.
|
||||||
String[] swingColumns = {"status", "decoder", "from", "from.alias", "to", "to.alias", "channel", "frequency",
|
String[] swingColumns = {"status", "decoder", "from", "from.alias", "to", "to.alias", "channel", "frequency",
|
||||||
"channel.name"};
|
"channel.name"};
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import io.github.dsheirer.gui.playlist.channel.ChannelEditor;
|
|||||||
import io.github.dsheirer.gui.playlist.channel.ChannelTabRequest;
|
import io.github.dsheirer.gui.playlist.channel.ChannelTabRequest;
|
||||||
import io.github.dsheirer.gui.playlist.manager.PlaylistManagerEditor;
|
import io.github.dsheirer.gui.playlist.manager.PlaylistManagerEditor;
|
||||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceEditor;
|
import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceEditor;
|
||||||
|
import io.github.dsheirer.gui.playlist.radioreference.ViewRadioReferenceRequest;
|
||||||
import io.github.dsheirer.gui.playlist.streaming.StreamingEditor;
|
import io.github.dsheirer.gui.playlist.streaming.StreamingEditor;
|
||||||
import io.github.dsheirer.gui.preference.PreferenceEditorType;
|
import io.github.dsheirer.gui.preference.PreferenceEditorType;
|
||||||
import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
|
import io.github.dsheirer.gui.preference.ViewUserPreferenceEditorRequest;
|
||||||
@@ -77,6 +78,7 @@ public class PlaylistEditor extends BorderPane
|
|||||||
private Tab mStreamingTab;
|
private Tab mStreamingTab;
|
||||||
private AliasEditor mAliasEditor;
|
private AliasEditor mAliasEditor;
|
||||||
private ChannelEditor mChannelEditor;
|
private ChannelEditor mChannelEditor;
|
||||||
|
private RadioReferenceEditor mRadioReferenceEditor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance
|
* Constructs an instance
|
||||||
@@ -122,6 +124,13 @@ public class PlaylistEditor extends BorderPane
|
|||||||
getChannelEditor().process((ChannelTabRequest)request);
|
getChannelEditor().process((ChannelTabRequest)request);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case RADIOREFERENCE:
|
||||||
|
if(request instanceof ViewRadioReferenceRequest viewRequest)
|
||||||
|
{
|
||||||
|
getTabPane().getSelectionModel().select(getRadioReferenceTab());
|
||||||
|
getRadioReferenceEditor().view(viewRequest);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PLAYLIST:
|
case PLAYLIST:
|
||||||
//Ignore - this is a request to simply show te playlist editor
|
//Ignore - this is a request to simply show te playlist editor
|
||||||
break;
|
break;
|
||||||
@@ -266,12 +275,22 @@ public class PlaylistEditor extends BorderPane
|
|||||||
if(mRadioReferenceTab == null)
|
if(mRadioReferenceTab == null)
|
||||||
{
|
{
|
||||||
mRadioReferenceTab = new Tab("Radio Reference");
|
mRadioReferenceTab = new Tab("Radio Reference");
|
||||||
mRadioReferenceTab.setContent(new RadioReferenceEditor(mUserPreferences, mPlaylistManager));
|
mRadioReferenceTab.setContent(getRadioReferenceEditor());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mRadioReferenceTab;
|
return mRadioReferenceTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RadioReferenceEditor getRadioReferenceEditor()
|
||||||
|
{
|
||||||
|
if(mRadioReferenceEditor == null)
|
||||||
|
{
|
||||||
|
mRadioReferenceEditor = new RadioReferenceEditor(mUserPreferences, mPlaylistManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRadioReferenceEditor;
|
||||||
|
}
|
||||||
|
|
||||||
private Tab getStreamingTab()
|
private Tab getStreamingTab()
|
||||||
{
|
{
|
||||||
if(mStreamingTab == null)
|
if(mStreamingTab == null)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import io.github.dsheirer.alias.Alias;
|
import io.github.dsheirer.alias.Alias;
|
||||||
import io.github.dsheirer.alias.AliasFactory;
|
import io.github.dsheirer.alias.AliasFactory;
|
||||||
import io.github.dsheirer.alias.AliasList;
|
import io.github.dsheirer.alias.AliasList;
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
import io.github.dsheirer.alias.AliasModel;
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
import io.github.dsheirer.eventbus.MyEventBus;
|
import io.github.dsheirer.eventbus.MyEventBus;
|
||||||
import io.github.dsheirer.gui.control.MaxLengthUnaryOperator;
|
import io.github.dsheirer.gui.control.MaxLengthUnaryOperator;
|
||||||
@@ -33,6 +34,11 @@ import io.github.dsheirer.icon.Icon;
|
|||||||
import io.github.dsheirer.playlist.PlaylistManager;
|
import io.github.dsheirer.playlist.PlaylistManager;
|
||||||
import io.github.dsheirer.preference.PreferenceType;
|
import io.github.dsheirer.preference.PreferenceType;
|
||||||
import io.github.dsheirer.preference.UserPreferences;
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
|
import io.github.dsheirer.service.radioreference.AliasListSynchronizer;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -49,6 +55,7 @@ import javafx.geometry.Pos;
|
|||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.MenuButton;
|
import javafx.scene.control.MenuButton;
|
||||||
@@ -62,10 +69,12 @@ import javafx.scene.control.TableView;
|
|||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.TextFormatter;
|
import javafx.scene.control.TextFormatter;
|
||||||
import javafx.scene.control.TextInputDialog;
|
import javafx.scene.control.TextInputDialog;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
|
import javafx.scene.layout.Region;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
@@ -106,6 +115,13 @@ public class AliasConfigurationEditor extends SplitPane implements IAliasListRef
|
|||||||
private FilteredList<Alias> mAliasFilteredList;
|
private FilteredList<Alias> mAliasFilteredList;
|
||||||
private SortedList<Alias> mAliasSortedList;
|
private SortedList<Alias> mAliasSortedList;
|
||||||
private AliasPredicate mAliasPredicate;
|
private AliasPredicate mAliasPredicate;
|
||||||
|
private VBox mRadioReferenceBox;
|
||||||
|
private Label mRadioReferenceSystemLabel;
|
||||||
|
private Label mRadioReferenceStatusLabel;
|
||||||
|
private CheckBox mAutoUpdateCheckBox;
|
||||||
|
private Button mRefreshAliasListButton;
|
||||||
|
private boolean mRefreshInProgress;
|
||||||
|
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance
|
* Constructs an instance
|
||||||
@@ -120,7 +136,7 @@ public class AliasConfigurationEditor extends SplitPane implements IAliasListRef
|
|||||||
|
|
||||||
VBox leftBox = new VBox();
|
VBox leftBox = new VBox();
|
||||||
VBox.setVgrow(getAliasTableView(), Priority.ALWAYS);
|
VBox.setVgrow(getAliasTableView(), Priority.ALWAYS);
|
||||||
leftBox.getChildren().addAll(getSearchAndListSelectionBox(), getAliasTableView());
|
leftBox.getChildren().addAll(getSearchAndListSelectionBox(), getRadioReferenceBox(), getAliasTableView());
|
||||||
|
|
||||||
HBox topBox = new HBox();
|
HBox topBox = new HBox();
|
||||||
HBox.setHgrow(leftBox, Priority.ALWAYS);
|
HBox.setHgrow(leftBox, Priority.ALWAYS);
|
||||||
@@ -130,9 +146,191 @@ public class AliasConfigurationEditor extends SplitPane implements IAliasListRef
|
|||||||
mCurrentEditor = getAliasItemEditor();
|
mCurrentEditor = getAliasItemEditor();
|
||||||
getItems().addAll(topBox, getAliasItemEditor());
|
getItems().addAll(topBox, getAliasItemEditor());
|
||||||
|
|
||||||
|
//Configuration changes (e.g. a background Radio Reference check) update the Radio Reference controls
|
||||||
|
mPlaylistManager.getAliasModel().aliasListConfigurations()
|
||||||
|
.addListener((ListChangeListener<AliasListConfiguration>)c -> updateRadioReferenceControls());
|
||||||
|
updateRadioReferenceControls();
|
||||||
|
|
||||||
MyEventBus.getGlobalEventBus().register(this);
|
MyEventBus.getGlobalEventBus().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the alias list selected in the combo box, or null.
|
||||||
|
*/
|
||||||
|
private AliasListConfiguration getSelectedConfiguration()
|
||||||
|
{
|
||||||
|
String aliasListName = getAliasListNameComboBox().getSelectionModel().getSelectedItem();
|
||||||
|
return mPlaylistManager.getAliasModel().getAliasListConfiguration(aliasListName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio Reference system tracking controls for the selected alias list. Disabled when the alias list doesn't
|
||||||
|
* track a Radio Reference system.
|
||||||
|
*/
|
||||||
|
private VBox getRadioReferenceBox()
|
||||||
|
{
|
||||||
|
if(mRadioReferenceBox == null)
|
||||||
|
{
|
||||||
|
//Two rows so that a long system name doesn't push the controls and status off the editor
|
||||||
|
Label label = new Label("Radio Reference:");
|
||||||
|
label.setLabelFor(getRadioReferenceSystemLabel());
|
||||||
|
label.setMinWidth(Region.USE_PREF_SIZE);
|
||||||
|
HBox systemRow = new HBox(10, label, getRadioReferenceSystemLabel());
|
||||||
|
systemRow.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
|
||||||
|
HBox controlsRow = new HBox(10, getAutoUpdateCheckBox(), getRefreshAliasListButton(),
|
||||||
|
getRadioReferenceStatusLabel());
|
||||||
|
controlsRow.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
|
||||||
|
mRadioReferenceBox = new VBox(5, systemRow, controlsRow);
|
||||||
|
mRadioReferenceBox.setPadding(new Insets(0, 0, 10, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRadioReferenceBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Label getRadioReferenceSystemLabel()
|
||||||
|
{
|
||||||
|
if(mRadioReferenceSystemLabel == null)
|
||||||
|
{
|
||||||
|
mRadioReferenceSystemLabel = new Label();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRadioReferenceSystemLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Label getRadioReferenceStatusLabel()
|
||||||
|
{
|
||||||
|
if(mRadioReferenceStatusLabel == null)
|
||||||
|
{
|
||||||
|
mRadioReferenceStatusLabel = new Label();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRadioReferenceStatusLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CheckBox getAutoUpdateCheckBox()
|
||||||
|
{
|
||||||
|
if(mAutoUpdateCheckBox == null)
|
||||||
|
{
|
||||||
|
mAutoUpdateCheckBox = new CheckBox("Auto-Update Talkgroups");
|
||||||
|
mAutoUpdateCheckBox.setTooltip(new Tooltip("Automatically add or update talkgroup aliases when the " +
|
||||||
|
"system changes on Radio Reference. Set how often to check in User Preferences > Radio Reference > Alias Lists."));
|
||||||
|
mAutoUpdateCheckBox.setOnAction(event -> {
|
||||||
|
AliasListConfiguration configuration = getSelectedConfiguration();
|
||||||
|
|
||||||
|
if(configuration != null && configuration.isTrackingRadioReferenceSystem())
|
||||||
|
{
|
||||||
|
configuration.setAutoUpdate(getAutoUpdateCheckBox().isSelected());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return mAutoUpdateCheckBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button getRefreshAliasListButton()
|
||||||
|
{
|
||||||
|
if(mRefreshAliasListButton == null)
|
||||||
|
{
|
||||||
|
mRefreshAliasListButton = new Button("Refresh Now");
|
||||||
|
mRefreshAliasListButton.setTooltip(new Tooltip("Add or update talkgroup aliases from Radio Reference now"));
|
||||||
|
mRefreshAliasListButton.setOnAction(event -> {
|
||||||
|
AliasListConfiguration configuration = getSelectedConfiguration();
|
||||||
|
|
||||||
|
if(configuration == null || !configuration.isTrackingRadioReferenceSystem())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mRefreshInProgress = true;
|
||||||
|
updateRadioReferenceControls();
|
||||||
|
getRadioReferenceStatusLabel().setText("Refreshing from Radio Reference...");
|
||||||
|
|
||||||
|
mPlaylistManager.getAliasListSynchronizer().refresh(configuration)
|
||||||
|
.whenComplete((result, throwable) -> Platform.runLater(() -> {
|
||||||
|
mRefreshInProgress = false;
|
||||||
|
updateRadioReferenceControls();
|
||||||
|
|
||||||
|
if(throwable != null)
|
||||||
|
{
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR, "Unable to refresh alias list [" +
|
||||||
|
configuration.getName() + "] from Radio Reference.\n\n" +
|
||||||
|
AliasListSynchronizer.getMessage(throwable), ButtonType.OK);
|
||||||
|
alert.setTitle("Refresh Alias List");
|
||||||
|
alert.setHeaderText("Radio Reference Refresh Failed");
|
||||||
|
alert.initOwner(getRefreshAliasListButton().getScene().getWindow());
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
else if(result != null && result.applied() && configuration == getSelectedConfiguration())
|
||||||
|
{
|
||||||
|
getRadioReferenceStatusLabel().setText("Added " + result.added() + ", updated " +
|
||||||
|
result.updated() + " aliases. " + getStatusText(configuration));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRefreshAliasListButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the Radio Reference controls for the currently selected alias list.
|
||||||
|
*/
|
||||||
|
private void updateRadioReferenceControls()
|
||||||
|
{
|
||||||
|
AliasListConfiguration configuration = getSelectedConfiguration();
|
||||||
|
boolean tracking = configuration != null && configuration.isTrackingRadioReferenceSystem();
|
||||||
|
|
||||||
|
getAutoUpdateCheckBox().setDisable(!tracking);
|
||||||
|
getAutoUpdateCheckBox().setSelected(tracking && configuration.isAutoUpdate());
|
||||||
|
getRefreshAliasListButton().setDisable(!tracking || mRefreshInProgress);
|
||||||
|
|
||||||
|
if(tracking)
|
||||||
|
{
|
||||||
|
String name = configuration.getRadioReferenceSystemName();
|
||||||
|
getRadioReferenceSystemLabel().setText((name != null && !name.isEmpty() ? name : "System") + " [" +
|
||||||
|
configuration.getRadioReferenceSystemId() + "]");
|
||||||
|
|
||||||
|
if(!mRefreshInProgress)
|
||||||
|
{
|
||||||
|
getRadioReferenceStatusLabel().setText(getStatusText(configuration));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getRadioReferenceSystemLabel().setText("Not tracking a system");
|
||||||
|
getRadioReferenceStatusLabel().setText(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status text for a tracked alias list: Radio Reference last updated and synchronized timestamps.
|
||||||
|
*/
|
||||||
|
private static String getStatusText(AliasListConfiguration configuration)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Updated on Radio Reference: ").append(format(configuration.getRadioReferenceLastUpdated()));
|
||||||
|
sb.append(" Synchronized: ").append(format(configuration.getSynchronizedLastUpdated()));
|
||||||
|
|
||||||
|
if(configuration.isUpdateAvailable())
|
||||||
|
{
|
||||||
|
sb.append(" (Update Available)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String format(long timestamp)
|
||||||
|
{
|
||||||
|
if(timestamp <= 0)
|
||||||
|
{
|
||||||
|
return "never";
|
||||||
|
}
|
||||||
|
|
||||||
|
return DATE_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redraws the alias color swatches after a change to the application theme.
|
* Redraws the alias color swatches after a change to the application theme.
|
||||||
*/
|
*/
|
||||||
@@ -331,6 +529,7 @@ public class AliasConfigurationEditor extends SplitPane implements IAliasListRef
|
|||||||
{
|
{
|
||||||
getNewAliasButton().setDisable(newValue == null || newValue.contentEquals(AliasModel.NO_ALIAS_LIST));
|
getNewAliasButton().setDisable(newValue == null || newValue.contentEquals(AliasModel.NO_ALIAS_LIST));
|
||||||
update();
|
update();
|
||||||
|
updateRadioReferenceControls();
|
||||||
});
|
});
|
||||||
|
|
||||||
if(mAliasListNameComboBox.getItems().size() > 1)
|
if(mAliasListNameComboBox.getItems().size() > 1)
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
private TextField mNameField;
|
private TextField mNameField;
|
||||||
private ComboBox<String> mAliasListComboBox;
|
private ComboBox<String> mAliasListComboBox;
|
||||||
private Button mNewAliasListButton;
|
private Button mNewAliasListButton;
|
||||||
|
private CheckBox mAutoAddTalkerAliasesCheckBox;
|
||||||
private GridPane mTextFieldPane;
|
private GridPane mTextFieldPane;
|
||||||
private Button mSaveButton;
|
private Button mSaveButton;
|
||||||
private Button mResetButton;
|
private Button mResetButton;
|
||||||
@@ -187,6 +188,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
getNameField().setDisable(disable);
|
getNameField().setDisable(disable);
|
||||||
getAliasListComboBox().setDisable(disable);
|
getAliasListComboBox().setDisable(disable);
|
||||||
getNewAliasListButton().setDisable(disable);
|
getNewAliasListButton().setDisable(disable);
|
||||||
|
getAutoAddTalkerAliasesCheckBox().setDisable(disable);
|
||||||
getAutoStartSwitch().setDisable(disable);
|
getAutoStartSwitch().setDisable(disable);
|
||||||
|
|
||||||
if(channel != null)
|
if(channel != null)
|
||||||
@@ -210,6 +212,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
getAliasListComboBox().getSelectionModel().select(null);
|
getAliasListComboBox().getSelectionModel().select(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAutoAddTalkerAliasesCheckBox().setSelected(channel.isAutoAddTalkerAliases());
|
||||||
getAutoStartSwitch().selectedProperty().set(channel.isAutoStart());
|
getAutoStartSwitch().selectedProperty().set(channel.isAutoStart());
|
||||||
getAutoStartOrderSpinner().setDisable(!channel.isAutoStart());
|
getAutoStartOrderSpinner().setDisable(!channel.isAutoStart());
|
||||||
Integer order = channel.getAutoStartOrder();
|
Integer order = channel.getAutoStartOrder();
|
||||||
@@ -251,6 +254,7 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
getSiteField().setText(null);
|
getSiteField().setText(null);
|
||||||
getNameField().setText(null);
|
getNameField().setText(null);
|
||||||
getAliasListComboBox().getSelectionModel().select(null);
|
getAliasListComboBox().getSelectionModel().select(null);
|
||||||
|
getAutoAddTalkerAliasesCheckBox().setSelected(false);
|
||||||
getAutoStartSwitch().selectedProperty().set(false);
|
getAutoStartSwitch().selectedProperty().set(false);
|
||||||
getAutoStartOrderSpinner().setDisable(true);
|
getAutoStartOrderSpinner().setDisable(true);
|
||||||
getAutoStartOrderSpinner().getValueFactory().setValue(0);
|
getAutoStartOrderSpinner().getValueFactory().setValue(0);
|
||||||
@@ -277,6 +281,12 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
getItem().setName(" ");
|
getItem().setName(" ");
|
||||||
getItem().setName(getNameField().getText());
|
getItem().setName(getNameField().getText());
|
||||||
getItem().setAliasListName(getAliasListComboBox().getSelectionModel().getSelectedItem());
|
getItem().setAliasListName(getAliasListComboBox().getSelectionModel().getSelectedItem());
|
||||||
|
|
||||||
|
if(providesTalkerAlias())
|
||||||
|
{
|
||||||
|
getItem().setAutoAddTalkerAliases(getAutoAddTalkerAliasesCheckBox().isSelected());
|
||||||
|
}
|
||||||
|
|
||||||
getItem().setAutoStart(getAutoStartSwitch().isSelected());
|
getItem().setAutoStart(getAutoStartSwitch().isSelected());
|
||||||
|
|
||||||
Integer order = getAutoStartOrderSpinner().getValue();
|
Integer order = getAutoStartOrderSpinner().getValue();
|
||||||
@@ -598,6 +608,12 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
|
|
||||||
GridPane.setConstraints(getNewAliasListButton(), 4, row);
|
GridPane.setConstraints(getNewAliasListButton(), 4, row);
|
||||||
mTextFieldPane.getChildren().add(getNewAliasListButton());
|
mTextFieldPane.getChildren().add(getNewAliasListButton());
|
||||||
|
|
||||||
|
if(providesTalkerAlias())
|
||||||
|
{
|
||||||
|
GridPane.setConstraints(getAutoAddTalkerAliasesCheckBox(), 3, ++row, 2, 1);
|
||||||
|
mTextFieldPane.getChildren().add(getAutoAddTalkerAliasesCheckBox());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mTextFieldPane;
|
return mTextFieldPane;
|
||||||
@@ -660,6 +676,32 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
|||||||
return mAliasListComboBox;
|
return mAliasListComboBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the decoder for this editor produces talker aliases.
|
||||||
|
*/
|
||||||
|
private boolean providesTalkerAlias()
|
||||||
|
{
|
||||||
|
return getDecoderType() != null && getDecoderType().providesTalkerAlias();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check box to automatically add decoded talker aliases to the selected alias list.
|
||||||
|
*/
|
||||||
|
private CheckBox getAutoAddTalkerAliasesCheckBox()
|
||||||
|
{
|
||||||
|
if(mAutoAddTalkerAliasesCheckBox == null)
|
||||||
|
{
|
||||||
|
mAutoAddTalkerAliasesCheckBox = new CheckBox("Auto-Add Talker Aliases");
|
||||||
|
mAutoAddTalkerAliasesCheckBox.setDisable(true);
|
||||||
|
mAutoAddTalkerAliasesCheckBox.setTooltip(new Tooltip("Adds a radio alias for each talker alias decoded " +
|
||||||
|
"on this system, named with the talker alias, and renames the radio alias when its talker alias " +
|
||||||
|
"changes. Applies when the channel is (re)started."));
|
||||||
|
mAutoAddTalkerAliasesCheckBox.setOnAction(event -> modifiedProperty().set(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mAutoAddTalkerAliasesCheckBox;
|
||||||
|
}
|
||||||
|
|
||||||
private Button getNewAliasListButton()
|
private Button getNewAliasListButton()
|
||||||
{
|
{
|
||||||
if(mNewAliasListButton == null)
|
if(mNewAliasListButton == null)
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ public class AgencyEditor extends VBox
|
|||||||
private ListView<Agency> mAgencyListView;
|
private ListView<Agency> mAgencyListView;
|
||||||
private AgencyFrequencyEditor mAgencyFrequencyEditor;
|
private AgencyFrequencyEditor mAgencyFrequencyEditor;
|
||||||
private IntegerProperty mAgencyCountProperty = new SimpleIntegerProperty();
|
private IntegerProperty mAgencyCountProperty = new SimpleIntegerProperty();
|
||||||
|
private Integer mPendingAgencyId;
|
||||||
|
private AgencyFrequencyEditor.FrequencyTarget mPendingFrequency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance
|
* Constructs an instance
|
||||||
@@ -109,6 +111,56 @@ public class AgencyEditor extends VBox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares to show the agency with the frequency selected when the agencies are next set
|
||||||
|
* @param agencyId of the agency, or the negative county id for a county's own frequencies
|
||||||
|
* @param frequency to select, or null
|
||||||
|
*/
|
||||||
|
public void prepareView(int agencyId, AgencyFrequencyEditor.FrequencyTarget frequency)
|
||||||
|
{
|
||||||
|
mUserPreferences.getRadioReferencePreference().setPreferredAgencyId(agencyId, mLevel);
|
||||||
|
mPendingAgencyId = agencyId;
|
||||||
|
mPendingFrequency = frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the agency with the frequency selected
|
||||||
|
* @param agencyId of the agency, or the negative county id for a county's own frequencies
|
||||||
|
* @param frequency to select, or null
|
||||||
|
* @return false when the editor doesn't list the agency
|
||||||
|
*/
|
||||||
|
public boolean view(int agencyId, AgencyFrequencyEditor.FrequencyTarget frequency)
|
||||||
|
{
|
||||||
|
prepareView(agencyId, frequency);
|
||||||
|
|
||||||
|
for(Agency agency: getAgencyListView().getItems())
|
||||||
|
{
|
||||||
|
if(agency.getAgencyId() == agencyId)
|
||||||
|
{
|
||||||
|
if(getAgencyListView().getSelectionModel().getSelectedItem() == agency)
|
||||||
|
{
|
||||||
|
//Already shown - select the frequency in the shown categories
|
||||||
|
mPendingAgencyId = null;
|
||||||
|
mPendingFrequency = null;
|
||||||
|
|
||||||
|
if(frequency != null)
|
||||||
|
{
|
||||||
|
getAgencyFrequencyEditor().viewFrequency(frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getAgencyListView().getSelectionModel().select(agency);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAgencyListView().scrollTo(agency);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAgencyListView().getItems().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public void clear()
|
public void clear()
|
||||||
{
|
{
|
||||||
getAgencyListView().getItems().clear();
|
getAgencyListView().getItems().clear();
|
||||||
@@ -155,6 +207,17 @@ public class AgencyEditor extends VBox
|
|||||||
{
|
{
|
||||||
getAgencyFrequencyEditor().clearAndSetLoading();
|
getAgencyFrequencyEditor().clearAndSetLoading();
|
||||||
|
|
||||||
|
if(mPendingAgencyId != null && mPendingAgencyId == agency.getAgencyId())
|
||||||
|
{
|
||||||
|
if(mPendingFrequency != null)
|
||||||
|
{
|
||||||
|
getAgencyFrequencyEditor().viewFrequency(mPendingFrequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
mPendingAgencyId = null;
|
||||||
|
mPendingFrequency = null;
|
||||||
|
}
|
||||||
|
|
||||||
mUserPreferences.getRadioReferencePreference().setPreferredAgencyId(agency.getAgencyId(), mLevel);
|
mUserPreferences.getRadioReferencePreference().setPreferredAgencyId(agency.getAgencyId(), mLevel);
|
||||||
|
|
||||||
ThreadPool.CACHED.submit(() -> {
|
ThreadPool.CACHED.submit(() -> {
|
||||||
|
|||||||
@@ -68,6 +68,21 @@ public class AgencyFrequencyEditor extends GridPane
|
|||||||
private Level mLevel;
|
private Level mLevel;
|
||||||
private ComboBox<Category> mCategoryComboBox;
|
private ComboBox<Category> mCategoryComboBox;
|
||||||
private ComboBox<SubCategory> mSubCategoryComboBox;
|
private ComboBox<SubCategory> mSubCategoryComboBox;
|
||||||
|
private FrequencyTarget mPendingFrequency;
|
||||||
|
private boolean mLoadingFrequencies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frequency to select in the editor
|
||||||
|
* @param category name, or null
|
||||||
|
* @param subCategory name, or null
|
||||||
|
* @param frequencyHz downlink frequency
|
||||||
|
* @param description of the frequency, or null
|
||||||
|
* @param alphaTag of the frequency, or null
|
||||||
|
*/
|
||||||
|
public record FrequencyTarget(String category, String subCategory, long frequencyHz, String description,
|
||||||
|
String alphaTag)
|
||||||
|
{
|
||||||
|
}
|
||||||
private TableView<Frequency> mFrequencyTableView;
|
private TableView<Frequency> mFrequencyTableView;
|
||||||
private Label mPlaceholderLabel;
|
private Label mPlaceholderLabel;
|
||||||
private ProgressIndicator mProgressIndicator;
|
private ProgressIndicator mProgressIndicator;
|
||||||
@@ -165,14 +180,127 @@ public class AgencyFrequencyEditor extends GridPane
|
|||||||
sorted.add(0, ALL_CATEGORIES);
|
sorted.add(0, ALL_CATEGORIES);
|
||||||
}
|
}
|
||||||
getCategoryComboBox().getItems().addAll(sorted);
|
getCategoryComboBox().getItems().addAll(sorted);
|
||||||
|
|
||||||
|
if(mPendingFrequency == null || !selectPendingFrequency())
|
||||||
|
{
|
||||||
getCategoryComboBox().getSelectionModel().select(sorted.get(0));
|
getCategoryComboBox().getSelectionModel().select(sorted.get(0));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the frequency in its category and subcategory, now or once the categories are set
|
||||||
|
*/
|
||||||
|
public void viewFrequency(FrequencyTarget target)
|
||||||
|
{
|
||||||
|
mPendingFrequency = target;
|
||||||
|
|
||||||
|
if(!getCategoryComboBox().getItems().isEmpty())
|
||||||
|
{
|
||||||
|
selectPendingFrequency();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the pending frequency's category and subcategory, which loads the frequencies, or selects the frequency
|
||||||
|
* when they're already shown.
|
||||||
|
* @return false when the categories don't include the frequency's category
|
||||||
|
*/
|
||||||
|
private boolean selectPendingFrequency()
|
||||||
|
{
|
||||||
|
FrequencyTarget target = mPendingFrequency;
|
||||||
|
Category category = null;
|
||||||
|
|
||||||
|
for(Category candidate: getCategoryComboBox().getItems())
|
||||||
|
{
|
||||||
|
if(candidate != ALL_CATEGORIES && candidate.getName() != null &&
|
||||||
|
candidate.getName().equals(target.category()))
|
||||||
|
{
|
||||||
|
category = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(category == null)
|
||||||
|
{
|
||||||
|
mPendingFrequency = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getCategoryComboBox().getValue() != category)
|
||||||
|
{
|
||||||
|
getCategoryComboBox().getSelectionModel().select(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
SubCategory subCategory = null;
|
||||||
|
|
||||||
|
for(SubCategory candidate: getSubCategoryComboBox().getItems())
|
||||||
|
{
|
||||||
|
if(candidate != ALL_SUB_CATEGORIES && candidate.getName() != null &&
|
||||||
|
candidate.getName().equals(target.subCategory()))
|
||||||
|
{
|
||||||
|
subCategory = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(subCategory != null && getSubCategoryComboBox().getValue() != subCategory)
|
||||||
|
{
|
||||||
|
//Loading the subcategory frequencies selects the frequency
|
||||||
|
getSubCategoryComboBox().getSelectionModel().select(subCategory);
|
||||||
|
}
|
||||||
|
else if(!mLoadingFrequencies)
|
||||||
|
{
|
||||||
|
selectFrequency();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the pending frequency in the frequencies table: the one with the same description or alpha tag, or else
|
||||||
|
* the first one with the same frequency
|
||||||
|
*/
|
||||||
|
private void selectFrequency()
|
||||||
|
{
|
||||||
|
FrequencyTarget target = mPendingFrequency;
|
||||||
|
mPendingFrequency = null;
|
||||||
|
|
||||||
|
if(target == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Frequency match = null;
|
||||||
|
|
||||||
|
for(Frequency frequency: getFrequencyTableView().getItems())
|
||||||
|
{
|
||||||
|
if(frequency.getDownlinkHz() == target.frequencyHz())
|
||||||
|
{
|
||||||
|
boolean same = (target.description() != null && target.description().equals(frequency.getDescription())) ||
|
||||||
|
(target.alphaTag() != null && target.alphaTag().equals(frequency.getAlphaTag()));
|
||||||
|
|
||||||
|
if(same)
|
||||||
|
{
|
||||||
|
match = frequency;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(match == null)
|
||||||
|
{
|
||||||
|
match = frequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(match != null)
|
||||||
|
{
|
||||||
|
getFrequencyTableView().getSelectionModel().select(match);
|
||||||
|
getFrequencyTableView().scrollTo(match);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private FrequencyEditor getFrequencyEditor()
|
private FrequencyEditor getFrequencyEditor()
|
||||||
{
|
{
|
||||||
if(mFrequencyEditor == null)
|
if(mFrequencyEditor == null)
|
||||||
@@ -400,6 +528,7 @@ public class AgencyFrequencyEditor extends GridPane
|
|||||||
getFrequencyTableView().getItems().clear();
|
getFrequencyTableView().getItems().clear();
|
||||||
|
|
||||||
SubCategory subCategory = mSubCategoryComboBox.getValue();
|
SubCategory subCategory = mSubCategoryComboBox.getValue();
|
||||||
|
mLoadingFrequencies = subCategory != null;
|
||||||
|
|
||||||
if(subCategory != null)
|
if(subCategory != null)
|
||||||
{
|
{
|
||||||
@@ -453,14 +582,23 @@ public class AgencyFrequencyEditor extends GridPane
|
|||||||
}
|
}
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
//Another subcategory was selected while loading - its frequencies are shown instead
|
||||||
|
if(getSubCategoryComboBox().getValue() != subCategory)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mLoadingFrequencies = false;
|
||||||
getFrequencyTableView().getItems().addAll(frequencies);
|
getFrequencyTableView().getItems().addAll(frequencies);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
selectFrequency();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch(Throwable t)
|
catch(Throwable t)
|
||||||
{
|
{
|
||||||
mLog.error("Error retrieving frequencies for subcategory [" + subCategory.getName() + "]", t);
|
mLog.error("Error retrieving frequencies for subcategory [" + subCategory.getName() + "]", t);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
mLoadingFrequencies = false;
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
new RadioReferenceUnavailableAlert(getSubCategoryComboBox()).showAndWait();
|
new RadioReferenceUnavailableAlert(getSubCategoryComboBox()).showAndWait();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,12 +26,17 @@ import io.github.dsheirer.preference.PreferenceType;
|
|||||||
import io.github.dsheirer.preference.UserPreferences;
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
|
import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
|
||||||
import io.github.dsheirer.rrapi.RadioReferenceException;
|
import io.github.dsheirer.rrapi.RadioReferenceException;
|
||||||
|
import io.github.dsheirer.rrapi.RadioReferenceService;
|
||||||
|
import io.github.dsheirer.rrapi.type.AgencyInfo;
|
||||||
import io.github.dsheirer.rrapi.type.Agency;
|
import io.github.dsheirer.rrapi.type.Agency;
|
||||||
import io.github.dsheirer.rrapi.type.AuthorizationInformation;
|
import io.github.dsheirer.rrapi.type.AuthorizationInformation;
|
||||||
import io.github.dsheirer.rrapi.type.Country;
|
import io.github.dsheirer.rrapi.type.Country;
|
||||||
import io.github.dsheirer.rrapi.type.CountryInfo;
|
import io.github.dsheirer.rrapi.type.CountryInfo;
|
||||||
import io.github.dsheirer.rrapi.type.County;
|
import io.github.dsheirer.rrapi.type.County;
|
||||||
import io.github.dsheirer.rrapi.type.CountyInfo;
|
import io.github.dsheirer.rrapi.type.CountyInfo;
|
||||||
|
import io.github.dsheirer.rrapi.type.Site;
|
||||||
|
import io.github.dsheirer.rrapi.type.SystemInformation;
|
||||||
|
import io.github.dsheirer.service.radioreference.FrequencyCandidate;
|
||||||
import io.github.dsheirer.rrapi.type.State;
|
import io.github.dsheirer.rrapi.type.State;
|
||||||
import io.github.dsheirer.rrapi.type.StateInfo;
|
import io.github.dsheirer.rrapi.type.StateInfo;
|
||||||
import io.github.dsheirer.service.radioreference.RadioReference;
|
import io.github.dsheirer.service.radioreference.RadioReference;
|
||||||
@@ -41,7 +46,9 @@ import javafx.application.Platform;
|
|||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ButtonType;
|
||||||
import javafx.scene.control.ComboBox;
|
import javafx.scene.control.ComboBox;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
@@ -62,7 +69,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -168,8 +177,6 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
{
|
{
|
||||||
getCountryComboBox().getItems().clear();
|
getCountryComboBox().getItems().clear();
|
||||||
|
|
||||||
final int preferredCountryId = mUserPreferences.getRadioReferencePreference().getPreferredCountryId();
|
|
||||||
|
|
||||||
ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -177,6 +184,8 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
getCountryComboBox().getItems().addAll(countries);
|
getCountryComboBox().getItems().addAll(countries);
|
||||||
|
//Read when the list arrives, so a view request made while loading is honored
|
||||||
|
int preferredCountryId = mUserPreferences.getRadioReferencePreference().getPreferredCountryId();
|
||||||
|
|
||||||
if(preferredCountryId >= 0)
|
if(preferredCountryId >= 0)
|
||||||
{
|
{
|
||||||
@@ -199,6 +208,342 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where a view request's system or frequency is listed in the editor
|
||||||
|
* @param countryId of the country
|
||||||
|
* @param stateId of the state
|
||||||
|
* @param countyId of the county, or 0 for a state level listing
|
||||||
|
* @param level of the listing: COUNTY or STATE
|
||||||
|
* @param systemId of the trunked system, or null for an agency
|
||||||
|
* @param siteId of the site to select, or -1
|
||||||
|
* @param agencyId of the agency, or the negative county id for a county's own frequencies, or null for a system
|
||||||
|
* @param frequency to select in the agency, or null
|
||||||
|
*/
|
||||||
|
private record ViewTarget(int countryId, int stateId, int countyId, Level level, Integer systemId, int siteId,
|
||||||
|
Integer agencyId, AgencyFrequencyEditor.FrequencyTarget frequency)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the request's trunked system site or conventional frequency: selects its country, state and county, the
|
||||||
|
* tab that lists it, and the system and site or the agency and frequency. Finds where it's listed in the
|
||||||
|
* background.
|
||||||
|
*/
|
||||||
|
public void view(ViewRadioReferenceRequest request)
|
||||||
|
{
|
||||||
|
ThreadPool.CACHED.execute(() -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ViewTarget target = resolve(request);
|
||||||
|
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
if(target == null)
|
||||||
|
{
|
||||||
|
showViewError("Radio Reference doesn't list where this " +
|
||||||
|
(request.getSystemId() != null ? "system" : "frequency") + " is listed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
navigate(target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(RadioReferenceException rre)
|
||||||
|
{
|
||||||
|
mLog.error("Error finding radio reference listing to view - " + rre.getMessage());
|
||||||
|
Platform.runLater(() -> new RadioReferenceUnavailableAlert(getTabPane()).showAndWait());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds where the request's system or frequency is listed. Call from a background thread.
|
||||||
|
* @return target, or null when it can't be found
|
||||||
|
*/
|
||||||
|
private ViewTarget resolve(ViewRadioReferenceRequest request) throws RadioReferenceException
|
||||||
|
{
|
||||||
|
RadioReferenceService service = mRadioReference.getService();
|
||||||
|
|
||||||
|
if(request.getSystemId() != null)
|
||||||
|
{
|
||||||
|
int systemId = request.getSystemId();
|
||||||
|
int siteId = request.getSiteId() != null ? request.getSiteId() : -1;
|
||||||
|
//The site's county first, then the system's counties, then its states
|
||||||
|
Set<Integer> countyIds = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
for(Site site: nonNull(service.getSites(systemId)))
|
||||||
|
{
|
||||||
|
if(site.getSiteId() == siteId && isCounty(site.getCountyId()))
|
||||||
|
{
|
||||||
|
countyIds.add(site.getCountyId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemInformation systemInformation = service.getSystemInformation(systemId);
|
||||||
|
|
||||||
|
if(systemInformation != null)
|
||||||
|
{
|
||||||
|
for(County county: nonNull(systemInformation.getCounties()))
|
||||||
|
{
|
||||||
|
if(isCounty(county.getCountyId()))
|
||||||
|
{
|
||||||
|
countyIds.add(county.getCountyId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Limit the requests for systems that span many counties
|
||||||
|
int checked = 0;
|
||||||
|
|
||||||
|
for(Integer countyId: countyIds)
|
||||||
|
{
|
||||||
|
if(checked++ >= 10)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
CountyInfo countyInfo = service.getCountyInfo(countyId);
|
||||||
|
|
||||||
|
if(countyInfo != null && nonNull(countyInfo.getSystems()).stream()
|
||||||
|
.anyMatch(system -> system.getSystemId() == systemId))
|
||||||
|
{
|
||||||
|
return new ViewTarget(getCountryId(service, countyInfo.getStateId()), countyInfo.getStateId(),
|
||||||
|
countyId, Level.COUNTY, systemId, siteId, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(systemInformation != null)
|
||||||
|
{
|
||||||
|
for(State state: nonNull(systemInformation.getStates()))
|
||||||
|
{
|
||||||
|
StateInfo stateInfo = service.getStateInfo(state.getStateId());
|
||||||
|
|
||||||
|
if(stateInfo != null && nonNull(stateInfo.getSystems()).stream()
|
||||||
|
.anyMatch(system -> system.getSystemId() == systemId))
|
||||||
|
{
|
||||||
|
return new ViewTarget(getCountryId(service, state.getStateId()), state.getStateId(), 0,
|
||||||
|
Level.STATE, systemId, siteId, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = request.getSourceKey();
|
||||||
|
AgencyFrequencyEditor.FrequencyTarget frequency = getFrequencyTarget(request.getCandidate());
|
||||||
|
|
||||||
|
if(key != null && key.startsWith("county:"))
|
||||||
|
{
|
||||||
|
int countyId = Integer.parseInt(key.substring("county:".length()));
|
||||||
|
CountyInfo countyInfo = service.getCountyInfo(countyId);
|
||||||
|
|
||||||
|
if(countyInfo != null)
|
||||||
|
{
|
||||||
|
return new ViewTarget(getCountryId(service, countyInfo.getStateId()), countyInfo.getStateId(),
|
||||||
|
countyId, Level.COUNTY, null, -1, -countyId, frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(key != null && key.startsWith("agency:"))
|
||||||
|
{
|
||||||
|
int agencyId = Integer.parseInt(key.substring("agency:".length()));
|
||||||
|
AgencyInfo agencyInfo = service.getAgencyInfo(agencyId);
|
||||||
|
|
||||||
|
if(agencyInfo != null && isCounty(agencyInfo.getCountyId()))
|
||||||
|
{
|
||||||
|
CountyInfo countyInfo = service.getCountyInfo(agencyInfo.getCountyId());
|
||||||
|
|
||||||
|
if(countyInfo != null && nonNull(countyInfo.getAgencies()).stream()
|
||||||
|
.anyMatch(agency -> agency.getAgencyId() == agencyId))
|
||||||
|
{
|
||||||
|
return new ViewTarget(getCountryId(service, countyInfo.getStateId()), countyInfo.getStateId(),
|
||||||
|
countyInfo.getCountyId(), Level.COUNTY, null, -1, agencyId, frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(agencyInfo != null && agencyInfo.getStateId() > 0)
|
||||||
|
{
|
||||||
|
StateInfo stateInfo = service.getStateInfo(agencyInfo.getStateId());
|
||||||
|
|
||||||
|
if(stateInfo != null && nonNull(stateInfo.getAgencies()).stream()
|
||||||
|
.anyMatch(agency -> agency.getAgencyId() == agencyId))
|
||||||
|
{
|
||||||
|
return new ViewTarget(getCountryId(service, stateInfo.getStateId()), stateInfo.getStateId(), 0,
|
||||||
|
Level.STATE, null, -1, agencyId, frequency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frequency to select for the candidate: its source is the owner, category and subcategory
|
||||||
|
*/
|
||||||
|
private static AgencyFrequencyEditor.FrequencyTarget getFrequencyTarget(FrequencyCandidate candidate)
|
||||||
|
{
|
||||||
|
if(candidate == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] source = candidate.source() != null ? candidate.source().split(" › ") : new String[0];
|
||||||
|
String category = source.length >= 3 ? source[source.length - 2] : null;
|
||||||
|
String subCategory = source.length >= 3 ? source[source.length - 1] : null;
|
||||||
|
return new AgencyFrequencyEditor.FrequencyTarget(category, subCategory, candidate.frequencyHz(),
|
||||||
|
candidate.title(), candidate.alphaTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Country of the state: the preferred country when it has the state, or else the first country that has it
|
||||||
|
*/
|
||||||
|
private int getCountryId(RadioReferenceService service, int stateId) throws RadioReferenceException
|
||||||
|
{
|
||||||
|
int preferredCountryId = mUserPreferences.getRadioReferencePreference().getPreferredCountryId();
|
||||||
|
List<Integer> countryIds = new ArrayList<>();
|
||||||
|
|
||||||
|
if(preferredCountryId > 0)
|
||||||
|
{
|
||||||
|
countryIds.add(preferredCountryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Country country: nonNull(service.getCountries()))
|
||||||
|
{
|
||||||
|
if(country.getCountryId() != preferredCountryId)
|
||||||
|
{
|
||||||
|
countryIds.add(country.getCountryId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Integer countryId: countryIds)
|
||||||
|
{
|
||||||
|
CountryInfo countryInfo = service.getCountryInfo(countryId);
|
||||||
|
|
||||||
|
if(countryInfo != null && nonNull(countryInfo.getStates()).stream()
|
||||||
|
.anyMatch(state -> state.getStateId() == stateId))
|
||||||
|
{
|
||||||
|
return countryId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return preferredCountryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the county id is a real county. Temporary sites in an unknown county have county id 99999.
|
||||||
|
*/
|
||||||
|
private static boolean isCounty(int countyId)
|
||||||
|
{
|
||||||
|
return countyId > 0 && countyId != 99999;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> List<T> nonNull(List<T> list)
|
||||||
|
{
|
||||||
|
return list != null ? list : List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the target's country, state and county, its tab, and its system or agency. Selecting a country, state
|
||||||
|
* or county loads the lists below it, which select the preferred ids set here, so only the first selection that
|
||||||
|
* changes is made here.
|
||||||
|
*/
|
||||||
|
private void navigate(ViewTarget target)
|
||||||
|
{
|
||||||
|
RadioReferencePreference preference = mUserPreferences.getRadioReferencePreference();
|
||||||
|
preference.setPreferredCountryId(target.countryId());
|
||||||
|
preference.setPreferredStateId(target.stateId());
|
||||||
|
|
||||||
|
if(target.countyId() > 0)
|
||||||
|
{
|
||||||
|
preference.setPreferredCountyId(target.countyId());
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemEditor systemEditor = target.level() == Level.COUNTY ? getCountySystemEditor() : getStateSystemEditor();
|
||||||
|
AgencyEditor agencyEditor = target.level() == Level.COUNTY ? getCountyAgencyEditor() : getStateAgencyEditor();
|
||||||
|
|
||||||
|
if(target.systemId() != null)
|
||||||
|
{
|
||||||
|
systemEditor.prepareView(target.systemId(), target.siteId());
|
||||||
|
getTabPane().getSelectionModel().select(target.level() == Level.COUNTY ? getCountySystemTab() :
|
||||||
|
getStateSystemTab());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
agencyEditor.prepareView(target.agencyId(), target.frequency());
|
||||||
|
getTabPane().getSelectionModel().select(target.level() == Level.COUNTY ? getCountyAgencyTab() :
|
||||||
|
getStateAgencyTab());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Lists that are still loading select the preferred ids when they arrive
|
||||||
|
Country country = getCountryComboBox().getItems().stream()
|
||||||
|
.filter(item -> item.getCountryId() == target.countryId()).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if(country == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getCountryComboBox().getValue() != country)
|
||||||
|
{
|
||||||
|
getCountryComboBox().getSelectionModel().select(country);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
State state = getStateComboBox().getItems().stream()
|
||||||
|
.filter(item -> item.getStateId() == target.stateId()).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if(state == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getStateComboBox().getValue() != state)
|
||||||
|
{
|
||||||
|
getStateComboBox().getSelectionModel().select(state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(target.level() == Level.COUNTY)
|
||||||
|
{
|
||||||
|
County county = getCountyComboBox().getItems().stream()
|
||||||
|
.filter(item -> item.getCountyId() == target.countyId()).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if(county == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getCountyComboBox().getValue() != county)
|
||||||
|
{
|
||||||
|
getCountyComboBox().getSelectionModel().select(county);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean listed = target.systemId() != null ? systemEditor.view(target.systemId(), target.siteId()) :
|
||||||
|
agencyEditor.view(target.agencyId(), target.frequency());
|
||||||
|
|
||||||
|
if(!listed)
|
||||||
|
{
|
||||||
|
showViewError("The Radio Reference tab doesn't list this " + (target.systemId() != null ? "system" :
|
||||||
|
"agency") + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showViewError(String message)
|
||||||
|
{
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION, message, ButtonType.OK);
|
||||||
|
alert.setTitle("Radio Reference");
|
||||||
|
alert.setHeaderText("Can't show the Radio Reference listing");
|
||||||
|
|
||||||
|
if(getScene() != null)
|
||||||
|
{
|
||||||
|
alert.initOwner(getScene().getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
|
||||||
private TabPane getTabPane()
|
private TabPane getTabPane()
|
||||||
{
|
{
|
||||||
if(mTabPane == null)
|
if(mTabPane == null)
|
||||||
@@ -596,8 +941,6 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
|
|
||||||
if(country != null)
|
if(country != null)
|
||||||
{
|
{
|
||||||
int preferredStateId = mUserPreferences.getRadioReferencePreference().getPreferredStateId();
|
|
||||||
|
|
||||||
ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -606,6 +949,7 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
getNationalAgencyEditor().setAgencies(countryInfo.getAgencies());
|
getNationalAgencyEditor().setAgencies(countryInfo.getAgencies());
|
||||||
getStateComboBox().getItems().addAll(countryInfo.getStates());
|
getStateComboBox().getItems().addAll(countryInfo.getStates());
|
||||||
|
int preferredStateId = mUserPreferences.getRadioReferencePreference().getPreferredStateId();
|
||||||
|
|
||||||
for(State state: mStateComboBox.getItems())
|
for(State state: mStateComboBox.getItems())
|
||||||
{
|
{
|
||||||
@@ -652,8 +996,6 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
clearEditors(Level.STATE);
|
clearEditors(Level.STATE);
|
||||||
getCountyComboBox().getItems().clear();
|
getCountyComboBox().getItems().clear();
|
||||||
|
|
||||||
int preferredCountyId = mUserPreferences.getRadioReferencePreference().getPreferredCountyId();
|
|
||||||
|
|
||||||
if(state != null)
|
if(state != null)
|
||||||
{
|
{
|
||||||
ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
@@ -665,6 +1007,7 @@ public class RadioReferenceEditor extends BorderPane implements Consumer<Authori
|
|||||||
getStateAgencyEditor().setAgencies(stateInfo.getAgencies());
|
getStateAgencyEditor().setAgencies(stateInfo.getAgencies());
|
||||||
getStateSystemEditor().setSystems(stateInfo.getSystems());
|
getStateSystemEditor().setSystems(stateInfo.getSystems());
|
||||||
getCountyComboBox().getItems().addAll(stateInfo.getCounties());
|
getCountyComboBox().getItems().addAll(stateInfo.getCounties());
|
||||||
|
int preferredCountyId = mUserPreferences.getRadioReferencePreference().getPreferredCountyId();
|
||||||
|
|
||||||
for(County county: mCountyComboBox.getItems())
|
for(County county: mCountyComboBox.getItems())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Playlist actions for radio reference frequencies and trunked system sites: find the playlist channel that already
|
* Playlist actions for radio reference frequencies and trunked system sites: find the playlist channel that already
|
||||||
* decodes a frequency or site, enable or disable it, or add a channel and start it. A frequency or site that already
|
* decodes a frequency or site, enable or disable it, or add a channel and optionally start it. A frequency or site that already
|
||||||
* has a playlist channel with the same protocol isn't added again.
|
* has a playlist channel with the same protocol isn't added again.
|
||||||
*
|
*
|
||||||
* The add, enable and disable actions run in the background and report errors to the caller's error handler, on the
|
* The add, enable and disable actions run in the background and report errors to the caller's error handler, on the
|
||||||
@@ -452,6 +452,17 @@ public class RadioReferencePlaylistActions
|
|||||||
* @param firstFrequency to start the new control channel on, e.g. the frequency the user picked, or null
|
* @param firstFrequency to start the new control channel on, e.g. the frequency the user picked, or null
|
||||||
*/
|
*/
|
||||||
public void addSite(SiteRecord siteRecord, Long firstFrequency, Consumer<String> onError)
|
public void addSite(SiteRecord siteRecord, Long firstFrequency, Consumer<String> onError)
|
||||||
|
{
|
||||||
|
addSite(siteRecord, firstFrequency, true, onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds playlist channels for the trunked system site, like {@link #addSite(SiteRecord, Long, Consumer)}, and
|
||||||
|
* optionally starts them.
|
||||||
|
* @param firstFrequency to start the new control channel on, e.g. the frequency the user picked, or null
|
||||||
|
* @param start true to start the new channels, or the site's existing channels
|
||||||
|
*/
|
||||||
|
public void addSite(SiteRecord siteRecord, Long firstFrequency, boolean start, Consumer<String> onError)
|
||||||
{
|
{
|
||||||
ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
SiteDetails details = getSiteDetails(siteRecord, onError);
|
SiteDetails details = getSiteDetails(siteRecord, onError);
|
||||||
@@ -475,15 +486,22 @@ public class RadioReferencePlaylistActions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(start)
|
||||||
|
{
|
||||||
enableAll(existing, onError);
|
enableAll(existing, onError);
|
||||||
|
}
|
||||||
|
|
||||||
//The channel model's list backs the playlist editor, so it's changed on the JavaFX thread
|
//The channel model's list backs the playlist editor, so it's changed on the JavaFX thread
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
for(Channel channel: channels)
|
for(Channel channel: channels)
|
||||||
{
|
{
|
||||||
mPlaylistManager.getChannelModel().addChannel(channel);
|
mPlaylistManager.getChannelModel().addChannel(channel);
|
||||||
|
|
||||||
|
if(start)
|
||||||
|
{
|
||||||
enable(channel, onError);
|
enable(channel, onError);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -499,7 +517,7 @@ public class RadioReferencePlaylistActions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addAndStart(channel, onError);
|
add(channel, start, onError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,6 +525,16 @@ public class RadioReferencePlaylistActions
|
|||||||
* Adds a playlist channel for one repeater of a repeater site (LTR) and starts it, or starts its existing channel
|
* Adds a playlist channel for one repeater of a repeater site (LTR) and starts it, or starts its existing channel
|
||||||
*/
|
*/
|
||||||
public void addRepeater(SiteRecord siteRecord, long frequency, Consumer<String> onError)
|
public void addRepeater(SiteRecord siteRecord, long frequency, Consumer<String> onError)
|
||||||
|
{
|
||||||
|
addRepeater(siteRecord, frequency, true, onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a playlist channel for one repeater of a repeater site (LTR) unless the playlist has one, and optionally
|
||||||
|
* starts the channel
|
||||||
|
* @param start true to start the new or existing channel
|
||||||
|
*/
|
||||||
|
public void addRepeater(SiteRecord siteRecord, long frequency, boolean start, Consumer<String> onError)
|
||||||
{
|
{
|
||||||
ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
SiteDetails details = getSiteDetails(siteRecord, onError);
|
SiteDetails details = getSiteDetails(siteRecord, onError);
|
||||||
@@ -526,7 +554,7 @@ public class RadioReferencePlaylistActions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addAndStart(channels.get(0), onError);
|
add(channels.get(0), start, onError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,6 +562,16 @@ public class RadioReferencePlaylistActions
|
|||||||
* Adds a playlist channel for the conventional frequency and starts it, or starts the existing channel
|
* Adds a playlist channel for the conventional frequency and starts it, or starts the existing channel
|
||||||
*/
|
*/
|
||||||
public void addConventional(FrequencyCandidate candidate, Consumer<String> onError)
|
public void addConventional(FrequencyCandidate candidate, Consumer<String> onError)
|
||||||
|
{
|
||||||
|
addConventional(candidate, true, onError);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a playlist channel for the conventional frequency unless the playlist has one, and optionally starts the
|
||||||
|
* channel
|
||||||
|
* @param start true to start the new or existing channel
|
||||||
|
*/
|
||||||
|
public void addConventional(FrequencyCandidate candidate, boolean start, Consumer<String> onError)
|
||||||
{
|
{
|
||||||
ModeDecoderType mode = ModeDecoderType.fromName(candidate.mode());
|
ModeDecoderType mode = ModeDecoderType.fromName(candidate.mode());
|
||||||
String[] source = candidate.source() != null ? candidate.source().split(" › ") : new String[0];
|
String[] source = candidate.source() != null ? candidate.source().split(" › ") : new String[0];
|
||||||
@@ -550,28 +588,36 @@ public class RadioReferencePlaylistActions
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addAndStart(channel, onError);
|
add(channel, start, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the channel to the playlist and starts it, unless the playlist already has a channel for its frequencies
|
* Adds the channel to the playlist and optionally starts it, unless the playlist already has a channel for its
|
||||||
* and protocol, which is started instead
|
* frequencies and protocol, which is started instead when starting
|
||||||
*/
|
*/
|
||||||
private void addAndStart(Channel channel, Consumer<String> onError)
|
private void add(Channel channel, boolean start, Consumer<String> onError)
|
||||||
{
|
{
|
||||||
Channel existing = findChannel(getFrequencies(channel.getSourceConfiguration()),
|
Channel existing = findChannel(getFrequencies(channel.getSourceConfiguration()),
|
||||||
getProtocolFamily(channel.getDecodeConfiguration().getDecoderType()));
|
getProtocolFamily(channel.getDecodeConfiguration().getDecoderType()));
|
||||||
|
|
||||||
if(existing != null)
|
if(existing != null)
|
||||||
|
{
|
||||||
|
if(start)
|
||||||
{
|
{
|
||||||
enable(existing, onError);
|
enable(existing, onError);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//The channel model's list backs the playlist editor, so it's changed on the JavaFX thread
|
//The channel model's list backs the playlist editor, so it's changed on the JavaFX thread
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mPlaylistManager.getChannelModel().addChannel(channel);
|
mPlaylistManager.getChannelModel().addChannel(channel);
|
||||||
|
|
||||||
|
if(start)
|
||||||
|
{
|
||||||
enable(channel, onError);
|
enable(channel, onError);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package io.github.dsheirer.gui.playlist.radioreference;
|
package io.github.dsheirer.gui.playlist.radioreference;
|
||||||
|
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
import io.github.dsheirer.alias.AliasModel;
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
import io.github.dsheirer.controller.channel.Channel;
|
import io.github.dsheirer.controller.channel.Channel;
|
||||||
import io.github.dsheirer.eventbus.MyEventBus;
|
import io.github.dsheirer.eventbus.MyEventBus;
|
||||||
@@ -45,6 +46,7 @@ import io.github.dsheirer.rrapi.type.Site;
|
|||||||
import io.github.dsheirer.rrapi.type.SiteFrequency;
|
import io.github.dsheirer.rrapi.type.SiteFrequency;
|
||||||
import io.github.dsheirer.rrapi.type.System;
|
import io.github.dsheirer.rrapi.type.System;
|
||||||
import io.github.dsheirer.rrapi.type.SystemInformation;
|
import io.github.dsheirer.rrapi.type.SystemInformation;
|
||||||
|
import io.github.dsheirer.service.radioreference.AliasListSynchronizer;
|
||||||
import io.github.dsheirer.source.config.SourceConfigTuner;
|
import io.github.dsheirer.source.config.SourceConfigTuner;
|
||||||
import io.github.dsheirer.source.config.SourceConfigTunerMultipleFrequency;
|
import io.github.dsheirer.source.config.SourceConfigTunerMultipleFrequency;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@@ -55,6 +57,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import javafx.animation.RotateTransition;
|
import javafx.animation.RotateTransition;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
@@ -75,6 +78,7 @@ import javafx.scene.control.TextField;
|
|||||||
import javafx.scene.control.TextFormatter;
|
import javafx.scene.control.TextFormatter;
|
||||||
import javafx.scene.control.TextInputDialog;
|
import javafx.scene.control.TextInputDialog;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
import javafx.scene.layout.ColumnConstraints;
|
import javafx.scene.layout.ColumnConstraints;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
@@ -120,6 +124,7 @@ public class SiteEditor extends GridPane
|
|||||||
private SystemInformation mCurrentSystemInformation;
|
private SystemInformation mCurrentSystemInformation;
|
||||||
private ComboBox mAliasListNameComboBox;
|
private ComboBox mAliasListNameComboBox;
|
||||||
private Button mNewAliasListButton;
|
private Button mNewAliasListButton;
|
||||||
|
private Button mNewSystemAliasListButton;
|
||||||
private Label mP25ControlLabel;
|
private Label mP25ControlLabel;
|
||||||
private SegmentedButton mP25ControlSegmentedButton;
|
private SegmentedButton mP25ControlSegmentedButton;
|
||||||
private ToggleButton mFdmaControlToggleButton;
|
private ToggleButton mFdmaControlToggleButton;
|
||||||
@@ -222,8 +227,12 @@ public class SiteEditor extends GridPane
|
|||||||
GridPane.setHgrow(getAliasListNameComboBox(), Priority.ALWAYS);
|
GridPane.setHgrow(getAliasListNameComboBox(), Priority.ALWAYS);
|
||||||
getChildren().add(getAliasListNameComboBox());
|
getChildren().add(getAliasListNameComboBox());
|
||||||
|
|
||||||
GridPane.setConstraints(getNewAliasListButton(), 2, ++row);
|
HBox aliasListButtonsBox = new HBox();
|
||||||
getChildren().add(getNewAliasListButton());
|
aliasListButtonsBox.setAlignment(Pos.CENTER_LEFT);
|
||||||
|
aliasListButtonsBox.setSpacing(10);
|
||||||
|
aliasListButtonsBox.getChildren().addAll(getNewAliasListButton(), getNewSystemAliasListButton());
|
||||||
|
GridPane.setConstraints(aliasListButtonsBox, 2, ++row);
|
||||||
|
getChildren().add(aliasListButtonsBox);
|
||||||
|
|
||||||
HBox createBox = new HBox();
|
HBox createBox = new HBox();
|
||||||
createBox.setAlignment(Pos.CENTER_LEFT);
|
createBox.setAlignment(Pos.CENTER_LEFT);
|
||||||
@@ -278,6 +287,18 @@ public class SiteEditor extends GridPane
|
|||||||
getGoToChannelEditorCheckBox().setDisable(disable || !supported);
|
getGoToChannelEditorCheckBox().setDisable(disable || !supported);
|
||||||
getAliasListNameComboBox().setDisable(disable || !supported);
|
getAliasListNameComboBox().setDisable(disable || !supported);
|
||||||
getNewAliasListButton().setDisable(disable || !supported);
|
getNewAliasListButton().setDisable(disable || !supported);
|
||||||
|
getNewSystemAliasListButton().setDisable(disable || !supported || system == null);
|
||||||
|
|
||||||
|
//Select an alias list that tracks this site's system, if there is one
|
||||||
|
if(system != null)
|
||||||
|
{
|
||||||
|
String trackingAliasList = mPlaylistManager.getAliasModel().getAliasListNameTracking(system.getSystemId());
|
||||||
|
|
||||||
|
if(trackingAliasList != null)
|
||||||
|
{
|
||||||
|
getAliasListNameComboBox().getSelectionModel().select(trackingAliasList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getCreateChannelConfigurationButton().setVisible(false);
|
getCreateChannelConfigurationButton().setVisible(false);
|
||||||
getGoToChannelEditorCheckBox().setVisible(false);
|
getGoToChannelEditorCheckBox().setVisible(false);
|
||||||
@@ -878,6 +899,97 @@ public class SiteEditor extends GridPane
|
|||||||
return mNewAliasListButton;
|
return mNewAliasListButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button to create an alias list that tracks the talkgroups of the current system on Radio Reference.
|
||||||
|
*/
|
||||||
|
private Button getNewSystemAliasListButton()
|
||||||
|
{
|
||||||
|
if(mNewSystemAliasListButton == null)
|
||||||
|
{
|
||||||
|
mNewSystemAliasListButton = new Button("New Alias List For System");
|
||||||
|
mNewSystemAliasListButton.setTooltip(new Tooltip("Create an alias list with the system's talkgroups " +
|
||||||
|
"that tracks the system on Radio Reference and automatically adds or updates talkgroup aliases"));
|
||||||
|
mNewSystemAliasListButton.setDisable(true);
|
||||||
|
mNewSystemAliasListButton.setOnAction(event -> createSystemAliasList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mNewSystemAliasListButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompts for a name and creates an alias list that tracks the current system, then imports the talkgroups.
|
||||||
|
*/
|
||||||
|
private void createSystemAliasList()
|
||||||
|
{
|
||||||
|
if(mCurrentSystem == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String systemName = mCurrentSystem.getName() != null ? mCurrentSystem.getName().trim() : "";
|
||||||
|
|
||||||
|
if(systemName.length() > 25)
|
||||||
|
{
|
||||||
|
systemName = systemName.substring(0, 25).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextInputDialog dialog = new TextInputDialog(systemName);
|
||||||
|
dialog.setTitle("Create New Alias List For System");
|
||||||
|
dialog.setHeaderText("Create an alias list that tracks the talkgroups for " + mCurrentSystem.getName() +
|
||||||
|
".\nPlease enter an alias list name (max 25 chars).");
|
||||||
|
dialog.setContentText("Name:");
|
||||||
|
dialog.getEditor().setTextFormatter(new TextFormatter<String>(new MaxLengthUnaryOperator(25)));
|
||||||
|
dialog.initOwner(getNewSystemAliasListButton().getScene().getWindow());
|
||||||
|
Optional<String> result = dialog.showAndWait();
|
||||||
|
|
||||||
|
if(result.isEmpty() || result.get().trim().isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = result.get().trim();
|
||||||
|
AliasModel aliasModel = mPlaylistManager.getAliasModel();
|
||||||
|
|
||||||
|
if(name.equals(AliasModel.NO_ALIAS_LIST) || aliasModel.aliasListNames().contains(name))
|
||||||
|
{
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR, "An alias list named [" + name +
|
||||||
|
"] already exists. Please choose another name.", ButtonType.OK);
|
||||||
|
alert.setTitle("Create New Alias List For System");
|
||||||
|
alert.setHeaderText("Alias List Exists");
|
||||||
|
alert.initOwner(getNewSystemAliasListButton().getScene().getWindow());
|
||||||
|
alert.showAndWait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AliasListConfiguration configuration = aliasModel.getOrCreateAliasListConfiguration(name);
|
||||||
|
configuration.track(mCurrentSystem.getSystemId(), mCurrentSystem.getName());
|
||||||
|
configuration.setAutoUpdate(true);
|
||||||
|
getAliasListNameComboBox().getSelectionModel().select(name);
|
||||||
|
|
||||||
|
getNewSystemAliasListButton().setDisable(true);
|
||||||
|
|
||||||
|
mPlaylistManager.getAliasListSynchronizer().refresh(configuration)
|
||||||
|
.whenComplete((syncResult, throwable) -> Platform.runLater(() -> {
|
||||||
|
getNewSystemAliasListButton().setDisable(mCurrentSystem == null);
|
||||||
|
|
||||||
|
if(throwable != null)
|
||||||
|
{
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR, "Alias list [" + name + "] was created, but the " +
|
||||||
|
"talkgroups couldn't be imported from Radio Reference. Use Refresh Now in the Aliases tab " +
|
||||||
|
"to try again.\n\n" + AliasListSynchronizer.getMessage(throwable), ButtonType.OK);
|
||||||
|
alert.setTitle("Create New Alias List For System");
|
||||||
|
alert.setHeaderText("Talkgroup Import Failed");
|
||||||
|
|
||||||
|
if(getScene() != null)
|
||||||
|
{
|
||||||
|
alert.initOwner(getScene().getWindow());
|
||||||
|
}
|
||||||
|
|
||||||
|
alert.show();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
private Label getProtocolNotSupportedLabel()
|
private Label getProtocolNotSupportedLabel()
|
||||||
{
|
{
|
||||||
if(mProtocolNotSupportedLabel == null)
|
if(mProtocolNotSupportedLabel == null)
|
||||||
|
|||||||
@@ -156,6 +156,41 @@ public class SystemEditor extends VBox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares to show the system with the site selected when the systems are next set.
|
||||||
|
* @param systemId of the system
|
||||||
|
* @param siteId to select, or -1 for none
|
||||||
|
*/
|
||||||
|
public void prepareView(int systemId, int siteId)
|
||||||
|
{
|
||||||
|
mUserPreferences.getRadioReferencePreference().setPreferredSystemId(systemId, mLevel);
|
||||||
|
getTabPane().getSelectionModel().select(getSystemTab());
|
||||||
|
getSystemSiteSelectionEditor().viewSite(systemId, siteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the system with the site selected
|
||||||
|
* @param systemId of the system
|
||||||
|
* @param siteId to select, or -1 for none
|
||||||
|
* @return false when the editor doesn't list the system
|
||||||
|
*/
|
||||||
|
public boolean view(int systemId, int siteId)
|
||||||
|
{
|
||||||
|
prepareView(systemId, siteId);
|
||||||
|
|
||||||
|
for(System system: getSystemComboBox().getItems())
|
||||||
|
{
|
||||||
|
if(system.getSystemId() == systemId)
|
||||||
|
{
|
||||||
|
//Selecting the shown system again doesn't reload it - the site is selected in the shown system
|
||||||
|
getSystemComboBox().getSelectionModel().select(system);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getSystemComboBox().getItems().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private TabPane getTabPane()
|
private TabPane getTabPane()
|
||||||
{
|
{
|
||||||
if(mTabPane == null)
|
if(mTabPane == null)
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public class SystemSiteSelectionEditor extends GridPane
|
|||||||
private UserPreferences mUserPreferences;
|
private UserPreferences mUserPreferences;
|
||||||
private PlaylistManager mPlaylistManager;
|
private PlaylistManager mPlaylistManager;
|
||||||
private ProgressIndicator mProgressIndicator;
|
private ProgressIndicator mProgressIndicator;
|
||||||
|
private int mPendingSystemId = -1;
|
||||||
|
private int mPendingSiteId = -1;
|
||||||
private Label mPlaceholderLabel;
|
private Label mPlaceholderLabel;
|
||||||
private Label mProtocolLabel;
|
private Label mProtocolLabel;
|
||||||
private Label mFlavorLabel;
|
private Label mFlavorLabel;
|
||||||
@@ -132,6 +134,46 @@ public class SystemSiteSelectionEditor extends GridPane
|
|||||||
Collections.sort(sites, Ordering.natural());
|
Collections.sort(sites, Ordering.natural());
|
||||||
getSiteTableView().getItems().addAll(sites);
|
getSiteTableView().getItems().addAll(sites);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
|
if(system != null && system.getSystemId() == mPendingSystemId)
|
||||||
|
{
|
||||||
|
selectSite(mPendingSiteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selects the site once the system is shown, or now when it's already shown.
|
||||||
|
* @param systemId of the system
|
||||||
|
* @param siteId to select, or -1 for none
|
||||||
|
*/
|
||||||
|
public void viewSite(int systemId, int siteId)
|
||||||
|
{
|
||||||
|
if(mCurrentSystem != null && mCurrentSystem.getSystemId() == systemId &&
|
||||||
|
!getSiteTableView().getItems().isEmpty())
|
||||||
|
{
|
||||||
|
selectSite(siteId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPendingSystemId = systemId;
|
||||||
|
mPendingSiteId = siteId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectSite(int siteId)
|
||||||
|
{
|
||||||
|
mPendingSystemId = -1;
|
||||||
|
mPendingSiteId = -1;
|
||||||
|
|
||||||
|
for(EnrichedSite site: getSiteTableView().getItems())
|
||||||
|
{
|
||||||
|
if(site.getSite() != null && site.getSite().getSiteId() == siteId)
|
||||||
|
{
|
||||||
|
getSiteTableView().getSelectionModel().select(site);
|
||||||
|
getSiteTableView().scrollTo(site);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear()
|
public void clear()
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.gui.playlist.radioreference;
|
||||||
|
|
||||||
|
import io.github.dsheirer.gui.playlist.PlaylistEditorRequest;
|
||||||
|
import io.github.dsheirer.service.radioreference.FrequencyCandidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to show a trunked system site, or a conventional frequency, in the playlist editor's Radio Reference tab
|
||||||
|
*/
|
||||||
|
public class ViewRadioReferenceRequest extends PlaylistEditorRequest
|
||||||
|
{
|
||||||
|
private final Integer mSystemId;
|
||||||
|
private final Integer mSiteId;
|
||||||
|
private final String mSourceKey;
|
||||||
|
private final FrequencyCandidate mCandidate;
|
||||||
|
|
||||||
|
private ViewRadioReferenceRequest(Integer systemId, Integer siteId, String sourceKey, FrequencyCandidate candidate)
|
||||||
|
{
|
||||||
|
mSystemId = systemId;
|
||||||
|
mSiteId = siteId;
|
||||||
|
mSourceKey = sourceKey;
|
||||||
|
mCandidate = candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to show a trunked system with the site selected
|
||||||
|
* @param systemId radio reference system id
|
||||||
|
* @param siteId radio reference site id, or null to show the system only
|
||||||
|
*/
|
||||||
|
public static ViewRadioReferenceRequest site(int systemId, Integer siteId)
|
||||||
|
{
|
||||||
|
return new ViewRadioReferenceRequest(systemId, siteId, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to show a conventional frequency in the county or agency that lists it
|
||||||
|
* @param sourceKey of the county or agency that lists the frequency: county:123 or agency:789
|
||||||
|
* @param candidate frequency to select
|
||||||
|
*/
|
||||||
|
public static ViewRadioReferenceRequest frequency(String sourceKey, FrequencyCandidate candidate)
|
||||||
|
{
|
||||||
|
return new ViewRadioReferenceRequest(null, null, sourceKey, candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio reference system id, or null for a conventional frequency
|
||||||
|
*/
|
||||||
|
public Integer getSystemId()
|
||||||
|
{
|
||||||
|
return mSystemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio reference site id, or null
|
||||||
|
*/
|
||||||
|
public Integer getSiteId()
|
||||||
|
{
|
||||||
|
return mSiteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key of the county or agency that lists the conventional frequency, or null for a trunked system
|
||||||
|
*/
|
||||||
|
public String getSourceKey()
|
||||||
|
{
|
||||||
|
return mSourceKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conventional frequency to select, or null for a trunked system
|
||||||
|
*/
|
||||||
|
public FrequencyCandidate getCandidate()
|
||||||
|
{
|
||||||
|
return mCandidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TabName getTabName()
|
||||||
|
{
|
||||||
|
return TabName.RADIOREFERENCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ import io.github.dsheirer.gui.preference.decoder.JmbeLibraryPreferenceEditor;
|
|||||||
import io.github.dsheirer.gui.preference.directory.DirectoryPreferenceEditor;
|
import io.github.dsheirer.gui.preference.directory.DirectoryPreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.mp3.MP3PreferenceEditor;
|
import io.github.dsheirer.gui.preference.mp3.MP3PreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.playback.PlaybackPreferenceEditor;
|
import io.github.dsheirer.gui.preference.playback.PlaybackPreferenceEditor;
|
||||||
|
import io.github.dsheirer.gui.preference.radioreference.RadioReferencePreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.record.RecordPreferenceEditor;
|
import io.github.dsheirer.gui.preference.record.RecordPreferenceEditor;
|
||||||
import io.github.dsheirer.gui.preference.tuner.TunerPreferenceEditor;
|
import io.github.dsheirer.gui.preference.tuner.TunerPreferenceEditor;
|
||||||
import io.github.dsheirer.preference.UserPreferences;
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
@@ -59,6 +60,8 @@ public class PreferenceEditorFactory
|
|||||||
return new DirectoryPreferenceEditor(userPreferences);
|
return new DirectoryPreferenceEditor(userPreferences);
|
||||||
case JMBE_LIBRARY:
|
case JMBE_LIBRARY:
|
||||||
return new JmbeLibraryPreferenceEditor(userPreferences);
|
return new JmbeLibraryPreferenceEditor(userPreferences);
|
||||||
|
case RADIO_REFERENCE_ALIAS_LISTS:
|
||||||
|
return new RadioReferencePreferenceEditor(userPreferences);
|
||||||
case SOURCE_TUNERS:
|
case SOURCE_TUNERS:
|
||||||
return new TunerPreferenceEditor(userPreferences);
|
return new TunerPreferenceEditor(userPreferences);
|
||||||
case TALKGROUP_FORMAT:
|
case TALKGROUP_FORMAT:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public enum PreferenceEditorType
|
|||||||
CHANNEL_EVENT("Channel Events"),
|
CHANNEL_EVENT("Channel Events"),
|
||||||
DIRECTORY("Directories"),
|
DIRECTORY("Directories"),
|
||||||
JMBE_LIBRARY("JMBE Audio Library"),
|
JMBE_LIBRARY("JMBE Audio Library"),
|
||||||
|
RADIO_REFERENCE_ALIAS_LISTS("Alias Lists"),
|
||||||
AUDIO_MP3("MP3"),
|
AUDIO_MP3("MP3"),
|
||||||
AUDIO_RECORD("Record"),
|
AUDIO_RECORD("Record"),
|
||||||
AUDIO_OUTPUT("Playback/Tones"),
|
AUDIO_OUTPUT("Playback/Tones"),
|
||||||
|
|||||||
@@ -200,6 +200,11 @@ public class UserPreferencesEditor extends BorderPane
|
|||||||
treeRoot.getChildren().add(storageItem);
|
treeRoot.getChildren().add(storageItem);
|
||||||
storageItem.setExpanded(true);
|
storageItem.setExpanded(true);
|
||||||
|
|
||||||
|
TreeItem<String> radioReferenceItem = new TreeItem<>("Radio Reference");
|
||||||
|
radioReferenceItem.getChildren().add(new TreeItem(PreferenceEditorType.RADIO_REFERENCE_ALIAS_LISTS));
|
||||||
|
treeRoot.getChildren().add(radioReferenceItem);
|
||||||
|
radioReferenceItem.setExpanded(true);
|
||||||
|
|
||||||
TreeItem<String> sourceItem = new TreeItem<>("Source");
|
TreeItem<String> sourceItem = new TreeItem<>("Source");
|
||||||
sourceItem.getChildren().add(new TreeItem(PreferenceEditorType.SOURCE_TUNERS));
|
sourceItem.getChildren().add(new TreeItem(PreferenceEditorType.SOURCE_TUNERS));
|
||||||
treeRoot.getChildren().add(sourceItem);
|
treeRoot.getChildren().add(sourceItem);
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.gui.preference.radioreference;
|
||||||
|
|
||||||
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
|
import io.github.dsheirer.preference.radioreference.AliasListUpdateInterval;
|
||||||
|
import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
|
||||||
|
import javafx.geometry.HPos;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference settings for alias lists that track a Radio Reference system.
|
||||||
|
*/
|
||||||
|
public class RadioReferencePreferenceEditor extends VBox
|
||||||
|
{
|
||||||
|
private RadioReferencePreference mRadioReferencePreference;
|
||||||
|
private ComboBox<AliasListUpdateInterval> mUpdateIntervalComboBox;
|
||||||
|
|
||||||
|
public RadioReferencePreferenceEditor(UserPreferences userPreferences)
|
||||||
|
{
|
||||||
|
mRadioReferencePreference = userPreferences.getRadioReferencePreference();
|
||||||
|
|
||||||
|
setPadding(new Insets(10, 10, 10, 10));
|
||||||
|
setSpacing(10);
|
||||||
|
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setHgap(10);
|
||||||
|
gridPane.setVgap(10);
|
||||||
|
|
||||||
|
Label intervalLabel = new Label("Check Tracked Systems For Talkgroup Changes:");
|
||||||
|
intervalLabel.setLabelFor(getUpdateIntervalComboBox());
|
||||||
|
GridPane.setHalignment(intervalLabel, HPos.RIGHT);
|
||||||
|
gridPane.add(intervalLabel, 0, 0);
|
||||||
|
gridPane.add(getUpdateIntervalComboBox(), 1, 0);
|
||||||
|
|
||||||
|
Label help = new Label("Alias lists that track a Radio Reference system check the system on this schedule " +
|
||||||
|
"while sdrtrunk is running and a Radio Reference login is stored. Alias lists with Auto-Update enabled " +
|
||||||
|
"add or update talkgroup aliases when the system changed. Use Refresh Now in the playlist editor's " +
|
||||||
|
"Aliases tab to update an alias list immediately.");
|
||||||
|
help.setWrapText(true);
|
||||||
|
help.setMaxWidth(500);
|
||||||
|
|
||||||
|
getChildren().addAll(gridPane, help);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComboBox<AliasListUpdateInterval> getUpdateIntervalComboBox()
|
||||||
|
{
|
||||||
|
if(mUpdateIntervalComboBox == null)
|
||||||
|
{
|
||||||
|
mUpdateIntervalComboBox = new ComboBox<>();
|
||||||
|
mUpdateIntervalComboBox.getItems().addAll(AliasListUpdateInterval.values());
|
||||||
|
mUpdateIntervalComboBox.getSelectionModel().select(mRadioReferencePreference.getAliasListUpdateInterval());
|
||||||
|
mUpdateIntervalComboBox.setOnAction(event -> mRadioReferencePreference
|
||||||
|
.setAliasListUpdateInterval(mUpdateIntervalComboBox.getSelectionModel().getSelectedItem()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return mUpdateIntervalComboBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.gui.spectrum;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channel shown in the display's Channels hover card
|
||||||
|
* @param title of the channel, drawn in the color of its state
|
||||||
|
* @param details lines
|
||||||
|
* @param state of the channel: an enabled or disabled playlist channel, or a radio reference candidate
|
||||||
|
* @param key identifying the channel, e.g. the playlist channel, so the card lists it once, or null
|
||||||
|
* @param prompts true when the entry is reason to show the card, e.g. the channel's labels don't fit in its box, or
|
||||||
|
* false when it's only listed while the card is shown for other entries
|
||||||
|
*/
|
||||||
|
public record ChannelCardEntry(String title, List<String> details, ChannelMenus.State state, Object key,
|
||||||
|
boolean prompts)
|
||||||
|
{
|
||||||
|
}
|
||||||
399
src/main/java/io/github/dsheirer/gui/spectrum/ChannelMenus.java
Normal file
399
src/main/java/io/github/dsheirer/gui/spectrum/ChannelMenus.java
Normal file
@@ -0,0 +1,399 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.gui.spectrum;
|
||||||
|
|
||||||
|
import io.github.dsheirer.controller.channel.Channel;
|
||||||
|
import io.github.dsheirer.eventbus.MyEventBus;
|
||||||
|
import io.github.dsheirer.gui.playlist.channel.ViewChannelRequest;
|
||||||
|
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import javafx.event.Event;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.ContextMenu;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.Menu;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
import javafx.scene.control.SeparatorMenuItem;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.stage.WindowEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context menu entries of the Channels section, shared by the playlist channel and radio reference layers. Each
|
||||||
|
* channel is a submenu showing its title and details, like the display's hover cards, with the actions for its state.
|
||||||
|
* The entries have the display theme's colors: the card background, with the title colored by state - the theme's
|
||||||
|
* active color (a green) for an enabled playlist channel, its inactive color (a blue) for a disabled one, and its
|
||||||
|
* plain text color for a radio reference candidate that isn't in the playlist.
|
||||||
|
*/
|
||||||
|
public final class ChannelMenus
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Context menu section of the channel entries
|
||||||
|
*/
|
||||||
|
public static final String SECTION = "Channels";
|
||||||
|
|
||||||
|
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||||
|
private static final String STYLE_ITEM = "channel-menu-item";
|
||||||
|
private static final String STYLE_TITLE = "channel-menu-title";
|
||||||
|
private static final String STYLE_DETAIL = "channel-menu-detail";
|
||||||
|
private static final String STYLE_NOTE = "channel-menu-note";
|
||||||
|
//Minimum contrast ratio of the colored text against the menu background
|
||||||
|
private static final double MIN_CONTRAST = 3.0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State of a channel entry, which sets its color
|
||||||
|
*/
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
ENABLED("channel-menu-enabled"),
|
||||||
|
DISABLED("channel-menu-disabled"),
|
||||||
|
CANDIDATE("channel-menu-candidate");
|
||||||
|
|
||||||
|
private final String mStyleClass;
|
||||||
|
|
||||||
|
State(String styleClass)
|
||||||
|
{
|
||||||
|
mStyleClass = styleClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStyleClass()
|
||||||
|
{
|
||||||
|
return mStyleClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelMenus()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channel entry submenu showing the title and details
|
||||||
|
* @param title of the channel
|
||||||
|
* @param details line, or null
|
||||||
|
* @param state of the channel
|
||||||
|
* @param key identifying the channel, e.g. the playlist channel, so the display lists it once, or null
|
||||||
|
*/
|
||||||
|
public static Menu createEntry(String title, String details, State state, Object key)
|
||||||
|
{
|
||||||
|
Label titleLabel = new Label(title);
|
||||||
|
titleLabel.getStyleClass().add(STYLE_TITLE);
|
||||||
|
VBox box = new VBox(titleLabel);
|
||||||
|
|
||||||
|
if(details != null)
|
||||||
|
{
|
||||||
|
Label detailLabel = new Label(details);
|
||||||
|
detailLabel.getStyleClass().add(STYLE_DETAIL);
|
||||||
|
box.getChildren().add(detailLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu menu = new Menu(null, box);
|
||||||
|
menu.getStyleClass().addAll(STYLE_ITEM, state.getStyleClass());
|
||||||
|
menu.setUserData(key);
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry for a playlist channel: enable or disable it, and view or edit it in the playlist editor
|
||||||
|
* @param channel in the playlist
|
||||||
|
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||||
|
* @param toggle that enables the channel when it's disabled or disables it when it's enabled, or null when the
|
||||||
|
* channel can't be started or stopped from the menu, e.g. a traffic channel
|
||||||
|
*/
|
||||||
|
public static Menu createChannelEntry(Channel channel, TunerChannel tunerChannel, Runnable toggle)
|
||||||
|
{
|
||||||
|
boolean processing = channel.isProcessing();
|
||||||
|
State state = getState(channel);
|
||||||
|
Menu menu = createEntry(getTitle(channel), String.join(" \u00B7 ", getDetails(channel, tunerChannel)), state,
|
||||||
|
channel);
|
||||||
|
|
||||||
|
if(toggle != null)
|
||||||
|
{
|
||||||
|
menu.getItems().add(createItem(processing ? "Disable" : "Enable", state, toggle));
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.getItems().add(createItem("View/Edit in Playlist", state,
|
||||||
|
() -> MyEventBus.getGlobalEventBus().post(new ViewChannelRequest(channel))));
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hover card entry for a playlist channel
|
||||||
|
* @param channel in the playlist
|
||||||
|
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||||
|
* @param prompts true when the entry is reason to show the card
|
||||||
|
*/
|
||||||
|
public static ChannelCardEntry createCardEntry(Channel channel, TunerChannel tunerChannel, boolean prompts)
|
||||||
|
{
|
||||||
|
//One details line, as in the menu entry, so the card has room for more channels
|
||||||
|
return new ChannelCardEntry(getTitle(channel), List.of(String.join(" \u00B7 ", getDetails(channel,
|
||||||
|
tunerChannel))), getState(channel), channel, prompts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* State of a playlist channel
|
||||||
|
*/
|
||||||
|
public static State getState(Channel channel)
|
||||||
|
{
|
||||||
|
return channel.isProcessing() ? State.ENABLED : State.DISABLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getTitle(Channel channel)
|
||||||
|
{
|
||||||
|
return channel.getName() != null && !channel.getName().isEmpty() ? channel.getName() : "(unnamed)";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detail lines of a playlist channel: the system and site, then the decoder, frequency and state
|
||||||
|
* @param tunerChannel of the channel to describe, or null for the channel's first
|
||||||
|
*/
|
||||||
|
public static List<String> getDetails(Channel channel, TunerChannel tunerChannel)
|
||||||
|
{
|
||||||
|
if(tunerChannel == null)
|
||||||
|
{
|
||||||
|
List<TunerChannel> tunerChannels = channel.getTunerChannels();
|
||||||
|
tunerChannel = tunerChannels.isEmpty() ? null : tunerChannels.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> details = new ArrayList<>();
|
||||||
|
String systemSite = join(channel.hasSystem() ? channel.getSystem() : null,
|
||||||
|
channel.hasSite() ? channel.getSite() : null);
|
||||||
|
|
||||||
|
if(systemSite != null)
|
||||||
|
{
|
||||||
|
details.add(systemSite);
|
||||||
|
}
|
||||||
|
|
||||||
|
details.add(join(channel.getDecodeConfiguration().getDecoderType().getShortDisplayString(),
|
||||||
|
tunerChannel != null ? FREQUENCY_FORMAT.format(tunerChannel.getFrequency() / 1E6) + " MHz" : null,
|
||||||
|
channel.isProcessing() ? "Enabled" : "Disabled"));
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action item of an entry's submenu
|
||||||
|
*/
|
||||||
|
public static MenuItem createItem(String text, State state, Runnable action)
|
||||||
|
{
|
||||||
|
MenuItem item = new MenuItem(text);
|
||||||
|
item.getStyleClass().addAll(STYLE_ITEM, state.getStyleClass());
|
||||||
|
item.setOnAction(event -> action.run());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inactive item of an entry's submenu that explains something, e.g. why a candidate can't be added
|
||||||
|
*/
|
||||||
|
public static MenuItem createNote(String text)
|
||||||
|
{
|
||||||
|
MenuItem item = new MenuItem(text);
|
||||||
|
item.getStyleClass().addAll(STYLE_ITEM, STYLE_NOTE);
|
||||||
|
item.setDisable(true);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Separator of an entry's submenu
|
||||||
|
*/
|
||||||
|
public static SeparatorMenuItem createSeparator()
|
||||||
|
{
|
||||||
|
SeparatorMenuItem separator = new SeparatorMenuItem();
|
||||||
|
separator.getStyleClass().add(STYLE_ITEM);
|
||||||
|
return separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives the context menu's channel entries the theme's colors. The stylesheet goes into the scenes of the menu
|
||||||
|
* and the entry submenus, since a popup takes its owner's stylesheets when it's shown and the application theme's
|
||||||
|
* stylesheets are added to each popup's scene: the more specific rules win in the same scene.
|
||||||
|
*/
|
||||||
|
public static void style(ContextMenu menu, SpectralDisplayTheme theme)
|
||||||
|
{
|
||||||
|
String stylesheet = createStylesheet(theme);
|
||||||
|
menu.addEventHandler(WindowEvent.WINDOW_SHOWN, event -> addStylesheet(menu.getScene(), stylesheet));
|
||||||
|
|
||||||
|
for(MenuItem item: menu.getItems())
|
||||||
|
{
|
||||||
|
if(item instanceof Menu entry && entry.getStyleClass().contains(STYLE_ITEM))
|
||||||
|
{
|
||||||
|
//The submenu's popup isn't exposed, but its items' nodes are in its scene once it's showing
|
||||||
|
EventHandler<Event> handler = event -> {
|
||||||
|
for(MenuItem child: entry.getItems())
|
||||||
|
{
|
||||||
|
Node node = child.getStyleableNode();
|
||||||
|
|
||||||
|
if(node != null && node.getScene() != null)
|
||||||
|
{
|
||||||
|
addStylesheet(node.getScene(), stylesheet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
entry.setOnShowing(handler);
|
||||||
|
entry.setOnShown(handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addStylesheet(Scene scene, String stylesheet)
|
||||||
|
{
|
||||||
|
if(scene != null && !scene.getStylesheets().contains(stylesheet))
|
||||||
|
{
|
||||||
|
scene.getStylesheets().add(stylesheet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stylesheet with the theme's colors
|
||||||
|
* @return data URL of the stylesheet
|
||||||
|
*/
|
||||||
|
static String createStylesheet(SpectralDisplayTheme theme)
|
||||||
|
{
|
||||||
|
Color background = opaque(theme.getBackground());
|
||||||
|
String detail = css(readable(opaque(theme.getLine()), background));
|
||||||
|
String item = ".menu-item." + STYLE_ITEM;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(item).append(" { -fx-background-color: ").append(css(background)).append("; }\n");
|
||||||
|
sb.append(item).append(":focused, ").append(item).append(":hover { -fx-background-color: ")
|
||||||
|
.append(css(background)).append(", ").append(css(theme.getLine(0.35))).append("; }\n");
|
||||||
|
sb.append(item).append(":disabled, ").append(item).append(":disabled .label { -fx-opacity: 1; }\n");
|
||||||
|
|
||||||
|
for(State state: State.values())
|
||||||
|
{
|
||||||
|
String color = css(readable(getColor(theme, state), background));
|
||||||
|
String stateItem = item + "." + state.getStyleClass();
|
||||||
|
//The item labels, and the title of an entry
|
||||||
|
sb.append(textRules(color, stateItem + " .label", stateItem + ":focused .label",
|
||||||
|
stateItem + ":hover .label"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//More specific than the state rules, so the details keep their color on hover
|
||||||
|
sb.append(textRules(detail, item + " .label." + STYLE_DETAIL, item + ":focused .label." + STYLE_DETAIL,
|
||||||
|
item + ":hover .label." + STYLE_DETAIL, item + "." + STYLE_NOTE + " .label"));
|
||||||
|
sb.append(item).append(" .label.").append(STYLE_TITLE).append(" { -fx-font-weight: bold; }\n");
|
||||||
|
sb.append(".menu.").append(STYLE_ITEM).append(" > .right-container > .arrow { -fx-background-color: ")
|
||||||
|
.append(detail).append("; }\n");
|
||||||
|
sb.append(".separator-menu-item.").append(STYLE_ITEM).append(" { -fx-padding: 0.25em 0; }\n");
|
||||||
|
sb.append(".separator-menu-item.").append(STYLE_ITEM).append(" > .line { -fx-border-color: ")
|
||||||
|
.append(css(theme.getLine(0.5)))
|
||||||
|
.append(" transparent transparent transparent; -fx-border-insets: 0; -fx-padding: 0; }\n");
|
||||||
|
return "data:text/css;base64," +
|
||||||
|
Base64.getEncoder().encodeToString(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title color of the state: the theme's active color (a green) for an enabled playlist channel, its inactive
|
||||||
|
* color (a blue) for a disabled one, and its plain text color for a radio reference candidate
|
||||||
|
*/
|
||||||
|
public static Color getColor(SpectralDisplayTheme theme, State state)
|
||||||
|
{
|
||||||
|
return switch(state)
|
||||||
|
{
|
||||||
|
case ENABLED -> theme.getChannelActive();
|
||||||
|
case DISABLED -> theme.getChannelInactive();
|
||||||
|
case CANDIDATE -> theme.getText();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color moved toward white on a dark background, or black on a light one, until it's readable on the background
|
||||||
|
*/
|
||||||
|
public static Color readable(Color color, Color background)
|
||||||
|
{
|
||||||
|
Color target = luminance(background) < 0.5 ? Color.WHITE : Color.BLACK;
|
||||||
|
Color adjusted = color;
|
||||||
|
|
||||||
|
for(int step = 1; step <= 10 && contrast(adjusted, background) < MIN_CONTRAST; step++)
|
||||||
|
{
|
||||||
|
adjusted = color.interpolate(target, step / 10.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return adjusted;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double contrast(Color a, Color b)
|
||||||
|
{
|
||||||
|
double la = luminance(a);
|
||||||
|
double lb = luminance(b);
|
||||||
|
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double luminance(Color color)
|
||||||
|
{
|
||||||
|
return (0.2126 * linear(color.getRed())) + (0.7152 * linear(color.getGreen())) +
|
||||||
|
(0.0722 * linear(color.getBlue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double linear(double channel)
|
||||||
|
{
|
||||||
|
return channel <= 0.03928 ? channel / 12.92 : Math.pow((channel + 0.055) / 1.055, 2.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rules that set the text color of the labels and of their text nodes. The dark application theme fills each
|
||||||
|
* label's text node, so both are set.
|
||||||
|
*/
|
||||||
|
private static String textRules(String color, String... labelSelectors)
|
||||||
|
{
|
||||||
|
String labels = String.join(", ", labelSelectors);
|
||||||
|
String texts = String.join(" .text, ", labelSelectors) + " .text";
|
||||||
|
return labels + " { -fx-text-fill: " + color + "; }\n" + texts + " { -fx-fill: " + color + "; }\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color opaque(Color color)
|
||||||
|
{
|
||||||
|
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String css(Color color)
|
||||||
|
{
|
||||||
|
return String.format(Locale.ROOT, "rgba(%d,%d,%d,%.3f)", Math.round(color.getRed() * 255),
|
||||||
|
Math.round(color.getGreen() * 255), Math.round(color.getBlue() * 255), color.getOpacity());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Values joined with a middle dot, skipping null and empty values
|
||||||
|
*/
|
||||||
|
public static String join(String... values)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for(String value: values)
|
||||||
|
{
|
||||||
|
if(value != null && !value.isEmpty())
|
||||||
|
{
|
||||||
|
if(!sb.isEmpty())
|
||||||
|
{
|
||||||
|
sb.append(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.isEmpty() ? null : sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,12 @@
|
|||||||
package io.github.dsheirer.gui.spectrum;
|
package io.github.dsheirer.gui.spectrum;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@@ -1120,15 +1126,53 @@ public class SpectralDisplay extends StackPane
|
|||||||
double xFraction = width > 0 ? event.getX() / width : 0.5;
|
double xFraction = width > 0 ? event.getX() / width : 0.5;
|
||||||
ContextMenu menu = new ContextMenu();
|
ContextMenu menu = new ContextMenu();
|
||||||
|
|
||||||
|
//Items of the layers grouped by section, in layer order. A layer without a section is a group of its own.
|
||||||
|
Map<Object,List<MenuItem>> groups = new LinkedHashMap<>();
|
||||||
|
Map<Object,Map<Object,MenuItem>> listed = new HashMap<>();
|
||||||
|
|
||||||
for(SpectralDisplayLayer layer: mLayers)
|
for(SpectralDisplayLayer layer: mLayers)
|
||||||
{
|
{
|
||||||
List<MenuItem> items = layer.getContextMenuItems(pane.getSection(), frequency);
|
List<MenuItem> items = layer.getContextMenuItems(pane.getSection(), frequency);
|
||||||
|
|
||||||
if(items != null && !items.isEmpty())
|
if(items == null || items.isEmpty())
|
||||||
{
|
{
|
||||||
menu.getItems().addAll(items);
|
continue;
|
||||||
menu.getItems().add(new SeparatorMenuItem());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object key = layer.getContextMenuSection() != null ? layer.getContextMenuSection() : layer;
|
||||||
|
List<MenuItem> group = groups.computeIfAbsent(key, k -> new ArrayList<>());
|
||||||
|
Map<Object,MenuItem> keys = listed.computeIfAbsent(key, k -> new IdentityHashMap<>());
|
||||||
|
|
||||||
|
for(MenuItem item: items)
|
||||||
|
{
|
||||||
|
MenuItem earlier = item.getUserData() != null ? keys.get(item.getUserData()) : null;
|
||||||
|
|
||||||
|
if(earlier != null)
|
||||||
|
{
|
||||||
|
//The same channel from another layer is listed once, with the other layer's options added
|
||||||
|
mergeOptions(earlier, item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(item.getUserData() != null)
|
||||||
|
{
|
||||||
|
keys.put(item.getUserData(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
group.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Map.Entry<Object,List<MenuItem>> group: groups.entrySet())
|
||||||
|
{
|
||||||
|
if(group.getKey() instanceof String section)
|
||||||
|
{
|
||||||
|
menu.getItems().add(SpectralDisplayLayer.createSectionHeader(section));
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.getItems().addAll(group.getValue());
|
||||||
|
menu.getItems().add(new SeparatorMenuItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu zoomMenu = new Menu("Zoom");
|
Menu zoomMenu = new Menu("Zoom");
|
||||||
@@ -1154,11 +1198,97 @@ public class SpectralDisplay extends StackPane
|
|||||||
menu.getItems().add(pause);
|
menu.getItems().add(pause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alignLabels(menu.getItems());
|
||||||
|
ChannelMenus.style(menu, getTheme());
|
||||||
mContextMenu = menu;
|
mContextMenu = menu;
|
||||||
menu.show(pane, event.getScreenX(), event.getScreenY());
|
menu.show(pane, event.getScreenX(), event.getScreenY());
|
||||||
event.consume();
|
event.consume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the submenu options of a later entry for the same channel that the earlier entry doesn't have, e.g. the
|
||||||
|
* radio reference layer's option to view a playlist channel's listing. When the later entry has all of the
|
||||||
|
* earlier entry's options, the earlier entry takes the later entry's options in their order, otherwise the
|
||||||
|
* missing options are added after a separator.
|
||||||
|
*/
|
||||||
|
private static void mergeOptions(MenuItem earlier, MenuItem later)
|
||||||
|
{
|
||||||
|
if(!(earlier instanceof Menu earlierMenu) || !(later instanceof Menu laterMenu))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> earlierTexts = getOptionTexts(earlierMenu);
|
||||||
|
Set<String> laterTexts = getOptionTexts(laterMenu);
|
||||||
|
|
||||||
|
if(laterTexts.containsAll(earlierTexts))
|
||||||
|
{
|
||||||
|
if(laterTexts.size() > earlierTexts.size())
|
||||||
|
{
|
||||||
|
//Items belong to one menu, so they're moved
|
||||||
|
List<MenuItem> options = new ArrayList<>(laterMenu.getItems());
|
||||||
|
laterMenu.getItems().clear();
|
||||||
|
earlierMenu.getItems().setAll(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MenuItem> added = new ArrayList<>();
|
||||||
|
|
||||||
|
for(MenuItem option: laterMenu.getItems())
|
||||||
|
{
|
||||||
|
if(!(option instanceof SeparatorMenuItem) && option.getText() != null &&
|
||||||
|
!earlierTexts.contains(option.getText()))
|
||||||
|
{
|
||||||
|
added.add(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!added.isEmpty())
|
||||||
|
{
|
||||||
|
laterMenu.getItems().removeAll(added);
|
||||||
|
earlierMenu.getItems().add(ChannelMenus.createSeparator());
|
||||||
|
earlierMenu.getItems().addAll(added);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> getOptionTexts(Menu menu)
|
||||||
|
{
|
||||||
|
Set<String> texts = new HashSet<>();
|
||||||
|
|
||||||
|
for(MenuItem option: menu.getItems())
|
||||||
|
{
|
||||||
|
if(!(option instanceof SeparatorMenuItem) && option.getText() != null)
|
||||||
|
{
|
||||||
|
texts.add(option.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return texts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A context menu places item text in a column after the widest graphic, so when a layer's items show their
|
||||||
|
* content as a graphic, the text of the other items is moved into a graphic too, to line up on the left.
|
||||||
|
*/
|
||||||
|
private static void alignLabels(List<MenuItem> items)
|
||||||
|
{
|
||||||
|
if(items.stream().noneMatch(item -> item.getGraphic() != null && !(item instanceof SeparatorMenuItem)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(MenuItem item: items)
|
||||||
|
{
|
||||||
|
if(item.getGraphic() == null && item.getText() != null && !(item instanceof SeparatorMenuItem))
|
||||||
|
{
|
||||||
|
item.setGraphic(new Label(item.getText()));
|
||||||
|
item.setText(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizable pane that holds a canvas for one display section.
|
* Resizable pane that holds a canvas for one display section.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -147,6 +147,44 @@ public abstract class SpectralDisplayLayer
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channels at the mouse position for the display's Channels hover card (see
|
||||||
|
* {@link io.github.dsheirer.gui.spectrum.layer.ChannelCardLayer}). Called on the JavaFX application thread while
|
||||||
|
* the mouse rests over the display, so it should be quick.
|
||||||
|
* @param cursor mouse position
|
||||||
|
* @param area of the section under the mouse
|
||||||
|
* @return entries, or an empty list
|
||||||
|
*/
|
||||||
|
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context menu section of this layer's items. The items of layers with the same section are listed together
|
||||||
|
* under a header with the section name, each item once: an item whose user data is the same object as an earlier
|
||||||
|
* item's in the section is left out.
|
||||||
|
* @return section name, or null for items of their own without a header
|
||||||
|
*/
|
||||||
|
public String getContextMenuSection()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section header for context menu items: an inactive item with smaller bold text in the theme's text color,
|
||||||
|
* slightly faded. Inline styles, since the application theme's stylesheets are added to each popup's scene.
|
||||||
|
* @param title of the section
|
||||||
|
*/
|
||||||
|
public static MenuItem createSectionHeader(String title)
|
||||||
|
{
|
||||||
|
MenuItem header = new MenuItem(title);
|
||||||
|
header.setDisable(true);
|
||||||
|
header.getStyleClass().add("spectral-menu-section-header");
|
||||||
|
header.setStyle("-fx-opacity: 0.6; -fx-font-size: 0.85em; -fx-font-weight: bold;");
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of this layer's section in the configuration panel, or null to place the layer's rows in the panel's
|
* Title of this layer's section in the configuration panel, or null to place the layer's rows in the panel's
|
||||||
* Display section instead of a section of their own.
|
* Display section instead of a section of their own.
|
||||||
|
|||||||
@@ -239,6 +239,74 @@ public enum SpectralDisplayTheme
|
|||||||
return mCorrection;
|
return mCorrection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text color for an active (enabled) playlist channel in the Channels menu and card: a green that reads as
|
||||||
|
* active on the theme's background, or the theme's own highlight in the monochrome themes. Red/green color
|
||||||
|
* blind themes use a yellowish green and blue/yellow color blind themes a green that stays distinct from
|
||||||
|
* {@link #getChannelInactive()}.
|
||||||
|
*/
|
||||||
|
public Color getChannelActive()
|
||||||
|
{
|
||||||
|
return Color.web(switch(this)
|
||||||
|
{
|
||||||
|
case CLASSIC -> "#33E633";
|
||||||
|
case DARK -> "#66BB6A";
|
||||||
|
case MEDIUM -> "#81C784";
|
||||||
|
case LIGHT -> "#2E7D32";
|
||||||
|
case GREEN_PHOSPHOR -> "#66FF8C";
|
||||||
|
case AMBER -> "#FFC233";
|
||||||
|
case GRAYSCALE -> "#FFFFFF";
|
||||||
|
case HIGH_CONTRAST_DARK -> "#00FF00";
|
||||||
|
case HIGH_CONTRAST_LIGHT -> "#006400";
|
||||||
|
case VIRIDIS -> "#6DCD59";
|
||||||
|
case CIVIDIS -> "#B4DE2C";
|
||||||
|
case INFERNO -> "#4CC764";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text color for an inactive (disabled) playlist channel in the Channels menu and card: a blue that reads as
|
||||||
|
* inactive on the theme's background, or a dimmed shade in the monochrome themes. The blue/yellow color blind
|
||||||
|
* theme uses a pink, since blue and green look alike there.
|
||||||
|
*/
|
||||||
|
public Color getChannelInactive()
|
||||||
|
{
|
||||||
|
return Color.web(switch(this)
|
||||||
|
{
|
||||||
|
case CLASSIC -> "#4D9FFF";
|
||||||
|
case DARK -> "#64B5F6";
|
||||||
|
case MEDIUM -> "#90CAF9";
|
||||||
|
case LIGHT -> "#1565C0";
|
||||||
|
case GREEN_PHOSPHOR -> "#3FAF5C";
|
||||||
|
case AMBER -> "#B07A10";
|
||||||
|
case GRAYSCALE -> "#8C8C8C";
|
||||||
|
case HIGH_CONTRAST_DARK -> "#00BFFF";
|
||||||
|
case HIGH_CONTRAST_LIGHT -> "#0000C0";
|
||||||
|
case VIRIDIS -> "#5B9BF0";
|
||||||
|
case CIVIDIS -> "#56B4E9";
|
||||||
|
case INFERNO -> "#E879C6";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plain text color on the theme's background, e.g. for menu entries that aren't highlighted
|
||||||
|
*/
|
||||||
|
public Color getText()
|
||||||
|
{
|
||||||
|
return Color.web(switch(this)
|
||||||
|
{
|
||||||
|
case CLASSIC, HIGH_CONTRAST_DARK -> "#FFFFFF";
|
||||||
|
case DARK -> "#E6E8EB";
|
||||||
|
case MEDIUM -> "#F0F4F8";
|
||||||
|
case LIGHT -> "#212529";
|
||||||
|
case GREEN_PHOSPHOR -> "#CCFFCC";
|
||||||
|
case AMBER -> "#FFF0C2";
|
||||||
|
case GRAYSCALE -> "#D0D0D0";
|
||||||
|
case HIGH_CONTRAST_LIGHT -> "#000000";
|
||||||
|
case VIRIDIS, CIVIDIS, INFERNO -> "#E8E8EE";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ARGB color for the waterfall intensity index (0 - 255).
|
* ARGB color for the waterfall intensity index (0 - 255).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package io.github.dsheirer.gui.spectrum;
|
|||||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||||
|
import io.github.dsheirer.gui.spectrum.layer.ChannelCardLayer;
|
||||||
import io.github.dsheirer.gui.spectrum.layer.ChannelLayer;
|
import io.github.dsheirer.gui.spectrum.layer.ChannelLayer;
|
||||||
import io.github.dsheirer.gui.spectrum.layer.RadioReferenceLayer;
|
import io.github.dsheirer.gui.spectrum.layer.RadioReferenceLayer;
|
||||||
import io.github.dsheirer.playlist.PlaylistManager;
|
import io.github.dsheirer.playlist.PlaylistManager;
|
||||||
@@ -104,8 +105,8 @@ public class TunerSpectralDisplay extends DftSpectralDisplay implements ISourceE
|
|||||||
private TunerSpectralDisplay(ChannelLayer channelLayer, RadioReferenceLayer radioReferenceLayer,
|
private TunerSpectralDisplay(ChannelLayer channelLayer, RadioReferenceLayer radioReferenceLayer,
|
||||||
DiscoveredTunerModel discoveredTunerModel, boolean saveSettings)
|
DiscoveredTunerModel discoveredTunerModel, boolean saveSettings)
|
||||||
{
|
{
|
||||||
//The radio reference layer draws after the channel layer, so its card is on top
|
//The channels card draws after the other layers, so it's on top
|
||||||
super(SETTINGS_PREFIX, saveSettings, channelLayer, radioReferenceLayer);
|
super(SETTINGS_PREFIX, saveSettings, channelLayer, radioReferenceLayer, new ChannelCardLayer());
|
||||||
mChannelLayer = channelLayer;
|
mChannelLayer = channelLayer;
|
||||||
mRadioReferenceLayer = radioReferenceLayer;
|
mRadioReferenceLayer = radioReferenceLayer;
|
||||||
mDiscoveredTunerModel = discoveredTunerModel;
|
mDiscoveredTunerModel = discoveredTunerModel;
|
||||||
|
|||||||
@@ -0,0 +1,430 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.gui.spectrum.layer;
|
||||||
|
|
||||||
|
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||||
|
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||||
|
import io.github.dsheirer.gui.spectrum.CursorReadout;
|
||||||
|
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||||
|
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||||
|
import io.github.dsheirer.gui.spectrum.RenderArea;
|
||||||
|
import io.github.dsheirer.gui.spectrum.SpectralDisplayLayer;
|
||||||
|
import io.github.dsheirer.gui.spectrum.SpectralDisplayModel;
|
||||||
|
import io.github.dsheirer.gui.spectrum.SpectralDisplayTheme;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import javafx.animation.PauseTransition;
|
||||||
|
import javafx.geometry.VPos;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.scene.text.FontWeight;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.scene.text.TextAlignment;
|
||||||
|
import javafx.util.Duration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Channels hover card. When the mouse rests over the spectrum or the waterfall, shows a card next to the mouse with
|
||||||
|
* the channels at the mouse position that the other layers provide (see
|
||||||
|
* {@link SpectralDisplayLayer#getCardEntries}): playlist channels first, then radio reference candidates. The titles
|
||||||
|
* have the colors of the Channels context menu entries: one for an enabled playlist channel, one for a disabled one
|
||||||
|
* and one for a candidate. The card replaces the cursor readout and ends with the readout lines.
|
||||||
|
*
|
||||||
|
* The card is shown when an entry prompts it, e.g. a playlist channel whose labels don't fit in its box or a
|
||||||
|
* candidate; the other channels at the mouse position are then listed too.
|
||||||
|
*/
|
||||||
|
public class ChannelCardLayer extends SpectralDisplayLayer
|
||||||
|
{
|
||||||
|
private static final Duration HOVER_DELAY = Duration.millis(400);
|
||||||
|
private static final Font FONT = Font.font(11);
|
||||||
|
private static final Font TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
||||||
|
private static final int MAX_ENTRIES = 6;
|
||||||
|
private static final double MAX_TEXT_WIDTH = 380;
|
||||||
|
private static final double PADDING = 6;
|
||||||
|
private static final double GAP = 5;
|
||||||
|
//Space beside the text and below the readout lines, as in the cursor readout, so the readout lines stay in place
|
||||||
|
private static final double PADDING_X = 4;
|
||||||
|
//Space kept between the card and the edges of the section
|
||||||
|
private static final double EDGE_MARGIN = 2;
|
||||||
|
private static final double READOUT_PADDING = 2;
|
||||||
|
private static final String HEADER = ChannelMenus.SECTION;
|
||||||
|
|
||||||
|
private final Text mMeasure = new Text();
|
||||||
|
private final double mTextHeight;
|
||||||
|
private PauseTransition mHoverTimer;
|
||||||
|
private DisplaySection mHoverSection;
|
||||||
|
private double mHoverX = Double.NaN;
|
||||||
|
private double mHoverY = Double.NaN;
|
||||||
|
private boolean mHoverReady;
|
||||||
|
private List<ChannelCardEntry> mEntries = Collections.emptyList();
|
||||||
|
private Card mCard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card text, measured when the entries or the room change
|
||||||
|
* @param entries lines of each shown entry: the title, then the details
|
||||||
|
* @param states of the shown entries
|
||||||
|
* @param more line, or null
|
||||||
|
* @param textWidth of the widest line
|
||||||
|
* @param lineCount of the header, entry and more lines
|
||||||
|
* @param source entries the card was made from
|
||||||
|
* @param maxTextWidth that the lines were shortened to
|
||||||
|
* @param maxHeight that the card was limited to
|
||||||
|
* @param readoutLines that the card was sized for
|
||||||
|
*/
|
||||||
|
private record Card(List<List<String>> entries, List<ChannelMenus.State> states, String more, double textWidth,
|
||||||
|
int lineCount, List<ChannelCardEntry> source, double maxTextWidth, double maxHeight,
|
||||||
|
int readoutLines)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
*/
|
||||||
|
public ChannelCardLayer()
|
||||||
|
{
|
||||||
|
mMeasure.setFont(FONT);
|
||||||
|
mMeasure.setText("Ag");
|
||||||
|
mTextHeight = Math.ceil(mMeasure.getLayoutBounds().getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
if(mHoverTimer != null)
|
||||||
|
{
|
||||||
|
mHoverTimer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderSpectrumForeground(GraphicsContext gc, RenderArea area)
|
||||||
|
{
|
||||||
|
render(gc, area, DisplaySection.SPECTRUM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
||||||
|
{
|
||||||
|
render(gc, area, DisplaySection.WATERFALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the card in the section under the mouse once the mouse has rested for the hover delay
|
||||||
|
*/
|
||||||
|
private void render(GraphicsContext gc, RenderArea area, DisplaySection section)
|
||||||
|
{
|
||||||
|
DisplayCursor cursor = getSpectralDisplay() != null ? getSpectralDisplay().getDisplayCursor() : null;
|
||||||
|
trackHover(cursor);
|
||||||
|
|
||||||
|
if(cursor != null && cursor.section() == section && replacesCursorReadout(cursor, area))
|
||||||
|
{
|
||||||
|
drawCard(gc, area, cursor, mEntries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The card replaces the cursor readout while it's shown: it ends with the readout lines, in the readout's place.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean replacesCursorReadout(DisplayCursor cursor, RenderArea area)
|
||||||
|
{
|
||||||
|
SpectralDisplayModel model = getModel();
|
||||||
|
|
||||||
|
//Only for the position the mouse rested at - the readout comes back as soon as the mouse moves
|
||||||
|
if(!mHoverReady || model == null || !model.hasSource() || cursor == null || cursor.section() != mHoverSection ||
|
||||||
|
cursor.x() != mHoverX || cursor.y() != mHoverY || area.width() <= 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mEntries = getEntries(cursor, area);
|
||||||
|
return mEntries.stream().anyMatch(ChannelCardEntry::prompts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entries of the other layers, each channel once, playlist channels first
|
||||||
|
*/
|
||||||
|
private List<ChannelCardEntry> getEntries(DisplayCursor cursor, RenderArea area)
|
||||||
|
{
|
||||||
|
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||||
|
Set<Object> keys = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||||
|
|
||||||
|
for(SpectralDisplayLayer layer: getSpectralDisplay().getLayers())
|
||||||
|
{
|
||||||
|
if(layer == this)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ChannelCardEntry entry: layer.getCardEntries(cursor, area))
|
||||||
|
{
|
||||||
|
if(entry.key() == null || keys.add(entry.key()))
|
||||||
|
{
|
||||||
|
entries.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entries.sort(Comparator.comparing(entry -> entry.state() == ChannelMenus.State.CANDIDATE));
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restarts the hover delay each time the mouse moves, and hides the card until it passes
|
||||||
|
*/
|
||||||
|
private void trackHover(DisplayCursor cursor)
|
||||||
|
{
|
||||||
|
if(cursor == null)
|
||||||
|
{
|
||||||
|
if(mHoverSection != null)
|
||||||
|
{
|
||||||
|
mHoverSection = null;
|
||||||
|
mHoverReady = false;
|
||||||
|
getHoverTimer().stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY)
|
||||||
|
{
|
||||||
|
mHoverSection = cursor.section();
|
||||||
|
mHoverX = cursor.x();
|
||||||
|
mHoverY = cursor.y();
|
||||||
|
mHoverReady = false;
|
||||||
|
getHoverTimer().playFromStart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PauseTransition getHoverTimer()
|
||||||
|
{
|
||||||
|
if(mHoverTimer == null)
|
||||||
|
{
|
||||||
|
mHoverTimer = new PauseTransition(HOVER_DELAY);
|
||||||
|
mHoverTimer.setOnFinished(event -> {
|
||||||
|
mHoverReady = true;
|
||||||
|
requestRender();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return mHoverTimer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the card in place of the cursor readout: beside the mouse and above it, placed like the readout, with the
|
||||||
|
* channels above the readout lines so the frequency and level stay where the readout showed them. The card fits
|
||||||
|
* the larger side of the mouse and the height of the section, showing as many channels as fit.
|
||||||
|
*/
|
||||||
|
private void drawCard(GraphicsContext gc, RenderArea area, DisplayCursor cursor, List<ChannelCardEntry> entries)
|
||||||
|
{
|
||||||
|
//The level line changes with the mouse height while the channels don't
|
||||||
|
List<String> readout = CursorReadout.lines(cursor, area, getModel());
|
||||||
|
double readoutWidth = 0;
|
||||||
|
|
||||||
|
for(String line: readout)
|
||||||
|
{
|
||||||
|
readoutWidth = Math.max(readoutWidth, measure(line, FONT));
|
||||||
|
}
|
||||||
|
|
||||||
|
double room = Math.max(area.width() - cursor.x(), cursor.x()) - CursorReadout.GAP_X - EDGE_MARGIN;
|
||||||
|
double maxTextWidth = Math.max(readoutWidth, Math.min(MAX_TEXT_WIDTH, room - (PADDING_X * 2)));
|
||||||
|
//Above the mouse, so the readout lines stay where the readout showed them, when an entry fits there
|
||||||
|
double above = cursor.y() - CursorReadout.GAP_Y;
|
||||||
|
double maxHeight = above >= cardHeight(5, 1, true, readout.size()) ? above : area.plotHeight() - EDGE_MARGIN;
|
||||||
|
|
||||||
|
if(mCard == null || !mCard.source().equals(entries) || mCard.maxTextWidth() != maxTextWidth ||
|
||||||
|
mCard.maxHeight() != maxHeight || mCard.readoutLines() != readout.size())
|
||||||
|
{
|
||||||
|
mCard = createCard(entries, maxTextWidth, maxHeight, readout.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
Card card = mCard;
|
||||||
|
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
||||||
|
Color background = opaque(theme.getBackground());
|
||||||
|
Color detail = opaque(theme.getLine());
|
||||||
|
double width = Math.max(card.textWidth(), readoutWidth) + (PADDING_X * 2);
|
||||||
|
double height = cardHeight(card.lineCount(), card.entries().size(), card.more() != null, readout.size());
|
||||||
|
double x = Math.max(0, CursorReadout.x(cursor, width, area));
|
||||||
|
double y = CursorReadout.y(cursor, height, area);
|
||||||
|
|
||||||
|
gc.setFill(theme.getBackground(0.92));
|
||||||
|
gc.fillRoundRect(x, y, width, height, 8, 8);
|
||||||
|
gc.setStroke(detail);
|
||||||
|
gc.setLineWidth(1.0);
|
||||||
|
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
||||||
|
gc.setTextAlign(TextAlignment.LEFT);
|
||||||
|
gc.setTextBaseline(VPos.TOP);
|
||||||
|
|
||||||
|
double textX = x + PADDING_X;
|
||||||
|
double lineY = y + PADDING;
|
||||||
|
gc.setFill(detail);
|
||||||
|
gc.setFont(TITLE_FONT);
|
||||||
|
gc.fillText(HEADER, textX, lineY);
|
||||||
|
lineY += mTextHeight + GAP;
|
||||||
|
|
||||||
|
for(int index = 0; index < card.entries().size(); index++)
|
||||||
|
{
|
||||||
|
List<String> lines = card.entries().get(index);
|
||||||
|
gc.setFill(ChannelMenus.readable(ChannelMenus.getColor(theme, card.states().get(index)), background));
|
||||||
|
gc.setFont(TITLE_FONT);
|
||||||
|
gc.fillText(lines.get(0), textX, lineY);
|
||||||
|
lineY += mTextHeight;
|
||||||
|
gc.setFill(detail);
|
||||||
|
gc.setFont(FONT);
|
||||||
|
|
||||||
|
for(int line = 1; line < lines.size(); line++)
|
||||||
|
{
|
||||||
|
gc.fillText(lines.get(line), textX, lineY);
|
||||||
|
lineY += mTextHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
lineY += GAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(card.more() != null)
|
||||||
|
{
|
||||||
|
gc.setFill(detail);
|
||||||
|
gc.setFont(FONT);
|
||||||
|
gc.fillText(card.more(), textX, lineY);
|
||||||
|
lineY += mTextHeight + GAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
//The readout lines, separated from the channels, in the readout's style
|
||||||
|
double separator = Math.floor(lineY - (GAP / 2.0)) + 0.5;
|
||||||
|
gc.setStroke(theme.getLine(0.5));
|
||||||
|
gc.strokeLine(textX, separator, x + width - PADDING_X, separator);
|
||||||
|
gc.setFill(theme.getCursor());
|
||||||
|
gc.setFont(FONT);
|
||||||
|
|
||||||
|
for(String line: readout)
|
||||||
|
{
|
||||||
|
gc.fillText(line, textX, lineY);
|
||||||
|
lineY += mTextHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Height of a card with the lines
|
||||||
|
* @param lineCount of the header, entry and more lines
|
||||||
|
* @param entries number of entries
|
||||||
|
* @param more true when the card has a more line
|
||||||
|
* @param readoutLines number of readout lines
|
||||||
|
*/
|
||||||
|
private double cardHeight(int lineCount, int entries, boolean more, int readoutLines)
|
||||||
|
{
|
||||||
|
int gaps = 1 + entries + (more ? 1 : 0);
|
||||||
|
return ((lineCount + readoutLines) * mTextHeight) + (gaps * GAP) + PADDING + READOUT_PADDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card text for as many entries as fit the height, shortened to the width
|
||||||
|
*/
|
||||||
|
private Card createCard(List<ChannelCardEntry> source, double maxTextWidth, double maxHeight, int readoutLines)
|
||||||
|
{
|
||||||
|
int limit = Math.min(source.size(), MAX_ENTRIES);
|
||||||
|
List<List<String>> entries = new ArrayList<>();
|
||||||
|
List<ChannelMenus.State> states = new ArrayList<>();
|
||||||
|
double textWidth = measure(HEADER, TITLE_FONT);
|
||||||
|
int lineCount = 1;
|
||||||
|
|
||||||
|
for(int index = 0; index < limit; index++)
|
||||||
|
{
|
||||||
|
ChannelCardEntry entry = source.get(index);
|
||||||
|
List<String> lines = new ArrayList<>();
|
||||||
|
lines.add(fit(entry.title(), TITLE_FONT, maxTextWidth));
|
||||||
|
|
||||||
|
for(String detail: entry.details())
|
||||||
|
{
|
||||||
|
if(detail != null)
|
||||||
|
{
|
||||||
|
lines.add(fit(detail, FONT, maxTextWidth));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Keep room for the more line when entries are left out
|
||||||
|
boolean more = index + 1 < source.size();
|
||||||
|
|
||||||
|
if(!entries.isEmpty() && cardHeight(lineCount + lines.size() + (more ? 1 : 0), entries.size() + 1, more,
|
||||||
|
readoutLines) > maxHeight)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textWidth = Math.max(textWidth, measure(lines.get(0), TITLE_FONT));
|
||||||
|
|
||||||
|
for(int line = 1; line < lines.size(); line++)
|
||||||
|
{
|
||||||
|
textWidth = Math.max(textWidth, measure(lines.get(line), FONT));
|
||||||
|
}
|
||||||
|
|
||||||
|
lineCount += lines.size();
|
||||||
|
entries.add(lines);
|
||||||
|
states.add(entry.state());
|
||||||
|
}
|
||||||
|
|
||||||
|
String more = source.size() > entries.size() ? "+ " + (source.size() - entries.size()) + " more" : null;
|
||||||
|
|
||||||
|
if(more != null)
|
||||||
|
{
|
||||||
|
textWidth = Math.max(textWidth, measure(more, FONT));
|
||||||
|
lineCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Card(entries, states, more, textWidth, lineCount, source, maxTextWidth, maxHeight, readoutLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text shortened with an ellipsis to fit the width
|
||||||
|
*/
|
||||||
|
private String fit(String text, Font font, double maxWidth)
|
||||||
|
{
|
||||||
|
if(measure(text, font) <= maxWidth)
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = text.length();
|
||||||
|
|
||||||
|
while(length > 1 && measure(text.substring(0, length) + "…", font) > maxWidth)
|
||||||
|
{
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.substring(0, length) + "…";
|
||||||
|
}
|
||||||
|
|
||||||
|
private double measure(String text, Font font)
|
||||||
|
{
|
||||||
|
mMeasure.setFont(font);
|
||||||
|
mMeasure.setText(text);
|
||||||
|
double width = mMeasure.getLayoutBounds().getWidth();
|
||||||
|
mMeasure.setFont(FONT);
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color opaque(Color color)
|
||||||
|
{
|
||||||
|
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,8 +24,8 @@ import io.github.dsheirer.controller.channel.ChannelEvent;
|
|||||||
import io.github.dsheirer.controller.channel.ChannelException;
|
import io.github.dsheirer.controller.channel.ChannelException;
|
||||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||||
import io.github.dsheirer.eventbus.MyEventBus;
|
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||||
import io.github.dsheirer.gui.playlist.channel.ViewChannelRequest;
|
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||||
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
||||||
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||||
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||||
@@ -56,7 +56,6 @@ import javafx.scene.control.MenuItem;
|
|||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.FontWeight;
|
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.scene.text.TextAlignment;
|
import javafx.scene.text.TextAlignment;
|
||||||
|
|
||||||
@@ -66,24 +65,20 @@ import javafx.scene.text.TextAlignment;
|
|||||||
* decoder. Processing and selected channels use their own colors. When the decoder applies a frequency correction,
|
* decoder. Processing and selected channels use their own colors. When the decoder applies a frequency correction,
|
||||||
* a bracket at the bottom of the box shows the corrected channel position and the PPM error.
|
* a bracket at the bottom of the box shows the corrected channel position and the PPM error.
|
||||||
*
|
*
|
||||||
* When the zoom level is too low for a channel's labels to fit in its box, moving the mouse over the channel shows a
|
* When the zoom level is too low for a channel's labels to fit in its box, resting the mouse over the channel lists
|
||||||
* popout card near the bottom of the spectrum (or the waterfall) with the channel name, system, site, decoder,
|
* it in the Channels hover card (drawn by {@link ChannelCardLayer}) with its system, site, decoder, frequency and
|
||||||
* frequency and state. The popout can be turned off with the hover details setting.
|
* state. This can be turned off with the hover details setting.
|
||||||
*
|
*
|
||||||
* Right-clicking a channel adds a menu item to view or edit the channel in the playlist editor.
|
* Right-clicking a channel lists it in the Channels context menu, to enable or disable it or view or edit it in the
|
||||||
|
* playlist editor.
|
||||||
*/
|
*/
|
||||||
public class ChannelLayer extends SpectralDisplayLayer
|
public class ChannelLayer extends SpectralDisplayLayer
|
||||||
{
|
{
|
||||||
private static final Font FONT = Font.font(11);
|
private static final Font FONT = Font.font(11);
|
||||||
private static final DecimalFormat PPM_FORMAT = new DecimalFormat("0.0");
|
private static final DecimalFormat PPM_FORMAT = new DecimalFormat("0.0");
|
||||||
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||||
private static final Font POPOUT_TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
|
||||||
private static final double MIN_LABEL_BOX_WIDTH = 12;
|
private static final double MIN_LABEL_BOX_WIDTH = 12;
|
||||||
private static final double POPOUT_MIN_HIT_WIDTH = 10;
|
private static final double MIN_HIT_WIDTH = 10;
|
||||||
private static final double POPOUT_PADDING = 6;
|
|
||||||
private static final double POPOUT_GAP = 5;
|
|
||||||
private static final double POPOUT_SWATCH = 8;
|
|
||||||
private static final int POPOUT_MAX_CHANNELS = 4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Which channels the layer shows.
|
* Which channels the layer shows.
|
||||||
@@ -382,131 +377,23 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPopout(gc, area, DisplaySection.SPECTRUM);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
|
||||||
{
|
|
||||||
renderPopout(gc, area, DisplaySection.WATERFALL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a card near the bottom of the section under the mouse with the details of each channel under the mouse
|
* Card entries for the channels under the mouse. A channel whose labels don't fit in its box at the current
|
||||||
* whose labels don't fit in its box at the current zoom. The card moves to the top of the section when the mouse
|
* zoom prompts the card. The hit area of a narrow channel is widened so it can be found with the mouse.
|
||||||
* is over the bottom of the section.
|
|
||||||
*/
|
*/
|
||||||
private void renderPopout(GraphicsContext gc, RenderArea area, DisplaySection section)
|
@Override
|
||||||
|
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||||
{
|
{
|
||||||
SpectralDisplayModel model = getModel();
|
SpectralDisplayModel model = getModel();
|
||||||
DisplayCursor cursor = getSpectralDisplay().getDisplayCursor();
|
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||||
|
|
||||||
if(!mHoverDetails.get() || model == null || !model.hasSource() || cursor == null ||
|
if(!mHoverDetails.get() || model == null || mChannelDisplay.get() == ChannelDisplay.NONE)
|
||||||
cursor.section() != section || mChannelDisplay.get() == ChannelDisplay.NONE)
|
|
||||||
{
|
{
|
||||||
return;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PopoutEntry> entries = getPopoutEntries(model, area, cursor.x());
|
|
||||||
|
|
||||||
if(entries.isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
|
||||||
int shown = Math.min(entries.size(), POPOUT_MAX_CHANNELS);
|
|
||||||
String more = entries.size() > shown ? "+ " + (entries.size() - shown) + " more" : null;
|
|
||||||
|
|
||||||
//Measure the card
|
|
||||||
double textWidth = 0;
|
|
||||||
int lineCount = 0;
|
|
||||||
|
|
||||||
for(int x = 0; x < shown; x++)
|
|
||||||
{
|
|
||||||
PopoutEntry entry = entries.get(x);
|
|
||||||
textWidth = Math.max(textWidth, measure(entry.title(), POPOUT_TITLE_FONT) + POPOUT_SWATCH + 5);
|
|
||||||
|
|
||||||
for(String line: entry.details())
|
|
||||||
{
|
|
||||||
textWidth = Math.max(textWidth, measure(line, FONT));
|
|
||||||
}
|
|
||||||
|
|
||||||
lineCount += 1 + entry.details().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(more != null)
|
|
||||||
{
|
|
||||||
textWidth = Math.max(textWidth, measure(more, FONT));
|
|
||||||
lineCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
double width = textWidth + (POPOUT_PADDING * 2);
|
|
||||||
double height = (lineCount * mTextHeight) + ((shown - 1) * POPOUT_GAP) + (POPOUT_PADDING * 2);
|
|
||||||
double bottom = section == DisplaySection.SPECTRUM ? area.plotHeight() : area.height();
|
|
||||||
double x = Math.max(4, Math.min(area.width() - width - 4, cursor.x() - (width / 2.0)));
|
|
||||||
double y = bottom - height - 6;
|
|
||||||
|
|
||||||
//Keep the card out from under the mouse
|
|
||||||
if(cursor.y() >= y - 4)
|
|
||||||
{
|
|
||||||
y = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(y < 0 || width > area.width())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gc.setFill(theme.getBackground(0.88));
|
|
||||||
gc.fillRoundRect(x, y, width, height, 8, 8);
|
|
||||||
gc.setStroke(opaque(theme.getLine()));
|
|
||||||
gc.setLineWidth(1.0);
|
|
||||||
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
|
||||||
gc.setTextAlign(TextAlignment.LEFT);
|
|
||||||
gc.setTextBaseline(VPos.TOP);
|
|
||||||
|
|
||||||
double lineY = y + POPOUT_PADDING;
|
|
||||||
double textX = x + POPOUT_PADDING;
|
|
||||||
|
|
||||||
for(int index = 0; index < shown; index++)
|
|
||||||
{
|
|
||||||
PopoutEntry entry = entries.get(index);
|
|
||||||
double swatchY = lineY + ((mTextHeight - POPOUT_SWATCH) / 2.0);
|
|
||||||
gc.setFill(opaque(entry.color()));
|
|
||||||
gc.fillRect(textX, swatchY, POPOUT_SWATCH, POPOUT_SWATCH);
|
|
||||||
gc.setFill(theme.getCursor());
|
|
||||||
gc.setFont(POPOUT_TITLE_FONT);
|
|
||||||
gc.fillText(entry.title(), textX + POPOUT_SWATCH + 5, lineY);
|
|
||||||
lineY += mTextHeight;
|
|
||||||
gc.setFill(opaque(theme.getLine()));
|
|
||||||
gc.setFont(FONT);
|
|
||||||
|
|
||||||
for(String line: entry.details())
|
|
||||||
{
|
|
||||||
gc.fillText(line, textX, lineY);
|
|
||||||
lineY += mTextHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
lineY += POPOUT_GAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(more != null)
|
|
||||||
{
|
|
||||||
gc.fillText(more, textX, lineY - POPOUT_GAP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Channels under the screen x position whose labels don't fit in the channel box. The hit area of a narrow
|
|
||||||
* channel is widened so it can be found with the mouse.
|
|
||||||
*/
|
|
||||||
private List<PopoutEntry> getPopoutEntries(SpectralDisplayModel model, RenderArea area, double cursorX)
|
|
||||||
{
|
|
||||||
List<PopoutEntry> entries = new ArrayList<>();
|
|
||||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
|
||||||
|
|
||||||
for(Channel channel: getChannels(model))
|
for(Channel channel: getChannels(model))
|
||||||
{
|
{
|
||||||
if(!isShown(channel))
|
if(!isShown(channel))
|
||||||
@@ -523,40 +410,16 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double hitWidth = Math.max(POPOUT_MIN_HIT_WIDTH, box.width());
|
double hitWidth = Math.max(MIN_HIT_WIDTH, box.width());
|
||||||
double hitStart = box.center() - (hitWidth / 2.0);
|
double hitStart = box.center() - (hitWidth / 2.0);
|
||||||
|
|
||||||
if(cursorX < hitStart || cursorX > hitStart + hitWidth || labelsFit(channel, box))
|
if(cursor.x() >= hitStart && cursor.x() <= hitStart + hitWidth)
|
||||||
{
|
{
|
||||||
continue;
|
entries.add(ChannelMenus.createCardEntry(channel, tunerChannel, !labelsFit(channel, box)));
|
||||||
}
|
|
||||||
|
|
||||||
List<String> details = new ArrayList<>();
|
|
||||||
String systemSite = join(channel.hasSystem() ? channel.getSystem() : null,
|
|
||||||
channel.hasSite() ? channel.getSite() : null);
|
|
||||||
|
|
||||||
if(systemSite != null)
|
|
||||||
{
|
|
||||||
details.add(systemSite);
|
|
||||||
}
|
|
||||||
|
|
||||||
String state = channel.isProcessing() ? "Enabled" : "Disabled";
|
|
||||||
|
|
||||||
if(channel.isSelected())
|
|
||||||
{
|
|
||||||
state += ", Selected";
|
|
||||||
}
|
|
||||||
|
|
||||||
details.add(join(channel.getDecodeConfiguration().getDecoderType().getShortDisplayString(),
|
|
||||||
FREQUENCY_FORMAT.format(tunerChannel.getFrequency() / 1E6) + " MHz", state));
|
|
||||||
|
|
||||||
Color color = channel.isSelected() ? theme.getChannelSelected() :
|
|
||||||
channel.isProcessing() ? theme.getChannelProcessing() : theme.getChannel();
|
|
||||||
entries.add(new PopoutEntry(channel.getName() != null ? channel.getName() : "(unnamed)", details,
|
|
||||||
color));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
@@ -723,14 +586,9 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
frequency <= tunerChannel.getMaxFrequency())
|
frequency <= tunerChannel.getMaxFrequency())
|
||||||
{
|
{
|
||||||
//Traffic channels are started and stopped by their decoder, not from the playlist
|
//Traffic channels are started and stopped by their decoder, not from the playlist
|
||||||
if(!channel.isTrafficChannel() && mChannelProcessingManager != null)
|
Runnable toggle = !channel.isTrafficChannel() && mChannelProcessingManager != null ?
|
||||||
{
|
() -> toggle(channel) : null;
|
||||||
items.add(createEnableItem(channel));
|
items.add(ChannelMenus.createChannelEntry(channel, tunerChannel, toggle));
|
||||||
}
|
|
||||||
|
|
||||||
MenuItem item = new MenuItem("View/Edit: " + channel.getShortTitle());
|
|
||||||
item.setOnAction(e -> MyEventBus.getGlobalEventBus().post(new ViewChannelRequest(channel)));
|
|
||||||
items.add(item);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -739,14 +597,20 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContextMenuSection()
|
||||||
|
{
|
||||||
|
return ChannelMenus.SECTION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu item that starts the channel when it's disabled, or stops it when it's enabled, in the background
|
* Stops the channel when it's processing, otherwise starts it
|
||||||
*/
|
*/
|
||||||
private MenuItem createEnableItem(Channel channel)
|
private void toggle(Channel channel)
|
||||||
{
|
{
|
||||||
boolean processing = channel.isProcessing();
|
boolean processing = channel.isProcessing();
|
||||||
MenuItem item = new MenuItem((processing ? "Disable: " : "Enable: ") + channel.getShortTitle());
|
|
||||||
item.setOnAction(e -> ThreadPool.CACHED.execute(() -> {
|
ThreadPool.CACHED.execute(() -> {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(processing)
|
if(processing)
|
||||||
@@ -762,8 +626,7 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
{
|
{
|
||||||
showError((processing ? "Can't stop " : "Can't start ") + channel.getShortTitle(), ce.getMessage());
|
showError((processing ? "Can't stop " : "Can't start ") + channel.getShortTitle(), ce.getMessage());
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -792,10 +655,4 @@ public class ChannelLayer extends SpectralDisplayLayer
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Channel details for the popout card.
|
|
||||||
*/
|
|
||||||
private record PopoutEntry(String title, List<String> details, Color color)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,24 +20,27 @@
|
|||||||
package io.github.dsheirer.gui.spectrum.layer;
|
package io.github.dsheirer.gui.spectrum.layer;
|
||||||
|
|
||||||
import io.github.dsheirer.controller.channel.Channel;
|
import io.github.dsheirer.controller.channel.Channel;
|
||||||
|
import io.github.dsheirer.eventbus.MyEventBus;
|
||||||
|
import io.github.dsheirer.gui.playlist.radioreference.ViewRadioReferenceRequest;
|
||||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||||
import io.github.dsheirer.module.decode.DecoderType;
|
import io.github.dsheirer.module.decode.DecoderType;
|
||||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.scene.control.Menu;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
|
import io.github.dsheirer.gui.spectrum.ChannelCardEntry;
|
||||||
|
import io.github.dsheirer.gui.spectrum.ChannelMenus;
|
||||||
|
import io.github.dsheirer.gui.spectrum.ChannelMenus.State;
|
||||||
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
import io.github.dsheirer.gui.spectrum.ConfigurationRow;
|
||||||
import io.github.dsheirer.gui.spectrum.CursorReadout;
|
|
||||||
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
import io.github.dsheirer.gui.spectrum.DisplayCursor;
|
||||||
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
import io.github.dsheirer.gui.spectrum.DisplaySection;
|
||||||
import io.github.dsheirer.gui.spectrum.RenderArea;
|
import io.github.dsheirer.gui.spectrum.RenderArea;
|
||||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayLayer;
|
import io.github.dsheirer.gui.spectrum.SpectralDisplayLayer;
|
||||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayModel;
|
import io.github.dsheirer.gui.spectrum.SpectralDisplayModel;
|
||||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayTheme;
|
|
||||||
import io.github.dsheirer.service.radioreference.DistanceFormat;
|
import io.github.dsheirer.service.radioreference.DistanceFormat;
|
||||||
import io.github.dsheirer.service.radioreference.FrequencyCandidate;
|
import io.github.dsheirer.service.radioreference.FrequencyCandidate;
|
||||||
import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
|
import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
|
||||||
@@ -45,76 +48,37 @@ import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex.Ra
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javafx.animation.PauseTransition;
|
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.geometry.VPos;
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.text.Font;
|
|
||||||
import javafx.scene.text.FontWeight;
|
|
||||||
import javafx.scene.text.Text;
|
|
||||||
import javafx.scene.text.TextAlignment;
|
|
||||||
import javafx.util.Duration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Radio reference candidates layer. When the mouse rests over the spectrum or the waterfall, shows a card next to the
|
* Radio reference candidates layer. Lists the radio reference frequencies near the frequency under the mouse,
|
||||||
* mouse with the radio reference frequencies near the frequency under the mouse, nearest to the user's location first.
|
* nearest to the user's location first, in the Channels hover card (drawn by {@link ChannelCardLayer}) and the
|
||||||
|
* Channels context menu. A candidate that a playlist channel already decodes is listed as that channel.
|
||||||
*
|
*
|
||||||
* The candidates come from the radio reference frequency index, which needs a premium account and the user's location.
|
* The candidates come from the radio reference frequency index, which needs a premium account and the user's location.
|
||||||
* Looking up a frequency doesn't call the web service.
|
* Looking up a frequency doesn't call the web service.
|
||||||
*/
|
*/
|
||||||
public class RadioReferenceLayer extends SpectralDisplayLayer
|
public class RadioReferenceLayer extends SpectralDisplayLayer
|
||||||
{
|
{
|
||||||
private static final Duration HOVER_DELAY = Duration.millis(400);
|
|
||||||
private static final Font FONT = Font.font(11);
|
|
||||||
private static final Font TITLE_FONT = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
|
||||||
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
private static final DecimalFormat FREQUENCY_FORMAT = new DecimalFormat("0.00000");
|
||||||
private static final long MIN_TOLERANCE_HZ = 3_000;
|
private static final long MIN_TOLERANCE_HZ = 3_000;
|
||||||
private static final double TOLERANCE_PIXELS = 3.0;
|
private static final double TOLERANCE_PIXELS = 3.0;
|
||||||
private static final int MAX_CANDIDATES = 6;
|
private static final int MAX_CANDIDATES = 6;
|
||||||
private static final double MAX_TEXT_WIDTH = 380;
|
|
||||||
private static final double PADDING = 6;
|
|
||||||
private static final double GAP = 5;
|
|
||||||
//Space beside the text and below the readout lines, as in the cursor readout, so the readout lines stay in place
|
|
||||||
private static final double PADDING_X = 4;
|
|
||||||
//Space kept between the card and the edges of the section
|
|
||||||
private static final double EDGE_MARGIN = 2;
|
|
||||||
private static final double READOUT_PADDING = 2;
|
|
||||||
private static final String HEADER = "Radio Reference";
|
|
||||||
|
|
||||||
private final RadioReferenceFrequencyIndex mIndex;
|
private final RadioReferenceFrequencyIndex mIndex;
|
||||||
private final RadioReferencePlaylistActions mActions;
|
private final RadioReferencePlaylistActions mActions;
|
||||||
private final BooleanProperty mHoverCandidates = new SimpleBooleanProperty(true);
|
private final BooleanProperty mHoverCandidates = new SimpleBooleanProperty(true);
|
||||||
private final Text mMeasure = new Text();
|
|
||||||
private final double mTextHeight;
|
|
||||||
private PauseTransition mHoverTimer;
|
|
||||||
private DisplaySection mHoverSection;
|
|
||||||
private double mHoverX = Double.NaN;
|
|
||||||
private double mHoverY = Double.NaN;
|
|
||||||
private boolean mHoverReady;
|
|
||||||
private long mResultsFrequency = Long.MIN_VALUE;
|
private long mResultsFrequency = Long.MIN_VALUE;
|
||||||
private long mResultsTolerance;
|
private long mResultsTolerance;
|
||||||
private List<RankedCandidate> mResults = Collections.emptyList();
|
private List<RankedCandidate> mResults = Collections.emptyList();
|
||||||
private Card mCard;
|
private List<RankedCandidate> mCardCandidates;
|
||||||
|
private List<ChannelCardEntry> mCardEntries = Collections.emptyList();
|
||||||
/**
|
private long mCardEntriesTime;
|
||||||
* Candidate text of the card, measured once per lookup
|
|
||||||
* @param entries lines of each candidate: the title, then the details
|
|
||||||
* @param more line, or null
|
|
||||||
* @param textWidth of the widest line
|
|
||||||
* @param lineCount of the header, candidate and more lines
|
|
||||||
* @param maxTextWidth that the lines were shortened to
|
|
||||||
* @param maxHeight that the card was limited to
|
|
||||||
* @param readoutLines that the card was sized for
|
|
||||||
*/
|
|
||||||
private record Card(List<List<String>> entries, String more, double textWidth, int lineCount,
|
|
||||||
double maxTextWidth, double maxHeight, int readoutLines)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance.
|
* Constructs an instance.
|
||||||
@@ -125,9 +89,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
{
|
{
|
||||||
mIndex = index;
|
mIndex = index;
|
||||||
mActions = actions;
|
mActions = actions;
|
||||||
mMeasure.setFont(FONT);
|
|
||||||
mMeasure.setText("Ag");
|
|
||||||
mTextHeight = Math.ceil(mMeasure.getLayoutBounds().getHeight());
|
|
||||||
mHoverCandidates.addListener((ob, ov, nv) -> requestRender());
|
mHoverCandidates.addListener((ob, ov, nv) -> requestRender());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,15 +109,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose()
|
|
||||||
{
|
|
||||||
if(mHoverTimer != null)
|
|
||||||
{
|
|
||||||
mHoverTimer.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getConfigurationTitle()
|
public String getConfigurationTitle()
|
||||||
{
|
{
|
||||||
@@ -181,10 +133,17 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
return List.of(hover, new ConfigurationRow("Nearby", status));
|
return List.of(hover, new ConfigurationRow("Nearby", status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContextMenuSection()
|
||||||
|
{
|
||||||
|
return ChannelMenus.SECTION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context menu items for the candidates at the frequency, in the card's order: add a candidate to the playlist and
|
* Channel entries for the candidates at the frequency, in the card's order. A candidate that a playlist channel
|
||||||
* start it, or enable or disable the playlist channel that already decodes it. One item per site, and per
|
* already decodes is listed as that playlist channel, otherwise as a candidate to add to the playlist (and
|
||||||
* frequency and protocol, so an item never adds a duplicate channel.
|
* start). Both can be viewed in the playlist editor's Radio Reference tab (View in Radio Reference). One entry per site, since the site's
|
||||||
|
* frequencies share its channel. Adding never duplicates a playlist channel.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<MenuItem> getContextMenuItems(DisplaySection section, long frequency)
|
public List<MenuItem> getContextMenuItems(DisplaySection section, long frequency)
|
||||||
@@ -219,139 +178,121 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
|
|
||||||
if(site != null && offered.add(key))
|
if(site != null && offered.add(key))
|
||||||
{
|
{
|
||||||
addSiteItem(items, site, candidate, frequency);
|
items.add(createSiteEntry(site, ranked));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if(offered.add("frequency:" + candidate.frequencyHz() + ":" + candidate.title() + ":" +
|
||||||
|
candidate.source()))
|
||||||
{
|
{
|
||||||
DecoderType decoderType = RadioReferencePlaylistActions.getDecoderType(candidate);
|
items.add(createConventionalEntry(ranked, RadioReferencePlaylistActions.getDecoderType(candidate)));
|
||||||
Set<DecoderType> family = RadioReferencePlaylistActions.getProtocolFamily(decoderType);
|
|
||||||
String protocol = family.isEmpty() ? String.valueOf(candidate.mode()) : family.iterator().next().name();
|
|
||||||
|
|
||||||
if(offered.add("frequency:" + candidate.frequencyHz() + ":" + protocol))
|
|
||||||
{
|
|
||||||
addConventionalItem(items, candidate, decoderType, frequency);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!items.isEmpty())
|
//Playlist channels first, then the candidates, each in the card's order
|
||||||
{
|
items.sort(Comparator.comparing(item -> item.getUserData() == null));
|
||||||
MenuItem header = new MenuItem("Radio Reference");
|
|
||||||
header.setDisable(true);
|
|
||||||
items.add(0, header);
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSiteItem(List<MenuItem> items, SiteRecord site, FrequencyCandidate candidate, long frequency)
|
/**
|
||||||
|
* Entry for a trunked system site, or for the candidate's repeater of a repeater site (LTR)
|
||||||
|
*/
|
||||||
|
private Menu createSiteEntry(SiteRecord site, RankedCandidate ranked)
|
||||||
{
|
{
|
||||||
String label = site.systemName() + " \u00B7 Site " + site.siteNumber() +
|
FrequencyCandidate candidate = ranked.candidate();
|
||||||
(site.description() != null ? " " + site.description() : "");
|
boolean repeater = RadioReferencePlaylistActions.isRepeaterSite(site);
|
||||||
|
ViewRadioReferenceRequest view = ViewRadioReferenceRequest.site(site.systemId(), site.siteId());
|
||||||
String unsupported = RadioReferencePlaylistActions.getUnsupportedReason(site);
|
String unsupported = RadioReferencePlaylistActions.getUnsupportedReason(site);
|
||||||
|
Channel existing = unsupported != null ? null : repeater ? mActions.findChannel(List.of(candidate.frequencyHz()),
|
||||||
|
RadioReferencePlaylistActions.getSiteDecoderTypes(site)) : mActions.findSiteChannel(site);
|
||||||
|
|
||||||
|
if(existing != null)
|
||||||
|
{
|
||||||
|
return createPlaylistEntry(existing, view);
|
||||||
|
}
|
||||||
|
|
||||||
|
String title = site.systemName() + " \u00B7 Site " + site.siteNumber() +
|
||||||
|
(site.description() != null ? " " + site.description() : "");
|
||||||
|
|
||||||
|
if(repeater)
|
||||||
|
{
|
||||||
|
title += site.channels().stream().filter(channel -> channel.frequencyHz() == candidate.frequencyHz() &&
|
||||||
|
channel.logicalChannelNumber() > 0).map(channel -> " LCN " + channel.logicalChannelNumber())
|
||||||
|
.findFirst().orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu menu = ChannelMenus.createEntry(title, describe(ranked), State.CANDIDATE, null);
|
||||||
|
|
||||||
if(unsupported != null)
|
if(unsupported != null)
|
||||||
{
|
{
|
||||||
MenuItem item = new MenuItem(label + " \u2013 " + unsupported);
|
menu.getItems().add(ChannelMenus.createNote(unsupported));
|
||||||
item.setDisable(true);
|
|
||||||
items.add(item);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if(repeater)
|
||||||
if(RadioReferencePlaylistActions.isRepeaterSite(site))
|
|
||||||
{
|
{
|
||||||
addRepeaterItem(items, site, candidate.frequencyHz(), label, frequency);
|
menu.getItems().addAll(
|
||||||
return;
|
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||||
}
|
() -> mActions.addRepeater(site, candidate.frequencyHz(), true, this::showError)),
|
||||||
|
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||||
Channel existing = mActions.findSiteChannel(site);
|
() -> mActions.addRepeater(site, candidate.frequencyHz(), false, this::showError)));
|
||||||
|
|
||||||
if(existing != null)
|
|
||||||
{
|
|
||||||
//The channel layer offers the channels at the clicked frequency
|
|
||||||
if(!covers(existing, frequency))
|
|
||||||
{
|
|
||||||
items.add(createEnableItem(existing));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MenuItem item = new MenuItem("Add and Start: " + label);
|
//Start on the candidate frequency when it's a control or alternate control channel
|
||||||
//Start on the right-clicked frequency when it's a control or alternate control channel
|
menu.getItems().addAll(
|
||||||
item.setOnAction(event -> mActions.addSite(site, candidate.frequencyHz(), this::showError));
|
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||||
items.add(item);
|
() -> mActions.addSite(site, candidate.frequencyHz(), true, this::showError)),
|
||||||
|
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||||
|
() -> mActions.addSite(site, candidate.frequencyHz(), false, this::showError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addViewItem(menu, State.CANDIDATE, view);
|
||||||
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu item for one repeater of a repeater site (LTR): add and start it, or enable or disable its channel
|
* Entry for a conventional frequency
|
||||||
*/
|
*/
|
||||||
private void addRepeaterItem(List<MenuItem> items, SiteRecord site, long repeaterFrequency, String label,
|
private Menu createConventionalEntry(RankedCandidate ranked, DecoderType decoderType)
|
||||||
long frequency)
|
|
||||||
{
|
{
|
||||||
Channel existing = mActions.findChannel(List.of(repeaterFrequency),
|
FrequencyCandidate candidate = ranked.candidate();
|
||||||
RadioReferencePlaylistActions.getSiteDecoderTypes(site));
|
String sourceKey = mIndex.getSourceKey(candidate);
|
||||||
|
ViewRadioReferenceRequest view = sourceKey != null ?
|
||||||
|
ViewRadioReferenceRequest.frequency(sourceKey, candidate) : null;
|
||||||
|
Channel existing = decoderType != null ? mActions.findConventionalChannel(candidate) : null;
|
||||||
|
|
||||||
if(existing != null)
|
if(existing != null)
|
||||||
{
|
{
|
||||||
if(!covers(existing, frequency))
|
return createPlaylistEntry(existing, view);
|
||||||
{
|
|
||||||
items.add(createEnableItem(existing));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
Menu menu = ChannelMenus.createEntry(candidate.title() != null ? candidate.title() : "(untitled)",
|
||||||
}
|
describe(ranked), State.CANDIDATE, null);
|
||||||
|
|
||||||
String lcn = site.channels().stream().filter(channel -> channel.frequencyHz() == repeaterFrequency &&
|
|
||||||
channel.logicalChannelNumber() > 0).map(channel -> " LCN " + channel.logicalChannelNumber())
|
|
||||||
.findFirst().orElse("");
|
|
||||||
MenuItem item = new MenuItem("Add and Start: " + label + lcn + " (" +
|
|
||||||
FREQUENCY_FORMAT.format(repeaterFrequency / 1E6) + " MHz)");
|
|
||||||
item.setOnAction(event -> mActions.addRepeater(site, repeaterFrequency, this::showError));
|
|
||||||
items.add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addConventionalItem(List<MenuItem> items, FrequencyCandidate candidate, DecoderType decoderType,
|
|
||||||
long frequency)
|
|
||||||
{
|
|
||||||
String label = candidate.title() + " (" + FREQUENCY_FORMAT.format(candidate.frequencyHz() / 1E6) + " MHz" +
|
|
||||||
(candidate.mode() != null ? " " + candidate.mode() : "") + ")";
|
|
||||||
|
|
||||||
if(decoderType == null)
|
if(decoderType == null)
|
||||||
{
|
{
|
||||||
MenuItem item = new MenuItem(label + " \u2013 mode isn't supported");
|
menu.getItems().add(ChannelMenus.createNote("Mode isn't supported"));
|
||||||
item.setDisable(true);
|
|
||||||
items.add(item);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Channel existing = mActions.findConventionalChannel(candidate);
|
|
||||||
|
|
||||||
if(existing != null)
|
|
||||||
{
|
|
||||||
if(!covers(existing, frequency))
|
|
||||||
{
|
|
||||||
items.add(createEnableItem(existing));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MenuItem item = new MenuItem("Add and Start: " + label);
|
menu.getItems().addAll(
|
||||||
item.setOnAction(event -> mActions.addConventional(candidate, this::showError));
|
ChannelMenus.createItem("Add to Playlist and Start", State.CANDIDATE,
|
||||||
items.add(item);
|
() -> mActions.addConventional(candidate, true, this::showError)),
|
||||||
|
ChannelMenus.createItem("Add to Playlist", State.CANDIDATE,
|
||||||
|
() -> mActions.addConventional(candidate, false, this::showError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addViewItem(menu, State.CANDIDATE, view);
|
||||||
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu item that enables the playlist channel when it's disabled, or disables it when it's enabled
|
* Entry for the playlist channel that decodes a candidate: enable or disable it, view or edit it, and view the
|
||||||
|
* candidate in the Radio Reference tab
|
||||||
|
* @param view request for the candidate, or null when its listing isn't known
|
||||||
*/
|
*/
|
||||||
private MenuItem createEnableItem(Channel channel)
|
private Menu createPlaylistEntry(Channel channel, ViewRadioReferenceRequest view)
|
||||||
{
|
{
|
||||||
boolean processing = channel.isProcessing();
|
Runnable toggle = channel.isTrafficChannel() ? null : () -> {
|
||||||
MenuItem item = new MenuItem((processing ? "Disable: " : "Enable: ") + channel.getShortTitle());
|
if(channel.isProcessing())
|
||||||
item.setOnAction(event -> {
|
|
||||||
if(processing)
|
|
||||||
{
|
{
|
||||||
mActions.disable(channel, this::showError);
|
mActions.disable(channel, this::showError);
|
||||||
}
|
}
|
||||||
@@ -359,25 +300,22 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
{
|
{
|
||||||
mActions.enable(channel, this::showError);
|
mActions.enable(channel, this::showError);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
return item;
|
Menu menu = ChannelMenus.createChannelEntry(channel, null, toggle);
|
||||||
|
addViewItem(menu, channel.isProcessing() ? State.ENABLED : State.DISABLED, view);
|
||||||
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if one of the channel's tuner channels includes the frequency
|
* Adds the item that shows the candidate in the playlist editor's Radio Reference tab
|
||||||
|
* @param request to show the candidate, or null when the candidate's listing isn't known
|
||||||
*/
|
*/
|
||||||
private static boolean covers(Channel channel, long frequency)
|
private static void addViewItem(Menu menu, State state, ViewRadioReferenceRequest request)
|
||||||
{
|
{
|
||||||
for(TunerChannel tunerChannel: channel.getTunerChannels())
|
MenuItem view = ChannelMenus.createItem("View in Radio Reference", state,
|
||||||
{
|
() -> MyEventBus.getGlobalEventBus().post(request));
|
||||||
if(tunerChannel != null && tunerChannel.getMinFrequency() <= frequency &&
|
view.setDisable(request == null);
|
||||||
frequency <= tunerChannel.getMaxFrequency())
|
menu.getItems().addAll(ChannelMenus.createSeparator(), view);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -399,49 +337,88 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderSpectrumForeground(GraphicsContext gc, RenderArea area)
|
|
||||||
{
|
|
||||||
render(gc, area, DisplaySection.SPECTRUM);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderWaterfall(GraphicsContext gc, RenderArea area)
|
|
||||||
{
|
|
||||||
render(gc, area, DisplaySection.WATERFALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the card in the section under the mouse once the mouse has rested for the hover delay
|
* Card entries for the candidates at the mouse position, in the card's order. A candidate that a playlist
|
||||||
*/
|
* channel already decodes is listed as that playlist channel.
|
||||||
private void render(GraphicsContext gc, RenderArea area, DisplaySection section)
|
|
||||||
{
|
|
||||||
DisplayCursor cursor = getSpectralDisplay() != null ? getSpectralDisplay().getDisplayCursor() : null;
|
|
||||||
trackHover(cursor);
|
|
||||||
|
|
||||||
if(cursor != null && cursor.section() == section && replacesCursorReadout(cursor, area))
|
|
||||||
{
|
|
||||||
drawCard(gc, area, cursor, getCandidates(cursor.frequency(), getTolerance(getModel(), area)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The card replaces the cursor readout while it's shown: it ends with the readout lines, in the readout's place.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean replacesCursorReadout(DisplayCursor cursor, RenderArea area)
|
public List<ChannelCardEntry> getCardEntries(DisplayCursor cursor, RenderArea area)
|
||||||
{
|
{
|
||||||
SpectralDisplayModel model = getModel();
|
SpectralDisplayModel model = getModel();
|
||||||
|
|
||||||
//Only for the position the mouse rested at - the readout comes back as soon as the mouse moves
|
if(mIndex == null || !mHoverCandidates.get() || model == null || area.width() <= 0)
|
||||||
if(mIndex == null || !mHoverCandidates.get() || !mHoverReady || model == null || !model.hasSource() ||
|
|
||||||
cursor == null || cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY ||
|
|
||||||
area.width() <= 0)
|
|
||||||
{
|
{
|
||||||
return false;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return !getCandidates(cursor.frequency(), getTolerance(model, area)).isEmpty();
|
List<RankedCandidate> candidates = getCandidates(cursor.frequency(), getTolerance(model, area));
|
||||||
|
|
||||||
|
//The playlist channels of the candidates, looked up once per lookup or second, since that copies the playlist
|
||||||
|
if(candidates != mCardCandidates || System.currentTimeMillis() - mCardEntriesTime > 1000)
|
||||||
|
{
|
||||||
|
mCardCandidates = candidates;
|
||||||
|
mCardEntriesTime = System.currentTimeMillis();
|
||||||
|
mCardEntries = createCardEntries(candidates);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mCardEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ChannelCardEntry> createCardEntries(List<RankedCandidate> candidates)
|
||||||
|
{
|
||||||
|
List<ChannelCardEntry> entries = new ArrayList<>();
|
||||||
|
Set<String> listed = new HashSet<>();
|
||||||
|
|
||||||
|
for(RankedCandidate ranked: candidates)
|
||||||
|
{
|
||||||
|
FrequencyCandidate candidate = ranked.candidate();
|
||||||
|
Channel existing = mActions != null ? findChannel(candidate) : null;
|
||||||
|
|
||||||
|
if(existing != null)
|
||||||
|
{
|
||||||
|
entries.add(ChannelMenus.createCardEntry(existing, null, true));
|
||||||
|
}
|
||||||
|
//The same listing in several places (e.g. a county and its agency) is shown once
|
||||||
|
else if(listed.add(candidate.frequencyHz() + "|" + candidate.title() + "|" + candidate.source()))
|
||||||
|
{
|
||||||
|
List<String> details = new ArrayList<>();
|
||||||
|
details.add(describe(ranked));
|
||||||
|
String source = source(candidate);
|
||||||
|
|
||||||
|
if(source != null)
|
||||||
|
{
|
||||||
|
details.add(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
String title = candidate.title() != null ? candidate.title() : "(untitled)";
|
||||||
|
entries.add(new ChannelCardEntry(title, details, State.CANDIDATE, null, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playlist channel that decodes the candidate, or null
|
||||||
|
*/
|
||||||
|
private Channel findChannel(FrequencyCandidate candidate)
|
||||||
|
{
|
||||||
|
if(candidate.isSiteFrequency())
|
||||||
|
{
|
||||||
|
SiteRecord site = mIndex.getSite(candidate.systemId(), candidate.siteId());
|
||||||
|
|
||||||
|
if(site == null || RadioReferencePlaylistActions.getUnsupportedReason(site) != null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RadioReferencePlaylistActions.isRepeaterSite(site) ?
|
||||||
|
mActions.findChannel(List.of(candidate.frequencyHz()),
|
||||||
|
RadioReferencePlaylistActions.getSiteDecoderTypes(site)) : mActions.findSiteChannel(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RadioReferencePlaylistActions.getDecoderType(candidate) != null ?
|
||||||
|
mActions.findConventionalChannel(candidate) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -453,47 +430,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
return Math.max(MIN_TOLERANCE_HZ, Math.round(Math.max(TOLERANCE_PIXELS * hertzPerPixel, model.getBinWidth())));
|
return Math.max(MIN_TOLERANCE_HZ, Math.round(Math.max(TOLERANCE_PIXELS * hertzPerPixel, model.getBinWidth())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Restarts the hover delay each time the mouse moves, and hides the card until it passes
|
|
||||||
*/
|
|
||||||
private void trackHover(DisplayCursor cursor)
|
|
||||||
{
|
|
||||||
if(cursor == null)
|
|
||||||
{
|
|
||||||
if(mHoverSection != null)
|
|
||||||
{
|
|
||||||
mHoverSection = null;
|
|
||||||
mHoverReady = false;
|
|
||||||
getHoverTimer().stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cursor.section() != mHoverSection || cursor.x() != mHoverX || cursor.y() != mHoverY)
|
|
||||||
{
|
|
||||||
mHoverSection = cursor.section();
|
|
||||||
mHoverX = cursor.x();
|
|
||||||
mHoverY = cursor.y();
|
|
||||||
mHoverReady = false;
|
|
||||||
getHoverTimer().playFromStart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private PauseTransition getHoverTimer()
|
|
||||||
{
|
|
||||||
if(mHoverTimer == null)
|
|
||||||
{
|
|
||||||
mHoverTimer = new PauseTransition(HOVER_DELAY);
|
|
||||||
mHoverTimer.setOnFinished(event -> {
|
|
||||||
mHoverReady = true;
|
|
||||||
requestRender();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return mHoverTimer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Candidates for the frequency, looked up again only when the frequency or the tolerance changes
|
* Candidates for the frequency, looked up again only when the frequency or the tolerance changes
|
||||||
*/
|
*/
|
||||||
@@ -504,172 +440,11 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
mResults = mIndex.lookup(frequency, tolerance);
|
mResults = mIndex.lookup(frequency, tolerance);
|
||||||
mResultsFrequency = frequency;
|
mResultsFrequency = frequency;
|
||||||
mResultsTolerance = tolerance;
|
mResultsTolerance = tolerance;
|
||||||
mCard = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mResults;
|
return mResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws the card in place of the cursor readout: beside the mouse and above it, placed like the readout, with the
|
|
||||||
* candidates above the readout lines so the frequency and level stay where the readout showed them. The card
|
|
||||||
* fits the larger side of the mouse and the height of the section, showing as many candidates as fit.
|
|
||||||
*/
|
|
||||||
private void drawCard(GraphicsContext gc, RenderArea area, DisplayCursor cursor, List<RankedCandidate> candidates)
|
|
||||||
{
|
|
||||||
//The level line changes with the mouse height while the candidates don't
|
|
||||||
List<String> readout = CursorReadout.lines(cursor, area, getModel());
|
|
||||||
double readoutWidth = 0;
|
|
||||||
|
|
||||||
for(String line: readout)
|
|
||||||
{
|
|
||||||
readoutWidth = Math.max(readoutWidth, measure(line, FONT));
|
|
||||||
}
|
|
||||||
|
|
||||||
double room = Math.max(area.width() - cursor.x(), cursor.x()) - CursorReadout.GAP_X - EDGE_MARGIN;
|
|
||||||
double maxTextWidth = Math.max(readoutWidth, Math.min(MAX_TEXT_WIDTH, room - (PADDING_X * 2)));
|
|
||||||
//Above the mouse, so the readout lines stay where the readout showed them, when a candidate fits there
|
|
||||||
double above = cursor.y() - CursorReadout.GAP_Y;
|
|
||||||
double maxHeight = above >= cardHeight(5, 1, true, readout.size()) ? above : area.plotHeight() - EDGE_MARGIN;
|
|
||||||
|
|
||||||
if(mCard == null || mCard.maxTextWidth() != maxTextWidth || mCard.maxHeight() != maxHeight ||
|
|
||||||
mCard.readoutLines() != readout.size())
|
|
||||||
{
|
|
||||||
mCard = createCard(candidates, maxTextWidth, maxHeight, readout.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
Card card = mCard;
|
|
||||||
SpectralDisplayTheme theme = getSpectralDisplay().getTheme();
|
|
||||||
double width = Math.max(card.textWidth(), readoutWidth) + (PADDING_X * 2);
|
|
||||||
double height = cardHeight(card.lineCount(), card.entries().size(), card.more() != null, readout.size());
|
|
||||||
double x = Math.max(0, CursorReadout.x(cursor, width, area));
|
|
||||||
double y = CursorReadout.y(cursor, height, area);
|
|
||||||
|
|
||||||
gc.setFill(theme.getBackground(0.92));
|
|
||||||
gc.fillRoundRect(x, y, width, height, 8, 8);
|
|
||||||
gc.setStroke(opaque(theme.getLine()));
|
|
||||||
gc.setLineWidth(1.0);
|
|
||||||
gc.strokeRoundRect(Math.floor(x) + 0.5, Math.floor(y) + 0.5, width, height, 8, 8);
|
|
||||||
gc.setTextAlign(TextAlignment.LEFT);
|
|
||||||
gc.setTextBaseline(VPos.TOP);
|
|
||||||
|
|
||||||
double textX = x + PADDING_X;
|
|
||||||
double lineY = y + PADDING;
|
|
||||||
gc.setFill(theme.getCursor());
|
|
||||||
gc.setFont(TITLE_FONT);
|
|
||||||
gc.fillText(HEADER, textX, lineY);
|
|
||||||
lineY += mTextHeight + GAP;
|
|
||||||
|
|
||||||
for(List<String> lines: card.entries())
|
|
||||||
{
|
|
||||||
gc.setFill(theme.getCursor());
|
|
||||||
gc.setFont(TITLE_FONT);
|
|
||||||
gc.fillText(lines.get(0), textX, lineY);
|
|
||||||
lineY += mTextHeight;
|
|
||||||
gc.setFill(opaque(theme.getLine()));
|
|
||||||
gc.setFont(FONT);
|
|
||||||
|
|
||||||
for(int line = 1; line < lines.size(); line++)
|
|
||||||
{
|
|
||||||
gc.fillText(lines.get(line), textX, lineY);
|
|
||||||
lineY += mTextHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
lineY += GAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(card.more() != null)
|
|
||||||
{
|
|
||||||
gc.setFill(opaque(theme.getLine()));
|
|
||||||
gc.setFont(FONT);
|
|
||||||
gc.fillText(card.more(), textX, lineY);
|
|
||||||
lineY += mTextHeight + GAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
//The readout lines, separated from the candidates, in the readout's style
|
|
||||||
double separator = Math.floor(lineY - (GAP / 2.0)) + 0.5;
|
|
||||||
gc.setStroke(theme.getLine(0.5));
|
|
||||||
gc.strokeLine(textX, separator, x + width - PADDING_X, separator);
|
|
||||||
gc.setFill(theme.getCursor());
|
|
||||||
gc.setFont(FONT);
|
|
||||||
|
|
||||||
for(String line: readout)
|
|
||||||
{
|
|
||||||
gc.fillText(line, textX, lineY);
|
|
||||||
lineY += mTextHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Height of a card with the lines
|
|
||||||
* @param lineCount of the header, candidate and more lines
|
|
||||||
* @param entries number of candidates
|
|
||||||
* @param more true when the card has a more line
|
|
||||||
* @param readoutLines number of readout lines
|
|
||||||
*/
|
|
||||||
private double cardHeight(int lineCount, int entries, boolean more, int readoutLines)
|
|
||||||
{
|
|
||||||
int gaps = 1 + entries + (more ? 1 : 0);
|
|
||||||
return ((lineCount + readoutLines) * mTextHeight) + (gaps * GAP) + PADDING + READOUT_PADDING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Card text for as many candidates as fit the height: each candidate's title, details and source, shortened to
|
|
||||||
* the width
|
|
||||||
*/
|
|
||||||
private Card createCard(List<RankedCandidate> candidates, double maxTextWidth, double maxHeight,
|
|
||||||
int readoutLines)
|
|
||||||
{
|
|
||||||
int limit = Math.min(candidates.size(), MAX_CANDIDATES);
|
|
||||||
List<List<String>> entries = new ArrayList<>();
|
|
||||||
double textWidth = measure(HEADER, TITLE_FONT);
|
|
||||||
int lineCount = 1;
|
|
||||||
|
|
||||||
for(int index = 0; index < limit; index++)
|
|
||||||
{
|
|
||||||
RankedCandidate candidate = candidates.get(index);
|
|
||||||
List<String> lines = new ArrayList<>();
|
|
||||||
String title = candidate.candidate().title() != null ? candidate.candidate().title() : "(untitled)";
|
|
||||||
lines.add(fit(title, TITLE_FONT, maxTextWidth));
|
|
||||||
lines.add(fit(describe(candidate), FONT, maxTextWidth));
|
|
||||||
String source = source(candidate.candidate());
|
|
||||||
|
|
||||||
if(source != null)
|
|
||||||
{
|
|
||||||
lines.add(fit(source, FONT, maxTextWidth));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Keep room for the more line when candidates are left out
|
|
||||||
boolean more = index + 1 < candidates.size();
|
|
||||||
|
|
||||||
if(!entries.isEmpty() && cardHeight(lineCount + lines.size() + (more ? 1 : 0), entries.size() + 1, more,
|
|
||||||
readoutLines) > maxHeight)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
textWidth = Math.max(textWidth, measure(lines.get(0), TITLE_FONT));
|
|
||||||
|
|
||||||
for(int line = 1; line < lines.size(); line++)
|
|
||||||
{
|
|
||||||
textWidth = Math.max(textWidth, measure(lines.get(line), FONT));
|
|
||||||
}
|
|
||||||
|
|
||||||
lineCount += lines.size();
|
|
||||||
entries.add(lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
String more = candidates.size() > entries.size() ? "+ " + (candidates.size() - entries.size()) + " more" : null;
|
|
||||||
|
|
||||||
if(more != null)
|
|
||||||
{
|
|
||||||
textWidth = Math.max(textWidth, measure(more, FONT));
|
|
||||||
lineCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Card(entries, more, textWidth, lineCount, maxTextWidth, maxHeight, readoutLines);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frequency, mode or use, tone, encryption and distance of the candidate
|
* Frequency, mode or use, tone, encryption and distance of the candidate
|
||||||
*/
|
*/
|
||||||
@@ -691,35 +466,6 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
return join(alphaTag, candidate.source());
|
return join(alphaTag, candidate.source());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Text shortened with an ellipsis to fit the width
|
|
||||||
*/
|
|
||||||
private String fit(String text, Font font, double maxWidth)
|
|
||||||
{
|
|
||||||
if(measure(text, font) <= maxWidth)
|
|
||||||
{
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
int length = text.length();
|
|
||||||
|
|
||||||
while(length > 1 && measure(text.substring(0, length) + "…", font) > maxWidth)
|
|
||||||
{
|
|
||||||
length--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return text.substring(0, length) + "…";
|
|
||||||
}
|
|
||||||
|
|
||||||
private double measure(String text, Font font)
|
|
||||||
{
|
|
||||||
mMeasure.setFont(font);
|
|
||||||
mMeasure.setText(text);
|
|
||||||
double width = mMeasure.getLayoutBounds().getWidth();
|
|
||||||
mMeasure.setFont(FONT);
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String join(String... values)
|
private static String join(String... values)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@@ -739,9 +485,4 @@ public class RadioReferenceLayer extends SpectralDisplayLayer
|
|||||||
|
|
||||||
return sb.isEmpty() ? null : sb.toString();
|
return sb.isEmpty() ? null : sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Color opaque(Color color)
|
|
||||||
{
|
|
||||||
return Color.color(color.getRed(), color.getGreen(), color.getBlue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Talker alias cache manager. Collects observed talker aliases and inserts them into an identifier collection when
|
* Talker alias cache manager. Collects observed talker aliases and inserts them into an identifier collection when
|
||||||
@@ -41,6 +42,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class TalkerAliasManager
|
public class TalkerAliasManager
|
||||||
{
|
{
|
||||||
private Map<Integer,TalkerAliasIdentifier> mAliasMap = new ConcurrentHashMap<>();
|
private Map<Integer,TalkerAliasIdentifier> mAliasMap = new ConcurrentHashMap<>();
|
||||||
|
private volatile BiConsumer<RadioIdentifier,TalkerAliasIdentifier> mTalkerAliasListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance
|
* Constructs an instance
|
||||||
@@ -49,6 +51,16 @@ public class TalkerAliasManager
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an optional listener to receive each talker alias that is assigned to a radio, e.g. to automatically add
|
||||||
|
* talker aliases to an alias list. The listener is invoked on the calling decoder thread.
|
||||||
|
* @param listener to receive radio and talker alias updates, or null to clear the listener.
|
||||||
|
*/
|
||||||
|
public void setTalkerAliasListener(BiConsumer<RadioIdentifier,TalkerAliasIdentifier> listener)
|
||||||
|
{
|
||||||
|
mTalkerAliasListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the alias for the radio identifier
|
* Updates the alias for the radio identifier
|
||||||
*
|
*
|
||||||
@@ -60,6 +72,13 @@ public class TalkerAliasManager
|
|||||||
if(identifier.getRole() == Role.FROM)
|
if(identifier.getRole() == Role.FROM)
|
||||||
{
|
{
|
||||||
mAliasMap.put(identifier.getValue(), alias);
|
mAliasMap.put(identifier.getValue(), alias);
|
||||||
|
|
||||||
|
BiConsumer<RadioIdentifier,TalkerAliasIdentifier> listener = mTalkerAliasListener;
|
||||||
|
|
||||||
|
if(listener != null && alias != null)
|
||||||
|
{
|
||||||
|
listener.accept(identifier, alias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package io.github.dsheirer.module.decode;
|
|||||||
|
|
||||||
import io.github.dsheirer.alias.AliasList;
|
import io.github.dsheirer.alias.AliasList;
|
||||||
import io.github.dsheirer.alias.AliasModel;
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
|
import io.github.dsheirer.alias.TalkerAliasAutoAdder;
|
||||||
import io.github.dsheirer.alias.action.AliasActionManager;
|
import io.github.dsheirer.alias.action.AliasActionManager;
|
||||||
import io.github.dsheirer.audio.*;
|
import io.github.dsheirer.audio.*;
|
||||||
import io.github.dsheirer.audio.codec.mbe.JmbeAudioModule;
|
import io.github.dsheirer.audio.codec.mbe.JmbeAudioModule;
|
||||||
@@ -210,9 +211,37 @@ public class DecoderFactory
|
|||||||
throw new IllegalArgumentException("Unknown decoder type [" + decodeConfig.getDecoderType().toString() + "]");
|
throw new IllegalArgumentException("Unknown decoder type [" + decodeConfig.getDecoderType().toString() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureTalkerAliasAutoAdd(channel, modules, aliasModel);
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the traffic channel manager of a standard (control) channel to automatically add talker aliases to
|
||||||
|
* the channel's alias list, when the channel is configured for it. Traffic channels share the talker alias manager
|
||||||
|
* of their control channel, so they use the control channel's setting.
|
||||||
|
* @param channel configuration
|
||||||
|
* @param modules for the channel
|
||||||
|
* @param aliasModel to add aliases to
|
||||||
|
*/
|
||||||
|
private static void configureTalkerAliasAutoAdd(Channel channel, List<Module> modules, AliasModel aliasModel)
|
||||||
|
{
|
||||||
|
if(channel.isStandardChannel() && channel.isAutoAddTalkerAliases() &&
|
||||||
|
channel.getDecodeConfiguration().getDecoderType().providesTalkerAlias() &&
|
||||||
|
channel.getAliasListName() != null && !channel.getAliasListName().isEmpty())
|
||||||
|
{
|
||||||
|
TalkerAliasAutoAdder autoAdder = new TalkerAliasAutoAdder(aliasModel, channel.getAliasListName());
|
||||||
|
|
||||||
|
for(Module module: modules)
|
||||||
|
{
|
||||||
|
if(module instanceof TrafficChannelManager tcm && tcm.getTalkerAliasManager() != null)
|
||||||
|
{
|
||||||
|
tcm.getTalkerAliasManager().setTalkerAliasListener(autoAdder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates decoder modules for APCO-25 Phase 2 decoder
|
* Creates decoder modules for APCO-25 Phase 2 decoder
|
||||||
* @param channel configuration
|
* @param channel configuration
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ public enum DecoderType
|
|||||||
*/
|
*/
|
||||||
public static final EnumSet<DecoderType> MBE_AUDIO_CODEC_DECODERS = EnumSet.of(DMR, NXDN, P25_PHASE1, P25_PHASE2);
|
public static final EnumSet<DecoderType> MBE_AUDIO_CODEC_DECODERS = EnumSet.of(DMR, NXDN, P25_PHASE1, P25_PHASE2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decoders that produce talker aliases
|
||||||
|
*/
|
||||||
|
public static final EnumSet<DecoderType> TALKER_ALIAS_DECODERS = EnumSet.of(DMR, NXDN, P25_PHASE1, P25_PHASE2);
|
||||||
|
|
||||||
public Protocol getProtocol()
|
public Protocol getProtocol()
|
||||||
{
|
{
|
||||||
return mProtocol;
|
return mProtocol;
|
||||||
@@ -114,4 +119,12 @@ public enum DecoderType
|
|||||||
{
|
{
|
||||||
return MBE_AUDIO_CODEC_DECODERS.contains(this);
|
return MBE_AUDIO_CODEC_DECODERS.contains(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the decoder type produces talker aliases
|
||||||
|
*/
|
||||||
|
public boolean providesTalkerAlias()
|
||||||
|
{
|
||||||
|
return TALKER_ALIAS_DECODERS.contains(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ public class DMRTrafficChannelManager extends TrafficChannelManager implements I
|
|||||||
/**
|
/**
|
||||||
* Talker alias manager
|
* Talker alias manager
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public TalkerAliasManager getTalkerAliasManager()
|
public TalkerAliasManager getTalkerAliasManager()
|
||||||
{
|
{
|
||||||
return mTalkerAliasManager;
|
return mTalkerAliasManager;
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ public class NXDNTrafficChannelManager extends TrafficChannelManager implements
|
|||||||
/**
|
/**
|
||||||
* Talker alias manager
|
* Talker alias manager
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public TalkerAliasManager getTalkerAliasManager()
|
public TalkerAliasManager getTalkerAliasManager()
|
||||||
{
|
{
|
||||||
return mTalkerAliasManager;
|
return mTalkerAliasManager;
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ public class P25TrafficChannelManager extends TrafficChannelManager implements I
|
|||||||
* Talker alias manager
|
* Talker alias manager
|
||||||
* @return manager
|
* @return manager
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public TalkerAliasManager getTalkerAliasManager()
|
public TalkerAliasManager getTalkerAliasManager()
|
||||||
{
|
{
|
||||||
return mTalkerAliasManager;
|
return mTalkerAliasManager;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
package io.github.dsheirer.module.decode.traffic;
|
package io.github.dsheirer.module.decode.traffic;
|
||||||
|
|
||||||
import io.github.dsheirer.controller.channel.Channel;
|
import io.github.dsheirer.controller.channel.Channel;
|
||||||
|
import io.github.dsheirer.identifier.alias.TalkerAliasManager;
|
||||||
import io.github.dsheirer.module.Module;
|
import io.github.dsheirer.module.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,6 +37,15 @@ public abstract class TrafficChannelManager extends Module
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Talker alias manager shared by the control and traffic channels of the system.
|
||||||
|
* @return talker alias manager, or null if the protocol doesn't have talker aliases.
|
||||||
|
*/
|
||||||
|
public TalkerAliasManager getTalkerAliasManager()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current control frequency
|
* Current control frequency
|
||||||
* @return frequency in hertz
|
* @return frequency in hertz
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||||||
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import io.github.dsheirer.alias.Alias;
|
import io.github.dsheirer.alias.Alias;
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
import io.github.dsheirer.alias.AliasModel;
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
import io.github.dsheirer.audio.broadcast.BroadcastModel;
|
import io.github.dsheirer.audio.broadcast.BroadcastModel;
|
||||||
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
||||||
@@ -39,6 +40,7 @@ import io.github.dsheirer.module.log.EventLogManager;
|
|||||||
import io.github.dsheirer.preference.UserPreferences;
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
import io.github.dsheirer.preference.playlist.PlaylistPreference;
|
import io.github.dsheirer.preference.playlist.PlaylistPreference;
|
||||||
import io.github.dsheirer.sample.Listener;
|
import io.github.dsheirer.sample.Listener;
|
||||||
|
import io.github.dsheirer.service.radioreference.AliasListSynchronizer;
|
||||||
import io.github.dsheirer.service.radioreference.RadioReference;
|
import io.github.dsheirer.service.radioreference.RadioReference;
|
||||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||||
import io.github.dsheirer.util.ThreadPool;
|
import io.github.dsheirer.util.ThreadPool;
|
||||||
@@ -76,6 +78,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
private TunerManager mTunerManager;
|
private TunerManager mTunerManager;
|
||||||
private UserPreferences mUserPreferences;
|
private UserPreferences mUserPreferences;
|
||||||
private RadioReference mRadioReference;
|
private RadioReference mRadioReference;
|
||||||
|
private AliasListSynchronizer mAliasListSynchronizer;
|
||||||
private AtomicBoolean mPlaylistSavePending = new AtomicBoolean();
|
private AtomicBoolean mPlaylistSavePending = new AtomicBoolean();
|
||||||
private ScheduledFuture<?> mPlaylistSaveFuture;
|
private ScheduledFuture<?> mPlaylistSaveFuture;
|
||||||
private boolean mPlaylistLoading = false;
|
private boolean mPlaylistLoading = false;
|
||||||
@@ -103,6 +106,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
|
|
||||||
mBroadcastModel = new BroadcastModel(mAliasModel, mIconModel, userPreferences);
|
mBroadcastModel = new BroadcastModel(mAliasModel, mIconModel, userPreferences);
|
||||||
mRadioReference = new RadioReference(mUserPreferences);
|
mRadioReference = new RadioReference(mUserPreferences);
|
||||||
|
mAliasListSynchronizer = new AliasListSynchronizer(mAliasModel, mRadioReference, mUserPreferences);
|
||||||
|
|
||||||
mChannelModel = new ChannelModel(mAliasModel);
|
mChannelModel = new ChannelModel(mAliasModel);
|
||||||
mChannelProcessingManager = new ChannelProcessingManager(mChannelMapModel, eventLogManager, mTunerManager,
|
mChannelProcessingManager = new ChannelProcessingManager(mChannelMapModel, eventLogManager, mTunerManager,
|
||||||
@@ -120,6 +124,8 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
mChannelModel.addListener(this);
|
mChannelModel.addListener(this);
|
||||||
|
|
||||||
mAliasModel.aliasList().addListener((ListChangeListener<Alias>)c -> schedulePlaylistSave());
|
mAliasModel.aliasList().addListener((ListChangeListener<Alias>)c -> schedulePlaylistSave());
|
||||||
|
mAliasModel.aliasListConfigurations()
|
||||||
|
.addListener((ListChangeListener<AliasListConfiguration>)c -> schedulePlaylistSave());
|
||||||
|
|
||||||
mChannelMapModel.getChannelMaps().addListener((ListChangeListener<ChannelMap>)c -> schedulePlaylistSave());
|
mChannelMapModel.getChannelMaps().addListener((ListChangeListener<ChannelMap>)c -> schedulePlaylistSave());
|
||||||
|
|
||||||
@@ -248,6 +254,14 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
return mBroadcastModel;
|
return mBroadcastModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronizer for alias lists that track a Radio Reference system.
|
||||||
|
*/
|
||||||
|
public AliasListSynchronizer getAliasListSynchronizer()
|
||||||
|
{
|
||||||
|
return mAliasListSynchronizer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Channel Map model managed by this playlist manager
|
* Channel Map model managed by this playlist manager
|
||||||
*/
|
*/
|
||||||
@@ -264,6 +278,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
{
|
{
|
||||||
PlaylistV2 playlist = load();
|
PlaylistV2 playlist = load();
|
||||||
transferPlaylistToModels(playlist);
|
transferPlaylistToModels(playlist);
|
||||||
|
mAliasListSynchronizer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -401,6 +416,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
mPlaylistLoading = true;
|
mPlaylistLoading = true;
|
||||||
|
|
||||||
mAliasModel.addAliases(playlist.getAliases());
|
mAliasModel.addAliases(playlist.getAliases());
|
||||||
|
mAliasModel.addAliasListConfigurations(playlist.getAliasListConfigurations());
|
||||||
|
|
||||||
|
|
||||||
mBroadcastModel.addBroadcastConfigurations(playlist.getBroadcastConfigurations());
|
mBroadcastModel.addBroadcastConfigurations(playlist.getBroadcastConfigurations());
|
||||||
@@ -445,6 +461,7 @@ public class PlaylistManager implements Listener<ChannelEvent>
|
|||||||
PlaylistV2 playlist = new PlaylistV2();
|
PlaylistV2 playlist = new PlaylistV2();
|
||||||
|
|
||||||
playlist.setAliases(new ArrayList(mAliasModel.getAliases()));
|
playlist.setAliases(new ArrayList(mAliasModel.getAliases()));
|
||||||
|
playlist.setAliasListConfigurations(new ArrayList<>(mAliasModel.aliasListConfigurations()));
|
||||||
playlist.setBroadcastConfigurations(new ArrayList(mBroadcastModel.getBroadcastConfigurations()));
|
playlist.setBroadcastConfigurations(new ArrayList(mBroadcastModel.getBroadcastConfigurations()));
|
||||||
playlist.setChannels(new ArrayList(mChannelModel.getChannels()));
|
playlist.setChannels(new ArrayList(mChannelModel.getChannels()));
|
||||||
playlist.setChannelMaps(new ArrayList(mChannelMapModel.getChannelMaps()));
|
playlist.setChannelMaps(new ArrayList(mChannelMapModel.getChannelMaps()));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package io.github.dsheirer.playlist;
|
|||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||||
import io.github.dsheirer.alias.Alias;
|
import io.github.dsheirer.alias.Alias;
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
import io.github.dsheirer.audio.broadcast.BroadcastConfiguration;
|
import io.github.dsheirer.audio.broadcast.BroadcastConfiguration;
|
||||||
import io.github.dsheirer.controller.channel.Channel;
|
import io.github.dsheirer.controller.channel.Channel;
|
||||||
import io.github.dsheirer.controller.channel.map.ChannelMap;
|
import io.github.dsheirer.controller.channel.map.ChannelMap;
|
||||||
@@ -36,6 +37,7 @@ public class PlaylistV2
|
|||||||
{
|
{
|
||||||
private int mVersion = PlaylistManager.PLAYLIST_CURRENT_VERSION;
|
private int mVersion = PlaylistManager.PLAYLIST_CURRENT_VERSION;
|
||||||
private List<Alias> mAliases = new ArrayList<>();
|
private List<Alias> mAliases = new ArrayList<>();
|
||||||
|
private List<AliasListConfiguration> mAliasListConfigurations = new ArrayList<>();
|
||||||
private List<BroadcastConfiguration> mBroadcastConfigurations = new ArrayList<>();
|
private List<BroadcastConfiguration> mBroadcastConfigurations = new ArrayList<>();
|
||||||
private List<Channel> mChannels = new ArrayList<>();
|
private List<Channel> mChannels = new ArrayList<>();
|
||||||
private List<ChannelMap> mChannelMaps = new ArrayList<>();
|
private List<ChannelMap> mChannelMaps = new ArrayList<>();
|
||||||
@@ -72,6 +74,20 @@ public class PlaylistV2
|
|||||||
mAliases = aliases;
|
mAliases = aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias list settings, like Radio Reference system tracking. Older playlists don't have these.
|
||||||
|
*/
|
||||||
|
@JacksonXmlProperty(isAttribute = false, localName = "alias_list")
|
||||||
|
public List<AliasListConfiguration> getAliasListConfigurations()
|
||||||
|
{
|
||||||
|
return mAliasListConfigurations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAliasListConfigurations(List<AliasListConfiguration> configurations)
|
||||||
|
{
|
||||||
|
mAliasListConfigurations = configurations != null ? configurations : new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
@JacksonXmlProperty(isAttribute = false, localName = "channel")
|
@JacksonXmlProperty(isAttribute = false, localName = "channel")
|
||||||
public List<Channel> getChannels()
|
public List<Channel> getChannels()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.preference.radioreference;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How often alias lists that track a Radio Reference system check the system for changes.
|
||||||
|
*/
|
||||||
|
public enum AliasListUpdateInterval
|
||||||
|
{
|
||||||
|
TWELVE_HOURS("Every 12 Hours", Duration.ofHours(12)),
|
||||||
|
DAILY("Every Day", Duration.ofDays(1)),
|
||||||
|
WEEKLY("Once a Week", Duration.ofDays(7)),
|
||||||
|
MONTHLY("Once a Month", Duration.ofDays(30));
|
||||||
|
|
||||||
|
private final String mLabel;
|
||||||
|
private final Duration mInterval;
|
||||||
|
|
||||||
|
AliasListUpdateInterval(String label, Duration interval)
|
||||||
|
{
|
||||||
|
mLabel = label;
|
||||||
|
mInterval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time between checks
|
||||||
|
*/
|
||||||
|
public Duration getInterval()
|
||||||
|
{
|
||||||
|
return mInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return mLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ public class RadioReferencePreference extends Preference
|
|||||||
private static final String ENCRYPTED_TALKGROUP_DO_NOT_MONITOR = "encrypted.talkgroup.import.do.not.monitor";
|
private static final String ENCRYPTED_TALKGROUP_DO_NOT_MONITOR = "encrypted.talkgroup.import.do.not.monitor";
|
||||||
private static final String CREATE_AND_SHOW_CHANNEL_EDITOR = "create.and.show.channel.editor";
|
private static final String CREATE_AND_SHOW_CHANNEL_EDITOR = "create.and.show.channel.editor";
|
||||||
private static final String LOCATION = "location";
|
private static final String LOCATION = "location";
|
||||||
|
private static final String ALIAS_LIST_UPDATE_INTERVAL = "alias.list.update.interval";
|
||||||
private static final String LOCATION_LABEL = "location.label";
|
private static final String LOCATION_LABEL = "location.label";
|
||||||
|
|
||||||
private String mUserName;
|
private String mUserName;
|
||||||
@@ -71,6 +72,7 @@ public class RadioReferencePreference extends Preference
|
|||||||
private Boolean mShowChannelEditorCounty;
|
private Boolean mShowChannelEditorCounty;
|
||||||
private Boolean mEncryptedTalkgroupImport;
|
private Boolean mEncryptedTalkgroupImport;
|
||||||
private Boolean mCreateAndShowChannelEditor;
|
private Boolean mCreateAndShowChannelEditor;
|
||||||
|
private AliasListUpdateInterval mAliasListUpdateInterval;
|
||||||
private int mPreferredCountryId = INVALID_ID;
|
private int mPreferredCountryId = INVALID_ID;
|
||||||
private int mPreferredStateId = INVALID_ID;
|
private int mPreferredStateId = INVALID_ID;
|
||||||
private int mPreferredCountyId = INVALID_ID;
|
private int mPreferredCountyId = INVALID_ID;
|
||||||
@@ -494,6 +496,41 @@ public class RadioReferencePreference extends Preference
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How often alias lists that track a Radio Reference system check the system for changes.
|
||||||
|
*/
|
||||||
|
public AliasListUpdateInterval getAliasListUpdateInterval()
|
||||||
|
{
|
||||||
|
if(mAliasListUpdateInterval == null)
|
||||||
|
{
|
||||||
|
String name = mPreferences.get(ALIAS_LIST_UPDATE_INTERVAL, AliasListUpdateInterval.DAILY.name());
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mAliasListUpdateInterval = AliasListUpdateInterval.valueOf(name);
|
||||||
|
}
|
||||||
|
catch(IllegalArgumentException iae)
|
||||||
|
{
|
||||||
|
mAliasListUpdateInterval = AliasListUpdateInterval.DAILY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mAliasListUpdateInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets how often alias lists that track a Radio Reference system check the system for changes.
|
||||||
|
*/
|
||||||
|
public void setAliasListUpdateInterval(AliasListUpdateInterval interval)
|
||||||
|
{
|
||||||
|
if(interval != null)
|
||||||
|
{
|
||||||
|
mAliasListUpdateInterval = interval;
|
||||||
|
mPreferences.put(ALIAS_LIST_UPDATE_INTERVAL, interval.name());
|
||||||
|
notifyPreferenceUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if should show channel editor after trunked channel configuration create
|
* Indicates if should show channel editor after trunked channel configuration create
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,510 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.service.radioreference;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import io.github.dsheirer.alias.Alias;
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
|
import io.github.dsheirer.alias.id.AliasID;
|
||||||
|
import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceDecoder;
|
||||||
|
import io.github.dsheirer.gui.playlist.radioreference.TalkgroupEncryption;
|
||||||
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
|
import io.github.dsheirer.preference.radioreference.AliasListUpdateInterval;
|
||||||
|
import io.github.dsheirer.rrapi.RadioReferenceException;
|
||||||
|
import io.github.dsheirer.rrapi.RadioReferenceService;
|
||||||
|
import io.github.dsheirer.rrapi.type.System;
|
||||||
|
import io.github.dsheirer.rrapi.type.SystemInformation;
|
||||||
|
import io.github.dsheirer.rrapi.type.Talkgroup;
|
||||||
|
import io.github.dsheirer.rrapi.type.TalkgroupCategory;
|
||||||
|
import io.github.dsheirer.util.ThreadPool;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keeps alias lists that track a Radio Reference system up to date. Checks each tracked system on the interval from
|
||||||
|
* the user's Radio Reference preferences, records the system's Radio Reference last updated timestamp, and when the
|
||||||
|
* alias list is set to auto-update and the system changed, adds an alias for each new talkgroup and updates the name
|
||||||
|
* and group of aliases for talkgroups that changed on Radio Reference since the last synchronization.
|
||||||
|
*
|
||||||
|
* Aliases for talkgroups that are removed from Radio Reference are left in place, and alias settings other than the
|
||||||
|
* name and group (color, icon, priority, record, stream, etc.) are never changed.
|
||||||
|
*/
|
||||||
|
public class AliasListSynchronizer
|
||||||
|
{
|
||||||
|
private static final Logger mLog = LoggerFactory.getLogger(AliasListSynchronizer.class);
|
||||||
|
private static final long CHECK_PERIOD_MINUTES = 30;
|
||||||
|
private static final long INITIAL_DELAY_MINUTES = 2;
|
||||||
|
private static final long RETRY_AFTER_FAILURE_MS = TimeUnit.HOURS.toMillis(1);
|
||||||
|
|
||||||
|
private final AliasModel mAliasModel;
|
||||||
|
private final RadioReference mRadioReference;
|
||||||
|
private final UserPreferences mUserPreferences;
|
||||||
|
private final Object mSynchronizationLock = new Object();
|
||||||
|
private final Map<Integer,Long> mFailedAttempts = new HashMap<>();
|
||||||
|
private RadioReferenceDecoder mRadioReferenceDecoder;
|
||||||
|
private ScheduledFuture<?> mScheduledCheck;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance
|
||||||
|
* @param aliasModel containing aliases and alias list configurations
|
||||||
|
* @param radioReference for access to the web service
|
||||||
|
* @param userPreferences for the update interval and encrypted talkgroup import preferences
|
||||||
|
*/
|
||||||
|
public AliasListSynchronizer(AliasModel aliasModel, RadioReference radioReference, UserPreferences userPreferences)
|
||||||
|
{
|
||||||
|
mAliasModel = aliasModel;
|
||||||
|
mRadioReference = radioReference;
|
||||||
|
mUserPreferences = userPreferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts periodic checks of tracked alias lists.
|
||||||
|
*/
|
||||||
|
public synchronized void start()
|
||||||
|
{
|
||||||
|
if(mScheduledCheck == null)
|
||||||
|
{
|
||||||
|
mScheduledCheck = ThreadPool.SCHEDULED.scheduleAtFixedRate(this::checkDueAliasLists,
|
||||||
|
INITIAL_DELAY_MINUTES, CHECK_PERIOD_MINUTES, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops periodic checks.
|
||||||
|
*/
|
||||||
|
public synchronized void stop()
|
||||||
|
{
|
||||||
|
if(mScheduledCheck != null)
|
||||||
|
{
|
||||||
|
mScheduledCheck.cancel(false);
|
||||||
|
mScheduledCheck = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks each tracked alias list whose last check is older than the preferred update interval. Runs on a
|
||||||
|
* scheduler thread.
|
||||||
|
*/
|
||||||
|
private void checkDueAliasLists()
|
||||||
|
{
|
||||||
|
if(!mUserPreferences.getRadioReferencePreference().hasStoredCredentials())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AliasListUpdateInterval interval = mUserPreferences.getRadioReferencePreference().getAliasListUpdateInterval();
|
||||||
|
long now = java.lang.System.currentTimeMillis();
|
||||||
|
|
||||||
|
for(AliasListConfiguration configuration: getTrackedConfigurations())
|
||||||
|
{
|
||||||
|
boolean due = now - configuration.getLastChecked() >= interval.getInterval().toMillis();
|
||||||
|
|
||||||
|
Long failed;
|
||||||
|
synchronized(mFailedAttempts)
|
||||||
|
{
|
||||||
|
failed = mFailedAttempts.get(configuration.getRadioReferenceSystemId());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean retryWait = failed != null && now - failed < RETRY_AFTER_FAILURE_MS;
|
||||||
|
|
||||||
|
if(due && !retryWait)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
synchronize(configuration, false).join();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
mLog.warn("Unable to check Radio Reference system [" + configuration.getRadioReferenceSystemId() +
|
||||||
|
"] for alias list [" + configuration.getName() + "] - " + getMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snapshot of the alias list configurations that track a Radio Reference system.
|
||||||
|
*/
|
||||||
|
private List<AliasListConfiguration> getTrackedConfigurations()
|
||||||
|
{
|
||||||
|
List<AliasListConfiguration> tracked = new ArrayList<>();
|
||||||
|
|
||||||
|
//The configuration list is modified on the FX thread, so retry on a concurrent change
|
||||||
|
for(int attempt = 0; attempt < 3; attempt++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tracked.clear();
|
||||||
|
|
||||||
|
for(AliasListConfiguration configuration: new ArrayList<>(mAliasModel.aliasListConfigurations()))
|
||||||
|
{
|
||||||
|
if(configuration.isTrackingRadioReferenceSystem())
|
||||||
|
{
|
||||||
|
tracked.add(configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tracked;
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
//Try again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tracked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes the alias list now: reads the current system and talkgroups from Radio Reference and adds or updates
|
||||||
|
* aliases, regardless of the alias list's auto-update setting.
|
||||||
|
* @param configuration of a tracked alias list
|
||||||
|
* @return future result, completed after the aliases are updated on the FX thread
|
||||||
|
*/
|
||||||
|
public CompletableFuture<Result> refresh(AliasListConfiguration configuration)
|
||||||
|
{
|
||||||
|
return synchronize(configuration, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the tracked system and, when forced or when the alias list auto-updates and the system changed,
|
||||||
|
* synchronizes the talkgroup aliases.
|
||||||
|
* @param configuration of the tracked alias list
|
||||||
|
* @param force true to synchronize regardless of the auto-update setting or the last updated timestamps
|
||||||
|
* @return future result
|
||||||
|
*/
|
||||||
|
private CompletableFuture<Result> synchronize(AliasListConfiguration configuration, boolean force)
|
||||||
|
{
|
||||||
|
CompletableFuture<Result> future = new CompletableFuture<>();
|
||||||
|
|
||||||
|
if(configuration == null || !configuration.isTrackingRadioReferenceSystem())
|
||||||
|
{
|
||||||
|
future.completeExceptionally(new IllegalArgumentException("Alias list doesn't track a Radio Reference system"));
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadPool.CACHED.execute(() -> {
|
||||||
|
//One synchronization at a time so that a manual refresh and a scheduled check can't both add aliases
|
||||||
|
synchronized(mSynchronizationLock)
|
||||||
|
{
|
||||||
|
int systemId = configuration.getRadioReferenceSystemId();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RadioReferenceService service = mRadioReference.getService();
|
||||||
|
|
||||||
|
if(service instanceof CachingRadioReferenceService caching)
|
||||||
|
{
|
||||||
|
caching.invalidateSystem(systemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemInformation systemInformation = service.getSystemInformation(systemId);
|
||||||
|
|
||||||
|
if(systemInformation == null)
|
||||||
|
{
|
||||||
|
throw new RadioReferenceException("Radio Reference didn't provide system [" + systemId + "]");
|
||||||
|
}
|
||||||
|
|
||||||
|
long lastUpdated = getTime(systemInformation.getLastUpdated());
|
||||||
|
boolean changed = lastUpdated > configuration.getSynchronizedLastUpdated();
|
||||||
|
boolean synchronize = force || (configuration.isAutoUpdate() && changed);
|
||||||
|
|
||||||
|
List<Talkgroup> talkgroups = null;
|
||||||
|
Map<Integer,String> categoryNames = new HashMap<>();
|
||||||
|
System system = null;
|
||||||
|
RadioReferenceDecoder decoder = null;
|
||||||
|
|
||||||
|
if(synchronize)
|
||||||
|
{
|
||||||
|
decoder = getRadioReferenceDecoder();
|
||||||
|
system = toSystem(systemId, systemInformation);
|
||||||
|
talkgroups = service.getTalkgroups(systemId);
|
||||||
|
|
||||||
|
List<TalkgroupCategory> categories = service.getTalkgroupCategories(systemId);
|
||||||
|
|
||||||
|
if(categories != null)
|
||||||
|
{
|
||||||
|
for(TalkgroupCategory category: categories)
|
||||||
|
{
|
||||||
|
categoryNames.put(category.getTalkgroupCategoryId(), category.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized(mFailedAttempts)
|
||||||
|
{
|
||||||
|
mFailedAttempts.remove(systemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Talkgroup> talkgroupsToApply = talkgroups;
|
||||||
|
System systemToApply = system;
|
||||||
|
RadioReferenceDecoder decoderToApply = decoder;
|
||||||
|
String systemName = systemInformation.getName();
|
||||||
|
|
||||||
|
runOnFxThread(() -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
future.complete(apply(configuration, systemId, systemName, lastUpdated, talkgroupsToApply,
|
||||||
|
categoryNames, systemToApply, decoderToApply));
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
future.completeExceptionally(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
synchronized(mFailedAttempts)
|
||||||
|
{
|
||||||
|
mFailedAttempts.put(systemId, java.lang.System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
future.completeExceptionally(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the check and applies the talkgroups to the alias list. Runs on the FX thread.
|
||||||
|
* @param talkgroups to apply, or null when only recording the check
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
Result apply(AliasListConfiguration configuration, int systemId, String systemName, long lastUpdated,
|
||||||
|
List<Talkgroup> talkgroups, Map<Integer,String> categoryNames, System system,
|
||||||
|
RadioReferenceDecoder decoder)
|
||||||
|
{
|
||||||
|
//The user may have deleted the alias list or stopped tracking while the request was in progress
|
||||||
|
if(!mAliasModel.aliasListConfigurations().contains(configuration) || !configuration.isTracking(systemId))
|
||||||
|
{
|
||||||
|
return new Result(false, 0, 0, lastUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration.setLastChecked(java.lang.System.currentTimeMillis());
|
||||||
|
configuration.setRadioReferenceLastUpdated(lastUpdated);
|
||||||
|
|
||||||
|
if(systemName != null && !systemName.isEmpty())
|
||||||
|
{
|
||||||
|
configuration.setRadioReferenceSystemName(systemName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(talkgroups == null)
|
||||||
|
{
|
||||||
|
return new Result(false, 0, 0, lastUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
String aliasListName = configuration.getName();
|
||||||
|
long previousSynchronization = configuration.getSynchronizedLastUpdated();
|
||||||
|
boolean encryptedDoNotMonitor = mUserPreferences.getRadioReferencePreference().isEncryptedTalkgroupDoNotMonitor();
|
||||||
|
|
||||||
|
List<Alias> listAliases = new ArrayList<>();
|
||||||
|
|
||||||
|
for(Alias alias: mAliasModel.getAliases())
|
||||||
|
{
|
||||||
|
if(aliasListName.equals(alias.getAliasListName()))
|
||||||
|
{
|
||||||
|
listAliases.add(alias);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Alias> created = new ArrayList<>();
|
||||||
|
int updated = 0;
|
||||||
|
|
||||||
|
for(Talkgroup talkgroup: talkgroups)
|
||||||
|
{
|
||||||
|
io.github.dsheirer.alias.id.talkgroup.Talkgroup aliasId = decoder.getTalkgroupAliasId(talkgroup, system);
|
||||||
|
String group = categoryNames.get(talkgroup.getTalkgroupCategoryId());
|
||||||
|
List<Alias> matches = getMatches(listAliases, aliasId);
|
||||||
|
|
||||||
|
if(matches.isEmpty())
|
||||||
|
{
|
||||||
|
Alias alias = decoder.createAlias(talkgroup, system, aliasListName, group);
|
||||||
|
|
||||||
|
if(encryptedDoNotMonitor &&
|
||||||
|
TalkgroupEncryption.lookup(talkgroup.getEncryptionState()) == TalkgroupEncryption.FULL)
|
||||||
|
{
|
||||||
|
alias.addAliasID(new io.github.dsheirer.alias.id.priority.Priority(
|
||||||
|
io.github.dsheirer.alias.id.priority.Priority.DO_NOT_MONITOR));
|
||||||
|
}
|
||||||
|
|
||||||
|
created.add(alias);
|
||||||
|
listAliases.add(alias);
|
||||||
|
}
|
||||||
|
//Only update aliases for talkgroups that changed on Radio Reference after the previous synchronization, so
|
||||||
|
//that the first synchronization and unchanged talkgroups keep any names the user has edited.
|
||||||
|
else if(previousSynchronization > 0 && getTime(talkgroup.getLastUpdated()) > previousSynchronization)
|
||||||
|
{
|
||||||
|
for(Alias alias: matches)
|
||||||
|
{
|
||||||
|
boolean aliasUpdated = false;
|
||||||
|
String name = talkgroup.getAlphaTag();
|
||||||
|
|
||||||
|
if(name != null && !name.isEmpty() && !Objects.equals(name, alias.getName()))
|
||||||
|
{
|
||||||
|
alias.setName(name);
|
||||||
|
aliasUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(group != null && !group.isEmpty() && !Objects.equals(group, alias.getGroup()))
|
||||||
|
{
|
||||||
|
alias.setGroup(group);
|
||||||
|
aliasUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(aliasUpdated)
|
||||||
|
{
|
||||||
|
updated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!created.isEmpty())
|
||||||
|
{
|
||||||
|
mAliasModel.addAliases(created);
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration.setSynchronizedLastUpdated(lastUpdated);
|
||||||
|
|
||||||
|
mLog.info("Alias list [" + aliasListName + "] synchronized with Radio Reference system [" +
|
||||||
|
configuration.getRadioReferenceSystemId() + "] - added [" + created.size() + "] updated [" + updated +
|
||||||
|
"] aliases");
|
||||||
|
|
||||||
|
return new Result(true, created.size(), updated, lastUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aliases with a talkgroup alias identifier that matches the talkgroup.
|
||||||
|
*/
|
||||||
|
private static List<Alias> getMatches(List<Alias> aliases, io.github.dsheirer.alias.id.talkgroup.Talkgroup aliasId)
|
||||||
|
{
|
||||||
|
List<Alias> matches = new ArrayList<>();
|
||||||
|
|
||||||
|
for(Alias alias: aliases)
|
||||||
|
{
|
||||||
|
for(AliasID id: alias.getAliasIdentifiers())
|
||||||
|
{
|
||||||
|
if(aliasId.matches(id))
|
||||||
|
{
|
||||||
|
matches.add(alias);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decoder for talkgroup values and protocols, created on first use from the cached Radio Reference maps.
|
||||||
|
*/
|
||||||
|
private RadioReferenceDecoder getRadioReferenceDecoder() throws RadioReferenceException
|
||||||
|
{
|
||||||
|
if(mRadioReferenceDecoder == null)
|
||||||
|
{
|
||||||
|
RadioReferenceService service = mRadioReference.getService();
|
||||||
|
mRadioReferenceDecoder = new RadioReferenceDecoder(mUserPreferences, service.getTypesMap(),
|
||||||
|
service.getFlavorsMap(), service.getVoicesMap(), service.getTagsMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mRadioReferenceDecoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a system from the system information, for the decoder's protocol lookup.
|
||||||
|
*/
|
||||||
|
private static System toSystem(int systemId, SystemInformation systemInformation)
|
||||||
|
{
|
||||||
|
System system = new System();
|
||||||
|
system.setSystemId(systemId);
|
||||||
|
system.setName(systemInformation.getName());
|
||||||
|
system.setTypeId(systemInformation.getTypeId());
|
||||||
|
system.setFlavorId(systemInformation.getFlavorId());
|
||||||
|
system.setVoiceId(systemInformation.getVoiceId());
|
||||||
|
system.setCity(systemInformation.getCity());
|
||||||
|
system.setLastUpdated(systemInformation.getLastUpdated());
|
||||||
|
return system;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long getTime(Date date)
|
||||||
|
{
|
||||||
|
return date != null ? date.getTime() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs on the FX thread, or on this thread when the FX toolkit isn't running (headless).
|
||||||
|
*/
|
||||||
|
private static void runOnFxThread(Runnable runnable)
|
||||||
|
{
|
||||||
|
if(Platform.isFxApplicationThread())
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Platform.runLater(runnable);
|
||||||
|
}
|
||||||
|
catch(IllegalStateException ise)
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message for an exception, unwrapping completion exceptions.
|
||||||
|
*/
|
||||||
|
public static String getMessage(Throwable throwable)
|
||||||
|
{
|
||||||
|
Throwable cause = throwable;
|
||||||
|
|
||||||
|
while(cause.getCause() != null && (cause instanceof java.util.concurrent.CompletionException ||
|
||||||
|
cause instanceof java.util.concurrent.ExecutionException))
|
||||||
|
{
|
||||||
|
cause = cause.getCause();
|
||||||
|
}
|
||||||
|
|
||||||
|
return cause.getMessage() != null ? cause.getMessage() : cause.getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronization result
|
||||||
|
* @param applied true if the talkgroups were applied to the alias list
|
||||||
|
* @param added alias count
|
||||||
|
* @param updated alias count
|
||||||
|
* @param lastUpdated Radio Reference system last updated timestamp
|
||||||
|
*/
|
||||||
|
public record Result(boolean applied, int added, int updated, long lastUpdated) {}
|
||||||
|
}
|
||||||
@@ -148,6 +148,17 @@ public class CachingRadioReferenceService extends RadioReferenceService
|
|||||||
return get(mTalkgroupCache, systemId);
|
return get(mTalkgroupCache, systemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discards the cached system information and talkgroups for the system so that the next request reads current
|
||||||
|
* values from the web service.
|
||||||
|
* @param systemId to discard
|
||||||
|
*/
|
||||||
|
public void invalidateSystem(int systemId)
|
||||||
|
{
|
||||||
|
mSystemInfoCache.invalidate(systemId);
|
||||||
|
mTalkgroupCache.invalidate(systemId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a value from the web service
|
* Loads a value from the web service
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ public class RadioReferenceFrequencyIndex
|
|||||||
});
|
});
|
||||||
private volatile NavigableMap<Long,List<FrequencyCandidate>> mFrequencies = Collections.emptyNavigableMap();
|
private volatile NavigableMap<Long,List<FrequencyCandidate>> mFrequencies = Collections.emptyNavigableMap();
|
||||||
private volatile List<SiteRecord> mSites = Collections.emptyList();
|
private volatile List<SiteRecord> mSites = Collections.emptyList();
|
||||||
|
//Key of the source (county:123 or agency:789) that lists each conventional frequency
|
||||||
|
private volatile Map<FrequencyCandidate,String> mSourceKeys = Collections.emptyMap();
|
||||||
private final List<Runnable> mUpdateListeners = new java.util.concurrent.CopyOnWriteArrayList<>();
|
private final List<Runnable> mUpdateListeners = new java.util.concurrent.CopyOnWriteArrayList<>();
|
||||||
private volatile BuildParameters mParameters;
|
private volatile BuildParameters mParameters;
|
||||||
private volatile long mRefreshed;
|
private volatile long mRefreshed;
|
||||||
@@ -308,6 +310,7 @@ public class RadioReferenceFrequencyIndex
|
|||||||
stopBuild();
|
stopBuild();
|
||||||
mFrequencies = Collections.emptyNavigableMap();
|
mFrequencies = Collections.emptyNavigableMap();
|
||||||
mSites = Collections.emptyList();
|
mSites = Collections.emptyList();
|
||||||
|
mSourceKeys = Collections.emptyMap();
|
||||||
mParameters = null;
|
mParameters = null;
|
||||||
notifyUpdated();
|
notifyUpdated();
|
||||||
setStatus("Set your location in the playlist editor's Radio Reference tab");
|
setStatus("Set your location in the playlist editor's Radio Reference tab");
|
||||||
@@ -1105,6 +1108,16 @@ public class RadioReferenceFrequencyIndex
|
|||||||
nonNull(source.candidates()).stream().anyMatch(candidate -> !candidate.isSiteFrequency()));
|
nonNull(source.candidates()).stream().anyMatch(candidate -> !candidate.isSiteFrequency()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key of the radio reference source that lists the conventional frequency: county:123 for a county's frequencies
|
||||||
|
* or agency:789 for an agency's frequencies. Can be called from any thread.
|
||||||
|
* @return key, or null when the index doesn't have the candidate or it's a trunked site frequency
|
||||||
|
*/
|
||||||
|
public String getSourceKey(FrequencyCandidate candidate)
|
||||||
|
{
|
||||||
|
return candidate != null ? mSourceKeys.get(candidate) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site record by system and site id
|
* Site record by system and site id
|
||||||
* @return site, or null when the index doesn't have it
|
* @return site, or null when the index doesn't have it
|
||||||
@@ -1280,13 +1293,23 @@ public class RadioReferenceFrequencyIndex
|
|||||||
{
|
{
|
||||||
mFrequencies = toFrequencies(sources);
|
mFrequencies = toFrequencies(sources);
|
||||||
List<SiteRecord> sites = new ArrayList<>();
|
List<SiteRecord> sites = new ArrayList<>();
|
||||||
|
Map<FrequencyCandidate,String> sourceKeys = new HashMap<>();
|
||||||
|
|
||||||
for(Source source: sources)
|
for(Source source: sources)
|
||||||
{
|
{
|
||||||
sites.addAll(nonNull(source.sites()));
|
sites.addAll(nonNull(source.sites()));
|
||||||
|
|
||||||
|
if(!source.isSystem())
|
||||||
|
{
|
||||||
|
for(FrequencyCandidate candidate: nonNull(source.candidates()))
|
||||||
|
{
|
||||||
|
sourceKeys.putIfAbsent(candidate, source.key());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSites = Collections.unmodifiableList(sites);
|
mSites = Collections.unmodifiableList(sites);
|
||||||
|
mSourceKeys = Collections.unmodifiableMap(sourceKeys);
|
||||||
notifyUpdated();
|
notifyUpdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -70,7 +70,7 @@ public class RspNativeBuffer extends AbstractNativeBuffer
|
|||||||
@Override
|
@Override
|
||||||
public int sampleCount()
|
public int sampleCount()
|
||||||
{
|
{
|
||||||
return mISamples.length;
|
return mISamples.length * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* *****************************************************************************
|
* *****************************************************************************
|
||||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -31,8 +31,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.function.ToLongFunction;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -56,9 +54,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
private HeartbeatManager mHeartbeatManager;
|
private HeartbeatManager mHeartbeatManager;
|
||||||
private long mDroppedCount = 0;
|
private long mDroppedCount = 0;
|
||||||
private long mLastOverflowLogTimestamp = 0;
|
private long mLastOverflowLogTimestamp = 0;
|
||||||
private final ToLongFunction<E> mWeigher;
|
|
||||||
private volatile long mMaximumQueuedWeight = Long.MAX_VALUE;
|
|
||||||
private final AtomicLong mQueuedWeight = new AtomicLong();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an instance of a Dispatcher with integrated heartbeat support.
|
* Constructs an instance of a Dispatcher with integrated heartbeat support.
|
||||||
@@ -95,7 +90,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
mThreadName = threadName;
|
mThreadName = threadName;
|
||||||
mInterval = interval;
|
mInterval = interval;
|
||||||
mQueue = new LinkedTransferQueue<>();
|
mQueue = new LinkedTransferQueue<>();
|
||||||
mWeigher = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,46 +103,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
mThreadName = threadName;
|
mThreadName = threadName;
|
||||||
mInterval = interval;
|
mInterval = interval;
|
||||||
mQueue = new LinkedBlockingQueue<>(maximumQueueSize);
|
mQueue = new LinkedBlockingQueue<>(maximumQueueSize);
|
||||||
mWeigher = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs an instance that is bounded by the total weight of the queued elements instead of the element count,
|
|
||||||
* for when element sizes vary widely, for example sample buffers from different tuners. An element is dropped
|
|
||||||
* when adding it would exceed the maximum weight, except when nothing is queued, so that an element heavier than
|
|
||||||
* the maximum is still delivered. Elements count toward the weight until the listener has processed them.
|
|
||||||
*
|
|
||||||
* @param threadName to name the dispatcher thread
|
|
||||||
* @param interval for processing each batch in milliseconds.
|
|
||||||
* @param weigher to calculate the weight of each element, for example a sample count.
|
|
||||||
* @param maximumQueuedWeight for the queued elements.
|
|
||||||
*/
|
|
||||||
public Dispatcher(String threadName, long interval, ToLongFunction<E> weigher, long maximumQueuedWeight)
|
|
||||||
{
|
|
||||||
if(weigher == null)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Weigher cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
mThreadName = threadName;
|
|
||||||
mInterval = interval;
|
|
||||||
mQueue = new LinkedTransferQueue<>();
|
|
||||||
mWeigher = weigher;
|
|
||||||
setMaximumQueuedWeight(maximumQueuedWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the maximum total weight of the queued elements, for a dispatcher that was constructed with a weigher.
|
|
||||||
* @param maximumQueuedWeight for the queued elements.
|
|
||||||
*/
|
|
||||||
public void setMaximumQueuedWeight(long maximumQueuedWeight)
|
|
||||||
{
|
|
||||||
if(maximumQueuedWeight <= 0)
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Maximum queued weight must be positive: " + maximumQueuedWeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
mMaximumQueuedWeight = maximumQueuedWeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,27 +149,7 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean queued;
|
boolean queued = mQueue.offer(e);
|
||||||
|
|
||||||
if(mWeigher != null)
|
|
||||||
{
|
|
||||||
long weight = mWeigher.applyAsLong(e);
|
|
||||||
long queuedWeight = mQueuedWeight.addAndGet(weight);
|
|
||||||
|
|
||||||
if(queuedWeight > mMaximumQueuedWeight && queuedWeight > weight)
|
|
||||||
{
|
|
||||||
mQueuedWeight.addAndGet(-weight);
|
|
||||||
queued = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
queued = mQueue.offer(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
queued = mQueue.offer(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!queued)
|
if(!queued)
|
||||||
{
|
{
|
||||||
@@ -255,7 +189,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
mQueue.clear();
|
mQueue.clear();
|
||||||
mQueuedWeight.set(0);
|
|
||||||
mExecutorService = Executors.newSingleThreadScheduledExecutor(new NamingThreadFactory(mThreadName));
|
mExecutorService = Executors.newSingleThreadScheduledExecutor(new NamingThreadFactory(mThreadName));
|
||||||
|
|
||||||
Runnable r = (mHeartbeatManager != null ? new ProcessorWithHeartbeat() : new Processor());
|
Runnable r = (mHeartbeatManager != null ? new ProcessorWithHeartbeat() : new Processor());
|
||||||
@@ -277,7 +210,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
mScheduledFuture.cancel(false);
|
mScheduledFuture.cancel(false);
|
||||||
mScheduledFuture = null;
|
mScheduledFuture = null;
|
||||||
mQueue.clear();
|
mQueue.clear();
|
||||||
mQueuedWeight.set(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mExecutorService != null)
|
if(mExecutorService != null)
|
||||||
@@ -327,8 +259,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
mListener.getClass() + "]", t);
|
mListener.getClass() + "]", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
release(element);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,19 +294,6 @@ public class Dispatcher<E> implements Listener<E>
|
|||||||
mListener.getClass() + "]", t);
|
mListener.getClass() + "]", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
release(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the weight of a dequeued element from the queued weight, once the element is processed.
|
|
||||||
*/
|
|
||||||
private void release(E element)
|
|
||||||
{
|
|
||||||
if(mWeigher != null)
|
|
||||||
{
|
|
||||||
mQueuedWeight.addAndGet(-mWeigher.applyAsLong(element));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.alias;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
import io.github.dsheirer.playlist.PlaylistV2;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias list configuration persistence and alias model rename/delete handling.
|
||||||
|
*/
|
||||||
|
public class AliasListConfigurationTest
|
||||||
|
{
|
||||||
|
private static ObjectMapper mapper()
|
||||||
|
{
|
||||||
|
JacksonXmlModule xmlModule = new JacksonXmlModule();
|
||||||
|
xmlModule.setDefaultUseWrapper(false);
|
||||||
|
return new XmlMapper(xmlModule).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playlistRoundTrip() throws Exception
|
||||||
|
{
|
||||||
|
AliasListConfiguration configuration = new AliasListConfiguration("County P25");
|
||||||
|
configuration.track(1234, "County Public Safety");
|
||||||
|
configuration.setAutoUpdate(true);
|
||||||
|
configuration.setRadioReferenceLastUpdated(2000L);
|
||||||
|
configuration.setSynchronizedLastUpdated(1000L);
|
||||||
|
configuration.setLastChecked(3000L);
|
||||||
|
|
||||||
|
Alias alias = new Alias("Fire Dispatch");
|
||||||
|
alias.setAliasListName("County P25");
|
||||||
|
|
||||||
|
PlaylistV2 playlist = new PlaylistV2();
|
||||||
|
playlist.getAliases().add(alias);
|
||||||
|
playlist.getAliasListConfigurations().add(configuration);
|
||||||
|
|
||||||
|
String xml = mapper().writeValueAsString(playlist);
|
||||||
|
PlaylistV2 read = mapper().readValue(xml, PlaylistV2.class);
|
||||||
|
|
||||||
|
assertEquals(1, read.getAliasListConfigurations().size(), xml);
|
||||||
|
AliasListConfiguration readConfiguration = read.getAliasListConfigurations().get(0);
|
||||||
|
assertEquals("County P25", readConfiguration.getName());
|
||||||
|
assertEquals(1234, readConfiguration.getRadioReferenceSystemId());
|
||||||
|
assertEquals("County Public Safety", readConfiguration.getRadioReferenceSystemName());
|
||||||
|
assertTrue(readConfiguration.isAutoUpdate());
|
||||||
|
assertEquals(2000L, readConfiguration.getRadioReferenceLastUpdated());
|
||||||
|
assertEquals(1000L, readConfiguration.getSynchronizedLastUpdated());
|
||||||
|
assertEquals(3000L, readConfiguration.getLastChecked());
|
||||||
|
assertTrue(readConfiguration.isUpdateAvailable());
|
||||||
|
assertEquals(1, read.getAliases().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void legacyPlaylistWithoutConfigurations() throws Exception
|
||||||
|
{
|
||||||
|
String xml = "<playlist version=\"4\"><alias name=\"A\" list=\"L\"/></playlist>";
|
||||||
|
PlaylistV2 read = mapper().readValue(xml, PlaylistV2.class);
|
||||||
|
assertTrue(read.getAliasListConfigurations().isEmpty());
|
||||||
|
assertEquals(1, read.getAliases().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void trackingLookupRenameAndDelete()
|
||||||
|
{
|
||||||
|
AliasModel model = new AliasModel();
|
||||||
|
model.addAliasListConfigurations(List.of(new AliasListConfiguration("Plain")));
|
||||||
|
AliasListConfiguration tracked = model.getOrCreateAliasListConfiguration("Tracked");
|
||||||
|
tracked.track(42, "System 42");
|
||||||
|
|
||||||
|
//Configured alias lists are listed before they have any aliases
|
||||||
|
assertTrue(model.aliasListNames().contains("Tracked"));
|
||||||
|
assertEquals("Tracked", model.getAliasListNameTracking(42));
|
||||||
|
assertNull(model.getAliasListNameTracking(7));
|
||||||
|
assertFalse(model.getAliasListConfiguration("Plain").isTrackingRadioReferenceSystem());
|
||||||
|
|
||||||
|
Alias alias = new Alias("TG 1");
|
||||||
|
alias.setAliasListName("Tracked");
|
||||||
|
model.addAlias(alias);
|
||||||
|
|
||||||
|
model.renameAliasList("Tracked", "Renamed");
|
||||||
|
assertEquals("Renamed", model.getAliasListNameTracking(42));
|
||||||
|
assertEquals("Renamed", alias.getAliasListName());
|
||||||
|
assertNull(model.getAliasListConfiguration("Tracked"));
|
||||||
|
|
||||||
|
model.refreshAliasListNames();
|
||||||
|
assertTrue(model.aliasListNames().contains("Plain"));
|
||||||
|
|
||||||
|
model.deleteAliasList("Renamed");
|
||||||
|
assertNull(model.getAliasListNameTracking(42));
|
||||||
|
assertTrue(model.getAliases().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.alias;
|
||||||
|
|
||||||
|
import io.github.dsheirer.alias.TalkerAliasAutoAdder.Decision;
|
||||||
|
import io.github.dsheirer.alias.id.radio.P25FullyQualifiedRadio;
|
||||||
|
import io.github.dsheirer.alias.id.radio.Radio;
|
||||||
|
import io.github.dsheirer.alias.id.talkgroup.Talkgroup;
|
||||||
|
import io.github.dsheirer.identifier.alias.P25TalkerAliasIdentifier;
|
||||||
|
import io.github.dsheirer.identifier.alias.TalkerAliasManager;
|
||||||
|
import io.github.dsheirer.identifier.radio.RadioIdentifier;
|
||||||
|
import io.github.dsheirer.module.decode.p25.identifier.radio.APCO25FullyQualifiedRadioIdentifier;
|
||||||
|
import io.github.dsheirer.module.decode.p25.identifier.radio.APCO25RadioIdentifier;
|
||||||
|
import io.github.dsheirer.protocol.Protocol;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for automatically adding talker aliases to an alias list. The JavaFX toolkit isn't running, so the alias model
|
||||||
|
* updates run on the calling thread.
|
||||||
|
*/
|
||||||
|
public class TalkerAliasAutoAdderTest
|
||||||
|
{
|
||||||
|
private static final String LIST = "Test List";
|
||||||
|
private static final RadioIdentifier RADIO = (RadioIdentifier)APCO25RadioIdentifier.createFrom(1234);
|
||||||
|
|
||||||
|
private AliasModel mAliasModel;
|
||||||
|
private TalkerAliasManager mManager;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup()
|
||||||
|
{
|
||||||
|
mAliasModel = new AliasModel();
|
||||||
|
mManager = new TalkerAliasManager();
|
||||||
|
mManager.setTalkerAliasListener(new TalkerAliasAutoAdder(mAliasModel, LIST));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decode(RadioIdentifier radio, String alias)
|
||||||
|
{
|
||||||
|
mManager.update(radio, P25TalkerAliasIdentifier.create(alias));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Alias> aliases()
|
||||||
|
{
|
||||||
|
return mAliasModel.getAliases().stream().filter(a -> LIST.equals(a.getAliasListName())).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Alias alias(RadioIdentifier radio)
|
||||||
|
{
|
||||||
|
return TalkerAliasAutoAdder.findExactMatch(aliases(), TalkerAliasAutoAdder.createAliasId(radio));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createsAliasForRadio()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(1, aliases().size());
|
||||||
|
Alias alias = alias(RADIO);
|
||||||
|
assertEquals("ENGINE 12", alias.getName());
|
||||||
|
assertEquals(TalkerAliasAutoAdder.ALIAS_GROUP, alias.getGroup());
|
||||||
|
assertTrue(alias.getAliasIdentifiers().get(0) instanceof Radio radio && radio.getValue() == 1234 &&
|
||||||
|
radio.getProtocol() == Protocol.APCO25);
|
||||||
|
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(1, aliases().size(), "no duplicate alias");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fragmentNeverReplacesFullAlias()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12 OFFICER");
|
||||||
|
|
||||||
|
for(int x = 0; x < 5; x++)
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12 OFF");
|
||||||
|
decode(RADIO, "ENG");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("ENGINE 12 OFFICER", alias(RADIO).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fullAliasReplacesStoredFragment()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 1");
|
||||||
|
assertEquals("ENGINE 1", alias(RADIO).getName());
|
||||||
|
decode(RADIO, "ENGINE 12 OFFICER");
|
||||||
|
assertEquals("ENGINE 12 OFFICER", alias(RADIO).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void differentAliasRequiresConfirmation()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
assertEquals("ENGINE 12", alias(RADIO).getName(), "a single decode doesn't rename");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
assertEquals("LADDER 3", alias(RADIO).getName(), "confirmed decode renames");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fragmentsOfNewAliasDontInterruptConfirmation()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "LADDER 3 CAPTAIN");
|
||||||
|
decode(RADIO, "LADDER");
|
||||||
|
decode(RADIO, "LADDER 3 CAPTAIN");
|
||||||
|
assertEquals("LADDER 3 CAPTAIN", alias(RADIO).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void interleavedDifferentAliasesDontConfirm()
|
||||||
|
{
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
decode(RADIO, "RESCUE 5");
|
||||||
|
decode(RADIO, "LADDER 3");
|
||||||
|
assertEquals("ENGINE 12", alias(RADIO).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multiIdentifierAliasIsLeftAlone()
|
||||||
|
{
|
||||||
|
Alias alias = new Alias("Portables");
|
||||||
|
alias.setAliasListName(LIST);
|
||||||
|
alias.addAliasID(new Radio(Protocol.APCO25, 1234));
|
||||||
|
alias.addAliasID(new Radio(Protocol.APCO25, 5678));
|
||||||
|
mAliasModel.addAlias(alias);
|
||||||
|
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(1, aliases().size());
|
||||||
|
assertEquals("Portables", alias.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void userAliasForRadioIsRenamed()
|
||||||
|
{
|
||||||
|
Alias alias = new Alias("Old Name");
|
||||||
|
alias.setAliasListName(LIST);
|
||||||
|
alias.addAliasID(new Radio(Protocol.APCO25, 1234));
|
||||||
|
alias.addAliasID(new io.github.dsheirer.alias.id.priority.Priority(1));
|
||||||
|
mAliasModel.addAlias(alias);
|
||||||
|
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(1, aliases().size());
|
||||||
|
assertEquals("ENGINE 12", alias.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void talkgroupAliasWithSameValueIsIgnored()
|
||||||
|
{
|
||||||
|
Alias alias = new Alias("Dispatch");
|
||||||
|
alias.setAliasListName(LIST);
|
||||||
|
alias.addAliasID(new Talkgroup(Protocol.APCO25, 1234));
|
||||||
|
mAliasModel.addAlias(alias);
|
||||||
|
|
||||||
|
decode(RADIO, "ENGINE 12");
|
||||||
|
assertEquals(2, aliases().size());
|
||||||
|
assertEquals("Dispatch", alias.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fullyQualifiedRadio()
|
||||||
|
{
|
||||||
|
RadioIdentifier roaming = APCO25FullyQualifiedRadioIdentifier.createFrom(1234, 0xBEE00, 0x123, 777);
|
||||||
|
decode(roaming, "ROAMER");
|
||||||
|
Alias alias = alias(roaming);
|
||||||
|
assertTrue(alias.getAliasIdentifiers().get(0) instanceof P25FullyQualifiedRadio);
|
||||||
|
assertNull(alias(RADIO), "local radio with the same value isn't aliased");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decide()
|
||||||
|
{
|
||||||
|
assertEquals(Decision.UPDATE, TalkerAliasAutoAdder.decide(null, "A", 1));
|
||||||
|
assertEquals(Decision.UNCHANGED, TalkerAliasAutoAdder.decide("ABC", "ABC", 1));
|
||||||
|
assertEquals(Decision.FRAGMENT, TalkerAliasAutoAdder.decide("ABCDEF", "ABC", 5));
|
||||||
|
assertEquals(Decision.UPDATE, TalkerAliasAutoAdder.decide("ABC", "ABCDEF", 1));
|
||||||
|
assertEquals(Decision.AWAIT_CONFIRMATION, TalkerAliasAutoAdder.decide("ABC", "XYZ", 1));
|
||||||
|
assertEquals(Decision.UPDATE, TalkerAliasAutoAdder.decide("ABC", "XYZ", 2));
|
||||||
|
assertEquals(Decision.AWAIT_CONFIRMATION, TalkerAliasAutoAdder.decide("ABC", "X<EFBFBD>Z", 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void normalize()
|
||||||
|
{
|
||||||
|
assertEquals("JOS", TalkerAliasAutoAdder.normalize("JOS<EFBFBD>"));
|
||||||
|
assertEquals("ENGINE 12", TalkerAliasAutoAdder.normalize(" ENGINE 12\u0000\u0000 "));
|
||||||
|
assertNull(TalkerAliasAutoAdder.normalize("\u0000 "));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.controller.channel;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
import io.github.dsheirer.playlist.PlaylistV2;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
/**
|
||||||
|
* Tests channel auto-add talker aliases default and playlist persistence.
|
||||||
|
*/
|
||||||
|
public class ChannelAutoAddTalkerAliasesTest {
|
||||||
|
@Test public void newChannelsDefaultOnLegacyChannelsStayOff() throws Exception {
|
||||||
|
JacksonXmlModule m = new JacksonXmlModule(); m.setDefaultUseWrapper(false);
|
||||||
|
XmlMapper mapper = new XmlMapper(m);
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
assertTrue(new Channel().isAutoAddTalkerAliases(), "new channel default on");
|
||||||
|
assertTrue(new Channel("n").isAutoAddTalkerAliases(), "new named channel default on");
|
||||||
|
Channel off = new Channel("x"); off.setAutoAddTalkerAliases(false);
|
||||||
|
assertFalse(mapper.readValue(mapper.writeValueAsString(off), Channel.class).isAutoAddTalkerAliases());
|
||||||
|
assertTrue(mapper.readValue(mapper.writeValueAsString(new Channel("y")), Channel.class).isAutoAddTalkerAliases());
|
||||||
|
String legacy = mapper.writeValueAsString(new Channel("z")).replace(" auto_add_talker_aliases=\"true\"", "");
|
||||||
|
assertFalse(legacy.contains("auto_add"));
|
||||||
|
Channel legacyChannel = mapper.readValue(legacy, Channel.class);
|
||||||
|
assertFalse(legacyChannel.isAutoAddTalkerAliases(), "legacy channel stays off");
|
||||||
|
assertEquals("z", legacyChannel.getName());
|
||||||
|
PlaylistV2 pl = new PlaylistV2(); pl.getChannels().add(new Channel("p"));
|
||||||
|
String plXml = mapper.writeValueAsString(pl).replace(" auto_add_talker_aliases=\"true\"", "");
|
||||||
|
assertFalse(mapper.readValue(plXml, PlaylistV2.class).getChannels().get(0).isAutoAddTalkerAliases(), "legacy playlist off");
|
||||||
|
off.setAutoAddTalkerAliases(false); assertFalse(off.copyOf().isAutoAddTalkerAliases());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,4 +69,23 @@ public class SpectralDisplayThemeTest
|
|||||||
SpectralDisplayTheme theme = SpectralDisplayTheme.CLASSIC;
|
SpectralDisplayTheme theme = SpectralDisplayTheme.CLASSIC;
|
||||||
assertEquals(theme.getWaterfallColor(255), theme.getWaterfallColor((byte)255));
|
assertEquals(theme.getWaterfallColor(255), theme.getWaterfallColor((byte)255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void channelMenuColorsAreReadableAndDistinct()
|
||||||
|
{
|
||||||
|
for(SpectralDisplayTheme theme: SpectralDisplayTheme.values())
|
||||||
|
{
|
||||||
|
javafx.scene.paint.Color background = theme.getBackground();
|
||||||
|
javafx.scene.paint.Color active = theme.getChannelActive();
|
||||||
|
javafx.scene.paint.Color inactive = theme.getChannelInactive();
|
||||||
|
javafx.scene.paint.Color text = theme.getText();
|
||||||
|
|
||||||
|
//Readable without the menu having to adjust them
|
||||||
|
assertTrue(ChannelMenus.contrast(active, background) >= 3.0, theme + " active contrast");
|
||||||
|
assertTrue(ChannelMenus.contrast(inactive, background) >= 3.0, theme + " inactive contrast");
|
||||||
|
assertTrue(ChannelMenus.contrast(text, background) >= 4.5, theme + " text contrast");
|
||||||
|
assertTrue(!active.equals(inactive) && !active.equals(text) && !inactive.equals(text),
|
||||||
|
theme + " colors differ");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
/*
|
||||||
|
* *****************************************************************************
|
||||||
|
* Copyright (C) 2014-2026 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.service.radioreference;
|
||||||
|
|
||||||
|
import io.github.dsheirer.alias.Alias;
|
||||||
|
import io.github.dsheirer.alias.AliasListConfiguration;
|
||||||
|
import io.github.dsheirer.alias.AliasModel;
|
||||||
|
import io.github.dsheirer.alias.id.AliasIDType;
|
||||||
|
import io.github.dsheirer.gui.playlist.radioreference.RadioReferenceDecoder;
|
||||||
|
import io.github.dsheirer.preference.UserPreferences;
|
||||||
|
import io.github.dsheirer.protocol.Protocol;
|
||||||
|
import io.github.dsheirer.rrapi.type.System;
|
||||||
|
import io.github.dsheirer.rrapi.type.Talkgroup;
|
||||||
|
import io.github.dsheirer.rrapi.type.Type;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applying Radio Reference talkgroups to a tracked alias list, without the web service.
|
||||||
|
*/
|
||||||
|
public class AliasListSynchronizerTest
|
||||||
|
{
|
||||||
|
private static final int SYSTEM_ID = 42;
|
||||||
|
private static final String LIST = "Tracked";
|
||||||
|
|
||||||
|
private AliasModel mAliasModel;
|
||||||
|
private AliasListSynchronizer mSynchronizer;
|
||||||
|
private RadioReferenceDecoder mDecoder;
|
||||||
|
private System mSystem;
|
||||||
|
private AliasListConfiguration mConfiguration;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
UserPreferences userPreferences = new UserPreferences();
|
||||||
|
mAliasModel = new AliasModel();
|
||||||
|
mSynchronizer = new AliasListSynchronizer(mAliasModel, null, userPreferences);
|
||||||
|
|
||||||
|
Type p25 = new Type();
|
||||||
|
p25.setTypeId(1);
|
||||||
|
p25.setName("Project 25");
|
||||||
|
mDecoder = new RadioReferenceDecoder(userPreferences, Map.of(1, p25), Map.of(), Map.of(), Map.of());
|
||||||
|
|
||||||
|
mSystem = new System();
|
||||||
|
mSystem.setSystemId(SYSTEM_ID);
|
||||||
|
mSystem.setTypeId(1);
|
||||||
|
|
||||||
|
mConfiguration = mAliasModel.getOrCreateAliasListConfiguration(LIST);
|
||||||
|
mConfiguration.track(SYSTEM_ID, "System");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Talkgroup talkgroup(int value, String alphaTag, int categoryId, long lastUpdated)
|
||||||
|
{
|
||||||
|
Talkgroup talkgroup = new Talkgroup();
|
||||||
|
talkgroup.setDecimalValue(value);
|
||||||
|
talkgroup.setAlphaTag(alphaTag);
|
||||||
|
talkgroup.setTalkgroupCategoryId(categoryId);
|
||||||
|
talkgroup.setLastUpdated(new Date(lastUpdated));
|
||||||
|
return talkgroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AliasListSynchronizer.Result apply(long lastUpdated, List<Talkgroup> talkgroups)
|
||||||
|
{
|
||||||
|
return mSynchronizer.apply(mConfiguration, SYSTEM_ID, "System", lastUpdated, talkgroups,
|
||||||
|
Map.of(1, "Fire", 2, "Police"), mSystem, mDecoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Alias alias(int value)
|
||||||
|
{
|
||||||
|
return mAliasModel.getAliases(LIST, AliasIDType.TALKGROUP).stream()
|
||||||
|
.filter(a -> a.getAliasIdentifiers().stream().anyMatch(id ->
|
||||||
|
new io.github.dsheirer.alias.id.talkgroup.Talkgroup(Protocol.APCO25, value).matches(id)))
|
||||||
|
.findFirst().orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void firstSynchronizationAddsMissingAndKeepsExistingNames()
|
||||||
|
{
|
||||||
|
//The user already has an alias for talkgroup 100 with their own name
|
||||||
|
Alias existing = new Alias("My Name");
|
||||||
|
existing.setAliasListName(LIST);
|
||||||
|
existing.addAliasID(new io.github.dsheirer.alias.id.talkgroup.Talkgroup(Protocol.APCO25, 100));
|
||||||
|
mAliasModel.addAlias(existing);
|
||||||
|
|
||||||
|
AliasListSynchronizer.Result result = apply(5000,
|
||||||
|
List.of(talkgroup(100, "FD Dispatch", 1, 4000), talkgroup(200, "PD Main", 2, 4000)));
|
||||||
|
|
||||||
|
assertTrue(result.applied());
|
||||||
|
assertEquals(1, result.added());
|
||||||
|
assertEquals(0, result.updated());
|
||||||
|
assertEquals("My Name", alias(100).getName());
|
||||||
|
assertEquals("PD Main", alias(200).getName());
|
||||||
|
assertEquals("Police", alias(200).getGroup());
|
||||||
|
assertEquals(5000, mConfiguration.getSynchronizedLastUpdated());
|
||||||
|
assertEquals(5000, mConfiguration.getRadioReferenceLastUpdated());
|
||||||
|
assertTrue(mConfiguration.getLastChecked() > 0);
|
||||||
|
assertFalse(mConfiguration.isUpdateAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void laterSynchronizationUpdatesOnlyChangedTalkgroups()
|
||||||
|
{
|
||||||
|
apply(5000, List.of(talkgroup(100, "FD Dispatch", 1, 4000), talkgroup(200, "PD Main", 2, 4000)));
|
||||||
|
alias(200).setName("User Edited");
|
||||||
|
|
||||||
|
//Talkgroup 100 was renamed on Radio Reference after the first synchronization; 200 didn't change
|
||||||
|
AliasListSynchronizer.Result result = apply(9000, List.of(talkgroup(100, "FD Dispatch 1", 2, 8000),
|
||||||
|
talkgroup(200, "PD Main", 2, 4000), talkgroup(300, "EMS", 1, 8000)));
|
||||||
|
|
||||||
|
assertEquals(1, result.added());
|
||||||
|
assertEquals(1, result.updated());
|
||||||
|
assertEquals("FD Dispatch 1", alias(100).getName());
|
||||||
|
assertEquals("Police", alias(100).getGroup());
|
||||||
|
assertEquals("User Edited", alias(200).getName());
|
||||||
|
assertEquals("EMS", alias(300).getName());
|
||||||
|
assertEquals(9000, mConfiguration.getSynchronizedLastUpdated());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void checkOnlyRecordsTimestamps()
|
||||||
|
{
|
||||||
|
AliasListSynchronizer.Result result = apply(7000, null);
|
||||||
|
|
||||||
|
assertFalse(result.applied());
|
||||||
|
assertEquals(7000, mConfiguration.getRadioReferenceLastUpdated());
|
||||||
|
assertEquals(0, mConfiguration.getSynchronizedLastUpdated());
|
||||||
|
assertTrue(mConfiguration.isUpdateAvailable());
|
||||||
|
assertTrue(mAliasModel.getAliases().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deletedAliasListIsIgnored()
|
||||||
|
{
|
||||||
|
mAliasModel.deleteAliasList(LIST);
|
||||||
|
AliasListSynchronizer.Result result = apply(5000, List.of(talkgroup(100, "FD Dispatch", 1, 4000)));
|
||||||
|
|
||||||
|
assertFalse(result.applied());
|
||||||
|
assertTrue(mAliasModel.getAliases().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -125,60 +125,4 @@ public class DispatcherTest
|
|||||||
|
|
||||||
assertEquals(101, received.size());
|
assertEquals(101, received.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test: a weight-bounded queue drops elements that would exceed the maximum weight and keeps lighter ones.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void weightBoundedQueueDropsElementsOverMaximumWeight() throws Exception
|
|
||||||
{
|
|
||||||
//Each element weighs its own value: 1 + 2 + 3 = 6 is queued, then 4 would exceed 6 and is dropped, then 0 fits
|
|
||||||
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
|
|
||||||
List<Integer> received = dispatchWhileBlocked(dispatcher, 4);
|
|
||||||
dispatcher.receive(0);
|
|
||||||
awaitSize(received, 5);
|
|
||||||
Thread.sleep(50);
|
|
||||||
dispatcher.stop();
|
|
||||||
|
|
||||||
assertEquals(List.of(0, 1, 2, 3, 0), received);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test: an element heavier than the maximum weight is delivered when nothing else is queued.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void weightBoundedQueueAcceptsHeavyElementWhenEmpty() throws Exception
|
|
||||||
{
|
|
||||||
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
|
|
||||||
List<Integer> received = dispatchWhileBlocked(dispatcher, 0);
|
|
||||||
dispatcher.receive(100);
|
|
||||||
dispatcher.receive(1);
|
|
||||||
awaitSize(received, 2);
|
|
||||||
Thread.sleep(50);
|
|
||||||
dispatcher.stop();
|
|
||||||
|
|
||||||
assertEquals(List.of(0, 100), received);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test: processed elements release their weight so that the queue accepts new elements after an overflow.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
void weightBoundedQueueRecoversAfterOverflow() throws Exception
|
|
||||||
{
|
|
||||||
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
|
|
||||||
List<Integer> received = dispatchWhileBlocked(dispatcher, 10);
|
|
||||||
awaitSize(received, 4);
|
|
||||||
Thread.sleep(50);
|
|
||||||
|
|
||||||
for(int x = 0; x < 3; x++)
|
|
||||||
{
|
|
||||||
dispatcher.receive(5);
|
|
||||||
awaitSize(received, 5 + x);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatcher.stop();
|
|
||||||
|
|
||||||
assertEquals(List.of(0, 1, 2, 3, 5, 5, 5), received);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user