Skip to content

Commit

Permalink
Stop UI picking up illegal values from settings
Browse files Browse the repository at this point in the history
Fixes a crash caused by IllegalArgumentException thrown by
javax.swing.SpinnerNumberModel.
  • Loading branch information
jdhoek committed May 2, 2020
1 parent 362482b commit 0d3f8b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/nl/jeroenhoek/josm/gridify/GridifySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@ public class GridifySettings {
);

public int getNumRows() {
return numRowsSetting.get();
int rows = numRowsSetting.get();

// Limit number of rows to permissible values.
if (rows < 1 || rows > 1000) {
setNumRows(2);
return 2;
}

return rows;
}

public void setNumRows(int numRows) {
numRowsSetting.put(numRows);
}

public int getNumColumns() {
return numColsSetting.get();
int columns = numColsSetting.get();

// Limit number of rows to permissible values.
if (columns < 1 || columns > 1000) {
setNumColumns(4);
return 4;
}

return columns;
}

public void setNumColumns(int numColumns) {
Expand Down
2 changes: 2 additions & 0 deletions src/nl/jeroenhoek/josm/gridify/ui/GridSizePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public GridSizePanel(ChangeCallback changeCallback, int rows, int columns) {
}

void setRowCount(int rows) {
if (rows < 1 || rows > 1000) return;
this.rows = rows;
this.spinnerRows.setValue(rows);
changeCallback.changed(getRowCount(), getColumnCount());
}

void setColumnCount(int columns) {
if (columns < 1 || columns > 1000) return;
this.columns = columns;
this.spinnerColumns.setValue(columns);
changeCallback.changed(getRowCount(), getColumnCount());
Expand Down

0 comments on commit 0d3f8b2

Please sign in to comment.