Editor Comparison Updates:

- Resolved issue where missing TableSwitch getType() method breaks table rendering.
 - Added ability to compare DTC's.  Differences will change the DTC radio button text to Red.
 - Unsupported DTC menu options are now disabled.
 - Wrapped all table compare functions in try catch returning false on errors.
 - Added Override equals() method to axis tables (Table1D).
This commit is contained in:
Scotthew 2013-05-21 21:40:35 -07:00
parent a49e03a24e
commit 1c9ce70774
7 changed files with 309 additions and 93 deletions

View File

@ -121,6 +121,10 @@ public class Settings implements Serializable {
public static Color TABLE_DIFFERENT_COLOR = new Color(193, 27, 23); public static Color TABLE_DIFFERENT_COLOR = new Color(193, 27, 23);
public static Color TABLE_MISSING_COLOR = new Color(251,185,23); public static Color TABLE_MISSING_COLOR = new Color(251,185,23);
/* Compare DTC Foreground Colors */
public static Color TABLESWITCH_DEFAULT_COLOR = Color.black;
public static Color TABLESWITCH_DIFFERENT_COLOR = new Color(193, 27, 23);
/* MDI Desktop Settings*/ /* MDI Desktop Settings*/
public static int FRAME_OFFSET = 20; public static int FRAME_OFFSET = 20;

View File

@ -607,38 +607,53 @@ public abstract class Table extends JPanel implements Serializable {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if(null == other) { try {
return false; if(null == other) {
}
if(other == this) {
return true;
}
if(!(other instanceof Table)) {
return false;
}
Table otherTable = (Table)other;
if(this.data.length != otherTable.data.length)
{
return false;
}
if(this.data.equals(otherTable.data))
{
return true;
}
// Compare Bin Values
for(int i=0 ; i < this.data.length ; i++) {
if(this.data[i].getBinValue() != otherTable.data[i].getBinValue()) {
return false; return false;
} }
}
return true; if(other == this) {
return true;
}
if(!(other instanceof Table)) {
return false;
}
Table otherTable = (Table)other;
if( (null == this.getName() && null == otherTable.getName())
|| (this.getName().isEmpty() && otherTable.getName().isEmpty()) ) {
;// Skip name compare if name is null or empty. This typically happens with
// a table axis. A table axis should be handled by Table1D.
} else {
if(!this.getName().equalsIgnoreCase(otherTable.getName())) {
return false;
}
}
if(this.data.length != otherTable.data.length)
{
return false;
}
if(this.data.equals(otherTable.data))
{
return true;
}
// Compare Bin Values
for(int i=0 ; i < this.data.length ; i++) {
if(this.data[i].getBinValue() != otherTable.data[i].getBinValue()) {
return false;
}
}
return true;
} catch(Exception ex) {
// TODO: Log Exception.
return false;
}
} }
public boolean isStatic() { public boolean isStatic() {

View File

@ -185,4 +185,61 @@ public class Table1D extends Table {
public boolean isButtonSelected() { public boolean isButtonSelected() {
return true; return true;
} }
@Override
public boolean equals(Object other) {
try {
if(null == other) {
return false;
}
if(other == this) {
return true;
}
if(!(other instanceof Table1D)) {
return false;
}
Table1D otherTable = (Table1D)other;
if(this.isIsAxis()) {
if(!otherTable.isIsAxis()) {
return false;
}
if(! this.isStatic() == otherTable.isStatic()) {
return false;
}
} else {
// TODO: Possibly Log Error. It appears that Table1D is always an Axis.
if(!this.getName().equalsIgnoreCase(otherTable.getName())) {
return false;
}
}
if(this.data.length != otherTable.data.length)
{
return false;
}
if(this.data.equals(otherTable.data))
{
return true;
}
// Compare Bin Values
for(int i=0 ; i < this.data.length ; i++) {
if(this.data[i].getBinValue() != otherTable.data[i].getBinValue()) {
return false;
}
}
return true;
} catch(Exception ex) {
// TODO: Log Exception.
return false;
}
}
} }

View File

@ -456,42 +456,51 @@ public class Table2D extends Table {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if(null == other) { try {
return false; if(null == other) {
}
if(other == this) {
return true;
}
if(!(other instanceof Table2D)) {
return false;
}
Table2D otherTable = (Table2D)other;
if(!this.axis.equals(otherTable.axis)) {
return false;
}
if(this.data.length != otherTable.data.length)
{
return false;
}
if(this.data.equals(otherTable.data))
{
return true;
}
// Compare Bin Values
for(int i = 0 ; i < this.data.length ; i++) {
if(this.data[i].getBinValue() != otherTable.data[i].getBinValue()) {
return false; return false;
} }
}
return true; if(other == this) {
return true;
}
if(!(other instanceof Table2D)) {
return false;
}
Table2D otherTable = (Table2D)other;
if(!this.getName().equalsIgnoreCase(otherTable.getName())) {
return false;
}
if(!this.axis.equals(otherTable.axis)) {
return false;
}
if(this.data.length != otherTable.data.length)
{
return false;
}
if(this.data.equals(otherTable.data))
{
return true;
}
// Compare Bin Values
for(int i = 0 ; i < this.data.length ; i++) {
if(this.data[i].getBinValue() != otherTable.data[i].getBinValue()) {
return false;
}
}
return true;
} catch(Exception ex) {
// TODO: Log Exception.
return false;
}
} }
} }

View File

@ -1079,48 +1079,57 @@ public class Table3D extends Table {
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if(null == other) { try {
return false; if(null == other) {
} return false;
}
if(other == this) { if(other == this) {
return true; return true;
} }
if(!(other instanceof Table3D)) { if(!(other instanceof Table3D)) {
return false; return false;
} }
Table3D otherTable = (Table3D)other; Table3D otherTable = (Table3D)other;
if(! this.xAxis.equals(otherTable.xAxis)) { if(!this.getName().equalsIgnoreCase(otherTable.getName())) {
return false; return false;
} }
if(! this.yAxis.equals(otherTable.yAxis)) { if(! this.xAxis.equals(otherTable.xAxis)) {
return false; return false;
} }
if(this.data.length != otherTable.data.length || this.data[0].length != otherTable.data[0].length) if(! this.yAxis.equals(otherTable.yAxis)) {
{ return false;
return false; }
}
if(this.data.equals(otherTable.data)) if(this.data.length != otherTable.data.length || this.data[0].length != otherTable.data[0].length)
{ {
return true; return false;
} }
// Compare Bin Values if(this.data.equals(otherTable.data))
for(int i = 0 ; i < this.data.length ; i++) { {
for(int j = 0; j < this.data[i].length ; j++) { return true;
if(this.data[i][j].getBinValue() != otherTable.data[i][j].getBinValue()) { }
return false;
// Compare Bin Values
for(int i = 0 ; i < this.data.length ; i++) {
for(int j = 0; j < this.data[i].length ; j++) {
if(this.data[i][j].getBinValue() != otherTable.data[i][j].getBinValue()) {
return false;
}
} }
} }
}
return true; return true;
} catch(Exception ex) {
// TODO: Log Exception.
return false;
}
} }
} }

View File

@ -33,7 +33,9 @@ import java.awt.GridLayout;
import java.awt.Insets; import java.awt.Insets;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.swing.AbstractButton; import javax.swing.AbstractButton;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
@ -157,6 +159,11 @@ public class TableSwitch extends Table {
super.setName(name); super.setName(name);
} }
@Override
public int getType() {
return Settings.TABLE_SWITCH;
}
@Override @Override
public void setDescription(String description) { public void setDescription(String description) {
super.setDescription(description); super.setDescription(description);
@ -208,6 +215,14 @@ public class TableSwitch extends Table {
return new Dimension(width, height); return new Dimension(width, height);
} }
public ButtonGroup getButtonGroup() {
return this.buttonGroup;
}
public Map<String, byte[]> getSwitchStates() {
return this.switchStates;
}
@Override @Override
public void colorize() { public void colorize() {
} }
@ -247,6 +262,100 @@ public class TableSwitch extends Table {
} }
} }
@Override
public boolean equals(Object other) {
// TODO: Validate DTC equals.
try {
if(null == other) {
return false;
}
if(other == this) {
return true;
}
if(!(other instanceof TableSwitch)) {
return false;
}
TableSwitch otherTable = (TableSwitch)other;
if(!this.getName().equalsIgnoreCase(otherTable.getName())) {
return false;
}
if(this.getDataSize() != otherTable.getDataSize()) {
return false;
}
if(this.getSwitchStates() == otherTable.getSwitchStates()) {
return true;
}
// Compare Map Keys
Set<String> keys = new HashSet<String>(this.getSwitchStates().keySet());
Set<String> otherKeys = new HashSet<String>(otherTable.getSwitchStates().keySet());
if(keys.size() != otherKeys.size()) {
return false;
}
if(!keys.containsAll(otherKeys)) {
return false;
}
// Compare Map Values.
Set<byte[]> values = new HashSet<byte[]>(this.getSwitchStates().values());
Set<byte[]> otherValues = new HashSet<byte[]>(otherTable.getSwitchStates().values());
if(values.equals(otherValues)) {
return true;
}
// Compare DTC. Is there a better way to compare the DTC?
for(String key : keys) {
JRadioButton button = getButtonByText(this.getButtonGroup(), key);
JRadioButton otherButton = getButtonByText(otherTable.getButtonGroup(), key);
if(button.isSelected() != otherButton.isSelected()) {
return false;
}
}
return true;
} catch(Exception ex) {
// TODO: Log Exception.
return false;
}
}
@Override
public boolean fillCompareValues() {
return true; // Do Nothing.
}
@Override
public void refreshCellDisplay() {
if(!(compareTable instanceof TableSwitch)) {
return;
}
TableSwitch otherTable = (TableSwitch)compareTable;
Set<String> keys = new HashSet<String>(this.getSwitchStates().keySet());
// Compare DTC.
for(String key : keys) {
JRadioButton button = getButtonByText(this.getButtonGroup(), key);
JRadioButton otherButton = getButtonByText(otherTable.getButtonGroup(), key);
if(compareDisplay == Settings.COMPARE_DISPLAY_OFF || button.isSelected() == otherButton.isSelected()) {
button.setForeground(Settings.TABLESWITCH_DEFAULT_COLOR);
} else {
button.setForeground(Settings.TABLESWITCH_DIFFERENT_COLOR);
}
}
}
// returns the selected radio button in the specified group // returns the selected radio button in the specified group
private static JRadioButton getSelectedButton(ButtonGroup group) { private static JRadioButton getSelectedButton(ButtonGroup group) {
for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements(); ) { for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements(); ) {

View File

@ -80,6 +80,7 @@ public class TableMenuBar extends JMenuBar implements ActionListener {
initFileMenu(); initFileMenu();
initEditMenu(); initEditMenu();
initViewMenu(); initViewMenu();
applyTableTypeRules();
} }
public void refreshTableMenuBar() { public void refreshTableMenuBar() {
@ -239,6 +240,18 @@ public class TableMenuBar extends JMenuBar implements ActionListener {
} }
} }
private void applyTableTypeRules() {
// Hide items that don't work with a DTC tables.
if(table.getType() == Settings.TABLE_SWITCH) {
editMenu.setEnabled(false);
compareOriginal.setEnabled(false);
comparePercent.setEnabled(false);
compareAbsolute.setEnabled(false);
compareToOriginal.setEnabled(false);
compareToBin.setEnabled(false);
}
}
private void refreshSimilarOpenTables() { private void refreshSimilarOpenTables() {
similarOpenTables.removeAll(); similarOpenTables.removeAll();
String currentTableName = table.getName(); String currentTableName = table.getName();