Merge pull request #368 from DSheirer/96-disable-spectral-display-option

#96 Disable Spectral Display Option
This commit is contained in:
Denny Sheirer
2018-07-14 16:05:00 -04:00
committed by GitHub
12 changed files with 700 additions and 516 deletions

View File

@@ -40,10 +40,13 @@ import io.github.dsheirer.record.RecorderManager;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.settings.SettingsManager; import io.github.dsheirer.settings.SettingsManager;
import io.github.dsheirer.source.SourceManager; import io.github.dsheirer.source.SourceManager;
import io.github.dsheirer.source.tuner.Tuner;
import io.github.dsheirer.source.tuner.TunerEvent; import io.github.dsheirer.source.tuner.TunerEvent;
import io.github.dsheirer.source.tuner.TunerModel; import io.github.dsheirer.source.tuner.TunerModel;
import io.github.dsheirer.source.tuner.TunerSpectralDisplayManager; import io.github.dsheirer.source.tuner.TunerSpectralDisplayManager;
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationModel; import io.github.dsheirer.source.tuner.configuration.TunerConfigurationModel;
import io.github.dsheirer.spectrum.ClearTunerMenuItem;
import io.github.dsheirer.spectrum.ShowTunerMenuItem;
import io.github.dsheirer.spectrum.SpectralDisplayPanel; import io.github.dsheirer.spectrum.SpectralDisplayPanel;
import io.github.dsheirer.util.ThreadPool; import io.github.dsheirer.util.ThreadPool;
import io.github.dsheirer.util.TimeStamp; import io.github.dsheirer.util.TimeStamp;
@@ -174,10 +177,10 @@ public class SDRTrunk implements Listener<TunerEvent>
mapService, mSettingsManager, mSourceManager, tunerModel); mapService, mSettingsManager, mSourceManager, tunerModel);
mSpectralPanel = new SpectralDisplayPanel(mChannelModel, mSpectralPanel = new SpectralDisplayPanel(mChannelModel,
mChannelProcessingManager, mSettingsManager); mChannelProcessingManager, mSettingsManager, tunerModel);
TunerSpectralDisplayManager tunerSpectralDisplayManager = new TunerSpectralDisplayManager(mSpectralPanel, TunerSpectralDisplayManager tunerSpectralDisplayManager = new TunerSpectralDisplayManager(mSpectralPanel,
mChannelModel, mChannelProcessingManager, mSettingsManager); mChannelModel, mChannelProcessingManager, mSettingsManager, tunerModel);
tunerModel.addListener(tunerSpectralDisplayManager); tunerModel.addListener(tunerSpectralDisplayManager);
tunerModel.addListener(this); tunerModel.addListener(this);
@@ -325,6 +328,15 @@ public class SDRTrunk implements Listener<TunerEvent>
JMenu viewMenu = new JMenu("View"); JMenu viewMenu = new JMenu("View");
viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel)); viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel));
viewMenu.add(new JSeparator());
for(Tuner tuner: mSourceManager.getTunerModel().getTuners())
{
viewMenu.add(new ShowTunerMenuItem(mSpectralPanel, tuner));
}
viewMenu.add(new JSeparator());
viewMenu.add(new ClearTunerMenuItem(mSpectralPanel));
menuBar.add(viewMenu); menuBar.add(viewMenu);

View File

@@ -29,6 +29,7 @@ public class TunerEvent
CHANNEL_COUNT, CHANNEL_COUNT,
FREQUENCY, FREQUENCY,
SAMPLE_RATE, SAMPLE_RATE,
CLEAR_MAIN_SPECTRAL_DISPLAY,
REQUEST_MAIN_SPECTRAL_DISPLAY, REQUEST_MAIN_SPECTRAL_DISPLAY,
REQUEST_NEW_SPECTRAL_DISPLAY; REQUEST_NEW_SPECTRAL_DISPLAY;
} }

View File

@@ -1,5 +1,6 @@
package io.github.dsheirer.source.tuner; package io.github.dsheirer.source.tuner;
import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.source.Source; import io.github.dsheirer.source.Source;
import io.github.dsheirer.source.SourceException; import io.github.dsheirer.source.SourceException;
@@ -9,6 +10,7 @@ import io.github.dsheirer.source.tuner.channel.TunerChannel;
import io.github.dsheirer.source.tuner.channel.TunerChannelSource; import io.github.dsheirer.source.tuner.channel.TunerChannelSource;
import io.github.dsheirer.source.tuner.configuration.TunerConfiguration; import io.github.dsheirer.source.tuner.configuration.TunerConfiguration;
import io.github.dsheirer.source.tuner.configuration.TunerConfigurationModel; import io.github.dsheirer.source.tuner.configuration.TunerConfigurationModel;
import io.github.dsheirer.spectrum.SpectralDisplayPanel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -177,10 +179,16 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
*/ */
public void requestFirstTunerDisplay() public void requestFirstTunerDisplay()
{ {
if(mTuners.size() > 0) SystemProperties properties = SystemProperties.getInstance();
boolean enabled = properties.get(SpectralDisplayPanel.SPECTRAL_DISPLAY_ENABLED, true);
if(enabled && mTuners.size() > 0)
{ {
broadcast(new TunerEvent(mTuners.get(0), broadcast(new TunerEvent(mTuners.get(0), Event.REQUEST_MAIN_SPECTRAL_DISPLAY));
Event.REQUEST_MAIN_SPECTRAL_DISPLAY)); }
else
{
broadcast(new TunerEvent(null, Event.CLEAR_MAIN_SPECTRAL_DISPLAY));
} }
} }

View File

@@ -1,3 +1,18 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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.source.tuner; package io.github.dsheirer.source.tuner;
import io.github.dsheirer.controller.channel.ChannelModel; import io.github.dsheirer.controller.channel.ChannelModel;
@@ -7,7 +22,7 @@ import io.github.dsheirer.settings.SettingsManager;
import io.github.dsheirer.spectrum.SpectralDisplayPanel; import io.github.dsheirer.spectrum.SpectralDisplayPanel;
import io.github.dsheirer.spectrum.SpectrumFrame; import io.github.dsheirer.spectrum.SpectrumFrame;
import java.awt.*; import java.awt.EventQueue;
public class TunerSpectralDisplayManager implements Listener<TunerEvent> public class TunerSpectralDisplayManager implements Listener<TunerEvent>
{ {
@@ -15,16 +30,19 @@ public class TunerSpectralDisplayManager implements Listener<TunerEvent>
private ChannelModel mChannelModel; private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager; private ChannelProcessingManager mChannelProcessingManager;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;
private TunerModel mTunerModel;
public TunerSpectralDisplayManager(SpectralDisplayPanel panel, public TunerSpectralDisplayManager(SpectralDisplayPanel panel,
ChannelModel channelModel, ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager, ChannelProcessingManager channelProcessingManager,
SettingsManager settingsManager ) SettingsManager settingsManager,
TunerModel tunerModel)
{ {
mSpectralDisplayPanel = panel; mSpectralDisplayPanel = panel;
mChannelModel = channelModel; mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager; mChannelProcessingManager = channelProcessingManager;
mSettingsManager = settingsManager; mSettingsManager = settingsManager;
mTunerModel = tunerModel;
} }
@Override @Override
@@ -32,12 +50,15 @@ public class TunerSpectralDisplayManager implements Listener<TunerEvent>
{ {
switch(event.getEvent()) switch(event.getEvent())
{ {
case CLEAR_MAIN_SPECTRAL_DISPLAY:
mSpectralDisplayPanel.clearTuner();
break;
case REQUEST_MAIN_SPECTRAL_DISPLAY: case REQUEST_MAIN_SPECTRAL_DISPLAY:
mSpectralDisplayPanel.showTuner(event.getTuner()); mSpectralDisplayPanel.showTuner(event.getTuner());
break; break;
case REQUEST_NEW_SPECTRAL_DISPLAY: case REQUEST_NEW_SPECTRAL_DISPLAY:
final SpectrumFrame frame = new SpectrumFrame(mChannelModel, final SpectrumFrame frame = new SpectrumFrame(mChannelModel,
mChannelProcessingManager, mSettingsManager, event.getTuner() ); mChannelProcessingManager, mSettingsManager, mTunerModel, event.getTuner());
EventQueue.invokeLater(new Runnable() EventQueue.invokeLater(new Runnable()
{ {

View File

@@ -0,0 +1,46 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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.properties.SystemProperties;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ClearTunerMenuItem extends JMenuItem
{
private SpectralDisplayPanel mSpectralDisplayPanel;
public ClearTunerMenuItem(SpectralDisplayPanel spectralDisplayPanel)
{
super("Disable Spectrum & Waterfall");
mSpectralDisplayPanel = spectralDisplayPanel;
addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
mSpectralDisplayPanel.clearTuner();
SystemProperties properties = SystemProperties.getInstance();
properties.set(SpectralDisplayPanel.SPECTRAL_DISPLAY_ENABLED, false);
}
});
}
}

View File

@@ -164,6 +164,8 @@ public class DFTProcessor implements Listener<ReusableComplexBuffer>, ISourceEve
} }
public void start() public void start()
{
if(mProcessorTaskHandle == null)
{ {
//Schedule the DFT to run calculations at a fixed rate //Schedule the DFT to run calculations at a fixed rate
int initialDelay = 0; int initialDelay = 0;
@@ -172,6 +174,7 @@ public class DFTProcessor implements Listener<ReusableComplexBuffer>, ISourceEve
mProcessorTaskHandle = ThreadPool.SCHEDULED.scheduleAtFixedRate(new DFTCalculationTask(), initialDelay, period, mProcessorTaskHandle = ThreadPool.SCHEDULED.scheduleAtFixedRate(new DFTCalculationTask(), initialDelay, period,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
}
public void stop() public void stop()
{ {
@@ -179,9 +182,15 @@ public class DFTProcessor implements Listener<ReusableComplexBuffer>, ISourceEve
if(mProcessorTaskHandle != null) if(mProcessorTaskHandle != null)
{ {
mProcessorTaskHandle.cancel(true); mProcessorTaskHandle.cancel(true);
mProcessorTaskHandle = null;
} }
} }
public boolean isRunning()
{
return mProcessorTaskHandle != null;
}
public void restart() public void restart()
{ {
stop(); stop();

View File

@@ -342,6 +342,10 @@ public class OverlayPanel extends JPanel implements ChannelEventListener, ISourc
{ {
minor = 1; minor = 1;
} }
if(label == 0)
{
label = 1;
}
//Adjust the start frequency to a multiple of the minor tick spacing //Adjust the start frequency to a multiple of the minor tick spacing
long frequency = minFrequency - (minFrequency % minor); long frequency = minFrequency - (minFrequency % minor);

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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.source.tuner.Tuner;
import javax.swing.JMenuItem;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ShowTunerMenuItem extends JMenuItem
{
private SpectralDisplayPanel mSpectralDisplayPanel;
private Tuner mTuner;
public ShowTunerMenuItem(SpectralDisplayPanel spectralDisplayPanel, Tuner tuner)
{
super(tuner != null ? "Show: " + tuner.getName() : "(empty)");
mSpectralDisplayPanel = spectralDisplayPanel;
mTuner = tuner;
addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mSpectralDisplayPanel.showTuner(mTuner);
}
});
}
});
}
}

View File

@@ -22,7 +22,6 @@ import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.controller.channel.ChannelUtils; import io.github.dsheirer.controller.channel.ChannelUtils;
import io.github.dsheirer.dsp.filter.Window.WindowType; import io.github.dsheirer.dsp.filter.Window.WindowType;
import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter.SmoothingType; import io.github.dsheirer.dsp.filter.smoothing.SmoothingFilter.SmoothingType;
import io.github.dsheirer.module.decode.DecoderType;
import io.github.dsheirer.properties.SystemProperties; import io.github.dsheirer.properties.SystemProperties;
import io.github.dsheirer.sample.Listener; import io.github.dsheirer.sample.Listener;
import io.github.dsheirer.sample.SampleType; import io.github.dsheirer.sample.SampleType;
@@ -33,6 +32,7 @@ import io.github.dsheirer.settings.SettingsManager;
import io.github.dsheirer.source.ISourceEventProcessor; import io.github.dsheirer.source.ISourceEventProcessor;
import io.github.dsheirer.source.SourceEvent; import io.github.dsheirer.source.SourceEvent;
import io.github.dsheirer.source.tuner.Tuner; import io.github.dsheirer.source.tuner.Tuner;
import io.github.dsheirer.source.tuner.TunerModel;
import io.github.dsheirer.spectrum.OverlayPanel.ChannelDisplay; import io.github.dsheirer.spectrum.OverlayPanel.ChannelDisplay;
import io.github.dsheirer.spectrum.converter.ComplexDecibelConverter; import io.github.dsheirer.spectrum.converter.ComplexDecibelConverter;
import io.github.dsheirer.spectrum.converter.DFTResultsConverter; import io.github.dsheirer.spectrum.converter.DFTResultsConverter;
@@ -71,7 +71,6 @@ import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener; import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
@@ -82,9 +81,8 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
private final static Logger mLog = LoggerFactory.getLogger(SpectralDisplayPanel.class); private final static Logger mLog = LoggerFactory.getLogger(SpectralDisplayPanel.class);
private static DecimalFormat sCURSOR_FORMAT = new DecimalFormat("000.00000");
public static final String FFT_SIZE_PROPERTY = "spectral.display.dft.size"; 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 NO_ZOOM = 0;
public static final int MAX_ZOOM = 6; public static final int MAX_ZOOM = 6;
@@ -102,6 +100,7 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
private ChannelModel mChannelModel; private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager; private ChannelProcessingManager mChannelProcessingManager;
private SettingsManager mSettingsManager; private SettingsManager mSettingsManager;
private TunerModel mTunerModel;
private Tuner mTuner; private Tuner mTuner;
/** /**
@@ -118,11 +117,13 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
*/ */
public SpectralDisplayPanel(ChannelModel channelModel, public SpectralDisplayPanel(ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager, ChannelProcessingManager channelProcessingManager,
SettingsManager settingsManager) SettingsManager settingsManager,
TunerModel tunerModel)
{ {
mChannelModel = channelModel; mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager; mChannelProcessingManager = channelProcessingManager;
mSettingsManager = settingsManager; mSettingsManager = settingsManager;
mTunerModel = tunerModel;
mSpectrumPanel = new SpectrumPanel(mSettingsManager); mSpectrumPanel = new SpectrumPanel(mSettingsManager);
mOverlayPanel = new OverlayPanel(mSettingsManager, mChannelModel); mOverlayPanel = new OverlayPanel(mSettingsManager, mChannelModel);
@@ -428,6 +429,8 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
mDFTProcessor.clearBuffer(); mDFTProcessor.clearBuffer();
mDFTProcessor.start();
mTuner = tuner; mTuner = tuner;
if(mTuner != null) if(mTuner != null)
@@ -462,6 +465,11 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
mTuner.getTunerController().removeBufferListener(mDFTProcessor); mTuner.getTunerController().removeBufferListener(mDFTProcessor);
mTuner = null; mTuner = null;
} }
mDFTProcessor.stop();
mDFTProcessor.clearBuffer();
mSpectrumPanel.clearSpectrum();
mWaterfallPanel.clearWaterfall();
} }
/** /**
@@ -614,6 +622,7 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
if(event.getComponent() == mWaterfallPanel) if(event.getComponent() == mWaterfallPanel)
{ {
contextMenu.add(new PauseItem(mWaterfallPanel, "Pause")); contextMenu.add(new PauseItem(mWaterfallPanel, "Pause"));
contextMenu.add(new JSeparator());
} }
long frequency = long frequency =
@@ -643,22 +652,6 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
} }
// JMenu frequencyMenu = new JMenu(
// sCURSOR_FORMAT.format((float) frequency / 1000000.0f));
//
// JMenu decoderMenu = new JMenu("Add Decoder");
//
// for(DecoderType type : DecoderType.getPrimaryDecoders())
// {
// decoderMenu.add(new DecoderItem(type, frequency));
// }
//
// frequencyMenu.add(decoderMenu);
//
// contextMenu.add(frequencyMenu);
//
// contextMenu.add(new JSeparator());
/** /**
* Color Menus * Color Menus
*/ */
@@ -791,6 +784,27 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
contextMenu.add(zoomMenu); contextMenu.add(zoomMenu);
if(mTuner != null)
{
contextMenu.add(new JSeparator());
contextMenu.add(new ClearTunerMenuItem(SpectralDisplayPanel.this));
}
boolean separatorAdded = false;
for(Tuner tuner: mTunerModel.getTuners())
{
if(mTuner == null || mTuner != tuner)
{
if(!separatorAdded)
{
contextMenu.add(new JSeparator());
separatorAdded = true;
}
contextMenu.add(new ShowTunerMenuItem(SpectralDisplayPanel.this, tuner));
}
}
if(contextMenu != null) if(contextMenu != null)
{ {
@@ -920,34 +934,4 @@ public class SpectralDisplayPanel extends JPanel implements Listener<ReusableCom
}); });
} }
} }
/**
* Context menu item to provide one-click access to starting a channel
* processing with the selected decoder
*/
public class DecoderItem extends JMenuItem
{
private static final long serialVersionUID = 1L;
private ChannelModel mChannelModel;
private long mFrequency;
private DecoderType mDecoder;
public DecoderItem(DecoderType type, long frequency)
{
super(type.getDisplayString());
mFrequency = frequency;
mDecoder = type;
addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
mChannelModel.createChannel(mDecoder, mFrequency);
}
});
}
}
} }

View File

@@ -1,19 +1,17 @@
/******************************************************************************* /*******************************************************************************
* SDR Trunk * sdr-trunk
* Copyright (C) 2014 Dennis Sheirer * Copyright (C) 2014-2018 Dennis Sheirer
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* it under the terms of the GNU General Public License as published by * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* the Free Software Foundation, either version 3 of the License, or * later version.
* (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* but WITHOUT ANY WARRANTY; without even the implied warranty of * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* 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/>
* *
* 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; package io.github.dsheirer.spectrum;
@@ -21,10 +19,11 @@ import io.github.dsheirer.controller.channel.ChannelModel;
import io.github.dsheirer.controller.channel.ChannelProcessingManager; import io.github.dsheirer.controller.channel.ChannelProcessingManager;
import io.github.dsheirer.settings.SettingsManager; import io.github.dsheirer.settings.SettingsManager;
import io.github.dsheirer.source.tuner.Tuner; import io.github.dsheirer.source.tuner.Tuner;
import io.github.dsheirer.source.tuner.TunerModel;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import javax.swing.*; import javax.swing.JFrame;
import java.awt.*; import java.awt.EventQueue;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
@@ -37,6 +36,7 @@ public class SpectrumFrame extends JFrame implements WindowListener
public SpectrumFrame(ChannelModel channelModel, public SpectrumFrame(ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager, ChannelProcessingManager channelProcessingManager,
SettingsManager settingsManager, SettingsManager settingsManager,
TunerModel tunerModel,
Tuner tuner) Tuner tuner)
{ {
setTitle("SDRTRunk [" + tuner.getName() + "]"); setTitle("SDRTRunk [" + tuner.getName() + "]");
@@ -46,7 +46,7 @@ public class SpectrumFrame extends JFrame implements WindowListener
setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]")); setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]"));
mSpectralDisplayPanel = new SpectralDisplayPanel(channelModel, mSpectralDisplayPanel = new SpectralDisplayPanel(channelModel,
channelProcessingManager, settingsManager ); channelProcessingManager, settingsManager, tunerModel);
mSpectralDisplayPanel.showTuner(tuner); mSpectralDisplayPanel.showTuner(tuner);
add(mSpectralDisplayPanel, "grow"); add(mSpectralDisplayPanel, "grow");
@@ -70,15 +70,32 @@ public class SpectrumFrame extends JFrame implements WindowListener
} }
@Override @Override
public void windowActivated( WindowEvent arg0 ) {} public void windowActivated(WindowEvent arg0)
@Override {
public void windowClosing( WindowEvent arg0 ) {} }
@Override
public void windowDeactivated( WindowEvent arg0 ) {} @Override
@Override public void windowClosing(WindowEvent arg0)
public void windowDeiconified( WindowEvent arg0 ) {} {
@Override }
public void windowIconified( WindowEvent arg0 ) {}
@Override @Override
public void windowOpened( WindowEvent arg0 ) {} public void windowDeactivated(WindowEvent arg0)
{
}
@Override
public void windowDeiconified(WindowEvent arg0)
{
}
@Override
public void windowIconified(WindowEvent arg0)
{
}
@Override
public void windowOpened(WindowEvent arg0)
{
}
} }

View File

@@ -327,8 +327,7 @@ public class SpectrumPanel extends JPanel implements DFTResultsListener, Setting
*/ */
public void clearSpectrum() public void clearSpectrum()
{ {
mDisplayFFTBins = null; Arrays.fill(mDisplayFFTBins, 0.0f);
repaint(); repaint();
} }

View File

@@ -25,12 +25,18 @@ import io.github.dsheirer.settings.SettingsManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.JPanel;
import java.awt.*; import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.awt.image.ColorModel; import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource; import java.awt.image.MemoryImageSource;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Arrays;
public class WaterfallPanel extends JPanel implements DFTResultsListener, public class WaterfallPanel extends JPanel implements DFTResultsListener,
Pausable, Pausable,
@@ -42,7 +48,8 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
LoggerFactory.getLogger(WaterfallPanel.class); LoggerFactory.getLogger(WaterfallPanel.class);
private static DecimalFormat CURSOR_FORMAT = new DecimalFormat("0.00000"); private static DecimalFormat CURSOR_FORMAT = new DecimalFormat("0.00000");
private static final String PAUSED = "PAUSED"; 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[] mPixels;
private byte[] mPausedPixels; private byte[] mPausedPixels;
@@ -57,6 +64,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
private boolean mCursorVisible = false; private boolean mCursorVisible = false;
private long mCursorFrequency = 0; private long mCursorFrequency = 0;
private boolean mPaused = false; private boolean mPaused = false;
private boolean mDisabled = true;
private int mZoom = 0; private int mZoom = 0;
private int mDFTZoomWindowOffset = 0; private int mDFTZoomWindowOffset = 0;
@@ -135,6 +143,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
/** /**
* Returns current pause state * Returns current pause state
*
* @return true if paused, false otherwise * @return true if paused, false otherwise
*/ */
public boolean isPaused() public boolean isPaused()
@@ -142,6 +151,14 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
return mPaused; return mPaused;
} }
/**
* Indicates if the waterfall is currently disabled.
*/
public boolean isDisabled()
{
return mDisabled;
}
/** /**
* Sets the current zoom level (2^zoom) * Sets the current zoom level (2^zoom)
* *
@@ -171,6 +188,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
/** /**
* Sets the zoom window offset from zero * Sets the zoom window offset from zero
*
* @param offset in DFT bins * @param offset in DFT bins
*/ */
public void setZoomWindowOffset(int offset) public void setZoomWindowOffset(int offset)
@@ -209,7 +227,8 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
} }
@Override @Override
public void settingDeleted( Setting setting ) { /* Not implemented */ } public void settingDeleted(Setting setting)
{ /* Not implemented */ }
/** /**
* Sets the display location of the cursor. Cursor location monitoring is * Sets the display location of the cursor. Cursor location monitoring is
@@ -237,6 +256,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
/** /**
* Toggles the visibility of the cursor * Toggles the visibility of the cursor
*
* @param visible * @param visible
*/ */
public void setCursorVisible(boolean visible) public void setCursorVisible(boolean visible)
@@ -298,21 +318,16 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
if(mCursorVisible) if(mCursorVisible)
{ {
graphics.draw(new Line2D.Float(mCursorLocation.x, 0, mCursorLocation.x, (float)(getSize().getHeight())));
graphics.draw( new Line2D.Float( mCursorLocation.x,
0,
mCursorLocation.x,
(float)(getSize().getHeight() ) ) );
String frequency = CURSOR_FORMAT.format(mCursorFrequency / 1000000.0D); String frequency = CURSOR_FORMAT.format(mCursorFrequency / 1000000.0D);
graphics.drawString(frequency, mCursorLocation.x + 5, mCursorLocation.y);
graphics.drawString( frequency ,
mCursorLocation.x + 5,
mCursorLocation.y );
} }
if( mPaused ) if(mDisabled)
{
graphics.drawString(DISABLED, 20, 20);
}
else if(mPaused)
{ {
graphics.drawString(PAUSED, 20, 20); graphics.drawString(PAUSED, 20, 20);
} }
@@ -364,6 +379,8 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
@Override @Override
public void receive(float[] update) public void receive(float[] update)
{ {
mDisabled = false;
//If our FFT size changes, reset our pixel map and image source //If our FFT size changes, reset our pixel map and image source
if(mDFTSize != update.length) if(mDFTSize != update.length)
{ {
@@ -373,8 +390,7 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
} }
//Move the pixels down a row to make room for the new results //Move the pixels down a row to make room for the new results
System.arraycopy( mPixels, 0, System.arraycopy(mPixels, 0, mPixels, mDFTSize, mPixels.length - mDFTSize);
mPixels, mDFTSize, mPixels.length - mDFTSize );
/** /**
* Find the average value and scale the display to it * Find the average value and scale the display to it
@@ -428,4 +444,19 @@ public class WaterfallPanel extends JPanel implements DFTResultsListener,
} }
}); });
} }
public void clearWaterfall()
{
Arrays.fill(mPixels, (byte)0);
mDisabled = true;
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
mMemoryImageSource.newPixels(mPixels, mColorModel, 0, mDFTSize);
}
});
}
} }