TableurModel.java
5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package osp.utils;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import osp.SkyObject;
public class TableurModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private int NB_COL=9; // Come from MainFrame
/** Required columns in tab :
* "Selected - Num obj(proj) - Id obj(when imported) - IsRef - Priority -catalog from - Affected Slit - Ra - Dec -
* others columns are optionnals
* */
private String[] colType =
{ "int", "String", "boolean", "String", "String", "String", "String", "String", "String" };
private int valMaxCol=Integer.MAX_VALUE;
private int[] colSize = {45, valMaxCol, 40, 55, 45, 40, valMaxCol, valMaxCol, valMaxCol};
private String colString[] = {"num", "IdOb", "IsRef", "Priority", "Slit", " Cat", "RA", "DEC", " " };
private boolean[] colEditable = { false, false, true, true, false,
false, false, false, false};
public int num, id, ref,ra,dec, prior, slit, nbcat;
private ArrayList<String> colList;
private Object[][] donnees;
// private OSPE_VisuPanel vPanel;
/**
* Constructor
*/
public TableurModel() {
attributeNumCol();
Object[][] objectsData = new Object[0][NB_COL];
fillTableModelPerso(objectsData);
}
/** Test Constructor
*
* @param visuPanel
* @param colString2
* @param colEditable2
* @param colType2
*/
// public TableurModel(OSPE_VisuPanel visuPanel, String[] colString2, boolean[] colEditable2,
public TableurModel(String[] colString2, boolean[] colEditable2,String[] colType2) {
// TODO Auto-generated constructor stub
Object[][] objectsData = new Object[0][NB_COL];
fillTableModelPerso(objectsData);
}
public void fillTableModelPerso(Object[][] data) {
donnees = new Object[data.length][NB_COL];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < NB_COL; j++) {
donnees[i][j] = data[i][j];
}
}
}
@Override
public boolean isCellEditable(int row, int col) {
return colEditable[col];
}
@Override
public int getColumnCount() {
return (NB_COL);
}
@Override
public Object getValueAt(int parm1, int parm2) {
return donnees[parm1][parm2];
}
@Override
public int getRowCount() {
return donnees.length;
}
@Override
public String getColumnName(int col) {
return colString[col];
}
public Object[][] getDonnees() {
return donnees;
}
@Override
public void setValueAt(Object value, int row, int col) {
if (value != null) {
if (value.getClass() != getColumnClass(col))
donnees[row][col] = null;
else
donnees[row][col] = value;
}
fireTableDataChanged();
}
public void clear() {
for (int i = 0; i < colString.length; i++)
donnees[i] = null;
fireTableDataChanged();
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Class getColumnClass(int columnIndex) {
Object valueAt = getValueAt(0, columnIndex);
if (valueAt == null)
return String.class;
else
return valueAt.getClass();
}
/** Not used for the moment
* Get the column type
* @param col : column number.
* @return column type
*/
public Object getTypecol(int col) {
return colSize[col];
}
/** Not used for the moment
* Get the column size
* @param col : column number.
* @return column size
*/
public int getSizecol(int col) {
return colSize[col];
}
/**
* Not used for the moment - data are filled in visu.
* == Ne sert pas pour le moment.
* Les donnees sont remplies ds visu - getObjectProp()
* ce qui n'est pas top. A revoir.
* @param objectlist
*/
public void setnewData(List<SkyObject> objectlist)
{
Object[][] data = new Object[][]{};
int nb_Object;
if (objectlist != null)
{
//priority = projectControler.getImageControler().getCurrentImage().getPriorityChoose();
nb_Object = objectlist.size();
data = new Object[nb_Object][NB_COL];
for (int i = 0; i < objectlist.size() && nb_Object > 0; i++)
{
SkyObject object = objectlist.get(i);
//SkyObject skObj= image.getObject(i);
// if (priority == 0 || objectModel.getPriority() == priority)
// {
for (int j = 0; j < NB_COL; j++) {
if (j == 0)
data[i][j] = object.getNum();
else if (j == 1)
data[i][j] = object.isRef();
else if (j == 2)
data[i][j] = object.getObjWorldCenter().getRA();
else if (j == 3)
data[i][j] = object.getObjWorldCenter().getDec();
else if (j == 4)
data[i][j] = object.getSrc();
else if (j == 5)
data[i][j] = String.valueOf(object.getPriority());
//}
}
}
}
this.donnees = data;
fireTableDataChanged();
}
private void attributeNumCol(){
/** Set the value column number **/
for (int i=0;i<NB_COL;i++)
{
num=0;
id=1;
nbcat=2;
ref=3;
prior=4;
slit=5;
ra=6;
dec=7;
}
}
/**
* Adjust colon size
* @return Table colon size
*/
public int[] getColSize() {
// TODO Auto-generated method stub
return colSize;
}
}