Scaling Fixes:

- Set default scale format to #.##
 - Removed unused table reference from Scale.java.
 - Added checks for staticDataTable before setting the scale.
 - fix for NullPointerException when changing table scales.
This commit is contained in:
Scotthew 2014-05-07 20:39:51 -07:00
parent 1127b78879
commit 0b55ac2f52
4 changed files with 87 additions and 19 deletions

View File

@ -31,12 +31,11 @@ public class Scale implements Serializable {
private String unit = "0x"; private String unit = "0x";
private String expression = "x"; private String expression = "x";
private String byteExpression = "x"; private String byteExpression = "x";
private String format = "#"; private String format = "#.##";
private double coarseIncrement = 2; private double coarseIncrement = 2;
private double fineIncrement = 1; private double fineIncrement = 1;
private double min = 0.0; private double min = 0.0;
private double max = 0.0; private double max = 0.0;
private Table table;
public Scale() { public Scale() {
} }
@ -142,11 +141,75 @@ public class Scale implements Serializable {
this.max = max; this.max = max;
} }
public Table getTable() { @Override
return table; public boolean equals(Object other) {
try {
if(null == other) {
return false;
} }
public void setTable(Table table) { if(other == this) {
this.table = table; return true;
}
if(!(other instanceof Scale)) {
return false;
}
Scale otherScale = (Scale)other;
if( (null == this.getName() && null == otherScale.getName())
|| (this.getName().isEmpty() && otherScale.getName().isEmpty()) ) {
;// Skip name compare if name is null or empty.
} else {
if(!this.getName().equalsIgnoreCase(otherScale.getName())) {
return false;
}
}
if(!this.getUnit().equals(otherScale.getUnit()))
{
return false;
}
if(!this.getExpression().equals(otherScale.getExpression()))
{
return false;
}
if(!this.getByteExpression().equals(otherScale.getByteExpression()))
{
return false;
}
if(!this.getFormat().equals(otherScale.getFormat()))
{
return false;
}
if(this.getCoarseIncrement() != otherScale.getCoarseIncrement())
{
return false;
}
if(this.getFineIncrement() != otherScale.getFineIncrement())
{
return false;
}
if(this.getMin() != otherScale.getMin())
{
return false;
}
if(this.getMax() != otherScale.getMax())
{
return false;
}
return true;
} catch(Exception ex) {
return false;
}
} }
} }

View File

@ -1236,7 +1236,8 @@ public abstract class Table extends JPanel implements Serializable {
public void setScaleByName(String scaleName) throws NameNotFoundException { public void setScaleByName(String scaleName) throws NameNotFoundException {
for(Scale scale : scales) { for(Scale scale : scales) {
if(scale.getName().equalsIgnoreCase(scaleName)) { if(scale.getName().equalsIgnoreCase(scaleName)) {
if(!getCurrentScale().equals(scale)) { Scale currentScale = getCurrentScale();
if(currentScale == null || !currentScale.equals(scale)) {
this.setCurrentScale(scale); this.setCurrentScale(scale);
} }
return; return;

View File

@ -375,7 +375,7 @@ public class Table2D extends Table {
@Override @Override
public void setCurrentScale(Scale curScale) { public void setCurrentScale(Scale curScale) {
if(SettingsManager.getSettings().isScaleHeadersAndData()) { if(SettingsManager.getSettings().isScaleHeadersAndData() && !axis.isStaticDataTable()) {
try { try {
this.axis.setScaleByName(curScale.getName()); this.axis.setScaleByName(curScale.getName());
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {

View File

@ -916,6 +916,7 @@ public class Table3D extends Table {
@Override @Override
public void setCurrentScale(Scale curScale) { public void setCurrentScale(Scale curScale) {
if(SettingsManager.getSettings().isScaleHeadersAndData()) { if(SettingsManager.getSettings().isScaleHeadersAndData()) {
if(!xAxis.isStaticDataTable()) {
try { try {
this.xAxis.setScaleByName(curScale.getName()); this.xAxis.setScaleByName(curScale.getName());
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
@ -924,6 +925,8 @@ public class Table3D extends Table {
} catch (NameNotFoundException e1) { } catch (NameNotFoundException e1) {
} }
} }
}
if(!yAxis.isStaticDataTable()) {
try { try {
this.yAxis.setScaleByName(curScale.getName()); this.yAxis.setScaleByName(curScale.getName());
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
@ -933,6 +936,7 @@ public class Table3D extends Table {
} }
} }
} }
}
this.curScale = curScale; this.curScale = curScale;
updateTableLabel(); updateTableLabel();
drawTable(); drawTable();