diff --git a/MafScaling.jar b/MafScaling.jar index 4bc184a..16e834b 100644 Binary files a/MafScaling.jar and b/MafScaling.jar differ diff --git a/src/com/vgi/mafscaling/ACompCalc.java b/src/com/vgi/mafscaling/ACompCalc.java index a374024..a78dff6 100644 --- a/src/com/vgi/mafscaling/ACompCalc.java +++ b/src/com/vgi/mafscaling/ACompCalc.java @@ -743,7 +743,11 @@ protected void plot3dCorrection() { for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i); double[][] z = Utils.doubleZArray(corrTable, x, y); - Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1); + Color[][] tableColors = Utils.generateTableColorMatrix(corrTable, 1, 1, y.length + 1, x.length + 1); + Color[][] colors = new Color[y.length][x.length]; + for (int j = 1; j < tableColors.length; ++j) + for (i = 1; i < tableColors[j].length; ++i) + colors[j - 1][i - 1] = tableColors[j][i]; plot3d.addGridPlot("Average Error % Plot", colors, x, y, z); } catch (Exception e) { diff --git a/src/com/vgi/mafscaling/MafScaling.java b/src/com/vgi/mafscaling/MafScaling.java index 2c0e8ff..5693949 100644 --- a/src/com/vgi/mafscaling/MafScaling.java +++ b/src/com/vgi/mafscaling/MafScaling.java @@ -35,7 +35,7 @@ public class MafScaling { private static final Logger logger = Logger.getLogger(MafScaling.class); - private static final String Title = "MAF Scaling - v2.2.2"; + private static final String Title = "MAF Scaling - v2.2.3"; private static final String OLTabName = "Open Loop"; private static final String CLTabName = "Closed Loop"; private static final String RTabName = "Rescale"; diff --git a/src/com/vgi/mafscaling/Utils.java b/src/com/vgi/mafscaling/Utils.java index 6e82e13..c674c05 100644 --- a/src/com/vgi/mafscaling/Utils.java +++ b/src/com/vgi/mafscaling/Utils.java @@ -46,6 +46,7 @@ public final class Utils { public final static String onOffRegex = "(?i)^\\s*(ON|OFF|OPENED|OPEN|CLOSED|CLOSE)\\s*$"; public final static Pattern offPattern = Pattern.compile("^\\s*(OFF|CLOSED|CLOSE)\\s*$", Pattern.CASE_INSENSITIVE); public final static Pattern onPattern = Pattern.compile("^\\s*(ON|OPENED|OPEN)\\s*$", Pattern.CASE_INSENSITIVE); + public final static Color ZeroColor = new Color(255, 255, 255, 0); private static long baseTime = 0; @@ -107,33 +108,41 @@ public static Color[] getColorArray(Color begin, Color end, int numColors) { * @param startColumn, column to begin coloring from */ public static Color[][] generateTableColorMatrix(JTable table, int startRow, int startColumn) { + return generateTableColorMatrix(table, startRow, startColumn, table.getRowCount(), table.getColumnCount()); + } + + /** + * Methods return table gradient colors matrix + * @param table, table to get matrix for + * @param startRow, row to begin coloring from + * @param startColumn, column to begin coloring from + * @param endRow, row to finish coloring on + * @param endColumn, column to finish coloring on + * @return + */ + public static Color[][] generateTableColorMatrix(JTable table, int startRow, int startColumn, int endRow, int endColumn) { Color[][] colorMatrix = null; TreeSet uniqueValues = new TreeSet(); int i, j; - Object cellValue; String value; - for (i = startRow; i < table.getRowCount(); ++i) { - for (j = startColumn; j < table.getColumnCount(); ++j) { - cellValue = table.getValueAt(i, j); - if (cellValue != null) { - value = cellValue.toString(); - if (!value.isEmpty() && Pattern.matches(Utils.fpRegex, value)) - uniqueValues.add(Double.valueOf(value)); - } + for (i = startRow; i < endRow; ++i) { + for (j = startColumn; j < endColumn; ++j) { + value = table.getValueAt(i, j).toString(); + if (!value.isEmpty() && Pattern.matches(Utils.fpRegex, value)) + uniqueValues.add(Double.valueOf(value)); } } if (uniqueValues.size() > 0) { List colors = Arrays.asList(Utils.getColorArray(uniqueValues.size())); Collections.reverse(colors); - colorMatrix = new Color[table.getRowCount()][table.getColumnCount()]; - for (i = startRow; i < table.getRowCount(); ++i) { - for (j = startColumn; j < table.getColumnCount(); ++j) { - cellValue = table.getValueAt(i, j); - if (cellValue != null) { - value = cellValue.toString(); - if (!value.isEmpty() && Pattern.matches(Utils.fpRegex, value)) - colorMatrix[i][j] = colors.get(uniqueValues.headSet(Double.valueOf(value)).size()); - } + colorMatrix = new Color[endRow][endColumn]; + for (i = startRow; i < endRow; ++i) { + for (j = startColumn; j < endColumn; ++j) { + value = table.getValueAt(i, j).toString(); + if (!value.isEmpty() && Pattern.matches(Utils.fpRegex, value)) + colorMatrix[i][j] = colors.get(uniqueValues.headSet(Double.valueOf(value)).size()); + else + colorMatrix[i][j] = ZeroColor; } } } @@ -421,7 +430,7 @@ public static Color[][] doubleColorArray(JTable dataTable, double[] x, double[] if (!dataTable.getValueAt(j + 1, i + 1).toString().isEmpty()) z[j][i] = renderer.getColorAt(j + 1, i + 1); else - z[j][i] = new Color(255, 255, 255, 0); + z[j][i] = ZeroColor; } } return z; diff --git a/src/com/vgi/mafscaling/VECalc.java b/src/com/vgi/mafscaling/VECalc.java index 72847c1..d8a9b86 100644 --- a/src/com/vgi/mafscaling/VECalc.java +++ b/src/com/vgi/mafscaling/VECalc.java @@ -654,7 +654,11 @@ private boolean plotCorrectionData() { for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i); double[][] z = Utils.doubleZArray(corrTable, x, y); - Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1); + Color[][] tableColors = Utils.generateTableColorMatrix(corrTable, 1, 1, y.length + 1, x.length + 1); + Color[][] colors = new Color[y.length][x.length]; + for (j = 1; j < tableColors.length; ++j) + for (i = 1; i < tableColors[j].length; ++i) + colors[j - 1][i - 1] = tableColors[j][i]; plot3d.addGridPlot("Average Error % Plot", colors, x, y, z); } catch (NumberFormatException e) {