1 package tim.prune.correlate;
3 import java.util.ArrayList;
4 import java.util.TimeZone;
6 import javax.swing.table.AbstractTableModel;
7 import tim.prune.I18nManager;
8 import tim.prune.config.TimezoneHelper;
9 import tim.prune.data.MediaObject;
13 * Class to act as the table model for the selection table in the correlation functions.
14 * Can be used by both photo correlation and audio correlation
16 public class MediaSelectionTableModel extends AbstractTableModel
18 /** Text for first column heading */
19 private String _firstColumnHeading = null;
20 /** Text for last column heading */
21 private String _lastColumnHeading = null;
23 private ArrayList<MediaSelectionTableRow> _list = new ArrayList<MediaSelectionTableRow>();
24 /** Current timezone */
25 private TimeZone _timezone = null;
30 * @param inFirstColumnKey key for first column heading
31 * @param inLastColumnKey key for last column heading
33 public MediaSelectionTableModel(String inFirstColumnKey, String inLastColumnKey)
35 _firstColumnHeading = I18nManager.getText(inFirstColumnKey);
36 _lastColumnHeading = I18nManager.getText(inLastColumnKey);
37 _timezone = TimezoneHelper.getSelectedTimezone();
41 * @return the column count, always 4
43 public int getColumnCount() {
48 * Get the name of the column
49 * @param inColNum column number
52 public String getColumnName(int inColNum)
54 if (inColNum == 0) return _firstColumnHeading;
55 else if (inColNum == 1) return I18nManager.getText("fieldname.timestamp");
56 else if (inColNum == 2) return I18nManager.getText("dialog.correlate.select.timediff");
57 return _lastColumnHeading;
62 * @return the row count
64 public int getRowCount()
71 * Get the selected row from the table
72 * @param inRowIndex row index
73 * @return table row object
75 public MediaSelectionTableRow getRow(int inRowIndex)
77 return _list.get(inRowIndex);
82 * Get the value of the specified cell
83 * @param inRowIndex row index
84 * @param inColumnIndex column index
85 * @return value of specified cell
87 public Object getValueAt(int inRowIndex, int inColumnIndex)
89 // MAYBE: only show time of photos (not date) if dates all identical
90 MediaSelectionTableRow row = _list.get(inRowIndex);
91 if (inColumnIndex == 0) return row.getMedia().getName();
92 else if (inColumnIndex == 1) {
93 return (row.getMedia().hasTimestamp() ?
94 row.getMedia().getTimestamp().getText(_timezone) : "");
96 else if (inColumnIndex == 2) return row.getTimeDiff().getDescription();
97 return (row.getTimeDiff().getIsPositive() ? I18nManager.getText("dialog.about.yes") :
98 I18nManager.getText("dialog.about.no"));
105 public void reset() {
110 * Add a media object to the list
111 * @param inMedia item to add
112 * @param inTimeDiff time difference
114 public void addMedia(MediaObject inMedia, long inTimeDiff)
116 _list.add(new MediaSelectionTableRow(inMedia, inTimeDiff));