Data Table Model code refactor
This commit is contained in:
@@ -21,6 +21,53 @@ public class DataTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getColumnNames() {
|
||||||
|
return columnNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Data[][] getRowData() {
|
||||||
|
return rowData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColumnNames(String[] columnNames) {
|
||||||
|
this.columnNames = columnNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int column) {
|
||||||
|
return columnNames[column];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return rowData.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columnNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int row, int col) {
|
||||||
|
return rowData[row][col];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int row, int column) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setValueAt(Object value, int row, int col) {
|
||||||
|
rowData[row][col] = new Data(value.toString());
|
||||||
|
fireTableCellUpdated(row, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Menu action functions:
|
||||||
|
*/
|
||||||
|
|
||||||
public void addRow(int newRowPos) {
|
public void addRow(int newRowPos) {
|
||||||
int newRowCount = getRowCount() + 1;
|
int newRowCount = getRowCount() + 1;
|
||||||
Data[][] newRowData = new Data[newRowCount][getColumnCount()];
|
Data[][] newRowData = new Data[newRowCount][getColumnCount()];
|
||||||
@@ -137,7 +184,7 @@ public class DataTableModel extends AbstractTableModel {
|
|||||||
// Go through all cells in table
|
// Go through all cells in table
|
||||||
for (int row = 0; row < getRowCount(); row++) {
|
for (int row = 0; row < getRowCount(); row++) {
|
||||||
for (int col = 0; col < getColumnCount(); col++) {
|
for (int col = 0; col < getColumnCount(); col++) {
|
||||||
Data cell = rowData[row][col];
|
Data cell = rowData[row][col];
|
||||||
// 1) Check if cell contains target tree
|
// 1) Check if cell contains target tree
|
||||||
// 2) Compare tree output with max, save if higher
|
// 2) Compare tree output with max, save if higher
|
||||||
if (cell.getTree().equals(treeName) && cell.getHarvest() > maxHarvest) {
|
if (cell.getTree().equals(treeName) && cell.getHarvest() > maxHarvest) {
|
||||||
@@ -172,47 +219,4 @@ public class DataTableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
return harvest;
|
return harvest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getColumnNames() {
|
|
||||||
return columnNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Data[][] getRowData() {
|
|
||||||
return rowData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumnNames(String[] columnNames) {
|
|
||||||
this.columnNames = columnNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getColumnName(int column) {
|
|
||||||
return columnNames[column];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRowCount() {
|
|
||||||
return rowData.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return columnNames.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getValueAt(int row, int col) {
|
|
||||||
return rowData[row][col];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCellEditable(int row, int column) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setValueAt(Object value, int row, int col) {
|
|
||||||
rowData[row][col] = new Data(value.toString());
|
|
||||||
fireTableCellUpdated(row, col);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user