Revision 5038

View differences:

org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.134/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.134/src/main/java/org/gvsig/symbology/fmap/rendering/VectorFilterExpressionLegend.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.rendering;
25

  
26

  
27
import java.util.ArrayList;
28
import org.gvsig.fmap.dal.DALLocator;
29
import org.gvsig.fmap.dal.DataManager;
30
import org.gvsig.fmap.dal.exception.InitializeException;
31

  
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.geom.Geometry;
37
import org.gvsig.fmap.geom.GeometryLocator;
38
import org.gvsig.fmap.geom.GeometryManager;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.MapContextManager;
41
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
44
import org.gvsig.i18n.Messages;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.driver.impl.PersistenceBasedLegendWriter;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynobject.DynStruct;
49
import org.gvsig.tools.evaluator.Evaluator;
50
import org.gvsig.tools.evaluator.EvaluatorData;
51
import org.gvsig.tools.persistence.PersistenceManager;
52
import org.gvsig.tools.persistence.PersistentState;
53
import org.gvsig.tools.persistence.exception.PersistenceException;
54
import org.gvsig.tools.util.Callable;
55
import org.gvsig.tools.util.Caller;
56
import org.gvsig.tools.util.impl.DefaultCaller;
57

  
58

  
59
/**
60
 *
61
 * Implements a vector legend which represents the elements of a layer
62
 * depending on the value of an expression. That is, if the expression is
63
 * evaluated to true, then the symbol associated to the expression is painted.
64
 * In other case it is not showed.
65
 *
66
 * If the expression result is a string, it is considered false if
67
 * it is the empty string "", true otherwise.
68
 *
69
 * If the expression result is numeric, it is considered false
70
 * if it is zero, and true otherwise.
71
 *
72
 * In other cases, it is considered false if the result is null and true
73
 * otherwise.
74
 *
75
 * @author gvSIG Team
76
 */
77
public class VectorFilterExpressionLegend
78
extends AbstractClassifiedVectorLegend  {
79

  
80
    private static final Logger logger = LoggerFactory.getLogger(
81
        VectorFilterExpressionLegend.class);
82

  
83
    public static final String
84
    FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME =
85
    "FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME";
86

  
87
    public static final String
88
    FILTER_EXPRESSION_LEGEND_NAME = "FILTER_EXPRESSION_LEGEND_NAME";
89

  
90
    public static final String I18N_DEFAULT = Messages.getText("default_value");
91
    public static final String NON_I18N_DEFAULT = Messages.getText("Default");
92

  
93
	private int shapeType;
94
	private ISymbol defaultSymbol;
95

  
96
	private boolean useDefaultSymbol = false;
97

  
98
	private long error_msg_count = 0;
99

  
100
	private ArrayList<Item> newSymbols = new ArrayList<Item>() {
101
		private static final long serialVersionUID = 1L;
102

  
103
		public int indexOf(String expr) {
104
			return super.indexOf(new Item(expr, null));
105
		}
106
	};
107

  
108

  
109
	private class Item implements Cloneable {
110

  
111
		private ISymbol sym;
112
		private Evaluator evaluator;
113

  
114
		public Item(String expression, ISymbol sym) {
115
			this.sym = sym;
116
      DataManager dataManager = DALLocator.getDataManager();
117
      try {
118
        evaluator = dataManager.createFilter(expression);
119
      } catch (InitializeException ex) {
120
        evaluator = null;
121
      }
122
		}
123

  
124
		public boolean equals(Object obj) {
125
			if (obj == null) return false;
126
			if (!obj.getClass().equals(Item.class)) return false;
127
			return this.evaluator.getSQL().equals(
128
			    ((Item) obj).evaluator.getSQL()
129
			    );
130
		}
131

  
132
		public String getStringExpression() {
133
			return evaluator.getSQL();
134
		}
135

  
136
		public Evaluator getEvaluator() {
137
			return evaluator;
138
		}
139

  
140
		public Object clone() {
141

  
142
		    ISymbol clonesym = null;
143
		    try {
144
                clonesym = (ISymbol) this.sym.clone();
145
            } catch (CloneNotSupportedException e) {
146
                logger.info("Error: unable to clone symbol.", e);
147
                clonesym = this.sym;
148
            }
149
		    return new Item(getStringExpression(), clonesym);
150
		}
151
	}
152

  
153
    public VectorFilterExpressionLegend() {
154
        this.setClassifyingFieldNames(new String[0]);
155
        this.setClassifyingFieldTypes(new int[0]);
156
    }
157

  
158
	public ISymbol getSymbolByFeature(Feature featu) {
159

  
160
	    EvaluatorData evda = featu.getEvaluatorData();
161

  
162
		ISymbol returnSymbol = null;
163
		Object result = null;
164
		String expr = null;
165

  
166
		try {
167

  
168
			for (int i = 0; i < newSymbols.size(); i++) {
169

  
170
				Evaluator eval = newSymbols.get(i).getEvaluator();
171
				expr = eval.getSQL();
172

  
173
                if (expr.equalsIgnoreCase(VectorFilterExpressionLegend.I18N_DEFAULT)){
174
                    /*
175
                     * Skip default item
176
                     */
177
                    continue;
178
                }
179

  
180
				result = eval.evaluate(evda);
181
				if (isConsideredTrue(result)) {
182
                    returnSymbol = newSymbols.get(i).sym;
183
                    if (returnSymbol != null) {
184
                        return returnSymbol;
185
                    }
186
				}
187
			}
188
		} catch (Exception e) {
189

  
190
		    if (error_msg_count % 1000 == 0) {
191
		        logger.info("Error (msg every 1000 occurrences) while getting symbol in VectorFilterExpressionLegend", e);
192
		        error_msg_count = 0;
193
		    }
194
		    error_msg_count++;
195
		}
196

  
197
		if (useDefaultSymbol)
198
			return getDefaultSymbol();
199

  
200
		return null;
201
	}
202

  
203
	/**
204
	 * Tells whether the input object is considered true.
205
	 * Basically, it is false if it has an empty value
206
	 * (FALSE, null, 0, "")
207
	 *
208
     * @param result
209
     * @return
210
     */
211
    private boolean isConsideredTrue(Object res) {
212

  
213
        if (res == null) {
214
            return false;
215
        }
216

  
217
        if (res instanceof Boolean) {
218
            return ((Boolean) res).booleanValue();
219
        }
220

  
221
        if (res instanceof Number) {
222
            return ((Number) res).doubleValue() != 0d;
223
        }
224

  
225
        if (res instanceof String) {
226
            return ((String) res).length() > 0;
227
        }
228

  
229
        // Because it is not null
230
        return true;
231
    }
232

  
233
	public void addSymbol(Object key, ISymbol symbol) {
234
		newSymbols.add(new Item((String)key.toString(),
235
				symbol));
236
	}
237

  
238
	public void clear() {
239
		newSymbols.clear();
240
	}
241

  
242
	public void resetItems() {
243
	    newSymbols = new ArrayList<Item>() {
244
            private static final long serialVersionUID = 1L;
245

  
246
            public int indexOf(String expr) {
247
                return super.indexOf(new Item(expr, null));
248
            }
249
	    };
250
	}
251

  
252
	public void delSymbol(Object key) {
253
		ISymbol mySymbol = null;
254
		for (int i = 0; i < newSymbols.size(); i++) {
255
			if (newSymbols.get(i).evaluator.getSQL().equals(key))
256
				newSymbols.remove(i);
257
		}
258
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(mySymbol,null));
259
	}
260

  
261

  
262
	public void replace(ISymbol oldSymbol, ISymbol newSymbol) {
263

  
264
		for (int i = 0; i < newSymbols.size(); i++) {
265
			if (newSymbols.get(i).sym.equals(oldSymbol))
266
				newSymbols.get(i).sym = newSymbol;
267
		}
268

  
269
		fireClassifiedSymbolChangeEvent(new SymbolLegendEvent(oldSymbol,newSymbol));
270
	}
271

  
272

  
273
	public String[] getDescriptions() {
274
		String[] descriptions = new String[newSymbols.size()];
275
		ISymbol[] auxSym = getSymbols();
276

  
277
		for (int i = 0; i < descriptions.length; i++)
278
			descriptions[i] = auxSym[i].getDescription();
279

  
280
		return descriptions;
281
	}
282

  
283
	public ISymbol[] getSymbols() {
284

  
285
		if (newSymbols != null) {
286
			ISymbol[] mySymbols = new ISymbol[newSymbols.size()];
287
			for (int i = 0; i < newSymbols.size(); i++) {
288
				mySymbols[i] = newSymbols.get(i).sym;
289
			}
290
			return mySymbols;
291
		}
292
		return null;
293
	}
294

  
295

  
296

  
297
	public ISymbol getDefaultSymbol() {
298
		if(defaultSymbol==null) {
299

  
300
		    defaultSymbol = MapContextLocator.getSymbolManager(
301
		        ).createSymbol(shapeType);
302
			fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null, defaultSymbol));
303
		}
304
		return defaultSymbol;
305
	}
306

  
307

  
308
	public String getClassName() {
309
		return getClass().getName();
310
	}
311

  
312

  
313
	public int getShapeType() {
314
		return shapeType;
315
	}
316

  
317
	public boolean isUseDefaultSymbol() {
318
		return useDefaultSymbol;
319
	}
320

  
321
	public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
322
		if (s == null) throw new NullPointerException("Default symbol cannot be null");
323
		ISymbol old = defaultSymbol;
324
		defaultSymbol = s;
325
		fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, defaultSymbol));
326
	}
327

  
328
	public void setShapeType(int shapeType) {
329
		if (this.shapeType != shapeType) {
330

  
331
		    ISymbol sym = MapContextLocator.getSymbolManager(
332
		        ).createSymbol(shapeType);
333
			setDefaultSymbol(sym);
334
			this.shapeType = shapeType;
335
		}
336
	}
337

  
338
	public void useDefaultSymbol(boolean b) {
339
		useDefaultSymbol = b;
340
	}
341

  
342
	public Object[] getValues() {
343
		if (newSymbols != null) {
344
			Object[] myObjects = new Object[newSymbols.size()];
345
			for (int i = 0; i < newSymbols.size(); i++) {
346
				myObjects[i] = newSymbols.get(i).getStringExpression();
347
			}
348
			return myObjects;
349
		}
350
		return null;
351
	}
352

  
353
    public static boolean isPolygonal(int ty) {
354
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
355
        return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || 
356
            geomManager.isSubtype(Geometry.TYPES.SURFACE, ty);
357
    }
358

  
359

  
360
    public static boolean isLinear(int ty) {
361
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
362
        return geomManager.isSubtype(Geometry.TYPES.MULTICURVE, ty) || 
363
            geomManager.isSubtype(Geometry.TYPES.CURVE, ty);
364
    }
365
    
366
    public static boolean isPoint(int ty) {
367
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
368
        return geomManager.isSubtype(Geometry.TYPES.MULTIPOINT, ty) || 
369
            geomManager.isSubtype(Geometry.TYPES.POINT, ty);
370
    }
371
    
372
    public void removeDefaultSymbol() {
373

  
374
    }
375

  
376
    // =============================
377

  
378
    public static class RegisterPersistence implements Callable {
379

  
380
        public Object call() throws Exception {
381

  
382
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
383
            if (manager.getDefinition(
384
                FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
385
                DynStruct definition = manager
386
                    .addDefinition(VectorFilterExpressionLegend.class,
387
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
388
                        FILTER_EXPRESSION_LEGEND_PERSISTENCE_DEFINITION_NAME
389
                        + " Persistence definition", null, null);
390

  
391
                definition.extend(manager.getDefinition(
392
                    AbstractClassifiedVectorLegend
393
                    .CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME));
394

  
395
                definition.addDynFieldBoolean("useDefaultSymbol")
396
                .setMandatory(true);
397
                definition.addDynFieldObject("defaultSymbol")
398
                .setClassOfValue(ISymbol.class).setMandatory(true);
399
                definition.addDynFieldInt("shapeType")
400
                .setMandatory(true);
401

  
402
                definition.addDynFieldArray("itemSymbolArray")
403
                .setClassOfItems(ISymbol.class);
404
                definition.addDynFieldArray("itemStringArray")
405
                .setClassOfItems(String.class);
406

  
407
            }
408
            return Boolean.TRUE;
409
        }
410

  
411
    }
412

  
413
    public static class RegisterLegend implements Callable {
414

  
415
        public Object call() throws Exception {
416
            MapContextManager manager =
417
                MapContextLocator.getMapContextManager();
418

  
419
            manager.registerLegend(
420
                FILTER_EXPRESSION_LEGEND_NAME,
421
                VectorFilterExpressionLegend.class);
422

  
423
            return Boolean.TRUE;
424
        }
425

  
426
    }
427

  
428
    public void saveToState(PersistentState state) throws PersistenceException {
429

  
430
        super.saveToState(state);
431
        state.set("useDefaultSymbol", this.isUseDefaultSymbol());
432
        state.set("defaultSymbol", this.getDefaultSymbol());
433
        state.set("shapeType", this.getShapeType());
434

  
435
        ISymbol[] syms = this.getSymbols();
436
        if (syms == null) {
437
            syms = new ISymbol[0];
438
        }
439
        Object[] vals = this.getValues();
440
        String[] vals_str = null;
441
        if (vals == null) {
442
            vals_str = new String[0];
443
        } else {
444
            vals_str = new String[vals.length];
445
            for (int i=0; i<vals.length; i++) {
446
                String aux = ((vals[i] == null) ? null : vals[i].toString());
447
                // Prevents saving localized version of 'Default'
448
                aux = translateDefault(aux, false);
449
                vals_str[i] = aux;
450
            }
451
        }
452

  
453
        state.set("itemSymbolArray", syms);
454
        state.set("itemStringArray", vals_str);
455

  
456
    }
457

  
458
    public void loadFromState(PersistentState state)
459
        throws PersistenceException {
460

  
461
        super.loadFromState(state);
462

  
463
        this.setShapeType(state.getInt("shapeType"));
464
        Boolean b = state.getBoolean("useDefaultSymbol");
465
        this.useDefaultSymbol(b);
466
        ISymbol defsym = (ISymbol) state.get("defaultSymbol");
467
        this.setDefaultSymbol(defsym);
468

  
469
        String[] strs = state.getStringArray("itemStringArray");
470
        ISymbol[] syms = (ISymbol[]) state.getArray("itemSymbolArray",
471
            ISymbol.class);
472

  
473
        if (strs.length != syms.length) {
474
            logger.info("VectorFilterExpressionLegend - load state - Different size in arrays: " + strs.length + ", " + syms.length);
475
        }
476
        int nmin = Math.min(strs.length, syms.length);
477
        for (int i=0; i<nmin; i++) {
478
            String aux = strs[i];
479
            aux = translateDefault(aux, true);
480
            this.addSymbol(aux, syms[i]);
481
        }
482
    }
483

  
484
    /**
485
     * Utility method to (un)translate the word 'Default'
486
     * @param aux
487
     * @param forward
488
     * If TRUE, then translate (Default -> Por defecto)
489
     * If FALSE then untranslate (Por defecto -> Default)
490
     * @return
491
     */
492
    private String translateDefault(String aux, boolean forward) {
493

  
494
        if (aux == null) {
495
            return null;
496
        }
497
        if (forward && aux.compareTo(NON_I18N_DEFAULT) == 0) {
498
            return I18N_DEFAULT;
499
        }
500
        if (!forward && aux.compareTo(I18N_DEFAULT) == 0) {
501
            return NON_I18N_DEFAULT;
502
        }
503
        return aux;
504
    }
505

  
506

  
507
    public Object clone() throws CloneNotSupportedException {
508

  
509
        VectorFilterExpressionLegend resp =
510
            (VectorFilterExpressionLegend) super.clone();
511

  
512
        Object[] vals = this.getValues();
513
        ISymbol[] syms = this.getSymbols();
514
        if (vals != null && syms != null) {
515

  
516
            resp.resetItems();
517

  
518
            int n = Math.min(vals.length, syms.length);
519
            for (int i=0; i<n; i++) {
520
                resp.addSymbol(
521
                    vals[i],
522
                    (ISymbol) syms[i].clone());
523
            }
524
        }
525
        ISymbol sym = this.getDefaultSymbol();
526
        sym = (ISymbol) sym.clone();
527
        resp.setDefaultSymbol(sym);
528
        return resp;
529
    }
530

  
531

  
532
  public static void selfRegister() {
533
    Caller caller = new DefaultCaller();
534

  
535
    caller.add(new VectorFilterExpressionLegend.RegisterLegend());
536
    caller.add(new VectorFilterExpressionLegend.RegisterPersistence());
537

  
538
    if (!caller.call()) {
539
      throw new RuntimeException(
540
              "Can't register VectorFilterExpressionLegend",
541
              caller.getException()
542
      );
543
    }
544
    MapContextManager mcoman = MapContextLocator.getMapContextManager();
545
    mcoman.registerLegendWriter(
546
        VectorFilterExpressionLegend.class,
547
            SymbolManager.LEGEND_FILE_EXTENSION.substring(1),
548
            PersistenceBasedLegendWriter.class);
549
    
550
    
551
  }
552

  
553
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.134/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanelView.java
1
package org.gvsig.symbology.gui.layerproperties;
2

  
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
6
import java.awt.BorderLayout;
7
import java.awt.Color;
8
import java.awt.ComponentOrientation;
9
import java.awt.Container;
10
import java.awt.Dimension;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JCheckBox;
15
import javax.swing.JFrame;
16
import javax.swing.JPanel;
17
import javax.swing.JScrollPane;
18
import javax.swing.JTable;
19
import javax.swing.border.EmptyBorder;
20
import javax.swing.border.LineBorder;
21

  
22

  
23
public class VectorFilterExpressionPanelView extends JPanel
24
{
25
   JTable tblSymbols = new JTable();
26
   JCheckBox chkDefaultValues = new JCheckBox();
27
   JButton btnDefaultValuesPreview = new JButton();
28
   JButton btnUp = new JButton();
29
   JButton btnDown = new JButton();
30
   JButton btnAdd = new JButton();
31
   JButton btnRemove = new JButton();
32
   JButton btnRemoveAll = new JButton();
33

  
34
   /**
35
    * Default constructor
36
    */
37
   public VectorFilterExpressionPanelView()
38
   {
39
      initializePanel();
40
   }
41

  
42
   /**
43
    * Adds fill components to empty cells in the first row and first column of the grid.
44
    * This ensures that the grid spacing will be the same as shown in the designer.
45
    * @param cols an array of column indices in the first row where fill components should be added.
46
    * @param rows an array of row indices in the first column where fill components should be added.
47
    */
48
   void addFillComponents( Container panel, int[] cols, int[] rows )
49
   {
50
      Dimension filler = new Dimension(10,10);
51

  
52
      boolean filled_cell_11 = false;
53
      CellConstraints cc = new CellConstraints();
54
      if ( cols.length > 0 && rows.length > 0 )
55
      {
56
         if ( cols[0] == 1 && rows[0] == 1 )
57
         {
58
            /** add a rigid area  */
59
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
60
            filled_cell_11 = true;
61
         }
62
      }
63

  
64
      for( int index = 0; index < cols.length; index++ )
65
      {
66
         if ( cols[index] == 1 && filled_cell_11 )
67
         {
68
            continue;
69
         }
70
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
71
      }
72

  
73
      for( int index = 0; index < rows.length; index++ )
74
      {
75
         if ( rows[index] == 1 && filled_cell_11 )
76
         {
77
            continue;
78
         }
79
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
80
      }
81

  
82
   }
83

  
84
   /**
85
    * Helper method to load an image file from the CLASSPATH
86
    * @param imageName the package and name of the file to load relative to the CLASSPATH
87
    * @return an ImageIcon instance with the specified image file
88
    * @throws IllegalArgumentException if the image resource cannot be loaded.
89
    */
90
   public ImageIcon loadImage( String imageName )
91
   {
92
      try
93
      {
94
         ClassLoader classloader = getClass().getClassLoader();
95
         java.net.URL url = classloader.getResource( imageName );
96
         if ( url != null )
97
         {
98
            ImageIcon icon = new ImageIcon( url );
99
            return icon;
100
         }
101
      }
102
      catch( Exception e )
103
      {
104
         e.printStackTrace();
105
      }
106
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
107
   }
108

  
109
   /**
110
    * Method for recalculating the component orientation for 
111
    * right-to-left Locales.
112
    * @param orientation the component orientation to be applied
113
    */
114
   public void applyComponentOrientation( ComponentOrientation orientation )
115
   {
116
      // Not yet implemented...
117
      // I18NUtils.applyComponentOrientation(this, orientation);
118
      super.applyComponentOrientation(orientation);
119
   }
120

  
121
   public JPanel createPanel()
122
   {
123
      JPanel jpanel1 = new JPanel();
124
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
125
      CellConstraints cc = new CellConstraints();
126
      jpanel1.setLayout(formlayout1);
127

  
128
      tblSymbols.setName("tblSymbols");
129
      JScrollPane jscrollpane1 = new JScrollPane();
130
      jscrollpane1.setViewportView(tblSymbols);
131
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
132
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
133
      jpanel1.add(jscrollpane1,cc.xy(2,4));
134

  
135
      jpanel1.add(createPanel1(),cc.xy(2,2));
136
      jpanel1.add(createPanel2(),cc.xy(4,4));
137
      jpanel1.add(createPanel3(),cc.xy(2,6));
138
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7 });
139
      return jpanel1;
140
   }
141

  
142
   public JPanel createPanel1()
143
   {
144
      JPanel jpanel1 = new JPanel();
145
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:100PX:NONE","CENTER:MAX(22PX;MIN):NONE");
146
      CellConstraints cc = new CellConstraints();
147
      jpanel1.setLayout(formlayout1);
148

  
149
      chkDefaultValues.setActionCommand("_Resto_de_valores");
150
      chkDefaultValues.setName("chkDefaultValues");
151
      chkDefaultValues.setText("resto_valores");
152
      jpanel1.add(chkDefaultValues,cc.xy(1,1));
153

  
154
      btnDefaultValuesPreview.setName("btnDefaultValuesPreview");
155
      LineBorder lineborder1 = new LineBorder(new Color(0,0,0),1,false);
156
      btnDefaultValuesPreview.setBorder(lineborder1);
157
      jpanel1.add(btnDefaultValuesPreview,new CellConstraints(3,1,1,1,CellConstraints.FILL,CellConstraints.FILL));
158

  
159
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
160
      return jpanel1;
161
   }
162

  
163
   public JPanel createPanel2()
164
   {
165
      JPanel jpanel1 = new JPanel();
166
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0)");
167
      CellConstraints cc = new CellConstraints();
168
      jpanel1.setLayout(formlayout1);
169

  
170
      btnUp.setActionCommand("...");
171
      btnUp.setName("btnUp");
172
      btnUp.setText("...");
173
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
174
      btnUp.setBorder(emptyborder1);
175
      jpanel1.add(btnUp,cc.xy(1,1));
176

  
177
      btnDown.setActionCommand("...");
178
      btnDown.setName("btnDown");
179
      btnDown.setText("...");
180
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
181
      btnDown.setBorder(emptyborder2);
182
      jpanel1.add(btnDown,cc.xy(1,3));
183

  
184
      addFillComponents(jpanel1,new int[0],new int[]{ 2,4 });
185
      return jpanel1;
186
   }
187

  
188
   public JPanel createPanel3()
189
   {
190
      JPanel jpanel1 = new JPanel();
191
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(0.1),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.1),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.1),FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE");
192
      CellConstraints cc = new CellConstraints();
193
      jpanel1.setLayout(formlayout1);
194

  
195
      btnAdd.setActionCommand("JButton");
196
      btnAdd.setName("btnAdd");
197
      btnAdd.setText("Anadir");
198
      jpanel1.add(btnAdd,cc.xy(1,1));
199

  
200
      btnRemove.setActionCommand("JButton");
201
      btnRemove.setName("btnRemove");
202
      btnRemove.setText("Quitar");
203
      jpanel1.add(btnRemove,cc.xy(5,1));
204

  
205
      btnRemoveAll.setActionCommand("JButton");
206
      btnRemoveAll.setName("btnRemoveAll");
207
      btnRemoveAll.setText("Quitar_todos");
208
      jpanel1.add(btnRemoveAll,cc.xy(3,1));
209

  
210
      addFillComponents(jpanel1,new int[]{ 2,4,6 },new int[0]);
211
      return jpanel1;
212
   }
213

  
214
   /**
215
    * Initializer
216
    */
217
   protected void initializePanel()
218
   {
219
      setLayout(new BorderLayout());
220
      add(createPanel(), BorderLayout.CENTER);
221
   }
222

  
223

  
224
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.134/src/main/java/org/gvsig/symbology/gui/layerproperties/ExpressionSymbolPanel.java
1
package org.gvsig.symbology.gui.layerproperties;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
5
import org.gvsig.expressionevaluator.Expression;
6
import org.gvsig.expressionevaluator.swing.JExpressionBuilder;
7
import org.gvsig.fmap.dal.feature.FeatureStore;
8
import org.gvsig.fmap.dal.swing.DALSwingLocator;
9
import org.gvsig.fmap.dal.swing.DataSwingManager;
10
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
11
import org.gvsig.tools.swing.api.ToolsSwingLocator;
12
import org.gvsig.tools.swing.api.ToolsSwingManager;
13
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
14

  
15

  
16
public class ExpressionSymbolPanel extends ExpressionSymbolPanelView
17
  {
18

  
19
  private final FeatureStore store;
20
  private PickerController<ISymbol> pickerSymbolController;
21
  private JExpressionBuilder expressionPanel;
22
  private final ISymbol symbol;
23
  private final int symbolType;
24
  
25
  public ExpressionSymbolPanel(FeatureStore store,  int symbolType, ISymbol symbol) {
26
    this.store = store;
27
    this.symbolType = symbolType;
28
    this.symbol = symbol;
29
    this.initComponents();
30
  }
31

  
32
  private void initComponents() {
33
    ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
34
    DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
35
    
36
    toolsSwingManager.translate(this.lblExpression);
37
    toolsSwingManager.translate(this.lblSymbolAndDescriptor);
38
    
39
    this.expressionPanel = dataSwingManager.createQueryFilterExpresion(this.store);
40
    this.pnlExpression.setLayout(new BorderLayout());
41
    this.pnlExpression.add(expressionPanel.asJComponent(), BorderLayout.CENTER);
42
    
43
    this.pickerSymbolController = new SymbolPickerController(
44
            this.btnSymbolPreview, 
45
            this.txtSymbolDescription,
46
            this.symbolType,
47
            this.symbol
48
    );
49
    this.setPreferredSize(new Dimension(800,500));
50
  }
51
  
52
  public String getExpression() {
53
    Expression exp = this.expressionPanel.getExpression();
54
    if( exp == null ) {
55
      return null;
56
    }
57
    return exp.getPhrase();
58
  }
59

  
60
  public ISymbol getSymbol() {
61
      ISymbol theSymbol = this.pickerSymbolController.get();
62
      if( theSymbol == null ) {
63
        return null;
64
      }
65
      return theSymbol;
66
  }
67
  
68
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.134/src/main/java/org/gvsig/symbology/gui/layerproperties/SymbolPickerController.java
1
package org.gvsig.symbology.gui.layerproperties;
2

  
3
import java.awt.Dimension;
4
import java.awt.Graphics2D;
5
import java.awt.Rectangle;
6
import java.awt.event.ActionEvent;
7
import java.awt.event.ComponentAdapter;
8
import java.awt.event.ComponentEvent;
9
import java.awt.event.ComponentListener;
10
import java.awt.geom.AffineTransform;
11
import java.awt.image.BufferedImage;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JTextField;
15
import javax.swing.text.JTextComponent;
16
import org.gvsig.andami.ui.mdiManager.MDIManager;
17
import org.gvsig.app.ApplicationLocator;
18
import org.gvsig.app.gui.styling.SymbolSelector;
19
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
20
import org.gvsig.fmap.mapcontext.MapContextLocator;
21
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
22
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
23
import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController;
24

  
25
/**
26
 *
27
 * @author gvSIG Team
28
 */
29
@SuppressWarnings("UseSpecificCatch")
30
public class SymbolPickerController extends AbstractPickerController<ISymbol> {
31

  
32
  private final JButton btnPreview;
33
  private final JTextComponent txtDescription;
34
  private Dimension previewSize;
35
  private int geomType;
36
  private ISymbol symbol;
37

  
38
  SymbolPickerController(JButton btnPreview, JTextComponent txtDescription, int geomType, ISymbol symbol) {
39
    this.btnPreview = btnPreview;
40
    if( txtDescription==null ) {
41
      this.txtDescription = new JTextField();
42
    } else {
43
      this.txtDescription = txtDescription;
44
    }
45

  
46
    if (symbol == null) {
47
      this.symbol = MapContextLocator.getSymbolManager().createSymbol(geomType);
48
    }
49
    this.previewSize = null;
50
    this.btnPreview.addActionListener((ActionEvent e) -> {
51
      doSelectSymbol();
52
    });
53
    this.btnPreview.addComponentListener(new ComponentAdapter() {
54
      @Override
55
      public void componentResized(ComponentEvent e) {
56
        updatePreview();
57
      }      
58
    });
59
    this.set(this.symbol);
60
  }
61

  
62
  private void updatePreview() {
63
    int width = btnPreview.getWidth();
64
    int height = btnPreview.getHeight();
65
    if( width<5 || height<5 ) {
66
      return;
67
    }
68
    previewSize = new Dimension(width - 4, height - 4);
69
    this.btnPreview.setIcon(
70
            new ImageIcon(this.createPreview(this.previewSize, this.symbol))
71
    );
72
  }
73
  
74
  private BufferedImage createPreview(Dimension size, ISymbol symbol) {
75
    BufferedImage previewImage = new BufferedImage(
76
            size.width,
77
            size.height, 
78
            BufferedImage.TYPE_INT_ARGB
79
    );
80

  
81
    Graphics2D g2 = (Graphics2D) previewImage.createGraphics();
82
    if (g2 != null) {
83
      Rectangle bounds = new Rectangle(size.width, size.height);
84
      ISymbol prevSymbol = symbol;
85
      try {
86
        prevSymbol.drawInsideRectangle(g2, new AffineTransform(), bounds, null);
87
      } catch (Exception e) {
88
          try {
89
            prevSymbol = MapContextLocator.getSymbolManager().getWarningSymbol(
90
                    SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
91
                    symbol.getDescription(),
92
                    SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS
93
            );
94
            prevSymbol.drawInsideRectangle(g2,g2.getTransform(),bounds,null);
95
          } catch (Exception e1) {
96
            LOG.debug("Can't create preview symbol",e1);
97
          }
98
      }
99
    }
100
    return previewImage;
101
  }
102

  
103
  private void doSelectSymbol() {
104
    MDIManager uiManager = ApplicationLocator.getManager().getUIManager();
105
    ISymbolSelector sSelect = SymbolSelector.createSymbolSelector(this.symbol, this.geomType);
106
    uiManager.addWindow(sSelect);
107
    if (sSelect.getSelectedObject() != null) {
108
      this.symbol = (ISymbol) sSelect.getSelectedObject();
109
      this.updatePreview();
110
    }
111
  }
112

  
113
  @Override
114
  public ISymbol get() {
115
    symbol.setDescription(this.txtDescription.getText());
116
    return symbol;
117
  }
118

  
119
  @Override
120
  public final void set(ISymbol symbol) {
121
      this.symbol = symbol;
122
      this.geomType = symbol.getSymbolType();
123
      this.txtDescription.setText(this.symbol.getDescription());
124
      this.updatePreview();
125
  }
126

  
127
  @Override
128
  public void coerceAndSet(Object o) {
129
    this.set((ISymbol) o);
130
  }
131

  
132
  @Override
133
  public void setEnabled(boolean enabled) {
134
    this.btnPreview.setEnabled(enabled);
135
    this.txtDescription.setEnabled(enabled);
136
  }
137

  
138
  @Override
139
  public boolean isEnabled() {
140
    return this.btnPreview.isEnabled();
141
  }
142

  
143
}
org.gvsig.legend.vectorfilterexpression.app.mainplugin/tags/org.gvsig.legend.vectorfilterexpression.app.mainplugin-1.0.134/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.gui.layerproperties;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import javax.swing.BoxLayout;
36
import javax.swing.ImageIcon;
37
import javax.swing.JButton;
38
import javax.swing.JCheckBox;
39
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
41
import org.apache.commons.lang3.StringUtils;
42

  
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
import org.gvsig.andami.IconThemeHelper;
47
import org.gvsig.app.ApplicationLocator;
48
import org.gvsig.app.project.documents.view.legend.gui.Categories;
49
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
50
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
51
import org.gvsig.app.project.documents.view.legend.gui.SymbolTable;
52
import org.gvsig.fmap.dal.exception.ReadException;
53
import org.gvsig.fmap.dal.feature.Feature;
54
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
55
import org.gvsig.fmap.dal.feature.FeatureStore;
56
import org.gvsig.fmap.dal.feature.FeatureType;
57
import org.gvsig.fmap.mapcontext.layers.FLayer;
58
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
61
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
62
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
63
import org.gvsig.gui.beans.swing.JBlank;
64
import org.gvsig.i18n.Messages;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
67
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend;
68
import org.gvsig.symbology.swing.SymbologySwingLocator;
69
import org.gvsig.tools.ToolsLocator;
70
import org.gvsig.tools.i18n.I18nManager;
71
import org.gvsig.tools.swing.api.ToolsSwingLocator;
72
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
73
import org.gvsig.tools.swing.api.windowmanager.Dialog;
74
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
75
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
76

  
77
/**
78
 * Implements the JPanel that shows the properties of a
79
 * VectorialFilterExpressionLegend
80
 * in order to allows the user to modify its characteristics
81
 *
82
 * @author gvSIG Team
83
 *
84
 */
85
public class VectorFilterExpressionPanel extends JPanel
86
implements ILegendPanel, ActionListener {
87

  
88
    private static final Logger logger = LoggerFactory.getLogger(
89
        VectorFilterExpressionPanel.class);
90

  
91
	private static final long serialVersionUID = -7187473609965942511L;
92
	private VectorFilterExpressionLegend theLegend;
93
	private VectorFilterExpressionLegend auxLegend;
94
	private ClassifiableVectorial layer;
95
	private PictureFillSymbol previewSymbol;
96
	private JPanel pnlCenter;
97
	private JPanel pnlMovBut;
98
	private SymbolTable symbolTable;
99
	private JButton btnAddExpression;
100
//	private JButton btnModExpression;
101
	private JButton btnRemoveExpression;
102
	private JButton moveUp;
103
	private JButton moveDown;
104
	private int shapeType;
105
	protected JCheckBox chkdefaultvalues = null;
106
	protected JSymbolPreviewButton defaultSymbolPrev;
107
	private GridBagLayoutPanel defaultSymbolPanel = new GridBagLayoutPanel();
108
	private UsabilitySwingManager usabilitySwingManager = ToolsSwingLocator.getUsabilitySwingManager();
109

  
110
	/**
111
	 * This is the default constructor
112
	 */
113
	public VectorFilterExpressionPanel() {
114
		super();
115
		initialize();
116
	}
117

  
118

  
119
	/**
120
	 * This method initializes this
121
	 */
122
	private void initialize() {
123

  
124
		pnlCenter = new JPanel();
125
		pnlCenter.setLayout(new BorderLayout());
126

  
127
		JPanel pnlButtons = new JPanel();
128
		btnAddExpression = usabilitySwingManager.createJButton(
129
		    Messages.getText("Anadir"));
130
		btnAddExpression.setActionCommand("NEW_EXPRESSION");
131
		btnAddExpression.addActionListener(this);
132
		pnlButtons.add(btnAddExpression);
133

  
134
//		btnModExpression = usabilitySwingManager.createJButton(
135
//		    Messages.getText("modify_filter_expression"));
136
//		btnModExpression.setActionCommand("MODIFY_EXPRESSION");
137
//		btnModExpression.addActionListener(this);
138
//		pnlButtons.add(btnModExpression);
139

  
140
		btnRemoveExpression = usabilitySwingManager.createJButton(
141
		    Messages.getText("Quitar"));
142
		btnRemoveExpression.setActionCommand("REMOVE");
143
		btnRemoveExpression.addActionListener(this);
144
		pnlButtons.add(btnRemoveExpression);
145
		defaultSymbolPanel.add(getChkDefaultvalues());
146
		pnlCenter.add(defaultSymbolPanel,BorderLayout.NORTH);
147

  
148
		this.setLayout(new BorderLayout());
149
		this.add(pnlCenter, BorderLayout.CENTER);
150
		this.add(pnlButtons, BorderLayout.SOUTH);
151

  
152

  
153
	}
154
	public void getDefaultSymbolPrev(int shapeType) {
155
		if(defaultSymbolPrev == null){
156
			defaultSymbolPrev = new JSymbolPreviewButton(shapeType);
157
			defaultSymbolPrev.setPreferredSize(new Dimension(110,20));
158
			defaultSymbolPanel.add(defaultSymbolPrev,null);
159
		}
160
	}
161

  
162
	public String getDescription() {
163
		return Messages.getText(
164
		    "shows_the_elements_of_the_layer_depending_on_the_value_of_a_filter_expression") + ".";
165
	}
166

  
167
	public ISymbol getIconSymbol() {
168
		if (previewSymbol == null) {
169
			try {
170
				previewSymbol = new PictureFillSymbol();
171
				previewSymbol.setImage( new File(
172
						this.getClass().getClassLoader().
173
						getResource("images" + File.separator
174
						    + "legend" + File.separator
175
						    + "legend-overview-vectorial-unique-value.png").
176
						getFile()).toURI().toURL());
177
				previewSymbol.getMarkerFillProperties().
178
				setFillStyle(
179
						IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
180
			} catch (IOException e) {
181
				return null;
182
			}
183
		}
184
		return previewSymbol;
185
	}
186

  
187
	public ILegend getLegend() {
188
		auxLegend.clear();
189
		fillSymbolListFromTable();
190

  
191
		theLegend = (VectorFilterExpressionLegend) auxLegend.cloneLegend();
192
		if(defaultSymbolPrev.getSymbol() != null)
193
			theLegend.setDefaultSymbol(defaultSymbolPrev.getSymbol());
194

  
195
		theLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
196
		return theLegend;
197
	}
198
	/**
199
	 * Fills the list of symbols of the legend
200
	 *
201
	 */
202
	private void fillSymbolListFromTable() {
203
		Object clave;
204
		ISymbol theSymbol;
205

  
206
		FLyrVect m = (FLyrVect) layer;
207
		try {
208

  
209
			if(auxLegend.getClassifyingFieldNames() != null) {
210
				String[] fNames= auxLegend.getClassifyingFieldNames();
211
				int[] fieldTypes  = new int[auxLegend.getClassifyingFieldNames().length];
212

  
213
				FeatureStore fsto = (FeatureStore) m.getDataStore();
214
				FeatureType fty = fsto.getDefaultFeatureType();
215

  
216
				for (int i = 0; i < fNames.length; i++) {
217
					fieldTypes[i] = fty.getAttributeDescriptor(fNames[i]).getType();
218
				}
219

  
220
				auxLegend.setClassifyingFieldTypes(fieldTypes);
221
			}
222
		} catch (Exception e) {
223

  
224
		}
225

  
226
		auxLegend.useDefaultSymbol(chkdefaultvalues.isSelected());
227

  
228
		for (int row = 0; row < symbolTable.getRowCount(); row++) {
229
			clave =  symbolTable.getFieldValue(row, 1);
230
			theSymbol = (ISymbol) symbolTable.getFieldValue(row, 0);
231
			theSymbol.setDescription((String) symbolTable.getFieldValue(row, 2));
232
			auxLegend.addSymbol(clave, theSymbol);
233
		}
234
		if(chkdefaultvalues.isSelected()){
235
			if(defaultSymbolPrev.getSymbol() != null){
236
				String description = VectorFilterExpressionLegend.I18N_DEFAULT;
237
				defaultSymbolPrev.getSymbol().setDescription(description);
238
				auxLegend.addSymbol(
239
				    description, defaultSymbolPrev.getSymbol());
240
			}
241
		}
242

  
243
	}
244

  
245
	public Class<VectorFilterExpressionLegend> getLegendClass() {
246
		return VectorFilterExpressionLegend.class;
247
	}
248

  
249
	public JPanel getPanel() {
250
		return this;
251
	}
252

  
253
	public Class<Categories> getParentClass() {
254
		return Categories.class;
255
	}
256

  
257
	public String getTitle() {
258
		return Messages.getText("expressions");
259
	}
260

  
261
	public boolean isSuitableFor(FLayer layer) {
262
		FLyrVect lVect = (FLyrVect) layer;
263
		try {
264
			return
265
			    VectorFilterExpressionLegend.isPoint(lVect.getShapeType())
266
			    ||
267
                VectorFilterExpressionLegend.isLinear(lVect.getShapeType())
268
                ||
269
                VectorFilterExpressionLegend.isPolygonal(lVect.getShapeType());
270
		} catch (Exception e) {
271
			return false;
272
		}
273

  
274
	}
275

  
276
	public void setData(FLayer lyr, ILegend legend) {
277
		this.layer = (ClassifiableVectorial) lyr;
278
		shapeType = 0;
279

  
280
		try {
281
			shapeType = this.layer.getGeometryType().getType();
282
		} catch (ReadException e) {
283
		    logger.info("Error while getting layer shp type", e);
284
		    ApplicationLocator.getManager().message(
285
		        Messages.getText("generating_intervals"),
286
		        JOptionPane.ERROR_MESSAGE);
287
		}
288

  
289
		if (symbolTable != null)
290
			pnlCenter.remove(symbolTable);
291
		if (pnlMovBut != null)
292
			pnlCenter.remove(pnlMovBut);
293

  
294
		getDefaultSymbolPrev(shapeType);
295

  
296
		symbolTable = new SymbolTable(this, "expressions", shapeType);
297
    try {
298
      ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor(
299
              ((FLyrVect)layer).getFeatureStore()
300
      );
301
      symbolTable.setCellEditor(cellEditor);
302
    } catch(Exception ex) {
303
      
304
    }
305
		pnlCenter.add(symbolTable, BorderLayout.CENTER);
306
		pnlCenter.add(getPnlMovBut(),BorderLayout.EAST);
307

  
308

  
309
		if (legend instanceof VectorFilterExpressionLegend) {
310

  
311
            auxLegend = (VectorFilterExpressionLegend) legend.cloneLegend();
312
            if (auxLegend.isUseDefaultSymbol()) {
313
                // Default must not be in table
314
                fillTableSkipDefault(auxLegend);
315
            } else {
316
                symbolTable.fillTableFromSymbolList(
317
                    auxLegend.getSymbols(),
318
                    auxLegend.getValues(),
319
                    auxLegend.getDescriptions());
320
            }
321

  
322

  
323
		} else {
324
			auxLegend = new VectorFilterExpressionLegend();
325
			auxLegend.setShapeType(shapeType);
326
		}
327
		defaultSymbolPrev.setSymbol(auxLegend.getDefaultSymbol());
328
		getChkDefaultvalues().setSelected(auxLegend.isUseDefaultSymbol());
329
	}
330

  
331
	private JPanel getPnlMovBut() {
332
		if(pnlMovBut == null){
333
			pnlMovBut = new JPanel();
334
			pnlMovBut.setLayout(new BoxLayout(pnlMovBut, BoxLayout.Y_AXIS));
335
			pnlMovBut.add(new JBlank(1, 70));
336
			ImageIcon ico = IconThemeHelper.getImageIcon(
337
			    "symbol-layer-move-up");
338
			moveUp = usabilitySwingManager.createJButton(ico);
339
			pnlMovBut.add(moveUp);
340
			moveUp.setSize(new Dimension(15,15));
341
			pnlMovBut.add(new JBlank(1,10));
342
			ico = IconThemeHelper.getImageIcon(
343
                "symbol-layer-move-down");
344
			moveDown = usabilitySwingManager.createJButton(ico);
345
			pnlMovBut.add(moveDown);
346
			pnlMovBut.add(new JBlank(1, 70));
347
			moveDown.setActionCommand("MOVE-DOWN");
348
			moveUp.setActionCommand("MOVE-UP");
349
			moveDown.addActionListener(this);
350
			moveUp.addActionListener(this);
351
		}
352
		return pnlMovBut;
353
	}
354

  
355
	public void actionPerformed(ActionEvent e) {
356

  
357
		int[] indices = null;
358
		Feature dummyFeat = null;
359

  
360
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
361
			indices = symbolTable.getSelectedRows();
362
		}
363

  
364
		if(e.getActionCommand() == "MOVE-UP"){
365
			if (indices.length>0) {
366
				int classIndex = indices[0];
367
				int targetPos = Math.max(0, classIndex-1);
368
				symbolTable.moveUpRows(classIndex, targetPos,indices.length);
369
			}
370
		}
371

  
372
		if(e.getActionCommand() == "MOVE-DOWN"){
373
			if (indices.length>0) {
374
				int classIndex = indices[indices.length-1];
375
				int targetPos = Math.min(symbolTable.getRowCount()-1, classIndex+1);
376
				symbolTable.moveDownRows(classIndex, targetPos,indices.length);
377
			}
378
		}
379

  
380
		if(e.getActionCommand() == "MOVE-UP" || e.getActionCommand() == "MOVE-DOWN"){
381
			ArrayList<String> orders = new ArrayList<String>();
382

  
383
			for (int i = 0; i < symbolTable.getRowCount(); i++) {
384
				orders.add(symbolTable.getFieldValue(i,1).toString());
385
			}
386
      
387
		} if (e.getActionCommand() == "NEW_EXPRESSION") {
388

  
389
		    FLyrVect vect = (FLyrVect) layer;
390
		    final FeatureStore fsto = vect.getFeatureStore();
391
		    final FeatureType fty = fsto.getDefaultFeatureTypeQuietly();
392
		    final int shptype = fty.getDefaultGeometryAttribute().getGeomType().getType();
393
        final I18nManager i18n = ToolsLocator.getI18nManager();
394
        final ExpressionSymbolPanel esp = new ExpressionSymbolPanel(fsto, shptype, previewSymbol);
395
        final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
396
        final Dialog dialog = windowManager.createDialog(
397
              esp,
398
              i18n.getTranslation("expression_creator"),
399
              "",
400
              WindowManager_v2.BUTTONS_OK_CANCEL
401
        );
402
        dialog.addActionListener((ActionEvent e1) -> {
403
          if( dialog.getAction()!=WindowManager_v2.BUTTON_OK ) {
404
            return;
405
          }
406
          String expr = esp.getExpression();
407
          if ( StringUtils.isBlank(expr) ) {
408
              ApplicationLocator.getManager().messageDialog(
409
                  Messages.getText("error_validating_filter_query"),
410
                  Messages.getText("error"),
411
                  JOptionPane.ERROR_MESSAGE);
412
              return;
413
          }
414
          ISymbol sym = esp.getSymbol();
415
          this.addClassFieldNames(fty);
416

  
417
          auxLegend.addSymbol(expr, sym);
418
          symbolTable.removeAllItems();
419
          fillTableSkipDefault(auxLegend);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff