1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.corrector;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import javax.swing.table.AbstractTableModel;
|
---|
10 |
|
---|
11 | public abstract class CorrectionTableModel<C extends Correction> extends AbstractTableModel {
|
---|
12 |
|
---|
13 | private transient List<C> corrections;
|
---|
14 | private boolean[] apply;
|
---|
15 | private int applyColumn;
|
---|
16 |
|
---|
17 | public CorrectionTableModel(List<C> corrections) {
|
---|
18 | this.corrections = corrections;
|
---|
19 | apply = new boolean[this.corrections.size()];
|
---|
20 | Arrays.fill(apply, true);
|
---|
21 | applyColumn = getColumnCount() - 1;
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Override
|
---|
25 | public abstract int getColumnCount();
|
---|
26 |
|
---|
27 | protected abstract boolean isBoldCell(int row, int column);
|
---|
28 |
|
---|
29 | public abstract String getCorrectionColumnName(int colIndex);
|
---|
30 |
|
---|
31 | public abstract Object getCorrectionValueAt(int rowIndex, int colIndex);
|
---|
32 |
|
---|
33 | public List<C> getCorrections() {
|
---|
34 | return corrections;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public int getApplyColumn() {
|
---|
38 | return applyColumn;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public boolean getApply(int i) {
|
---|
42 | return apply[i];
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public int getRowCount() {
|
---|
47 | return corrections.size();
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public Class<?> getColumnClass(int columnIndex) {
|
---|
52 | if (columnIndex == applyColumn)
|
---|
53 | return Boolean.class;
|
---|
54 | return String.class;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public String getColumnName(int columnIndex) {
|
---|
59 | if (columnIndex == applyColumn)
|
---|
60 | return tr("Apply?");
|
---|
61 |
|
---|
62 | return getCorrectionColumnName(columnIndex);
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public boolean isCellEditable(int rowIndex, int columnIndex) {
|
---|
67 | return columnIndex == applyColumn;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
---|
72 | if (columnIndex == applyColumn && aValue instanceof Boolean)
|
---|
73 | apply[rowIndex] = (Boolean) aValue;
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public Object getValueAt(int rowIndex, int colIndex) {
|
---|
78 | if (colIndex == applyColumn)
|
---|
79 | return apply[rowIndex];
|
---|
80 |
|
---|
81 | return getCorrectionValueAt(rowIndex, colIndex);
|
---|
82 | }
|
---|
83 | }
|
---|