Revision 1201

View differences:

org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/buildNumber.properties
1
#Sun Aug 21 23:20:06 CEST 2016
2
buildNumber=40
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.symbology.library.VectorFilterExpressionLibrary
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/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.37/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.37/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 boolean useDefaultSymbol = false;
108

  
109
	private long error_msg_count = 0;
110

  
111
	private ArrayList<Item> newSymbols = new ArrayList<Item>() {
112
		private static final long serialVersionUID = 1L;
113

  
114
		public int indexOf(String expr) {
115
			return super.indexOf(new Item(expr, null));
116
		}
117
	};
118

  
119

  
120
	private class Item implements Cloneable {
121

  
122
		private ISymbol sym;
123
		// get it with getSql()
124
		// private String expression;
125
		private EvaluatorWithDescriptions evaluator;
126

  
127
		public Item(String expression, ISymbol sym) {
128
			this.sym = sym;
129
			evaluator = EvaluatorCreator.getEvaluator(expression);
130
		}
131

  
132
		public boolean equals(Object obj) {
133
			if (obj == null) return false;
134
			if (!obj.getClass().equals(Item.class)) return false;
135
			return this.evaluator.getSQL().equals(
136
			    ((Item) obj).evaluator.getSQL()
137
			    );
138
		}
139

  
140
		public String getStringExpression() {
141
			return evaluator.getSQL();
142
		}
143

  
144
		public Evaluator getEvaluator() {
145
			return evaluator;
146
		}
147

  
148
		public Object clone() {
149

  
150
		    ISymbol clonesym = null;
151
		    try {
152
                clonesym = (ISymbol) this.sym.clone();
153
            } catch (CloneNotSupportedException e) {
154
                logger.info("Error: unable to clone symbol.", e);
155
                clonesym = this.sym;
156
            }
157
		    return new Item(getStringExpression(), clonesym);
158
		}
159
	}
160

  
161
    public VectorFilterExpressionLegend() {
162
        this.setClassifyingFieldNames(new String[0]);
163
        this.setClassifyingFieldTypes(new int[0]);
164
    }
165

  
166
	public ISymbol getSymbolByFeature(Feature featu) {
167

  
168
	    EvaluatorData evda = featu.getEvaluatorData();
169

  
170
		ISymbol returnSymbol = null;
171
		Object result = null;
172
		String expr = null;
173

  
174
		try {
175

  
176
			for (int i = 0; i < newSymbols.size(); i++) {
177

  
178
				Evaluator eval = newSymbols.get(i).getEvaluator();
179
				expr = eval.getSQL();
180

  
181
                if (expr.equalsIgnoreCase(VectorFilterExpressionLegend.I18N_DEFAULT)){
182
                    /*
183
                     * Skip default item
184
                     */
185
                    continue;
186
                }
187

  
188
				result = eval.evaluate(evda);
189
				if (isConsideredTrue(result)) {
190
                    returnSymbol = newSymbols.get(i).sym;
191
                    if (returnSymbol != null) {
192
                        return returnSymbol;
193
                    }
194
				}
195
			}
196
		} catch (Exception e) {
197

  
198
		    if (error_msg_count % 1000 == 0) {
199
		        logger.info("Error (msg every 1000 occurrences) while getting symbol in VectorFilterExpressionLegend", e);
200
		        error_msg_count = 0;
201
		    }
202
		    error_msg_count++;
203
		}
204

  
205
		if (useDefaultSymbol)
206
			return getDefaultSymbol();
207

  
208
		return null;
209
	}
210

  
211
	/**
212
	 * Tells whether the input object is considered true.
213
	 * Basically, it is false if it has an empty value
214
	 * (FALSE, null, 0, "")
215
	 *
216
     * @param result
217
     * @return
218
     */
219
    private boolean isConsideredTrue(Object res) {
220

  
221
        if (res == null) {
222
            return false;
223
        }
224

  
225
        if (res instanceof Boolean) {
226
            return ((Boolean) res).booleanValue();
227
        }
228

  
229
        if (res instanceof Number) {
230
            return ((Number) res).doubleValue() != 0d;
231
        }
232

  
233
        if (res instanceof String) {
234
            return ((String) res).length() > 0;
235
        }
236

  
237
        // Because it is not null
238
        return true;
239
    }
240

  
241
	public void addSymbol(Object key, ISymbol symbol) {
242
		newSymbols.add(new Item((String)key.toString(),
243
				symbol));
244
	}
245

  
246
	public void clear() {
247
		newSymbols.clear();
248
	}
249

  
250
	public void resetItems() {
251
	    newSymbols = new ArrayList<Item>() {
252
            private static final long serialVersionUID = 1L;
253

  
254
            public int indexOf(String expr) {
255
                return super.indexOf(new Item(expr, null));
256
            }
257
	    };
258
	}
259

  
260
	public void delSymbol(Object key) {
261
		ISymbol mySymbol = null;
262
		for (int i = 0; i < newSymbols.size(); i++) {
263
			if (newSymbols.get(i).evaluator.getSQL().equals(key))
264
				newSymbols.remove(i);
265
		}
266
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(mySymbol,null));
267
	}
268

  
269

  
270
	public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
271

  
272
		for (int i = 0; i < newSymbols.size(); i++) {
273
			if (newSymbols.get(i).sym.equals(oldSymbol))
274
				newSymbols.get(i).sym = newSymbol;
275
		}
276

  
277
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(oldSymbol,newSymbol));
278
	}
279

  
280

  
281
	public String[] getDescriptions() {
282
		String[] descriptions = new String[newSymbols.size()];
283
		ISymbol[] auxSym = getSymbols();
284

  
285
		for (int i = 0; i < descriptions.length; i++)
286
			descriptions[i] = auxSym[i].getDescription();
287

  
288
		return descriptions;
289
	}
290

  
291
	public ISymbol[] getSymbols() {
292

  
293
		if (newSymbols != null) {
294
			ISymbol[] mySymbols = new ISymbol[newSymbols.size()];
295
			for (int i = 0; i < newSymbols.size(); i++) {
296
				mySymbols[i] = newSymbols.get(i).sym;
297
			}
298
			return mySymbols;
299
		}
300
		return null;
301
	}
302

  
303

  
304

  
305
	public ISymbol getDefaultSymbol() {
306
		if(defaultSymbol==null) {
307

  
308
		    defaultSymbol = MapContextLocator.getSymbolManager(
309
		        ).createSymbol(shapeType);
310
			fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol));
311
		}
312
		return defaultSymbol;
313
	}
314

  
315

  
316
	public String getClassName() {
317
		return getClass().getName();
318
	}
319

  
320

  
321
	public int getShapeType() {
322
		return shapeType;
323
	}
324

  
325
	public boolean isUseDefaultSymbol() {
326
		return useDefaultSymbol;
327
	}
328

  
329
	public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
330
		if (s == null) throw new NullPointerException("Default symbol cannot be null");
331
		ISymbol old = defaultSymbol;
332
		defaultSymbol = s;
333
		fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
334
	}
335

  
336
	public void setShapeType(int shapeType) {
337
		if (this.shapeType != shapeType) {
338

  
339
		    ISymbol sym = MapContextLocator.getSymbolManager(
340
		        ).createSymbol(shapeType);
341
			setDefaultSymbol(sym);
342
			this.shapeType = shapeType;
343
		}
344
	}
345

  
346
	public void useDefaultSymbol(boolean b) {
347
		useDefaultSymbol = b;
348
	}
349

  
350
	public Object[] getValues() {
351
		if (newSymbols != null) {
352
			Object[] myObjects = new Object[newSymbols.size()];
353
			for (int i = 0; i < newSymbols.size(); i++) {
354
				myObjects[i] = newSymbols.get(i).getStringExpression();
355
			}
356
			return myObjects;
357
		}
358
		return null;
359
	}
360

  
361
    public static boolean isPolygonal(int ty) {
362
        if (ty == Geometry.TYPES.MULTISURFACE
363
            || ty == Geometry.TYPES.SURFACE
364
            ) {
365
            return true;
366
        } else {
367
            return false;
368
        }
369
    }
370

  
371

  
372
    public static boolean isLinear(int ty) {
373
        if (ty == Geometry.TYPES.CIRCLE
374
            || ty == Geometry.TYPES.ARC
375
            || ty == Geometry.TYPES.CURVE
376
            || ty == Geometry.TYPES.ELLIPSE
377
            || ty == Geometry.TYPES.ELLIPTICARC
378
            || ty == Geometry.TYPES.SPLINE
379
            || ty == Geometry.TYPES.MULTICURVE
380
            ) {
381
            return true;
382
        } else {
383
            return false;
384
        }
385
    }
386

  
387
    public static boolean isPoint(int ty) {
388
        if (ty == Geometry.TYPES.POINT
389
            || ty == Geometry.TYPES.MULTIPOINT
390
            ) {
391
            return true;
392
        } else {
393
            return false;
394
        }
395
    }
396

  
397
    public void removeDefaultSymbol() {
398

  
399
    }
400

  
401
    // =============================
402

  
403
    public static class RegisterPersistence implements Callable {
404

  
405
        public Object call() throws Exception {
406

  
407
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
408
            if (manager.getDefinition(
409
                FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
410
                DynStruct definition = manager
411
                    .addDefinition(VectorFilterExpressionLegend.class,
412
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
413
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME
414
                        + " Persistence definition", null, null);
415

  
416
                definition.extend(manager.getDefinition(
417
                    AbstractClassifiedVectorLegend
418
                    .CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME));
419

  
420
                definition.addDynFieldBoolean("useDefaultSymbol")
421
                .setMandatory(true);
422
                definition.addDynFieldObject("defaultSymbol")
423
                .setClassOfValue(ISymbol.class).setMandatory(true);
424
                definition.addDynFieldInt("shapeType")
425
                .setMandatory(true);
426

  
427
                definition.addDynFieldArray("itemSymbolArray")
428
                .setClassOfItems(ISymbol.class);
429
                definition.addDynFieldArray("itemStringArray")
430
                .setClassOfItems(String.class);
431

  
432
            }
433
            return Boolean.TRUE;
434
        }
435

  
436
    }
437

  
438
    public static class RegisterLegend implements Callable {
439

  
440
        public Object call() throws Exception {
441
            MapContextManager manager =
442
                MapContextLocator.getMapContextManager();
443

  
444
            manager.registerLegend(
445
                FILTER_EXPRESSION_LEGEND_NAME,
446
                VectorFilterExpressionLegend.class);
447

  
448
            return Boolean.TRUE;
449
        }
450

  
451
    }
452

  
453
    public void saveToState(PersistentState state) throws PersistenceException {
454

  
455
        super.saveToState(state);
456
        state.set("useDefaultSymbol", this.isUseDefaultSymbol());
457
        state.set("defaultSymbol", this.getDefaultSymbol());
458
        state.set("shapeType", this.getShapeType());
459

  
460
        ISymbol[] syms = this.getSymbols();
461
        if (syms == null) {
462
            syms = new ISymbol[0];
463
        }
464
        Object[] vals = this.getValues();
465
        String[] vals_str = null;
466
        if (vals == null) {
467
            vals_str = new String[0];
468
        } else {
469
            vals_str = new String[vals.length];
470
            for (int i=0; i<vals.length; i++) {
471
                String aux = ((vals[i] == null) ? null : vals[i].toString());
472
                // Prevents saving localized version of 'Default'
473
                aux = translateDefault(aux, false);
474
                vals_str[i] = aux;
475
            }
476
        }
477

  
478
        state.set("itemSymbolArray", syms);
479
        state.set("itemStringArray", vals_str);
480

  
481
    }
482

  
483
    public void loadFromState(PersistentState state)
484
        throws PersistenceException {
485

  
486
        super.loadFromState(state);
487

  
488
        this.setShapeType(state.getInt("shapeType"));
489
        Boolean b = state.getBoolean("useDefaultSymbol");
490
        this.useDefaultSymbol(b);
491
        ISymbol defsym = (ISymbol) state.get("defaultSymbol");
492
        this.setDefaultSymbol(defsym);
493

  
494
        String[] strs = state.getStringArray("itemStringArray");
495
        ISymbol[] syms = (ISymbol[]) state.getArray("itemSymbolArray",
496
            ISymbol.class);
497

  
498
        if (strs.length != syms.length) {
499
            logger.info("VectorFilterExpressionLegend - load state - Different size in arrays: " + strs.length + ", " + syms.length);
500
        }
501
        int nmin = Math.min(strs.length, syms.length);
502
        for (int i=0; i<nmin; i++) {
503
            String aux = strs[i];
504
            aux = translateDefault(aux, true);
505
            this.addSymbol(aux, syms[i]);
506
        }
507
    }
508

  
509
    /**
510
     * Utility method to (un)translate the word 'Default'
511
     * @param aux
512
     * @param forward
513
     * If TRUE, then translate (Default -> Por defecto)
514
     * If FALSE then untranslate (Por defecto -> Default)
515
     * @return
516
     */
517
    private String translateDefault(String aux, boolean forward) {
518

  
519
        if (aux == null) {
520
            return null;
521
        }
522
        if (forward && aux.compareTo(NON_I18N_DEFAULT) == 0) {
523
            return I18N_DEFAULT;
524
        }
525
        if (!forward && aux.compareTo(I18N_DEFAULT) == 0) {
526
            return NON_I18N_DEFAULT;
527
        }
528
        return aux;
529
    }
530

  
531

  
532
    public Object clone() throws CloneNotSupportedException {
533

  
534
        VectorFilterExpressionLegend resp =
535
            (VectorFilterExpressionLegend) super.clone();
536

  
537
        Object[] vals = this.getValues();
538
        ISymbol[] syms = this.getSymbols();
539
        if (vals != null && syms != null) {
540

  
541
            resp.resetItems();
542

  
543
            int n = Math.min(vals.length, syms.length);
544
            for (int i=0; i<n; i++) {
545
                resp.addSymbol(
546
                    vals[i],
547
                    (ISymbol) syms[i].clone());
548
            }
549
        }
550
        ISymbol sym = this.getDefaultSymbol();
551
        sym = (ISymbol) sym.clone();
552
        resp.setDefaultSymbol(sym);
553
        return resp;
554
    }
555

  
556

  
557

  
558
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/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.JButton;
55
import javax.swing.JCheckBox;
56
import javax.swing.JOptionPane;
57
import javax.swing.JPanel;
58

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

  
62
import org.gvsig.andami.IconThemeHelper;
63
import org.gvsig.andami.ui.mdiManager.MDIManager;
64
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
import org.gvsig.fmap.dal.feature.Feature;
71
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
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
80
import org.gvsig.gui.beans.swing.JBlank;
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
import org.gvsig.tools.swing.api.ToolsSwingLocator;
88
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
89

  
90
/**
91
 * Implements the JPanel that shows the properties of a
92
 * VectorialFilterExpressionLegend
93
 * in order to allows the user to modify its characteristics
94
 *
95
 * @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
96
 *
97
 */
98
public class VectorFilterExpressionPanel extends JPanel
99
implements ILegendPanel, ActionListener {
100

  
101
    private static final Logger logger = LoggerFactory.getLogger(
102
        VectorFilterExpressionPanel.class);
103

  
104
	private static final long serialVersionUID = -7187473609965942511L;
105
	private VectorFilterExpressionLegend theLegend;
106
	private VectorFilterExpressionLegend auxLegend;
107
	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
	private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
122

  
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
		btnAddExpression = usabilitySwingManager.createJButton(
142
		    Messages.getText("new_filter_expression"));
143
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
144
		btnAddExpression.addActionListener(this);
145
		pnlButtons.add(btnAddExpression);
146

  
147
		btnModExpression = usabilitySwingManager.createJButton(
148
		    Messages.getText("modify_filter_expression"));
149
		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
150
		btnModExpression.addActionListener(this);
151
		pnlButtons.add(btnModExpression);
152

  
153
		btnRemoveExpression = usabilitySwingManager.createJButton(
154
		    Messages.getText("delete_filter_expression"));
155
		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
		return Messages.getText(
177
		    "shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + ".";
178
	}
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
						getResource("images" + File.separator
187
						    + "legend" + File.separator
188
						    + "legend-overview-vectorial-unique-value.png").
189
						getFile()).toURI().toURL());
190
				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
		theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend();
205
		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
				FeatureStore fsto = (FeatureStore) m.getDataStore();
227
				FeatureType fty = fsto.getDefaultFeatureType();
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

  
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
				String description = VectorFilterExpressionLegend.I18N_DEFAULT;
250
				defaultSymbolPrev.getSymbol().setDescription(description);
251
				auxLegend.addSymbol(
252
				    description, defaultSymbolPrev.getSymbol());
253
			}
254
		}
255

  
256
	}
257

  
258
	public Class<VectorFilterExpressionLegend> getLegendClass() {
259
		return VectorFilterExpressionLegend.class;
260
	}
261

  
262
	public JPanel getPanel() {
263
		return this;
264
	}
265

  
266
	public Class<Categories> getParentClass() {
267
		return Categories.class;
268
	}
269

  
270
	public String getTitle() {
271
		return Messages.getText("expressions");
272
	}
273

  
274
	public boolean isSuitableFor(FLayer layer) {
275
		FLyrVect lVect = (FLyrVect) layer;
276
		try {
277
			return
278
			    VectorFilterExpressionLegend.isPoint(lVect.getShapeType())
279
			    ||
280
                VectorFilterExpressionLegend.isLinear(lVect.getShapeType())
281
                ||
282
                VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType());
283
		} catch (Exception e) {
284
			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
			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
		}
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

  
316
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
317
            if (auxLegend.isUseDefaultSymbol()) {
318
                // Default must not be in table
319
                fillTableSkipDefault(auxLegend);
320
            } else {
321
                symbolTable.fillTableFromSymbolList(
322
                    auxLegend.getSymbols(),
323
                    auxLegend.getValues(),
324
                    auxLegend.getDescriptions());
325
            }
326

  
327

  
328
		} 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
			ImageIcon ico = IconThemeHelper.getImageIcon(
342
			    "symbol-layer-move-up");
343
			moveUp = usabilitySwingManager.createJButton(ico);
344
			pnlMovBut.add(moveUp);
345
			moveUp.setSize(new Dimension(15,15));
346
			pnlMovBut.add(new JBlank(1,10));
347
			ico = IconThemeHelper.getImageIcon(
348
                "symbol-layer-move-down");
349
			moveDown = usabilitySwingManager.createJButton(ico);
350
			pnlMovBut.add(moveDown);
351
			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

  
362
		int[] indices = null;
363
		Feature dummyFeat = null;
364

  
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
			ArrayList<String> orders = new ArrayList<String>();
387

  
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

  
394
		    FLyrVect vect = (FLyrVect) layer;
395
		    FeatureStore fsto = (FeatureStore) vect.getDataStore();
396
		    FeatureType fty = null;
397
		    int shptype = 0;
398

  
399
		    try {
400
		        fty = fsto.getDefaultFeatureType();
401
		        shptype = vect.getGeometryType().getType();
402
		        dummyFeat = fsto.createNewFeature(true);
403
		    } catch (Exception exc) {
404
		        logger.error(Messages.getText(
405
		            "error_trying_to_access_to_the_layer"), exc);
406
		        return;
407
		    }
408

  
409
		    EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator("");
410
		    MDIManager mm = ApplicationLocator.getManager().getUIManager();
411

  
412
		    ExpressionSymbolPanel esp = new ExpressionSymbolPanel(
413
		        dummyFeat, evalu, shptype, null);
414
		    mm.addCentredWindow(esp);
415

  
416
		    /*
417
		     * esp is modal
418
		     */
419
		    if (!esp.isOkPressed()) {
420
		        return;
421
		    }
422

  
423
		    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

  
432
		    ISymbol sym = esp.getSymbol();
433
		    evalu = EvaluatorCreator.getEvaluator(expr);
434
		    // Add all fields in the feature type
435
		    this.addClassFieldNames(fty);
436

  
437
            auxLegend.addSymbol(expr, sym);
438
            symbolTable.removeAllItems();
439
            fillTableSkipDefault(auxLegend);
440

  
441
			repaint();
442
		}
443
		else if (e.getActionCommand() == "MODIFY_EXPRESSION") {
444

  
445
			if(symbolTable.getSelectedRowElements() == null) {
446
				JOptionPane.showMessageDialog(this,
447
				    Messages.getText("select_one_row")+".\n");
448
			} else {
449

  
450
		         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

  
464
		        ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0];
465
                String expression = (String) symbolTable.getSelectedRowElements()[1];
466

  
467
                EvaluatorWithDescriptions evalu =
468
                    EvaluatorCreator.getEvaluator(expression);
469

  
470
                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

  
481
	            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

  
490
	            ISymbol sym = esp.getSymbol();
491
	            evalu = EvaluatorCreator.getEvaluator(expr);
492
	            // Add all fields in the feature type
493
	            this.addClassFieldNames(fty);
494

  
495
	            // Remove old
496
				auxLegend.delSymbol(expression);
497
				auxLegend.addSymbol(expr, sym);
498
				symbolTable.removeAllItems();
499
				this.fillTableSkipDefault(auxLegend);
500

  
501
				repaint();
502
			}
503
		}
504

  
505
		else if (e.getActionCommand() == "REMOVE") {
506

  
507
			if(symbolTable.getSelectedRowElements() == null) {
508
				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
				symbolTable.removeAllItems();
514
				fillTableSkipDefault(auxLegend);
515

  
516
				repaint();
517
			}
518
		}
519
	}
520

  
521

  
522
	private void addClassFieldNames(FeatureType ft) {
523

  
524
	    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
	/**
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
	private void addClassFieldNames(String[] fieldNamesExpression) {
537
		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
	    ImageIcon ii = IconThemeHelper.getImageIcon(
572
	        "legend-overview-vector-filter-expression");
573
	    return ii;
574
	}
575

  
576
	/**
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
			chkdefaultvalues.setText(Messages.getText("resto_valores")+": ");
585
			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

  
601
	private void fillTableSkipDefault(VectorFilterExpressionLegend leg) {
602

  
603
	    Object[] src_expr = leg.getValues();
604
	    List<Integer> rem_ind = new ArrayList<Integer>();
605
	    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

  
615
        List<ISymbol> syms = new ArrayList<ISymbol>();
616
        List<Object> vals = new ArrayList<Object>();
617
        List<String> descs = new ArrayList<String>();
618
        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

  
631

  
632
    /**
633
     * @param i
634
     * @param rem_ind
635
     * @return
636
     */
637
    private boolean isIn(int n, List<Integer> int_list) {
638

  
639
        if (int_list == null || int_list.size() == 0) {
640
            return false;
641
        }
642

  
643
        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
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionFieldCellEditor.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.Component;
44
import java.util.EventObject;
45

  
46
import javax.swing.JTable;
47
import javax.swing.JTextField;
48
import javax.swing.event.CellEditorListener;
49
import javax.swing.table.TableCellEditor;
50

  
51
/**
52
 * Cell Editor for expressions. It controls the edition events in an expression
53
 * column of the table
54
 *
55
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
56
 */
57
public class ExpressionFieldCellEditor extends JTextField implements TableCellEditor {
58

  
59
	private static final long serialVersionUID = 1L;
60

  
61
	public ExpressionFieldCellEditor() {
62

  
63
	}
64

  
65
	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
66

  
67
		return null;
68
	}
69

  
70
	public void addCellEditorListener(CellEditorListener l) {
71
		throw new RuntimeException("Not yet implemented");
72
	}
73

  
74
	public void cancelCellEditing() {
75
		throw new RuntimeException("Not yet implemented");
76

  
77
	}
78

  
79
	public Object getCellEditorValue() {
80
		return null;
81
	}
82

  
83
	public boolean isCellEditable(EventObject anEvent) {
84
		return false;
85
	}
86

  
87
	public void removeCellEditorListener(CellEditorListener l) {
88
		throw new RuntimeException("Not yet implemented");
89

  
90
	}
91

  
92
	public boolean shouldSelectCell(EventObject anEvent) {
93
		return false;
94
	}
95

  
96
	public boolean stopCellEditing() {
97
		return false;
98
	}
99

  
100
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.37/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;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff