Revision 55
1.10/tags/gvSIG_3D_Animation_1_10_build_15/libraries/lib3DMap-share/src/test/java/com/iver/ai2/gvsig3d/AppTest.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d; |
|
2 |
|
|
3 |
import junit.framework.Test; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import junit.framework.TestSuite; |
|
6 |
|
|
7 |
/** |
|
8 |
* Unit test for simple App. |
|
9 |
*/ |
|
10 |
public class AppTest |
|
11 |
extends TestCase |
|
12 |
{ |
|
13 |
/** |
|
14 |
* Create the test case |
|
15 |
* |
|
16 |
* @param testName name of the test case |
|
17 |
*/ |
|
18 |
public AppTest( String testName ) |
|
19 |
{ |
|
20 |
super( testName ); |
|
21 |
} |
|
22 |
|
|
23 |
/** |
|
24 |
* @return the suite of tests being tested |
|
25 |
*/ |
|
26 |
public static Test suite() |
|
27 |
{ |
|
28 |
return new TestSuite( AppTest.class ); |
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* Rigourous Test :-) |
|
33 |
*/ |
|
34 |
public void testApp() |
|
35 |
{ |
|
36 |
assertTrue( true ); |
|
37 |
} |
|
38 |
} |
1.10/tags/gvSIG_3D_Animation_1_10_build_15/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/extrusion/SymbolTableExtrusion.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
package com.iver.ai2.gvsig3d.legend.extrusion; |
|
20 |
|
|
21 |
import java.awt.Component; |
|
22 |
import java.awt.Dimension; |
|
23 |
import java.awt.GridLayout; |
|
24 |
import java.awt.Point; |
|
25 |
import java.awt.Rectangle; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
import java.awt.event.MouseAdapter; |
|
28 |
import java.awt.event.MouseEvent; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Hashtable; |
|
31 |
|
|
32 |
import javax.swing.JPanel; |
|
33 |
import javax.swing.JScrollPane; |
|
34 |
import javax.swing.event.ChangeEvent; |
|
35 |
import javax.swing.table.DefaultTableModel; |
|
36 |
import javax.swing.table.TableCellEditor; |
|
37 |
import javax.swing.table.TableColumn; |
|
38 |
|
|
39 |
import com.hardcode.gdbms.engine.values.NullValue; |
|
40 |
import com.iver.andami.PluginServices; |
|
41 |
import com.iver.andami.ui.mdiFrame.JMenuItem; |
|
42 |
import com.iver.andami.ui.mdiFrame.JPopUpMenu; |
|
43 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
|
44 |
import com.iver.cit.gvsig.fmap.rendering.NullIntervalValue; |
|
45 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
|
46 |
import com.iver.cit.gvsig.project.documents.gui.SymbolCellEditor; |
|
47 |
import com.iver.cit.gvsig.project.documents.gui.TableSymbolCellRenderer; |
|
48 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.IntervalCellEditor; |
|
49 |
import com.iver.cit.gvsig.project.documents.view.legend.edition.gui.ValueCellEditor; |
|
50 |
|
|
51 |
|
|
52 |
import com.iver.utiles.swing.jtable.JTable; |
|
53 |
import com.iver.utiles.swing.jtable.TextFieldCellEditor; |
|
54 |
|
|
55 |
public class SymbolTableExtrusion extends JPanel { |
|
56 |
private static final long serialVersionUID = -8694846716328735113L; |
|
57 |
private static Hashtable<String,TableCellEditor> cellEditors = new Hashtable<String,TableCellEditor>(); |
|
58 |
|
|
59 |
public static final String VALUES_TYPE = "values"; |
|
60 |
public static final String INTERVALS_TYPE = "intervals"; |
|
61 |
private JTable table; |
|
62 |
private String type; |
|
63 |
private int shapeType; |
|
64 |
private OnTableMouseAdapter rightClickActions; |
|
65 |
|
|
66 |
/** |
|
67 |
* Crea un nuevo FSymbolTable. |
|
68 |
* |
|
69 |
* @param type |
|
70 |
* tipo de valor si es intervalo: "intervals" y si es por |
|
71 |
* valores: "values". |
|
72 |
*/ |
|
73 |
public SymbolTableExtrusion(Component ownerComponent, String type, int shapeType) { |
|
74 |
super(new GridLayout(1, 0)); |
|
75 |
this.type = type; |
|
76 |
this.shapeType = shapeType; |
|
77 |
|
|
78 |
rightClickActions = new OnTableMouseAdapter(); |
|
79 |
table = new JTable(); |
|
80 |
table.setModel(new MyTableModel()); |
|
81 |
table.setPreferredScrollableViewportSize(new Dimension(480, 110)); |
|
82 |
|
|
83 |
initializeCellEditors(); |
|
84 |
|
|
85 |
// Create the scroll pane and add the table to it. |
|
86 |
JScrollPane scrollPane = new JScrollPane(table); |
|
87 |
|
|
88 |
// Set up column sizes. |
|
89 |
// initColumnSizes(table); |
|
90 |
setUpSymbolColumn(table, table.getColumnModel().getColumn(0)); |
|
91 |
|
|
92 |
if(cellEditors.get(type) == null) |
|
93 |
throw new Error("Symbol table type not set!"); |
|
94 |
|
|
95 |
setUpValueColumn(table, table.getColumnModel().getColumn(0),cellEditors.get(this.type)); |
|
96 |
setUpLabelColumn(table, table.getColumnModel().getColumn(1)); |
|
97 |
|
|
98 |
// Add the scroll pane to this panel. |
|
99 |
add(scrollPane); |
|
100 |
table.setRowSelectionAllowed(true); |
|
101 |
table.addMouseListener(rightClickActions); |
|
102 |
} |
|
103 |
/** |
|
104 |
* Inicializa los valores de los CellEditors que la SymbolTable poseer? por defecto |
|
105 |
*/ |
|
106 |
private void initializeCellEditors() { |
|
107 |
this.cellEditors.put(this.INTERVALS_TYPE,new IntervalCellEditor()); |
|
108 |
this.cellEditors.put(this.VALUES_TYPE, new ValueCellEditor()); |
|
109 |
} |
|
110 |
/** |
|
111 |
* A?ade un nuevo CellEditor a la lista de disponibles |
|
112 |
* |
|
113 |
* @param key String con el nombre identificativo del CellEditor |
|
114 |
* @param cellEditor CellEditor que va a ser a?adido |
|
115 |
*/ |
|
116 |
public static void addCellEditor(String key,TableCellEditor cellEditor ) { |
|
117 |
cellEditors.put(key, cellEditor); |
|
118 |
} |
|
119 |
/** |
|
120 |
* Obtiene el valor de los elementos de una fila seleccionada |
|
121 |
* |
|
122 |
* @return Object[] Array con los objetos de cada una de las columnas de la fila seleccionada |
|
123 |
*/ |
|
124 |
public Object[] getSelectedRowElements() { |
|
125 |
Object[] values = new Object[2]; |
|
126 |
|
|
127 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
128 |
int[] selectedRows = table.getSelectedRows(); |
|
129 |
|
|
130 |
if(selectedRows.length != 1) |
|
131 |
return null; |
|
132 |
|
|
133 |
for (int i = 0; i < 2; i++) { |
|
134 |
values[i] = m.getValueAt(selectedRows[0], i); |
|
135 |
} |
|
136 |
|
|
137 |
return values; |
|
138 |
} |
|
139 |
/** |
|
140 |
* A?ade una fila al modelo. |
|
141 |
* |
|
142 |
* @param vector |
|
143 |
* Fila en forma de vector de Object para a?adir al modelo. |
|
144 |
*/ |
|
145 |
public void addRow(Object[] vector) { |
|
146 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
147 |
m.addRow(vector); |
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Elimina la fila que tiene como clave el objeto que se pasa como |
|
153 |
* par?metro. |
|
154 |
* |
|
155 |
* @param obj |
|
156 |
* clave del objeto a eliminar. |
|
157 |
*/ |
|
158 |
public void removeRow(Object obj) { |
|
159 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
160 |
|
|
161 |
for (int i = 0; i < m.getRowCount(); i++) { |
|
162 |
if (m.getValueAt(i, 0) instanceof NullUniqueValue |
|
163 |
|| m.getValueAt(i, 0) instanceof NullIntervalValue) { |
|
164 |
m.removeRow(i); |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Elimina las filas que est?n seleccionadas. |
|
171 |
*/ |
|
172 |
public void removeSelectedRows() { |
|
173 |
if (table.getCellEditor() != null) { |
|
174 |
table.getCellEditor().cancelCellEditing(); |
|
175 |
} |
|
176 |
|
|
177 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
178 |
int[] selectedRows = table.getSelectedRows(); |
|
179 |
|
|
180 |
for (int i = selectedRows.length - 1; i >= 0; i--) { |
|
181 |
m.removeRow(selectedRows[i]); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Rellena la tabla con los s?mbolos valores y descripciones que se pasan |
|
187 |
* como par?metro. |
|
188 |
* |
|
189 |
* @param symbols |
|
190 |
* Array de s?mbolos |
|
191 |
* @param values |
|
192 |
* Array de valores. |
|
193 |
* @param descriptions |
|
194 |
* Array de descripciones. |
|
195 |
*/ |
|
196 |
public void fillTableFromSymbolList(ISymbol[] symbols, Object[] values, |
|
197 |
Object[] descriptions) { |
|
198 |
ISymbol theSymbol; |
|
199 |
|
|
200 |
for (int i = 0; i < symbols.length; i++) { |
|
201 |
theSymbol = symbols[i]; |
|
202 |
if(!(values[i] instanceof NullIntervalValue) && !(values[i] instanceof NullUniqueValue)) |
|
203 |
addTableRecord(theSymbol, values[i], descriptions[i]); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* A?ade una fila con los objetos que se pasan como par?metros. |
|
209 |
* |
|
210 |
* @param symbol |
|
211 |
* s?mbolo de la fila. |
|
212 |
* @param value |
|
213 |
* Valor de la fila. |
|
214 |
* @param description |
|
215 |
* Descripci?n. |
|
216 |
*/ |
|
217 |
public void addTableRecord(ISymbol symbol, Object value, Object description) { |
|
218 |
Object[] theRow = new Object[2]; |
|
219 |
theRow[0] = value; |
|
220 |
theRow[1] = description; |
|
221 |
addRow(theRow); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* Devuelve el valor a partie del n?mero de fila y columna. |
|
226 |
* |
|
227 |
* @param row |
|
228 |
* n?mero de fila. |
|
229 |
* @param col |
|
230 |
* n?mero de columna. |
|
231 |
* |
|
232 |
* @return Objeto. |
|
233 |
*/ |
|
234 |
public Object getFieldValue(int row, int col) { |
|
235 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
236 |
|
|
237 |
return m.getValueAt(row, col); |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* Devuelve el n?mero total de filas que contiene el modelo. |
|
242 |
* |
|
243 |
* @return N?mero de filas. |
|
244 |
*/ |
|
245 |
public int getRowCount() { |
|
246 |
MyTableModel m = (MyTableModel) table.getModel(); |
|
247 |
|
|
248 |
return m.getRowCount(); |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Elimina todas las filas del modelo. |
|
253 |
*/ |
|
254 |
public void removeAllItems() { |
|
255 |
table.setModel(new MyTableModel()); |
|
256 |
setUpValueColumn(table, table.getColumnModel().getColumn(0),cellEditors.get(this.type)); |
|
257 |
setUpLabelColumn(table, table.getColumnModel().getColumn(1)); |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Inicializa el cell editor de tipo descripci?n de la columna que se pasa |
|
262 |
* como par?metro. |
|
263 |
* |
|
264 |
* @param table2 |
|
265 |
* Tabla. |
|
266 |
* @param column |
|
267 |
* Columna. |
|
268 |
*/ |
|
269 |
public void setUpLabelColumn(JTable table2, TableColumn column) { |
|
270 |
TextFieldCellEditor labeleditor = new TextFieldCellEditor(); |
|
271 |
column.setCellEditor(labeleditor); |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Inicializa el cell editor de tipo valor de la columna que se pasa como |
|
276 |
* par?metro. |
|
277 |
* |
|
278 |
* @param table2 |
|
279 |
* Tabla. |
|
280 |
* @param column |
|
281 |
* Columna. |
|
282 |
* @param tableCellEditor |
|
283 |
*/ |
|
284 |
public void setUpValueColumn(JTable table2,TableColumn column, TableCellEditor tableCellEditor) { |
|
285 |
column.setCellEditor(tableCellEditor); |
|
286 |
} |
|
287 |
/** |
|
288 |
* Inicializa el cell editor de tipo s?mbolo de la columna que se pasa como |
|
289 |
* par?metro. |
|
290 |
* |
|
291 |
* @param table2 |
|
292 |
* Tabla. |
|
293 |
* @param column |
|
294 |
* Columna. |
|
295 |
*/ |
|
296 |
public void setUpSymbolColumn(JTable table2, TableColumn column) { |
|
297 |
// Set up the editor |
|
298 |
column.setMaxWidth(100); |
|
299 |
column.setWidth(60); |
|
300 |
column.setPreferredWidth(60); |
|
301 |
column.setMinWidth(50); |
|
302 |
|
|
303 |
// FSymbolCellEditor symboleditor = new FSymbolCellEditor(); |
|
304 |
// SymbolCellEditor symboleditor = new SymbolCellEditor(shapeType); |
|
305 |
SymbolCellEditor symboleditor = new SymbolCellEditor(); |
|
306 |
column.setCellEditor(symboleditor); |
|
307 |
|
|
308 |
TableSymbolCellRenderer renderer = new TableSymbolCellRenderer(true); |
|
309 |
column.setCellRenderer(renderer); |
|
310 |
} |
|
311 |
|
|
312 |
/** |
|
313 |
* Modelo que propio que se aplica a la tabla. |
|
314 |
* |
|
315 |
* @author Vicente Caballero Navarro |
|
316 |
*/ |
|
317 |
class MyTableModel extends DefaultTableModel { |
|
318 |
private static final long serialVersionUID = 1L; |
|
319 |
|
|
320 |
// AbstractTableModel { |
|
321 |
private String[] columnNames = { |
|
322 |
PluginServices.getText(this, "Valor_inicial"), |
|
323 |
PluginServices.getText(this, "Valor_extrusionado") }; |
|
324 |
|
|
325 |
/** |
|
326 |
* Devuelve el n?mero de columnas. |
|
327 |
* |
|
328 |
* @return N?mero de columnas. |
|
329 |
*/ |
|
330 |
public int getColumnCount() { |
|
331 |
return columnNames.length; |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* Devuelve el String del valor de la columna. |
|
336 |
* |
|
337 |
* @param col |
|
338 |
* N?mero de columna. |
|
339 |
* |
|
340 |
* @return Nombre de la columna. |
|
341 |
*/ |
|
342 |
public String getColumnName(int col) { |
|
343 |
return columnNames[col]; |
|
344 |
} |
|
345 |
|
|
346 |
/** |
|
347 |
* JTable uses this method to determine the default renderer/ editor for |
|
348 |
* each cell. If we didn't implement this method, then the last column |
|
349 |
* would contain text ("true"/"false"), rather than a check box. |
|
350 |
*/ |
|
351 |
public Class getColumnClass(int c) { |
|
352 |
if (getValueAt(0, c) == null) { |
|
353 |
return NullValue.class; |
|
354 |
} |
|
355 |
return getValueAt(0, c).getClass(); |
|
356 |
} |
|
357 |
|
|
358 |
/* |
|
359 |
* Don't need to implement this method unless your table's editable. |
|
360 |
*/ |
|
361 |
public boolean isCellEditable(int row, int col) { |
|
362 |
// Note that the data/cell address is constant, |
|
363 |
// no matter where the cell appears onscreen. |
|
364 |
// if (col > 0) { |
|
365 |
return true; |
|
366 |
} |
|
367 |
|
|
368 |
@Override |
|
369 |
public Object getValueAt(int row, int column) { |
|
370 |
// if(column == 1) |
|
371 |
// return ((ISymbol)getValueAt(row,0)).getDescription(); |
|
372 |
|
|
373 |
return super.getValueAt(row, column); |
|
374 |
} |
|
375 |
|
|
376 |
@Override |
|
377 |
public void setValueAt(Object aValue, int row, int column) { |
|
378 |
|
|
379 |
// if(column == 1){ |
|
380 |
// ISymbol symbol = (ISymbol) getValueAt(row,0); |
|
381 |
// symbol.setDescription((String) aValue); |
|
382 |
// setValueAt(symbol,row,0); |
|
383 |
// } |
|
384 |
|
|
385 |
super.setValueAt(aValue, row, column); |
|
386 |
} |
|
387 |
|
|
388 |
} |
|
389 |
|
|
390 |
private class OnTableMouseAdapter extends MouseAdapter { |
|
391 |
|
|
392 |
private JPopUpMenu menu = new JPopUpMenu(); |
|
393 |
|
|
394 |
// group option |
|
395 |
private JMenuItem groupItem = new JMenuItem( |
|
396 |
PluginServices.getText(this, "group")); |
|
397 |
private ActionListener groupAction = new ActionListener() { |
|
398 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
399 |
hidePopUp(); |
|
400 |
int[] selectedRows = table.getSelectedRows(); |
|
401 |
if (selectedRows.length > 1) { |
|
402 |
DefaultTableModel model = (DefaultTableModel) table |
|
403 |
.getModel(); |
|
404 |
int theRow = selectedRows[0]; |
|
405 |
// ISymbol symboToBeApplied = (ISymbol) model.getValueAt( |
|
406 |
// theRow, 0); |
|
407 |
String labelToBeApplied = (String) model.getValueAt( |
|
408 |
theRow, 1); |
|
409 |
ArrayList<Object> valuesToBeApplied = new ArrayList<Object>( |
|
410 |
selectedRows.length); |
|
411 |
for (int i = 0; i < selectedRows.length; i++) { |
|
412 |
valuesToBeApplied.add(model.getValueAt(selectedRows[i], |
|
413 |
0)); |
|
414 |
} |
|
415 |
|
|
416 |
for (int i = selectedRows.length - 1; i > 0; i--) { |
|
417 |
model.removeRow(selectedRows[i]); |
|
418 |
} |
|
419 |
|
|
420 |
// model.setValueAt(symboToBeApplied, theRow, 0); |
|
421 |
model.setValueAt(labelToBeApplied, theRow, 1); |
|
422 |
table.clearSelection(); |
|
423 |
table.doLayout(); |
|
424 |
} |
|
425 |
} |
|
426 |
}; |
|
427 |
|
|
428 |
// combine option |
|
429 |
private JMenuItem combineItem = new JMenuItem( |
|
430 |
PluginServices.getText(this, "combine")); |
|
431 |
private ActionListener combineAction = new ActionListener() { |
|
432 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
433 |
hidePopUp(); |
|
434 |
int[] selectedRows = table.getSelectedRows(); |
|
435 |
if (selectedRows.length > 1) { |
|
436 |
DefaultTableModel model = (DefaultTableModel) table |
|
437 |
.getModel(); |
|
438 |
int theRow = selectedRows[0]; |
|
439 |
// ISymbol symboToBeApplied = (ISymbol) model.getValueAt( |
|
440 |
// theRow, 0); |
|
441 |
String labelToBeApplied = (String) model.getValueAt( |
|
442 |
theRow, 1); |
|
443 |
ArrayList<Object> valuesToBeApplied = new ArrayList<Object>( |
|
444 |
selectedRows.length); |
|
445 |
for (int i = 0; i < selectedRows.length; i++) { |
|
446 |
valuesToBeApplied.add(model.getValueAt(selectedRows[i], |
|
447 |
0)); |
|
448 |
} |
|
449 |
|
|
450 |
for (int i = selectedRows.length - 1; i > 0; i--) { |
|
451 |
model.removeRow(selectedRows[i]); |
|
452 |
} |
|
453 |
|
|
454 |
// model.setValueAt(symboToBeApplied, theRow, 0); |
|
455 |
model.setValueAt(labelToBeApplied, theRow, 1); |
|
456 |
table.clearSelection(); |
|
457 |
table.doLayout(); |
|
458 |
} |
|
459 |
} |
|
460 |
}; |
|
461 |
|
|
462 |
private boolean menuEmpty = false; |
|
463 |
|
|
464 |
|
|
465 |
{ |
|
466 |
groupItem.addActionListener(groupAction); |
|
467 |
if (VALUES_TYPE.equals(type)) { |
|
468 |
menu.add(groupItem); |
|
469 |
} else if (INTERVALS_TYPE.equals(type)) { |
|
470 |
menu.add(combineItem); |
|
471 |
} else { |
|
472 |
menuEmpty = true; |
|
473 |
} |
|
474 |
|
|
475 |
} |
|
476 |
|
|
477 |
@Override |
|
478 |
public void mouseExited(MouseEvent e) { |
|
479 |
// if we click outside the popup menu |
|
480 |
if (menu.isVisible()) { |
|
481 |
Rectangle tableBounds = table.getBounds(); |
|
482 |
tableBounds.setLocation(table.getLocationOnScreen()); |
|
483 |
if (!tableBounds.contains(getClickLocation(e))) { |
|
484 |
hidePopUp(); |
|
485 |
} |
|
486 |
} |
|
487 |
|
|
488 |
} |
|
489 |
|
|
490 |
@Override |
|
491 |
public void mouseClicked(MouseEvent e) { |
|
492 |
super.mouseClicked(e); |
|
493 |
|
|
494 |
// if we click outside the popup menu |
|
495 |
if (menu.isVisible() |
|
496 |
&& !menu.getBounds().contains(getClickLocation(e))) { |
|
497 |
hidePopUp(); |
|
498 |
} |
|
499 |
|
|
500 |
if (e.getButton() == MouseEvent.BUTTON3) { |
|
501 |
e.consume(); |
|
502 |
int[] selectedRows = table.getSelectedRows(); |
|
503 |
if (selectedRows.length > 0) { |
|
504 |
Point realClickLocation = getClickLocation(e); |
|
505 |
menu.setLocation(realClickLocation); |
|
506 |
showPopUp(); |
|
507 |
} |
|
508 |
} |
|
509 |
|
|
510 |
} |
|
511 |
|
|
512 |
private void showPopUp() { |
|
513 |
if (!menuEmpty) { |
|
514 |
table.setEnabled(false); |
|
515 |
table.editingCanceled(new ChangeEvent(table)); |
|
516 |
menu.setVisible(true); |
|
517 |
} |
|
518 |
} |
|
519 |
|
|
520 |
private void hidePopUp() { |
|
521 |
if (!menuEmpty ) { |
|
522 |
menu.setVisible(false); |
|
523 |
table.setEnabled(true); |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
private Point getClickLocation(MouseEvent e) { |
|
528 |
Point tableLocation = table.getLocationOnScreen(); |
|
529 |
Point relativeClickPoint = e.getPoint(); |
|
530 |
Point realClickLocation = new Point(tableLocation.x |
|
531 |
+ relativeClickPoint.x, tableLocation.y |
|
532 |
+ relativeClickPoint.y); |
|
533 |
return realClickLocation; |
|
534 |
} |
|
535 |
|
|
536 |
} |
|
537 |
|
|
538 |
} |
1.10/tags/gvSIG_3D_Animation_1_10_build_15/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/extrusion/ExtrusionLegend.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.legend.extrusion; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
|
|
5 |
import com.hardcode.gdbms.engine.values.Value; |
|
6 |
import com.iver.ai2.gvsig3d.legend.symbols.BaseExtrusionSymbol; |
|
7 |
import com.iver.ai2.gvsig3d.legend.symbols.ExtrusionPointSymbol; |
|
8 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
9 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
|
10 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
|
11 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
|
12 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
|
13 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
|
14 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
|
15 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
|
16 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
|
17 |
import com.iver.utiles.XMLEntity; |
|
18 |
|
|
19 |
public class ExtrusionLegend extends VectorialUniqueValueLegend { |
|
20 |
|
|
21 |
private BaseExtrusionSymbol defaultSimbolExtrusion; |
|
22 |
private double extrusionFactor; |
|
23 |
|
|
24 |
|
|
25 |
public ExtrusionLegend() { |
|
26 |
} |
|
27 |
public ExtrusionLegend(int shapeType) { |
|
28 |
super(shapeType); |
|
29 |
} |
|
30 |
public ISymbol getSymbolByFeature(IFeature feat) { |
|
31 |
return super.getSymbolByFeature(feat); |
|
32 |
} |
|
33 |
|
|
34 |
public ISymbol getSymbolByValue(Value key) { |
|
35 |
ISymbol theSymbol = super.getSymbolByValue(key); |
|
36 |
|
|
37 |
if (theSymbol== null) |
|
38 |
return null; |
|
39 |
double extrusion = Double.parseDouble(theSymbol.getDescription()); |
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
defaultSimbolExtrusion = new BaseExtrusionSymbol(extrusion); |
|
44 |
if (theSymbol.getClass().equals(SimpleFillSymbol.class)) {// Nuevo s�mbolo pol�gono |
|
45 |
Color color = ((IFillSymbol)theSymbol).getFillColor(); |
|
46 |
defaultSimbolExtrusion.setFillColor(color); |
|
47 |
} |
|
48 |
else if (theSymbol.getClass().equals(SimpleLineSymbol.class)) {// Nuevo s�mbolo l�nea |
|
49 |
defaultSimbolExtrusion = new BaseExtrusionSymbol(extrusion); |
|
50 |
Color color = ((ILineSymbol)theSymbol).getColor(); |
|
51 |
defaultSimbolExtrusion.setFillColor(color); |
|
52 |
} |
|
53 |
else if (theSymbol.getClass().equals(SimpleMarkerSymbol.class)) {// Nuevo s�mbolo punto |
|
54 |
defaultSimbolExtrusion = new BaseExtrusionSymbol(extrusion); |
|
55 |
Color color = ((IMarkerSymbol)theSymbol).getColor(); |
|
56 |
defaultSimbolExtrusion.setFillColor(color); |
|
57 |
} |
|
58 |
|
|
59 |
// defaultSimbolExtrusion.setExtrusion(factorExtrusion); |
|
60 |
|
|
61 |
return defaultSimbolExtrusion; |
|
62 |
} |
|
63 |
|
|
64 |
public String getClassName() { |
|
65 |
return getClass().getName(); |
|
66 |
} |
|
67 |
|
|
68 |
public double getExtrusionFactor() { |
|
69 |
return extrusionFactor; |
|
70 |
} |
|
71 |
|
|
72 |
public void setExtrusionFactor(double extrusionFactor) { |
|
73 |
this.extrusionFactor = extrusionFactor; |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
public XMLEntity getXMLEntity() { |
|
78 |
XMLEntity xml = super.getXMLEntity(); |
|
79 |
xml.putProperty("extrusionFactor", this.extrusionFactor); |
|
80 |
return xml; |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
public void setXMLEntity(XMLEntity xml) { |
|
85 |
// TODO: It is necessary to insert here all the properties to load with the extrusion legend. |
|
86 |
super.setXMLEntity(xml); |
|
87 |
if (xml.contains("extrusionFactor")) |
|
88 |
extrusionFactor = xml.getDoubleProperty("extrusionFactor"); |
|
89 |
} |
|
90 |
|
|
91 |
} |
1.10/tags/gvSIG_3D_Animation_1_10_build_15/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/extrusion/ExtrusionLegendPanel.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.legend.extrusion; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Color; |
|
5 |
import java.awt.Component; |
|
6 |
import java.awt.FlowLayout; |
|
7 |
import java.awt.event.ActionEvent; |
|
8 |
import java.awt.event.ActionListener; |
|
9 |
import java.awt.event.ItemEvent; |
|
10 |
import java.awt.event.ItemListener; |
|
11 |
import java.awt.event.KeyEvent; |
|
12 |
import java.awt.event.KeyListener; |
|
13 |
import java.sql.Types; |
|
14 |
import java.util.ArrayList; |
|
15 |
import java.util.HashMap; |
|
16 |
|
|
17 |
import javax.swing.DefaultComboBoxModel; |
|
18 |
import javax.swing.ImageIcon; |
|
19 |
import javax.swing.JCheckBox; |
|
20 |
import javax.swing.JComboBox; |
|
21 |
import javax.swing.JLabel; |
|
22 |
import javax.swing.JOptionPane; |
|
23 |
import javax.swing.JPanel; |
|
24 |
import javax.swing.JTextField; |
|
25 |
|
|
26 |
import org.gvsig.gui.beans.swing.JButton; |
|
27 |
|
|
28 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
29 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
30 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
|
31 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
|
32 |
import com.hardcode.gdbms.engine.values.NullValue; |
|
33 |
import com.hardcode.gdbms.engine.values.Value; |
|
34 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
35 |
import com.iver.ai2.gvsig3d.legend.symbols.BaseExtrusionSymbol; |
|
36 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
|
37 |
import com.iver.andami.PluginServices; |
|
38 |
import com.iver.andami.messages.NotificationManager; |
|
39 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
|
40 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
|
41 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
42 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
43 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
44 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
|
45 |
import com.iver.cit.gvsig.fmap.rendering.AbstractClassifiedVectorLegend; |
|
46 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
|
47 |
import com.iver.cit.gvsig.fmap.rendering.LegendContentsChangedListener; |
|
48 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
|
49 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
|
50 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
|
51 |
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme; |
|
52 |
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow; |
|
53 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ILegendPanel; |
|
54 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.SymbolTable; |
|
55 |
|
|
56 |
/** |
|
57 |
* DOCUMENT ME! |
|
58 |
* |
|
59 |
* @author fjp To change the template for this generated type comment go to |
|
60 |
* Window>Preferences>Java>Code Generation>Code and Comments |
|
61 |
*/ |
|
62 |
public class ExtrusionLegendPanel extends JPanel implements ILegendPanel, |
|
63 |
ActionListener, KeyListener, ItemListener { |
|
64 |
/** |
|
65 |
* |
|
66 |
*/ |
|
67 |
private static final long serialVersionUID = 6470946030927461473L; |
|
68 |
|
|
69 |
// private static Logger logger = |
|
70 |
// Logger.getLogger(VectorialUniqueValue.class.getName()); |
|
71 |
|
|
72 |
private ExtrusionLegend theLegend; |
|
73 |
private ClassifiableVectorial layer; |
|
74 |
private SymbolTableExtrusion symbolTable; |
|
75 |
private JComboBox cmbFields; |
|
76 |
private JButton btnRemoveAll; |
|
77 |
private JButton btnRemove; |
|
78 |
private JCheckBox chbUseDefault = null; |
|
79 |
private ExtrusionLegend auxLegend; |
|
80 |
private JPanel pnlCenter; |
|
81 |
private ZSort zSort; |
|
82 |
private JButton btnOpenSymbolLevelsEditor; |
|
83 |
private JTextField jtvariable; |
|
84 |
private JComboBoxColorScheme cmbColorScheme; |
|
85 |
private double extrusionValue = 1; |
|
86 |
private JTextField jtfija; |
|
87 |
private JCheckBox fixedOption; |
|
88 |
private double extrusionFixedValue = 1; |
|
89 |
|
|
90 |
private Value aux; |
|
91 |
|
|
92 |
/** |
|
93 |
* |
|
94 |
*/ |
|
95 |
public ExtrusionLegendPanel() { |
|
96 |
super(); |
|
97 |
initialize(); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* DOCUMENT ME! |
|
102 |
*/ |
|
103 |
protected void initialize() { |
|
104 |
/* |
|
105 |
* JLabel label = new JLabel(); label.setIcon(new |
|
106 |
* javax.swing.ImageIcon(Abrir |
|
107 |
* .class.getClassLoader().getResource("images/ValoresUnicos.png"))); |
|
108 |
* limagen[1] = new JLabel(); limagen[1] = label; |
|
109 |
*/ |
|
110 |
JPanel pnlButtons = new JPanel(); |
|
111 |
|
|
112 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
|
113 |
"Anadir_todos")); |
|
114 |
btnAddAll.setActionCommand("ADD_ALL_VALUES"); |
|
115 |
btnAddAll.addActionListener(this); |
|
116 |
pnlButtons.add(btnAddAll); |
|
117 |
|
|
118 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
|
119 |
btnAdd.setActionCommand("ADD_VALUE"); |
|
120 |
btnAdd.addActionListener(this); |
|
121 |
pnlButtons.add(btnAdd); |
|
122 |
|
|
123 |
btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos")); |
|
124 |
btnRemoveAll.setActionCommand("REMOVE_ALL"); |
|
125 |
btnRemoveAll.addActionListener(this); |
|
126 |
pnlButtons.add(btnRemoveAll); |
|
127 |
|
|
128 |
btnRemove = new JButton(PluginServices.getText(this, "Quitar")); |
|
129 |
btnRemove.setActionCommand("REMOVE"); |
|
130 |
btnRemove.addActionListener(this); |
|
131 |
pnlButtons.add(btnRemove); |
|
132 |
|
|
133 |
// btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, |
|
134 |
// "symbol_levels")); |
|
135 |
// btnOpenSymbolLevelsEditor.addActionListener(this); |
|
136 |
//btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR") |
|
137 |
// ; |
|
138 |
// pnlButtons.add(btnOpenSymbolLevelsEditor); |
|
139 |
|
|
140 |
pnlCenter = new JPanel(); |
|
141 |
pnlCenter.setLayout(new BorderLayout()); |
|
142 |
|
|
143 |
cmbFields = new JComboBox(); |
|
144 |
cmbFields.setActionCommand("FIELD_SELECTED"); |
|
145 |
cmbFields.addActionListener(this); |
|
146 |
cmbFields.setVisible(true); |
|
147 |
|
|
148 |
JPanel pnlNorth = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 0)); |
|
149 |
JPanel pAux1 = new JPanel(); |
|
150 |
|
|
151 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText(this, |
|
152 |
"Campo_de_clasificacion")); |
|
153 |
pAux1.add(lblFieldClassification); |
|
154 |
pAux1.add(cmbFields); |
|
155 |
pAux1.add(getChbUseDefault(), null); |
|
156 |
pnlNorth.add(pAux1); |
|
157 |
|
|
158 |
pAux1 = new JPanel(); |
|
159 |
pAux1.add(new JLabel(PluginServices.getText(this, "Nivel_de_extrusion") |
|
160 |
+ ":")); |
|
161 |
jtvariable = new JTextField(PluginServices.getText(this, "" |
|
162 |
+ this.extrusionValue), 3); |
|
163 |
jtvariable.setColumns(3); |
|
164 |
jtvariable.setHorizontalAlignment(JTextField.RIGHT); |
|
165 |
jtvariable.setToolTipText(PluginServices.getText(this, "Valor_inicial") |
|
166 |
+ " * " + PluginServices.getText(this, "Nivel_de_extrusion")); |
|
167 |
jtvariable.addKeyListener(this); |
|
168 |
pAux1.add(jtvariable); |
|
169 |
|
|
170 |
pnlNorth.add(pAux1); |
|
171 |
|
|
172 |
pAux1 = new JPanel(); |
|
173 |
fixedOption = new JCheckBox(PluginServices.getText(this, "Altura_fija") |
|
174 |
+ ":", false); |
|
175 |
fixedOption.setHorizontalAlignment(JTextField.RIGHT); |
|
176 |
fixedOption.setEnabled(true); |
|
177 |
fixedOption.setSelected(false); |
|
178 |
pAux1.add(fixedOption); |
|
179 |
|
|
180 |
jtfija = new JTextField(PluginServices.getText(this, "1"), 3); |
|
181 |
jtfija.setColumns(10); |
|
182 |
jtfija.setHorizontalAlignment(JTextField.RIGHT); |
|
183 |
jtfija.addKeyListener(this); |
|
184 |
jtfija.setToolTipText(PluginServices.getText(this, "Valor_inicial") |
|
185 |
+ " = " + PluginServices.getText(this, "Altura_fija")); |
|
186 |
jtfija.setEnabled(false); |
|
187 |
pAux1.add(jtfija); |
|
188 |
|
|
189 |
pnlNorth.add(pAux1); |
|
190 |
|
|
191 |
pAux1 = new JPanel(); |
|
192 |
pAux1 |
|
193 |
.add(new JLabel(PluginServices.getText(this, "color_scheme") |
|
194 |
+ ":")); |
|
195 |
cmbColorScheme = new JComboBoxColorScheme(false); |
|
196 |
|
|
197 |
// pAux1.add(cmbColorScheme); |
|
198 |
// pnlNorth.add(pAux1); |
|
199 |
|
|
200 |
fixedOption.addItemListener(this); |
|
201 |
this.setLayout(new BorderLayout()); |
|
202 |
this.add(pnlNorth, BorderLayout.NORTH); |
|
203 |
this.add(pnlCenter, BorderLayout.CENTER); |
|
204 |
this.add(pnlButtons, BorderLayout.SOUTH); |
|
205 |
|
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* DOCUMENT ME! |
|
210 |
*/ |
|
211 |
private void fillTableValues() { |
|
212 |
DataSource elRs; |
|
213 |
|
|
214 |
try { |
|
215 |
elRs = ((FLyrVect) layer).getRecordset(); |
|
216 |
// logger.debug("elRs.start()"); |
|
217 |
elRs.start(); |
|
218 |
|
|
219 |
int idField = -1; |
|
220 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
221 |
if (fieldName == null) { |
|
222 |
JOptionPane.showMessageDialog((Component) PluginServices |
|
223 |
.getMainFrame(), PluginServices.getText(this, |
|
224 |
"no_hay_campo_seleccionado")); |
|
225 |
return; |
|
226 |
} |
|
227 |
|
|
228 |
idField = elRs.getFieldIndexByName(fieldName); |
|
229 |
theLegend.setClassifyingFieldNames(new String[] { fieldName }); |
|
230 |
|
|
231 |
// long numReg = elRs.getRowCount(); |
|
232 |
if (idField == -1) { |
|
233 |
NotificationManager.addWarning(PluginServices.getText(this, |
|
234 |
"unrecognized_field_name") |
|
235 |
+ " " + fieldName, null); |
|
236 |
|
|
237 |
return; |
|
238 |
} |
|
239 |
|
|
240 |
symbolTable.removeAllItems(); |
|
241 |
|
|
242 |
int numSymbols = 0; |
|
243 |
ISymbol theSymbol = null; |
|
244 |
|
|
245 |
// auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend(); |
|
246 |
// auxLegend = |
|
247 |
// LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType |
|
248 |
// ()); |
|
249 |
auxLegend = new ExtrusionLegend(layer.getShapeType()); |
|
250 |
auxLegend.setExtrusionFactor(this.extrusionValue); |
|
251 |
|
|
252 |
// Object resul; |
|
253 |
if (chbUseDefault.isSelected()) { |
|
254 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
255 |
auxLegend.addSymbol(new NullUniqueValue(), auxLegend |
|
256 |
.getDefaultSymbol()); |
|
257 |
} |
|
258 |
|
|
259 |
|
|
260 |
int r; |
|
261 |
int g; |
|
262 |
int b; |
|
263 |
int stepR; |
|
264 |
int stepG; |
|
265 |
int stepB; |
|
266 |
|
|
267 |
|
|
268 |
int interval = 0; |
|
269 |
HashMap<Value, Object> auxMap = new HashMap<Value, Object>(); |
|
270 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
|
271 |
Value clave = elRs.getFieldValue(j, idField); |
|
272 |
|
|
273 |
if (clave instanceof NullValue) { |
|
274 |
continue; |
|
275 |
} |
|
276 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
277 |
auxMap.put((Value)clave, null); |
|
278 |
} |
|
279 |
} |
|
280 |
interval = auxMap.size()-1; |
|
281 |
Color startColor = Color.blue; |
|
282 |
|
|
283 |
Color endColor = Color.red; |
|
284 |
|
|
285 |
r = startColor.getRed(); |
|
286 |
g = startColor.getGreen(); |
|
287 |
b = startColor.getBlue(); |
|
288 |
stepR = (endColor.getRed() - r) / interval; |
|
289 |
stepG = (endColor.getGreen() - g) / interval; |
|
290 |
stepB = (endColor.getBlue() - b) / interval; |
|
291 |
HashMap<Value, Color> colorPalete = new HashMap<Value, Color>(); |
|
292 |
int cont = 0; |
|
293 |
|
|
294 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
|
295 |
Value clave = elRs.getFieldValue(j, idField); |
|
296 |
|
|
297 |
if (clave instanceof NullValue) { |
|
298 |
continue; |
|
299 |
} |
|
300 |
|
|
301 |
// Comprobar que no esta repetido y no hace falta introducir en |
|
302 |
// el hashtable el campo junto con el simbolo. |
|
303 |
if (auxLegend.getSymbolByValue(clave) == null) { |
|
304 |
// si no esta creado el simbolo se crea |
|
305 |
// jaume (moved to ISymbol); theSymbol = new |
|
306 |
// FSymbol(layer.getShapeType()); |
|
307 |
// theSymbol = SymbologyFactory. |
|
308 |
// createDefaultSymbolByShapeType(layer.getShapeType(), |
|
309 |
//colorScheme[rand.nextInt(colorScheme.length)].getColor()); |
|
310 |
|
|
311 |
Color co = null; |
|
312 |
if (!(colorPalete.containsKey(clave))) { |
|
313 |
int red, green, blue; |
|
314 |
red = r + (stepR * cont); |
|
315 |
green = g + (stepG * cont); |
|
316 |
blue = b + (stepB * cont); |
|
317 |
co = new Color(red, green, |
|
318 |
blue); |
|
319 |
colorPalete.put((Value) clave,co); |
|
320 |
cont++; |
|
321 |
} else { |
|
322 |
co = colorPalete.get(clave); |
|
323 |
} |
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
theSymbol = SymbologyFactory |
|
328 |
.createDefaultSymbolByShapeType(layer |
|
329 |
.getShapeType(), co); |
|
330 |
|
|
331 |
aux = clave.producto(ValueFactory |
|
332 |
.createValue(extrusionValue)); |
|
333 |
theSymbol.setDescription(aux.toString()); |
|
334 |
auxLegend.addSymbol(clave, theSymbol); |
|
335 |
|
|
336 |
numSymbols++; |
|
337 |
|
|
338 |
if (numSymbols == 100) { |
|
339 |
int resp = JOptionPane.showConfirmDialog(this, |
|
340 |
PluginServices.getText(this, |
|
341 |
"mas_de_100_simbolos"), PluginServices |
|
342 |
.getText(this, "quiere_continuar"), |
|
343 |
JOptionPane.YES_NO_OPTION, |
|
344 |
JOptionPane.WARNING_MESSAGE); |
|
345 |
|
|
346 |
if ((resp == JOptionPane.NO_OPTION) |
|
347 |
|| (resp == JOptionPane.DEFAULT_OPTION)) { |
|
348 |
return; |
|
349 |
} |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
} // for |
|
354 |
|
|
355 |
Object[] extrudedValue = auxLegend.getValues(); |
|
356 |
|
|
357 |
double defaultValue = 1; |
|
358 |
|
|
359 |
|
|
360 |
for (int i = 0; i < extrudedValue.length; i++) { |
|
361 |
if (jtvariable.isEnabled()) { |
|
362 |
try { |
|
363 |
extrudedValue[i] = ((Value) auxLegend.getValues()[i]) |
|
364 |
.producto(ValueFactory |
|
365 |
.createValue(extrusionValue)); |
|
366 |
theSymbol.setDescription(extrudedValue[i].toString()); |
|
367 |
|
|
368 |
} catch (IncompatibleTypesException e) { |
|
369 |
extrudedValue[i] = ValueFactory |
|
370 |
.createValue(defaultValue); |
|
371 |
} |
|
372 |
} else |
|
373 |
extrudedValue[i] = ValueFactory |
|
374 |
.createValue(extrusionFixedValue); |
|
375 |
|
|
376 |
} |
|
377 |
// symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
|
378 |
// auxLegend.getValues(), auxLegend.getDescriptions()); |
|
379 |
|
|
380 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
|
381 |
auxLegend.getValues(), extrudedValue); |
|
382 |
elRs.stop(); |
|
383 |
} catch (ReadDriverException e) { |
|
384 |
NotificationManager.addError(PluginServices.getText(this, |
|
385 |
"recovering_recordset"), e); |
|
386 |
} catch (IncompatibleTypesException e) { |
|
387 |
// TODO Auto-generated catch block |
|
388 |
e.printStackTrace(); |
|
389 |
} |
|
390 |
|
|
391 |
btnRemoveAll.setEnabled(true); |
|
392 |
btnRemove.setEnabled(true); |
|
393 |
|
|
394 |
// m_bCacheDirty = false; |
|
395 |
} |
|
396 |
|
|
397 |
|
|
398 |
/** |
|
399 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo el |
|
400 |
* symbolList, si no tambi�n el arrayKeys y el defaultRenderer |
|
401 |
*/ |
|
402 |
private void fillSymbolListFromTable() { |
|
403 |
Value clave; |
|
404 |
ISymbol theSymbol; |
|
405 |
|
|
406 |
// Borramos las anteriores listas: |
|
407 |
|
|
408 |
boolean bRestoValores = false; // PONERLO EN UN CHECKBOX |
|
409 |
int hasta; |
|
410 |
String fieldName = (String) cmbFields.getSelectedItem(); |
|
411 |
theLegend.setClassifyingFieldNames(new String[] { fieldName }); |
|
412 |
// ///////////////////////////////////////PEPE |
|
413 |
FLyrVect m = (FLyrVect) layer; |
|
414 |
try { |
|
415 |
int fieldType = m.getSource().getRecordset().getFieldType( |
|
416 |
(int) cmbFields.getSelectedIndex()); |
|
417 |
theLegend.setClassifyingFieldTypes(new int[] { fieldType }); |
|
418 |
} catch (ReadDriverException e) { |
|
419 |
NotificationManager.addError(PluginServices.getText(this, |
|
420 |
"could_not_setup_legend"), e); |
|
421 |
} |
|
422 |
// ///////////////////////////////////////PEPE |
|
423 |
if (bRestoValores) { |
|
424 |
hasta = symbolTable.getRowCount() - 1; |
|
425 |
} else { |
|
426 |
hasta = symbolTable.getRowCount(); |
|
427 |
} |
|
428 |
|
|
429 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
|
430 |
clave = (Value) symbolTable.getFieldValue(row, 0); |
|
431 |
DoubleValue extrusion = null; |
|
432 |
try { |
|
433 |
extrusion = (DoubleValue) symbolTable.getFieldValue(row, 1); |
|
434 |
theSymbol = new BaseExtrusionSymbol(extrusion.getValue()); |
|
435 |
theSymbol.setDescription(extrusion.toString()); |
|
436 |
} catch (Exception e) { |
|
437 |
theSymbol = new BaseExtrusionSymbol(1); |
|
438 |
theSymbol.setDescription("1"); |
|
439 |
} |
|
440 |
|
|
441 |
theLegend.addSymbol(clave, theSymbol); |
|
442 |
} |
|
443 |
|
|
444 |
if (bRestoValores) { |
|
445 |
theSymbol = (ISymbol) symbolTable.getFieldValue(hasta, 0); |
|
446 |
theLegend.setDefaultSymbol(theSymbol); |
|
447 |
} |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* DOCUMENT ME! |
|
452 |
*/ |
|
453 |
protected void fillFieldNames() { |
|
454 |
DataSource rs = null; |
|
455 |
ArrayList nomFields = null; |
|
456 |
|
|
457 |
try { |
|
458 |
rs = ((AlphanumericData) layer).getRecordset(); |
|
459 |
rs.start(); |
|
460 |
|
|
461 |
nomFields = new ArrayList(); |
|
462 |
|
|
463 |
int type; |
|
464 |
for (int i = 0; i < rs.getFieldCount(); i++) { |
|
465 |
type = rs.getFieldType(i); |
|
466 |
|
|
467 |
if (type == Types.NULL) { |
|
468 |
continue; |
|
469 |
} |
|
470 |
|
|
471 |
if ((type == Types.INTEGER) || (type == Types.DOUBLE) |
|
472 |
|| (type == Types.FLOAT) || (type == Types.BIGINT)) { |
|
473 |
nomFields.add(rs.getFieldName(i).trim()); |
|
474 |
} |
|
475 |
} |
|
476 |
|
|
477 |
rs.stop(); |
|
478 |
} catch (ReadDriverException e) { |
|
479 |
NotificationManager.addError(PluginServices.getText(this, |
|
480 |
"recovering_recordset"), e); |
|
481 |
} |
|
482 |
|
|
483 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields.toArray()); |
|
484 |
cmbFields.setModel(cM); |
|
485 |
|
|
486 |
symbolTable.removeAllItems(); |
|
487 |
} |
|
488 |
|
|
489 |
public void setData(FLayer layer, ILegend legend) { |
|
490 |
this.layer = (ClassifiableVectorial) layer; |
|
491 |
int shapeType = 0; |
|
492 |
try { |
|
493 |
shapeType = this.layer.getShapeType(); |
|
494 |
} catch (ReadDriverException e) { |
|
495 |
NotificationManager.addError(PluginServices.getText(this, |
|
496 |
"generating_intervals"), e); |
|
497 |
} |
|
498 |
|
|
499 |
if (symbolTable != null) |
|
500 |
pnlCenter.remove(symbolTable); |
|
501 |
symbolTable = new SymbolTableExtrusion(this, SymbolTable.VALUES_TYPE, |
|
502 |
shapeType); |
|
503 |
pnlCenter.add(symbolTable, BorderLayout.CENTER); |
|
504 |
|
|
505 |
fillFieldNames(); |
|
506 |
|
|
507 |
symbolTable.removeAllItems(); |
|
508 |
|
|
509 |
if (legend instanceof ExtrusionLegend) { |
|
510 |
theLegend = (ExtrusionLegend) legend; |
|
511 |
getChbUseDefault().setSelected(theLegend.isUseDefaultSymbol()); |
|
512 |
cmbFields.getModel().setSelectedItem( |
|
513 |
theLegend.getClassifyingFieldNames()[0]); |
|
514 |
symbolTable.fillTableFromSymbolList(theLegend.getSymbols(), |
|
515 |
theLegend.getValues(), theLegend.getDescriptions()); |
|
516 |
zSort = theLegend.getZSort(); |
|
517 |
} else { |
|
518 |
theLegend = new ExtrusionLegend(shapeType); |
|
519 |
} |
|
520 |
if (theLegend != null) { |
|
521 |
this.extrusionValue = ((ExtrusionLegend) this.theLegend) |
|
522 |
.getExtrusionFactor(); |
|
523 |
jtvariable.setText(Double.toString(this.extrusionValue)); |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
/* |
|
528 |
* (non-Javadoc) |
|
529 |
* |
|
530 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend() |
|
531 |
*/ |
|
532 |
public ILegend getLegend() { |
|
533 |
fillSymbolListFromTable(); |
|
534 |
fillTableValues(); |
|
535 |
if (auxLegend != null) { |
|
536 |
// your settings that are not the set of symbols must be located |
|
537 |
// here |
|
538 |
auxLegend |
|
539 |
.setClassifyingFieldNames(new String[] { (String) cmbFields |
|
540 |
.getSelectedItem() }); |
|
541 |
auxLegend.setClassifyingFieldTypes(theLegend |
|
542 |
.getClassifyingFieldTypes()); |
|
543 |
|
|
544 |
LegendContentsChangedListener[] l = theLegend.getListeners(); |
|
545 |
for (int i = 0; i < l.length; i++) { |
|
546 |
auxLegend.addLegendListener(l[i]); |
|
547 |
} |
|
548 |
; |
|
549 |
|
|
550 |
theLegend = auxLegend; |
|
551 |
} |
|
552 |
theLegend.setZSort(zSort); |
|
553 |
|
|
554 |
return theLegend; |
|
555 |
} |
|
556 |
|
|
557 |
private JCheckBox getChbUseDefault() { |
|
558 |
if (chbUseDefault == null) { |
|
559 |
chbUseDefault = new JCheckBox(); |
|
560 |
chbUseDefault.setSelected(true); |
|
561 |
chbUseDefault |
|
562 |
.addActionListener(new java.awt.event.ActionListener() { |
|
563 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
564 |
if (auxLegend == null) |
|
565 |
auxLegend = theLegend; |
|
566 |
if (chbUseDefault.isSelected()) { |
|
567 |
addDefault(); |
|
568 |
} else { |
|
569 |
delDefault(); |
|
570 |
} |
|
571 |
} |
|
572 |
}); |
|
573 |
chbUseDefault |
|
574 |
.setText(PluginServices.getText(this, "resto_valores")); |
|
575 |
} |
|
576 |
|
|
577 |
return chbUseDefault; |
|
578 |
} |
|
579 |
|
|
580 |
/** |
|
581 |
* A�ade el resto de valores. |
|
582 |
*/ |
|
583 |
private void addDefault() { |
|
584 |
auxLegend.getDefaultSymbol().setDescription("Default"); |
|
585 |
auxLegend |
|
586 |
.addSymbol(new NullUniqueValue(), auxLegend.getDefaultSymbol()); |
|
587 |
symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
|
588 |
new NullUniqueValue(), auxLegend.getDefaultSymbol() |
|
589 |
.getDescription()); |
|
590 |
symbolTable.repaint(); |
|
591 |
} |
|
592 |
|
|
593 |
/** |
|
594 |
* Elimina el resto de valores que no estan representados por ning�n otro |
|
595 |
* s�mbolo.. |
|
596 |
*/ |
|
597 |
private void delDefault() { |
|
598 |
auxLegend.delSymbol(new NullUniqueValue()); |
|
599 |
symbolTable.removeRow(new NullUniqueValue()); |
|
600 |
symbolTable.repaint(); |
|
601 |
} |
|
602 |
|
|
603 |
public void actionPerformed(ActionEvent e) { |
|
604 |
|
|
605 |
// modificar el combobox de valor |
|
606 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
|
607 |
JComboBox cb = (JComboBox) e.getSource(); |
|
608 |
String fieldName = (String) cb.getSelectedItem(); |
|
609 |
symbolTable.removeAllItems(); |
|
610 |
|
|
611 |
} |
|
612 |
|
|
613 |
// add all elements by value |
|
614 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
|
615 |
fillTableValues(); |
|
616 |
} |
|
617 |
|
|
618 |
// add only one value |
|
619 |
if (e.getActionCommand() == "ADD_VALUE") { |
|
620 |
try { |
|
621 |
symbolTable.addTableRecord(SymbologyFactory |
|
622 |
.createDefaultSymbolByShapeType(layer.getShapeType()), |
|
623 |
ValueFactory.createValue(0.0), "0 - 0"); |
|
624 |
} catch (ReadDriverException ex) { |
|
625 |
NotificationManager.addError(PluginServices.getText(this, |
|
626 |
"getting_shape_type"), ex); |
|
627 |
} |
|
628 |
} |
|
629 |
|
|
630 |
// Vacia la tabla |
|
631 |
if (e.getActionCommand() == "REMOVE_ALL") { |
|
632 |
symbolTable.removeAllItems(); |
|
633 |
theLegend.setZSort(null); |
|
634 |
zSort = null; |
|
635 |
} |
|
636 |
|
|
637 |
// Quitar solo el elemento seleccionado |
|
638 |
if (e.getActionCommand() == "REMOVE") { |
|
639 |
symbolTable.removeSelectedRows(); |
|
640 |
} |
|
641 |
|
|
642 |
if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") { |
|
643 |
|
|
644 |
if (theLegend != null) { |
|
645 |
ZSort myZSort = ((AbstractClassifiedVectorLegend) getLegend()) |
|
646 |
.getZSort(); |
|
647 |
if (myZSort == null) { |
|
648 |
myZSort = new ZSort(theLegend); |
|
649 |
} |
|
650 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort); |
|
651 |
PluginServices.getMDIManager().addWindow(sl); |
|
652 |
zSort = sl.getZSort(); |
|
653 |
if (auxLegend != null) |
|
654 |
auxLegend.setZSort(zSort); |
|
655 |
} |
|
656 |
|
|
657 |
} |
|
658 |
} |
|
659 |
|
|
660 |
public String getDescription() { |
|
661 |
return PluginServices.getText(this, PluginServices.getText(this, |
|
662 |
"info_extrusion")); |
|
663 |
} |
|
664 |
|
|
665 |
public ImageIcon getIcon() { |
|
666 |
return null; |
|
667 |
} |
|
668 |
|
|
669 |
public Class getParentClass() { |
|
670 |
return null; |
|
671 |
} |
|
672 |
|
|
673 |
public String getTitle() { |
|
674 |
return ("<html><b>" + PluginServices.getText(this, "Extrusion") + "</b></html>"); |
|
675 |
} |
|
676 |
|
|
677 |
public JPanel getPanel() { |
|
678 |
return this; |
|
679 |
} |
|
680 |
|
|
681 |
public Class getLegendClass() { |
|
682 |
return ExtrusionLegend.class; |
|
683 |
} |
|
684 |
|
|
685 |
public boolean isSuitableFor(FLayer layer) { |
|
686 |
|
|
687 |
Layer3DProps props3D = Layer3DProps.getLayer3DProps(layer); |
|
688 |
return ((props3D != null) && (props3D.getType() == Layer3DProps.layer3DVector)); |
|
689 |
} |
|
690 |
|
|
691 |
public void keyPressed(KeyEvent e) { |
|
692 |
// TODO Auto-generated method stub |
|
693 |
|
|
694 |
} |
|
695 |
|
|
696 |
public void keyReleased(KeyEvent e) { |
|
697 |
|
|
698 |
try { |
|
699 |
extrusionValue = new Double(this.jtvariable.getText()) |
|
700 |
.doubleValue(); |
|
701 |
extrusionFixedValue = new Double(this.jtfija.getText()) |
|
702 |
.doubleValue(); |
|
703 |
} catch (Exception e2) { |
|
704 |
// String s = " "; |
|
705 |
// if(!this.jtvariable.getText().equals(s)) { |
|
706 |
// JOptionPane.showMessageDialog(null, PluginServices.getText(this, |
|
707 |
// "Introduce un dato numerico"), |
|
708 |
// PluginServices.getText(this, "Dato incorrecto"), |
|
709 |
// JOptionPane.WARNING_MESSAGE); |
|
710 |
// |
|
711 |
// jtvariable.setText(Double.toString(extrusionValue)); |
|
712 |
// jtfija.setText(Double.toString(extrusionFixedValue)); |
|
713 |
// } |
|
714 |
} |
|
715 |
} |
|
716 |
|
|
717 |
public void keyTyped(KeyEvent e) { |
|
718 |
// TODO Auto-generated method stub |
|
719 |
|
|
720 |
} |
|
721 |
|
|
722 |
public void itemStateChanged(ItemEvent e) { |
|
723 |
jtfija.setEnabled(fixedOption.isSelected()); |
|
724 |
jtvariable.setEnabled(!fixedOption.isSelected()); |
|
725 |
|
|
726 |
} |
|
727 |
|
|
728 |
} |
1.10/tags/gvSIG_3D_Animation_1_10_build_15/libraries/lib3DMap-share/src/main/java/com/iver/ai2/gvsig3d/legend/symbols/Object3DMarkerSymbol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
/* CVS MESSAGES: |
|
43 |
* |
|
44 |
* $Id: PictureMarkerSymbol.java 15593 2007-10-29 13:01:13Z jdominguez $ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.17 2007-09-21 12:25:32 jaume |
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level |
|
48 |
* |
|
49 |
* Revision 1.16 2007/09/19 16:22:04 jaume |
|
50 |
* removed unnecessary imports |
|
51 |
* |
|
52 |
* Revision 1.15 2007/09/11 07:46:55 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.14 2007/08/16 06:55:19 jvidal |
|
56 |
* javadoc updated |
|
57 |
* |
|
58 |
* Revision 1.13 2007/08/09 06:42:24 jvidal |
|
59 |
* javadoc |
|
60 |
* |
|
61 |
* Revision 1.12 2007/08/08 12:05:17 jvidal |
|
62 |
* javadoc |
|
63 |
* |
|
64 |
* Revision 1.11 2007/07/18 06:54:35 jaume |
|
65 |
* continuing with cartographic support |
|
66 |
* |
|
67 |
* Revision 1.10 2007/07/03 10:58:29 jaume |
|
68 |
* first refactor on CartographicSupport |
|
69 |
* |
|
70 |
* Revision 1.9 2007/06/29 13:07:01 jaume |
|
71 |
* +PictureLineSymbol |
|
72 |
* |
|
73 |
* Revision 1.8 2007/06/11 12:25:48 jaume |
|
74 |
* ISymbol drawing integration tests (markers and lines) |
|
75 |
* |
|
76 |
* Revision 1.7 2007/06/07 06:50:40 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.6 2007/05/29 15:46:37 jaume |
|
80 |
* *** empty log message *** |
|
81 |
* |
Also available in: Unified diff