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