diff --git a/src/gui/control/JFrequencyControl.java b/src/gui/control/JFrequencyControl.java index cbc2c5b0..8e3b9802 100644 --- a/src/gui/control/JFrequencyControl.java +++ b/src/gui/control/JFrequencyControl.java @@ -129,6 +129,17 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess 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 @@ -246,7 +257,10 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess public void increment( boolean fireChangeEvent ) { - set( mValue + 1, fireChangeEvent ); + if( isEnabled() ) + { + set( mValue + 1, fireChangeEvent ); + } } public void decrement() @@ -256,7 +270,10 @@ public class JFrequencyControl extends JPanel implements IFrequencyChangeProcess public void decrement( boolean fireChangeEvent ) { - set( mValue - 1, fireChangeEvent ); + if( isEnabled() ) + { + set( mValue - 1, fireChangeEvent ); + } } /** diff --git a/src/source/tuner/TunerClass.java b/src/source/tuner/TunerClass.java index 8326cb2e..9b98be92 100644 --- a/src/source/tuner/TunerClass.java +++ b/src/source/tuner/TunerClass.java @@ -21,7 +21,7 @@ import javax.usb.UsbDeviceDescriptor; 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_2838( TunerType.RTL2832_VARIOUS, "0BDA", "2838", "RTL2832", "SDR" ), COMPRO_VIDEOMATE_U620F( TunerType.ELONICS_E4000, "185B", "0620", "Compro", "Videomate U620F" ), diff --git a/src/source/tuner/TunerEditor.java b/src/source/tuner/TunerEditor.java index 394e8f4e..3559a404 100644 --- a/src/source/tuner/TunerEditor.java +++ b/src/source/tuner/TunerEditor.java @@ -11,7 +11,10 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.JTextArea; import javax.swing.RowFilter; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import javax.swing.table.TableRowSorter; import net.miginfocom.swing.MigLayout; @@ -35,6 +38,9 @@ public class TunerEditor extends Editor private JTable mTunerConfigurationTable; private TableRowSorter mRowSorter; 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 ) { @@ -47,33 +53,53 @@ public class TunerEditor extends Editor setLayout( new MigLayout( "insets 0 0 0 0", "[grow,fill]", "[grow,fill]" ) ); JPanel listPanel = new JPanel(); - listPanel.setLayout( new MigLayout( "fill,wrap 1", - "[grow,fill]", "[][][grow,fill][]" ) ); - listPanel.add( mFrequencyControl ); + listPanel.setLayout( new MigLayout( "fill,wrap 2", "[grow,fill]", "[][][][grow,fill][]" ) ); + + listPanel.add( mSelectedTunerType, "span" ); + + mFrequencyControl.setEnabled( false ); + listPanel.add( mFrequencyControl, "span" ); mTunerConfigurationTable = new JTable( mTunerConfigurationModel ); mRowSorter = new TableRowSorter<>( mTunerConfigurationModel ); 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" ) ); - listPanel.add( mTunerConfigurationTable ); + if( modelRow >= 0 ) + { + setConfigurationEditor( mTunerConfigurationModel.getTunerConfiguration( modelRow ) ); + } + } + } + } + } ); - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout( new MigLayout( "insets 0 0 0 0", - "[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 ); + listPanel.add( new JLabel( "Tuner Configurations" ), "span" ); + listPanel.add( mTunerConfigurationTable, "span" ); + 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 JScrollPane listScroller = new JScrollPane( listPanel ); listScroller.setPreferredSize( new Dimension( 200, 80 ) ); +//TODO: this has to be changed JPanel editorPanel = new EmptyEditor(); JScrollPane editorScroller = new JScrollPane( editorPanel ); editorScroller.setPreferredSize( new Dimension( 200, 80 ) ); @@ -107,6 +133,11 @@ public class TunerEditor extends Editor if( hasItem() ) { + mSelectedTunerType.setText( tuner.getName() ); + mFrequencyControl.setEnabled( true ); + mTunerConfigurationTable.setEnabled( true ); + mNewConfigurationButton.setEnabled( true ); + mRowSorter.setRowFilter( new ConfigurationRowFilter( tuner.getTunerType() ) ); TunerConfiguration assigned = mTunerConfigurationModel @@ -138,10 +169,26 @@ public class TunerEditor extends Editor } else { + mSelectedTunerType.setText( "No Tuner Selected" ); + mFrequencyControl.setEnabled( false ); + mTunerConfigurationTable.setEnabled( false ); + mNewConfigurationButton.setEnabled( false ); mRowSorter.setRowFilter( null ); } } + private void setConfigurationEditor( TunerConfiguration config ) + { + if( config != null ) + { + mDeleteConfigurationButton.setEnabled( true ); + } + else + { + mDeleteConfigurationButton.setEnabled( false ); + } + } + public class ConfigurationRowFilter extends RowFilter { private TunerType mTunerType; diff --git a/src/source/tuner/TunerModel.java b/src/source/tuner/TunerModel.java index 80086c94..3c386642 100644 --- a/src/source/tuner/TunerModel.java +++ b/src/source/tuner/TunerModel.java @@ -27,8 +27,8 @@ public class TunerModel extends AbstractTableModel implements Listener mTuners = new ArrayList<>(); private List> mTunerEventListeners = new ArrayList<>(); @@ -217,10 +217,10 @@ public class TunerModel extends AbstractTableModel implements Listener