]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/save/FieldSelectionTableModel.java
92fda1e540ff1eb84d17db2ae7dce425bb29a3d7
[GpsPrune.git] / tim / prune / save / FieldSelectionTableModel.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 dialog
9  */
10 public class FieldSelectionTableModel extends AbstractTableModel
11 {
12         private FieldInfo[] _info = null;
13
14
15         /**
16          * Constructor giving list size
17          */
18         public FieldSelectionTableModel(int inSize)
19         {
20                 _info = new FieldInfo[inSize];
21         }
22
23
24         /**
25          * Set the given FieldInfo object in the array
26          * @param inInfo FieldInfo object describing the field
27          * @param inIndex index to place in array
28          */
29         public void addFieldInfo(FieldInfo inInfo, int inIndex)
30         {
31                 _info[inIndex] = inInfo;
32         }
33
34
35         /**
36          * @see javax.swing.table.TableModel#getColumnCount()
37          */
38         public int getColumnCount()
39         {
40                 return 3;
41         }
42
43
44         /**
45          * @see javax.swing.table.TableModel#getRowCount()
46          */
47         public int getRowCount()
48         {
49                 return _info.length;
50         }
51
52
53         /**
54          * @see javax.swing.table.TableModel#getValueAt(int, int)
55          */
56         public Object getValueAt(int inRowIndex, int inColumnIndex)
57         {
58                 if (inColumnIndex == 0)
59                 {
60                         return _info[inRowIndex].getField().getName();
61                 }
62                 else if (inColumnIndex == 1)
63                 {
64                         return new Boolean(_info[inRowIndex].hasData());
65                 }
66                 return new Boolean(_info[inRowIndex].isSelected());
67         }
68
69
70         /**
71          * @return true if cell is editable
72          */
73         public boolean isCellEditable(int inRowIndex, int inColumnIndex)
74         {
75                 // only the select column is editable
76                 return inColumnIndex == 2;
77         }
78
79
80         /**
81          * Set the given cell value
82          * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
83          */
84         public void setValueAt(Object inValue, int inRowIndex, int inColumnIndex)
85         {
86                 // ignore edits to other columns
87                 if (inColumnIndex == 2)
88                         _info[inRowIndex].setSelected(((Boolean) inValue).booleanValue());
89         }
90
91
92         /**
93          * Swap the specified items in the array
94          * @param inIndex1 first index
95          * @param inIndex2 second index
96          */
97         public void swapItems(int inIndex1, int inIndex2)
98         {
99                 if (inIndex1 >= 0 && inIndex1 < _info.length && inIndex2 >= 0 && inIndex2 < _info.length)
100                 {
101                         FieldInfo temp = _info[inIndex1];
102                         _info[inIndex1] = _info[inIndex2];
103                         _info[inIndex2] = temp;
104                 }
105         }
106
107
108         /**
109          * @return Class of cell data
110          */
111         public Class getColumnClass(int inColumnIndex)
112         {
113                 if (inColumnIndex==0) return String.class;
114                 return Boolean.class;
115         }
116
117
118         /**
119          * Get the name of the column
120          */
121         public String getColumnName(int inColNum)
122         {
123                 if (inColNum == 0) return I18nManager.getText("dialog.save.table.field");
124                 else if (inColNum == 1) return I18nManager.getText("dialog.save.table.hasdata");
125                 return I18nManager.getText("dialog.save.table.save");
126         }
127
128
129         /**
130          * Retrieve the FieldInfo object at the given index
131          * @param inIndex index, starting at 0
132          * @return FieldInfo object at this position
133          */
134         public FieldInfo getFieldInfo(int inIndex)
135         {
136                 if (inIndex < 0 || inIndex >= _info.length)
137                 {
138                         return null;
139                 }
140                 return _info[inIndex];
141         }
142 }