Revision 70

View differences:

org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/buildNumber.properties
1
#Thu Nov 14 01:53:41 CET 2013
2
buildNumber=4
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
<!-- No dependencies
51
  <dependencySets>
52
    <dependencySet>
53
      <useProjectArtifact>false</useProjectArtifact>
54
      <useTransitiveDependencies>false</useTransitiveDependencies>
55
      <outputDirectory>lib</outputDirectory>
56
      <includes>
57
		<include>...</include>
58
      </includes>
59
    </dependencySet>
60
  </dependencySets>
61
-->
62

  
63
</assembly>
64

  
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/src/main/java/org/gvsig/symbology/fmap/rendering/filterexpression/EvaluatorCreator.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2013 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.symbology.fmap.rendering.filterexpression;
24

  
25
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
26
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator;
27

  
28

  
29
/**
30
 * 
31
 * Utility class to centralize the creation of an
32
 * @link {@link EvaluatorWithDescriptions}
33
 * 
34
 * TODO Perhaps create a manager in Tools to perform this operation
35
 * 
36
 * @author jldominguez
37
 *
38
 */
39
public class EvaluatorCreator {
40

  
41
    /**
42
     * Create an {@link EvaluatorWithDescriptions} that uses
43
     * the string expression provided
44
     * 
45
     * @param expr
46
     * @return
47
     */
48
    public static EvaluatorWithDescriptions getEvaluator(String expr) {
49
        return new SQLJEPEvaluator(expr);
50
    }
51

  
52
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/src/main/java/org/gvsig/symbology/fmap/rendering/VectorFilterExpressionLegend.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.rendering;
42

  
43

  
44
import java.util.ArrayList;
45

  
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

  
49
import org.gvsig.fmap.dal.feature.Feature;
50
import org.gvsig.fmap.geom.Geometry;
51
import org.gvsig.fmap.mapcontext.MapContextLocator;
52
import org.gvsig.fmap.mapcontext.MapContextManager;
53
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
54
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
55
import org.gvsig.i18n.Messages;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
57
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
58
import org.gvsig.tools.ToolsLocator;
59
import org.gvsig.tools.dynobject.DynStruct;
60
import org.gvsig.tools.evaluator.Evaluator;
61
import org.gvsig.tools.evaluator.EvaluatorData;
62
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
63
import org.gvsig.tools.persistence.PersistenceManager;
64
import org.gvsig.tools.persistence.PersistentState;
65
import org.gvsig.tools.persistence.exception.PersistenceException;
66
import org.gvsig.tools.util.Callable;
67

  
68

  
69
/**
70
 *
71
 * Implements a vector legend which represents the elements of a layer
72
 * depending on the value of an expression. That is, if the expression is
73
 * evaluated to true, then the symbol associated to the expression is painted.
74
 * In other case it is not showed.
75
 * 
76
 * If the expression result is a string, it is considered false if
77
 * it is the empty string "", true otherwise.
78
 * 
79
 * If the expression result is numeric, it is considered false
80
 * if it is zero, and true otherwise.
81
 * 
82
 * In other cases, it is considered false if the result is null and true
83
 * otherwise.
84
 *
85
 * @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
86
 * @author jldominguez
87
 */
88
public class VectorFilterExpressionLegend
89
extends AbstractClassifiedVectorLegend  {
90

  
91
    private static final Logger logger = LoggerFactory.getLogger(
92
        VectorFilterExpressionLegend.class);
93
    
94
    public static final String
95
    FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME =
96
    "FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME";
97
    
98
    public static final String
99
    FILTER_EXPRESSION_LEGEND_NAME = "FILTER_EXPRESSION_LEGEND_NAME";
100

  
101
    public static final String I18N_DEFAULT = Messages.getText("default_value");
102
    public static final String NON_I18N_DEFAULT = Messages.getText("Default");
103
    
104
	private int shapeType;
105
	private ISymbol defaultSymbol;
106
	/*
107
	private String labelFieldName;
108
	private String labelFieldHeight;
109
	private String labelFieldRotation;
110
	*/
111
	private boolean useDefaultSymbol = false;
112

  
113
	private long error_msg_count = 0;
114
	/*
115
	private Hashtable<String, Object> parser_symbol_table =
116
	    new Hashtable<String, Object>();
117
	*/
118
	
119
	
120
	private ArrayList<Item> newSymbols = new ArrayList<Item>() {
121
		private static final long serialVersionUID = 1L;
122

  
123
		public int indexOf(String expr) {
124
			return super.indexOf(new Item(expr, null));
125
		}
126
	};
127

  
128

  
129
	private class Item implements Cloneable {
130
	    
131
		private ISymbol sym;
132
		// get it with getSql()
133
		// private String expression;
134
		private EvaluatorWithDescriptions evaluator;
135

  
136
		public Item(String expression, ISymbol sym) {
137
			this.sym = sym;
138
			evaluator = EvaluatorCreator.getEvaluator(expression);
139
		}
140

  
141
		public boolean equals(Object obj) {
142
			if (obj == null) return false;
143
			if (!obj.getClass().equals(Item.class)) return false;
144
			return this.evaluator.getSQL().equals(
145
			    ((Item) obj).evaluator.getSQL()
146
			    );
147
		}
148

  
149
		public String getStringExpression() {
150
			return evaluator.getSQL();
151
		}
152

  
153
		public Evaluator getEvaluator() {
154
			return evaluator;
155
		}
156
		
157
		public Object clone() {
158
		    
159
		    ISymbol clonesym = null;
160
		    try {
161
                clonesym = (ISymbol) this.sym.clone();
162
            } catch (CloneNotSupportedException e) {
163
                logger.info("Error: unable to clone symbol.", e);
164
                clonesym = this.sym;
165
            }
166
		    return new Item(getStringExpression(), clonesym);
167
		}
168
	}
169

  
170
    public VectorFilterExpressionLegend() {
171
        this.setClassifyingFieldNames(new String[0]);
172
        this.setClassifyingFieldTypes(new int[0]);
173
    }
174

  
175

  
176
	/*
177
	public VectorFilterExpressionLegend(int type,String[] fieldNames) {
178
		setShapeType(type);
179
		this.setClassifyingFieldNames(fieldNames);
180
		// this.fNames = fieldNames;
181
	}
182
	*/
183

  
184

  
185

  
186
	public ISymbol getSymbolByFeature(Feature featu) {
187
	    
188
	    EvaluatorData evda = featu.getEvaluatorData();
189
	    
190
		ISymbol returnSymbol = null;
191
		Object result = null;
192
		String expr = null;
193
		
194
		String[] fNames =  getClassifyingFieldNames();
195
		try {
196
			// updateSymbolsTable(featu, fNames);
197

  
198
			for (int i = 0; i < newSymbols.size(); i++) {
199
			    
200
				Evaluator eval = newSymbols.get(i).getEvaluator();
201
				expr = eval.getSQL();
202
				
203
                if (expr.equalsIgnoreCase(VectorFilterExpressionLegend.I18N_DEFAULT)){
204
                    /*
205
                     * Skip default item
206
                     */
207
                    continue;
208
                }
209
                
210
				result = eval.evaluate(evda);
211
				if (isConsideredTrue(result)) {
212
                    returnSymbol = newSymbols.get(i).sym;
213
                    if (returnSymbol != null) {
214
                        return returnSymbol;
215
                    }
216
				}
217
			}
218
		} catch (Exception e) {
219
		    
220
		    if (error_msg_count % 1000 == 0) {
221
		        logger.info("Error (msg every 1000 occurrences) while getting symbol in VectorFilterExpressionLegend", e);
222
		        error_msg_count = 0;
223
		    }
224
		    error_msg_count++;
225
		}
226

  
227
		if (useDefaultSymbol)
228
			return getDefaultSymbol();
229

  
230
		return null;
231
	}
232
	
233
	/**
234
	 * Tells whether the input object is considered true.
235
	 * Basically, it is false if it has an empty value
236
	 * (FALSE, null, 0, "")
237
	 * 
238
     * @param result
239
     * @return
240
     */
241
    private boolean isConsideredTrue(Object res) {
242
        
243
        if (res == null) {
244
            return false;
245
        }
246
        
247
        if (res instanceof Boolean) {
248
            return ((Boolean) res).booleanValue();
249
        }
250
        
251
        if (res instanceof Number) {
252
            return ((Number) res).doubleValue() != 0d;
253
        }
254
        
255
        if (res instanceof String) {
256
            return ((String) res).length() > 0;
257
        }
258
        
259
        // Because it is not null
260
        return true;
261
    }
262

  
263

  
264
    /**
265
	 * Returns a HashTable containing the name of the field of an specific feature
266
	 * and its values
267
	 *
268
	 * @param feat specific feature
269
	 * @param fNames field names
270
	 * @return HashTable
271
	 * @throws LegendDriverException
272
	 */
273
	/*
274
	private void updateSymbolsTable(Feature feat, String[] fNames)
275
	throws EvaluatorException {
276

  
277
	    Object val = null;
278
	    
279
		if (fNames != null)
280
			for (int j = 0; j < fNames.length; j++) {
281
			    
282
			    val = feat.get(fNames[j]);
283
				if (val != null) {
284
				    parser_symbol_table.put(fNames[j], val);
285
				} else {
286
				    throw new EvaluatorException(
287
				        new Exception("Field not found: '" + fNames[j] + "'"));
288
				}
289
			}
290
	}
291
	*/
292

  
293

  
294
	public void addSymbol(Object key, ISymbol symbol) {
295
		newSymbols.add(new Item((String)key.toString(),
296
				symbol));
297
	}
298

  
299
	public void clear() {
300
		newSymbols.clear();
301
	}
302
	
303
	public void resetItems() {
304
	    newSymbols = new ArrayList<Item>() {
305
            private static final long serialVersionUID = 1L;
306

  
307
            public int indexOf(String expr) {
308
                return super.indexOf(new Item(expr, null));
309
            }
310
	    };
311
	}
312

  
313
	public void delSymbol(Object key) {
314
		ISymbol mySymbol = null;
315
		for (int i = 0; i < newSymbols.size(); i++) {
316
			if (newSymbols.get(i).evaluator.getSQL().equals(key))
317
				newSymbols.remove(i);
318
		}
319
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(mySymbol,null));
320
	}
321

  
322

  
323
	public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
324

  
325
		for (int i = 0; i < newSymbols.size(); i++) {
326
			if (newSymbols.get(i).sym.equals(oldSymbol))
327
				newSymbols.get(i).sym = newSymbol;
328
		}
329

  
330
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(oldSymbol,newSymbol));
331
	}
332

  
333

  
334
	public String[] getDescriptions() {
335
		String[] descriptions = new String[newSymbols.size()];
336
		ISymbol[] auxSym = getSymbols();
337

  
338
		for (int i = 0; i < descriptions.length; i++)
339
			descriptions[i] = auxSym[i].getDescription();
340

  
341
		return descriptions;
342
	}
343

  
344
	public ISymbol[] getSymbols() {
345

  
346
		if (newSymbols != null) {
347
			ISymbol[] mySymbols = new ISymbol[newSymbols.size()];
348
			for (int i = 0; i < newSymbols.size(); i++) {
349
				mySymbols[i] = newSymbols.get(i).sym;
350
			}
351
			return mySymbols;
352
		}
353
		return null;
354
	}
355

  
356

  
357

  
358
	public ISymbol getDefaultSymbol() {
359
		if(defaultSymbol==null) {
360

  
361
		    defaultSymbol = MapContextLocator.getSymbolManager(
362
		        ).createSymbol(shapeType);
363
			fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol));
364
		}
365
		return defaultSymbol;
366
	}
367

  
368

  
369
	public String getClassName() {
370
		return getClass().getName();
371
	}
372

  
373

  
374
	public int getShapeType() {
375
		return shapeType;
376
	}
377

  
378
	public boolean isUseDefaultSymbol() {
379
		return useDefaultSymbol;
380
	}
381

  
382
	public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
383
		if (s == null) throw new NullPointerException("Default symbol cannot be null");
384
		ISymbol old = defaultSymbol;
385
		defaultSymbol = s;
386
		fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
387
	}
388

  
389
	public void setShapeType(int shapeType) {
390
		if (this.shapeType != shapeType) {
391
		    
392
		    ISymbol sym = MapContextLocator.getSymbolManager(
393
		        ).createSymbol(shapeType);
394
			setDefaultSymbol(sym);
395
			this.shapeType = shapeType;
396
		}
397
	}
398

  
399
	public void useDefaultSymbol(boolean b) {
400
		useDefaultSymbol = b;
401
	}
402

  
403
	public Object[] getValues() {
404
		if (newSymbols != null) {
405
			Object[] myObjects = new Object[newSymbols.size()];
406
			for (int i = 0; i < newSymbols.size(); i++) {
407
				myObjects[i] = newSymbols.get(i).getStringExpression();
408
			}
409
			return myObjects;
410
		}
411
		return null;
412
	}
413
	
414
    public static boolean isPolygonal(int ty) {
415
        if (ty == Geometry.TYPES.MULTISURFACE
416
            || ty == Geometry.TYPES.SURFACE
417
            ) {
418
            return true;
419
        } else {
420
            return false;
421
        }
422
    }
423

  
424

  
425
    public static boolean isLinear(int ty) {
426
        if (ty == Geometry.TYPES.CIRCLE
427
            || ty == Geometry.TYPES.ARC
428
            || ty == Geometry.TYPES.CURVE
429
            || ty == Geometry.TYPES.ELLIPSE
430
            || ty == Geometry.TYPES.ELLIPTICARC
431
            || ty == Geometry.TYPES.SPLINE
432
            || ty == Geometry.TYPES.MULTICURVE
433
            ) {
434
            return true;
435
        } else {
436
            return false;
437
        }
438
    }
439
    
440
    public static boolean isPoint(int ty) {
441
        if (ty == Geometry.TYPES.POINT
442
            || ty == Geometry.TYPES.MULTIPOINT
443
            ) {
444
            return true;
445
        } else {
446
            return false;
447
        }
448
    }
449
    
450
    public void removeDefaultSymbol() {
451
        
452
    }
453
    
454
    // =============================
455
    
456
    public static class RegisterPersistence implements Callable {
457

  
458
        public Object call() throws Exception {
459
            
460
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
461
            if (manager.getDefinition(
462
                FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
463
                DynStruct definition = manager
464
                    .addDefinition(VectorFilterExpressionLegend.class,
465
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
466
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME
467
                        + " Persistence definition", null, null);
468
                
469
                definition.extend(manager.getDefinition(
470
                    AbstractClassifiedVectorLegend
471
                    .CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME));
472
                
473
                definition.addDynFieldBoolean("useDefaultSymbol")
474
                .setMandatory(true);
475
                definition.addDynFieldObject("defaultSymbol")
476
                .setClassOfValue(ISymbol.class).setMandatory(true);
477
                definition.addDynFieldInt("shapeType")
478
                .setMandatory(true);
479
                
480
                definition.addDynFieldArray("itemSymbolArray")
481
                .setClassOfItems(ISymbol.class);
482
                definition.addDynFieldArray("itemStringArray")
483
                .setClassOfItems(String.class);
484

  
485
            }
486
            return Boolean.TRUE;
487
        }
488

  
489
    }
490

  
491
    public static class RegisterLegend implements Callable {
492

  
493
        public Object call() throws Exception {
494
            MapContextManager manager =
495
                MapContextLocator.getMapContextManager();
496

  
497
            manager.registerLegend(
498
                FILTER_EXPRESSION_LEGEND_NAME,
499
                VectorFilterExpressionLegend.class);
500

  
501
            return Boolean.TRUE;
502
        }
503

  
504
    }
505
    
506
    public void saveToState(PersistentState state) throws PersistenceException {
507

  
508
        super.saveToState(state);
509
        state.set("useDefaultSymbol", this.isUseDefaultSymbol());
510
        state.set("defaultSymbol", this.getDefaultSymbol());
511
        state.set("shapeType", this.getShapeType());
512
        
513
        ISymbol[] syms = this.getSymbols();
514
        if (syms == null) {
515
            syms = new ISymbol[0];
516
        }
517
        Object[] vals = this.getValues();
518
        String[] vals_str = null;
519
        if (vals == null) {
520
            vals_str = new String[0];
521
        } else {
522
            vals_str = new String[vals.length];
523
            for (int i=0; i<vals.length; i++) {
524
                String aux = ((vals[i] == null) ? null : vals[i].toString());
525
                // Prevents saving localized version of 'Default'
526
                aux = translateDefault(aux, false);
527
                vals_str[i] = aux;
528
            }
529
        }
530
        
531
        state.set("itemSymbolArray", syms);
532
        state.set("itemStringArray", vals_str);
533
        
534
    }
535

  
536
    public void loadFromState(PersistentState state)
537
        throws PersistenceException {
538
        
539
        super.loadFromState(state);
540
        
541
        this.setShapeType(state.getInt("shapeType"));
542
        Boolean b = state.getBoolean("useDefaultSymbol");
543
        this.useDefaultSymbol(b);
544
        ISymbol defsym = (ISymbol) state.get("defaultSymbol");
545
        this.setDefaultSymbol(defsym);
546
        
547
        String[] strs = state.getStringArray("itemStringArray");
548
        ISymbol[] syms = (ISymbol[]) state.getArray("itemSymbolArray",
549
            ISymbol.class);
550
        
551
        if (strs.length != syms.length) {
552
            logger.info("VectorFilterExpressionLegend - load state - Different size in arrays: " + strs.length + ", " + syms.length);
553
        }
554
        int nmin = Math.min(strs.length, syms.length);
555
        for (int i=0; i<nmin; i++) {
556
            String aux = strs[i];
557
            aux = translateDefault(aux, true);
558
            this.addSymbol(aux, syms[i]);
559
        }
560
    }
561
    
562
    /**
563
     * Utility method to (un)translate the word 'Default'
564
     * @param aux
565
     * @param forward
566
     * If TRUE, then translate (Default -> Por defecto)
567
     * If FALSE then untranslate (Por defecto -> Default)
568
     * @return
569
     */
570
    private String translateDefault(String aux, boolean forward) {
571
        
572
        if (aux == null) {
573
            return null;
574
        }
575
        if (forward && aux.compareTo(NON_I18N_DEFAULT) == 0) {
576
            return I18N_DEFAULT;
577
        }
578
        if (!forward && aux.compareTo(I18N_DEFAULT) == 0) {
579
            return NON_I18N_DEFAULT;
580
        }
581
        return aux;
582
    }
583

  
584

  
585
    public Object clone() throws CloneNotSupportedException {
586
        
587
        VectorFilterExpressionLegend resp =
588
            (VectorFilterExpressionLegend) super.clone();
589
        
590
        Object[] vals = this.getValues();
591
        ISymbol[] syms = this.getSymbols();
592
        if (vals != null && syms != null) {
593
            
594
            resp.resetItems();
595
                
596
            int n = Math.min(vals.length, syms.length);
597
            for (int i=0; i<n; i++) {
598
                resp.addSymbol(
599
                    vals[i],
600
                    (ISymbol) syms[i].clone());
601
            }
602
        }
603
        ISymbol sym = this.getDefaultSymbol();
604
        sym = (ISymbol) sym.clone();
605
        resp.setDefaultSymbol(sym);
606
        return resp;
607
    }
608
    
609

  
610

  
611
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionSymbolPanel.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2013 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.symbology.gui.layerproperties;
24

  
25
import java.awt.Dimension;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.Insets;
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31

  
32
import javax.swing.BorderFactory;
33
import javax.swing.JOptionPane;
34
import javax.swing.JPanel;
35
import javax.swing.JScrollPane;
36
import javax.swing.JTextArea;
37
import javax.swing.ScrollPaneConstants;
38

  
39
import org.gvsig.andami.ui.mdiManager.IWindow;
40
import org.gvsig.andami.ui.mdiManager.MDIManager;
41
import org.gvsig.andami.ui.mdiManager.WindowInfo;
42
import org.gvsig.app.ApplicationLocator;
43
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
44
import org.gvsig.fmap.dal.feature.Feature;
45
import org.gvsig.fmap.geom.Geometry;
46
import org.gvsig.fmap.mapcontext.MapContextLocator;
47
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
48
import org.gvsig.gui.beans.AcceptCancelPanel;
49
import org.gvsig.i18n.Messages;
50
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
51
import org.gvsig.tools.evaluator.EvaluatorException;
52
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
53
import org.gvsig.tools.swing.api.ToolsSwingLocator;
54
import org.gvsig.tools.swing.api.evaluator.ComponentSwingManager;
55
import org.gvsig.tools.swing.api.evaluator.EvaluatorPanel;
56

  
57

  
58
/**
59
 * This panel shows an expression creation panel (from the Tools
60
 * library) and shows a symbol preview panel with a description
61
 * so the user can associate a symbol to the expression (symbol
62
 * will be used if expression evaluates to TRUE)
63
 * 
64
 * @see EvaluatorPanel
65
 * 
66
 * 
67
 * @author jldominguez
68
 *
69
 */
70
public class ExpressionSymbolPanel extends JPanel
71
implements ActionListener, IWindow {
72
    
73
    private Feature dummyFeature = null;
74
    private EvaluatorWithDescriptions evald = null;
75
    private int shptype = Geometry.TYPES.GEOMETRY;
76
    
77
    private JPanel symPanel = null;
78
    private JSymbolPreviewButton templateButton = null;
79
    private JTextArea descArea = null;
80
    private AcceptCancelPanel acPanel;
81
    private boolean okPressed = false;
82
    private WindowInfo winfo = null;
83
    
84
    private EvaluatorPanel evapa = null;
85
    
86
    public ExpressionSymbolPanel(
87
        Feature dummy_feat, EvaluatorWithDescriptions ed, int st, ISymbol sym) {
88
        
89
        dummyFeature = dummy_feat;
90
        evald = ed;
91
        shptype = st;
92
        
93
        initialize(sym);
94
    }
95
    
96
    private EvaluatorPanel getEvaluatorPanel() {
97
        if (evapa == null) {
98
            ComponentSwingManager esm =
99
                ToolsSwingLocator.getComponentSwingManager();
100
            evapa = esm.getEvaluatorPanel(
101
                dummyFeature.getType(),
102
                evald);
103
        }
104
        return evapa;
105
    }
106
    
107
    public String getExpression() {
108
        return getEvaluatorPanel().getExpression();
109
    }
110
    
111
    public ISymbol getSymbol() {
112
        ISymbol resp = getTemplateButton(null).getSymbol();
113
        resp.setDescription(this.getDescArea(null).getText());
114
        return resp;
115
    }
116

  
117
    /**
118
     * 
119
     */
120
    private void initialize(ISymbol sym) {
121
        
122
        this.setLayout(new GridBagLayout());
123
        GridBagConstraints gbc = new GridBagConstraints();
124
        
125
        gbc.gridx = 0;
126
        gbc.gridy = 0;
127
        gbc.anchor = GridBagConstraints.CENTER;
128
        gbc.fill = GridBagConstraints.BOTH;
129
        gbc.weightx = 1;
130
        gbc.weighty = 1;
131
        this.add(getEvaluatorPanel(), gbc);
132
        gbc.gridy = 1;
133
        gbc.weighty = 0;
134
        this.add(getSymbolPanel(sym), gbc);
135
        gbc.gridy = 2;
136
        this.add(getAcceptCancel(), gbc);
137
    }
138

  
139
    /**
140
     * @return
141
     */
142
    private JPanel getAcceptCancel() {
143
        
144
        if (acPanel == null) {
145
            acPanel = new AcceptCancelPanel(this, this);
146
        }
147
        return acPanel;
148
    }
149

  
150
    /**
151
     * @return
152
     */
153
    private JPanel getSymbolPanel(ISymbol sym) {
154
        
155
        if (symPanel == null) {
156
            
157
            symPanel = new JPanel();
158
            symPanel.setLayout(new GridBagLayout());
159
            symPanel.setBorder(BorderFactory.createTitledBorder(
160
                Messages.getText("_Symbol_and_description")));
161

  
162
            GridBagConstraints gbc = new GridBagConstraints();
163
            
164
            gbc.fill = GridBagConstraints.BOTH;
165
            gbc.anchor = GridBagConstraints.NORTHWEST;
166
            gbc.gridx = 0;
167
            gbc.gridy = 0;
168
            gbc.weightx = 0.2;
169
            gbc.weighty = 0;
170
            gbc.insets = new Insets(7, 7, 7, 7);
171
            symPanel.add(getTemplateButton(sym), gbc);
172
            
173
            gbc.gridx = 1;
174
            gbc.weightx = 0.8;
175
            
176
            JScrollPane scroll = new JScrollPane(getDescArea(sym));
177
            scroll.setHorizontalScrollBarPolicy(
178
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
179
            scroll.setVerticalScrollBarPolicy(
180
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
181
            symPanel.add(scroll, gbc);
182
        }
183
        return symPanel;
184
    }
185

  
186
    /**
187
     * @return
188
     */
189
    private JTextArea getDescArea(ISymbol sym) {
190
        if (descArea == null) {
191
            
192
            descArea = new JTextArea();
193
            descArea.setWrapStyleWord(true);
194
            descArea.setLineWrap(true);
195
            if (sym != null) {
196
                descArea.setText(sym.getDescription());
197
            }
198
        }
199
        return descArea;
200
    }
201

  
202
    /**
203
     * @return
204
     */
205
    private JSymbolPreviewButton getTemplateButton(ISymbol sym) {
206
        if (templateButton == null) {
207
            ISymbol inisym = sym;
208
            if (inisym == null) {
209
                inisym = MapContextLocator.getSymbolManager().
210
                    createSymbol(shptype);
211
            }
212
            templateButton = new JSymbolPreviewButton(inisym, shptype);
213
            templateButton.setPreferredSize(new Dimension(100, 35));
214
            templateButton.setMinimumSize(new Dimension(100, 35));
215
        }
216
        return templateButton;
217
    }
218

  
219
    /* (non-Javadoc)
220
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
221
     */
222
    public void actionPerformed(ActionEvent e) {
223
        
224
        if (e.getActionCommand().compareToIgnoreCase("ok") == 0) {
225
            
226
            Class return_class = null;
227
            try {
228
                return_class = validateExpression();
229
            } catch (EvaluatorException epe) {
230
                
231
                if (epe.getCause() instanceof ArithmeticException) {
232
                    
233
                    if (!userTolerates(epe)) {
234
                        okPressed = false;
235
                        return;
236
                    } else {
237
                        // User said ok
238
                        okPressed = true;
239
                        closeThis();
240
                        return;
241
                    }
242
                    
243
                } else {
244
                    String detail = epe.getMessageStack();
245
                    ApplicationLocator.getManager().messageDialog(
246
                        Messages.getText("incorrect_expression")
247
                        + "\n\n" + detail,
248
                        Messages.getText("error"),
249
                        JOptionPane.ERROR_MESSAGE);
250
                    okPressed = false;
251
                    return;
252
                }
253
            }
254
            
255
            if (return_class != Boolean.class) {
256
                int usr_opt = JOptionPane.showConfirmDialog(
257
                    this,
258
                    Messages.getText("_Result_not_boolean_so_zero_empty_string_null_are_false_Continue_question"),
259
                    Messages.getText("confirmation_dialog"),
260
                    JOptionPane.YES_NO_OPTION);
261
                if (usr_opt == JOptionPane.NO_OPTION) {
262
                    okPressed = false;
263
                    return;
264
                }
265
            }
266
            okPressed = true;
267
            closeThis();
268
            
269
        } else {
270
            if (e.getActionCommand().compareToIgnoreCase("cancel") == 0) {
271
                okPressed = false;
272
                closeThis();
273
            }
274
        }
275
    }
276
    
277
 
278
    /**
279
     * @param epe
280
     * @return
281
     */
282
    private boolean userTolerates(EvaluatorException epe) {
283
        
284
        String detail = Messages.getText(
285
            "_Expression_can_cause_arithmetic_issues_Continue_question");
286
        detail = detail + "\n\nMessage: ";
287
        detail = detail + epe.getMessageStack();
288

  
289
        int usr_opt = JOptionPane.showConfirmDialog(
290
            this,
291
            detail,
292
            Messages.getText("confirmation_dialog"),
293
            JOptionPane.YES_NO_OPTION);
294
        
295
        return usr_opt == JOptionPane.YES_OPTION;
296
    }
297

  
298
    /**
299
     * @return class of the return value
300
     */
301
    private Class validateExpression() throws EvaluatorException {
302
        
303
        String expr = this.getExpression();
304
        EvaluatorWithDescriptions evde = EvaluatorCreator.getEvaluator(expr);
305
        Object resp_class = null;
306
        
307
        try {
308
            /*
309
             * Try evaluate feature with default values
310
             */
311
            resp_class = evde.evaluate(dummyFeature.getEvaluatorData());
312
        } catch (EvaluatorException e) {
313
            /*
314
             * Parse exception or field not found or
315
             * divison by zero, etc.
316
             * Malformed expression, not valid
317
             */
318
            throw e;
319
        } catch (Exception e) {
320
            /*
321
             * All other exceptions.
322
             * Should not happen often.
323
             * We assume a strange
324
             * exception (NPE, etc) and decide it's not a valid
325
             * expression
326
             *  
327
             */
328
            throw new EvaluatorException(e);
329
        }
330
        
331
        if (resp_class == null) {
332
            return null;
333
        } else {
334
            return resp_class.getClass();
335
        }
336
    }
337

  
338
    private void closeThis() {
339
        MDIManager mm = ApplicationLocator.getManager().getUIManager();
340
        mm.closeWindow(this);
341
    }
342
    
343
    public boolean isOkPressed() {
344
        return okPressed;
345
    }
346

  
347
    /* (non-Javadoc)
348
     * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
349
     */
350
    public WindowInfo getWindowInfo() {
351
        if (winfo == null) {
352
            winfo = new WindowInfo(
353
                WindowInfo.MODALDIALOG |
354
                WindowInfo.RESIZABLE);
355

  
356
            winfo.setTitle(Messages.getText("expression_creator"));
357
            winfo.setWidth(675);
358
            winfo.setHeight(400);
359
        }
360
        return winfo;
361
    }
362

  
363
    /* (non-Javadoc)
364
     * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowProfile()
365
     */
366
    public Object getWindowProfile() {
367
        return WindowInfo.DIALOG_PROFILE;
368
    }
369

  
370
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.1/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package 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
import java.util.List;
51

  
52
import javax.swing.BoxLayout;
53
import javax.swing.ImageIcon;
54
import javax.swing.JCheckBox;
55
import javax.swing.JOptionPane;
56
import javax.swing.JPanel;
57

  
58
import org.slf4j.Logger;
59
import org.slf4j.LoggerFactory;
60

  
61
import org.gvsig.andami.IconThemeHelper;
62
import org.gvsig.andami.ui.mdiManager.MDIManager;
63
import org.gvsig.app.ApplicationLocator;
64
import org.gvsig.app.project.documents.view.legend.gui.Categories;
65
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
66
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
67
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
68
import org.gvsig.fmap.dal.exception.ReadException;
69
import org.gvsig.fmap.dal.feature.Feature;
70
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
71
import org.gvsig.fmap.dal.feature.FeatureStore;
72
import org.gvsig.fmap.dal.feature.FeatureType;
73
import org.gvsig.fmap.mapcontext.layers.FLayer;
74
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
75
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
76
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
77
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
78
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
79
import org.gvsig.gui.beans.swing.JBlank;
80
import org.gvsig.gui.beans.swing.JButton;
81
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
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
85
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
86
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
87

  
88
/**
89
 * Implements the JPanel that shows the properties of a
90
 * VectorialFilterExpressionLegend
91
 * in order to allows the user to modify its characteristics
92
 *
93
 * @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
94
 *
95
 */
96
public class VectorFilterExpressionPanel extends JPanel
97
implements ILegendPanel, ActionListener {
98
    
99
    private static final Logger logger = LoggerFactory.getLogger(
100
        VectorFilterExpressionPanel.class);
101
    
102
	private static final long serialVersionUID = -7187473609965942511L;
103
	private VectorFilterExpressionLegend theLegend;
104
	private VectorFilterExpressionLegend auxLegend;
105
	private ClassifiableVectorial layer;
106
	private PictureFillSymbol previewSymbol;
107
	private JPanel pnlCenter;
108
	private JPanel pnlMovBut;
109
	private SymbolTable symbolTable;
110
	private JButton btnAddExpression;
111
	private JButton btnModExpression;
112
	private JButton btnRemoveExpression;
113
	private JButton moveUp;
114
	private JButton moveDown;
115
	private int shapeType;
116
	protected JCheckBox chkdefaultvalues = null;
117
	protected JSymbolPreviewButton defaultSymbolPrev;
118
	private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
119

  
120
	/**
121
	 * This is the default constructor
122
	 */
123
	public VectorFilterExpressionPanel() {
124
		super();
125
		initialize();
126
	}
127

  
128

  
129
	/**
130
	 * This method initializes this
131
	 */
132
	private void initialize() {
133

  
134
		pnlCenter = new JPanel();
135
		pnlCenter.setLayout(new BorderLayout());
136

  
137
		JPanel pnlButtons = new JPanel();
138
		btnAddExpression = new JButton(
139
		    Messages.getText("new_filter_expression"));
140
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
141
		btnAddExpression.addActionListener(this);
142
		pnlButtons.add(btnAddExpression);
143

  
144
		btnModExpression = new JButton(
145
		    Messages.getText("modify_filter_expression"));
146
		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
147
		btnModExpression.addActionListener(this);
148
		pnlButtons.add(btnModExpression);
149

  
150
		btnRemoveExpression = new JButton(
151
		    Messages.getText("delete_filter_expression"));
152
		btnRemoveExpression.setActionCommand("REMOVE");
153
		btnRemoveExpression.addActionListener(this);
154
		pnlButtons.add(btnRemoveExpression);
155
		defaultSymbolPanel.add(getChkDefaultvalues());
156
		pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH);
157

  
158
		this.setLayout(new BorderLayout());
159
		this.add(pnlCenter, BorderLayout.CENTER);
160
		this.add(pnlButtons, BorderLayout.SOUTH);
161

  
162

  
163
	}
164
	public void getDefaultSymbolPrev(int shapeType) {
165
		if(defaultSymbolPrev == null){
166
			defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
167
			defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
168
			defaultSymbolPanel.add(defaultSymbolPrev,null);
169
		}
170
	}
171

  
172
	public String getDescription() {
173
		return Messages.getText(
174
		    "shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + ".";
175
	}
176

  
177
	public ISymbol getIconSymbol() {
178
		if (previewSymbol == null) {
179
			try {
180
				previewSymbol = new PictureFillSymbol();
181
				previewSymbol.setImage( new File(
182
						this.getClass().getClassLoader().
183
						getResource("images" + File.separator
184
						    + "legend" + File.separator
185
						    + "legend-overview-vectorial-unique-value.png").
186
						getFile()).toURI().toURL());
187
				previewSymbol.getMarkerFillProperties().
188
				setFillStyle(
189
						IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
190
			} catch (IOException e) {
191
				return null;
192
			}
193
		}
194
		return previewSymbol;
195
	}
196

  
197
	public ILegend getLegend() {
198
		auxLegend.clear();
199
		fillSymbolListFromTable();
200

  
201
		theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend();
202
		if(defaultSymbolPrev.getSymbol() != null)
203
			theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol());
204

  
205
		theLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
206
		return theLegend;
207
	}
208
	/**
209
	 * Fills the list of symbols of the legend
210
	 *
211
	 */
212
	private void fillSymbolListFromTable() {
213
		Object clave;
214
		ISymbol theSymbol;
215
		boolean bRestoValores = false;
216
		int hasta;
217

  
218
		FLyrVect m = (FLyrVect) layer;
219
		try {
220

  
221
			if(auxLegend.getClassifyingFieldNames() != null) {
222
				String[] fNames= auxLegend.getClassifyingFieldNames();
223
				int[] fieldTypes  = new int[auxLegend.getClassifyingFieldNames().length];
224

  
225
				FeatureStore fsto = (FeatureStore) m.getDataStore();
226
				FeatureType fty = fsto.getDefaultFeatureType();
227
				FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
228
				
229
				for (int i = 0; i < fNames.length; i++) {
230
					fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
231
				}
232

  
233
				auxLegend.setClassifyingFieldTypes(fieldTypes);
234
			}
235
		} catch (Exception e) {
236
		    
237
		}
238

  
239
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
240
		if (bRestoValores) {
241
			hasta = symbolTable.getRowCount() - 1;
242
		} else {
243
			hasta = symbolTable.getRowCount();
244
		}
245

  
246
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
247
			clave =  symbolTable.getFieldValue(row, 1);
248
			theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
249
			theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
250
			auxLegend.addSymbol(clave, theSymbol);
251
		}
252
		if(chkdefaultvalues.isSelected()){
253
			if(defaultSymbolPrev.getSymbol() != null){
254
				String description = VectorFilterExpressionLegend.I18N_DEFAULT;
255
				defaultSymbolPrev.getSymbol().setDescription(description);
256
				auxLegend.addSymbol(
257
				    description, defaultSymbolPrev.getSymbol());
258
			}
259
		}
260

  
261
	}
262

  
263
	public Class getLegendClass() {
264
		return VectorFilterExpressionLegend.class;
265
	}
266

  
267
	public JPanel getPanel() {
268
		return this;
269
	}
270

  
271
	public Class getParentClass() {
272
		return Categories.class;
273
	}
274

  
275
	public String getTitle() {
276
		return Messages.getText("expressions");
277
	}
278

  
279
	public boolean isSuitableFor(FLayer layer) {
280
		FLyrVect lVect = (FLyrVect) layer;
281
		try {
282
			return
283
			    VectorFilterExpressionLegend.isPoint(lVect.getShapeType())
284
			    ||
285
                VectorFilterExpressionLegend.isLinear(lVect.getShapeType())
286
                ||
287
                VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType());
288
		} catch (Exception e) {
289
			return false;
290
		}
291

  
292
	}
293

  
294
	public void setData(FLayer lyr, ILegend legend) {
295
		this.layer = (ClassifiableVectorial) lyr;
296
		shapeType = 0;
297

  
298
		try {
299
			shapeType = this.layer.getGeometryType().getType();
300
		} catch (ReadException e) {
301
		    logger.info("Error while getting layer shp type", e);
302
		    ApplicationLocator.getManager().message(
303
		        Messages.getText("generating_intervals"),
304
		        JOptionPane.ERROR_MESSAGE);
305
		}
306

  
307
		if (symbolTable != null)
308
			pnlCenter.remove(symbolTable);
309
		if (pnlMovBut != null)
310
			pnlCenter.remove(pnlMovBut);
311

  
312
		getDefaultSymbolPrev(shapeType);
313

  
314
		symbolTable = new SymbolTable(this, "expressions", shapeType);
315
		pnlCenter.add(symbolTable, BorderLayout.CENTER);
316
		pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
317

  
318

  
319
		if (legend instanceof VectorFilterExpressionLegend) {
320
		    
321
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
322
            if (auxLegend.isUseDefaultSymbol()) {
323
                // Default must not be in table
324
                fillTableSkipDefault(auxLegend);                
325
            } else {
326
                symbolTable.fillTableFromSymbolList(
327
                    auxLegend.getSymbols(),
328
                    auxLegend.getValues(),
329
                    auxLegend.getDescriptions());
330
            }
331
            
332
			
333
		} else {
334
			auxLegend = new VectorFilterExpressionLegend();
335
			auxLegend.setShapeType(shapeType);
336
		}
337
		defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
338
		getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol());
339
	}
340

  
341
	private JPanel getPnlMovBut() {
342
		if(pnlMovBut == null){
343
			pnlMovBut = new JPanel();
344
			pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS));
345
			pnlMovBut.add(new JBlank(1, 70));
346
			ImageIcon ico = IconThemeHelper.getImageIcon(
347
			    "symbol-layer-move-up");
348
			moveUp = new JButton(ico);
349
			pnlMovBut.add(moveUp);
350
			moveUp.setSize(new Dimension(15,15));
351
			pnlMovBut.add(new JBlank(1,10));
352
			ico = IconThemeHelper.getImageIcon(
353
                "symbol-layer-move-down");
354
			moveDown = new JButton(ico);
355
			pnlMovBut.add(moveDown);
356
			pnlMovBut.add(new JBlank(1, 70));
357
			moveDown.setActionCommand("MOVE-DOWN");
358
			moveUp.setActionCommand("MOVE-UP");
359
			moveDown.addActionListener(this);
360
			moveUp.addActionListener(this);
361
		}
362
		return pnlMovBut;
363
	}
364

  
365
	public void actionPerformed(ActionEvent e) {
366
	    
367
		int[] indices = null;
368
		Feature dummyFeat = null;
369

  
370
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
371
			indices = symbolTable.getSelectedRows();
372
		}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff