source: josm/trunk/src/org/openstreetmap/josm/corrector/CorrectionTableModel.java @ 5241

Revision 3083, 2.1 KB checked in by bastiK, 2 years ago (diff)

added svn:eol-style=native to source files

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