Refactoring: TableType enum & reducing code complexity

This commit is contained in:
rusefi 2018-12-22 23:10:14 -05:00
parent 40af0dd981
commit 94ce1e8a9c
12 changed files with 143 additions and 119 deletions

View File

@ -93,13 +93,6 @@ public class Settings implements Serializable {
public static final int ENDIAN_LITTLE = 1; public static final int ENDIAN_LITTLE = 1;
public static final int ENDIAN_BIG = 2; public static final int ENDIAN_BIG = 2;
public static final int TABLE_1D = 1;
public static final int TABLE_2D = 2;
public static final int TABLE_3D = 3;
public static final int TABLE_X_AXIS = 4;
public static final int TABLE_Y_AXIS = 5;
public static final int TABLE_SWITCH = 6;
public enum DataType { public enum DataType {
ORIGINAL, ORIGINAL,
BIN BIN

View File

@ -67,7 +67,6 @@ public abstract class Table extends JPanel implements Serializable {
protected static int memModelEndian; protected static int memModelEndian;
protected String name; protected String name;
protected int type;
protected String category = "Other"; protected String category = "Other";
protected String description = Settings.BLANK; protected String description = Settings.BLANK;
protected Vector<Scale> scales = new Vector<Scale>(); protected Vector<Scale> scales = new Vector<Scale>();
@ -123,7 +122,7 @@ public abstract class Table extends JPanel implements Serializable {
private Table compareTable = null; private Table compareTable = null;
public Table() { protected Table() {
scales.clear(); scales.clear();
this.setLayout(borderLayout); this.setLayout(borderLayout);
@ -548,18 +547,12 @@ public abstract class Table extends JPanel implements Serializable {
calcCellRanges(); calcCellRanges();
} }
public int getType() { public abstract TableType getType();
return type;
}
public DataCell getDataCell(int location) { public DataCell getDataCell(int location) {
return data[location]; return data[location];
} }
public void setType(int type) {
this.type = type;
}
@Override @Override
public String getName() { public String getName() {
if(null == name || name.isEmpty()) { if(null == name || name.isEmpty()) {
@ -1256,7 +1249,7 @@ public abstract class Table extends JPanel implements Serializable {
} }
public void validateScaling() { public void validateScaling() {
if (type != Settings.TABLE_SWITCH) { if (getType() != TableType.SWITCH) {
// make sure a scale is present // make sure a scale is present
if (scales.isEmpty()) { if (scales.isEmpty()) {
@ -1521,6 +1514,38 @@ public abstract class Table extends JPanel implements Serializable {
public int getMemModelEndian() { public int getMemModelEndian() {
return memModelEndian; return memModelEndian;
} }
public enum TableType {
TABLE_1D(1),
TABLE_2D(2),
TABLE_3D(3),
X_AXIS(4),
Y_AXIS(5),
SWITCH(6);
private final int marshallingCode;
TableType(int marshallingCode) {
this.marshallingCode = marshallingCode;
}
public int getDimension() {
switch (this) {
case TABLE_1D:
return 1;
case TABLE_2D:
return 2;
case TABLE_3D:
return 3;
default:
return -1;
}
}
public String getMarshallingString() {
return String.valueOf(marshallingCode);
}
}
} }
class CopySelectionWorker extends SwingWorker<Void, Void> { class CopySelectionWorker extends SwingWorker<Void, Void> {

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2017 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,8 +28,15 @@ import com.romraider.util.NumberUtil;
public class Table1D extends Table { public class Table1D extends Table {
private static final long serialVersionUID = -8747180767803835631L; private static final long serialVersionUID = -8747180767803835631L;
private Table axisParent = null; private Table axisParent = null;
private final TableType type;
public Table1D() { public Table1D(TableType type) {
this.type = type;
}
@Override
public TableType getType() {
return type;
} }
public void setAxisParent(Table axisParent) { public void setAxisParent(Table axisParent) {
@ -81,50 +88,50 @@ public class Table1D extends Table {
@Override @Override
public void cursorUp() { public void cursorUp() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
if (highlightY > 0 && data[highlightY].isSelected()) { if (highlightY > 0 && data[highlightY].isSelected()) {
selectCellAt(highlightY - 1); selectCellAt(highlightY - 1);
} }
} else if (type == Settings.TABLE_X_AXIS) { } else if (type == Table.TableType.X_AXIS) {
// Y axis is on top.. nothing happens // Y axis is on top.. nothing happens
} else if (type == Settings.TABLE_1D) { } else if (type == Table.TableType.TABLE_1D) {
// no where to move up to // no where to move up to
} }
} }
@Override @Override
public void cursorDown() { public void cursorDown() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
if (getAxisParent().getType() == Settings.TABLE_3D) { if (getAxisParent().getType() == Table.TableType.TABLE_3D) {
if (highlightY < getDataSize() - 1 && data[highlightY].isSelected()) { if (highlightY < getDataSize() - 1 && data[highlightY].isSelected()) {
selectCellAt(highlightY + 1); selectCellAt(highlightY + 1);
} }
} else if (getAxisParent().getType() == Settings.TABLE_2D) { } else if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
if (data[highlightY].isSelected()) { if (data[highlightY].isSelected()) {
getAxisParent().selectCellAt(highlightY); getAxisParent().selectCellAt(highlightY);
} }
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
((Table3D) getAxisParent()).selectCellAt(highlightY, this); ((Table3D) getAxisParent()).selectCellAt(highlightY, this);
} else if (type == Settings.TABLE_1D) { } else if (type == Table.TableType.TABLE_1D) {
// no where to move down to // no where to move down to
} }
} }
@Override @Override
public void cursorLeft() { public void cursorLeft() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
// X axis is on left.. nothing happens // X axis is on left.. nothing happens
if (getAxisParent().getType() == Settings.TABLE_2D) { if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
if (data[highlightY].isSelected()) { if (data[highlightY].isSelected()) {
selectCellAt(highlightY - 1); selectCellAt(highlightY - 1);
} }
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
if (highlightY > 0) { if (highlightY > 0) {
selectCellAt(highlightY - 1); selectCellAt(highlightY - 1);
} }
} else if (type == Settings.TABLE_1D && data[highlightY].isSelected()) { } else if (type == Table.TableType.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY > 0) { if (highlightY > 0) {
selectCellAt(highlightY - 1); selectCellAt(highlightY - 1);
} }
@ -133,17 +140,17 @@ public class Table1D extends Table {
@Override @Override
public void cursorRight() { public void cursorRight() {
if (type == Settings.TABLE_Y_AXIS && data[highlightY].isSelected()) { if (type == Table.TableType.Y_AXIS && data[highlightY].isSelected()) {
if (getAxisParent().getType() == Settings.TABLE_3D) { if (getAxisParent().getType() == Table.TableType.TABLE_3D) {
((Table3D) getAxisParent()).selectCellAt(highlightY, this); ((Table3D) getAxisParent()).selectCellAt(highlightY, this);
} else if (getAxisParent().getType() == Settings.TABLE_2D) { } else if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
selectCellAt(highlightY + 1); selectCellAt(highlightY + 1);
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) { if (highlightY < getDataSize() - 1) {
selectCellAt(highlightY + 1); selectCellAt(highlightY + 1);
} }
} else if (type == Settings.TABLE_1D && data[highlightY].isSelected()) { } else if (type == Table.TableType.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) { if (highlightY < getDataSize() - 1) {
selectCellAt(highlightY + 1); selectCellAt(highlightY + 1);
} }
@ -152,50 +159,50 @@ public class Table1D extends Table {
@Override @Override
public void shiftCursorUp() { public void shiftCursorUp() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
if (highlightY > 0 && data[highlightY].isSelected()) { if (highlightY > 0 && data[highlightY].isSelected()) {
selectCellAtWithoutClear(highlightY - 1); selectCellAtWithoutClear(highlightY - 1);
} }
} else if (type == Settings.TABLE_X_AXIS) { } else if (type == Table.TableType.X_AXIS) {
// Y axis is on top.. nothing happens // Y axis is on top.. nothing happens
} else if (type == Settings.TABLE_1D) { } else if (type == Table.TableType.TABLE_1D) {
// no where to move up to // no where to move up to
} }
} }
@Override @Override
public void shiftCursorDown() { public void shiftCursorDown() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
if (getAxisParent().getType() == Settings.TABLE_3D) { if (getAxisParent().getType() == Table.TableType.TABLE_3D) {
if (highlightY < getDataSize() - 1 && data[highlightY].isSelected()) { if (highlightY < getDataSize() - 1 && data[highlightY].isSelected()) {
selectCellAtWithoutClear(highlightY + 1); selectCellAtWithoutClear(highlightY + 1);
} }
} else if (getAxisParent().getType() == Settings.TABLE_2D) { } else if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
if (data[highlightY].isSelected()) { if (data[highlightY].isSelected()) {
getAxisParent().selectCellAtWithoutClear(highlightY); getAxisParent().selectCellAtWithoutClear(highlightY);
} }
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
((Table3D) getAxisParent()).selectCellAt(highlightY, this); ((Table3D) getAxisParent()).selectCellAt(highlightY, this);
} else if (type == Settings.TABLE_1D) { } else if (type == Table.TableType.TABLE_1D) {
// no where to move down to // no where to move down to
} }
} }
@Override @Override
public void shiftCursorLeft() { public void shiftCursorLeft() {
if (type == Settings.TABLE_Y_AXIS) { if (type == Table.TableType.Y_AXIS) {
// X axis is on left.. nothing happens // X axis is on left.. nothing happens
if (getAxisParent().getType() == Settings.TABLE_2D) { if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
if (data[highlightY].isSelected()) { if (data[highlightY].isSelected()) {
selectCellAtWithoutClear(highlightY - 1); selectCellAtWithoutClear(highlightY - 1);
} }
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
if (highlightY > 0) { if (highlightY > 0) {
selectCellAtWithoutClear(highlightY - 1); selectCellAtWithoutClear(highlightY - 1);
} }
} else if (type == Settings.TABLE_1D && data[highlightY].isSelected()) { } else if (type == Table.TableType.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY > 0) { if (highlightY > 0) {
selectCellAtWithoutClear(highlightY - 1); selectCellAtWithoutClear(highlightY - 1);
} }
@ -204,17 +211,17 @@ public class Table1D extends Table {
@Override @Override
public void shiftCursorRight() { public void shiftCursorRight() {
if (type == Settings.TABLE_Y_AXIS && data[highlightY].isSelected()) { if (type == Table.TableType.Y_AXIS && data[highlightY].isSelected()) {
if (getAxisParent().getType() == Settings.TABLE_3D) { if (getAxisParent().getType() == Table.TableType.TABLE_3D) {
((Table3D) getAxisParent()).selectCellAt(highlightY, this); ((Table3D) getAxisParent()).selectCellAt(highlightY, this);
} else if (getAxisParent().getType() == Settings.TABLE_2D) { } else if (getAxisParent().getType() == Table.TableType.TABLE_2D) {
selectCellAtWithoutClear(highlightY + 1); selectCellAtWithoutClear(highlightY + 1);
} }
} else if (type == Settings.TABLE_X_AXIS && data[highlightY].isSelected()) { } else if (type == Table.TableType.X_AXIS && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) { if (highlightY < getDataSize() - 1) {
selectCellAtWithoutClear(highlightY + 1); selectCellAtWithoutClear(highlightY + 1);
} }
} else if (type == Settings.TABLE_1D && data[highlightY].isSelected()) { } else if (type == Table.TableType.TABLE_1D && data[highlightY].isSelected()) {
if (highlightY < getDataSize() - 1) { if (highlightY < getDataSize() - 1) {
selectCellAtWithoutClear(highlightY + 1); selectCellAtWithoutClear(highlightY + 1);
} }
@ -234,9 +241,9 @@ public class Table1D extends Table {
if(axisParent instanceof Table3D) { if(axisParent instanceof Table3D) {
Table3D table3D = (Table3D) axisParent; Table3D table3D = (Table3D) axisParent;
if(getType() == Settings.TABLE_X_AXIS) { if(getType() == Table.TableType.X_AXIS) {
table3D.getYAxis().clearSelectedData(); table3D.getYAxis().clearSelectedData();
} else if (getType() == Settings.TABLE_Y_AXIS) { } else if (getType() == Table.TableType.Y_AXIS) {
table3D.getXAxis().clearSelectedData(); table3D.getXAxis().clearSelectedData();
} }
} else if (axisParent instanceof Table2D) { } else if (axisParent instanceof Table2D) {
@ -308,8 +315,8 @@ public class Table1D extends Table {
} }
public boolean isAxis() { public boolean isAxis() {
return getType() == Settings.TABLE_X_AXIS || return getType() == Table.TableType.X_AXIS ||
getType() == Settings.TABLE_Y_AXIS || isStaticDataTable(); getType() == Table.TableType.Y_AXIS || isStaticDataTable();
} }
@Override @Override

View File

@ -44,7 +44,7 @@ import com.romraider.util.SettingsManager;
public class Table2D extends Table { public class Table2D extends Table {
private static final long serialVersionUID = -7684570967109324784L; private static final long serialVersionUID = -7684570967109324784L;
private Table1D axis = new Table1D(); private Table1D axis = new Table1D(Table.TableType.Y_AXIS);
private JLabel axisLabel; private JLabel axisLabel;
private CopyTable2DWorker copyTable2DWorker; private CopyTable2DWorker copyTable2DWorker;
@ -54,6 +54,11 @@ public class Table2D extends Table {
verticalOverhead += 18; verticalOverhead += 18;
} }
@Override
public TableType getType() {
return TableType.TABLE_2D;
}
public Table1D getAxis() { public Table1D getAxis() {
return axis; return axis;
} }

View File

@ -52,8 +52,8 @@ import com.romraider.xml.RomAttributeParser;
public class Table3D extends Table { public class Table3D extends Table {
private static final long serialVersionUID = 3103448753263606599L; private static final long serialVersionUID = 3103448753263606599L;
private Table1D xAxis = new Table1D(); private Table1D xAxis = new Table1D(TableType.X_AXIS);
private Table1D yAxis = new Table1D(); private Table1D yAxis = new Table1D(TableType.Y_AXIS);
private JLabel xAxisLabel; private JLabel xAxisLabel;
private JLabel yAxisLabel; private JLabel yAxisLabel;
@ -70,6 +70,11 @@ public class Table3D extends Table {
horizontalOverhead += 10; horizontalOverhead += 10;
} }
@Override
public TableType getType() {
return Table.TableType.TABLE_3D;
}
public Table1D getXAxis() { public Table1D getXAxis() {
return xAxis; return xAxis;
} }
@ -612,7 +617,7 @@ public class Table3D extends Table {
} }
public void selectCellAt(int y, Table1D axisType) { public void selectCellAt(int y, Table1D axisType) {
if (axisType.getType() == Settings.TABLE_Y_AXIS) { if (axisType.getType() == Table.TableType.Y_AXIS) {
selectCellAt(0, y); selectCellAt(0, y);
} else { // y axis } else { // y axis
selectCellAt(y, 0); selectCellAt(y, 0);

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2014 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -44,8 +44,6 @@ import javax.swing.JPanel;
import javax.swing.JRadioButton; import javax.swing.JRadioButton;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import com.romraider.Settings;
public class TableSwitch extends Table { public class TableSwitch extends Table {
private static final long serialVersionUID = -4887718305447362308L; private static final long serialVersionUID = -4887718305447362308L;
@ -56,7 +54,6 @@ public class TableSwitch extends Table {
public TableSwitch() { public TableSwitch() {
super(); super();
storageType = 1; storageType = 1;
type = Settings.TABLE_SWITCH;
locked = true; locked = true;
removeAll(); removeAll();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -165,8 +162,8 @@ public class TableSwitch extends Table {
} }
@Override @Override
public int getType() { public TableType getType() {
return Settings.TABLE_SWITCH; return Table.TableType.SWITCH;
} }
@Override @Override

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,7 +35,6 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import com.romraider.Settings;
import com.romraider.maps.Rom; import com.romraider.maps.Rom;
import com.romraider.maps.Table; import com.romraider.maps.Table;
@ -108,13 +107,13 @@ public class RomCellRenderer implements TreeCellRenderer {
renderer.setBackground(Color.WHITE); renderer.setBackground(Color.WHITE);
// display icon // display icon
if (table.getType() == Settings.TABLE_1D) { if (table.getType() == Table.TableType.TABLE_1D) {
tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/1d.gif")), JLabel.LEFT); tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/1d.gif")), JLabel.LEFT);
} else if (table.getType() == Settings.TABLE_2D) { } else if (table.getType() == Table.TableType.TABLE_2D) {
tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/2d.gif")), JLabel.LEFT); tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/2d.gif")), JLabel.LEFT);
} else if (table.getType() == Settings.TABLE_3D) { } else if (table.getType() == Table.TableType.TABLE_3D) {
tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/3d.gif")), JLabel.LEFT); tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/3d.gif")), JLabel.LEFT);
} else if (table.getType() == Settings.TABLE_SWITCH) { } else if (table.getType() == Table.TableType.SWITCH) {
tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/switch.gif")), JLabel.LEFT); tableName = new JLabel(table.getName() + " ", new ImageIcon(getClass().getResource("/graphics/switch.gif")), JLabel.LEFT);
} }

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,7 +26,7 @@ import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem; import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import com.romraider.Settings; import com.romraider.maps.Table;
import com.romraider.maps.Table3D; import com.romraider.maps.Table3D;
public class TableMenuBar extends JMenuBar { public class TableMenuBar extends JMenuBar {
@ -216,7 +216,7 @@ public class TableMenuBar extends JMenuBar {
private void applyTableTypeRules(TableFrame frame) { private void applyTableTypeRules(TableFrame frame) {
// Hide items that don't work with a DTC tables. // Hide items that don't work with a DTC tables.
if(frame.getTable().getType() == Settings.TABLE_SWITCH) { if(frame.getTable().getType() == Table.TableType.SWITCH) {
editMenu.setEnabled(false); editMenu.setEnabled(false);
getCompareOriginal().setEnabled(false); getCompareOriginal().setEnabled(false);
getComparePercent().setEnabled(false); getComparePercent().setEnabled(false);

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2017 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -45,7 +45,7 @@ public class TablePropertyPanel extends javax.swing.JPanel {
category.setText(table.getCategory()); category.setText(table.getCategory());
int dim; int dim;
if (Settings.TABLE_SWITCH == table.getType()) { if (Table.TableType.SWITCH == table.getType()) {
dim = 1; dim = 1;
storageSize.setText("switch"); storageSize.setText("switch");
scrollPane.setViewportView(populateScalesTable( scrollPane.setViewportView(populateScalesTable(
@ -71,7 +71,7 @@ public class TablePropertyPanel extends javax.swing.JPanel {
} }
storageSize.setText(dataType + (table.getStorageType() * 8)); storageSize.setText(dataType + (table.getStorageType() * 8));
} }
dim = table.getType(); dim = table.getType().getDimension();
scrollPane.setViewportView(populateScalesTable(table.getScales())); scrollPane.setViewportView(populateScalesTable(table.getScales()));
} }

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2017 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -329,7 +329,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
updateToolbarIncrementDecrementValues(); updateToolbarIncrementDecrementValues();
this.overlayLog.setSelected(selectedTable.getOverlayLog()); this.overlayLog.setSelected(selectedTable.getOverlayLog());
this.enable3d.setEnabled(selectedTable.getType() == Settings.TABLE_3D); this.enable3d.setEnabled(selectedTable.getType() == Table.TableType.TABLE_3D);
setScales(selectedTable.getScales()); setScales(selectedTable.getScales());
@ -406,7 +406,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
refreshCompare.setEnabled(enabled); refreshCompare.setEnabled(enabled);
//Only enable the 3d button if table includes 3d data //Only enable the 3d button if table includes 3d data
if (null != currentTable && currentTable.getType() == Settings.TABLE_3D && enabled) { if (null != currentTable && currentTable.getType() == Table.TableType.TABLE_3D && enabled) {
enable3d.setEnabled(true); enable3d.setEnabled(true);
} }
else{ else{
@ -577,7 +577,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
Vector<float[]> graphValues = new Vector<float[]>(); Vector<float[]> graphValues = new Vector<float[]>();
graphValues.clear(); graphValues.clear();
if (currentTable.getType() == Settings.TABLE_3D) { if (currentTable.getType() == Table.TableType.TABLE_3D) {
Table3D table3d = (Table3D) currentTable; Table3D table3d = (Table3D) currentTable;
DataCell[][] tableData = table3d.get3dData(); DataCell[][] tableData = table3d.get3dData();
valueCount = tableData.length; valueCount = tableData.length;
@ -758,7 +758,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
return; return;
} }
if(curTable.getType() == Settings.TABLE_3D) { if(curTable.getType() == Table.TableType.TABLE_3D) {
Table3D table3d = (Table3D) curTable; Table3D table3d = (Table3D) curTable;
table3d.selectCellAt(x, table3d.getSizeY() - z - 1); table3d.selectCellAt(x, table3d.getSizeY() - z - 1);
@ -774,7 +774,7 @@ public class TableToolBar extends JToolBar implements MouseListener, ItemListene
return; return;
} }
if(curTable.getType() == Settings.TABLE_3D) { if(curTable.getType() == Table.TableType.TABLE_3D) {
if (value) { if (value) {
Table3D table3d = (Table3D) curTable; Table3D table3d = (Table3D) curTable;
table3d.selectCellAtWithoutClear(x, table3d.getSizeY() - z - 1); table3d.selectCellAtWithoutClear(x, table3d.getSizeY() - z - 1);

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2017 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -37,7 +37,6 @@ import org.apache.log4j.Logger;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import com.romraider.Settings;
import com.romraider.editor.ecu.ECUEditorManager; import com.romraider.editor.ecu.ECUEditorManager;
import com.romraider.maps.DataCell; import com.romraider.maps.DataCell;
import com.romraider.maps.Rom; import com.romraider.maps.Rom;
@ -373,10 +372,7 @@ public final class DOMRomUnmarshaller {
} }
} }
try { if (table == null) {
if (table.getType() < 1) {
}
} catch (NullPointerException ex) { // if type is null or less than 0,
// create new instance (otherwise it // create new instance (otherwise it
// is inherited) // is inherited)
final String tn = unmarshallAttribute(tableNode, "name", "unknown"); final String tn = unmarshallAttribute(tableNode, "name", "unknown");
@ -397,20 +393,19 @@ public final class DOMRomUnmarshaller {
} else if (unmarshallAttribute(tableNode, "type", "unknown") } else if (unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("1D")) { .equalsIgnoreCase("1D")) {
table = new Table1D(); table = new Table1D(Table.TableType.TABLE_1D);
} else if (unmarshallAttribute(tableNode, "type", "unknown") } else if (unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("X Axis") .equalsIgnoreCase("X Axis")
|| unmarshallAttribute(tableNode, "type", "unknown") || unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("Y Axis")) { .equalsIgnoreCase("Static X Axis")) {
table = new Table1D(); table = new Table1D(Table.TableType.X_AXIS);
} else if (unmarshallAttribute(tableNode, "type", "unknown") } else if (unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("Static Y Axis") .equalsIgnoreCase("Y Axis")
|| unmarshallAttribute(tableNode, "type", "unknown") || unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("Static X Axis")) { .equalsIgnoreCase("Static Y Axis")) {
table = new Table1D(); table = new Table1D(Table.TableType.Y_AXIS);
} else if (unmarshallAttribute(tableNode, "type", "unknown") } else if (unmarshallAttribute(tableNode, "type", "unknown")
.equalsIgnoreCase("Switch")) { .equalsIgnoreCase("Switch")) {
table = new TableSwitch(); table = new TableSwitch();
@ -428,10 +423,7 @@ public final class DOMRomUnmarshaller {
// unmarshall table attributes // unmarshall table attributes
final String tn = unmarshallAttribute(tableNode, "name", table.getName()); final String tn = unmarshallAttribute(tableNode, "name", table.getName());
final int type = RomAttributeParser.parseTableType(unmarshallAttribute(
tableNode, "type", String.valueOf(table.getType())));
table.setName(tn); table.setName(tn);
table.setType(type);
if (unmarshallAttribute(tableNode, "beforeram", "false") if (unmarshallAttribute(tableNode, "beforeram", "false")
.equalsIgnoreCase("true")) { .equalsIgnoreCase("true")) {
table.setBeforeRam(true); table.setBeforeRam(true);
@ -479,7 +471,7 @@ public final class DOMRomUnmarshaller {
table.setLogParam(unmarshallAttribute(tableNode, "logparam", table.setLogParam(unmarshallAttribute(tableNode, "logparam",
table.getLogParam())); table.getLogParam()));
if (table.getType() == Settings.TABLE_3D) { if (table.getType() == Table.TableType.TABLE_3D) {
((Table3D) table).setSwapXY(unmarshallAttribute(tableNode, ((Table3D) table).setSwapXY(unmarshallAttribute(tableNode,
"swapxy", ((Table3D) table).getSwapXY())); "swapxy", ((Table3D) table).getSwapXY()));
((Table3D) table).setFlipX(unmarshallAttribute(tableNode, "flipx", ((Table3D) table).setFlipX(unmarshallAttribute(tableNode, "flipx",
@ -501,15 +493,15 @@ public final class DOMRomUnmarshaller {
if (n.getNodeType() == ELEMENT_NODE) { if (n.getNodeType() == ELEMENT_NODE) {
if (n.getNodeName().equalsIgnoreCase("table")) { if (n.getNodeName().equalsIgnoreCase("table")) {
if (table.getType() == Settings.TABLE_2D) { // if table is 2D, if (table.getType() == Table.TableType.TABLE_2D) { // if table is 2D,
// parse axis // parse axis
if (RomAttributeParser if (RomAttributeParser
.parseTableType(unmarshallAttribute(n, "type", .parseTableType(unmarshallAttribute(n, "type",
"unknown")) == Settings.TABLE_Y_AXIS "unknown")) == Table.TableType.Y_AXIS
|| RomAttributeParser || RomAttributeParser
.parseTableType(unmarshallAttribute(n, .parseTableType(unmarshallAttribute(n,
"type", "unknown")) == Settings.TABLE_X_AXIS) { "type", "unknown")) == Table.TableType.X_AXIS) {
Table1D tempTable = (Table1D) unmarshallTable(n, Table1D tempTable = (Table1D) unmarshallTable(n,
((Table2D) table).getAxis(), rom); ((Table2D) table).getAxis(), rom);
@ -521,13 +513,13 @@ public final class DOMRomUnmarshaller {
((Table2D) table).setAxis(tempTable); ((Table2D) table).setAxis(tempTable);
} }
} else if (table.getType() == Settings.TABLE_3D) { // if table } else if (table.getType() == Table.TableType.TABLE_3D) { // if table
// is 3D, // is 3D,
// populate // populate
// xAxis // xAxis
if (RomAttributeParser if (RomAttributeParser
.parseTableType(unmarshallAttribute(n, "type", .parseTableType(unmarshallAttribute(n, "type",
"unknown")) == Settings.TABLE_X_AXIS) { "unknown")) == Table.TableType.X_AXIS) {
Table1D tempTable = (Table1D) unmarshallTable(n, Table1D tempTable = (Table1D) unmarshallTable(n,
((Table3D) table).getXAxis(), rom); ((Table3D) table).getXAxis(), rom);
@ -542,7 +534,7 @@ public final class DOMRomUnmarshaller {
} else if (RomAttributeParser } else if (RomAttributeParser
.parseTableType(unmarshallAttribute(n, "type", .parseTableType(unmarshallAttribute(n, "type",
"unknown")) == Settings.TABLE_Y_AXIS) { "unknown")) == Table.TableType.Y_AXIS) {
Table1D tempTable = (Table1D) unmarshallTable(n, Table1D tempTable = (Table1D) unmarshallTable(n,
((Table3D) table).getYAxis(), rom); ((Table3D) table).getYAxis(), rom);

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2017 RomRaider.com * Copyright (C) 2006-2018 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,6 +26,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import com.romraider.Settings; import com.romraider.Settings;
import com.romraider.maps.Table;
public final class RomAttributeParser { public final class RomAttributeParser {
@ -96,21 +97,21 @@ public final class RomAttributeParser {
} }
} }
public static int parseTableType(String input) { public static Table.TableType parseTableType(String input) {
if (input.equalsIgnoreCase("3D") || input.equalsIgnoreCase(String.valueOf(Settings.TABLE_3D))) { if (input.equalsIgnoreCase("3D") || input.equalsIgnoreCase(Table.TableType.TABLE_3D.getMarshallingString())) {
return Settings.TABLE_3D; return Table.TableType.TABLE_3D;
} }
else if (input.equalsIgnoreCase("2D") || input.equalsIgnoreCase(String.valueOf(Settings.TABLE_2D))) { else if (input.equalsIgnoreCase("2D") || input.equalsIgnoreCase(Table.TableType.TABLE_2D.getMarshallingString())) {
return Settings.TABLE_2D; return Table.TableType.TABLE_2D;
} }
else if (input.equalsIgnoreCase("X Axis") || input.equalsIgnoreCase("Static X Axis") || input.equalsIgnoreCase(String.valueOf(Settings.TABLE_X_AXIS))) { else if (input.equalsIgnoreCase("X Axis") || input.equalsIgnoreCase("Static X Axis") || input.equalsIgnoreCase(Table.TableType.X_AXIS.getMarshallingString())) {
return Settings.TABLE_X_AXIS; return Table.TableType.X_AXIS;
} }
else if (input.equalsIgnoreCase("Y Axis") || input.equalsIgnoreCase("Static Y Axis") || input.equalsIgnoreCase(String.valueOf(Settings.TABLE_Y_AXIS))) { else if (input.equalsIgnoreCase("Y Axis") || input.equalsIgnoreCase("Static Y Axis") || input.equalsIgnoreCase(Table.TableType.Y_AXIS.getMarshallingString())) {
return Settings.TABLE_Y_AXIS; return Table.TableType.Y_AXIS;
} }
else { else {
return Settings.TABLE_1D; return Table.TableType.TABLE_1D;
} }
} }