Cell Color Changes:

- Updated cell color functionality.  Part 1.
 - Should give a performance increase.

Note: color scale is set off of the original values.  As values change the colors can move outside the range.  A button will be added to allow for a range refresh and a table redraw.
This commit is contained in:
Scotthew 2013-07-11 11:13:45 -07:00
parent df8221749e
commit a46345edb3
8 changed files with 125 additions and 280 deletions

View File

@ -361,8 +361,8 @@ public class ECUEditor extends AbstractFrame {
}
}
// frame not added. add the frame.
frame.getTable().refreshDataBounds();
// frame not added. Draw table and add the frame.
frame.getTable().drawTable();
rightPanel.add(frame);
} catch (IllegalArgumentException ex) {
;// Do nothing.

View File

@ -180,9 +180,9 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
double scaleValue = getBinValue();
table.getMaxValue();
if (table.getMaxValue() < table.getMaxBin()) {
if (table.getMaxValue() < scaleValue) {
return getSettings().getWarningColor();
} else if (table.getMinValue() > table.getMinBin()) {
} else if (table.getMinValue() > scaleValue) {
return getSettings().getWarningColor();
} else {
// limits not set, scale based on table values
@ -199,7 +199,7 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
}
public void drawCell() {
if(!staticValue && (table == null || !table.isLoaded()) ) {
if(table == null) {
return;
}
@ -383,64 +383,10 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
return;
}
// get current real and compare.
double currentBin = getBinValue();
double currentCompare = getCompareValue();
// set bin.
binValue = checkedValue;
table.refreshCompares();
// get new real and compare.
double compareValue = getCompareValue();
// check for compare refresh.
if( (currentCompare == table.getMaxCompare() && compareValue < currentCompare) ||
(currentCompare == table.getMinCompare() && compareValue > currentCompare)) {
// look for a new max or min.
table.refreshDataBounds();
return;
}
boolean drawTable = false;
// if new max set max.
if(compareValue > table.getMaxCompare()) {
table.setMaxCompare(compareValue);
drawTable = true;
}
// if new min set min.
if(compareValue < table.getMinCompare()) {
table.setMinCompare(compareValue);
drawTable = true;
}
// check for bin refresh.
if( (currentBin == table.getMaxBin() && checkedValue < currentBin) ||
(currentBin == table.getMinBin() && checkedValue > currentBin)){
// look for a new max or min.
table.refreshDataBounds();
return;
}
// if new max set max.
if(checkedValue > table.getMaxBin()) {
table.setMaxBin(checkedValue);
drawTable = true;
}
// if new min set min.
if(checkedValue < table.getMinBin()) {
table.setMinBin(checkedValue);
drawTable = true;
}
if(drawTable) {
table.drawTable();
} else {
drawCell();
}
drawCell();
}
@Override
@ -576,8 +522,6 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
this.compareToValue = compareCell.originalValue;
}
drawCell();
}
public void multiply(double factor) {

View File

@ -99,16 +99,16 @@ public abstract class Table extends JPanel implements Serializable {
protected CopyTableWorker copyTableWorker;
protected CopySelectionWorker copySelectionWorker;
protected RefreshTableCompareWorker refreshTableCompareWorker;
protected RefreshDataBoundsWorker refreshDataBoundsWorker;
protected boolean loaded = false;
protected double minAllowedValue = 0.0;
protected double maxAllowedValue = 0.0;
protected double maxBin;
protected double minBin;
protected double maxCompare = 0.0;
protected double minCompare = 0.0;
protected double maxBin = 0.0;
protected double minBin = 0.0;
private boolean comparing = false;
protected int compareDisplay = Settings.COMPARE_DISPLAY_ABSOLUTE;
@ -446,7 +446,6 @@ public abstract class Table extends JPanel implements Serializable {
data[i] = new DataCell(this, dataValue, 0, i, scales.get(scaleIndex), getSettings().getCellSize());
data[i].setPreferredSize(new Dimension(cellWidth, cellHeight));
data[i].setBinValue(dataValue);
centerPanel.add(data[i]);
// show locked cell
@ -458,7 +457,7 @@ public abstract class Table extends JPanel implements Serializable {
// reset locked status
locked = tempLock;
loaded = true;
calcCellRanges();
}
public int getType() {
@ -543,6 +542,7 @@ public abstract class Table extends JPanel implements Serializable {
public void setStorageType(int storageType) {
this.storageType = storageType;
calcValueRange();
}
public boolean isSignedData() {
@ -657,23 +657,10 @@ public abstract class Table extends JPanel implements Serializable {
}
}
public void refreshDataBounds() {
Window ancestorWindow = SwingUtilities.getWindowAncestor(this);
if(null != ancestorWindow) {
ancestorWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
ECUEditorManager.getECUEditor().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
refreshDataBoundsWorker = new RefreshDataBoundsWorker(this);
refreshDataBoundsWorker.execute();
}
public double getMaxValue() {
double maxVal = getScale().getMax();
if(0.0 == maxVal) {
maxVal = Double.MAX_VALUE;
maxVal = maxAllowedValue;
}
return maxVal;
}
@ -681,34 +668,88 @@ public abstract class Table extends JPanel implements Serializable {
public double getMinValue() {
double minVal = getScale().getMin();
if(0.0 == minVal) {
minVal = -Double.MAX_VALUE;
minVal = minAllowedValue;
}
return minVal;
}
private void calcValueRange() {
if (getStorageType() != Settings.STORAGE_TYPE_FLOAT) {
if (isSignedData()) {
switch (getStorageType()) {
case 1:
minAllowedValue = Byte.MIN_VALUE;
maxAllowedValue = Byte.MAX_VALUE;
break;
case 2:
minAllowedValue = Short.MIN_VALUE;
maxAllowedValue = Short.MAX_VALUE;
break;
case 4:
minAllowedValue = Integer.MIN_VALUE;
maxAllowedValue = Integer.MAX_VALUE;
break;
}
}
else {
maxAllowedValue = (Math.pow(256, getStorageType()) - 1);
minAllowedValue = 0.0;
}
} else {
maxAllowedValue = Float.MAX_VALUE;
if(isSignedData()) {
minAllowedValue = 0.0;
} else {
minAllowedValue = -Float.MAX_VALUE;
}
}
}
public void calcCellRanges() {
double binMax = data[0].getBinValue();
double binMin = data[0].getBinValue();
double compareMax = data[0].getBinValue() - data[0].getCompareValue();
double compareMin = data[0].getBinValue() - data[0].getCompareValue();
for(DataCell cell : data) {
// Calc bin
if(binMax < cell.getBinValue()) {
binMax = cell.getBinValue();
}
if(binMin > cell.getBinValue()) {
binMin = cell.getBinValue();
}
// Calc compare
double compareValue = cell.getBinValue() - cell.getCompareValue();
if(compareMax < compareValue) {
compareMax = compareValue;
}
if(compareMin > compareValue) {
compareMin = compareValue;
}
}
setMaxBin(binMax);
setMinBin(binMin);
setMaxCompare(compareMax);
setMinCompare(compareMin);
}
public double getMaxBin() {
return this.maxBin;
}
public void setMaxBin(double maxBin) {
if(this.maxBin == maxBin)
{
return;
}
this.maxBin = maxBin;
}
public double getMinBin() {
return this.minBin;
}
public void setMinBin(double minBin) {
if(this.minBin == minBin)
{
return;
}
public void setMaxBin(double maxBin) {
this.maxBin = maxBin;
}
public void setMinBin(double minBin) {
this.minBin = minBin;
}
@ -717,11 +758,6 @@ public abstract class Table extends JPanel implements Serializable {
}
public void setMaxCompare(double maxCompare) {
if(this.maxCompare == maxCompare)
{
return;
}
this.maxCompare = maxCompare;
}
@ -730,11 +766,6 @@ public abstract class Table extends JPanel implements Serializable {
}
public void setMinCompare(double minCompare) {
if(this.minCompare == minCompare)
{
return;
}
this.minCompare = minCompare;
}
@ -1056,15 +1087,12 @@ public abstract class Table extends JPanel implements Serializable {
}
public void populateCompareValues(Table otherTable) {
loaded = false;
if(null == otherTable) {
loaded = true;
return;
}
DataCell[] compareData = otherTable.getData();
if(data.length != compareData.length) {
loaded = true;
return;
}
@ -1075,8 +1103,8 @@ public abstract class Table extends JPanel implements Serializable {
cell.setCompareValue(compareData[i]);
i++;
}
loaded = true;
refreshDataBounds();
calcCellRanges();
}
public void setCompareDisplay(int compareDisplay) {
@ -1126,14 +1154,6 @@ public abstract class Table extends JPanel implements Serializable {
public void setScaleIndex(int scaleIndex) {
// TODO: what is the scale max and min?
this.scaleIndex = scaleIndex;
// recalc max values.
if(maxBin < getScale().getMax()) {
maxBin = getScale().getMax();
}
if(minBin < getScale().getMin()) {
minBin = getScale().getMin();
}
}
public void setScaleByName(String scaleName) {
@ -1168,10 +1188,6 @@ public abstract class Table extends JPanel implements Serializable {
this.locked = locked;
}
public boolean isLoaded() {
return this.loaded;
}
public void setOverlayLog(boolean overlayLog) {
this.overlayLog = overlayLog;
if (overlayLog) {
@ -1352,61 +1368,6 @@ class RefreshTableCompareWorker extends SwingWorker<Void, Void> {
return null;
}
@Override
public void done() {
Window ancestorWindow = SwingUtilities.getWindowAncestor(table);
if(null != ancestorWindow) {
ancestorWindow.setCursor(null);
}
table.setCursor(null);
ECUEditorManager.getECUEditor().setCursor(null);
}
}
class RefreshDataBoundsWorker extends SwingWorker<Void, Void> {
Table table;
public RefreshDataBoundsWorker(Table table) {
this.table = table;
}
@Override
protected Void doInBackground() throws Exception {
try {
double maxBin = table.getData()[0].getBinValue();
double minBin = table.getData()[0].getBinValue();
double maxCompare = table.getData()[0].getCompareValue();
double minCompare = table.getData()[0].getCompareValue();
for(DataCell cell : table.getData()) {
double cellVal = cell.getBinValue();
double compareVal = cell.getCompareValue();
if(cellVal > maxBin) {
maxBin = cellVal;
}
if(cellVal < minBin) {
minBin = cellVal;
}
if(compareVal > maxCompare) {
maxCompare = compareVal;
}
if(compareVal < minCompare) {
minCompare = compareVal;
}
}
table.setMaxBin(maxBin);
table.setMinBin(minBin);
table.setMaxCompare(maxCompare);
table.setMinCompare(minCompare);
} catch (Exception ex) {
; // Do Nothing.
}
return null;
}
@Override
public void done() {
table.drawTable();

View File

@ -42,7 +42,6 @@ public class Table1D extends Table {
}
public void addStaticDataCell(DataCell input) {
loaded = true;
for(int i = 0; i < data.length; i++) {
if(data[i] == null) {
data[i] = input;
@ -53,12 +52,10 @@ public class Table1D extends Table {
@Override
public void populateTable(byte[] input, int romRamOffset) throws ArrayIndexOutOfBoundsException, IndexOutOfBoundsException {
loaded = false;
centerLayout.setRows(1);
centerLayout.setColumns(this.getDataSize());
super.populateTable(input, romRamOffset);
loaded = false;
// add to table
for (int i = 0; i < this.getDataSize(); i++) {
@ -73,7 +70,6 @@ public class Table1D extends Table {
} else {
add(new JLabel(name + " (" + getScale().getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
}
loaded = true;
}
@Override

View File

@ -68,12 +68,6 @@ public class Table2D extends Table {
return super.toString() + " (2D)";// + axis;
}
@Override
public void refreshDataBounds(){
super.refreshDataBounds();
axis.refreshDataBounds();
}
@Override
public void refreshCompares() {
super.refreshCompares();
@ -82,21 +76,15 @@ public class Table2D extends Table {
@Override
public void populateCompareValues(Table otherTable) {
loaded = false;
if(null == otherTable || !(otherTable instanceof Table2D)) {
loaded = true;
return;
}
Table2D compareTable2D = (Table2D) otherTable;
if(data.length != compareTable2D.data.length ||
axis.data.length != compareTable2D.axis.data.length) {
loaded = true;
return;
}
loaded = true;
refreshDataBounds();
drawTable();
super.populateCompareValues(otherTable);
axis.populateCompareValues(compareTable2D.getAxis());
@ -160,6 +148,7 @@ public class Table2D extends Table {
add(new JLabel(axis.getName() + " (" + axis.getScale().getUnit() + ")", JLabel.CENTER), BorderLayout.NORTH);
}
add(new JLabel(getScale().getUnit(), JLabel.CENTER), BorderLayout.SOUTH);
repaint();
}
@Override

View File

@ -61,7 +61,6 @@ public class Table3D extends Table {
CopyTable3DWorker copyTable3DWorker;
CopySelection3DWorker copySelection3DWorker;
RefreshDataBounds3DWorker refreshDataBounds3DWorker;
public Table3D() {
super();
@ -129,20 +128,6 @@ public class Table3D extends Table {
return data[0].length;
}
@Override
public void refreshDataBounds(){
Window ancestorWindow = SwingUtilities.getWindowAncestor(this);
if(null != ancestorWindow) {
ancestorWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
ECUEditorManager.getECUEditor().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
refreshDataBounds3DWorker = new RefreshDataBounds3DWorker(this);
refreshDataBounds3DWorker.execute();
}
@Override
public void drawTable() {
for(DataCell[] column : data) {
@ -158,7 +143,6 @@ public class Table3D extends Table {
@Override
public void populateTable(byte[] input, int romRamOffset) throws NullPointerException, ArrayIndexOutOfBoundsException, IndexOutOfBoundsException {
loaded = false;
// fill first empty cell
centerPanel.add(new JLabel());
if (!beforeRam) {
@ -222,7 +206,6 @@ public class Table3D extends Table {
}
data[x][y] = new DataCell(this, cellBinValue, x, y, scales.get(scaleIndex), getSettings().getCellSize());
data[x][y].setBinValue(cellBinValue);
offset++;
}
}
@ -248,7 +231,42 @@ public class Table3D extends Table {
add(yLabel, BorderLayout.WEST);
add(new JLabel(getScale().getUnit(), JLabel.CENTER), BorderLayout.SOUTH);
loaded = true;
calcCellRanges();
}
@Override
public void calcCellRanges() {
double binMax = data[0][0].getBinValue();
double binMin = data[0][0].getBinValue();
double compareMax = data[0][0].getBinValue() - data[0][0].getCompareValue();
double compareMin = data[0][0].getBinValue() - data[0][0].getCompareValue();
for(DataCell[] column : data) {
for(DataCell cell : column) {
// Calc bin
if(binMax < cell.getBinValue()) {
binMax = cell.getBinValue();
}
if(binMin > cell.getBinValue()) {
binMin = cell.getBinValue();
}
// Calc compare
double compareValue = cell.getBinValue() - cell.getCompareValue();
if(compareMax < compareValue) {
compareMax = compareValue;
}
if(compareMin > compareValue) {
compareMin = compareValue;
}
}
}
setMaxBin(binMax);
setMinBin(binMin);
setMaxCompare(compareMax);
setMinCompare(compareMin);
}
@Override
@ -279,9 +297,7 @@ public class Table3D extends Table {
@Override
public void populateCompareValues(Table otherTable) {
loaded = false;
if(null == otherTable || !(otherTable instanceof Table3D)) {
loaded = true;
return;
}
@ -290,7 +306,6 @@ public class Table3D extends Table {
data[0].length != compareTable3D.data[0].length ||
xAxis.getDataSize() != compareTable3D.xAxis.getDataSize() ||
yAxis.getDataSize() != compareTable3D.yAxis.getDataSize()) {
loaded = true;
return;
}
@ -305,11 +320,11 @@ public class Table3D extends Table {
}
x++;
}
loaded = true;
refreshDataBounds();
xAxis.populateCompareValues(compareTable3D.getXAxis());
yAxis.populateCompareValues(compareTable3D.getYAxis());
calcCellRanges();
}
@Override
@ -1051,62 +1066,3 @@ class CopyTable3DWorker extends SwingWorker<Void, Void> {
ECUEditorManager.getECUEditor().setCursor(null);
}
}
class RefreshDataBounds3DWorker extends SwingWorker<Void, Void> {
Table3D table;
public RefreshDataBounds3DWorker(Table3D table) {
this.table = table;
}
@Override
protected Void doInBackground() throws Exception {
try {
double maxBin = table.get3dData()[0][0].getBinValue();
double minBin = table.get3dData()[0][0].getBinValue();
double maxCompare = table.get3dData()[0][0].getCompareValue();
double minCompare = table.get3dData()[0][0].getCompareValue();
for(DataCell[] column : table.get3dData()) {
for(DataCell cell : column) {
double cellVal = cell.getBinValue();
double compareVal = cell.getCompareValue();
if(cellVal > maxBin) {
maxBin = cellVal;
}
if(cellVal < minBin) {
minBin = cellVal;
}
if(compareVal > maxCompare) {
maxCompare = compareVal;
}
if(compareVal < minCompare) {
minCompare = compareVal;
}
}
}
table.setMaxBin(maxBin);
table.setMinBin(minBin);
table.setMaxCompare(maxCompare);
table.setMinCompare(minCompare);
table.getXAxis().refreshDataBounds();
table.getYAxis().refreshDataBounds();
} catch (Exception ex) {
;// Do nothing.
}
return null;
}
@Override
public void done() {
table.drawTable();
Window ancestorWindow = SwingUtilities.getWindowAncestor(table);
if(null != ancestorWindow) {
ancestorWindow.setCursor(null);
}
table.setCursor(null);
ECUEditorManager.getECUEditor().setCursor(null);
}
}

View File

@ -329,7 +329,7 @@ public class TableSwitch extends Table {
}
@Override
public void refreshDataBounds(){
public void calcCellRanges() {
return; // Do nothing.
}

View File

@ -196,7 +196,6 @@ public class TableFrame extends JInternalFrame implements InternalFrameListener,
selectedTable.addComparedToTable(getTable());
selectedTable.refreshCompares();
getTable().drawTable();
}
public void refreshSimilarOpenTables() {