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