wip #34 - adds enable/disable to tuner editor components and frequency

control
This commit is contained in:
denny
2016-03-13 08:43:55 -04:00
parent 0605760fcd
commit 86816228c2
6 changed files with 91 additions and 28 deletions

View File

@@ -129,6 +129,17 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess
revalidate(); revalidate();
} }
@Override
public void setEnabled( boolean enabled )
{
super.setEnabled( enabled );
for( Digit digit: mDigits.values() )
{
digit.setEnabled( enabled );
}
}
/** /**
* Receives a frequency change event invoked by another control. We don't * Receives a frequency change event invoked by another control. We don't
@@ -246,7 +257,10 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess
public void increment( boolean fireChangeEvent ) public void increment( boolean fireChangeEvent )
{ {
set( mValue + 1, fireChangeEvent ); if( isEnabled() )
{
set( mValue + 1, fireChangeEvent );
}
} }
public void decrement() public void decrement()
@@ -256,7 +270,10 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess
public void decrement( boolean fireChangeEvent ) public void decrement( boolean fireChangeEvent )
{ {
set( mValue - 1, fireChangeEvent ); if( isEnabled() )
{
set( mValue - 1, fireChangeEvent );
}
} }
/** /**

View File

@@ -21,7 +21,7 @@ import javax.usb.UsbDeviceDescriptor;
public enum TunerClass public enum TunerClass
{ {
AIRSPY( TunerType.AIRSPY_R820T, "1D50", "60A1", "Airspy.com", "Airspy" ), AIRSPY( TunerType.AIRSPY_R820T, "1D50", "60A1", "Airspy", "Airspy" ),
GENERIC_2832( TunerType.RTL2832_VARIOUS, "0BDA", "2832", "RTL2832", "SDR" ), GENERIC_2832( TunerType.RTL2832_VARIOUS, "0BDA", "2832", "RTL2832", "SDR" ),
GENERIC_2838( TunerType.RTL2832_VARIOUS, "0BDA", "2838", "RTL2832", "SDR" ), GENERIC_2838( TunerType.RTL2832_VARIOUS, "0BDA", "2838", "RTL2832", "SDR" ),
COMPRO_VIDEOMATE_U620F( TunerType.ELONICS_E4000, "185B", "0620", "Compro", "Videomate U620F" ), COMPRO_VIDEOMATE_U620F( TunerType.ELONICS_E4000, "185B", "0620", "Compro", "Videomate U620F" ),

View File

@@ -11,7 +11,10 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.RowFilter; import javax.swing.RowFilter;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableRowSorter; import javax.swing.table.TableRowSorter;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
@@ -35,6 +38,9 @@ public class TunerEditor extends Editor<Tuner>
private JTable mTunerConfigurationTable; private JTable mTunerConfigurationTable;
private TableRowSorter<TunerConfigurationModel> mRowSorter; private TableRowSorter<TunerConfigurationModel> mRowSorter;
private JFrequencyControl mFrequencyControl = new JFrequencyControl(); private JFrequencyControl mFrequencyControl = new JFrequencyControl();
private JLabel mSelectedTunerType = new JLabel( "No Tuner Selected" );
private JButton mNewConfigurationButton = new JButton( "New" );
private JButton mDeleteConfigurationButton = new JButton( "Delete" );
public TunerEditor( TunerConfigurationModel tunerConfigurationModel ) public TunerEditor( TunerConfigurationModel tunerConfigurationModel )
{ {
@@ -47,33 +53,53 @@ public class TunerEditor extends Editor<Tuner>
setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]" ) ); setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]" ) );
JPanel listPanel = new JPanel(); JPanel listPanel = new JPanel();
listPanel.setLayout( new MigLayout( "fill,wrap 1", listPanel.setLayout( new MigLayout( "fill,wrap 2", "[grow,fill]", "[][][][grow,fill][]" ) );
"[grow,fill]", "[][][grow,fill][]" ) );
listPanel.add( mFrequencyControl ); listPanel.add( mSelectedTunerType, "span" );
mFrequencyControl.setEnabled( false );
listPanel.add( mFrequencyControl, "span" );
mTunerConfigurationTable = new JTable( mTunerConfigurationModel ); mTunerConfigurationTable = new JTable( mTunerConfigurationModel );
mRowSorter = new TableRowSorter<>( mTunerConfigurationModel ); mRowSorter = new TableRowSorter<>( mTunerConfigurationModel );
mTunerConfigurationTable.setRowSorter( mRowSorter ); mTunerConfigurationTable.setRowSorter( mRowSorter );
mTunerConfigurationTable.setEnabled( false );
mTunerConfigurationTable.getSelectionModel().addListSelectionListener( new ListSelectionListener()
{
@Override
public void valueChanged( ListSelectionEvent event )
{
if( !event.getValueIsAdjusting() )
{
int row = mTunerConfigurationTable.getSelectedRow();
if( row >= 0 )
{
int modelRow = mTunerConfigurationTable.convertRowIndexToModel( row );
listPanel.add( new JLabel( "Tuner Configurations" ) ); if( modelRow >= 0 )
listPanel.add( mTunerConfigurationTable ); {
setConfigurationEditor( mTunerConfigurationModel.getTunerConfiguration( modelRow ) );
}
}
}
}
} );
JPanel buttonPanel = new JPanel(); listPanel.add( new JLabel( "Tuner Configurations" ), "span" );
buttonPanel.setLayout( new MigLayout( "insets 0 0 0 0", listPanel.add( mTunerConfigurationTable, "span" );
"[grow,fill][grow,fill]", "[grow,fill]" ) );
JButton newButton = new JButton( "New" );
buttonPanel.add( newButton );
JButton deleteButton = new JButton( "Delete" );
buttonPanel.add( deleteButton );
listPanel.add( buttonPanel );
mNewConfigurationButton.setEnabled( false );
listPanel.add( mNewConfigurationButton );
mDeleteConfigurationButton.setEnabled( false );
listPanel.add( mDeleteConfigurationButton );
//Set preferred size on both scrollers to same width, so they split the space //Set preferred size on both scrollers to same width, so they split the space
JScrollPane listScroller = new JScrollPane( listPanel ); JScrollPane listScroller = new JScrollPane( listPanel );
listScroller.setPreferredSize( new Dimension( 200, 80 ) ); listScroller.setPreferredSize( new Dimension( 200, 80 ) );
//TODO: this has to be changed
JPanel editorPanel = new EmptyEditor<TunerConfiguration>(); JPanel editorPanel = new EmptyEditor<TunerConfiguration>();
JScrollPane editorScroller = new JScrollPane( editorPanel ); JScrollPane editorScroller = new JScrollPane( editorPanel );
editorScroller.setPreferredSize( new Dimension( 200, 80 ) ); editorScroller.setPreferredSize( new Dimension( 200, 80 ) );
@@ -107,6 +133,11 @@ public class TunerEditor extends Editor<Tuner>
if( hasItem() ) if( hasItem() )
{ {
mSelectedTunerType.setText( tuner.getName() );
mFrequencyControl.setEnabled( true );
mTunerConfigurationTable.setEnabled( true );
mNewConfigurationButton.setEnabled( true );
mRowSorter.setRowFilter( new ConfigurationRowFilter( tuner.getTunerType() ) ); mRowSorter.setRowFilter( new ConfigurationRowFilter( tuner.getTunerType() ) );
TunerConfiguration assigned = mTunerConfigurationModel TunerConfiguration assigned = mTunerConfigurationModel
@@ -138,10 +169,26 @@ public class TunerEditor extends Editor<Tuner>
} }
else else
{ {
mSelectedTunerType.setText( "No Tuner Selected" );
mFrequencyControl.setEnabled( false );
mTunerConfigurationTable.setEnabled( false );
mNewConfigurationButton.setEnabled( false );
mRowSorter.setRowFilter( null ); mRowSorter.setRowFilter( null );
} }
} }
private void setConfigurationEditor( TunerConfiguration config )
{
if( config != null )
{
mDeleteConfigurationButton.setEnabled( true );
}
else
{
mDeleteConfigurationButton.setEnabled( false );
}
}
public class ConfigurationRowFilter extends RowFilter<TunerConfigurationModel,Integer> public class ConfigurationRowFilter extends RowFilter<TunerConfigurationModel,Integer>
{ {
private TunerType mTunerType; private TunerType mTunerType;

View File

@@ -27,8 +27,8 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
private final static Logger mLog = LoggerFactory.getLogger( TunerModel.class ); private final static Logger mLog = LoggerFactory.getLogger( TunerModel.class );
public static final int TUNER_CLASS = 0; public static final int TUNER_TYPE = 0;
public static final int TUNER_TYPE = 1; public static final int TUNER_ID = 1;
public static final int SAMPLE_RATE = 2; public static final int SAMPLE_RATE = 2;
public static final int FREQUENCY = 3; public static final int FREQUENCY = 3;
public static final int CHANNEL_COUNT = 4; public static final int CHANNEL_COUNT = 4;
@@ -37,7 +37,7 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
private static final String MHZ = " MHz"; private static final String MHZ = " MHz";
private static final String[] COLUMNS = private static final String[] COLUMNS =
{ "Class", "Type", "Sample Rate", "Frequency", "Channels", "Spectral", "Display" }; { "Tuner", "ID", "Sample Rate", "Frequency", "Channels", "Spectral", "Display" };
private List<Tuner> mTuners = new ArrayList<>(); private List<Tuner> mTuners = new ArrayList<>();
private List<Listener<TunerEvent>> mTunerEventListeners = new ArrayList<>(); private List<Listener<TunerEvent>> mTunerEventListeners = new ArrayList<>();
@@ -217,10 +217,10 @@ public class TunerModel extends AbstractTableModel implements Listener<TunerEven
switch( columnIndex ) switch( columnIndex )
{ {
case TUNER_CLASS:
return tuner.getTunerClass().getVendorDescription();
case TUNER_TYPE: case TUNER_TYPE:
return tuner.getTunerType().getLabel(); return tuner.getTunerType().getLabel();
case TUNER_ID:
return tuner.getUniqueID();
case SAMPLE_RATE: case SAMPLE_RATE:
int sampleRate = tuner.getTunerController().getSampleRate(); int sampleRate = tuner.getTunerController().getSampleRate();

View File

@@ -32,7 +32,6 @@ import source.tuner.TunerClass;
import source.tuner.TunerEvent; import source.tuner.TunerEvent;
import source.tuner.TunerType; import source.tuner.TunerType;
import source.tuner.airspy.AirspyTunerController.BoardID; import source.tuner.airspy.AirspyTunerController.BoardID;
import source.tuner.configuration.TunerConfiguration;
public class AirspyTuner extends Tuner public class AirspyTuner extends Tuner
{ {
@@ -40,7 +39,7 @@ public class AirspyTuner extends Tuner
public AirspyTuner( AirspyTunerController controller ) public AirspyTuner( AirspyTunerController controller )
{ {
super( "Airspy", controller ); super( "Airspy " + controller.getDeviceInfo().getSerialNumber(), controller );
} }
public AirspyTunerController getController() public AirspyTunerController getController()
@@ -57,7 +56,7 @@ public class AirspyTuner extends Tuner
} }
catch( Exception e ) catch( Exception e )
{ {
mLog.error( "error gettting serial number", e ); mLog.error( "error getting serial number", e );
} }
return BoardID.AIRSPY.getLabel(); return BoardID.AIRSPY.getLabel();

View File

@@ -47,7 +47,7 @@ public class RTL2832Tuner extends Tuner
throws SourceException throws SourceException
{ {
super( tunerClass.getVendorDeviceLabel() + "/" + super( tunerClass.getVendorDeviceLabel() + "/" +
controller.getTunerType().getLabel() + " #" + controller.getTunerType().getLabel() + " " +
controller.getUniqueID(), controller ); controller.getUniqueID(), controller );
mTunerClass = tunerClass; mTunerClass = tunerClass;