Save Fine Course Values in tables

This commit is contained in:
Robin K 2020-03-29 17:34:39 +02:00
parent 601c491af0
commit 96013bc398
2 changed files with 45 additions and 2 deletions

View File

@ -594,7 +594,14 @@ public abstract class Table extends JPanel implements Serializable {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
//Gets called by toolbar
public void updateIncrementDecrementValues(double fineInc, double courseInc) {
this.curScale.setCoarseIncrement(courseInc);
this.curScale.setFineIncrement(fineInc);
}
public Scale getCurrentScale() { public Scale getCurrentScale() {
return this.curScale; return this.curScale;
} }
@ -905,6 +912,7 @@ public abstract class Table extends JPanel implements Serializable {
} }
public void drawTable() { public void drawTable() {
for(DataCell cell : data) { for(DataCell cell : data) {
if(null != cell) { if(null != cell) {
cell.drawCell(); cell.drawCell();

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2018 RomRaider.com * Copyright (C) 2006-2020 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -304,6 +304,37 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
this.updateTableToolBar(getTable()); this.updateTableToolBar(getTable());
} }
private void saveFineCourseValuesInTable(Table t) {
if(t == null || t.getCurrentScale() == null) return;
double incCoarse = 0;
double incFine = 0;
try {
//Commit the value which was typed (if field still has focus)
incrementByCoarse.commitEdit();
incrementByFine.commitEdit();
incCoarse = Double.parseDouble(String.valueOf(incrementByCoarse.getValue()));
incFine = Double.parseDouble(String.valueOf(incrementByFine.getValue()));
}
//Current value in the inc/dec field are not valid
catch(ParseException e) {
return;
}
//Should not happen since ParseException would happen before that
catch(NumberFormatException e) {
return;
}
//Save current inc/dec values in table before we switch
if(incCoarse!=0 && incFine != 0) {
t.updateIncrementDecrementValues(incFine,incCoarse);
}
}
public void updateTableToolBar(Table selectedTable) { public void updateTableToolBar(Table selectedTable) {
if(selectedTable == null && this.selectedTable == null) { if(selectedTable == null && this.selectedTable == null) {
// Skip if the table is the same to avoid multiple updates // Skip if the table is the same to avoid multiple updates
@ -315,6 +346,10 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
return; return;
} }
//Save the current inc/dec values in the table
saveFineCourseValuesInTable(this.selectedTable);
this.selectedTable = selectedTable; this.selectedTable = selectedTable;
setBorder(toolbarBorder); setBorder(toolbarBorder);