root / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FSymbolTable.java @ 10293
History | View | Annotate | Download (12.9 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-abr-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
48 |
|
49 |
import java.awt.Dimension; |
50 |
import java.awt.GridLayout; |
51 |
|
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.JScrollPane; |
54 |
import javax.swing.table.DefaultTableModel; |
55 |
import javax.swing.table.TableColumn; |
56 |
|
57 |
import com.hardcode.gdbms.engine.values.NullValue; |
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
60 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
61 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
62 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
63 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.FCellSymbolRenderer; |
64 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.IntervalCellEditor; |
65 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.SymbolCellEditor; |
66 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.ValueCellEditor; |
67 |
import com.iver.utiles.swing.jtable.JTable; |
68 |
import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
69 |
|
70 |
|
71 |
/**
|
72 |
* JPanel que contiene la tabla con los s?mbolos intervalos o valores y
|
73 |
* etiquetado de estos valores.
|
74 |
*
|
75 |
* @author Vicente Caballero Navarro
|
76 |
*/
|
77 |
public class FSymbolTable extends JPanel { |
78 |
private static final long serialVersionUID = 1L; |
79 |
|
80 |
// private boolean DEBUG = true;
|
81 |
// private MyTableModel m_TableModel;
|
82 |
private JTable table; |
83 |
private String type; |
84 |
|
85 |
private int shapeType; |
86 |
|
87 |
/**
|
88 |
* Crea un nuevo FSymbolTable.
|
89 |
*
|
90 |
* @param type tipo de valor si es intervalo: "intervals" y si es por
|
91 |
* valores: "values".
|
92 |
*/
|
93 |
public FSymbolTable(String type, int shapeType) { |
94 |
super(new GridLayout(1, 0)); |
95 |
this.type = type;
|
96 |
this.shapeType = shapeType;
|
97 |
table = new JTable(); |
98 |
table.setModel(new MyTableModel());
|
99 |
table.setPreferredScrollableViewportSize(new Dimension(480, 110)); |
100 |
|
101 |
//Create the scroll pane and add the table to it.
|
102 |
JScrollPane scrollPane = new JScrollPane(table); |
103 |
|
104 |
//Set up column sizes.
|
105 |
//initColumnSizes(table);
|
106 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
|
107 |
setUpValueColumn(table, table.getColumnModel().getColumn(1));
|
108 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2));
|
109 |
|
110 |
//Add the scroll pane to this panel.
|
111 |
add(scrollPane); |
112 |
table.setRowSelectionAllowed(true);
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* A?ade una fila al modelo.
|
117 |
*
|
118 |
* @param vector Fila en forma de vector de Object para a?adir al modelo.
|
119 |
*/
|
120 |
public void addRow(Object[] vector) { |
121 |
MyTableModel m = (MyTableModel) table.getModel(); |
122 |
m.addRow(vector); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Elimina la fila que tiene como clave el objeto que se pasa como
|
127 |
* par?metro.
|
128 |
*
|
129 |
* @param obj clave del objeto a eliminar.
|
130 |
*/
|
131 |
public void removeRow(Object obj) { |
132 |
MyTableModel m = (MyTableModel) table.getModel(); |
133 |
|
134 |
for (int i = 0; i < m.getRowCount(); i++) { |
135 |
if (m.getValueAt(i, 1) instanceof NullUniqueValue || |
136 |
m.getValueAt(i, 1) instanceof NullIntervalValue) { |
137 |
m.removeRow(i); |
138 |
} |
139 |
} |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Elimina las filas que est?n seleccionadas.
|
144 |
*/
|
145 |
public void removeSelectedRows() { |
146 |
if (table.getCellEditor() != null) { |
147 |
table.getCellEditor().cancelCellEditing(); |
148 |
} |
149 |
|
150 |
MyTableModel m = (MyTableModel) table.getModel(); |
151 |
int[] selectedRows = table.getSelectedRows(); |
152 |
|
153 |
for (int i = selectedRows.length - 1; i >= 0; i--) { |
154 |
m.removeRow(selectedRows[i]); |
155 |
} |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Rellena la tabla con los s?mbolos valores y descripciones que se pasan
|
160 |
* como par?metro.
|
161 |
*
|
162 |
* @param symbols Array de s?mbolos
|
163 |
* @param values Array de valores.
|
164 |
* @param descriptions Array de descripciones.
|
165 |
*/
|
166 |
public void fillTableFromSymbolList(ISymbol[] symbols, Object[] values, |
167 |
String[] descriptions) { |
168 |
ISymbol theSymbol; |
169 |
|
170 |
for (int i = 0; i < symbols.length; i++) { |
171 |
theSymbol = symbols[i]; |
172 |
addTableRecord(theSymbol, values[i], descriptions[i]); |
173 |
} |
174 |
} |
175 |
|
176 |
/**
|
177 |
* A?ade una fila con los objetos que se pasan como par?metros.
|
178 |
*
|
179 |
* @param symbol s?mbolo de la fila.
|
180 |
* @param value Valor de la fila.
|
181 |
* @param description Descripci?n.
|
182 |
*/
|
183 |
public void addTableRecord(ISymbol symbol, Object value, String description) { |
184 |
Object[] theRow = new Object[3]; |
185 |
theRow[0] = symbol;
|
186 |
theRow[1] = value;
|
187 |
theRow[2] = description;
|
188 |
addRow(theRow); |
189 |
} |
190 |
|
191 |
/**
|
192 |
* Devuelve el valor a partie del n?mero de fila y columna.
|
193 |
*
|
194 |
* @param row n?mero de fila.
|
195 |
* @param col n?mero de columna.
|
196 |
*
|
197 |
* @return Objeto.
|
198 |
*/
|
199 |
public Object getFieldValue(int row, int col) { |
200 |
MyTableModel m = (MyTableModel) table.getModel(); |
201 |
|
202 |
return m.getValueAt(row, col);
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Devuelve el n?mero total de filas que contiene el modelo.
|
207 |
*
|
208 |
* @return N?mero de filas.
|
209 |
*/
|
210 |
public int getRowCount() { |
211 |
MyTableModel m = (MyTableModel) table.getModel(); |
212 |
|
213 |
return m.getRowCount();
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Elimina todas las filas del modelo.
|
218 |
*/
|
219 |
public void removeAllItems() { |
220 |
table.setModel(new MyTableModel());
|
221 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
|
222 |
setUpValueColumn(table, table.getColumnModel().getColumn(1));
|
223 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2));
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* Inicializa el cell editor de tipo descripci?n de la columna que se pasa
|
228 |
* como par?metro.
|
229 |
*
|
230 |
* @param table2 Tabla.
|
231 |
* @param column Columna.
|
232 |
*/
|
233 |
public void setUpLabelColumn(JTable table2, TableColumn column) { |
234 |
TextFieldCellEditor labeleditor = new TextFieldCellEditor();
|
235 |
column.setCellEditor(labeleditor); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* Inicializa el cell editor de tipo valor de la columna que se pasa como
|
240 |
* par?metro.
|
241 |
*
|
242 |
* @param table2 Tabla.
|
243 |
* @param column Columna.
|
244 |
*/
|
245 |
public void setUpValueColumn(JTable table2, TableColumn column) { |
246 |
if (type.equals("intervals")) { |
247 |
//FIntervalCellEditor intervaleditor = new FIntervalCellEditor();
|
248 |
IntervalCellEditor intervaleditor = new IntervalCellEditor();
|
249 |
column.setCellEditor(intervaleditor); |
250 |
|
251 |
///FCellIntervalRenderer renderer = new FCellIntervalRenderer(true);
|
252 |
///column.setCellRenderer(renderer);
|
253 |
} else {
|
254 |
///FValueCellEditor valueeditor = new FValueCellEditor();
|
255 |
///TextFieldCellEditor valueeditor = new TextFieldCellEditor();
|
256 |
ValueCellEditor valueeditor = new ValueCellEditor();
|
257 |
column.setCellEditor(valueeditor); |
258 |
} |
259 |
} |
260 |
|
261 |
/*
|
262 |
* This method picks good column sizes.
|
263 |
* If all column heads are wider than the column's cells'
|
264 |
* contents, then you can just use column.sizeWidthToFit().
|
265 |
*/
|
266 |
|
267 |
//private void initColumnSizes(JTable table) {
|
268 |
//MyTableModel model = (MyTableModel) table.getModel();
|
269 |
//TableColumn column = null;
|
270 |
//Component comp = null;
|
271 |
//int headerWidth = 0;
|
272 |
//int cellWidth = 0;
|
273 |
//TableCellRenderer headerRenderer = table.getTableHeader()
|
274 |
// .getDefaultRenderer();
|
275 |
//}
|
276 |
|
277 |
/**
|
278 |
* Inicializa el cell editor de tipo s?mbolo de la columna que se pasa como
|
279 |
* par?metro.
|
280 |
*
|
281 |
* @param table2 Tabla.
|
282 |
* @param column Columna.
|
283 |
*/
|
284 |
public void setUpSymbolColumn(JTable table2, TableColumn column) { |
285 |
//Set up the editor
|
286 |
column.setMaxWidth(100);
|
287 |
column.setWidth(60);
|
288 |
column.setPreferredWidth(60);
|
289 |
column.setMinWidth(50);
|
290 |
|
291 |
//FSymbolCellEditor symboleditor = new FSymbolCellEditor();
|
292 |
SymbolCellEditor symboleditor = new SymbolCellEditor(shapeType);
|
293 |
column.setCellEditor(symboleditor); |
294 |
|
295 |
FCellSymbolRenderer renderer = new FCellSymbolRenderer(true); |
296 |
column.setCellRenderer(renderer); |
297 |
} |
298 |
|
299 |
/**
|
300 |
* Modelo que propio que se aplica a la tabla.
|
301 |
*
|
302 |
* @author Vicente Caballero Navarro
|
303 |
*/
|
304 |
class MyTableModel extends DefaultTableModel { /** |
305 |
*
|
306 |
*/
|
307 |
|
308 |
private static final long serialVersionUID = 1L; |
309 |
|
310 |
// AbstractTableModel {
|
311 |
private String[] columnNames = { |
312 |
PluginServices.getText(this, "Simbolo"), |
313 |
PluginServices.getText(this, "Valor"), |
314 |
PluginServices.getText(this, "Etiqueta") |
315 |
}; |
316 |
|
317 |
/**
|
318 |
* Devuelve el n?mero de columnas.
|
319 |
*
|
320 |
* @return N?mero de columnas.
|
321 |
*/
|
322 |
public int getColumnCount() { |
323 |
return columnNames.length;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* Devuelve el String del valor de la columna.
|
328 |
*
|
329 |
* @param col N?mero de columna.
|
330 |
*
|
331 |
* @return Nombre de la columna.
|
332 |
*/
|
333 |
public String getColumnName(int col) { |
334 |
return columnNames[col];
|
335 |
} |
336 |
|
337 |
/*
|
338 |
* JTable uses this method to determine the default renderer/
|
339 |
* editor for each cell. If we didn't implement this method,
|
340 |
* then the last column would contain text ("true"/"false"),
|
341 |
* rather than a check box.
|
342 |
*/
|
343 |
public Class getColumnClass(int c) { |
344 |
if (getValueAt(0, c) == null) { |
345 |
return NullValue.class;
|
346 |
} |
347 |
|
348 |
return getValueAt(0, c).getClass(); |
349 |
} |
350 |
|
351 |
/*
|
352 |
* Don't need to implement this method unless your table's
|
353 |
* editable.
|
354 |
*/
|
355 |
public boolean isCellEditable(int row, int col) { |
356 |
//Note that the data/cell address is constant,
|
357 |
//no matter where the cell appears onscreen.
|
358 |
//if (col > 0) {
|
359 |
return true; |
360 |
|
361 |
/* } else {
|
362 |
return false;
|
363 |
} */
|
364 |
} |
365 |
|
366 |
/*
|
367 |
* Don't need to implement this method unless your table's
|
368 |
* data can change.
|
369 |
*/
|
370 |
/* public void setValueAt(Object value, int row, int col) {
|
371 |
if (DEBUG) {
|
372 |
System.out.println("Setting value at " + row + "," + col
|
373 |
+ " to " + value
|
374 |
+ " (an instance of "
|
375 |
+ value.getClass() + ")");
|
376 |
}
|
377 |
// FSymbol theSymbol;
|
378 |
switch (col)
|
379 |
{
|
380 |
case 0: // Simbolo
|
381 |
// m_FRenderer.setValueSymbol(row,(FSymbol) value);
|
382 |
break;
|
383 |
case 1: // Clave
|
384 |
FInterval newInterval = FInterval.parseString((String) value);
|
385 |
this.setValueAt(newInterval,row,col);
|
386 |
break;
|
387 |
case 2: // Etiqueta
|
388 |
// theSymbol = m_FRenderer.getSymbolByID(row);
|
389 |
// theSymbol.m_Descrip = (String) value;
|
390 |
|
391 |
}
|
392 |
// data[row][col] = value;
|
393 |
fireTableCellUpdated(row, col);
|
394 |
} */
|
395 |
/* private void printDebugData() {
|
396 |
int numRows = getRowCount();
|
397 |
int numCols = getColumnCount();
|
398 |
for (int i=0; i < numRows; i++) {
|
399 |
System.out.print(" row " + i + ":");
|
400 |
for (int j=0; j < numCols; j++) {
|
401 |
System.out.print(" " + data[i][j]);
|
402 |
}
|
403 |
System.out.println();
|
404 |
}
|
405 |
System.out.println("--------------------------");
|
406 |
} */
|
407 |
} |
408 |
} |