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