]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/MediaSelectionTableModel.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / correlate / MediaSelectionTableModel.java
1 package tim.prune.correlate;
2
3 import java.util.ArrayList;
4 import javax.swing.table.AbstractTableModel;
5 import tim.prune.I18nManager;
6 import tim.prune.data.MediaObject;
7
8
9 /**
10  * Class to act as the table model for the selection table in the correlation functions.
11  * Can be used by both photo correlation and audio correlation
12  */
13 public class MediaSelectionTableModel extends AbstractTableModel
14 {
15         /** Text for first column heading */
16         private String _firstColumnHeading = null;
17         /** Text for last column heading */
18         private String _lastColumnHeading = null;
19         /** List of rows */
20         private ArrayList<MediaSelectionTableRow> _list = new ArrayList<MediaSelectionTableRow>();
21
22
23         /**
24          * Constructor
25          * @param inFirstColumnKey key for first column heading
26          * @param inLastColumnKey key for last column heading
27          */
28         public MediaSelectionTableModel(String inFirstColumnKey, String inLastColumnKey)
29         {
30                 _firstColumnHeading = I18nManager.getText(inFirstColumnKey);
31                 _lastColumnHeading = I18nManager.getText(inLastColumnKey);
32         }
33
34         /**
35          * @return the column count, always 4
36          */
37         public int getColumnCount() {
38                 return 4;
39         }
40
41         /**
42          * Get the name of the column
43          * @param inColNum column number
44          * @return column name
45          */
46         public String getColumnName(int inColNum)
47         {
48                 if (inColNum == 0) return _firstColumnHeading;
49                 else if (inColNum == 1) return I18nManager.getText("fieldname.timestamp");
50                 else if (inColNum == 2) return I18nManager.getText("dialog.correlate.select.timediff");
51                 return _lastColumnHeading;
52         }
53
54
55         /**
56          * @return the row count
57          */
58         public int getRowCount()
59         {
60                 return _list.size();
61         }
62
63
64         /**
65          * Get the selected row from the table
66          * @param inRowIndex row index
67          * @return table row object
68          */
69         public MediaSelectionTableRow getRow(int inRowIndex)
70         {
71                 return _list.get(inRowIndex);
72         }
73
74
75         /**
76          * Get the value of the specified cell
77          * @param inRowIndex row index
78          * @param inColumnIndex column index
79          * @return value of specified cell
80          */
81         public Object getValueAt(int inRowIndex, int inColumnIndex)
82         {
83                 // MAYBE: only show time of photos (not date) if dates all identical
84                 MediaSelectionTableRow row = _list.get(inRowIndex);
85                 if (inColumnIndex == 0) return row.getMedia().getName();
86                 else if (inColumnIndex == 1) {
87                         return (row.getMedia().hasTimestamp() ? row.getMedia().getTimestamp().getText() : "");
88                 }
89                 else if (inColumnIndex == 2) return row.getTimeDiff().getDescription();
90                 return (row.getTimeDiff().getIsPositive() ? I18nManager.getText("dialog.about.yes") :
91                         I18nManager.getText("dialog.about.no"));
92         }
93
94
95         /**
96          * Clear the list
97          */
98         public void reset() {
99                 _list.clear();
100         }
101
102         /**
103          * Add a media object to the list
104          * @param inMedia item to add
105          * @param inTimeDiff time difference
106          */
107         public void addMedia(MediaObject inMedia, long inTimeDiff)
108         {
109                 _list.add(new MediaSelectionTableRow(inMedia, inTimeDiff));
110         }
111 }