mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-19 03:57:26 -05:00
* Popout configuration panel (top-left of display) * Themed color support * Reworked signal averating/smoothing * Optional decibel overlay with corrected decibel calculations * Integrated noise floor slider in channel view * Traffic channel overlays * Popup channel information when hovering over playlist channels. * Removes legacy swing components. Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
@@ -46,10 +46,12 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
private static final String FRAME_RATE_PROPERTY = "spectral.display.frame.rate";
|
||||
|
||||
//The Cosine and Hann windows seem to offer the best spectral display with minimal bin leakage/smearing
|
||||
private WindowType mWindowType = WindowType.BLACKMAN_HARRIS_7;
|
||||
private volatile WindowType mWindowType = WindowType.BLACKMAN_HARRIS_7;
|
||||
private volatile boolean mWindowChanged = true;
|
||||
private volatile boolean mUnityGainWindow = false;
|
||||
private float[] mWindow;
|
||||
private DFTSize mDFTSize = DFTSize.FFT04096;
|
||||
private DFTSize mNewDFTSize = DFTSize.FFT04096;
|
||||
private volatile DFTSize mNewDFTSize = DFTSize.FFT04096;
|
||||
private FloatFFT_1D mFFT = new FloatFFT_1D(mDFTSize.getSize());
|
||||
private int mFrameRate;
|
||||
private AtomicBoolean mRunning = new AtomicBoolean();
|
||||
@@ -62,13 +64,14 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
public ComplexDftProcessor()
|
||||
{
|
||||
mFrameRate = SystemProperties.getInstance().get(FRAME_RATE_PROPERTY, 20);
|
||||
setWindowType(mWindowType);
|
||||
mWindow = createWindow(mWindowType, mDFTSize.getSize(), mUnityGainWindow);
|
||||
start();
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
stop();
|
||||
mExecutorService.shutdown();
|
||||
|
||||
mListeners.clear();
|
||||
mWindow = null;
|
||||
@@ -79,15 +82,87 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
return mWindowType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a window type change. The processor applies the change before the next calculation.
|
||||
*/
|
||||
public void setWindowType(WindowType windowType)
|
||||
{
|
||||
mWindowType = windowType;
|
||||
updateWindow();
|
||||
if(windowType != null)
|
||||
{
|
||||
mWindowType = windowType;
|
||||
mWindowChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWindow()
|
||||
/**
|
||||
* Scales the window to unity coherent gain, so that a full scale complex tone centered in a bin has a DFT
|
||||
* magnitude equal to the DFT size, regardless of the window type. Use this with a full scale (dBFS) converter.
|
||||
* Defaults to false, which leaves the window coefficients unscaled.
|
||||
*/
|
||||
public void setUnityGainWindow(boolean unityGain)
|
||||
{
|
||||
mWindow = WindowFactory.getWindow(mWindowType, mDFTSize.getSize() * 2);
|
||||
mUnityGainWindow = unityGain;
|
||||
mWindowChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the window coefficients for interleaved complex samples, with the same coefficient applied to the I
|
||||
* and Q values of each sample.
|
||||
* @param type of window. Kaiser windows need extra parameters, so Kaiser uses a Blackman-Harris 7 window.
|
||||
* @param size of the DFT in complex samples
|
||||
* @param unityGain to scale the window so the coefficients sum to the DFT size (unity coherent gain)
|
||||
* @return interleaved window coefficients, twice the DFT size
|
||||
*/
|
||||
public static float[] createWindow(WindowType type, int size, boolean unityGain)
|
||||
{
|
||||
if(type == null || type == WindowType.KAISER)
|
||||
{
|
||||
type = WindowType.BLACKMAN_HARRIS_7;
|
||||
}
|
||||
|
||||
float[] window = WindowFactory.getWindow(type, size);
|
||||
double sum = 0.0;
|
||||
|
||||
for(float coefficient: window)
|
||||
{
|
||||
sum += coefficient;
|
||||
}
|
||||
|
||||
float scale = (unityGain && sum > 0) ? (float)(size / sum) : 1.0f;
|
||||
float[] interleaved = new float[size * 2];
|
||||
|
||||
for(int x = 0; x < size; x++)
|
||||
{
|
||||
interleaved[2 * x] = window[x] * scale;
|
||||
interleaved[2 * x + 1] = window[x] * scale;
|
||||
}
|
||||
|
||||
return interleaved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equivalent noise bandwidth of the window type, in DFT bins. This is how much wider the window's noise
|
||||
* bandwidth is than one bin: 1.0 for no window and about 2 to 4 for the low leakage windows.
|
||||
*/
|
||||
public static double getNoiseBandwidth(WindowType type)
|
||||
{
|
||||
if(type == null || type == WindowType.KAISER)
|
||||
{
|
||||
type = WindowType.BLACKMAN_HARRIS_7;
|
||||
}
|
||||
|
||||
int size = 4096;
|
||||
float[] window = WindowFactory.getWindow(type, size);
|
||||
double sum = 0.0;
|
||||
double sumSquares = 0.0;
|
||||
|
||||
for(float coefficient: window)
|
||||
{
|
||||
sum += coefficient;
|
||||
sumSquares += coefficient * coefficient;
|
||||
}
|
||||
|
||||
return sum > 0 ? size * sumSquares / (sum * sum) : 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +185,15 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
}
|
||||
|
||||
public void setFrameRate(int framesPerSecond)
|
||||
{
|
||||
setFrameRateNoSave(framesPerSecond);
|
||||
SystemProperties.getInstance().set(FRAME_RATE_PROPERTY, mFrameRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the frame rate without saving it as the default frame rate setting.
|
||||
*/
|
||||
public void setFrameRateNoSave(int framesPerSecond)
|
||||
{
|
||||
if(framesPerSecond < 1 || framesPerSecond > 1000)
|
||||
{
|
||||
@@ -118,7 +202,6 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
}
|
||||
|
||||
mFrameRate = framesPerSecond;
|
||||
SystemProperties.getInstance().set(FRAME_RATE_PROPERTY, mFrameRate);
|
||||
restart();
|
||||
}
|
||||
|
||||
@@ -176,6 +259,11 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
{
|
||||
//If this throws an IO exception, the buffer queue is (temporarily) empty and we return from the method
|
||||
float[] samples = mDftBufferManager.get(mDFTSize.getSize());
|
||||
if(mWindow == null || mWindow.length != samples.length)
|
||||
{
|
||||
mWindow = createWindow(mWindowType, mDFTSize.getSize(), mUnityGainWindow);
|
||||
}
|
||||
|
||||
WindowFactory.apply(mWindow, samples);
|
||||
mFFT.complexForward(samples);
|
||||
mPreviousSamples = samples;
|
||||
@@ -237,7 +325,7 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a queued FFT width change request and applies it. This
|
||||
* Checks for a queued FFT width or window change request and applies it. This
|
||||
* method will only be accessed by the scheduled executor that gains
|
||||
* access to run a calculate method, thus providing thread safety.
|
||||
*/
|
||||
@@ -246,9 +334,15 @@ public class ComplexDftProcessor<T extends INativeBuffer> implements Listener<T>
|
||||
if(mNewDFTSize.getSize() != mDFTSize.getSize())
|
||||
{
|
||||
mDFTSize = mNewDFTSize;
|
||||
updateWindow();
|
||||
mWindowChanged = true;
|
||||
mFFT = new FloatFFT_1D(mDFTSize.getSize());
|
||||
}
|
||||
|
||||
if(mWindowChanged)
|
||||
{
|
||||
mWindowChanged = false;
|
||||
mWindow = createWindow(mWindowType, mDFTSize.getSize(), mUnityGainWindow);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearBuffer()
|
||||
|
||||
@@ -18,7 +18,10 @@
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.gui.spectrum.SpectralDisplayPanel;
|
||||
import io.github.dsheirer.gui.spectrum.TunerSpectralDisplay;
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.util.ThreadPool;
|
||||
import jiconfont.icons.font_awesome.FontAwesome;
|
||||
import io.github.dsheirer.gui.theme.ThemedFontIcon;
|
||||
|
||||
@@ -44,8 +47,8 @@ public class DisableSpectrumWaterfallMenuItem extends JMenuItem
|
||||
|
||||
addActionListener(e -> {
|
||||
SystemProperties properties = SystemProperties.getInstance();
|
||||
properties.set(SpectralDisplayPanel.SPECTRAL_DISPLAY_ENABLED, false);
|
||||
mSpectralDisplayPanel.clearTuner();
|
||||
properties.set(TunerSpectralDisplay.SPECTRAL_DISPLAY_ENABLED, false);
|
||||
ThreadPool.CACHED.submit(() -> mSpectralDisplayPanel.clearTuner());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,608 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.settings.ColorSetting;
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingChangeListener;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.DecimalFormat;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
* Frequency overlay panel.
|
||||
*/
|
||||
public class FrequencyOverlayPanel extends JPanel implements ISourceEventProcessor, SettingChangeListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final DecimalFormat PPM_FORMATTER = new DecimalFormat( "#.0" );
|
||||
private final static RenderingHints RENDERING_HINTS = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
static
|
||||
{
|
||||
RENDERING_HINTS.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
}
|
||||
|
||||
private static DecimalFormat CURSOR_FORMAT = new DecimalFormat("000.00000");
|
||||
private long mFrequency = 0;
|
||||
private int mBandwidth = 0;
|
||||
private int mChannelBandwidth = 0;
|
||||
|
||||
private long mEstimatedCarrierOffsetFrequency = 0;
|
||||
private Point mCursorLocation = new Point(0, 0);
|
||||
private boolean mCursorVisible = false;
|
||||
|
||||
private DFTSize mDFTSize = DFTSize.FFT04096;
|
||||
|
||||
/**
|
||||
* Colors used by this component
|
||||
*/
|
||||
private Color mColorSpectrumBackground;
|
||||
private Color mColorSpectrumCursor;
|
||||
private Color mColorSpectrumLine;
|
||||
|
||||
//Defines the offset at the bottom of the spectral display to account for
|
||||
//the frequency labels
|
||||
private double mSpectrumInset = 20.0d;
|
||||
private LabelSizeManager mLabelSizeMonitor = new LabelSizeManager();
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
/**
|
||||
* Translucent overlay panel for displaying channel configurations,
|
||||
* processing channels, selected channels, frequency labels and lines, and
|
||||
* a cursor with a frequency readout.
|
||||
*/
|
||||
public FrequencyOverlayPanel(SettingsManager settingsManager)
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
|
||||
if(mSettingsManager != null)
|
||||
{
|
||||
mSettingsManager.addListener(this);
|
||||
}
|
||||
|
||||
addComponentListener(mLabelSizeMonitor);
|
||||
|
||||
//Set the background transparent, so the spectrum display can be seen
|
||||
setOpaque(false);
|
||||
|
||||
//Fetch color settings from settings manager
|
||||
setColors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the estimated carrier offset of the channel's signal
|
||||
* @param estimatedCarrierOffsetFrequency current setting. Set to 0 to reset.
|
||||
*/
|
||||
public void setEstimatedCarrierOffsetFrequency(long estimatedCarrierOffsetFrequency)
|
||||
{
|
||||
mEstimatedCarrierOffsetFrequency = estimatedCarrierOffsetFrequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bandwidth of the channel.
|
||||
* @param channelBandwidth in Hertz
|
||||
*/
|
||||
public void setChannelBandwidth(int channelBandwidth)
|
||||
{
|
||||
mChannelBandwidth = channelBandwidth;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
if(mSettingsManager != null)
|
||||
{
|
||||
mSettingsManager.removeListener(this);
|
||||
}
|
||||
|
||||
mSettingsManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/changes the DFT bin size
|
||||
*/
|
||||
public void setDFTSize(DFTSize size)
|
||||
{
|
||||
mDFTSize = size;
|
||||
}
|
||||
|
||||
public void setCursorLocation(Point point)
|
||||
{
|
||||
mCursorLocation = point;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setCursorVisible(boolean visible)
|
||||
{
|
||||
mCursorVisible = visible;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the color settings from the settings manager
|
||||
*/
|
||||
private void setColors()
|
||||
{
|
||||
mColorSpectrumCursor = getColor(ColorSettingName.SPECTRUM_CURSOR);
|
||||
mColorSpectrumLine = getColor(ColorSettingName.SPECTRUM_LINE);
|
||||
mColorSpectrumBackground = getColor(ColorSettingName.SPECTRUM_BACKGROUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a named color setting from the settings manager. If the setting
|
||||
* doesn't exist, creates the setting using the defaultColor
|
||||
*/
|
||||
private Color getColor(ColorSettingName name)
|
||||
{
|
||||
ColorSetting setting = mSettingsManager.getColorSetting(name);
|
||||
return setting.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors for setting changes. Colors can be changed by external actions
|
||||
* and will automatically update in this class
|
||||
*/
|
||||
@Override
|
||||
public void settingChanged(Setting setting)
|
||||
{
|
||||
if(setting instanceof ColorSetting)
|
||||
{
|
||||
ColorSetting colorSetting = (ColorSetting)setting;
|
||||
|
||||
switch(colorSetting.getColorSettingName())
|
||||
{
|
||||
case SPECTRUM_BACKGROUND:
|
||||
mColorSpectrumBackground = colorSetting.getColor();
|
||||
break;
|
||||
case SPECTRUM_CURSOR:
|
||||
mColorSpectrumCursor = colorSetting.getColor();
|
||||
break;
|
||||
case SPECTRUM_LINE:
|
||||
mColorSpectrumLine = colorSetting.getColor();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the channel configs, lines, labels, and cursor
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
Graphics2D graphics = (Graphics2D)g;
|
||||
graphics.setBackground(mColorSpectrumBackground);
|
||||
graphics.setRenderingHints(RENDERING_HINTS);
|
||||
drawFrequencies(graphics);
|
||||
drawCursor(graphics);
|
||||
drawEstimatedCarrierOffset(graphics);
|
||||
drawChannelBandwidth(graphics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a cursor on the panel, whenever the mouse is hovering over the
|
||||
* panel
|
||||
*/
|
||||
private void drawCursor(Graphics2D graphics)
|
||||
{
|
||||
if(mCursorVisible)
|
||||
{
|
||||
drawFrequencyLine(graphics, mCursorLocation.x, mColorSpectrumCursor);
|
||||
String frequency = CURSOR_FORMAT.format(getFrequencyFromAxis(mCursorLocation.getX()) / 1E6D);
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(this.getFont());
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(frequency, graphics);
|
||||
|
||||
if(mCursorLocation.y > rect.getHeight())
|
||||
{
|
||||
graphics.drawString(frequency, mCursorLocation.x + 5, mCursorLocation.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the frequency lines and labels every 10kHz
|
||||
*/
|
||||
private void drawFrequencies(Graphics2D graphics)
|
||||
{
|
||||
long minFrequency = getMinDisplayFrequency();
|
||||
long maxFrequency = getMaxDisplayFrequency();
|
||||
|
||||
//Frequency increments for label and tick spacing
|
||||
int label = mLabelSizeMonitor.getLabelIncrement(graphics);
|
||||
int major = mLabelSizeMonitor.getMajorTickIncrement(graphics);
|
||||
int minor = mLabelSizeMonitor.getMinorTickIncrement(graphics);
|
||||
|
||||
//Avoid divide by zero error
|
||||
if(minor == 0)
|
||||
{
|
||||
minor = 1;
|
||||
}
|
||||
if(label == 0)
|
||||
{
|
||||
label = 1;
|
||||
}
|
||||
|
||||
//Adjust the start frequency to a multiple of the minor tick spacing
|
||||
long frequency = minFrequency - (minFrequency % minor);
|
||||
|
||||
while(frequency < maxFrequency)
|
||||
{
|
||||
if(frequency % label == 0)
|
||||
{
|
||||
drawFrequencyLineAndLabel(graphics, frequency);
|
||||
}
|
||||
else if(frequency % major == 0)
|
||||
{
|
||||
drawTickLine(graphics, frequency, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawTickLine(graphics, frequency, false);
|
||||
}
|
||||
|
||||
frequency += minor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line and a corresponding frequency label at the bottom
|
||||
*/
|
||||
private void drawFrequencyLineAndLabel(Graphics2D graphics, long frequency)
|
||||
{
|
||||
double xAxis = getAxisFromFrequency(frequency);
|
||||
drawFrequencyLine(graphics, xAxis, mColorSpectrumLine);
|
||||
drawTickLine(graphics, frequency, false);
|
||||
graphics.setColor(mColorSpectrumLine);
|
||||
drawFrequencyLabel(graphics, xAxis, frequency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawTickLine(Graphics2D graphics, long frequency, boolean major)
|
||||
{
|
||||
graphics.setColor(mColorSpectrumLine);
|
||||
double xAxis = getAxisFromFrequency(frequency);
|
||||
double start = getSize().getHeight() - mSpectrumInset;
|
||||
double end = start + (major ? 9.0d : 3.0d);
|
||||
graphics.draw(new Line2D.Double(xAxis, start, xAxis, end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawFrequencyLine(Graphics2D graphics, double xaxis, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
graphics.draw(new Line2D.Double(xaxis, 0.0d, xaxis, getSize().getHeight() - mSpectrumInset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawChannelCenterLine(Graphics2D graphics, double xaxis)
|
||||
{
|
||||
double height = getSize().getHeight() - mSpectrumInset;
|
||||
graphics.setColor(Color.LIGHT_GRAY);
|
||||
graphics.draw(new Line2D.Double(xaxis, height * 0.65d, xaxis, height - 1.0d));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the estimated carrier offset measured by the CarrierOffsetProcessor
|
||||
*/
|
||||
private void drawEstimatedCarrierOffset(Graphics2D graphics)
|
||||
{
|
||||
long frequency = mFrequency + mEstimatedCarrierOffsetFrequency;
|
||||
double xAxis = getAxisFromFrequency(frequency);
|
||||
|
||||
double height = getSize().getHeight() - mSpectrumInset;
|
||||
double verticalAxisTop = height * 0.02d;
|
||||
double verticalAxisBottom = height * 0.98d;
|
||||
|
||||
graphics.setColor(Color.YELLOW);
|
||||
|
||||
//Vertical band edge lines
|
||||
graphics.draw(new Line2D.Double(xAxis, verticalAxisTop, xAxis, verticalAxisBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the channel bandwidth indicators
|
||||
*/
|
||||
private void drawChannelBandwidth(Graphics2D graphics)
|
||||
{
|
||||
if(mChannelBandwidth == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
long minFrequency = mFrequency - (mChannelBandwidth / 2);
|
||||
long maxFrequency = mFrequency + (mChannelBandwidth / 2);
|
||||
|
||||
double height = getSize().getHeight() - mSpectrumInset;
|
||||
double verticalAxisTop = height * 0.8d;
|
||||
double verticalAxisBottom = height * 0.98d;
|
||||
|
||||
double minXAxis = getAxisFromFrequency(minFrequency);
|
||||
double maxXAxis = getAxisFromFrequency(maxFrequency);
|
||||
|
||||
graphics.setColor(Color.GREEN);
|
||||
|
||||
graphics.draw(new Line2D.Double(minXAxis, verticalAxisTop, minXAxis, verticalAxisBottom));
|
||||
graphics.draw(new Line2D.Double(maxXAxis, verticalAxisTop, maxXAxis, verticalAxisBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the x-axis value corresponding to the frequency
|
||||
*/
|
||||
private double getAxisFromFrequency(long frequency)
|
||||
{
|
||||
double screenWidth = (double)getSize().getWidth();
|
||||
double pixelsPerBin = screenWidth / (double)mDFTSize.getSize();
|
||||
double pixelOffsetToMinDisplayFrequency = pixelsPerBin * 2.0d;
|
||||
|
||||
//Calculate frequency offset from the min frequency
|
||||
double frequencyOffset = (double)(frequency - getMinDisplayFrequency());
|
||||
|
||||
//Determine ratio of frequency offset to overall bandwidth
|
||||
double ratio = frequencyOffset / (double)getDisplayBandwidth();
|
||||
|
||||
//Apply the ratio to the screen width minus 1 bin width
|
||||
double screenOffset = screenWidth * ratio;
|
||||
return pixelOffsetToMinDisplayFrequency + screenOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frequency corresponding to the x-axis value using the current
|
||||
* zoom level.
|
||||
*/
|
||||
public long getFrequencyFromAxis(double xAxis)
|
||||
{
|
||||
double width = getSize().getWidth();
|
||||
double offset = xAxis / width;
|
||||
long frequency = getMinDisplayFrequency() + FastMath.round((double)getDisplayBandwidth() * offset);
|
||||
if(frequency > (getMaxFrequency()))
|
||||
{
|
||||
frequency = getMaxFrequency();
|
||||
}
|
||||
return frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a frequency label at the x-axis position, at the bottom of the panel
|
||||
*/
|
||||
private void drawFrequencyLabel(Graphics2D graphics, double xaxis, long frequency)
|
||||
{
|
||||
String label = mLabelSizeMonitor.format(frequency);
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(this.getFont());
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(label, graphics);
|
||||
float xOffset = (float)rect.getWidth() / 2;
|
||||
graphics.drawString(label, (float)(xaxis - xOffset), (float)(getSize().getHeight() - 2.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Frequency change event handler
|
||||
*/
|
||||
@Override
|
||||
public void process(SourceEvent event)
|
||||
{
|
||||
switch(event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_SAMPLE_RATE_CHANGE:
|
||||
mBandwidth = event.getValue().intValue();
|
||||
mLabelSizeMonitor.update();
|
||||
break;
|
||||
case NOTIFICATION_FREQUENCY_CHANGE:
|
||||
mFrequency = event.getValue().longValue();
|
||||
mLabelSizeMonitor.update();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int getBandwidth()
|
||||
{
|
||||
return mBandwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently displayed minimum frequency
|
||||
*/
|
||||
public long getMinFrequency()
|
||||
{
|
||||
return mFrequency - (mBandwidth / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently displayed maximum frequency
|
||||
*/
|
||||
public long getMaxFrequency()
|
||||
{
|
||||
return mFrequency + (mBandwidth / 2);
|
||||
}
|
||||
|
||||
public boolean containsFrequency(long frequency)
|
||||
{
|
||||
return FastMath.abs(mFrequency - frequency) <= (mBandwidth / 2);
|
||||
}
|
||||
|
||||
private long getMinDisplayFrequency()
|
||||
{
|
||||
double bandwidthPerBin = (double)mBandwidth / (double)(mDFTSize.getSize());
|
||||
|
||||
return getMinFrequency();
|
||||
// return getMinFrequency() + (int)((mDFTZoomWindowOffset) * bandwidthPerBin);
|
||||
}
|
||||
|
||||
private long getMaxDisplayFrequency()
|
||||
{
|
||||
return getMinDisplayFrequency() + getDisplayBandwidth();
|
||||
}
|
||||
|
||||
private int getDisplayBandwidth()
|
||||
{
|
||||
return mBandwidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingDeleted(Setting setting) { /* not implemented */ }
|
||||
|
||||
/**
|
||||
* Calculates correct spacing and format for frequency labels and major/minor
|
||||
* tick lines based on current frequency, bandwidth, zoom and screen size.
|
||||
*/
|
||||
public class LabelSizeManager implements ComponentListener
|
||||
{
|
||||
private static final double LABEL_FILL_THRESHOLD = 0.5d;
|
||||
|
||||
private DecimalFormat mFrequencyFormat = new DecimalFormat("0.0");
|
||||
|
||||
private boolean mUpdateRequired = true;
|
||||
private int mLabelIncrement = 1;
|
||||
private int mMajorTickIncrement = 1;
|
||||
private int mMinorTickIncrement = 1;
|
||||
|
||||
public String format(long frequency)
|
||||
{
|
||||
return mFrequencyFormat.format((double)frequency / 1E6D);
|
||||
}
|
||||
|
||||
private void setPrecision(int precision)
|
||||
{
|
||||
if(precision < 1)
|
||||
{
|
||||
precision = 1;
|
||||
}
|
||||
|
||||
if(precision > 5)
|
||||
{
|
||||
precision = 5;
|
||||
}
|
||||
|
||||
mFrequencyFormat.setMinimumFractionDigits(precision);
|
||||
mFrequencyFormat.setMaximumFractionDigits(precision);
|
||||
}
|
||||
|
||||
private void update(Graphics2D graphics)
|
||||
{
|
||||
if(mUpdateRequired)
|
||||
{
|
||||
//Set maximum precision as a starting point
|
||||
setPrecision(5);
|
||||
|
||||
FontMetrics fontMetrics =
|
||||
graphics.getFontMetrics(FrequencyOverlayPanel.this.getFont());
|
||||
|
||||
int maxLabelWidth = fontMetrics.stringWidth(format(getMaxDisplayFrequency()));
|
||||
|
||||
double maxLabels = ((double) FrequencyOverlayPanel.this.getWidth() * LABEL_FILL_THRESHOLD) / (double)maxLabelWidth;
|
||||
|
||||
//Calculate the next smallest base 10 value for the major increment
|
||||
int power = (int)FastMath.log10((double)getDisplayBandwidth() / maxLabels);
|
||||
|
||||
//Set the number of decimal places to display in frequency labels
|
||||
int precision = 5 - power;
|
||||
|
||||
int start = (int)FastMath.pow(10.0, power + 1);
|
||||
|
||||
int minimum = (int)FastMath.pow(10.0, power);
|
||||
|
||||
int labelIncrement = start;
|
||||
|
||||
while(((double)getDisplayBandwidth() / (double)labelIncrement) < maxLabels && labelIncrement >= minimum)
|
||||
{
|
||||
labelIncrement /= 2;
|
||||
precision++;
|
||||
}
|
||||
|
||||
if(labelIncrement == minimum)
|
||||
{
|
||||
precision = 5 - power;
|
||||
}
|
||||
|
||||
setPrecision(precision);
|
||||
|
||||
mLabelIncrement = labelIncrement;
|
||||
mMajorTickIncrement = labelIncrement / 2;
|
||||
mMinorTickIncrement = labelIncrement / 10;
|
||||
|
||||
mUpdateRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the display to update the label and frequency display
|
||||
* calculations
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
mUpdateRequired = true;
|
||||
}
|
||||
|
||||
public int getMajorTickIncrement(Graphics2D graphics)
|
||||
{
|
||||
//Check to see if a calculation update is scheduled
|
||||
update(graphics);
|
||||
|
||||
return mMajorTickIncrement;
|
||||
}
|
||||
|
||||
public int getMinorTickIncrement(Graphics2D graphics)
|
||||
{
|
||||
return mMinorTickIncrement;
|
||||
}
|
||||
|
||||
public int getLabelIncrement(Graphics2D graphics)
|
||||
{
|
||||
return mLabelIncrement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent arg0)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent arg0) {}
|
||||
public void componentMoved(ComponentEvent arg0) {}
|
||||
public void componentShown(ComponentEvent arg0) {}
|
||||
}
|
||||
}
|
||||
@@ -1,948 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2024 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.controller.channel.Channel.ChannelType;
|
||||
import io.github.dsheirer.controller.channel.ChannelEvent;
|
||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.settings.ColorSetting;
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingChangeListener;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.channel.TunerChannel;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class OverlayPanel extends JPanel implements Listener<ChannelEvent>, ISourceEventProcessor, SettingChangeListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final static Logger mLog = LoggerFactory.getLogger(OverlayPanel.class);
|
||||
private final DecimalFormat PPM_FORMATTER = new DecimalFormat( "#.0" );
|
||||
|
||||
private final static RenderingHints RENDERING_HINTS = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
static
|
||||
{
|
||||
RENDERING_HINTS.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
}
|
||||
|
||||
private final static BasicStroke DASHED_STROKE = new BasicStroke(0.8f, BasicStroke.CAP_BUTT,
|
||||
BasicStroke.JOIN_MITER, 5.0f, new float[]{2.0f, 4.0f}, 0.0f);
|
||||
|
||||
private static DecimalFormat CURSOR_FORMAT = new DecimalFormat("000.00000");
|
||||
private long mFrequency = 0;
|
||||
private int mBandwidth = 0;
|
||||
private Point mCursorLocation = new Point(0, 0);
|
||||
private boolean mCursorVisible = false;
|
||||
|
||||
private DFTSize mDFTSize = DFTSize.FFT04096;
|
||||
private int mZoom = 0;
|
||||
private int mDFTZoomWindowOffset = 0;
|
||||
|
||||
/**
|
||||
* Colors used by this component
|
||||
*/
|
||||
private Color mColorChannelConfig;
|
||||
private Color mColorChannelConfigProcessing;
|
||||
private Color mColorChannelConfigSelected;
|
||||
private Color mColorSpectrumBackground;
|
||||
private Color mColorSpectrumCursor;
|
||||
private Color mColorSpectrumLine;
|
||||
|
||||
//Currently visible/displayable channels
|
||||
private List<Channel> mVisibleChannels = new CopyOnWriteArrayList<>();
|
||||
private List<Channel> mTrafficChannels = new CopyOnWriteArrayList<>();
|
||||
|
||||
private ChannelDisplay mChannelDisplay = ChannelDisplay.ALL;
|
||||
|
||||
//Defines the offset at the bottom of the spectral display to account for
|
||||
//the frequency labels
|
||||
private double mSpectrumInset = 20.0d;
|
||||
private LabelSizeManager mLabelSizeMonitor = new LabelSizeManager();
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
private ChannelModel mChannelModel;
|
||||
private ChannelProcessingManager mChannelProcessingManager;
|
||||
|
||||
/**
|
||||
* Translucent overlay panel for displaying channel configurations,
|
||||
* processing channels, selected channels, frequency labels and lines, and
|
||||
* a cursor with a frequency readout.
|
||||
*/
|
||||
public OverlayPanel(SettingsManager settingsManager, ChannelModel channelModel, ChannelProcessingManager channelProcessingManager)
|
||||
{
|
||||
mSettingsManager = settingsManager;
|
||||
|
||||
if(mSettingsManager != null)
|
||||
{
|
||||
mSettingsManager.addListener(this);
|
||||
}
|
||||
|
||||
mChannelModel = channelModel;
|
||||
|
||||
if(mChannelModel != null)
|
||||
{
|
||||
mChannelModel.addListener(this::receive);
|
||||
}
|
||||
|
||||
mChannelProcessingManager = channelProcessingManager;
|
||||
|
||||
if(mChannelProcessingManager != null)
|
||||
{
|
||||
mChannelProcessingManager.addChannelEventListener(this::receive);
|
||||
}
|
||||
|
||||
addComponentListener(mLabelSizeMonitor);
|
||||
|
||||
//Set the background transparent, so the spectrum display can be seen
|
||||
setOpaque(false);
|
||||
|
||||
//Fetch color settings from settings manager
|
||||
setColors();
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
if(mChannelModel != null)
|
||||
{
|
||||
mChannelModel.removeListener(this);
|
||||
}
|
||||
|
||||
mChannelModel = null;
|
||||
|
||||
mVisibleChannels.clear();
|
||||
|
||||
if(mSettingsManager != null)
|
||||
{
|
||||
mSettingsManager.removeListener(this);
|
||||
}
|
||||
|
||||
mSettingsManager = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/changes the DFT bin size
|
||||
*/
|
||||
public void setDFTSize(DFTSize size)
|
||||
{
|
||||
mDFTSize = size;
|
||||
}
|
||||
|
||||
public ChannelDisplay getChannelDisplay()
|
||||
{
|
||||
return mChannelDisplay;
|
||||
}
|
||||
|
||||
public void setChannelDisplay(ChannelDisplay display)
|
||||
{
|
||||
mChannelDisplay = display;
|
||||
}
|
||||
|
||||
public void setCursorLocation(Point point)
|
||||
{
|
||||
mCursorLocation = point;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setCursorVisible(boolean visible)
|
||||
{
|
||||
mCursorVisible = visible;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current zoom level (2^zoom)
|
||||
*
|
||||
* 0 No Zoom
|
||||
* 1 2x Zoom
|
||||
* 2 4x Zoom
|
||||
* 3 8x Zoom
|
||||
* 4 16x Zoom
|
||||
* 5 32x Zoom
|
||||
* 6 64x Zoom
|
||||
*
|
||||
* @param zoom level, 0 - 6.
|
||||
*/
|
||||
public void setZoom(int zoom)
|
||||
{
|
||||
mZoom = zoom;
|
||||
|
||||
mLabelSizeMonitor.update();
|
||||
}
|
||||
|
||||
public void setZoomWindowOffset(int offset)
|
||||
{
|
||||
mDFTZoomWindowOffset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the color settings from the settings manager
|
||||
*/
|
||||
private void setColors()
|
||||
{
|
||||
mColorChannelConfig = getColor(ColorSettingName.CHANNEL_CONFIG);
|
||||
mColorChannelConfigProcessing = getColor(ColorSettingName.CHANNEL_CONFIG_PROCESSING);
|
||||
mColorChannelConfigSelected = getColor(ColorSettingName.CHANNEL_CONFIG_SELECTED);
|
||||
mColorSpectrumCursor = getColor(ColorSettingName.SPECTRUM_CURSOR);
|
||||
mColorSpectrumLine = getColor(ColorSettingName.SPECTRUM_LINE);
|
||||
mColorSpectrumBackground = getColor(ColorSettingName.SPECTRUM_BACKGROUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a named color setting from the settings manager. If the setting
|
||||
* doesn't exist, creates the setting using the defaultColor
|
||||
*/
|
||||
private Color getColor(ColorSettingName name)
|
||||
{
|
||||
ColorSetting setting = mSettingsManager.getColorSetting(name);
|
||||
|
||||
return setting.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors for setting changes. Colors can be changed by external actions
|
||||
* and will automatically update in this class
|
||||
*/
|
||||
@Override
|
||||
public void settingChanged(Setting setting)
|
||||
{
|
||||
if(setting instanceof ColorSetting)
|
||||
{
|
||||
ColorSetting colorSetting = (ColorSetting)setting;
|
||||
|
||||
switch(colorSetting.getColorSettingName())
|
||||
{
|
||||
case CHANNEL_CONFIG:
|
||||
mColorChannelConfig = colorSetting.getColor();
|
||||
break;
|
||||
case CHANNEL_CONFIG_PROCESSING:
|
||||
mColorChannelConfigProcessing = colorSetting.getColor();
|
||||
break;
|
||||
case CHANNEL_CONFIG_SELECTED:
|
||||
mColorChannelConfigSelected = colorSetting.getColor();
|
||||
break;
|
||||
case SPECTRUM_BACKGROUND:
|
||||
mColorSpectrumBackground = colorSetting.getColor();
|
||||
break;
|
||||
case SPECTRUM_CURSOR:
|
||||
mColorSpectrumCursor = colorSetting.getColor();
|
||||
break;
|
||||
case SPECTRUM_LINE:
|
||||
mColorSpectrumLine = colorSetting.getColor();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the channel configs, lines, labels, and cursor
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
Graphics2D graphics = (Graphics2D)g;
|
||||
graphics.setBackground(mColorSpectrumBackground);
|
||||
|
||||
graphics.setRenderingHints(RENDERING_HINTS);
|
||||
|
||||
drawFrequencies(graphics);
|
||||
drawChannels(graphics);
|
||||
drawCursor(graphics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a cursor on the panel, whenever the mouse is hovering over the
|
||||
* panel
|
||||
*/
|
||||
private void drawCursor(Graphics2D graphics)
|
||||
{
|
||||
if(mCursorVisible)
|
||||
{
|
||||
drawFrequencyLine(graphics, mCursorLocation.x, mColorSpectrumCursor);
|
||||
|
||||
String frequency = CURSOR_FORMAT.format(getFrequencyFromAxis(mCursorLocation.getX()) / 1E6D);
|
||||
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(this.getFont());
|
||||
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(frequency, graphics);
|
||||
|
||||
if(mCursorLocation.y > rect.getHeight())
|
||||
{
|
||||
graphics.drawString(frequency, mCursorLocation.x + 5, mCursorLocation.y);
|
||||
}
|
||||
|
||||
if(mZoom != 0)
|
||||
{
|
||||
graphics.drawString("Zoom: " + (int)FastMath.pow(2.0, mZoom) + "x", mCursorLocation.x + 17,
|
||||
mCursorLocation.y + 11);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the frequency lines and labels every 10kHz
|
||||
*/
|
||||
private void drawFrequencies(Graphics2D graphics)
|
||||
{
|
||||
Stroke currentStroke = graphics.getStroke();
|
||||
|
||||
long minFrequency = getMinDisplayFrequency();
|
||||
long maxFrequency = getMaxDisplayFrequency();
|
||||
|
||||
//Frequency increments for label and tick spacing
|
||||
int label = mLabelSizeMonitor.getLabelIncrement(graphics);
|
||||
int major = mLabelSizeMonitor.getMajorTickIncrement(graphics);
|
||||
int minor = mLabelSizeMonitor.getMinorTickIncrement(graphics);
|
||||
|
||||
//Avoid divide by zero error
|
||||
if(minor == 0)
|
||||
{
|
||||
minor = 1;
|
||||
}
|
||||
if(label == 0)
|
||||
{
|
||||
label = 1;
|
||||
}
|
||||
|
||||
//Adjust the start frequency to a multiple of the minor tick spacing
|
||||
long frequency = minFrequency - (minFrequency % minor);
|
||||
|
||||
while(frequency < maxFrequency)
|
||||
{
|
||||
if(frequency % label == 0)
|
||||
{
|
||||
drawFrequencyLineAndLabel(graphics, frequency);
|
||||
}
|
||||
else if(frequency % major == 0)
|
||||
{
|
||||
drawTickLine(graphics, frequency, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawTickLine(graphics, frequency, false);
|
||||
}
|
||||
|
||||
frequency += minor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line and a corresponding frequency label at the bottom
|
||||
*/
|
||||
private void drawFrequencyLineAndLabel(Graphics2D graphics, long frequency)
|
||||
{
|
||||
double xAxis = getAxisFromFrequency(frequency);
|
||||
|
||||
drawFrequencyLine(graphics, xAxis, mColorSpectrumLine);
|
||||
|
||||
drawTickLine(graphics, frequency, false);
|
||||
|
||||
graphics.setColor(mColorSpectrumLine);
|
||||
|
||||
drawFrequencyLabel(graphics, xAxis, frequency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawTickLine(Graphics2D graphics, long frequency, boolean major)
|
||||
{
|
||||
graphics.setColor(mColorSpectrumLine);
|
||||
|
||||
double xAxis = getAxisFromFrequency(frequency);
|
||||
|
||||
double start = getSize().getHeight() - mSpectrumInset;
|
||||
double end = start + (major ? 9.0d : 3.0d);
|
||||
|
||||
graphics.draw(new Line2D.Double(xAxis, start, xAxis, end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawFrequencyLine(Graphics2D graphics, double xaxis, Color color)
|
||||
{
|
||||
graphics.setColor(color);
|
||||
|
||||
graphics.draw(new Line2D.Double(xaxis, 0.0d, xaxis, getSize().getHeight() - mSpectrumInset));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a vertical line at the xaxis
|
||||
*/
|
||||
private void drawChannelCenterLine(Graphics2D graphics, double xaxis)
|
||||
{
|
||||
double height = getSize().getHeight() - mSpectrumInset;
|
||||
|
||||
graphics.setColor(Color.LIGHT_GRAY);
|
||||
|
||||
graphics.draw(new Line2D.Double(xaxis, height * 0.65d, xaxis, height - 1.0d));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the Automatic Frequency Control (AFC) channel center offset
|
||||
*/
|
||||
private void drawAFC(Graphics2D graphics, double frequencyAxis, double errorAxis, double bandwidth,
|
||||
int correction, long frequency)
|
||||
{
|
||||
double height = getSize().getHeight() - mSpectrumInset;
|
||||
double verticalAxisTop = height * 0.88d;
|
||||
double verticalAxisBottom = height * 0.98d;
|
||||
|
||||
double halfBandwidth = bandwidth / 2.0;
|
||||
double errorEdgeStart = errorAxis - halfBandwidth;
|
||||
double errorEdgeStop = errorAxis + halfBandwidth;
|
||||
|
||||
graphics.setColor(Color.YELLOW);
|
||||
|
||||
//Horizontal line connecting frequency and error line
|
||||
graphics.draw(new Line2D.Double(errorEdgeStart, verticalAxisBottom, errorEdgeStop, verticalAxisBottom));
|
||||
|
||||
//Vertical band edge lines
|
||||
graphics.draw(new Line2D.Double(errorEdgeStart, verticalAxisTop, errorEdgeStart, verticalAxisBottom));
|
||||
graphics.draw(new Line2D.Double(errorEdgeStop, verticalAxisTop, errorEdgeStop, verticalAxisBottom));
|
||||
|
||||
double ppm = (double)correction / ((double)frequency / 1E6d);
|
||||
|
||||
String label = "PPM " + PPM_FORMATTER.format(ppm) ;
|
||||
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(this.getFont());
|
||||
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(label, graphics);
|
||||
|
||||
//Only render the correction value label if the spacing is large enough
|
||||
if(rect.getWidth() <= bandwidth && rect.getHeight() * 5 <= height)
|
||||
{
|
||||
graphics.drawString(label, (float)(errorEdgeStart + 1.0), (float)(verticalAxisBottom - 2.0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the x-axis value corresponding to the frequency
|
||||
*/
|
||||
private double getAxisFromFrequency(long frequency)
|
||||
{
|
||||
double screenWidth = (double)getSize().getWidth();
|
||||
|
||||
double pixelsPerBin = screenWidth / (double)mDFTSize.getSize();
|
||||
|
||||
double pixelOffsetToMinDisplayFrequency = pixelsPerBin * 2.0d;
|
||||
|
||||
//Calculate frequency offset from the min frequency
|
||||
double frequencyOffset = (double)(frequency - getMinDisplayFrequency());
|
||||
|
||||
//Determine ratio of frequency offset to overall bandwidth
|
||||
double ratio = frequencyOffset / (double)getDisplayBandwidth();
|
||||
|
||||
//Apply the ratio to the screen width minus 1 bin width
|
||||
double screenOffset = screenWidth * ratio;
|
||||
|
||||
return pixelOffsetToMinDisplayFrequency + screenOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frequency corresponding to the x-axis value using the current
|
||||
* zoom level.
|
||||
*/
|
||||
public long getFrequencyFromAxis(double xAxis)
|
||||
{
|
||||
double width = getSize().getWidth();
|
||||
|
||||
double offset = xAxis / width;
|
||||
|
||||
long frequency = getMinDisplayFrequency() + FastMath.round((double)getDisplayBandwidth() * offset);
|
||||
|
||||
if(frequency > (getMaxFrequency()))
|
||||
{
|
||||
frequency = getMaxFrequency();
|
||||
}
|
||||
|
||||
return frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a frequency label at the x-axis position, at the bottom of the panel
|
||||
*/
|
||||
private void drawFrequencyLabel(Graphics2D graphics, double xaxis, long frequency)
|
||||
{
|
||||
String label = mLabelSizeMonitor.format(frequency);
|
||||
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(this.getFont());
|
||||
|
||||
Rectangle2D rect = fontMetrics.getStringBounds(label, graphics);
|
||||
|
||||
float xOffset = (float)rect.getWidth() / 2;
|
||||
|
||||
graphics.drawString(label, (float)(xaxis - xOffset), (float)(getSize().getHeight() - 2.0f));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws visible channel configs as translucent shaded frequency regions
|
||||
*/
|
||||
private void drawChannels(Graphics2D graphics)
|
||||
{
|
||||
for(Channel channel : mVisibleChannels)
|
||||
{
|
||||
if(mChannelDisplay == ChannelDisplay.ALL || (mChannelDisplay == ChannelDisplay.ENABLED && channel.isProcessing()))
|
||||
{
|
||||
List<TunerChannel> tunerChannels = channel.getTunerChannels();
|
||||
|
||||
for(TunerChannel tunerChannel: tunerChannels)
|
||||
{
|
||||
if(tunerChannel.overlaps(getMinDisplayFrequency(), getMaxDisplayFrequency()))
|
||||
{
|
||||
//Choose the correct background color to use
|
||||
if(channel.isSelected())
|
||||
{
|
||||
graphics.setColor(mColorChannelConfigSelected);
|
||||
}
|
||||
else if(channel.isProcessing())
|
||||
{
|
||||
graphics.setColor(mColorChannelConfigProcessing);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.setColor(mColorChannelConfig);
|
||||
}
|
||||
|
||||
double xAxis = getAxisFromFrequency(tunerChannel.getFrequency());
|
||||
double width = (double)(tunerChannel.getBandwidth()) / (double)getDisplayBandwidth() * getSize().getWidth();
|
||||
|
||||
Rectangle2D.Double box = new Rectangle2D.Double(xAxis - (width / 2.0d), 0.0d, width,
|
||||
getSize().getHeight() - mSpectrumInset);
|
||||
|
||||
//Fill the box with the correct color
|
||||
graphics.fill(box);
|
||||
graphics.draw(box);
|
||||
|
||||
//Change to the line color to render the channel name, etc.
|
||||
graphics.setColor(mColorSpectrumLine);
|
||||
|
||||
//Draw the labels starting at yAxis position 0
|
||||
double yAxis = 0;
|
||||
|
||||
//Draw the system label and adjust the y-axis position
|
||||
String system = channel.hasSystem() ? channel.getSystem() : " ";
|
||||
|
||||
yAxis += drawLabel(graphics, system, this.getFont(), xAxis, yAxis, width);
|
||||
|
||||
//Draw the site label and adjust the y-axis position
|
||||
String site = channel.hasSite() ? channel.getSite() : " ";
|
||||
|
||||
yAxis += drawLabel(graphics, site, this.getFont(), xAxis, yAxis, width);
|
||||
|
||||
//Draw the channel label and adjust the y-axis position
|
||||
yAxis += drawLabel(graphics, channel.getName(), this.getFont(), xAxis, yAxis, width);
|
||||
|
||||
//Draw the decoder label
|
||||
drawLabel(graphics, channel.getDecodeConfiguration().getDecoderType().getShortDisplayString(),
|
||||
this.getFont(), xAxis, yAxis, width);
|
||||
long frequency = tunerChannel.getFrequency();
|
||||
double frequencyAxis = getAxisFromFrequency(frequency);
|
||||
drawChannelCenterLine(graphics, frequencyAxis);
|
||||
|
||||
/* Draw Automatic Frequency Control line */
|
||||
int correction = channel.getChannelFrequencyCorrection();
|
||||
|
||||
if(correction != 0)
|
||||
{
|
||||
long error = frequency + correction;
|
||||
drawAFC(graphics, frequencyAxis, getAxisFromFrequency(error), width, correction,
|
||||
tunerChannel.getFrequency());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws a textual label at the x/y position, clipping the end of the text
|
||||
* to fit within the maxwidth value.
|
||||
*
|
||||
* @return height of the drawn label
|
||||
*/
|
||||
private double drawLabel(Graphics2D graphics, String text, Font font, double x, double baseY, double maxWidth)
|
||||
{
|
||||
FontMetrics fontMetrics = graphics.getFontMetrics(font);
|
||||
|
||||
if(text == null || text.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Rectangle2D label = fontMetrics.getStringBounds(text, graphics);
|
||||
|
||||
double offset = label.getWidth() / 2.0d;
|
||||
double y = baseY + label.getHeight();
|
||||
|
||||
/**
|
||||
* If the label is wider than the max width, left justify the text and
|
||||
* clip the end of it
|
||||
*/
|
||||
if(offset > (maxWidth / 2.0d))
|
||||
{
|
||||
label.setRect(x - (maxWidth / 2.0d), y - label.getHeight(), maxWidth, label.getHeight());
|
||||
|
||||
graphics.setClip(label);
|
||||
|
||||
graphics.drawString(text, (float)(x - (maxWidth / 2.0d)), (float)y);
|
||||
|
||||
graphics.setClip(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.drawString(text, (float)(x - offset), (float)y);
|
||||
}
|
||||
|
||||
return label.getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Frequency change event handler
|
||||
*/
|
||||
@Override
|
||||
public void process(SourceEvent event)
|
||||
{
|
||||
switch(event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_SAMPLE_RATE_CHANGE:
|
||||
mBandwidth = event.getValue().intValue();
|
||||
mLabelSizeMonitor.update();
|
||||
break;
|
||||
case NOTIFICATION_FREQUENCY_CHANGE:
|
||||
mFrequency = event.getValue().longValue();
|
||||
mLabelSizeMonitor.update();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the visible channels list
|
||||
*/
|
||||
mVisibleChannels.clear();
|
||||
mVisibleChannels.addAll(mChannelModel.getChannelsInFrequencyRange(getMinFrequency(), getMaxFrequency()));
|
||||
|
||||
for(Channel trafficChannel: mTrafficChannels)
|
||||
{
|
||||
if(trafficChannel.isWithin(getMinFrequency(), getMaxFrequency()))
|
||||
{
|
||||
mVisibleChannels.add(trafficChannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel change event handler
|
||||
*/
|
||||
@Override
|
||||
public void receive(ChannelEvent event)
|
||||
{
|
||||
Channel channel = event.getChannel();
|
||||
|
||||
switch(event.getEvent())
|
||||
{
|
||||
case NOTIFICATION_ADD:
|
||||
case NOTIFICATION_PROCESSING_START:
|
||||
if(channel.getChannelType() == ChannelType.TRAFFIC && !mTrafficChannels.contains(channel))
|
||||
{
|
||||
mTrafficChannels.add(channel);
|
||||
}
|
||||
if(!mVisibleChannels.contains(channel) && channel.isWithin(getMinFrequency(), getMaxFrequency()))
|
||||
{
|
||||
mVisibleChannels.add(channel);
|
||||
}
|
||||
break;
|
||||
case NOTIFICATION_DELETE:
|
||||
mVisibleChannels.remove(channel);
|
||||
break;
|
||||
case NOTIFICATION_PROCESSING_STOP:
|
||||
case NOTIFICATION_PROCESSING_START_REJECTED:
|
||||
if(channel.getChannelType() == ChannelType.TRAFFIC)
|
||||
{
|
||||
mVisibleChannels.remove(channel);
|
||||
mTrafficChannels.remove(channel);
|
||||
}
|
||||
break;
|
||||
case NOTIFICATION_CONFIGURATION_CHANGE:
|
||||
if(mVisibleChannels.contains(channel) && !channel.isWithin(getMinFrequency(), getMaxFrequency()))
|
||||
{
|
||||
mVisibleChannels.remove(channel);
|
||||
}
|
||||
|
||||
if(!mVisibleChannels.contains(channel) && channel.isWithin(getMinFrequency(), getMaxFrequency()))
|
||||
{
|
||||
mVisibleChannels.add(channel);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int getBandwidth()
|
||||
{
|
||||
return mBandwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently displayed minimum frequency
|
||||
*/
|
||||
public long getMinFrequency()
|
||||
{
|
||||
return mFrequency - (mBandwidth / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently displayed maximum frequency
|
||||
*/
|
||||
public long getMaxFrequency()
|
||||
{
|
||||
return mFrequency + (mBandwidth / 2);
|
||||
}
|
||||
|
||||
public boolean containsFrequency(long frequency)
|
||||
{
|
||||
return FastMath.abs(mFrequency - frequency) <= (mBandwidth / 2);
|
||||
}
|
||||
|
||||
private long getMinDisplayFrequency()
|
||||
{
|
||||
double bandwidthPerBin = (double)mBandwidth / (double)(mDFTSize.getSize());
|
||||
|
||||
return getMinFrequency() + (int)((mDFTZoomWindowOffset) * bandwidthPerBin);
|
||||
}
|
||||
|
||||
private long getMaxDisplayFrequency()
|
||||
{
|
||||
return getMinDisplayFrequency() + getDisplayBandwidth();
|
||||
}
|
||||
|
||||
private int getDisplayBandwidth()
|
||||
{
|
||||
if(mZoom != 0)
|
||||
{
|
||||
return mBandwidth / (int)FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
return mBandwidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of channel configs that contain the frequency within their
|
||||
* min/max frequency settings.
|
||||
*/
|
||||
public ArrayList<Channel> getChannelsAtFrequency(long frequency)
|
||||
{
|
||||
ArrayList<Channel> configs = new ArrayList<Channel>();
|
||||
|
||||
for(Channel config : mVisibleChannels)
|
||||
{
|
||||
List<TunerChannel> channels = config.getTunerChannels();
|
||||
|
||||
for(TunerChannel channel: channels)
|
||||
{
|
||||
if(channel != null && channel.getMinFrequency() <= frequency && channel.getMaxFrequency() >= frequency)
|
||||
{
|
||||
configs.add(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingDeleted(Setting setting)
|
||||
{ /* not implemented */ }
|
||||
|
||||
/**
|
||||
* Calculates correct spacing and format for frequency labels and major/minor
|
||||
* tick lines based on current frequency, bandwidth, zoom and screen size.
|
||||
*/
|
||||
public class LabelSizeManager implements ComponentListener
|
||||
{
|
||||
private static final double LABEL_FILL_THRESHOLD = 0.5d;
|
||||
|
||||
private DecimalFormat mFrequencyFormat = new DecimalFormat("0.0");
|
||||
|
||||
private boolean mUpdateRequired = true;
|
||||
private int mLabelIncrement = 1;
|
||||
private int mMajorTickIncrement = 1;
|
||||
private int mMinorTickIncrement = 1;
|
||||
|
||||
public String format(long frequency)
|
||||
{
|
||||
return mFrequencyFormat.format((double)frequency / 1E6D);
|
||||
}
|
||||
|
||||
private void setPrecision(int precision)
|
||||
{
|
||||
if(precision < 1)
|
||||
{
|
||||
precision = 1;
|
||||
}
|
||||
|
||||
if(precision > 5)
|
||||
{
|
||||
precision = 5;
|
||||
}
|
||||
|
||||
mFrequencyFormat.setMinimumFractionDigits(precision);
|
||||
mFrequencyFormat.setMaximumFractionDigits(precision);
|
||||
}
|
||||
|
||||
private void update(Graphics2D graphics)
|
||||
{
|
||||
if(mUpdateRequired)
|
||||
{
|
||||
//Set maximum precision as a starting point
|
||||
setPrecision(5);
|
||||
|
||||
FontMetrics fontMetrics =
|
||||
graphics.getFontMetrics(OverlayPanel.this.getFont());
|
||||
|
||||
int maxLabelWidth = fontMetrics.stringWidth(format(getMaxDisplayFrequency()));
|
||||
|
||||
double maxLabels = ((double)OverlayPanel.this.getWidth() * LABEL_FILL_THRESHOLD) / (double)maxLabelWidth;
|
||||
|
||||
//Calculate the next smallest base 10 value for the major increment
|
||||
int power = (int)FastMath.log10((double)getDisplayBandwidth() / maxLabels);
|
||||
|
||||
//Set the number of decimal places to display in frequency labels
|
||||
int precision = 5 - power;
|
||||
|
||||
int start = (int)FastMath.pow(10.0, power + 1);
|
||||
|
||||
int minimum = (int)FastMath.pow(10.0, power);
|
||||
|
||||
int labelIncrement = start;
|
||||
|
||||
while(((double)getDisplayBandwidth() / (double)labelIncrement) < maxLabels && labelIncrement >= minimum)
|
||||
{
|
||||
labelIncrement /= 2;
|
||||
precision++;
|
||||
}
|
||||
|
||||
if(labelIncrement == minimum)
|
||||
{
|
||||
precision = 5 - power;
|
||||
}
|
||||
|
||||
setPrecision(precision);
|
||||
|
||||
mLabelIncrement = labelIncrement;
|
||||
mMajorTickIncrement = labelIncrement / 2;
|
||||
mMinorTickIncrement = labelIncrement / 10;
|
||||
|
||||
mUpdateRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the display to update the label and frequency display
|
||||
* calculations
|
||||
*/
|
||||
public void update()
|
||||
{
|
||||
mUpdateRequired = true;
|
||||
}
|
||||
|
||||
public int getMajorTickIncrement(Graphics2D graphics)
|
||||
{
|
||||
//Check to see if a calculation update is scheduled
|
||||
update(graphics);
|
||||
|
||||
return mMajorTickIncrement;
|
||||
}
|
||||
|
||||
public int getMinorTickIncrement(Graphics2D graphics)
|
||||
{
|
||||
return mMinorTickIncrement;
|
||||
}
|
||||
|
||||
public int getLabelIncrement(Graphics2D graphics)
|
||||
{
|
||||
return mLabelIncrement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent arg0)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ChannelDisplay
|
||||
{
|
||||
ALL, ENABLED, NONE;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
/**
|
||||
* Interface to add pause action to moving displays like the spectrum and
|
||||
* waterfall panels
|
||||
*/
|
||||
public interface Pausable
|
||||
{
|
||||
public void setPaused( boolean paused );
|
||||
|
||||
public boolean isPaused();
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.gui.spectrum.TunerSpectralDisplay;
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.source.tuner.Tuner;
|
||||
import io.github.dsheirer.source.tuner.TunerEvent;
|
||||
@@ -50,7 +51,7 @@ public class ShowTunerMenuItem extends JMenuItem
|
||||
public void run()
|
||||
{
|
||||
SystemProperties properties = SystemProperties.getInstance();
|
||||
properties.set(SpectralDisplayPanel.SPECTRAL_DISPLAY_ENABLED, true);
|
||||
properties.set(TunerSpectralDisplay.SPECTRAL_DISPLAY_ENABLED, true);
|
||||
mDiscoveredTunerModel.broadcast(new TunerEvent(mTuner, TunerEvent.Event.REQUEST_MAIN_SPECTRAL_DISPLAY));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,904 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2023 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import com.jidesoft.swing.JideSplitPane;
|
||||
import io.github.dsheirer.buffer.INativeBuffer;
|
||||
import io.github.dsheirer.controller.channel.Channel;
|
||||
import io.github.dsheirer.controller.channel.ChannelModel;
|
||||
import io.github.dsheirer.controller.channel.ChannelProcessingManager;
|
||||
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter.SmoothingType;
|
||||
import io.github.dsheirer.dsp.window.WindowType;
|
||||
import io.github.dsheirer.eventbus.MyEventBus;
|
||||
import io.github.dsheirer.gui.playlist.channel.ViewChannelRequest;
|
||||
import io.github.dsheirer.playlist.PlaylistManager;
|
||||
import io.github.dsheirer.properties.SystemProperties;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.settings.ColorSettingMenuItem;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.source.ISourceEventProcessor;
|
||||
import io.github.dsheirer.source.SourceEvent;
|
||||
import io.github.dsheirer.source.tuner.Tuner;
|
||||
import io.github.dsheirer.source.tuner.manager.DiscoveredTuner;
|
||||
import io.github.dsheirer.source.tuner.ui.DiscoveredTunerModel;
|
||||
import io.github.dsheirer.spectrum.OverlayPanel.ChannelDisplay;
|
||||
import io.github.dsheirer.spectrum.converter.ComplexDecibelConverter;
|
||||
import io.github.dsheirer.spectrum.converter.DFTResultsConverter;
|
||||
import io.github.dsheirer.spectrum.menu.AveragingItem;
|
||||
import io.github.dsheirer.spectrum.menu.DFTSizeItem;
|
||||
import io.github.dsheirer.spectrum.menu.FFTWindowTypeItem;
|
||||
import io.github.dsheirer.spectrum.menu.FrameRateItem;
|
||||
import io.github.dsheirer.spectrum.menu.SmoothingItem;
|
||||
import io.github.dsheirer.spectrum.menu.SmoothingTypeItem;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
public class SpectralDisplayPanel extends JPanel
|
||||
implements Listener<INativeBuffer>, ISourceEventProcessor, IDFTWidthChangeProcessor
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static Logger mLog = LoggerFactory.getLogger(SpectralDisplayPanel.class);
|
||||
|
||||
public static final String FFT_SIZE_PROPERTY = "spectral.display.dft.size";
|
||||
public static final String SPECTRAL_DISPLAY_ENABLED = "spectral.display.enabled";
|
||||
public static final int NO_ZOOM = 0;
|
||||
public static final int MAX_ZOOM = 6;
|
||||
|
||||
private DFTSize mDFTSize = DFTSize.FFT04096;
|
||||
private int mZoom = 0;
|
||||
private int mDFTZoomWindowOffset = 0;
|
||||
|
||||
private JScrollPane mScrollPane;
|
||||
private JLayeredPane mLayeredPanel;
|
||||
private SpectrumPanel mSpectrumPanel;
|
||||
private WaterfallPanel mWaterfallPanel;
|
||||
private OverlayPanel mOverlayPanel;
|
||||
private ComplexDftProcessor mComplexDftProcessor;
|
||||
private DFTResultsConverter mDFTConverter;
|
||||
private ChannelModel mChannelModel;
|
||||
private ChannelProcessingManager mChannelProcessingManager;
|
||||
private SettingsManager mSettingsManager;
|
||||
private DiscoveredTunerModel mDiscoveredTunerModel;
|
||||
private Tuner mTuner;
|
||||
|
||||
/**
|
||||
* Spectral Display Panel provides a frequency component display with a
|
||||
* historical waterfall display and a transparent overlay to show frequency,
|
||||
* cursor and channel information.
|
||||
* <p>
|
||||
* Mouse scrolling and zooming are supported and the waterfall display can
|
||||
* be paused.
|
||||
* <p>
|
||||
* Complex sample buffers are processed by a DFTProcessor and the output of
|
||||
* the DFT is translated to decibels for display in the spectrum and
|
||||
* waterfall components.
|
||||
*/
|
||||
public SpectralDisplayPanel(PlaylistManager playlistManager, SettingsManager settingsManager, DiscoveredTunerModel discoveredTunerModel)
|
||||
{
|
||||
mChannelModel = playlistManager.getChannelModel();
|
||||
mChannelProcessingManager = playlistManager.getChannelProcessingManager();
|
||||
mSettingsManager = settingsManager;
|
||||
mDiscoveredTunerModel = discoveredTunerModel;
|
||||
|
||||
mSpectrumPanel = new SpectrumPanel(mSettingsManager);
|
||||
mOverlayPanel = new OverlayPanel(mSettingsManager, mChannelModel, mChannelProcessingManager);
|
||||
mWaterfallPanel = new WaterfallPanel(mSettingsManager);
|
||||
|
||||
init();
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
private void loadSettings()
|
||||
{
|
||||
SystemProperties properties = SystemProperties.getInstance();
|
||||
|
||||
String rawSize = properties.get(FFT_SIZE_PROPERTY, DFTSize.FFT04096.name());
|
||||
|
||||
DFTSize size = null;
|
||||
|
||||
if(rawSize != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
size = DFTSize.valueOf(rawSize);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if(size == null)
|
||||
{
|
||||
size = DFTSize.FFT04096;
|
||||
}
|
||||
|
||||
setDFTSize(size, false);
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
/* De-register from receiving samples when the window closes */
|
||||
clearTuner();
|
||||
|
||||
mSettingsManager = null;
|
||||
|
||||
mComplexDftProcessor.dispose();
|
||||
mComplexDftProcessor = null;
|
||||
|
||||
mDFTConverter.dispose();
|
||||
mDFTConverter = null;
|
||||
|
||||
mSpectrumPanel.dispose();
|
||||
mSpectrumPanel = null;
|
||||
|
||||
mWaterfallPanel.dispose();
|
||||
mWaterfallPanel = null;
|
||||
|
||||
mOverlayPanel.dispose();
|
||||
mOverlayPanel = null;
|
||||
|
||||
mTuner = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues an FFT size change request. The scheduled executor will apply
|
||||
* the change when it runs.
|
||||
*/
|
||||
public void setDFTSize(DFTSize size, boolean save)
|
||||
{
|
||||
mComplexDftProcessor.setDFTSize(size);
|
||||
mOverlayPanel.setDFTSize(size);
|
||||
mDFTSize = size;
|
||||
|
||||
if(save)
|
||||
{
|
||||
SystemProperties.getInstance().set(FFT_SIZE_PROPERTY, size.name());
|
||||
}
|
||||
|
||||
setZoom(0, 0, 0);
|
||||
}
|
||||
|
||||
public void setDFTSize(DFTSize size)
|
||||
{
|
||||
setDFTSize(size, true);
|
||||
}
|
||||
|
||||
@Override public DFTSize getDFTSize()
|
||||
{
|
||||
return mDFTSize;
|
||||
}
|
||||
|
||||
public int getZoom()
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current zoom level which will be 2 to the power of zoom (2^zoom)
|
||||
* <p>
|
||||
* 0 No Zoom
|
||||
* 1 2x Zoom
|
||||
* 2 4x Zoom
|
||||
* 3 8x Zoom
|
||||
* 4 16x Zoom
|
||||
* 5 32x Zoom
|
||||
* 6 64x Zoom
|
||||
*
|
||||
* @param zoom level, 0 - 6.
|
||||
* @param frequency under the mouse to maintain while zooming
|
||||
* @param windowOffset where to maintain the frequency under the mouse
|
||||
*/
|
||||
public void setZoom(int zoom, long frequency, double windowOffset)
|
||||
{
|
||||
if(zoom < NO_ZOOM)
|
||||
{
|
||||
zoom = NO_ZOOM;
|
||||
}
|
||||
else if(zoom > MAX_ZOOM)
|
||||
{
|
||||
zoom = MAX_ZOOM;
|
||||
}
|
||||
|
||||
if(zoom != mZoom)
|
||||
{
|
||||
mZoom = zoom;
|
||||
|
||||
//Calculate the bin offset that would place the reference frequency
|
||||
//at the left edge of the zoom window.
|
||||
double binOffsetToFrequency = getBinOffset(frequency);
|
||||
|
||||
//Calculate the bin offset into the newly sized zoom window that
|
||||
//would place the frequency in the same proportional window location
|
||||
//that it was in the previous zoom size
|
||||
double windowBinOffset = (double)getZoomWindowSizeInBins() * windowOffset;
|
||||
|
||||
//Set the overall offset to place the reference frequency in the
|
||||
//same location in the newly zoomed window
|
||||
double offset = binOffsetToFrequency - windowBinOffset;
|
||||
|
||||
mSpectrumPanel.setZoom(mZoom);
|
||||
mOverlayPanel.setZoom(mZoom);
|
||||
mWaterfallPanel.setZoom(mZoom);
|
||||
|
||||
setZoomWindowOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the offset (in DFT bins) to the first bin that the zoom window displays
|
||||
*/
|
||||
public void setZoomWindowOffset(double offset)
|
||||
{
|
||||
if(offset < 0)
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if(offset > (mDFTSize.getSize() - getZoomWindowSizeInBins()))
|
||||
{
|
||||
offset = mDFTSize.getSize() - getZoomWindowSizeInBins();
|
||||
}
|
||||
|
||||
mDFTZoomWindowOffset = (int)offset;
|
||||
|
||||
mSpectrumPanel.setZoomWindowOffset(mDFTZoomWindowOffset);
|
||||
mOverlayPanel.setZoomWindowOffset(mDFTZoomWindowOffset);
|
||||
mWaterfallPanel.setZoomWindowOffset(mDFTZoomWindowOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the size of the current zoom window in DFT bins
|
||||
*/
|
||||
private int getZoomWindowSizeInBins()
|
||||
{
|
||||
return mDFTSize.getSize() / getZoomMultiplier();
|
||||
}
|
||||
|
||||
public int getZoomMultiplier()
|
||||
{
|
||||
return (int)FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the overall offset of the frequency from the current minimum
|
||||
* frequency in terms of total FFT width
|
||||
*
|
||||
* @param frequency
|
||||
* @return
|
||||
*/
|
||||
private double getBinOffset(long frequency)
|
||||
{
|
||||
double offset = 0.0;
|
||||
|
||||
if(mOverlayPanel.containsFrequency(frequency))
|
||||
{
|
||||
offset = (double)mDFTSize.getSize() * ((double)(frequency - mOverlayPanel.getMinFrequency())
|
||||
/ (double)mOverlayPanel.getBandwidth());
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides JComponent method to return false, since we have overlapping
|
||||
* panels with the spectrum and channel panels
|
||||
*/
|
||||
public boolean isOptimizedDrawingEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]"));
|
||||
|
||||
/**
|
||||
* The layered pane holds the overlapping spectrum and channel panels
|
||||
* and manages the sizing of each panel with the resize listener
|
||||
*/
|
||||
mLayeredPanel = new JLayeredPane();
|
||||
mLayeredPanel.addComponentListener(new ResizeListener());
|
||||
|
||||
/**
|
||||
* Create a mouse adapter to handle mouse events over the spectrum
|
||||
* and waterfall panels
|
||||
*/
|
||||
MouseEventProcessor mouser = new MouseEventProcessor();
|
||||
|
||||
mOverlayPanel.addMouseListener(mouser);
|
||||
mOverlayPanel.addMouseMotionListener(mouser);
|
||||
mOverlayPanel.addMouseWheelListener(mouser);
|
||||
|
||||
//Add the spectrum and channel panels to the layered panel
|
||||
mLayeredPanel.add(mSpectrumPanel, 0, 0);
|
||||
mLayeredPanel.add(mOverlayPanel, 1, 0);
|
||||
|
||||
//Create the waterfall
|
||||
mWaterfallPanel.addMouseListener(mouser);
|
||||
mWaterfallPanel.addMouseMotionListener(mouser);
|
||||
mWaterfallPanel.addMouseWheelListener(mouser);
|
||||
|
||||
/* Attempt to set a 50/50 split preferred size for the split pane */
|
||||
double totalHeight =
|
||||
mLayeredPanel.getPreferredSize().getHeight() + mWaterfallPanel.getPreferredSize().getHeight();
|
||||
|
||||
mLayeredPanel.setPreferredSize(
|
||||
new Dimension((int)mLayeredPanel.getPreferredSize().getWidth(), (int)(totalHeight / 2.0d)));
|
||||
|
||||
mWaterfallPanel.setPreferredSize(
|
||||
new Dimension((int)mWaterfallPanel.getPreferredSize().getWidth(), (int)(totalHeight / 2.0d)));
|
||||
|
||||
//Create the split pane to hold the layered pane and the waterfall
|
||||
JideSplitPane splitPane = new JideSplitPane(JSplitPane.VERTICAL_SPLIT);
|
||||
splitPane.setDividerSize(5);
|
||||
splitPane.add(mLayeredPanel);
|
||||
splitPane.add(mWaterfallPanel);
|
||||
|
||||
mScrollPane = new JScrollPane(splitPane);
|
||||
|
||||
add(mScrollPane, "grow");
|
||||
|
||||
/**
|
||||
* Setup DFTProcessor to process samples and register the waterfall and
|
||||
* spectrum panel to receive the processed dft results
|
||||
*/
|
||||
mComplexDftProcessor = new ComplexDftProcessor();
|
||||
mDFTConverter = new ComplexDecibelConverter();
|
||||
mComplexDftProcessor.addConverter(mDFTConverter);
|
||||
|
||||
mDFTConverter.addListener((DFTResultsListener)mSpectrumPanel);
|
||||
mDFTConverter.addListener((DFTResultsListener)mWaterfallPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives frequency change events -- primarily from tuner components.
|
||||
*/
|
||||
public void process(SourceEvent event)
|
||||
{
|
||||
mOverlayPanel.process(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Complex sample buffer receive method
|
||||
*/
|
||||
@Override public void receive(INativeBuffer nativeBuffer)
|
||||
{
|
||||
mComplexDftProcessor.receive(nativeBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to tuner event by deregistering from the current
|
||||
* complex sample buffer source and registering with the tuner argument.
|
||||
*/
|
||||
public void showTuner(Tuner tuner)
|
||||
{
|
||||
clearTuner();
|
||||
|
||||
mComplexDftProcessor.clearBuffer();
|
||||
|
||||
mComplexDftProcessor.start();
|
||||
|
||||
mTuner = tuner;
|
||||
|
||||
if(mTuner != null)
|
||||
{
|
||||
//Register the dft processor to receive samples from the tuner
|
||||
mTuner.getTunerController().addBufferListener(mComplexDftProcessor);
|
||||
|
||||
//Verify that the tuner is still non-null, in case it encountered an error on starting sample stream
|
||||
if(mTuner != null)
|
||||
{
|
||||
//Register to receive frequency change events
|
||||
mTuner.getTunerController().addListener(this);
|
||||
|
||||
mSpectrumPanel.setSampleSize(mTuner.getSampleSize());
|
||||
|
||||
//Fire frequency and sample rate change events so that the spectrum
|
||||
//and overlay panels can synchronize
|
||||
process(SourceEvent.frequencyChange(null, mTuner.getTunerController().getFrequency()));
|
||||
process(SourceEvent.sampleRateChange(mTuner.getTunerController().getSampleRate()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tuner de-selection cleanup method
|
||||
*/
|
||||
public void clearTuner()
|
||||
{
|
||||
if(mTuner != null)
|
||||
{
|
||||
//Deregister for frequency change events from the tuner
|
||||
mTuner.getTunerController().removeListener(SpectralDisplayPanel.this);
|
||||
|
||||
//Deregister the dft processor from receiving samples
|
||||
mTuner.getTunerController().removeBufferListener(mComplexDftProcessor);
|
||||
mTuner = null;
|
||||
}
|
||||
|
||||
mComplexDftProcessor.stop();
|
||||
mComplexDftProcessor.clearBuffer();
|
||||
mSpectrumPanel.clearSpectrum();
|
||||
mWaterfallPanel.clearWaterfall();
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently displayed tuner
|
||||
*/
|
||||
public Tuner getTuner()
|
||||
{
|
||||
return mTuner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors the sizing of the layered pane and resizes the spectrum and
|
||||
* channel panels whenever the layered pane is resized
|
||||
*/
|
||||
public class ResizeListener implements ComponentListener
|
||||
{
|
||||
@Override public void componentResized(ComponentEvent e)
|
||||
{
|
||||
Component c = e.getComponent();
|
||||
|
||||
mSpectrumPanel.setBounds(0, 0, c.getWidth(), c.getHeight());
|
||||
mOverlayPanel.setBounds(0, 0, c.getWidth(), c.getHeight());
|
||||
}
|
||||
|
||||
@Override public void componentHidden(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override public void componentMoved(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override public void componentShown(ComponentEvent arg0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse event handler for the spectral display panel.
|
||||
*/
|
||||
public class MouseEventProcessor extends MouseInputAdapter
|
||||
{
|
||||
private int mDFTZoomWindowOffsetAtDragStart = 0;
|
||||
private int mDragStartX = 0;
|
||||
private double mPixelsPerBin;
|
||||
|
||||
public MouseEventProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
@Override public void mouseWheelMoved(MouseWheelEvent e)
|
||||
{
|
||||
int zoom = mZoom - e.getWheelRotation();
|
||||
|
||||
long frequency = mOverlayPanel.getFrequencyFromAxis(e.getX());
|
||||
|
||||
double windowOffset = (double)e.getX() / (double)getWidth();
|
||||
|
||||
setZoom(zoom, frequency, windowOffset);
|
||||
}
|
||||
|
||||
@Override public void mouseMoved(MouseEvent event)
|
||||
{
|
||||
update(event);
|
||||
}
|
||||
|
||||
@Override public void mouseDragged(MouseEvent event)
|
||||
{
|
||||
update(event);
|
||||
|
||||
int dragDistance = mDragStartX - event.getX();
|
||||
|
||||
double binDistance = (double)dragDistance / mPixelsPerBin;
|
||||
|
||||
int offset = (int)(mDFTZoomWindowOffsetAtDragStart + binDistance);
|
||||
|
||||
if(offset < 0)
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
int maxOffset = mDFTSize.getSize() - (mDFTSize.getSize() / getZoomMultiplier());
|
||||
|
||||
if(offset > maxOffset)
|
||||
{
|
||||
offset = maxOffset;
|
||||
}
|
||||
|
||||
setZoomWindowOffset(offset);
|
||||
}
|
||||
|
||||
@Override public void mousePressed(MouseEvent e)
|
||||
{
|
||||
mDragStartX = e.getX();
|
||||
|
||||
mDFTZoomWindowOffsetAtDragStart = mDFTZoomWindowOffset;
|
||||
|
||||
mPixelsPerBin = (double)getWidth() / ((double)(mDFTSize.getSize()) / (double)getZoomMultiplier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the cursor display while the mouse is performing actions
|
||||
*/
|
||||
private void update(MouseEvent event)
|
||||
{
|
||||
if(event.getComponent() == mOverlayPanel)
|
||||
{
|
||||
mOverlayPanel.setCursorLocation(event.getPoint());
|
||||
}
|
||||
else
|
||||
{
|
||||
mWaterfallPanel.setCursorLocation(event.getPoint());
|
||||
mWaterfallPanel.setCursorFrequency(mOverlayPanel.getFrequencyFromAxis(event.getPoint().x));
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
if(e.getComponent() == mOverlayPanel)
|
||||
{
|
||||
mOverlayPanel.setCursorVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mWaterfallPanel.setCursorVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void mouseExited(MouseEvent e)
|
||||
{
|
||||
mOverlayPanel.setCursorVisible(false);
|
||||
mWaterfallPanel.setCursorVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the context menu.
|
||||
*/
|
||||
@Override public void mouseClicked(MouseEvent event)
|
||||
{
|
||||
if(SwingUtilities.isRightMouseButton(event))
|
||||
{
|
||||
JPopupMenu contextMenu = new JPopupMenu();
|
||||
|
||||
if(event.getComponent() == mWaterfallPanel)
|
||||
{
|
||||
contextMenu.add(new PauseItem(mWaterfallPanel, "Pause"));
|
||||
contextMenu.add(new JSeparator());
|
||||
}
|
||||
|
||||
long frequency = mOverlayPanel.getFrequencyFromAxis(event.getX());
|
||||
|
||||
if(event.getComponent() == mOverlayPanel)
|
||||
{
|
||||
ArrayList<Channel> channels = mOverlayPanel.getChannelsAtFrequency(frequency);
|
||||
|
||||
JMenu channelMenu = new JMenu("Channels");
|
||||
for(Channel channel : channels)
|
||||
{
|
||||
JMenuItem viewChannel = new JMenuItem("View/Edit: " + channel.getShortTitle());
|
||||
viewChannel.addActionListener(
|
||||
e -> MyEventBus.getGlobalEventBus().post(new ViewChannelRequest(channel)));
|
||||
channelMenu.add(viewChannel);
|
||||
}
|
||||
|
||||
contextMenu.add(channelMenu);
|
||||
|
||||
if(!channels.isEmpty())
|
||||
{
|
||||
contextMenu.add(new JSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Color Menus
|
||||
*/
|
||||
JMenu colorMenu = new JMenu("Color");
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.CHANNEL_CONFIG));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.CHANNEL_CONFIG_PROCESSING));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.CHANNEL_CONFIG_SELECTED));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.SPECTRUM_CURSOR));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.SPECTRUM_LINE));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.SPECTRUM_BACKGROUND));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.SPECTRUM_GRADIENT_BOTTOM));
|
||||
|
||||
colorMenu.add(new ColorSettingMenuItem(mSettingsManager, ColorSettingName.SPECTRUM_GRADIENT_TOP));
|
||||
|
||||
contextMenu.add(colorMenu);
|
||||
|
||||
/**
|
||||
* Display items: fft and frame rate
|
||||
*/
|
||||
JMenu displayMenu = new JMenu("Display");
|
||||
contextMenu.add(displayMenu);
|
||||
|
||||
if(event.getComponent() != mWaterfallPanel)
|
||||
{
|
||||
/**
|
||||
* Averaging menu
|
||||
*/
|
||||
JMenu averagingMenu = new JMenu("Averaging");
|
||||
averagingMenu.add(new AveragingItem(mSpectrumPanel, 4));
|
||||
displayMenu.add(averagingMenu);
|
||||
|
||||
/**
|
||||
* Channel Display setting menu
|
||||
*/
|
||||
JMenu channelDisplayMenu = new JMenu("Channel");
|
||||
|
||||
channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel, ChannelDisplay.ALL));
|
||||
channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel, ChannelDisplay.ENABLED));
|
||||
channelDisplayMenu.add(new ChannelDisplayItem(mOverlayPanel, ChannelDisplay.NONE));
|
||||
|
||||
displayMenu.add(channelDisplayMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* FFT width
|
||||
*/
|
||||
JMenu fftWidthMenu = new JMenu("FFT Width");
|
||||
displayMenu.add(fftWidthMenu);
|
||||
|
||||
for(DFTSize width : DFTSize.values())
|
||||
{
|
||||
fftWidthMenu.add(new DFTSizeItem(SpectralDisplayPanel.this, width));
|
||||
}
|
||||
|
||||
/**
|
||||
* DFT Processor Frame Rate
|
||||
*/
|
||||
JMenu frameRateMenu = new JMenu("Frame Rate");
|
||||
displayMenu.add(frameRateMenu);
|
||||
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 14));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 16));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 18));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 20));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 25));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 30));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 40));
|
||||
frameRateMenu.add(new FrameRateItem(mComplexDftProcessor, 50));
|
||||
|
||||
/**
|
||||
* FFT Window Type
|
||||
*/
|
||||
JMenu fftWindowType = new JMenu("Window Type");
|
||||
displayMenu.add(fftWindowType);
|
||||
|
||||
for(WindowType type : WindowType.values())
|
||||
{
|
||||
fftWindowType.add(new FFTWindowTypeItem(mComplexDftProcessor, type));
|
||||
}
|
||||
|
||||
if(event.getComponent() != mWaterfallPanel)
|
||||
{
|
||||
/**
|
||||
* Smoothing menu
|
||||
*/
|
||||
JMenu smoothingMenu = new JMenu("Smoothing");
|
||||
|
||||
if(mSpectrumPanel.getSmoothingType() != SmoothingType.NONE)
|
||||
{
|
||||
smoothingMenu.add(new SmoothingItem(mSpectrumPanel, 5));
|
||||
smoothingMenu.add(new JSeparator());
|
||||
}
|
||||
smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel, SmoothingType.GAUSSIAN));
|
||||
smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel, SmoothingType.TRIANGLE));
|
||||
smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel, SmoothingType.RECTANGLE));
|
||||
smoothingMenu.add(new SmoothingTypeItem(mSpectrumPanel, SmoothingType.NONE));
|
||||
|
||||
displayMenu.add(smoothingMenu);
|
||||
}
|
||||
|
||||
/*
|
||||
* Zoom menu
|
||||
*/
|
||||
JMenuItem zoomMenu = new JMenu("Zoom");
|
||||
|
||||
double windowOffset = (double)event.getX() / (double)getWidth();
|
||||
|
||||
zoomMenu.add(new ZoomItem(frequency, windowOffset));
|
||||
|
||||
contextMenu.add(zoomMenu);
|
||||
|
||||
if(mTuner != null)
|
||||
{
|
||||
contextMenu.add(new JSeparator());
|
||||
contextMenu.add(new DisableSpectrumWaterfallMenuItem(SpectralDisplayPanel.this));
|
||||
}
|
||||
|
||||
boolean separatorAdded = false;
|
||||
|
||||
for(DiscoveredTuner discoveredTuner : mDiscoveredTunerModel.getAvailableTuners())
|
||||
{
|
||||
if(mTuner == null || mTuner != discoveredTuner.getTuner())
|
||||
{
|
||||
if(!separatorAdded)
|
||||
{
|
||||
contextMenu.add(new JSeparator());
|
||||
separatorAdded = true;
|
||||
}
|
||||
|
||||
contextMenu.add(new ShowTunerMenuItem(mDiscoveredTunerModel, discoveredTuner.getTuner()));
|
||||
}
|
||||
}
|
||||
|
||||
if(contextMenu != null)
|
||||
{
|
||||
if(event.getComponent() == mOverlayPanel)
|
||||
{
|
||||
contextMenu.show(mOverlayPanel, event.getX(), event.getY());
|
||||
}
|
||||
else
|
||||
{
|
||||
contextMenu.show(mWaterfallPanel, event.getX(), event.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PauseItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Pausable mPausable;
|
||||
|
||||
public PauseItem(Pausable pausable, String label)
|
||||
{
|
||||
super(label);
|
||||
|
||||
final boolean paused = pausable.isPaused();
|
||||
|
||||
setSelected(paused);
|
||||
|
||||
mPausable = pausable;
|
||||
|
||||
addActionListener(new ActionListener()
|
||||
{
|
||||
@Override public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override public void run()
|
||||
{
|
||||
mPausable.setPaused(!paused);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ZoomItem extends JSlider
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private long mFrequency;
|
||||
private double mWindowOffset;
|
||||
|
||||
public ZoomItem(long frequency, double windowOffset)
|
||||
{
|
||||
super(NO_ZOOM, MAX_ZOOM, mZoom);
|
||||
|
||||
mFrequency = frequency;
|
||||
mWindowOffset = windowOffset;
|
||||
|
||||
Hashtable<Integer, JComponent> labels = new Hashtable<>();
|
||||
labels.put(0, new JLabel("1x"));
|
||||
labels.put(1, new JLabel("2x"));
|
||||
labels.put(2, new JLabel("4x"));
|
||||
labels.put(3, new JLabel("8x"));
|
||||
labels.put(4, new JLabel("16x"));
|
||||
labels.put(5, new JLabel("32x"));
|
||||
labels.put(6, new JLabel("64x"));
|
||||
|
||||
setLabelTable(labels);
|
||||
|
||||
setMajorTickSpacing(1);
|
||||
setMinorTickSpacing(1);
|
||||
setPaintTicks(true);
|
||||
setPaintLabels(true);
|
||||
|
||||
this.addChangeListener(new ChangeListener()
|
||||
{
|
||||
@Override public void stateChanged(ChangeEvent e)
|
||||
{
|
||||
setZoom(getValue(), mFrequency, mWindowOffset);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class ChannelDisplayItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private OverlayPanel mOverlayPanel;
|
||||
private ChannelDisplay mChannelDisplay;
|
||||
|
||||
public ChannelDisplayItem(OverlayPanel panel, ChannelDisplay display)
|
||||
{
|
||||
super(display.name());
|
||||
|
||||
mOverlayPanel = panel;
|
||||
|
||||
mChannelDisplay = display;
|
||||
|
||||
setSelected(mOverlayPanel.getChannelDisplay() == mChannelDisplay);
|
||||
|
||||
addActionListener(new ActionListener()
|
||||
{
|
||||
@Override public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
@Override public void run()
|
||||
{
|
||||
mOverlayPanel.setChannelDisplay(mChannelDisplay);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.playlist.PlaylistManager;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import io.github.dsheirer.source.tuner.Tuner;
|
||||
import io.github.dsheirer.source.tuner.ui.DiscoveredTunerModel;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
public class SpectrumFrame extends JFrame implements WindowListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SpectralDisplayPanel mSpectralDisplayPanel;
|
||||
|
||||
public SpectrumFrame(PlaylistManager playlistManager, SettingsManager settingsManager,
|
||||
DiscoveredTunerModel discoveredTunerModel, Tuner tuner)
|
||||
{
|
||||
setTitle("SDRTRunk [" + tuner.getPreferredName() + "]");
|
||||
setBounds(100, 100, 1280, 600);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
|
||||
setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]"));
|
||||
|
||||
mSpectralDisplayPanel = new SpectralDisplayPanel(playlistManager, settingsManager, discoveredTunerModel);
|
||||
|
||||
mSpectralDisplayPanel.showTuner(tuner);
|
||||
add(mSpectralDisplayPanel, "grow");
|
||||
|
||||
/* Register a shutdown listener */
|
||||
this.addWindowListener(this);
|
||||
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent arg0)
|
||||
{
|
||||
mSpectralDisplayPanel.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent arg0)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import java.awt.image.IndexColorModel;
|
||||
|
||||
|
||||
public class WaterfallColorModel
|
||||
{
|
||||
public static IndexColorModel getDefaultColorModel()
|
||||
{
|
||||
int bitDepth = 8;
|
||||
int indexSize = 256;
|
||||
|
||||
byte[] red = new byte[ indexSize ];
|
||||
byte[] green = new byte[ indexSize ];
|
||||
byte[] blue = new byte[ indexSize ];
|
||||
|
||||
//Background noise
|
||||
for( int x = 0; x < 16; x++ ) //Blue
|
||||
{
|
||||
red[ x ] = (byte)0;
|
||||
|
||||
green[ x ] = (byte)0;
|
||||
|
||||
blue[ x ] = (byte)127;
|
||||
}
|
||||
|
||||
for( int x = 16; x < 32; x++ ) //Blue
|
||||
{
|
||||
red[ x ] = (byte)0;
|
||||
|
||||
green[ x ] = (byte)0;
|
||||
|
||||
blue[ x ] = (byte)191;
|
||||
}
|
||||
|
||||
int r = 0;
|
||||
int g = 0;
|
||||
int b = 191;
|
||||
|
||||
for( int x = 32; x < 60; x++ )
|
||||
{
|
||||
red[ x ] = (byte)r;
|
||||
r += 9;
|
||||
|
||||
green[ x ] = (byte)g;
|
||||
g += 9;
|
||||
|
||||
blue[ x ] = (byte)b;
|
||||
b -= 6;
|
||||
}
|
||||
|
||||
r = 255;
|
||||
g = 255;
|
||||
b = 0;
|
||||
|
||||
for( int x = 60; x < 188; x++ ) //Yellow
|
||||
{
|
||||
red[ x ] = (byte)r;
|
||||
|
||||
green[ x ] = (byte)g;
|
||||
g -= 2;
|
||||
|
||||
blue[ x ] = (byte)b;
|
||||
}
|
||||
|
||||
for( int x = 188; x < 256; x++ ) //Red
|
||||
{
|
||||
red[ x ] = (byte)255;
|
||||
|
||||
green[ x ] = (byte)0;
|
||||
|
||||
blue[ x ] = (byte)0;
|
||||
}
|
||||
|
||||
return new IndexColorModel( bitDepth, indexSize, red, green, blue );
|
||||
}
|
||||
}
|
||||
@@ -1,425 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
package io.github.dsheirer.spectrum;
|
||||
|
||||
import io.github.dsheirer.settings.ColorSetting;
|
||||
import io.github.dsheirer.settings.ColorSetting.ColorSettingName;
|
||||
import io.github.dsheirer.settings.Setting;
|
||||
import io.github.dsheirer.settings.SettingChangeListener;
|
||||
import io.github.dsheirer.settings.SettingsManager;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class WaterfallPanel extends JPanel implements DFTResultsListener,
|
||||
Pausable,
|
||||
SettingChangeListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger(WaterfallPanel.class);
|
||||
|
||||
private static DecimalFormat CURSOR_FORMAT = new DecimalFormat("0.00000");
|
||||
private static final String PAUSED = "PAUSED - Right Click to Unpause";
|
||||
private static final String DISABLED = "DISABLED - Right Click to Select a Tuner";
|
||||
|
||||
private byte[] mPixels;
|
||||
private byte[] mPausedPixels;
|
||||
private int mDFTSize = 4096;
|
||||
private int mImageHeight = 700;
|
||||
private IndexColorModel mColorModel = WaterfallColorModel.getDefaultColorModel();
|
||||
private Color mColorSpectrumCursor;
|
||||
private BufferedImage mVisibleImage;
|
||||
private byte[] mVisiblePixels;
|
||||
private boolean mIsDisposed = false;
|
||||
|
||||
private Point mCursorLocation = new Point(0, 0);
|
||||
private boolean mCursorVisible = false;
|
||||
private long mCursorFrequency = 0;
|
||||
private boolean mPaused = false;
|
||||
private boolean mDisabled = true;
|
||||
private int mZoom = 0;
|
||||
private int mDFTZoomWindowOffset = 0;
|
||||
|
||||
private SettingsManager mSettingsManager;
|
||||
|
||||
/**
|
||||
* Displays a scrolling window of multiple DFT frequency bin outputs over
|
||||
* time. Maps DFT frequency bin decibel values into a 256 bucket color map
|
||||
* for display.
|
||||
*
|
||||
* @param settingsManager
|
||||
*/
|
||||
public WaterfallPanel(SettingsManager settingsManager)
|
||||
{
|
||||
super();
|
||||
mSettingsManager = settingsManager;
|
||||
mSettingsManager.addListener(this);
|
||||
mColorSpectrumCursor = getColor(ColorSettingName.SPECTRUM_CURSOR);
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares this instance for disposal
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
if(mSettingsManager != null)
|
||||
{
|
||||
mSettingsManager.removeListener(this);
|
||||
}
|
||||
|
||||
mSettingsManager = null;
|
||||
mIsDisposed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the byte backing arrays when the DFT point size has changed
|
||||
*/
|
||||
private void reset()
|
||||
{
|
||||
mPixels = new byte[mDFTSize * mImageHeight];
|
||||
|
||||
if(mPaused)
|
||||
{
|
||||
mPausedPixels = mPixels.clone();
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pausable interface - pauses updates to the waterfall
|
||||
*/
|
||||
public void setPaused(boolean paused)
|
||||
{
|
||||
if(paused)
|
||||
{
|
||||
mPausedPixels = mPixels.clone();
|
||||
}
|
||||
|
||||
mPaused = paused;
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current pause state
|
||||
*
|
||||
* @return true if paused, false otherwise
|
||||
*/
|
||||
public boolean isPaused()
|
||||
{
|
||||
return mPaused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the waterfall is currently disabled.
|
||||
*/
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return mDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current zoom level (2^zoom)
|
||||
*
|
||||
* 0 No Zoom
|
||||
* 1 2x Zoom
|
||||
* 2 4x Zoom
|
||||
* 3 8x Zoom
|
||||
* 4 16x Zoom
|
||||
* 5 32x Zoom
|
||||
* 6 64x Zoom
|
||||
*
|
||||
* @param zoom level, 0 - 6.
|
||||
*/
|
||||
public void setZoom(int zoom)
|
||||
{
|
||||
mZoom = zoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplier for the current zoom level
|
||||
*/
|
||||
private int getZoomMultiplier()
|
||||
{
|
||||
return (int) FastMath.pow(2.0, mZoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the zoom window offset from zero
|
||||
*
|
||||
* @param offset in DFT bins
|
||||
*/
|
||||
public void setZoomWindowOffset(int offset)
|
||||
{
|
||||
mDFTZoomWindowOffset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a named color setting from the settings manager. If the setting
|
||||
* doesn't exist, creates the setting using the defaultColor
|
||||
*/
|
||||
private Color getColor(ColorSettingName name)
|
||||
{
|
||||
ColorSetting setting = mSettingsManager.getColorSetting(name);
|
||||
|
||||
return setting.getColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors for setting changes. Colors can be changed by external actions
|
||||
* and will automatically update in this class
|
||||
*/
|
||||
@Override
|
||||
public void settingChanged(Setting setting)
|
||||
{
|
||||
if(setting instanceof ColorSetting colorSetting)
|
||||
{
|
||||
if(colorSetting.getColorSettingName() == ColorSettingName.SPECTRUM_CURSOR)
|
||||
{
|
||||
mColorSpectrumCursor = colorSetting.getColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingDeleted(Setting setting)
|
||||
{ /* Not implemented */ }
|
||||
|
||||
/**
|
||||
* Sets the display location of the cursor. Cursor location monitoring is
|
||||
* handled external to this class.
|
||||
*
|
||||
* @param point
|
||||
*/
|
||||
public void setCursorLocation(Point point)
|
||||
{
|
||||
mCursorLocation = point;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current cursor display frequency. Cursor location frequency
|
||||
* monitoring is handled external to this class.
|
||||
*
|
||||
* @param frequency
|
||||
*/
|
||||
public void setCursorFrequency(long frequency)
|
||||
{
|
||||
mCursorFrequency = frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the visibility of the cursor
|
||||
*
|
||||
* @param visible
|
||||
*/
|
||||
public void setCursorVisible(boolean visible)
|
||||
{
|
||||
mCursorVisible = visible;
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the DFT bins that are visible at the current zoom level and offset into an image that is sized to hold
|
||||
* only those bins. The whole waterfall can't be scaled to the zoomed width and clipped to the panel because the
|
||||
* XRender pipeline silently renders nothing once the scaled width of the source image reaches 65,536 pixels.
|
||||
*
|
||||
* The image's pixel array is accessed directly, so Java2D doesn't cache it and each paint renders the current bins.
|
||||
*
|
||||
* @param multiplier - current zoom multiplier
|
||||
*/
|
||||
private void updateVisibleImage(int multiplier)
|
||||
{
|
||||
int bins = mDFTSize / multiplier;
|
||||
|
||||
if(mVisibleImage == null || mVisibleImage.getWidth() != bins)
|
||||
{
|
||||
mVisibleImage = new BufferedImage(bins, mImageHeight, BufferedImage.TYPE_BYTE_INDEXED, mColorModel);
|
||||
mVisiblePixels = ((DataBufferByte)mVisibleImage.getRaster().getDataBuffer()).getData();
|
||||
}
|
||||
|
||||
byte[] source = mPaused ? mPausedPixels : mPixels;
|
||||
|
||||
//The display is shifted one bin to the left, to align with the spectrum. Bins past the end are set to zero.
|
||||
int firstBin = Math.min(mDFTZoomWindowOffset + 1, mDFTSize);
|
||||
int length = Math.min(bins, mDFTSize - firstBin);
|
||||
|
||||
for(int row = 0; row < mImageHeight; row++)
|
||||
{
|
||||
int destination = row * bins;
|
||||
System.arraycopy(source, (row * mDFTSize) + firstBin, mVisiblePixels, destination, length);
|
||||
Arrays.fill(mVisiblePixels, destination + length, destination + bins, (byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the screen at each refresh
|
||||
*/
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
super.paintComponent(g);
|
||||
|
||||
updateVisibleImage(getZoomMultiplier());
|
||||
g.drawImage(mVisibleImage, 0, 0, getWidth(), mImageHeight, null);
|
||||
Graphics2D graphics = (Graphics2D)g;
|
||||
graphics.setColor(mColorSpectrumCursor);
|
||||
|
||||
if(mCursorVisible)
|
||||
{
|
||||
graphics.draw(new Line2D.Float(mCursorLocation.x, 0, mCursorLocation.x, (float)(getSize().getHeight())));
|
||||
String frequency = CURSOR_FORMAT.format(mCursorFrequency / 1000000.0D);
|
||||
graphics.drawString(frequency, mCursorLocation.x + 5, mCursorLocation.y);
|
||||
}
|
||||
|
||||
if(mDisabled)
|
||||
{
|
||||
graphics.drawString(DISABLED, 20, 20);
|
||||
}
|
||||
else if(mPaused)
|
||||
{
|
||||
graphics.drawString(PAUSED, 20, 20);
|
||||
}
|
||||
|
||||
paintZoomIndicator(graphics);
|
||||
graphics.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* When zoom level is greater than zero, paints a small indicator at the
|
||||
* bottom center of the screen showing the location of the zoom window
|
||||
* within the overall DFT results window
|
||||
*/
|
||||
private void paintZoomIndicator(Graphics2D graphics)
|
||||
{
|
||||
if(mZoom != 0)
|
||||
{
|
||||
int width = getWidth() / 4;
|
||||
int x = (getWidth() / 2) - (width / 2);
|
||||
|
||||
//Draw the outer window
|
||||
graphics.drawRect(x, getHeight() - 12, width, 10);
|
||||
int zoomWidth = width / getZoomMultiplier();
|
||||
int windowOffset = 0;
|
||||
|
||||
if(mDFTZoomWindowOffset != 0)
|
||||
{
|
||||
windowOffset = (int)(((double)mDFTZoomWindowOffset / (double)mDFTSize) * width);
|
||||
}
|
||||
|
||||
//Draw the zoom window
|
||||
graphics.fillRect(x + windowOffset, getHeight() - 12, zoomWidth, 10);
|
||||
|
||||
//Draw the zoom text
|
||||
graphics.drawString("Zoom: " + getZoomMultiplier() + "x", x + width + 3, getHeight() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the DFT results listener interface method. This is the primary method for receiving new frequency bin results.
|
||||
*/
|
||||
@Override
|
||||
public void receive(float[] update)
|
||||
{
|
||||
mDisabled = false;
|
||||
|
||||
byte[] newPixels = new byte[update.length];
|
||||
|
||||
/**
|
||||
* Find the average value and scale the display to it
|
||||
*/
|
||||
double sum = 0.0d;
|
||||
|
||||
for(int x = 0; x < update.length - 1; x++)
|
||||
{
|
||||
sum += update[x];
|
||||
}
|
||||
|
||||
float average = (float)(sum / (double)update.length - 1);
|
||||
float scale = 256.0f / average;
|
||||
|
||||
for(int x = 0; x < update.length - 1; x++)
|
||||
{
|
||||
float value = (average - update[x]) * scale;
|
||||
|
||||
if(value < 0)
|
||||
{
|
||||
newPixels[x] = 0;
|
||||
}
|
||||
else if(value > 255)
|
||||
{
|
||||
newPixels[x] = (byte)255;
|
||||
}
|
||||
else
|
||||
{
|
||||
newPixels[x] = (byte)value;
|
||||
}
|
||||
}
|
||||
|
||||
//Task the swing event thread to add the new pixels to the pixel array and update the display
|
||||
EventQueue.invokeLater(() -> {
|
||||
if(!mIsDisposed)
|
||||
{
|
||||
//If our FFT size changes, reset our pixel map
|
||||
if(mDFTSize != newPixels.length)
|
||||
{
|
||||
mDFTSize = newPixels.length;
|
||||
reset();
|
||||
}
|
||||
|
||||
//Move the pixels down a row and add in the new pixels row
|
||||
System.arraycopy(mPixels, 0, mPixels, mDFTSize, mPixels.length - mDFTSize);
|
||||
System.arraycopy(newPixels, 0, mPixels, 0, newPixels.length);
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clearWaterfall()
|
||||
{
|
||||
mDisabled = true;
|
||||
|
||||
EventQueue.invokeLater(() -> {
|
||||
Arrays.fill(mPixels, (byte)0);
|
||||
|
||||
if(mPausedPixels != null)
|
||||
{
|
||||
Arrays.fill(mPausedPixels, (byte)0);
|
||||
}
|
||||
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,22 @@ public class ComplexDecibelConverter extends DFTResultsConverter
|
||||
}
|
||||
|
||||
public static float[] convert(float[] results)
|
||||
{
|
||||
return convert(results, 1.0f / (float)(results.length / 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the output of the JTransforms FloatFFT_1D.complexForward() calculation into decibels, with each bin's
|
||||
* power (magnitude squared) multiplied by the scale factor, and swaps the upper and lower halves of the results
|
||||
* so the lowest frequency is first.
|
||||
* @param results interleaved complex DFT results
|
||||
* @param powerScale to multiply each bin's power by before converting to decibels
|
||||
* @return decibel value for each bin, half the length of the results
|
||||
*/
|
||||
public static float[] convert(float[] results, float powerScale)
|
||||
{
|
||||
int halfResults = results.length / 2;
|
||||
float dftBinSizeScalor = 1.0f / (float) halfResults;
|
||||
float dftBinSizeScalor = powerScale;
|
||||
float[] processed = new float[halfResults];
|
||||
int middle = processed.length / 2;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2026 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.spectrum.converter;
|
||||
|
||||
/**
|
||||
* Converts complex DFT results to decibels relative to full scale (dBFS). A complex tone with an amplitude of 1.0
|
||||
* (the full scale of the normalized samples) centered in a DFT bin converts to 0 dBFS.
|
||||
*
|
||||
* Use with a ComplexDftProcessor whose window is scaled to unity coherent gain (setUnityGainWindow(true)). With
|
||||
* unity coherent gain the DFT magnitude of a full scale tone equals the DFT size N, so each bin's power is divided
|
||||
* by N squared.
|
||||
*
|
||||
* Noise spreads across the bins, so the noise floor of each bin is lower than the total noise power by the DFT
|
||||
* processing gain: 10 * log10(N / window noise bandwidth in bins). Doubling the DFT size lowers the noise floor by
|
||||
* about 3 dB while tones stay at the same level.
|
||||
*/
|
||||
public class FullScaleDecibelConverter extends DFTResultsConverter
|
||||
{
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*/
|
||||
public FullScaleDecibelConverter()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts interleaved complex DFT results to dBFS, with the lowest frequency first.
|
||||
*/
|
||||
public static float[] convert(float[] results)
|
||||
{
|
||||
double size = results.length / 2.0;
|
||||
return ComplexDecibelConverter.convert(results, (float)(1.0 / (size * size)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(float[] results)
|
||||
{
|
||||
dispatch(convert(results));
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.spectrum.SpectralDisplayAdjuster;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class AveragingItem extends JSlider implements ChangeListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SpectralDisplayAdjuster mAdjuster;
|
||||
private int mDefaultValue;
|
||||
|
||||
public AveragingItem( SpectralDisplayAdjuster adjuster, int defaultValue )
|
||||
{
|
||||
super( JSlider.HORIZONTAL, 1, 20, adjuster.getAveraging() );
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
mAdjuster = adjuster;
|
||||
|
||||
setMajorTickSpacing( 5 );
|
||||
setMinorTickSpacing( 1 );
|
||||
setPaintTicks( true );
|
||||
setPaintLabels( true );
|
||||
|
||||
addChangeListener( this );
|
||||
|
||||
addMouseListener( new MouseListener()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked( MouseEvent event )
|
||||
{
|
||||
if( event.getClickCount() == 2 )
|
||||
{
|
||||
AveragingItem.this.setValue( mDefaultValue );
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased( MouseEvent arg0 ) {}
|
||||
public void mousePressed( MouseEvent arg0 ) {}
|
||||
public void mouseExited( MouseEvent arg0 ) {}
|
||||
public void mouseEntered( MouseEvent arg0 ) {}
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged( ChangeEvent event )
|
||||
{
|
||||
int value = ((JSlider)event.getSource()).getValue();
|
||||
|
||||
mAdjuster.setAveraging( value );
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.spectrum.DFTSize;
|
||||
import io.github.dsheirer.spectrum.IDFTWidthChangeProcessor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class DFTSizeItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IDFTWidthChangeProcessor mDFTProcessor;
|
||||
private DFTSize mDFTSize;
|
||||
|
||||
public DFTSizeItem( IDFTWidthChangeProcessor processor, DFTSize size )
|
||||
{
|
||||
super( size.getLabel() );
|
||||
|
||||
mDFTProcessor = processor;
|
||||
mDFTSize = size;
|
||||
|
||||
if( processor.getDFTSize() == mDFTSize )
|
||||
{
|
||||
setSelected( true );
|
||||
}
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent arg0 )
|
||||
{
|
||||
mDFTProcessor.setDFTSize( mDFTSize );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.dsp.window.WindowType;
|
||||
import io.github.dsheirer.spectrum.ComplexDftProcessor;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FFTWindowTypeItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ComplexDftProcessor mComplexDftProcessor;
|
||||
private WindowType mWindowType;
|
||||
|
||||
public FFTWindowTypeItem(ComplexDftProcessor processor, WindowType windowType)
|
||||
{
|
||||
super(windowType.toString());
|
||||
|
||||
mComplexDftProcessor = processor;
|
||||
mWindowType = windowType;
|
||||
|
||||
if(processor.getWindowType() == mWindowType)
|
||||
{
|
||||
setSelected(true);
|
||||
}
|
||||
|
||||
addActionListener(new ActionListener()
|
||||
{
|
||||
@Override public void actionPerformed(ActionEvent arg0)
|
||||
{
|
||||
mComplexDftProcessor.setWindowType(mWindowType);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* *****************************************************************************
|
||||
* Copyright (C) 2014-2022 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* ****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.spectrum.ComplexDftProcessor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FrameRateItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ComplexDftProcessor mComplexDftProcessor;
|
||||
private int mFrameRate;
|
||||
|
||||
public FrameRateItem(ComplexDftProcessor processor, int frameRate )
|
||||
{
|
||||
super( String.valueOf( frameRate ) );
|
||||
|
||||
mComplexDftProcessor = processor;
|
||||
mFrameRate = frameRate;
|
||||
|
||||
if( processor.getFrameRate() == mFrameRate )
|
||||
{
|
||||
setSelected( true );
|
||||
}
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent arg0 )
|
||||
{
|
||||
mComplexDftProcessor.setFrameRate( mFrameRate );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* ******************************************************************************
|
||||
* sdrtrunk
|
||||
* Copyright (C) 2014-2019 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
* *****************************************************************************
|
||||
*/
|
||||
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter;
|
||||
import io.github.dsheirer.spectrum.SpectralDisplayAdjuster;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class SmoothingItem extends JSlider implements ChangeListener
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SpectralDisplayAdjuster mAdjuster;
|
||||
private int mDefaultValue;
|
||||
|
||||
public SmoothingItem(SpectralDisplayAdjuster adjuster, int defaultValue)
|
||||
{
|
||||
super(JSlider.HORIZONTAL,
|
||||
SmoothingFilter.SMOOTHING_MINIMUM,
|
||||
SmoothingFilter.SMOOTHING_MAXIMUM,
|
||||
adjuster.getSmoothing());
|
||||
|
||||
mDefaultValue = defaultValue;
|
||||
mAdjuster = adjuster;
|
||||
|
||||
setSnapToTicks(true);
|
||||
setMajorTickSpacing(6);
|
||||
setMinorTickSpacing(2);
|
||||
setPaintTicks(true);
|
||||
setPaintLabels(true);
|
||||
|
||||
Hashtable<Integer,JLabel> labels = new Hashtable<>();
|
||||
labels.put(3, new JLabel("3"));
|
||||
labels.put(9, new JLabel("9"));
|
||||
labels.put(15, new JLabel("15"));
|
||||
labels.put(21, new JLabel("21"));
|
||||
labels.put(27, new JLabel("27"));
|
||||
|
||||
setLabelTable(labels);
|
||||
|
||||
addChangeListener(this);
|
||||
|
||||
addMouseListener(new MouseListener()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent event)
|
||||
{
|
||||
if(event.getClickCount() == 2)
|
||||
{
|
||||
SmoothingItem.this.setValue(mDefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent arg0)
|
||||
{
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent arg0)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent event)
|
||||
{
|
||||
int value = ((JSlider)event.getSource()).getValue();
|
||||
|
||||
if(value % 2 == 1)
|
||||
{
|
||||
mAdjuster.setSmoothing(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package io.github.dsheirer.spectrum.menu;
|
||||
|
||||
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter.SmoothingType;
|
||||
import io.github.dsheirer.spectrum.SpectralDisplayAdjuster;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class SmoothingTypeItem extends JCheckBoxMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SpectralDisplayAdjuster mAdjuster;
|
||||
private SmoothingType mSmoothingType;
|
||||
|
||||
public SmoothingTypeItem( SpectralDisplayAdjuster adjuster, SmoothingType type )
|
||||
{
|
||||
super( type.name() );
|
||||
|
||||
mAdjuster = adjuster;
|
||||
mSmoothingType = type;
|
||||
|
||||
setSelected( mAdjuster.getSmoothingType() == type );
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
mAdjuster.setSmoothingType( mSmoothingType );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user