]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/PhotoSelectionTableModel.java
Version 7, February 2009
[GpsPrune.git] / tim / prune / correlate / PhotoSelectionTableModel.java
1 package tim.prune.correlate;
2
3 import java.util.ArrayList;
4 import javax.swing.table.AbstractTableModel;
5
6 import tim.prune.I18nManager;
7 import tim.prune.data.Photo;
8
9 /**
10  * Class to act as table model for the photo selection table
11  */
12 public class PhotoSelectionTableModel extends AbstractTableModel
13 {
14         private ArrayList<PhotoSelectionTableRow> _list = new ArrayList<PhotoSelectionTableRow>();
15
16
17         /**
18          * @return the column count, always 4
19          */
20         public int getColumnCount()
21         {
22                 return 4;
23         }
24
25
26         /**
27          * Get the name of the column
28          * @param inColNum column number
29          * @return column name
30          */
31         public String getColumnName(int inColNum)
32         {
33                 if (inColNum == 0) return I18nManager.getText("dialog.correlate.photoselect.photoname");
34                 else if (inColNum == 1) return I18nManager.getText("fieldname.timestamp");
35                 else if (inColNum == 2) return I18nManager.getText("dialog.correlate.photoselect.timediff");
36                 return I18nManager.getText("dialog.correlate.photoselect.photolater");
37         }
38
39
40         /**
41          * @return the row count
42          */
43         public int getRowCount()
44         {
45                 return _list.size();
46         }
47
48
49         /**
50          * Get the selected row from the table
51          * @param inRowIndex row index
52          * @return table row object
53          */
54         public PhotoSelectionTableRow getRow(int inRowIndex)
55         {
56                 return _list.get(inRowIndex);
57         }
58
59
60         /**
61          * Get the value of the specified cell
62          * @param inRowIndex row index
63          * @param inColumnIndex column index
64          * @return value of specified cell
65          */
66         public Object getValueAt(int inRowIndex, int inColumnIndex)
67         {
68                 // TODO: only show time of photos (not date) if dates all identical
69                 PhotoSelectionTableRow row = _list.get(inRowIndex);
70                 if (inColumnIndex == 0) return row.getPhoto().getFile().getName();
71                 else if (inColumnIndex == 1) return row.getPhoto().getTimestamp().getText();
72                 else if (inColumnIndex == 2) return row.getTimeDiff().getDescription();
73                 return (row.getTimeDiff().getIsPositive() ? I18nManager.getText("dialog.about.yes") :
74                         I18nManager.getText("dialog.about.no"));
75         }
76
77
78         /**
79          * Clear the list
80          */
81         public void reset()
82         {
83                 _list.clear();
84         }
85
86         /**
87          * Add a photo to the list
88          * @param inPhoto photo to add
89          * @param inTimeDiff time difference
90          */
91         public void addPhoto(Photo inPhoto, long inTimeDiff)
92         {
93                 _list.add(new PhotoSelectionTableRow(inPhoto, inTimeDiff));
94         }
95 }