1 package tim.prune.correlate;
3 import java.text.NumberFormat;
4 import java.util.ArrayList;
5 import javax.swing.table.AbstractTableModel;
6 import tim.prune.I18nManager;
7 import tim.prune.data.Distance;
10 * Class to act as table model for the photo preview table
12 public class PhotoPreviewTableModel extends AbstractTableModel
14 /** ArrayList containing TableRow objects */
15 private ArrayList _list = new ArrayList();
17 private int _distanceUnits = Distance.UNITS_KILOMETRES;
18 /** Number formatter */
19 private static final NumberFormat FORMAT_ONE_DP = NumberFormat.getNumberInstance();
22 /** Static block to initialise the one d.p. formatter */
25 FORMAT_ONE_DP.setMaximumFractionDigits(1);
26 FORMAT_ONE_DP.setMinimumFractionDigits(1);
31 * @return the column count, always 5
33 public int getColumnCount()
40 * Get the name of the column
41 * @param inColNum column number
44 public String getColumnName(int inColNum)
46 if (inColNum == 0) return I18nManager.getText("dialog.correlate.photoselect.photoname");
47 else if (inColNum == 1) return I18nManager.getText("fieldname.timestamp");
48 else if (inColNum == 2) return I18nManager.getText("dialog.correlate.photoselect.timediff");
49 else if (inColNum == 3) return I18nManager.getText("fieldname.distance");
50 return I18nManager.getText("dialog.correlate.options.correlate");
55 * @return the row count
57 public int getRowCount()
64 * Get the selected row from the table
65 * @param inRowIndex row index
66 * @return table row object
68 public PhotoPreviewTableRow getRow(int inRowIndex)
70 PhotoPreviewTableRow row = (PhotoPreviewTableRow) _list.get(inRowIndex);
76 * Get the value of the specified cell
77 * @param inRowIndex row index
78 * @param inColumnIndex column index
79 * @return value of specified cell
81 public Object getValueAt(int inRowIndex, int inColumnIndex)
83 PhotoPreviewTableRow row = (PhotoPreviewTableRow) _list.get(inRowIndex);
84 if (inColumnIndex == 0) return row.getPhoto().getFile().getName();
85 else if (inColumnIndex == 1) {
86 return row.getPhoto().getTimestamp().getText();
88 else if (inColumnIndex == 2) {
89 if (row.getPointPair().isValid()) {
90 return row.getTimeDiff().getDescription();
94 else if (inColumnIndex == 3) {
95 if (row.getPointPair().isValid()) {
96 return FORMAT_ONE_DP.format(row.getDistance(_distanceUnits));
100 return row.getCorrelateFlag();
105 * @param inUnits the distance units to use
107 public void setDistanceUnits(int inUnits)
109 _distanceUnits = inUnits;
123 * Add a photo to the list
124 * @param inRow row to add
126 public void addPhotoRow(PhotoPreviewTableRow inRow)
133 * Get the class of objects in the given column
134 * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
136 public Class getColumnClass(int inColumnIndex)
138 if (inColumnIndex == 4) {return Boolean.class;}
139 return super.getColumnClass(inColumnIndex);
144 * Get whether the given cell is editable
145 * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
147 public boolean isCellEditable(int inRowIndex, int inColumnIndex)
149 if (inColumnIndex == 4) {return true;}
150 return super.isCellEditable(inRowIndex, inColumnIndex);
155 * @return true if any of the correlate flags are on
157 public boolean hasPhotosSelected()
159 for (int i=0; i<getRowCount(); i++)
161 if (getRow(i).getCorrelateFlag().booleanValue())
172 * Set the value at the given table cell
173 * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
175 public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
177 // can only edit the correlate column
178 if (inColumnIndex == 4)
180 PhotoPreviewTableRow row = getRow(inRowIndex);
181 // Don't allow setting of photos which can't be correlated
182 if (row.getPointPair().isValid())
184 row.setCorrelateFlag(((Boolean) inValue).booleanValue());