From f518c15a06a8b97c4468084c07f6aed7f32b11a2 Mon Sep 17 00:00:00 2001 From: denny Date: Thu, 17 Mar 2016 21:16:21 -0400 Subject: [PATCH] wip #34 34: Redesign Channel Management Task-Url: http://github.com/DSheirer/sdrtrunk/issues/issue/34 --- src/source/tuner/TunerEditor.java | 52 ++++++--- .../TunerConfigurationEditor.java | 3 + .../TunerConfigurationFactory.java | 6 +- .../TunerConfigurationModel.java | 6 - .../tuner/rtl/r820t/R820TTunerEditor.java | 110 +++++++++--------- 5 files changed, 100 insertions(+), 77 deletions(-) diff --git a/src/source/tuner/TunerEditor.java b/src/source/tuner/TunerEditor.java index c38f2d78..a5e91e17 100644 --- a/src/source/tuner/TunerEditor.java +++ b/src/source/tuner/TunerEditor.java @@ -14,8 +14,8 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.JTextArea; import javax.swing.RowFilter; +import javax.swing.ScrollPaneConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.table.TableRowSorter; @@ -25,8 +25,8 @@ import net.miginfocom.swing.MigLayout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import source.SourceException; import source.tuner.configuration.TunerConfiguration; +import source.tuner.configuration.TunerConfigurationEditor; import source.tuner.configuration.TunerConfigurationFactory; import source.tuner.configuration.TunerConfigurationModel; @@ -45,6 +45,9 @@ public class TunerEditor extends Editor private JLabel mSelectedTunerType = new JLabel( "No Tuner Selected" ); private JButton mNewConfigurationButton = new JButton( "New" ); private JButton mDeleteConfigurationButton = new JButton( "Delete" ); + private JScrollPane mEditorScroller; + private Editor mEditor = new EmptyEditor<>(); + private JideSplitPane mEditorSplitPane = new JideSplitPane(); public TunerEditor( TunerConfigurationModel tunerConfigurationModel ) { @@ -90,8 +93,10 @@ public class TunerEditor extends Editor } } ); + JScrollPane tableScroller = new JScrollPane( mTunerConfigurationTable ); + tableScroller.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); listPanel.add( new JLabel( "Tuner Configurations" ), "span" ); - listPanel.add( mTunerConfigurationTable, "span" ); + listPanel.add( tableScroller, "span" ); mNewConfigurationButton.setEnabled( false ); mNewConfigurationButton.addActionListener( new ActionListener() @@ -141,20 +146,18 @@ public class TunerEditor extends Editor listPanel.add( mDeleteConfigurationButton ); //Set preferred size on both scrollers to same width, so they split the space + listPanel.setPreferredSize( new Dimension( 100, 80 ) ); JScrollPane listScroller = new JScrollPane( listPanel ); - listScroller.setPreferredSize( new Dimension( 200, 80 ) ); + listScroller.setPreferredSize( new Dimension( 100, 80 ) ); -//TODO: this has to be changed - JPanel editorPanel = new EmptyEditor(); - JScrollPane editorScroller = new JScrollPane( editorPanel ); - editorScroller.setPreferredSize( new Dimension( 200, 80 ) ); + mEditorScroller = new JScrollPane( mEditor ); + mEditorScroller.setPreferredSize( new Dimension( 100, 80 ) ); - JideSplitPane splitPane = - new JideSplitPane( JideSplitPane.HORIZONTAL_SPLIT ); - splitPane.add( listScroller ); - splitPane.add( editorScroller ); + mEditorSplitPane = new JideSplitPane( JideSplitPane.HORIZONTAL_SPLIT ); + mEditorSplitPane.add( listScroller ); + mEditorSplitPane.add( mEditorScroller ); - add( splitPane ); + add( mEditorSplitPane ); } @Override @@ -211,6 +214,9 @@ public class TunerEditor extends Editor //Set the displayed frequency without adjusting the tuner's frequency mFrequencyControl.setFrequency( tuner.getTunerController().getFrequency(), false ); + + mEditor = TunerConfigurationFactory + .getEditor( getItem(), mTunerConfigurationModel ); } else { @@ -219,19 +225,35 @@ public class TunerEditor extends Editor mTunerConfigurationTable.setEnabled( false ); mNewConfigurationButton.setEnabled( false ); mRowSorter.setRowFilter( null ); + mEditor = new EmptyEditor(); } + + //Swap out the editor + int split = mEditorSplitPane.getDividerLocation( 0 ); + mEditorSplitPane.remove( mEditorScroller ); + mEditorScroller = new JScrollPane( mEditor ); + mEditorSplitPane.add( mEditorScroller ); + mEditorSplitPane.setDividerLocation( 0, split ); } private void setConfigurationEditor( TunerConfiguration config ) { if( config != null ) { - mDeleteConfigurationButton.setEnabled( true ); + if( !mDeleteConfigurationButton.isEnabled() ) + { + mDeleteConfigurationButton.setEnabled( true ); + } } else { - mDeleteConfigurationButton.setEnabled( false ); + if( mDeleteConfigurationButton.isEnabled() ) + { + mDeleteConfigurationButton.setEnabled( false ); + } } + + mEditor.setItem( config ); } public class ConfigurationRowFilter extends RowFilter diff --git a/src/source/tuner/configuration/TunerConfigurationEditor.java b/src/source/tuner/configuration/TunerConfigurationEditor.java index 1c02f4b0..2c0908c5 100644 --- a/src/source/tuner/configuration/TunerConfigurationEditor.java +++ b/src/source/tuner/configuration/TunerConfigurationEditor.java @@ -1,6 +1,7 @@ package source.tuner.configuration; import gui.editor.Editor; +import source.tuner.TunerType; public abstract class TunerConfigurationEditor extends Editor { @@ -13,6 +14,8 @@ public abstract class TunerConfigurationEditor extends Editor getEditor( Tuner tuner, TunerConfigurationModel model ) { switch( tuner.getTunerType() ) @@ -58,7 +60,7 @@ public class TunerConfigurationFactory break; } - return null; + return new EmptyEditor(); } } diff --git a/src/source/tuner/configuration/TunerConfigurationModel.java b/src/source/tuner/configuration/TunerConfigurationModel.java index b047447c..36625241 100644 --- a/src/source/tuner/configuration/TunerConfigurationModel.java +++ b/src/source/tuner/configuration/TunerConfigurationModel.java @@ -3,16 +3,13 @@ package source.tuner.configuration; import java.util.ArrayList; import java.util.List; -import javax.swing.RowFilter; import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableRowSorter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sample.Listener; import source.tuner.TunerType; -import source.tuner.TunerViewPanel; import source.tuner.configuration.TunerConfigurationEvent.Event; public class TunerConfigurationModel extends AbstractTableModel @@ -237,12 +234,10 @@ public class TunerConfigurationModel extends AbstractTableModel if( config.getTunerType() == type && config.getName().contentEquals( name ) ) { - mLog.debug( "Returning true for name: " + name ); return true; } } - mLog.debug( "Returning false for name: " + name ); return false; } @@ -382,5 +377,4 @@ public class TunerConfigurationModel extends AbstractTableModel return null; } - } diff --git a/src/source/tuner/rtl/r820t/R820TTunerEditor.java b/src/source/tuner/rtl/r820t/R820TTunerEditor.java index 0d106f8a..599ed4bd 100644 --- a/src/source/tuner/rtl/r820t/R820TTunerEditor.java +++ b/src/source/tuner/rtl/r820t/R820TTunerEditor.java @@ -29,6 +29,7 @@ import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JSeparator; import javax.swing.JSpinner; import javax.swing.JTextField; import javax.swing.SpinnerModel; @@ -45,6 +46,7 @@ import org.slf4j.LoggerFactory; import org.usb4java.LibUsbException; import source.SourceException; +import source.tuner.TunerType; import source.tuner.configuration.TunerConfiguration; import source.tuner.configuration.TunerConfigurationEditor; import source.tuner.configuration.TunerConfigurationEvent; @@ -83,8 +85,14 @@ public class R820TTunerEditor extends TunerConfigurationEditor init(); } - + @Override + public boolean canEdit( TunerType tunerType ) + { + return tunerType == TunerType.RAFAELMICRO_R820T; + } + + @Override public void save() { if( hasItem() ) @@ -147,9 +155,10 @@ public class R820TTunerEditor extends TunerConfigurationEditor private void init() { - setLayout( new MigLayout( "fill,wrap 2", "[right][grow]", "[][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 4", "[right][grow,fill][right][grow,fill]", + "[][][][][][][grow]" ) ); - add( new JLabel( "R820T Tuner" ), "span, align center" ); + add( new JLabel( "R820T Tuner Configuration" ), "span, align center" ); /** * Tuner Configuration Name @@ -166,9 +175,40 @@ public class R820TTunerEditor extends TunerConfigurationEditor public void focusGained( FocusEvent e ) {} } ); - add( new JLabel( "Configuration:" ) ); - add( mConfigurationName, "growx,push" ); + add( new JLabel( "Name:" ) ); + add( mConfigurationName, "span,grow" ); + mComboSampleRate = new JComboBox<>( SampleRate.values() ); + mComboSampleRate.addActionListener( new ActionListener() + { + @Override + public void actionPerformed( ActionEvent e ) + { + SampleRate sampleRate = + (SampleRate)mComboSampleRate.getSelectedItem(); + try + { + + mController.setSampleRate( sampleRate ); + save(); + } + catch ( SourceException | LibUsbException eSampleRate ) + { + JOptionPane.showMessageDialog( + R820TTunerEditor.this, + "R820T Tuner Controller - couldn't apply the sample " + + "rate setting [" + sampleRate.getLabel() + "] " + + eSampleRate.getLocalizedMessage() ); + + mLog.error( "R820T Tuner Controller - couldn't apply sample " + + "rate setting [" + sampleRate.getLabel() + "]", + eSampleRate ); + } + } + } ); + add( new JLabel( "Sample Rate:" ) ); + add( mComboSampleRate ); + /** * Frequency Correction */ @@ -208,50 +248,14 @@ public class R820TTunerEditor extends TunerConfigurationEditor } } ); - add( new JLabel( "Correction PPM:" ) ); - add( mFrequencyCorrection, "growx,push" ); + add( new JLabel( "PPM:" ) ); + add( mFrequencyCorrection ); - /** - * Sample Rate - */ - mComboSampleRate = new JComboBox<>( SampleRate.values() ); - mComboSampleRate.addActionListener( new ActionListener() - { - @Override - public void actionPerformed( ActionEvent e ) - { - SampleRate sampleRate = - (SampleRate)mComboSampleRate.getSelectedItem(); - try - { - - mController.setSampleRate( sampleRate ); - save(); - } - catch ( SourceException | LibUsbException eSampleRate ) - { - JOptionPane.showMessageDialog( - R820TTunerEditor.this, - "R820T Tuner Controller - couldn't apply the sample " - + "rate setting [" + sampleRate.getLabel() + "] " + - eSampleRate.getLocalizedMessage() ); - - mLog.error( "R820T Tuner Controller - couldn't apply sample " - + "rate setting [" + sampleRate.getLabel() + "]", - eSampleRate ); - } - } - } ); - add( new JLabel( "Sample Rate:" ) ); - add( mComboSampleRate, "growx,push" ); + add( new JSeparator( JSeparator.HORIZONTAL ), "span,grow" ); /** * Gain Controls */ - JPanel gainPanel = new JPanel(); - gainPanel.setLayout( new MigLayout( "", "[grow,fill]", "[grow,fill]" ) ); - gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) ); - /* Master Gain Control */ mComboMasterGain = new JComboBox( R820TGain.values() ); @@ -308,8 +312,8 @@ public class R820TTunerEditor extends TunerConfigurationEditor + "Mixer, LNA and Enhance gain
" + "settings, or one of the individual gain settings for
" + "semi-manual gain control" ); - gainPanel.add( new JLabel( "Master" ) ); - gainPanel.add( mComboMasterGain ); + add( new JLabel( "Master:" ) ); + add( mComboMasterGain ); /* Mixer Gain Control */ mComboMixerGain = new JComboBox( R820TMixerGain.values() ); @@ -356,8 +360,8 @@ public class R820TTunerEditor extends TunerConfigurationEditor mComboMixerGain.setToolTipText( "Mixer Gain. Set master gain " + "to MASTER to enable adjustment" ); mComboMixerGain.setEnabled( false ); - gainPanel.add( new JLabel( "Mixer" ) ); - gainPanel.add( mComboMixerGain, "wrap" ); + add( new JLabel( "Mixer:" ) ); + add( mComboMixerGain ); /* LNA Gain Control */ mComboLNAGain = new JComboBox( R820TLNAGain.values() ); @@ -397,8 +401,8 @@ public class R820TTunerEditor extends TunerConfigurationEditor mComboLNAGain.setToolTipText( "LNA Gain. Set master gain " + "to MANUAL to enable adjustment" ); mComboLNAGain.setEnabled( false ); - gainPanel.add( new JLabel( "LNA" ) ); - gainPanel.add( mComboLNAGain ); + add( new JLabel( "LNA:" ) ); + add( mComboLNAGain ); /* VGA Gain Control */ mComboVGAGain = new JComboBox( R820TVGAGain.values() ); @@ -438,9 +442,7 @@ public class R820TTunerEditor extends TunerConfigurationEditor mComboVGAGain.setToolTipText( "VGA Gain. Set master gain " + "to MANUAL to enable adjustment" ); mComboVGAGain.setEnabled( false ); - gainPanel.add( new JLabel( "VGA" ) ); - gainPanel.add( mComboVGAGain, "wrap" ); - - add( gainPanel, "span" ); + add( new JLabel( "VGA:" ) ); + add( mComboVGAGain ); } }