diff --git a/src/main/java/io/github/dsheirer/gui/control/FrequencyControl.java b/src/main/java/io/github/dsheirer/gui/control/FrequencyControl.java
new file mode 100644
index 000000000..06e942a30
--- /dev/null
+++ b/src/main/java/io/github/dsheirer/gui/control/FrequencyControl.java
@@ -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
+ * ****************************************************************************
+ */
+
+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 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();
+ }
+ }
+}
diff --git a/src/main/java/io/github/dsheirer/gui/control/FrequencyEntry.java b/src/main/java/io/github/dsheirer/gui/control/FrequencyEntry.java
new file mode 100644
index 000000000..885420148
--- /dev/null
+++ b/src/main/java/io/github/dsheirer/gui/control/FrequencyEntry.java
@@ -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
+ * ****************************************************************************
+ */
+
+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;
+ }
+ }
+}
diff --git a/src/main/java/io/github/dsheirer/gui/control/FrequencyField.java b/src/main/java/io/github/dsheirer/gui/control/FrequencyField.java
new file mode 100644
index 000000000..044221515
--- /dev/null
+++ b/src/main/java/io/github/dsheirer/gui/control/FrequencyField.java
@@ -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
+ * ****************************************************************************
+ */
+
+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);
+ }
+ }
+}
diff --git a/src/main/java/io/github/dsheirer/gui/control/FrequencyTextField.java b/src/main/java/io/github/dsheirer/gui/control/FrequencyTextField.java
deleted file mode 100644
index 91a8b573c..000000000
--- a/src/main/java/io/github/dsheirer/gui/control/FrequencyTextField.java
+++ /dev/null
@@ -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
- * ****************************************************************************
- */
-
-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));
- }
-}
diff --git a/src/main/java/io/github/dsheirer/gui/control/JFrequencyControl.java b/src/main/java/io/github/dsheirer/gui/control/JFrequencyControl.java
deleted file mode 100644
index 3f042b82b..000000000
--- a/src/main/java/io/github/dsheirer/gui/control/JFrequencyControl.java
+++ /dev/null
@@ -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
- * ****************************************************************************
- */
-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 mProcessors = new ArrayList<>();
- private Color mHighlightColor = Color.YELLOW;
- private long mFrequency;
- private HashMap mDigits = new HashMap();
-
- /**
- * 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 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()));
- }
- }
- }
- }
-}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerEditor.java
index 542d73a11..8cf1aaf80 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/airspy/AirspyTunerEditor.java
@@ -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
{
- private static final long serialVersionUID = 1L;
- private final static Logger mLog = LoggerFactory.getLogger(AirspyTunerEditor.class);
- private JButton mTunerInfoButton;
- private JComboBox mSampleRateCombo;
- private JComboBox 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 mSampleRateCombo;
+ private ComboBox 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 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
- {
- 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
- {
- 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
- {
- 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
- {
- 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 getGainModeCombo()
+ private ComboBox 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 getSampleRateCombo()
+ private ComboBox 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 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 0)
+ if(!rates.isEmpty())
{
return rates.get(0);
}
@@ -684,56 +444,32 @@ public class AirspyTunerEditor extends TunerEditorAirspy Tuner
");
- sb.append("Serial: ");
- sb.append(info.getSerialNumber());
- sb.append("
");
-
- sb.append("Firmware: ");
- String[] firmware = info.getVersion().split(" ");
- sb.append(firmware.length > 1 ? firmware[0] : info.getVersion());
- sb.append("
");
-
- sb.append("Part: ");
- sb.append(info.getPartNumber());
- sb.append("
");
-
- sb.append("Board: ");
- sb.append(info.getBoardName());
- sb.append("
");
-
- return sb.toString();
- }
-
- return null;
+ StringBuilder sb = new StringBuilder();
+ AirspyDeviceInformation info = getTuner().getController().getDeviceInfo();
+ sb.append("Airspy Tuner
");
+ sb.append("Serial: ").append(info.getSerialNumber()).append("
");
+ String[] firmware = info.getVersion().split(" ");
+ sb.append("Firmware: ").append(firmware.length > 1 ? firmware[0] : info.getVersion()).append("
");
+ sb.append("Part: ").append(info.getPartNumber()).append("
");
+ sb.append("Board: ").append(info.getBoardName()).append("
");
+ return sb.toString();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/airspy/hf/AirspyHfTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/airspy/hf/AirspyHfTunerEditor.java
index e5266b1d5..7eb53821b 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/airspy/hf/AirspyHfTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/airspy/hf/AirspyHfTunerEditor.java
@@ -16,50 +16,40 @@
* along with this program. If not, see
* ****************************************************************************
*/
-
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
{
- private static final Logger mLog = LoggerFactory.getLogger(AirspyHfTunerEditor.class);
- private JComboBox mSampleRateCombo;
- private JComboBox mAttenuationCombo;
- private JToggleButton mAgcToggleButton;
- private JToggleButton mLnaToggleButton;
- private JToggleButton mBiasTToggleButton;
+ private ComboBox mSampleRateCombo;
+ private ComboBox 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 TunerEditorAirspy HF+ Tuner
" +
+ "Board: " + controller.getBoardId() + "
" +
+ "Serial: " + controller.getSerialNumber() + "
" +
+ "Firmware: " + controller.getFirmwareVersion() + "
";
}
@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 getSampleRateCombo()
+ private ComboBox 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 getAttenuationCombo()
+ private ComboBox 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 {
- 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;
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/bladerf/BladeRfTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/bladerf/BladeRfTunerEditor.java
index 0074c8d29..067b59eed 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/bladerf/BladeRfTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/bladerf/BladeRfTunerEditor.java
@@ -16,7 +16,6 @@
* along with this program. If not, see
* ****************************************************************************
*/
-
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
{
- @Serial
- private static final long serialVersionUID = 1L;
- private static final Logger mLog = LoggerFactory.getLogger(BladeRfTunerEditor.class);
- private JButton mTunerInfoButton;
- private JComboBox mSampleRateCombo;
- private JCheckBox mBiasTCheckBox;
- private JComboBox mGainModeCombo;
- private JSlider mGainSlider;
- private JLabel mGainValueLabel;
+ private ComboBox mSampleRateCombo;
+ private CheckBox mBiasTCheckBox;
+ private ComboBox mGainModeCombo;
+ private GainSlider mGainSlider;
+ private Label mGainLabel;
/**
* Constructs an instance
@@ -71,7 +55,7 @@ public class BladeRfTunerEditor extends TunerEditor 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 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());
- 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 getSampleRateCombo()
+ private ComboBox 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
- {
- 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 getGainModeCombo()
+ private ComboBox 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
- {
- 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("bladeRF Tuner
");
- sb.append("Serial: ").append(info.serial()).append("
");
- sb.append("Board: ").append(info.board()).append("
");
- sb.append("Firmware: ").append(info.firmware()).append("
");
- sb.append("FPGA: ").append(info.fpga()).append("
");
- sb.append("USB Speed: ").append(info.speed()).append("
");
- return sb.toString();
- }
-
- return null;
+ BladeRfDeviceInformation info = getTuner().getController().getDeviceInfo();
+ StringBuilder sb = new StringBuilder();
+ sb.append("bladeRF Tuner
");
+ sb.append("Serial: ").append(info.serial()).append("
");
+ sb.append("Board: ").append(info.board()).append("
");
+ sb.append("Firmware: ").append(info.firmware()).append("
");
+ sb.append("FPGA: ").append(info.fpga()).append("
");
+ sb.append("USB Speed: ").append(info.speed()).append("
");
+ return sb.toString();
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerEditor.java
index bd34a42ad..117bf50e3 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/fcd/proV1/FCD1TunerEditor.java
@@ -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
{
- private static final long serialVersionUID = 1L;
- private final static Logger mLog = LoggerFactory.getLogger(FCD1TunerEditor.class);
- private JButton mTunerInfoButton;
- private JComboBox mLnaGainCombo;
- private JComboBox mLnaEnhanceCombo;
- private JComboBox mMixerGainCombo;
- private JCheckBox mBiasTCheckBox;
+ private ComboBox mLnaGainCombo;
+ private ComboBox mLnaEnhanceCombo;
+ private ComboBox mMixerGainCombo;
+ private CheckBox mBiasTCheckBox;
private CorrectionSpinner mCorrectionDCI;
private CorrectionSpinner mCorrectionDCQ;
private CorrectionSpinner mGainCorrectionSpinner;
@@ -63,14 +52,14 @@ public class FCD1TunerEditor extends TunerEditor 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
- {
- 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 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 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 JOptionPane.showMessageDialog(FCD1TunerEditor.this,
- getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
- }
-
- return mTunerInfoButton;
- }
-
- private String getTunerInfo()
+ protected String getTunerInfo()
{
StringBuilder sb = new StringBuilder();
-
sb.append("Funcube Dongle Pro Tuner
");
-
- if(hasTuner())
- {
- sb.append("USB ID: ");
- sb.append(getController().getUSBID());
- sb.append("
");
-
- sb.append("USB Address: ");
- sb.append(getController().getUSBAddress());
- sb.append("
");
-
- sb.append("USB Speed: ");
- sb.append(getController().getUSBSpeed());
- sb.append("
");
-
- sb.append("Cellular Band: ");
- sb.append(getController().getConfiguration().getBandBlocking());
- sb.append("
");
-
- sb.append("Firmware: ");
- sb.append(getController().getConfiguration().getFirmware());
- sb.append("
");
- }
-
+ sb.append("USB ID: ").append(getController().getUSBID()).append("
");
+ sb.append("USB Address: ").append(getController().getUSBAddress()).append("
");
+ sb.append("USB Speed: ").append(getController().getUSBSpeed()).append("
");
+ sb.append("Cellular Band: ").append(getController().getConfiguration().getBandBlocking()).append("
");
+ sb.append("Firmware: ").append(getController().getConfiguration().getFirmware()).append("
");
return sb.toString();
}
@@ -415,88 +274,95 @@ public class FCD1TunerEditor extends TunerEditor
{
- 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;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerEditor.java
index 62d7f723f..5b5948ad5 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/fcd/proplusV2/FCD2TunerEditor.java
@@ -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
{
- 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 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
- {
- 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
- {
- 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 TunerEditorFuncube Dongle Pro Plus Tuner
");
-
- if(hasTuner())
- {
- sb.append("USB ID: ");
- sb.append(getController().getUSBID());
- sb.append("
");
-
- sb.append("USB Address: ");
- sb.append(getController().getUSBAddress());
- sb.append("
");
-
- sb.append("USB Speed: ");
- sb.append(getController().getUSBSpeed());
- sb.append("
");
-
- sb.append("Cellular Band: ");
- sb.append(getController().getConfiguration().getBandBlocking());
- sb.append("
");
-
- sb.append("Firmware: ");
- sb.append(getController().getConfiguration().getFirmware());
- sb.append("
");
- }
-
+ sb.append("USB ID: ").append(getController().getUSBID()).append("
");
+ sb.append("USB Address: ").append(getController().getUSBAddress()).append("
");
+ sb.append("USB Speed: ").append(getController().getUSBSpeed()).append("
");
+ sb.append("Cellular Band: ").append(getController().getConfiguration().getBandBlocking()).append("
");
+ sb.append("Firmware: ").append(getController().getConfiguration().getFirmware()).append("
");
return sb.toString();
}
@@ -286,16 +163,12 @@ public class FCD2TunerEditor extends TunerEditor
{
- private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger(HackRFTunerEditor.class);
- private JButton mTunerInfo;
- private JComboBox mSampleRateCombo;
- private JToggleButton mAmplifier;
- private JToggleButton mBiasT;
- private JComboBox mLnaGainCombo;
- private JComboBox mVgaGainCombo;
+ private ComboBox mSampleRateCombo;
+ private CheckBox mAmplifierCheckBox;
+ private CheckBox mBiasTCheckBox;
+ private ComboBox mLnaGainCombo;
+ private ComboBox 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 getVgaGainCombo()
{
if(mVgaGainCombo == null)
{
- mVgaGainCombo = new JComboBox(HackRFVGAGain.values());
- mVgaGainCombo.setToolTipText("VGA Gain. Adjust to set the baseband gain");
- 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 getLnaGainCombo()
{
if(mLnaGainCombo == null)
{
- mLnaGainCombo = new JComboBox(HackRFLNAGain.values());
- mLnaGainCombo.setToolTipText("LNA Gain. Adjust to set the IF gain");
- 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
- {
- 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 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 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("HackRF Tuner
");
appendInfo(sb, "Board", controller != null ? controller.getBoardName() : null);
@@ -391,9 +258,6 @@ public class HackRFTunerEditor extends TunerEditor").append(label).append(": ").append(value != null ? value : "Unknown").append("
");
@@ -404,18 +268,14 @@ public class HackRFTunerEditor extends TunerEditor
{
- private static final long serialVersionUID = 1L;
- private final static Logger mLog = LoggerFactory.getLogger(HydraSdrTunerEditor.class);
- private JButton mTunerInfoButton;
- private JComboBox mSampleRateCombo;
- private JComboBox 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 mSampleRateCombo;
+ private ComboBox 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 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 {
+ 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
- {
- 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 getGainModeCombo()
+ private ComboBox 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 getSampleRateCombo()
+ private ComboBox 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 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 0)
+ if(!rates.isEmpty())
{
return rates.get(0);
}
@@ -687,55 +444,31 @@ public class HydraSdrTunerEditor extends TunerEditorHydraSDR Tuner
");
- sb.append("Serial: ");
- sb.append(info.getSerialNumber());
- sb.append("
");
-
- sb.append("Firmware: ");
- sb.append(info.getVersion());
- sb.append("
");
-
- sb.append("Part: ");
- sb.append(info.getPartNumber());
- sb.append("
");
-
- sb.append("Board: ");
- sb.append(info.getBoardName());
- sb.append("
");
-
- return sb.toString();
- }
-
- return null;
+ StringBuilder sb = new StringBuilder();
+ HydraSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
+ sb.append("HydraSDR Tuner
");
+ sb.append("Serial: ").append(info.getSerialNumber()).append("
");
+ sb.append("Firmware: ").append(info.getVersion()).append("
");
+ sb.append("Part: ").append(info.getPartNumber()).append("
");
+ sb.append("Board: ").append(info.getBoardName()).append("
");
+ return sb.toString();
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/limesdr/LimeSdrTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/limesdr/LimeSdrTunerEditor.java
index d8bd32175..4553b788a 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/limesdr/LimeSdrTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/limesdr/LimeSdrTunerEditor.java
@@ -16,42 +16,25 @@
* along with this program. If not, see
* ****************************************************************************
*/
-
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
{
- @Serial
- private static final long serialVersionUID = 1L;
- private static final Logger mLog = LoggerFactory.getLogger(LimeSdrTunerEditor.class);
- private JButton mTunerInfoButton;
- private JComboBox mSampleRateCombo;
- private JComboBox mAntennaCombo;
- private JSlider mGainSlider;
- private JLabel mGainValueLabel;
+ private ComboBox mSampleRateCombo;
+ private ComboBox mAntennaCombo;
+ private GainSlider mGainSlider;
/**
* Constructs an instance
@@ -63,7 +46,7 @@ public class LimeSdrTunerEditor extends TunerEditor rates = controller.getSampleRates();
- getSampleRateCombo().setModel(new DefaultComboBoxModel<>(rates.toArray(new LimeSdrSampleRate[0])));
- getSampleRateCombo().setSelectedItem(controller.getLimeSdrSampleRate());
- getSampleRateCombo().setEnabled(!controller.isLockedSampleRate());
-
- List 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 getSampleRateCombo()
+ private ComboBox 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 getAntennaCombo()
+ private ComboBox 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
- {
- 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("LimeSDR Tuner
");
- sb.append("Board: ").append(info.board()).append("
");
- sb.append("Serial: ").append(info.serial()).append("
");
- sb.append("Hardware: ").append(info.hardware()).append("
");
- sb.append("Firmware: ").append(info.firmware()).append("
");
- sb.append("Gateware: ").append(info.gateware()).append("
");
- sb.append("Connection: ").append(info.connection()).append("
");
- sb.append("LimeSuiteNG: ").append(info.library()).append("
");
- return sb.toString();
- }
-
- return null;
+ LimeSdrDeviceInformation info = getTuner().getController().getDeviceInfo();
+ StringBuilder sb = new StringBuilder();
+ sb.append("LimeSDR Tuner
");
+ sb.append("Board: ").append(info.board()).append("
");
+ sb.append("Serial: ").append(info.serial()).append("
");
+ sb.append("Hardware: ").append(info.hardware()).append("
");
+ sb.append("Firmware: ").append(info.firmware()).append("
");
+ sb.append("Gateware: ").append(info.gateware()).append("
");
+ sb.append("Connection: ").append(info.connection()).append("
");
+ sb.append("LimeSuiteNG: ").append(info.library()).append("
");
+ return sb.toString();
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/network/AddNetworkTunerDialog.java b/src/main/java/io/github/dsheirer/source/tuner/network/AddNetworkTunerDialog.java
index 4f9584ac0..addf88d7c 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/network/AddNetworkTunerDialog.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/network/AddNetworkTunerDialog.java
@@ -18,165 +18,150 @@
*/
package io.github.dsheirer.source.tuner.network;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import net.miginfocom.swing.MigLayout;
-
-import org.apache.commons.lang3.Validate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import io.github.dsheirer.gui.control.FrequencyEntry;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationManager;
import io.github.dsheirer.source.tuner.manager.DiscoveredNetworkTuner;
import io.github.dsheirer.source.tuner.ui.DiscoveredTunerModel;
+import javafx.application.Platform;
+import javafx.geometry.Insets;
+import javafx.scene.Node;
+import javafx.scene.control.ButtonBar;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.Dialog;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.Priority;
+import javafx.stage.Window;
+import org.apache.commons.lang3.Validate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
+/**
+ * Dialog for adding an rtl_tcp network tuner.
+ */
+public class AddNetworkTunerDialog extends Dialog {
+ private static final Logger mLog = LoggerFactory.getLogger(AddNetworkTunerDialog.class);
+ private static final ButtonType ADD = new ButtonType("Add", ButtonBar.ButtonData.OK_DONE);
+ private final UserPreferences mUserPreferences;
+ private final DiscoveredTunerModel mDiscoveredTunerModel;
+ private final TunerConfigurationManager mTunerConfigurationManager;
+ private final ComboBox mTypeComboBox = new ComboBox<>();
+ private final TextField mHostField = new TextField();
+ private final TextField mPortField = new TextField("1234");
+ private final TextField mFrequencyField = new TextField();
+ private final Label mValidationLabel = new Label();
-public class AddNetworkTunerDialog extends JFrame {
- private final static Logger mLog = LoggerFactory.getLogger(AddNetworkTunerDialog.class);
- private UserPreferences mUserPreferences;
- private DiscoveredTunerModel mDiscoveredTunerModel;
- private TunerConfigurationManager mTunerConfigurationManager;
- private JLabel mTypeLabel;
- private JLabel mHostLabel;
- private JLabel mPortLabel;
- private JLabel mFrequencyLabel;
- private JComboBox mTypeComboBox;
- private JTextField mHostField;
- private JTextField mPortField;
- private JTextField mFrequencyField;
- private JButton mAddButton;
- private JButton mCancelButton;
-
- public AddNetworkTunerDialog(UserPreferences userPreferences, DiscoveredTunerModel discoveredTunerModel,
+ public AddNetworkTunerDialog(Window owner, UserPreferences userPreferences, DiscoveredTunerModel discoveredTunerModel,
TunerConfigurationManager tunerConfigurationManager) {
Validate.notNull(userPreferences, "UserPreferences cannot be null");
Validate.notNull(discoveredTunerModel, "TunerModel cannot be null");
Validate.notNull(tunerConfigurationManager, "TunerConfigurationManager cannot be null");
-
mDiscoveredTunerModel = discoveredTunerModel;
mUserPreferences = userPreferences;
mTunerConfigurationManager = tunerConfigurationManager;
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ initOwner(owner);
setTitle("Add Network Tuner");
- setSize(new Dimension(500, 250));
+ setHeaderText("Add an rtl_tcp network tuner");
- JPanel content = new JPanel();
- content.setLayout(new MigLayout("", "[align right][][]", "[][][][][grow][]"));
+ mTypeComboBox.getItems().add("rtl-tcp");
+ mTypeComboBox.getSelectionModel().selectFirst();
+ mTypeComboBox.setMaxWidth(Double.MAX_VALUE);
+ mHostField.setPromptText("hostname or IP address");
+ mPortField.setPromptText("e.g. 1234");
+ mFrequencyField.setPromptText("e.g. 851.0125");
+ mValidationLabel.getStyleClass().add("tuner-validation");
+ mValidationLabel.setWrapText(true);
+ mValidationLabel.setStyle("-fx-text-fill: #d9443a;");
- mTypeLabel = new JLabel("Type:");
- content.add(mTypeLabel);
+ GridPane grid = new GridPane();
+ grid.setHgap(10);
+ grid.setVgap(8);
+ grid.setPadding(new Insets(10));
+ grid.addRow(0, new Label("Type"), mTypeComboBox);
+ grid.addRow(1, new Label("Host"), mHostField);
+ grid.addRow(2, new Label("Port"), mPortField);
+ grid.addRow(3, new Label("Frequency (MHz)"), mFrequencyField);
+ grid.add(mValidationLabel, 0, 4, 2, 1);
+ GridPane.setHgrow(mHostField, Priority.ALWAYS);
+ grid.setPrefWidth(420);
- String[] options = { "rtl-tcp" };
- mTypeComboBox = new JComboBox<>(options);
- content.add(mTypeComboBox, "span2,grow,wrap");
+ getDialogPane().setContent(grid);
+ getDialogPane().getButtonTypes().addAll(ADD, ButtonType.CANCEL);
- mHostLabel = new JLabel("Host:");
- content.add(mHostLabel);
+ Node addButton = getDialogPane().lookupButton(ADD);
+ addButton.setDisable(true);
+ Runnable validate = () -> {
+ String error = getValidationError();
+ mValidationLabel.setText(error == null ? "" : error);
+ addButton.setDisable(error != null);
+ };
+ mHostField.textProperty().addListener((observable, oldValue, newValue) -> validate.run());
+ mPortField.textProperty().addListener((observable, oldValue, newValue) -> validate.run());
+ mFrequencyField.textProperty().addListener((observable, oldValue, newValue) -> validate.run());
+ validate.run();
+ mValidationLabel.setText("");
- mHostField = new JTextField("");
- mHostField.setToolTipText("Enter the hostname or IP address of the network tuner");
- content.add(mHostField, "span2,grow,wrap");
-
- mPortLabel = new JLabel("Port:");
- content.add(mPortLabel);
-
- mPortField = new JTextField("");
- mHostField.setToolTipText("Enter the port number of the network tuner");
- content.add(mPortField, "span2,grow,wrap");
-
- mFrequencyLabel = new JLabel("Frequency (Hz):");
- content.add(mFrequencyLabel);
-
- mFrequencyField = new JTextField("");
- mFrequencyField.setToolTipText("Enter the center frequency of the network tuner in Hertz (Hz)");
- content.add(mFrequencyField, "span2,grow,wrap");
-
- content.add(new JLabel(""), "wrap");
- content.add(new JLabel(""));
-
- mAddButton = new JButton("Add");
- // mAddButton.setEnabled(false);
- mAddButton.addActionListener(e -> {
-
- long frequency = getFrequency();
-
- if (frequency <= 0 || frequency > Integer.MAX_VALUE) {
- JOptionPane.showMessageDialog(AddNetworkTunerDialog.this,
- "Please provide a center frequency (1Hz to 2.14 GHz)",
- "Center Frequency Required",
- JOptionPane.ERROR_MESSAGE);
- return;
+ setResultConverter(buttonType -> {
+ if (buttonType == ADD) {
+ addTuner();
}
-
- mLog.info("Adding network tuner = frequency [" + frequency + "] host [" + getHost() + ":" + getPort() + "]");
-
- try {
- NetworkTunerConfiguration config = NetworkTunerConfiguration.create();
- config.setFrequency(frequency);
- config.setHost(getHost());
- config.setPort(getPort());
- mTunerConfigurationManager.addTunerConfiguration(config);
- DiscoveredNetworkTuner discoveredNetworkTuner = new DiscoveredNetworkTuner(mUserPreferences, config);
- mDiscoveredTunerModel.addDiscoveredTuner(discoveredNetworkTuner);
- } catch (Exception ex) {
- mLog.error("Error adding network tuner", ex);
- }
-
- AddNetworkTunerDialog.this.setVisible(false);
+ return buttonType;
});
- content.add(mAddButton, "grow,push");
- mCancelButton = new JButton("Cancel");
- mCancelButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- AddNetworkTunerDialog.this.setVisible(false);
- }
- });
- content.add(mCancelButton, "grow,push");
-
- setContentPane(content);
+ Platform.runLater(mHostField::requestFocus);
}
- private long getFrequency() {
- String text = mFrequencyField.getText();
-
- if (text != null && !text.isEmpty()) {
- try {
- return Long.parseLong(text);
- } catch (Exception e) {
- // Do nothing, we couldn't parse the frequency value
- }
+ /**
+ * Validation error for the current entries, or null when they are valid.
+ */
+ private String getValidationError() {
+ if (getHost().isEmpty()) {
+ return "Enter the host name or IP address of the rtl_tcp server";
}
- return 0l;
+ if (getPort() <= 0) {
+ return "Enter a port number from 1 to " + Short.MAX_VALUE;
+ }
+
+ Long frequency = FrequencyEntry.parse(mFrequencyField.getText());
+
+ if (frequency == null || frequency <= 0 || frequency > Integer.MAX_VALUE) {
+ return "Enter a center frequency up to 2147.483647 MHz";
+ }
+
+ return null;
+ }
+
+ private void addTuner() {
+ long frequency = FrequencyEntry.parse(mFrequencyField.getText());
+ mLog.info("Adding network tuner = frequency [" + frequency + "] host [" + getHost() + ":" + getPort() + "]");
+
+ try {
+ NetworkTunerConfiguration config = NetworkTunerConfiguration.create();
+ config.setFrequency(frequency);
+ config.setHost(getHost());
+ config.setPort(getPort());
+ mTunerConfigurationManager.addTunerConfiguration(config);
+ DiscoveredNetworkTuner discoveredNetworkTuner = new DiscoveredNetworkTuner(mUserPreferences, config);
+ mDiscoveredTunerModel.addDiscoveredTuner(discoveredNetworkTuner);
+ } catch (Exception ex) {
+ mLog.error("Error adding network tuner", ex);
+ }
}
private String getHost() {
- return mHostField.getText();
+ return mHostField.getText() == null ? "" : mHostField.getText().trim();
}
private short getPort() {
- String text = mPortField.getText();
-
- if (text != null && !text.isEmpty()) {
- try {
- return Short.parseShort(text);
- } catch (Exception e) {
- // Do nothing, we couldn't parse the port value
- }
+ try {
+ return Short.parseShort(mPortField.getText().trim());
+ } catch (Exception e) {
+ return 0;
}
-
- return 0;
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/network/NetworkTunerDisabledEditor.java b/src/main/java/io/github/dsheirer/source/tuner/network/NetworkTunerDisabledEditor.java
index fa57a36fd..e241d93b4 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/network/NetworkTunerDisabledEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/network/NetworkTunerDisabledEditor.java
@@ -18,42 +18,30 @@
*/
package io.github.dsheirer.source.tuner.network;
-import javax.swing.JLabel;
-import javax.swing.JSeparator;
-
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.ui.TunerEditor;
-import net.miginfocom.swing.MigLayout;
+import io.github.dsheirer.source.tuner.ui.TunerSection;
+import javafx.scene.control.Label;
/**
- * Minimal tuner editor for a network (rtl_tcp) tuner that has not been started. Mirrors
- * RTL2832UnknownTunerEditor's pattern: only the id/status labels and the button panel are shown -
- * no frequency/sample-rate/gain controls, since there's no live tuner to configure yet.
+ * Editor for a network tuner that is disabled or not connected. Shows the status and the enable switch only.
*/
public class NetworkTunerDisabledEditor extends TunerEditor {
- private static final long serialVersionUID = 1L;
-
public NetworkTunerDisabledEditor(UserPreferences userPreferences, TunerManager tunerManager,
DiscoveredTuner discoveredTuner) {
super(userPreferences, tunerManager, discoveredTuner);
- init();
- tunerStatusUpdated();
+ TunerSection section = addSection("Network Tuner");
+ Label message = new Label("Enable the tuner to connect to the rtl_tcp server and change its settings.");
+ message.setWrapText(true);
+ section.addFullRow(message);
+ refresh();
}
- private void init() {
- setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]", "[][][][grow]"));
-
- add(new JLabel("Tuner:"));
- add(getTunerIdLabel(), "wrap");
-
- add(new JLabel("Status:"));
- add(getTunerStatusLabel(), "wrap");
-
- add(getButtonPanel(), "span,align left");
-
- add(new JSeparator(), "span,growx,push");
+ @Override
+ protected boolean hasTuningControls() {
+ return false;
}
@Override
@@ -75,20 +63,6 @@ public class NetworkTunerDisabledEditor extends TunerEditor {
- private static final long serialVersionUID = 1L;
- private static final Logger mLog = LoggerFactory.getLogger(NetworkTunerEditor.class);
+ private static final List R820T_GAINS_TENTHS_DB = List.of(0, 9, 14, 27, 37, 77, 87, 125, 144, 157, 166,
+ 197, 207, 229, 254, 280, 297, 328, 338, 364, 372, 386, 402, 421, 434, 439, 445, 480, 496);
- //R820T total gain table (tenths of dB), from librtlsdr's rtlsdr_get_tuner_gains() - most rtl_tcp
- //servers are backed by an R820T/R820T2 dongle and report this same gain table.
- private static final Integer[] R820T_GAINS_TENTHS_DB = {0, 9, 14, 27, 37, 77, 87, 125, 144, 157, 166, 197, 207,
- 229, 254, 280, 297, 328, 338, 364, 372, 386, 402, 421, 434, 439, 445, 480, 496};
-
- private JButton mTunerInfoButton;
- private JToggleButton mBiasTButton;
- private JComboBox mSampleRateCombo;
- private JCheckBox mGainAutoCheckBox;
- private JComboBox mGainCombo;
- private JCheckBox mAutoReconnectCheckBox;
+ private CheckBox mBiasTCheckBox;
+ private ComboBox mSampleRateCombo;
+ private CheckBox mGainAutoCheckBox;
+ private ComboBox mGainCombo;
+ private CheckBox mAutoReconnectCheckBox;
public NetworkTunerEditor(UserPreferences userPreferences, TunerManager tunerManager,
DiscoveredTuner discoveredTuner) {
super(userPreferences, tunerManager, discoveredTuner);
init();
- tunerStatusUpdated();
- }
-
- @Override
- public void setTunerLockState(boolean locked) {
- getFrequencyPanel().updateControls();
- //Matches the USB RTL2832/R8x tuner pattern: sample rate can't change while channels are active. Gain and
- //Bias-T don't affect channelizing, so they remain adjustable regardless of lock state.
- getSampleRateCombo().setEnabled(hasTuner() && !locked);
+ refresh();
}
@Override
@@ -74,134 +58,92 @@ public class NetworkTunerEditor extends TunerEditorrtl_tcp Network Tuner
" +
+ "Host: " + getConfiguration().getHost() + "
" +
+ "Port: " + getConfiguration().getPort() + "
" +
+ "Tuner Type: rtl_tcp
";
}
- 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());
- add(getBiasTButton(), "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("Gain:"));
- add(getGainAutoCheckBox(), "split 2");
- add(getGainCombo(), "wrap");
-
- add(new JLabel("Auto-Reconnect:"));
- add(getAutoReconnectCheckBox(), "wrap");
- }
-
- /**
- * Bias-T toggle button, matching the USB RTL2832/R8x tuner editor's top-row placement.
- */
- private JToggleButton getBiasTButton() {
- if (mBiasTButton == null) {
- mBiasTButton = new JToggleButton("Bias-T");
- mBiasTButton.setEnabled(false);
- mBiasTButton.addActionListener(e -> {
+ private CheckBox getBiasTCheckBox() {
+ if (mBiasTCheckBox == null) {
+ mBiasTCheckBox = new CheckBox("Bias-T");
+ mBiasTCheckBox.setTooltip(new Tooltip("Ask the rtl_tcp server to provide DC power on the antenna connector"));
+ mBiasTCheckBox.setDisable(true);
+ mBiasTCheckBox.setOnAction(e -> {
if (!isLoading()) {
- boolean enabled = mBiasTButton.isSelected();
-
if (hasTuner()) {
- getTuner().getTunerController().setBiasTEnabled(enabled);
+ getTuner().getTunerController().setBiasTEnabled(mBiasTCheckBox.isSelected());
}
-
save();
}
});
}
- return mBiasTButton;
+ return mBiasTCheckBox;
}
- /**
- * Hyperlink-style button that shows the network tuner's connection details.
- */
- private JButton getTunerInfoButton() {
- if (mTunerInfoButton == null) {
- mTunerInfoButton = new JButton("Info");
- mTunerInfoButton.setEnabled(false);
- mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(NetworkTunerEditor.this,
- getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
- }
-
- return mTunerInfoButton;
- }
-
- private String getTunerInfo() {
- StringBuilder sb = new StringBuilder();
- sb.append("rtl_tcp Network Tuner
");
- sb.append("Host: ").append(getConfiguration().getHost()).append("
");
- sb.append("Port: ").append(getConfiguration().getPort()).append("
");
- sb.append("Tuner Type: rtl_tcp
");
- return sb.toString();
- }
-
- private JComboBox getSampleRateCombo() {
+ private ComboBox getSampleRateCombo() {
if (mSampleRateCombo == null) {
- mSampleRateCombo = new JComboBox<>(SampleRate.values());
- mSampleRateCombo.setEnabled(false);
- mSampleRateCombo.addActionListener(e -> {
- if (!isLoading()) {
- SampleRate sampleRate = (SampleRate) mSampleRateCombo.getSelectedItem();
+ mSampleRateCombo = new ComboBox<>(FXCollections.observableArrayList(SampleRate.values()));
+ mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
+ mSampleRateCombo.setDisable(true);
+ mSampleRateCombo.setOnAction(e -> {
+ SampleRate sampleRate = mSampleRateCombo.getValue();
- if (sampleRate != null) {
- if (hasTuner()) {
- getTuner().getTunerController().setSampleRate(sampleRate.getRate());
- }
-
- save();
+ if (!isLoading() && sampleRate != null) {
+ if (hasTuner()) {
+ getTuner().getTunerController().setSampleRate(sampleRate.getRate());
+ adjustForSampleRate(sampleRate.getRate());
}
+ save();
}
});
}
@@ -209,18 +151,18 @@ public class NetworkTunerEditor extends TunerEditor {
+ mGainAutoCheckBox = new CheckBox("Auto");
+ mGainAutoCheckBox.setTooltip(new Tooltip("Let the rtl_tcp server's tuner set the gain automatically"));
+ mGainAutoCheckBox.setOnAction(e -> {
boolean gainAuto = mGainAutoCheckBox.isSelected();
- getGainCombo().setEnabled(hasTuner() && !gainAuto);
+ getGainCombo().setDisable(!hasTuner() || gainAuto);
if (!isLoading()) {
if (hasTuner()) {
getTuner().getTunerController().setGainAuto(gainAuto);
}
-
save();
}
});
@@ -229,22 +171,31 @@ public class NetworkTunerEditor extends TunerEditor getGainCombo() {
+ private ComboBox getGainCombo() {
if (mGainCombo == null) {
- mGainCombo = new JComboBox<>(R820T_GAINS_TENTHS_DB);
- mGainCombo.setEnabled(false);
- mGainCombo.setToolTipText("Gain in tenths of dB. Uncheck Auto to enable manual gain.");
- mGainCombo.addActionListener(e -> {
- if (!isLoading()) {
- Integer gain = (Integer) mGainCombo.getSelectedItem();
+ mGainCombo = new ComboBox<>(FXCollections.observableArrayList(R820T_GAINS_TENTHS_DB));
+ mGainCombo.setMaxWidth(Double.MAX_VALUE);
+ mGainCombo.setDisable(true);
+ mGainCombo.setTooltip(new Tooltip("Manual gain. Uncheck Auto to enable manual gain."));
+ mGainCombo.setConverter(new StringConverter<>() {
+ @Override
+ public String toString(Integer gain) {
+ return gain == null ? "" : String.format("%.1f dB", gain / 10.0);
+ }
- if (gain != null) {
- if (hasTuner()) {
- getTuner().getTunerController().setGain(gain);
- }
+ @Override
+ public Integer fromString(String text) {
+ return null;
+ }
+ });
+ mGainCombo.setOnAction(e -> {
+ Integer gain = mGainCombo.getValue();
- save();
+ if (!isLoading() && gain != null) {
+ if (hasTuner()) {
+ getTuner().getTunerController().setGain(gain);
}
+ save();
}
});
}
@@ -252,18 +203,16 @@ public class NetworkTunerEditor extends TunerEditor {
+ mAutoReconnectCheckBox = new CheckBox("Auto-reconnect");
+ mAutoReconnectCheckBox.setTooltip(new Tooltip("Automatically reconnect if the connection to the rtl_tcp " +
+ "server is lost"));
+ mAutoReconnectCheckBox.setOnAction(e -> {
if (!isLoading()) {
- boolean autoReconnect = mAutoReconnectCheckBox.isSelected();
-
if (hasTuner()) {
- getTuner().getTunerController().setAutoReconnect(autoReconnect);
+ getTuner().getTunerController().setAutoReconnect(mAutoReconnectCheckBox.isSelected());
}
-
save();
}
});
@@ -272,9 +221,6 @@ public class NetworkTunerEditor extends TunerEditor
* ****************************************************************************
*/
-
package io.github.dsheirer.source.tuner.recording;
+import io.github.dsheirer.gui.control.FrequencyEntry;
import io.github.dsheirer.preference.UserPreferences;
import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationManager;
import io.github.dsheirer.source.tuner.manager.DiscoveredRecordingTuner;
import io.github.dsheirer.source.tuner.ui.DiscoveredTunerModel;
import io.github.dsheirer.source.wave.SDRSharpIQRecording;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.miginfocom.swing.MigLayout;
+import javafx.geometry.Insets;
+import javafx.scene.Node;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Button;
+import javafx.scene.control.ButtonBar;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.Dialog;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.Priority;
+import javafx.stage.FileChooser;
+import javafx.stage.Window;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.JButton;
-import javax.swing.JFileChooser;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextField;
-import javax.swing.filechooser.FileNameExtensionFilter;
-
/**
- * Dialog to select a recording and specify a center frequency for use in adding a Recording Tuner
+ * Dialog for adding a recording tuner that replays a baseband recording file.
*/
-public class AddRecordingTunerDialog extends JFrame
+public class AddRecordingTunerDialog extends Dialog
{
private final static Logger mLog = LoggerFactory.getLogger(AddRecordingTunerDialog.class);
- private static final String SELECT_A_FILE = "Please select a recording file";
+ private static final String SELECT_A_FILE = "No recording selected";
private static final String LAST_FILE_BROWSE_LOCATION_KEY = "AddRecordingTunerDialog.lastBrowseLocation";
- private UserPreferences mUserPreferences;
- private DiscoveredTunerModel mDiscoveredTunerModel;
- private TunerConfigurationManager mTunerConfigurationManager;
- private JButton mSelectFileButton;
- private File mSelectedRecording;
- private JLabel mRecordingFileLabel;
- private JLabel mFrequencyLabel;
- private JTextField mFrequencyTextField;
- private JButton mAddButton;
- private JButton mCancelButton;
+ private static final ButtonType ADD = new ButtonType("Add", ButtonBar.ButtonData.OK_DONE);
private static final Pattern TUNER_RECORDING_PATTERN = Pattern.compile(".*_(\\d*)_baseband_\\d{8}_\\d{6}\\.wav");
+ private final UserPreferences mUserPreferences;
+ private final DiscoveredTunerModel mDiscoveredTunerModel;
+ private final TunerConfigurationManager mTunerConfigurationManager;
+ private final Label mRecordingFileLabel = new Label(SELECT_A_FILE);
+ private final TextField mFrequencyField = new TextField();
+ private final Label mValidationLabel = new Label();
+ private File mSelectedRecording;
+ private Node mAddButton;
- public AddRecordingTunerDialog(UserPreferences userPreferences, DiscoveredTunerModel discoveredTunerModel,
+ /**
+ * Constructs an instance
+ * @param owner window for the dialog
+ * @param userPreferences for the default recording directory
+ * @param discoveredTunerModel to add the recording tuner to
+ * @param tunerConfigurationManager to add the recording tuner configuration to
+ */
+ public AddRecordingTunerDialog(Window owner, UserPreferences userPreferences, DiscoveredTunerModel discoveredTunerModel,
TunerConfigurationManager tunerConfigurationManager)
{
Validate.notNull(userPreferences, "UserPreferences cannot be null");
Validate.notNull(discoveredTunerModel, "TunerModel cannot be null");
Validate.notNull(tunerConfigurationManager, "TunerConfigurationManager cannot be null");
-
mDiscoveredTunerModel = discoveredTunerModel;
mUserPreferences = userPreferences;
mTunerConfigurationManager = tunerConfigurationManager;
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- setTitle("Select Recording File");
- setSize(new Dimension(500, 250));
+ initOwner(owner);
+ setTitle("Add Recording Tuner");
+ setHeaderText("Replay a baseband recording (.wav or SDR# .iq) as a tuner");
- JPanel content = new JPanel();
- content.setLayout(new MigLayout("", "[align right][][]", "[][][grow][]"));
+ Button selectFileButton = new Button("Select ...");
+ selectFileButton.setOnAction(e -> selectFile());
+ mRecordingFileLabel.setWrapText(true);
+ mFrequencyField.setPromptText("e.g. 851.0125");
+ mValidationLabel.setWrapText(true);
+ mValidationLabel.setStyle("-fx-text-fill: #d9443a;");
- mSelectFileButton = new JButton("Select ...");
- mSelectFileButton.addActionListener(e -> {
- JFileChooser fileChooser = new JFileChooser();
- String lastBrowsedDirectory = SystemProperties.getInstance().get(LAST_FILE_BROWSE_LOCATION_KEY, "");
+ GridPane grid = new GridPane();
+ grid.setHgap(10);
+ grid.setVgap(8);
+ grid.setPadding(new Insets(10));
+ grid.addRow(0, selectFileButton, mRecordingFileLabel);
+ grid.addRow(1, new Label("Frequency (MHz)"), mFrequencyField);
+ grid.add(mValidationLabel, 0, 2, 2, 1);
+ GridPane.setHgrow(mFrequencyField, Priority.ALWAYS);
+ grid.setPrefWidth(460);
- File browseDirectory;
+ getDialogPane().setContent(grid);
+ getDialogPane().getButtonTypes().addAll(ADD, ButtonType.CANCEL);
+ mAddButton = getDialogPane().lookupButton(ADD);
+ mAddButton.setDisable(true);
+ mFrequencyField.textProperty().addListener((observable, oldValue, newValue) -> validate());
- if(lastBrowsedDirectory != null && !lastBrowsedDirectory.isEmpty())
+ setResultConverter(buttonType -> {
+ if(buttonType == ADD)
{
- browseDirectory = new File(lastBrowsedDirectory);
+ addTuner();
}
- else
- {
- browseDirectory = mUserPreferences.getDirectoryPreference().getDefaultRecordingDirectory().toFile();
- }
-
- fileChooser.setCurrentDirectory(browseDirectory);
- fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- FileNameExtensionFilter basebandFilter = new FileNameExtensionFilter("Baseband Recordings (*.wav, *.iq)",
- "wav", SDRSharpIQRecording.FILE_EXTENSION);
- fileChooser.addChoosableFileFilter(basebandFilter);
- fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Wave Recordings (*.wav)", "wav"));
- fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SDRSharp I/Q Recordings (*.iq)",
- SDRSharpIQRecording.FILE_EXTENSION));
- fileChooser.setFileFilter(basebandFilter);
-
- int returnVal = fileChooser.showOpenDialog(AddRecordingTunerDialog.this);
-
- File lastDirectory = fileChooser.getCurrentDirectory();
-
- if(lastDirectory != null)
- {
- SystemProperties.getInstance().set(LAST_FILE_BROWSE_LOCATION_KEY, lastDirectory.getAbsolutePath());
- }
-
- if(returnVal == JFileChooser.APPROVE_OPTION)
- {
- mSelectedRecording = fileChooser.getSelectedFile();
-
- if(SDRSharpIQRecording.hasIQExtension(mSelectedRecording))
- {
- SDRSharpIQRecording iqRecording = SDRSharpIQRecording.parse(mSelectedRecording);
-
- if(iqRecording == null)
- {
- JOptionPane.showMessageDialog(AddRecordingTunerDialog.this,
- "Unable to determine the sample rate and center frequency from the I/Q recording " +
- "file name.
Expected format: yyyyMMdd-HHmmss_label_TUNER_123456789Hz_10MSps.iq",
- "Unsupported I/Q Recording",
- JOptionPane.ERROR_MESSAGE);
- mSelectedRecording = null;
- }
- else
- {
- mLog.info("Selected " + iqRecording);
-
- if(mFrequencyTextField.getText() == null || mFrequencyTextField.getText().isEmpty())
- {
- mFrequencyTextField.setText(String.valueOf(iqRecording.getCenterFrequency()));
- }
- }
- }
- else if(mSelectedRecording != null &&
- (mFrequencyTextField.getText() == null || mFrequencyTextField.getText().isEmpty()))
- {
- Matcher m = TUNER_RECORDING_PATTERN.matcher(mSelectedRecording.getName());
-
- if(m.matches())
- {
- mFrequencyTextField.setText(m.group(1));
- }
- }
-
- mAddButton.setEnabled(mSelectedRecording != null);
- }
- else
- {
- mSelectedRecording = null;
- }
-
- mRecordingFileLabel.setText(mSelectedRecording != null ? mSelectedRecording.getName() : SELECT_A_FILE);
+ return buttonType;
});
- content.add(mSelectFileButton);
-
- mRecordingFileLabel = new JLabel(SELECT_A_FILE);
- content.add(mRecordingFileLabel, "span 2,wrap");
-
- mFrequencyLabel = new JLabel("Frequency (Hz):");
- content.add(mFrequencyLabel);
-
- mFrequencyTextField = new JTextField("");
- mFrequencyTextField.setToolTipText("Center frequency for the recording in Hertz (Hz)");
- content.add(mFrequencyTextField, "span 2,grow,wrap");
-
- content.add(new JLabel(""), "wrap");
-
- content.add(new JLabel(""));
-
- mAddButton = new JButton("Add");
- mAddButton.setEnabled(false);
- mAddButton.addActionListener(e -> {
- if(mSelectedRecording == null)
- {
- JOptionPane.showMessageDialog(AddRecordingTunerDialog.this,
- "Please select a recording file",
- "Select a Recording File",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- long frequency = getFrequency();
-
- if(frequency <= 0 || frequency > Integer.MAX_VALUE)
- {
- JOptionPane.showMessageDialog(AddRecordingTunerDialog.this,
- "Please provide a recording center frequency (1 Hz to 2.14 GHz)",
- "Center Frequency Required",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- mLog.info("Adding recording tuner = frequency [" + frequency +
- "] recording [" + mSelectedRecording.getAbsolutePath() + "]");
-
-
- try
- {
- RecordingTunerConfiguration config = RecordingTunerConfiguration.create();
- config.setFrequency(frequency);
- config.setPath(mSelectedRecording.getAbsolutePath());
- mTunerConfigurationManager.addTunerConfiguration(config);
- DiscoveredRecordingTuner discoveredRecordingTuner = new DiscoveredRecordingTuner(mUserPreferences, config);
- mDiscoveredTunerModel.addDiscoveredTuner(discoveredRecordingTuner);
- }
- catch(Exception ex)
- {
- mLog.error("Error adding recording tuner", ex);
- }
-
- AddRecordingTunerDialog.this.setVisible(false);
- });
- content.add(mAddButton, "grow,push");
-
- mCancelButton = new JButton("Cancel");
- mCancelButton.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- AddRecordingTunerDialog.this.setVisible(false);
- }
- });
- content.add(mCancelButton, "grow,push");
-
- setContentPane(content);
}
- private long getFrequency()
+ private void selectFile()
{
- String text = mFrequencyTextField.getText();
+ FileChooser fileChooser = new FileChooser();
+ fileChooser.setTitle("Select Recording File");
+ String lastBrowsedDirectory = SystemProperties.getInstance().get(LAST_FILE_BROWSE_LOCATION_KEY, "");
+ File browseDirectory = (lastBrowsedDirectory != null && !lastBrowsedDirectory.isEmpty()) ?
+ new File(lastBrowsedDirectory) : mUserPreferences.getDirectoryPreference().getDefaultRecordingDirectory().toFile();
- if(text != null && !text.isEmpty())
+ if(browseDirectory.isDirectory())
{
- try
+ fileChooser.setInitialDirectory(browseDirectory);
+ }
+
+ FileChooser.ExtensionFilter basebandFilter = new FileChooser.ExtensionFilter("Baseband Recordings (*.wav, *.iq)",
+ "*.wav", "*." + SDRSharpIQRecording.FILE_EXTENSION);
+ fileChooser.getExtensionFilters().addAll(basebandFilter,
+ new FileChooser.ExtensionFilter("Wave Recordings (*.wav)", "*.wav"),
+ new FileChooser.ExtensionFilter("SDRSharp I/Q Recordings (*.iq)", "*." + SDRSharpIQRecording.FILE_EXTENSION));
+ fileChooser.setSelectedExtensionFilter(basebandFilter);
+
+ File selected = fileChooser.showOpenDialog(getDialogPane().getScene().getWindow());
+
+ if(selected == null)
+ {
+ return;
+ }
+
+ if(selected.getParentFile() != null)
+ {
+ SystemProperties.getInstance().set(LAST_FILE_BROWSE_LOCATION_KEY, selected.getParentFile().getAbsolutePath());
+ }
+
+ mSelectedRecording = selected;
+
+ if(SDRSharpIQRecording.hasIQExtension(selected))
+ {
+ SDRSharpIQRecording iqRecording = SDRSharpIQRecording.parse(selected);
+
+ if(iqRecording == null)
{
- return Long.parseLong(text);
+ Alert alert = new Alert(Alert.AlertType.ERROR, "Unable to determine the sample rate and center " +
+ "frequency from the I/Q recording file name.\n\nExpected format: " +
+ "yyyyMMdd-HHmmss_label_TUNER_123456789Hz_10MSps.iq");
+ alert.initOwner(getDialogPane().getScene().getWindow());
+ alert.setTitle("Unsupported I/Q Recording");
+ alert.setHeaderText(null);
+ alert.showAndWait();
+ mSelectedRecording = null;
}
- catch(Exception e)
+ else
{
- //Do nothing, we couldn't parse the frequency value
+ mLog.info("Selected " + iqRecording);
+
+ if(mFrequencyField.getText() == null || mFrequencyField.getText().isEmpty())
+ {
+ mFrequencyField.setText(FrequencyEntry.format(iqRecording.getCenterFrequency()));
+ }
+ }
+ }
+ else if(mFrequencyField.getText() == null || mFrequencyField.getText().isEmpty())
+ {
+ Matcher m = TUNER_RECORDING_PATTERN.matcher(selected.getName());
+
+ if(m.matches() && !m.group(1).isEmpty())
+ {
+ try
+ {
+ mFrequencyField.setText(FrequencyEntry.format(Long.parseLong(m.group(1))));
+ }
+ catch(NumberFormatException nfe)
+ {
+ //Leave the frequency for the user to enter
+ }
}
}
- return 0l;
+ mRecordingFileLabel.setText(mSelectedRecording != null ? mSelectedRecording.getName() : SELECT_A_FILE);
+ validate();
+ }
+
+ private void validate()
+ {
+ String error = null;
+
+ if(mSelectedRecording == null)
+ {
+ error = "Select a recording file";
+ }
+ else
+ {
+ Long frequency = FrequencyEntry.parse(mFrequencyField.getText());
+
+ if(frequency == null || frequency <= 0 || frequency > Integer.MAX_VALUE)
+ {
+ error = "Enter the recording's center frequency, up to 2147.483647 MHz";
+ }
+ }
+
+ mValidationLabel.setText(error == null ? "" : error);
+ mAddButton.setDisable(error != null);
+ }
+
+ private void addTuner()
+ {
+ long frequency = FrequencyEntry.parse(mFrequencyField.getText());
+ mLog.info("Adding recording tuner = frequency [" + frequency + "] recording [" +
+ mSelectedRecording.getAbsolutePath() + "]");
+
+ try
+ {
+ RecordingTunerConfiguration config = RecordingTunerConfiguration.create();
+ config.setFrequency(frequency);
+ config.setPath(mSelectedRecording.getAbsolutePath());
+ mTunerConfigurationManager.addTunerConfiguration(config);
+ DiscoveredRecordingTuner discoveredRecordingTuner = new DiscoveredRecordingTuner(mUserPreferences, config);
+ mDiscoveredTunerModel.addDiscoveredTuner(discoveredRecordingTuner);
+ }
+ catch(Exception ex)
+ {
+ mLog.error("Error adding recording tuner", ex);
+ }
}
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/recording/RecordingTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/recording/RecordingTunerEditor.java
index 5d0a588d4..28510eed1 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/recording/RecordingTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/recording/RecordingTunerEditor.java
@@ -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
@@ -22,39 +22,28 @@ 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.ui.TunerEditor;
-import net.miginfocom.swing.MigLayout;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.swing.JLabel;
-import javax.swing.JSeparator;
+import javafx.scene.control.Label;
/**
- * Recording tuner configuration editor
+ * Recording tuner editor. Shows the recording file and the frequency of the recording.
*/
public class RecordingTunerEditor extends TunerEditor
{
- private static final long serialVersionUID = 1L;
- private final static Logger mLog = LoggerFactory.getLogger(RecordingTunerEditor.class);
- private JLabel mRecordingPath;
+ private final Label mRecordingPath = new Label();
/**
* Constructs an instance
- * @param userPreferences for wide-band recordings
+ * @param userPreferences for settings
* @param tunerManager for saving configurations
- * @param discoveredTuner for this configuration
+ * @param discoveredTuner to edit
*/
public RecordingTunerEditor(UserPreferences userPreferences, TunerManager tunerManager, DiscoveredTuner discoveredTuner)
{
super(userPreferences, tunerManager, discoveredTuner);
- init();
- tunerStatusUpdated();
- }
-
- @Override
- public void setTunerLockState(boolean locked)
- {
- getFrequencyPanel().updateControls();
+ mRecordingPath.setWrapText(true);
+ mRecordingPath.getStyleClass().add("tuner-value-label");
+ getTuningSection().addRow("File", mRecordingPath);
+ refresh();
}
@Override
@@ -72,62 +61,7 @@ public class RecordingTunerEditor extends TunerEditor
{
- private static final Logger mLog = LoggerFactory.getLogger(RTL2832TunerEditor.class);
- private static final long serialVersionUID = 1L;
- private JButton mTunerInfoButton;
- private JToggleButton mBiasTButton;
- private JComboBox mSampleRateCombo;
- private JToggleButton mAgcToggleButton;
- private JComboBox mGainCombo;
- private JLabel mIFGainLabel;
- private JComboBox mIFGainCombo;
+ private ComboBox mSampleRateCombo;
+ private CheckBox mBiasTCheckBox;
+ private CheckBox mAgcCheckBox;
+ private ComboBox mGainCombo;
+ private Label mIFGainLabel;
+ private ComboBox mIFGainCombo;
/**
* Constructs an instance
@@ -67,7 +58,7 @@ public class RTL2832TunerEditor extends TunerEditor gainModel = new DefaultComboBoxModel<>();
-
- if(hasTuner())
- {
- RTL2832TunerController controller = getTuner().getController();
-
- if(controller.hasGainControl())
- {
- for(int gain : controller.getTunerGains())
- {
- gainModel.addElement(new Gain(gain));
- }
- }
- }
-
- getGainCombo().setModel(gainModel);
-
- boolean e4k = isE4K();
- getIFGainLabel().setVisible(e4k);
- getIFGainCombo().setVisible(e4k);
-
- if(hasTuner() && hasConfiguration())
- {
- RTL2832TunerConfiguration config = getConfiguration();
- getBiasTButton().setEnabled(true);
- getBiasTButton().setSelected(config.isBiasT());
- getTunerInfoButton().setEnabled(true);
- getSampleRateCombo().setEnabled(true);
- getSampleRateCombo().setSelectedItem(config.getSampleRate());
- RTL2832TunerController controller = getTuner().getController();
- //The FC2580 always uses its internal AGC and the FC0012 doesn't support AGC
- boolean agc = controller.hasGainControl() ? controller.hasTunerAGC() && config.isAGC() : true;
- getAgcToggleButton().setEnabled(controller.hasTunerAGC());
- getAgcToggleButton().setSelected(agc);
- getAgcToggleButton().setToolTipText(getAgcToolTip(controller));
- getGainCombo().setEnabled(!agc && gainModel.getSize() > 0);
- getGainCombo().setSelectedItem(new Gain(getTuner().getController().getClosestTunerGain(config.getGain())));
-
- if(e4k && config instanceof E4KTunerConfiguration e4kConfig)
- {
- getIFGainCombo().setEnabled(true);
- getIFGainCombo().setSelectedItem(e4kConfig.getIFGainDb());
- }
- }
- else
- {
- getBiasTButton().setEnabled(false);
- getBiasTButton().setSelected(false);
- getTunerInfoButton().setEnabled(false);
- getSampleRateCombo().setEnabled(false);
- getAgcToggleButton().setEnabled(false);
- getGainCombo().setEnabled(false);
- getIFGainCombo().setEnabled(false);
- }
-
- updateSampleRateToolTip();
-
- setLoading(false);
- }
-
- /**
- * Bias-T toggle button
- */
- private JToggleButton getBiasTButton()
- {
- if(mBiasTButton == null)
- {
- mBiasTButton = new JToggleButton("Bias-T");
- mBiasTButton.setEnabled(false);
- mBiasTButton.addActionListener(e -> {
- if(!isLoading())
- {
- getTuner().getController().setBiasT(mBiasTButton.isSelected());
- save();
- }
- });
- }
-
- return mBiasTButton;
- }
-
- /**
- * Button that provides tuner information
- */
- private JButton getTunerInfoButton()
- {
- if(mTunerInfoButton == null)
- {
- mTunerInfoButton = new JButton("Info");
- mTunerInfoButton.setEnabled(false);
- mTunerInfoButton.addActionListener(e -> JOptionPane.showMessageDialog(RTL2832TunerEditor.this,
- getTunerInfo(), "Tuner Info", JOptionPane.INFORMATION_MESSAGE));
- }
-
- return mTunerInfoButton;
- }
-
- /**
- * Applies the current AGC and gain settings to the tuner and saves the configuration.
- */
- private void applyGain()
- {
- if(isLoading() || !hasTuner())
- {
- return;
- }
-
- boolean agc = getAgcToggleButton().isSelected();
- Gain gain = (Gain)getGainCombo().getSelectedItem();
- getGainCombo().setEnabled(!agc && getGainCombo().getItemCount() > 0);
-
- try
- {
- getTuner().getController().setGain(agc, gain != null ? gain.value() : getConfiguration().getGain());
- save();
- }
- catch(SourceException se)
- {
- JOptionPane.showMessageDialog(RTL2832TunerEditor.this, getLogPrefix() +
- "couldn't apply the gain setting - " + se.getLocalizedMessage());
- mLog.error(getLogPrefix() + "couldn't apply gain setting", se);
- }
- }
-
- /**
- * Tool tip for the AGC button that explains when the tuner doesn't support switching AGC.
- */
- private static String getAgcToolTip(RTL2832TunerController controller)
- {
- if(!controller.hasGainControl())
- {
- return "The " + controller.getTunerType().getLabel() + " tuner always uses its automatic gain control (AGC)";
- }
- else if(!controller.hasTunerAGC())
- {
- return "The " + controller.getTunerType().getLabel() + " tuner doesn't support automatic gain control (AGC)";
- }
-
- return "Turn on the tuner's automatic gain control (AGC)";
- }
-
- private JToggleButton getAgcToggleButton()
- {
- if(mAgcToggleButton == null)
- {
- mAgcToggleButton = new JToggleButton("AGC");
- mAgcToggleButton.setEnabled(false);
- mAgcToggleButton.setToolTipText("Turn on the tuner's automatic gain control (AGC)");
- mAgcToggleButton.addActionListener(e -> applyGain());
- }
-
- return mAgcToggleButton;
- }
-
- private JComboBox getGainCombo()
- {
- if(mGainCombo == null)
- {
- mGainCombo = new JComboBox<>();
- mGainCombo.setEnabled(false);
- mGainCombo.setToolTipText("Tuner gain. Turn off AGC to enable adjustment.");
- mGainCombo.addActionListener(e -> applyGain());
- }
-
- return mGainCombo;
- }
-
- private JLabel getIFGainLabel()
- {
- if(mIFGainLabel == null)
- {
- mIFGainLabel = new JLabel("IF Gain (dB):");
- }
-
- return mIFGainLabel;
- }
-
- private JComboBox getIFGainCombo()
- {
- if(mIFGainCombo == null)
- {
- mIFGainCombo = new JComboBox<>();
-
- for(int gain = RTL2832TunerController.E4K_IF_GAIN_MINIMUM; gain <= RTL2832TunerController.E4K_IF_GAIN_MAXIMUM; gain++)
- {
- mIFGainCombo.addItem(gain);
- }
-
- mIFGainCombo.setEnabled(false);
- mIFGainCombo.setToolTipText("E4000 IF gain, distributed across the six IF gain stages");
- mIFGainCombo.addActionListener(e ->
- {
- Integer gain = (Integer)mIFGainCombo.getSelectedItem();
-
- if(!isLoading() && hasTuner() && gain != null)
- {
- try
- {
- getTuner().getController().setE4KIFGain(gain);
- save();
- }
- catch(SourceException se)
- {
- JOptionPane.showMessageDialog(RTL2832TunerEditor.this, getLogPrefix() +
- "couldn't apply the IF gain setting - " + se.getLocalizedMessage());
- mLog.error(getLogPrefix() + "couldn't apply IF gain setting", se);
- }
- }
- });
- }
-
- return mIFGainCombo;
- }
-
- private JComboBox getSampleRateCombo()
- {
- if(mSampleRateCombo == null)
- {
- mSampleRateCombo = new JComboBox<>(SampleRate.values());
- mSampleRateCombo.setEnabled(false);
- mSampleRateCombo.addActionListener(e ->
- {
- if(!isLoading())
- {
- SampleRate sampleRate = (SampleRate) mSampleRateCombo.getSelectedItem();
-
- try
- {
- getTuner().getController().setSampleRate(sampleRate);
- //Adjust the min/max values for the sample rate.
- adjustForSampleRate(sampleRate.getRate());
- save();
- }
- catch(SourceException se)
- {
- JOptionPane.showMessageDialog(RTL2832TunerEditor.this,
- getLogPrefix() + "couldn't apply the sample rate setting [" +
- sampleRate.getLabel() + "] " + se.getLocalizedMessage());
-
- mLog.error(getLogPrefix() + "couldn't apply sample rate setting [" + sampleRate.getLabel() +
- "]", se);
- }
- }
- });
- }
-
- return mSampleRateCombo;
- }
-
- /**
- * 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.");
- }
- else if(hasTuner())
- {
- getSampleRateCombo().setToolTipText("Select a sample rate for the tuner");
- }
- else
- {
- getSampleRateCombo().setToolTipText("No tuner available");
- }
- }
-
- @Override
- public void setTunerLockState(boolean locked)
- {
- getFrequencyPanel().updateControls();
- getSampleRateCombo().setEnabled(!locked);
- updateSampleRateToolTip();
- }
-
- private String getTunerInfo()
+ protected String getTunerInfo()
{
StringBuilder sb = new StringBuilder();
RTL2832TunerController.Descriptor descriptor = getTuner().getController().getDescriptor();
@@ -463,28 +129,242 @@ public class RTL2832TunerEditor extends TunerEditor {
+ if(!isLoading() && hasTuner())
+ {
+ getTuner().getController().setBiasT(mBiasTCheckBox.isSelected());
+ save();
+ }
+ });
+ }
+
+ return mBiasTCheckBox;
+ }
+
+ /**
+ * Applies the current AGC and gain settings to the tuner and saves the configuration.
+ */
+ private void applyGain()
+ {
+ if(isLoading() || !hasTuner())
+ {
+ return;
+ }
+
+ boolean agc = getAgcCheckBox().isSelected();
+ Gain gain = getGainCombo().getValue();
+ getGainCombo().setDisable(agc || getGainCombo().getItems().isEmpty());
+
+ if(applyToTuner("gain", () -> getTuner().getController().setGain(agc,
+ gain != null ? gain.value() : getConfiguration().getGain())))
+ {
+ save();
+ }
+ }
+
+ /**
+ * Tool tip for the AGC control that explains when the tuner doesn't support switching AGC.
+ */
+ private static String getAgcToolTip(RTL2832TunerController controller)
+ {
+ if(!controller.hasGainControl())
+ {
+ return "The " + controller.getTunerType().getLabel() + " tuner always uses its automatic gain control (AGC)";
+ }
+ else if(!controller.hasTunerAGC())
+ {
+ return "The " + controller.getTunerType().getLabel() + " tuner doesn't support automatic gain control (AGC)";
+ }
+
+ return "Turn on the tuner's automatic gain control (AGC)";
+ }
+
+ private CheckBox getAgcCheckBox()
+ {
+ if(mAgcCheckBox == null)
+ {
+ mAgcCheckBox = new CheckBox("AGC");
+ mAgcCheckBox.setDisable(true);
+ mAgcCheckBox.setTooltip(new Tooltip("Turn on the tuner's automatic gain control (AGC)"));
+ mAgcCheckBox.setOnAction(e -> applyGain());
+ }
+
+ return mAgcCheckBox;
+ }
+
+ private ComboBox getGainCombo()
+ {
+ if(mGainCombo == null)
+ {
+ mGainCombo = new ComboBox<>();
+ mGainCombo.setMaxWidth(Double.MAX_VALUE);
+ mGainCombo.setDisable(true);
+ mGainCombo.setTooltip(new Tooltip("Tuner gain. Turn off AGC to enable adjustment."));
+ mGainCombo.setOnAction(e -> applyGain());
+ }
+
+ return mGainCombo;
+ }
+
+ private ComboBox getIFGainCombo()
+ {
+ if(mIFGainCombo == null)
+ {
+ mIFGainCombo = new ComboBox<>();
+ mIFGainCombo.setMaxWidth(Double.MAX_VALUE);
+
+ for(int gain = RTL2832TunerController.E4K_IF_GAIN_MINIMUM; gain <= RTL2832TunerController.E4K_IF_GAIN_MAXIMUM; gain++)
+ {
+ mIFGainCombo.getItems().add(gain);
+ }
+
+ mIFGainCombo.setDisable(true);
+ mIFGainCombo.setTooltip(new Tooltip("E4000 IF gain, distributed across the six IF gain stages"));
+ mIFGainCombo.setOnAction(e -> {
+ Integer gain = mIFGainCombo.getValue();
+
+ if(!isLoading() && hasTuner() && gain != null &&
+ applyToTuner("IF gain", () -> getTuner().getController().setE4KIFGain(gain)))
+ {
+ save();
+ }
+ });
+ }
+
+ return mIFGainCombo;
+ }
+
+ private ComboBox getSampleRateCombo()
+ {
+ if(mSampleRateCombo == null)
+ {
+ mSampleRateCombo = new ComboBox<>(FXCollections.observableArrayList(SampleRate.values()));
+ mSampleRateCombo.setMaxWidth(Double.MAX_VALUE);
+ mSampleRateCombo.setDisable(true);
+ mSampleRateCombo.setOnAction(e -> {
+ SampleRate sampleRate = mSampleRateCombo.getValue();
+
+ if(!isLoading() && hasTuner() && sampleRate != null &&
+ applyToTuner("sample rate [" + sampleRate.getLabel() + "]",
+ () -> getTuner().getController().setSampleRate(sampleRate)))
+ {
+ //Adjust the min/max values for the sample rate.
+ adjustForSampleRate(sampleRate.getRate());
+ save();
+ }
+ });
+ }
+
+ return mSampleRateCombo;
+ }
+
@Override
public void save()
{
if(hasConfiguration() && !isLoading())
{
RTL2832TunerConfiguration config = getConfiguration();
+ saveCommonSettings(config);
config.setBiasT(getTuner().getController().isBiasT());
- config.setFrequency(getFrequencyControl().getFrequency());
- config.setMinimumFrequency(getMinimumFrequencyTextField().getFrequency());
- config.setMaximumFrequency(getMaximumFrequencyTextField().getFrequency());
- double value = ((SpinnerNumberModel)getFrequencyCorrectionSpinner().getModel()).getNumber().doubleValue();
- config.setFrequencyCorrection(value);
- config.setAutoPPMCorrectionEnabled(getAutoPPMCheckBox().isSelected());
- config.setSampleRate((SampleRate)getSampleRateCombo().getSelectedItem());
- config.setAGC(getAgcToggleButton().isSelected());
+ config.setSampleRate(getSampleRateCombo().getValue());
+ config.setAGC(getAgcCheckBox().isSelected());
- if(getGainCombo().getSelectedItem() instanceof Gain gain)
+ if(getGainCombo().getValue() instanceof Gain gain)
{
config.setGain(gain.value());
}
- if(config instanceof E4KTunerConfiguration e4k && getIFGainCombo().getSelectedItem() instanceof Integer ifGain)
+ if(config instanceof E4KTunerConfiguration e4k && getIFGainCombo().getValue() instanceof Integer ifGain)
{
e4k.setIFGainDb(ifGain);
}
diff --git a/src/main/java/io/github/dsheirer/source/tuner/rtl/RTL2832UnknownTunerEditor.java b/src/main/java/io/github/dsheirer/source/tuner/rtl/RTL2832UnknownTunerEditor.java
index c8c2c12bb..fa8a7b31f 100644
--- a/src/main/java/io/github/dsheirer/source/tuner/rtl/RTL2832UnknownTunerEditor.java
+++ b/src/main/java/io/github/dsheirer/source/tuner/rtl/RTL2832UnknownTunerEditor.java
@@ -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
@@ -16,7 +16,6 @@
* along with this program. If not, see
* ****************************************************************************
*/
-
package io.github.dsheirer.source.tuner.rtl;
import io.github.dsheirer.preference.UserPreferences;
@@ -24,46 +23,32 @@ import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
import io.github.dsheirer.source.tuner.manager.TunerManager;
import io.github.dsheirer.source.tuner.rtl.r8x.R8xTunerConfiguration;
import io.github.dsheirer.source.tuner.ui.TunerEditor;
-import net.miginfocom.swing.MigLayout;
-
-import javax.swing.JLabel;
-import javax.swing.JSeparator;
+import io.github.dsheirer.source.tuner.ui.TunerSection;
+import javafx.scene.control.Label;
/**
- * Tuner editor for RTL2832 tuner that has not been started, or for an unknown tuner type
+ * Editor for an RTL-2832 with an embedded tuner type that sdrtrunk doesn't support. Only shows the tuner status.
*/
public class RTL2832UnknownTunerEditor extends TunerEditor
{
- /**
- * Constructs an instance
- *
- * @param userPreferences for starting wide-band recorders
- * @param tunerManager for requesting configuration saves.
- * @param discoveredTuner that is not started, or that doesn't have a recognized tuner type
- */
+ private final Label mUniqueIdLabel = new Label();
+
public RTL2832UnknownTunerEditor(UserPreferences userPreferences, TunerManager tunerManager,
DiscoveredTuner discoveredTuner)
{
super(userPreferences, tunerManager, discoveredTuner);
- init();
- tunerStatusUpdated();
+ TunerSection section = addSection("Unsupported Tuner");
+ Label message = new Label("This RTL-2832 device has an embedded tuner type that isn't supported.");
+ message.setWrapText(true);
+ section.addFullRow(message);
+ section.addRow("ID", mUniqueIdLabel);
+ refresh();
}
- private void init()
+ @Override
+ protected boolean hasTuningControls()
{
- setLayout(new MigLayout("fill,wrap 3", "[right][grow,fill][fill]",
- "[][][][][][][][][][][][][][][][grow]"));
-
- add(new JLabel("Tuner:"));
- add(getTunerIdLabel(), "wrap");
-
- add(new JLabel("Status:"));
- add(getTunerStatusLabel(), "wrap");
-
- add(getButtonPanel(), "span,align left");
-
- add(new JSeparator(), "span,growx,push");
-
+ return false;
}
@Override
@@ -89,22 +74,6 @@ public class RTL2832UnknownTunerEditor extends TunerEditor
* ****************************************************************************
*/
-
package io.github.dsheirer.source.tuner.sdrplay;
import io.github.dsheirer.preference.UserPreferences;
-import io.github.dsheirer.source.tuner.manager.TunerManager;
import io.github.dsheirer.sdrplay.Tuner;
+import io.github.dsheirer.source.tuner.manager.TunerManager;
+import io.github.dsheirer.source.tuner.ui.GainSlider;
import io.github.dsheirer.source.tuner.ui.TunerEditor;
+import io.github.dsheirer.source.tuner.ui.TunerSection;
import io.github.dsheirer.util.ThreadPool;
-import java.awt.Color;
-import java.awt.EventQueue;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import net.miginfocom.swing.MigLayout;
+import javafx.css.PseudoClass;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.Tooltip;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Region;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.JButton;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JSlider;
-import javax.swing.JToggleButton;
-
/**
- * Abstract RSP tuner editor
+ * Base SDRPlay RSP tuner editor. Provides the sample rate control, the gain section (LNA state, IF gain reduction,
+ * IF AGC, gain readout and overload indicator) and helpers for binding the model specific option check boxes and
+ * choices to the device.
*/
-public abstract class RspTunerEditor extends TunerEditor implements ITunerStatusListener
+public abstract class RspTunerEditor extends TunerEditor
+ implements ITunerStatusListener
{
- private Logger mLog = LoggerFactory.getLogger(RspTunerEditor.class);
- protected static final String MANUAL = "Manual";
- protected static final String AUTOMATIC = "Automatic";
- private JToggleButton mAgcButton;
- private JLabel mGainValueLabel;
- private LnaSlider mLNASlider;
- private IfGainSlider mIfGainSlider;
- private JButton mGainOverloadButton;
- private JPanel mGainPanel;
- private AtomicBoolean mGainOverloadAlert = new AtomicBoolean();
+ private static final Logger mLog = LoggerFactory.getLogger(RspTunerEditor.class);
+ private static final PseudoClass OVERLOAD = PseudoClass.getPseudoClass("overload");
+ private static final int IF_GAIN_SLIDER_MAX = 39;
+ private ComboBox mSampleRateCombo;
+ private CheckBox mAgcCheckBox;
+ private Label mGainValueLabel;
+ private Label mGainOverloadLabel;
+ private GainSlider mLNASlider;
+ private GainSlider mIfGainSlider;
+ private Label mLnaLabel;
+ private Label mIfGainLabel;
+ private boolean mGainOverloadAlert;
+ private final List