root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / VectorialUniqueValue.java @ 31169
History | View | Annotate | Download (22.6 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.cit.gvsig.project.documents.view.legend.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Component; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.GridLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.util.ArrayList; |
51 |
import java.util.Random; |
52 |
|
53 |
import javax.swing.BoxLayout; |
54 |
import javax.swing.DefaultComboBoxModel; |
55 |
import javax.swing.ImageIcon; |
56 |
import javax.swing.JCheckBox; |
57 |
import javax.swing.JComboBox; |
58 |
import javax.swing.JLabel; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
|
62 |
import org.apache.log4j.Logger; |
63 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
64 |
import org.gvsig.gui.beans.swing.JBlank; |
65 |
import org.gvsig.gui.beans.swing.JButton; |
66 |
import org.gvsig.raster.datastruct.ColorItem; |
67 |
|
68 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
69 |
import com.hardcode.gdbms.engine.data.DataSource; |
70 |
import com.hardcode.gdbms.engine.values.NullValue; |
71 |
import com.hardcode.gdbms.engine.values.Value; |
72 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
73 |
import com.iver.andami.PluginServices; |
74 |
import com.iver.andami.messages.NotificationManager; |
75 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
76 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
78 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
79 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
82 |
import com.iver.cit.gvsig.fmap.rendering.AbstractClassifiedVectorLegend; |
83 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
84 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
85 |
import com.iver.cit.gvsig.fmap.rendering.NullUniqueValue; |
86 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
87 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
88 |
import com.iver.cit.gvsig.gui.styling.JComboBoxColorScheme; |
89 |
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow; |
90 |
|
91 |
|
92 |
/**
|
93 |
* DOCUMENT ME!
|
94 |
*
|
95 |
* @author fjp To change the template for this generated type comment go to
|
96 |
* Window>Preferences>Java>Code Generation>Code and
|
97 |
* Comments
|
98 |
*/
|
99 |
public class VectorialUniqueValue extends JPanel implements ILegendPanel, ActionListener{ |
100 |
private static Logger logger = Logger.getLogger(VectorialUniqueValue.class.getName()); |
101 |
|
102 |
protected VectorialUniqueValueLegend theLegend;
|
103 |
private ClassifiableVectorial layer;
|
104 |
private SymbolTable symbolTable;
|
105 |
protected JComboBox cmbFields; |
106 |
private JButton btnRemoveAll; |
107 |
private JButton btnRemove; |
108 |
private JButton moveUp; |
109 |
private JButton moveDown; |
110 |
private JCheckBox chbUseDefault = null; |
111 |
private JSymbolPreviewButton defaultSymbolPrev;
|
112 |
private VectorialUniqueValueLegend auxLegend;
|
113 |
private JPanel pnlCenter; |
114 |
private JPanel pnlMovBut; |
115 |
private JButton btnOpenSymbolLevelsEditor; |
116 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
117 |
|
118 |
private JComboBoxColorScheme cmbColorScheme;
|
119 |
|
120 |
/**
|
121 |
*
|
122 |
*/
|
123 |
public VectorialUniqueValue() {
|
124 |
super();
|
125 |
initComponents(); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* DOCUMENT ME!
|
130 |
*/
|
131 |
protected void initComponents() { |
132 |
|
133 |
JPanel pnlButtons = new JPanel(); |
134 |
|
135 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
136 |
"Anadir_todos"));
|
137 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
138 |
btnAddAll.addActionListener(this);
|
139 |
pnlButtons.add(btnAddAll); |
140 |
|
141 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
142 |
btnAdd.setActionCommand("ADD_VALUE");
|
143 |
btnAdd.addActionListener(this);
|
144 |
pnlButtons.add(btnAdd); |
145 |
|
146 |
btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos")); |
147 |
btnRemoveAll.setActionCommand("REMOVE_ALL");
|
148 |
btnRemoveAll.addActionListener(this);
|
149 |
pnlButtons.add(btnRemoveAll); |
150 |
|
151 |
btnRemove = new JButton(PluginServices.getText(this, "Quitar")); |
152 |
btnRemove.setActionCommand("REMOVE");
|
153 |
btnRemove.addActionListener(this);
|
154 |
pnlButtons.add(btnRemove); |
155 |
|
156 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
157 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
158 |
btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
|
159 |
pnlButtons.add(btnOpenSymbolLevelsEditor); |
160 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0); |
161 |
|
162 |
pnlCenter = new JPanel(); |
163 |
pnlCenter.setLayout(new BorderLayout()); |
164 |
|
165 |
cmbFields = new JComboBox(); |
166 |
cmbFields.setActionCommand("FIELD_SELECTED");
|
167 |
cmbFields.addActionListener(this);
|
168 |
cmbFields.setVisible(true);
|
169 |
|
170 |
JPanel pnlNorth = new JPanel(); |
171 |
pnlNorth.setLayout(new GridLayout(0,2)); |
172 |
|
173 |
GridBagLayoutPanel auxPanel = new GridBagLayoutPanel();
|
174 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText( |
175 |
this, "Campo_de_clasificacion")+": "); |
176 |
auxPanel.add(lblFieldClassification); |
177 |
auxPanel.add(cmbFields); |
178 |
pnlNorth.add(auxPanel); |
179 |
|
180 |
auxPanel = new GridBagLayoutPanel();
|
181 |
auxPanel.add(new JLabel(PluginServices.getText(this, "color_scheme")+": ")); |
182 |
cmbColorScheme = new JComboBoxColorScheme(false); |
183 |
cmbColorScheme.addActionListener(this);
|
184 |
auxPanel.add(cmbColorScheme); |
185 |
pnlNorth.add(auxPanel); |
186 |
|
187 |
|
188 |
defaultSymbolPanel.add(getChbUseDefault(), null);
|
189 |
pnlNorth.add(defaultSymbolPanel); |
190 |
pnlNorth.add(new JBlank(0,30)); |
191 |
|
192 |
this.setLayout(new BorderLayout()); |
193 |
this.add(pnlNorth, BorderLayout.NORTH); |
194 |
this.add(pnlCenter, BorderLayout.CENTER); |
195 |
this.add(pnlButtons, BorderLayout.SOUTH); |
196 |
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* DOCUMENT ME!
|
201 |
*/
|
202 |
private void fillTableValues() { |
203 |
DataSource elRs;
|
204 |
|
205 |
try {
|
206 |
elRs = ((FLyrVect) layer).getRecordset(); |
207 |
logger.debug("elRs.start()");
|
208 |
elRs.start(); |
209 |
|
210 |
int idField = -1; |
211 |
String fieldName = (String) cmbFields.getSelectedItem(); |
212 |
if (fieldName==null) { |
213 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_campo_seleccionado")); |
214 |
return;
|
215 |
} |
216 |
|
217 |
idField = elRs.getFieldIndexByName(fieldName); |
218 |
auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType()); |
219 |
auxLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol()); |
220 |
auxLegend.setClassifyingFieldNames(new String[] {fieldName}); |
221 |
|
222 |
//long numReg = elRs.getRowCount();
|
223 |
if (idField == -1) { |
224 |
NotificationManager.addWarning( |
225 |
PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null); |
226 |
|
227 |
return;
|
228 |
} |
229 |
|
230 |
symbolTable.removeAllItems(); |
231 |
|
232 |
int numSymbols = 0; |
233 |
ISymbol theSymbol = null;
|
234 |
|
235 |
//auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
|
236 |
// auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
|
237 |
|
238 |
Value clave; |
239 |
|
240 |
ColorItem[] colorScheme = cmbColorScheme.getSelectedColors();
|
241 |
|
242 |
Color[] colors = new Color[colorScheme.length]; |
243 |
for (int i = 0; i < colorScheme.length; i++) { |
244 |
colors[i] = colorScheme[i].getColor(); |
245 |
} |
246 |
auxLegend.setColorScheme(colors); |
247 |
|
248 |
|
249 |
Random rand = new Random(System.currentTimeMillis()); |
250 |
|
251 |
for (int j = 0; j < elRs.getRowCount(); j++) { |
252 |
clave = elRs.getFieldValue(j, idField); |
253 |
|
254 |
if (clave instanceof NullValue) { |
255 |
continue;
|
256 |
} |
257 |
|
258 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo.
|
259 |
if (auxLegend.getSymbolByValue(clave) == null) { |
260 |
//si no esta creado el simbolo se crea
|
261 |
// jaume (moved to ISymbol); theSymbol = new FSymbol(layer.getShapeType());
|
262 |
theSymbol = SymbologyFactory. |
263 |
createDefaultSymbolByShapeType(layer.getShapeType(), |
264 |
colorScheme[rand.nextInt(colorScheme.length)].getColor()); |
265 |
theSymbol.setDescription(clave.toString()); |
266 |
auxLegend.addSymbol(clave, theSymbol); |
267 |
|
268 |
numSymbols++; |
269 |
|
270 |
if (numSymbols == 100) { |
271 |
int resp = JOptionPane.showConfirmDialog(this, |
272 |
PluginServices.getText(this,
|
273 |
"mas_de_100_simbolos"),
|
274 |
PluginServices.getText(this, "quiere_continuar"), |
275 |
JOptionPane.YES_NO_OPTION,
|
276 |
JOptionPane.WARNING_MESSAGE);
|
277 |
|
278 |
if ((resp == JOptionPane.NO_OPTION) || |
279 |
(resp == JOptionPane.DEFAULT_OPTION)) {
|
280 |
return;
|
281 |
} |
282 |
} |
283 |
} |
284 |
} // for
|
285 |
|
286 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
287 |
auxLegend.getValues(),auxLegend.getDescriptions()); |
288 |
elRs.stop(); |
289 |
} catch (ReadDriverException e) {
|
290 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
291 |
} |
292 |
|
293 |
btnRemoveAll.setEnabled(true);
|
294 |
btnRemove.setEnabled(true);
|
295 |
|
296 |
//m_bCacheDirty = false;
|
297 |
} |
298 |
|
299 |
private boolean compareClassifyingFieldNames(String[] a, String[] b){ |
300 |
if (a==b) return true; |
301 |
if (a == null || b == null) return false; |
302 |
if (a.length != b.length) return false; |
303 |
for (int i=0; i<a.length; i++){ |
304 |
if (!a[i].equals(b[i])) return false; |
305 |
} |
306 |
return true; |
307 |
} |
308 |
|
309 |
private boolean compareClassifyingFieldTypes(int[] a, int[] b){ |
310 |
if (a==b) return true; |
311 |
if (a == null || b == null) return false; |
312 |
if (a.length != b.length) return false; |
313 |
for (int i=0; i<a.length; i++){ |
314 |
if (a[i]!=b[i]) return false; |
315 |
} |
316 |
return true; |
317 |
} |
318 |
/**
|
319 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo
|
320 |
* el symbolList, si no tambi?n el arrayKeys y el defaultRenderer
|
321 |
*/
|
322 |
private void fillSymbolListFromTable() { |
323 |
Value clave; |
324 |
ISymbol theSymbol; |
325 |
ArrayList<Value> visitedKeys = new ArrayList(); |
326 |
boolean changedLegend = false; |
327 |
|
328 |
String fieldName = (String) cmbFields.getSelectedItem(); |
329 |
String[] classifyingFieldNames = new String[] {fieldName}; |
330 |
if(auxLegend!=null){ |
331 |
if(!compareClassifyingFieldNames(classifyingFieldNames,auxLegend.getClassifyingFieldNames())){
|
332 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
333 |
changedLegend = true;
|
334 |
} |
335 |
} else {
|
336 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
337 |
changedLegend = true;
|
338 |
} |
339 |
|
340 |
FLyrVect m = (FLyrVect) layer; |
341 |
try {
|
342 |
// int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
|
343 |
int fieldType = m.getRecordset().getFieldType((int)cmbFields.getSelectedIndex()); |
344 |
int[] classifyingFieldTypes = new int[] {fieldType}; |
345 |
if(auxLegend!=null){ |
346 |
if(!compareClassifyingFieldTypes(classifyingFieldTypes,auxLegend.getClassifyingFieldTypes())){
|
347 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
348 |
changedLegend = true;
|
349 |
} |
350 |
} else {
|
351 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
352 |
changedLegend = true;
|
353 |
} |
354 |
} catch (ReadDriverException e) {
|
355 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e); |
356 |
} catch (Exception e) { |
357 |
NotificationManager.showMessageWarning(PluginServices.getText(this, "could_not_setup_legend"), e); |
358 |
} |
359 |
|
360 |
if(changedLegend){
|
361 |
auxLegend.clear(); |
362 |
} |
363 |
|
364 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
365 |
clave = (Value) symbolTable.getFieldValue(row, 1);
|
366 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
367 |
String description = (String) symbolTable.getFieldValue(row, 2); |
368 |
theSymbol.setDescription(description); |
369 |
ISymbol legendSymbol = null;
|
370 |
if (auxLegend != null){ |
371 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
372 |
} |
373 |
if( legendSymbol == null || ( auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())){ |
374 |
if (auxLegend != null){ |
375 |
auxLegend.addSymbol(clave, theSymbol); |
376 |
} |
377 |
} else {
|
378 |
/* FIXME: Se optimizar?a descomentarizando el if, pero el metodo equals del AbstractSymbol
|
379 |
* no tiene en cuenta determinadas propiedades del simbolo, como, por ejemplo, el tama?o.
|
380 |
* Descomentarizar al arreglar el metodo equals del AbstractSymbol.
|
381 |
*/
|
382 |
// if(!legendSymbol.equals(theSymbol)){
|
383 |
auxLegend.replace(legendSymbol, theSymbol); |
384 |
// }
|
385 |
} |
386 |
visitedKeys.add(clave); |
387 |
} |
388 |
if(auxLegend != null){ |
389 |
Object[] keys = auxLegend.getValues(); |
390 |
for(int i=0; i<keys.length; i++){ |
391 |
Object key = keys[i];
|
392 |
if(!visitedKeys.contains(key)){
|
393 |
auxLegend.delSymbol(key); |
394 |
} |
395 |
} |
396 |
} |
397 |
|
398 |
clave = new NullUniqueValue();
|
399 |
if(chbUseDefault.isSelected()){
|
400 |
theSymbol = defaultSymbolPrev.getSymbol(); |
401 |
if(theSymbol != null){ |
402 |
String description = PluginServices.getText(this,"default"); |
403 |
theSymbol.setDescription(description); |
404 |
ISymbol legendSymbol = null;
|
405 |
if (auxLegend != null){ |
406 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
407 |
} |
408 |
if( legendSymbol == null){ |
409 |
auxLegend.addSymbol(clave, theSymbol); |
410 |
} else {
|
411 |
// if(!legendSymbol.equals(theSymbol)){
|
412 |
if(legendSymbol!=theSymbol){
|
413 |
auxLegend.replace(legendSymbol, theSymbol); |
414 |
} |
415 |
} |
416 |
} |
417 |
} else {
|
418 |
if (auxLegend != null){ |
419 |
ISymbol legendSymbol = auxLegend.getSymbolByValue(clave); |
420 |
if( legendSymbol != null){ |
421 |
auxLegend.replace(legendSymbol, null);
|
422 |
} |
423 |
} |
424 |
} |
425 |
} |
426 |
|
427 |
/**
|
428 |
* DOCUMENT ME!
|
429 |
*/
|
430 |
private void fillFieldNames() { |
431 |
DataSource rs;
|
432 |
|
433 |
try {
|
434 |
// rs = ((FLyrVect) layer).getSource().getRecordset();
|
435 |
rs = ((FLyrVect) layer).getRecordset(); // Todos los campos, tambi?n los de uniones
|
436 |
logger.debug("rs.start()");
|
437 |
rs.start(); |
438 |
int fieldCount=rs.getFieldCount();
|
439 |
String[] nomFields = new String[fieldCount]; |
440 |
|
441 |
for (int i = 0; i < fieldCount; i++) { |
442 |
nomFields[i] = rs.getFieldName(i).trim(); |
443 |
} |
444 |
|
445 |
rs.stop(); |
446 |
|
447 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(nomFields); |
448 |
cmbFields.setModel(cM); |
449 |
|
450 |
// fieldsListValor.setSelectedIndex(0);
|
451 |
} catch (ReadDriverException e) {
|
452 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
453 |
} |
454 |
} |
455 |
|
456 |
public void setData(FLayer layer, ILegend legend) { |
457 |
this.layer = (ClassifiableVectorial) layer;
|
458 |
int shapeType = 0; |
459 |
try {
|
460 |
shapeType = this.layer.getShapeType();
|
461 |
} catch (ReadDriverException e) {
|
462 |
NotificationManager.addError(PluginServices.getText(this, "accessing_to_the_layer"), e); |
463 |
} |
464 |
|
465 |
getDefaultSymbolPrev(shapeType); |
466 |
|
467 |
|
468 |
if (symbolTable != null) |
469 |
pnlCenter.remove(symbolTable); |
470 |
if(pnlMovBut != null) |
471 |
pnlCenter.remove(pnlMovBut); |
472 |
|
473 |
symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType); |
474 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
475 |
pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
|
476 |
|
477 |
fillFieldNames(); |
478 |
|
479 |
symbolTable.removeAllItems(); |
480 |
|
481 |
if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
|
482 |
try {
|
483 |
auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
484 |
//FIXME: parche
|
485 |
ZSort legendZSort = ((VectorialUniqueValueLegend) legend).getZSort(); |
486 |
if(legendZSort != null){ |
487 |
ZSort auxZSort = new ZSort(auxLegend);
|
488 |
auxZSort.copyLevels(legendZSort); |
489 |
auxZSort.setUsingZSort(legendZSort.isUsingZSort()); |
490 |
auxLegend.setZSort(auxZSort); |
491 |
} |
492 |
//Fin del parche
|
493 |
} catch (XMLException e) {
|
494 |
// TODO Auto-generated catch block
|
495 |
e.printStackTrace(); |
496 |
} |
497 |
getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol()); |
498 |
cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
499 |
setColorScheme(); |
500 |
symbolTable.fillTableFromSymbolList(auxLegend.getSymbols(), |
501 |
auxLegend.getValues(),auxLegend.getDescriptions()); |
502 |
chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol()); |
503 |
} else {
|
504 |
auxLegend = new VectorialUniqueValueLegend(shapeType);
|
505 |
} |
506 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
507 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0); |
508 |
} |
509 |
|
510 |
|
511 |
private JPanel getPnlMovBut() { |
512 |
if(pnlMovBut == null){ |
513 |
pnlMovBut = new JPanel(); |
514 |
pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS)); |
515 |
pnlMovBut.add(new JBlank(1, 70)); |
516 |
pnlMovBut.add(moveUp = new JButton(PluginServices.getIconTheme().get("up-arrow"))); |
517 |
moveUp.setSize(new Dimension(15,15)); |
518 |
pnlMovBut.add(new JBlank(1,10)); |
519 |
pnlMovBut.add(moveDown = new JButton(PluginServices.getIconTheme().get("down-arrow"))); |
520 |
pnlMovBut.add(new JBlank(1, 70)); |
521 |
moveDown.setActionCommand("MOVE-DOWN");
|
522 |
moveUp.setActionCommand("MOVE-UP");
|
523 |
moveDown.addActionListener(this);
|
524 |
moveUp.addActionListener(this);
|
525 |
} |
526 |
return pnlMovBut;
|
527 |
} |
528 |
|
529 |
private void setColorScheme(){ |
530 |
|
531 |
if(auxLegend.getColorScheme() != null) { |
532 |
ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length]; |
533 |
for (int i = 0; i < auxLegend.getColorScheme().length; i++) { |
534 |
colors[i] = new ColorItem();
|
535 |
colors[i].setColor(auxLegend.getColorScheme()[i]); |
536 |
} |
537 |
cmbColorScheme.setSelectedColors(colors); |
538 |
} |
539 |
} |
540 |
|
541 |
|
542 |
|
543 |
private void getDefaultSymbolPrev(int shapeType) { |
544 |
if(defaultSymbolPrev == null){ |
545 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
546 |
defaultSymbolPrev.setPreferredSize(new Dimension(110,20)); |
547 |
defaultSymbolPrev.addActionListener(this);
|
548 |
defaultSymbolPanel.add(defaultSymbolPrev,null);
|
549 |
} |
550 |
} |
551 |
|
552 |
/* (non-Javadoc)
|
553 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
554 |
*/
|
555 |
public ILegend getLegend() {
|
556 |
fillSymbolListFromTable(); |
557 |
|
558 |
if (auxLegend != null) { |
559 |
// your settings that are not the set of symbols must be located here
|
560 |
// auxLegend.setClassifyingFieldNames(
|
561 |
// new String[] {(String) cmbFields.getSelectedItem()});
|
562 |
|
563 |
ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol(); |
564 |
ISymbol symbol = defaultSymbolPrev.getSymbol(); |
565 |
if(symbol != null){ |
566 |
if(symbol!=defaultSymbolLegend){
|
567 |
auxLegend.setDefaultSymbol(symbol); |
568 |
} |
569 |
} |
570 |
auxLegend.useDefaultSymbol(chbUseDefault.isSelected()); |
571 |
|
572 |
try {
|
573 |
theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend(); |
574 |
} catch (XMLException e) {
|
575 |
// TODO Auto-generated catch block
|
576 |
e.printStackTrace(); |
577 |
} |
578 |
//FIXME: parche
|
579 |
ZSort auxZSort = ((VectorialUniqueValueLegend) auxLegend).getZSort(); |
580 |
if(auxZSort != null){ |
581 |
ZSort legendZSort = new ZSort(theLegend);
|
582 |
legendZSort.copyLevels(auxZSort); |
583 |
legendZSort.setUsingZSort(auxZSort.isUsingZSort()); |
584 |
theLegend.setZSort(legendZSort); |
585 |
} |
586 |
//Fin del parche
|
587 |
} |
588 |
|
589 |
return theLegend;
|
590 |
} |
591 |
|
592 |
private JCheckBox getChbUseDefault() { |
593 |
if (chbUseDefault == null) { |
594 |
chbUseDefault = new JCheckBox(); |
595 |
chbUseDefault.setSelected(false);
|
596 |
chbUseDefault.addActionListener(new java.awt.event.ActionListener() {
|
597 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
598 |
if (chbUseDefault.isSelected()) {
|
599 |
auxLegend.useDefaultSymbol(true);
|
600 |
} else {
|
601 |
auxLegend.useDefaultSymbol(false);
|
602 |
} |
603 |
} |
604 |
}); |
605 |
chbUseDefault.setText(PluginServices.getText(this, "resto_valores")+ ": "); |
606 |
} |
607 |
|
608 |
return chbUseDefault;
|
609 |
} |
610 |
|
611 |
public void actionPerformed(ActionEvent e) { |
612 |
int[] indices = null; |
613 |
|
614 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
615 |
if(!auxLegend.isOwnOrder()){
|
616 |
auxLegend.setOwnOrder(true);
|
617 |
} |
618 |
indices = symbolTable.getSelectedRows(); |
619 |
} |
620 |
|
621 |
if(e.getActionCommand() == "MOVE-UP"){ |
622 |
if (indices.length>0) { |
623 |
int classIndex = indices[0]; |
624 |
int targetPos = Math.max(0, classIndex-1); |
625 |
symbolTable.moveUpRows(classIndex, targetPos,indices.length); |
626 |
} |
627 |
} |
628 |
|
629 |
if(e.getActionCommand() == "MOVE-DOWN"){ |
630 |
if (indices.length>0) { |
631 |
int classIndex = indices[indices.length-1]; |
632 |
int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1); |
633 |
symbolTable.moveDownRows(classIndex, targetPos,indices.length); |
634 |
} |
635 |
} |
636 |
|
637 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
638 |
ArrayList orders = new ArrayList(); |
639 |
|
640 |
for (int i = 0; i < symbolTable.getRowCount(); i++) { |
641 |
orders.add(symbolTable.getFieldValue(i,1).toString());
|
642 |
} |
643 |
auxLegend.setOrders(orders); |
644 |
|
645 |
|
646 |
|
647 |
} |
648 |
|
649 |
//modificar el combobox de valor
|
650 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
651 |
JComboBox cb = (JComboBox) e.getSource(); |
652 |
String fieldName = (String) cb.getSelectedItem(); |
653 |
symbolTable.removeAllItems(); |
654 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
655 |
} |
656 |
|
657 |
// add all elements by value
|
658 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
659 |
fillTableValues(); |
660 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount()>0); |
661 |
} |
662 |
|
663 |
// add only one value
|
664 |
if (e.getActionCommand() == "ADD_VALUE") { |
665 |
try {
|
666 |
ISymbol symbol = SymbologyFactory.createDefaultSymbolByShapeType(layer.getShapeType()); |
667 |
Value clave = ValueFactory.createValue(0.0);
|
668 |
symbolTable.addTableRecord(symbol, |
669 |
clave,"0 - 0");
|
670 |
btnOpenSymbolLevelsEditor.setEnabled(true);
|
671 |
} catch (ReadDriverException ex) {
|
672 |
NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex); |
673 |
} |
674 |
} |
675 |
|
676 |
//Vacia la tabla
|
677 |
if (e.getActionCommand() == "REMOVE_ALL") { |
678 |
symbolTable.removeAllItems(); |
679 |
auxLegend.setZSort(null);
|
680 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
681 |
} |
682 |
|
683 |
//Quitar solo el elemento seleccionado
|
684 |
if (e.getActionCommand() == "REMOVE") { |
685 |
symbolTable.removeSelectedRows(); |
686 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount()>0);
|
687 |
} |
688 |
|
689 |
if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") { |
690 |
ZSort myZSort = null;
|
691 |
if (auxLegend != null) { |
692 |
myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort(); |
693 |
if(myZSort == null){ |
694 |
myZSort = new ZSort(auxLegend);
|
695 |
} |
696 |
} |
697 |
if (myZSort == null && theLegend != null) { |
698 |
myZSort = new ZSort(theLegend);
|
699 |
} |
700 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
701 |
PluginServices.getMDIManager().addWindow(sl); |
702 |
auxLegend.setZSort(sl.getZSort()); |
703 |
} |
704 |
} |
705 |
|
706 |
|
707 |
public String getDescription() { |
708 |
return PluginServices.getText(this,"Dado_un_campo_de_atributos") + ", " + PluginServices.getText(this,"muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico").toLowerCase() + "."; |
709 |
} |
710 |
|
711 |
public ImageIcon getIcon() { |
712 |
return new ImageIcon(this.getClass().getClassLoader(). |
713 |
getResource("images/ValoresUnicos.png"));
|
714 |
} |
715 |
|
716 |
public Class getParentClass() { |
717 |
return Categories.class;
|
718 |
} |
719 |
|
720 |
public String getTitle() { |
721 |
return PluginServices.getText(this,"Valores_unicos"); |
722 |
} |
723 |
|
724 |
public JPanel getPanel() { |
725 |
return this; |
726 |
} |
727 |
|
728 |
public Class getLegendClass() { |
729 |
return VectorialUniqueValueLegend.class;
|
730 |
} |
731 |
|
732 |
|
733 |
public boolean isSuitableFor(FLayer layer) { |
734 |
return (layer instanceof FLyrVect); |
735 |
} |
736 |
|
737 |
} |