source: josm/trunk/src/org/openstreetmap/josm/gui/correction/CorrectionTableModel.java@ 14037

Last change on this file since 14037 was 10153, checked in by Don-vip, 8 years ago

sonar - squid:S3038 - Abstract methods should not be redundant

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.correction;
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
11import org.openstreetmap.josm.data.correction.Correction;
12
13/**
14 * Abstract correction table model.
15 * @param <C> type of correction
16 */
17public abstract class CorrectionTableModel<C extends Correction> extends AbstractTableModel {
18
19 private final transient List<C> corrections;
20 private boolean[] apply;
21 private final int applyColumn;
22
23 /**
24 * Constructs a new {@code CorrectionTableModel}.
25 * @param corrections list of corrections
26 */
27 public CorrectionTableModel(List<C> corrections) {
28 this.corrections = corrections;
29 apply = new boolean[this.corrections.size()];
30 Arrays.fill(apply, true);
31 applyColumn = getColumnCount() - 1;
32 }
33
34 protected abstract boolean isBoldCell(int row, int column);
35
36 /**
37 * Returns the column name for columns other than "Apply".
38 * @param colIndex column index
39 * @return the translated column name for given index
40 * @see #getApplyColumn
41 */
42 public abstract String getCorrectionColumnName(int colIndex);
43
44 /**
45 * Returns the correction value at given position.
46 * @param rowIndex row index
47 * @param colIndex column index
48 * @return the correction value at given position
49 */
50 public abstract Object getCorrectionValueAt(int rowIndex, int colIndex);
51
52 /**
53 * Returns the list of corrections.
54 * @return the list of corrections
55 */
56 public List<C> getCorrections() {
57 return corrections;
58 }
59
60 /**
61 * Returns the index of the "Apply" column.
62 * @return the index of the "Apply" column
63 */
64 public int getApplyColumn() {
65 return applyColumn;
66 }
67
68 /**
69 * Returns the "Apply" flag for given index.
70 * @param i index
71 * @return the "Apply" flag for given index
72 */
73 public boolean getApply(int i) {
74 return apply[i];
75 }
76
77 @Override
78 public int getRowCount() {
79 return corrections.size();
80 }
81
82 @Override
83 public Class<?> getColumnClass(int columnIndex) {
84 if (columnIndex == applyColumn)
85 return Boolean.class;
86 return String.class;
87 }
88
89 @Override
90 public String getColumnName(int columnIndex) {
91 if (columnIndex == applyColumn)
92 return tr("Apply?");
93
94 return getCorrectionColumnName(columnIndex);
95 }
96
97 @Override
98 public boolean isCellEditable(int rowIndex, int columnIndex) {
99 return columnIndex == applyColumn;
100 }
101
102 @Override
103 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
104 if (columnIndex == applyColumn && aValue instanceof Boolean)
105 apply[rowIndex] = (Boolean) aValue;
106 }
107
108 @Override
109 public Object getValueAt(int rowIndex, int colIndex) {
110 if (colIndex == applyColumn)
111 return apply[rowIndex];
112
113 return getCorrectionValueAt(rowIndex, colIndex);
114 }
115}
Note: See TracBrowser for help on using the repository browser.