]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/MediaSelectionTableModel.java
Version 19, May 2018
[GpsPrune.git] / tim / prune / correlate / MediaSelectionTableModel.java
1 package tim.prune.correlate;
2
3 import java.util.ArrayList;
4 import java.util.TimeZone;
5
6 import javax.swing.table.AbstractTableModel;
7 import tim.prune.I18nManager;
8 import tim.prune.config.TimezoneHelper;
9 import tim.prune.data.MediaObject;
10
11
12 /**
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
15  */
16 public class MediaSelectionTableModel extends AbstractTableModel
17 {
18         /** Text for first column heading */
19         private String _firstColumnHeading = null;
20         /** Text for last column heading */
21         private String _lastColumnHeading = null;
22         /** List of rows */
23         private ArrayList<MediaSelectionTableRow> _list = new ArrayList<MediaSelectionTableRow>();
24         /** Current timezone */
25         private TimeZone _timezone = null;
26
27
28         /**
29          * Constructor
30          * @param inFirstColumnKey key for first column heading
31          * @param inLastColumnKey key for last column heading
32          */
33         public MediaSelectionTableModel(String inFirstColumnKey, String inLastColumnKey)
34         {
35                 _firstColumnHeading = I18nManager.getText(inFirstColumnKey);
36                 _lastColumnHeading = I18nManager.getText(inLastColumnKey);
37                 _timezone = TimezoneHelper.getSelectedTimezone();
38         }
39
40         /**
41          * @return the column count, always 4
42          */
43         public int getColumnCount() {
44                 return 4;
45         }
46
47         /**
48          * Get the name of the column
49          * @param inColNum column number
50          * @return column name
51          */
52         public String getColumnName(int inColNum)
53         {
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;
58         }
59
60
61         /**
62          * @return the row count
63          */
64         public int getRowCount()
65         {
66                 return _list.size();
67         }
68
69
70         /**
71          * Get the selected row from the table
72          * @param inRowIndex row index
73          * @return table row object
74          */
75         public MediaSelectionTableRow getRow(int inRowIndex)
76         {
77                 return _list.get(inRowIndex);
78         }
79
80
81         /**
82          * Get the value of the specified cell
83          * @param inRowIndex row index
84          * @param inColumnIndex column index
85          * @return value of specified cell
86          */
87         public Object getValueAt(int inRowIndex, int inColumnIndex)
88         {
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) : "");
95                 }
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"));
99         }
100
101
102         /**
103          * Clear the list
104          */
105         public void reset() {
106                 _list.clear();
107         }
108
109         /**
110          * Add a media object to the list
111          * @param inMedia item to add
112          * @param inTimeDiff time difference
113          */
114         public void addMedia(MediaObject inMedia, long inTimeDiff)
115         {
116                 _list.add(new MediaSelectionTableRow(inMedia, inTimeDiff));
117         }
118 }