diff --git a/src/main/java/com/romraider/Settings.java b/src/main/java/com/romraider/Settings.java index 40c0a33c..7d7a1e81 100644 --- a/src/main/java/com/romraider/Settings.java +++ b/src/main/java/com/romraider/Settings.java @@ -121,6 +121,10 @@ public class Settings implements Serializable { public static Color TABLE_DIFFERENT_COLOR = new Color(193, 27, 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*/ public static int FRAME_OFFSET = 20; diff --git a/src/main/java/com/romraider/maps/Table.java b/src/main/java/com/romraider/maps/Table.java index dd00ab43..db3f225b 100644 --- a/src/main/java/com/romraider/maps/Table.java +++ b/src/main/java/com/romraider/maps/Table.java @@ -607,38 +607,53 @@ public abstract class Table extends JPanel implements Serializable { @Override public boolean equals(Object other) { - if(null == other) { - return false; - } - - 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()) { + try { + if(null == other) { 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() { diff --git a/src/main/java/com/romraider/maps/Table1D.java b/src/main/java/com/romraider/maps/Table1D.java index f0d77673..0f1aed9f 100644 --- a/src/main/java/com/romraider/maps/Table1D.java +++ b/src/main/java/com/romraider/maps/Table1D.java @@ -185,4 +185,61 @@ public class Table1D extends Table { public boolean isButtonSelected() { 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; + } + } } \ No newline at end of file diff --git a/src/main/java/com/romraider/maps/Table2D.java b/src/main/java/com/romraider/maps/Table2D.java index 4f5eb4cd..69447281 100644 --- a/src/main/java/com/romraider/maps/Table2D.java +++ b/src/main/java/com/romraider/maps/Table2D.java @@ -456,42 +456,51 @@ public class Table2D extends Table { @Override public boolean equals(Object other) { - if(null == other) { - return false; - } - - 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()) { + try { + if(null == other) { 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; + } } } diff --git a/src/main/java/com/romraider/maps/Table3D.java b/src/main/java/com/romraider/maps/Table3D.java index 2f68840d..dfa49e5b 100644 --- a/src/main/java/com/romraider/maps/Table3D.java +++ b/src/main/java/com/romraider/maps/Table3D.java @@ -1079,48 +1079,57 @@ public class Table3D extends Table { @Override public boolean equals(Object other) { - if(null == other) { - return false; - } + try { + if(null == other) { + return false; + } - if(other == this) { - return true; - } + if(other == this) { + return true; + } - if(!(other instanceof Table3D)) { - return false; - } + if(!(other instanceof Table3D)) { + return false; + } - Table3D otherTable = (Table3D)other; + Table3D otherTable = (Table3D)other; - if(! this.xAxis.equals(otherTable.xAxis)) { - return false; - } + if(!this.getName().equalsIgnoreCase(otherTable.getName())) { + return false; + } - if(! this.yAxis.equals(otherTable.yAxis)) { - return false; - } + if(! this.xAxis.equals(otherTable.xAxis)) { + return false; + } - if(this.data.length != otherTable.data.length || this.data[0].length != otherTable.data[0].length) - { - return false; - } + if(! this.yAxis.equals(otherTable.yAxis)) { + return false; + } - if(this.data.equals(otherTable.data)) - { - return true; - } + if(this.data.length != otherTable.data.length || this.data[0].length != otherTable.data[0].length) + { + 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; + if(this.data.equals(otherTable.data)) + { + return true; + } + + // 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; + } } } diff --git a/src/main/java/com/romraider/maps/TableSwitch.java b/src/main/java/com/romraider/maps/TableSwitch.java index e1f9eedc..8b44da85 100644 --- a/src/main/java/com/romraider/maps/TableSwitch.java +++ b/src/main/java/com/romraider/maps/TableSwitch.java @@ -33,7 +33,9 @@ import java.awt.GridLayout; import java.awt.Insets; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; @@ -157,6 +159,11 @@ public class TableSwitch extends Table { super.setName(name); } + @Override + public int getType() { + return Settings.TABLE_SWITCH; + } + @Override public void setDescription(String description) { super.setDescription(description); @@ -208,6 +215,14 @@ public class TableSwitch extends Table { return new Dimension(width, height); } + public ButtonGroup getButtonGroup() { + return this.buttonGroup; + } + + public Map getSwitchStates() { + return this.switchStates; + } + @Override 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 keys = new HashSet(this.getSwitchStates().keySet()); + Set otherKeys = new HashSet(otherTable.getSwitchStates().keySet()); + + if(keys.size() != otherKeys.size()) { + return false; + } + + if(!keys.containsAll(otherKeys)) { + return false; + } + + // Compare Map Values. + Set values = new HashSet(this.getSwitchStates().values()); + Set otherValues = new HashSet(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 keys = new HashSet(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 private static JRadioButton getSelectedButton(ButtonGroup group) { for (Enumeration e = group.getElements(); e.hasMoreElements(); ) { diff --git a/src/main/java/com/romraider/swing/TableMenuBar.java b/src/main/java/com/romraider/swing/TableMenuBar.java index 0ddb095e..d5b80fd2 100644 --- a/src/main/java/com/romraider/swing/TableMenuBar.java +++ b/src/main/java/com/romraider/swing/TableMenuBar.java @@ -80,6 +80,7 @@ public class TableMenuBar extends JMenuBar implements ActionListener { initFileMenu(); initEditMenu(); initViewMenu(); + applyTableTypeRules(); } 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() { similarOpenTables.removeAll(); String currentTableName = table.getName();