Revision 1422

View differences:

org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/buildNumber.properties
1
#Wed May 31 09:22:12 CEST 2017
2
buildNumber=47
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.symbology.library.ProportionalSymbolsLibrary
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/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.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/src/main/java/org/gvsig/symbology/fmap/rendering/ProportionalSymbolsLegend.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

  
46
import org.gvsig.fmap.dal.feature.Feature;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.mapcontext.MapContextLocator;
49
import org.gvsig.fmap.mapcontext.MapContextManager;
50
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
51
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
52
import org.gvsig.fmap.mapcontext.rendering.legend.events.IntervalLegendEvent;
53
import org.gvsig.fmap.mapcontext.rendering.legend.events.LabelLegendEvent;
54
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
55
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
56
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
57
import org.gvsig.fmap.mapcontext.rendering.legend.events.ValueLegendEvent;
58
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
59
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
60
import org.gvsig.i18n.Messages;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle;
67
import org.gvsig.tools.ToolsLocator;
68
import org.gvsig.tools.dynobject.DynStruct;
69
import org.gvsig.tools.persistence.PersistenceManager;
70
import org.gvsig.tools.persistence.PersistentState;
71
import org.gvsig.tools.persistence.exception.PersistenceException;
72
import org.gvsig.tools.util.Callable;
73

  
74

  
75
/**
76
 * Implements a legend which represents the quantitative information
77
 * (numeric values). This representation is possible thanks to a symbol
78
 * whose size is different each time (depending on the numeric values
79
 * and if we want to use normalization or not).
80
 *
81
 * @author jaume dominguez faus - jaume.dominguez@iver.es
82
 * @author jldominguez
83
 */
84
public class ProportionalSymbolsLegend extends VectorialUniqueValueLegend  {
85

  
86
    private static Logger logger = LoggerFactory.getLogger(ProportionalSymbolsLegend.class);
87
    public static final String
88
    PROPORTIONAL_SYMBOL_LEGEND_NAME =
89
        "PROPORTIONAL_SYMBOL_LEGEND";
90
    public static final String
91
    PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME =
92
        "PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION";
93

  
94
	public void setClassifyingFieldNames(String[] fNames) {
95
		super.setClassifyingFieldNames(fNames);
96
		valueField = fNames[0];
97
		normalizationField = fNames[1];
98
	}
99

  
100
	private ISymbol backgroundSymbol;
101
	private String valueField;
102
	private String normalizationField;
103
	private double minSize;
104
	private double maxSize;
105
	private int templateShapeType;
106
	private boolean useNormalization;
107
	private double maxFeature, minFeature;
108
	private ZSort zSort = null;
109

  
110

  
111
	public ISymbol getSymbolByValue(Object key) {
112
		return null;
113
	}
114

  
115
	public ISymbol getSymbolByFeature(Feature feat) {
116

  
117
		ISymbol theSymbol = getDefaultSymbol();
118
		ISymbol auxSymbol;
119

  
120
		double value = 0;
121
		double normValue = 0;
122
		double size;
123
		double separation = maxSize-minSize;
124

  
125
		if (separation == 0) {
126
			separation = 1;
127
		}
128

  
129
		try {
130

  
131
			value = feat.getDouble(this.valueField);
132
			if (useNormalization) {
133

  
134
			    normValue = feat.getDouble(this.normalizationField);
135
			    if (normValue == 0) {
136
			        size = (value >= 0) ?
137
			            Double.POSITIVE_INFINITY :
138
			            Double.NEGATIVE_INFINITY;
139
			    } else {
140
	                value = value / normValue;
141
	                size = minSize + (value * separation) ;
142
			    }
143

  
144
			} else {
145
				double difFeat = maxFeature - minFeature;
146
				double step = difFeat/separation;
147
				size = minSize + ((value - minFeature)/step);
148
			}
149

  
150
		} catch (Exception e) {
151
			logger.info("Error while getting value in ProportionalSymbolsLegend.", e);
152
			return null;
153
		}
154

  
155
		if (size == Double.NaN || size == Double.POSITIVE_INFINITY
156
		    || size == Double.NEGATIVE_INFINITY) {
157

  
158
            // logger.info("The symbol size is NaN or INFINITE.");
159
			return null;
160
		}
161

  
162
		Geometry defgeom = feat.getDefaultGeometry();
163
		int def_geom_type = defgeom.getGeometryType().getType();
164

  
165
		if (isPolygonal(def_geom_type) && theSymbol instanceof IMarkerSymbol) {
166

  
167
			MarkerFillSymbol aux = new MarkerFillSymbol();
168
			((IMarkerSymbol) theSymbol).setSize(size);
169
			aux.setMarker((IMarkerSymbol) theSymbol);
170
			SimpleMarkerFillPropertiesStyle p = new SimpleMarkerFillPropertiesStyle();
171
			p.setFillStyle(SimpleMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
172
			aux.setMarkerFillProperties(p);
173
			theSymbol = aux;
174
		}
175
		else if (isLinear(def_geom_type)) {
176

  
177
			ILineSymbol line = (ILineSymbol) theSymbol;
178
			line.setLineWidth(size);
179
			theSymbol = line;
180
		}
181
		else if (isPoint(def_geom_type)) {
182
			IMarkerSymbol marker = (IMarkerSymbol) theSymbol;
183
			marker.setSize(size);
184
			theSymbol = marker;
185
		}
186

  
187
		if (backgroundSymbol != null) {
188
			MultiLayerFillSymbol multi = new MultiLayerFillSymbol() ;
189
			multi.addLayer(backgroundSymbol);
190
			multi.addLayer(theSymbol);
191
			return multi;
192
		}
193
		auxSymbol = theSymbol;
194

  
195
		return auxSymbol;
196

  
197
	}
198

  
199
	public static boolean isPolygonal(int ty) {
200
        if (ty == Geometry.TYPES.MULTISURFACE
201
            || ty == Geometry.TYPES.SURFACE
202
            ) {
203
            return true;
204
        } else {
205
            return false;
206
        }
207
	}
208

  
209

  
210
	public static boolean isLinear(int ty) {
211
        if (ty == Geometry.TYPES.CIRCLE
212
            || ty == Geometry.TYPES.ARC
213
            || ty == Geometry.TYPES.CURVE
214
            || ty == Geometry.TYPES.ELLIPSE
215
            || ty == Geometry.TYPES.ELLIPTICARC
216
            || ty == Geometry.TYPES.SPLINE
217
            || ty == Geometry.TYPES.MULTICURVE
218
            ) {
219
            return true;
220
        } else {
221
            return false;
222
        }
223
	}
224

  
225
	public static boolean isPoint(int ty) {
226
        if (ty == Geometry.TYPES.POINT
227
            || ty == Geometry.TYPES.MULTIPOINT
228
            ) {
229
            return true;
230
        } else {
231
            return false;
232
        }
233
    }
234

  
235

  
236

  
237
	/**
238
	 * Gets the background symbol which only can appear when the shapetype of the layer
239
	 * is polygonal
240
	 *
241
	 * @return ISymbol the symbol for the background
242
	 */
243
	public ISymbol getBackgroundSymbol() {return backgroundSymbol;}
244
	/**
245
	 * Sets the background symbol which is used only when the shapetype of the layer is polygonal
246
	 *
247
	 * @param backgroundSymbol the symbol for the background
248
	 */
249
	public void setBackgroundSymbol(ISymbol backgroundSymbol) {this.backgroundSymbol = backgroundSymbol;}
250
	/**
251
	 * Obtains the classifying field name to be used to calculate the size of the symbol
252
	 *
253
	 * @return String  the name of the field
254
	 * @throws ReadDriverException
255
	 */
256
	public String getValueField() {
257
//		try {
258
//			// TODO:
259
//			// Por los alias, al guardar un proyecto no podemos
260
//			// permitir que se guarde con campos que luego
261
//			// no van a existir.
262
////			int id = dataSource.getFieldIndexByName(valueField);
263
////			valueField = dataSource.getFieldName(id);
264
//		} catch (ReadDriverException e) {
265
//			e.printStackTrace();
266
//			throw new RuntimeException(e);
267
//		}
268
		return valueField;
269
	}
270
	/**
271
	 * Sets the classifying field name to be used to calculate the size of the symbol
272
	 *
273
	 * @param String  the name of the field
274
	 */
275
	public void setValueField(String valueField) {this.valueField = valueField;}
276
	/**
277
	 * Obtains the classifying field name to be used to calculate the size of the symbol when the
278
	 * user is doing it with a normalization value.
279
	 *
280
	 * @return String  the name of the field
281
	 */
282
	public String getNormalizationField() {
283
		return normalizationField;
284
	}
285
	/**
286
	 * Sets the classifying field name to be used to calculate the size of the symbol when the
287
	 * user is doing it with a normalization value.
288
	 *
289
	 * @param String  the name of the field
290
	 */
291
	public void setNormalizationField(String normalizationField) {this.normalizationField = normalizationField;}
292
	/**
293
	 * Obtains the minimum size for the symbol
294
	 *
295
	 * @return double  the minimum size for the symbol
296
	 */
297
	public double getMinSize() {return minSize;}
298
	/**
299
	 * Sets the minimum size for the symbol
300
	 *
301
	 * @param minSize  the minimum size for the symbol
302
	 */
303
	public void setMinSize(double minSize) {this.minSize = minSize;}
304
	/**
305
	 * Obtains the maximum size for the symbol
306
	 *
307
	 * @return double  the minimum size for the symbol
308
	 */
309
	public double getMaxSize() {return maxSize;}
310
	/**
311
	 * Sets the maximum size for the symbol
312
	 *
313
	 * @param maxSize  the minimum size for the symbol
314
	 */
315
	public void setMaxSize(double maxSize) {this.maxSize = maxSize;}
316
	/**
317
	 * Obtains the shapetype of the template symbol
318
	 *
319
	 * @return int shape type for the template symbol
320
	 */
321
	public int getTemplateShapeType() {return templateShapeType;}
322
	/**
323
	 * Sets the shapetype of the template symbol
324
	 *
325
	 * @param templateShapeType shape type for the template symbol
326
	 */
327
	public void setTemplateShapeType(int tst) {
328

  
329
		if (isPolygonal(getShapeType())) {
330
			if (isPoint(tst) || isPolygonal(tst)) {
331
			    this.templateShapeType = tst;
332
			}
333
		} else {
334

  
335
		    if ((isPoint(tst) && isPoint(getShapeType()))
336
		        || (isLinear(tst) && isLinear(getShapeType()))) {
337
		        // || (getShapeType() == Geometry.TYPES.NULL)) {
338

  
339
		        this.templateShapeType = tst;
340
		    }
341
		}
342
	}
343

  
344
	/**
345
	 * Obtains the boolean which is true if the user wants to calculate the size of the
346
	 * symbol using a normalization field.
347
	 *
348
	 * @return boolean true if the user wants normalization.Otherwise, false.
349
	 */
350
	public boolean getUseNormalization() {return useNormalization;}
351
	/**
352
	 * Sets the boolean which is true if the user wants to calculate the size of the
353
	 * symbol using a normalization field.
354
	 *
355
	 * @param useNormalization true if the user wants normalization.Otherwise, false.
356
	 */
357
	public void setUseNormalization(boolean useNormalization) {this.useNormalization = useNormalization;}
358
	/**
359
	 * Obtains the variable which represents the maximum value of the classifying field that is used
360
	 * to calculate the size of the symbol
361
	 *
362
	 * @return double  the maximum value of the classifying field
363
	 */
364
	public double getMaxFeature() {return maxFeature;}
365
	/**
366
	 * Sets the variable which represents the maximum value of the classifying field that is used
367
	 * to calculate the size of the symbol
368
	 *
369
	 * @param maxFeature
370
	 */
371
	public void setMaxFeature(double maxFeature) {this.maxFeature = maxFeature;}
372
	/**
373
	 * Obtains the variable which represents the minimum value of the classifying field that is used
374
	 * to calculate the size of the symbol
375
	 *
376
	 * @return double  the minimum value of the classifying field
377
	 */
378
	public double getMinFeature() {return minFeature;}
379
	/**
380
	 * Sets the variable which represents the minimum value of the classifying field that is used
381
	 * to calculate the size of the symbol
382
	 *
383
	 * @param minFeature
384
	 */
385
	public void setMinFeature(double minFeature) {this.minFeature = minFeature;}
386

  
387

  
388
	public ISymbol[] getSymbols() {
389
		ISymbol[] auxSymbols=super.getSymbols();
390
		if(backgroundSymbol != null){
391
			ISymbol[] symbols=new ISymbol[auxSymbols.length+1];
392
			for (int i = 0; i < auxSymbols.length; i++) {
393
				symbols[i]=auxSymbols[i];
394
			}
395
			symbols[symbols.length-1]=backgroundSymbol;
396
			return symbols;
397
		} else {
398
			return auxSymbols;
399
		}
400
	}
401

  
402

  
403

  
404
	public ZSort getZSort() {
405
		if (zSort == null){
406
			zSort = new MyZSort(this);
407
		}
408
		return zSort;
409
	}
410

  
411
	public void setZSort(ZSort zSort){
412
		return;
413
	}
414

  
415
	private class MyZSort extends ZSort {
416

  
417
		public MyZSort(ILegend legend) {
418
			super(legend);
419
		}
420

  
421
		public void legendChanged(LegendChangedEvent e) {
422
		}
423

  
424
		public String getClassName() {
425
			return getClass().getName();
426
		}
427

  
428
		public int getLevelCount() {
429
			int levels = 0;
430
			if (backgroundSymbol!=null){
431
				if(backgroundSymbol instanceof IMultiLayerSymbol){
432
					levels += ((IMultiLayerSymbol)backgroundSymbol).getLayerCount();
433
				} else {
434
					levels += 1;
435
				}
436
			}
437
			ISymbol sym = getDefaultSymbol();
438
			if(getDefaultSymbol() instanceof IMultiLayerSymbol){
439
				levels += ((IMultiLayerSymbol)sym).getLayerCount();
440
			} else {
441
				levels += 1;
442
			}
443
			return levels+1;
444
		}
445

  
446

  
447
		public void setUsingZSort(boolean usingZSort) {
448
		}
449

  
450
		public void setLevels(ISymbol sym, int[] values) {
451
		}
452

  
453

  
454
		public void setLevels(int row, int[] values) {
455
		}
456

  
457
		public int[] getLevels(ISymbol sym) {
458
			return getLevels(0);
459
		}
460

  
461
		public int[] getLevels(int row) {
462
			int levelsCount = getLevelCount();
463
			int[] levels = new int[levelsCount];
464
			int bgLevels = 1;
465
			if (backgroundSymbol!=null){
466
				if(backgroundSymbol instanceof IMultiLayerSymbol){
467
					bgLevels = ((IMultiLayerSymbol)backgroundSymbol).getLayerCount();
468
				}
469
				for (int i=0; i<bgLevels; i++) {
470
					levels[i]=i;
471
				}
472
			}
473

  
474
			ISymbol sym = getDefaultSymbol();
475
			int frLevels = 1;
476
			if(getDefaultSymbol() instanceof IMultiLayerSymbol){
477
				frLevels = ((IMultiLayerSymbol)sym).getLayerCount();
478
			}
479
			for (int i=0; i<frLevels; i++) {
480
				levels[i+bgLevels]=i+bgLevels;
481
			}
482
			levels[frLevels+bgLevels]=frLevels+bgLevels;
483
			return levels;
484
		}
485

  
486

  
487
		public boolean isUsingZSort() {
488
			return backgroundSymbol!=null;
489
		}
490

  
491

  
492
		public ISymbol[] getSymbols() {
493
			return getSymbols();
494
		}
495

  
496
		public String[] getDescriptions() {
497
			return getDescriptions();
498
		}
499

  
500
		public int getTopLevelIndexAllowed() {
501
			return getLevelCount();
502
		}
503

  
504
		@Override
505
		public String toString() {
506
			String out = "ZSort for ProportionalSymbolLegend";
507
			return out;
508
		}
509

  
510
		public boolean symbolChanged(SymbolLegendEvent e) {
511
			return true;
512
		}
513

  
514
		public boolean classifiedSymbolChange(SymbolLegendEvent e) {
515
			return true;
516
		}
517

  
518
		public boolean intervalChange(IntervalLegendEvent e) {
519
			return false;
520
		}
521

  
522
		public boolean valueChange(ValueLegendEvent e) {
523
			return false;
524
		}
525

  
526
		// TODO should not exist here
527
		public boolean labelFieldChange(LabelLegendEvent e) {
528
			return false;
529
		}
530

  
531
		public void legendCleared(LegendClearEvent event) {
532
		}
533
	}
534

  
535

  
536
    public void loadFromState(PersistentState state)
537
        throws PersistenceException {
538

  
539
        int[] ft = state.getIntArray("fieldTypes");
540
        this.setClassifyingFieldTypes(ft);
541

  
542
        this.valueField = state.getString("valueField");
543
        this.normalizationField = state.getString("normalizationField");
544
        this.templateShapeType = state.getInt("templateShapeType");
545
        this.maxSize = state.getDouble("maxSize");
546
        this.minSize = state.getDouble("minSize");
547
        this.maxFeature = state.getDouble("maxFeature");
548
        this.minFeature = state.getDouble("minFeature");
549
        this.useNormalization = state.getBoolean("useNormalization");
550

  
551
        ISymbol sym = (ISymbol) state.get("defaultSymbol");
552
        this.setDefaultSymbol(sym);
553

  
554
        sym = (ISymbol) state.get("backgroundSymbol");
555
        this.setBackgroundSymbol(sym);
556

  
557
        String[] fieldNames = new String[2];
558
        fieldNames[0]= valueField;
559
        if (normalizationField.compareTo(Messages.getText("none")) == 0) {
560
            fieldNames[1]= fieldNames[0];
561
        } else {
562
            fieldNames[1] = normalizationField;
563
        }
564
        setClassifyingFieldNames(fieldNames);
565
    }
566

  
567

  
568
    public void saveToState(PersistentState state) throws PersistenceException {
569

  
570
        int[] ft = this.getClassifyingFieldTypes();
571
        state.set("fieldTypes", ft);
572

  
573
        state.set("valueField", this.valueField);
574
        state.set("normalizationField", this.normalizationField);
575
        state.set("templateShapeType", this.templateShapeType);
576
        state.set("maxSize", this.maxSize);
577
        state.set("minSize", this.minSize);
578
        state.set("maxFeature", this.maxFeature);
579
        state.set("minFeature", this.minFeature);
580
        state.set("useNormalization", this.useNormalization);
581
        state.set("defaultSymbol", this.getDefaultSymbol());
582
        state.set("backgroundSymbol", this.backgroundSymbol);
583
    }
584

  
585

  
586
    public static class RegisterPersistence implements Callable {
587

  
588
        public Object call() throws Exception {
589

  
590
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
591
            if (manager
592
                .getDefinition(PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
593
                DynStruct definition =
594
                    manager
595
                        .addDefinition(
596
                            ProportionalSymbolsLegend.class,
597
                            PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME,
598
                            PROPORTIONAL_SYMBOL_LEGEND_PERSISTENCE_DEFINITION_NAME
599
                                + " Persistence definition", null, null);
600

  
601
                definition.addDynFieldString("valueField").setMandatory(true);
602
                definition.addDynFieldString("normalizationField").setMandatory(true);
603
                definition.addDynFieldInt("templateShapeType").setMandatory(true);
604
                definition.addDynFieldArray("fieldTypes").setClassOfItems(Integer.class).setMandatory(true);
605
                definition.addDynFieldDouble("maxSize").setMandatory(true);
606
                definition.addDynFieldDouble("minSize").setMandatory(true);
607
                definition.addDynFieldDouble("maxFeature").setMandatory(true);
608
                definition.addDynFieldDouble("minFeature").setMandatory(true);
609
                definition.addDynFieldBoolean("useNormalization").setMandatory(true);
610

  
611
                definition.addDynFieldObject("defaultSymbol")
612
                .setClassOfValue(ISymbol.class).setMandatory(true);
613
                definition.addDynFieldObject("backgroundSymbol")
614
                .setClassOfValue(ISymbol.class).setMandatory(true);
615
            }
616
            return Boolean.TRUE;
617
        }
618

  
619
    }
620

  
621
    public static class RegisterLegend implements Callable {
622

  
623
        public Object call() throws Exception {
624
            MapContextManager manager =
625
                MapContextLocator.getMapContextManager();
626

  
627
            manager.registerLegend(
628
                PROPORTIONAL_SYMBOL_LEGEND_NAME,
629
                ProportionalSymbolsLegend.class);
630

  
631
            return Boolean.TRUE;
632
        }
633

  
634
    }
635

  
636
}
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/src/main/java/org/gvsig/symbology/gui/layerproperties/ProportionalSymbolsPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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.Color;
45
import java.awt.Dimension;
46
import java.awt.FlowLayout;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49

  
50
import javax.swing.BorderFactory;
51
import javax.swing.DefaultComboBoxModel;
52
import javax.swing.ImageIcon;
53
import javax.swing.JComboBox;
54
import javax.swing.JLabel;
55
import javax.swing.JOptionPane;
56
import javax.swing.JPanel;
57

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

  
61
import org.gvsig.andami.IconThemeHelper;
62
import org.gvsig.app.ApplicationLocator;
63
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
64
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
65
import org.gvsig.app.project.documents.view.legend.gui.Quantities;
66
import org.gvsig.fmap.dal.exception.DataException;
67
import org.gvsig.fmap.dal.exception.ReadException;
68
import org.gvsig.fmap.dal.feature.Feature;
69
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
70
import org.gvsig.fmap.dal.feature.FeatureSet;
71
import org.gvsig.fmap.dal.feature.FeatureStore;
72
import org.gvsig.fmap.dal.feature.FeatureType;
73
import org.gvsig.fmap.geom.Geometry;
74
import org.gvsig.fmap.mapcontext.MapContextLocator;
75
import org.gvsig.fmap.mapcontext.layers.FLayer;
76
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
77
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
78
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
79
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
80
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
81
import org.gvsig.gui.beans.swing.JBlank;
82
import org.gvsig.gui.beans.swing.JNumberSpinner;
83
import org.gvsig.i18n.Messages;
84
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MarkerFillSymbol;
85
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
86
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
87
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
88
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
89
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
90
import org.gvsig.symbology.fmap.rendering.ProportionalSymbolsLegend;
91
import org.gvsig.tools.dispose.DisposableIterator;
92

  
93
/**
94
 * Implements the panel for the legend of proportional symbols.In the interface will be
95
 * options to select the value field, the normalization field (if the user wants to use it) and
96
 * options to select the symbol an its minimum and maximum size.
97
 *
98
 * Also there will be possible to select a background symbol (only when the shapetype of the layer is
99
 * polygonal).
100
 *
101
 * @author jaume dominguez faus - jaume.dominguez@iver.es
102
 * @author jldominguez
103
 */
104
public class ProportionalSymbolsPanel extends JPanel implements ILegendPanel {
105

  
106
    private static Logger logger = LoggerFactory.getLogger(ProportionalSymbolsPanel.class);
107

  
108
	private static final long serialVersionUID = 7394720230276170902L;
109
	private JPanel symbolPanel;
110
	private JPanel backgroundPanel;
111
	private JSymbolPreviewButton tmplateSymbol;
112
	private JSymbolPreviewButton backSymbol;
113
	private JComboBox cmbValue;
114
	private JComboBox cmbNormalization;
115
	private JNumberSpinner txtMinSize;
116
	private JNumberSpinner txtMaxSize;
117
	private ClassifiableVectorial myLayer;
118
	private ProportionalSymbolsLegend auxLegend;
119
	private String[] fieldNames;
120
	private int templateShapeType = 0;
121

  
122
	private String noNormalization = Messages.getText("none");
123

  
124
	private boolean useNormalization = true;
125

  
126
	/**
127
	 * Default constructor
128
	 */
129
	public ProportionalSymbolsPanel() {
130
		initialize();
131
	}
132

  
133
	/**
134
	 * This method initializes this
135
	 */
136
	private void initialize() {
137

  
138
		setLayout(new BorderLayout());
139
		JPanel aux = new JPanel(new BorderLayout());
140

  
141
		JPanel fieldsPanel = new JPanel(new FlowLayout());
142
		fieldsPanel.setBorder(BorderFactory.
143
				createTitledBorder(null,
144
				    Messages.getText("fields")
145
						));
146
		fieldsPanel.setPreferredSize(new Dimension(300,60));
147

  
148
		cmbValue = new JComboBox();
149
		cmbValue.setActionCommand("VALUE_SELECTED");
150

  
151
		cmbNormalization = new JComboBox();
152
		cmbNormalization.setActionCommand("NORMALIZATION_SELECTED");
153

  
154
		fieldsPanel.add(new JLabel(
155
		    Messages.getText("value")
156
		    +":" ));
157
		fieldsPanel.add(cmbValue);
158

  
159
		fieldsPanel.add(new JLabel(
160
		    Messages.getText("normalization")
161
		    +":" ));
162
		fieldsPanel.add(cmbNormalization);
163

  
164

  
165
		symbolPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 3,2));
166
		symbolPanel.setBorder(BorderFactory.
167
				createTitledBorder(null,
168
				    Messages.getText("symbol")
169
						));
170

  
171
		GridBagLayoutPanel aux2 = new GridBagLayoutPanel();
172
		aux2.addComponent(new JLabel(
173
		    Messages.getText("size")
174
		    ));
175
		aux2.addComponent(new JBlank(10,10));
176
		aux2.addComponent(
177
		    Messages.getText("from")
178
		    +":",
179
				getTxtMinSize());
180
		aux2.addComponent(
181
		    Messages.getText("to")
182
		    +":",
183
				getTxtMaxSize());
184

  
185
		JPanel templatePanel = new JPanel();
186
		templatePanel.setBorder(BorderFactory.createTitledBorder(null,
187
		    Messages.getText("template")
188
				));
189
		templatePanel.add(getTemplSymbol());
190
		symbolPanel.add(new JBlank(10,10));
191
		symbolPanel.add(aux2);
192
		symbolPanel.add(new JBlank(10,10));
193
		symbolPanel.add(templatePanel);
194

  
195
		aux.add(fieldsPanel, BorderLayout.NORTH);
196
		aux.add(symbolPanel, BorderLayout.CENTER);
197

  
198
		this.add(aux, BorderLayout.CENTER);
199

  
200
		cmbValue.addActionListener(action);
201
		cmbNormalization.addActionListener(action);
202
		tmplateSymbol.addActionListener(action);
203
	}
204
	/**
205
	 * Creates the panel where the button for the background symbol will be placed
206
	 *
207
	 * @return JPanel panel
208
	 */
209

  
210
	private JPanel getBackgroundPanel() {
211
		backgroundPanel = new JPanel();
212
		backgroundPanel.setBorder(BorderFactory.createTitledBorder(null,
213
		    Messages.getText("background")
214
				));
215
		backgroundPanel.add(getBtnBackground());
216
		return backgroundPanel;
217
	}
218
	/**
219
	 * Creates a JNumberSpinner which is used to select the maximum size for the symbol
220
	 *
221
	 * @return JNumberSpinner
222
	 */
223
	private JNumberSpinner getTxtMaxSize() {
224
		if (txtMaxSize == null) {
225
			txtMaxSize = new JNumberSpinner(25.0,7,0.0,100.0,1.0,2);
226
			txtMaxSize.addActionListener(action);
227
		}
228
		return txtMaxSize;
229
	}
230
	/**
231
	 * Creates a JNumberSpinner which is used to select the minimum size for the symbol
232
	 *
233
	 * @return JNumberSpinner
234
	 */
235
	private JNumberSpinner getTxtMinSize() {
236
		if (txtMinSize == null) {
237
			txtMinSize = new JNumberSpinner(3.0,7,0.0,100.0,1.0,2);
238
			txtMinSize.addActionListener(action);
239
		}
240
		return txtMinSize;
241
	}
242
	/**
243
	 * Creates a JSymbolPreviewButton which is used to select the template symbol
244
	 *
245
	 * @return JSymbolPreviewButton
246
	 */
247
	private JSymbolPreviewButton getTemplSymbol() {
248

  
249
		if (tmplateSymbol == null) {
250
			int tst = ProportionalSymbolsLegend.isPolygonal(this.templateShapeType) ?
251
			    Geometry.TYPES.POINT
252
			    : this.templateShapeType;
253

  
254
			tmplateSymbol = new JSymbolPreviewButton(tst);
255
		}
256
		tmplateSymbol.setPreferredSize(new Dimension(100, 45));
257
		return tmplateSymbol;
258
	}
259
	/**
260
	 * Creates a JSymbolPreviewButton which is used to select the background symbol
261
	 *
262
	 * @return JSymbolPreviewButton
263
	 */
264
	private JSymbolPreviewButton getBtnBackground() {
265
		if (backSymbol == null) {
266
			backSymbol = new JSymbolPreviewButton(Geometry.TYPES.SURFACE);
267
			backSymbol.setPreferredSize(new Dimension(100, 45));
268

  
269
            ISymbol fillsym = MapContextLocator.getSymbolManager().createSymbol(
270
                Geometry.TYPES.SURFACE, Color.ORANGE);
271
            backSymbol.setSymbol(fillsym);
272
		}
273
		return backSymbol;
274
	}
275
	/**
276
	 * Creates a new symbol of an specific shapetype with a concrete size
277
	 *
278
	 * @param shapeType
279
	 * @param size
280
	 *
281
	 * @return ISymbol symbol created
282
	 */
283
	private ISymbol newSymbol(int shapeType, double size) {
284
		if (getTemplSymbol().getSymbol() == null) {
285
			ISymbol templateSymbol;
286
			switch (shapeType) {
287

  
288
			case Geometry.TYPES.POINT:
289
            case Geometry.TYPES.MULTIPOINT:
290
            case Geometry.TYPES.SURFACE:
291
            case Geometry.TYPES.MULTISURFACE:
292
				templateSymbol = new SimpleMarkerSymbol();
293
				((SimpleMarkerSymbol) templateSymbol).setSize(size);
294
				((SimpleMarkerSymbol) templateSymbol).setColor(Color.DARK_GRAY);
295
				break;
296

  
297
            case Geometry.TYPES.ARC:
298
            case Geometry.TYPES.CIRCLE:
299
            case Geometry.TYPES.CURVE:
300
            case Geometry.TYPES.ELLIPSE:
301
            case Geometry.TYPES.ELLIPTICARC:
302
            case Geometry.TYPES.MULTICURVE:
303
            case Geometry.TYPES.SPLINE:
304
				templateSymbol = new SimpleLineSymbol();
305
				((SimpleLineSymbol) templateSymbol).setLineWidth(size);
306
				((SimpleLineSymbol) templateSymbol).setLineColor(Color.DARK_GRAY);
307
				break;
308
			default:
309
				throw new Error("Unknown symbol type");
310
			}
311
			getTemplSymbol().setSymbol(templateSymbol);
312
			return newSymbol(shapeType, size);
313
		} else {
314
			// clone symbol
315
			ISymbol mySymbol = getTemplSymbol().getSymbol();
316

  
317
			try {
318
                mySymbol = (ISymbol) mySymbol.clone();
319
            } catch (CloneNotSupportedException e) {
320
                logger.info("Error while cloning symbol", e);
321
                ApplicationLocator.getManager().messageDialog(
322
                    Messages.getText("_Unable_to_clone_symbol"),
323
                    Messages.getText("error"),
324
                    JOptionPane.ERROR_MESSAGE);
325
            }
326

  
327
			if (mySymbol instanceof ILineSymbol) {
328
				ILineSymbol lSym = (ILineSymbol) mySymbol;
329
				lSym.setLineWidth(size);
330

  
331
			}
332
			if (mySymbol instanceof IMarkerSymbol) {
333
				IMarkerSymbol mSym = (IMarkerSymbol) mySymbol;
334
				mSym.setSize(size);
335

  
336
				if (ProportionalSymbolsLegend.isPolygonal(shapeType)) {
337
					// this is to allow using in Polygon layers
338
					MarkerFillSymbol fillSymbol = new MarkerFillSymbol();
339
					fillSymbol.setOutline(null);
340
					fillSymbol.setFillColor(null);
341
					fillSymbol.getMarkerFillProperties().
342
					setFillStyle(IMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
343
					fillSymbol.setMarker(mSym);
344
				}
345
			}
346
			return mySymbol;
347
		}
348
	}
349

  
350
	/**
351
	 * Fills the comboboxes that are placed in the panel with the classifying field names of the layer
352
	 * which contain numerical information
353
	 *
354
	 */
355
	private void fillFieldNames() {
356

  
357
		// SelectableDataSource rs;
358

  
359
		try {
360
		    FeatureStore fsto = (FeatureStore) ((FLyrVect) myLayer).getDataStore();
361
		    FeatureType fty = fsto.getDefaultFeatureType();
362

  
363
		    FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
364
			int cont = 0;
365
			for (int i = 0; i < atts.length; i++) {
366
			    if (atts[i].getDataType().isNumeric()) {
367
                    cont++;
368
			    }
369
			}
370
			String[] nomFields = new String[cont];
371

  
372
			cont = 0;
373
            for (int i = 0; i < atts.length; i++) {
374
                if (atts[i].getDataType().isNumeric()) {
375
                    nomFields[cont] = atts[i].getName();
376
                    cont++;
377
                }
378
            }
379
			this.fieldNames = nomFields;
380

  
381

  
382
			DefaultComboBoxModel cMValue = new DefaultComboBoxModel(this.fieldNames);
383
			DefaultComboBoxModel cMNormalization = new DefaultComboBoxModel(this.fieldNames);
384
			cmbValue.setModel(cMValue);
385
			cmbNormalization.setModel(cMNormalization);
386
			cmbNormalization.addItem(noNormalization);
387

  
388
		} catch (DataException e) {
389

  
390
		    logger.info("Error while getting fields", e);
391
		    ApplicationLocator.getManager().messageDialog(
392
		        Messages.getText("_Error_while_getting_fields"),
393
                Messages.getText("error"),
394
		        JOptionPane.ERROR_MESSAGE);
395

  
396
			// NotificationManager.addError(PluginServices.getText(this, "recovering_recordset"), e);
397
		}
398
	}
399

  
400

  
401
	public void setData(FLayer lyr, ILegend legend) {
402

  
403
		this.myLayer = (ClassifiableVectorial) lyr;
404

  
405
		fillFieldNames();
406

  
407
	    int myt = Geometry.TYPES.GEOMETRY;
408

  
409
	    try {
410
	        myt = this.myLayer.getGeometryType().getType();
411
	    } catch (ReadException re) {
412
	        logger.info("Error while getting geometry type", re);
413
	        ApplicationLocator.getManager().message(
414
	            "Error getting geometry type",
415
	            JOptionPane.ERROR_MESSAGE);
416
	    }
417

  
418
		templateShapeType =
419
		    ProportionalSymbolsLegend.isPolygonal(myt) ?
420
		    Geometry.TYPES.POINT : myt;
421

  
422
		getTemplSymbol().setShapeType(templateShapeType);
423

  
424
		if (ProportionalSymbolsLegend.isPolygonal(myt) && backgroundPanel == null) {
425
		    symbolPanel.add(getBackgroundPanel());
426
		}
427

  
428

  
429
		if (ProportionalSymbolsLegend.class.equals(legend.getClass())) {
430

  
431
            auxLegend = (ProportionalSymbolsLegend) legend.cloneLegend();
432
			cmbValue.setSelectedItem(auxLegend.getClassifyingFieldNames()[0]);
433
			ISymbol defSymbol = auxLegend.getDefaultSymbol();
434

  
435
			if(((ProportionalSymbolsLegend) auxLegend).getUseNormalization())
436
				cmbNormalization.setSelectedItem(auxLegend.getClassifyingFieldNames()[1]);
437
			else cmbNormalization.setSelectedItem(noNormalization);
438

  
439
			txtMaxSize.setDouble(auxLegend.getMaxSize());
440
			txtMinSize.setDouble(auxLegend.getMinSize());
441

  
442
			if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
443
			    ((ILineSymbol)defSymbol).setLineWidth(2);
444
			} else {
445
                ((IMarkerSymbol)defSymbol).setSize(15);
446
			}
447

  
448
			getTemplSymbol().setSymbol(defSymbol);
449

  
450
			if(((ProportionalSymbolsLegend) auxLegend).getBackgroundSymbol() != null)
451
				getBtnBackground().setSymbol(((ProportionalSymbolsLegend) auxLegend).getBackgroundSymbol());
452

  
453
		} else {
454

  
455
			auxLegend = new ProportionalSymbolsLegend();
456
			auxLegend.setTemplateShapeType(templateShapeType);
457

  
458
			if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
459
	            auxLegend.setDefaultSymbol(newSymbol(templateShapeType, 2));
460
			} else {
461
	            auxLegend.setDefaultSymbol(newSymbol(templateShapeType, 15));
462
			}
463

  
464
			getTemplSymbol().setSymbol(auxLegend.getDefaultSymbol());
465
			if (ProportionalSymbolsLegend.isLinear(templateShapeType)) {
466
                txtMinSize.setDouble(3);
467
                txtMaxSize.setDouble(3);
468
			} else {
469
                txtMinSize.setDouble(10);
470
                txtMaxSize.setDouble(10);
471
			}
472
		}
473

  
474
	}
475

  
476

  
477
	public ILegend getLegend() {
478
		ProportionalSymbolsLegend theLegend = new ProportionalSymbolsLegend();
479

  
480
		String[] fieldNames = new String[2];
481
		fieldNames[0]= cmbValue.getSelectedItem().toString();
482

  
483
		if(!useNormalization)
484
			fieldNames[1]= fieldNames[0];
485
		else fieldNames[1]= cmbNormalization.getSelectedItem().toString();
486

  
487
		auxLegend.setTemplateShapeType(templateShapeType);
488
		auxLegend.setValueField(cmbValue.getSelectedItem().toString());
489
		auxLegend.setNormalizationField(cmbNormalization.getSelectedItem().toString());
490
		auxLegend.setUseNormalization(useNormalization);
491

  
492
		auxLegend.setMinSize(txtMinSize.getDouble());
493
		auxLegend.setMaxSize(txtMaxSize.getDouble());
494

  
495
		ISymbol symbol = getTemplSymbol().getSymbol();
496
		symbol.setDescription(getSymbolDescription());
497
		auxLegend.setDefaultSymbol(symbol);
498

  
499
        auxLegend.clear();
500
		auxLegend.addSymbol("defaultSymbol", symbol);
501

  
502
		auxLegend.setBackgroundSymbol(getBtnBackground().getSymbol());
503
		auxLegend.setClassifyingFieldNames(fieldNames);
504

  
505
		// ==================================
506

  
507
		FLyrVect vect = (FLyrVect) myLayer;
508
		FeatureStore fsto = null;
509
		FeatureType fty = null;
510
		FeatureAttributeDescriptor[] atts = null;
511

  
512
		try {
513
		    fsto = (FeatureStore) vect.getDataStore();
514
		    fty = fsto.getDefaultFeatureType();
515

  
516
		    int[] fieldTyp = new int[2];
517
		    fieldTyp[0] = fty.getAttributeDescriptor(fieldNames[0]).getType();
518
            fieldTyp[1] = fty.getAttributeDescriptor(fieldNames[1]).getType();
519
            auxLegend.setClassifyingFieldTypes(fieldTyp);
520

  
521
		    FeatureSet fset = fsto.getFeatureSet();
522
		    DisposableIterator diter = fset.fastIterator();
523
		    Feature fitem = null;
524
		    double[] maxs = new double[fieldNames.length];
525
            double[] mins = new double[fieldNames.length];
526
            for (int i=0; i<fieldNames.length; i++) {
527
                // init to worst values
528
                maxs[i] = -Double.MAX_VALUE;
529
                mins[i] = Double.MAX_VALUE;
530
            }
531
            double aux_dob = 0;
532

  
533
		    while (diter.hasNext()) {
534
		        fitem = (Feature) diter.next();
535
		        for (int i=0; i<fieldNames.length; i++) {
536
		            aux_dob = fitem.getDouble(fieldNames[i]);
537
		            if (aux_dob > maxs[i]) {
538
		                maxs[i] = aux_dob;
539
		            }
540
                    if (aux_dob < mins[i]) {
541
                        mins[i] = aux_dob;
542
                    }
543
		        }
544
		    }
545
            auxLegend.setMinFeature(mins[0]);
546
            auxLegend.setMaxFeature(maxs[0]);
547

  
548
		} catch (DataException e) {
549
		    logger.info("Error while creating ProportionalSymbols legend", e);
550
		    ApplicationLocator.getManager().message(
551
		        Messages.getText("_Error_while_creating_legend"),
552
		        JOptionPane.ERROR_MESSAGE);
553
		}
554

  
555
        theLegend = (ProportionalSymbolsLegend) auxLegend.cloneLegend();
556
        // theLegend.addSymbol("defaultSymbol", symbol);
557

  
558
		return theLegend;
559
	}
560
	/**
561
	 * Creates the String which will be the description of the symbol. If the selected normalization field
562
	 * is not "None", then the String created will have this structure ValueField/NormalizationField. Else,
563
	 * if the user select "None" for the normalization field,the string will show the ValueField only.
564
	 *
565
	 * @return String	description for the symbol
566
	 */
567

  
568
	private String getSymbolDescription() {
569
		String description = "";
570

  
571
		if (cmbValue.getSelectedItem() != null)
572
			description += cmbValue.getSelectedItem().toString();
573
		if (cmbNormalization.getSelectedItem().toString().compareTo(noNormalization) != 0 )
574
			description += " / "+cmbNormalization.getSelectedItem().toString();
575

  
576
		return description;
577
	}
578

  
579
	public String getDescription() {
580
		return Messages.getText(
581
		    "draw_quantities_using_symbol_size_to_show_exact_values");
582
	}
583

  
584
	public ImageIcon getIcon() {
585
	    return IconThemeHelper.getImageIcon(
586
	        "legend-overview-proportional-symbols");
587
	}
588

  
589
	public Class getParentClass() {
590
		return Quantities.class;
591
	}
592

  
593
	public String getTitle() {
594
	    return Messages.getText("proportional_symbols");
595
	}
596

  
597
	public Class getLegendClass() {
598
		return ProportionalSymbolsLegend.class;
599
	}
600

  
601

  
602
	public boolean isSuitableFor(FLayer layer) {
603
		if (layer instanceof FLyrVect) {
604

  
605
			FLyrVect lyr = (FLyrVect) layer;
606
			try {
607
				if (lyr.getShapeType() == Geometry.TYPES.GEOMETRY)
608
					return false;
609

  
610
				FeatureStore fsto = (FeatureStore) lyr.getDataStore();
611
				FeatureType fty = fsto.getDefaultFeatureType();
612
				FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
613

  
614
				for (int i = 0; i < atts.length; i++) {
615
					if (atts[i].getDataType().isNumeric()) {
616
						return true;
617
					}
618
				}
619
			} catch (DataException e) {
620
			    logger.info("Error in isSuitableFor", e);
621
			    ApplicationLocator.getManager().message(
622
			        Messages.getText("_Error_while_checking_suitability"),
623
			        JOptionPane.ERROR_MESSAGE);
624
				return false;
625
			}
626
		}
627
		return false;
628
	}
629

  
630

  
631
	public JPanel getPanel() {
632
		return this;
633
	}
634

  
635

  
636
	private ActionListener action = new ActionListener() {
637

  
638
		public void actionPerformed(ActionEvent e) {
639

  
640
			if (e.getSource().equals(cmbValue)) {
641
				JComboBox cb = (JComboBox) e.getSource();
642
				auxLegend.setValueField(cb.getSelectedItem().toString());
643
			}
644
			if (e.getSource().equals(cmbNormalization)) {
645
				JComboBox cb = (JComboBox) e.getSource();
646
				if(cb.getSelectedItem().toString().compareTo(noNormalization) == 0) {
647
					useNormalization = false;
648
					auxLegend.setNormalizationField(cmbValue.getSelectedItem().toString());
649
				}
650
				else {
651
					useNormalization = true;
652
					auxLegend.setNormalizationField(cb.getSelectedItem().toString());
653
				}
654
				auxLegend.setUseNormalization(useNormalization);
655
			}
656
			if (e.getSource().equals(txtMinSize)) {
657
//				ISymbol sym = tmplateSymbol.getSymbol();
658
//				if(sym != null) {
659
//					if(sym instanceof ILineSymbol) {
660
//						ILineSymbol line = (ILineSymbol)sym;
661
//						line.setLineWidth(txtMinSize.getDouble());
662
//						tmplateSymbol.setSymbol(line);
663
//					}
664
//
665
//					if(sym instanceof IMarkerSymbol) {
666
//						IMarkerSymbol point = (IMarkerSymbol)sym;
667
//						point.setSize(txtMinSize.getDouble());
668
//						tmplateSymbol.setSymbol(point);
669
//					}
670
//					tmplateSymbol.repaint();
671
//				}
672

  
673
				if(txtMaxSize.getDouble() < txtMinSize.getDouble())
674
					txtMaxSize.setDouble(txtMinSize.getDouble());
675
			}
676
			if(e.getSource().equals(txtMaxSize)) {
677
				if(txtMaxSize.getDouble() < txtMinSize.getDouble())
678
					txtMinSize.setDouble(txtMaxSize.getDouble());
679
			}
680
//			if(e.getSource().equals(tmplateSymbol)) {
681
//				ISymbol sym = tmplateSymbol.getSymbol();
682
//				if(sym != null) {
683
//					if(sym instanceof ILineSymbol) {
684
//						ILineSymbol line = (ILineSymbol)sym;
685
//						txtMinSize.setDouble(((int)line.getLineWidth()));
686
//						txtMaxSize.setDouble(((int)line.getLineWidth()));
687
//					}
688
//
689
//					if(sym instanceof IMarkerSymbol) {
690
//						IMarkerSymbol point = (IMarkerSymbol)sym;
691
//						txtMinSize.setDouble(((int)point.getSize()));
692
//						txtMaxSize.setDouble(((int)point.getSize()));
693
//
694
//					}
695
//				}
696
//			}
697
		}
698
	};
699

  
700
}
org.gvsig.legend.proportionalsymbols.app.mainplugin/tags/org.gvsig.legend.proportionalsymbols.app.mainplugin-1.0.44/src/main/java/org/gvsig/symbology/library/ProportionalSymbolsLibrary.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.library;
24

  
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.app.project.documents.view.legend.gui.LegendManager;
27
import org.gvsig.symbology.SymbologyLibrary;
28
import org.gvsig.symbology.fmap.rendering.ProportionalSymbolsLegend;
29
import org.gvsig.symbology.gui.layerproperties.ProportionalSymbolsPanel;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32
import org.gvsig.tools.persistence.xml.XMLPersistenceLibrary;
33
import org.gvsig.tools.util.Caller;
34
import org.gvsig.tools.util.impl.DefaultCaller;
35

  
36

  
37
/**
38
 * Simple library to register proportional symbols legend
39
 * 
40
 * @author jldominguez
41
 *
42
 */
43
public class ProportionalSymbolsLibrary extends AbstractLibrary {
44

  
45

  
46
    public void doRegistration() {
47
        registerAsImplementationOf(ProportionalSymbolsLibrary.class);
48
        /*
49
         * This checks map context library registration
50
         */
51
        require(SymbologyLibrary.class);
52
        /*
53
         * This is because we need to use persistence manager
54
         */
55
        require(XMLPersistenceLibrary.class);
56
    }
57

  
58
    protected void doInitialize() throws LibraryException {
59
        
60
    }
61

  
62

  
63
    protected void doPostInitialize() throws LibraryException {
64
        
65
        IconThemeHelper.registerIcon(
66
            "legend", "legend-overview-proportional-symbols", this);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff