mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-20 04:27:48 -05:00
Compare commits
15 Commits
DSheirer-p
...
2717-tuner
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
463a805890 | ||
|
|
156dd40bfe | ||
|
|
e01dd02b74 | ||
|
|
8324233acb | ||
|
|
838e7708c0 | ||
|
|
d3a9adc06f | ||
|
|
cd098955aa | ||
|
|
61efb3d299 | ||
|
|
6d89a604c3 | ||
|
|
3473150ee9 | ||
|
|
ff6e2bd710 | ||
|
|
f302d46be1 | ||
|
|
f47479b8d4 | ||
|
|
bc7dd201ab | ||
|
|
c46b80b06b |
18
README.md
18
README.md
@@ -25,24 +25,6 @@ A cross-platform java application for decoding, monitoring, recording and stream
|
||||

|
||||
**Figure 1:** sdrtrunk decoding a P25 Phase 1 simulcast trunked radio system
|
||||
|
||||
## MacOS Tahoe 26.1 Users - Attention
|
||||
Changes to USB support in Tahoe version 26.x cause sdrtrunk to fail to launch. Do the following to install the latest libusb and create a symbolic link and then use the nightly build which includes an updated usb4java native library for Tahoe with ARM processor. There may still be issue(s) with MacOS accessing your USB SDR tuners.
|
||||
|
||||
```
|
||||
brew install libusb --HEAD
|
||||
cd /opt
|
||||
sudo mkdir local
|
||||
cd local
|
||||
sudo mkdir lib
|
||||
```
|
||||
Next, find where brew installed the libusb library, for example: ```/opt/homebrew/Cellar/libusb/HEAD-9ceaa52/lib/libusb-1.0.0.dylib``` Note: the folder "HEAD-9ceaa52" is the version stamp for HEAD when you installed from it.
|
||||
|
||||
Finally, create a symbolic link from the installed library to the place where usb4java is expecting to find libusb (/opt/local/lib/libusb-1.0.0.dylib)
|
||||
|
||||
```
|
||||
sudo ln -s /opt/homebrew/Cellar/libusb/HEAD-9ceaa52/lib/libusb-1.0.0.dylib /opt/local/lib/libusb-1.0.0.dylib
|
||||
```
|
||||
|
||||
## Download the Latest Release
|
||||
All release versions of sdrtrunk are available from the [releases](https://github.com/DSheirer/sdrtrunk/releases) tab.
|
||||
|
||||
|
||||
32
build.gradle
32
build.gradle
@@ -213,6 +213,14 @@ def jvmArgsLinux =
|
||||
'--enable-native-access=javafx.graphics', //JDK24 - suppress restricted java.lang.System calls
|
||||
'--enable-native-access=ALL-UNNAMED'] //Suppress warnings for FFM API native calls (tuner libraries)
|
||||
|
||||
/**
|
||||
* Startup splash screen image. The JVM shows it before any application code runs and closes it when the main window
|
||||
* opens. The release launch scripts load it from the runtime image lib folder (see the runtime task below) and the
|
||||
* gradle run task loads it from the resources folder. The JVM picks up the @2x image on HiDPI displays.
|
||||
*/
|
||||
def splashImages = ['sdrtrunk-splash.png', 'sdrtrunk-splash@2x.png']
|
||||
def splashResourceDir = 'src/main/resources/images/sdrtrunk'
|
||||
|
||||
application {
|
||||
mainClass = "io.github.dsheirer.gui.SDRTrunk"
|
||||
|
||||
@@ -224,6 +232,10 @@ application {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named('run') {
|
||||
jvmArgs "-splash:${file(splashResourceDir + '/' + splashImages[0]).absolutePath}"
|
||||
}
|
||||
|
||||
test {
|
||||
if(os.isWindows()) {
|
||||
jvmArgs = jvmArgsWindows
|
||||
@@ -288,8 +300,8 @@ def jdk_download_windows_aarch64 = jdk_download_base + "windows-aarch64-full.zip
|
||||
* @return configured task.
|
||||
*/
|
||||
def configure(RuntimeZipTask rt, List<String> jvmArgs) {
|
||||
//Use the correct set of JVM arguments
|
||||
rt.extension.launcherData.get().jvmArgs = jvmArgs
|
||||
//Use the correct set of JVM arguments, plus the startup splash screen that the runtime task copies to lib
|
||||
rt.extension.launcherData.get().jvmArgs = jvmArgs + ['-splash:{{BIN_DIR}}/../lib/sdrtrunk-splash.png']
|
||||
|
||||
//Additional modules to include with auto-detected modules.
|
||||
//jdk.charsets - NXDN BIG5 encoding support
|
||||
@@ -388,6 +400,22 @@ tasks.named('runtime') {rt ->
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the startup splash screen images into the lib folder of each runtime target image, where the launch scripts
|
||||
* load them from (-splash:{{BIN_DIR}}/../lib/...).
|
||||
*/
|
||||
tasks.named('runtime') {rt ->
|
||||
rt.doLast {
|
||||
rt.targetPlatforms.get().keySet().each { target ->
|
||||
def lib = new File(rt.imageDir.asFile, "${project.name}-${target}/lib")
|
||||
splashImages.each { name ->
|
||||
java.nio.file.Files.copy(file(splashResourceDir + '/' + name).toPath(), new File(lib, name).toPath(),
|
||||
java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that each runtime target image contains every module that the sdrtrunk jar requires, as reported by jdeps.
|
||||
* This guards against the runtime plugin's module auto-detection silently missing modules (e.g. when it can't parse
|
||||
|
||||
@@ -52,7 +52,9 @@ import org.slf4j.LoggerFactory;
|
||||
* </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.
|
||||
* identifiers (e.g. several radios or talkgroups) is left alone. The exception is a P25 radio's simple and fully
|
||||
* qualified radio identifiers with the same radio ID: the second form decoded is added to the alias for the first
|
||||
* form, including a user alias outside the managed group, instead of creating a second alias for the same radio.
|
||||
*
|
||||
* This class is thread safe. Talker aliases are received on decoder threads and the alias model is updated on the
|
||||
* JavaFX application thread.
|
||||
@@ -200,6 +202,21 @@ public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAl
|
||||
AliasList aliasList = mAliasModel.getAliasList(mAliasListName);
|
||||
Alias existing = findExactMatch(aliasList.getAliases(radio), aliasId);
|
||||
|
||||
if(existing == null)
|
||||
{
|
||||
existing = findCompanion(aliasList.aliases(), radio, aliasId);
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
//Add the radio to the alias for the same radio's other identifier form, then continue below to
|
||||
//compare the talker alias with the alias name (only managed aliases are renamed).
|
||||
existing.addAliasID(aliasId);
|
||||
aliasList.updateAlias(existing);
|
||||
mLog.info("Talker alias radio [" + aliasId + "] added to existing alias [" + existing.getName() +
|
||||
"] in alias list [" + mAliasListName + "]");
|
||||
}
|
||||
}
|
||||
|
||||
if(existing == null)
|
||||
{
|
||||
Alias alias = new Alias(value);
|
||||
@@ -213,6 +230,13 @@ public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAl
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ALIAS_GROUP.equals(existing.getGroup()))
|
||||
{
|
||||
//Only maintain aliases in the managed group. Existing user aliases must not be renamed or duplicated.
|
||||
markChecked(key, value);
|
||||
return;
|
||||
}
|
||||
|
||||
if(getIdentityCount(existing) > 1)
|
||||
{
|
||||
//The alias also identifies other radios or talkgroups - leave it alone.
|
||||
@@ -401,22 +425,114 @@ public class TalkerAliasAutoAdder implements BiConsumer<RadioIdentifier,TalkerAl
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of identifiers (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
||||
* streaming.
|
||||
* Finds the alias for the other identifier form of a P25 radio, so that a radio's simple and fully qualified
|
||||
* identifiers share one alias instead of creating an alias for each. This includes user aliases outside the
|
||||
* managed group, so that either identifier maps to the user's alias. The user alias is never renamed.
|
||||
* <ul>
|
||||
* <li>Fully qualified radio: the alias whose only identifier is the simple radio with the same radio
|
||||
* ID. Only when the fully qualified radio isn't using a different local address (e.g. a roaming radio), since
|
||||
* the radio ID then belongs to the home system and doesn't identify the radio on this system.</li>
|
||||
* <li>Simple radio: the alias whose only identifier is a fully qualified radio with the same radio ID. None
|
||||
* when more than one fully qualified radio alias matches.</li>
|
||||
* </ul>
|
||||
* @param aliases to search
|
||||
* @param radio decoded radio identifier
|
||||
* @param aliasId created from the decoded radio
|
||||
* @return companion alias or null.
|
||||
*/
|
||||
private static int getIdentityCount(Alias alias)
|
||||
@VisibleForTesting
|
||||
static Alias findCompanion(List<Alias> aliases, RadioIdentifier radio, Radio aliasId)
|
||||
{
|
||||
int count = 0;
|
||||
if(aliases == null || aliasId.getProtocol() != Protocol.APCO25)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean fullyQualified = aliasId instanceof P25FullyQualifiedRadio;
|
||||
|
||||
if(fullyQualified && !(radio instanceof FullyQualifiedRadioIdentifier fqri &&
|
||||
fqri.getValue() != null && fqri.getValue() == fqri.getRadio()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Alias match = null;
|
||||
|
||||
for(Alias alias: aliases)
|
||||
{
|
||||
if(getSoleIdentity(alias) instanceof Radio candidate &&
|
||||
(candidate instanceof P25FullyQualifiedRadio) != fullyQualified &&
|
||||
candidate.getProtocol() == Protocol.APCO25 && candidate.getValue() == aliasId.getValue())
|
||||
{
|
||||
if(match != null)
|
||||
{
|
||||
//Ambiguous - more than one candidate.
|
||||
return null;
|
||||
}
|
||||
|
||||
match = alias;
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier of an alias that has exactly one identifier, excluding audio settings.
|
||||
* @return identifier or null if the alias has none or more than one.
|
||||
*/
|
||||
private static AliasID getSoleIdentity(Alias alias)
|
||||
{
|
||||
AliasID sole = null;
|
||||
|
||||
for(AliasID id: alias.getAliasIdentifiers())
|
||||
{
|
||||
if(!id.isAudioIdentifier())
|
||||
{
|
||||
count++;
|
||||
if(sole != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
sole = id;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
return sole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of identities (e.g. radios, talkgroups) in the alias, excluding audio settings like priority, record and
|
||||
* streaming. A P25 radio's simple and fully qualified radio identifiers with the same radio ID count as one
|
||||
* identity.
|
||||
*/
|
||||
private static int getIdentityCount(Alias alias)
|
||||
{
|
||||
List<AliasID> ids = alias.getAliasIdentifiers().stream().filter(id -> !id.isAudioIdentifier()).toList();
|
||||
|
||||
if(ids.size() == 2 && isRadioPair(ids.get(0), ids.get(1)))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ids.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the identifiers are the simple and fully qualified forms of the same P25 radio ID.
|
||||
*/
|
||||
private static boolean isRadioPair(AliasID a, AliasID b)
|
||||
{
|
||||
if(a instanceof P25FullyQualifiedRadio)
|
||||
{
|
||||
AliasID swap = a;
|
||||
a = b;
|
||||
b = swap;
|
||||
}
|
||||
|
||||
return a instanceof Radio simple && !(a instanceof P25FullyQualifiedRadio) &&
|
||||
b instanceof P25FullyQualifiedRadio fqr && simple.getProtocol() == Protocol.APCO25 &&
|
||||
simple.getValue() == fqr.getValue();
|
||||
}
|
||||
|
||||
private static String getKey(Radio aliasId)
|
||||
|
||||
@@ -26,7 +26,7 @@ import io.github.dsheirer.gui.nowplaying.NowPlayingPanel;
|
||||
import io.github.dsheirer.gui.playlist.ViewPlaylistRequest;
|
||||
import io.github.dsheirer.icon.IconModel;
|
||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||
import io.github.dsheirer.map.MapPanel;
|
||||
import io.github.dsheirer.gui.map.MapPanel;
|
||||
import io.github.dsheirer.map.MapService;
|
||||
import io.github.dsheirer.playlist.PlaylistManager;
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
@@ -64,7 +64,7 @@ public class ControllerPanel extends JPanel
|
||||
mAudioPanel = new AudioPanel(iconModel, userPreferences, settingsManager, audioPlaybackManager,
|
||||
playlistManager.getAliasModel());
|
||||
mNowPlayingPanel = new NowPlayingPanel(playlistManager, iconModel, userPreferences, detailTabsVisible);
|
||||
mMapPanel = new MapPanel(mapService, playlistManager.getAliasModel(), iconModel, userPreferences,
|
||||
mMapPanel = new MapPanel(mapService, iconModel, userPreferences,
|
||||
playlistManager.getRadioReference() != null ? playlistManager.getRadioReference().getFrequencyIndex() : null,
|
||||
new RadioReferencePlaylistActions(playlistManager));
|
||||
mTunerManagerPanel = new TunerViewPanel(tunerManager, userPreferences);
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ChannelDFTFactory
|
||||
case VECTOR_SIMD_PREFERRED:
|
||||
return new VectorChannelDFT(channelCount);
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarChannelDFT(channelCount);
|
||||
}
|
||||
|
||||
@@ -79,9 +79,11 @@ public class ComplexPolyphaseChannelizerM2 extends AbstractComplexPolyphaseChann
|
||||
private static final int MAXIMUM_QUEUED_BATCHES = 50;
|
||||
|
||||
/**
|
||||
* Maximum batch sample arrays held for reuse: the queued IFFT batches plus the batches queued for channel output.
|
||||
* Maximum batch sample arrays held for reuse: the queued IFFT batches plus the batch being filled and the batch
|
||||
* being transformed. Channel output processors copy their channels from a batch instead of retaining it, so no
|
||||
* other batches are held.
|
||||
*/
|
||||
private static final int MAXIMUM_POOLED_BATCHES = 2 * MAXIMUM_QUEUED_BATCHES;
|
||||
private static final int MAXIMUM_POOLED_BATCHES = MAXIMUM_QUEUED_BATCHES + 2;
|
||||
|
||||
//Sized to process 40 times per second
|
||||
private IFFTProcessorDispatcher mIFFTProcessorDispatcher = new IFFTProcessorDispatcher(25);
|
||||
|
||||
@@ -68,7 +68,12 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
private final static Logger mLog = LoggerFactory.getLogger(PolyphaseChannelManager.class);
|
||||
private static final double CHANNEL_OVERSAMPLING = 2.0;
|
||||
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 TunerController mTunerController;
|
||||
@@ -78,7 +83,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
private ComplexPolyphaseChannelizerM2 mPolyphaseChannelizer;
|
||||
private ChannelSourceEventListener mChannelSourceEventListener = new ChannelSourceEventListener();
|
||||
private NativeBufferReceiver mNativeBufferReceiver = new NativeBufferReceiver();
|
||||
private Dispatcher mBufferDispatcher;
|
||||
private Dispatcher<INativeBuffer> mBufferDispatcher;
|
||||
private boolean mRunning = true;
|
||||
|
||||
/**
|
||||
@@ -99,10 +104,21 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
|
||||
mChannelCalculator = new ChannelCalculator(tunerController.getSampleRate(), channelCount,
|
||||
tunerController.getFrequency(), CHANNEL_OVERSAMPLING);
|
||||
mBufferDispatcher = new Dispatcher("sdrtrunk polyphase buffer processor", 10, MAXIMUM_QUEUED_NATIVE_BUFFERS);
|
||||
mBufferDispatcher = new Dispatcher<>("sdrtrunk polyphase buffer processor", 10, INativeBuffer::sampleCount,
|
||||
getMaximumQueuedSamples(tunerController.getSampleRate()));
|
||||
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.
|
||||
*/
|
||||
@@ -278,6 +294,7 @@ public class PolyphaseChannelManager implements ISourceEventProcessor
|
||||
double sampleRate = sourceEvent.getValue().doubleValue();
|
||||
int channelCount = ComplexPolyphaseChannelizerM2.getChannelCount(sampleRate);
|
||||
mChannelCalculator.setRates(sampleRate, channelCount);
|
||||
mBufferDispatcher.setMaximumQueuedWeight(getMaximumQueuedSamples(sampleRate));
|
||||
break;
|
||||
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_LOCKED:
|
||||
case NOTIFICATION_FREQUENCY_AND_SAMPLE_RATE_UNLOCKED:
|
||||
|
||||
@@ -180,7 +180,8 @@ public class PolyphaseChannelSource extends TunerChannelSource implements Listen
|
||||
/**
|
||||
* Performs the output processor update. This method must be invoked on the channel results calling thread so that
|
||||
* replacing the output processor doesn't overlap with delivery of channel results to it. The output processor
|
||||
* applies the configuration changes on its own dispatcher thread.
|
||||
* applies channel index changes as it copies the next batch, and applies mixer and filter changes on its own
|
||||
* dispatcher thread at that same batch.
|
||||
* @param channelCalculator for updates
|
||||
* @param filterManager for updates
|
||||
* @throws IllegalArgumentException if there's an issue.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -24,6 +24,7 @@ import io.github.dsheirer.sample.complex.ComplexSamples;
|
||||
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
|
||||
import io.github.dsheirer.util.Dispatcher;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.slf4j.Logger;
|
||||
@@ -34,12 +35,20 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
||||
private final static Logger mLog = LoggerFactory.getLogger(ChannelOutputProcessor.class);
|
||||
|
||||
/**
|
||||
* Maximum queued channel results batches, about one second of samples. A full batch is dropped when this channel
|
||||
* Maximum queued channel sample batches, about one second of samples. A full batch is dropped when this channel
|
||||
* falls behind, which preserves the even-sized batch block parity that two-channel synthesis relies on.
|
||||
*/
|
||||
private static final int MAXIMUM_QUEUED_BATCHES = 50;
|
||||
|
||||
private Dispatcher<QueuedChannelResults> mChannelResultsDispatcher;
|
||||
/**
|
||||
* Maximum channel sample arrays held for reuse: the queued batches plus the batch being processed and the batch
|
||||
* being copied.
|
||||
*/
|
||||
private static final int MAXIMUM_POOLED_ARRAYS = MAXIMUM_QUEUED_BATCHES + 2;
|
||||
|
||||
private Dispatcher<QueuedChannelSamples> mChannelSamplesDispatcher;
|
||||
private final Queue<float[]> mSamplePool = new ArrayBlockingQueue<>(MAXIMUM_POOLED_ARRAYS);
|
||||
private volatile int[] mChannelOffsets = new int[0];
|
||||
private final Queue<PendingUpdate> mPendingUpdates = new ConcurrentLinkedQueue<>();
|
||||
private final AtomicLong mBatchSequence = new AtomicLong();
|
||||
private HeartbeatManager mHeartbeatManager;
|
||||
@@ -60,25 +69,45 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
||||
mInputChannelCount = inputChannelCount;
|
||||
//Process 1/10th of the sample rate per second at a rate of 20 times a second (200% of anticipated rate)
|
||||
mHeartbeatManager = heartbeatManager;
|
||||
mChannelResultsDispatcher = new Dispatcher(threadName,50, mHeartbeatManager, MAXIMUM_QUEUED_BATCHES);
|
||||
mChannelResultsDispatcher.setListener(queued -> {
|
||||
mChannelSamplesDispatcher = new Dispatcher<>(threadName,50, mHeartbeatManager, MAXIMUM_QUEUED_BATCHES);
|
||||
mChannelSamplesDispatcher.setListener(queued -> {
|
||||
try
|
||||
{
|
||||
applyPendingUpdates(queued.sequence());
|
||||
mCurrentSampleTimestamp = queued.channelResults().getTimestamp();
|
||||
process(queued.channelResults());
|
||||
mCurrentSampleTimestamp = queued.timestamp();
|
||||
process(queued.samples(), queued.blockCount());
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
mLog.error("Error processing channel results", t);
|
||||
mLog.error("Error processing channel samples", t);
|
||||
}
|
||||
finally
|
||||
{
|
||||
queued.channelResults().release();
|
||||
mSamplePool.offer(queued.samples());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the I/Q offsets within each channel results block for the polyphase channel(s) that this processor copies.
|
||||
* The offsets take effect at the first channel results batch received after this method is invoked, the same as a
|
||||
* change queued with enqueueUpdate(), so a change of offsets and of the mixer frequency apply to the same batch.
|
||||
* This should only be invoked on the thread that delivers channel results, or before results are delivered.
|
||||
* @param offsets for each polyphase channel, which is twice the channel index.
|
||||
*/
|
||||
protected void setChannelOffsets(int... offsets)
|
||||
{
|
||||
mChannelOffsets = offsets.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Current I/Q offsets within each channel results block for the polyphase channel(s) that this processor copies.
|
||||
*/
|
||||
protected int[] getChannelOffsets()
|
||||
{
|
||||
return mChannelOffsets.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a configuration change to apply on the dispatcher thread, so that configuration changes don't overlap with
|
||||
* sample processing. The change takes effect at the first channel results batch received after this method is
|
||||
@@ -119,13 +148,13 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
||||
@Override
|
||||
public void start()
|
||||
{
|
||||
mChannelResultsDispatcher.start();
|
||||
mChannelSamplesDispatcher.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop()
|
||||
{
|
||||
mChannelResultsDispatcher.stop();
|
||||
mChannelSamplesDispatcher.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,22 +176,66 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies this processor's polyphase channel(s) from the channel results batch and queues the copy for processing on
|
||||
* the dispatcher thread. The copy is small (about 8 kB per polyphase channel for a 1024 block batch), so the batch
|
||||
* isn't retained beyond this method and its large shared sample array returns to the channelizer's pool as soon as
|
||||
* the channelizer has dispatched it to every channel. A slow channel then queues only its own samples.
|
||||
*
|
||||
* @param channelResults batch to copy from
|
||||
*/
|
||||
@Override
|
||||
public void receiveChannelResults(ChannelResultsBatch channelResults)
|
||||
{
|
||||
channelResults.retain();
|
||||
long sequence = mBatchSequence.incrementAndGet();
|
||||
|
||||
if(!mChannelResultsDispatcher.offer(new QueuedChannelResults(channelResults, mBatchSequence.incrementAndGet())))
|
||||
if(!mChannelSamplesDispatcher.isRunning())
|
||||
{
|
||||
channelResults.release();
|
||||
return;
|
||||
}
|
||||
|
||||
int[] offsets = mChannelOffsets;
|
||||
float[] source = channelResults.getSamples();
|
||||
int blockLength = channelResults.getBlockLength();
|
||||
int blockCount = channelResults.getBlockCount();
|
||||
float[] samples = getPooledArray(blockCount * offsets.length * 2);
|
||||
int pointer = 0;
|
||||
|
||||
for(int block = 0; block < blockCount; block++)
|
||||
{
|
||||
int blockOffset = block * blockLength;
|
||||
|
||||
for(int offset : offsets)
|
||||
{
|
||||
samples[pointer++] = source[blockOffset + offset];
|
||||
samples[pointer++] = source[blockOffset + offset + 1];
|
||||
}
|
||||
}
|
||||
|
||||
if(!mChannelSamplesDispatcher.offer(new QueuedChannelSamples(samples, blockCount, channelResults.getTimestamp(),
|
||||
sequence)))
|
||||
{
|
||||
mSamplePool.offer(samples);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub-class implementation to process one polyphase channelizer results batch.
|
||||
* @param channelResults to process
|
||||
* Provides a reused sample array of the requested length when one is available, or a new array.
|
||||
*/
|
||||
public abstract void process(ChannelResultsBatch channelResults);
|
||||
private float[] getPooledArray(int length)
|
||||
{
|
||||
float[] samples = mSamplePool.poll();
|
||||
return samples != null && samples.length == length ? samples : new float[length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub-class implementation to process one batch of copied channel samples.
|
||||
* @param samples for each block in order, with the I/Q pair of each polyphase channel in the order of the channel
|
||||
* offsets, for example I1,Q1,I2,Q2 per block for two channels.
|
||||
* @param blockCount number of blocks. Batches start on an even block index, so the index of a block within this
|
||||
* batch has the same parity as its absolute block index.
|
||||
*/
|
||||
public abstract void process(float[] samples, int blockCount);
|
||||
|
||||
@Override
|
||||
public int getInputChannelCount()
|
||||
@@ -171,9 +244,10 @@ public abstract class ChannelOutputProcessor implements IPolyphaseChannelOutputP
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel results batch and its position in the sequence of received batches.
|
||||
* Copied channel samples with the timestamp of the batch they were copied from and the batch's position in the
|
||||
* sequence of received batches.
|
||||
*/
|
||||
private record QueuedChannelResults(ChannelResultsBatch channelResults, long sequence) {}
|
||||
private record QueuedChannelSamples(float[] samples, int blockCount, long timestamp, long sequence) {}
|
||||
|
||||
/**
|
||||
* Configuration change and the sequence number of the last batch received before the change was requested.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package io.github.dsheirer.dsp.filter.channelizer.output;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.channelizer.ChannelResultsBatch;
|
||||
import io.github.dsheirer.sample.complex.ComplexSamples;
|
||||
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,7 +29,6 @@ public class OneChannelOutputProcessor extends ChannelOutputProcessor
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(OneChannelOutputProcessor.class);
|
||||
private final OneChannelMixerAssembler mMixerAssembler;
|
||||
private int mChannelOffset;
|
||||
|
||||
/**
|
||||
* Processor to extract a single channel from a polyphase channelizer and produce an output I/Q complex sample
|
||||
@@ -55,7 +54,7 @@ public class OneChannelOutputProcessor extends ChannelOutputProcessor
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("One Channel Output Processor");
|
||||
sb.append("\n\tIndex (doubled) [").append(mChannelOffset).append("]");
|
||||
sb.append("\n\tIndex (doubled) ").append(Arrays.toString(getChannelOffsets()));
|
||||
sb.append("\n\tMixer Assembler: none");
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -81,8 +80,7 @@ public class OneChannelOutputProcessor extends ChannelOutputProcessor
|
||||
|
||||
//Set the channelized output results offset to twice the channel index to account for each channel having
|
||||
//an I/Q pair
|
||||
int channelOffset = indexes.get(0) * 2;
|
||||
enqueueUpdate(() -> mChannelOffset = channelOffset);
|
||||
setChannelOffsets(indexes.get(0) * 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,19 +90,18 @@ public class OneChannelOutputProcessor extends ChannelOutputProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the channel from the channel results array and pass to the assembler. The assembler will
|
||||
* apply frequency translation and gain and indicate when a buffer is fully assembled.
|
||||
* Passes the copied channel samples to the assembler. The assembler will apply frequency translation and gain and
|
||||
* indicate when a buffer is fully assembled.
|
||||
*
|
||||
* @param channelResults to process containing blocks of channel I/Q sample pairs (I0,Q0,I1,Q1...In,Qn)
|
||||
* @param samples containing an I/Q pair for each block (I0,Q0,I1,Q1...In,Qn)
|
||||
* @param blockCount number of blocks
|
||||
*/
|
||||
@Override
|
||||
public void process(ChannelResultsBatch channelResults)
|
||||
public void process(float[] samples, int blockCount)
|
||||
{
|
||||
float[] samples = channelResults.getSamples();
|
||||
int blockLength = channelResults.getBlockLength();
|
||||
int channelOffset = mChannelOffset;
|
||||
int length = blockCount * 2;
|
||||
|
||||
for(int index = channelOffset; index < samples.length; index += blockLength)
|
||||
for(int index = 0; index < length; index += 2)
|
||||
{
|
||||
mMixerAssembler.receive(samples[index], samples[index + 1]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package io.github.dsheirer.dsp.filter.channelizer.output;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.channelizer.ChannelResultsBatch;
|
||||
import io.github.dsheirer.sample.complex.ComplexSamples;
|
||||
import io.github.dsheirer.source.heartbeat.HeartbeatManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,8 +29,6 @@ public class TwoChannelOutputProcessor extends ChannelOutputProcessor
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(TwoChannelOutputProcessor.class);
|
||||
private TwoChannelMixerAssembler mMixerAssembler;
|
||||
private int mChannelOffset1;
|
||||
private int mChannelOffset2;
|
||||
|
||||
/**
|
||||
* Processor to extract two channels from a polyphase channelizer, synthesize/recombine the channels, apply
|
||||
@@ -60,7 +58,7 @@ public class TwoChannelOutputProcessor extends ChannelOutputProcessor
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Two Channel Output Processor");
|
||||
sb.append("\n\tIndices (doubled) 1 [").append(mChannelOffset1).append("] 2 [").append(mChannelOffset2).append("]");
|
||||
sb.append("\n\tIndices (doubled) ").append(Arrays.toString(getChannelOffsets()));
|
||||
sb.append("\n\tMixer Assembler: ").append(mMixerAssembler.getStateDescription());
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -98,45 +96,32 @@ public class TwoChannelOutputProcessor extends ChannelOutputProcessor
|
||||
|
||||
//Set the channelized output results offsets to twice the channel index to account for each channel having
|
||||
//an I/Q pair
|
||||
int channelOffset1 = indexes.get(0) * 2;
|
||||
int channelOffset2 = indexes.get(1) * 2;
|
||||
|
||||
enqueueUpdate(() -> {
|
||||
mChannelOffset1 = channelOffset1;
|
||||
mChannelOffset2 = channelOffset2;
|
||||
});
|
||||
setChannelOffsets(indexes.get(0) * 2, indexes.get(1) * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the channel from the channel results array, apply frequency translation, and deliver the
|
||||
* extracted frequency-corrected channel I/Q sample set to the complex sample listener.
|
||||
* Synthesizes the two copied channels, applies frequency translation, and delivers the frequency-corrected channel
|
||||
* I/Q sample set to the complex sample listener.
|
||||
*
|
||||
* @param channelResults to process containing blocks of channel I/Q sample pairs (I0,Q0,I1,Q1...In,Qn)
|
||||
* @param samples containing an I/Q pair for each of the two channels per block (I1,Q1,I2,Q2 ...)
|
||||
* @param blockCount number of blocks
|
||||
*/
|
||||
@Override
|
||||
public void process(ChannelResultsBatch channelResults)
|
||||
public void process(float[] samples, int blockCount)
|
||||
{
|
||||
float[] samples = channelResults.getSamples();
|
||||
int blockLength = channelResults.getBlockLength();
|
||||
int blockCount = channelResults.getBlockCount();
|
||||
int channelOffset1 = mChannelOffset1;
|
||||
int channelOffset2 = mChannelOffset2;
|
||||
|
||||
//Translate channel 2 up by FS/2 (multiply by (-1)^n) so that it sits adjacent to channel 1 for synthesis. The
|
||||
//channelizer dispatches even-sized batches, so the index within the batch carries the absolute block parity.
|
||||
for(int x = 0; x < blockCount; x++)
|
||||
{
|
||||
int block = x * blockLength;
|
||||
int block = x * 4;
|
||||
|
||||
if((x & 1) == 0)
|
||||
{
|
||||
mMixerAssembler.receive(samples[block + channelOffset1], samples[block + channelOffset1 + 1],
|
||||
samples[block + channelOffset2], samples[block + channelOffset2 + 1]);
|
||||
mMixerAssembler.receive(samples[block], samples[block + 1], samples[block + 2], samples[block + 3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMixerAssembler.receive(samples[block + channelOffset1], samples[block + channelOffset1 + 1],
|
||||
-samples[block + channelOffset2], -samples[block + channelOffset2 + 1]);
|
||||
mMixerAssembler.receive(samples[block], samples[block + 1], -samples[block + 2], -samples[block + 3]);
|
||||
}
|
||||
|
||||
if(mMixerAssembler.hasBuffer())
|
||||
|
||||
@@ -42,6 +42,7 @@ public class DcRemovalFilterFactory
|
||||
case VECTOR_SIMD_PREFERRED:
|
||||
return new VectorDcRemovalFilter(gain);
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarDcRemovalFilter(gain);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class FmDemodulatorFactory
|
||||
case VECTOR_SIMD_512:
|
||||
return new VectorFMDemodulator512();
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarFMDemodulator();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ComplexGainFactory
|
||||
return new VectorComplexGainControl();
|
||||
}
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ComplexGainControl();
|
||||
}
|
||||
@@ -64,6 +65,7 @@ public class ComplexGainFactory
|
||||
return new VectorComplexGain(gain);
|
||||
}
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarComplexGain(gain);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class MagnitudeFactory
|
||||
case VECTOR_SIMD_512:
|
||||
return new VectorMagnitudeCalculator512();
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarMagnitudeCalculator();
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class ComplexMixerFactory
|
||||
return new VectorComplexMixer(frequency, sampleRate);
|
||||
}
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
{
|
||||
return new ScalarComplexMixer(frequency, sampleRate);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class OscillatorFactory
|
||||
case VECTOR_SIMD_PREFERRED:
|
||||
return new VectorRealOscillator(frequency, sampleRate);
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarRealOscillator(frequency, sampleRate);
|
||||
}
|
||||
@@ -69,6 +70,7 @@ public class OscillatorFactory
|
||||
case VECTOR_SIMD_PREFERRED:
|
||||
return new VectorComplexOscillator(frequency, sampleRate);
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new ScalarComplexOscillator(frequency, sampleRate);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ public class DifferentialDemodulatorFactory
|
||||
case VECTOR_SIMD_128 -> new DifferentialDemodulatorFloatVector128(sampleRate, symbolRate);
|
||||
case VECTOR_SIMD_256 -> new DifferentialDemodulatorFloatVector256(sampleRate, symbolRate);
|
||||
case VECTOR_SIMD_512 -> new DifferentialDemodulatorFloatVector512(sampleRate, symbolRate);
|
||||
default -> new DifferentialDemodulatorFloatScalar(sampleRate, symbolRate); //Includes SCALAR case
|
||||
case SCALAR, UNCALIBRATED -> new DifferentialDemodulatorFloatScalar(sampleRate, symbolRate);
|
||||
default -> new DifferentialDemodulatorFloatScalar(sampleRate, symbolRate);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
255
src/main/java/io/github/dsheirer/gui/ApplicationIcons.java
Normal file
255
src/main/java/io/github/dsheirer/gui/ApplicationIcons.java
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Taskbar;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* sdrtrunk application icon for Swing frames and dialogs, JavaFX stages and the macOS Dock.
|
||||
*
|
||||
* Call installSwing() once at startup and installJavaFx() once the JavaFX toolkit is running. After that, each
|
||||
* window that opens without its own icon gets the sdrtrunk icon, so individual windows don't have to set it.
|
||||
*/
|
||||
public final class ApplicationIcons
|
||||
{
|
||||
private static final Logger mLog = LoggerFactory.getLogger(ApplicationIcons.class);
|
||||
private static final String RESOURCE_PATTERN = "/images/sdrtrunk/sdrtrunk-icon-%d.png";
|
||||
private static final int[] SIZES = {16, 24, 32, 48, 64, 128, 256, 512};
|
||||
private static final int TASKBAR_SIZE = 512;
|
||||
|
||||
private static List<Image> sAwtImages;
|
||||
private static List<javafx.scene.image.Image> sFxImages;
|
||||
private static boolean sSwingInstalled;
|
||||
private static boolean sJavaFxInstalled;
|
||||
|
||||
private ApplicationIcons()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Application icon in each available size, smallest first, for Swing/AWT windows.
|
||||
* @return images, or an empty list if the icon resources can't be loaded.
|
||||
*/
|
||||
public static synchronized List<Image> getAwtImages()
|
||||
{
|
||||
if(sAwtImages == null)
|
||||
{
|
||||
List<Image> images = new ArrayList<>();
|
||||
|
||||
for(int size: SIZES)
|
||||
{
|
||||
String path = String.format(RESOURCE_PATTERN, size);
|
||||
|
||||
try(InputStream in = ApplicationIcons.class.getResourceAsStream(path))
|
||||
{
|
||||
if(in != null)
|
||||
{
|
||||
Image image = ImageIO.read(in);
|
||||
|
||||
if(image != null)
|
||||
{
|
||||
images.add(image);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.warn("Application icon resource not found [" + path + "]");
|
||||
}
|
||||
}
|
||||
catch(IOException ioe)
|
||||
{
|
||||
mLog.warn("Unable to load application icon [" + path + "]", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
sAwtImages = Collections.unmodifiableList(images);
|
||||
}
|
||||
|
||||
return sAwtImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Application icon in each available size, smallest first, for JavaFX stages.
|
||||
* @return images, or an empty list if the icon resources can't be loaded.
|
||||
*/
|
||||
public static synchronized List<javafx.scene.image.Image> getFxImages()
|
||||
{
|
||||
if(sFxImages == null)
|
||||
{
|
||||
List<javafx.scene.image.Image> images = new ArrayList<>();
|
||||
|
||||
for(int size: SIZES)
|
||||
{
|
||||
String path = String.format(RESOURCE_PATTERN, size);
|
||||
|
||||
try(InputStream in = ApplicationIcons.class.getResourceAsStream(path))
|
||||
{
|
||||
if(in != null)
|
||||
{
|
||||
javafx.scene.image.Image image = new javafx.scene.image.Image(in);
|
||||
|
||||
if(!image.isError())
|
||||
{
|
||||
images.add(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException ioe)
|
||||
{
|
||||
mLog.warn("Unable to load application icon [" + path + "]", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
sFxImages = Collections.unmodifiableList(images);
|
||||
}
|
||||
|
||||
return sFxImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application icon on the Swing/AWT window if it doesn't already have one.
|
||||
*/
|
||||
public static void apply(java.awt.Window window)
|
||||
{
|
||||
if(window != null && window.getIconImages().isEmpty() && !getAwtImages().isEmpty())
|
||||
{
|
||||
window.setIconImages(getAwtImages());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application icon on the JavaFX stage if it doesn't already have one. Call on the FX thread.
|
||||
*/
|
||||
public static void apply(Stage stage)
|
||||
{
|
||||
if(stage != null && stage.getIcons().isEmpty() && !getFxImages().isEmpty())
|
||||
{
|
||||
stage.getIcons().setAll(getFxImages());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the macOS Dock icon and gives each Swing frame and dialog that opens without an icon the application
|
||||
* icon. Safe to call more than once. Does nothing in a headless environment.
|
||||
*/
|
||||
public static synchronized void installSwing()
|
||||
{
|
||||
if(sSwingInstalled || java.awt.GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sSwingInstalled = true;
|
||||
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
|
||||
if(event.getID() == WindowEvent.WINDOW_OPENED &&
|
||||
(event.getSource() instanceof Frame || event.getSource() instanceof Dialog))
|
||||
{
|
||||
apply((java.awt.Window)event.getSource());
|
||||
}
|
||||
}, AWTEvent.WINDOW_EVENT_MASK);
|
||||
|
||||
//The Dock icon on macOS. Windows and Linux take the icon from each window instead.
|
||||
try
|
||||
{
|
||||
if(Taskbar.isTaskbarSupported() && Taskbar.getTaskbar().isSupported(Taskbar.Feature.ICON_IMAGE))
|
||||
{
|
||||
List<Image> images = getAwtImages();
|
||||
|
||||
for(int x = 0; x < SIZES.length && x < images.size(); x++)
|
||||
{
|
||||
if(SIZES[x] == TASKBAR_SIZE)
|
||||
{
|
||||
Taskbar.getTaskbar().setIconImage(images.get(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.debug("Unable to set taskbar icon", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives each JavaFX stage that shows without an icon the application icon, and closes the startup splash screen
|
||||
* if a JavaFX window opens before the main window does. Safe to call more than once. The JavaFX toolkit must
|
||||
* already be running.
|
||||
*/
|
||||
public static synchronized void installJavaFx()
|
||||
{
|
||||
if(sJavaFxInstalled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sJavaFxInstalled = true;
|
||||
|
||||
Platform.runLater(() -> {
|
||||
for(Window window: Window.getWindows())
|
||||
{
|
||||
onFxWindowShown(window);
|
||||
}
|
||||
|
||||
Window.getWindows().addListener((ListChangeListener<Window>)change -> {
|
||||
while(change.next())
|
||||
{
|
||||
for(Window window: change.getAddedSubList())
|
||||
{
|
||||
onFxWindowShown(window);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a JavaFX window that is showing.
|
||||
*/
|
||||
private static void onFxWindowShown(Window window)
|
||||
{
|
||||
//Only stages are top-level windows. JFXPanel content and popups (menus, tooltips) are other Window types.
|
||||
if(window instanceof Stage stage)
|
||||
{
|
||||
apply(stage);
|
||||
|
||||
//A JavaFX window (e.g. an error dialog) that shows before the main window would sit behind the splash.
|
||||
Splash.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,7 @@ public class JavaFxWindowManager extends Application
|
||||
{
|
||||
mJFXPanel = new JFXPanel();
|
||||
Platform.setImplicitExit(false);
|
||||
ApplicationIcons.installJavaFx();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,12 +144,28 @@ public class SDRTrunk implements Listener<TunerEvent>
|
||||
private String mTitle;
|
||||
|
||||
public SDRTrunk()
|
||||
{
|
||||
try
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
startupFailed(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and starts the application components and shows the main window.
|
||||
*/
|
||||
private void initialize()
|
||||
{
|
||||
if(!GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
//Initialize the theme manager before any Swing components are realized so the chosen
|
||||
//look-and-feel applies to the very first window that is created.
|
||||
ThemeManager.getInstance().initialize(mUserPreferences);
|
||||
ApplicationIcons.installSwing();
|
||||
mMainGui = new JFrame();
|
||||
}
|
||||
|
||||
@@ -273,6 +289,9 @@ public class SDRTrunk implements Listener<TunerEvent>
|
||||
if(!GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
mMainGui.setVisible(true);
|
||||
|
||||
//The JVM closes the splash when the first window shows. Close it here as well in case it didn't.
|
||||
Splash.close();
|
||||
Tuner tuner = tunerSpectralDisplayManager.showFirstTuner();
|
||||
|
||||
if(tuner != null)
|
||||
@@ -311,7 +330,15 @@ public class SDRTrunk implements Listener<TunerEvent>
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
if(mMainGui != null && !mMainGui.isVisible())
|
||||
{
|
||||
//The main window didn't open, so the user has no way to close the application.
|
||||
startupFailed(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLog.error("Error while starting the application", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -361,6 +388,7 @@ public class SDRTrunk implements Listener<TunerEvent>
|
||||
*/
|
||||
mTitle = SystemProperties.getInstance().getApplicationName();
|
||||
mMainGui.setTitle(mTitle);
|
||||
ApplicationIcons.apply(mMainGui);
|
||||
|
||||
Point location = mUserPreferences.getSwingPreference().getLocation(WINDOW_FRAME_IDENTIFIER);
|
||||
if(location != null)
|
||||
@@ -967,11 +995,117 @@ public class SDRTrunk implements Listener<TunerEvent>
|
||||
JOptionPane.showMessageDialog(mMainGui, message, "Duplicate Library Versions", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an error that stops the application from starting. Stops the tuners that already started, so that they
|
||||
* are released for the next start, then reports the error and exits. Without this, the threads that the
|
||||
* application started before the error keep the JVM running with no main window and the splash screen showing.
|
||||
* @param t error
|
||||
*/
|
||||
private void startupFailed(Throwable t)
|
||||
{
|
||||
mLog.error("sdrtrunk failed to start", t);
|
||||
|
||||
if(mTunerManager != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
mTunerManager.stop();
|
||||
}
|
||||
catch(Throwable t2)
|
||||
{
|
||||
mLog.error("Error stopping tuners after the startup error", t2);
|
||||
}
|
||||
}
|
||||
|
||||
String logsDirectory = null;
|
||||
|
||||
try
|
||||
{
|
||||
logsDirectory = mUserPreferences.getDirectoryPreference().getDirectoryApplicationLog().toString();
|
||||
}
|
||||
catch(Throwable t2)
|
||||
{
|
||||
//Not available - the dialog leaves out the log location
|
||||
}
|
||||
|
||||
if(mApplicationLog != null)
|
||||
{
|
||||
mApplicationLog.stop();
|
||||
}
|
||||
|
||||
exitAfterStartupError(t, logsDirectory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the splash screen, shows the startup error to the user and exits the JVM with a non-zero status.
|
||||
* @param t error
|
||||
* @param logsDirectory where the application log is, or null if not known.
|
||||
*/
|
||||
private static void exitAfterStartupError(Throwable t, String logsDirectory)
|
||||
{
|
||||
//The application log may not be running yet, so also write the error to the console.
|
||||
System.err.println("sdrtrunk failed to start");
|
||||
t.printStackTrace();
|
||||
|
||||
Splash.close();
|
||||
|
||||
if(!GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
String message = "<html><body style='width: 450px'>" +
|
||||
"<p>sdrtrunk couldn't start because of this error:</p><br>" +
|
||||
"<p><b>" + escapeHtml(String.valueOf(t)) + "</b></p><br>" +
|
||||
(logsDirectory != null ? "<p>The application log has the details:</p><p>" +
|
||||
escapeHtml(logsDirectory) + "</p><br>" : "") +
|
||||
"<p>See Help / Support on the sdrtrunk wiki for help.</p>" +
|
||||
"</body></html>";
|
||||
|
||||
try
|
||||
{
|
||||
Runnable dialog = () -> JOptionPane.showMessageDialog(null, message, "sdrtrunk Startup Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
if(EventQueue.isDispatchThread())
|
||||
{
|
||||
dialog.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
EventQueue.invokeAndWait(dialog);
|
||||
}
|
||||
}
|
||||
catch(Throwable t2)
|
||||
{
|
||||
t2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes text for display in a Swing HTML label.
|
||||
*/
|
||||
private static String escapeHtml(String text)
|
||||
{
|
||||
return text.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new SDRTrunk();
|
||||
String version = SDRTrunk.class.getPackage().getImplementationVersion();
|
||||
Splash.showVersion(version != null ? "v" + version : null);
|
||||
|
||||
try
|
||||
{
|
||||
new SDRTrunk();
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
//An error creating the SDRTrunk fields, before the constructor's own startup error handling runs.
|
||||
exitAfterStartupError(t, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
117
src/main/java/io/github/dsheirer/gui/Splash.java
Normal file
117
src/main/java/io/github/dsheirer/gui/Splash.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.SplashScreen;
|
||||
|
||||
/**
|
||||
* Startup splash screen.
|
||||
*
|
||||
* The JVM shows the splash image named by the -splash:path option (set by the launch scripts) before any application
|
||||
* code runs, and closes it when the main window becomes visible. This class draws the version on the splash and lets
|
||||
* the application close the splash early, for example when a dialog has to show before the main window.
|
||||
*
|
||||
* Headless operation: the java launcher doesn't show the splash when -Djava.awt.headless=true is on the command line
|
||||
* (for example in JAVA_OPTS or SDR_TRUNK_OPTS), and there is nothing to show it on without a display. This class does
|
||||
* nothing when headless.
|
||||
*/
|
||||
public final class Splash
|
||||
{
|
||||
//Splash image layout, in pixels of the 640 x 360 image. The version goes under the tagline.
|
||||
private static final double IMAGE_WIDTH = 640.0;
|
||||
private static final double VERSION_X = 214.0;
|
||||
private static final double VERSION_Y = 232.0;
|
||||
private static final double VERSION_FONT_SIZE = 13.0;
|
||||
private static final Color VERSION_COLOR = new Color(0x2E, 0xE6, 0xA6);
|
||||
|
||||
private Splash()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the version text on the splash screen, if a splash screen is showing.
|
||||
* @param version to show, for example "v1.0.1", or null to leave the splash unchanged.
|
||||
*/
|
||||
public static void showVersion(String version)
|
||||
{
|
||||
if(version == null || version.isBlank() || GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SplashScreen splash = SplashScreen.getSplashScreen();
|
||||
|
||||
if(splash == null || !splash.isVisible())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Overlay coordinates are in the splash's size, which can differ from the image (HiDPI @2x image).
|
||||
Dimension size = splash.getSize();
|
||||
double scale = size.width / IMAGE_WIDTH;
|
||||
|
||||
Graphics2D g = splash.createGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setColor(VERSION_COLOR);
|
||||
g.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int)Math.round(VERSION_FONT_SIZE * scale)));
|
||||
g.drawString(version, (float)(VERSION_X * scale), (float)(VERSION_Y * scale));
|
||||
g.dispose();
|
||||
splash.update();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//The splash is cosmetic. Never let it stop the application from starting.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the splash screen if it is still showing.
|
||||
*/
|
||||
public static void close()
|
||||
{
|
||||
if(GraphicsEnvironment.isHeadless())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SplashScreen splash = SplashScreen.getSplashScreen();
|
||||
|
||||
if(splash != null && splash.isVisible())
|
||||
{
|
||||
splash.close();
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//The splash is cosmetic. Never let it stop the application from starting.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,678 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.control;
|
||||
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.LongConsumer;
|
||||
import javafx.animation.KeyFrame;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.animation.Timeline;
|
||||
import javafx.application.Platform;
|
||||
import javafx.css.PseudoClass;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.AccessibleRole;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.SeparatorMenuItem;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.util.Duration;
|
||||
|
||||
/**
|
||||
* Frequency display and tuning control that shows a frequency in MHz with six fractional digits (1 Hz).
|
||||
*
|
||||
* Mouse: hover over a digit to reveal its up/down halves. Click the upper half to increment the digit or the lower
|
||||
* half to decrement it (hold the button to repeat), or use the scroll wheel over the digit. Steps carry into the
|
||||
* higher digits and stop at the minimum/maximum frequency.
|
||||
*
|
||||
* Keyboard: left/right move the digit cursor, up/down (or +/-) step the digit under the cursor. Typing digits
|
||||
* starts a calculator style entry (e.g. 851.0125) that is applied with Enter and cancelled with Escape. Shortcut-C
|
||||
* and Shortcut-V copy and paste the frequency.
|
||||
*
|
||||
* The control only reports user requested frequencies to the listeners. {@link #setFrequency(long)} updates the
|
||||
* display without notifying them, which is how the tuner reports its actual frequency back to the control.
|
||||
*/
|
||||
public class FrequencyControl extends HBox implements ISourceEventProcessor
|
||||
{
|
||||
private static final PseudoClass HOVER_UP = PseudoClass.getPseudoClass("hover-up");
|
||||
private static final PseudoClass HOVER_DOWN = PseudoClass.getPseudoClass("hover-down");
|
||||
private static final PseudoClass LEADING = PseudoClass.getPseudoClass("leading");
|
||||
private static final PseudoClass CURSOR = PseudoClass.getPseudoClass("cursor");
|
||||
private static final PseudoClass ENTRY = PseudoClass.getPseudoClass("entry");
|
||||
private static final PseudoClass TYPED = PseudoClass.getPseudoClass("typed");
|
||||
private static final PseudoClass INVALID = PseudoClass.getPseudoClass("invalid");
|
||||
private static final Duration REPEAT_DELAY = Duration.millis(400);
|
||||
private static final Duration REPEAT_INTERVAL = Duration.millis(70);
|
||||
|
||||
private final List<LongConsumer> mListeners = new CopyOnWriteArrayList<>();
|
||||
private final Digit[] mDigits = new Digit[FrequencyEntry.DIGIT_COUNT];
|
||||
private final FrequencyEntry.TypedEntry mTypedEntry = new FrequencyEntry.TypedEntry();
|
||||
private final Text mProbe = new Text("0");
|
||||
private final Label mUnitLabel = new Label("MHz");
|
||||
private final Tooltip mTooltip = new Tooltip();
|
||||
private final PauseTransition mInvalidFlash = new PauseTransition(Duration.millis(1200));
|
||||
private final Timeline mRepeat = new Timeline();
|
||||
private long mFrequency;
|
||||
private long mMinimum = 1;
|
||||
private long mMaximum = FrequencyEntry.MAXIMUM_DISPLAYABLE;
|
||||
private int mCursorPosition = FrequencyEntry.FRACTION_DIGITS;
|
||||
private double mScrollAccumulator;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public FrequencyControl()
|
||||
{
|
||||
getStyleClass().add("frequency-control");
|
||||
URL stylesheet = FrequencyControl.class.getResource("/frequency_control.css");
|
||||
|
||||
if(stylesheet != null)
|
||||
{
|
||||
getStylesheets().add(stylesheet.toExternalForm());
|
||||
}
|
||||
|
||||
setAlignment(Pos.CENTER_LEFT);
|
||||
setFocusTraversable(true);
|
||||
setAccessibleRole(AccessibleRole.SPINNER);
|
||||
setMaxWidth(Region.USE_PREF_SIZE);
|
||||
|
||||
//Invisible probe text, styled like the digits, sizes every digit cell to the same width so that a
|
||||
//proportional font doesn't make the display jitter as the digits change.
|
||||
mProbe.getStyleClass().add("frequency-digit-text");
|
||||
mProbe.setManaged(false);
|
||||
mProbe.setVisible(false);
|
||||
getChildren().add(mProbe);
|
||||
|
||||
for(int position = FrequencyEntry.DIGIT_COUNT - 1; position >= 0; position--)
|
||||
{
|
||||
Digit digit = new Digit(position);
|
||||
mDigits[position] = digit;
|
||||
getChildren().add(digit);
|
||||
|
||||
if(position == FrequencyEntry.FRACTION_DIGITS)
|
||||
{
|
||||
Text point = new Text(".");
|
||||
point.getStyleClass().addAll("frequency-digit-text", "frequency-point");
|
||||
getChildren().add(point);
|
||||
}
|
||||
else if(position % 3 == 0 && position > 0)
|
||||
{
|
||||
Region gap = new Region();
|
||||
gap.getStyleClass().add("frequency-group-gap");
|
||||
getChildren().add(gap);
|
||||
}
|
||||
}
|
||||
|
||||
mUnitLabel.getStyleClass().add("frequency-unit");
|
||||
getChildren().add(mUnitLabel);
|
||||
|
||||
Tooltip.install(this, mTooltip);
|
||||
updateTooltip();
|
||||
|
||||
mInvalidFlash.setOnFinished(e -> pseudoClassStateChanged(INVALID, false));
|
||||
mRepeat.setCycleCount(Timeline.INDEFINITE);
|
||||
|
||||
addEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
|
||||
addEventHandler(KeyEvent.KEY_TYPED, this::keyTyped);
|
||||
addEventHandler(MouseEvent.MOUSE_PRESSED, e -> requestFocus());
|
||||
focusedProperty().addListener((observable, wasFocused, focused) -> {
|
||||
if(!focused)
|
||||
{
|
||||
cancelEntry();
|
||||
}
|
||||
updateDigits();
|
||||
});
|
||||
disabledProperty().addListener((observable, wasDisabled, disabled) -> {
|
||||
if(disabled)
|
||||
{
|
||||
stopRepeat();
|
||||
cancelEntry();
|
||||
}
|
||||
});
|
||||
|
||||
setOnContextMenuRequested(e -> {
|
||||
buildContextMenu().show(this, e.getScreenX(), e.getScreenY());
|
||||
e.consume();
|
||||
});
|
||||
|
||||
updateDigits();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener to be notified of frequencies requested by the user. Listeners are invoked on the JavaFX
|
||||
* application thread.
|
||||
*/
|
||||
public void addListener(LongConsumer listener)
|
||||
{
|
||||
if(listener != null && !mListeners.contains(listener))
|
||||
{
|
||||
mListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the listener.
|
||||
*/
|
||||
public void removeListener(LongConsumer listener)
|
||||
{
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all listeners.
|
||||
*/
|
||||
public void clearListeners()
|
||||
{
|
||||
mListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Current frequency in Hertz.
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
return mFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the displayed frequency without notifying listeners. Safe to call from any thread.
|
||||
* @param frequency in Hertz
|
||||
*/
|
||||
public void setFrequency(long frequency)
|
||||
{
|
||||
if(Platform.isFxApplicationThread())
|
||||
{
|
||||
mFrequency = Math.max(0, Math.min(FrequencyEntry.MAXIMUM_DISPLAYABLE, frequency));
|
||||
updateDigits();
|
||||
}
|
||||
else
|
||||
{
|
||||
Platform.runLater(() -> setFrequency(frequency));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the range of frequencies that the user can request.
|
||||
* @param minimum frequency in Hertz
|
||||
* @param maximum frequency in Hertz
|
||||
*/
|
||||
public void setRange(long minimum, long maximum)
|
||||
{
|
||||
mMinimum = Math.max(0, Math.min(minimum, maximum));
|
||||
mMaximum = Math.min(FrequencyEntry.MAXIMUM_DISPLAYABLE, Math.max(minimum, maximum));
|
||||
updateTooltip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimum frequency that the user can request.
|
||||
*/
|
||||
public long getMinimum()
|
||||
{
|
||||
return mMinimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maximum frequency that the user can request.
|
||||
*/
|
||||
public long getMaximum()
|
||||
{
|
||||
return mMaximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives tuner frequency change notifications and shows the new frequency. Requests are not re-broadcast.
|
||||
*/
|
||||
@Override
|
||||
public void process(SourceEvent event)
|
||||
{
|
||||
if(event.getEvent() == SourceEvent.Event.NOTIFICATION_FREQUENCY_CHANGE && event.getValue() != null)
|
||||
{
|
||||
setFrequency(event.getValue().longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Digit position under the keyboard cursor.
|
||||
*/
|
||||
public int getCursorPosition()
|
||||
{
|
||||
return mCursorPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps the digit at the position and notifies listeners when the frequency changes.
|
||||
* @param position of the digit (0 = 1 Hz)
|
||||
* @param steps positive to increment, negative to decrement
|
||||
*/
|
||||
public void step(int position, int steps)
|
||||
{
|
||||
if(isDisabled() || steps == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cancelEntry();
|
||||
long stepped = FrequencyEntry.step(mFrequency, position, steps, mMinimum, mMaximum);
|
||||
request(stepped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the frequency on behalf of the user. An out of range frequency is rejected and flagged.
|
||||
* @return true if the frequency was accepted.
|
||||
*/
|
||||
public boolean request(long frequency)
|
||||
{
|
||||
if(frequency < mMinimum || frequency > mMaximum)
|
||||
{
|
||||
flagInvalid();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(frequency != mFrequency)
|
||||
{
|
||||
mFrequency = frequency;
|
||||
updateDigits();
|
||||
|
||||
for(LongConsumer listener: mListeners)
|
||||
{
|
||||
listener.accept(frequency);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if a typed entry is in progress.
|
||||
*/
|
||||
public boolean isEntryActive()
|
||||
{
|
||||
return !mTypedEntry.isEmpty();
|
||||
}
|
||||
|
||||
private void keyTyped(KeyEvent event)
|
||||
{
|
||||
if(isDisabled() || event.isShortcutDown() || event.isAltDown())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String character = event.getCharacter();
|
||||
|
||||
if(character == null || character.length() != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char c = character.charAt(0);
|
||||
|
||||
if((c >= '0' && c <= '9') || c == '.' || c == ',')
|
||||
{
|
||||
mTypedEntry.type(c);
|
||||
updateDigits();
|
||||
event.consume();
|
||||
}
|
||||
else if(c == '+' || c == '=')
|
||||
{
|
||||
step(mCursorPosition, 1);
|
||||
event.consume();
|
||||
}
|
||||
else if(c == '-')
|
||||
{
|
||||
step(mCursorPosition, -1);
|
||||
event.consume();
|
||||
}
|
||||
}
|
||||
|
||||
private void keyPressed(KeyEvent event)
|
||||
{
|
||||
if(isDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.isShortcutDown())
|
||||
{
|
||||
if(event.getCode() == KeyCode.C)
|
||||
{
|
||||
copy();
|
||||
event.consume();
|
||||
}
|
||||
else if(event.getCode() == KeyCode.V)
|
||||
{
|
||||
paste();
|
||||
event.consume();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch(event.getCode())
|
||||
{
|
||||
case LEFT, KP_LEFT -> moveCursor(1);
|
||||
case RIGHT, KP_RIGHT -> moveCursor(-1);
|
||||
case HOME -> setCursorPosition(FrequencyEntry.DIGIT_COUNT - 1);
|
||||
case END -> setCursorPosition(0);
|
||||
case UP, KP_UP -> step(mCursorPosition, 1);
|
||||
case DOWN, KP_DOWN -> step(mCursorPosition, -1);
|
||||
case PAGE_UP -> step(mCursorPosition, 10);
|
||||
case PAGE_DOWN -> step(mCursorPosition, -10);
|
||||
case ENTER ->
|
||||
{
|
||||
if(!commitEntry())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
case ESCAPE ->
|
||||
{
|
||||
if(!isEntryActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
cancelEntry();
|
||||
}
|
||||
case BACK_SPACE ->
|
||||
{
|
||||
if(!isEntryActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
mTypedEntry.backspace();
|
||||
updateDigits();
|
||||
}
|
||||
default ->
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the typed entry.
|
||||
* @return true if there was an entry to apply.
|
||||
*/
|
||||
private boolean commitEntry()
|
||||
{
|
||||
if(!isEntryActive())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
long frequency = mTypedEntry.getFrequency();
|
||||
mTypedEntry.clear();
|
||||
|
||||
if(!request(frequency))
|
||||
{
|
||||
updateDigits();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cancelEntry()
|
||||
{
|
||||
if(isEntryActive())
|
||||
{
|
||||
mTypedEntry.clear();
|
||||
updateDigits();
|
||||
}
|
||||
}
|
||||
|
||||
private void moveCursor(int direction)
|
||||
{
|
||||
cancelEntry();
|
||||
setCursorPosition(mCursorPosition + direction);
|
||||
}
|
||||
|
||||
private void setCursorPosition(int position)
|
||||
{
|
||||
mCursorPosition = Math.max(0, Math.min(FrequencyEntry.DIGIT_COUNT - 1, position));
|
||||
updateDigits();
|
||||
}
|
||||
|
||||
private void copy()
|
||||
{
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
content.putString(FrequencyEntry.format(mFrequency));
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
}
|
||||
|
||||
private void paste()
|
||||
{
|
||||
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
|
||||
if(clipboard.hasString())
|
||||
{
|
||||
Long frequency = FrequencyEntry.parse(clipboard.getString());
|
||||
|
||||
cancelEntry();
|
||||
|
||||
if(frequency != null)
|
||||
{
|
||||
request(frequency);
|
||||
}
|
||||
else
|
||||
{
|
||||
flagInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ContextMenu buildContextMenu()
|
||||
{
|
||||
MenuItem copy = new MenuItem("Copy Frequency");
|
||||
copy.setAccelerator(KeyCombination.keyCombination("Shortcut+C"));
|
||||
copy.setOnAction(e -> copy());
|
||||
|
||||
MenuItem paste = new MenuItem("Paste Frequency");
|
||||
paste.setAccelerator(KeyCombination.keyCombination("Shortcut+V"));
|
||||
paste.setDisable(isDisabled() || !Clipboard.getSystemClipboard().hasString());
|
||||
paste.setOnAction(e -> paste());
|
||||
|
||||
MenuItem minimum = new MenuItem("Tune to Minimum (" + FrequencyEntry.format(mMinimum) + " MHz)");
|
||||
minimum.setDisable(isDisabled());
|
||||
minimum.setOnAction(e -> request(mMinimum));
|
||||
|
||||
MenuItem maximum = new MenuItem("Tune to Maximum (" + FrequencyEntry.format(mMaximum) + " MHz)");
|
||||
maximum.setDisable(isDisabled());
|
||||
maximum.setOnAction(e -> request(mMaximum));
|
||||
|
||||
return new ContextMenu(copy, paste, new SeparatorMenuItem(), minimum, maximum);
|
||||
}
|
||||
|
||||
private void flagInvalid()
|
||||
{
|
||||
pseudoClassStateChanged(INVALID, true);
|
||||
mInvalidFlash.playFromStart();
|
||||
}
|
||||
|
||||
private void updateTooltip()
|
||||
{
|
||||
mTooltip.setText("Tuning range " + FrequencyEntry.format(mMinimum) + " - " +
|
||||
FrequencyEntry.format(mMaximum) + " MHz\n\n" +
|
||||
"Hover over a digit and use the scroll wheel, or click its upper or lower half, to step it.\n" +
|
||||
"Or type a frequency in MHz (e.g. 851.0125) and press Enter. Escape cancels.\n" +
|
||||
"Arrow keys move between digits and step the selected digit.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes every digit's value and state.
|
||||
*/
|
||||
private void updateDigits()
|
||||
{
|
||||
boolean entry = isEntryActive();
|
||||
long shown = entry ? mTypedEntry.getFrequency() : mFrequency;
|
||||
boolean focused = isFocused();
|
||||
pseudoClassStateChanged(ENTRY, entry);
|
||||
|
||||
for(Digit digit: mDigits)
|
||||
{
|
||||
int position = digit.getPosition();
|
||||
digit.setValue(FrequencyEntry.getDigit(shown, position));
|
||||
digit.pseudoClassStateChanged(LEADING, FrequencyEntry.isLeadingZero(shown, position));
|
||||
digit.pseudoClassStateChanged(TYPED, entry && mTypedEntry.isTyped(position));
|
||||
digit.pseudoClassStateChanged(CURSOR, focused && !entry && position == mCursorPosition);
|
||||
}
|
||||
|
||||
setAccessibleText(FrequencyEntry.format(mFrequency) + " MHz");
|
||||
}
|
||||
|
||||
private void stopRepeat()
|
||||
{
|
||||
mRepeat.stop();
|
||||
mRepeat.getKeyFrames().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* A single digit with up and down halves.
|
||||
*/
|
||||
private class Digit extends VBox
|
||||
{
|
||||
private final int mPosition;
|
||||
private final Text mText = new Text("0");
|
||||
private final Region mUpHalf = new Region();
|
||||
private final Region mDownHalf = new Region();
|
||||
|
||||
Digit(int position)
|
||||
{
|
||||
mPosition = position;
|
||||
getStyleClass().add("frequency-digit");
|
||||
setAlignment(Pos.CENTER);
|
||||
|
||||
Region upArrow = new Region();
|
||||
upArrow.getStyleClass().addAll("frequency-arrow", "frequency-arrow-up");
|
||||
Region downArrow = new Region();
|
||||
downArrow.getStyleClass().addAll("frequency-arrow", "frequency-arrow-down");
|
||||
|
||||
mText.getStyleClass().add("frequency-digit-text");
|
||||
|
||||
mUpHalf.getStyleClass().addAll("frequency-half", "frequency-half-up");
|
||||
mDownHalf.getStyleClass().addAll("frequency-half", "frequency-half-down");
|
||||
|
||||
StackPane cell = new StackPane(mUpHalf, mDownHalf, mText);
|
||||
cell.getStyleClass().add("frequency-digit-cell");
|
||||
StackPane.setAlignment(mUpHalf, Pos.TOP_CENTER);
|
||||
StackPane.setAlignment(mDownHalf, Pos.BOTTOM_CENTER);
|
||||
mUpHalf.maxHeightProperty().bind(cell.heightProperty().divide(2));
|
||||
mDownHalf.maxHeightProperty().bind(cell.heightProperty().divide(2));
|
||||
cell.minWidthProperty().bind(mProbe.layoutBoundsProperty().map(bounds -> bounds.getWidth() + 4));
|
||||
cell.prefWidthProperty().bind(cell.minWidthProperty());
|
||||
|
||||
//Arrow size follows the digit font size, so it scales with the user's GUI scale
|
||||
upArrow.prefWidthProperty().bind(mProbe.layoutBoundsProperty().map(bounds -> bounds.getWidth() * 0.6));
|
||||
upArrow.prefHeightProperty().bind(mProbe.layoutBoundsProperty().map(bounds -> bounds.getHeight() * 0.18));
|
||||
upArrow.maxWidthProperty().bind(upArrow.prefWidthProperty());
|
||||
upArrow.maxHeightProperty().bind(upArrow.prefHeightProperty());
|
||||
downArrow.prefWidthProperty().bind(upArrow.prefWidthProperty());
|
||||
downArrow.prefHeightProperty().bind(upArrow.prefHeightProperty());
|
||||
downArrow.maxWidthProperty().bind(upArrow.prefWidthProperty());
|
||||
downArrow.maxHeightProperty().bind(upArrow.prefHeightProperty());
|
||||
|
||||
getChildren().addAll(upArrow, cell, downArrow);
|
||||
|
||||
addEventHandler(MouseEvent.MOUSE_MOVED, e -> setHalf(e.getY() < getHeight() / 2 ? 1 : -1));
|
||||
addEventHandler(MouseEvent.MOUSE_ENTERED, e -> setHalf(e.getY() < getHeight() / 2 ? 1 : -1));
|
||||
addEventHandler(MouseEvent.MOUSE_EXITED, e -> {
|
||||
setHalf(0);
|
||||
stopRepeat();
|
||||
});
|
||||
addEventHandler(MouseEvent.MOUSE_PRESSED, this::pressed);
|
||||
addEventHandler(MouseEvent.MOUSE_RELEASED, e -> stopRepeat());
|
||||
addEventHandler(ScrollEvent.SCROLL, this::scrolled);
|
||||
}
|
||||
|
||||
int getPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
void setValue(int value)
|
||||
{
|
||||
mText.setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
private void setHalf(int half)
|
||||
{
|
||||
pseudoClassStateChanged(HOVER_UP, half > 0);
|
||||
pseudoClassStateChanged(HOVER_DOWN, half < 0);
|
||||
}
|
||||
|
||||
private void pressed(MouseEvent event)
|
||||
{
|
||||
if(event.getButton() != MouseButton.PRIMARY || isDisabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
requestFocus();
|
||||
mCursorPosition = mPosition;
|
||||
int direction = event.getY() < getHeight() / 2 ? 1 : -1;
|
||||
setHalf(direction);
|
||||
step(mPosition, direction);
|
||||
|
||||
stopRepeat();
|
||||
mRepeat.getKeyFrames().add(new KeyFrame(REPEAT_INTERVAL, e -> step(mPosition, direction)));
|
||||
mRepeat.setDelay(REPEAT_DELAY);
|
||||
mRepeat.playFromStart();
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void scrolled(ScrollEvent event)
|
||||
{
|
||||
if(isDisabled() || event.getDeltaY() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Accumulate so that high resolution (touchpad) scrolling steps once per wheel notch
|
||||
double notch = event.getMultiplierY() > 1 ? event.getMultiplierY() : 40;
|
||||
mScrollAccumulator += event.getDeltaY() / notch;
|
||||
int steps = (int)mScrollAccumulator;
|
||||
|
||||
if(steps != 0)
|
||||
{
|
||||
mScrollAccumulator -= steps;
|
||||
mCursorPosition = mPosition;
|
||||
step(mPosition, steps);
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
}
|
||||
}
|
||||
372
src/main/java/io/github/dsheirer/gui/control/FrequencyEntry.java
Normal file
372
src/main/java/io/github/dsheirer/gui/control/FrequencyEntry.java
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.control;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Frequency arithmetic for the {@link FrequencyControl}, kept free of JavaFX so that it can be unit tested.
|
||||
*
|
||||
* The control shows a frequency in MHz as a fixed number of digits: {@link #INTEGER_DIGITS} MHz digits and
|
||||
* {@link #FRACTION_DIGITS} fractional digits, so the least significant digit is 1 Hz. Digit positions are
|
||||
* numbered by their power of ten in Hertz: position 0 is the 1 Hz digit and position 9 is the 1000 MHz digit.
|
||||
*/
|
||||
public final class FrequencyEntry
|
||||
{
|
||||
/**
|
||||
* Number of MHz (integer) digits.
|
||||
*/
|
||||
public static final int INTEGER_DIGITS = 4;
|
||||
|
||||
/**
|
||||
* Number of fractional MHz digits (precision to 1 Hz).
|
||||
*/
|
||||
public static final int FRACTION_DIGITS = 6;
|
||||
|
||||
/**
|
||||
* Total number of displayed digits.
|
||||
*/
|
||||
public static final int DIGIT_COUNT = INTEGER_DIGITS + FRACTION_DIGITS;
|
||||
|
||||
/**
|
||||
* Largest frequency that fits the display: 9999.999999 MHz.
|
||||
*/
|
||||
public static final long MAXIMUM_DISPLAYABLE = 9_999_999_999L;
|
||||
|
||||
private FrequencyEntry()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Value of the digit at the position.
|
||||
* @param frequency in Hertz
|
||||
* @param position power of ten (0 = 1 Hz)
|
||||
* @return digit 0-9
|
||||
*/
|
||||
public static int getDigit(long frequency, int position)
|
||||
{
|
||||
return (int)((Math.abs(frequency) / pow10(position)) % 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the digit at the position is a leading zero, which the control shows dimmed. The 1 MHz digit is
|
||||
* never a leading zero.
|
||||
*/
|
||||
public static boolean isLeadingZero(long frequency, int position)
|
||||
{
|
||||
return position > FRACTION_DIGITS && Math.abs(frequency) < pow10(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps the frequency by a number of units of the digit position, carrying into the higher digits, and clamps
|
||||
* the result to the range. A step that would leave the range lands on the range limit.
|
||||
* @param frequency current value in Hertz
|
||||
* @param position power of ten for the digit being stepped
|
||||
* @param steps positive to increment, negative to decrement
|
||||
* @param minimum allowed frequency
|
||||
* @param maximum allowed frequency
|
||||
* @return stepped and clamped frequency
|
||||
*/
|
||||
public static long step(long frequency, int position, int steps, long minimum, long maximum)
|
||||
{
|
||||
long stepped = frequency + (steps * pow10(position));
|
||||
return clamp(stepped, minimum, maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the digit at the position with a new value, without carry.
|
||||
*/
|
||||
public static long setDigit(long frequency, int position, int digit)
|
||||
{
|
||||
long unit = pow10(position);
|
||||
int current = getDigit(frequency, position);
|
||||
return frequency + ((long)(digit - current) * unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamps the frequency to the range.
|
||||
*/
|
||||
public static long clamp(long frequency, long minimum, long maximum)
|
||||
{
|
||||
return Math.max(minimum, Math.min(maximum, frequency));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a typed or pasted frequency. A bare number is in MHz (e.g. 851.0125) unless it is too large to be MHz
|
||||
* for the display, in which case it is read as Hertz (e.g. 851012500). An optional unit suffix of Hz, kHz, MHz
|
||||
* or GHz (any case, with or without a space) overrides that. Thousands separators (comma, underscore or space)
|
||||
* are ignored.
|
||||
* @param text to parse
|
||||
* @return frequency in Hertz, or null if the text isn't a frequency or has more precision than 1 Hz.
|
||||
*/
|
||||
public static Long parse(String text)
|
||||
{
|
||||
if(text == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String value = text.trim().toLowerCase().replace(",", "").replace("_", "").replace(" ", "");
|
||||
|
||||
if(value.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
BigDecimal multiplier = null;
|
||||
|
||||
if(value.endsWith("ghz"))
|
||||
{
|
||||
multiplier = BigDecimal.valueOf(1_000_000_000L);
|
||||
value = value.substring(0, value.length() - 3);
|
||||
}
|
||||
else if(value.endsWith("mhz"))
|
||||
{
|
||||
multiplier = BigDecimal.valueOf(1_000_000L);
|
||||
value = value.substring(0, value.length() - 3);
|
||||
}
|
||||
else if(value.endsWith("khz"))
|
||||
{
|
||||
multiplier = BigDecimal.valueOf(1_000L);
|
||||
value = value.substring(0, value.length() - 3);
|
||||
}
|
||||
else if(value.endsWith("hz"))
|
||||
{
|
||||
multiplier = BigDecimal.ONE;
|
||||
value = value.substring(0, value.length() - 2);
|
||||
}
|
||||
|
||||
BigDecimal number;
|
||||
|
||||
try
|
||||
{
|
||||
number = new BigDecimal(value);
|
||||
}
|
||||
catch(NumberFormatException nfe)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(number.signum() < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if(multiplier == null)
|
||||
{
|
||||
//A whole number too large to be MHz on the display is taken as Hertz
|
||||
boolean whole = number.stripTrailingZeros().scale() <= 0;
|
||||
multiplier = (whole && number.compareTo(BigDecimal.valueOf(10_000)) >= 0) ? BigDecimal.ONE :
|
||||
BigDecimal.valueOf(1_000_000L);
|
||||
}
|
||||
|
||||
BigDecimal hertz = number.multiply(multiplier).stripTrailingZeros();
|
||||
|
||||
if(hertz.scale() > 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return hertz.longValueExact();
|
||||
}
|
||||
catch(ArithmeticException ae)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the frequency in MHz with all six fractional digits, e.g. 851.012500
|
||||
*/
|
||||
public static String format(long frequency)
|
||||
{
|
||||
return BigDecimal.valueOf(frequency, FRACTION_DIGITS).toPlainString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ten raised to the power.
|
||||
*/
|
||||
public static long pow10(int power)
|
||||
{
|
||||
long value = 1;
|
||||
|
||||
for(int x = 0; x < power; x++)
|
||||
{
|
||||
value *= 10;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculator style typed entry. Digits typed before the decimal point fill the MHz digits from the right and
|
||||
* digits typed after it fill the fractional digits from the left, so typing 851.0125 shows 851.012500.
|
||||
*/
|
||||
public static class TypedEntry
|
||||
{
|
||||
private final StringBuilder mIntegerPart = new StringBuilder();
|
||||
private final StringBuilder mFractionPart = new StringBuilder();
|
||||
private boolean mDecimal = false;
|
||||
|
||||
/**
|
||||
* Adds a typed character.
|
||||
* @param c digit or decimal point
|
||||
* @return true if the character was accepted
|
||||
*/
|
||||
public boolean type(char c)
|
||||
{
|
||||
if(c == '.' || c == ',')
|
||||
{
|
||||
if(mDecimal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
mDecimal = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(c < '0' || c > '9')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mDecimal)
|
||||
{
|
||||
if(mFractionPart.length() >= FRACTION_DIGITS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
mFractionPart.append(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Ignore leading zeros so they don't use up the MHz digits
|
||||
if(mIntegerPart.isEmpty() && c == '0')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(mIntegerPart.length() >= INTEGER_DIGITS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
mIntegerPart.append(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last typed character.
|
||||
* @return true if there is still something typed after the removal.
|
||||
*/
|
||||
public boolean backspace()
|
||||
{
|
||||
if(!mFractionPart.isEmpty())
|
||||
{
|
||||
mFractionPart.setLength(mFractionPart.length() - 1);
|
||||
}
|
||||
else if(mDecimal)
|
||||
{
|
||||
mDecimal = false;
|
||||
}
|
||||
else if(!mIntegerPart.isEmpty())
|
||||
{
|
||||
mIntegerPart.setLength(mIntegerPart.length() - 1);
|
||||
}
|
||||
|
||||
return !isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if nothing has been typed.
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return mIntegerPart.isEmpty() && mFractionPart.isEmpty() && !mDecimal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of fractional digits typed so far.
|
||||
*/
|
||||
public int getFractionDigitsTyped()
|
||||
{
|
||||
return mFractionPart.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the decimal point has been typed.
|
||||
*/
|
||||
public boolean hasDecimal()
|
||||
{
|
||||
return mDecimal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of MHz digits typed so far.
|
||||
*/
|
||||
public int getIntegerDigitsTyped()
|
||||
{
|
||||
return mIntegerPart.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Frequency for what has been typed so far.
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
long mhz = mIntegerPart.isEmpty() ? 0 : Long.parseLong(mIntegerPart.toString());
|
||||
long fraction = 0;
|
||||
|
||||
if(!mFractionPart.isEmpty())
|
||||
{
|
||||
fraction = Long.parseLong(mFractionPart.toString()) * pow10(FRACTION_DIGITS - mFractionPart.length());
|
||||
}
|
||||
|
||||
return (mhz * 1_000_000L) + fraction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the digit at the position has been typed, as opposed to an implied trailing zero.
|
||||
*/
|
||||
public boolean isTyped(int position)
|
||||
{
|
||||
if(position >= FRACTION_DIGITS)
|
||||
{
|
||||
return position - FRACTION_DIGITS < mIntegerPart.length();
|
||||
}
|
||||
|
||||
return (FRACTION_DIGITS - 1 - position) < mFractionPart.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the typed entry.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
mIntegerPart.setLength(0);
|
||||
mFractionPart.setLength(0);
|
||||
mDecimal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
111
src/main/java/io/github/dsheirer/gui/control/FrequencyField.java
Normal file
111
src/main/java/io/github/dsheirer/gui/control/FrequencyField.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.control;
|
||||
|
||||
import java.util.function.LongPredicate;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyCode;
|
||||
|
||||
/**
|
||||
* Text field for a frequency in MHz (to 1 Hz). The value is committed when the user presses Enter or leaves the
|
||||
* field. A commit handler can reject the new value, which restores the previous value. Escape reverts the text.
|
||||
*/
|
||||
public class FrequencyField extends TextField
|
||||
{
|
||||
private long mFrequency;
|
||||
private LongPredicate mCommitHandler;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param frequency initial value in Hertz
|
||||
*/
|
||||
public FrequencyField(long frequency)
|
||||
{
|
||||
getStyleClass().add("frequency-field");
|
||||
setPrefColumnCount(11);
|
||||
setFrequency(frequency);
|
||||
|
||||
setOnAction(e -> commit());
|
||||
focusedProperty().addListener((observable, wasFocused, focused) -> {
|
||||
if(!focused)
|
||||
{
|
||||
commit();
|
||||
}
|
||||
});
|
||||
setOnKeyPressed(e -> {
|
||||
if(e.getCode() == KeyCode.ESCAPE)
|
||||
{
|
||||
setText(FrequencyEntry.format(mFrequency));
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the handler for committed values. The handler returns false to reject the value.
|
||||
*/
|
||||
public void setCommitHandler(LongPredicate handler)
|
||||
{
|
||||
mCommitHandler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current frequency in Hertz.
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
return mFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the frequency without invoking the commit handler.
|
||||
*/
|
||||
public void setFrequency(long frequency)
|
||||
{
|
||||
mFrequency = frequency;
|
||||
setText(FrequencyEntry.format(frequency));
|
||||
}
|
||||
|
||||
private void commit()
|
||||
{
|
||||
Long parsed = FrequencyEntry.parse(getText());
|
||||
|
||||
if(parsed == null)
|
||||
{
|
||||
setText(FrequencyEntry.format(mFrequency));
|
||||
return;
|
||||
}
|
||||
|
||||
if(parsed == mFrequency)
|
||||
{
|
||||
setText(FrequencyEntry.format(mFrequency));
|
||||
return;
|
||||
}
|
||||
|
||||
long previous = mFrequency;
|
||||
mFrequency = parsed;
|
||||
setText(FrequencyEntry.format(parsed));
|
||||
|
||||
if(mCommitHandler != null && !mCommitHandler.test(parsed))
|
||||
{
|
||||
setFrequency(previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.gui.control;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.DocumentFilter;
|
||||
import javax.swing.text.PlainDocument;
|
||||
|
||||
/**
|
||||
* Swing text field control for entering frequency (MHz) values.
|
||||
*/
|
||||
public class FrequencyTextField extends JTextField
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FrequencyTextField.class);
|
||||
//Value range: 0.000001 to 9999.999999
|
||||
private static final String REGEX = "^[0-9]{0,4}[.]?[0-9]{0,6}$";
|
||||
//This lets users start typing a really small number like 1 Hertz ... 0.00000
|
||||
private static final String ZEROS_REGEX = "^0?([.]0{0,5})?$";
|
||||
private double mMinimum;
|
||||
private double mMaximum;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*
|
||||
* @param minimum allowable frequency value in Hertz
|
||||
* @param maximum allowable frequency value in Hertz
|
||||
* @param current frequency value in Hertz
|
||||
*/
|
||||
public FrequencyTextField(long minimum, long maximum, long current)
|
||||
{
|
||||
super(8);
|
||||
mMinimum = minimum / 1E6d;
|
||||
mMaximum = maximum / 1E6d;
|
||||
|
||||
PlainDocument document = (PlainDocument)this.getDocument();
|
||||
document.setDocumentFilter(new FrequencyFilter());
|
||||
setFrequency(current);
|
||||
}
|
||||
|
||||
/**
|
||||
* Current frequency value
|
||||
* @return frequency in Hertz
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
String value = getText();
|
||||
|
||||
if(value == null || value.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (long)(Double.parseDouble(getText()) * 1E6d);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOGGER.error("Unable to parse frequency value from text [" + value + "] " + e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current frequency value
|
||||
* @param frequency in Hertz
|
||||
*/
|
||||
public void setFrequency(long frequency)
|
||||
{
|
||||
double frequencyMHz = frequency / 1E6d;
|
||||
|
||||
if(isValid(String.valueOf(frequencyMHz)))
|
||||
{
|
||||
setText(String.valueOf(frequencyMHz));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.warn("Can't set frequency [" + frequency + "Hz / " + frequencyMHz + "MHz] with current minimum [" + mMinimum + "MHz] and maximum [" + mMaximum + "MHz] limits");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the value is a valid double value that is between the minimum and maximum extents.
|
||||
* @param value to test
|
||||
* @return true if it is valid.
|
||||
*/
|
||||
private boolean isValid(String value)
|
||||
{
|
||||
if(value == null || value.isEmpty() || value.matches(ZEROS_REGEX))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(value.matches(REGEX))
|
||||
{
|
||||
try
|
||||
{
|
||||
double frequency = Double.parseDouble(value);
|
||||
return mMinimum <= frequency && frequency <= mMaximum;
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Input filter for user entered values.
|
||||
*/
|
||||
class FrequencyFilter extends DocumentFilter
|
||||
{
|
||||
@Override
|
||||
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException
|
||||
{
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.insert(offset, string);
|
||||
|
||||
if(isValid(sb.toString()))
|
||||
{
|
||||
super.insertString(fb, offset, string, attr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException
|
||||
{
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.replace(offset, offset + length, text);
|
||||
|
||||
if(isValid(sb.toString()))
|
||||
{
|
||||
super.replace(fb, offset, length, text, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(FilterBypass fb, int offset, int length) throws BadLocationException
|
||||
{
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.delete(offset, offset + length);
|
||||
|
||||
if(isValid(sb.toString()))
|
||||
{
|
||||
super.remove(fb, offset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
JFrame frame = new JFrame("Frequency Control Test");
|
||||
frame.setSize(300, 200);
|
||||
FrequencyTextField ftf = new FrequencyTextField(1, 9_999_999_999l, 101_100_000);
|
||||
frame.setLayout(new MigLayout());
|
||||
frame.add(ftf);
|
||||
|
||||
EventQueue.invokeLater(() -> frame.setVisible(true));
|
||||
}
|
||||
}
|
||||
@@ -1,593 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.gui.control;
|
||||
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.InvalidFrequencyException;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* Custom frequency controller for displaying or editing frequency values in MHz.
|
||||
*/
|
||||
public class JFrequencyControl extends JPanel implements ISourceEventProcessor
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(JFrequencyControl.class);
|
||||
private List<ISourceEventProcessor> mProcessors = new ArrayList<>();
|
||||
private Color mHighlightColor = Color.YELLOW;
|
||||
private long mFrequency;
|
||||
private HashMap<Integer,Digit> mDigits = new HashMap<Integer,Digit>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public JFrequencyControl()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the control/layout.
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("insets 0 0 0 0", "[]0[]", ""));
|
||||
|
||||
Font font = new Font(Font.MONOSPACED, Font.BOLD, 30);
|
||||
|
||||
for(int x = 9; x >= 0; x--)
|
||||
{
|
||||
Digit digit = null;
|
||||
|
||||
try
|
||||
{
|
||||
digit = new Digit(x);
|
||||
}
|
||||
catch(ParseException e)
|
||||
{
|
||||
mLog.error("JFrequencyControl - parse exception constructing a digit - " + e);
|
||||
}
|
||||
|
||||
if(digit != null)
|
||||
{
|
||||
mDigits.put(x, digit);
|
||||
|
||||
add(digit);
|
||||
|
||||
digit.setFont(font);
|
||||
|
||||
if(x == 6)
|
||||
{
|
||||
add(new JLabel(". "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the control.
|
||||
* @param enabled true if this component should be enabled, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
super.setEnabled(enabled);
|
||||
|
||||
for(Digit digit : mDigits.values())
|
||||
{
|
||||
digit.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a frequency change event invoked by another control. We don't
|
||||
* rebroadcast this event, just set the control to indicate the new frequency.
|
||||
*/
|
||||
@Override
|
||||
public void process(SourceEvent event)
|
||||
{
|
||||
switch(event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_FREQUENCY_CHANGE:
|
||||
EventQueue.invokeLater(() -> setFrequency(event.getValue().longValue(), false));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the frequency into the display and optionally fires a change event
|
||||
* to all registered listeners
|
||||
*/
|
||||
public void setFrequency(long frequency, boolean fireChangeEvent)
|
||||
{
|
||||
mFrequency = frequency;
|
||||
|
||||
for(Digit digit : mDigits.values())
|
||||
{
|
||||
digit.setFrequency(frequency, fireChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current frequency value for the control.
|
||||
* @return frequency
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
return mFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the frequency value according to the manually changed digit value.
|
||||
*/
|
||||
private void updateFrequency()
|
||||
{
|
||||
long frequency = 0;
|
||||
|
||||
for(Digit digit : mDigits.values())
|
||||
{
|
||||
frequency += digit.getFrequency();
|
||||
}
|
||||
|
||||
mFrequency = frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires a source changed event
|
||||
* @throws SourceException of there's an error
|
||||
*/
|
||||
private void fireSourceChanged() throws SourceException
|
||||
{
|
||||
updateFrequency();
|
||||
Iterator<ISourceEventProcessor> it = mProcessors.iterator();
|
||||
SourceEvent event = SourceEvent.frequencyRequest(mFrequency);
|
||||
while(it.hasNext())
|
||||
{
|
||||
it.next().process(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the source event listener
|
||||
* @param processor
|
||||
*/
|
||||
public void addListener(ISourceEventProcessor processor)
|
||||
{
|
||||
if(!mProcessors.contains(processor))
|
||||
{
|
||||
mProcessors.add(processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all source event processors
|
||||
*/
|
||||
public void clearListeners()
|
||||
{
|
||||
mProcessors.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the source event processor
|
||||
* @param processor
|
||||
*/
|
||||
public void removeListener(ISourceEventProcessor processor)
|
||||
{
|
||||
mProcessors.remove(processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom single digit value editor.
|
||||
*/
|
||||
public class Digit extends JTextField
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int mPower = 0;
|
||||
private long mValue = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param position of the digit where a position of 1 is the ones unit of MHz and a position of -1 is the tenths
|
||||
* unit of MHz.
|
||||
* @throws ParseException if there is an error
|
||||
*/
|
||||
private Digit(int position) throws ParseException
|
||||
{
|
||||
super("0");
|
||||
setColumns(1);
|
||||
|
||||
mPower = position;
|
||||
setToolTipText(getTooltip(mPower));
|
||||
Listener listener = new Listener();
|
||||
|
||||
this.addKeyListener(listener);
|
||||
this.addMouseListener(listener);
|
||||
this.addMouseWheelListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a custom tooltip for the current hover-over digit.
|
||||
* @param power of the digit in units of 10
|
||||
* @return custom tooptip.
|
||||
*/
|
||||
private static String getTooltip(int power)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Center frequency ");
|
||||
switch(power)
|
||||
{
|
||||
case 0:
|
||||
sb.append("1 Hertz");
|
||||
break;
|
||||
case 1:
|
||||
sb.append("10 Hertz");
|
||||
break;
|
||||
case 2:
|
||||
sb.append("100 Hertz");
|
||||
break;
|
||||
case 3:
|
||||
sb.append("1 Kilohertz");
|
||||
break;
|
||||
case 4:
|
||||
sb.append("10 Kilohertz");
|
||||
break;
|
||||
case 5:
|
||||
sb.append("100 Kilohertz");
|
||||
break;
|
||||
case 6:
|
||||
sb.append("1 Megahertz");
|
||||
break;
|
||||
case 7:
|
||||
sb.append("10 Megahertz");
|
||||
break;
|
||||
case 8:
|
||||
sb.append("100 Megahertz");
|
||||
break;
|
||||
case 9:
|
||||
sb.append("1 Gigahertz");
|
||||
break;
|
||||
}
|
||||
|
||||
sb.append(" units. Type a number, use up/down arrows, or click the upper/lower digit control to adjust");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this digit to the value of the column in frequency that corresponds
|
||||
* to the power (ie column) set for this digit. Optionally, fires a
|
||||
* value change event to all listeners.
|
||||
*/
|
||||
public void setFrequency(long frequency, boolean fireChangeEvent)
|
||||
{
|
||||
//Strip the digits higher than this one
|
||||
long lower = frequency % (long)(FastMath.pow(10, mPower + 1));
|
||||
//Set the value to int value of dividing by 10 to this power
|
||||
long value = (long)(lower / (long)(FastMath.pow(10, mPower)));
|
||||
set(value, fireChangeEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frequency value.
|
||||
* @return frequency value.
|
||||
*/
|
||||
public long getFrequency()
|
||||
{
|
||||
return mValue * (long)FastMath.pow(10, mPower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the unit value and fires a change event
|
||||
*/
|
||||
public void increment()
|
||||
{
|
||||
increment(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the unit value and fires a change event
|
||||
* @param fireChangeEvent true to fire an event
|
||||
*/
|
||||
public void increment(boolean fireChangeEvent)
|
||||
{
|
||||
if(isEnabled())
|
||||
{
|
||||
set(mValue + 1, fireChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the unit value and fires a change event.
|
||||
*/
|
||||
public void decrement()
|
||||
{
|
||||
decrement(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the unit value and optionally fires a change event.
|
||||
* @param fireChangeEvent set to true to fire an event
|
||||
*/
|
||||
public void decrement(boolean fireChangeEvent)
|
||||
{
|
||||
if(isEnabled())
|
||||
{
|
||||
set(mValue - 1, fireChangeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience wrapper to change amount and fire change event
|
||||
*/
|
||||
private void set(long amount)
|
||||
{
|
||||
set(amount, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value and optionally fires change event to listeners
|
||||
*/
|
||||
private void set(long amount, boolean fireChangeEvent)
|
||||
{
|
||||
long previous = mValue;
|
||||
boolean higherDigitIncremented = false;
|
||||
boolean higherDigitDecremented = false;
|
||||
|
||||
mValue = amount;
|
||||
|
||||
|
||||
while(mValue < 0)
|
||||
{
|
||||
mValue += 10;
|
||||
Digit nextHigherDigit = mDigits.get(mPower + 1);
|
||||
|
||||
if(nextHigherDigit != null)
|
||||
{
|
||||
nextHigherDigit.decrement(false);
|
||||
higherDigitDecremented = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(mValue > 9)
|
||||
{
|
||||
mValue -= 10;
|
||||
Digit nextHigherDigit = mDigits.get(mPower + 1);
|
||||
|
||||
if(nextHigherDigit != null)
|
||||
{
|
||||
nextHigherDigit.increment(false);
|
||||
higherDigitIncremented = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(fireChangeEvent)
|
||||
{
|
||||
try
|
||||
{
|
||||
fireSourceChanged();
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
mValue = previous;
|
||||
|
||||
if(higherDigitIncremented)
|
||||
{
|
||||
Digit nextHigherDigit = mDigits.get(mPower + 1);
|
||||
|
||||
if(nextHigherDigit != null)
|
||||
{
|
||||
nextHigherDigit.decrement(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(higherDigitDecremented)
|
||||
{
|
||||
Digit nextHigherDigit = mDigits.get(mPower + 1);
|
||||
|
||||
if(nextHigherDigit != null)
|
||||
{
|
||||
nextHigherDigit.increment(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(se instanceof InvalidFrequencyException ife)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, ife.getMessage() + " for this tuner.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setText(String.valueOf(mValue));
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple Listener interface implementation
|
||||
*/
|
||||
private class Listener implements KeyListener, MouseListener, MouseWheelListener
|
||||
{
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
int key = e.getKeyCode();
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case KeyEvent.VK_0:
|
||||
case KeyEvent.VK_NUMPAD0:
|
||||
set(0);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_1:
|
||||
case KeyEvent.VK_NUMPAD1:
|
||||
set(1);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_2:
|
||||
case KeyEvent.VK_NUMPAD2:
|
||||
set(2);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_3:
|
||||
case KeyEvent.VK_NUMPAD3:
|
||||
set(3);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_4:
|
||||
case KeyEvent.VK_NUMPAD4:
|
||||
set(4);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_5:
|
||||
case KeyEvent.VK_NUMPAD5:
|
||||
set(5);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_6:
|
||||
case KeyEvent.VK_NUMPAD6:
|
||||
set(6);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_7:
|
||||
case KeyEvent.VK_NUMPAD7:
|
||||
set(7);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_8:
|
||||
case KeyEvent.VK_NUMPAD8:
|
||||
set(8);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_9:
|
||||
case KeyEvent.VK_NUMPAD9:
|
||||
set(9);
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
Digit.this.transferFocusBackward();
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
Digit.this.transferFocus();
|
||||
break;
|
||||
case KeyEvent.VK_UP:
|
||||
increment();
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
decrement();
|
||||
break;
|
||||
case KeyEvent.VK_TAB:
|
||||
break;
|
||||
default:
|
||||
set(mValue);
|
||||
break;
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {}
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
switch(e.getButton())
|
||||
{
|
||||
case MouseEvent.BUTTON1:
|
||||
increment();
|
||||
break;
|
||||
case MouseEvent.BUTTON2:
|
||||
break;
|
||||
case MouseEvent.BUTTON3:
|
||||
decrement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
Color bg = UIManager.getColor("TextField.selectionBackground");
|
||||
Color fg = UIManager.getColor("TextField.selectionForeground");
|
||||
Digit.this.setBackground(bg != null ? bg : Color.YELLOW);
|
||||
Digit.this.setForeground(fg != null ? fg : Color.BLACK);
|
||||
repaint(); }
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
Color bg = UIManager.getColor("TextField.background");
|
||||
Color fg = UIManager.getColor("TextField.foreground");
|
||||
Digit.this.setBackground(bg != null ? bg : Color.WHITE);
|
||||
Digit.this.setForeground(fg != null ? fg : Color.BLACK);
|
||||
repaint(); }
|
||||
|
||||
@Override
|
||||
public void mouseWheelMoved(MouseWheelEvent e)
|
||||
{
|
||||
//Swing delivers mouse wheel events to disabled components, so check enabled state explicitly so that
|
||||
//the wheel can't bypass the lock when the tuner is providing channels.
|
||||
if(isEnabled())
|
||||
{
|
||||
set(mValue - e.getWheelRotation());
|
||||
}
|
||||
else if(getParent() != null)
|
||||
{
|
||||
//Pass the event up so that an enclosing scroll pane can still scroll while this control is locked
|
||||
getParent().dispatchEvent(SwingUtilities.convertMouseEvent(Digit.this, e, getParent()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
* 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
|
||||
@@ -17,35 +17,19 @@
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* WaypointRenderer.java
|
||||
*
|
||||
* Created on March 30, 2006, 5:56 PM
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package io.github.dsheirer.gui.map;
|
||||
|
||||
package org.jdesktop.swingx.mapviewer;
|
||||
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
|
||||
/**
|
||||
* A interface that draws waypoints. Implementations of WaypointRenderer can
|
||||
* be set on a WayPointPainter to draw waypoints on a JXMapViewer
|
||||
* @param <W> the waypoint type
|
||||
* @author joshua.marinacci@sun.com
|
||||
* Overlay drawn over the map tiles, in the order the layers were added to the {@link TileMapView}.
|
||||
*/
|
||||
public interface WaypointRenderer<W>
|
||||
public interface MapLayer
|
||||
{
|
||||
/**
|
||||
* paint the specified waypoint on the specified map and graphics context
|
||||
* @param g the graphics2D object
|
||||
* @param map the map
|
||||
* @param waypoint the waypoint
|
||||
* Draws the layer. Called on the JavaFX thread.
|
||||
* @param gc of the map canvas, in screen pixels
|
||||
* @param map for converting positions to screen pixels
|
||||
*/
|
||||
public void paintWaypoint(Graphics2D g, JXMapViewer map, W waypoint);
|
||||
|
||||
void draw(GraphicsContext gc, TileMapView map);
|
||||
}
|
||||
59
src/main/java/io/github/dsheirer/gui/map/MapPanel.java
Normal file
59
src/main/java/io/github/dsheirer/gui/map/MapPanel.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.gui.playlist.radioreference.RadioReferencePlaylistActions;
|
||||
import io.github.dsheirer.gui.theme.ThemeManager;
|
||||
import io.github.dsheirer.icon.IconModel;
|
||||
import io.github.dsheirer.map.MapService;
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.service.radioreference.RadioReferenceFrequencyIndex;
|
||||
import javafx.application.Platform;
|
||||
import javafx.embed.swing.JFXPanel;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
/**
|
||||
* Swing panel that holds the JavaFX map view for the main application window. The JavaFX view is created on the
|
||||
* JavaFX application thread after construction.
|
||||
*/
|
||||
public class MapPanel extends JFXPanel
|
||||
{
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param mapService for the entities to plot
|
||||
* @param iconModel for alias icons
|
||||
* @param userPreferences for the map view and the user's location
|
||||
* @param frequencyIndex of the radio reference frequencies near the user, for the trunked system sites, or null
|
||||
* @param playlistActions to add sites to the playlist or enable their channels, or null
|
||||
*/
|
||||
public MapPanel(MapService mapService, IconModel iconModel, UserPreferences userPreferences,
|
||||
RadioReferenceFrequencyIndex frequencyIndex, RadioReferencePlaylistActions playlistActions)
|
||||
{
|
||||
Platform.setImplicitExit(false);
|
||||
ThemeManager.getInstance().registerSwing(this);
|
||||
|
||||
Platform.runLater(() -> {
|
||||
MapView view = new MapView(mapService, iconModel, userPreferences, frequencyIndex, playlistActions, true);
|
||||
Scene scene = new Scene(view);
|
||||
ThemeManager.getInstance().register(scene);
|
||||
setScene(scene);
|
||||
});
|
||||
}
|
||||
}
|
||||
1141
src/main/java/io/github/dsheirer/gui/map/MapView.java
Normal file
1141
src/main/java/io/github/dsheirer/gui/map/MapView.java
Normal file
File diff suppressed because it is too large
Load Diff
203
src/main/java/io/github/dsheirer/gui/map/MapViewport.java
Normal file
203
src/main/java/io/github/dsheirer/gui/map/MapViewport.java
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import io.github.dsheirer.preference.map.MapPreference;
|
||||
|
||||
/**
|
||||
* Part of the world in view: the center point, the tile zoom level and the size of the view in pixels, with the
|
||||
* conversions between positions and screen pixels. The map repeats east and west, so it can be panned around the
|
||||
* world, and it stops at the top and bottom of the projection. Not thread safe: use it on the JavaFX thread.
|
||||
*/
|
||||
public class MapViewport
|
||||
{
|
||||
private double mCenterX = Mercator.x(0);
|
||||
private double mCenterY = Mercator.y(0);
|
||||
private int mZoom = 2;
|
||||
private double mWidth;
|
||||
private double mHeight;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public MapViewport()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tile zoom level
|
||||
*/
|
||||
public int getZoom()
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile zoom level, keeping the center point
|
||||
* @param zoom level, clamped to the map preference's range
|
||||
*/
|
||||
public void setZoom(int zoom)
|
||||
{
|
||||
mZoom = Math.clamp(zoom, MapPreference.MINIMUM_TILE_ZOOM, MapPreference.MAXIMUM_TILE_ZOOM);
|
||||
clamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the zoom level, keeping the position under the screen point in place
|
||||
* @param zoom level, clamped to the map preference's range
|
||||
* @param x of the screen point
|
||||
* @param y of the screen point
|
||||
*/
|
||||
public void zoomAt(int zoom, double x, double y)
|
||||
{
|
||||
double worldX = (getLeft() + x) / getWorldSize();
|
||||
double worldY = (getTop() + y) / getWorldSize();
|
||||
mZoom = Math.clamp(zoom, MapPreference.MINIMUM_TILE_ZOOM, MapPreference.MAXIMUM_TILE_ZOOM);
|
||||
mCenterX = worldX - (x - mWidth / 2.0) / getWorldSize();
|
||||
mCenterY = worldY - (y - mHeight / 2.0) / getWorldSize();
|
||||
clamp();
|
||||
}
|
||||
|
||||
public double getWidth()
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public double getHeight()
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the view, keeping the center point
|
||||
*/
|
||||
public void setSize(double width, double height)
|
||||
{
|
||||
mWidth = Math.max(0, width);
|
||||
mHeight = Math.max(0, height);
|
||||
clamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Center point of the view
|
||||
*/
|
||||
public GeoPosition getCenter()
|
||||
{
|
||||
return new GeoPosition(Mercator.latitude(mCenterY), Mercator.longitude(mCenterX));
|
||||
}
|
||||
|
||||
/**
|
||||
* Centers the view on the position
|
||||
*/
|
||||
public void setCenter(GeoPosition position)
|
||||
{
|
||||
mCenterX = Mercator.x(position.getLongitude());
|
||||
mCenterY = Mercator.y(position.getLatitude());
|
||||
clamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the view by screen pixels, as when the map is dragged by the opposite amount
|
||||
* @param dx pixels to move the view east
|
||||
* @param dy pixels to move the view south
|
||||
*/
|
||||
public void pan(double dx, double dy)
|
||||
{
|
||||
mCenterX += dx / getWorldSize();
|
||||
mCenterY += dy / getWorldSize();
|
||||
clamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* World width and height in pixels at the current zoom level
|
||||
*/
|
||||
public double getWorldSize()
|
||||
{
|
||||
return Mercator.worldSize(mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* World pixel at the left edge of the view, which is whole so tiles line up with screen pixels. It can be
|
||||
* negative or past the world width, since the map repeats east and west.
|
||||
*/
|
||||
public double getLeft()
|
||||
{
|
||||
return Math.round(mCenterX * getWorldSize() - mWidth / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* World pixel at the top edge of the view, which is whole so tiles line up with screen pixels
|
||||
*/
|
||||
public double getTop()
|
||||
{
|
||||
return Math.round(mCenterY * getWorldSize() - mHeight / 2.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Screen x of the longitude, for the copy of the world nearest the middle of the view
|
||||
*/
|
||||
public double getScreenX(double longitude)
|
||||
{
|
||||
double worldSize = getWorldSize();
|
||||
double x = Mercator.x(longitude) * worldSize - getLeft();
|
||||
double middle = mWidth / 2.0;
|
||||
return x - Math.round((x - middle) / worldSize) * worldSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Screen y of the latitude
|
||||
*/
|
||||
public double getScreenY(double latitude)
|
||||
{
|
||||
return Mercator.y(latitude) * getWorldSize() - getTop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Position at the screen point
|
||||
*/
|
||||
public GeoPosition getPosition(double x, double y)
|
||||
{
|
||||
double worldSize = getWorldSize();
|
||||
return new GeoPosition(Mercator.latitude((getTop() + y) / worldSize),
|
||||
Mercator.longitude((getLeft() + x) / worldSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the center within one copy of the world, and the top and bottom of the map at the edges of the view, or
|
||||
* the map in the middle when it's shorter than the view
|
||||
*/
|
||||
private void clamp()
|
||||
{
|
||||
mCenterX = mCenterX - Math.floor(mCenterX);
|
||||
|
||||
double worldSize = getWorldSize();
|
||||
double halfHeight = mHeight / 2.0 / worldSize;
|
||||
|
||||
if(halfHeight >= 0.5)
|
||||
{
|
||||
mCenterY = 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCenterY = Math.clamp(mCenterY, halfHeight, 1.0 - halfHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
src/main/java/io/github/dsheirer/gui/map/Mercator.java
Normal file
100
src/main/java/io/github/dsheirer/gui/map/Mercator.java
Normal file
@@ -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.map;
|
||||
|
||||
/**
|
||||
* Web (spherical) Mercator projection used by OpenStreetMap tiles. Positions are expressed as fractions of the world
|
||||
* width and height (0 to 1), independent of the zoom level: x grows eastward from -180 degrees longitude and y grows
|
||||
* southward from the top of the map at about 85.05 degrees north latitude.
|
||||
*/
|
||||
public final class Mercator
|
||||
{
|
||||
/**
|
||||
* Pixel width and height of a map tile
|
||||
*/
|
||||
public static final int TILE_SIZE = 256;
|
||||
|
||||
/**
|
||||
* Northern and southern limit of the projection, where the map is square
|
||||
*/
|
||||
public static final double MAX_LATITUDE = 85.05112878;
|
||||
|
||||
private Mercator()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* World width and height in pixels at the zoom level
|
||||
*/
|
||||
public static double worldSize(int zoom)
|
||||
{
|
||||
return TILE_SIZE * (double)(1L << zoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of tiles across the world at the zoom level
|
||||
*/
|
||||
public static int tileCount(int zoom)
|
||||
{
|
||||
return 1 << zoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Longitude to a fraction of the world width
|
||||
*/
|
||||
public static double x(double longitude)
|
||||
{
|
||||
return (longitude + 180.0) / 360.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Latitude to a fraction of the world height, clamped to the projection's limits
|
||||
*/
|
||||
public static double y(double latitude)
|
||||
{
|
||||
double radians = Math.toRadians(Math.clamp(latitude, -MAX_LATITUDE, MAX_LATITUDE));
|
||||
return (1.0 - Math.log(Math.tan(radians) + 1.0 / Math.cos(radians)) / Math.PI) / 2.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fraction of the world width to a longitude, wrapped into -180 to 180 degrees
|
||||
*/
|
||||
public static double longitude(double x)
|
||||
{
|
||||
return normalizeLongitude(x * 360.0 - 180.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fraction of the world height to a latitude
|
||||
*/
|
||||
public static double latitude(double y)
|
||||
{
|
||||
double n = Math.PI * (1.0 - 2.0 * Math.clamp(y, 0.0, 1.0));
|
||||
return Math.toDegrees(Math.atan(Math.sinh(n)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a longitude into -180 to 180 degrees, since the map can be panned past +/-180 degrees
|
||||
*/
|
||||
public static double normalizeLongitude(double longitude)
|
||||
{
|
||||
return ((longitude + 180.0) % 360.0 + 360.0) % 360.0 - 180.0;
|
||||
}
|
||||
}
|
||||
220
src/main/java/io/github/dsheirer/gui/map/SiteCard.java
Normal file
220
src/main/java/io/github/dsheirer/gui/map/SiteCard.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
|
||||
import io.github.dsheirer.rrapi.type.Coverage;
|
||||
import io.github.dsheirer.service.radioreference.DistanceFormat;
|
||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Separator;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
|
||||
/**
|
||||
* Card with the details of radio reference trunked system sites, shown when the mouse rests over a site's tower on the
|
||||
* map: the system and protocol, the site, and the site's channels.
|
||||
*/
|
||||
public final class SiteCard
|
||||
{
|
||||
private static final int MAX_SITES = 3;
|
||||
private static final int CHANNEL_COLUMNS = 3;
|
||||
private static final int MAX_CHANNELS = 24;
|
||||
private static final double MAX_TEXT_WIDTH = 380;
|
||||
private static final String SEPARATOR = " · ";
|
||||
private static final String STYLE = "-fx-background-color: -fx-control-inner-background; " +
|
||||
"-fx-border-color: -fx-box-border; -fx-background-radius: 3; -fx-border-radius: 3; -fx-padding: 6; " +
|
||||
"-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.35), 6, 0, 1, 2);";
|
||||
|
||||
/**
|
||||
* Channel frequency with a control channel marker: C for control, A for alternate control, or null
|
||||
*/
|
||||
public record Channel(String frequency, String marker) {}
|
||||
|
||||
/**
|
||||
* Details of one site
|
||||
* @param title system name
|
||||
* @param lines protocol, site, identifiers
|
||||
* @param channels of the site, up to the card's limit
|
||||
* @param notes about the channels
|
||||
*/
|
||||
public record Entry(String title, List<String> lines, List<Channel> channels, List<String> notes) {}
|
||||
|
||||
/**
|
||||
* Card content
|
||||
* @param entries for the sites shown, nearest first
|
||||
* @param moreSites count of the sites under the mouse that aren't shown
|
||||
*/
|
||||
public record Content(List<Entry> entries, int moreSites) {}
|
||||
|
||||
private SiteCard()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Content of the card for the sites
|
||||
* @param sites under the mouse, nearest first
|
||||
* @param location of the user, for the distances, or null
|
||||
*/
|
||||
public static Content content(List<SiteRecord> sites, RadioReferencePreference.Location location)
|
||||
{
|
||||
DecimalFormat frequencyFormat = new DecimalFormat("0.00000");
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
int shown = Math.min(sites.size(), MAX_SITES);
|
||||
|
||||
for(int index = 0; index < shown; index++)
|
||||
{
|
||||
SiteRecord site = sites.get(index);
|
||||
List<String> lines = new ArrayList<>();
|
||||
addLine(lines, site.protocol(), site.voice());
|
||||
String distance = location != null ? DistanceFormat.format(Coverage.distanceKilometers(
|
||||
location.latitude(), location.longitude(), site.latitude(), site.longitude())) : null;
|
||||
addLine(lines, "Site " + site.siteNumber(), site.description(), site.county(), distance);
|
||||
addLine(lines, site.nac() != null ? "NAC " + site.nac() : null,
|
||||
site.rfss() > 0 ? "RFSS " + site.rfss() : null, site.zone() > 0 ? "Zone " + site.zone() : null);
|
||||
|
||||
List<Channel> channels = new ArrayList<>();
|
||||
List<String> notes = new ArrayList<>();
|
||||
boolean control = false;
|
||||
|
||||
if(site.channels() != null)
|
||||
{
|
||||
for(SiteRecord.SiteChannel channel: site.channels().subList(0, Math.min(site.channels().size(),
|
||||
MAX_CHANNELS)))
|
||||
{
|
||||
String marker = "Control".equals(channel.use()) ? "C" :
|
||||
"Alternate control".equals(channel.use()) ? "A" : null;
|
||||
control |= marker != null;
|
||||
channels.add(new Channel(frequencyFormat.format(channel.frequencyHz() / 1E6), marker));
|
||||
}
|
||||
|
||||
if(site.channels().size() > MAX_CHANNELS)
|
||||
{
|
||||
notes.add("+ " + (site.channels().size() - MAX_CHANNELS) + " more channels");
|
||||
}
|
||||
}
|
||||
|
||||
if(control)
|
||||
{
|
||||
notes.add("C control, A alternate control");
|
||||
}
|
||||
|
||||
entries.add(new Entry(site.systemName() != null ? site.systemName() : "(unnamed system)", lines,
|
||||
channels, notes.isEmpty() ? List.of() : List.of(String.join(SEPARATOR, notes))));
|
||||
}
|
||||
|
||||
return new Content(entries, sites.size() - shown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Card node for the content
|
||||
*/
|
||||
public static Region create(Content content)
|
||||
{
|
||||
VBox card = new VBox(2);
|
||||
card.setStyle(STYLE);
|
||||
card.setMaxWidth(Region.USE_PREF_SIZE);
|
||||
card.setMaxHeight(Region.USE_PREF_SIZE);
|
||||
Font font = Font.font(11);
|
||||
Font bold = Font.font(Font.getDefault().getFamily(), FontWeight.BOLD, 11);
|
||||
|
||||
for(int index = 0; index < content.entries().size(); index++)
|
||||
{
|
||||
Entry entry = content.entries().get(index);
|
||||
|
||||
if(index > 0)
|
||||
{
|
||||
card.getChildren().add(new Separator());
|
||||
}
|
||||
|
||||
card.getChildren().add(label(entry.title(), bold));
|
||||
entry.lines().forEach(line -> card.getChildren().add(label(line, font)));
|
||||
|
||||
if(!entry.channels().isEmpty())
|
||||
{
|
||||
GridPane grid = new GridPane();
|
||||
grid.setHgap(10);
|
||||
|
||||
for(int channelIndex = 0; channelIndex < entry.channels().size(); channelIndex++)
|
||||
{
|
||||
Channel channel = entry.channels().get(channelIndex);
|
||||
HBox cell = new HBox(3, label(channel.frequency(), font));
|
||||
|
||||
if(channel.marker() != null)
|
||||
{
|
||||
cell.getChildren().add(label(channel.marker(), bold));
|
||||
}
|
||||
|
||||
grid.add(cell, channelIndex % CHANNEL_COLUMNS, channelIndex / CHANNEL_COLUMNS);
|
||||
}
|
||||
|
||||
card.getChildren().add(grid);
|
||||
}
|
||||
|
||||
entry.notes().forEach(note -> card.getChildren().add(label(note, font)));
|
||||
}
|
||||
|
||||
if(content.moreSites() > 0)
|
||||
{
|
||||
card.getChildren().add(new Separator());
|
||||
card.getChildren().add(label("+ " + content.moreSites() + " more site" +
|
||||
(content.moreSites() > 1 ? "s" : "") + " here", font));
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
private static Label label(String text, Font font)
|
||||
{
|
||||
Label label = new Label(text);
|
||||
label.setFont(font);
|
||||
label.setWrapText(true);
|
||||
label.setMaxWidth(MAX_TEXT_WIDTH);
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a line with the non-empty values separated by dots, or nothing when all are empty
|
||||
*/
|
||||
private static void addLine(List<String> lines, String... values)
|
||||
{
|
||||
List<String> parts = new ArrayList<>();
|
||||
|
||||
for(String value: values)
|
||||
{
|
||||
if(value != null && !value.isBlank())
|
||||
{
|
||||
parts.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!parts.isEmpty())
|
||||
{
|
||||
lines.add(String.join(SEPARATOR, parts));
|
||||
}
|
||||
}
|
||||
}
|
||||
156
src/main/java/io/github/dsheirer/gui/map/SiteLayer.java
Normal file
156
src/main/java/io/github/dsheirer/gui/map/SiteLayer.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.ArcType;
|
||||
import javafx.scene.shape.StrokeLineCap;
|
||||
import javafx.scene.shape.StrokeLineJoin;
|
||||
|
||||
/**
|
||||
* Radio reference trunked system sites: a radio tower at each site, with the base of the tower at the site location.
|
||||
* Use on the JavaFX thread.
|
||||
*/
|
||||
public class SiteLayer implements MapLayer
|
||||
{
|
||||
private static final Color TOWER = Color.rgb(240, 128, 32);
|
||||
private static final Color OUTLINE = Color.rgb(40, 40, 40, 200 / 255.0);
|
||||
private static final double TOWER_WIDTH = 1.6;
|
||||
private static final double OUTLINE_WIDTH = 3.6;
|
||||
private static final double HEIGHT = 16;
|
||||
private static final double HALF_BASE = 5;
|
||||
//Hit area around the tower, in pixels from the site location
|
||||
private static final double HIT_LEFT = -10;
|
||||
private static final double HIT_TOP = -24;
|
||||
private static final double HIT_WIDTH = 20;
|
||||
private static final double HIT_HEIGHT = 28;
|
||||
|
||||
private final Supplier<List<SiteRecord>> mSites;
|
||||
private boolean mShowSites = true;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param sites to draw, read each time the map is drawn
|
||||
*/
|
||||
public SiteLayer(Supplier<List<SiteRecord>> sites)
|
||||
{
|
||||
mSites = sites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows or hides the sites
|
||||
*/
|
||||
public void setShowSites(boolean show)
|
||||
{
|
||||
mShowSites = show;
|
||||
}
|
||||
|
||||
public boolean isShowSites()
|
||||
{
|
||||
return mShowSites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sites whose tower is under the point, nearest first
|
||||
* @param viewport of the map
|
||||
* @param x of the point in the view
|
||||
* @param y of the point in the view
|
||||
* @return sites, or an empty list when the sites are hidden or none is under the point
|
||||
*/
|
||||
public List<SiteRecord> getSitesAt(MapViewport viewport, double x, double y)
|
||||
{
|
||||
if(!mShowSites)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
record Hit(SiteRecord site, double distance) {}
|
||||
|
||||
List<Hit> hits = new ArrayList<>();
|
||||
|
||||
for(SiteRecord site: mSites.get())
|
||||
{
|
||||
double dx = x - viewport.getScreenX(site.longitude());
|
||||
double dy = y - viewport.getScreenY(site.latitude());
|
||||
|
||||
if(dx >= HIT_LEFT && dx < HIT_LEFT + HIT_WIDTH && dy >= HIT_TOP && dy < HIT_TOP + HIT_HEIGHT)
|
||||
{
|
||||
//Nearest to the middle of the tower first
|
||||
hits.add(new Hit(site, Math.hypot(dx, dy + (HEIGHT / 2.0))));
|
||||
}
|
||||
}
|
||||
|
||||
//Stable, so sites at the same spot keep their order
|
||||
hits.sort(Comparator.comparingDouble(Hit::distance));
|
||||
return hits.stream().map(Hit::site).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GraphicsContext gc, TileMapView map)
|
||||
{
|
||||
if(!mShowSites)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MapViewport viewport = map.getViewport();
|
||||
double width = viewport.getWidth();
|
||||
double height = viewport.getHeight();
|
||||
gc.setLineCap(StrokeLineCap.ROUND);
|
||||
gc.setLineJoin(StrokeLineJoin.ROUND);
|
||||
|
||||
for(SiteRecord site: mSites.get())
|
||||
{
|
||||
double x = viewport.getScreenX(site.longitude());
|
||||
double y = viewport.getScreenY(site.latitude());
|
||||
|
||||
if(x >= -20 && x <= width + 20 && y >= -4 && y <= height + 30)
|
||||
{
|
||||
drawTower(gc, x, y, OUTLINE, OUTLINE_WIDTH);
|
||||
drawTower(gc, x, y, TOWER, TOWER_WIDTH);
|
||||
gc.setFill(TOWER);
|
||||
gc.fillOval(x - 2, y - HEIGHT - 2, 4, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strokes a tower with its base at the point: an A-frame mast with a cross brace and radio waves at the top
|
||||
*/
|
||||
private static void drawTower(GraphicsContext gc, double x, double y, Color color, double lineWidth)
|
||||
{
|
||||
double top = y - HEIGHT;
|
||||
gc.setStroke(color);
|
||||
gc.setLineWidth(lineWidth);
|
||||
gc.strokePolyline(new double[]{x - HALF_BASE, x, x + HALF_BASE}, new double[]{y, top, y}, 3);
|
||||
gc.strokeLine(x - (HALF_BASE * 0.55), y - (HEIGHT * 0.45), x + (HALF_BASE * 0.55), y - (HEIGHT * 0.45));
|
||||
gc.strokeArc(x - 5, top - 4, 10, 8, 135, 90, ArcType.OPEN);
|
||||
gc.strokeArc(x - 5, top - 4, 10, 8, -45, 90, ArcType.OPEN);
|
||||
gc.strokeArc(x - 9, top - 7, 18, 14, 135, 90, ArcType.OPEN);
|
||||
gc.strokeArc(x - 9, top - 7, 18, 14, -45, 90, ArcType.OPEN);
|
||||
}
|
||||
}
|
||||
122
src/main/java/io/github/dsheirer/gui/map/TileChoice.java
Normal file
122
src/main/java/io/github/dsheirer/gui/map/TileChoice.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Entry in the tile server chooser: a server with tiles that follow the theme, or always light or always dark tiles.
|
||||
* Dark tiles come from the server's dark style, or are recolored light tiles when it has none.
|
||||
* @param server tile server
|
||||
* @param style of the tiles
|
||||
*/
|
||||
public record TileChoice(TileServer server, Style style)
|
||||
{
|
||||
/**
|
||||
* Tile style. The name is stored in the map preference. Don't change it.
|
||||
*/
|
||||
public enum Style
|
||||
{
|
||||
THEME(" - Auto"),
|
||||
LIGHT(" - Light"),
|
||||
DARK(" - Dark");
|
||||
|
||||
private final String mSuffix;
|
||||
|
||||
Style(String suffix)
|
||||
{
|
||||
mSuffix = suffix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Choices offered to the user, in menu order: each server following the theme, then light, then dark
|
||||
*/
|
||||
public static final List<TileChoice> CHOICES;
|
||||
|
||||
static
|
||||
{
|
||||
List<TileChoice> choices = new ArrayList<>();
|
||||
|
||||
for(TileServer server: TileServer.SERVERS)
|
||||
{
|
||||
for(Style style: Style.values())
|
||||
{
|
||||
choices.add(new TileChoice(server, style));
|
||||
}
|
||||
}
|
||||
|
||||
CHOICES = Collections.unmodifiableList(choices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Choice with the server and style
|
||||
* @param serverId from the map preference, or null
|
||||
* @param style name from the map preference, or null
|
||||
* @return choice, following the theme when the style is unknown, see {@link TileServer#get(String)}
|
||||
*/
|
||||
public static TileChoice get(String serverId, String style)
|
||||
{
|
||||
TileServer server = TileServer.get(serverId);
|
||||
|
||||
for(Style candidate: Style.values())
|
||||
{
|
||||
if(candidate.name().equals(style))
|
||||
{
|
||||
return new TileChoice(server, candidate);
|
||||
}
|
||||
}
|
||||
|
||||
return new TileChoice(server, Style.THEME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the tiles are dark
|
||||
* @param darkTheme true when the application uses a dark theme
|
||||
*/
|
||||
public boolean isDark(boolean darkTheme)
|
||||
{
|
||||
return switch(style)
|
||||
{
|
||||
case THEME -> darkTheme;
|
||||
case LIGHT -> false;
|
||||
case DARK -> true;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tiles to load
|
||||
* @param darkTheme true when the application uses a dark theme
|
||||
* @param key from the user, for a server that needs one, or null
|
||||
*/
|
||||
public TileSource getSource(boolean darkTheme, String key)
|
||||
{
|
||||
return server.getSource(isDark(darkTheme), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return server.name() + style.mSuffix;
|
||||
}
|
||||
}
|
||||
89
src/main/java/io/github/dsheirer/gui/map/TileDarkener.java
Normal file
89
src/main/java/io/github/dsheirer/gui/map/TileDarkener.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.PixelFormat;
|
||||
import javafx.scene.image.WritableImage;
|
||||
|
||||
/**
|
||||
* Recolors light map tiles for a dark theme: inverts each pixel's lightness while keeping its hue, so a light
|
||||
* background turns dark, water stays blue and roads keep their colors. The lightness is kept within a range so
|
||||
* the darkest areas aren't black and the lightest aren't white, and the colors are muted a little.
|
||||
*/
|
||||
public final class TileDarkener
|
||||
{
|
||||
//Lightness of a white pixel after recoloring, and of a black pixel
|
||||
static final double DARKEST = 0.10;
|
||||
static final double LIGHTEST = 0.85;
|
||||
private static final double SATURATION = 0.80;
|
||||
|
||||
private TileDarkener()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Recolored copy of the image. Can be called on any thread.
|
||||
*/
|
||||
public static Image darken(Image image)
|
||||
{
|
||||
int width = (int)image.getWidth();
|
||||
int height = (int)image.getHeight();
|
||||
int[] pixels = new int[width * height];
|
||||
image.getPixelReader().getPixels(0, 0, width, height, PixelFormat.getIntArgbInstance(), pixels, 0, width);
|
||||
|
||||
for(int index = 0; index < pixels.length; index++)
|
||||
{
|
||||
pixels[index] = darken(pixels[index]);
|
||||
}
|
||||
|
||||
WritableImage darkened = new WritableImage(width, height);
|
||||
darkened.getPixelWriter().setPixels(0, 0, width, height, PixelFormat.getIntArgbInstance(), pixels, 0, width);
|
||||
return darkened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recolors one ARGB pixel: the HSL lightness L becomes DARKEST + (LIGHTEST - DARKEST) * (1 - L), and the
|
||||
* saturation is scaled by SATURATION, keeping the hue and alpha
|
||||
*/
|
||||
static int darken(int argb)
|
||||
{
|
||||
double r = ((argb >> 16) & 0xFF) / 255.0;
|
||||
double g = ((argb >> 8) & 0xFF) / 255.0;
|
||||
double b = (argb & 0xFF) / 255.0;
|
||||
double max = Math.max(r, Math.max(g, b));
|
||||
double min = Math.min(r, Math.min(g, b));
|
||||
double lightness = (max + min) / 2.0;
|
||||
double chroma = max - min;
|
||||
double target = DARKEST + (LIGHTEST - DARKEST) * (1.0 - lightness);
|
||||
|
||||
//Chroma that keeps the saturation at the new lightness: saturation = chroma / (1 - |2L - 1|)
|
||||
double room = 1.0 - Math.abs(2.0 * lightness - 1.0);
|
||||
double scale = chroma > 0 && room > 0 ? SATURATION * (1.0 - Math.abs(2.0 * target - 1.0)) / room : 0;
|
||||
|
||||
return (argb & 0xFF000000) | (channel(target + (r - lightness) * scale) << 16) |
|
||||
(channel(target + (g - lightness) * scale) << 8) | channel(target + (b - lightness) * scale);
|
||||
}
|
||||
|
||||
private static int channel(double value)
|
||||
{
|
||||
return (int)Math.round(Math.clamp(value, 0.0, 1.0) * 255.0);
|
||||
}
|
||||
}
|
||||
39
src/main/java/io/github/dsheirer/gui/map/TileKey.java
Normal file
39
src/main/java/io/github/dsheirer/gui/map/TileKey.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
/**
|
||||
* Map tile address in the OpenStreetMap (slippy map) scheme
|
||||
* @param zoom level, 0 for the whole world in one tile
|
||||
* @param x tile column, 0 to 2^zoom - 1, west to east
|
||||
* @param y tile row, 0 to 2^zoom - 1, north to south
|
||||
*/
|
||||
public record TileKey(int zoom, int x, int y)
|
||||
{
|
||||
/**
|
||||
* Tile that covers this tile at a lower (farther) zoom level
|
||||
* @param levels to go up, 1 or more
|
||||
* @return covering tile
|
||||
*/
|
||||
public TileKey parent(int levels)
|
||||
{
|
||||
return new TileKey(zoom - levels, x >> levels, y >> levels);
|
||||
}
|
||||
}
|
||||
492
src/main/java/io/github/dsheirer/gui/map/TileLoader.java
Normal file
492
src/main/java/io/github/dsheirer/gui/map/TileLoader.java
Normal file
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Duration;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import javafx.scene.image.Image;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Loads map tile images from a {@link TileSource} in the background, with a memory cache of recently drawn tiles and
|
||||
* a disk cache that follows the tile server's caching headers. Follows the OpenStreetMap tile usage policy, which
|
||||
* suits the other servers too: an identifying User-Agent, two download threads, and local caching. The newest
|
||||
* requests load first and requests for tiles that scrolled out of view are dropped. Changing the source drops the
|
||||
* loaded and requested tiles.
|
||||
*/
|
||||
public class TileLoader
|
||||
{
|
||||
private static final Logger mLog = LoggerFactory.getLogger(TileLoader.class);
|
||||
private static final String USER_AGENT = "sdrtrunk (https://github.com/DSheirer/sdrtrunk)";
|
||||
private static final int DOWNLOAD_THREADS = 2;
|
||||
//256 tiles of 256x256 pixels is about 64 MB
|
||||
private static final int MEMORY_CACHE_TILES = 256;
|
||||
private static final Duration DEFAULT_EXPIRY = Duration.ofDays(7);
|
||||
private static final Duration MINIMUM_EXPIRY = Duration.ofHours(1);
|
||||
private static final Duration RETRY_DELAY = Duration.ofSeconds(60);
|
||||
private static final long DISK_CACHE_LIMIT_BYTES = 512L * 1024 * 1024;
|
||||
private static final long DISK_CACHE_TRIM_BYTES = 400L * 1024 * 1024;
|
||||
private static final Pattern MAX_AGE = Pattern.compile("max-age=(\\d+)");
|
||||
|
||||
private final Path mCacheDirectory;
|
||||
private final Consumer<TileKey> mLoadedListener;
|
||||
private final HttpClient mHttpClient;
|
||||
private final Map<TileKey,Image> mMemoryCache = new LinkedHashMap<>(MEMORY_CACHE_TILES, 0.75f, true)
|
||||
{
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<TileKey,Image> eldest)
|
||||
{
|
||||
return size() > MEMORY_CACHE_TILES;
|
||||
}
|
||||
};
|
||||
private final LinkedBlockingDeque<TileKey> mQueue = new LinkedBlockingDeque<>();
|
||||
private final Set<TileKey> mPending = ConcurrentHashMap.newKeySet();
|
||||
private final Map<TileKey,Long> mFailures = new ConcurrentHashMap<>();
|
||||
private volatile Set<TileKey> mWanted = Collections.emptySet();
|
||||
private volatile TileSource mSource;
|
||||
private final AtomicBoolean mTrimmed = new AtomicBoolean();
|
||||
private final List<Thread> mThreads = new ArrayList<>();
|
||||
private volatile boolean mRunning = true;
|
||||
|
||||
/**
|
||||
* Constructs an instance and starts the download threads. Nothing loads until a source is set.
|
||||
* @param cacheDirectory for the disk cache, with a folder for each source, or null for no disk cache
|
||||
* @param loadedListener notified on a download thread when a requested tile is ready in {@link #get(TileKey)}
|
||||
*/
|
||||
public TileLoader(Path cacheDirectory, Consumer<TileKey> loadedListener)
|
||||
{
|
||||
mCacheDirectory = cacheDirectory;
|
||||
mLoadedListener = loadedListener;
|
||||
mHttpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10))
|
||||
.followRedirects(HttpClient.Redirect.NORMAL).build();
|
||||
|
||||
for(int index = 0; index < DOWNLOAD_THREADS; index++)
|
||||
{
|
||||
Thread thread = Thread.ofPlatform().daemon().name("sdrtrunk map tile loader " + index)
|
||||
.unstarted(this::run);
|
||||
mThreads.add(thread);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tiles to load, dropping the loaded and requested tiles of the previous source. Call on the thread that
|
||||
* requests tiles.
|
||||
* @param source of the tiles, or null to load none
|
||||
*/
|
||||
public void setSource(TileSource source)
|
||||
{
|
||||
if(Objects.equals(source, mSource))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mSource = source;
|
||||
mQueue.clear();
|
||||
mPending.clear();
|
||||
mFailures.clear();
|
||||
|
||||
synchronized(mMemoryCache)
|
||||
{
|
||||
mMemoryCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tile image from the memory cache
|
||||
* @param key of the tile
|
||||
* @return image, or null when it isn't loaded
|
||||
*/
|
||||
public Image get(TileKey key)
|
||||
{
|
||||
synchronized(mMemoryCache)
|
||||
{
|
||||
return mMemoryCache.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tiles that are in view. Queued requests for other tiles are dropped when they come up.
|
||||
*/
|
||||
public void setWanted(Set<TileKey> wanted)
|
||||
{
|
||||
mWanted = Set.copyOf(wanted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a tile, unless it's loaded, already requested, or failed recently. The newest request loads first.
|
||||
*/
|
||||
public void request(TileKey key)
|
||||
{
|
||||
TileSource source = mSource;
|
||||
|
||||
if(source == null || !source.isAvailable() || get(key) != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Long failed = mFailures.get(key);
|
||||
|
||||
if(failed != null && System.currentTimeMillis() < failed + RETRY_DELAY.toMillis())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(mPending.add(key))
|
||||
{
|
||||
mQueue.addLast(key);
|
||||
}
|
||||
else if(mQueue.remove(key))
|
||||
{
|
||||
//Requested again, so move it to the front of the line
|
||||
mQueue.addLast(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the download threads
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
mRunning = false;
|
||||
mThreads.forEach(Thread::interrupt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download thread: takes the newest request, from the disk cache when it's fresh, else from the tile server
|
||||
*/
|
||||
private void run()
|
||||
{
|
||||
trimDiskCache();
|
||||
|
||||
while(mRunning)
|
||||
{
|
||||
TileKey key;
|
||||
|
||||
try
|
||||
{
|
||||
key = mQueue.takeLast();
|
||||
}
|
||||
catch(InterruptedException e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TileSource source = mSource;
|
||||
|
||||
try
|
||||
{
|
||||
if(source != null && source.isAvailable() && mWanted.contains(key))
|
||||
{
|
||||
Image image = load(key, source);
|
||||
|
||||
//Drop the tile when the source changed while it loaded
|
||||
if(source == mSource)
|
||||
{
|
||||
if(image != null)
|
||||
{
|
||||
mFailures.remove(key);
|
||||
|
||||
synchronized(mMemoryCache)
|
||||
{
|
||||
mMemoryCache.put(key, image);
|
||||
}
|
||||
|
||||
mLoadedListener.accept(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
mFailures.put(key, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Error loading map tile " + (source != null ? source.cacheName() : "") + " " + key, e);
|
||||
mFailures.put(key, System.currentTimeMillis());
|
||||
}
|
||||
finally
|
||||
{
|
||||
mPending.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a tile from the disk cache while it's fresh, else downloads it, falling back to a stale cached copy when the
|
||||
* download fails. Recolors the tile when the source darkens its tiles.
|
||||
* @return image, or null
|
||||
*/
|
||||
private Image load(TileKey key, TileSource source)
|
||||
{
|
||||
Path file = getCacheFile(key, source);
|
||||
byte[] bytes = null;
|
||||
boolean fresh = false;
|
||||
|
||||
if(file != null && Files.isRegularFile(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
//The file's modified time is when it expires
|
||||
fresh = Files.getLastModifiedTime(file).toMillis() > System.currentTimeMillis();
|
||||
bytes = Files.readAllBytes(file);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
bytes = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(!fresh)
|
||||
{
|
||||
byte[] downloaded = download(key, file, source);
|
||||
|
||||
if(downloaded != null)
|
||||
{
|
||||
bytes = downloaded;
|
||||
}
|
||||
}
|
||||
|
||||
if(bytes == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Image image = new Image(new ByteArrayInputStream(bytes));
|
||||
|
||||
if(image.isError())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.darken() ? TileDarkener.darken(image) : image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the tile and stores it in the disk cache
|
||||
* @param key of the tile
|
||||
* @param file of the disk cache, or null
|
||||
* @param source of the tile
|
||||
* @return tile image bytes, or null when the download failed
|
||||
*/
|
||||
private byte[] download(TileKey key, Path file, TileSource source)
|
||||
{
|
||||
if(!mRunning)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
URI uri = URI.create(source.getUrl(key));
|
||||
//The URL can hold the user's key, so the log names the source and the tile instead
|
||||
String tile = source.cacheName() + " " + key;
|
||||
HttpRequest request = HttpRequest.newBuilder(uri).timeout(Duration.ofSeconds(20))
|
||||
.header("User-Agent", USER_AGENT).GET().build();
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse<byte[]> response = mHttpClient.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||
|
||||
if(response.statusCode() != 200)
|
||||
{
|
||||
mLog.debug("Map tile " + tile + " response " + response.statusCode());
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = response.body();
|
||||
|
||||
if(file != null)
|
||||
{
|
||||
store(file, bytes, getExpiry(response));
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
catch(InterruptedException e)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.debug("Unable to download map tile " + tile + " - " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time the tile expires: the Cache-Control max-age, else the Expires header, else a week, and at least an hour
|
||||
*/
|
||||
private static long getExpiry(HttpResponse<?> response)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
Duration expiry = DEFAULT_EXPIRY;
|
||||
Optional<String> cacheControl = response.headers().firstValue("Cache-Control");
|
||||
Optional<String> expires = response.headers().firstValue("Expires");
|
||||
|
||||
if(cacheControl.isPresent())
|
||||
{
|
||||
Matcher matcher = MAX_AGE.matcher(cacheControl.get());
|
||||
|
||||
if(matcher.find())
|
||||
{
|
||||
expiry = Duration.ofSeconds(Long.parseLong(matcher.group(1)));
|
||||
}
|
||||
}
|
||||
else if(expires.isPresent())
|
||||
{
|
||||
try
|
||||
{
|
||||
long time = ZonedDateTime.parse(expires.get(), DateTimeFormatter.RFC_1123_DATE_TIME).toInstant()
|
||||
.toEpochMilli();
|
||||
expiry = Duration.ofMillis(time - now);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Use the default
|
||||
}
|
||||
}
|
||||
|
||||
if(expiry.compareTo(MINIMUM_EXPIRY) < 0)
|
||||
{
|
||||
expiry = MINIMUM_EXPIRY;
|
||||
}
|
||||
|
||||
return now + expiry.toMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the tile to the disk cache, with its modified time set to when it expires
|
||||
*/
|
||||
private static void store(Path file, byte[] bytes, long expiry)
|
||||
{
|
||||
try
|
||||
{
|
||||
Files.createDirectories(file.getParent());
|
||||
Path temporary = Files.createTempFile(file.getParent(), "tile", ".tmp");
|
||||
Files.write(temporary, bytes);
|
||||
Files.setLastModifiedTime(temporary, FileTime.fromMillis(expiry));
|
||||
Files.move(temporary, file, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.debug("Unable to cache map tile " + file + " - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Path getCacheFile(TileKey key, TileSource source)
|
||||
{
|
||||
return mCacheDirectory != null ? mCacheDirectory.resolve(source.cacheName())
|
||||
.resolve(String.valueOf(key.zoom())).resolve(String.valueOf(key.x())).resolve(key.y() + ".tile") : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the tiles that expire first when the disk cache grows past its limit. Runs once per instance.
|
||||
*/
|
||||
private void trimDiskCache()
|
||||
{
|
||||
if(mCacheDirectory == null || !Files.isDirectory(mCacheDirectory) || mTrimmed.getAndSet(true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
record CachedTile(Path path, long size, long expiry) {}
|
||||
|
||||
List<CachedTile> tiles = new ArrayList<>();
|
||||
|
||||
try(Stream<Path> stream = Files.walk(mCacheDirectory))
|
||||
{
|
||||
stream.filter(Files::isRegularFile).forEach(path -> {
|
||||
try
|
||||
{
|
||||
tiles.add(new CachedTile(path, Files.size(path), Files.getLastModifiedTime(path).toMillis()));
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//Skip it
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
mLog.debug("Unable to read the map tile cache - " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
long total = tiles.stream().mapToLong(CachedTile::size).sum();
|
||||
|
||||
if(total <= DISK_CACHE_LIMIT_BYTES)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tiles.sort(Comparator.comparingLong(CachedTile::expiry));
|
||||
int deleted = 0;
|
||||
|
||||
for(CachedTile tile: tiles)
|
||||
{
|
||||
if(total <= DISK_CACHE_TRIM_BYTES)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Files.deleteIfExists(tile.path());
|
||||
total -= tile.size();
|
||||
deleted++;
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
//Skip it
|
||||
}
|
||||
}
|
||||
|
||||
mLog.info("Trimmed the map tile cache: deleted " + deleted + " tiles");
|
||||
}
|
||||
}
|
||||
546
src/main/java/io/github/dsheirer/gui/map/TileMapView.java
Normal file
546
src/main/java/io/github/dsheirer/gui/map/TileMapView.java
Normal file
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
||||
import javafx.beans.property.ReadOnlyIntegerWrapper;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.scene.input.ZoomEvent;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
|
||||
/**
|
||||
* JavaFX slippy map: tiles from a {@link TileSource} drawn on a canvas, with {@link MapLayer} overlays. While a tile
|
||||
* loads, the matching part of a loaded tile from a farther zoom level stands in for it. Past the source's highest
|
||||
* zoom level, its closest tiles are enlarged.
|
||||
*
|
||||
* Mouse: drag with the primary button to pan, scroll to zoom at the mouse, double-click or middle-click to center and
|
||||
* zoom in. Keys: arrows pan, plus and minus zoom. Use on the JavaFX thread.
|
||||
*/
|
||||
public class TileMapView extends Region
|
||||
{
|
||||
private static final Color BACKGROUND = Color.rgb(221, 221, 221);
|
||||
private static final Color DARK_BACKGROUND = Color.rgb(38, 38, 38);
|
||||
private static final Color ATTRIBUTION_BACKGROUND = Color.rgb(255, 255, 255, 0.75);
|
||||
private static final Color DARK_ATTRIBUTION_BACKGROUND = Color.rgb(30, 30, 30, 0.75);
|
||||
private static final Color ATTRIBUTION_TEXT = Color.rgb(40, 40, 40);
|
||||
private static final Color DARK_ATTRIBUTION_TEXT = Color.rgb(210, 210, 210);
|
||||
private static final Font ATTRIBUTION_FONT = Font.font(11);
|
||||
private static final Font MESSAGE_FONT = Font.font(14);
|
||||
private static final int FALLBACK_LEVELS = 5;
|
||||
//Scroll distance for one zoom step: one mouse wheel notch, or several trackpad events
|
||||
private static final double SCROLL_STEP = 40.0;
|
||||
private static final double PINCH_STEP = 1.4;
|
||||
private static final double KEY_PAN_PIXELS = 64.0;
|
||||
|
||||
private final Canvas mCanvas = new Canvas();
|
||||
private final MapViewport mViewport = new MapViewport();
|
||||
private final TileLoader mTileLoader;
|
||||
private final List<MapLayer> mLayers = new ArrayList<>();
|
||||
private final List<Runnable> mViewListeners = new CopyOnWriteArrayList<>();
|
||||
private final ReadOnlyIntegerWrapper mZoom = new ReadOnlyIntegerWrapper(mViewport.getZoom());
|
||||
private final Text mMeasure = new Text();
|
||||
private TileSource mSource;
|
||||
private boolean mRedrawPending;
|
||||
private double mDragX = Double.NaN;
|
||||
private double mDragY = Double.NaN;
|
||||
private double mScrollAccumulator;
|
||||
private double mPinchAccumulator = 1.0;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param cacheDirectory for the map tiles on disk, or null to not keep tiles on disk
|
||||
* @param loadTiles true to download tiles, or false for a blank map (tests and off-screen rendering)
|
||||
*/
|
||||
public TileMapView(Path cacheDirectory, boolean loadTiles)
|
||||
{
|
||||
mTileLoader = loadTiles ? new TileLoader(cacheDirectory, key -> Platform.runLater(this::requestRedraw)) : null;
|
||||
getChildren().add(mCanvas);
|
||||
setFocusTraversable(true);
|
||||
setMinSize(0, 0);
|
||||
setPrefSize(600, 400);
|
||||
|
||||
addEventHandler(MouseEvent.MOUSE_PRESSED, this::mousePressed);
|
||||
addEventHandler(MouseEvent.MOUSE_DRAGGED, this::mouseDragged);
|
||||
addEventHandler(MouseEvent.MOUSE_RELEASED, this::mouseReleased);
|
||||
addEventHandler(MouseEvent.MOUSE_CLICKED, this::mouseClicked);
|
||||
addEventHandler(ScrollEvent.SCROLL, this::scrolled);
|
||||
addEventHandler(ZoomEvent.ZOOM_STARTED, event -> mPinchAccumulator = 1.0);
|
||||
addEventHandler(ZoomEvent.ZOOM, this::pinched);
|
||||
addEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Viewport, for converting positions to screen pixels
|
||||
*/
|
||||
public MapViewport getViewport()
|
||||
{
|
||||
return mViewport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tiles to show, dropping the tiles of the previous source
|
||||
* @param source of the tiles, or null to show none
|
||||
*/
|
||||
public void setSource(TileSource source)
|
||||
{
|
||||
mSource = source;
|
||||
|
||||
if(mTileLoader != null)
|
||||
{
|
||||
mTileLoader.setSource(source);
|
||||
}
|
||||
|
||||
requestRedraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Source of the tiles, or null
|
||||
*/
|
||||
public TileSource getSource()
|
||||
{
|
||||
return mSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tile zoom level, updated when the map zooms
|
||||
*/
|
||||
public ReadOnlyIntegerProperty zoomProperty()
|
||||
{
|
||||
return mZoom.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
public int getZoom()
|
||||
{
|
||||
return mViewport.getZoom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the tile zoom level, keeping the center point
|
||||
*/
|
||||
public void setZoom(int zoom)
|
||||
{
|
||||
if(zoom != mViewport.getZoom())
|
||||
{
|
||||
mViewport.setZoom(zoom);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the zoom level, keeping the position under the screen point in place
|
||||
*/
|
||||
public void zoomAt(int zoom, double x, double y)
|
||||
{
|
||||
if(zoom != mViewport.getZoom())
|
||||
{
|
||||
mViewport.zoomAt(zoom, x, y);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public GeoPosition getCenter()
|
||||
{
|
||||
return mViewport.getCenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Centers the map on the position
|
||||
*/
|
||||
public void setCenter(GeoPosition position)
|
||||
{
|
||||
if(position != null)
|
||||
{
|
||||
mViewport.setCenter(position);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a layer over the tiles and the layers added before it
|
||||
*/
|
||||
public void addLayer(MapLayer layer)
|
||||
{
|
||||
mLayers.add(layer);
|
||||
requestRedraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener that's notified on the JavaFX thread each time the map pans or zooms
|
||||
*/
|
||||
public void addViewListener(Runnable listener)
|
||||
{
|
||||
mViewListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the map on the next JavaFX pulse. Can be called often: the requests are combined.
|
||||
*/
|
||||
public void requestRedraw()
|
||||
{
|
||||
if(!mRedrawPending)
|
||||
{
|
||||
mRedrawPending = true;
|
||||
Platform.runLater(() -> {
|
||||
mRedrawPending = false;
|
||||
draw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops loading tiles
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if(mTileLoader != null)
|
||||
{
|
||||
mTileLoader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void viewChanged()
|
||||
{
|
||||
mZoom.set(mViewport.getZoom());
|
||||
requestRedraw();
|
||||
mViewListeners.forEach(Runnable::run);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layoutChildren()
|
||||
{
|
||||
double width = snapSizeX(getWidth());
|
||||
double height = snapSizeY(getHeight());
|
||||
|
||||
if(mCanvas.getWidth() != width || mCanvas.getHeight() != height)
|
||||
{
|
||||
mCanvas.setWidth(width);
|
||||
mCanvas.setHeight(height);
|
||||
mViewport.setSize(width, height);
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the tiles and the layers now
|
||||
*/
|
||||
public void draw()
|
||||
{
|
||||
GraphicsContext gc = mCanvas.getGraphicsContext2D();
|
||||
double width = mCanvas.getWidth();
|
||||
double height = mCanvas.getHeight();
|
||||
boolean dark = mSource != null && mSource.dark();
|
||||
gc.setFill(dark ? DARK_BACKGROUND : BACKGROUND);
|
||||
gc.fillRect(0, 0, width, height);
|
||||
|
||||
if(width <= 0 || height <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(mSource != null && mSource.isAvailable())
|
||||
{
|
||||
drawTiles(gc, width, height);
|
||||
}
|
||||
else if(mSource != null && mSource.unavailableReason() != null)
|
||||
{
|
||||
gc.setFill(dark ? DARK_ATTRIBUTION_TEXT : ATTRIBUTION_TEXT);
|
||||
gc.setFont(MESSAGE_FONT);
|
||||
gc.setTextAlign(TextAlignment.CENTER);
|
||||
gc.setTextBaseline(VPos.CENTER);
|
||||
gc.fillText(mSource.unavailableReason(), width / 2.0, height / 2.0);
|
||||
}
|
||||
|
||||
for(MapLayer layer: mLayers)
|
||||
{
|
||||
gc.save();
|
||||
layer.draw(gc, this);
|
||||
gc.restore();
|
||||
}
|
||||
|
||||
if(mSource != null)
|
||||
{
|
||||
drawAttribution(gc, mSource.attribution(), dark, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTiles(GraphicsContext gc, double width, double height)
|
||||
{
|
||||
int zoom = mViewport.getZoom();
|
||||
int count = Mercator.tileCount(zoom);
|
||||
double left = mViewport.getLeft();
|
||||
double top = mViewport.getTop();
|
||||
int firstColumn = (int)Math.floor(left / Mercator.TILE_SIZE);
|
||||
int lastColumn = (int)Math.floor((left + width - 1) / Mercator.TILE_SIZE);
|
||||
int firstRow = Math.max(0, (int)Math.floor(top / Mercator.TILE_SIZE));
|
||||
int lastRow = Math.min(count - 1, (int)Math.floor((top + height - 1) / Mercator.TILE_SIZE));
|
||||
|
||||
//Past the source's highest zoom level, its closest tiles are enlarged
|
||||
int enlarged = Math.max(0, zoom - mSource.maxZoom());
|
||||
Set<TileKey> wanted = new HashSet<>();
|
||||
List<TileKey> missing = new ArrayList<>();
|
||||
|
||||
for(int row = firstRow; row <= lastRow; row++)
|
||||
{
|
||||
for(int column = firstColumn; column <= lastColumn; column++)
|
||||
{
|
||||
TileKey key = new TileKey(zoom, Math.floorMod(column, count), row);
|
||||
TileKey source = enlarged > 0 ? key.parent(enlarged) : key;
|
||||
double x = column * (double)Mercator.TILE_SIZE - left;
|
||||
double y = row * (double)Mercator.TILE_SIZE - top;
|
||||
wanted.add(source);
|
||||
|
||||
Image image = mTileLoader != null ? mTileLoader.get(source) : null;
|
||||
|
||||
if(image != null)
|
||||
{
|
||||
drawPart(gc, image, key, enlarged, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawFallback(gc, key, enlarged, x, y);
|
||||
|
||||
if(!missing.contains(source))
|
||||
{
|
||||
missing.add(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mTileLoader != null)
|
||||
{
|
||||
mTileLoader.setWanted(wanted);
|
||||
|
||||
//Request the tiles nearest the middle last, so they load first
|
||||
double scale = 1 << enlarged;
|
||||
int sourceCount = Mercator.tileCount(zoom - enlarged);
|
||||
double middleColumn = ((left + width / 2.0) / Mercator.TILE_SIZE) / scale - 0.5;
|
||||
double middleRow = ((top + height / 2.0) / Mercator.TILE_SIZE) / scale - 0.5;
|
||||
missing.sort((a, b) -> Double.compare(distance(b, middleColumn, middleRow, sourceCount),
|
||||
distance(a, middleColumn, middleRow, sourceCount)));
|
||||
missing.forEach(mTileLoader::request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Distance in tiles from the middle of the view, allowing for the world repeating east and west
|
||||
*/
|
||||
private static double distance(TileKey key, double column, double row, int count)
|
||||
{
|
||||
double dx = Math.abs(key.x() - Math.floorMod((long)Math.floor(column), count));
|
||||
dx = Math.min(dx, count - dx);
|
||||
return Math.hypot(dx, key.y() - row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the part of a tile from a farther zoom level that covers the tile, enlarged to the tile's size
|
||||
* @param image of the tile from the farther zoom level
|
||||
* @param key of the tile to cover
|
||||
* @param levels between the tiles' zoom levels, 0 to draw the whole image
|
||||
*/
|
||||
private static void drawPart(GraphicsContext gc, Image image, TileKey key, int levels, double x, double y)
|
||||
{
|
||||
if(levels == 0)
|
||||
{
|
||||
gc.drawImage(image, x, y, Mercator.TILE_SIZE, Mercator.TILE_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
TileKey parent = key.parent(levels);
|
||||
double size = image.getWidth() / (1 << levels);
|
||||
double sourceX = (key.x() - ((long)parent.x() << levels)) * size;
|
||||
double sourceY = (key.y() - ((long)parent.y() << levels)) * size;
|
||||
gc.drawImage(image, sourceX, sourceY, size, size, x, y, Mercator.TILE_SIZE, Mercator.TILE_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the part of a loaded tile from a farther zoom level than the requested tile that covers the tile
|
||||
* @param enlarged levels between the tile and the requested tile
|
||||
*/
|
||||
private void drawFallback(GraphicsContext gc, TileKey key, int enlarged, double x, double y)
|
||||
{
|
||||
if(mTileLoader == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(int levels = enlarged + 1; levels <= enlarged + FALLBACK_LEVELS && key.zoom() - levels >= 0; levels++)
|
||||
{
|
||||
Image image = mTileLoader.get(key.parent(levels));
|
||||
|
||||
if(image != null)
|
||||
{
|
||||
drawPart(gc, image, key, levels, x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attribution in the bottom right corner, required by the tile servers
|
||||
*/
|
||||
private void drawAttribution(GraphicsContext gc, String attribution, boolean dark, double width, double height)
|
||||
{
|
||||
mMeasure.setText(attribution);
|
||||
mMeasure.setFont(ATTRIBUTION_FONT);
|
||||
double boxWidth = mMeasure.getLayoutBounds().getWidth() + 8;
|
||||
double boxHeight = 16;
|
||||
gc.setFill(dark ? DARK_ATTRIBUTION_BACKGROUND : ATTRIBUTION_BACKGROUND);
|
||||
gc.fillRect(width - boxWidth, height - boxHeight, boxWidth, boxHeight);
|
||||
gc.setFill(dark ? DARK_ATTRIBUTION_TEXT : ATTRIBUTION_TEXT);
|
||||
gc.setFont(ATTRIBUTION_FONT);
|
||||
gc.setTextAlign(TextAlignment.LEFT);
|
||||
gc.setTextBaseline(VPos.CENTER);
|
||||
gc.fillText(attribution, width - boxWidth + 4, height - boxHeight / 2.0);
|
||||
}
|
||||
|
||||
private void mousePressed(MouseEvent event)
|
||||
{
|
||||
requestFocus();
|
||||
|
||||
if(event.getButton() == MouseButton.PRIMARY)
|
||||
{
|
||||
mDragX = event.getX();
|
||||
mDragY = event.getY();
|
||||
}
|
||||
}
|
||||
|
||||
private void mouseDragged(MouseEvent event)
|
||||
{
|
||||
if(event.isPrimaryButtonDown() && !Double.isNaN(mDragX))
|
||||
{
|
||||
mViewport.pan(mDragX - event.getX(), mDragY - event.getY());
|
||||
mDragX = event.getX();
|
||||
mDragY = event.getY();
|
||||
setCursor(Cursor.MOVE);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void mouseReleased(MouseEvent event)
|
||||
{
|
||||
if(event.getButton() == MouseButton.PRIMARY)
|
||||
{
|
||||
mDragX = Double.NaN;
|
||||
mDragY = Double.NaN;
|
||||
setCursor(Cursor.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
private void mouseClicked(MouseEvent event)
|
||||
{
|
||||
boolean doubleClick = event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2 &&
|
||||
event.isStillSincePress();
|
||||
|
||||
if(doubleClick || event.getButton() == MouseButton.MIDDLE)
|
||||
{
|
||||
mViewport.setCenter(mViewport.getPosition(event.getX(), event.getY()));
|
||||
mViewport.setZoom(mViewport.getZoom() + 1);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void scrolled(ScrollEvent event)
|
||||
{
|
||||
if(event.getDeltaY() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Restart when the direction changes
|
||||
if(Math.signum(event.getDeltaY()) != Math.signum(mScrollAccumulator))
|
||||
{
|
||||
mScrollAccumulator = 0;
|
||||
}
|
||||
|
||||
mScrollAccumulator += event.getDeltaY();
|
||||
int steps = (int)(mScrollAccumulator / SCROLL_STEP);
|
||||
|
||||
if(steps != 0)
|
||||
{
|
||||
mScrollAccumulator -= steps * SCROLL_STEP;
|
||||
zoomAt(mViewport.getZoom() + steps, event.getX(), event.getY());
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void pinched(ZoomEvent event)
|
||||
{
|
||||
mPinchAccumulator *= event.getZoomFactor();
|
||||
|
||||
if(mPinchAccumulator >= PINCH_STEP)
|
||||
{
|
||||
mPinchAccumulator = 1.0;
|
||||
zoomAt(mViewport.getZoom() + 1, event.getX(), event.getY());
|
||||
}
|
||||
else if(mPinchAccumulator <= 1.0 / PINCH_STEP)
|
||||
{
|
||||
mPinchAccumulator = 1.0;
|
||||
zoomAt(mViewport.getZoom() - 1, event.getX(), event.getY());
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void keyPressed(KeyEvent event)
|
||||
{
|
||||
switch(event.getCode())
|
||||
{
|
||||
case LEFT, KP_LEFT -> pan(-KEY_PAN_PIXELS, 0);
|
||||
case RIGHT, KP_RIGHT -> pan(KEY_PAN_PIXELS, 0);
|
||||
case UP, KP_UP -> pan(0, -KEY_PAN_PIXELS);
|
||||
case DOWN, KP_DOWN -> pan(0, KEY_PAN_PIXELS);
|
||||
case PLUS, EQUALS, ADD -> setZoom(getZoom() + 1);
|
||||
case MINUS, SUBTRACT -> setZoom(getZoom() - 1);
|
||||
default -> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.consume();
|
||||
}
|
||||
|
||||
private void pan(double dx, double dy)
|
||||
{
|
||||
mViewport.pan(dx, dy);
|
||||
viewChanged();
|
||||
}
|
||||
}
|
||||
129
src/main/java/io/github/dsheirer/gui/map/TileServer.java
Normal file
129
src/main/java/io/github/dsheirer/gui/map/TileServer.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Free map tile server. A server with a dark style follows the theme; a server without one has its light tiles
|
||||
* recolored in dark themes.
|
||||
* @param id stored in the map preference. Don't change it.
|
||||
* @param name shown to the user
|
||||
* @param lightUrl template of the light style tiles, see {@link TileSource#urlTemplate()}, with a {key} placeholder
|
||||
* when the server needs a key
|
||||
* @param darkUrl template of the dark style tiles, or null when the server has no dark style
|
||||
* @param subdomains for the {s} placeholder, or empty
|
||||
* @param maxZoom highest zoom level the server provides
|
||||
* @param attribution required by the server
|
||||
* @param keyUrl web page where the user gets a free key, or null when the server doesn't need a key
|
||||
*/
|
||||
public record TileServer(String id, String name, String lightUrl, String darkUrl, List<String> subdomains,
|
||||
int maxZoom, String attribution, String keyUrl)
|
||||
{
|
||||
private static final String OSM = "© OpenStreetMap contributors";
|
||||
|
||||
public static final TileServer OPEN_STREET_MAP = new TileServer("osm", "OpenStreetMap",
|
||||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png", null, List.of(), 19, OSM, null);
|
||||
|
||||
/**
|
||||
* Positron (light) and Dark Matter (dark). Needs a free key since 25 September 2026: 5 million tiles per month
|
||||
* for non-commercial use.
|
||||
*/
|
||||
public static final TileServer CARTO = new TileServer("carto", "CARTO",
|
||||
"https://basemaps.cartocdn.com/rastertiles/light_all/{z}/{x}/{y}.png?key={key}",
|
||||
"https://basemaps.cartocdn.com/rastertiles/dark_all/{z}/{x}/{y}.png?key={key}", List.of(), 18,
|
||||
OSM + ", © CARTO", "https://carto.com/basemaps/apikey/");
|
||||
|
||||
public static final TileServer ESRI_GRAY = new TileServer("esri.gray", "Esri Gray Canvas",
|
||||
"https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}",
|
||||
"https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}",
|
||||
List.of(), 16, "Tiles © Esri — Esri, HERE, Garmin, " + OSM, null);
|
||||
|
||||
public static final TileServer OPEN_TOPO_MAP = new TileServer("opentopomap", "OpenTopoMap",
|
||||
"https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", null, List.of("a", "b", "c"), 17,
|
||||
"Map data: " + OSM + ", SRTM | Map style: © OpenTopoMap (CC-BY-SA)", null);
|
||||
|
||||
/**
|
||||
* Servers offered to the user, in menu order
|
||||
*/
|
||||
public static final List<TileServer> SERVERS = List.of(OPEN_STREET_MAP, CARTO, ESRI_GRAY, OPEN_TOPO_MAP);
|
||||
|
||||
/**
|
||||
* Server with the id
|
||||
* @param id from the map preference, or null
|
||||
* @return server, or OpenStreetMap when there's no server with the id
|
||||
*/
|
||||
public static TileServer get(String id)
|
||||
{
|
||||
return SERVERS.stream().filter(server -> server.id().equals(id)).findFirst().orElse(OPEN_STREET_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the server needs a key from the user
|
||||
*/
|
||||
public boolean requiresKey()
|
||||
{
|
||||
return keyUrl != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the server has its own dark style
|
||||
*/
|
||||
public boolean hasDarkStyle()
|
||||
{
|
||||
return darkUrl != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tiles to load for the theme
|
||||
* @param dark true for a dark theme
|
||||
* @param key from the user, for a server that needs one, or null
|
||||
*/
|
||||
public TileSource getSource(boolean dark, String key)
|
||||
{
|
||||
boolean darkStyle = dark && hasDarkStyle();
|
||||
String template = darkStyle ? darkUrl : lightUrl;
|
||||
String cacheName = id + (darkStyle ? "/dark" : "/light");
|
||||
String unavailable = null;
|
||||
|
||||
if(requiresKey())
|
||||
{
|
||||
if(key == null || key.isBlank())
|
||||
{
|
||||
unavailable = name + " needs a free API key: enter it in the map's Settings tab";
|
||||
}
|
||||
else
|
||||
{
|
||||
template = template.replace("{key}", URLEncoder.encode(key.strip(), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
return new TileSource(cacheName, template, subdomains, maxZoom, dark && !hasDarkStyle(), dark, attribution,
|
||||
unavailable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
57
src/main/java/io/github/dsheirer/gui/map/TileSource.java
Normal file
57
src/main/java/io/github/dsheirer/gui/map/TileSource.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tiles the map loads: one style of a {@link TileServer}, resolved for the theme and the user's key.
|
||||
* @param cacheName folder of the tiles in the disk cache, e.g. osm/light
|
||||
* @param urlTemplate with {s} subdomain, {z} zoom, {x} column and {y} row placeholders, or null when unavailable
|
||||
* @param subdomains for the {s} placeholder, or empty
|
||||
* @param maxZoom highest zoom level the server provides. Closer zoom levels enlarge these tiles.
|
||||
* @param darken true to recolor the tiles for a dark theme, for a server without a dark style
|
||||
* @param dark true when the tiles are dark, from a dark style or recolored
|
||||
* @param attribution shown on the map, as the server requires
|
||||
* @param unavailableReason shown instead of tiles when the source can't load tiles, or null
|
||||
*/
|
||||
public record TileSource(String cacheName, String urlTemplate, List<String> subdomains, int maxZoom, boolean darken,
|
||||
boolean dark, String attribution, String unavailableReason)
|
||||
{
|
||||
/**
|
||||
* Indicates if the source can load tiles
|
||||
*/
|
||||
public boolean isAvailable()
|
||||
{
|
||||
return urlTemplate != null && unavailableReason == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL of the tile. Spreads the tiles over the subdomains by position, so each tile always comes from the same
|
||||
* subdomain and stays in the server's and the browser-style caches.
|
||||
*/
|
||||
public String getUrl(TileKey key)
|
||||
{
|
||||
String subdomain = subdomains.isEmpty() ? "" :
|
||||
subdomains.get(Math.floorMod(key.x() + key.y(), subdomains.size()));
|
||||
return urlTemplate.replace("{s}", subdomain).replace("{z}", String.valueOf(key.zoom()))
|
||||
.replace("{x}", String.valueOf(key.x())).replace("{y}", String.valueOf(key.y()));
|
||||
}
|
||||
}
|
||||
228
src/main/java/io/github/dsheirer/gui/map/TrackLayer.java
Normal file
228
src/main/java/io/github/dsheirer/gui/map/TrackLayer.java
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.icon.Icon;
|
||||
import io.github.dsheirer.icon.IconModel;
|
||||
import io.github.dsheirer.map.PlottableEntityHistory;
|
||||
import io.github.dsheirer.map.PlottableEntityModel;
|
||||
import io.github.dsheirer.map.TimestampedGeoPosition;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.StrokeLineCap;
|
||||
import javafx.scene.shape.StrokeLineJoin;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.TextAlignment;
|
||||
|
||||
/**
|
||||
* Plotted tracks: for each entity, a two-tone trail through its most recent positions, its alias icon at the latest
|
||||
* position and its alias name (or identifier) beside the icon, in the alias color. Use on the JavaFX thread.
|
||||
*/
|
||||
public class TrackLayer implements MapLayer
|
||||
{
|
||||
private static final Color DEFAULT_COLOR = Color.BLUE;
|
||||
private static final Color TRAIL_BACKGROUND = Color.BLACK;
|
||||
private static final Color LABEL_HALO = Color.rgb(255, 255, 255, 0.85);
|
||||
private static final Font LABEL_FONT = Font.font(12);
|
||||
//Map edge allowance for icons and labels that are partly in view
|
||||
private static final double MARGIN = 200;
|
||||
|
||||
private final PlottableEntityModel mEntityModel;
|
||||
private final IconModel mIconModel;
|
||||
private final Set<PlottableEntityHistory> mEntities = new LinkedHashSet<>();
|
||||
private int mTrackHistoryLength = 3;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param entityModel for the entities' aliases
|
||||
* @param iconModel for the alias icons
|
||||
*/
|
||||
public TrackLayer(PlottableEntityModel entityModel, IconModel iconModel)
|
||||
{
|
||||
mEntityModel = entityModel;
|
||||
mIconModel = iconModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of positions in each trail, including the latest position
|
||||
*/
|
||||
public int getTrackHistoryLength()
|
||||
{
|
||||
return mTrackHistoryLength;
|
||||
}
|
||||
|
||||
public void setTrackHistoryLength(int length)
|
||||
{
|
||||
mTrackHistoryLength = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the entity
|
||||
* @return true if it wasn't shown
|
||||
*/
|
||||
public boolean add(PlottableEntityHistory entity)
|
||||
{
|
||||
return entity != null && mEntities.add(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the entities
|
||||
* @return true if any wasn't shown
|
||||
*/
|
||||
public boolean addAll(Collection<PlottableEntityHistory> entities)
|
||||
{
|
||||
boolean added = false;
|
||||
|
||||
for(PlottableEntityHistory entity: entities)
|
||||
{
|
||||
added |= add(entity);
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops showing the entities
|
||||
*/
|
||||
public void removeAll(Collection<PlottableEntityHistory> entities)
|
||||
{
|
||||
mEntities.removeAll(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops showing all entities. They're shown again when they report a new position.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
mEntities.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GraphicsContext gc, TileMapView map)
|
||||
{
|
||||
MapViewport viewport = map.getViewport();
|
||||
gc.setLineCap(StrokeLineCap.ROUND);
|
||||
gc.setLineJoin(StrokeLineJoin.ROUND);
|
||||
gc.setFont(LABEL_FONT);
|
||||
gc.setTextAlign(TextAlignment.LEFT);
|
||||
gc.setTextBaseline(VPos.CENTER);
|
||||
|
||||
for(PlottableEntityHistory entity: mEntities)
|
||||
{
|
||||
List<TimestampedGeoPosition> history = entity.getTrackHistoryModel().getTrackHistory();
|
||||
|
||||
if(history.isEmpty() || !history.getFirst().isValid())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Alias> aliases = mEntityModel.getAliases(entity);
|
||||
Alias alias = aliases.isEmpty() ? null : aliases.getFirst();
|
||||
Color color = alias != null ? toColor(alias.getColor()) : DEFAULT_COLOR;
|
||||
|
||||
drawTrail(gc, viewport, history, color);
|
||||
|
||||
TimestampedGeoPosition latest = history.getFirst();
|
||||
double x = viewport.getScreenX(latest.getLongitude());
|
||||
double y = viewport.getScreenY(latest.getLatitude());
|
||||
|
||||
if(x < -MARGIN || x > viewport.getWidth() + MARGIN || y < -MARGIN || y > viewport.getHeight() + MARGIN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
double iconWidth = drawIcon(gc, alias, x, y);
|
||||
String label = alias != null ? alias.getName() : String.valueOf(entity.getIdentifier());
|
||||
double labelX = x + iconWidth / 2.0 + 3;
|
||||
gc.setStroke(LABEL_HALO);
|
||||
gc.setLineWidth(3);
|
||||
gc.strokeText(label, labelX, y);
|
||||
gc.setFill(color);
|
||||
gc.fillText(label, labelX, y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trail through the most recent positions: a wide black line under a narrow line in the entity's color
|
||||
*/
|
||||
private void drawTrail(GraphicsContext gc, MapViewport viewport, List<TimestampedGeoPosition> history,
|
||||
Color color)
|
||||
{
|
||||
int length = Math.min(history.size(), mTrackHistoryLength);
|
||||
|
||||
if(length < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double[] xs = new double[length];
|
||||
double[] ys = new double[length];
|
||||
double reference = viewport.getScreenX(history.getFirst().getLongitude());
|
||||
double worldSize = viewport.getWorldSize();
|
||||
|
||||
for(int index = 0; index < length; index++)
|
||||
{
|
||||
TimestampedGeoPosition position = history.get(index);
|
||||
double x = viewport.getScreenX(position.getLongitude());
|
||||
//Keep the trail on the same copy of the world as the latest position
|
||||
xs[index] = x - Math.round((x - reference) / worldSize) * worldSize;
|
||||
ys[index] = viewport.getScreenY(position.getLatitude());
|
||||
}
|
||||
|
||||
gc.setStroke(TRAIL_BACKGROUND);
|
||||
gc.setLineWidth(3);
|
||||
gc.strokePolyline(xs, ys, length);
|
||||
gc.setStroke(color);
|
||||
gc.setLineWidth(1);
|
||||
gc.strokePolyline(xs, ys, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the alias icon, or the default icon, centered on the point
|
||||
* @return drawn icon width
|
||||
*/
|
||||
private double drawIcon(GraphicsContext gc, Alias alias, double x, double y)
|
||||
{
|
||||
Icon icon = mIconModel.getIcon(alias != null ? alias.getIconName() : null);
|
||||
Image image = icon != null ? icon.getFxImage() : null;
|
||||
|
||||
if(image == null || image.getHeight() <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double height = IconModel.DEFAULT_ICON_SIZE;
|
||||
double width = image.getWidth() * height / image.getHeight();
|
||||
gc.drawImage(image, x - width / 2.0, y - height / 2.0, width, height);
|
||||
return width;
|
||||
}
|
||||
|
||||
private static Color toColor(int rgb)
|
||||
{
|
||||
return Color.rgb((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.StrokeLineCap;
|
||||
|
||||
/**
|
||||
* Push-pin at the user's location, with the tip of the pin at the location. Use on the JavaFX thread.
|
||||
*/
|
||||
public class UserLocationLayer implements MapLayer
|
||||
{
|
||||
private static final Color NEEDLE = Color.rgb(90, 90, 90);
|
||||
private static final Color HEAD = Color.rgb(220, 40, 40);
|
||||
private static final Color HEAD_OUTLINE = Color.rgb(110, 0, 0);
|
||||
private static final Color HIGHLIGHT = Color.rgb(255, 255, 255, 170 / 255.0);
|
||||
private static final Color SHADOW = Color.rgb(0, 0, 0, 70 / 255.0);
|
||||
private static final double NEEDLE_LENGTH = 14.0;
|
||||
private static final double HEAD_RADIUS = 7.0;
|
||||
|
||||
private GeoPosition mPosition;
|
||||
|
||||
/**
|
||||
* Sets the location to mark
|
||||
* @param position of the user, or null to remove the pin
|
||||
*/
|
||||
public void setPosition(GeoPosition position)
|
||||
{
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location that is marked, or null
|
||||
*/
|
||||
public GeoPosition getPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GraphicsContext gc, TileMapView map)
|
||||
{
|
||||
if(mPosition == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MapViewport viewport = map.getViewport();
|
||||
double x = viewport.getScreenX(mPosition.getLongitude());
|
||||
double y = viewport.getScreenY(mPosition.getLatitude());
|
||||
double headY = y - NEEDLE_LENGTH - HEAD_RADIUS;
|
||||
|
||||
//Shadow where the needle enters the map, so the tip reads as the location
|
||||
gc.setFill(SHADOW);
|
||||
gc.fillOval(x - 4, y - 2, 8, 4);
|
||||
|
||||
gc.setStroke(NEEDLE);
|
||||
gc.setLineWidth(2.0);
|
||||
gc.setLineCap(StrokeLineCap.ROUND);
|
||||
gc.strokeLine(x, y, x, headY);
|
||||
|
||||
gc.setFill(HEAD);
|
||||
gc.fillOval(x - HEAD_RADIUS, headY - HEAD_RADIUS, HEAD_RADIUS * 2, HEAD_RADIUS * 2);
|
||||
gc.setStroke(HEAD_OUTLINE);
|
||||
gc.setLineWidth(1.0);
|
||||
gc.strokeOval(x - HEAD_RADIUS, headY - HEAD_RADIUS, HEAD_RADIUS * 2, HEAD_RADIUS * 2);
|
||||
|
||||
gc.setFill(HIGHLIGHT);
|
||||
gc.fillOval(x - HEAD_RADIUS / 2 - 1, headY - HEAD_RADIUS / 2 - 1, 4, 4);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import io.github.dsheirer.preference.swing.SwingPreference;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
@@ -30,8 +31,14 @@ import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
import javafx.collections.transformation.SortedList;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.SelectionMode;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyCodeCombination;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
@@ -45,6 +52,7 @@ import javafx.scene.layout.VBox;
|
||||
*/
|
||||
public abstract class HistoryTableView<T,F> extends VBox
|
||||
{
|
||||
private static final KeyCombination COPY = new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN);
|
||||
private final ObservableList<Row<T>> mRows = FXCollections.observableArrayList();
|
||||
private final FilteredList<Row<T>> mFilteredRows = new FilteredList<>(mRows);
|
||||
private final Map<T,Row<T>> mRowMap = new HashMap<>();
|
||||
@@ -71,6 +79,16 @@ public abstract class HistoryTableView<T,F> extends VBox
|
||||
mTableView.setItems(sortedRows);
|
||||
mTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_SUBSEQUENT_COLUMNS);
|
||||
mTableView.setPlaceholder(new Label(""));
|
||||
mTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
mTableView.setOnKeyPressed(event -> {
|
||||
if(COPY.match(event))
|
||||
{
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
content.putString(getSelectedText());
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
event.consume();
|
||||
}
|
||||
});
|
||||
mTableColumnMonitor = new TableColumnMonitor<>(mTableView, tableKey, swingPreference, swingTableKey);
|
||||
mHistoryControls = new HistoryControls<>(filterEditorTitle, this::clear, this::setHistorySize,
|
||||
mTableColumnMonitor, columnsTitle);
|
||||
@@ -160,6 +178,32 @@ public abstract class HistoryTableView<T,F> extends VBox
|
||||
mRows.forEach(Row::refresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text of the selected rows, one line per row with the visible column values separated by tabs.
|
||||
*/
|
||||
private String getSelectedText()
|
||||
{
|
||||
StringJoiner text = new StringJoiner("\n");
|
||||
|
||||
for(int row = 0; row < mTableView.getItems().size(); row++)
|
||||
{
|
||||
if(mTableView.getSelectionModel().isSelected(row))
|
||||
{
|
||||
StringJoiner line = new StringJoiner("\t");
|
||||
|
||||
for(TableColumn<Row<T>,?> column: mTableView.getVisibleLeafColumns())
|
||||
{
|
||||
Object value = column.getCellData(row);
|
||||
line.add(value == null ? "" : value.toString());
|
||||
}
|
||||
|
||||
text.add(line.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private void setHistorySize(int historySize)
|
||||
{
|
||||
mHistorySize = historySize;
|
||||
|
||||
@@ -660,7 +660,7 @@ public class AliasConfigurationEditor extends SplitPane implements IAliasListRef
|
||||
nameColumn.setPrefWidth(140);
|
||||
|
||||
TableColumn groupColumn = new TableColumn();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
groupColumn.setPrefWidth(140);
|
||||
|
||||
|
||||
@@ -1094,7 +1094,7 @@ public class AliasItemEditor extends Editor<Alias>
|
||||
GridPane.setConstraints(getColorPicker(), 7, row);
|
||||
mTextFieldPane.getChildren().add(getColorPicker());
|
||||
|
||||
Label groupLabel = new Label("Group");
|
||||
Label groupLabel = new Label("Category");
|
||||
groupLabel.setLabelFor(getGroupField());
|
||||
GridPane.setHalignment(groupLabel, HPos.RIGHT);
|
||||
GridPane.setConstraints(groupLabel, 0, ++row);
|
||||
|
||||
@@ -243,7 +243,7 @@ public class AliasViewByIdentifierEditor extends VBox
|
||||
aliasColumn.setPrefWidth(200);
|
||||
|
||||
TableColumn<AliasAndIdentifier, String> groupColumn = new TableColumn<>();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
groupColumn.setPrefWidth(200);
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ public class AliasViewByRecordingEditor extends VBox
|
||||
nameColumn.setCellValueFactory(new PropertyValueFactory<Alias,String>("name"));
|
||||
|
||||
TableColumn groupColumn = new TableColumn();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setPrefWidth(200);
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
|
||||
@@ -280,7 +280,7 @@ public class AliasViewByRecordingEditor extends VBox
|
||||
nameColumn.setCellValueFactory(new PropertyValueFactory<Alias,String>("name"));
|
||||
|
||||
TableColumn groupColumn = new TableColumn();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setPrefWidth(200);
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
|
||||
|
||||
@@ -693,9 +693,10 @@ public abstract class ChannelConfigurationEditor extends Editor<Channel>
|
||||
{
|
||||
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.setTooltip(new Tooltip("Adds decoded talker aliases as radio aliases in " +
|
||||
"the Talker Alias category. Only radio aliases in that category are automatically renamed; existing " +
|
||||
"radio aliases outside the category are left unchanged. Move an alias out of the Talker Alias category " +
|
||||
"to preserve a custom name. Applies when the channel is (re)started."));
|
||||
mAutoAddTalkerAliasesCheckBox.setOnAction(event -> modifiedProperty().set(true));
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ public class StreamAliasSelectionEditor extends VBox
|
||||
aliasListNameColumn.setCellValueFactory(new PropertyValueFactory<>("aliasListName"));
|
||||
|
||||
TableColumn groupColumn = new TableColumn();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setPrefWidth(150);
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
|
||||
@@ -270,7 +270,7 @@ public class StreamAliasSelectionEditor extends VBox
|
||||
aliasListNameColumn.setCellValueFactory(new PropertyValueFactory<>("aliasListName"));
|
||||
|
||||
TableColumn groupColumn = new TableColumn();
|
||||
groupColumn.setText("Group");
|
||||
groupColumn.setText("Category");
|
||||
groupColumn.setPrefWidth(150);
|
||||
groupColumn.setCellValueFactory(new PropertyValueFactory<>("group"));
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ChannelSpectralDisplay extends DftSpectralDisplay
|
||||
SpectralDisplayModel model = getSpectralDisplay().getModel();
|
||||
getSpectralDisplay().messageProperty().set(MESSAGE_NO_CHANNEL);
|
||||
|
||||
//Noise floor slider along the right edge, below the configuration panel tab
|
||||
//Noise floor slider for the spectrum
|
||||
mNoiseFloorSlider = new EdgeSlider("Floor", "Noise floor: moves the bottom of the spectrum's dB range. " +
|
||||
"Higher settings show a deeper range and move the noise floor up the display.",
|
||||
MINIMUM_SAMPLE_SIZE, MAXIMUM_SAMPLE_SIZE, 1, this::formatPlotBottom);
|
||||
@@ -82,9 +82,10 @@ public class ChannelSpectralDisplay extends DftSpectralDisplay
|
||||
model.binCountProperty().addListener((ob, ov, nv) -> mNoiseFloorSlider.refreshLabel());
|
||||
model.noiseBandwidthProperty().addListener((ob, ov, nv) -> mNoiseFloorSlider.refreshLabel());
|
||||
mNoiseFloorSlider.refreshLabel();
|
||||
//Along the right edge of the spectrum section, below the configuration panel tab
|
||||
StackPane.setAlignment(mNoiseFloorSlider, Pos.CENTER_RIGHT);
|
||||
StackPane.setMargin(mNoiseFloorSlider, new Insets(44, 0, 8, 0));
|
||||
getChildren().add(mNoiseFloorSlider);
|
||||
getSpectralDisplay().addSectionOverlay(DisplaySection.SPECTRUM, mNoiseFloorSlider);
|
||||
|
||||
installConfigPanel();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public abstract class DftSpectralDisplay extends StackPane
|
||||
private static final String PEAK_HOLD = "peak.hold";
|
||||
private static final String SPECTRUM_ENABLED = "spectrum.enabled";
|
||||
private static final String WATERFALL_ENABLED = "waterfall.enabled";
|
||||
private static final String WATERFALL_RANGE = "waterfall.range";
|
||||
private static final String WATERFALL_AVERAGING = "waterfall.averaging";
|
||||
private static final String DIVIDER_POSITION = "divider.position";
|
||||
private static final String DECIBEL_SCALE = "decibel.scale";
|
||||
private static final String CONFIG_PINNED = "config.pinned";
|
||||
@@ -121,6 +123,9 @@ public abstract class DftSpectralDisplay extends StackPane
|
||||
});
|
||||
mSpectralDisplay.averagingProperty().addListener((ob, ov, nv) -> save(AVERAGING, nv.intValue()));
|
||||
mSpectralDisplay.peakHoldProperty().addListener((ob, ov, nv) -> save(PEAK_HOLD, nv));
|
||||
mSpectralDisplay.waterfallRangeProperty().addListener((ob, ov, nv) -> save(WATERFALL_RANGE, nv.intValue()));
|
||||
mSpectralDisplay.waterfallAveragingProperty().addListener((ob, ov, nv) ->
|
||||
save(WATERFALL_AVERAGING, nv.intValue()));
|
||||
mSpectralDisplay.dividerPositionProperty().addListener((ob, ov, nv) ->
|
||||
save(DIVIDER_POSITION, String.valueOf(nv.doubleValue())));
|
||||
mDecibelLayer.visibleProperty().addListener((ob, ov, nv) -> save(DECIBEL_SCALE, nv));
|
||||
@@ -205,6 +210,12 @@ public abstract class DftSpectralDisplay extends StackPane
|
||||
mSpectralDisplay.averagingProperty().set(Math.max(SpectralDisplay.AVERAGING_MINIMUM,
|
||||
Math.min(SpectralDisplay.AVERAGING_MAXIMUM, averaging)));
|
||||
mSpectralDisplay.peakHoldProperty().set(properties.get(key(PEAK_HOLD), false));
|
||||
mSpectralDisplay.waterfallRangeProperty().set(Math.max(WaterfallScaler.RANGE_MINIMUM,
|
||||
Math.min(WaterfallScaler.RANGE_MAXIMUM, properties.get(key(WATERFALL_RANGE),
|
||||
WaterfallScaler.RANGE_DEFAULT))));
|
||||
mSpectralDisplay.waterfallAveragingProperty().set(Math.max(WaterfallScaler.AVERAGING_MINIMUM,
|
||||
Math.min(WaterfallScaler.AVERAGING_MAXIMUM, properties.get(key(WATERFALL_AVERAGING),
|
||||
WaterfallScaler.AVERAGING_DEFAULT))));
|
||||
mDecibelLayer.visibleProperty().set(properties.get(key(DECIBEL_SCALE), true));
|
||||
|
||||
try
|
||||
|
||||
@@ -42,6 +42,8 @@ import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.Cursor;
|
||||
@@ -104,6 +106,10 @@ public class SpectralDisplay extends StackPane
|
||||
private final SplitPane mSplitPane = new SplitPane();
|
||||
private final CanvasPane mSpectrumPane = new CanvasPane(DisplaySection.SPECTRUM);
|
||||
private final CanvasPane mWaterfallPane = new CanvasPane(DisplaySection.WATERFALL);
|
||||
//Each section's canvas with overlay controls stacked on top
|
||||
private final StackPane mSpectrumSection = new StackPane(mSpectrumPane);
|
||||
private final StackPane mWaterfallSection = new StackPane(mWaterfallPane);
|
||||
private final EdgeSlider mWaterfallRangeSlider;
|
||||
private final StackPane mDisabledPane = new StackPane();
|
||||
|
||||
private final BooleanProperty mSpectrumEnabled = new SimpleBooleanProperty(true);
|
||||
@@ -112,6 +118,8 @@ public class SpectralDisplay extends StackPane
|
||||
private final IntegerProperty mAveraging = new SimpleIntegerProperty(AVERAGING_DEFAULT);
|
||||
private final BooleanProperty mPeakHold = new SimpleBooleanProperty(false);
|
||||
private final DoubleProperty mDividerPosition = new SimpleDoubleProperty(0.5);
|
||||
private final IntegerProperty mWaterfallRange = new SimpleIntegerProperty(WaterfallScaler.RANGE_DEFAULT);
|
||||
private final IntegerProperty mWaterfallAveraging = new SimpleIntegerProperty(WaterfallScaler.AVERAGING_DEFAULT);
|
||||
private final StringProperty mMessage = new SimpleStringProperty();
|
||||
|
||||
//Values read on the DFT results thread
|
||||
@@ -119,6 +127,7 @@ public class SpectralDisplay extends StackPane
|
||||
private volatile boolean mWaterfallActive = true;
|
||||
private volatile boolean mWaterfallPausedFlag = false;
|
||||
private final SpectrumAverager mAverager = new SpectrumAverager();
|
||||
private final WaterfallScaler mWaterfallScaler = new WaterfallScaler();
|
||||
|
||||
//Hand off from the DFT results thread to the JavaFX thread
|
||||
private final AtomicReference<SpectrumAverager.Frame> mLatestSpectrum = new AtomicReference<>();
|
||||
@@ -133,8 +142,10 @@ public class SpectralDisplay extends StackPane
|
||||
private WritableImage[] mWaterfallTiles;
|
||||
private int mWaterfallWidth;
|
||||
private int mWaterfallHeight;
|
||||
private byte[] mWaterfallIndexes;
|
||||
private byte[] mWaterfallLevels;
|
||||
private int[] mWaterfallPixels;
|
||||
//ARGB color for each waterfall level code, for the current theme and range. Null when it needs to be rebuilt.
|
||||
private int[] mWaterfallColors;
|
||||
private int mWaterfallWriteRow = 0;
|
||||
private double[] mPolygonX = new double[0];
|
||||
private double[] mPolygonY = new double[0];
|
||||
@@ -167,6 +178,37 @@ public class SpectralDisplay extends StackPane
|
||||
themeChanged(disabledLabel);
|
||||
getChildren().addAll(mDisabledPane, mSplitPane);
|
||||
setMinSize(0, 0);
|
||||
mSpectrumSection.setMinSize(0, 0);
|
||||
mWaterfallSection.setMinSize(0, 0);
|
||||
|
||||
//Waterfall gain slider along the right edge of the waterfall. The slider value is inverted so that moving it
|
||||
//up narrows the dB range, which raises the contrast of weak signals.
|
||||
int rangeSum = WaterfallScaler.RANGE_MINIMUM + WaterfallScaler.RANGE_MAXIMUM;
|
||||
mWaterfallRangeSlider = new EdgeSlider("Gain", "Waterfall gain: dB range from the noise floor to the top " +
|
||||
"of the color palette. Higher settings use a smaller range, which gives weak signals more contrast " +
|
||||
"against the noise and saturates strong signals sooner.", WaterfallScaler.RANGE_MINIMUM,
|
||||
WaterfallScaler.RANGE_MAXIMUM, 1, value -> (rangeSum - Math.round(value)) + " dB");
|
||||
mWaterfallRangeSlider.valueProperty().set(rangeSum - mWaterfallRange.get());
|
||||
mWaterfallRangeSlider.valueProperty().addListener((ob, ov, nv) ->
|
||||
mWaterfallRange.set(rangeSum - (int)Math.round(nv.doubleValue())));
|
||||
mWaterfallRange.addListener((ob, ov, nv) -> {
|
||||
int range = Math.max(WaterfallScaler.RANGE_MINIMUM, Math.min(WaterfallScaler.RANGE_MAXIMUM,
|
||||
nv.intValue()));
|
||||
|
||||
if(range != nv.intValue())
|
||||
{
|
||||
mWaterfallRange.set(range);
|
||||
return;
|
||||
}
|
||||
|
||||
mWaterfallRangeSlider.valueProperty().set(rangeSum - range);
|
||||
mWaterfallColors = null;
|
||||
repaintWaterfallImage();
|
||||
});
|
||||
StackPane.setAlignment(mWaterfallRangeSlider, Pos.CENTER_RIGHT);
|
||||
mWaterfallSection.getChildren().add(mWaterfallRangeSlider);
|
||||
|
||||
mWaterfallAveraging.addListener((ob, ov, nv) -> mWaterfallScaler.setAveraging(nv.intValue()));
|
||||
|
||||
mSpectrumEnabled.addListener((ob, ov, nv) -> updateSections());
|
||||
mWaterfallEnabled.addListener((ob, ov, nv) -> updateSections());
|
||||
@@ -261,6 +303,7 @@ public class SpectralDisplay extends StackPane
|
||||
SpectralDisplayTheme theme = getTheme();
|
||||
mDisabledPane.setBackground(new Background(new BackgroundFill(theme.getBackground(), null, null)));
|
||||
disabledLabel.setTextFill(theme.getLine());
|
||||
mWaterfallColors = null;
|
||||
repaintWaterfallImage();
|
||||
requestRender();
|
||||
}
|
||||
@@ -357,6 +400,42 @@ public class SpectralDisplay extends StackPane
|
||||
return mPeakHold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waterfall dB range from the noise floor to the top of the color palette, from WaterfallScaler.RANGE_MINIMUM to
|
||||
* RANGE_MAXIMUM. Smaller ranges give weak signals more contrast. JavaFX thread only.
|
||||
*/
|
||||
public IntegerProperty waterfallRangeProperty()
|
||||
{
|
||||
return mWaterfallRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of DFT frames averaged into each waterfall row, from WaterfallScaler.AVERAGING_MINIMUM to
|
||||
* AVERAGING_MAXIMUM. Averaging steadies the noise floor so weak signals stand out, but the waterfall scrolls
|
||||
* more slowly.
|
||||
*/
|
||||
public IntegerProperty waterfallAveragingProperty()
|
||||
{
|
||||
return mWaterfallAveraging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waterfall gain slider along the right edge of the waterfall section.
|
||||
*/
|
||||
public EdgeSlider getWaterfallRangeSlider()
|
||||
{
|
||||
return mWaterfallRangeSlider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a control on top of the spectrum or the waterfall section, for example an EdgeSlider. Set its StackPane
|
||||
* alignment and margin before adding it. The control is hidden with its section.
|
||||
*/
|
||||
public void addSectionOverlay(DisplaySection section, javafx.scene.Node node)
|
||||
{
|
||||
(section == DisplaySection.SPECTRUM ? mSpectrumSection : mWaterfallSection).getChildren().add(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Divider position (0 - 1.0) between the spectrum and the waterfall when both are showing.
|
||||
*/
|
||||
@@ -395,6 +474,7 @@ public class SpectralDisplay extends StackPane
|
||||
public void clear()
|
||||
{
|
||||
mAverager.reset();
|
||||
mWaterfallScaler.reset();
|
||||
|
||||
mLatestSpectrum.set(null);
|
||||
mWaterfallRows.clear();
|
||||
@@ -412,10 +492,11 @@ public class SpectralDisplay extends StackPane
|
||||
return;
|
||||
}
|
||||
|
||||
//The first DFT results on startup can be NaN or infinite
|
||||
//The first DFT results on startup can be NaN or infinite - drop them. Replacing them with zeros would add
|
||||
//full scale (0 dBFS) values to the spectrum averaging and the waterfall floor tracking.
|
||||
if(Float.isNaN(bins[0]) || Float.isInfinite(bins[0]))
|
||||
{
|
||||
bins = new float[bins.length];
|
||||
return;
|
||||
}
|
||||
|
||||
if(mSpectrumActive)
|
||||
@@ -425,11 +506,16 @@ public class SpectralDisplay extends StackPane
|
||||
|
||||
if(mWaterfallActive && !mWaterfallPausedFlag)
|
||||
{
|
||||
mWaterfallRows.offer(toWaterfallRow(bins));
|
||||
byte[] row = mWaterfallScaler.process(bins);
|
||||
|
||||
while(mWaterfallRows.size() > WATERFALL_QUEUE_LIMIT)
|
||||
if(row != null)
|
||||
{
|
||||
mWaterfallRows.poll();
|
||||
mWaterfallRows.offer(row);
|
||||
|
||||
while(mWaterfallRows.size() > WATERFALL_QUEUE_LIMIT)
|
||||
{
|
||||
mWaterfallRows.poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,33 +538,7 @@ public class SpectralDisplay extends StackPane
|
||||
mLatestSpectrum.set(null);
|
||||
mWaterfallRows.clear();
|
||||
mWaterfallTiles = null;
|
||||
mWaterfallIndexes = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the DFT results to a row of waterfall intensity indexes (0 - 255). Each bin is scaled relative to the
|
||||
* average bin value so the noise floor stays at the bottom of the palette regardless of tuner gain.
|
||||
*/
|
||||
private static byte[] toWaterfallRow(float[] bins)
|
||||
{
|
||||
double sum = 0.0;
|
||||
|
||||
for(float bin: bins)
|
||||
{
|
||||
sum += bin;
|
||||
}
|
||||
|
||||
float average = (float)(sum / bins.length) - 1.0f;
|
||||
float scale = 256.0f / average;
|
||||
byte[] row = new byte[bins.length];
|
||||
|
||||
for(int x = 0; x < bins.length; x++)
|
||||
{
|
||||
int value = (int)((average - bins[x]) * scale);
|
||||
row[x] = (byte)Math.max(0, Math.min(255, value));
|
||||
}
|
||||
|
||||
return row;
|
||||
mWaterfallLevels = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,11 +551,11 @@ public class SpectralDisplay extends StackPane
|
||||
mSpectrumActive = spectrum;
|
||||
mWaterfallActive = waterfall;
|
||||
|
||||
List<Pane> items = new ArrayList<>();
|
||||
List<StackPane> items = new ArrayList<>();
|
||||
|
||||
if(spectrum)
|
||||
{
|
||||
items.add(mSpectrumPane);
|
||||
items.add(mSpectrumSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -505,13 +565,16 @@ public class SpectralDisplay extends StackPane
|
||||
|
||||
if(waterfall)
|
||||
{
|
||||
items.add(mWaterfallPane);
|
||||
items.add(mWaterfallSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
mWaterfallRows.clear();
|
||||
}
|
||||
|
||||
//Keep the waterfall slider below the configuration panel tab when the waterfall is at the top
|
||||
StackPane.setMargin(mWaterfallRangeSlider, new Insets(spectrum ? 8 : 44, 0, 8, 0));
|
||||
|
||||
mSplitPane.getItems().setAll(items);
|
||||
mSplitPane.setVisible(!items.isEmpty());
|
||||
|
||||
@@ -543,7 +606,7 @@ public class SpectralDisplay extends StackPane
|
||||
if(mWaterfallTiles != null)
|
||||
{
|
||||
mWaterfallTiles = null;
|
||||
mWaterfallIndexes = null;
|
||||
mWaterfallLevels = null;
|
||||
mWaterfallWriteRow = 0;
|
||||
}
|
||||
|
||||
@@ -581,8 +644,8 @@ public class SpectralDisplay extends StackPane
|
||||
|
||||
/**
|
||||
* Writes the row into the waterfall ring buffer. The newest row is at mWaterfallWriteRow and older rows follow
|
||||
* it, wrapping around the end of the image. The intensity indexes are kept alongside the image so the history
|
||||
* can be recolored when the theme changes.
|
||||
* it, wrapping around the end of the image. The level codes are kept alongside the image so the history
|
||||
* can be recolored when the theme or the waterfall range changes.
|
||||
*/
|
||||
private void writeWaterfallRow(byte[] row)
|
||||
{
|
||||
@@ -590,7 +653,7 @@ public class SpectralDisplay extends StackPane
|
||||
|
||||
if(mWaterfallTiles == null || mWaterfallWidth != row.length)
|
||||
{
|
||||
mWaterfallIndexes = new byte[row.length * rows];
|
||||
mWaterfallLevels = new byte[row.length * rows];
|
||||
createWaterfallTiles(row.length, rows);
|
||||
mWaterfallWriteRow = 0;
|
||||
repaintWaterfallImage();
|
||||
@@ -602,7 +665,7 @@ public class SpectralDisplay extends StackPane
|
||||
|
||||
int width = row.length;
|
||||
mWaterfallWriteRow = (mWaterfallWriteRow - 1 + mWaterfallHeight) % mWaterfallHeight;
|
||||
System.arraycopy(row, 0, mWaterfallIndexes, mWaterfallWriteRow * width, width);
|
||||
System.arraycopy(row, 0, mWaterfallLevels, mWaterfallWriteRow * width, width);
|
||||
writeWaterfallPixels(mWaterfallWriteRow);
|
||||
}
|
||||
|
||||
@@ -625,7 +688,7 @@ public class SpectralDisplay extends StackPane
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors one row of the waterfall image tiles from the stored intensity indexes.
|
||||
* Colors one row of the waterfall image tiles from the stored level codes.
|
||||
*/
|
||||
private void writeWaterfallPixels(int imageRow)
|
||||
{
|
||||
@@ -636,12 +699,12 @@ public class SpectralDisplay extends StackPane
|
||||
mWaterfallPixels = new int[width];
|
||||
}
|
||||
|
||||
SpectralDisplayTheme theme = getTheme();
|
||||
int[] colors = getWaterfallColors();
|
||||
int offset = imageRow * width;
|
||||
|
||||
for(int x = 0; x < width; x++)
|
||||
{
|
||||
mWaterfallPixels[x] = theme.getWaterfallColor(mWaterfallIndexes[offset + x]);
|
||||
mWaterfallPixels[x] = colors[mWaterfallLevels[offset + x] & 0xFF];
|
||||
}
|
||||
|
||||
for(int tile = 0; tile < mWaterfallTiles.length; tile++)
|
||||
@@ -653,11 +716,33 @@ public class SpectralDisplay extends StackPane
|
||||
}
|
||||
|
||||
/**
|
||||
* Recolors the whole waterfall image from the stored intensity indexes using the current theme.
|
||||
* ARGB color for each waterfall level code, for the current theme and range.
|
||||
*/
|
||||
private int[] getWaterfallColors()
|
||||
{
|
||||
if(mWaterfallColors == null)
|
||||
{
|
||||
SpectralDisplayTheme theme = getTheme();
|
||||
int range = mWaterfallRange.get();
|
||||
int[] colors = new int[256];
|
||||
|
||||
for(int level = 0; level < colors.length; level++)
|
||||
{
|
||||
colors[level] = theme.getWaterfallColor(WaterfallScaler.paletteIndex(level, range));
|
||||
}
|
||||
|
||||
mWaterfallColors = colors;
|
||||
}
|
||||
|
||||
return mWaterfallColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recolors the whole waterfall image from the stored level codes using the current theme and range.
|
||||
*/
|
||||
private void repaintWaterfallImage()
|
||||
{
|
||||
if(mWaterfallTiles != null && mWaterfallIndexes != null)
|
||||
if(mWaterfallTiles != null && mWaterfallLevels != null)
|
||||
{
|
||||
for(int y = 0; y < mWaterfallHeight; y++)
|
||||
{
|
||||
@@ -689,10 +774,10 @@ public class SpectralDisplay extends StackPane
|
||||
for(int y = 0; y < previousHeight; y++)
|
||||
{
|
||||
int source = (mWaterfallWriteRow + y) % previousHeight;
|
||||
System.arraycopy(mWaterfallIndexes, source * width, indexes, y * width, width);
|
||||
System.arraycopy(mWaterfallLevels, source * width, indexes, y * width, width);
|
||||
}
|
||||
|
||||
mWaterfallIndexes = indexes;
|
||||
mWaterfallLevels = indexes;
|
||||
createWaterfallTiles(width, rows);
|
||||
mWaterfallWriteRow = 0;
|
||||
repaintWaterfallImage();
|
||||
|
||||
@@ -353,6 +353,27 @@ public class SpectralDisplayConfigPanel extends VBox
|
||||
"falling slowly"));
|
||||
row = addRow(grid, row, peakHold.label(), peakHold.control());
|
||||
|
||||
//Waterfall
|
||||
grid.add(sectionLabel("Waterfall"), 0, row++, 2, 1);
|
||||
ComboBox<Integer> waterfallAveraging = new ComboBox<>();
|
||||
for(int frames = WaterfallScaler.AVERAGING_MINIMUM; frames <= WaterfallScaler.AVERAGING_MAXIMUM; frames++)
|
||||
{
|
||||
waterfallAveraging.getItems().add(frames);
|
||||
}
|
||||
waterfallAveraging.setMaxWidth(Double.MAX_VALUE);
|
||||
waterfallAveraging.setConverter(converter(frames -> frames == 1 ? "Off" : frames + " frames"));
|
||||
waterfallAveraging.setValue(mSpectralDisplay.waterfallAveragingProperty().get());
|
||||
waterfallAveraging.valueProperty().addListener((ob, ov, nv) -> {
|
||||
if(nv != null)
|
||||
{
|
||||
mSpectralDisplay.waterfallAveragingProperty().set(nv);
|
||||
}
|
||||
});
|
||||
waterfallAveraging.setTooltip(new Tooltip("FFT frames averaged into each waterfall row. Averaging steadies " +
|
||||
"the noise floor so weak signals stand out, but the waterfall scrolls more slowly."));
|
||||
trackPopup(waterfallAveraging.showingProperty());
|
||||
row = addRow(grid, row, "Averaging", waterfallAveraging);
|
||||
|
||||
//Layer settings
|
||||
for(SpectralDisplayLayer layer: mSpectralDisplay.getLayers())
|
||||
{
|
||||
|
||||
@@ -33,44 +33,31 @@ public class WaterfallPalette
|
||||
}
|
||||
|
||||
/**
|
||||
* Palette of the original Swing waterfall: dark blue noise floor, a blue to yellow ramp, yellow fading to orange,
|
||||
* then red.
|
||||
* Palette based on the original Swing waterfall colors: a dark to bright blue ramp, a blue to yellow ramp, yellow
|
||||
* fading to orange, then red. The blue ramp covers the bottom quarter of the palette, where the waterfall places
|
||||
* the noise floor, so the noise stays blue and weak signals stand out from it.
|
||||
*/
|
||||
public static int[] classic()
|
||||
{
|
||||
int[] palette = new int[SIZE];
|
||||
|
||||
for(int x = 0; x < 16; x++)
|
||||
for(int x = 0; x < 64; x++)
|
||||
{
|
||||
palette[x] = argb(0, 0, 127);
|
||||
palette[x] = argb(0, 0, blend(64, 191, x / 63.0));
|
||||
}
|
||||
|
||||
for(int x = 16; x < 32; x++)
|
||||
for(int x = 64; x < 100; x++)
|
||||
{
|
||||
palette[x] = argb(0, 0, 191);
|
||||
double t = (x - 64) / 36.0;
|
||||
palette[x] = argb(blend(0, 255, t), blend(0, 255, t), blend(191, 0, t));
|
||||
}
|
||||
|
||||
int r = 0;
|
||||
int g = 0;
|
||||
int b = 191;
|
||||
|
||||
for(int x = 32; x < 60; x++)
|
||||
for(int x = 100; x < 220; x++)
|
||||
{
|
||||
palette[x] = argb(r, g, b);
|
||||
r += 9;
|
||||
g += 9;
|
||||
b -= 6;
|
||||
palette[x] = argb(255, blend(255, 0, (x - 100) / 120.0), 0);
|
||||
}
|
||||
|
||||
g = 255;
|
||||
|
||||
for(int x = 60; x < 188; x++)
|
||||
{
|
||||
palette[x] = argb(255, g, 0);
|
||||
g -= 2;
|
||||
}
|
||||
|
||||
for(int x = 188; x < SIZE; x++)
|
||||
for(int x = 220; x < SIZE; x++)
|
||||
{
|
||||
palette[x] = argb(255, 0, 0);
|
||||
}
|
||||
@@ -78,6 +65,11 @@ public class WaterfallPalette
|
||||
return palette;
|
||||
}
|
||||
|
||||
private static int blend(int from, int to, double fraction)
|
||||
{
|
||||
return (int)Math.round(from + (to - from) * fraction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Palette that blends linearly between evenly spaced colors.
|
||||
* @param colors web color strings (for example #440154), lowest intensity first
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.Arrays;
|
||||
|
||||
/**
|
||||
* Converts DFT results in dB to rows of waterfall level codes, and level codes to palette indexes.
|
||||
*
|
||||
* Optionally averages several DFT frames (in linear power) into each row. Averaging reduces the random variation of
|
||||
* the noise bins (about 5.6 dB for a single frame), which is the only thing that makes weak signals statistically
|
||||
* easier to see, at the cost of fewer rows per second.
|
||||
*
|
||||
* The noise floor reference is a low percentile of the bins, so signals that fill much of the span don't raise it,
|
||||
* smoothed across rows so the waterfall background doesn't flicker.
|
||||
*
|
||||
* Each row stores a level code per bin: the bin level relative to the floor reference in LEVEL_STEP_DB steps. The
|
||||
* level codes are mapped to palette indexes over a dB range above the floor (see paletteIndex()) when the row is
|
||||
* colored, so the range can change and the waterfall history can be recolored without the original DFT results.
|
||||
*
|
||||
* Not thread safe: process() on the DFT results thread only. reset() and setAveraging() are safe from any thread.
|
||||
*/
|
||||
public class WaterfallScaler
|
||||
{
|
||||
public static final int RANGE_MINIMUM = 20;
|
||||
public static final int RANGE_MAXIMUM = 80;
|
||||
public static final int RANGE_DEFAULT = 45;
|
||||
public static final int AVERAGING_MINIMUM = 1;
|
||||
public static final int AVERAGING_MAXIMUM = 4;
|
||||
public static final int AVERAGING_DEFAULT = 2;
|
||||
|
||||
//Percentile of the bins used as the noise floor reference. Robust to signals in up to 75% of the bins.
|
||||
static final double FLOOR_PERCENTILE = 0.25;
|
||||
//Smoothing applied to the floor reference each row: about 5 rows. The percentile barely varies from row to row,
|
||||
//so this mostly limits jumps from bursts of signals while still following tuner gain changes quickly.
|
||||
static final float FLOOR_SMOOTHING = 0.2f;
|
||||
//Floor reference changes larger than this jump straight to the new level instead of smoothing, for example when
|
||||
//the first samples arrive after DFT frames of an empty buffer (-196 dB), or after a tuner or gain change.
|
||||
static final float FLOOR_JUMP_DB = 10.0f;
|
||||
//Level code resolution and the level code of the floor reference: codes cover -8 dB to +94 dB from the floor,
|
||||
//which covers the palette at the maximum range.
|
||||
static final float LEVEL_STEP_DB = 0.4f;
|
||||
static final int FLOOR_LEVEL = 20;
|
||||
//Palette index for the floor reference. Noise bins spread above the 25th percentile, so this places the noise in
|
||||
//the lower part of the palette as texture with only the weakest noise bins at the background color.
|
||||
static final float FLOOR_INDEX = 16.0f;
|
||||
|
||||
private static final float DB_TO_LN_POWER = (float)(Math.log(10.0) / 10.0);
|
||||
|
||||
private float mFloor = Float.NaN;
|
||||
private volatile boolean mResetRequested;
|
||||
private volatile int mAveraging = AVERAGING_DEFAULT;
|
||||
private float[] mScratch = new float[0];
|
||||
private float[] mPowerSum = new float[0];
|
||||
private float[] mAverage = new float[0];
|
||||
private int mFrameCount;
|
||||
|
||||
/**
|
||||
* Restarts floor tracking and frame averaging on the next frame, for example after the source changes. Safe to
|
||||
* call from any thread.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
mResetRequested = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of DFT frames averaged into each waterfall row. Safe to call from any thread.
|
||||
* @param frames from AVERAGING_MINIMUM to AVERAGING_MAXIMUM
|
||||
*/
|
||||
public void setAveraging(int frames)
|
||||
{
|
||||
mAveraging = Math.max(AVERAGING_MINIMUM, Math.min(AVERAGING_MAXIMUM, frames));
|
||||
}
|
||||
|
||||
/**
|
||||
* Current noise floor reference in dB, or NaN before the first row.
|
||||
*/
|
||||
public float getFloor()
|
||||
{
|
||||
return mFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the DFT results to the current row.
|
||||
* @param bins in dB
|
||||
* @return the row of level codes (unsigned bytes) when the row is complete, otherwise null
|
||||
*/
|
||||
public byte[] process(float[] bins)
|
||||
{
|
||||
if(mResetRequested)
|
||||
{
|
||||
mResetRequested = false;
|
||||
mFloor = Float.NaN;
|
||||
mFrameCount = 0;
|
||||
}
|
||||
|
||||
int frames = mAveraging;
|
||||
|
||||
if(frames <= 1 && mFrameCount == 0)
|
||||
{
|
||||
return levels(bins);
|
||||
}
|
||||
|
||||
if(mPowerSum.length != bins.length)
|
||||
{
|
||||
mPowerSum = new float[bins.length];
|
||||
mAverage = new float[bins.length];
|
||||
mFrameCount = 0;
|
||||
}
|
||||
|
||||
if(mFrameCount == 0)
|
||||
{
|
||||
Arrays.fill(mPowerSum, 0.0f);
|
||||
}
|
||||
|
||||
for(int x = 0; x < bins.length; x++)
|
||||
{
|
||||
mPowerSum[x] += (float)Math.exp(bins[x] * DB_TO_LN_POWER);
|
||||
}
|
||||
|
||||
mFrameCount++;
|
||||
|
||||
//The averaging can drop below the frames already summed - complete the row with what has been summed
|
||||
if(mFrameCount < frames)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
float scale = 1.0f / mFrameCount;
|
||||
|
||||
for(int x = 0; x < bins.length; x++)
|
||||
{
|
||||
mAverage[x] = (float)(10.0 * Math.log10(mPowerSum[x] * scale));
|
||||
}
|
||||
|
||||
mFrameCount = 0;
|
||||
return levels(mAverage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the floor reference and converts the bins to level codes.
|
||||
*/
|
||||
private byte[] levels(float[] bins)
|
||||
{
|
||||
float percentile = percentile(bins);
|
||||
|
||||
if(Float.isNaN(mFloor) || Float.isInfinite(mFloor) || Math.abs(percentile - mFloor) > FLOOR_JUMP_DB)
|
||||
{
|
||||
mFloor = percentile;
|
||||
}
|
||||
else
|
||||
{
|
||||
mFloor += (percentile - mFloor) * FLOOR_SMOOTHING;
|
||||
}
|
||||
|
||||
byte[] row = new byte[bins.length];
|
||||
float floor = mFloor;
|
||||
|
||||
for(int x = 0; x < bins.length; x++)
|
||||
{
|
||||
int level = Math.round((bins[x] - floor) / LEVEL_STEP_DB) + FLOOR_LEVEL;
|
||||
row[x] = (byte)Math.max(0, Math.min(255, level));
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Palette index for a level code.
|
||||
* @param level code (0 - 255)
|
||||
* @param range in dB from the noise floor reference to the top of the palette. Smaller ranges give weak signals
|
||||
* more contrast against the noise and saturate strong signals sooner.
|
||||
* @return palette index (0 - 255)
|
||||
*/
|
||||
public static int paletteIndex(int level, double range)
|
||||
{
|
||||
double db = (level - FLOOR_LEVEL) * LEVEL_STEP_DB;
|
||||
long index = Math.round(db * (WaterfallPalette.SIZE - 1) / range + FLOOR_INDEX);
|
||||
return (int)Math.max(0, Math.min(WaterfallPalette.SIZE - 1, index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Floor reference percentile of the bins, using quickselect on a scratch copy.
|
||||
*/
|
||||
private float percentile(float[] bins)
|
||||
{
|
||||
if(mScratch.length != bins.length)
|
||||
{
|
||||
mScratch = new float[bins.length];
|
||||
}
|
||||
|
||||
System.arraycopy(bins, 0, mScratch, 0, bins.length);
|
||||
return select(mScratch, (int)(FLOOR_PERCENTILE * (bins.length - 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickselect: the k-th smallest value, partially reordering the array.
|
||||
*/
|
||||
static float select(float[] values, int k)
|
||||
{
|
||||
int left = 0;
|
||||
int right = values.length - 1;
|
||||
|
||||
while(left < right)
|
||||
{
|
||||
//Median of three pivot
|
||||
int middle = (left + right) >>> 1;
|
||||
|
||||
if(values[middle] < values[left])
|
||||
{
|
||||
swap(values, middle, left);
|
||||
}
|
||||
|
||||
if(values[right] < values[left])
|
||||
{
|
||||
swap(values, right, left);
|
||||
}
|
||||
|
||||
if(values[right] < values[middle])
|
||||
{
|
||||
swap(values, right, middle);
|
||||
}
|
||||
|
||||
float pivot = values[middle];
|
||||
int i = left;
|
||||
int j = right;
|
||||
|
||||
while(i <= j)
|
||||
{
|
||||
while(values[i] < pivot)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
while(values[j] > pivot)
|
||||
{
|
||||
j--;
|
||||
}
|
||||
|
||||
if(i <= j)
|
||||
{
|
||||
swap(values, i, j);
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
if(k <= j)
|
||||
{
|
||||
right = j;
|
||||
}
|
||||
else if(k >= i)
|
||||
{
|
||||
left = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
return values[k];
|
||||
}
|
||||
}
|
||||
|
||||
return values[k];
|
||||
}
|
||||
|
||||
private static void swap(float[] values, int a, int b)
|
||||
{
|
||||
float temp = values[a];
|
||||
values[a] = values[b];
|
||||
values[b] = temp;
|
||||
}
|
||||
}
|
||||
@@ -502,10 +502,10 @@ public class ThemeManager
|
||||
.append("-fx-background-color: ").append(accent).append(";")
|
||||
.append("}");
|
||||
|
||||
//URL-encode the body; java.net.URLEncoder is fine for our restricted charset.
|
||||
String encoded = java.net.URLEncoder.encode(css.toString(),
|
||||
java.nio.charset.StandardCharsets.UTF_8);
|
||||
return "data:text/css," + encoded;
|
||||
//Base64-encode the body. Don't use URLEncoder: it is form encoding and turns spaces
|
||||
//into '+', which a data URL doesn't decode, so JavaFX silently drops the whole sheet.
|
||||
return "data:text/css;base64," + java.util.Base64.getEncoder().encodeToString(
|
||||
css.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
}
|
||||
catch(Throwable t)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.jdesktop.swingx.mapviewer;
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
/**
|
||||
* An immutable coordinate in the real (geographic) world,
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2018 Dennis Sheirer
|
||||
* *****************************************************************************
|
||||
* 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
|
||||
@@ -15,13 +14,30 @@
|
||||
*
|
||||
* 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.map;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Listener for changes to the plottable entities. Called on the thread that made the change: the decode event thread
|
||||
* for new locations, or the thread that deleted the entities.
|
||||
*/
|
||||
public interface IPlottableUpdateListener
|
||||
{
|
||||
void entitiesUpdated();
|
||||
void addPlottableEntity(PlottableEntityHistory entity);
|
||||
void removePlottableEntity(PlottableEntityHistory entity);
|
||||
/**
|
||||
* A new entity was added
|
||||
*/
|
||||
void entityAdded(PlottableEntityHistory entity);
|
||||
|
||||
/**
|
||||
* An existing entity received a new decode event or location
|
||||
*/
|
||||
void entityUpdated(PlottableEntityHistory entity);
|
||||
|
||||
/**
|
||||
* Entities were deleted
|
||||
*/
|
||||
void entitiesRemoved(List<PlottableEntityHistory> entities);
|
||||
}
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.map;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class MapMouseListener extends MouseInputAdapter implements MouseWheelListener
|
||||
{
|
||||
private JXMapViewer mJXMapViewer;
|
||||
private Consumer<GeoPosition> mMyLocationListener;
|
||||
private Function<Point,List<JMenuItem>> mMenuItemProvider;
|
||||
private Point mPreviousPoint;
|
||||
private Point mCurrentPoint;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param viewer map
|
||||
* @param myLocationListener receives the location chosen with the 'Set My Location Here' menu item
|
||||
* @param menuItemProvider of additional context menu items for the point that was right-clicked, listed first
|
||||
*/
|
||||
public MapMouseListener( JXMapViewer viewer, Consumer<GeoPosition> myLocationListener,
|
||||
Function<Point,List<JMenuItem>> menuItemProvider )
|
||||
{
|
||||
mJXMapViewer = viewer;
|
||||
mMyLocationListener = myLocationListener;
|
||||
mMenuItemProvider = menuItemProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged( MouseEvent event )
|
||||
{
|
||||
if ( !SwingUtilities.isLeftMouseButton( event ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Point current = event.getPoint();
|
||||
|
||||
double x = mJXMapViewer.getCenter().getX() -
|
||||
( current.getX() - mPreviousPoint.getX() );
|
||||
|
||||
double y = mJXMapViewer.getCenter().getY() -
|
||||
(current.getY() - mPreviousPoint.getY() );
|
||||
|
||||
if ( !mJXMapViewer.isNegativeYAllowed() )
|
||||
{
|
||||
if ( y < 0 )
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int maxHeight = (int)( mJXMapViewer.getTileFactory()
|
||||
.getMapSize( mJXMapViewer.getZoom() ).getHeight() *
|
||||
mJXMapViewer.getTileFactory()
|
||||
.getTileSize( mJXMapViewer.getZoom() ) );
|
||||
|
||||
if (y > maxHeight)
|
||||
{
|
||||
y = maxHeight;
|
||||
}
|
||||
|
||||
mPreviousPoint = current;
|
||||
|
||||
mJXMapViewer.setCenter( new Point2D.Double( x, y ) );
|
||||
|
||||
mJXMapViewer.repaint();
|
||||
|
||||
/* Set cursor to dragging */
|
||||
mJXMapViewer.setCursor( Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased( MouseEvent event )
|
||||
{
|
||||
if ( !SwingUtilities.isLeftMouseButton( event ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mPreviousPoint = null;
|
||||
|
||||
/* Reset the curson */
|
||||
mJXMapViewer.setCursor(
|
||||
Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered( MouseEvent event )
|
||||
{
|
||||
SwingUtilities.invokeLater( new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mJXMapViewer.requestFocusInWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed( MouseEvent event )
|
||||
{
|
||||
mCurrentPoint = event.getPoint();
|
||||
mPreviousPoint = event.getPoint();
|
||||
|
||||
boolean left = SwingUtilities.isLeftMouseButton( event );
|
||||
|
||||
boolean middle = SwingUtilities.isMiddleMouseButton( event );
|
||||
|
||||
boolean right = SwingUtilities.isRightMouseButton( event );
|
||||
|
||||
boolean doubleClick = ( event.getClickCount() == 2 );
|
||||
|
||||
if (middle || ( left && doubleClick ) )
|
||||
{
|
||||
recenterMap( event );
|
||||
}
|
||||
else if( right )
|
||||
{
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
|
||||
if( mMenuItemProvider != null )
|
||||
{
|
||||
List<JMenuItem> items = mMenuItemProvider.apply( event.getPoint() );
|
||||
|
||||
if( items != null && !items.isEmpty() )
|
||||
{
|
||||
items.forEach( popup::add );
|
||||
popup.addSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
JMenuItem mapViewItem = new JMenuItem( "Set My Location Here" );
|
||||
mapViewItem.setToolTipText( "Sets your location, which is also used by the playlist editor's " +
|
||||
"Radio Reference tab, to this point" );
|
||||
mapViewItem.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent arg0 )
|
||||
{
|
||||
mMyLocationListener.accept( mJXMapViewer.convertPointToGeoPosition( mCurrentPoint ) );
|
||||
}
|
||||
} );
|
||||
popup.add( mapViewItem );
|
||||
|
||||
popup.show( mJXMapViewer, event.getX(), event.getY() );
|
||||
}
|
||||
}
|
||||
|
||||
private void recenterMap( MouseEvent event )
|
||||
{
|
||||
Rectangle bounds = mJXMapViewer.getViewportBounds();
|
||||
|
||||
double x = bounds.getX() + event.getX();
|
||||
|
||||
double y = bounds.getY() + event.getY();
|
||||
|
||||
mJXMapViewer.setCenter( new Point2D.Double( x, y ) );
|
||||
|
||||
mJXMapViewer.setZoom( mJXMapViewer.getZoom() - 1 );
|
||||
|
||||
mJXMapViewer.repaint();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@ import io.github.dsheirer.module.decode.event.PlottableDecodeEvent;
|
||||
public class PlottableEntityHistory
|
||||
{
|
||||
private final TrackHistoryModel mTrackHistoryModel = new TrackHistoryModel();
|
||||
private PlottableDecodeEvent mCurrentEvent;
|
||||
private volatile PlottableDecodeEvent mCurrentEvent;
|
||||
private final Identifier mIdentifier;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
@@ -27,31 +26,24 @@ import io.github.dsheirer.identifier.Identifier;
|
||||
import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier;
|
||||
import io.github.dsheirer.module.decode.event.PlottableDecodeEvent;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import java.awt.EventQueue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Table model for plottable entity history elements.
|
||||
* Plottable entity histories, one for each FROM identifier and alias list that reported a location. Thread safe:
|
||||
* listeners are called on the thread that made the change, outside of the model's lock.
|
||||
*/
|
||||
public class PlottableEntityModel extends AbstractTableModel implements Listener<PlottableDecodeEvent>
|
||||
public class PlottableEntityModel implements Listener<PlottableDecodeEvent>
|
||||
{
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(PlottableEntityModel.class);
|
||||
private static final int COLUMN_ID = 0;
|
||||
private static final int COLUMN_ALIAS = 1;
|
||||
private static final int COLUMN_ALIAS_LIST = 2;
|
||||
private static final String[] COLUMN_NAMES = {"ID", "Alias", "List"};
|
||||
private static final String KEY_NO_ALIAS_LIST = "(no alias list)";
|
||||
private Map<String,PlottableEntityHistory> mEntityHistoryMap = new HashMap();
|
||||
private List<PlottableEntityHistory> mEntityHistories = new ArrayList<>();
|
||||
private List<IPlottableUpdateListener> mPlottableUpdateListeners = new ArrayList<>();
|
||||
private AliasModel mAliasModel;
|
||||
private final Map<String,PlottableEntityHistory> mEntityHistoryMap = new HashMap<>();
|
||||
private final List<PlottableEntityHistory> mEntityHistories = new ArrayList<>();
|
||||
private final List<IPlottableUpdateListener> mPlottableUpdateListeners = new CopyOnWriteArrayList<>();
|
||||
private final AliasModel mAliasModel;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -67,181 +59,144 @@ public class PlottableEntityModel extends AbstractTableModel implements Listener
|
||||
*/
|
||||
public void deleteAllTracks()
|
||||
{
|
||||
EventQueue.invokeLater(() -> {
|
||||
if(mEntityHistories.size() > 0)
|
||||
{
|
||||
int firstRow = 0;
|
||||
int lastRow = mEntityHistories.size() - 1;
|
||||
mEntityHistoryMap.clear();
|
||||
mEntityHistories.clear();
|
||||
fireTableRowsDeleted(firstRow, lastRow);
|
||||
}
|
||||
});
|
||||
List<PlottableEntityHistory> removed;
|
||||
|
||||
synchronized(this)
|
||||
{
|
||||
removed = new ArrayList<>(mEntityHistories);
|
||||
mEntityHistoryMap.clear();
|
||||
mEntityHistories.clear();
|
||||
}
|
||||
|
||||
if(!removed.isEmpty())
|
||||
{
|
||||
mPlottableUpdateListeners.forEach(listener -> listener.entitiesRemoved(removed));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the tracks from both the map and entity histories and fires a table model changed event.
|
||||
* Deletes the tracks from the entity histories.
|
||||
* @param tracksToDelete to delete
|
||||
*/
|
||||
public void delete(List<PlottableEntityHistory> tracksToDelete)
|
||||
{
|
||||
EventQueue.invokeLater(() ->
|
||||
List<PlottableEntityHistory> removed = new ArrayList<>();
|
||||
|
||||
synchronized(this)
|
||||
{
|
||||
for(PlottableEntityHistory track : tracksToDelete)
|
||||
{
|
||||
int index = mEntityHistories.indexOf(track);
|
||||
mEntityHistories.remove(track);
|
||||
mEntityHistoryMap.entrySet().removeIf(entry -> entry.getValue() == track);
|
||||
fireTableRowsDeleted(index, index);
|
||||
if(mEntityHistories.remove(track))
|
||||
{
|
||||
mEntityHistoryMap.values().removeIf(value -> value == track);
|
||||
removed.add(track);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(!removed.isEmpty())
|
||||
{
|
||||
mPlottableUpdateListeners.forEach(listener -> listener.entitiesRemoved(removed));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(PlottableDecodeEvent plottableDecodeEvent)
|
||||
{
|
||||
if(plottableDecodeEvent.isValidLocation())
|
||||
if(!plottableDecodeEvent.isValidLocation())
|
||||
{
|
||||
//Add or update the event on the swing event thread
|
||||
EventQueue.invokeLater(() -> {
|
||||
Identifier from = plottableDecodeEvent.getIdentifierCollection().getFromIdentifier();
|
||||
|
||||
if(from != null && from.getForm() != Form.LOCATION)
|
||||
{
|
||||
AliasListConfigurationIdentifier aliasList = plottableDecodeEvent.getIdentifierCollection().getAliasListConfiguration();
|
||||
String key = (aliasList != null ? aliasList.toString() : KEY_NO_ALIAS_LIST) + from;
|
||||
|
||||
PlottableEntityHistory entityHistory = mEntityHistoryMap.get(key);
|
||||
|
||||
if(entityHistory == null)
|
||||
{
|
||||
entityHistory = new PlottableEntityHistory(from, plottableDecodeEvent);
|
||||
mEntityHistories.add(entityHistory);
|
||||
mEntityHistoryMap.put(key, entityHistory);
|
||||
int index = mEntityHistories.indexOf(entityHistory);
|
||||
fireTableRowsInserted(index, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
entityHistory.add(plottableDecodeEvent);
|
||||
int index = mEntityHistories.indexOf(entityHistory);
|
||||
fireTableRowsUpdated(index, index);
|
||||
}
|
||||
|
||||
for(IPlottableUpdateListener listener : mPlottableUpdateListeners)
|
||||
{
|
||||
listener.addPlottableEntity(entityHistory);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// LOGGER.warn("Received plottable decode event that does not contain a FROM identifier - cannot plot");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column)
|
||||
{
|
||||
if(0 <= column && column < COLUMN_NAMES.length)
|
||||
{
|
||||
return COLUMN_NAMES[column];
|
||||
return;
|
||||
}
|
||||
|
||||
return "error!";
|
||||
}
|
||||
Identifier from = plottableDecodeEvent.getIdentifierCollection().getFromIdentifier();
|
||||
|
||||
@Override
|
||||
public int getRowCount()
|
||||
{
|
||||
return mEntityHistories.size();
|
||||
}
|
||||
if(from == null || from.getForm() == Form.LOCATION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount()
|
||||
{
|
||||
return COLUMN_NAMES.length;
|
||||
AliasListConfigurationIdentifier aliasList = plottableDecodeEvent.getIdentifierCollection()
|
||||
.getAliasListConfiguration();
|
||||
String key = (aliasList != null ? aliasList.toString() : KEY_NO_ALIAS_LIST) + from;
|
||||
PlottableEntityHistory entityHistory;
|
||||
boolean added = false;
|
||||
|
||||
synchronized(this)
|
||||
{
|
||||
entityHistory = mEntityHistoryMap.get(key);
|
||||
|
||||
if(entityHistory == null)
|
||||
{
|
||||
entityHistory = new PlottableEntityHistory(from, plottableDecodeEvent);
|
||||
mEntityHistories.add(entityHistory);
|
||||
mEntityHistoryMap.put(key, entityHistory);
|
||||
added = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
entityHistory.add(plottableDecodeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
for(IPlottableUpdateListener listener : mPlottableUpdateListeners)
|
||||
{
|
||||
if(added)
|
||||
{
|
||||
listener.entityAdded(entityHistory);
|
||||
}
|
||||
else
|
||||
{
|
||||
listener.entityUpdated(entityHistory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plottable entity history for the specified model index
|
||||
* @param index in the model
|
||||
* @return entity history or null.
|
||||
* Snapshot of all plottable entity histories, in the order they were added.
|
||||
*/
|
||||
public PlottableEntityHistory get(int index)
|
||||
{
|
||||
if(index >= 0 && index < mEntityHistories.size())
|
||||
{
|
||||
return mEntityHistories.get(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plottable entity histories.
|
||||
*/
|
||||
public List<PlottableEntityHistory> getAll()
|
||||
public synchronized List<PlottableEntityHistory> getAll()
|
||||
{
|
||||
return new ArrayList<>(mEntityHistories);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
/**
|
||||
* Aliases for the entity's identifier from the entity's alias list
|
||||
* @param history of the entity
|
||||
* @return aliases, or an empty list
|
||||
*/
|
||||
public List<Alias> getAliases(PlottableEntityHistory history)
|
||||
{
|
||||
PlottableEntityHistory history = mEntityHistories.get(rowIndex);
|
||||
AliasList aliasList = mAliasModel.getAliasList(history.getIdentifierCollection());
|
||||
|
||||
if(history != null)
|
||||
if(aliasList != null && history.getIdentifier() != null)
|
||||
{
|
||||
switch(columnIndex)
|
||||
{
|
||||
case COLUMN_ID:
|
||||
Identifier identifier = history.getIdentifier();
|
||||
|
||||
if(identifier != null)
|
||||
{
|
||||
return identifier.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "(no ID)";
|
||||
}
|
||||
case COLUMN_ALIAS:
|
||||
Identifier aliasListConfig = history.getIdentifierCollection().getAliasListConfiguration();
|
||||
if(aliasListConfig != null)
|
||||
{
|
||||
AliasList al = mAliasModel.getAliasList(aliasListConfig.toString());
|
||||
|
||||
if(al != null)
|
||||
{
|
||||
List<Alias> aliases = al.getAliases(history.getIdentifier());
|
||||
|
||||
if(!aliases.isEmpty())
|
||||
{
|
||||
return aliases.get(0).getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COLUMN_ALIAS_LIST:
|
||||
Identifier aliasList = history.getIdentifierCollection().getAliasListConfiguration();
|
||||
if(aliasList != null)
|
||||
{
|
||||
return aliasList.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "(no alias list)";
|
||||
}
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected column index");
|
||||
}
|
||||
return aliasList.getAliases(history.getIdentifier());
|
||||
}
|
||||
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the entity's first alias, or null
|
||||
*/
|
||||
public String getAliasName(PlottableEntityHistory history)
|
||||
{
|
||||
List<Alias> aliases = getAliases(history);
|
||||
return aliases.isEmpty() ? null : aliases.getFirst().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the entity's alias list
|
||||
*/
|
||||
public static String getAliasListName(PlottableEntityHistory history)
|
||||
{
|
||||
Identifier aliasList = history.getIdentifierCollection().getAliasListConfiguration();
|
||||
return aliasList != null ? aliasList.toString() : KEY_NO_ALIAS_LIST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener. New listeners don't receive the existing entities: see {@link #getAll()}.
|
||||
*/
|
||||
public void addListener(IPlottableUpdateListener listener)
|
||||
{
|
||||
mPlottableUpdateListeners.add(listener);
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import io.github.dsheirer.alias.AliasModel;
|
||||
import io.github.dsheirer.icon.IconModel;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.painter.AbstractPainter;
|
||||
|
||||
/**
|
||||
* Paints plottable entities to the map.
|
||||
*/
|
||||
public class PlottableEntityPainter extends AbstractPainter<JXMapViewer>
|
||||
{
|
||||
private PlottableEntityRenderer mRenderer;
|
||||
private Set<PlottableEntityHistory> mEntities = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param aliasModel to lookup alias for entities
|
||||
* @param iconModel to lookup icon from alias.
|
||||
*/
|
||||
public PlottableEntityPainter(AliasModel aliasModel, IconModel iconModel)
|
||||
{
|
||||
mRenderer = new PlottableEntityRenderer(aliasModel, iconModel);
|
||||
setAntialiasing(true);
|
||||
setCacheable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the plotted history trails.
|
||||
* @param length of history trails
|
||||
*/
|
||||
public void setTrackHistoryLength(int length)
|
||||
{
|
||||
mRenderer.setTrackHistoryLength(length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Current size of the history trail length.
|
||||
*/
|
||||
public int getTrackHistoryLength()
|
||||
{
|
||||
return mRenderer.getTrackHistoryLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entity to the map
|
||||
* @param entity to add
|
||||
*/
|
||||
public boolean addEntity(PlottableEntityHistory entity)
|
||||
{
|
||||
if(entity != null && !mEntities.contains(entity))
|
||||
{
|
||||
mEntities.add(entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all entities to this painter
|
||||
* @param entities to add.
|
||||
*/
|
||||
public boolean addAll(List<PlottableEntityHistory> entities)
|
||||
{
|
||||
boolean added = false;
|
||||
for(PlottableEntityHistory entity : entities)
|
||||
{
|
||||
added |= addEntity(entity);
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an entity from the map
|
||||
* @param entity to remove
|
||||
*/
|
||||
public void removeEntity(PlottableEntityHistory entity)
|
||||
{
|
||||
mEntities.remove(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all entities from the map.
|
||||
*/
|
||||
public void clearAllEntities()
|
||||
{
|
||||
mEntities.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears teh specified entities from the map
|
||||
* @param toDelete to delete
|
||||
*/
|
||||
public void clearEntities(List<PlottableEntityHistory> toDelete)
|
||||
{
|
||||
mEntities.removeAll(toDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
|
||||
{
|
||||
Rectangle viewportBounds = map.getViewportBounds();
|
||||
|
||||
g.translate(-viewportBounds.getX(), -viewportBounds.getY());
|
||||
|
||||
for(PlottableEntityHistory entity : mEntities)
|
||||
{
|
||||
mRenderer.paintPlottableEntity(g, map, entity, true);
|
||||
}
|
||||
|
||||
g.translate(viewportBounds.getX(), viewportBounds.getY());
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 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.map;
|
||||
|
||||
import io.github.dsheirer.alias.Alias;
|
||||
import io.github.dsheirer.alias.AliasList;
|
||||
import io.github.dsheirer.alias.AliasModel;
|
||||
import io.github.dsheirer.icon.IconModel;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
/**
|
||||
* Paints a single plottable entity to the map.
|
||||
*/
|
||||
public class PlottableEntityRenderer
|
||||
{
|
||||
private AliasModel mAliasModel;
|
||||
private IconModel mIconModel;
|
||||
private int mTrackHistoryLength = 3;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param aliasModel for alias lookup for the entity to determine plot color and icon
|
||||
* @param iconModel to retrieve icon for plotting.
|
||||
*/
|
||||
public PlottableEntityRenderer(AliasModel aliasModel, IconModel iconModel)
|
||||
{
|
||||
mAliasModel = aliasModel;
|
||||
mIconModel = iconModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the plotted history trails.
|
||||
* @param length of history trails
|
||||
*/
|
||||
public void setTrackHistoryLength(int length)
|
||||
{
|
||||
mTrackHistoryLength = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current size of the history trail length.
|
||||
*/
|
||||
public int getTrackHistoryLength()
|
||||
{
|
||||
return mTrackHistoryLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the plottable entity be painted to the map viewer.
|
||||
* @param g graphics
|
||||
* @param viewer requesting the painting
|
||||
* @param entity to be painted
|
||||
* @param antiAliasing for rendering.
|
||||
*/
|
||||
public void paintPlottableEntity(Graphics2D g, JXMapViewer viewer, PlottableEntityHistory entity, boolean antiAliasing)
|
||||
{
|
||||
List<TimestampedGeoPosition> locationHistory = entity.getTrackHistoryModel().getTrackHistory();
|
||||
|
||||
if(!locationHistory.isEmpty() && locationHistory.getLast().isValid())
|
||||
{
|
||||
Graphics2D graphics = (Graphics2D)g.create();
|
||||
|
||||
if(antiAliasing)
|
||||
{
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
List<Alias> aliases = getAliases(entity);
|
||||
|
||||
Alias alias = aliases.isEmpty() ? null : aliases.get(0);
|
||||
|
||||
/**
|
||||
* Use the entity's preferred color for lines and labels
|
||||
*/
|
||||
Color color = (alias != null ? alias.getDisplayColor() : Color.BLUE);
|
||||
graphics.setColor(color);
|
||||
|
||||
/**
|
||||
* Paint the route first, so the icon and label overlay it
|
||||
*/
|
||||
paintRoute(graphics, viewer, entity, color);
|
||||
|
||||
|
||||
/**
|
||||
* Convert the lat/long geoposition to an x/y point on the viewer
|
||||
*/
|
||||
|
||||
Point2D point = viewer.getTileFactory().geoToPixel(entity.getLatestPosition(), viewer.getZoom());
|
||||
|
||||
/**
|
||||
* Paint the icon at the current location
|
||||
*/
|
||||
ImageIcon icon = getIcon(alias);
|
||||
paintIcon(graphics, point, icon);
|
||||
|
||||
/**
|
||||
* Paint the label offset to the right of the icon
|
||||
*/
|
||||
String label = (alias != null ? alias.getName() : entity.getIdentifier().toString());
|
||||
paintLabel(graphics, point, label, (int)(icon.getIconWidth() / 2), 0);
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
graphics.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional alias that matches the identifier for the entity history
|
||||
*/
|
||||
private List<Alias> getAliases(PlottableEntityHistory entityHistory)
|
||||
{
|
||||
AliasList aliasList = mAliasModel.getAliasList(entityHistory.getIdentifierCollection());
|
||||
|
||||
if(aliasList != null)
|
||||
{
|
||||
return aliasList.getAliases(entityHistory.getIdentifier());
|
||||
}
|
||||
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
private ImageIcon getIcon(Alias alias)
|
||||
{
|
||||
String iconName = (alias != null ? alias.getIconName() : null);
|
||||
return mIconModel.getIcon(iconName, IconModel.DEFAULT_ICON_SIZE);
|
||||
}
|
||||
|
||||
private void paintIcon(Graphics2D graphics, Point2D point, ImageIcon icon)
|
||||
{
|
||||
graphics.drawImage(icon.getImage(), (int)point.getX() - (icon.getIconWidth() / 2),
|
||||
(int)point.getY() - (icon.getIconHeight() / 2), null);
|
||||
}
|
||||
|
||||
private void paintLabel(Graphics2D graphics, Point2D point, String label, int xOffset, int yOffset)
|
||||
{
|
||||
graphics.drawString(label, (int)point.getX() + xOffset, (int)point.getY() + yOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a two-tone route from the entity's list of plottables (locations).
|
||||
* using black as a wider background route, and the entity's preferred color
|
||||
* as a narrower foreground route.
|
||||
*/
|
||||
private void paintRoute(Graphics2D graphics, JXMapViewer viewer, PlottableEntityHistory entity, Color color)
|
||||
{
|
||||
List<TimestampedGeoPosition> locations = entity.getTrackHistoryModel().getTrackHistory();
|
||||
|
||||
if(!locations.isEmpty())
|
||||
{
|
||||
// Draw the route with a black background line
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.setStroke(new BasicStroke(3));
|
||||
|
||||
drawRoute(locations, graphics, viewer);
|
||||
|
||||
// Draw the route again, in the entity's preferred color
|
||||
graphics.setColor(color);
|
||||
graphics.setStroke(new BasicStroke(1));
|
||||
|
||||
drawRoute(locations, graphics, viewer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a route from a list of plottables
|
||||
*/
|
||||
private void drawRoute(List<TimestampedGeoPosition> locations, Graphics2D g, JXMapViewer viewer)
|
||||
{
|
||||
Point2D previousPoint = null;
|
||||
|
||||
int length = Math.min(locations.size(), mTrackHistoryLength);
|
||||
|
||||
for(int x = 0; x < length; x++)
|
||||
{
|
||||
GeoPosition location = locations.get(x);
|
||||
|
||||
// convert geo-coordinate to world bitmap pixel
|
||||
Point2D currentPoint = viewer.getTileFactory().geoToPixel(location, viewer.getZoom());
|
||||
|
||||
if(previousPoint != null)
|
||||
{
|
||||
g.drawLine((int)previousPoint.getX(), (int)previousPoint.getY(), (int)currentPoint.getX(), (int)currentPoint.getY());
|
||||
}
|
||||
|
||||
previousPoint = currentPoint;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.preference.radioreference.RadioReferencePreference;
|
||||
import io.github.dsheirer.rrapi.type.Coverage;
|
||||
import io.github.dsheirer.service.radioreference.DistanceFormat;
|
||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HTML card with the details of radio reference trunked system sites, shown when the mouse is over a site's tower on
|
||||
* the map: the system and protocol, the site, and the site's channels.
|
||||
*/
|
||||
public final class RadioReferenceSiteCard
|
||||
{
|
||||
private static final int MAX_SITES = 3;
|
||||
private static final int CHANNEL_COLUMNS = 3;
|
||||
private static final int MAX_CHANNELS = 24;
|
||||
private static final String SEPARATOR = " · ";
|
||||
|
||||
private RadioReferenceSiteCard()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Card for the sites
|
||||
* @param sites under the mouse, nearest first
|
||||
* @param location of the user, for the distances, or null
|
||||
* @return HTML for a tooltip
|
||||
*/
|
||||
public static String html(List<SiteRecord> sites, RadioReferencePreference.Location location)
|
||||
{
|
||||
DecimalFormat frequencyFormat = new DecimalFormat("0.00000");
|
||||
StringBuilder sb = new StringBuilder("<html><body style='padding:3px'>");
|
||||
int shown = Math.min(sites.size(), MAX_SITES);
|
||||
|
||||
for(int index = 0; index < shown; index++)
|
||||
{
|
||||
SiteRecord site = sites.get(index);
|
||||
|
||||
if(index > 0)
|
||||
{
|
||||
sb.append("<hr>");
|
||||
}
|
||||
|
||||
sb.append("<div><b>").append(escape(site.systemName() != null ? site.systemName() : "(unnamed system)"))
|
||||
.append("</b></div>");
|
||||
appendLine(sb, site.protocol(), site.voice());
|
||||
|
||||
String siteName = "Site " + site.siteNumber();
|
||||
String distance = location != null ? DistanceFormat.format(Coverage.distanceKilometers(
|
||||
location.latitude(), location.longitude(), site.latitude(), site.longitude())) : null;
|
||||
appendLine(sb, siteName, site.description(), site.county(), distance);
|
||||
appendLine(sb, site.nac() != null ? "NAC " + site.nac() : null,
|
||||
site.rfss() > 0 ? "RFSS " + site.rfss() : null, site.zone() > 0 ? "Zone " + site.zone() : null);
|
||||
appendChannels(sb, site.channels(), frequencyFormat);
|
||||
}
|
||||
|
||||
if(sites.size() > shown)
|
||||
{
|
||||
sb.append("<hr><div>+ ").append(sites.size() - shown).append(" more site")
|
||||
.append(sites.size() - shown > 1 ? "s" : "").append(" here</div>");
|
||||
}
|
||||
|
||||
sb.append("</body></html>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels in columns, control channels marked C and alternate control channels marked A
|
||||
*/
|
||||
private static void appendChannels(StringBuilder sb, List<SiteRecord.SiteChannel> channels,
|
||||
DecimalFormat frequencyFormat)
|
||||
{
|
||||
if(channels == null || channels.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int shown = Math.min(channels.size(), MAX_CHANNELS);
|
||||
boolean control = false;
|
||||
sb.append("<table cellspacing='0' cellpadding='1'>");
|
||||
|
||||
for(int index = 0; index < shown; index++)
|
||||
{
|
||||
if(index % CHANNEL_COLUMNS == 0)
|
||||
{
|
||||
sb.append("<tr>");
|
||||
}
|
||||
|
||||
SiteRecord.SiteChannel channel = channels.get(index);
|
||||
sb.append("<td style='padding-right:8px'>").append(frequencyFormat.format(channel.frequencyHz() / 1E6));
|
||||
|
||||
if("Control".equals(channel.use()))
|
||||
{
|
||||
sb.append(" <b>C</b>");
|
||||
control = true;
|
||||
}
|
||||
else if("Alternate control".equals(channel.use()))
|
||||
{
|
||||
sb.append(" <b>A</b>");
|
||||
control = true;
|
||||
}
|
||||
|
||||
sb.append("</td>");
|
||||
|
||||
if(index % CHANNEL_COLUMNS == CHANNEL_COLUMNS - 1)
|
||||
{
|
||||
sb.append("</tr>");
|
||||
}
|
||||
}
|
||||
|
||||
if(shown % CHANNEL_COLUMNS != 0)
|
||||
{
|
||||
sb.append("</tr>");
|
||||
}
|
||||
|
||||
sb.append("</table>");
|
||||
List<String> notes = new ArrayList<>();
|
||||
|
||||
if(channels.size() > shown)
|
||||
{
|
||||
notes.add("+ " + (channels.size() - shown) + " more channels");
|
||||
}
|
||||
|
||||
if(control)
|
||||
{
|
||||
notes.add("C control, A alternate control");
|
||||
}
|
||||
|
||||
if(!notes.isEmpty())
|
||||
{
|
||||
appendLine(sb, notes.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a line with the non-empty values separated by dots, or nothing when all are empty
|
||||
*/
|
||||
private static void appendLine(StringBuilder sb, String... values)
|
||||
{
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
||||
for(String value: values)
|
||||
{
|
||||
if(value != null && !value.isBlank())
|
||||
{
|
||||
if(!line.isEmpty())
|
||||
{
|
||||
line.append(SEPARATOR);
|
||||
}
|
||||
|
||||
line.append(escape(value));
|
||||
}
|
||||
}
|
||||
|
||||
if(!line.isEmpty())
|
||||
{
|
||||
sb.append("<div>").append(line).append("</div>");
|
||||
}
|
||||
}
|
||||
|
||||
private static String escape(String text)
|
||||
{
|
||||
return text.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """);
|
||||
}
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import io.github.dsheirer.service.radioreference.SiteRecord;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import org.jdesktop.swingx.painter.AbstractPainter;
|
||||
|
||||
/**
|
||||
* Paints a radio tower at each radio reference trunked system site, with the base of the tower at the site location.
|
||||
*/
|
||||
public class RadioReferenceSitePainter extends AbstractPainter<JXMapViewer>
|
||||
{
|
||||
private static final Color TOWER = new Color(240, 128, 32);
|
||||
private static final Color OUTLINE = new Color(40, 40, 40, 200);
|
||||
private static final Stroke TOWER_STROKE = new BasicStroke(1.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
private static final Stroke OUTLINE_STROKE = new BasicStroke(3.6f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
|
||||
private static final double HEIGHT = 16;
|
||||
private static final double HALF_BASE = 5;
|
||||
//Hit area around the tower, in pixels from the site location
|
||||
private static final Rectangle HIT_AREA = new Rectangle(-10, -24, 20, 28);
|
||||
|
||||
private final Supplier<List<SiteRecord>> mSites;
|
||||
private volatile boolean mShowSites = true;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param sites to paint, read each time the map is painted
|
||||
*/
|
||||
public RadioReferenceSitePainter(Supplier<List<SiteRecord>> sites)
|
||||
{
|
||||
mSites = sites;
|
||||
setAntialiasing(true);
|
||||
setCacheable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows or hides the sites
|
||||
*/
|
||||
public void setShowSites(boolean show)
|
||||
{
|
||||
mShowSites = show;
|
||||
}
|
||||
|
||||
public boolean isShowSites()
|
||||
{
|
||||
return mShowSites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sites whose tower is under the point, nearest first
|
||||
* @param map viewer
|
||||
* @param point in the viewer
|
||||
* @return sites, or an empty list when the sites are hidden or none is under the point
|
||||
*/
|
||||
public List<SiteRecord> getSitesAt(JXMapViewer map, Point point)
|
||||
{
|
||||
if(!mShowSites)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Rectangle viewport = map.getViewportBounds();
|
||||
List<SiteRecord> sites = new ArrayList<>();
|
||||
List<Double> distances = new ArrayList<>();
|
||||
|
||||
for(SiteRecord site: mSites.get())
|
||||
{
|
||||
Point2D pixel = map.getTileFactory().geoToPixel(new GeoPosition(site.latitude(), site.longitude()),
|
||||
map.getZoom());
|
||||
double dx = point.x - (pixel.getX() - viewport.getX());
|
||||
double dy = point.y - (pixel.getY() - viewport.getY());
|
||||
|
||||
if(HIT_AREA.contains(dx, dy))
|
||||
{
|
||||
//Nearest to the middle of the tower first
|
||||
double distance = Math.hypot(dx, dy + (HEIGHT / 2.0));
|
||||
int index = 0;
|
||||
|
||||
while(index < distances.size() && distances.get(index) <= distance)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
sites.add(index, site);
|
||||
distances.add(index, distance);
|
||||
}
|
||||
}
|
||||
|
||||
return sites;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
|
||||
{
|
||||
if(!mShowSites)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle viewport = map.getViewportBounds();
|
||||
|
||||
for(SiteRecord site: mSites.get())
|
||||
{
|
||||
Point2D pixel = map.getTileFactory().geoToPixel(new GeoPosition(site.latitude(), site.longitude()),
|
||||
map.getZoom());
|
||||
double x = pixel.getX() - viewport.getX();
|
||||
double y = pixel.getY() - viewport.getY();
|
||||
|
||||
if(x >= -20 && x <= width + 20 && y >= -4 && y <= height + 30)
|
||||
{
|
||||
paintTower(g, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a tower with its base at the point: an A-frame mast with a cross brace and radio waves at the top
|
||||
*/
|
||||
private static void paintTower(Graphics2D g, double x, double y)
|
||||
{
|
||||
double top = y - HEIGHT;
|
||||
Path2D mast = new Path2D.Double();
|
||||
mast.moveTo(x - HALF_BASE, y);
|
||||
mast.lineTo(x, top);
|
||||
mast.lineTo(x + HALF_BASE, y);
|
||||
mast.moveTo(x - (HALF_BASE * 0.55), y - (HEIGHT * 0.45));
|
||||
mast.lineTo(x + (HALF_BASE * 0.55), y - (HEIGHT * 0.45));
|
||||
|
||||
Arc2D leftInner = new Arc2D.Double(x - 5, top - 4, 10, 8, 135, 90, Arc2D.OPEN);
|
||||
Arc2D rightInner = new Arc2D.Double(x - 5, top - 4, 10, 8, -45, 90, Arc2D.OPEN);
|
||||
Arc2D leftOuter = new Arc2D.Double(x - 9, top - 7, 18, 14, 135, 90, Arc2D.OPEN);
|
||||
Arc2D rightOuter = new Arc2D.Double(x - 9, top - 7, 18, 14, -45, 90, Arc2D.OPEN);
|
||||
|
||||
g.setStroke(OUTLINE_STROKE);
|
||||
g.setColor(OUTLINE);
|
||||
g.draw(mast);
|
||||
g.draw(leftInner);
|
||||
g.draw(rightInner);
|
||||
g.draw(leftOuter);
|
||||
g.draw(rightOuter);
|
||||
|
||||
g.setStroke(TOWER_STROKE);
|
||||
g.setColor(TOWER);
|
||||
g.draw(mast);
|
||||
g.draw(leftInner);
|
||||
g.draw(rightInner);
|
||||
g.draw(leftOuter);
|
||||
g.draw(rightOuter);
|
||||
g.fill(new Ellipse2D.Double(x - 2, top - 2, 4, 4));
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.map;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
/**
|
||||
* Creates a selection rectangle based on mouse input
|
||||
* Also triggers repaint events in the viewer
|
||||
* @author Martin Steiger
|
||||
*/
|
||||
public class SelectionAdapter extends MouseAdapter
|
||||
{
|
||||
private boolean dragging;
|
||||
private JXMapViewer viewer;
|
||||
|
||||
private Point2D startPos = new Point2D.Double();
|
||||
private Point2D endPos = new Point2D.Double();
|
||||
|
||||
/**
|
||||
* @param viewer the jxmapviewer
|
||||
*/
|
||||
public SelectionAdapter(JXMapViewer viewer)
|
||||
{
|
||||
this.viewer = viewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
if (e.getButton() != MouseEvent.BUTTON3)
|
||||
return;
|
||||
|
||||
startPos.setLocation(e.getX(), e.getY());
|
||||
endPos.setLocation(e.getX(), e.getY());
|
||||
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e)
|
||||
{
|
||||
if (!dragging)
|
||||
return;
|
||||
|
||||
endPos.setLocation(e.getX(), e.getY());
|
||||
|
||||
viewer.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if (!dragging)
|
||||
return;
|
||||
|
||||
if (e.getButton() != MouseEvent.BUTTON3)
|
||||
return;
|
||||
|
||||
viewer.repaint();
|
||||
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selection rectangle
|
||||
*/
|
||||
public Rectangle getRectangle()
|
||||
{
|
||||
if (dragging)
|
||||
{
|
||||
int x1 = (int) FastMath.min(startPos.getX(), endPos.getX());
|
||||
int y1 = (int) FastMath.min(startPos.getY(), endPos.getY());
|
||||
int x2 = (int) FastMath.max(startPos.getX(), endPos.getX());
|
||||
int y2 = (int) FastMath.max(startPos.getY(), endPos.getY());
|
||||
|
||||
return new Rectangle(x1, y1, x2-x1, y2-y1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 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.map;
|
||||
|
||||
import org.jdesktop.swingx.painter.Painter;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Paints a selection rectangle
|
||||
* @author Martin Steiger
|
||||
*/
|
||||
public class SelectionPainter implements Painter<Object>
|
||||
{
|
||||
private Color fillColor = new Color(128, 192, 255, 128);
|
||||
private Color frameColor = new Color(0, 0, 255, 128);
|
||||
|
||||
private SelectionAdapter adapter;
|
||||
|
||||
/**
|
||||
* @param adapter the selection adapter
|
||||
*/
|
||||
public SelectionPainter(SelectionAdapter adapter)
|
||||
{
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g, Object t, int width, int height)
|
||||
{
|
||||
Rectangle rc = adapter.getRectangle();
|
||||
|
||||
if (rc != null)
|
||||
{
|
||||
g.setColor(frameColor);
|
||||
g.draw(rc);
|
||||
g.setColor(fillColor);
|
||||
g.fill(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
/**
|
||||
* Timestamped geo position
|
||||
|
||||
@@ -36,7 +36,6 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
|
||||
/**
|
||||
* Map test track data generator.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2025 Dennis Sheirer
|
||||
* 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
|
||||
@@ -19,23 +19,16 @@
|
||||
|
||||
package io.github.dsheirer.map;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
/**
|
||||
* Track history table model.
|
||||
* Location history of a plottable entity, newest first. Thread safe: positions are added on the decode event thread
|
||||
* and read on the JavaFX thread.
|
||||
*/
|
||||
public class TrackHistoryModel extends AbstractTableModel
|
||||
public class TrackHistoryModel
|
||||
{
|
||||
public static final int MAX_LOCATION_HISTORY = 10;
|
||||
private static final String[] COLUMNS = new String[]{"Time", "Latitude", "Longitude"};
|
||||
private final SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private final DecimalFormat mDegreeFormat = new DecimalFormat("0.00000");
|
||||
private final List<TimestampedGeoPosition> mTimestampedGeoPositions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@@ -46,48 +39,46 @@ public class TrackHistoryModel extends AbstractTableModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete history for this entity.
|
||||
* Snapshot of the history for this entity, newest first.
|
||||
*/
|
||||
public List<TimestampedGeoPosition> getTrackHistory()
|
||||
public synchronized List<TimestampedGeoPosition> getTrackHistory()
|
||||
{
|
||||
return Collections.unmodifiableList(mTimestampedGeoPositions);
|
||||
return List.copyOf(mTimestampedGeoPositions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the position to the history if it is unique and trims the history to MAX_LOCATION_HISTORY size.
|
||||
* @param latest position to add.
|
||||
* @return true if the position was added
|
||||
*/
|
||||
public void add(TimestampedGeoPosition latest)
|
||||
public synchronized boolean add(TimestampedGeoPosition latest)
|
||||
{
|
||||
TimestampedGeoPosition mostRecentPosition = null;
|
||||
|
||||
if(!mTimestampedGeoPositions.isEmpty())
|
||||
{
|
||||
mostRecentPosition = mTimestampedGeoPositions.getFirst();
|
||||
}
|
||||
TimestampedGeoPosition mostRecentPosition = mTimestampedGeoPositions.isEmpty() ? null :
|
||||
mTimestampedGeoPositions.getFirst();
|
||||
|
||||
if(isUnique(latest, mostRecentPosition))
|
||||
{
|
||||
mTimestampedGeoPositions.addFirst(latest);
|
||||
fireTableRowsInserted(0, 0);
|
||||
|
||||
while(mTimestampedGeoPositions.size() > MAX_LOCATION_HISTORY)
|
||||
{
|
||||
int index = mTimestampedGeoPositions.size() - 1;
|
||||
mTimestampedGeoPositions.removeLast();
|
||||
fireTableRowsDeleted(index, index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the latest time and position is at least 30 seconds newer than the previous position and either the
|
||||
* latitude or longitude differs by at least 0.00001 degrees.
|
||||
* Indicates if the latest time is more than 2 seconds newer than the previous position or either the latitude or
|
||||
* longitude differs by more than 0.00001 degrees.
|
||||
* @param latest location
|
||||
* @param previous location
|
||||
* @return indication of uniqueness.
|
||||
*/
|
||||
private boolean isUnique(TimestampedGeoPosition latest, TimestampedGeoPosition previous)
|
||||
private static boolean isUnique(TimestampedGeoPosition latest, TimestampedGeoPosition previous)
|
||||
{
|
||||
if(latest != null && previous == null)
|
||||
{
|
||||
@@ -106,10 +97,10 @@ public class TrackHistoryModel extends AbstractTableModel
|
||||
|
||||
/**
|
||||
* Get the geo position at the specified index
|
||||
* @param index to retrieve
|
||||
* @param index to retrieve, 0 for the newest
|
||||
* @return geo or null.
|
||||
*/
|
||||
public TimestampedGeoPosition get(int index)
|
||||
public synchronized TimestampedGeoPosition get(int index)
|
||||
{
|
||||
if(index >= 0 && index < mTimestampedGeoPositions.size())
|
||||
{
|
||||
@@ -119,38 +110,11 @@ public class TrackHistoryModel extends AbstractTableModel
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount()
|
||||
/**
|
||||
* Number of positions in the history
|
||||
*/
|
||||
public synchronized int size()
|
||||
{
|
||||
return mTimestampedGeoPositions.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount()
|
||||
{
|
||||
return COLUMNS.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column)
|
||||
{
|
||||
return COLUMNS[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex)
|
||||
{
|
||||
TimestampedGeoPosition geoPosition = mTimestampedGeoPositions.get(rowIndex);
|
||||
switch (columnIndex)
|
||||
{
|
||||
case 0:
|
||||
return mSimpleDateFormat.format(geoPosition.getTimestamp());
|
||||
case 1:
|
||||
return mDegreeFormat.format(geoPosition.getLatitude());
|
||||
case 2:
|
||||
return mDegreeFormat.format(geoPosition.getLongitude());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* 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.map;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import org.jdesktop.swingx.JXMapViewer;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import org.jdesktop.swingx.painter.AbstractPainter;
|
||||
|
||||
/**
|
||||
* Paints a push-pin at the user's location, with the tip of the pin at the location.
|
||||
*/
|
||||
public class UserLocationPainter extends AbstractPainter<JXMapViewer>
|
||||
{
|
||||
private static final Color NEEDLE = new Color(90, 90, 90);
|
||||
private static final Color HEAD = new Color(220, 40, 40);
|
||||
private static final Color HEAD_OUTLINE = new Color(110, 0, 0);
|
||||
private static final Color HIGHLIGHT = new Color(255, 255, 255, 170);
|
||||
private static final Color SHADOW = new Color(0, 0, 0, 70);
|
||||
private static final double NEEDLE_LENGTH = 14.0;
|
||||
private static final double HEAD_RADIUS = 7.0;
|
||||
|
||||
private volatile GeoPosition mPosition;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public UserLocationPainter()
|
||||
{
|
||||
setAntialiasing(true);
|
||||
setCacheable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location to mark
|
||||
* @param position of the user, or null to remove the pin
|
||||
*/
|
||||
public void setPosition(GeoPosition position)
|
||||
{
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location that is marked
|
||||
* @return position, or null
|
||||
*/
|
||||
public GeoPosition getPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPaint(Graphics2D g, JXMapViewer map, int width, int height)
|
||||
{
|
||||
GeoPosition position = mPosition;
|
||||
|
||||
if(position == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle viewportBounds = map.getViewportBounds();
|
||||
Point2D point = map.getTileFactory().geoToPixel(position, map.getZoom());
|
||||
double x = point.getX() - viewportBounds.getX();
|
||||
double y = point.getY() - viewportBounds.getY();
|
||||
double headY = y - NEEDLE_LENGTH - HEAD_RADIUS;
|
||||
|
||||
//Shadow where the needle enters the map, so the tip reads as the location
|
||||
g.setColor(SHADOW);
|
||||
g.fill(new Ellipse2D.Double(x - 4, y - 2, 8, 4));
|
||||
|
||||
g.setColor(NEEDLE);
|
||||
g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||
g.draw(new Line2D.Double(x, y, x, headY));
|
||||
|
||||
Ellipse2D head = new Ellipse2D.Double(x - HEAD_RADIUS, headY - HEAD_RADIUS, HEAD_RADIUS * 2, HEAD_RADIUS * 2);
|
||||
g.setColor(HEAD);
|
||||
g.fill(head);
|
||||
g.setColor(HEAD_OUTLINE);
|
||||
g.setStroke(new BasicStroke(1.0f));
|
||||
g.draw(head);
|
||||
|
||||
g.setColor(HIGHLIGHT);
|
||||
g.fill(new Ellipse2D.Double(x - HEAD_RADIUS / 2 - 1, headY - HEAD_RADIUS / 2 - 1, 4, 4));
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ import io.github.dsheirer.source.tuner.channel.rotation.AddChannelRotationActive
|
||||
import io.github.dsheirer.util.PacketUtil;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import io.github.dsheirer.module.decode.dmr.message.type.PositionError;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* GPS Information
|
||||
|
||||
@@ -52,6 +52,7 @@ public class DMRSoftSyncDetectorFactory
|
||||
case VECTOR_SIMD_512:
|
||||
return new DMRSoftSyncDetectorVector512();
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new DMRSoftSyncDetectorScalar();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ package io.github.dsheirer.module.decode.event;
|
||||
import io.github.dsheirer.channel.IChannelDescriptor;
|
||||
import io.github.dsheirer.identifier.IdentifierCollection;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
public class PlottableDecodeEvent extends DecodeEvent
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ package io.github.dsheirer.module.decode.fleetsync2.message;
|
||||
|
||||
import io.github.dsheirer.bits.CorrectedBinaryMessage;
|
||||
import io.github.dsheirer.identifier.Identifier;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
@@ -75,6 +75,9 @@ import io.github.dsheirer.module.decode.nxdn.layer3.mobility.RegistrationCommand
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.mobility.RegistrationResponse;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.mobility.RegistrationResponseTypeD;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.proprietary.TalkerAliasComplete;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.scch.Information1;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.scch.InitializationVectorPart1;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.CipherType;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -288,8 +291,9 @@ public class NXDNDecoderState extends DecoderState
|
||||
{
|
||||
//Controller responds to a voice call request with either a channel grant, or this message if
|
||||
//it can't support the call or the called party is not available
|
||||
//Type-D call response doesn't carry a cause.
|
||||
broadcastEvent(vcr.getIdentifiers(), vcr.getTimestamp(), DecodeEventType.RESPONSE,
|
||||
"VOICE CALL REQUEST - RESPONSE:" + vcr.getCause().toString());
|
||||
vcr.isTypeD() ? "CALL RESPONSE" : "VOICE CALL REQUEST - RESPONSE:" + vcr.getCause());
|
||||
}
|
||||
break;
|
||||
case TRAFFIC_OUT_01_CC_VOICE_CALL:
|
||||
@@ -726,6 +730,24 @@ public class NXDNDecoderState extends DecoderState
|
||||
break;
|
||||
}
|
||||
|
||||
//Messages that don't otherwise change the state (e.g. Type-D SCCH) but are carried in a frame that also carries
|
||||
//voice are a continuation of the call. Otherwise, the ACTIVE state toggles the channel out of CALL state on
|
||||
//every voice frame, squelching the audio module which then discards the call audio.
|
||||
if(state == State.ACTIVE && event == DecoderStateEvent.Event.DECODE && layer3.getLICH().hasAudio())
|
||||
{
|
||||
//Type-D only sends the VOICE CALL at the start of a call. When we join late, or miss it, use the SCCH call
|
||||
//info or initialization vector to determine the encryption state.
|
||||
if(!mEncryptedCallStateDetermined && layer3 instanceof Information1 info1)
|
||||
{
|
||||
mEncryptedCallStateDetermined = true;
|
||||
mEncryptedCall = info1 instanceof InitializationVectorPart1 ||
|
||||
info1.getCipherType() != CipherType.UNENCRYPTED;
|
||||
}
|
||||
|
||||
state = (mEncryptedCallStateDetermined && mEncryptedCall) ? State.ENCRYPTED : State.CALL;
|
||||
event = DecoderStateEvent.Event.CONTINUATION;
|
||||
}
|
||||
|
||||
broadcast(new DecoderStateEvent(this, event, state));
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ import io.github.dsheirer.module.decode.nxdn.layer3.call.Audio;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.call.Disconnect;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.call.TransmissionRelease;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.call.VoiceCall;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.call.VoiceCallWithOptionalLocation;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.scch.Information1;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.scch.InitializationVectorPart1;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.AudioCodec;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.CipherType;
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import java.util.ArrayList;
|
||||
@@ -100,11 +102,18 @@ public class NXDNAudioModule extends AmbeAudioModule
|
||||
mAudioCodec = voiceCall.getCallOption().getCodec();
|
||||
processCachedAudio();
|
||||
}
|
||||
else if(message instanceof VoiceCallWithOptionalLocation voiceCall)
|
||||
//Note: VoiceCallWithOptionalLocation subclasses (request, response, assignment, etc.) don't carry the
|
||||
//cipher type and key ID, so they can't be used to establish the encryption state.
|
||||
else if(!mEncryptedCallStateEstablished && message instanceof Information1 info1 &&
|
||||
info1.getLICH().hasAudio())
|
||||
{
|
||||
mEncryptedCall = voiceCall.getEncryptionKeyIdentifier().isEncrypted();
|
||||
//Type-D only sends the VOICE CALL message at the start of the call. Use the SCCH call info or
|
||||
//initialization vector from a voice frame to establish the encryption state when we join a call
|
||||
//late, or when the VOICE CALL message was missed. Type-D only supports AMBE+ half-rate.
|
||||
mEncryptedCall = info1 instanceof InitializationVectorPart1 ||
|
||||
info1.getCipherType() != CipherType.UNENCRYPTED;
|
||||
mEncryptedCallStateEstablished = true;
|
||||
mAudioCodec = voiceCall.getCallOption().getCodec();
|
||||
mAudioCodec = AudioCodec.HALF_RATE;
|
||||
processCachedAudio();
|
||||
}
|
||||
else if(message instanceof Disconnect || message instanceof TransmissionRelease)
|
||||
|
||||
@@ -51,6 +51,7 @@ public class NXDNSyncDetectorFactory
|
||||
case VECTOR_SIMD_512:
|
||||
return new NXDNSoftSyncDetectorVector512();
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new NXDNSoftSyncDetectorScalar();
|
||||
}
|
||||
|
||||
@@ -25,15 +25,25 @@ import io.github.dsheirer.identifier.Identifier;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer2.LICH;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.NXDNMessageType;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.CauseVD;
|
||||
import io.github.dsheirer.module.decode.nxdn.layer3.type.SystemID;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Voice call response
|
||||
* Voice call response (VCALL_RESP) or Type-D call response (CALL_RESP).
|
||||
*
|
||||
* Note: the Type-D call response (NXDN TS 1-E, Figure 6.4-21) has no cause or cipher fields. Instead, octets 7-9
|
||||
* optionally carry a System ID Option and System ID when the CC Option indicates a multi trunked system.
|
||||
*/
|
||||
public class VoiceCallResponse extends VoiceCallWithOptionalLocation
|
||||
{
|
||||
private static final IntField CAUSE_VD = IntField.length8(OCTET_7);
|
||||
private static final int LOCATION_ID_OFFSET = OCTET_8;
|
||||
private static final int TYPE_D_MASK_MULTI_TRUNKED_SYSTEM = 0x10; //CC Option T-Type flag
|
||||
private static final IntField TYPE_D_SYSTEM_ID_RELATED_UNIT = IntField.length2(OCTET_7);
|
||||
private static final int TYPE_D_SYSTEM_ID_OFFSET = OCTET_7 + 5;
|
||||
private static final int TYPE_D_RELATED_UNIT_SOURCE = 2;
|
||||
private static final int TYPE_D_RELATED_UNIT_DESTINATION = 1;
|
||||
private SystemID mTypeDSystemID;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -58,6 +68,11 @@ public class VoiceCallResponse extends VoiceCallWithOptionalLocation
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(isTypeD())
|
||||
{
|
||||
return toStringTypeD();
|
||||
}
|
||||
|
||||
StringBuilder sb = getMessageBuilder();
|
||||
|
||||
if(getCallControlOption().isEmergency())
|
||||
@@ -88,28 +103,124 @@ public class VoiceCallResponse extends VoiceCallWithOptionalLocation
|
||||
sb.append(" FROM:").append(getSource());
|
||||
sb.append(" TO:").append(getDestination());
|
||||
sb.append(" ").append(getEncryptionKeyIdentifier());
|
||||
|
||||
if(isTypeD())
|
||||
{
|
||||
sb.append(" FREE REPEATER:").append(getMessage().getInt(CALL_OPTION));
|
||||
}
|
||||
|
||||
sb.append(" ").append(getCallOption());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-D call response formatted as a string.
|
||||
*/
|
||||
private String toStringTypeD()
|
||||
{
|
||||
StringBuilder sb = getMessageBuilder();
|
||||
|
||||
if(getCallControlOption().isEmergency())
|
||||
{
|
||||
sb.append("EMERGENCY ");
|
||||
}
|
||||
|
||||
if(getCallControlOption().isPriorityPaging())
|
||||
{
|
||||
sb.append("PRIORITY ");
|
||||
}
|
||||
|
||||
sb.append("TYPE-D ").append(getCallType()).append(" CALL RESPONSE");
|
||||
sb.append(" FROM:").append(getSource());
|
||||
sb.append(" TO:").append(getDestination());
|
||||
|
||||
if(hasTypeDSystemID())
|
||||
{
|
||||
sb.append(" MULTI-SYSTEM ").append(getTypeDSystemID());
|
||||
|
||||
if(isTypeDSystemIDForSource())
|
||||
{
|
||||
sb.append(" (SOURCE)");
|
||||
}
|
||||
else if(isTypeDSystemIDForDestination())
|
||||
{
|
||||
sb.append(" (DESTINATION)");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append(" FREE REPEATER:").append(getFreeRepeater());
|
||||
sb.append(" ").append(getCallOption());
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Type-D free repeater number.
|
||||
*/
|
||||
public int getFreeRepeater()
|
||||
{
|
||||
return getMessage().getInt(CALL_OPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this Type-D call response carries the optional System ID, which is present for a multi trunked
|
||||
* system.
|
||||
*/
|
||||
public boolean hasTypeDSystemID()
|
||||
{
|
||||
return isTypeD() && (getCallControlOption().value() & TYPE_D_MASK_MULTI_TRUNKED_SYSTEM) ==
|
||||
TYPE_D_MASK_MULTI_TRUNKED_SYSTEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional Type-D System ID.
|
||||
* @return system ID or null if the message doesn't carry a system ID.
|
||||
*/
|
||||
public SystemID getTypeDSystemID()
|
||||
{
|
||||
if(mTypeDSystemID == null && hasTypeDSystemID())
|
||||
{
|
||||
mTypeDSystemID = new SystemID(getMessage(), TYPE_D_SYSTEM_ID_OFFSET);
|
||||
}
|
||||
|
||||
return mTypeDSystemID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the Type-D System ID relates to the source unit.
|
||||
*/
|
||||
public boolean isTypeDSystemIDForSource()
|
||||
{
|
||||
return hasTypeDSystemID() && getMessage().getInt(TYPE_D_SYSTEM_ID_RELATED_UNIT) == TYPE_D_RELATED_UNIT_SOURCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the Type-D System ID relates to the destination unit.
|
||||
*/
|
||||
public boolean isTypeDSystemIDForDestination()
|
||||
{
|
||||
return hasTypeDSystemID() &&
|
||||
getMessage().getInt(TYPE_D_SYSTEM_ID_RELATED_UNIT) == TYPE_D_RELATED_UNIT_DESTINATION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Amplifying cause for the response.
|
||||
* @return cause, or UNKNOWN for a Type-D call response which doesn't carry a cause.
|
||||
*/
|
||||
public CauseVD getCause()
|
||||
{
|
||||
if(isTypeD())
|
||||
{
|
||||
return CauseVD.UNKNOWN;
|
||||
}
|
||||
|
||||
return CauseVD.fromValue(getMessage().getInt(CAUSE_VD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Identifier> getIdentifiers()
|
||||
{
|
||||
if(isTypeD())
|
||||
{
|
||||
//Type-D call response doesn't carry an encryption key
|
||||
return List.of(getSource(), getDestination());
|
||||
}
|
||||
|
||||
return List.of(getSource(), getDestination(), getEncryptionKeyIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* JVC/Kenwood NEXEDGE GPS position report.
|
||||
|
||||
@@ -175,7 +175,7 @@ import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.util.PacketUtil;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* L3Harris Talker GPS Complete. This message is assembled from FLC L3Harris Talker GPS Block 1 and Block 2.
|
||||
|
||||
@@ -26,7 +26,7 @@ import io.github.dsheirer.module.decode.dmr.identifier.P25Location;
|
||||
import io.github.dsheirer.module.decode.p25.phase1.message.lc.LinkControlWord;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* Motorola Unit Self-Reported GPS Location
|
||||
|
||||
@@ -52,6 +52,7 @@ public class P25P1SoftSyncDetectorFactory
|
||||
case VECTOR_SIMD_512:
|
||||
return new P25P1SoftSyncDetectorVector512();
|
||||
case SCALAR:
|
||||
case UNCALIBRATED:
|
||||
default:
|
||||
return new P25P1SoftSyncDetectorScalar();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* L3Harris Talker GPS Location.
|
||||
|
||||
@@ -32,7 +32,7 @@ import io.github.dsheirer.module.decode.event.PlottableDecodeEvent;
|
||||
import io.github.dsheirer.module.decode.tait.identifier.TaitIdentifier;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import java.util.TreeSet;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
public class Tait1200DecoderState extends DecoderState
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ import io.github.dsheirer.identifier.Identifier;
|
||||
import io.github.dsheirer.message.Message;
|
||||
import io.github.dsheirer.module.decode.tait.identifier.TaitIdentifier;
|
||||
import io.github.dsheirer.protocol.Protocol;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -40,9 +40,21 @@ public class MapPreference extends Preference
|
||||
*/
|
||||
public static final int DEFAULT_ZOOM = 7;
|
||||
|
||||
/**
|
||||
* Range of OpenStreetMap tile zoom levels the map shows
|
||||
*/
|
||||
public static final int MINIMUM_TILE_ZOOM = 2;
|
||||
public static final int MAXIMUM_TILE_ZOOM = 19;
|
||||
/**
|
||||
* Tile zoom level plus the stored zoom level, for the original Swing map viewer's inverted zoom scale
|
||||
*/
|
||||
private static final int TILE_ZOOM_OFFSET = 19;
|
||||
private static final String CENTER = "center";
|
||||
private static final String ZOOM = "zoom";
|
||||
private static final String SHOW_RADIO_REFERENCE_SITES = "show.radioreference.sites";
|
||||
private static final String TILE_SERVER = "tile.server";
|
||||
private static final String TILE_SERVER_KEY = "tile.server.key.";
|
||||
private static final String TILE_STYLE = "tile.style";
|
||||
private final Preferences mPreferences = Preferences.userNodeForPackage(MapPreference.class);
|
||||
|
||||
/**
|
||||
@@ -145,6 +157,27 @@ public class MapPreference extends Preference
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Last zoom level of the map as an OpenStreetMap tile zoom level, where 0 shows the whole world in one tile and
|
||||
* higher levels are closer. The stored zoom level uses the inverted scale of the original Swing map viewer,
|
||||
* where the tile zoom level is {@link #TILE_ZOOM_OFFSET} minus the stored level, so existing views carry over.
|
||||
* Can be called from any thread.
|
||||
* @return tile zoom level, {@link #MINIMUM_TILE_ZOOM} to {@link #MAXIMUM_TILE_ZOOM}
|
||||
*/
|
||||
public int getTileZoom()
|
||||
{
|
||||
return Math.clamp(TILE_ZOOM_OFFSET - getZoom(), MINIMUM_TILE_ZOOM, MAXIMUM_TILE_ZOOM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the zoom level of the map as an OpenStreetMap tile zoom level
|
||||
* @param tileZoom level, clamped to {@link #MINIMUM_TILE_ZOOM} to {@link #MAXIMUM_TILE_ZOOM}
|
||||
*/
|
||||
public void setTileZoom(int tileZoom)
|
||||
{
|
||||
setZoom(TILE_ZOOM_OFFSET - Math.clamp(tileZoom, MINIMUM_TILE_ZOOM, MAXIMUM_TILE_ZOOM));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the map shows the radio reference trunked system sites near the user
|
||||
*/
|
||||
@@ -165,6 +198,82 @@ public class MapPreference extends Preference
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier of the map tile server
|
||||
* @return identifier, or null when none was chosen
|
||||
*/
|
||||
public String getTileServer()
|
||||
{
|
||||
return mPreferences.get(TILE_SERVER, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the identifier of the map tile server
|
||||
*/
|
||||
public void setTileServer(String id)
|
||||
{
|
||||
if(id != null && !id.equals(getTileServer()))
|
||||
{
|
||||
mPreferences.put(TILE_SERVER, id);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Style of the map tiles: following the theme, light or dark
|
||||
* @return style name, or null when none was chosen
|
||||
*/
|
||||
public String getTileStyle()
|
||||
{
|
||||
return mPreferences.get(TILE_STYLE, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the style of the map tiles
|
||||
*/
|
||||
public void setTileStyle(String style)
|
||||
{
|
||||
if(style != null && !style.equals(getTileStyle()))
|
||||
{
|
||||
mPreferences.put(TILE_STYLE, style);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Key the user entered for a map tile server that needs one
|
||||
* @param id of the tile server
|
||||
* @return key, or null
|
||||
*/
|
||||
public String getTileServerKey(String id)
|
||||
{
|
||||
return mPreferences.get(TILE_SERVER_KEY + id, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the key for a map tile server, or removes it when it's blank
|
||||
* @param id of the tile server
|
||||
* @param key for the server, or null
|
||||
*/
|
||||
public void setTileServerKey(String id, String key)
|
||||
{
|
||||
String value = key != null && !key.isBlank() ? key.strip() : null;
|
||||
|
||||
if(!Objects.equals(value, getTileServerKey(id)))
|
||||
{
|
||||
if(value != null)
|
||||
{
|
||||
mPreferences.put(TILE_SERVER_KEY + id, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
mPreferences.remove(TILE_SERVER_KEY + id);
|
||||
}
|
||||
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the map view stored in the settings file by older versions of the application into this preference.
|
||||
* Does nothing once a center point is stored here.
|
||||
|
||||
@@ -20,7 +20,7 @@ package io.github.dsheirer.settings;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import org.jdesktop.swingx.mapviewer.GeoPosition;
|
||||
import io.github.dsheirer.map.GeoPosition;
|
||||
|
||||
/**
|
||||
* Map view stored in the settings file by older versions of the application. Only read so that settings files from
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -23,50 +23,35 @@ import io.github.dsheirer.source.tuner.airspy.AirspyTunerController.Gain;
|
||||
import io.github.dsheirer.source.tuner.airspy.AirspyTunerController.GainMode;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerStatus;
|
||||
import io.github.dsheirer.source.tuner.ui.GainSlider;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import java.util.List;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
/**
|
||||
* Airspy tuner editor/controller
|
||||
* Airspy tuner editor
|
||||
*/
|
||||
public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfiguration>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(AirspyTunerEditor.class);
|
||||
private JButton mTunerInfoButton;
|
||||
private JComboBox<AirspySampleRate> mSampleRateCombo;
|
||||
private JComboBox<GainMode> mGainModeCombo;
|
||||
private JSlider mMasterGainSlider;
|
||||
private JLabel mMasterGainLabel;
|
||||
private JLabel mMasterGainValueLabel;
|
||||
private JSlider mIFGainSlider;
|
||||
private JLabel mIFGainLabel;
|
||||
private JLabel mIFGainValueLabel;
|
||||
private JSlider mLNAGainSlider;
|
||||
private JLabel mLNAGainValueLabel;
|
||||
private JSlider mMixerGainSlider;
|
||||
private JLabel mMixerGainValueLabel;
|
||||
private JCheckBox mLNAAGCCheckBox;
|
||||
private JCheckBox mMixerAGCCheckBox;
|
||||
private JCheckBox mBiasTCheckBox;
|
||||
private ComboBox<AirspySampleRate> mSampleRateCombo;
|
||||
private ComboBox<GainMode> mGainModeCombo;
|
||||
private GainSlider mMasterGainSlider;
|
||||
private Label mMasterGainLabel;
|
||||
private GainSlider mIFGainSlider;
|
||||
private Label mIFGainLabel;
|
||||
private GainSlider mLNAGainSlider;
|
||||
private Label mLNAGainLabel;
|
||||
private GainSlider mMixerGainSlider;
|
||||
private Label mMixerGainLabel;
|
||||
private CheckBox mLNAAGCCheckBox;
|
||||
private CheckBox mMixerAGCCheckBox;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -78,7 +63,7 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,125 +78,62 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return AirspyTunerController.MAXIMUM_TUNABLE_FREQUENCY_HZ;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("Mode", getGainModeCombo());
|
||||
mMasterGainLabel = gain.addRow("Master", getMasterGainSlider(), new Region());
|
||||
mIFGainLabel = gain.addRow("IF", getIFGainSlider(), new Region());
|
||||
mMixerGainLabel = gain.addRow("Mixer", getMixerGainSlider(), getMixerAGCCheckBox());
|
||||
mLNAGainLabel = gain.addRow("LNA", getLNAGainSlider(), getLNAAGCCheckBox());
|
||||
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText(getTuner().getPreferredName());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText(getDiscoveredTuner().getId());
|
||||
}
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(hasTuner() && !getTuner().getTunerController().isLockedSampleRate());
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
getBiasTCheckBox().setEnabled(hasTuner());
|
||||
getSampleRateCombo().setDisable(!hasTuner() || getTuner().getTunerController().isLockedSampleRate());
|
||||
getBiasTCheckBox().setDisable(!hasTuner());
|
||||
getBiasTCheckBox().setSelected(hasTuner() && hasConfiguration() && getConfiguration().isBiasT());
|
||||
updateGainComponents((hasTuner() && hasConfiguration()) ? getConfiguration().getGain() : null);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
List<AirspySampleRate> rates = getTuner().getController().getSampleRates();
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>(rates.toArray(new AirspySampleRate[rates.size()])));
|
||||
getSampleRateCombo().getItems().setAll(rates);
|
||||
|
||||
if(hasConfiguration())
|
||||
{
|
||||
AirspySampleRate sampleRate = getSampleRate(getConfiguration().getSampleRate());
|
||||
getSampleRateCombo().setSelectedItem(sampleRate);
|
||||
getSampleRateCombo().setValue(getSampleRate(getConfiguration().getSampleRate()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getSampleRateCombo().getItems().clear();
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][][][][][][][grow]"));
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JLabel(""));
|
||||
add(getBiasTCheckBox(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Gain Control"), "wrap");
|
||||
|
||||
add(new JLabel("Mode:"));
|
||||
add(getGainModeCombo(), "wrap");
|
||||
|
||||
add(getMasterGainLabel());
|
||||
add(getMasterGainSlider());
|
||||
add(getMasterGainValueLabel());
|
||||
|
||||
add(getIFGainLabel());
|
||||
add(getIFGainSlider());
|
||||
add(getIFGainValueLabel());
|
||||
|
||||
add(getMixerAGCCheckBox());
|
||||
add(getMixerGainSlider());
|
||||
add(getMixerGainValueLabel());
|
||||
|
||||
add(getLNAAGCCheckBox());
|
||||
add(getLNAGainSlider());
|
||||
add(getLNAGainValueLabel());
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to enable/disable Bias-T power for active antennas
|
||||
*/
|
||||
private JCheckBox getBiasTCheckBox()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTCheckBox = new JCheckBox("Bias-T");
|
||||
mBiasTCheckBox.setEnabled(false);
|
||||
mBiasTCheckBox.setToolTipText("Enable Bias-T power output for active antennas");
|
||||
mBiasTCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas"));
|
||||
mBiasTCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("Bias-T", () -> getTuner().getController().setBiasT(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setBiasT(mBiasTCheckBox.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting Bias-T", e1);
|
||||
JOptionPane.showMessageDialog(mBiasTCheckBox, "Couldn't set Bias-T: " + e1.getMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -219,26 +141,19 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
|
||||
private JCheckBox getLNAAGCCheckBox()
|
||||
private CheckBox getLNAAGCCheckBox()
|
||||
{
|
||||
if(mLNAAGCCheckBox == null)
|
||||
{
|
||||
mLNAAGCCheckBox = new JCheckBox("AGC LNA:");
|
||||
mLNAAGCCheckBox.setEnabled(false);
|
||||
mLNAAGCCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mLNAAGCCheckBox = new CheckBox("AGC");
|
||||
mLNAAGCCheckBox.setTooltip(new Tooltip("Automatic LNA gain control"));
|
||||
mLNAAGCCheckBox.setDisable(true);
|
||||
mLNAAGCCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() && applyToTuner("LNA AGC",
|
||||
() -> getTuner().getController().setLNAAGC(getLNAAGCCheckBox().isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
getLNAGainSlider().setEnabled(!getLNAAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting LNA AGC Enabled");
|
||||
}
|
||||
getLNAGainSlider().setDisable(getLNAAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -246,26 +161,19 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return mLNAAGCCheckBox;
|
||||
}
|
||||
|
||||
private JCheckBox getMixerAGCCheckBox()
|
||||
private CheckBox getMixerAGCCheckBox()
|
||||
{
|
||||
if(mMixerAGCCheckBox == null)
|
||||
{
|
||||
mMixerAGCCheckBox = new JCheckBox("AGC Mixer:");
|
||||
mMixerAGCCheckBox.setEnabled(false);
|
||||
mMixerAGCCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mMixerAGCCheckBox = new CheckBox("AGC");
|
||||
mMixerAGCCheckBox.setTooltip(new Tooltip("Automatic mixer gain control"));
|
||||
mMixerAGCCheckBox.setDisable(true);
|
||||
mMixerAGCCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() && applyToTuner("mixer AGC",
|
||||
() -> getTuner().getController().setMixerAGC(getMixerAGCCheckBox().isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
getMixerGainSlider().setEnabled(!getMixerAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting Mixer AGC Enabled");
|
||||
}
|
||||
getMixerGainSlider().setDisable(getMixerAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -273,93 +181,37 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return mMixerAGCCheckBox;
|
||||
}
|
||||
|
||||
private JLabel getLNAGainValueLabel()
|
||||
{
|
||||
if(mLNAGainValueLabel == null)
|
||||
{
|
||||
mLNAGainValueLabel = new JLabel("0");
|
||||
mLNAGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mLNAGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getLNAGainSlider()
|
||||
private GainSlider getLNAGainSlider()
|
||||
{
|
||||
if(mLNAGainSlider == null)
|
||||
{
|
||||
mLNAGainSlider = new JSlider(JSlider.HORIZONTAL, AirspyTunerController.LNA_GAIN_MIN,
|
||||
AirspyTunerController.LNA_GAIN_MAX, AirspyTunerController.LNA_GAIN_MIN);
|
||||
mLNAGainSlider.setEnabled(false);
|
||||
mLNAGainSlider.setMajorTickSpacing(1);
|
||||
mLNAGainSlider.setPaintTicks(true);
|
||||
mLNAGainSlider.addChangeListener(event ->
|
||||
{
|
||||
int gain = mLNAGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mLNAGainSlider = new GainSlider(AirspyTunerController.LNA_GAIN_MIN, AirspyTunerController.LNA_GAIN_MAX,
|
||||
AirspyTunerController.LNA_GAIN_MIN);
|
||||
mLNAGainSlider.setDisable(true);
|
||||
mLNAGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("LNA gain", () -> getTuner().getController().setLNAGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setLNAGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set airspy LNA gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mLNAGainSlider, "Couldn't set LNA gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getLNAGainValueLabel().setText(String.valueOf(gain));
|
||||
});
|
||||
}
|
||||
|
||||
return mLNAGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getMixerGainValueLabel()
|
||||
{
|
||||
if(mMixerGainValueLabel == null)
|
||||
{
|
||||
mMixerGainValueLabel = new JLabel("0");
|
||||
mMixerGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mMixerGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getMixerGainSlider()
|
||||
private GainSlider getMixerGainSlider()
|
||||
{
|
||||
if(mMixerGainSlider == null)
|
||||
{
|
||||
mMixerGainSlider = new JSlider(JSlider.HORIZONTAL, AirspyTunerController.MIXER_GAIN_MIN,
|
||||
mMixerGainSlider = new GainSlider(AirspyTunerController.MIXER_GAIN_MIN,
|
||||
AirspyTunerController.MIXER_GAIN_MAX, AirspyTunerController.MIXER_GAIN_MIN);
|
||||
mMixerGainSlider.setEnabled(false);
|
||||
mMixerGainSlider.setMajorTickSpacing(1);
|
||||
mMixerGainSlider.setPaintTicks(true);
|
||||
mMixerGainSlider.addChangeListener(new ChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent event)
|
||||
mMixerGainSlider.setDisable(true);
|
||||
mMixerGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("mixer gain", () -> getTuner().getController().setMixerGain(gain)))
|
||||
{
|
||||
int gain = mMixerGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setMixerGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set airspy Mixer gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mMixerGainSlider, "Couldn't set Mixer gain value to " + gain);
|
||||
}
|
||||
}
|
||||
|
||||
getMixerGainValueLabel().setText(String.valueOf(gain));
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -367,134 +219,77 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return mMixerGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getIFGainLabel()
|
||||
{
|
||||
if(mIFGainLabel == null)
|
||||
{
|
||||
mIFGainLabel = new JLabel("IF:");
|
||||
}
|
||||
|
||||
return mIFGainLabel;
|
||||
}
|
||||
|
||||
private JLabel getIFGainValueLabel()
|
||||
{
|
||||
if(mIFGainValueLabel == null)
|
||||
{
|
||||
mIFGainValueLabel = new JLabel("0");
|
||||
mIFGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mIFGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getIFGainSlider()
|
||||
private GainSlider getIFGainSlider()
|
||||
{
|
||||
if(mIFGainSlider == null)
|
||||
{
|
||||
mIFGainSlider = new JSlider(JSlider.HORIZONTAL, AirspyTunerController.IF_GAIN_MIN,
|
||||
AirspyTunerController.IF_GAIN_MAX, AirspyTunerController.IF_GAIN_MIN);
|
||||
mIFGainSlider.setEnabled(false);
|
||||
mIFGainSlider.setMajorTickSpacing(1);
|
||||
mIFGainSlider.setPaintTicks(true);
|
||||
mIFGainSlider.addChangeListener(event ->
|
||||
{
|
||||
int gain = mIFGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mIFGainSlider = new GainSlider(AirspyTunerController.IF_GAIN_MIN, AirspyTunerController.IF_GAIN_MAX,
|
||||
AirspyTunerController.IF_GAIN_MIN);
|
||||
mIFGainSlider.setDisable(true);
|
||||
mIFGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("IF gain", () -> getTuner().getController().setIFGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setIFGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set airspy IF gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mIFGainSlider, "Couldn't set IF gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getIFGainValueLabel().setText(String.valueOf(gain));
|
||||
});
|
||||
}
|
||||
|
||||
return mIFGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getMasterGainLabel()
|
||||
{
|
||||
if(mMasterGainLabel == null)
|
||||
{
|
||||
mMasterGainLabel = new JLabel("Master:");
|
||||
}
|
||||
|
||||
return mMasterGainLabel;
|
||||
}
|
||||
|
||||
private JLabel getMasterGainValueLabel()
|
||||
{
|
||||
if(mMasterGainValueLabel == null)
|
||||
{
|
||||
mMasterGainValueLabel = new JLabel("0");
|
||||
mMasterGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mMasterGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getMasterGainSlider()
|
||||
private GainSlider getMasterGainSlider()
|
||||
{
|
||||
if(mMasterGainSlider == null)
|
||||
{
|
||||
mMasterGainSlider = new JSlider(JSlider.HORIZONTAL, AirspyTunerController.GAIN_MIN,
|
||||
AirspyTunerController.GAIN_MAX, AirspyTunerController.GAIN_MIN);
|
||||
mMasterGainSlider.setEnabled(false);
|
||||
mMasterGainSlider.setMajorTickSpacing(1);
|
||||
mMasterGainSlider.setPaintTicks(true);
|
||||
mMasterGainSlider = new GainSlider(AirspyTunerController.GAIN_MIN, AirspyTunerController.GAIN_MAX,
|
||||
AirspyTunerController.GAIN_MIN);
|
||||
mMasterGainSlider.setDisable(true);
|
||||
mMasterGainSlider.setOnChange(value -> {
|
||||
Gain gain = Gain.getGain(getGainModeCombo().getValue(), value);
|
||||
|
||||
mMasterGainSlider.addChangeListener(event ->
|
||||
{
|
||||
GainMode mode = (GainMode)mGainModeCombo.getSelectedItem();
|
||||
int value = mMasterGainSlider.getValue();
|
||||
Gain gain = Gain.getGain(mode, value);
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
if(hasTuner() && !isLoading() && applyToTuner("gain", () -> getTuner().getController().setGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set airspy gain to:" + gain.name(), e);
|
||||
JOptionPane.showMessageDialog(mMasterGainSlider, "Couldn't set gain value to " +
|
||||
gain.getValue());
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getMasterGainValueLabel().setText(String.valueOf(value));
|
||||
});
|
||||
}
|
||||
|
||||
return mMasterGainSlider;
|
||||
}
|
||||
|
||||
private JComboBox<GainMode> getGainModeCombo()
|
||||
private ComboBox<GainMode> getGainModeCombo()
|
||||
{
|
||||
if(mGainModeCombo == null)
|
||||
{
|
||||
mGainModeCombo = new JComboBox<>(GainMode.values());
|
||||
mGainModeCombo.setEnabled(false);
|
||||
mGainModeCombo.addActionListener(e ->
|
||||
{
|
||||
mGainModeCombo = new ComboBox<>(FXCollections.observableArrayList(GainMode.values()));
|
||||
mGainModeCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mGainModeCombo.setDisable(true);
|
||||
mGainModeCombo.setTooltip(new Tooltip("Linearity and sensitivity modes set all gains from the master " +
|
||||
"gain. Custom mode sets each gain separately."));
|
||||
mGainModeCombo.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
GainMode mode = (GainMode)mGainModeCombo.getSelectedItem();
|
||||
int value = getMasterGainSlider().getValue();
|
||||
Gain gain = Gain.getGain(mode, value);
|
||||
Gain gain = Gain.getGain(mGainModeCombo.getValue(), getMasterGainSlider().getValue());
|
||||
setLoading(true);
|
||||
updateGainComponents(gain);
|
||||
setLoading(false);
|
||||
applyToTuner("gain mode", () -> {
|
||||
AirspyTunerController controller = getTuner().getController();
|
||||
|
||||
if(gain == Gain.CUSTOM)
|
||||
{
|
||||
controller.setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
controller.setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
controller.setIFGain(getIFGainSlider().getValue());
|
||||
controller.setMixerGain(getMixerGainSlider().getValue());
|
||||
controller.setLNAGain(getLNAGainSlider().getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.setGain(gain);
|
||||
}
|
||||
});
|
||||
save();
|
||||
}
|
||||
});
|
||||
@@ -503,37 +298,23 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
return mGainModeCombo;
|
||||
}
|
||||
|
||||
private JComboBox<AirspySampleRate> getSampleRateCombo()
|
||||
private ComboBox<AirspySampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
mSampleRateCombo = new JComboBox<>();
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
mSampleRateCombo = new ComboBox<>();
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
AirspySampleRate rate = mSampleRateCombo.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading() && rate != null &&
|
||||
applyToTuner("sample rate [" + rate.getLabel() + "]",
|
||||
() -> getTuner().getController().setSampleRate(rate)))
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
AirspySampleRate rate = (AirspySampleRate)mSampleRateCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(rate);
|
||||
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(AirspyTunerEditor.this,
|
||||
"Couldn't set sample rate to " + rate.getLabel());
|
||||
mLog.error("Error setting airspy sample rate", e1);
|
||||
}
|
||||
}
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -542,48 +323,29 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
}
|
||||
|
||||
/**
|
||||
* Hyperlink button that provides tuner information
|
||||
*/
|
||||
private JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(AirspyTunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the enabled state of each of the gain controls according to the
|
||||
* specified gain mode. The master gain control is enabled for linearity
|
||||
* and sensitivity and the individual gain controls are disabled, and
|
||||
* vice-versa for custom mode.
|
||||
* Updates the enabled state of each of the gain controls according to the specified gain mode. The master gain
|
||||
* control is enabled for linearity and sensitivity and the individual gain controls are disabled, and vice-versa
|
||||
* for custom mode.
|
||||
*/
|
||||
private void updateGainComponents(Gain gain)
|
||||
{
|
||||
if(hasTuner() && gain != null)
|
||||
{
|
||||
boolean isCustom = gain.equals(Gain.CUSTOM);
|
||||
|
||||
getGainModeCombo().setEnabled(true);
|
||||
getGainModeCombo().setSelectedItem(gain.getGainMode());
|
||||
getMasterGainLabel().setEnabled(!isCustom);
|
||||
getMasterGainSlider().setEnabled(!isCustom);
|
||||
getGainModeCombo().setDisable(false);
|
||||
getGainModeCombo().setValue(gain.getGainMode());
|
||||
mMasterGainLabel.setDisable(isCustom);
|
||||
getMasterGainSlider().setDisable(isCustom);
|
||||
getMasterGainSlider().setValue(gain.getValue());
|
||||
getMasterGainValueLabel().setEnabled(!isCustom);
|
||||
getIFGainLabel().setEnabled(isCustom);
|
||||
getIFGainSlider().setEnabled(isCustom);
|
||||
getIFGainValueLabel().setEnabled(isCustom);
|
||||
getLNAAGCCheckBox().setEnabled(isCustom);
|
||||
getLNAGainSlider().setEnabled(isCustom && !getConfiguration().isLNAAGC());
|
||||
getLNAGainValueLabel().setEnabled(isCustom);
|
||||
getMixerAGCCheckBox().setEnabled(isCustom);
|
||||
getMixerGainSlider().setEnabled(isCustom && !getConfiguration().isMixerAGC());
|
||||
getMixerGainValueLabel().setEnabled(isCustom);
|
||||
mIFGainLabel.setDisable(!isCustom);
|
||||
getIFGainSlider().setDisable(!isCustom);
|
||||
mLNAGainLabel.setDisable(!isCustom);
|
||||
getLNAAGCCheckBox().setDisable(!isCustom);
|
||||
getLNAGainSlider().setDisable(!isCustom || getConfiguration().isLNAAGC());
|
||||
mMixerGainLabel.setDisable(!isCustom);
|
||||
getMixerAGCCheckBox().setDisable(!isCustom);
|
||||
getMixerGainSlider().setDisable(!isCustom || getConfiguration().isMixerAGC());
|
||||
|
||||
if(isCustom)
|
||||
{
|
||||
getIFGainSlider().setValue(getConfiguration().getIFGain());
|
||||
@@ -603,25 +365,23 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
}
|
||||
else
|
||||
{
|
||||
getGainModeCombo().setEnabled(false);
|
||||
getMasterGainLabel().setEnabled(false);
|
||||
getMasterGainSlider().setEnabled(false);
|
||||
getGainModeCombo().setDisable(true);
|
||||
mMasterGainLabel.setDisable(true);
|
||||
getMasterGainSlider().setDisable(true);
|
||||
getMasterGainSlider().setValue(0);
|
||||
getMasterGainValueLabel().setEnabled(false);
|
||||
getIFGainLabel().setEnabled(false);
|
||||
getIFGainSlider().setEnabled(false);
|
||||
mIFGainLabel.setDisable(true);
|
||||
getIFGainSlider().setDisable(true);
|
||||
getIFGainSlider().setValue(0);
|
||||
getIFGainValueLabel().setEnabled(false);
|
||||
getLNAAGCCheckBox().setEnabled(false);
|
||||
mLNAGainLabel.setDisable(true);
|
||||
getLNAAGCCheckBox().setDisable(true);
|
||||
getLNAAGCCheckBox().setSelected(false);
|
||||
getLNAGainSlider().setEnabled(false);
|
||||
getLNAGainSlider().setDisable(true);
|
||||
getLNAGainSlider().setValue(0);
|
||||
getLNAGainValueLabel().setEnabled(false);
|
||||
getMixerAGCCheckBox().setEnabled(false);
|
||||
mMixerGainLabel.setDisable(true);
|
||||
getMixerAGCCheckBox().setDisable(true);
|
||||
getMixerAGCCheckBox().setSelected(false);
|
||||
getMixerGainSlider().setEnabled(false);
|
||||
getMixerGainSlider().setDisable(true);
|
||||
getMixerGainSlider().setValue(0);
|
||||
getMixerGainValueLabel().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,21 +390,21 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setSampleRate(((AirspySampleRate)getSampleRateCombo().getSelectedItem()).getRate());
|
||||
Gain gain = Gain.getGain((GainMode)mGainModeCombo.getSelectedItem(), getMasterGainSlider().getValue());
|
||||
getConfiguration().setGain(gain);
|
||||
getConfiguration().setIFGain(getIFGainSlider().getValue());
|
||||
getConfiguration().setMixerGain(getMixerGainSlider().getValue());
|
||||
getConfiguration().setLNAGain(getLNAGainSlider().getValue());
|
||||
getConfiguration().setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
getConfiguration().setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
getConfiguration().setBiasT(getBiasTCheckBox().isSelected());
|
||||
AirspyTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
|
||||
if(getSampleRateCombo().getValue() != null)
|
||||
{
|
||||
config.setSampleRate(getSampleRateCombo().getValue().getRate());
|
||||
}
|
||||
|
||||
config.setGain(Gain.getGain(getGainModeCombo().getValue(), getMasterGainSlider().getValue()));
|
||||
config.setIFGain(getIFGainSlider().getValue());
|
||||
config.setMixerGain(getMixerGainSlider().getValue());
|
||||
config.setLNAGain(getLNAGainSlider().getValue());
|
||||
config.setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
config.setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -668,7 +428,7 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
}
|
||||
}
|
||||
|
||||
if(rates.size() > 0)
|
||||
if(!rates.isEmpty())
|
||||
{
|
||||
return rates.get(0);
|
||||
}
|
||||
@@ -684,56 +444,32 @@ public class AirspyTunerEditor extends TunerEditor<AirspyTuner, AirspyTunerConfi
|
||||
{
|
||||
if(hasTuner() && getTuner().getController().isLockedSampleRate())
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Sample Rate is locked. Disable decoding channels to unlock.");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Sample rate is locked. Disable decoding channels to unlock."));
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setDisable(!hasTuner() || locked);
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
if(getDiscoveredTuner().getTunerStatus() == TunerStatus.ERROR)
|
||||
{
|
||||
return getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
AirspyDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
|
||||
sb.append("<html><h3>Airspy Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>");
|
||||
sb.append(info.getSerialNumber());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Firmware: </b>");
|
||||
String[] firmware = info.getVersion().split(" ");
|
||||
sb.append(firmware.length > 1 ? firmware[0] : info.getVersion());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Part: </b>");
|
||||
sb.append(info.getPartNumber());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Board: </b>");
|
||||
sb.append(info.getBoardName());
|
||||
sb.append("<br>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
AirspyDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
sb.append("<html><h3>Airspy Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>").append(info.getSerialNumber()).append("<br>");
|
||||
String[] firmware = info.getVersion().split(" ");
|
||||
sb.append("<b>Firmware: </b>").append(firmware.length > 1 ? firmware[0] : info.getVersion()).append("<br>");
|
||||
sb.append("<b>Part: </b>").append(info.getPartNumber()).append("<br>");
|
||||
sb.append("<b>Board: </b>").append(info.getBoardName()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,50 +16,40 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.source.tuner.airspy.hf;
|
||||
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Tooltip;
|
||||
|
||||
/**
|
||||
* Tuner editor for Airspy HF+/Discovery tuners
|
||||
* Airspy HF+ tuner editor
|
||||
*/
|
||||
public class AirspyHfTunerEditor extends TunerEditor<AirspyHfTuner,AirspyHfTunerConfiguration>
|
||||
{
|
||||
private static final Logger mLog = LoggerFactory.getLogger(AirspyHfTunerEditor.class);
|
||||
private JComboBox<AirspyHfSampleRate> mSampleRateCombo;
|
||||
private JComboBox<Attenuation> mAttenuationCombo;
|
||||
private JToggleButton mAgcToggleButton;
|
||||
private JToggleButton mLnaToggleButton;
|
||||
private JToggleButton mBiasTToggleButton;
|
||||
private ComboBox<AirspyHfSampleRate> mSampleRateCombo;
|
||||
private ComboBox<Attenuation> mAttenuationCombo;
|
||||
private CheckBox mAgcCheckBox;
|
||||
private CheckBox mLnaCheckBox;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*
|
||||
* @param userPreferences
|
||||
* @param tunerManager for requesting configuration saves.
|
||||
* @param discoveredTuner
|
||||
* @param userPreferences for settings
|
||||
* @param tunerManager for state updates
|
||||
* @param discoveredTuner to edit or control.
|
||||
*/
|
||||
public AirspyHfTunerEditor(UserPreferences userPreferences, TunerManager tunerManager, DiscoveredTuner discoveredTuner)
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,61 +66,41 @@ public class AirspyHfTunerEditor extends TunerEditor<AirspyHfTuner,AirspyHfTuner
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][][][][grow]"));
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel(), "wrap");
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("Attenuation", getAttenuationCombo(), getAgcCheckBox());
|
||||
gain.addControl(getLnaCheckBox());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span");
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new MigLayout("insets 0", "[left]", ""));
|
||||
buttonPanel.add(getAgcToggleButton());
|
||||
buttonPanel.add(getLnaToggleButton());
|
||||
buttonPanel.add(getBiasTToggleButton());
|
||||
add(new JLabel(" "));
|
||||
add(buttonPanel, "wrap");
|
||||
|
||||
add(new JLabel("Attenuation:"));
|
||||
add(getAttenuationCombo(), "wrap");
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
AirspyHfTunerController controller = getTuner().getController();
|
||||
return "<html><h3>Airspy HF+ Tuner</h3>" +
|
||||
"<b>Board: </b>" + controller.getBoardId() + "<br>" +
|
||||
"<b>Serial: </b>" + controller.getSerialNumber() + "<br>" +
|
||||
"<b>Firmware: </b>" + controller.getFirmwareVersion() + "<br>";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void save()
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
if(hasConfiguration() && hasTuner() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setSampleRate((int)getTuner().getController().getSampleRate());
|
||||
AirspyHfTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
config.setSampleRate((int)getTuner().getController().getSampleRate());
|
||||
config.setAttenuation(getAttenuationCombo().getValue());
|
||||
config.setAgc(getAgcCheckBox().isSelected());
|
||||
config.setLna(getLnaCheckBox().isSelected());
|
||||
|
||||
Attenuation attenuation = (Attenuation)getAttenuationCombo().getSelectedItem();
|
||||
getConfiguration().setAttenuation(attenuation);
|
||||
getConfiguration().setAgc(getAgcToggleButton().isSelected());
|
||||
getConfiguration().setLna(getLnaToggleButton().isSelected());
|
||||
|
||||
//Only update bias-T when the device supports it, so the saved setting isn't lost on unsupported firmware.
|
||||
if(getTuner().getController().isBiasTSupported())
|
||||
{
|
||||
getConfiguration().setBiasT(getBiasTToggleButton().isSelected());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
}
|
||||
|
||||
saveConfiguration();
|
||||
@@ -140,123 +110,80 @@ public class AirspyHfTunerEditor extends TunerEditor<AirspyHfTuner,AirspyHfTuner
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText("Airspy " + getTuner().getController().getBoardId() + " SER# " +
|
||||
getTuner().getController().getSerialNumber() + " FW " + getTuner().getController().getFirmwareVersion());
|
||||
|
||||
getSampleRateCombo().setEnabled(!getTuner().getTunerController().isLockedSampleRate());
|
||||
getSampleRateCombo().removeAllItems();
|
||||
for(AirspyHfSampleRate sampleRate: getTuner().getController().getAvailableSampleRates())
|
||||
{
|
||||
getSampleRateCombo().addItem(sampleRate);
|
||||
}
|
||||
getAgcToggleButton().setEnabled(true);
|
||||
getAgcToggleButton().setSelected(getTuner().getController().getAgc());
|
||||
getLnaToggleButton().setEnabled(true);
|
||||
getLnaToggleButton().setSelected(getTuner().getController().getLna());
|
||||
boolean biasTSupported = getTuner().getController().isBiasTSupported();
|
||||
getBiasTToggleButton().setEnabled(biasTSupported);
|
||||
getBiasTToggleButton().setSelected(biasTSupported && getTuner().getController().getBiasT());
|
||||
getBiasTToggleButton().setToolTipText(biasTSupported ? "Enable Bias-T power output for active antennas" :
|
||||
"Bias-T not supported by this device or firmware");
|
||||
getSampleRateCombo().setSelectedItem(getTuner().getController().getCurrentAirspySampleRate());
|
||||
getAttenuationCombo().setEnabled(!getTuner().getController().getAgc());
|
||||
getAttenuationCombo().setSelectedItem(getTuner().getController().getAttenuation());
|
||||
AirspyHfTunerController controller = getTuner().getController();
|
||||
getSampleRateCombo().setDisable(controller.isLockedSampleRate());
|
||||
getSampleRateCombo().getItems().setAll(controller.getAvailableSampleRates());
|
||||
getSampleRateCombo().setValue(controller.getCurrentAirspySampleRate());
|
||||
getAgcCheckBox().setDisable(false);
|
||||
getAgcCheckBox().setSelected(controller.getAgc());
|
||||
getLnaCheckBox().setDisable(false);
|
||||
getLnaCheckBox().setSelected(controller.getLna());
|
||||
boolean biasTSupported = controller.isBiasTSupported();
|
||||
getBiasTCheckBox().setDisable(!biasTSupported);
|
||||
getBiasTCheckBox().setSelected(biasTSupported && controller.getBiasT());
|
||||
getBiasTCheckBox().setTooltip(new Tooltip(biasTSupported ? "Enable Bias-T power output for active " +
|
||||
"antennas" : "Bias-T not supported by this device or firmware"));
|
||||
getAttenuationCombo().setDisable(controller.getAgc());
|
||||
getAttenuationCombo().setValue(controller.getAttenuation());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText("Airspy HF+");
|
||||
getAgcToggleButton().setEnabled(false);
|
||||
getAgcToggleButton().setSelected(false);
|
||||
getLnaToggleButton().setEnabled(false);
|
||||
getLnaToggleButton().setSelected(false);
|
||||
getBiasTToggleButton().setEnabled(false);
|
||||
getBiasTToggleButton().setSelected(false);
|
||||
getBiasTToggleButton().setToolTipText("No tuner available");
|
||||
getSampleRateCombo().setEnabled(false);
|
||||
getAttenuationCombo().setEnabled(false);
|
||||
getAttenuationCombo().setSelectedItem(Attenuation.A0);
|
||||
getAgcCheckBox().setDisable(true);
|
||||
getAgcCheckBox().setSelected(false);
|
||||
getLnaCheckBox().setDisable(true);
|
||||
getLnaCheckBox().setSelected(false);
|
||||
getBiasTCheckBox().setDisable(true);
|
||||
getBiasTCheckBox().setSelected(false);
|
||||
getBiasTCheckBox().setTooltip(new Tooltip("No tuner available"));
|
||||
getSampleRateCombo().setDisable(true);
|
||||
getAttenuationCombo().setDisable(true);
|
||||
getAttenuationCombo().setValue(Attenuation.A0);
|
||||
}
|
||||
|
||||
updateSampleRateToolTip();
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sample rate tooltip according to the tuner controller's lock state.
|
||||
*/
|
||||
private void updateSampleRateToolTip()
|
||||
{
|
||||
if(hasTuner() && getTuner().getTunerController().isLockedSampleRate())
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Sample Rate is locked. Disable decoding channels to unlock.");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Sample rate is locked. Disable decoding channels to unlock."));
|
||||
}
|
||||
else if(hasTuner())
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("No tuner available");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("No tuner available"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setDisable(!hasTuner() || locked);
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample rate combo for selecting among available sample rates.
|
||||
* @return sample rate combo
|
||||
*/
|
||||
private JComboBox<AirspyHfSampleRate> getSampleRateCombo()
|
||||
private ComboBox<AirspyHfSampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
mSampleRateCombo = new JComboBox<>();
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(e ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mSampleRateCombo = new ComboBox<>();
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
AirspyHfSampleRate sampleRate = mSampleRateCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && sampleRate != null &&
|
||||
applyToTuner("sample rate [" + sampleRate + "]",
|
||||
() -> getTuner().getController().setSampleRate(sampleRate)))
|
||||
{
|
||||
AirspyHfSampleRate sampleRate = (AirspyHfSampleRate)mSampleRateCombo.getSelectedItem();
|
||||
|
||||
if(sampleRate != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(sampleRate);
|
||||
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(sampleRate.getSampleRate());
|
||||
|
||||
save();
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
mLog.error("Error setting Airspy Hf Sample Rate [" + sampleRate + "]", se);
|
||||
JOptionPane.showMessageDialog(AirspyHfTunerEditor.this,
|
||||
"Airspy Tuner Controller - couldn't apply the sample rate setting [" +
|
||||
sampleRate + "] " + se.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
adjustForSampleRate(sampleRate.getSampleRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -264,33 +191,22 @@ public class AirspyHfTunerEditor extends TunerEditor<AirspyHfTuner,AirspyHfTuner
|
||||
return mSampleRateCombo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combobox with available attenuation items
|
||||
* @return combo box
|
||||
*/
|
||||
private JComboBox<Attenuation> getAttenuationCombo()
|
||||
private ComboBox<Attenuation> getAttenuationCombo()
|
||||
{
|
||||
if(mAttenuationCombo == null)
|
||||
{
|
||||
mAttenuationCombo = new JComboBox<>(Attenuation.values());
|
||||
mAttenuationCombo.setToolTipText("Attenuation applies when the AGC is off");
|
||||
mAttenuationCombo.setEnabled(false);
|
||||
mAttenuationCombo.addActionListener(e -> {
|
||||
if(!isLoading())
|
||||
mAttenuationCombo = new ComboBox<>(FXCollections.observableArrayList(Attenuation.values()));
|
||||
mAttenuationCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mAttenuationCombo.setTooltip(new Tooltip("Attenuation applies when the AGC is off"));
|
||||
mAttenuationCombo.setDisable(true);
|
||||
mAttenuationCombo.setOnAction(e -> {
|
||||
Attenuation selected = mAttenuationCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && selected != null &&
|
||||
applyToTuner("attenuation [" + selected + "]",
|
||||
() -> getTuner().getController().setAttenuation(selected)))
|
||||
{
|
||||
Attenuation selected = (Attenuation)mAttenuationCombo.getSelectedItem();
|
||||
try
|
||||
{
|
||||
getTuner().getController().setAttenuation(selected);
|
||||
save();
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
mLog.error("Error setting Airspy Hf attenuation [" + selected + "]", se);
|
||||
JOptionPane.showMessageDialog(AirspyHfTunerEditor.this,
|
||||
"Airspy Tuner Controller - couldn't apply attenuation setting [" +
|
||||
selected + "] " + se.getLocalizedMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -298,98 +214,67 @@ public class AirspyHfTunerEditor extends TunerEditor<AirspyHfTuner,AirspyHfTuner
|
||||
return mAttenuationCombo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatic Gain Control (AGC) toggle button
|
||||
*/
|
||||
private JToggleButton getAgcToggleButton()
|
||||
private CheckBox getAgcCheckBox()
|
||||
{
|
||||
if(mAgcToggleButton == null)
|
||||
if(mAgcCheckBox == null)
|
||||
{
|
||||
mAgcToggleButton = new JToggleButton("AGC");
|
||||
mAgcToggleButton.setToolTipText("Automatic Gain Control");
|
||||
mAgcToggleButton.setEnabled(false);
|
||||
mAgcToggleButton.addActionListener(e -> {
|
||||
if(!isLoading())
|
||||
mAgcCheckBox = new CheckBox("AGC");
|
||||
mAgcCheckBox.setTooltip(new Tooltip("Automatic gain control"));
|
||||
mAgcCheckBox.setDisable(true);
|
||||
mAgcCheckBox.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner() &&
|
||||
applyToTuner("AGC", () -> getTuner().getController().setAgc(mAgcCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setAgc(mAgcToggleButton.isSelected());
|
||||
getAttenuationCombo().setEnabled(!mAgcToggleButton.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
mLog.error("Error setting Airspy HF AGC", se);
|
||||
JOptionPane.showMessageDialog(AirspyHfTunerEditor.this,
|
||||
"Airspy HF Tuner Controller - couldn't change AGC setting" + se.getLocalizedMessage());
|
||||
}
|
||||
getAttenuationCombo().setDisable(mAgcCheckBox.isSelected());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mAgcToggleButton;
|
||||
return mAgcCheckBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Low Noise Amplifier (LNA) toggle button
|
||||
*/
|
||||
private JToggleButton getLnaToggleButton()
|
||||
private CheckBox getLnaCheckBox()
|
||||
{
|
||||
if(mLnaToggleButton == null)
|
||||
if(mLnaCheckBox == null)
|
||||
{
|
||||
mLnaToggleButton = new JToggleButton("LNA");
|
||||
mLnaToggleButton.setToolTipText("Low Noise Amplifier");
|
||||
mLnaToggleButton.setEnabled(false);
|
||||
mLnaToggleButton.addActionListener(e -> {
|
||||
if(!isLoading())
|
||||
mLnaCheckBox = new CheckBox("LNA (low noise amplifier)");
|
||||
mLnaCheckBox.setTooltip(new Tooltip("Turn on the low noise amplifier"));
|
||||
mLnaCheckBox.setDisable(true);
|
||||
mLnaCheckBox.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner() &&
|
||||
applyToTuner("LNA", () -> getTuner().getController().setLna(mLnaCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setLna(mLnaToggleButton.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
mLog.error("Error setting Airspy HF LNA", se);
|
||||
JOptionPane.showMessageDialog(AirspyHfTunerEditor.this,
|
||||
"Airspy HF Tuner Controller - couldn't change LNA setting" + se.getLocalizedMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mLnaToggleButton;
|
||||
return mLnaCheckBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bias-T toggle button, enabled only when the device firmware supports a bias-T.
|
||||
*/
|
||||
private JToggleButton getBiasTToggleButton()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTToggleButton == null)
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTToggleButton = new JToggleButton("Bias-T");
|
||||
mBiasTToggleButton.setToolTipText("Enable Bias-T power output for active antennas");
|
||||
mBiasTToggleButton.setEnabled(false);
|
||||
mBiasTToggleButton.addActionListener(e -> {
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas"));
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
try
|
||||
if(applyToTuner("Bias-T", () -> getTuner().getController().setBiasT(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
getTuner().getController().setBiasT(mBiasTToggleButton.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException se)
|
||||
else
|
||||
{
|
||||
mLog.error("Error setting Airspy HF Bias-T", se);
|
||||
mBiasTToggleButton.setSelected(getTuner().getController().getBiasT());
|
||||
JOptionPane.showMessageDialog(AirspyHfTunerEditor.this,
|
||||
"Airspy HF Tuner Controller - couldn't change Bias-T setting " + se.getLocalizedMessage());
|
||||
mBiasTCheckBox.setSelected(getTuner().getController().getBiasT());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mBiasTToggleButton;
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.source.tuner.bladerf;
|
||||
|
||||
import io.github.dsheirer.bladerf.GainMode;
|
||||
@@ -25,41 +24,26 @@ import io.github.dsheirer.bladerf.Range;
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerStatus;
|
||||
import io.github.dsheirer.source.tuner.ui.GainSlider;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import java.awt.Component;
|
||||
import java.io.Serial;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import java.util.List;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
/**
|
||||
* bladeRF tuner editor
|
||||
* bladeRF tuner editor. sdrtrunk uses the RX1 connector as a single tuner.
|
||||
*/
|
||||
public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerConfiguration>
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger mLog = LoggerFactory.getLogger(BladeRfTunerEditor.class);
|
||||
private JButton mTunerInfoButton;
|
||||
private JComboBox<BladeRfSampleRate> mSampleRateCombo;
|
||||
private JCheckBox mBiasTCheckBox;
|
||||
private JComboBox<GainModeInfo> mGainModeCombo;
|
||||
private JSlider mGainSlider;
|
||||
private JLabel mGainValueLabel;
|
||||
private ComboBox<BladeRfSampleRate> mSampleRateCombo;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
private ComboBox<GainModeInfo> mGainModeCombo;
|
||||
private GainSlider mGainSlider;
|
||||
private Label mGainLabel;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -71,7 +55,7 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,78 +74,33 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]", "[][][][][][][][][][][][grow]"));
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("Mode", getGainModeCombo());
|
||||
mGainLabel = gain.addRow("Gain", getGainSlider());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JLabel());
|
||||
add(getBiasTCheckBox(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx");
|
||||
add(new JLabel("Gain Control"), "wrap");
|
||||
|
||||
add(new JLabel("Mode:"));
|
||||
add(getGainModeCombo(), "wrap");
|
||||
|
||||
add(new JLabel("Gain:"));
|
||||
add(getGainSlider());
|
||||
add(getGainValueLabel());
|
||||
|
||||
//Empty row that takes all extra vertical space so that the controls stay stacked at the top of the editor.
|
||||
add(new JLabel(), "span,pushy");
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
boolean started = hasStartedTuner();
|
||||
getTunerIdLabel().setText(started ? getTuner().getPreferredName() : getDiscoveredTuner().getId());
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getTunerInfoButton().setEnabled(started);
|
||||
|
||||
if(started)
|
||||
if(hasStartedTuner())
|
||||
{
|
||||
BladeRfTunerController controller = getTuner().getController();
|
||||
List<BladeRfSampleRate> rates = controller.getSampleRates();
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>(rates.toArray(new BladeRfSampleRate[0])));
|
||||
getSampleRateCombo().setSelectedItem(controller.getBladeRfSampleRate());
|
||||
getSampleRateCombo().setEnabled(!controller.isLockedSampleRate());
|
||||
|
||||
getSampleRateCombo().getItems().setAll(rates);
|
||||
getSampleRateCombo().setValue(controller.getBladeRfSampleRate());
|
||||
getSampleRateCombo().setDisable(controller.isLockedSampleRate());
|
||||
getBiasTCheckBox().setVisible(controller.isBiasTSupported());
|
||||
getBiasTCheckBox().setEnabled(true);
|
||||
|
||||
getBiasTCheckBox().setDisable(false);
|
||||
List<GainModeInfo> modes = controller.getGainModes();
|
||||
getGainModeCombo().setModel(new DefaultComboBoxModel<>(modes.toArray(new GainModeInfo[0])));
|
||||
getGainModeCombo().setEnabled(true);
|
||||
|
||||
getGainModeCombo().getItems().setAll(modes);
|
||||
getGainModeCombo().setDisable(false);
|
||||
Range range = controller.getGainRange();
|
||||
getGainSlider().setMinimum((int)range.min());
|
||||
getGainSlider().setMaximum((int)range.max());
|
||||
getGainSlider().setRange((int)range.min(), (int)range.max());
|
||||
|
||||
if(hasConfiguration())
|
||||
{
|
||||
@@ -172,7 +111,7 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
{
|
||||
if(mode.mode() == getConfiguration().getGainMode())
|
||||
{
|
||||
getGainModeCombo().setSelectedItem(mode);
|
||||
getGainModeCombo().setValue(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,81 +120,50 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getSampleRateCombo().setEnabled(false);
|
||||
getBiasTCheckBox().setEnabled(false);
|
||||
getSampleRateCombo().getItems().clear();
|
||||
getSampleRateCombo().setDisable(true);
|
||||
getBiasTCheckBox().setDisable(true);
|
||||
getBiasTCheckBox().setSelected(false);
|
||||
getGainModeCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getGainModeCombo().setEnabled(false);
|
||||
getGainSlider().setEnabled(false);
|
||||
getGainValueLabel().setEnabled(false);
|
||||
getGainModeCombo().getItems().clear();
|
||||
getGainModeCombo().setDisable(true);
|
||||
getGainSlider().setDisable(true);
|
||||
mGainLabel.setDisable(true);
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the tuner has finished starting, since a status update can arrive while it's starting or restarting.
|
||||
* Indicates if the tuner is started, which is when the controller has the gain range.
|
||||
*/
|
||||
private boolean hasStartedTuner()
|
||||
{
|
||||
return hasTuner() && getTuner().getController().getGainRange() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the gain slider when the gain mode is manual and refreshes the gain value label.
|
||||
*/
|
||||
private void updateGainControls()
|
||||
{
|
||||
GainModeInfo mode = (GainModeInfo)getGainModeCombo().getSelectedItem();
|
||||
GainModeInfo mode = getGainModeCombo().getValue();
|
||||
boolean manual = hasTuner() && mode != null && mode.mode() == GainMode.MANUAL;
|
||||
getGainSlider().setEnabled(manual);
|
||||
getGainValueLabel().setEnabled(manual);
|
||||
getGainValueLabel().setText(manual ? getGainSlider().getValue() + " dB" : "AGC");
|
||||
getGainSlider().setDisable(!manual);
|
||||
mGainLabel.setDisable(!manual);
|
||||
getGainSlider().setFormatter(value -> manual ? value + " dB" : "AGC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Button that provides tuner information
|
||||
*/
|
||||
private JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(_ -> JOptionPane.showMessageDialog(BladeRfTunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
private JComboBox<BladeRfSampleRate> getSampleRateCombo()
|
||||
private ComboBox<BladeRfSampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
mSampleRateCombo = new JComboBox<>();
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(_ ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mSampleRateCombo = new ComboBox<>();
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
BladeRfSampleRate rate = mSampleRateCombo.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading() && rate != null &&
|
||||
applyToTuner("sample rate [" + rate + "]", () -> getTuner().getController().setSampleRate(rate)))
|
||||
{
|
||||
BladeRfSampleRate rate = (BladeRfSampleRate)mSampleRateCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(rate);
|
||||
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting bladeRF sample rate", e1);
|
||||
JOptionPane.showMessageDialog(BladeRfTunerEditor.this, "Couldn't set sample rate to " + rate);
|
||||
}
|
||||
adjustForSampleRate(rate.getRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -263,30 +171,19 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
return mSampleRateCombo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to enable/disable Bias-T power for active antennas
|
||||
*/
|
||||
private JCheckBox getBiasTCheckBox()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTCheckBox = new JCheckBox("Bias-T");
|
||||
mBiasTCheckBox.setEnabled(false);
|
||||
mBiasTCheckBox.setToolTipText("Enable Bias-T power output for active antennas. Also powers the RX2 connector.");
|
||||
mBiasTCheckBox.addActionListener(_ ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas. Also powers the " +
|
||||
"RX2 connector."));
|
||||
mBiasTCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("Bias-T", () -> getTuner().getController().setBiasT(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setBiasT(mBiasTCheckBox.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting Bias-T", e1);
|
||||
JOptionPane.showMessageDialog(mBiasTCheckBox, "Couldn't set Bias-T: " + e1.getMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -294,39 +191,36 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
|
||||
private JComboBox<GainModeInfo> getGainModeCombo()
|
||||
private ComboBox<GainModeInfo> getGainModeCombo()
|
||||
{
|
||||
if(mGainModeCombo == null)
|
||||
{
|
||||
mGainModeCombo = new JComboBox<>();
|
||||
mGainModeCombo.setEnabled(false);
|
||||
mGainModeCombo.setRenderer(new DefaultListCellRenderer()
|
||||
mGainModeCombo = new ComboBox<>();
|
||||
mGainModeCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mGainModeCombo.setDisable(true);
|
||||
mGainModeCombo.setConverter(new StringConverter<>()
|
||||
{
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean selected,
|
||||
boolean focused)
|
||||
public String toString(GainModeInfo mode)
|
||||
{
|
||||
Object label = value instanceof GainModeInfo mode ? mode.name() : value;
|
||||
return super.getListCellRendererComponent(list, label, index, selected, focused);
|
||||
return mode == null ? "" : mode.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GainModeInfo fromString(String text)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
mGainModeCombo.addActionListener(_ ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
GainModeInfo mode = (GainModeInfo)mGainModeCombo.getSelectedItem();
|
||||
mGainModeCombo.setOnAction(e -> {
|
||||
GainModeInfo mode = mGainModeCombo.getValue();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setGainMode(mode.mode());
|
||||
updateGainControls();
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting bladeRF gain mode", e1);
|
||||
JOptionPane.showMessageDialog(mGainModeCombo, "Couldn't set gain mode to " + mode.name());
|
||||
}
|
||||
if(hasTuner() && !isLoading() && mode != null &&
|
||||
applyToTuner("gain mode [" + mode.name() + "]",
|
||||
() -> getTuner().getController().setGainMode(mode.mode())))
|
||||
{
|
||||
updateGainControls();
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -334,107 +228,73 @@ public class BladeRfTunerEditor extends TunerEditor<BladeRfTuner, BladeRfTunerCo
|
||||
return mGainModeCombo;
|
||||
}
|
||||
|
||||
private JSlider getGainSlider()
|
||||
private GainSlider getGainSlider()
|
||||
{
|
||||
if(mGainSlider == null)
|
||||
{
|
||||
mGainSlider = new JSlider(JSlider.HORIZONTAL, 0, 60, BladeRfTunerController.GAIN_DEFAULT);
|
||||
mGainSlider.setEnabled(false);
|
||||
mGainSlider.setMajorTickSpacing(5);
|
||||
mGainSlider.setPaintTicks(true);
|
||||
mGainSlider.addChangeListener(_ ->
|
||||
{
|
||||
int gain = mGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mGainSlider = new GainSlider(0, 60, BladeRfTunerController.GAIN_DEFAULT);
|
||||
mGainSlider.setDisable(true);
|
||||
mGainSlider.setFormatter(value -> value + " dB");
|
||||
mGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("gain", () -> getTuner().getController().setGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set bladeRF gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mGainSlider, "Couldn't set gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
updateGainControls();
|
||||
});
|
||||
}
|
||||
|
||||
return mGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getGainValueLabel()
|
||||
{
|
||||
if(mGainValueLabel == null)
|
||||
{
|
||||
mGainValueLabel = new JLabel("0 dB");
|
||||
mGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mGainValueLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel)getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
BladeRfTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
|
||||
if(getSampleRateCombo().getSelectedItem() instanceof BladeRfSampleRate rate)
|
||||
if(getSampleRateCombo().getValue() instanceof BladeRfSampleRate rate)
|
||||
{
|
||||
getConfiguration().setSampleRate(rate.getRate());
|
||||
config.setSampleRate(rate.getRate());
|
||||
}
|
||||
|
||||
if(getGainModeCombo().getSelectedItem() instanceof GainModeInfo mode)
|
||||
if(getGainModeCombo().getValue() instanceof GainModeInfo mode)
|
||||
{
|
||||
getConfiguration().setGainMode(mode.mode());
|
||||
config.setGainMode(mode.mode());
|
||||
}
|
||||
|
||||
getConfiguration().setGain(getGainSlider().getValue());
|
||||
getConfiguration().setBiasT(getBiasTCheckBox().isSelected());
|
||||
config.setGain(getGainSlider().getValue());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setToolTipText(locked ? "Sample Rate is locked. Disable decoding channels to unlock." :
|
||||
"Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setDisable(!hasStartedTuner() || locked);
|
||||
getSampleRateCombo().setTooltip(new Tooltip(locked ? "Sample rate is locked. Disable decoding channels " +
|
||||
"to unlock." : "Select a sample rate for the tuner"));
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
if(getDiscoveredTuner().getTunerStatus() == TunerStatus.ERROR)
|
||||
if(!hasStartedTuner())
|
||||
{
|
||||
return getDiscoveredTuner().getErrorMessage();
|
||||
return null;
|
||||
}
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
BladeRfDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><h3>bladeRF Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>").append(info.serial()).append("<br>");
|
||||
sb.append("<b>Board: </b>").append(info.board()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(info.firmware()).append("<br>");
|
||||
sb.append("<b>FPGA: </b>").append(info.fpga()).append("<br>");
|
||||
sb.append("<b>USB Speed: </b>").append(info.speed()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
BladeRfDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><h3>bladeRF Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>").append(info.serial()).append("<br>");
|
||||
sb.append("<b>Board: </b>").append(info.board()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(info.firmware()).append("<br>");
|
||||
sb.append("<b>FPGA: </b>").append(info.fpga()).append("<br>");
|
||||
sb.append("<b>USB Speed: </b>").append(info.speed()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -19,7 +19,6 @@
|
||||
package io.github.dsheirer.source.tuner.fcd.proV1;
|
||||
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import io.github.dsheirer.source.tuner.fcd.FCDTuner;
|
||||
import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.LNAEnhance;
|
||||
import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.LNAGain;
|
||||
@@ -27,34 +26,24 @@ import io.github.dsheirer.source.tuner.fcd.proV1.FCD1TunerController.MixerGain;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import java.text.DecimalFormat;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerModel;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Spinner;
|
||||
import javafx.scene.control.SpinnerValueFactory;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
/**
|
||||
* Funcube Dongle Pro tuner editor
|
||||
*/
|
||||
public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(FCD1TunerEditor.class);
|
||||
private JButton mTunerInfoButton;
|
||||
private JComboBox<LNAGain> mLnaGainCombo;
|
||||
private JComboBox<LNAEnhance> mLnaEnhanceCombo;
|
||||
private JComboBox<MixerGain> mMixerGainCombo;
|
||||
private JCheckBox mBiasTCheckBox;
|
||||
private ComboBox<LNAGain> mLnaGainCombo;
|
||||
private ComboBox<LNAEnhance> mLnaEnhanceCombo;
|
||||
private ComboBox<MixerGain> mMixerGainCombo;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
private CorrectionSpinner mCorrectionDCI;
|
||||
private CorrectionSpinner mCorrectionDCQ;
|
||||
private CorrectionSpinner mGainCorrectionSpinner;
|
||||
@@ -63,14 +52,14 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param userPreferences for wide-band recordings
|
||||
* @param tunerManager to save configuration
|
||||
* @param discoveredTuner to control
|
||||
* @param tunerManager for saving tuner configuration
|
||||
* @param discoveredTuner for the optionally usable tuner and controller
|
||||
*/
|
||||
public FCD1TunerEditor(UserPreferences userPreferences, TunerManager tunerManager, DiscoveredTuner discoveredTuner)
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
private FCD1TunerController getController()
|
||||
@@ -95,120 +84,64 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
return FCD1TunerController.MAXIMUM_TUNABLE_FREQUENCY_HZ;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("LNA", getLnaGainCombo());
|
||||
gain.addRow("LNA Enhance", getLnaEnhanceCombo());
|
||||
gain.addRow("Mixer", getMixerGainCombo());
|
||||
|
||||
TunerSection correction = addSection("I/Q Correction");
|
||||
correction.addRow("DC Inphase", getDcCorrectionSpinnerI());
|
||||
correction.addRow("DC Quadrature", getDcCorrectionSpinnerQ());
|
||||
correction.addRow("Gain", getGainCorrectionSpinner());
|
||||
correction.addRow("Phase", getPhaseCorrectionSpinner());
|
||||
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText(getTuner().getPreferredName());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText(getDiscoveredTuner().getId());
|
||||
}
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
|
||||
if(hasTuner() && hasConfiguration())
|
||||
{
|
||||
getMixerGainCombo().setSelectedItem(getConfiguration().getMixerGain());
|
||||
getLnaEnhanceCombo().setSelectedItem(getConfiguration().getLNAEnhance());
|
||||
getLnaGainCombo().setSelectedItem(getConfiguration().getLNAGain());
|
||||
getBiasTCheckBox().setSelected(getConfiguration().isBiasT());
|
||||
getDcCorrectionSpinnerI().setValue(getConfiguration().getInphaseDCCorrection());
|
||||
getDcCorrectionSpinnerQ().setValue(getConfiguration().getQuadratureDCCorrection());
|
||||
getPhaseCorrectionSpinner().setValue(getConfiguration().getGainCorrection());
|
||||
getGainCorrectionSpinner().setValue(getConfiguration().getPhaseCorrection());
|
||||
FCD1TunerConfiguration config = getConfiguration();
|
||||
getMixerGainCombo().setValue(config.getMixerGain());
|
||||
getLnaEnhanceCombo().setValue(config.getLNAEnhance());
|
||||
getLnaGainCombo().setValue(config.getLNAGain());
|
||||
getBiasTCheckBox().setSelected(config.isBiasT());
|
||||
getDcCorrectionSpinnerI().setCorrection(config.getInphaseDCCorrection());
|
||||
getDcCorrectionSpinnerQ().setCorrection(config.getQuadratureDCCorrection());
|
||||
getGainCorrectionSpinner().setCorrection(config.getGainCorrection());
|
||||
getPhaseCorrectionSpinner().setCorrection(config.getPhaseCorrection());
|
||||
}
|
||||
|
||||
getMixerGainCombo().setEnabled(hasTuner());
|
||||
getLnaEnhanceCombo().setEnabled(hasTuner());
|
||||
getLnaGainCombo().setEnabled(hasTuner());
|
||||
getBiasTCheckBox().setEnabled(hasTuner());
|
||||
getDcCorrectionSpinnerI().setEnabled(hasTuner());
|
||||
getDcCorrectionSpinnerQ().setEnabled(hasTuner());
|
||||
getPhaseCorrectionSpinner().setEnabled(hasTuner());
|
||||
getGainCorrectionSpinner().setEnabled(hasTuner());
|
||||
|
||||
setLoading(false);
|
||||
getMixerGainCombo().setDisable(!hasTuner());
|
||||
getLnaEnhanceCombo().setDisable(!hasTuner());
|
||||
getLnaGainCombo().setDisable(!hasTuner());
|
||||
getBiasTCheckBox().setDisable(!hasTuner());
|
||||
getDcCorrectionSpinnerI().setDisable(!hasTuner());
|
||||
getDcCorrectionSpinnerQ().setDisable(!hasTuner());
|
||||
getPhaseCorrectionSpinner().setDisable(!hasTuner());
|
||||
getGainCorrectionSpinner().setDisable(!hasTuner());
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][][][][][][][][grow]"));
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Gain"), "span,align center");
|
||||
add(new JLabel("LNA:"));
|
||||
add(getLnaGainCombo(), "wrap");
|
||||
add(new JLabel("Enhance:"));
|
||||
add(getLnaEnhanceCombo(), "wrap");
|
||||
add(new JLabel("Mixer:"));
|
||||
add(getMixerGainCombo(), "wrap");
|
||||
add(new JLabel(""));
|
||||
add(getBiasTCheckBox(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Correction"), "span,align center");
|
||||
add(new JLabel("DC Inphase:"));
|
||||
add(getDcCorrectionSpinnerI(), "wrap");
|
||||
add(new JLabel("DC Quadrature:"));
|
||||
add(getDcCorrectionSpinnerQ(), "wrap");
|
||||
add(new JLabel("Gain:"));
|
||||
add(getGainCorrectionSpinner(), "wrap");
|
||||
add(new JLabel("Phase:"));
|
||||
add(getPhaseCorrectionSpinner(), "wrap");
|
||||
}
|
||||
|
||||
public JComboBox getLnaGainCombo()
|
||||
private ComboBox<LNAGain> getLnaGainCombo()
|
||||
{
|
||||
if(mLnaGainCombo == null)
|
||||
{
|
||||
mLnaGainCombo = new JComboBox<>(LNAGain.values());
|
||||
mLnaGainCombo.setEnabled(false);
|
||||
mLnaGainCombo.setToolTipText("Adjust the low noise amplifier gain setting.");
|
||||
mLnaGainCombo.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mLnaGainCombo = new ComboBox<>(FXCollections.observableArrayList(LNAGain.values()));
|
||||
mLnaGainCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mLnaGainCombo.setDisable(true);
|
||||
mLnaGainCombo.setTooltip(new Tooltip("Adjust the low noise amplifier gain setting."));
|
||||
mLnaGainCombo.setOnAction(e -> {
|
||||
LNAGain gain = mLnaGainCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && gain != null &&
|
||||
applyToTuner("LNA gain [" + gain + "]", () -> getController().setLNAGain(gain)))
|
||||
{
|
||||
LNAGain gain = (LNAGain) mLnaGainCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getController().setLNAGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCD Pro Tuner " +
|
||||
"Controller - error setting LNA gain [" + gain + "]");
|
||||
|
||||
mLog.error("FuncubeDonglePro Controller - error setting gain [" + gain + "]", e);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -216,30 +149,18 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
return mLnaGainCombo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to enable/disable Bias-T power for active antennas
|
||||
*/
|
||||
public JCheckBox getBiasTCheckBox()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTCheckBox = new JCheckBox("Bias-T");
|
||||
mBiasTCheckBox.setEnabled(false);
|
||||
mBiasTCheckBox.setToolTipText("Enable Bias-T power output for active antennas");
|
||||
mBiasTCheckBox.addActionListener(event ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas"));
|
||||
mBiasTCheckBox.setOnAction(event -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("Bias-T", () -> getController().setBiasT(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getController().setBiasT(mBiasTCheckBox.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("Couldn't set bias-T for FCD Pro", e);
|
||||
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "Couldn't set Bias-T: " + e.getMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -247,31 +168,21 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
|
||||
public JComboBox getLnaEnhanceCombo()
|
||||
private ComboBox<LNAEnhance> getLnaEnhanceCombo()
|
||||
{
|
||||
if(mLnaEnhanceCombo == null)
|
||||
{
|
||||
mLnaEnhanceCombo = new JComboBox<>(LNAEnhance.values());
|
||||
mLnaEnhanceCombo.setEnabled(false);
|
||||
mLnaEnhanceCombo.setToolTipText("Adjust the LNA enhance setting. Default value is OFF");
|
||||
mLnaEnhanceCombo.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mLnaEnhanceCombo = new ComboBox<>(FXCollections.observableArrayList(LNAEnhance.values()));
|
||||
mLnaEnhanceCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mLnaEnhanceCombo.setDisable(true);
|
||||
mLnaEnhanceCombo.setTooltip(new Tooltip("Adjust the LNA enhance setting. Default value is OFF"));
|
||||
mLnaEnhanceCombo.setOnAction(e -> {
|
||||
LNAEnhance enhance = mLnaEnhanceCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && enhance != null &&
|
||||
applyToTuner("LNA enhance [" + enhance + "]", () -> getController().setLNAEnhance(enhance)))
|
||||
{
|
||||
LNAEnhance enhance = (LNAEnhance) mLnaEnhanceCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getController().setLNAEnhance(enhance);
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCD Pro Tuner"
|
||||
+ " error setting LNA enhance gain [" + enhance + "]");
|
||||
|
||||
mLog.error("FCDPro - error setting LNA enhance [" + enhance + "]", e1);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -279,31 +190,21 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
return mLnaEnhanceCombo;
|
||||
}
|
||||
|
||||
public JComboBox getMixerGainCombo()
|
||||
private ComboBox<MixerGain> getMixerGainCombo()
|
||||
{
|
||||
if(mMixerGainCombo == null)
|
||||
{
|
||||
mMixerGainCombo = new JComboBox<>(MixerGain.values());
|
||||
mMixerGainCombo.setEnabled(false);
|
||||
mMixerGainCombo.setToolTipText("Adjust mixer gain setting");
|
||||
mMixerGainCombo.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mMixerGainCombo = new ComboBox<>(FXCollections.observableArrayList(MixerGain.values()));
|
||||
mMixerGainCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mMixerGainCombo.setDisable(true);
|
||||
mMixerGainCombo.setTooltip(new Tooltip("Adjust mixer gain setting"));
|
||||
mMixerGainCombo.setOnAction(e -> {
|
||||
MixerGain gain = mMixerGainCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && gain != null &&
|
||||
applyToTuner("mixer gain [" + gain + "]", () -> getController().setMixerGain(gain)))
|
||||
{
|
||||
MixerGain gain = (MixerGain) mMixerGainCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getController().setMixerGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCDPro - error setting"
|
||||
+ " mixer gain [" + gain + "]");
|
||||
|
||||
mLog.error("FCDPro - error setting mixer gain [" + gain + "]", e1);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -311,102 +212,60 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
return mMixerGainCombo;
|
||||
}
|
||||
|
||||
public CorrectionSpinner getDcCorrectionSpinnerQ()
|
||||
private CorrectionSpinner getDcCorrectionSpinnerQ()
|
||||
{
|
||||
if(mCorrectionDCQ == null)
|
||||
{
|
||||
mCorrectionDCQ = new CorrectionSpinner(Correction.DC_QUADRATURE, 0.0, 0.00001, 5);
|
||||
mCorrectionDCQ.setEnabled(false);
|
||||
mCorrectionDCQ.setToolTipText("DC Bias Correction/Quadrature Component: valid values are -1.0 to 1.0 (default: 0.0)");
|
||||
mCorrectionDCQ = new CorrectionSpinner(Correction.DC_QUADRATURE);
|
||||
mCorrectionDCQ.setTooltip(new Tooltip("DC bias correction, quadrature component: -1.0 to 1.0 (default: 0.0)"));
|
||||
}
|
||||
|
||||
return mCorrectionDCQ;
|
||||
}
|
||||
|
||||
public CorrectionSpinner getDcCorrectionSpinnerI()
|
||||
private CorrectionSpinner getDcCorrectionSpinnerI()
|
||||
{
|
||||
if(mCorrectionDCI == null)
|
||||
{
|
||||
mCorrectionDCI = new CorrectionSpinner(Correction.DC_INPHASE, 0.0, 0.00001, 5);
|
||||
mCorrectionDCI.setEnabled(false);
|
||||
mCorrectionDCI.setToolTipText("DC Bias Correction/Inphase Component: valid values are -1.0 to 1.0 (default: 0.0)");
|
||||
mCorrectionDCI = new CorrectionSpinner(Correction.DC_INPHASE);
|
||||
mCorrectionDCI.setTooltip(new Tooltip("DC bias correction, inphase component: -1.0 to 1.0 (default: 0.0)"));
|
||||
}
|
||||
|
||||
return mCorrectionDCI;
|
||||
}
|
||||
|
||||
public CorrectionSpinner getGainCorrectionSpinner()
|
||||
private CorrectionSpinner getGainCorrectionSpinner()
|
||||
{
|
||||
if(mGainCorrectionSpinner == null)
|
||||
{
|
||||
mGainCorrectionSpinner = new CorrectionSpinner(Correction.GAIN, 0.0, 0.00001, 5);
|
||||
mGainCorrectionSpinner.setEnabled(false);
|
||||
mGainCorrectionSpinner.setToolTipText("Gain Correction: valid values are -1.0 to 1.0 (default: 0.0)");
|
||||
mGainCorrectionSpinner = new CorrectionSpinner(Correction.GAIN);
|
||||
mGainCorrectionSpinner.setTooltip(new Tooltip("Gain correction: -1.0 to 1.0 (default: 0.0)"));
|
||||
}
|
||||
|
||||
return mGainCorrectionSpinner;
|
||||
}
|
||||
|
||||
public CorrectionSpinner getPhaseCorrectionSpinner()
|
||||
private CorrectionSpinner getPhaseCorrectionSpinner()
|
||||
{
|
||||
if(mPhaseCorrectionSpinner == null)
|
||||
{
|
||||
mPhaseCorrectionSpinner = new CorrectionSpinner(Correction.PHASE, 0.0, 0.00001, 5);
|
||||
mPhaseCorrectionSpinner.setEnabled(false);
|
||||
mPhaseCorrectionSpinner.setToolTipText("Phase Correction: valid values are -1.0 to 1.0 (default: 0.0)");
|
||||
mPhaseCorrectionSpinner = new CorrectionSpinner(Correction.PHASE);
|
||||
mPhaseCorrectionSpinner.setTooltip(new Tooltip("Phase correction: -1.0 to 1.0 (default: 0.0)"));
|
||||
}
|
||||
|
||||
return mPhaseCorrectionSpinner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
}
|
||||
|
||||
public JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Tuner Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(FCD1TunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><h3>Funcube Dongle Pro Tuner</h3>");
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
sb.append("<b>USB ID: </b>");
|
||||
sb.append(getController().getUSBID());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>USB Address: </b>");
|
||||
sb.append(getController().getUSBAddress());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>USB Speed: </b>");
|
||||
sb.append(getController().getUSBSpeed());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Cellular Band: </b>");
|
||||
sb.append(getController().getConfiguration().getBandBlocking());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Firmware: </b>");
|
||||
sb.append(getController().getConfiguration().getFirmware());
|
||||
sb.append("<br>");
|
||||
}
|
||||
|
||||
sb.append("<b>USB ID: </b>").append(getController().getUSBID()).append("<br>");
|
||||
sb.append("<b>USB Address: </b>").append(getController().getUSBAddress()).append("<br>");
|
||||
sb.append("<b>USB Speed: </b>").append(getController().getUSBSpeed()).append("<br>");
|
||||
sb.append("<b>Cellular Band: </b>").append(getController().getConfiguration().getBandBlocking()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(getController().getConfiguration().getFirmware()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -415,88 +274,95 @@ public class FCD1TunerEditor extends TunerEditor<FCDTuner,FCD1TunerConfiguration
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setLNAEnhance((LNAEnhance) mLnaEnhanceCombo.getSelectedItem());
|
||||
getConfiguration().setLNAGain((LNAGain) mLnaGainCombo.getSelectedItem());
|
||||
getConfiguration().setMixerGain((MixerGain) mMixerGainCombo.getSelectedItem());
|
||||
getConfiguration().setBiasT(getBiasTCheckBox().isSelected());
|
||||
double dci = ((SpinnerNumberModel)mCorrectionDCI.getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setInphaseDCCorrection(dci);
|
||||
double dcq = ((SpinnerNumberModel)mCorrectionDCQ.getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setQuadratureDCCorrection(dcq);
|
||||
double gain = ((SpinnerNumberModel) mGainCorrectionSpinner.getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setGainCorrection(gain);
|
||||
double phase = ((SpinnerNumberModel) mPhaseCorrectionSpinner.getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setPhaseCorrection(phase);
|
||||
FCD1TunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
config.setLNAEnhance(getLnaEnhanceCombo().getValue());
|
||||
config.setLNAGain(getLnaGainCombo().getValue());
|
||||
config.setMixerGain(getMixerGainCombo().getValue());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
config.setInphaseDCCorrection(getDcCorrectionSpinnerI().getCorrection());
|
||||
config.setQuadratureDCCorrection(getDcCorrectionSpinnerQ().getCorrection());
|
||||
config.setGainCorrection(getGainCorrectionSpinner().getCorrection());
|
||||
config.setPhaseCorrection(getPhaseCorrectionSpinner().getCorrection());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Correction {GAIN, PHASE, DC_INPHASE, DC_QUADRATURE};
|
||||
public enum Correction {GAIN, PHASE, DC_INPHASE, DC_QUADRATURE}
|
||||
|
||||
public class CorrectionSpinner extends JSpinner
|
||||
/**
|
||||
* Spinner for a correction value in the range -1.0 to 1.0 with five decimal places.
|
||||
*/
|
||||
public class CorrectionSpinner extends Spinner<Double>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final double MIN_VALUE = -1.0d;
|
||||
private static final double MAX_VALUE = 1.0d;
|
||||
private final Correction mCorrectionComponent;
|
||||
|
||||
private Correction mCorrectionComponent;
|
||||
|
||||
public CorrectionSpinner(Correction component, double initialValue, double step, int decimalPlaces)
|
||||
public CorrectionSpinner(Correction component)
|
||||
{
|
||||
mCorrectionComponent = component;
|
||||
|
||||
SpinnerModel model = new SpinnerNumberModel(initialValue, MIN_VALUE, MAX_VALUE, step);
|
||||
setModel(model);
|
||||
|
||||
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)getEditor();
|
||||
|
||||
DecimalFormat format = editor.getFormat();
|
||||
format.setMinimumFractionDigits(decimalPlaces);
|
||||
|
||||
editor.getTextField().setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
addChangeListener(e ->
|
||||
SpinnerValueFactory.DoubleSpinnerValueFactory factory =
|
||||
new SpinnerValueFactory.DoubleSpinnerValueFactory(MIN_VALUE, MAX_VALUE, 0.0, 0.00001);
|
||||
factory.setConverter(new StringConverter<>()
|
||||
{
|
||||
if(!isLoading())
|
||||
@Override
|
||||
public String toString(Double value)
|
||||
{
|
||||
double value = ((SpinnerNumberModel)getModel()).getNumber().doubleValue();
|
||||
return value == null ? "" : String.format("%.5f", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double fromString(String text)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch(mCorrectionComponent)
|
||||
{
|
||||
case DC_INPHASE:
|
||||
getController().setDCCorrectionInPhase(value);
|
||||
break;
|
||||
case DC_QUADRATURE:
|
||||
getController().setDCCorrectionQuadrature(value);
|
||||
break;
|
||||
case GAIN:
|
||||
getController().setGainCorrection(value);
|
||||
break;
|
||||
case PHASE:
|
||||
getController().setPhaseCorrection(value);
|
||||
break;
|
||||
}
|
||||
|
||||
save();
|
||||
return Double.parseDouble(text.trim().replace(',', '.'));
|
||||
}
|
||||
catch(Exception e1)
|
||||
catch(Exception e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(FCD1TunerEditor.this, "FCDPro - error "
|
||||
+ "applying " + mCorrectionComponent.toString() + " correction value [" + value + "]");
|
||||
|
||||
mLog.error("FCDPro - error applying " + mCorrectionComponent.toString() + " correction value [" +
|
||||
value + "]", e1);
|
||||
return factory.getValue();
|
||||
}
|
||||
}
|
||||
});
|
||||
setValueFactory(factory);
|
||||
setEditable(true);
|
||||
setDisable(true);
|
||||
setMaxWidth(Double.MAX_VALUE);
|
||||
focusedProperty().addListener((observable, wasFocused, focused) -> {
|
||||
if(!focused)
|
||||
{
|
||||
increment(0);
|
||||
}
|
||||
});
|
||||
valueProperty().addListener((observable, oldValue, value) -> {
|
||||
if(!isLoading() && hasTuner() && value != null &&
|
||||
applyToTuner(mCorrectionComponent + " correction [" + value + "]", () -> apply(value)))
|
||||
{
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void apply(double value) throws Exception
|
||||
{
|
||||
switch(mCorrectionComponent)
|
||||
{
|
||||
case DC_INPHASE -> getController().setDCCorrectionInPhase(value);
|
||||
case DC_QUADRATURE -> getController().setDCCorrectionQuadrature(value);
|
||||
case GAIN -> getController().setGainCorrection(value);
|
||||
case PHASE -> getController().setPhaseCorrection(value);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCorrection(double value)
|
||||
{
|
||||
getValueFactory().setValue(value);
|
||||
}
|
||||
|
||||
public double getCorrection()
|
||||
{
|
||||
return getValue() != null ? getValue() : 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -19,46 +19,38 @@
|
||||
package io.github.dsheirer.source.tuner.fcd.proplusV2;
|
||||
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import io.github.dsheirer.source.tuner.fcd.FCDTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.Tooltip;
|
||||
|
||||
/**
|
||||
* Funcube Dongle Pro Plus tuner editor
|
||||
*/
|
||||
public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguration>
|
||||
{
|
||||
private final static Logger mLog = LoggerFactory.getLogger(FCD2TunerEditor.class);
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JButton mTunerInfoButton;
|
||||
private JCheckBox mLnaGainCheckBox;
|
||||
private JCheckBox mMixerGainCheckBox;
|
||||
private JCheckBox mBiasTCheckBox;
|
||||
private CheckBox mLnaGainCheckBox;
|
||||
private CheckBox mMixerGainCheckBox;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param userPreferences for wide-band recordings
|
||||
* @param tunerManager to save configuration
|
||||
* @param discoveredTuner to control
|
||||
* @param tunerManager for saving tuner configuration
|
||||
* @param discoveredTuner for the optionally usable tuner and controller
|
||||
*/
|
||||
public FCD2TunerEditor(UserPreferences userPreferences, TunerManager tunerManager, DiscoveredTuner discoveredTuner)
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addControl(getLnaGainCheckBox());
|
||||
gain.addControl(getMixerGainCheckBox());
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
refresh();
|
||||
}
|
||||
|
||||
private FCD2TunerController getController()
|
||||
@@ -86,29 +78,9 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText(getTuner().getPreferredName());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText(getDiscoveredTuner().getId());
|
||||
}
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
getLnaGainCheckBox().setEnabled(hasTuner());
|
||||
getMixerGainCheckBox().setEnabled(hasTuner());
|
||||
getBiasTCheckBox().setEnabled(hasTuner());
|
||||
getLnaGainCheckBox().setDisable(!hasTuner());
|
||||
getMixerGainCheckBox().setDisable(!hasTuner());
|
||||
getBiasTCheckBox().setDisable(!hasTuner());
|
||||
|
||||
if(hasTuner() && hasConfiguration())
|
||||
{
|
||||
@@ -116,69 +88,19 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
getMixerGainCheckBox().setSelected(getConfiguration().getGainMixer());
|
||||
getBiasTCheckBox().setSelected(getConfiguration().isBiasT());
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][grow]"));
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
JPanel checkBoxPanel = new JPanel();
|
||||
checkBoxPanel.setLayout(new MigLayout("insets 0", "[left][left][left]", ""));
|
||||
checkBoxPanel.add(getLnaGainCheckBox());
|
||||
checkBoxPanel.add(getMixerGainCheckBox());
|
||||
checkBoxPanel.add(getBiasTCheckBox());
|
||||
add(checkBoxPanel, "span,align left");
|
||||
}
|
||||
|
||||
public JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Tuner Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(FCD2TunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
public JCheckBox getLnaGainCheckBox()
|
||||
private CheckBox getLnaGainCheckBox()
|
||||
{
|
||||
if(mLnaGainCheckBox == null)
|
||||
{
|
||||
mLnaGainCheckBox = new JCheckBox("LNA Gain");
|
||||
mLnaGainCheckBox.setEnabled(false);
|
||||
mLnaGainCheckBox.addActionListener(event ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mLnaGainCheckBox = new CheckBox("LNA gain");
|
||||
mLnaGainCheckBox.setDisable(true);
|
||||
mLnaGainCheckBox.setOnAction(event -> {
|
||||
if(!isLoading() && hasTuner() && applyToTuner("LNA gain",
|
||||
() -> getController().setLNAGain(getLnaGainCheckBox().isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getController().setLNAGain(getLnaGainCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("Couldn't set LNA gain for FCD2", e);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -186,25 +108,17 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
return mLnaGainCheckBox;
|
||||
}
|
||||
|
||||
public JCheckBox getMixerGainCheckBox()
|
||||
private CheckBox getMixerGainCheckBox()
|
||||
{
|
||||
if(mMixerGainCheckBox == null)
|
||||
{
|
||||
mMixerGainCheckBox = new JCheckBox("Mixer Gain");
|
||||
mMixerGainCheckBox.setEnabled(false);
|
||||
mMixerGainCheckBox.addActionListener(event ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mMixerGainCheckBox = new CheckBox("Mixer gain");
|
||||
mMixerGainCheckBox.setDisable(true);
|
||||
mMixerGainCheckBox.setOnAction(event -> {
|
||||
if(!isLoading() && hasTuner() && applyToTuner("mixer gain",
|
||||
() -> getController().setMixerGain(getMixerGainCheckBox().isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getController().setMixerGain(getMixerGainCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("Couldn't set mixer gain for FCD2", e);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,30 +126,18 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
return mMixerGainCheckBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to enable/disable Bias-T power for active antennas
|
||||
*/
|
||||
public JCheckBox getBiasTCheckBox()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTCheckBox = new JCheckBox("Bias-T");
|
||||
mBiasTCheckBox.setEnabled(false);
|
||||
mBiasTCheckBox.setToolTipText("Enable Bias-T power output for active antennas");
|
||||
mBiasTCheckBox.addActionListener(event ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas"));
|
||||
mBiasTCheckBox.setOnAction(event -> {
|
||||
if(hasTuner() && !isLoading() && applyToTuner("Bias-T",
|
||||
() -> getController().setBiasT(getBiasTCheckBox().isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getController().setBiasT(getBiasTCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("Couldn't set bias-T for FCD2", e);
|
||||
JOptionPane.showMessageDialog(mBiasTCheckBox, "Couldn't set Bias-T: " + e.getMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -244,40 +146,15 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("<html><h3>Funcube Dongle Pro Plus Tuner</h3>");
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
sb.append("<b>USB ID: </b>");
|
||||
sb.append(getController().getUSBID());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>USB Address: </b>");
|
||||
sb.append(getController().getUSBAddress());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>USB Speed: </b>");
|
||||
sb.append(getController().getUSBSpeed());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Cellular Band: </b>");
|
||||
sb.append(getController().getConfiguration().getBandBlocking());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Firmware: </b>");
|
||||
sb.append(getController().getConfiguration().getFirmware());
|
||||
sb.append("<br>");
|
||||
}
|
||||
|
||||
sb.append("<b>USB ID: </b>").append(getController().getUSBID()).append("<br>");
|
||||
sb.append("<b>USB Address: </b>").append(getController().getUSBAddress()).append("<br>");
|
||||
sb.append("<b>USB Speed: </b>").append(getController().getUSBSpeed()).append("<br>");
|
||||
sb.append("<b>Cellular Band: </b>").append(getController().getConfiguration().getBandBlocking()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(getController().getConfiguration().getFirmware()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -286,16 +163,12 @@ public class FCD2TunerEditor extends TunerEditor<FCDTuner, FCD2TunerConfiguratio
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setGainLNA(getLnaGainCheckBox().isSelected());
|
||||
getConfiguration().setGainMixer(getMixerGainCheckBox().isSelected());
|
||||
getConfiguration().setBiasT(getBiasTCheckBox().isSelected());
|
||||
FCD2TunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
config.setGainLNA(getLnaGainCheckBox().isSelected());
|
||||
config.setGainMixer(getMixerGainCheckBox().isSelected());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,50 +20,43 @@ package io.github.dsheirer.source.tuner.hackrf;
|
||||
|
||||
import io.github.dsheirer.hackrf.HackRf;
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.SourceException;
|
||||
import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFLNAGain;
|
||||
import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFSampleRate;
|
||||
import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController.HackRFVGAGain;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
|
||||
/**
|
||||
* HackRF Tuner Editor
|
||||
* HackRF tuner editor
|
||||
*/
|
||||
public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfiguration>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(HackRFTunerEditor.class);
|
||||
private JButton mTunerInfo;
|
||||
private JComboBox<HackRFSampleRate> mSampleRateCombo;
|
||||
private JToggleButton mAmplifier;
|
||||
private JToggleButton mBiasT;
|
||||
private JComboBox<HackRFLNAGain> mLnaGainCombo;
|
||||
private JComboBox<HackRFVGAGain> mVgaGainCombo;
|
||||
private ComboBox<HackRFSampleRate> mSampleRateCombo;
|
||||
private CheckBox mAmplifierCheckBox;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
private ComboBox<HackRFLNAGain> mLnaGainCombo;
|
||||
private ComboBox<HackRFVGAGain> mVgaGainCombo;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
* @param userPreferences for wide-band recordings
|
||||
* @param tunerManager to save configuration
|
||||
* @param discoveredTuner to control
|
||||
* @param tunerManager for saving tuner configuration
|
||||
* @param discoveredTuner for the optionally usable HackRF tuner and controller
|
||||
*/
|
||||
public HackRFTunerEditor(UserPreferences userPreferences, TunerManager tunerManager, DiscoveredTuner discoveredTuner)
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,116 +73,55 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][][][grow]"));
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("LNA", getLnaGainCombo());
|
||||
gain.addRow("VGA", getVgaGainCombo());
|
||||
gain.addControl(getAmplifierCheckBox());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
|
||||
add(new JLabel("Gain Control"));
|
||||
add(getAmplifierToggle(), "wrap");
|
||||
|
||||
add(new JLabel("LNA:"));
|
||||
add(getLnaGainCombo(), "wrap");
|
||||
|
||||
add(new JLabel("VGA:"));
|
||||
add(getVgaGainCombo(), "wrap");
|
||||
|
||||
add(new JLabel("Bias-T:"));
|
||||
add(getBiasTToggle(), "wrap");
|
||||
|
||||
//Empty filler row that grows to take up the remaining vertical space
|
||||
add(new JLabel(), "span,grow,push");
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText(getTuner().getPreferredName());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText(getDiscoveredTuner().getId());
|
||||
}
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(hasTuner() && !getTuner().getTunerController().isLockedSampleRate());
|
||||
getSampleRateCombo().setDisable(!hasTuner() || getTuner().getTunerController().isLockedSampleRate());
|
||||
updateSampleRateToolTip();
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
|
||||
getAmplifierToggle().setEnabled(hasTuner());
|
||||
getBiasTToggle().setEnabled(hasTuner());
|
||||
getLnaGainCombo().setEnabled(hasTuner());
|
||||
getVgaGainCombo().setEnabled(hasTuner());
|
||||
getAmplifierCheckBox().setDisable(!hasTuner());
|
||||
getBiasTCheckBox().setDisable(!hasTuner());
|
||||
getLnaGainCombo().setDisable(!hasTuner());
|
||||
getVgaGainCombo().setDisable(!hasTuner());
|
||||
|
||||
if(hasConfiguration())
|
||||
{
|
||||
getSampleRateCombo().setSelectedItem(getConfiguration().getSampleRate());
|
||||
getAmplifierToggle().setSelected(getConfiguration().getAmplifierEnabled());
|
||||
getBiasTToggle().setSelected(getConfiguration().isBiasT());
|
||||
getLnaGainCombo().setSelectedItem(getConfiguration().getLNAGain());
|
||||
getVgaGainCombo().setSelectedItem(getConfiguration().getVGAGain());
|
||||
getSampleRateCombo().setValue(getConfiguration().getSampleRate());
|
||||
getAmplifierCheckBox().setSelected(getConfiguration().getAmplifierEnabled());
|
||||
getBiasTCheckBox().setSelected(getConfiguration().isBiasT());
|
||||
getLnaGainCombo().setValue(getConfiguration().getLNAGain());
|
||||
getVgaGainCombo().setValue(getConfiguration().getVGAGain());
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
private JComboBox getVgaGainCombo()
|
||||
private ComboBox<HackRFVGAGain> getVgaGainCombo()
|
||||
{
|
||||
if(mVgaGainCombo == null)
|
||||
{
|
||||
mVgaGainCombo = new JComboBox<HackRFVGAGain>(HackRFVGAGain.values());
|
||||
mVgaGainCombo.setToolTipText("<html>VGA Gain. Adjust to set the baseband gain</html>");
|
||||
mVgaGainCombo.setEnabled(false);
|
||||
mVgaGainCombo.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mVgaGainCombo = new ComboBox<>(FXCollections.observableArrayList(HackRFVGAGain.values()));
|
||||
mVgaGainCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mVgaGainCombo.setTooltip(new Tooltip("VGA gain. Adjust to set the baseband gain"));
|
||||
mVgaGainCombo.setDisable(true);
|
||||
mVgaGainCombo.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner())
|
||||
{
|
||||
try
|
||||
HackRFVGAGain vgaGain = mVgaGainCombo.getValue() != null ? mVgaGainCombo.getValue() :
|
||||
HackRFVGAGain.GAIN_16;
|
||||
|
||||
if(applyToTuner("VGA gain", () -> getTuner().getController().setVGAGain(vgaGain)))
|
||||
{
|
||||
HackRFVGAGain vgaGain = (HackRFVGAGain) mVgaGainCombo.getSelectedItem();
|
||||
|
||||
if(vgaGain == null)
|
||||
{
|
||||
vgaGain = HackRFVGAGain.GAIN_16;
|
||||
}
|
||||
|
||||
getTuner().getController().setVGAGain(vgaGain);
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
|
||||
+ " - couldn't apply the VGA gain setting - " + e.getLocalizedMessage());
|
||||
|
||||
mLog.error("HackRF Tuner Controller - couldn't apply VGA gain setting", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -197,35 +129,24 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
return mVgaGainCombo;
|
||||
}
|
||||
|
||||
private JComboBox getLnaGainCombo()
|
||||
private ComboBox<HackRFLNAGain> getLnaGainCombo()
|
||||
{
|
||||
if(mLnaGainCombo == null)
|
||||
{
|
||||
mLnaGainCombo = new JComboBox<HackRFLNAGain>(HackRFLNAGain.values());
|
||||
mLnaGainCombo.setToolTipText("<html>LNA Gain. Adjust to set the IF gain</html>");
|
||||
mLnaGainCombo.setEnabled(false);
|
||||
mLnaGainCombo.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mLnaGainCombo = new ComboBox<>(FXCollections.observableArrayList(HackRFLNAGain.values()));
|
||||
mLnaGainCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mLnaGainCombo.setTooltip(new Tooltip("LNA gain. Adjust to set the IF gain"));
|
||||
mLnaGainCombo.setDisable(true);
|
||||
mLnaGainCombo.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner())
|
||||
{
|
||||
try
|
||||
HackRFLNAGain lnaGain = mLnaGainCombo.getValue() != null ? mLnaGainCombo.getValue() :
|
||||
HackRFLNAGain.GAIN_16;
|
||||
|
||||
if(applyToTuner("LNA gain", () -> getTuner().getController().setLNAGain(lnaGain)))
|
||||
{
|
||||
HackRFLNAGain lnaGain = (HackRFLNAGain) mLnaGainCombo.getSelectedItem();
|
||||
|
||||
if(lnaGain == null)
|
||||
{
|
||||
lnaGain = HackRFLNAGain.GAIN_16;
|
||||
}
|
||||
|
||||
getTuner().getController().setLNAGain(lnaGain);
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
|
||||
+ " - couldn't apply the LNA gain setting - " + e.getLocalizedMessage());
|
||||
mLog.error("HackRF Tuner Controller - couldn't apply LNA gain setting - ", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -233,97 +154,61 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
return mLnaGainCombo;
|
||||
}
|
||||
|
||||
private JToggleButton getAmplifierToggle()
|
||||
private CheckBox getAmplifierCheckBox()
|
||||
{
|
||||
if(mAmplifier == null)
|
||||
if(mAmplifierCheckBox == null)
|
||||
{
|
||||
mAmplifier = new JToggleButton("Amplifier");
|
||||
mAmplifier.setToolTipText("Enable or disable the gain amplifier");
|
||||
mAmplifier.setEnabled(false);
|
||||
mAmplifier.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mAmplifierCheckBox = new CheckBox("RF amplifier");
|
||||
mAmplifierCheckBox.setTooltip(new Tooltip("Enable or disable the RF gain amplifier"));
|
||||
mAmplifierCheckBox.setDisable(true);
|
||||
mAmplifierCheckBox.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner() && applyToTuner("amplifier",
|
||||
() -> getTuner().getController().setAmplifierEnabled(mAmplifierCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setAmplifierEnabled(mAmplifier.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("couldn't enable/disable amplifier", e);
|
||||
|
||||
JOptionPane.showMessageDialog(HackRFTunerEditor.this, "Couldn't change amplifier setting",
|
||||
"Error changing amplifier setting", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mAmplifier;
|
||||
return mAmplifierCheckBox;
|
||||
}
|
||||
|
||||
private JToggleButton getBiasTToggle()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasT == null)
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasT = new JToggleButton("Disabled");
|
||||
mBiasT.setToolTipText("Enable or disable Bias-T power (3.3V) on the antenna port for active antennas or LNAs");
|
||||
mBiasT.setEnabled(false);
|
||||
//Item listener also fires for programmatic setSelected() when the configuration loads
|
||||
mBiasT.addItemListener(e -> mBiasT.setText(mBiasT.isSelected() ? "Enabled" : "Disabled"));
|
||||
mBiasT.addActionListener(arg0 ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable or disable Bias-T power (3.3V) on the antenna port for " +
|
||||
"active antennas or LNAs"));
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setOnAction(e -> {
|
||||
if(!isLoading() && hasTuner() && applyToTuner("Bias-T",
|
||||
() -> getTuner().getController().setBiasTEnabled(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setBiasTEnabled(mBiasT.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e)
|
||||
{
|
||||
mLog.error("couldn't enable/disable bias-t", e);
|
||||
|
||||
JOptionPane.showMessageDialog(HackRFTunerEditor.this, "Couldn't change Bias-T setting",
|
||||
"Error changing Bias-T setting", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mBiasT;
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
|
||||
private JComboBox getSampleRateCombo()
|
||||
private ComboBox<HackRFSampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
HackRFSampleRate[] validRates = HackRFSampleRate.VALID_SAMPLE_RATES.toArray(new HackRFSampleRate[0]);
|
||||
mSampleRateCombo = new JComboBox<>(validRates);
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(e ->
|
||||
{
|
||||
if(!isLoading())
|
||||
mSampleRateCombo = new ComboBox<>(FXCollections.observableArrayList(HackRFSampleRate.VALID_SAMPLE_RATES));
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
HackRFSampleRate sampleRate = mSampleRateCombo.getValue();
|
||||
|
||||
if(!isLoading() && hasTuner() && sampleRate != null &&
|
||||
applyToTuner("sample rate [" + sampleRate.getLabel() + "]",
|
||||
() -> getTuner().getController().setSampleRate(sampleRate)))
|
||||
{
|
||||
HackRFSampleRate sampleRate = (HackRFSampleRate)getSampleRateCombo().getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(sampleRate);
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(sampleRate.getRate());
|
||||
save();
|
||||
}
|
||||
catch(SourceException e2)
|
||||
{
|
||||
JOptionPane.showMessageDialog(HackRFTunerEditor.this, "HackRF Tuner Controller"
|
||||
+ " - couldn't apply the sample rate setting [" + sampleRate.getLabel() +
|
||||
"] " + e2.getLocalizedMessage());
|
||||
|
||||
mLog.error("HackRF Tuner Controller - couldn't apply sample rate setting [" +
|
||||
sampleRate.getLabel() + "]", e);
|
||||
}
|
||||
adjustForSampleRate(sampleRate.getRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -331,47 +216,29 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
return mSampleRateCombo;
|
||||
}
|
||||
|
||||
private JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfo == null)
|
||||
{
|
||||
mTunerInfo = new JButton("Tuner Info");
|
||||
mTunerInfo.setToolTipText("Provides details and information about the tuner");
|
||||
mTunerInfo.setEnabled(false);
|
||||
mTunerInfo.addActionListener(e -> JOptionPane.showMessageDialog(HackRFTunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sample rate tooltip according to the tuner controller's lock state.
|
||||
*/
|
||||
private void updateSampleRateToolTip()
|
||||
{
|
||||
if(hasTuner() && getTuner().getController().isLockedSampleRate())
|
||||
{
|
||||
mSampleRateCombo.setToolTipText("Sample Rate is locked. Disable decoding channels to unlock.");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Sample rate is locked. Disable decoding channels to unlock."));
|
||||
}
|
||||
else
|
||||
{
|
||||
mSampleRateCombo.setToolTipText("Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setDisable(!hasTuner() || locked);
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
HackRFTunerController controller = hasTuner() ? getTuner().getController() : null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><h3>HackRF Tuner</h3>");
|
||||
appendInfo(sb, "Board", controller != null ? controller.getBoardName() : null);
|
||||
@@ -391,9 +258,6 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a labeled tuner info value, or Unknown when the value is not available.
|
||||
*/
|
||||
private static void appendInfo(StringBuilder sb, String label, String value)
|
||||
{
|
||||
sb.append("<b>").append(label).append(": </b>").append(value != null ? value : "Unknown").append("<br>");
|
||||
@@ -404,18 +268,14 @@ public class HackRFTunerEditor extends TunerEditor<HackRFTuner,HackRFTunerConfig
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setSampleRate((HackRFSampleRate)getSampleRateCombo().getSelectedItem());
|
||||
getConfiguration().setAmplifierEnabled(getAmplifierToggle().isSelected());
|
||||
getConfiguration().setBiasT(getBiasTToggle().isSelected());
|
||||
getConfiguration().setLNAGain((HackRFLNAGain)getLnaGainCombo().getSelectedItem());
|
||||
getConfiguration().setVGAGain((HackRFVGAGain)getVgaGainCombo().getSelectedItem());
|
||||
HackRFTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
config.setSampleRate(getSampleRateCombo().getValue());
|
||||
config.setAmplifierEnabled(getAmplifierCheckBox().isSelected());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
config.setLNAGain(getLnaGainCombo().getValue());
|
||||
config.setVGAGain(getVgaGainCombo().getValue());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
* 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
|
||||
@@ -23,50 +23,35 @@ import io.github.dsheirer.source.tuner.hydrasdr.HydraSdrTunerController.Gain;
|
||||
import io.github.dsheirer.source.tuner.hydrasdr.HydraSdrTunerController.GainMode;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerStatus;
|
||||
import io.github.dsheirer.source.tuner.ui.GainSlider;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import java.util.List;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.CheckBox;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
/**
|
||||
* HydraSDR tuner editor/controller
|
||||
* HydraSDR tuner editor
|
||||
*/
|
||||
public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTunerConfiguration>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(HydraSdrTunerEditor.class);
|
||||
private JButton mTunerInfoButton;
|
||||
private JComboBox<HydraSdrSampleRate> mSampleRateCombo;
|
||||
private JComboBox<GainMode> mGainModeCombo;
|
||||
private JSlider mMasterGainSlider;
|
||||
private JLabel mMasterGainLabel;
|
||||
private JLabel mMasterGainValueLabel;
|
||||
private JSlider mIFGainSlider;
|
||||
private JLabel mIFGainLabel;
|
||||
private JLabel mIFGainValueLabel;
|
||||
private JSlider mLNAGainSlider;
|
||||
private JLabel mLNAGainValueLabel;
|
||||
private JSlider mMixerGainSlider;
|
||||
private JLabel mMixerGainValueLabel;
|
||||
private JCheckBox mLNAAGCCheckBox;
|
||||
private JCheckBox mMixerAGCCheckBox;
|
||||
private JCheckBox mBiasTCheckBox;
|
||||
private ComboBox<HydraSdrSampleRate> mSampleRateCombo;
|
||||
private ComboBox<GainMode> mGainModeCombo;
|
||||
private GainSlider mMasterGainSlider;
|
||||
private Label mMasterGainLabel;
|
||||
private GainSlider mIFGainSlider;
|
||||
private Label mIFGainLabel;
|
||||
private GainSlider mLNAGainSlider;
|
||||
private Label mLNAGainLabel;
|
||||
private GainSlider mMixerGainSlider;
|
||||
private Label mMixerGainLabel;
|
||||
private CheckBox mLNAAGCCheckBox;
|
||||
private CheckBox mMixerAGCCheckBox;
|
||||
private CheckBox mBiasTCheckBox;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -78,7 +63,7 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,182 +78,62 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
return HydraSdrTunerController.MAXIMUM_TUNABLE_FREQUENCY_HZ;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("Mode", getGainModeCombo());
|
||||
mMasterGainLabel = gain.addRow("Master", getMasterGainSlider(), new Region());
|
||||
mIFGainLabel = gain.addRow("IF", getIFGainSlider(), new Region());
|
||||
mMixerGainLabel = gain.addRow("Mixer", getMixerGainSlider(), getMixerAGCCheckBox());
|
||||
mLNAGainLabel = gain.addRow("LNA", getLNAGainSlider(), getLNAAGCCheckBox());
|
||||
|
||||
TunerSection options = addSection("Options");
|
||||
options.addControl(getBiasTCheckBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
getTunerIdLabel().setText(getTuner().getPreferredName());
|
||||
}
|
||||
else
|
||||
{
|
||||
getTunerIdLabel().setText(getDiscoveredTuner().getId());
|
||||
}
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(hasTuner() && !getTuner().getTunerController().isLockedSampleRate());
|
||||
getTunerInfoButton().setEnabled(hasTuner());
|
||||
getBiasTCheckBox().setEnabled(hasTuner());
|
||||
if(hasTuner() && hasConfiguration())
|
||||
{
|
||||
getBiasTCheckBox().setSelected(getConfiguration().isBiasT());
|
||||
}
|
||||
getSampleRateCombo().setDisable(!hasTuner() || getTuner().getTunerController().isLockedSampleRate());
|
||||
getBiasTCheckBox().setDisable(!hasTuner());
|
||||
getBiasTCheckBox().setSelected(hasTuner() && hasConfiguration() && getConfiguration().isBiasT());
|
||||
updateGainComponents((hasTuner() && hasConfiguration()) ? getConfiguration().getGain() : null);
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
List<HydraSdrSampleRate> rates = getTuner().getController().getSampleRates();
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>(rates.toArray(new HydraSdrSampleRate[rates.size()])));
|
||||
getSampleRateCombo().getItems().setAll(rates);
|
||||
|
||||
if(hasConfiguration())
|
||||
{
|
||||
HydraSdrSampleRate sampleRate = getSampleRate(getConfiguration().getSampleRate());
|
||||
getSampleRateCombo().setSelectedItem(sampleRate);
|
||||
getSampleRateCombo().setValue(getSampleRate(getConfiguration().getSampleRate()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getSampleRateCombo().getItems().clear();
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
|
||||
"[][][][][][][][][][][][][][][][grow]"));
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JLabel());
|
||||
add(getBiasTCheckBox(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx,push");
|
||||
add(new JLabel("Gain Control"), "wrap");
|
||||
|
||||
add(new JLabel("Mode:"));
|
||||
add(getGainModeCombo(), "wrap");
|
||||
|
||||
add(getMasterGainLabel());
|
||||
add(getMasterGainSlider());
|
||||
add(getMasterGainValueLabel());
|
||||
|
||||
add(getIFGainLabel());
|
||||
add(getIFGainSlider());
|
||||
add(getIFGainValueLabel());
|
||||
|
||||
add(getMixerAGCCheckBox());
|
||||
add(getMixerGainSlider());
|
||||
add(getMixerGainValueLabel());
|
||||
|
||||
add(getLNAAGCCheckBox());
|
||||
add(getLNAGainSlider());
|
||||
add(getLNAGainValueLabel());
|
||||
}
|
||||
|
||||
private JCheckBox getLNAAGCCheckBox()
|
||||
{
|
||||
if(mLNAAGCCheckBox == null)
|
||||
{
|
||||
mLNAAGCCheckBox = new JCheckBox("AGC LNA:");
|
||||
mLNAAGCCheckBox.setEnabled(false);
|
||||
mLNAAGCCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
getLNAGainSlider().setEnabled(!getLNAAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting LNA AGC Enabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mLNAAGCCheckBox;
|
||||
}
|
||||
|
||||
private JCheckBox getMixerAGCCheckBox()
|
||||
{
|
||||
if(mMixerAGCCheckBox == null)
|
||||
{
|
||||
mMixerAGCCheckBox = new JCheckBox("AGC Mixer:");
|
||||
mMixerAGCCheckBox.setEnabled(false);
|
||||
mMixerAGCCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
getMixerGainSlider().setEnabled(!getMixerAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting Mixer AGC Enabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mMixerAGCCheckBox;
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to enable/disable Bias-T power for active antennas
|
||||
*/
|
||||
private JCheckBox getBiasTCheckBox()
|
||||
private CheckBox getBiasTCheckBox()
|
||||
{
|
||||
if(mBiasTCheckBox == null)
|
||||
{
|
||||
mBiasTCheckBox = new JCheckBox("Bias-T");
|
||||
mBiasTCheckBox.setEnabled(false);
|
||||
mBiasTCheckBox.setToolTipText("Enable Bias-T power output for active antennas");
|
||||
mBiasTCheckBox.addActionListener(e ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mBiasTCheckBox = new CheckBox("Bias-T");
|
||||
mBiasTCheckBox.setDisable(true);
|
||||
mBiasTCheckBox.setTooltip(new Tooltip("Enable Bias-T power output for active antennas"));
|
||||
mBiasTCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("Bias-T", () -> getTuner().getController().setBiasT(mBiasTCheckBox.isSelected())))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setBiasT(mBiasTCheckBox.isSelected());
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting Bias-T", e1);
|
||||
JOptionPane.showMessageDialog(mBiasTCheckBox, "Couldn't set Bias-T: " + e1.getMessage());
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -276,93 +141,77 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
return mBiasTCheckBox;
|
||||
}
|
||||
|
||||
private JLabel getLNAGainValueLabel()
|
||||
private CheckBox getLNAAGCCheckBox()
|
||||
{
|
||||
if(mLNAGainValueLabel == null)
|
||||
if(mLNAAGCCheckBox == null)
|
||||
{
|
||||
mLNAGainValueLabel = new JLabel("0");
|
||||
mLNAGainValueLabel.setEnabled(false);
|
||||
mLNAAGCCheckBox = new CheckBox("AGC");
|
||||
mLNAAGCCheckBox.setTooltip(new Tooltip("Automatic LNA gain control"));
|
||||
mLNAAGCCheckBox.setDisable(true);
|
||||
mLNAAGCCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() && applyToTuner("LNA AGC",
|
||||
() -> getTuner().getController().setLNAAGC(getLNAAGCCheckBox().isSelected())))
|
||||
{
|
||||
getLNAGainSlider().setDisable(getLNAAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mLNAGainValueLabel;
|
||||
return mLNAAGCCheckBox;
|
||||
}
|
||||
|
||||
private JSlider getLNAGainSlider()
|
||||
private CheckBox getMixerAGCCheckBox()
|
||||
{
|
||||
if(mMixerAGCCheckBox == null)
|
||||
{
|
||||
mMixerAGCCheckBox = new CheckBox("AGC");
|
||||
mMixerAGCCheckBox.setTooltip(new Tooltip("Automatic mixer gain control"));
|
||||
mMixerAGCCheckBox.setDisable(true);
|
||||
mMixerAGCCheckBox.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading() && applyToTuner("mixer AGC",
|
||||
() -> getTuner().getController().setMixerAGC(getMixerAGCCheckBox().isSelected())))
|
||||
{
|
||||
getMixerGainSlider().setDisable(getMixerAGCCheckBox().isSelected());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return mMixerAGCCheckBox;
|
||||
}
|
||||
|
||||
private GainSlider getLNAGainSlider()
|
||||
{
|
||||
if(mLNAGainSlider == null)
|
||||
{
|
||||
mLNAGainSlider = new JSlider(JSlider.HORIZONTAL, HydraSdrTunerController.LNA_GAIN_MIN,
|
||||
HydraSdrTunerController.LNA_GAIN_MAX, HydraSdrTunerController.LNA_GAIN_MIN);
|
||||
mLNAGainSlider.setEnabled(false);
|
||||
mLNAGainSlider.setMajorTickSpacing(1);
|
||||
mLNAGainSlider.setPaintTicks(true);
|
||||
mLNAGainSlider.addChangeListener(event ->
|
||||
{
|
||||
int gain = mLNAGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mLNAGainSlider = new GainSlider(HydraSdrTunerController.LNA_GAIN_MIN, HydraSdrTunerController.LNA_GAIN_MAX,
|
||||
HydraSdrTunerController.LNA_GAIN_MIN);
|
||||
mLNAGainSlider.setDisable(true);
|
||||
mLNAGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("LNA gain", () -> getTuner().getController().setLNAGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setLNAGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set HydraSDR LNA gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mLNAGainSlider, "Couldn't set LNA gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getLNAGainValueLabel().setText(String.valueOf(gain));
|
||||
});
|
||||
}
|
||||
|
||||
return mLNAGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getMixerGainValueLabel()
|
||||
{
|
||||
if(mMixerGainValueLabel == null)
|
||||
{
|
||||
mMixerGainValueLabel = new JLabel("0");
|
||||
mMixerGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mMixerGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getMixerGainSlider()
|
||||
private GainSlider getMixerGainSlider()
|
||||
{
|
||||
if(mMixerGainSlider == null)
|
||||
{
|
||||
mMixerGainSlider = new JSlider(JSlider.HORIZONTAL, HydraSdrTunerController.MIXER_GAIN_MIN,
|
||||
mMixerGainSlider = new GainSlider(HydraSdrTunerController.MIXER_GAIN_MIN,
|
||||
HydraSdrTunerController.MIXER_GAIN_MAX, HydraSdrTunerController.MIXER_GAIN_MIN);
|
||||
mMixerGainSlider.setEnabled(false);
|
||||
mMixerGainSlider.setMajorTickSpacing(1);
|
||||
mMixerGainSlider.setPaintTicks(true);
|
||||
mMixerGainSlider.addChangeListener(new ChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent event)
|
||||
mMixerGainSlider.setDisable(true);
|
||||
mMixerGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("mixer gain", () -> getTuner().getController().setMixerGain(gain)))
|
||||
{
|
||||
int gain = mMixerGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setMixerGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set HydraSDR Mixer gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mMixerGainSlider, "Couldn't set Mixer gain value to " + gain);
|
||||
}
|
||||
}
|
||||
|
||||
getMixerGainValueLabel().setText(String.valueOf(gain));
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -370,134 +219,77 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
return mMixerGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getIFGainLabel()
|
||||
{
|
||||
if(mIFGainLabel == null)
|
||||
{
|
||||
mIFGainLabel = new JLabel("IF:");
|
||||
}
|
||||
|
||||
return mIFGainLabel;
|
||||
}
|
||||
|
||||
private JLabel getIFGainValueLabel()
|
||||
{
|
||||
if(mIFGainValueLabel == null)
|
||||
{
|
||||
mIFGainValueLabel = new JLabel("0");
|
||||
mIFGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mIFGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getIFGainSlider()
|
||||
private GainSlider getIFGainSlider()
|
||||
{
|
||||
if(mIFGainSlider == null)
|
||||
{
|
||||
mIFGainSlider = new JSlider(JSlider.HORIZONTAL, HydraSdrTunerController.IF_GAIN_MIN,
|
||||
HydraSdrTunerController.IF_GAIN_MAX, HydraSdrTunerController.IF_GAIN_MIN);
|
||||
mIFGainSlider.setEnabled(false);
|
||||
mIFGainSlider.setMajorTickSpacing(1);
|
||||
mIFGainSlider.setPaintTicks(true);
|
||||
mIFGainSlider.addChangeListener(event ->
|
||||
{
|
||||
int gain = mIFGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mIFGainSlider = new GainSlider(HydraSdrTunerController.IF_GAIN_MIN, HydraSdrTunerController.IF_GAIN_MAX,
|
||||
HydraSdrTunerController.IF_GAIN_MIN);
|
||||
mIFGainSlider.setDisable(true);
|
||||
mIFGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("IF gain", () -> getTuner().getController().setIFGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setIFGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set HydraSDR IF gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mIFGainSlider, "Couldn't set IF gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getIFGainValueLabel().setText(String.valueOf(gain));
|
||||
});
|
||||
}
|
||||
|
||||
return mIFGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getMasterGainLabel()
|
||||
{
|
||||
if(mMasterGainLabel == null)
|
||||
{
|
||||
mMasterGainLabel = new JLabel("Master:");
|
||||
}
|
||||
|
||||
return mMasterGainLabel;
|
||||
}
|
||||
|
||||
private JLabel getMasterGainValueLabel()
|
||||
{
|
||||
if(mMasterGainValueLabel == null)
|
||||
{
|
||||
mMasterGainValueLabel = new JLabel("0");
|
||||
mMasterGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mMasterGainValueLabel;
|
||||
}
|
||||
|
||||
private JSlider getMasterGainSlider()
|
||||
private GainSlider getMasterGainSlider()
|
||||
{
|
||||
if(mMasterGainSlider == null)
|
||||
{
|
||||
mMasterGainSlider = new JSlider(JSlider.HORIZONTAL, HydraSdrTunerController.GAIN_MIN,
|
||||
HydraSdrTunerController.GAIN_MAX, HydraSdrTunerController.GAIN_MIN);
|
||||
mMasterGainSlider.setEnabled(false);
|
||||
mMasterGainSlider.setMajorTickSpacing(1);
|
||||
mMasterGainSlider.setPaintTicks(true);
|
||||
mMasterGainSlider = new GainSlider(HydraSdrTunerController.GAIN_MIN, HydraSdrTunerController.GAIN_MAX,
|
||||
HydraSdrTunerController.GAIN_MIN);
|
||||
mMasterGainSlider.setDisable(true);
|
||||
mMasterGainSlider.setOnChange(value -> {
|
||||
Gain gain = Gain.getGain(getGainModeCombo().getValue(), value);
|
||||
|
||||
mMasterGainSlider.addChangeListener(event ->
|
||||
{
|
||||
GainMode mode = (GainMode)mGainModeCombo.getSelectedItem();
|
||||
int value = mMasterGainSlider.getValue();
|
||||
Gain gain = Gain.getGain(mode, value);
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
if(hasTuner() && !isLoading() && applyToTuner("gain", () -> getTuner().getController().setGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set HydraSDR gain to:" + gain.name(), e);
|
||||
JOptionPane.showMessageDialog(mMasterGainSlider, "Couldn't set gain value to " +
|
||||
gain.getValue());
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
getMasterGainValueLabel().setText(String.valueOf(value));
|
||||
});
|
||||
}
|
||||
|
||||
return mMasterGainSlider;
|
||||
}
|
||||
|
||||
private JComboBox<GainMode> getGainModeCombo()
|
||||
private ComboBox<GainMode> getGainModeCombo()
|
||||
{
|
||||
if(mGainModeCombo == null)
|
||||
{
|
||||
mGainModeCombo = new JComboBox<>(GainMode.values());
|
||||
mGainModeCombo.setEnabled(false);
|
||||
mGainModeCombo.addActionListener(e ->
|
||||
{
|
||||
mGainModeCombo = new ComboBox<>(FXCollections.observableArrayList(GainMode.values()));
|
||||
mGainModeCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mGainModeCombo.setDisable(true);
|
||||
mGainModeCombo.setTooltip(new Tooltip("Linearity and sensitivity modes set all gains from the master " +
|
||||
"gain. Custom mode sets each gain separately."));
|
||||
mGainModeCombo.setOnAction(e -> {
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
GainMode mode = (GainMode)mGainModeCombo.getSelectedItem();
|
||||
int value = getMasterGainSlider().getValue();
|
||||
Gain gain = Gain.getGain(mode, value);
|
||||
Gain gain = Gain.getGain(mGainModeCombo.getValue(), getMasterGainSlider().getValue());
|
||||
setLoading(true);
|
||||
updateGainComponents(gain);
|
||||
setLoading(false);
|
||||
applyToTuner("gain mode", () -> {
|
||||
HydraSdrTunerController controller = getTuner().getController();
|
||||
|
||||
if(gain == Gain.CUSTOM)
|
||||
{
|
||||
controller.setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
controller.setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
controller.setIFGain(getIFGainSlider().getValue());
|
||||
controller.setMixerGain(getMixerGainSlider().getValue());
|
||||
controller.setLNAGain(getLNAGainSlider().getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.setGain(gain);
|
||||
}
|
||||
});
|
||||
save();
|
||||
}
|
||||
});
|
||||
@@ -506,37 +298,23 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
return mGainModeCombo;
|
||||
}
|
||||
|
||||
private JComboBox<HydraSdrSampleRate> getSampleRateCombo()
|
||||
private ComboBox<HydraSdrSampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
mSampleRateCombo = new JComboBox<>();
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e)
|
||||
mSampleRateCombo = new ComboBox<>();
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
HydraSdrSampleRate rate = mSampleRateCombo.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading() && rate != null &&
|
||||
applyToTuner("sample rate [" + rate.getLabel() + "]",
|
||||
() -> getTuner().getController().setSampleRate(rate)))
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
HydraSdrSampleRate rate = (HydraSdrSampleRate)mSampleRateCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(rate);
|
||||
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(HydraSdrTunerEditor.this,
|
||||
"Couldn't set sample rate to " + rate.getLabel());
|
||||
mLog.error("Error setting HydraSDR sample rate", e1);
|
||||
}
|
||||
}
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -545,48 +323,29 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
}
|
||||
|
||||
/**
|
||||
* Hyperlink button that provides tuner information
|
||||
*/
|
||||
private JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(HydraSdrTunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the enabled state of each of the gain controls according to the
|
||||
* specified gain mode. The master gain control is enabled for linearity
|
||||
* and sensitivity and the individual gain controls are disabled, and
|
||||
* vice-versa for custom mode.
|
||||
* Updates the enabled state of each of the gain controls according to the specified gain mode. The master gain
|
||||
* control is enabled for linearity and sensitivity and the individual gain controls are disabled, and vice-versa
|
||||
* for custom mode.
|
||||
*/
|
||||
private void updateGainComponents(Gain gain)
|
||||
{
|
||||
if(hasTuner() && gain != null)
|
||||
{
|
||||
boolean isCustom = gain.equals(Gain.CUSTOM);
|
||||
|
||||
getGainModeCombo().setEnabled(true);
|
||||
getGainModeCombo().setSelectedItem(gain.getGainMode());
|
||||
getMasterGainLabel().setEnabled(!isCustom);
|
||||
getMasterGainSlider().setEnabled(!isCustom);
|
||||
getGainModeCombo().setDisable(false);
|
||||
getGainModeCombo().setValue(gain.getGainMode());
|
||||
mMasterGainLabel.setDisable(isCustom);
|
||||
getMasterGainSlider().setDisable(isCustom);
|
||||
getMasterGainSlider().setValue(gain.getValue());
|
||||
getMasterGainValueLabel().setEnabled(!isCustom);
|
||||
getIFGainLabel().setEnabled(isCustom);
|
||||
getIFGainSlider().setEnabled(isCustom);
|
||||
getIFGainValueLabel().setEnabled(isCustom);
|
||||
getLNAAGCCheckBox().setEnabled(isCustom);
|
||||
getLNAGainSlider().setEnabled(isCustom && !getConfiguration().isLNAAGC());
|
||||
getLNAGainValueLabel().setEnabled(isCustom);
|
||||
getMixerAGCCheckBox().setEnabled(isCustom);
|
||||
getMixerGainSlider().setEnabled(isCustom && !getConfiguration().isMixerAGC());
|
||||
getMixerGainValueLabel().setEnabled(isCustom);
|
||||
mIFGainLabel.setDisable(!isCustom);
|
||||
getIFGainSlider().setDisable(!isCustom);
|
||||
mLNAGainLabel.setDisable(!isCustom);
|
||||
getLNAAGCCheckBox().setDisable(!isCustom);
|
||||
getLNAGainSlider().setDisable(!isCustom || getConfiguration().isLNAAGC());
|
||||
mMixerGainLabel.setDisable(!isCustom);
|
||||
getMixerAGCCheckBox().setDisable(!isCustom);
|
||||
getMixerGainSlider().setDisable(!isCustom || getConfiguration().isMixerAGC());
|
||||
|
||||
if(isCustom)
|
||||
{
|
||||
getIFGainSlider().setValue(getConfiguration().getIFGain());
|
||||
@@ -606,25 +365,23 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
}
|
||||
else
|
||||
{
|
||||
getGainModeCombo().setEnabled(false);
|
||||
getMasterGainLabel().setEnabled(false);
|
||||
getMasterGainSlider().setEnabled(false);
|
||||
getGainModeCombo().setDisable(true);
|
||||
mMasterGainLabel.setDisable(true);
|
||||
getMasterGainSlider().setDisable(true);
|
||||
getMasterGainSlider().setValue(0);
|
||||
getMasterGainValueLabel().setEnabled(false);
|
||||
getIFGainLabel().setEnabled(false);
|
||||
getIFGainSlider().setEnabled(false);
|
||||
mIFGainLabel.setDisable(true);
|
||||
getIFGainSlider().setDisable(true);
|
||||
getIFGainSlider().setValue(0);
|
||||
getIFGainValueLabel().setEnabled(false);
|
||||
getLNAAGCCheckBox().setEnabled(false);
|
||||
mLNAGainLabel.setDisable(true);
|
||||
getLNAAGCCheckBox().setDisable(true);
|
||||
getLNAAGCCheckBox().setSelected(false);
|
||||
getLNAGainSlider().setEnabled(false);
|
||||
getLNAGainSlider().setDisable(true);
|
||||
getLNAGainSlider().setValue(0);
|
||||
getLNAGainValueLabel().setEnabled(false);
|
||||
getMixerAGCCheckBox().setEnabled(false);
|
||||
mMixerGainLabel.setDisable(true);
|
||||
getMixerAGCCheckBox().setDisable(true);
|
||||
getMixerAGCCheckBox().setSelected(false);
|
||||
getMixerGainSlider().setEnabled(false);
|
||||
getMixerGainSlider().setDisable(true);
|
||||
getMixerGainSlider().setValue(0);
|
||||
getMixerGainValueLabel().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,21 +390,21 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel) getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
getConfiguration().setSampleRate(((HydraSdrSampleRate)getSampleRateCombo().getSelectedItem()).getRate());
|
||||
Gain gain = Gain.getGain((GainMode)mGainModeCombo.getSelectedItem(), getMasterGainSlider().getValue());
|
||||
getConfiguration().setGain(gain);
|
||||
getConfiguration().setIFGain(getIFGainSlider().getValue());
|
||||
getConfiguration().setMixerGain(getMixerGainSlider().getValue());
|
||||
getConfiguration().setLNAGain(getLNAGainSlider().getValue());
|
||||
getConfiguration().setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
getConfiguration().setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
getConfiguration().setBiasT(getBiasTCheckBox().isSelected());
|
||||
HydraSdrTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
|
||||
if(getSampleRateCombo().getValue() != null)
|
||||
{
|
||||
config.setSampleRate(getSampleRateCombo().getValue().getRate());
|
||||
}
|
||||
|
||||
config.setGain(Gain.getGain(getGainModeCombo().getValue(), getMasterGainSlider().getValue()));
|
||||
config.setIFGain(getIFGainSlider().getValue());
|
||||
config.setMixerGain(getMixerGainSlider().getValue());
|
||||
config.setLNAGain(getLNAGainSlider().getValue());
|
||||
config.setMixerAGC(getMixerAGCCheckBox().isSelected());
|
||||
config.setLNAAGC(getLNAAGCCheckBox().isSelected());
|
||||
config.setBiasT(getBiasTCheckBox().isSelected());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -671,7 +428,7 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
}
|
||||
}
|
||||
|
||||
if(rates.size() > 0)
|
||||
if(!rates.isEmpty())
|
||||
{
|
||||
return rates.get(0);
|
||||
}
|
||||
@@ -687,55 +444,31 @@ public class HydraSdrTunerEditor extends TunerEditor<HydraSdrTuner, HydraSdrTune
|
||||
{
|
||||
if(hasTuner() && getTuner().getController().isLockedSampleRate())
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Sample Rate is locked. Disable decoding channels to unlock.");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Sample rate is locked. Disable decoding channels to unlock."));
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setToolTipText("Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setDisable(!hasTuner() || locked);
|
||||
updateSampleRateToolTip();
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
if(getDiscoveredTuner().getTunerStatus() == TunerStatus.ERROR)
|
||||
{
|
||||
return getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
HydraSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
|
||||
sb.append("<html><h3>HydraSDR Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>");
|
||||
sb.append(info.getSerialNumber());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Firmware: </b>");
|
||||
sb.append(info.getVersion());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Part: </b>");
|
||||
sb.append(info.getPartNumber());
|
||||
sb.append("<br>");
|
||||
|
||||
sb.append("<b>Board: </b>");
|
||||
sb.append(info.getBoardName());
|
||||
sb.append("<br>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
HydraSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
sb.append("<html><h3>HydraSDR Tuner</h3>");
|
||||
sb.append("<b>Serial: </b>").append(info.getSerialNumber()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(info.getVersion()).append("<br>");
|
||||
sb.append("<b>Part: </b>").append(info.getPartNumber()).append("<br>");
|
||||
sb.append("<b>Board: </b>").append(info.getBoardName()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,42 +16,25 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.source.tuner.limesdr;
|
||||
|
||||
import io.github.dsheirer.preference.UserPreferences;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerManager;
|
||||
import io.github.dsheirer.source.tuner.manager.TunerStatus;
|
||||
import io.github.dsheirer.source.tuner.ui.GainSlider;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerEditor;
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
import io.github.dsheirer.source.tuner.ui.TunerSection;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Tooltip;
|
||||
|
||||
/**
|
||||
* LimeSDR tuner editor
|
||||
*/
|
||||
public class LimeSdrTunerEditor extends TunerEditor<LimeSdrTuner, LimeSdrTunerConfiguration>
|
||||
{
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger mLog = LoggerFactory.getLogger(LimeSdrTunerEditor.class);
|
||||
private JButton mTunerInfoButton;
|
||||
private JComboBox<LimeSdrSampleRate> mSampleRateCombo;
|
||||
private JComboBox<String> mAntennaCombo;
|
||||
private JSlider mGainSlider;
|
||||
private JLabel mGainValueLabel;
|
||||
private ComboBox<LimeSdrSampleRate> mSampleRateCombo;
|
||||
private ComboBox<String> mAntennaCombo;
|
||||
private GainSlider mGainSlider;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
@@ -63,7 +46,7 @@ public class LimeSdrTunerEditor extends TunerEditor<LimeSdrTuner, LimeSdrTunerCo
|
||||
{
|
||||
super(userPreferences, tunerManager, discoveredTuner);
|
||||
init();
|
||||
tunerStatusUpdated();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,142 +65,62 @@ public class LimeSdrTunerEditor extends TunerEditor<LimeSdrTuner, LimeSdrTunerCo
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]", "[][][][][][][][][][][grow]"));
|
||||
getTuningSection().addRow("Sample Rate", getSampleRateCombo());
|
||||
getTuningSection().addRow("Antenna", getAntennaCombo());
|
||||
|
||||
add(new JLabel("Tuner:"));
|
||||
add(getTunerIdLabel());
|
||||
add(getTunerInfoButton());
|
||||
|
||||
add(new JLabel("Status:"));
|
||||
add(getTunerStatusLabel(), "wrap");
|
||||
|
||||
add(getButtonPanel(), "span,align left");
|
||||
|
||||
add(new JSeparator(), "span,growx");
|
||||
|
||||
add(new JLabel("Frequency (MHz):"));
|
||||
add(getFrequencyPanel(), "wrap");
|
||||
|
||||
add(new JLabel("Sample Rate:"));
|
||||
add(getSampleRateCombo(), "wrap");
|
||||
|
||||
add(new JLabel("Antenna:"));
|
||||
add(getAntennaCombo(), "wrap");
|
||||
|
||||
add(new JSeparator(), "span,growx");
|
||||
|
||||
add(new JLabel("Gain:"));
|
||||
add(getGainSlider());
|
||||
add(getGainValueLabel());
|
||||
|
||||
//Empty row that takes all extra vertical space so that the controls stay stacked at the top of the editor.
|
||||
add(new JLabel(), "span,pushy");
|
||||
TunerSection gain = addSection("Gain");
|
||||
gain.addRow("Gain", getGainSlider());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tunerStatusUpdated()
|
||||
{
|
||||
setLoading(true);
|
||||
|
||||
boolean started = hasStartedTuner();
|
||||
getTunerIdLabel().setText(started ? getTuner().getPreferredName() : getDiscoveredTuner().getId());
|
||||
|
||||
String status = getDiscoveredTuner().getTunerStatus().toString();
|
||||
if(getDiscoveredTuner().hasErrorMessage())
|
||||
{
|
||||
status += " - " + getDiscoveredTuner().getErrorMessage();
|
||||
}
|
||||
getTunerStatusLabel().setText(status);
|
||||
getButtonPanel().updateControls();
|
||||
getFrequencyPanel().updateControls();
|
||||
getTunerInfoButton().setEnabled(started);
|
||||
|
||||
if(started)
|
||||
if(hasStartedTuner())
|
||||
{
|
||||
LimeSdrTunerController controller = getTuner().getController();
|
||||
List<LimeSdrSampleRate> rates = controller.getSampleRates();
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>(rates.toArray(new LimeSdrSampleRate[0])));
|
||||
getSampleRateCombo().setSelectedItem(controller.getLimeSdrSampleRate());
|
||||
getSampleRateCombo().setEnabled(!controller.isLockedSampleRate());
|
||||
|
||||
List<String> antennas = controller.getAntennas();
|
||||
getAntennaCombo().setModel(new DefaultComboBoxModel<>(antennas.toArray(new String[0])));
|
||||
getAntennaCombo().setSelectedItem(controller.getAntenna());
|
||||
getAntennaCombo().setEnabled(true);
|
||||
|
||||
getSampleRateCombo().getItems().setAll(controller.getSampleRates());
|
||||
getSampleRateCombo().setValue(controller.getLimeSdrSampleRate());
|
||||
getSampleRateCombo().setDisable(controller.isLockedSampleRate());
|
||||
getAntennaCombo().getItems().setAll(controller.getAntennas());
|
||||
getAntennaCombo().setValue(controller.getAntenna());
|
||||
getAntennaCombo().setDisable(false);
|
||||
getGainSlider().setValue(controller.getGain());
|
||||
getGainSlider().setEnabled(true);
|
||||
getGainValueLabel().setEnabled(true);
|
||||
getGainSlider().setDisable(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
getSampleRateCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getSampleRateCombo().setEnabled(false);
|
||||
getAntennaCombo().setModel(new DefaultComboBoxModel<>());
|
||||
getAntennaCombo().setEnabled(false);
|
||||
getGainSlider().setEnabled(false);
|
||||
getGainValueLabel().setEnabled(false);
|
||||
getSampleRateCombo().getItems().clear();
|
||||
getSampleRateCombo().setDisable(true);
|
||||
getAntennaCombo().getItems().clear();
|
||||
getAntennaCombo().setDisable(true);
|
||||
getGainSlider().setDisable(true);
|
||||
}
|
||||
|
||||
updateGainLabel();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the tuner has finished starting, since a status update can arrive while it's starting or restarting.
|
||||
* Indicates if the tuner is started, which is when the controller knows the selected antenna.
|
||||
*/
|
||||
private boolean hasStartedTuner()
|
||||
{
|
||||
return hasTuner() && getTuner().getController().getAntenna() != null;
|
||||
}
|
||||
|
||||
private void updateGainLabel()
|
||||
{
|
||||
getGainValueLabel().setText(getGainSlider().getValue() + " dB");
|
||||
}
|
||||
|
||||
/**
|
||||
* Button that provides tuner information
|
||||
*/
|
||||
private JButton getTunerInfoButton()
|
||||
{
|
||||
if(mTunerInfoButton == null)
|
||||
{
|
||||
mTunerInfoButton = new JButton("Info");
|
||||
mTunerInfoButton.setEnabled(false);
|
||||
mTunerInfoButton.addActionListener(_ -> JOptionPane.showMessageDialog(LimeSdrTunerEditor.this,
|
||||
getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
|
||||
}
|
||||
|
||||
return mTunerInfoButton;
|
||||
}
|
||||
|
||||
private JComboBox<LimeSdrSampleRate> getSampleRateCombo()
|
||||
private ComboBox<LimeSdrSampleRate> getSampleRateCombo()
|
||||
{
|
||||
if(mSampleRateCombo == null)
|
||||
{
|
||||
mSampleRateCombo = new JComboBox<>();
|
||||
mSampleRateCombo.setEnabled(false);
|
||||
mSampleRateCombo.addActionListener(_ ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
mSampleRateCombo = new ComboBox<>();
|
||||
mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mSampleRateCombo.setDisable(true);
|
||||
mSampleRateCombo.setTooltip(new Tooltip("Select a sample rate for the tuner"));
|
||||
mSampleRateCombo.setOnAction(e -> {
|
||||
LimeSdrSampleRate rate = mSampleRateCombo.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading() && rate != null &&
|
||||
applyToTuner("sample rate [" + rate + "]", () -> getTuner().getController().setSampleRate(rate)))
|
||||
{
|
||||
LimeSdrSampleRate rate = (LimeSdrSampleRate)mSampleRateCombo.getSelectedItem();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setSampleRate(rate);
|
||||
|
||||
//Adjust the min/max values for the sample rate.
|
||||
adjustForSampleRate(rate.getRate());
|
||||
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting LimeSDR sample rate", e1);
|
||||
JOptionPane.showMessageDialog(LimeSdrTunerEditor.this, "Couldn't set sample rate to " + rate);
|
||||
}
|
||||
adjustForSampleRate(rate.getRate());
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -225,29 +128,21 @@ public class LimeSdrTunerEditor extends TunerEditor<LimeSdrTuner, LimeSdrTunerCo
|
||||
return mSampleRateCombo;
|
||||
}
|
||||
|
||||
private JComboBox<String> getAntennaCombo()
|
||||
private ComboBox<String> getAntennaCombo()
|
||||
{
|
||||
if(mAntennaCombo == null)
|
||||
{
|
||||
mAntennaCombo = new JComboBox<>();
|
||||
mAntennaCombo.setEnabled(false);
|
||||
mAntennaCombo.setToolTipText("Receive port: LNAW wideband (default), LNAL low band, LNAH high band");
|
||||
mAntennaCombo.addActionListener(_ ->
|
||||
{
|
||||
if(hasTuner() && !isLoading())
|
||||
{
|
||||
String antenna = (String)mAntennaCombo.getSelectedItem();
|
||||
mAntennaCombo = new ComboBox<>();
|
||||
mAntennaCombo.setMaxWidth(Double.MAX_VALUE);
|
||||
mAntennaCombo.setDisable(true);
|
||||
mAntennaCombo.setTooltip(new Tooltip("Receive port: LNAW wideband (default), LNAL low band, LNAH high band"));
|
||||
mAntennaCombo.setOnAction(e -> {
|
||||
String antenna = mAntennaCombo.getValue();
|
||||
|
||||
try
|
||||
{
|
||||
getTuner().getController().setAntenna(antenna);
|
||||
save();
|
||||
}
|
||||
catch(Exception e1)
|
||||
{
|
||||
mLog.error("Error setting LimeSDR antenna", e1);
|
||||
JOptionPane.showMessageDialog(mAntennaCombo, "Couldn't set antenna to " + antenna);
|
||||
}
|
||||
if(hasTuner() && !isLoading() && antenna != null &&
|
||||
applyToTuner("antenna [" + antenna + "]", () -> getTuner().getController().setAntenna(antenna)))
|
||||
{
|
||||
save();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -255,109 +150,75 @@ public class LimeSdrTunerEditor extends TunerEditor<LimeSdrTuner, LimeSdrTunerCo
|
||||
return mAntennaCombo;
|
||||
}
|
||||
|
||||
private JSlider getGainSlider()
|
||||
private GainSlider getGainSlider()
|
||||
{
|
||||
if(mGainSlider == null)
|
||||
{
|
||||
mGainSlider = new JSlider(JSlider.HORIZONTAL, LimeSdrTunerController.GAIN_MINIMUM,
|
||||
LimeSdrTunerController.GAIN_MAXIMUM, LimeSdrTunerController.GAIN_DEFAULT);
|
||||
mGainSlider.setEnabled(false);
|
||||
mGainSlider.setMajorTickSpacing(5);
|
||||
mGainSlider.setPaintTicks(true);
|
||||
mGainSlider.addChangeListener(_ ->
|
||||
{
|
||||
int gain = mGainSlider.getValue();
|
||||
|
||||
if(hasTuner() && !isLoading())
|
||||
mGainSlider = new GainSlider(LimeSdrTunerController.GAIN_MINIMUM, LimeSdrTunerController.GAIN_MAXIMUM,
|
||||
LimeSdrTunerController.GAIN_DEFAULT);
|
||||
mGainSlider.setDisable(true);
|
||||
mGainSlider.setFormatter(value -> value + " dB");
|
||||
mGainSlider.setOnChange(gain -> {
|
||||
if(hasTuner() && !isLoading() &&
|
||||
applyToTuner("gain", () -> getTuner().getController().setGain(gain)))
|
||||
{
|
||||
try
|
||||
{
|
||||
getTuner().getController().setGain(gain);
|
||||
save();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
mLog.error("Couldn't set LimeSDR gain to:" + gain, e);
|
||||
JOptionPane.showMessageDialog(mGainSlider, "Couldn't set gain value to " + gain);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
updateGainLabel();
|
||||
});
|
||||
}
|
||||
|
||||
return mGainSlider;
|
||||
}
|
||||
|
||||
private JLabel getGainValueLabel()
|
||||
{
|
||||
if(mGainValueLabel == null)
|
||||
{
|
||||
mGainValueLabel = new JLabel("0 dB");
|
||||
mGainValueLabel.setEnabled(false);
|
||||
}
|
||||
|
||||
return mGainValueLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
if(hasConfiguration() && !isLoading())
|
||||
{
|
||||
getConfiguration().setFrequency(getFrequencyControl().getFrequency());
|
||||
getConfiguration().setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
|
||||
getConfiguration().setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
|
||||
double value = ((SpinnerNumberModel)getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
|
||||
getConfiguration().setFrequencyCorrection(value);
|
||||
getConfiguration().setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
|
||||
LimeSdrTunerConfiguration config = getConfiguration();
|
||||
saveCommonSettings(config);
|
||||
|
||||
if(getSampleRateCombo().getSelectedItem() instanceof LimeSdrSampleRate rate)
|
||||
if(getSampleRateCombo().getValue() instanceof LimeSdrSampleRate rate)
|
||||
{
|
||||
getConfiguration().setSampleRate(rate.getRate());
|
||||
config.setSampleRate(rate.getRate());
|
||||
}
|
||||
|
||||
if(getAntennaCombo().getSelectedItem() instanceof String antenna)
|
||||
if(getAntennaCombo().getValue() instanceof String antenna)
|
||||
{
|
||||
getConfiguration().setAntenna(antenna);
|
||||
config.setAntenna(antenna);
|
||||
}
|
||||
|
||||
getConfiguration().setGain(getGainSlider().getValue());
|
||||
config.setGain(getGainSlider().getValue());
|
||||
saveConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTunerLockState(boolean locked)
|
||||
protected void tunerLockStateUpdated(boolean locked)
|
||||
{
|
||||
getFrequencyPanel().updateControls();
|
||||
getSampleRateCombo().setEnabled(!locked);
|
||||
getSampleRateCombo().setToolTipText(locked ? "Sample Rate is locked. Disable decoding channels to unlock." :
|
||||
"Select a sample rate for the tuner");
|
||||
getSampleRateCombo().setDisable(!hasStartedTuner() || locked);
|
||||
getSampleRateCombo().setTooltip(new Tooltip(locked ? "Sample rate is locked. Disable decoding channels " +
|
||||
"to unlock." : "Select a sample rate for the tuner"));
|
||||
}
|
||||
|
||||
private String getTunerInfo()
|
||||
@Override
|
||||
protected String getTunerInfo()
|
||||
{
|
||||
if(getDiscoveredTuner().getTunerStatus() == TunerStatus.ERROR)
|
||||
if(!hasStartedTuner())
|
||||
{
|
||||
return getDiscoveredTuner().getErrorMessage();
|
||||
return null;
|
||||
}
|
||||
|
||||
if(hasTuner())
|
||||
{
|
||||
LimeSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><h3>LimeSDR Tuner</h3>");
|
||||
sb.append("<b>Board: </b>").append(info.board()).append("<br>");
|
||||
sb.append("<b>Serial: </b>").append(info.serial()).append("<br>");
|
||||
sb.append("<b>Hardware: </b>").append(info.hardware()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(info.firmware()).append("<br>");
|
||||
sb.append("<b>Gateware: </b>").append(info.gateware()).append("<br>");
|
||||
sb.append("<b>Connection: </b>").append(info.connection()).append("<br>");
|
||||
sb.append("<b>LimeSuiteNG: </b>").append(info.library()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
LimeSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html><h3>LimeSDR Tuner</h3>");
|
||||
sb.append("<b>Board: </b>").append(info.board()).append("<br>");
|
||||
sb.append("<b>Serial: </b>").append(info.serial()).append("<br>");
|
||||
sb.append("<b>Hardware: </b>").append(info.hardware()).append("<br>");
|
||||
sb.append("<b>Firmware: </b>").append(info.firmware()).append("<br>");
|
||||
sb.append("<b>Gateware: </b>").append(info.gateware()).append("<br>");
|
||||
sb.append("<b>Connection: </b>").append(info.connection()).append("<br>");
|
||||
sb.append("<b>LimeSuiteNG: </b>").append(info.library()).append("<br>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user