]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/save/PhotoTableModel.java
fd66590d1c3a6d6429993ac1f44f07a3b36ebba3
[GpsPrune.git] / tim / prune / save / PhotoTableModel.java
1 package tim.prune.save;
2
3 import javax.swing.table.AbstractTableModel;
4
5 import tim.prune.I18nManager;
6
7 /**
8  * Class to hold table model information for save exif dialog
9  */
10 public class PhotoTableModel extends AbstractTableModel
11 {
12         private PhotoTableEntry[] _photos = null;
13         private int _addIndex = 0;
14
15
16         /**
17          * Constructor giving list size
18          */
19         public PhotoTableModel(int inSize)
20         {
21                 _photos = new PhotoTableEntry[inSize];
22         }
23
24
25         /**
26          * Set the given PhotoTableEntry object in the array
27          * @param inEntry PhotoTableEntry object describing the photo
28          */
29         public void addPhotoInfo(PhotoTableEntry inEntry)
30         {
31                 if (_addIndex < _photos.length && inEntry != null
32                         && inEntry.getStatus() != null)
33                 {
34                         _photos[_addIndex] = inEntry;
35                         _addIndex++;
36                 }
37         }
38
39         /**
40          * @return the number of photos in the list whose status has changed
41          */
42         public int getNumSaveablePhotos()
43         {
44                 return _addIndex;
45         }
46
47         /**
48          * @see javax.swing.table.TableModel#getColumnCount()
49          */
50         public int getColumnCount()
51         {
52                 return 3;
53         }
54
55
56         /**
57          * @see javax.swing.table.TableModel#getRowCount()
58          */
59         public int getRowCount()
60         {
61                 return _addIndex;
62         }
63
64
65         /**
66          * @see javax.swing.table.TableModel#getValueAt(int, int)
67          */
68         public Object getValueAt(int inRowIndex, int inColumnIndex)
69         {
70                 if (inColumnIndex == 0)
71                 {
72                         return _photos[inRowIndex].getName();
73                 }
74                 else if (inColumnIndex == 1)
75                 {
76                         return _photos[inRowIndex].getStatus();
77                 }
78                 return new Boolean(_photos[inRowIndex].getSaveFlag());
79         }
80
81
82         /**
83          * @return true if cell is editable
84          */
85         public boolean isCellEditable(int inRowIndex, int inColumnIndex)
86         {
87                 // only the save column is editable
88                 return inColumnIndex == 2;
89         }
90
91
92         /**
93          * Set the given cell value
94          * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
95          */
96         public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
97         {
98                 // ignore edits to other columns
99                 if (inColumnIndex == 2)
100                         _photos[inRowIndex].setSaveFlag(((Boolean) inValue).booleanValue());
101         }
102
103
104         /**
105          * @return Class of cell data
106          */
107         public Class getColumnClass(int inColumnIndex)
108         {
109                 if (inColumnIndex < 2) return String.class;
110                 return Boolean.class;
111         }
112
113
114         /**
115          * Get the name of the column
116          */
117         public String getColumnName(int inColNum)
118         {
119                 if (inColNum == 0) return I18nManager.getText("dialog.saveexif.table.photoname");
120                 else if (inColNum == 1) return I18nManager.getText("dialog.saveexif.table.status");
121                 return I18nManager.getText("dialog.saveexif.table.save");
122         }
123
124
125         /**
126          * Retrieve the object at the given index
127          * @param inIndex index, starting at 0
128          * @return PhotoTableEntry object at this position
129          */
130         public PhotoTableEntry getPhotoTableEntry(int inIndex)
131         {
132                 if (inIndex < 0 || inIndex >= _photos.length)
133                 {
134                         return null;
135                 }
136                 return _photos[inIndex];
137         }
138 }