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 @ 44921
History | View | Annotate | Download (21.9 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.Random; |
35 |
|
36 |
import javax.swing.DefaultComboBoxModel; |
37 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JComboBox; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JPanel; |
43 |
|
44 |
import org.gvsig.andami.IconThemeHelper; |
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.app.gui.styling.JComboBoxColorScheme; |
47 |
import org.gvsig.app.gui.styling.SymbolLevelsWindow; |
48 |
import org.gvsig.fmap.dal.exception.DataException; |
49 |
import org.gvsig.fmap.dal.exception.ReadException; |
50 |
import org.gvsig.fmap.dal.feature.Feature; |
51 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
52 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
53 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
54 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
55 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
56 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
57 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
58 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
59 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
60 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
61 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
62 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
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.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend; |
67 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
68 |
import org.gvsig.tools.ToolsLocator; |
69 |
import org.gvsig.tools.dispose.DisposableIterator; |
70 |
import org.gvsig.tools.dispose.DisposeUtils; |
71 |
import org.gvsig.tools.i18n.I18nManager; |
72 |
import org.slf4j.Logger; |
73 |
import org.slf4j.LoggerFactory; |
74 |
|
75 |
/**
|
76 |
* DOCUMENT ME!
|
77 |
*
|
78 |
* @author fjp To change the template for this generated type comment go to
|
79 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
80 |
*/
|
81 |
public class VectorialUniqueValue extends JPanel implements ILegendPanel, ActionListener { |
82 |
|
83 |
private static final Logger LOGGER = LoggerFactory |
84 |
.getLogger(VectorialUniqueValue.class); |
85 |
|
86 |
protected VectorialUniqueValueLegend theLegend;
|
87 |
private ClassifiableVectorial layer;
|
88 |
private SymbolTable symbolTable;
|
89 |
protected JComboBox cmbFields; |
90 |
private JButton btnRemoveAll; |
91 |
private JButton btnRemove; |
92 |
private JCheckBox chbUseDefault = null; |
93 |
private JSymbolPreviewButton defaultSymbolPrev;
|
94 |
private VectorialUniqueValueLegend auxLegend;
|
95 |
private JPanel pnlCenter; |
96 |
private JButton btnOpenSymbolLevelsEditor; |
97 |
|
98 |
private JComboBoxColorScheme cmbColorScheme;
|
99 |
private final GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
100 |
|
101 |
private final MapContextManager mapContextManager = MapContextLocator.getMapContextManager(); |
102 |
|
103 |
/**
|
104 |
*
|
105 |
*/
|
106 |
public VectorialUniqueValue() {
|
107 |
super();
|
108 |
initComponents(); |
109 |
} |
110 |
|
111 |
protected void initComponents() { |
112 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
113 |
JPanel pnlButtons = new JPanel(); |
114 |
|
115 |
JButton btnAddAll = new JButton(i18n.getTranslation("Anadir_todos")); |
116 |
btnAddAll.setActionCommand("ADD_ALL_VALUES");
|
117 |
btnAddAll.addActionListener(this);
|
118 |
pnlButtons.add(btnAddAll); |
119 |
|
120 |
JButton btnAdd = new JButton(i18n.getTranslation("Anadir")); |
121 |
btnAdd.setActionCommand("ADD_VALUE");
|
122 |
btnAdd.addActionListener(this);
|
123 |
pnlButtons.add(btnAdd); |
124 |
|
125 |
btnRemoveAll = new JButton(i18n.getTranslation("Quitar_todos")); |
126 |
btnRemoveAll.setActionCommand("REMOVE_ALL");
|
127 |
btnRemoveAll.addActionListener(this);
|
128 |
pnlButtons.add(btnRemoveAll); |
129 |
|
130 |
btnRemove = new JButton(i18n.getTranslation("Quitar")); |
131 |
btnRemove.setActionCommand("REMOVE");
|
132 |
btnRemove.addActionListener(this);
|
133 |
pnlButtons.add(btnRemove); |
134 |
|
135 |
btnOpenSymbolLevelsEditor = new JButton(i18n.getTranslation("symbol_levels")); |
136 |
btnOpenSymbolLevelsEditor.addActionListener(this);
|
137 |
btnOpenSymbolLevelsEditor.setActionCommand("OPEN_SYMBOL_LEVEL_EDITOR");
|
138 |
pnlButtons.add(btnOpenSymbolLevelsEditor); |
139 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
140 |
|
141 |
pnlCenter = new JPanel(); |
142 |
pnlCenter.setLayout(new BorderLayout()); |
143 |
|
144 |
cmbFields = new JComboBox(); |
145 |
cmbFields.setActionCommand("FIELD_SELECTED");
|
146 |
cmbFields.addActionListener(this);
|
147 |
cmbFields.setVisible(true);
|
148 |
|
149 |
JPanel pnlNorth = new JPanel(); |
150 |
pnlNorth.setLayout(new GridLayout(0, 2)); |
151 |
|
152 |
GridBagLayoutPanel auxPanel = new GridBagLayoutPanel();
|
153 |
JLabel lblFieldClassification = new JLabel(i18n.getTranslation("Campo_de_clasificacion") + ": "); |
154 |
auxPanel.add(lblFieldClassification); |
155 |
auxPanel.add(cmbFields); |
156 |
pnlNorth.add(auxPanel); |
157 |
|
158 |
auxPanel = new GridBagLayoutPanel();
|
159 |
auxPanel.add(new JLabel(i18n.getTranslation("color_scheme") + ": ")); |
160 |
cmbColorScheme = new JComboBoxColorScheme(false); |
161 |
cmbColorScheme.addActionListener(this);
|
162 |
auxPanel.add(cmbColorScheme); |
163 |
pnlNorth.add(auxPanel); |
164 |
|
165 |
defaultSymbolPanel.add(getChbUseDefault(), null);
|
166 |
pnlNorth.add(defaultSymbolPanel); |
167 |
pnlNorth.add(new JBlank(0, 30)); |
168 |
|
169 |
this.setLayout(new BorderLayout()); |
170 |
this.add(pnlNorth, BorderLayout.NORTH); |
171 |
this.add(pnlCenter, BorderLayout.CENTER); |
172 |
this.add(pnlButtons, BorderLayout.SOUTH); |
173 |
|
174 |
} |
175 |
|
176 |
private void fillTableValues() { |
177 |
FeatureStore elRs; |
178 |
|
179 |
try {
|
180 |
elRs = ((FLyrVect) layer).getFeatureStore(); |
181 |
String fieldName = (String) cmbFields.getSelectedItem(); |
182 |
if (fieldName == null) { |
183 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
184 |
JOptionPane.showMessageDialog(
|
185 |
(Component) PluginServices.getMainFrame(),
|
186 |
i18n.getTranslation("no_hay_campo_seleccionado")
|
187 |
); |
188 |
return;
|
189 |
} |
190 |
|
191 |
symbolTable.removeAllItems(); |
192 |
|
193 |
int numSymbols = 0; |
194 |
ISymbol theSymbol; |
195 |
|
196 |
auxLegend = (VectorialUniqueValueLegend) MapContextLocator |
197 |
.getMapContextManager().createLegend( |
198 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
199 |
auxLegend.setShapeType(layer.getShapeType()); |
200 |
auxLegend.setClassifyingFieldNames(new String[]{fieldName}); |
201 |
FeatureAttributeDescriptor attr = elRs.getDefaultFeatureTypeQuietly().getAttributeDescriptor(fieldName); |
202 |
int fieldType = attr.getDataType().getType();
|
203 |
auxLegend.setClassifyingFieldTypes(new int[]{fieldType}); |
204 |
Object clave;
|
205 |
|
206 |
//Object resul;
|
207 |
if (chbUseDefault.isSelected()) {
|
208 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
209 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
|
210 |
} |
211 |
|
212 |
Color[] colorScheme = cmbColorScheme.getSelectedColors(); |
213 |
|
214 |
Color[] colors = new Color[colorScheme.length]; |
215 |
System.arraycopy(colorScheme, 0, colors, 0, colorScheme.length); |
216 |
auxLegend.setColorScheme(colors); |
217 |
|
218 |
Random rand = new Random(System.currentTimeMillis()); |
219 |
|
220 |
FeatureSet set = null;
|
221 |
DisposableIterator iterator = null;
|
222 |
|
223 |
try {
|
224 |
set = elRs.getFeatureSet(); |
225 |
|
226 |
int count = 0; |
227 |
|
228 |
iterator = set.fastIterator(); |
229 |
while (iterator.hasNext()) {
|
230 |
Feature feature = (Feature) iterator.next(); |
231 |
clave = feature.get(fieldName); |
232 |
if (clave == null) { |
233 |
continue;
|
234 |
} |
235 |
|
236 |
// //Comprobar que no esta repetido y no hace falta
|
237 |
// introducir en el hashtable el campo junto con el simbolo.
|
238 |
if (auxLegend.getSymbolByValue(clave) == null) { |
239 |
|
240 |
if (count == 100) { |
241 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
242 |
int resp = JOptionPane.showConfirmDialog(this, |
243 |
i18n.getTranslation("mas_de_100_simbolos"),
|
244 |
i18n.getTranslation("quiere_continuar"),
|
245 |
JOptionPane.YES_NO_OPTION,
|
246 |
JOptionPane.WARNING_MESSAGE);
|
247 |
|
248 |
if ((resp == JOptionPane.NO_OPTION) |
249 |
|| (resp == JOptionPane.DEFAULT_OPTION)) {
|
250 |
break;
|
251 |
} |
252 |
} |
253 |
|
254 |
// si no esta creado el simbolo se crea
|
255 |
// jaume (moved to ISymbol); theSymbol = new
|
256 |
// FSymbol(layer.getShapeType());
|
257 |
theSymbol = mapContextManager.getSymbolManager().createSymbol( |
258 |
layer.getShapeType(), |
259 |
colorScheme[rand.nextInt(colorScheme.length)] |
260 |
); |
261 |
theSymbol.setDescription(clave.toString()); |
262 |
auxLegend.addSymbol(clave, theSymbol); |
263 |
count++; |
264 |
} |
265 |
|
266 |
} // for
|
267 |
} finally {
|
268 |
DisposeUtils.disposeQuietly(iterator); |
269 |
DisposeUtils.disposeQuietly(set); |
270 |
} |
271 |
|
272 |
Object[] values = auxLegend.getValues(); |
273 |
String[] descriptions = new String[values.length]; |
274 |
ISymbol[] symbols = new ISymbol[values.length]; |
275 |
|
276 |
for (int i = 0; i < values.length; i++) { |
277 |
Object value = values[i];
|
278 |
symbols[i] = auxLegend.getSymbolByValue(value); |
279 |
descriptions[i] = symbols[i].getDescription(); |
280 |
} |
281 |
|
282 |
symbolTable.fillTableFromSymbolList(symbols, |
283 |
values, descriptions); |
284 |
} catch (DataException e) {
|
285 |
LOGGER.warn("recovering_recordset", e);
|
286 |
} |
287 |
|
288 |
btnRemoveAll.setEnabled(true);
|
289 |
btnRemove.setEnabled(true);
|
290 |
} |
291 |
|
292 |
private boolean compareClassifyingFieldNames(String[] a, String[] b) { |
293 |
if (a == b) {
|
294 |
return true; |
295 |
} |
296 |
if (a == null || b == null) { |
297 |
return false; |
298 |
} |
299 |
if (a.length != b.length) {
|
300 |
return false; |
301 |
} |
302 |
for (int i = 0; i < a.length; i++) { |
303 |
if (!a[i].equals(b[i])) {
|
304 |
return false; |
305 |
} |
306 |
} |
307 |
return true; |
308 |
} |
309 |
|
310 |
private boolean compareClassifyingFieldTypes(int[] a, int[] b) { |
311 |
if (a == b) {
|
312 |
return true; |
313 |
} |
314 |
if (a == null || b == null) { |
315 |
return false; |
316 |
} |
317 |
if (a.length != b.length) {
|
318 |
return false; |
319 |
} |
320 |
for (int i = 0; i < a.length; i++) { |
321 |
if (a[i] != b[i]) {
|
322 |
return false; |
323 |
} |
324 |
} |
325 |
return true; |
326 |
} |
327 |
|
328 |
/**
|
329 |
* A partir de los registros de la tabla, regenera el FRenderer. (No solo el
|
330 |
* symbolList, si no tambi�n el arrayKeys y el defaultRenderer
|
331 |
*/
|
332 |
private void fillSymbolListFromTable() { |
333 |
Object clave;
|
334 |
ISymbol theSymbol; |
335 |
ArrayList visitedKeys = new ArrayList(); |
336 |
boolean changedLegend = false; |
337 |
|
338 |
String fieldName = (String) cmbFields.getSelectedItem(); |
339 |
String[] classifyingFieldNames = new String[]{fieldName}; |
340 |
if (auxLegend != null) { |
341 |
if (!compareClassifyingFieldNames(classifyingFieldNames, auxLegend.getClassifyingFieldNames())) {
|
342 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
343 |
changedLegend = true;
|
344 |
} |
345 |
} else {
|
346 |
auxLegend.setClassifyingFieldNames(classifyingFieldNames); |
347 |
changedLegend = true;
|
348 |
} |
349 |
|
350 |
FLyrVect m = (FLyrVect) layer; |
351 |
|
352 |
try {
|
353 |
int fieldType = m.getFeatureStore().getDefaultFeatureType()
|
354 |
.getAttributeDescriptor(cmbFields.getSelectedIndex()) |
355 |
.getType(); |
356 |
int[] classifyingFieldTypes = new int[]{fieldType}; |
357 |
if (auxLegend != null) { |
358 |
if (!compareClassifyingFieldTypes(classifyingFieldTypes, auxLegend.getClassifyingFieldTypes())) {
|
359 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
360 |
changedLegend = true;
|
361 |
} |
362 |
} else {
|
363 |
auxLegend.setClassifyingFieldTypes(classifyingFieldTypes); |
364 |
changedLegend = true;
|
365 |
} |
366 |
} catch (DataException e) {
|
367 |
LOGGER.warn("could_not_setup_legend", e);
|
368 |
} catch (Exception e) { |
369 |
LOGGER.warn("could_not_setup_legend", e);
|
370 |
} |
371 |
|
372 |
if (changedLegend) {
|
373 |
auxLegend.clear(); |
374 |
} |
375 |
|
376 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
377 |
clave = symbolTable.getFieldValue(row, 1);
|
378 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
379 |
String description = (String) symbolTable.getFieldValue(row, 2); |
380 |
theSymbol.setDescription(description); |
381 |
ISymbol legendSymbol = null;
|
382 |
if (auxLegend != null) { |
383 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
384 |
} |
385 |
if (legendSymbol == null || (auxLegend.isUseDefaultSymbol() && legendSymbol == auxLegend.getDefaultSymbol())) { |
386 |
if (auxLegend != null) { |
387 |
auxLegend.addSymbol(clave, theSymbol); |
388 |
} |
389 |
} else {
|
390 |
|
391 |
// avoid same instance
|
392 |
if (legendSymbol != theSymbol) {
|
393 |
|
394 |
/*
|
395 |
* Perhaps use this "if" when implementations of ISymbol
|
396 |
* properly implement the equals method.
|
397 |
*/
|
398 |
// if (!legendSymbol.equals(theSymbol)) {
|
399 |
auxLegend.replace(legendSymbol, theSymbol); |
400 |
// }
|
401 |
} |
402 |
} |
403 |
visitedKeys.add(clave); |
404 |
} |
405 |
if (auxLegend != null) { |
406 |
Object[] keys = auxLegend.getValues(); |
407 |
for (Object key : keys) { |
408 |
if (!visitedKeys.contains(key)) {
|
409 |
auxLegend.delSymbol(key); |
410 |
} |
411 |
} |
412 |
} |
413 |
clave = null;
|
414 |
if (chbUseDefault.isSelected()) {
|
415 |
theSymbol = defaultSymbolPrev.getSymbol(); |
416 |
if (theSymbol != null) { |
417 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
418 |
String description = i18n.getTranslation("default"); |
419 |
theSymbol.setDescription(description); |
420 |
ISymbol legendSymbol = null;
|
421 |
if (auxLegend != null) { |
422 |
legendSymbol = auxLegend.getSymbolByValue(clave); |
423 |
} |
424 |
if (legendSymbol == null) { |
425 |
auxLegend.addSymbol(clave, theSymbol); |
426 |
} else {
|
427 |
if (legendSymbol != theSymbol) {
|
428 |
auxLegend.replace(legendSymbol, theSymbol); |
429 |
} |
430 |
} |
431 |
} |
432 |
} else {
|
433 |
if (auxLegend != null) { |
434 |
ISymbol legendSymbol = auxLegend.getSymbolByValue(clave); |
435 |
if (legendSymbol != null) { |
436 |
auxLegend.replace(legendSymbol, null);
|
437 |
} |
438 |
} |
439 |
} |
440 |
} |
441 |
|
442 |
private void fillFieldNames() { |
443 |
FeatureStore rs; |
444 |
|
445 |
try {
|
446 |
rs = ((FLyrVect) layer).getFeatureStore(); |
447 |
ArrayList names = new ArrayList(); |
448 |
for (FeatureAttributeDescriptor descriptor : rs.getDefaultFeatureType()) {
|
449 |
Class fieldClass = descriptor.getDataType().getDefaultClass();
|
450 |
if (Comparable.class.isAssignableFrom(fieldClass)) { |
451 |
names.add(descriptor.getName()); |
452 |
} |
453 |
} |
454 |
DefaultComboBoxModel cM = new DefaultComboBoxModel(names.toArray(new String[0])); |
455 |
cmbFields.setModel(cM); |
456 |
|
457 |
} catch (DataException e) {
|
458 |
LOGGER.warn("recovering_recordset", e);
|
459 |
} |
460 |
} |
461 |
|
462 |
@Override
|
463 |
public void setData(FLayer layer, ILegend legend) { |
464 |
this.layer = (ClassifiableVectorial) layer;
|
465 |
int shapeType = 0; |
466 |
try {
|
467 |
shapeType = this.layer.getShapeType();
|
468 |
} catch (ReadException e) {
|
469 |
LOGGER.warn("generating_intervals", e);
|
470 |
} |
471 |
|
472 |
getDefaultSymbolPrev(shapeType); |
473 |
|
474 |
if (symbolTable != null) { |
475 |
pnlCenter.remove(symbolTable); |
476 |
} |
477 |
symbolTable = new SymbolTable(this, SymbolTable.VALUES_TYPE, shapeType); |
478 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
479 |
|
480 |
fillFieldNames(); |
481 |
|
482 |
symbolTable.removeAllItems(); |
483 |
|
484 |
if (VectorialUniqueValueLegend.class.equals(legend.getClass())) {
|
485 |
auxLegend = (VectorialUniqueValueLegend) legend.cloneLegend(); |
486 |
getChbUseDefault().setSelected(auxLegend.isUseDefaultSymbol()); |
487 |
cmbFields.getModel().setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
|
488 |
setColorScheme(); |
489 |
|
490 |
Object[] values = auxLegend.getValues(); |
491 |
String[] descriptions = new String[values.length]; |
492 |
ISymbol[] symbols = new ISymbol[values.length]; |
493 |
|
494 |
for (int i = 0; i < values.length; i++) { |
495 |
Object value = values[i];
|
496 |
symbols[i] = auxLegend.getSymbolByValue(value); |
497 |
descriptions[i] = symbols[i].getDescription(); |
498 |
} |
499 |
|
500 |
symbolTable.fillTableFromSymbolList(symbols, values, descriptions); |
501 |
chbUseDefault.setSelected(auxLegend.isUseDefaultSymbol()); |
502 |
} else {
|
503 |
auxLegend = new VectorialUniqueValueLegend(shapeType);
|
504 |
} |
505 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
506 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
507 |
} |
508 |
|
509 |
private void setColorScheme() { |
510 |
|
511 |
if (auxLegend.getColorScheme() != null) { |
512 |
Color[] colorScheme = auxLegend.getColorScheme(); |
513 |
cmbColorScheme.setSelectedColors(colorScheme); |
514 |
} |
515 |
} |
516 |
|
517 |
private void getDefaultSymbolPrev(int shapeType) { |
518 |
if (defaultSymbolPrev == null) { |
519 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
520 |
defaultSymbolPrev.setPreferredSize(new Dimension(110, 20)); |
521 |
defaultSymbolPrev.addActionListener(this);
|
522 |
defaultSymbolPanel.add(defaultSymbolPrev, null);
|
523 |
} |
524 |
} |
525 |
|
526 |
@Override
|
527 |
public ILegend getLegend() {
|
528 |
fillSymbolListFromTable(); |
529 |
|
530 |
if (auxLegend != null) { |
531 |
ISymbol defaultSymbolLegend = auxLegend.getDefaultSymbol(); |
532 |
ISymbol symbol = defaultSymbolPrev.getSymbol(); |
533 |
if (symbol != null) { |
534 |
if (symbol != defaultSymbolLegend) {
|
535 |
auxLegend.setDefaultSymbol(symbol); |
536 |
} |
537 |
} |
538 |
auxLegend.useDefaultSymbol(chbUseDefault.isSelected()); |
539 |
|
540 |
theLegend = (VectorialUniqueValueLegend) auxLegend.cloneLegend(); |
541 |
theLegend.setZSort(auxLegend.getZSort()); |
542 |
} |
543 |
return theLegend;
|
544 |
} |
545 |
|
546 |
private JCheckBox getChbUseDefault() { |
547 |
if (chbUseDefault == null) { |
548 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
549 |
chbUseDefault = new JCheckBox(); |
550 |
chbUseDefault.setSelected(false);
|
551 |
chbUseDefault.addActionListener((java.awt.event.ActionEvent e) -> { |
552 |
if (chbUseDefault.isSelected()) {
|
553 |
auxLegend.useDefaultSymbol(true);
|
554 |
} else {
|
555 |
auxLegend.useDefaultSymbol(false);
|
556 |
} |
557 |
}); |
558 |
chbUseDefault.setText(i18n.getTranslation("resto_valores") + ": "); |
559 |
} |
560 |
|
561 |
return chbUseDefault;
|
562 |
} |
563 |
|
564 |
private void addDefault() { |
565 |
auxLegend.getDefaultSymbol().setDescription("Default");
|
566 |
auxLegend.addSymbol(null, auxLegend.getDefaultSymbol());
|
567 |
symbolTable.addTableRecord( |
568 |
auxLegend.getDefaultSymbol(), |
569 |
null,
|
570 |
auxLegend.getDefaultSymbol().getDescription() |
571 |
); |
572 |
symbolTable.repaint(); |
573 |
} |
574 |
|
575 |
private void delDefault() { |
576 |
auxLegend.delSymbol(null);
|
577 |
symbolTable.removeRow(null);
|
578 |
symbolTable.repaint(); |
579 |
} |
580 |
|
581 |
@Override
|
582 |
public void actionPerformed(ActionEvent e) { |
583 |
|
584 |
//modificar el combobox de valor
|
585 |
if ("FIELD_SELECTED".equals(e.getActionCommand())) { |
586 |
JComboBox cb = (JComboBox) e.getSource(); |
587 |
String fieldName = (String) cb.getSelectedItem(); |
588 |
symbolTable.removeAllItems(); |
589 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
590 |
} |
591 |
|
592 |
// add all elements by value
|
593 |
if ("ADD_ALL_VALUES".equals(e.getActionCommand())) { |
594 |
fillTableValues(); |
595 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable != null && symbolTable.getRowCount() > 0); |
596 |
} |
597 |
|
598 |
// add only one value
|
599 |
if ("ADD_VALUE".equals(e.getActionCommand())) { |
600 |
try {
|
601 |
ISymbol symbol = mapContextManager.getSymbolManager().createSymbol( |
602 |
layer.getShapeType() |
603 |
); |
604 |
Double clave = 0.0; |
605 |
symbolTable.addTableRecord( |
606 |
symbol, clave, "0 - 0"
|
607 |
); |
608 |
btnOpenSymbolLevelsEditor.setEnabled(true);
|
609 |
} catch (ReadException ex) {
|
610 |
LOGGER.warn("getting_shape_type", ex);
|
611 |
} |
612 |
} |
613 |
|
614 |
//Vacia la tabla
|
615 |
if ("REMOVE_ALL".equals(e.getActionCommand())) { |
616 |
symbolTable.removeAllItems(); |
617 |
auxLegend.setZSort(null);
|
618 |
btnOpenSymbolLevelsEditor.setEnabled(false);
|
619 |
|
620 |
} |
621 |
|
622 |
//Quitar solo el elemento seleccionado
|
623 |
if ("REMOVE".equals(e.getActionCommand())) { |
624 |
symbolTable.removeSelectedRows(); |
625 |
btnOpenSymbolLevelsEditor.setEnabled(symbolTable.getRowCount() > 0);
|
626 |
} |
627 |
|
628 |
if ("OPEN_SYMBOL_LEVEL_EDITOR".equals(e.getActionCommand())) { |
629 |
ZSort myZSort = null;
|
630 |
if (auxLegend != null) { |
631 |
myZSort = ((AbstractClassifiedVectorLegend) getLegend()).getZSort(); |
632 |
if (myZSort == null) { |
633 |
myZSort = new ZSort(auxLegend);
|
634 |
} |
635 |
} |
636 |
if (myZSort == null && theLegend != null) { |
637 |
myZSort = new ZSort(theLegend);
|
638 |
} |
639 |
SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
|
640 |
PluginServices.getMDIManager().addWindow(sl); |
641 |
auxLegend.setZSort(sl.getZSort()); |
642 |
} |
643 |
} |
644 |
|
645 |
@Override
|
646 |
public String getDescription() { |
647 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
648 |
return i18n.getTranslation("Dado_un_campo_de_atributos") + "," |
649 |
+ i18n.getTranslation("muestra_los_elementos_de_la_capa_usando_un_simbolo_por_cada_valor_unico") + "."; |
650 |
} |
651 |
|
652 |
@Override
|
653 |
public ImageIcon getIcon() { |
654 |
return IconThemeHelper.getImageIcon(
|
655 |
"legend-overview-vectorial-unique-value");
|
656 |
} |
657 |
|
658 |
@Override
|
659 |
public Class getParentClass() { |
660 |
return Categories.class;
|
661 |
} |
662 |
|
663 |
@Override
|
664 |
public String getTitle() { |
665 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
666 |
return i18n.getTranslation("Valores_unicos"); |
667 |
} |
668 |
|
669 |
@Override
|
670 |
public JPanel getPanel() { |
671 |
return this; |
672 |
} |
673 |
|
674 |
@Override
|
675 |
public Class getLegendClass() { |
676 |
return VectorialUniqueValueLegend.class;
|
677 |
} |
678 |
|
679 |
@Override
|
680 |
public boolean isSuitableFor(FLayer layer) { |
681 |
return (layer instanceof FLyrVect); |
682 |
} |
683 |
} |