svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / VectorialUniqueValue.java @ 44909
History | View | Annotate | Download (27.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.legend.gui; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Color; |
28 |
import java.awt.Component; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.GridLayout; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.util.ArrayList; |
34 |
import java.util.Iterator; |
35 |
import java.util.Random; |
36 |
|
37 |
import javax.swing.DefaultComboBoxModel; |
38 |
import javax.swing.ImageIcon; |
39 |
import javax.swing.JCheckBox; |
40 |
import javax.swing.JComboBox; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JPanel; |
44 |
|
45 |
import org.gvsig.andami.IconThemeHelper; |
46 |
import org.gvsig.andami.PluginServices; |
47 |
import org.gvsig.andami.messages.NotificationManager; |
48 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
49 |
import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
50 |
import org.gvsig.fmap.dal.exception.DataException; |
51 |
import org.gvsig.fmap.dal.exception.ReadException; |
52 |
import org.gvsig.fmap.dal.feature.Feature; |
53 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
54 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
56 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
57 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
58 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
59 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
61 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
62 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
63 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
64 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
65 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
66 |
import org.gvsig.gui.beans.swing.JBlank; |
67 |
import org.gvsig.gui.beans.swing.JButton; |
68 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend; |
69 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
70 |
import org.gvsig.tools.dispose.DisposableIterator; |
71 |
import org.slf4j.Logger; |
72 |
import org.slf4j.LoggerFactory; |
73 |
|
74 |
/**
|
75 |
* DOCUMENT ME!
|
76 |
*
|
77 |
* @author fjp To change the template for this generated type comment go to
|
78 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
79 |
*/
|
80 |
public class VectorialUniqueValue extends JPanel implements ILegendPanel, ActionListener { |
81 |
|
82 |
private static final Logger logger = LoggerFactory |
83 |
.getLogger(VectorialUniqueValue.class); |
84 |
|
85 |
protected VectorialUniqueValueLegend theLegend;
|
86 |
private ClassifiableVectorial layer;
|
87 |
private SymbolTable symbolTable;
|
88 |
protected JComboBox cmbFields; |
89 |
private JButton btnRemoveAll; |
90 |
private JButton btnRemove; |
91 |
private JCheckBox chbUseDefault = null; |
92 |
private JSymbolPreviewButton defaultSymbolPrev;
|
93 |
private VectorialUniqueValueLegend auxLegend;
|
94 |
private JPanel pnlCenter; |
95 |
private JButton btnOpenSymbolLevelsEditor; |
96 |
|
97 |
private JComboBoxColorScheme cmbColorScheme;
|
98 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
99 |
|
100 |
private MapContextManager mapContextManager = MapContextLocator
|
101 |
.getMapContextManager(); |
102 |
|
103 |
/**
|
104 |
*
|
105 |
*/
|
106 |
public VectorialUniqueValue() {
|
107 |
super();
|
108 |
initComponents(); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* DOCUMENT ME!
|
113 |
*/
|
114 |
protected void initComponents() { |
115 |
JPanel pnlButtons = new JPanel(); |
116 |
|
117 |
JButton btnAddAll = new JButton(PluginServices.getText(this, |
118 |
"Anadir_todos"));
|
119 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
120 |
btnAddAll.addActionListener(this);
|
121 |
pnlButtons.add(btnAddAll); |
122 |
|
123 |
JButton btnAdd = new JButton(PluginServices.getText(this, "Anadir")); |
124 |
btnAdd.setActionCommand("ADD_VALUE");
|
125 |
btnAdd.addActionListener(this);
|
126 |
pnlButtons.add(btnAdd); |
127 |
|
128 |
btnRemoveAll = new JButton(PluginServices.getText(this, "Quitar_todos")); |
129 |
btnRemoveAll.setActionCommand("REMOVE_ALL");
|
130 |
btnRemoveAll.addActionListener(this);
|
131 |
pnlButtons.add(btnRemoveAll); |
132 |
|
133 |
btnRemove = new JButton(PluginServices.getText(this, "Quitar")); |
134 |
btnRemove.setActionCommand("REMOVE");
|
135 |
btnRemove.addActionListener(this);
|
136 |
pnlButtons.add(btnRemove); |
137 |
|
138 |
btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels")); |
139 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
140 |
btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
|
141 |
pnlButtons.add(btnOpenSymbolLevelsEditor); |
142 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
143 |
|
144 |
pnlCenter = new JPanel(); |
145 |
pnlCenter.setLayout(new BorderLayout()); |
146 |
|
147 |
cmbFields = new JComboBox(); |
148 |
cmbFields.setActionCommand("FIELD_SELECTED");
|
149 |
cmbFields.addActionListener(this);
|
150 |
cmbFields.setVisible(true);
|
151 |
|
152 |
JPanel pnlNorth = new JPanel(); |
153 |
pnlNorth.setLayout(new GridLayout(0, 2)); |
154 |
|
155 |
GridBagLayoutPanel auxPanel = new GridBagLayoutPanel();
|
156 |
JLabel lblFieldClassification = new JLabel(PluginServices.getText( |
157 |
this, "Campo_de_clasificacion") + ": "); |
158 |
auxPanel.add(lblFieldClassification); |
159 |
auxPanel.add(cmbFields); |
160 |
pnlNorth.add(auxPanel); |
161 |
|
162 |
auxPanel = new GridBagLayoutPanel();
|
163 |
auxPanel.add(new JLabel(PluginServices.getText(this, "color_scheme") + ": ")); |
164 |
cmbColorScheme = new JComboBoxColorScheme(false); |
165 |
cmbColorScheme.addActionListener(this);
|
166 |
auxPanel.add(cmbColorScheme); |
167 |
pnlNorth.add(auxPanel); |
168 |
|
169 |
defaultSymbolPanel.add(getChbUseDefault(), null);
|
170 |
pnlNorth.add(defaultSymbolPanel); |
171 |
pnlNorth.add(new JBlank(0, 30)); |
172 |
|
173 |
this.setLayout(new BorderLayout()); |
174 |
this.add(pnlNorth, BorderLayout.NORTH); |
175 |
this.add(pnlCenter, BorderLayout.CENTER); |
176 |
this.add(pnlButtons, BorderLayout.SOUTH); |
177 |
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* DOCUMENT ME!
|
182 |
*/
|
183 |
private void fillTableValues() { |
184 |
FeatureStore elRs; |
185 |
|
186 |
try {
|
187 |
elRs = ((FLyrVect) layer).getFeatureStore(); |
188 |
// logger.debug("elRs.start()");
|
189 |
// elRs.start();
|
190 |
|
191 |
// int idField = -1;
|
192 |
String fieldName = (String) cmbFields.getSelectedItem(); |
193 |
if (fieldName == null) { |
194 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "no_hay_campo_seleccionado")); |
195 |
return;
|
196 |
} |
197 |
|
198 |
// idField = elRs.getFieldIndexByName(fieldName);
|
199 |
auxLegend.setClassifyingFieldNames(new String[]{fieldName}); |
200 |
|
201 |
//long numReg = elRs.getRowCount();
|
202 |
// if (idField == -1) {
|
203 |
// NotificationManager.addWarning(
|
204 |
// PluginServices.getText(this, "unrecognized_field_name")+" " + fieldName, null);
|
205 |
//
|
206 |
// return;
|
207 |
// }
|
208 |
symbolTable.removeAllItems(); |
209 |
|
210 |
int numSymbols = 0; |
211 |
ISymbol theSymbol = null;
|
212 |
|
213 |
//auxLegend=(VectorialUniqueValueLegend)m_lyr.getLegend();
|
214 |
// auxLegend = LegendFactory.createVectorialUniqueValueLegend(layer.getShapeType());
|
215 |
auxLegend = (VectorialUniqueValueLegend) MapContextLocator |
216 |
.getMapContextManager().createLegend( |
217 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
218 |
auxLegend.setShapeType(layer.getShapeType()); |
219 |
|
220 |
Object clave = null; |
221 |
|
222 |
//Object resul;
|
223 |
if (chbUseDefault.isSelected()) {
|
224 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
225 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
|
226 |
} |
227 |
|
228 |
Color[] colorScheme = cmbColorScheme.getSelectedColors(); |
229 |
|
230 |
Color[] colors = new Color[colorScheme.length]; |
231 |
for (int i = 0; i < colorScheme.length; i++) { |
232 |
colors[i] = colorScheme[i]; |
233 |
} |
234 |
auxLegend.setColorScheme(colors); |
235 |
|
236 |
Random rand = new Random(System.currentTimeMillis()); |
237 |
|
238 |
FeatureSet set = null;
|
239 |
DisposableIterator iterator = null;
|
240 |
|
241 |
try {
|
242 |
set = elRs.getFeatureSet(); |
243 |
|
244 |
int count = 0; |
245 |
|
246 |
iterator = set.fastIterator(); |
247 |
while (iterator.hasNext()) {
|
248 |
Feature feature = (Feature) iterator.next(); |
249 |
clave = feature.get(fieldName); |
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 |
if (clave == null) { |
258 |
continue;
|
259 |
} |
260 |
|
261 |
// //Comprobar que no esta repetido y no hace falta
|
262 |
// introducir en el hashtable el campo junto con el simbolo.
|
263 |
if (auxLegend.getSymbolByValue(clave) == null) { |
264 |
|
265 |
if (count == 100) { |
266 |
int resp = JOptionPane.showConfirmDialog(this, |
267 |
PluginServices.getText(this,
|
268 |
"mas_de_100_simbolos"),
|
269 |
PluginServices.getText(this,
|
270 |
"quiere_continuar"),
|
271 |
JOptionPane.YES_NO_OPTION,
|
272 |
JOptionPane.WARNING_MESSAGE);
|
273 |
|
274 |
if ((resp == JOptionPane.NO_OPTION) |
275 |
|| (resp == JOptionPane.DEFAULT_OPTION)) {
|
276 |
break;
|
277 |
} |
278 |
} |
279 |
|
280 |
// si no esta creado el simbolo se crea
|
281 |
// jaume (moved to ISymbol); theSymbol = new
|
282 |
// FSymbol(layer.getShapeType());
|
283 |
theSymbol |
284 |
= mapContextManager.getSymbolManager() |
285 |
.createSymbol( |
286 |
layer |
287 |
.getShapeType(), colorScheme[rand |
288 |
.nextInt(colorScheme.length)]); |
289 |
theSymbol.setDescription(clave.toString()); |
290 |
auxLegend.addSymbol(clave, theSymbol); |
291 |
count++; |
292 |
} |
293 |
|
294 |
} // for
|
295 |
} finally {
|
296 |
if (iterator != null) { |
297 |
iterator.dispose(); |
298 |
} |
299 |
if (set != null) { |
300 |
set.dispose(); |
301 |
} |
302 |
} |
303 |
|
304 |
Object[] values = auxLegend.getValues(); |
305 |
String[] descriptions = new String[values.length]; |
306 |
ISymbol[] symbols = new ISymbol[values.length]; |
307 |
|
308 |
for (int i = 0; i < values.length; i++) { |
309 |
Object value = values[i];
|
310 |
symbols[i] = auxLegend.getSymbolByValue(value); |
311 |
descriptions[i] = symbols[i].getDescription(); |
312 |
} |
313 |
|
314 |
symbolTable.fillTableFromSymbolList(symbols, |
315 |
values, descriptions); |
316 |
// elRs.stop();
|
317 |
// set.dispose();
|
318 |
} catch (DataException e) {
|
319 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
320 |
} |
321 |
|
322 |
btnRemoveAll.setEnabled(true);
|
323 |
btnRemove.setEnabled(true);
|
324 |
|
325 |
//m_bCacheDirty = false;
|
326 |
} |
327 |
|
328 |
private boolean compareClassifyingFieldNames(String[] a, String[] b) { |
329 |
if (a == b) {
|
330 |
return true; |
331 |
} |
332 |
if (a == null || b == null) { |
333 |
return false; |
334 |
} |
335 |
if (a.length != b.length) {
|
336 |
return false; |
337 |
} |
338 |
for (int i = 0; i < a.length; i++) { |
339 |
if (!a[i].equals(b[i])) {
|
340 |
return false; |
341 |
} |
342 |
} |
343 |
return true; |
344 |
} |
345 |
|
346 |
private boolean compareClassifyingFieldTypes(int[] a, int[] b) { |
347 |
if (a == b) {
|
348 |
return true; |
349 |
} |
350 |
if (a == null || b == null) { |
351 |
return false; |
352 |
} |
353 |
if (a.length != b.length) {
|
354 |
return false; |
355 |
} |
356 |
for (int i = 0; i < a.length; i++) { |
357 |
if (a[i] != b[i]) {
|
358 |
return false; |
359 |
} |
360 |
} |
361 |
return true; |
362 |
} |
363 |
|
364 |
/**
|
365 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo el
|
366 |
* symbolList, si no tambi�n el arrayKeys y el defaultRenderer
|
367 |
*/
|
368 |
private void fillSymbolListFromTable() { |
369 |
Object clave = null; |
370 |
ISymbol theSymbol; |
371 |
ArrayList visitedKeys = new ArrayList(); |
372 |
boolean changedLegend = false; |
373 |
|
374 |
String fieldName = (String) cmbFields.getSelectedItem(); |
375 |
String[] classifyingFieldNames = new String[]{fieldName}; |
376 |
if (auxLegend != null) { |
377 |
if (!compareClassifyingFieldNames(classifyingFieldNames, auxLegend.getClassifyingFieldNames())) {
|
378 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
379 |
changedLegend = true;
|
380 |
} |
381 |
} else {
|
382 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
383 |
changedLegend = true;
|
384 |
} |
385 |
|
386 |
FLyrVect m = (FLyrVect) layer; |
387 |
|
388 |
try {
|
389 |
int fieldType = m.getFeatureStore().getDefaultFeatureType()
|
390 |
.getAttributeDescriptor(cmbFields.getSelectedIndex()) |
391 |
.getType(); |
392 |
// int fieldType = m.getSource().getRecordset().getFieldType((int)cmbFields.getSelectedIndex());
|
393 |
int[] classifyingFieldTypes = new int[]{fieldType}; |
394 |
if (auxLegend != null) { |
395 |
if (!compareClassifyingFieldTypes(classifyingFieldTypes, auxLegend.getClassifyingFieldTypes())) {
|
396 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
397 |
changedLegend = true;
|
398 |
} |
399 |
} else {
|
400 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
401 |
changedLegend = true;
|
402 |
} |
403 |
} catch (DataException e) {
|
404 |
NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e); |
405 |
} catch (Exception e) { |
406 |
NotificationManager.showMessageWarning(PluginServices.getText(this, "could_not_setup_legend"), e); |
407 |
} |
408 |
|
409 |
if (changedLegend) {
|
410 |
auxLegend.clear(); |
411 |
} |
412 |
|
413 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
414 |
clave = symbolTable.getFieldValue(row, 1);
|
415 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
416 |
String description = (String) symbolTable.getFieldValue(row, 2); |
417 |
theSymbol.setDescription(description); |
418 |
ISymbol legendSymbol = null;
|
419 |
if (auxLegend != null) { |
420 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
421 |
} |
422 |
if (legendSymbol == null || (auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())) { |
423 |
if (auxLegend != null) { |
424 |
auxLegend.addSymbol(clave, theSymbol); |
425 |
} |
426 |
} else {
|
427 |
|
428 |
// avoid same instance
|
429 |
if (legendSymbol != theSymbol) {
|
430 |
|
431 |
/*
|
432 |
* Perhaps use this "if" when implementations of ISymbol
|
433 |
* properly implement the equals method.
|
434 |
*/
|
435 |
// if (!legendSymbol.equals(theSymbol)) {
|
436 |
auxLegend.replace(legendSymbol, theSymbol); |
437 |
// }
|
438 |
} |
439 |
} |
440 |
visitedKeys.add(clave); |
441 |
} |
442 |
if (auxLegend != null) { |
443 |
Object[] keys = auxLegend.getValues(); |
444 |
for (int i = 0; i < keys.length; i++) { |
445 |
Object key = keys[i];
|
446 |
if (!visitedKeys.contains(key)) {
|
447 |
auxLegend.delSymbol(key); |
448 |
} |
449 |
} |
450 |
} |
451 |
clave = null;
|
452 |
if (chbUseDefault.isSelected()) {
|
453 |
theSymbol = defaultSymbolPrev.getSymbol(); |
454 |
if (theSymbol != null) { |
455 |
String description = PluginServices.getText(this, "default"); |
456 |
theSymbol.setDescription(description); |
457 |
ISymbol legendSymbol = null;
|
458 |
if (auxLegend != null) { |
459 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
460 |
} |
461 |
if (legendSymbol == null) { |
462 |
auxLegend.addSymbol(clave, theSymbol); |
463 |
} else {
|
464 |
// if(!legendSymbol.equals(theSymbol)){
|
465 |
if (legendSymbol != theSymbol) {
|
466 |
auxLegend.replace(legendSymbol, theSymbol); |
467 |
} |
468 |
} |
469 |
} |
470 |
} else {
|
471 |
if (auxLegend != null) { |
472 |
ISymbol legendSymbol = auxLegend.getSymbolByValue(clave); |
473 |
if (legendSymbol != null) { |
474 |
auxLegend.replace(legendSymbol, null);
|
475 |
} |
476 |
} |
477 |
} |
478 |
} |
479 |
|
480 |
/**
|
481 |
* DOCUMENT ME!
|
482 |
*/
|
483 |
private void fillFieldNames() { |
484 |
FeatureStore rs; |
485 |
|
486 |
try {
|
487 |
rs = ((FLyrVect) layer).getFeatureStore(); |
488 |
// logger.debug("rs.start()");
|
489 |
// rs.start();
|
490 |
|
491 |
ArrayList names = new ArrayList(); |
492 |
Iterator iterator = rs.getDefaultFeatureType().iterator();
|
493 |
while (iterator.hasNext()) {
|
494 |
FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next(); |
495 |
names.add(descriptor.getName()); |
496 |
} |
497 |
// String[] nomFields = new String[rs.getFieldCount()];
|
498 |
//
|
499 |
// for (int i = 0; i < rs.getFieldCount(); i++) {
|
500 |
// nomFields[i] = rs.getFieldName(i).trim();
|
501 |
// }
|
502 |
//
|
503 |
// rs.stop();
|
504 |
|
505 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0])); |
506 |
cmbFields.setModel(cM); |
507 |
|
508 |
// fieldsListValor.setSelectedIndex(0);
|
509 |
} catch (DataException e) {
|
510 |
NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e); |
511 |
} |
512 |
} |
513 |
|
514 |
public void setData(FLayer layer, ILegend legend) { |
515 |
this.layer = (ClassifiableVectorial) layer;
|
516 |
int shapeType = 0; |
517 |
try {
|
518 |
shapeType = this.layer.getShapeType();
|
519 |
} catch (ReadException e) {
|
520 |
NotificationManager.addError(PluginServices.getText(this, "generating_intervals"), e); |
521 |
} |
522 |
|
523 |
getDefaultSymbolPrev(shapeType); |
524 |
|
525 |
if (symbolTable != null) { |
526 |
pnlCenter.remove(symbolTable); |
527 |
} |
528 |
symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType); |
529 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
530 |
|
531 |
fillFieldNames(); |
532 |
|
533 |
symbolTable.removeAllItems(); |
534 |
|
535 |
if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
|
536 |
auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
537 |
getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol()); |
538 |
cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
539 |
setColorScheme(); |
540 |
|
541 |
Object[] values = auxLegend.getValues(); |
542 |
String[] descriptions = new String[values.length]; |
543 |
ISymbol[] symbols = new ISymbol[values.length]; |
544 |
|
545 |
for (int i = 0; i < values.length; i++) { |
546 |
Object value = values[i];
|
547 |
symbols[i] = auxLegend.getSymbolByValue(value); |
548 |
descriptions[i] = symbols[i].getDescription(); |
549 |
} |
550 |
|
551 |
symbolTable.fillTableFromSymbolList(symbols, |
552 |
values, descriptions); |
553 |
chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol()); |
554 |
} else {
|
555 |
auxLegend = new VectorialUniqueValueLegend(shapeType);
|
556 |
} |
557 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
558 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
559 |
} |
560 |
|
561 |
private void setColorScheme() { |
562 |
|
563 |
if (auxLegend.getColorScheme() != null) { |
564 |
Color[] colorScheme = auxLegend.getColorScheme(); |
565 |
// ColorItem[] colors = new ColorItem[auxLegend.getColorScheme().length];
|
566 |
// for (int i = 0; i < auxLegend.getColorScheme().length; i++) {
|
567 |
// colors[i] = new ColorItem();
|
568 |
// colors[i].setColor(auxLegend.getColorScheme()[i]);
|
569 |
// }
|
570 |
cmbColorScheme.setSelectedColors(colorScheme); |
571 |
} |
572 |
} |
573 |
|
574 |
private void getDefaultSymbolPrev(int shapeType) { |
575 |
if (defaultSymbolPrev == null) { |
576 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
577 |
defaultSymbolPrev.setPreferredSize(new Dimension(110, 20)); |
578 |
defaultSymbolPrev.addActionListener(this);
|
579 |
defaultSymbolPanel.add(defaultSymbolPrev, null);
|
580 |
} |
581 |
} |
582 |
|
583 |
/* (non-Javadoc)
|
584 |
* @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
|
585 |
*/
|
586 |
public ILegend getLegend() {
|
587 |
fillSymbolListFromTable(); |
588 |
|
589 |
if (auxLegend != null) { |
590 |
// your settings that are not the set of symbols must be located here
|
591 |
// auxLegend.setClassifyingFieldNames(
|
592 |
// new String[] {(String) cmbFields.getSelectedItem()});
|
593 |
|
594 |
ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol(); |
595 |
ISymbol symbol = defaultSymbolPrev.getSymbol(); |
596 |
if (symbol != null) { |
597 |
if (symbol != defaultSymbolLegend) {
|
598 |
auxLegend.setDefaultSymbol(symbol); |
599 |
} |
600 |
} |
601 |
|
602 |
auxLegend.useDefaultSymbol(chbUseDefault.isSelected()); |
603 |
|
604 |
theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend(); |
605 |
theLegend.setZSort(auxLegend.getZSort()); |
606 |
} |
607 |
|
608 |
return theLegend;
|
609 |
} |
610 |
|
611 |
private JCheckBox getChbUseDefault() { |
612 |
if (chbUseDefault == null) { |
613 |
chbUseDefault = new JCheckBox(); |
614 |
chbUseDefault.setSelected(false);
|
615 |
chbUseDefault.addActionListener(new java.awt.event.ActionListener() {
|
616 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
617 |
if (chbUseDefault.isSelected()) {
|
618 |
auxLegend.useDefaultSymbol(true);
|
619 |
} else {
|
620 |
auxLegend.useDefaultSymbol(false);
|
621 |
} |
622 |
} |
623 |
}); |
624 |
chbUseDefault.setText(PluginServices.getText(this, "resto_valores") + ": "); |
625 |
} |
626 |
|
627 |
return chbUseDefault;
|
628 |
} |
629 |
|
630 |
/**
|
631 |
* A�ade el resto de valores.
|
632 |
*/
|
633 |
private void addDefault() { |
634 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
635 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
|
636 |
symbolTable.addTableRecord(auxLegend.getDefaultSymbol(), |
637 |
null, auxLegend.getDefaultSymbol().getDescription());
|
638 |
symbolTable.repaint(); |
639 |
} |
640 |
|
641 |
/**
|
642 |
* Elimina el resto de valores que no estan representados por ning�n otro
|
643 |
* s�mbolo..
|
644 |
*/
|
645 |
private void delDefault() { |
646 |
auxLegend.delSymbol(null);
|
647 |
symbolTable.removeRow(null);
|
648 |
symbolTable.repaint(); |
649 |
} |
650 |
|
651 |
public void actionPerformed(ActionEvent e) { |
652 |
|
653 |
//modificar el combobox de valor
|
654 |
if (e.getActionCommand() == "FIELD_SELECTED") { |
655 |
JComboBox cb = (JComboBox) e.getSource(); |
656 |
String fieldName = (String) cb.getSelectedItem(); |
657 |
symbolTable.removeAllItems(); |
658 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
659 |
|
660 |
// if (theLegend.getClassifyingFieldNames()!=null && fieldName != theLegend.getClassifyingFieldNames()[0]) {
|
661 |
// //m_bCacheDirty = true;
|
662 |
// theLegend.setClassifyingFieldNames(new String[] {fieldName});
|
663 |
// }
|
664 |
//
|
665 |
// //////////////////////////////////////////PEPE
|
666 |
// FLyrVect m = (FLyrVect) layer;
|
667 |
// try {
|
668 |
// int fieldType = m.getSource().getRecordset().getFieldType((int)cb.getSelectedIndex());
|
669 |
// if (theLegend.getClassifyingFieldTypes()!=null && fieldType != theLegend.getClassifyingFieldTypes()[0]) {
|
670 |
// //m_bCacheDirty = true;
|
671 |
// theLegend.setClassifyingFieldTypes(new int[] {fieldType});
|
672 |
// }
|
673 |
// } catch (ReadDriverException e1) {
|
674 |
// NotificationManager.addError(PluginServices.getText(this, "could_not_setup_legend"), e1);
|
675 |
// }
|
676 |
// /////////////////////////////////////////PEPE
|
677 |
} |
678 |
|
679 |
// add all elements by value
|
680 |
if (e.getActionCommand() == "ADD_ALL_VALUES") { |
681 |
fillTableValues(); |
682 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
683 |
} |
684 |
|
685 |
// add only one value
|
686 |
if (e.getActionCommand() == "ADD_VALUE") { |
687 |
try {
|
688 |
ISymbol symbol |
689 |
= mapContextManager.getSymbolManager().createSymbol( |
690 |
layer.getShapeType()); |
691 |
Double clave = new Double(0.0); |
692 |
symbolTable.addTableRecord(symbol, |
693 |
clave, "0 - 0");
|
694 |
btnOpenSymbolLevelsEditor.setEnabled(true);
|
695 |
} catch (ReadException ex) {
|
696 |
NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), ex); |
697 |
} |
698 |
} |
699 |
|
700 |
//Vacia la tabla
|
701 |
if (e.getActionCommand() == "REMOVE_ALL") { |
702 |
symbolTable.removeAllItems(); |
703 |
auxLegend.setZSort(null);
|
704 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
705 |
|
706 |
} |
707 |
|
708 |
//Quitar solo el elemento seleccionado
|
709 |
if (e.getActionCommand() == "REMOVE") { |
710 |
symbolTable.removeSelectedRows(); |
711 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount() > 0);
|
712 |
} |
713 |
|
714 |
if (e.getActionCommand() == "OPEN_SYMBOL_LEVEL_EDITOR") { |
715 |
ZSort myZSort = null;
|
716 |
if (auxLegend != null) { |
717 |
myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort(); |
718 |
if (myZSort == null) { |
719 |
myZSort = new ZSort(auxLegend);
|
720 |
} |
721 |
} |
722 |
if (myZSort == null && theLegend != null) { |
723 |
myZSort = new ZSort(theLegend);
|
724 |
} |
725 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
726 |
PluginServices.getMDIManager().addWindow(sl); |
727 |
auxLegend.setZSort(sl.getZSort()); |
728 |
} |
729 |
} |
730 |
|
731 |
public String getDescription() { |
732 |
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") + "."; |
733 |
} |
734 |
|
735 |
public ImageIcon getIcon() { |
736 |
return IconThemeHelper.getImageIcon(
|
737 |
"legend-overview-vectorial-unique-value");
|
738 |
} |
739 |
|
740 |
public Class getParentClass() { |
741 |
return Categories.class;
|
742 |
} |
743 |
|
744 |
public String getTitle() { |
745 |
return PluginServices.getText(this, "Valores_unicos"); |
746 |
} |
747 |
|
748 |
public JPanel getPanel() { |
749 |
return this; |
750 |
} |
751 |
|
752 |
public Class getLegendClass() { |
753 |
return VectorialUniqueValueLegend.class;
|
754 |
} |
755 |
|
756 |
public boolean isSuitableFor(FLayer layer) { |
757 |
return (layer instanceof FLyrVect); |
758 |
} |
759 |
} |