diff --git a/src/controller/channel/ChannelEditor.java b/src/controller/channel/ChannelEditor.java index ff42633f..5c569db3 100644 --- a/src/controller/channel/ChannelEditor.java +++ b/src/controller/channel/ChannelEditor.java @@ -18,6 +18,7 @@ package controller.channel; import gui.editor.Editor; +import gui.editor.EditorValidationException; import java.awt.Color; import java.awt.event.ActionEvent; @@ -55,7 +56,7 @@ public class ChannelEditor extends Editor implements ActionListener, Ch private SourceConfigurationEditor mSourceConfigurationEditor; private DecodeConfigurationEditor mDecodeConfigurationEditor; private AuxDecodeConfigurationEditor mAuxDecodeConfigurationEditor; - private EventLogConfigurationEditor mEventLogConfiguraitonEditor; + private EventLogConfigurationEditor mEventLogConfigurationEditor; private RecordConfigurationEditor mRecordConfigurationEditor; private JButton mEnableButton = new JButton( "Enable" ); @@ -106,7 +107,7 @@ public class ChannelEditor extends Editor implements ActionListener, Ch mSourceConfigurationEditor.setItem( channel ); mDecodeConfigurationEditor.setItem( channel ); mAuxDecodeConfigurationEditor.setItem( channel ); - mEventLogConfiguraitonEditor.setItem( channel ); + mEventLogConfigurationEditor.setItem( channel ); mRecordConfigurationEditor.setItem( channel ); if( channel != null ) @@ -127,10 +128,8 @@ public class ChannelEditor extends Editor implements ActionListener, Ch private void init() { - setLayout( new MigLayout( "fill,wrap 3", "[grow,fill][grow,fill][grow,fill]", "[][][][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 3", "[grow,fill][grow,fill][grow,fill]", "[grow,fill][]" ) ); - add( mChannelName, "wrap" ); - JideTabbedPane tabs = new JideTabbedPane(); tabs.setFont( this.getFont() ); tabs.setForeground( Color.BLACK ); @@ -147,8 +146,8 @@ public class ChannelEditor extends Editor implements ActionListener, Ch mAuxDecodeConfigurationEditor = new AuxDecodeConfigurationEditor(); tabs.addTab( "Aux Decoders", mAuxDecodeConfigurationEditor ); - mEventLogConfiguraitonEditor = new EventLogConfigurationEditor(); - tabs.addTab( "Logging", mEventLogConfiguraitonEditor ); + mEventLogConfigurationEditor = new EventLogConfigurationEditor(); + tabs.addTab( "Logging", mEventLogConfigurationEditor ); mRecordConfigurationEditor = new RecordConfigurationEditor(); tabs.addTab( "Recording", mRecordConfigurationEditor ); @@ -234,40 +233,40 @@ public class ChannelEditor extends Editor implements ActionListener, Ch { if( hasItem() ) { -// try -// { -//TODO: validate the source editor against the decode editor -//TODO: validate the aux editor against the decode editor - verify no aux decoders with P25 -// } -// catch( ConfigurationValidationException e ) -// { -// /* ChannelValidationException can be thrown by any of the component -// * editors. Show the validation error text in a popup menu to the -// * user and set the focus on the error component */ -// JOptionPane.showMessageDialog( ChannelEditor.this, -// validationException.getMessage(), -// "Channel Configuration Error", -// JOptionPane.ERROR_MESSAGE ); -// -// Component component = validationException.getComponent(); -// -// if( component != null ) -// { -// component.requestFocus(); -// } -// -// return; -// } + try + { + mDecodeConfigurationEditor.validate( mSourceConfigurationEditor ); + mDecodeConfigurationEditor.validate( mAuxDecodeConfigurationEditor ); + } + catch( EditorValidationException e ) + { + JOptionPane.showMessageDialog( ChannelEditor.this, e.getReason(), + "Configuration Error", JOptionPane.ERROR_MESSAGE ); + e.getEditor().requestFocus(); + + return; + } + + boolean changed = mNameConfigurationEditor.isModified() || + mSourceConfigurationEditor.isModified() || + mDecodeConfigurationEditor.isModified() || + mAuxDecodeConfigurationEditor.isModified() || + mEventLogConfigurationEditor.isModified() || + mRecordConfigurationEditor.isModified(); + mNameConfigurationEditor.save(); mSourceConfigurationEditor.save(); mDecodeConfigurationEditor.save(); mAuxDecodeConfigurationEditor.save(); - mEventLogConfiguraitonEditor.save(); + mEventLogConfigurationEditor.save(); mRecordConfigurationEditor.save(); - //Broadcast a channel configuration change event - mChannelModel.broadcast( new ChannelEvent( getItem(), Event.NOTIFICATION_CONFIGURATION_CHANGE ) ); + if( changed ) + { + mChannelModel.broadcast( new ChannelEvent( getItem(), + Event.NOTIFICATION_CONFIGURATION_CHANGE ) ); + } } setModified( false ); diff --git a/src/gui/editor/EmptyValidatingEditor.java b/src/gui/editor/EmptyValidatingEditor.java index 5d8eda8a..1c37c92c 100644 --- a/src/gui/editor/EmptyValidatingEditor.java +++ b/src/gui/editor/EmptyValidatingEditor.java @@ -30,8 +30,7 @@ public class EmptyValidatingEditor extends ValidatingEditor } @Override - public boolean isValid( Editor editor ) throws EditorValidationException + public void validate( Editor editor ) throws EditorValidationException { - return true; } } diff --git a/src/gui/editor/ValidatingEditor.java b/src/gui/editor/ValidatingEditor.java index 30b13d72..149a8c4f 100644 --- a/src/gui/editor/ValidatingEditor.java +++ b/src/gui/editor/ValidatingEditor.java @@ -11,5 +11,5 @@ public abstract class ValidatingEditor extends Editor /** * Indicates if the editor argument is valid according to the settings of this editor */ - public abstract boolean isValid( Editor editor ) throws EditorValidationException; + public abstract void validate( Editor editor ) throws EditorValidationException; } diff --git a/src/module/decode/DecodeConfigurationEditor.java b/src/module/decode/DecodeConfigurationEditor.java index 8fcf52e5..450a1288 100644 --- a/src/module/decode/DecodeConfigurationEditor.java +++ b/src/module/decode/DecodeConfigurationEditor.java @@ -87,6 +87,7 @@ public class DecodeConfigurationEditor extends ValidatingEditor { remove( mCurrentEditor ); mCurrentEditor = editor; + mCurrentEditor.setItem( getItem() ); add( mCurrentEditor ); revalidate(); @@ -97,12 +98,12 @@ public class DecodeConfigurationEditor extends ValidatingEditor @Override public void save() { -// if( mEditor != null ) -// { -// mEditor.save(); -// } -// -// mChannel.setDecodeConfiguration( mEditor.getConfig() ); + if( hasItem() && mCurrentEditor != null ) + { + mCurrentEditor.save(); + } + + setModified( false ); } @Override @@ -119,11 +120,13 @@ public class DecodeConfigurationEditor extends ValidatingEditor { mComboDecoders.setEnabled( false ); } + + setModified( false ); } @Override - public boolean isValid( Editor editor ) throws EditorValidationException + public void validate( Editor editor ) throws EditorValidationException { - return mCurrentEditor.isValid( editor ); + mCurrentEditor.validate( editor ); } } diff --git a/src/module/decode/am/AMDecoderEditor.java b/src/module/decode/am/AMDecoderEditor.java index 525e4cfc..53d1d41c 100644 --- a/src/module/decode/am/AMDecoderEditor.java +++ b/src/module/decode/am/AMDecoderEditor.java @@ -31,9 +31,8 @@ public class AMDecoderEditor extends ValidatingEditor } @Override - public boolean isValid( Editor editor ) throws EditorValidationException + public void validate( Editor editor ) throws EditorValidationException { - return true; } @Override diff --git a/src/module/decode/ltrnet/LTRNetDecoderEditor.java b/src/module/decode/ltrnet/LTRNetDecoderEditor.java index 3f4e9c32..fafdba63 100644 --- a/src/module/decode/ltrnet/LTRNetDecoderEditor.java +++ b/src/module/decode/ltrnet/LTRNetDecoderEditor.java @@ -91,6 +91,7 @@ public class LTRNetDecoderEditor extends ValidatingEditor mComboDirection = new JComboBox(); mComboDirection.setModel( new DefaultComboBoxModel( MessageDirection.values() ) ); + mComboDirection.setSelectedItem( MessageDirection.OSW ); mComboDirection.setEnabled( false ); mComboDirection.addActionListener( new ActionListener() { @@ -106,9 +107,8 @@ public class LTRNetDecoderEditor extends ValidatingEditor } @Override - public boolean isValid( Editor editor ) throws EditorValidationException + public void validate( Editor editor ) throws EditorValidationException { - return true; } @@ -119,6 +119,8 @@ public class LTRNetDecoderEditor extends ValidatingEditor if( hasItem() ) { + mAFC.setEnabled( true ); + mAFCMaximumCorrection.setEnabled( true ); mComboDirection.setEnabled( true ); DecodeConfiguration config = getItem().getDecodeConfiguration(); @@ -133,6 +135,8 @@ public class LTRNetDecoderEditor extends ValidatingEditor } else { + mAFC.setEnabled( false ); + mAFCMaximumCorrection.setEnabled( false ); mComboDirection.setEnabled( false ); } }