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 | 1671 | jmorell | /*
|
---|---|---|---|
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 | 2364 | vcaballero | import com.hardcode.gdbms.engine.values.NullValue; |
58 | 1671 | jmorell | import com.iver.andami.PluginServices; |
59 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
60 | 2204 | vcaballero | import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition.FCellSymbolRenderer; |
61 | 2364 | vcaballero | 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 | 2334 | fernando | import com.iver.utiles.swing.jtable.JTable; |
65 | 2364 | vcaballero | import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
66 | 1671 | jmorell | |
67 | |||
68 | 2204 | vcaballero | /**
|
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 | 1671 | jmorell | public class FSymbolTable extends JPanel { |
75 | 2204 | vcaballero | private static final long serialVersionUID = 1L; |
76 | 1671 | jmorell | |
77 | 2204 | vcaballero | // private boolean DEBUG = true;
|
78 | |||
79 | 1671 | jmorell | // private MyTableModel m_TableModel;
|
80 | private JTable table; |
||
81 | 2204 | vcaballero | 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 | 2334 | fernando | table = new JTable(); |
92 | table.setModel(new MyTableModel());
|
||
93 | 2204 | vcaballero | 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 | 2439 | caballero | //initColumnSizes(table);
|
100 | 2204 | vcaballero | 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 | 2364 | vcaballero | table.setRowSelectionAllowed(true);
|
106 | 2204 | vcaballero | } |
107 | |||
108 | public void addRow(Object[] vector) { |
||
109 | 1671 | jmorell | MyTableModel m = (MyTableModel) table.getModel(); |
110 | 2204 | vcaballero | m.addRow(vector); |
111 | 1671 | jmorell | } |
112 | 2204 | vcaballero | |
113 | public void removeSelectedRows() { |
||
114 | 2439 | caballero | if (table.getCellEditor()!=null) |
115 | 2364 | vcaballero | table.getCellEditor().cancelCellEditing(); |
116 | 1671 | jmorell | MyTableModel m = (MyTableModel) table.getModel(); |
117 | 2204 | vcaballero | int[] selectedRows = table.getSelectedRows(); |
118 | |||
119 | for (int i = selectedRows.length - 1; i >= 0; i--) { |
||
120 | 1671 | jmorell | m.removeRow(selectedRows[i]); |
121 | } |
||
122 | } |
||
123 | |||
124 | 2204 | vcaballero | /**
|
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 | 1671 | jmorell | theSymbol = symbols[i]; |
137 | 2364 | vcaballero | addTableRecord(theSymbol,values[i],descriptions[i]); |
138 | 1671 | jmorell | } |
139 | } |
||
140 | 2364 | vcaballero | 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 | 2204 | vcaballero | public Object getFieldValue(int row, int col) { |
149 | 1671 | jmorell | MyTableModel m = (MyTableModel) table.getModel(); |
150 | 2204 | vcaballero | |
151 | return m.getValueAt(row, col);
|
||
152 | 1671 | jmorell | } |
153 | 2204 | vcaballero | |
154 | public int getRowCount() { |
||
155 | 1671 | jmorell | MyTableModel m = (MyTableModel) table.getModel(); |
156 | 2204 | vcaballero | |
157 | return m.getRowCount();
|
||
158 | 1671 | jmorell | } |
159 | 2204 | vcaballero | |
160 | public void removeAllItems() { |
||
161 | 1671 | jmorell | table.setModel(new MyTableModel());
|
162 | 2204 | vcaballero | setUpSymbolColumn(table, table.getColumnModel().getColumn(0));
|
163 | setUpValueColumn(table, table.getColumnModel().getColumn(1));
|
||
164 | setUpLabelColumn(table, table.getColumnModel().getColumn(2));
|
||
165 | 1671 | jmorell | } |
166 | |||
167 | 2204 | vcaballero | /**
|
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 | 2364 | vcaballero | TextFieldCellEditor labeleditor = new TextFieldCellEditor();
|
175 | 2204 | vcaballero | column.setCellEditor(labeleditor); |
176 | } |
||
177 | 1671 | jmorell | |
178 | 2204 | vcaballero | /**
|
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 | 2364 | vcaballero | //FIntervalCellEditor intervaleditor = new FIntervalCellEditor();
|
187 | IntervalCellEditor intervaleditor = new IntervalCellEditor();
|
||
188 | 2204 | vcaballero | column.setCellEditor(intervaleditor); |
189 | 1671 | jmorell | |
190 | 2364 | vcaballero | ///FCellIntervalRenderer renderer = new FCellIntervalRenderer(true);
|
191 | ///column.setCellRenderer(renderer);
|
||
192 | 2204 | vcaballero | } else {
|
193 | 2364 | vcaballero | ///FValueCellEditor valueeditor = new FValueCellEditor();
|
194 | ///TextFieldCellEditor valueeditor = new TextFieldCellEditor();
|
||
195 | ValueCellEditor valueeditor= new ValueCellEditor();
|
||
196 | 2204 | vcaballero | column.setCellEditor(valueeditor); |
197 | } |
||
198 | 1671 | jmorell | } |
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 | 2439 | caballero | //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 | 1671 | jmorell | |
215 | 2204 | vcaballero | /**
|
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 | 1671 | jmorell | //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 | 2204 | vcaballero | |
228 | 2364 | vcaballero | //FSymbolCellEditor symboleditor = new FSymbolCellEditor();
|
229 | SymbolCellEditor symboleditor = new SymbolCellEditor();
|
||
230 | 2204 | vcaballero | m_FSymbolComlumn.setCellEditor(symboleditor); |
231 | |||
232 | FCellSymbolRenderer renderer = new FCellSymbolRenderer(true); |
||
233 | 1671 | jmorell | m_FSymbolComlumn.setCellRenderer(renderer); |
234 | } |
||
235 | |||
236 | 2204 | vcaballero | /**
|
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 | 1671 | jmorell | |
247 | 2204 | vcaballero | 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 | 1671 | jmorell | public int getColumnCount() { |
259 | return columnNames.length;
|
||
260 | } |
||
261 | |||
262 | 2204 | vcaballero | /**
|
263 | * DOCUMENT ME!
|
||
264 | *
|
||
265 | * @param col DOCUMENT ME!
|
||
266 | *
|
||
267 | * @return DOCUMENT ME!
|
||
268 | */
|
||
269 | 1671 | jmorell | 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 | 2364 | vcaballero | if (getValueAt(0,c)==null)return NullValue.class; |
281 | 1671 | jmorell | 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 | 2204 | vcaballero | return true; |
293 | |||
294 | 1671 | jmorell | /* } else {
|
295 | 2204 | vcaballero | return false;
|
296 | } */
|
||
297 | 1671 | jmorell | } |
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 | 2204 | vcaballero | 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 | 1671 | jmorell | /* private void printDebugData() {
|
329 | 2204 | vcaballero | 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 | 1671 | jmorell | } |
341 | } |