Skip to content

Commit

Permalink
EcuEditor Compare Part 3:
Browse files Browse the repository at this point in the history
 - Simplified compare logic.
 - Comparing bin data now refreshes when compare to values are changed.
  - Possible performance implications.
 - added several checks for changes before updating the bin data.
 - Added tooltips to the compare menu.
  • Loading branch information
scotthew committed Jan 4, 2013
1 parent b91f9e1 commit ff45a14
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 96 deletions.
37 changes: 18 additions & 19 deletions src/com/romraider/maps/DataCell.java
Expand Up @@ -84,25 +84,23 @@ public void updateDisplayValue() {
if (getCompareDisplay() == Table.COMPARE_DISPLAY_OFF) {
displayValue = getRealValue();

} else {
if (getCompareDisplay() == Table.COMPARE_DISPLAY_ABSOLUTE) {
displayValue = formatter.format(
calcDisplayValue(binValue, table.getScale().getExpression()) -
calcDisplayValue(compareValue, table.getScale().getExpression()));

} else if (getCompareDisplay() == Table.COMPARE_DISPLAY_PERCENT) {
String expression = table.getScale().getExpression();
double thisValue = calcDisplayValue(binValue, expression);
double thatValue = calcDisplayValue(compareValue, expression);
double difference = thisValue - thatValue;
if (difference == 0) {
displayValue = PERCENT_FORMAT.format(0.0);
} else if (thatValue == 0.0) {
displayValue = '\u221e' + "%";
} else {
double d = difference / abs(thatValue);
displayValue = PERCENT_FORMAT.format(d);
}
} else if (getCompareDisplay() == Table.COMPARE_DISPLAY_ABSOLUTE) {
displayValue = formatter.format(
calcDisplayValue(binValue, table.getScale().getExpression()) -
calcDisplayValue(compareValue, table.getScale().getExpression()));

} else if (getCompareDisplay() == Table.COMPARE_DISPLAY_PERCENT) {
String expression = table.getScale().getExpression();
double thisValue = calcDisplayValue(binValue, expression);
double thatValue = calcDisplayValue(compareValue, expression);
double difference = thisValue - thatValue;
if (difference == 0) {
displayValue = PERCENT_FORMAT.format(0.0);
} else if (thatValue == 0.0) {
displayValue = '\u221e' + "%";
} else {
double d = difference / abs(thatValue);
displayValue = PERCENT_FORMAT.format(d);
}
}
setText(displayValue);
Expand Down Expand Up @@ -163,6 +161,7 @@ else if (binValue > Math.pow(256, table.getStorageType()) - 1) {
}
}
this.updateDisplayValue();
table.refreshCompares();
}

public double getBinValue() {
Expand Down
64 changes: 54 additions & 10 deletions src/com/romraider/maps/Table.java
Expand Up @@ -38,6 +38,8 @@
import java.awt.event.KeyListener;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

Expand Down Expand Up @@ -121,12 +123,15 @@ public abstract class Table extends JPanel implements Serializable {
protected Color maxColor;
protected Color minColor;
protected boolean isAxis = false;
protected int compareType = COMPARE_TYPE_ORIGINAL;
protected int compareDisplay = COMPARE_DISPLAY_OFF;
protected int userLevel = 0;
protected ECUEditor editor;
protected boolean locked = false;

protected int compareType = COMPARE_TYPE_ORIGINAL;
protected int compareDisplay = COMPARE_DISPLAY_OFF;
protected Table compareTable = null;
protected List<Table> comparedToTables = new ArrayList<Table>();

protected String logParam = BLANK;
protected String liveValue = BLANK;
protected boolean overlayLog = false;
Expand Down Expand Up @@ -896,7 +901,9 @@ public void undoAll() {
clearLiveDataTrace();
if (!isStatic) {
for (DataCell cell : data) {
cell.setBinValue(cell.getOriginalValue());
if(cell.getBinValue() != cell.getOriginalValue()) {
cell.setBinValue(cell.getOriginalValue());
}
}
}
colorize();
Expand All @@ -908,7 +915,9 @@ public void undoSelected() {
for (DataCell cell : data) {
// reset current value to original value
if (cell.isSelected()) {
cell.setBinValue(cell.getOriginalValue());
if(cell.getBinValue() != cell.getOriginalValue()) {
cell.setBinValue(cell.getOriginalValue());
}
}
}
}
Expand Down Expand Up @@ -1144,19 +1153,18 @@ public void actionPerformed(ActionEvent e) {
}
}

public void compare(Table compareTable, int compareType) {
public boolean fillCompareValues() {
if(null == compareTable) {
return;
return false;
}

clearLiveDataTrace();
this.compareType = compareType;

DataCell[] compareData = compareTable.getData();
if(data.length != compareData.length) {
return;
return false;
}

clearLiveDataTrace();

int i = 0;
for(DataCell cell : data) {
if(compareType == COMPARE_TYPE_BIN) {
Expand All @@ -1166,10 +1174,18 @@ public void compare(Table compareTable, int compareType) {
}
i++;
}
return true;
}

public void setCompareDisplay(int compareDisplay) {
this.compareDisplay = compareDisplay;
}

public int getCompareDisplay() {
return this.compareDisplay;
}

public void refreshCellDisplay() {
for(DataCell cell : data) {
cell.setCompareDisplay(compareDisplay);
cell.updateDisplayValue();
Expand Down Expand Up @@ -1311,6 +1327,34 @@ public int getCompareType() {
public void setCompareType(int compareType) {
this.compareType = compareType;
}

public void setCompareTable(Table compareTable) {
this.compareTable = compareTable;
}

public List<Table> getComparedToTables() {
return this.comparedToTables;
}

public void addComparedToTable(Table table) {
if(!table.equals(this) && !this.getComparedToTables().contains(table)) {
comparedToTables.add(table);
}
}

public void refreshCompares() {
if(null == comparedToTables || comparedToTables.size() < 1) {
return;
}

for(Table table : comparedToTables) {
if(null != table) {
if(table.fillCompareValues()) {
table.refreshCellDisplay();
}
}
}
}
}

class CopySelectionWorker extends SwingWorker<Void, Void> {
Expand Down
5 changes: 0 additions & 5 deletions src/com/romraider/maps/Table1D.java
Expand Up @@ -74,11 +74,6 @@ public void clearSelection(boolean calledByParent) {
}
}

@Override
public void colorize() {
super.colorize();
}

@Override
public void cursorUp() {
if (type == Table.TABLE_Y_AXIS) {
Expand Down
59 changes: 52 additions & 7 deletions src/com/romraider/maps/Table2D.java
Expand Up @@ -72,22 +72,24 @@ public String toString() {
}

@Override
public void compare(Table compareTable, int compareType) {
public boolean fillCompareValues() {
super.fillCompareValues();

if(null == compareTable || !(compareTable instanceof Table2D)) {
return;
return false;
}

Table2D compareTable2D = (Table2D) compareTable;

if(data.length != compareTable2D.data.length || axis.data.length != compareTable2D.axis.data.length) {
return;
if(data.length != compareTable2D.data.length ||
axis.data.length != compareTable2D.axis.data.length) {
return false;
}

super.compare(compareTable, compareType);
if(!axis.isStatic)
{
axis.compare(compareTable2D.axis, compareType);
axis.fillCompareValues();
}
return true;
}

@Override
Expand Down Expand Up @@ -392,6 +394,49 @@ public void setCompareDisplay(int compareDisplay) {
axis.setCompareDisplay(compareDisplay);
}
}

@Override
public void setCompareType(int compareType) {
super.setCompareType(compareType);
if(!axis.isStatic) {
axis.setCompareType(compareType);
}
}

@Override
public void setCompareTable(Table compareTable) {
super.setCompareTable(compareTable);

if(compareTable == null || !(compareTable instanceof Table2D)) {
return;
}

Table2D compareTable2D = (Table2D) compareTable;

if(!axis.isStatic) {
this.axis.setCompareTable(compareTable2D.axis);
}
}

@Override
public void refreshCellDisplay() {
super.refreshCellDisplay();
if(!axis.isStatic) {
axis.refreshCellDisplay();
}
}

@Override
public void addComparedToTable(Table table) {
super.addComparedToTable(table);
if(!(table instanceof Table2D)) {
return;
}
Table2D table2D = (Table2D) table;
if(!axis.isStatic) {
axis.addComparedToTable(table2D.axis);
}
}
}

class CopySelection2DWorker extends SwingWorker<Void, Void> {
Expand Down

0 comments on commit ff45a14

Please sign in to comment.