root / org.gvsig.legend.vectorfilterexpression.app.mainplugin / trunk / org.gvsig.legend.vectorfilterexpression.app.mainplugin / src / main / java / org / gvsig / symbology / gui / layerproperties / VectorFilterExpressionPanel.java @ 9334
History | View | Annotate | Download (22.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 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.symbology.gui.layerproperties; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.util.ArrayList; |
33 |
import java.util.List; |
34 |
|
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.ImageIcon; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JOptionPane; |
40 |
import javax.swing.JPanel; |
41 |
import org.apache.commons.lang3.StringUtils; |
42 |
|
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
import org.gvsig.andami.IconThemeHelper; |
47 |
import org.gvsig.app.ApplicationLocator; |
48 |
import org.gvsig.app.project.documents.view.legend.gui.Categories; |
49 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
50 |
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton; |
51 |
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable; |
52 |
import org.gvsig.fmap.dal.exception.ReadException; |
53 |
import org.gvsig.fmap.dal.feature.Feature; |
54 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
55 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
56 |
import org.gvsig.fmap.dal.feature.FeatureType; |
57 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
58 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
59 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
60 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
61 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
62 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
63 |
import org.gvsig.gui.beans.swing.JBlank; |
64 |
import org.gvsig.i18n.Messages; |
65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol; |
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
67 |
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend; |
68 |
import org.gvsig.symbology.swing.SymbologySwingLocator; |
69 |
import org.gvsig.tools.ToolsLocator; |
70 |
import org.gvsig.tools.i18n.I18nManager; |
71 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
72 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
73 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
74 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
75 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
76 |
|
77 |
/**
|
78 |
* Implements the JPanel that shows the properties of a
|
79 |
* VectorialFilterExpressionLegend
|
80 |
* in order to allows the user to modify its characteristics
|
81 |
*
|
82 |
* @author gvSIG Team
|
83 |
*
|
84 |
*/
|
85 |
public class VectorFilterExpressionPanel extends JPanel |
86 |
implements ILegendPanel, ActionListener { |
87 |
|
88 |
private static final Logger logger = LoggerFactory.getLogger( |
89 |
VectorFilterExpressionPanel.class); |
90 |
|
91 |
private static final long serialVersionUID = -7187473609965942511L; |
92 |
private VectorFilterExpressionLegend theLegend;
|
93 |
private VectorFilterExpressionLegend auxLegend;
|
94 |
private ClassifiableVectorial layer;
|
95 |
private PictureFillSymbol previewSymbol;
|
96 |
private JPanel pnlCenter; |
97 |
private JPanel pnlMovBut; |
98 |
private SymbolTable symbolTable;
|
99 |
private JButton btnAddExpression; |
100 |
// private JButton btnModExpression;
|
101 |
private JButton btnRemoveExpression; |
102 |
private JButton moveUp; |
103 |
private JButton moveDown; |
104 |
private int shapeType; |
105 |
protected JCheckBox chkdefaultvalues = null; |
106 |
protected JSymbolPreviewButton defaultSymbolPrev;
|
107 |
private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel(); |
108 |
private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
|
109 |
|
110 |
/**
|
111 |
* This is the default constructor
|
112 |
*/
|
113 |
public VectorFilterExpressionPanel() {
|
114 |
super();
|
115 |
initialize(); |
116 |
} |
117 |
|
118 |
|
119 |
/**
|
120 |
* This method initializes this
|
121 |
*/
|
122 |
private void initialize() { |
123 |
|
124 |
pnlCenter = new JPanel(); |
125 |
pnlCenter.setLayout(new BorderLayout()); |
126 |
|
127 |
JPanel pnlButtons = new JPanel(); |
128 |
btnAddExpression = usabilitySwingManager.createJButton( |
129 |
Messages.getText("Anadir"));
|
130 |
btnAddExpression.setActionCommand("NEW_EXPRESSION");
|
131 |
btnAddExpression.addActionListener(this);
|
132 |
pnlButtons.add(btnAddExpression); |
133 |
|
134 |
// btnModExpression = usabilitySwingManager.createJButton(
|
135 |
// Messages.getText("modify_filter_expression"));
|
136 |
// btnModExpression.setActionCommand("MODIFY_EXPRESSION");
|
137 |
// btnModExpression.addActionListener(this);
|
138 |
// pnlButtons.add(btnModExpression);
|
139 |
|
140 |
btnRemoveExpression = usabilitySwingManager.createJButton( |
141 |
Messages.getText("Quitar"));
|
142 |
btnRemoveExpression.setActionCommand("REMOVE");
|
143 |
btnRemoveExpression.addActionListener(this);
|
144 |
pnlButtons.add(btnRemoveExpression); |
145 |
defaultSymbolPanel.add(getChkDefaultvalues()); |
146 |
pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH);
|
147 |
|
148 |
this.setLayout(new BorderLayout()); |
149 |
this.add(pnlCenter, BorderLayout.CENTER); |
150 |
this.add(pnlButtons, BorderLayout.SOUTH); |
151 |
|
152 |
|
153 |
} |
154 |
public void getDefaultSymbolPrev(int shapeType) { |
155 |
if(defaultSymbolPrev == null){ |
156 |
defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
|
157 |
defaultSymbolPrev.setPreferredSize(new Dimension(110,20)); |
158 |
defaultSymbolPanel.add(defaultSymbolPrev,null);
|
159 |
} |
160 |
} |
161 |
|
162 |
public String getDescription() { |
163 |
return Messages.getText(
|
164 |
"shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + "."; |
165 |
} |
166 |
|
167 |
public ISymbol getIconSymbol() {
|
168 |
if (previewSymbol == null) { |
169 |
try {
|
170 |
previewSymbol = new PictureFillSymbol();
|
171 |
previewSymbol.setImage( new File( |
172 |
this.getClass().getClassLoader().
|
173 |
getResource("images" + File.separator |
174 |
+ "legend" + File.separator |
175 |
+ "legend-overview-vectorial-unique-value.png").
|
176 |
getFile()).toURI().toURL()); |
177 |
previewSymbol.getMarkerFillProperties(). |
178 |
setFillStyle( |
179 |
IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL); |
180 |
} catch (IOException e) { |
181 |
return null; |
182 |
} |
183 |
} |
184 |
return previewSymbol;
|
185 |
} |
186 |
|
187 |
public ILegend getLegend() {
|
188 |
auxLegend.clear(); |
189 |
fillSymbolListFromTable(); |
190 |
|
191 |
theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend(); |
192 |
if(defaultSymbolPrev.getSymbol() != null) |
193 |
theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol()); |
194 |
|
195 |
theLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
196 |
return theLegend;
|
197 |
} |
198 |
/**
|
199 |
* Fills the list of symbols of the legend
|
200 |
*
|
201 |
*/
|
202 |
private void fillSymbolListFromTable() { |
203 |
Object clave;
|
204 |
ISymbol theSymbol; |
205 |
|
206 |
FLyrVect m = (FLyrVect) layer; |
207 |
try {
|
208 |
|
209 |
if(auxLegend.getClassifyingFieldNames() != null) { |
210 |
String[] fNames= auxLegend.getClassifyingFieldNames(); |
211 |
int[] fieldTypes = new int[auxLegend.getClassifyingFieldNames().length]; |
212 |
|
213 |
FeatureStore fsto = (FeatureStore) m.getDataStore(); |
214 |
FeatureType fty = fsto.getDefaultFeatureType(); |
215 |
|
216 |
for (int i = 0; i < fNames.length; i++) { |
217 |
fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType(); |
218 |
} |
219 |
|
220 |
auxLegend.setClassifyingFieldTypes(fieldTypes); |
221 |
} |
222 |
} catch (Exception e) { |
223 |
|
224 |
} |
225 |
|
226 |
auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected()); |
227 |
|
228 |
for (int row = 0; row < symbolTable.getRowCount(); row++) { |
229 |
clave = symbolTable.getFieldValue(row, 1);
|
230 |
theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
|
231 |
theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2)); |
232 |
auxLegend.addSymbol(clave, theSymbol); |
233 |
} |
234 |
if(chkdefaultvalues.isSelected()){
|
235 |
if(defaultSymbolPrev.getSymbol() != null){ |
236 |
String description = VectorFilterExpressionLegend.I18N_DEFAULT;
|
237 |
defaultSymbolPrev.getSymbol().setDescription(description); |
238 |
auxLegend.addSymbol( |
239 |
description, defaultSymbolPrev.getSymbol()); |
240 |
} |
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
public Class<VectorFilterExpressionLegend> getLegendClass() { |
246 |
return VectorFilterExpressionLegend.class;
|
247 |
} |
248 |
|
249 |
public JPanel getPanel() { |
250 |
return this; |
251 |
} |
252 |
|
253 |
public Class<Categories> getParentClass() { |
254 |
return Categories.class;
|
255 |
} |
256 |
|
257 |
public String getTitle() { |
258 |
return Messages.getText("expressions"); |
259 |
} |
260 |
|
261 |
public boolean isSuitableFor(FLayer layer) { |
262 |
if (!(layer instanceof FLyrVect)) { |
263 |
return false; |
264 |
} |
265 |
FLyrVect lVect = (FLyrVect) layer; |
266 |
try {
|
267 |
return
|
268 |
VectorFilterExpressionLegend.isPoint(lVect.getShapeType()) |
269 |
|| |
270 |
VectorFilterExpressionLegend.isLinear(lVect.getShapeType()) |
271 |
|| |
272 |
VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType()); |
273 |
} catch (Exception e) { |
274 |
return false; |
275 |
} |
276 |
|
277 |
} |
278 |
|
279 |
public void setData(FLayer lyr, ILegend legend) { |
280 |
this.layer = (ClassifiableVectorial) lyr;
|
281 |
shapeType = 0;
|
282 |
|
283 |
try {
|
284 |
shapeType = this.layer.getGeometryType().getType();
|
285 |
} catch (ReadException e) {
|
286 |
logger.info("Error while getting layer shp type", e);
|
287 |
ApplicationLocator.getManager().message( |
288 |
Messages.getText("generating_intervals"),
|
289 |
JOptionPane.ERROR_MESSAGE);
|
290 |
} |
291 |
|
292 |
if (symbolTable != null) |
293 |
pnlCenter.remove(symbolTable); |
294 |
if (pnlMovBut != null) |
295 |
pnlCenter.remove(pnlMovBut); |
296 |
|
297 |
getDefaultSymbolPrev(shapeType); |
298 |
|
299 |
symbolTable = new SymbolTable(this, "expressions", shapeType); |
300 |
try {
|
301 |
ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
|
302 |
((FLyrVect)layer).getFeatureStore() |
303 |
); |
304 |
symbolTable.setCellEditor(cellEditor); |
305 |
} catch(Exception ex) { |
306 |
|
307 |
} |
308 |
pnlCenter.add(symbolTable, BorderLayout.CENTER);
|
309 |
pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
|
310 |
|
311 |
|
312 |
if (legend instanceof VectorFilterExpressionLegend) { |
313 |
|
314 |
auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend(); |
315 |
if (auxLegend.isUseDefaultSymbol()) {
|
316 |
// Default must not be in table
|
317 |
fillTableSkipDefault(auxLegend); |
318 |
} else {
|
319 |
symbolTable.fillTableFromSymbolList( |
320 |
auxLegend.getSymbols(), |
321 |
auxLegend.getValues(), |
322 |
auxLegend.getDescriptions()); |
323 |
} |
324 |
|
325 |
|
326 |
} else {
|
327 |
auxLegend = new VectorFilterExpressionLegend();
|
328 |
auxLegend.setShapeType(shapeType); |
329 |
} |
330 |
defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol()); |
331 |
getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol()); |
332 |
} |
333 |
|
334 |
private JPanel getPnlMovBut() { |
335 |
if(pnlMovBut == null){ |
336 |
pnlMovBut = new JPanel(); |
337 |
pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS)); |
338 |
pnlMovBut.add(new JBlank(1, 70)); |
339 |
ImageIcon ico = IconThemeHelper.getImageIcon(
|
340 |
"symbol-layer-move-up");
|
341 |
moveUp = usabilitySwingManager.createJButton(ico); |
342 |
pnlMovBut.add(moveUp); |
343 |
moveUp.setSize(new Dimension(15,15)); |
344 |
pnlMovBut.add(new JBlank(1,10)); |
345 |
ico = IconThemeHelper.getImageIcon( |
346 |
"symbol-layer-move-down");
|
347 |
moveDown = usabilitySwingManager.createJButton(ico); |
348 |
pnlMovBut.add(moveDown); |
349 |
pnlMovBut.add(new JBlank(1, 70)); |
350 |
moveDown.setActionCommand("MOVE-DOWN");
|
351 |
moveUp.setActionCommand("MOVE-UP");
|
352 |
moveDown.addActionListener(this);
|
353 |
moveUp.addActionListener(this);
|
354 |
} |
355 |
return pnlMovBut;
|
356 |
} |
357 |
|
358 |
public void actionPerformed(ActionEvent e) { |
359 |
|
360 |
int[] indices = null; |
361 |
Feature dummyFeat = null;
|
362 |
|
363 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
364 |
indices = symbolTable.getSelectedRows(); |
365 |
} |
366 |
|
367 |
if(e.getActionCommand() == "MOVE-UP"){ |
368 |
if (indices.length>0) { |
369 |
int classIndex = indices[0]; |
370 |
int targetPos = Math.max(0, classIndex-1); |
371 |
symbolTable.moveUpRows(classIndex, targetPos,indices.length); |
372 |
} |
373 |
} |
374 |
|
375 |
if(e.getActionCommand() == "MOVE-DOWN"){ |
376 |
if (indices.length>0) { |
377 |
int classIndex = indices[indices.length-1]; |
378 |
int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1); |
379 |
symbolTable.moveDownRows(classIndex, targetPos,indices.length); |
380 |
} |
381 |
} |
382 |
|
383 |
if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){ |
384 |
ArrayList<String> orders = new ArrayList<String>(); |
385 |
|
386 |
for (int i = 0; i < symbolTable.getRowCount(); i++) { |
387 |
orders.add(symbolTable.getFieldValue(i,1).toString());
|
388 |
} |
389 |
|
390 |
} if (e.getActionCommand() == "NEW_EXPRESSION") { |
391 |
|
392 |
FLyrVect vect = (FLyrVect) layer; |
393 |
final FeatureStore fsto = vect.getFeatureStore();
|
394 |
final FeatureType fty = fsto.getDefaultFeatureTypeQuietly();
|
395 |
final int shptype = fty.getDefaultGeometryAttribute().getGeomType().getType(); |
396 |
final I18nManager i18n = ToolsLocator.getI18nManager();
|
397 |
final ExpressionSymbolPanel esp = new ExpressionSymbolPanel(fsto, shptype, previewSymbol); |
398 |
final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
|
399 |
final Dialog dialog = windowManager.createDialog( |
400 |
esp, |
401 |
i18n.getTranslation("expression_creator"),
|
402 |
"",
|
403 |
WindowManager_v2.BUTTONS_OK_CANCEL |
404 |
); |
405 |
dialog.addActionListener((ActionEvent e1) -> {
|
406 |
if( dialog.getAction()!=WindowManager_v2.BUTTON_OK ) {
|
407 |
return;
|
408 |
} |
409 |
String expr = esp.getExpression();
|
410 |
if ( StringUtils.isBlank(expr) ) {
|
411 |
ApplicationLocator.getManager().messageDialog( |
412 |
Messages.getText("error_validating_filter_query"),
|
413 |
Messages.getText("error"),
|
414 |
JOptionPane.ERROR_MESSAGE);
|
415 |
return;
|
416 |
} |
417 |
ISymbol sym = esp.getSymbol(); |
418 |
this.addClassFieldNames(fty);
|
419 |
|
420 |
auxLegend.addSymbol(expr, sym); |
421 |
symbolTable.removeAllItems(); |
422 |
fillTableSkipDefault(auxLegend); |
423 |
|
424 |
repaint(); |
425 |
}); |
426 |
dialog.show(WindowManager.MODE.DIALOG); |
427 |
//
|
428 |
// }
|
429 |
// else if (e.getActionCommand() == "MODIFY_EXPRESSION") {
|
430 |
//
|
431 |
// if(symbolTable.getSelectedRowElements() == null) {
|
432 |
// JOptionPane.showMessageDialog(this,
|
433 |
// Messages.getText("select_one_row")+".\n");
|
434 |
// } else {
|
435 |
//
|
436 |
// FLyrVect vect = (FLyrVect) layer;
|
437 |
// FeatureStore fsto = (FeatureStore) vect.getDataStore();
|
438 |
// FeatureType fty = null;
|
439 |
// int shptype = 0;
|
440 |
// try {
|
441 |
// fty = fsto.getDefaultFeatureType();
|
442 |
// shptype = vect.getGeometryType().getType();
|
443 |
// dummyFeat = fsto.createNewFeature(true);
|
444 |
// } catch (Exception exc) {
|
445 |
// logger.error(Messages.getText(
|
446 |
// "error_trying_to_access_to_the_layer"), exc);
|
447 |
// return;
|
448 |
// }
|
449 |
//
|
450 |
// ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
|
451 |
// String expression = (String) symbolTable.getSelectedRowElements()[1];
|
452 |
//
|
453 |
// EvaluatorWithDescriptions evalu =
|
454 |
// EvaluatorCreator.getEvaluator(expression);
|
455 |
//
|
456 |
// MDIManager mm = ApplicationLocator.getManager().getUIManager();
|
457 |
// ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
|
458 |
// dummyFeat, evalu, shptype, mySymbol);
|
459 |
// mm.addCentredWindow(esp);
|
460 |
// /*
|
461 |
// * esp is modal
|
462 |
// */
|
463 |
// if (!esp.isOkPressed()) {
|
464 |
// return;
|
465 |
// }
|
466 |
//
|
467 |
// String expr = esp.getExpression();
|
468 |
// if (expr == null || expr.length() == 0) {
|
469 |
// ApplicationLocator.getManager().messageDialog(
|
470 |
// Messages.getText("error_validating_filter_query"),
|
471 |
// Messages.getText("error"),
|
472 |
// JOptionPane.ERROR_MESSAGE);
|
473 |
// return;
|
474 |
// }
|
475 |
//
|
476 |
// ISymbol sym = esp.getSymbol();
|
477 |
//// evalu = EvaluatorCreator.getEvaluator(expr);
|
478 |
// // Add all fields in the feature type
|
479 |
// this.addClassFieldNames(fty);
|
480 |
//
|
481 |
// // Remove old
|
482 |
// auxLegend.delSymbol(expression);
|
483 |
// auxLegend.addSymbol(expr, sym);
|
484 |
// symbolTable.removeAllItems();
|
485 |
// this.fillTableSkipDefault(auxLegend);
|
486 |
//
|
487 |
// repaint();
|
488 |
// }
|
489 |
|
490 |
} else if (e.getActionCommand() == "REMOVE") { |
491 |
|
492 |
if(symbolTable.getSelectedRowElements() == null) { |
493 |
JOptionPane.showMessageDialog(this, |
494 |
Messages.getText("select_one_row"));
|
495 |
} else{
|
496 |
String my_expr = (String) symbolTable.getSelectedRowElements()[1]; |
497 |
auxLegend.delSymbol(my_expr); |
498 |
symbolTable.removeAllItems(); |
499 |
fillTableSkipDefault(auxLegend); |
500 |
|
501 |
repaint(); |
502 |
} |
503 |
} |
504 |
} |
505 |
|
506 |
|
507 |
private void addClassFieldNames(FeatureType ft) { |
508 |
|
509 |
FeatureAttributeDescriptor[] atts = ft.getAttributeDescriptors();
|
510 |
String[] nn = new String[atts.length]; |
511 |
for (int i=0; i<atts.length; i++) { |
512 |
nn[i] = atts[i].getName(); |
513 |
} |
514 |
addClassFieldNames(nn); |
515 |
} |
516 |
/**
|
517 |
* Adds new classifying field names to the legend when a new expression is
|
518 |
* created or an existing one is modified
|
519 |
* @param fieldNamesExpression
|
520 |
*/
|
521 |
private void addClassFieldNames(String[] fieldNamesExpression) { |
522 |
boolean appears = false; |
523 |
ArrayList<String> myFieldNames = new ArrayList<String>(); |
524 |
|
525 |
if (auxLegend.getClassifyingFieldNames() != null) { |
526 |
|
527 |
for (int i = 0; i < auxLegend.getClassifyingFieldNames().length; i++) { |
528 |
myFieldNames.add(auxLegend.getClassifyingFieldNames()[i]); |
529 |
} |
530 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
531 |
appears = false;
|
532 |
for (int j = 0; j < auxLegend.getClassifyingFieldNames().length; j++) { |
533 |
if (auxLegend.getClassifyingFieldNames()[j].compareTo((String) fieldNamesExpression[i]) == 0) |
534 |
appears = true;
|
535 |
} |
536 |
if(!appears) {
|
537 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
538 |
} |
539 |
} |
540 |
|
541 |
auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
542 |
String[myFieldNames.size()]));
|
543 |
} |
544 |
|
545 |
else {
|
546 |
for (int i = 0; i < fieldNamesExpression.length; i++) { |
547 |
myFieldNames.add((String) fieldNamesExpression[i]);
|
548 |
} |
549 |
auxLegend.setClassifyingFieldNames((String[])myFieldNames.toArray(new |
550 |
String[myFieldNames.size()]));
|
551 |
} |
552 |
} |
553 |
|
554 |
|
555 |
public ImageIcon getIcon() { |
556 |
ImageIcon ii = IconThemeHelper.getImageIcon(
|
557 |
"legend-overview-vector-filter-expression");
|
558 |
return ii;
|
559 |
} |
560 |
|
561 |
/**
|
562 |
* This method initializes chkdefaultvalues
|
563 |
*
|
564 |
* @return javax.swing.JCheckBox
|
565 |
*/
|
566 |
protected JCheckBox getChkDefaultvalues() { |
567 |
if (chkdefaultvalues == null) { |
568 |
chkdefaultvalues = new JCheckBox(); |
569 |
chkdefaultvalues.setText(Messages.getText("resto_valores")+": "); |
570 |
chkdefaultvalues.setBounds(new java.awt.Rectangle(342, 26, 141, 20)); |
571 |
chkdefaultvalues.setSelected(false);
|
572 |
chkdefaultvalues.addActionListener(new java.awt.event.ActionListener() {
|
573 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
574 |
if (chkdefaultvalues.isSelected()) {
|
575 |
auxLegend.useDefaultSymbol(true);
|
576 |
} else {
|
577 |
auxLegend.useDefaultSymbol(false);
|
578 |
} |
579 |
} |
580 |
}); |
581 |
} |
582 |
|
583 |
return chkdefaultvalues;
|
584 |
} |
585 |
|
586 |
private void fillTableSkipDefault(VectorFilterExpressionLegend leg) { |
587 |
|
588 |
Object[] src_expr = leg.getValues(); |
589 |
List<Integer> rem_ind = new ArrayList<Integer>(); |
590 |
for (int i=0; i<src_expr.length; i++) { |
591 |
if (VectorFilterExpressionLegend.I18N_DEFAULT.
|
592 |
compareToIgnoreCase((String) src_expr[i]) == 0) { |
593 |
rem_ind.add(new Integer(i)); |
594 |
} |
595 |
} |
596 |
ISymbol[] src_syms = leg.getSymbols();
|
597 |
String[] src_descs = leg.getDescriptions(); |
598 |
// Object[] src_expr
|
599 |
|
600 |
List<ISymbol> syms = new ArrayList<ISymbol>(); |
601 |
List<Object> vals = new ArrayList<Object>(); |
602 |
List<String> descs = new ArrayList<String>(); |
603 |
for (int i=0; i<src_expr.length; i++) { |
604 |
if (!isIn(i, rem_ind)) {
|
605 |
syms.add(src_syms[i]); |
606 |
vals.add(src_expr[i]); |
607 |
descs.add(src_descs[i]); |
608 |
} |
609 |
} |
610 |
symbolTable.fillTableFromSymbolList( |
611 |
(ISymbol[]) syms.toArray(new ISymbol[0]), |
612 |
(Object[]) vals.toArray(new Object[0]), |
613 |
(String[]) descs.toArray(new String[0])); |
614 |
doUpdateCellEditor(); |
615 |
} |
616 |
|
617 |
private void doUpdateCellEditor() { |
618 |
try {
|
619 |
ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
|
620 |
((FLyrVect)layer).getFeatureStore() |
621 |
); |
622 |
symbolTable.setCellEditor(cellEditor); |
623 |
} catch(Exception ex) { |
624 |
logger.debug("Can't update cell editors",ex);
|
625 |
} |
626 |
} |
627 |
|
628 |
/**
|
629 |
* @param i
|
630 |
* @param rem_ind
|
631 |
* @return
|
632 |
*/
|
633 |
private boolean isIn(int n, List<Integer> int_list) { |
634 |
|
635 |
if (int_list == null || int_list.size() == 0) { |
636 |
return false; |
637 |
} |
638 |
|
639 |
for (int i=0; i<int_list.size(); i++) { |
640 |
if (int_list.get(i) instanceof Integer) { |
641 |
Integer item = (Integer) int_list.get(i); |
642 |
if (item.intValue() == n) {
|
643 |
return true; |
644 |
} |
645 |
} |
646 |
} |
647 |
return false; |
648 |
} |
649 |
|
650 |
public static void selfRegister() { |
651 |
IconThemeHelper.registerIcon("legend","legend-overview-vector-filter-expression", VectorFilterExpressionPanel.class); |
652 |
IconThemeHelper.registerIcon("legend","legend-overview-vectorial-unique-value", VectorFilterExpressionPanel.class); |
653 |
IconThemeHelper.registerIcon("symbol","symbol-layer-move-down", VectorFilterExpressionPanel.class); |
654 |
IconThemeHelper.registerIcon("symbol","symbol-layer-move-up", VectorFilterExpressionPanel.class); |
655 |
|
656 |
|
657 |
SymbologySwingLocator.getSwingManager().registerLegendEditor(VectorFilterExpressionPanel.class); |
658 |
|
659 |
// SymbologySwingLocator.getSwingManager().registerLegendEditor(VectorFilterExpressionPanel2.class);
|
660 |
|
661 |
|
662 |
|
663 |
SymbolTable.addNewCellEditor("expressions",
|
664 |
new ExpressionFieldCellEditor(null)); |
665 |
|
666 |
} |
667 |
} |