svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / FSymbolTable.java @ 2439
History | View | Annotate | Download (10.1 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.gui.thememanager.legendmanager.panels; |
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.v02.FSymbol; |
60 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition.FCellSymbolRenderer; |
61 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition.IntervalCellEditor; |
62 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition.SymbolCellEditor; |
63 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition.ValueCellEditor; |
64 |
import com.iver.utiles.swing.jtable.JTable; |
65 |
import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
66 |
|
67 |
|
68 |
/**
|
69 |
* JPanel que contiene la tabla con los s?mbolos intervalos o valores y
|
70 |
* etiquetado de estos valores.
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class FSymbolTable extends JPanel { |
75 |
private static final long serialVersionUID = 1L; |
76 |
|
77 |
// private boolean DEBUG = true;
|
78 |
|
79 |
// private MyTableModel m_TableModel;
|
80 |
private JTable table; |
81 |
private String type; |
82 |
|
83 |
/**
|
84 |
* Crea un nuevo FSymbolTable.
|
85 |
*
|
86 |
* @param type tipo de valor si es intervalo: "intervals" y si es por valores: "values".
|
87 |
*/
|
88 |
public FSymbolTable(String type) { |
89 |
super(new GridLayout(1, 0)); |
90 |
this.type = type;
|
91 |
table = new JTable(); |
92 |
table.setModel(new MyTableModel());
|
93 |
table.setPreferredScrollableViewportSize(new Dimension(500, 70)); |
94 |
|
95 |
//Create the scroll pane and add the table to it.
|
96 |
JScrollPane scrollPane = new JScrollPane(table); |
97 |
|
98 |
//Set up column sizes.
|
99 |
//initColumnSizes(table);
|
100 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
|
101 |
setUpValueColumn(table, table.getColumnModel().getColumn(1));
|
102 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2));
|
103 |
//Add the scroll pane to this panel.
|
104 |
add(scrollPane); |
105 |
table.setRowSelectionAllowed(true);
|
106 |
} |
107 |
|
108 |
public void addRow(Object[] vector) { |
109 |
MyTableModel m = (MyTableModel) table.getModel(); |
110 |
m.addRow(vector); |
111 |
} |
112 |
|
113 |
public void removeSelectedRows() { |
114 |
if (table.getCellEditor()!=null) |
115 |
table.getCellEditor().cancelCellEditing(); |
116 |
MyTableModel m = (MyTableModel) table.getModel(); |
117 |
int[] selectedRows = table.getSelectedRows(); |
118 |
|
119 |
for (int i = selectedRows.length - 1; i >= 0; i--) { |
120 |
m.removeRow(selectedRows[i]); |
121 |
} |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Rellena la tabla con los s?mbolos valores y descripciones que se pasan como par?metro.
|
126 |
*
|
127 |
* @param symbols Array de s?mbolos
|
128 |
* @param values Array de valores.
|
129 |
* @param descriptions Array de descripciones.
|
130 |
*/
|
131 |
public void fillTableFromSymbolList(FSymbol[] symbols, Object[] values, |
132 |
String[] descriptions) { |
133 |
FSymbol theSymbol; |
134 |
|
135 |
for (int i = 0; i < symbols.length; i++) { |
136 |
theSymbol = symbols[i]; |
137 |
addTableRecord(theSymbol,values[i],descriptions[i]); |
138 |
} |
139 |
} |
140 |
public void addTableRecord(FSymbol symbol, Object value, |
141 |
String description) {
|
142 |
Object[] theRow = new Object[3]; |
143 |
theRow[0] = symbol;
|
144 |
theRow[1] = value;
|
145 |
theRow[2] = description;
|
146 |
addRow(theRow); |
147 |
} |
148 |
public Object getFieldValue(int row, int col) { |
149 |
MyTableModel m = (MyTableModel) table.getModel(); |
150 |
|
151 |
return m.getValueAt(row, col);
|
152 |
} |
153 |
|
154 |
public int getRowCount() { |
155 |
MyTableModel m = (MyTableModel) table.getModel(); |
156 |
|
157 |
return m.getRowCount();
|
158 |
} |
159 |
|
160 |
public void removeAllItems() { |
161 |
table.setModel(new MyTableModel());
|
162 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
|
163 |
setUpValueColumn(table, table.getColumnModel().getColumn(1));
|
164 |
setUpLabelColumn(table, table.getColumnModel().getColumn(2));
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* Inicializa el cell editor de tipo descripci?n de la columna que se pasa como par?metro.
|
169 |
*
|
170 |
* @param table2 Tabla.
|
171 |
* @param column Columna.
|
172 |
*/
|
173 |
public void setUpLabelColumn(JTable table2, TableColumn column) { |
174 |
TextFieldCellEditor labeleditor = new TextFieldCellEditor();
|
175 |
column.setCellEditor(labeleditor); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Inicializa el cell editor de tipo valor de la columna que se pasa como par?metro.
|
180 |
*
|
181 |
* @param table2 Tabla.
|
182 |
* @param column Columna.
|
183 |
*/
|
184 |
public void setUpValueColumn(JTable table2, TableColumn column) { |
185 |
if (type.equals("intervals")) { |
186 |
//FIntervalCellEditor intervaleditor = new FIntervalCellEditor();
|
187 |
IntervalCellEditor intervaleditor = new IntervalCellEditor();
|
188 |
column.setCellEditor(intervaleditor); |
189 |
|
190 |
///FCellIntervalRenderer renderer = new FCellIntervalRenderer(true);
|
191 |
///column.setCellRenderer(renderer);
|
192 |
} else {
|
193 |
///FValueCellEditor valueeditor = new FValueCellEditor();
|
194 |
///TextFieldCellEditor valueeditor = new TextFieldCellEditor();
|
195 |
ValueCellEditor valueeditor= new ValueCellEditor();
|
196 |
column.setCellEditor(valueeditor); |
197 |
} |
198 |
} |
199 |
|
200 |
/*
|
201 |
* This method picks good column sizes.
|
202 |
* If all column heads are wider than the column's cells'
|
203 |
* contents, then you can just use column.sizeWidthToFit().
|
204 |
*/
|
205 |
//private void initColumnSizes(JTable table) {
|
206 |
//MyTableModel model = (MyTableModel) table.getModel();
|
207 |
//TableColumn column = null;
|
208 |
//Component comp = null;
|
209 |
//int headerWidth = 0;
|
210 |
//int cellWidth = 0;
|
211 |
//TableCellRenderer headerRenderer = table.getTableHeader()
|
212 |
// .getDefaultRenderer();
|
213 |
//}
|
214 |
|
215 |
/**
|
216 |
* Inicializa el cell editor de tipo s?mbolo de la columna que se pasa como par?metro.
|
217 |
*
|
218 |
* @param table2 Tabla.
|
219 |
* @param column Columna.
|
220 |
*/
|
221 |
public void setUpSymbolColumn(JTable table, TableColumn m_FSymbolComlumn) { |
222 |
//Set up the editor
|
223 |
m_FSymbolComlumn.setMaxWidth(100);
|
224 |
m_FSymbolComlumn.setWidth(60);
|
225 |
m_FSymbolComlumn.setPreferredWidth(60);
|
226 |
m_FSymbolComlumn.setMinWidth(50);
|
227 |
|
228 |
//FSymbolCellEditor symboleditor = new FSymbolCellEditor();
|
229 |
SymbolCellEditor symboleditor = new SymbolCellEditor();
|
230 |
m_FSymbolComlumn.setCellEditor(symboleditor); |
231 |
|
232 |
FCellSymbolRenderer renderer = new FCellSymbolRenderer(true); |
233 |
m_FSymbolComlumn.setCellRenderer(renderer); |
234 |
} |
235 |
|
236 |
/**
|
237 |
* Modelo que propio que se aplica a la tabla.
|
238 |
*
|
239 |
* @author Vicente Caballero Navarro
|
240 |
*/
|
241 |
class MyTableModel extends DefaultTableModel { /** |
242 |
*
|
243 |
*/
|
244 |
private static final long serialVersionUID = 1L; |
245 |
// AbstractTableModel {
|
246 |
|
247 |
private String[] columnNames = { |
248 |
PluginServices.getText(this, "Simbolo"), |
249 |
PluginServices.getText(this, "Valor"), |
250 |
PluginServices.getText(this, "Etiqueta") |
251 |
}; |
252 |
|
253 |
/**
|
254 |
* DOCUMENT ME!
|
255 |
*
|
256 |
* @return DOCUMENT ME!
|
257 |
*/
|
258 |
public int getColumnCount() { |
259 |
return columnNames.length;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* DOCUMENT ME!
|
264 |
*
|
265 |
* @param col DOCUMENT ME!
|
266 |
*
|
267 |
* @return DOCUMENT ME!
|
268 |
*/
|
269 |
public String getColumnName(int col) { |
270 |
return columnNames[col];
|
271 |
} |
272 |
|
273 |
/*
|
274 |
* JTable uses this method to determine the default renderer/
|
275 |
* editor for each cell. If we didn't implement this method,
|
276 |
* then the last column would contain text ("true"/"false"),
|
277 |
* rather than a check box.
|
278 |
*/
|
279 |
public Class getColumnClass(int c) { |
280 |
if (getValueAt(0,c)==null)return NullValue.class; |
281 |
return getValueAt(0, c).getClass(); |
282 |
} |
283 |
|
284 |
/*
|
285 |
* Don't need to implement this method unless your table's
|
286 |
* editable.
|
287 |
*/
|
288 |
public boolean isCellEditable(int row, int col) { |
289 |
//Note that the data/cell address is constant,
|
290 |
//no matter where the cell appears onscreen.
|
291 |
//if (col > 0) {
|
292 |
return true; |
293 |
|
294 |
/* } else {
|
295 |
return false;
|
296 |
} */
|
297 |
} |
298 |
|
299 |
/*
|
300 |
* Don't need to implement this method unless your table's
|
301 |
* data can change.
|
302 |
*/
|
303 |
/* public void setValueAt(Object value, int row, int col) {
|
304 |
if (DEBUG) {
|
305 |
System.out.println("Setting value at " + row + "," + col
|
306 |
+ " to " + value
|
307 |
+ " (an instance of "
|
308 |
+ value.getClass() + ")");
|
309 |
}
|
310 |
// FSymbol theSymbol;
|
311 |
switch (col)
|
312 |
{
|
313 |
case 0: // Simbolo
|
314 |
// m_FRenderer.setValueSymbol(row,(FSymbol) value);
|
315 |
break;
|
316 |
case 1: // Clave
|
317 |
FInterval newInterval = FInterval.parseString((String) value);
|
318 |
this.setValueAt(newInterval,row,col);
|
319 |
break;
|
320 |
case 2: // Etiqueta
|
321 |
// theSymbol = m_FRenderer.getSymbolByID(row);
|
322 |
// theSymbol.m_Descrip = (String) value;
|
323 |
|
324 |
}
|
325 |
// data[row][col] = value;
|
326 |
fireTableCellUpdated(row, col);
|
327 |
} */
|
328 |
/* private void printDebugData() {
|
329 |
int numRows = getRowCount();
|
330 |
int numCols = getColumnCount();
|
331 |
for (int i=0; i < numRows; i++) {
|
332 |
System.out.print(" row " + i + ":");
|
333 |
for (int j=0; j < numCols; j++) {
|
334 |
System.out.print(" " + data[i][j]);
|
335 |
}
|
336 |
System.out.println();
|
337 |
}
|
338 |
System.out.println("--------------------------");
|
339 |
} */
|
340 |
} |
341 |
} |