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