source: josm/trunk/src/org/openstreetmap/josm/gui/history/DiffTableModel.java@ 8465

Last change on this file since 8465 was 8308, checked in by Don-vip, 9 years ago

fix potential NPEs and Sonar issues related to serialization

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.util.ArrayList;
5import java.util.List;
6
7import javax.swing.table.AbstractTableModel;
8
9import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType;
10
11/**
12 * Simple model storing "diff cells" in a list. Could probably have
13 * used a {@link javax.swing.table.DefaultTableModel} instead.
14 */
15class DiffTableModel extends AbstractTableModel {
16 private transient List<TwoColumnDiff.Item> rows = new ArrayList<>();
17 private boolean reversed = false;
18
19 public void setRows(List<TwoColumnDiff.Item> rows, boolean reversed) {
20 this.rows = rows;
21 this.reversed = reversed;
22 fireTableDataChanged();
23 }
24 @Override
25 public int getRowCount() {
26 return rows.size();
27 }
28
29 @Override
30 public int getColumnCount() {
31 return 1;
32 }
33
34 public boolean isReversed() {
35 return reversed;
36 }
37
38 @Override
39 public TwoColumnDiff.Item getValueAt(int rowIndex, int columnIndex) {
40 return rows.get(rowIndex);
41 }
42
43 public int getFirstChange() {
44 for (int i=0; i<rows.size(); i++) {
45 if (rows.get(i).state != DiffItemType.SAME)
46 return i;
47 }
48 return -1;
49 }
50}
Note: See TracBrowser for help on using the repository browser.