Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issue #114: when the user settings contain incorrect indexes fo…

…r comboboxes a crash occurs.
  • Loading branch information...
commit 6951af6b6972043c2a2373e9893fa672d8a6e6ef 1 parent 7ab95d6
@jawi authored
View
4 tool.1wire/src/main/java/nl/lxtreme/ols/tool/onewire/OneWireAnalyserDialog.java
@@ -115,8 +115,10 @@ else if ( ExportFormat.CSV.equals( aFormat ) )
@Override
public void readPreferences( final UserSettings aSettings )
{
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.owLine, aSettings, "owLine" );
+
this.owMode.setSelectedIndex( aSettings.getInt( "owMode", this.owMode.getSelectedIndex() ) );
- this.owLine.setSelectedIndex( aSettings.getInt( "owLine", this.owLine.getSelectedIndex() ) );
}
/**
View
16 tool.asm45/src/main/java/nl/lxtreme/ols/tool/asm45/Asm45ProtocolAnalysisDialog.java
@@ -135,13 +135,15 @@ else if ( ExportFormat.HTML.equals( aFormat ) )
*/
public void readPreferences( final UserSettings aSettings )
{
- this.lineSMC.setSelectedIndex( aSettings.getInt( "lineSMC", this.lineSMC.getSelectedIndex() ) );
- this.lineSTM.setSelectedIndex( aSettings.getInt( "lineSTM", this.lineSTM.getSelectedIndex() ) );
- this.lineEBG.setSelectedIndex( aSettings.getInt( "lineEBG", this.lineEBG.getSelectedIndex() ) );
- this.lineBYTE.setSelectedIndex( aSettings.getInt( "lineBYTE", this.lineBYTE.getSelectedIndex() ) );
- this.lineBL.setSelectedIndex( aSettings.getInt( "lineBL", this.lineBL.getSelectedIndex() ) );
- this.lineWRT.setSelectedIndex( aSettings.getInt( "lineWRT", this.lineWRT.getSelectedIndex() ) );
- this.lineSYNC.setSelectedIndex( aSettings.getInt( "lineSYNC", this.lineSYNC.getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.lineSMC, aSettings, "lineSMC" );
+ setComboBoxIndex( this.lineSTM, aSettings, "lineSTM" );
+ setComboBoxIndex( this.lineEBG, aSettings, "lineEBG" );
+ setComboBoxIndex( this.lineBYTE, aSettings, "lineBYTE" );
+ setComboBoxIndex( this.lineBL, aSettings, "lineBL" );
+ setComboBoxIndex( this.lineWRT, aSettings, "lineWRT" );
+ setComboBoxIndex( this.lineSYNC, aSettings, "lineSYNC" );
+
this.showInst.setSelected( aSettings.getBoolean( "showInst", this.showInst.isSelected() ) );
this.showData.setSelected( aSettings.getBoolean( "showData", this.showData.isSelected() ) );
this.showBusGrants.setSelected( aSettings.getBoolean( "showBusGrants", this.showBusGrants.isSelected() ) );
View
17 tool.base/src/main/java/nl/lxtreme/ols/tool/base/BaseToolDialog.java
@@ -26,6 +26,7 @@
import javax.swing.*;
+import nl.lxtreme.ols.api.*;
import nl.lxtreme.ols.api.Configurable;
import nl.lxtreme.ols.api.acquisition.*;
import nl.lxtreme.ols.api.task.*;
@@ -385,6 +386,22 @@ protected void prepareToolTask( final ToolTask<RESULT_TYPE> aToolTask )
}
/**
+ * Convenience method to set the combobox index to a "safe" value, based on
+ * the given user settings.
+ *
+ * @param aComboBox
+ * the combobox to set the selected index for;
+ * @param aSettings
+ * the user settings to take the selected index from;
+ * @param aSettingName
+ * the name of the user setting to use.
+ */
+ protected final void setComboBoxIndex( final JComboBox aComboBox, final UserSettings aSettings, final String aSettingName )
+ {
+ ToolUtils.setComboBoxIndex( aComboBox, aSettings.getInt( aSettingName, -1 ) );
+ }
+
+ /**
* set the controls of the dialog enabled/disabled
*
* @param aEnabled
View
18 tool.base/src/main/java/nl/lxtreme/ols/tool/base/ToolUtils.java
@@ -264,6 +264,24 @@ public static JButton createRunAnalysisButton( final ToolDialog aToolDialog )
}
/**
+ * @param aComboBox
+ * @param aIndex
+ */
+ public static void setComboBoxIndex( final JComboBox aComboBox, final int aIndex )
+ {
+ int idx = aIndex;
+ if ( idx < 0 )
+ {
+ idx = aComboBox.getSelectedIndex();
+ }
+ else if ( idx > aComboBox.getItemCount() )
+ {
+ idx = idx % aComboBox.getItemCount();
+ }
+ aComboBox.setSelectedIndex( idx );
+ }
+
+ /**
* Convenience method to show an error message.
*
* @param aParent
View
3  tool.dmx512/src/main/java/nl/lxtreme/ols/tool/dmx512/DMX512AnalyzerDialog.java
@@ -117,7 +117,8 @@ else if ( ExportFormat.CSV.equals( aFormat ) )
@Override
public void readPreferences( final UserSettings aSettings )
{
- this.dataLine.setSelectedIndex( aSettings.getInt( "dataLine", this.dataLine.getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.dataLine, aSettings, "dataLine" );
}
/**
View
5 tool.i2c/src/main/java/nl/lxtreme/ols/tool/i2c/I2CProtocolAnalysisDialog.java
@@ -167,8 +167,9 @@ else if ( I2CAnalyserTask.LINE_B.equals( lineValue ) )
*/
public void readPreferences( final UserSettings aSettings )
{
- this.lineA.setSelectedIndex( aSettings.getInt( "lineA", this.lineA.getSelectedIndex() ) );
- this.lineB.setSelectedIndex( aSettings.getInt( "lineB", this.lineB.getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.lineA, aSettings, "lineA" );
+ setComboBoxIndex( this.lineB, aSettings, "lineB" );
this.detectSDA_SCL.setSelected( aSettings.getBoolean( "detectSDA_SCL", this.detectSDA_SCL.isSelected() ) );
this.detectSTART.setSelected( aSettings.getBoolean( "detectStart", this.detectSTART.isSelected() ) );
View
9 tool.jtag/src/main/java/nl/lxtreme/ols/tool/jtag/JTAGProtocolAnalysisDialog.java
@@ -120,10 +120,11 @@ else if ( ExportFormat.CSV.equals( aFormat ) )
*/
public void readPreferences( final UserSettings aSettings )
{
- this.tck.setSelectedIndex( aSettings.getInt( "tck", this.tck.getSelectedIndex() ) );
- this.tms.setSelectedIndex( aSettings.getInt( "tms", this.tms.getSelectedIndex() ) );
- this.tdi.setSelectedIndex( aSettings.getInt( "tdi", this.tdi.getSelectedIndex() ) );
- this.tdo.setSelectedIndex( aSettings.getInt( "tdo", this.tdo.getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.tck, aSettings, "tck" );
+ setComboBoxIndex( this.tms, aSettings, "tms" );
+ setComboBoxIndex( this.tdi, aSettings, "tdi" );
+ setComboBoxIndex( this.tdo, aSettings, "tdo" );
}
/**
View
3  ...linedecoder/src/main/java/nl/lxtreme/ols/tool/linedecoder/impl/LineDecoderToolDialog.java
@@ -126,7 +126,8 @@ public void readPreferences( final UserSettings aSettings )
for ( int i = 0; i < this.lines.length; i++ )
{
- this.lines[i].setSelectedIndex( aSettings.getInt( "decoder.line." + i, this.lines[i].getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.lines[i], aSettings, "decoder.line." + i );
}
}
View
15 tool.spi/src/main/java/nl/lxtreme/ols/tool/spi/SPIProtocolAnalysisDialog.java
@@ -287,12 +287,15 @@ public void readPreferences( final UserSettings aSettings )
this.spifiMode.setSelectedIndex( aSettings.getInt( "protocol", this.spifiMode.getSelectedIndex() ) );
this.reportCS.setSelected( aSettings.getBoolean( "reportCS", this.reportCS.isSelected() ) );
this.honourCS.setSelected( aSettings.getBoolean( "honourCS", this.honourCS.isSelected() ) );
- this.sck.setSelectedIndex( aSettings.getInt( "sck", this.sck.getSelectedIndex() ) );
- this.miso.setSelectedIndex( aSettings.getInt( "miso", this.miso.getSelectedIndex() ) );
- this.mosi.setSelectedIndex( aSettings.getInt( "mosi", this.mosi.getSelectedIndex() ) );
- this.io2.setSelectedIndex( aSettings.getInt( "io2", this.io2.getSelectedIndex() ) );
- this.io3.setSelectedIndex( aSettings.getInt( "io3", this.io3.getSelectedIndex() ) );
- this.cs.setSelectedIndex( aSettings.getInt( "cs", this.cs.getSelectedIndex() ) );
+
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.sck, aSettings, "sck" );
+ setComboBoxIndex( this.miso, aSettings, "miso" );
+ setComboBoxIndex( this.mosi, aSettings, "mosi" );
+ setComboBoxIndex( this.io2, aSettings, "io2" );
+ setComboBoxIndex( this.io3, aSettings, "io3" );
+ setComboBoxIndex( this.cs, aSettings, "cs" );
+
this.mode.setSelectedIndex( aSettings.getInt( "mode", this.mode.getSelectedIndex() ) );
this.bits.setSelectedIndex( aSettings.getInt( "bits", this.bits.getSelectedIndex() ) );
this.order.setSelectedIndex( aSettings.getInt( "order", this.order.getSelectedIndex() ) );
View
4 tool.state/src/main/java/nl/lxtreme/ols/tool/state/StateAnalysisDialog.java
@@ -122,8 +122,10 @@ public StateAnalysisDialog( final Window aOwner, final ToolContext aToolContext,
@Override
public void readPreferences( final UserSettings aSettings )
{
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.channelSelect, aSettings, "channel" );
+
this.edgeSelect.setSelectedIndex( aSettings.getInt( "edge", this.edgeSelect.getSelectedIndex() ) );
- this.channelSelect.setSelectedIndex( aSettings.getInt( "channel", this.channelSelect.getSelectedIndex() ) );
}
/**
View
18 tool.uart/src/main/java/nl/lxtreme/ols/tool/uart/impl/UARTProtocolAnalysisDialog.java
@@ -211,14 +211,16 @@ else if ( ExportFormat.CSV.equals( aFormat ) )
@Override
public void readPreferences( final UserSettings aSettings )
{
- this.rxd.setSelectedIndex( aSettings.getInt( "rxd", this.rxd.getSelectedIndex() ) );
- this.txd.setSelectedIndex( aSettings.getInt( "txd", this.txd.getSelectedIndex() ) );
- this.cts.setSelectedIndex( aSettings.getInt( "cts", this.cts.getSelectedIndex() ) );
- this.rts.setSelectedIndex( aSettings.getInt( "rts", this.rts.getSelectedIndex() ) );
- this.dtr.setSelectedIndex( aSettings.getInt( "dtr", this.dtr.getSelectedIndex() ) );
- this.dsr.setSelectedIndex( aSettings.getInt( "dsr", this.dsr.getSelectedIndex() ) );
- this.dcd.setSelectedIndex( aSettings.getInt( "dcd", this.dcd.getSelectedIndex() ) );
- this.ri.setSelectedIndex( aSettings.getInt( "ri", this.ri.getSelectedIndex() ) );
+ // Issue #114: avoid setting illegal values...
+ setComboBoxIndex( this.rxd, aSettings, "rxd" );
+ setComboBoxIndex( this.txd, aSettings, "txd" );
+ setComboBoxIndex( this.cts, aSettings, "cts" );
+ setComboBoxIndex( this.rts, aSettings, "rts" );
+ setComboBoxIndex( this.dtr, aSettings, "dtr" );
+ setComboBoxIndex( this.dsr, aSettings, "dsr" );
+ setComboBoxIndex( this.dcd, aSettings, "dcd" );
+ setComboBoxIndex( this.ri, aSettings, "ri" );
+
this.parity.setSelectedIndex( aSettings.getInt( "parity", this.parity.getSelectedIndex() ) );
this.bits.setSelectedIndex( aSettings.getInt( "bits", this.bits.getSelectedIndex() ) );
this.stop.setSelectedIndex( aSettings.getInt( "stop", this.stop.getSelectedIndex() ) );
Please sign in to comment.
Something went wrong with that request. Please try again.