Revision 571 org.gvsig.chart/trunk/org.gvsig.chart/org.gvsig.chart.app/org.gvsig.chart.app.legendplugin/src/main/java/org/gvsig/project/documents/view/legend/BarsChartLegend.java

View differences:

BarsChartLegend.java
27 27
import org.gvsig.fmap.mapcontext.MapContextManager;
28 28
import org.gvsig.fmap.mapcontext.ViewPort;
29 29
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
30
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
31 30
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
32 31
import org.gvsig.symbology.SymbologyLocator;
33 32
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
......
45 44
import org.slf4j.LoggerFactory;
46 45

  
47 46
public class BarsChartLegend extends VectorialUniqueValueLegend implements IBarsChartLegend {
48
    final static private Logger LOG = LoggerFactory.getLogger(BarsChartLegend.class);
49 47

  
48
    final static private Logger LOGGER = LoggerFactory.getLogger(BarsChartLegend.class);
50 49

  
51
	public static class RegisterLegend implements Callable {
50
    public static class RegisterLegend implements Callable {
52 51

  
53
		public Object call() throws Exception {
54
	        MapContextManager manager = MapContextLocator.getMapContextManager();
52
        @Override
53
        public Object call() throws Exception {
54
            MapContextManager manager = MapContextLocator.getMapContextManager();
55 55

  
56 56
            manager.registerLegend(IChartLegend.BARSCHART_LEGEND_NAME,
57 57
                    BarsChartLegend.class);
58 58

  
59
			return Boolean.TRUE;
60
		}
59
            return Boolean.TRUE;
60
        }
61 61

  
62
	}
62
    }
63 63

  
64
    public static final String BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "BarsChartLegend";
64 65

  
65
	public static final String BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME = "BarsChartLegend";
66
    private static final String FIELD_NAMES = "FieldLegendNames";
67
    private static final String FIELD_LABEL_NAMES = "FieldLabelNames";
68
    private static final String FIELD_LABEL_COLOR = "FieldLabelColor";
66 69

  
67
	private static final String FIELD_NAMES = "FieldLegendNames";
68
	private static final String FIELD_LABEL_NAMES = "FieldLabelNames";
69
	private static final String FIELD_LABEL_COLOR = "FieldLabelColor";
70
    protected ISymbol backgroundSymbol;
71
    protected String[] fields;
72
    protected String[] labels;
73
    protected int size = 150;
74
    protected boolean is3D;
70 75

  
71
	protected ISymbol backgroundSymbol;
72
	protected String[] fields;
73
	protected String[] labels;
74
	protected int size=150;
75
	protected boolean is3D;
76
    protected boolean isOutlineShow;
77
    protected Color outlineColor;
78
    protected int outlineWidth;
79
    protected boolean onlySelection = false;
80
    protected int referenceSystem = 0;
81
    protected String fieldSize;
82
    protected String fieldNormalize = "---";
83
    protected int sizeFrom = 10;
84
    protected int sizeTo = 1000;
85
    protected int unit = -1;
86
    protected int sizeOption = IChartSymbol.SIZEFIXED;
87
    protected boolean isActiveLimits;
88
    protected double minFeature;
89
    protected double maxFeature;
90
    protected Color[] colors = null;
91
    protected IChartSymbol symbol;
92
    private double maxField;
93
    protected FeatureSelection featSelection;
76 94

  
77
	protected boolean isOutlineShow;
78
	protected Color outlineColor;
79
	protected int outlineWidth;
80
	protected boolean onlySelection=false;
81
	protected int referenceSystem=0;
82
	protected String fieldSize;
83
	protected String fieldNormalize="---";
84
	protected int sizeFrom=10;
85
	protected int sizeTo=1000;
86
	protected int unit=-1;
87
	protected int sizeOption = IChartSymbol.SIZEFIXED;
88
	protected ZSort zSort = null;
89
	protected boolean isActiveLimits;
90
	protected double minFeature;
91
	protected double maxFeature;
92
	protected Color[] colors= null;
93
	protected IChartSymbol symbol;
94
	private double maxField;
95
	protected FeatureSelection featSelection;
95
    public BarsChartLegend() {
96
    }
96 97

  
97
	public BarsChartLegend() {
98
	}
98
    public BarsChartLegend(int shapeType) {
99
        super(shapeType);
100
    }
99 101

  
100
	public BarsChartLegend(int shapeType) {
101
		super(shapeType);
102
	}
102
    @Override
103
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
104
            Cancellable cancel, double scale, Map queryParameters,
105
            ICoordTrans coordTrans, FeatureStore featureStore,
106
            FeatureQuery featureQuery) throws LegendException {
107
        try {
108
            this.featSelection = featureStore.getFeatureSelection();
109
            System.out.println("CHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados.");
110
        } catch (DataException e) {
111
            e.printStackTrace();
112
        }
103 113

  
114
        super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
115
                featureStore, featureQuery);
116
    }
104 117

  
105
	@Override
106
	public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
107
			Cancellable cancel, double scale, Map queryParameters,
108
			ICoordTrans coordTrans, FeatureStore featureStore,
109
			FeatureQuery featureQuery) throws LegendException {
110
		try {
111
			this.featSelection = featureStore.getFeatureSelection();
112
			System.out.println("CHARTLEGEND: " + featSelection.getSelectedCount() + " seleccionados.");
113
		} catch (DataException e) {
114
			e.printStackTrace();
115
		}
118
    @Override
119
    public boolean is3D() {
120
        return is3D;
121
    }
116 122

  
123
    @Override
124
    public void setIs3D(boolean b) {
125
        is3D = b;
126
    }
117 127

  
118
		super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
119
				featureStore, featureQuery);
120
	}
128
    @Override
129
    public int getSize() {
130
        return size;
131
    }
121 132

  
122
	/* (non-Javadoc)
123
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#is3D()
124
	 */
125
	public boolean is3D() {
126
		return is3D;
127
	}
133
    @Override
134
    public void setSize(int size) {
135
        this.size = size;
136
    }
128 137

  
129
	/* (non-Javadoc)
130
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setIs3D(boolean)
131
	 */
132
	public void setIs3D(boolean b){
133
		is3D=b;
134
	}
138
    @Override
139
    public boolean isOutlineShow() {
140
        return isOutlineShow;
141
    }
135 142

  
136
	/* (non-Javadoc)
137
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getSize()
138
	 */
139
	public int getSize() {
140
		return size;
141
	}
143
    @Override
144
    public void setOutlineShow(boolean isOutlineShow) {
145
        this.isOutlineShow = isOutlineShow;
146
    }
142 147

  
143
	/* (non-Javadoc)
144
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setSize(int)
145
	 */
146
	public void setSize(int size) {
147
		this.size = size;
148
	}
148
    @Override
149
    public Color getOutlineColor() {
150
        return outlineColor;
151
    }
149 152

  
150
	/* (non-Javadoc)
151
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#isOutlineShow()
152
	 */
153
	public boolean isOutlineShow() {
154
		return isOutlineShow;
155
	}
153
    @Override
154
    public void setOutlineColor(Color outlineColor) {
155
        this.outlineColor = outlineColor;
156
    }
156 157

  
157
	/* (non-Javadoc)
158
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineShow(boolean)
159
	 */
160
	public void setOutlineShow(boolean isOutlineShow) {
161
		this.isOutlineShow = isOutlineShow;
162
	}
158
    @Override
159
    public int getOutlineWidth() {
160
        return outlineWidth;
161
    }
163 162

  
164
	/* (non-Javadoc)
165
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getOutlineColor()
166
	 */
167
	public Color getOutlineColor() {
168
		return outlineColor;
169
	}
163
    @Override
164
    public void setOutlineWidth(int outlineWidth) {
165
        this.outlineWidth = outlineWidth;
166
    }
170 167

  
171
	/* (non-Javadoc)
172
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineColor(java.awt.Color)
173
	 */
174
	public void setOutlineColor(Color outlineColor) {
175
		this.outlineColor = outlineColor;
176
	}
168
    @Override
169
    public void setOnlySelection(boolean onlySelection) {
170
        this.onlySelection = onlySelection;
171
    }
177 172

  
178
	/* (non-Javadoc)
179
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#getOutlineWidth()
180
	 */
181
	public int getOutlineWidth() {
182
		return outlineWidth;
183
	}
173
    @Override
174
    public boolean isOnlySelection() {
175
        return onlySelection;
176
    }
184 177

  
185
	/* (non-Javadoc)
186
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOutlineWidth(int)
187
	 */
188
	public void setOutlineWidth(int outlineWidth) {
189
		this.outlineWidth = outlineWidth;
190
	}
191
	/* (non-Javadoc)
192
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#setOnlySelection(boolean)
193
	 */
194
	public void setOnlySelection(boolean onlySelection) {
195
		this.onlySelection=onlySelection;
196
	}
178
    @Override
179
    public ISymbol getBackgroundSymbol() {
180
        return backgroundSymbol;
181
    }
197 182

  
198
	/* (non-Javadoc)
199
	 * @see org.gvsig.symbology.fmap.mapcontext.rendering.legend.IChartLegend#isOnlySelection()
200
	 */
201
	public boolean isOnlySelection() {
202
		return onlySelection;
203
	}
183
    @Override
184
    public void setBackgroundSymbol(ISymbol backgroundSymbol) {
185
        this.backgroundSymbol = backgroundSymbol;
186
    }
204 187

  
205
	public ISymbol getBackgroundSymbol() {
206
		return backgroundSymbol;
207
	}
188
    @Override
189
    public int getSizeOption() {
190
        return this.sizeOption;
191
    }
208 192

  
209
	public void setBackgroundSymbol(ISymbol backgroundSymbol) {
210
		this.backgroundSymbol = backgroundSymbol;
211
	}
193
    @Override
194
    public String getFieldSize() {
195
        return this.fieldSize;
196
    }
212 197

  
213
	public int getSizeOption() {
214
		return this.sizeOption;
215
	}
198
    @Override
199
    public String getFieldNormalize() {
200
        return this.fieldNormalize;
201
    }
216 202

  
217
	public String getFieldSize() {
218
		return this.fieldSize;
219
	}
203
    @Override
204
    public int getSizeFrom() {
205
        return this.sizeFrom;
206
    }
220 207

  
221
	public String getFieldNormalize() {
222
		return this.fieldNormalize;
223
	}
208
    @Override
209
    public int getSizeTo() {
210
        return this.sizeTo;
211
    }
224 212

  
225
	public int getSizeFrom() {
226
		return this.sizeFrom;
227
	}
213
    @Override
214
    public int getUnit() {
215
        return unit;
216
    }
228 217

  
229
	public int getSizeTo() {
230
		return this.sizeTo;
231
	}
218
    @Override
219
    public void setSizeFrom(int s) {
220
        this.sizeFrom = s;
221
    }
232 222

  
233
	public int getUnit() {
234
		return unit;
235
	}
223
    @Override
224
    public void setSizeTo(int s) {
225
        this.sizeTo = s;
226
    }
236 227

  
237
	public void setSizeFrom(int s) {
238
		this.sizeFrom = s;
239
	}
228
    @Override
229
    public void setUnit(int unit) {
230
        this.unit = unit;
231
    }
240 232

  
241
	public void setSizeTo(int s) {
242
		this.sizeTo = s;
243
	}
233
    @Override
234
    public void setFieldSize(String f) {
235
        this.fieldSize = f;
236
    }
244 237

  
245
	public void setUnit(int unit) {
246
		this.unit = unit;
247
	}
238
    @Override
239
    public void setFieldNormalize(String f) {
240
        this.fieldNormalize = f;
241
    }
248 242

  
249
	public void setFieldSize(String f) {
250
		this.fieldSize = f;
251
	}
243
    @Override
244
    public void setSizeOption(int option) {
245
        this.sizeOption = option;
246
    }
252 247

  
253
	public void setFieldNormalize(String f) {
254
		this.fieldNormalize = f;
255
	}
248
    @Override
249
    public boolean isActiveLimits() {
250
        return isActiveLimits;
251
    }
256 252

  
257
	public void setSizeOption(int option) {
258
		this.sizeOption = option;
259
	}
253
    @Override
254
    public void setActiveLimits(boolean b) {
255
        this.isActiveLimits = b;
256
    }
260 257

  
261
	public boolean isActiveLimits() {
262
		return isActiveLimits;
263
	}
258
    @Override
259
    public Color[] getColors() {
260
        return colors;
261
    }
264 262

  
265
	public void setActiveLimits(boolean b) {
266
		this.isActiveLimits = b;
267
	}
263
    @Override
264
    public void setColors(Color[] colors) {
265
        this.colors = colors;
266
        updateSymbols();
267
    }
268 268

  
269
	public Color[] getColors() {
270
		return colors;
271
	}
269
    @Override
270
    public int getReferenceSystem() {
271
        return referenceSystem;
272
    }
272 273

  
273
	public void setColors(Color[] colors) {
274
		this.colors = colors;
275
		updateSymbols();
276
	}
274
    @Override
275
    public void setReferenceSystem(int rs) {
276
        this.referenceSystem = rs;
277
    }
277 278

  
278
	public int getReferenceSystem() {
279
		return referenceSystem;
280
	}
279
    @Override
280
    public void setMinFeature(double min) {
281
        this.minFeature = min;
282
    }
281 283

  
282
	public void setReferenceSystem(int rs) {
283
		this.referenceSystem = rs;
284
	}
284
    @Override
285
    public void setMaxFeature(double max) {
286
        this.maxFeature = max;
287
    }
285 288

  
286
	public void setMinFeature(double min) {
287
		this.minFeature = min;
288
	}
289
    @Override
290
    public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
291
        Feature feat2 = feat.getCopy();
292
        if (this.onlySelection) {
293
            if (!featSelection.isSelected(feat)) {
294
                return null;
295
            }
296
        }
289 297

  
290
	public void setMaxFeature(double max) {
291
		this.maxFeature = max;
292
	}
298
        // TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
299
        symbol = (IChartSymbol) getDefaultSymbol();
300
        if (symbol == null) {
301
            symbol = (IChartSymbol) MapContextLocator
302
                    .getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
293 303

  
294
	@Override
295
	public ISymbol getSymbolByFeature(Feature feat) throws MapContextException {
296
		Feature feat2 = feat.getCopy();
297
		if (this.onlySelection)
298
			if (!featSelection.isSelected(feat))
299
				return null;
304
        }
305
        symbol.setOnlySelection(onlySelection);
306
        double size1 = 0d;
300 307

  
301
		// TODO: AQU? PRODR?AMOS RECUPERAR VARIOS SIMBOLOS. POR AHORA, SUPONEMOS QUE EL DEFAULTSYMBOL ES EL QUE TIENE EL CHARTSYMBOL
302
		symbol = (IChartSymbol) getDefaultSymbol();
303
		if (symbol==null){
304
			symbol = (IChartSymbol) MapContextLocator
305
				.getSymbolManager().createSymbol(IChartSymbol.SYMBOL_NAME);
308
        ChartDataSet dataSet = ChartLocator.getServiceManager()
309
                .getChartManager().createChartDataSet();
306 310

  
307
		}
308
		symbol.setOnlySelection(onlySelection);
309
		double size=0;
311
        String[] names = getFieldNames();
310 312

  
311
			ChartDataSet dataSet = ChartLocator.getServiceManager()
312
				.getChartManager().createChartDataSet();
313
        if (names != null) {
314
            ArrayList groupedBy = new ArrayList();
315
            ArrayList serie = new ArrayList();
316
            ArrayList category = new ArrayList();
317
            for (String name : names) {
318
                double val = feat2.getDouble(name);
319
                if (sizeOption == IChartSymbol.SIZESUM) {
320
                    size1 += val;
321
                }
322
                groupedBy.add(name);
323
                serie.add("default");
324
                category.add(val);
325
            }
326
            dataSet.addData("groupby", groupedBy);
327
            dataSet.addData("series", serie);
328
            dataSet.addData("categories", category);
313 329

  
314
		String[] names=getFieldNames();
330
            symbol.getChart().setChartDataSet(dataSet);
331
            ChartService cs = symbol.getChart();
332
            cs.getChartProperties().setChartDimension(this.is3D);
315 333

  
316
		if (names!=null){
317
			ArrayList groupedBy = new ArrayList();
318
			ArrayList serie = new ArrayList();
319
			ArrayList category = new ArrayList();
320
			for (int i = 0; i < names.length; i++) {
321
				double val = feat2.getDouble(names[i]);
322
				if (sizeOption==IChartSymbol.SIZESUM){
323
					size+=val;
324
				}
325
				groupedBy.add(names[i]);
326
				serie.add("default");
327
				category.add(val);
328
			}
329
			dataSet.addData("groupby", groupedBy);
330
			dataSet.addData("series", serie);
331
			dataSet.addData("categories", category);
334
            List<ChartSerieEntity> lst = cs.getChartLegendItems();
332 335

  
333
			symbol.getChart().setChartDataSet(dataSet);
334
			ChartService cs = symbol.getChart();
335
			cs.getChartProperties().setChartDimension(this.is3D);
336
//			cs.createChartLegendItems();
337
			List<ChartSerieEntity> lst  = cs.getChartLegendItems();
338

  
339
            for (int j=0; j < names.length; j++) {
336
            for (int j = 0; j < names.length; j++) {
340 337
                colors[j] = getSymbolByValue(names[j]).getColor();
341 338
                LegendItem item = new LegendItem(names[j], colors[j]);
342
				item.setSeriesKey(names[j]);
343
				ChartSerieEntity e = cs.createNewChartSerieEntity(item);
344
				if(e!=null)
345
					lst.add(e);
346
			}
339
                item.setSeriesKey(names[j]);
340
                ChartSerieEntity e = cs.createNewChartSerieEntity(item);
341
                if (e != null) {
342
                    lst.add(e);
343
                }
344
            }
347 345
            cs.setCategoriesPaint(Arrays.asList(colors));
348
		}
349
		double separation = sizeTo-sizeFrom;
346
        }
347
        double separation = sizeTo - sizeFrom;
350 348

  
351
		if (sizeOption==IChartSymbol.SIZESUM){
352
			if (isActiveLimits()){
353
				double difFeat = maxFeature - minFeature;
354
				double step = difFeat/separation;
355
				size = sizeFrom + ((size - minFeature)/step);
356
			}
357
			symbol.setSize(size);
358
		}else if (sizeOption==IChartSymbol.SIZEFIELD){
359
			if(separation == 0)
360
				separation = 1;
361
			double value=feat2.getDouble(getFieldSize());
349
        switch (sizeOption) {
350
            case IChartSymbol.SIZESUM:
351
                if (isActiveLimits()) {
352
                    double difFeat = maxFeature - minFeature;
353
                    double step = difFeat / separation;
354
                    size1 = sizeFrom + ((size1 - minFeature) / step);
355
                }
356
                symbol.setSize(size1);
357
                break;
358
            case IChartSymbol.SIZEFIELD:
359
                if (separation == 0) {
360
                    separation = 1;
361
                }
362
                double value = feat2.getDouble(getFieldSize());
363
                if (!getFieldNormalize().equals("---")) {
364
                    double normalize = feat2.getDouble(getFieldNormalize());
365
                    if (normalize != 0) {
366
                        value = value / normalize;
367
                    }
368
                    if (isActiveLimits()) {
369
                        size1 = sizeFrom + (value * separation);
370
                    } else {
371
                        size1 = value;
372
                    }
373
                } else {
374
                    if (isActiveLimits()) {
375
                        double difFeat = maxFeature - minFeature;
376
                        double step = difFeat / separation;
377
                        size1 = sizeFrom + ((value - minFeature) / step);
378
                    } else {
379
                        size1 = value;
380
                    }
381
                }
382
                symbol.setSize(size1);
383
                break;
384
            default:
385
                symbol.setSize(getSize());
386
                break;
387
        }
388
        return symbol;
362 389

  
363
			if (!getFieldNormalize().equals("---")){
364
				double normalize=feat2.getDouble(getFieldNormalize());
365
				if (normalize!=0){
366
					value= value/normalize;
367
				}
368
				if (isActiveLimits())
369
					size = sizeFrom + (value * separation) ;
370
				else
371
					size=value;
372
			}else{
373
				if (isActiveLimits()){
374
					double difFeat = maxFeature - minFeature;
375
					double step = difFeat/separation;
376
					size = sizeFrom + ((value - minFeature)/step);
377
				}else{
378
					size=value;
379
				}
380
			}
381
			symbol.setSize(size);
382
		}else{
383
			symbol.setSize(getSize());
384
		}
385
		return symbol;
390
    }
386 391

  
387
	}
392
    public String[] getFieldNames() {
393
        return fields;
394
    }
388 395

  
389
	public String[] getFieldNames() {
390
		return fields;
391
	}
396
    @Override
397
    public String[] getFieldLabels() {
398
        if (labels == null) {
399
            return new String[0];
400
        }
401
        return labels;
402
    }
392 403

  
393
	public String[] getFieldLabels() {
394
		if(labels==null)
395
			return new String[0];
396
		return labels;
397
	}
404
    @Override
405
    public void setFields(String[] fields) {
406
        this.fields = fields;
407
        updateSymbols();
408
    }
398 409

  
399
	public void setFields(String[] fields) {
400
		this.fields = fields;
401
		updateSymbols();
402
	}
410
    @Override
411
    public void setLabels(String[] fields) {
412
        this.labels = fields;
413
        updateSymbols();
414
    }
403 415

  
404
	public void setLabels(String[] fields) {
405
		this.labels = fields;
406
		updateSymbols();
407
	}
416
    @SuppressWarnings({"unchecked", "rawtypes"})
417
    @Override
418
    public void loadFromState(PersistentState state)
419
            throws PersistenceException {
420
        // Set parent properties
421
        super.loadFromState(state);
408 422

  
409
	@SuppressWarnings({ "unchecked", "rawtypes" })
410
	public void loadFromState(PersistentState state)
411
			throws PersistenceException {
412
		// Set parent properties
413
		super.loadFromState(state);
423
        this.fields = state.getStringArray(FIELD_NAMES);
424
        this.labels = state.getStringArray(FIELD_LABEL_NAMES);
425
        this.colors = (Color[]) state.getArray(FIELD_LABEL_COLOR, Color.class);
426
        // Set own properties
427
        this.backgroundSymbol = (ISymbol) state.get("backgroundSymbol");
428
        this.size = state.getInt("size");
429
        this.is3D = state.getBoolean("is3D");
414 430

  
415
		this.fields = state.getStringArray(FIELD_NAMES);
416
		this.labels = state.getStringArray(FIELD_LABEL_NAMES);
417
		this.colors = (Color[]) state.getArray(FIELD_LABEL_COLOR,Color.class);
418
		// Set own properties
419
		this.backgroundSymbol = (ISymbol) state.get("backgroundSymbol");
420
		this.size = state.getInt("size");
421
		this.is3D = state.getBoolean("is3D");
431
        this.isOutlineShow = state.getBoolean("isOutlineShow");
432
        this.onlySelection = state.getBoolean("onlySelection");
433
        this.isActiveLimits = state.getBoolean("isActiveLimits");
422 434

  
423
		this.isOutlineShow = state.getBoolean("isOutlineShow");
424
		this.onlySelection = state.getBoolean("onlySelection");
425
		this.isActiveLimits = state.getBoolean("isActiveLimits");
435
        this.outlineWidth = state.getInt("outlineWidth");
436
        this.referenceSystem = state.getInt("referenceSystem");
437
        this.sizeFrom = state.getInt("sizeFrom");
438
        this.sizeTo = state.getInt("sizeTo");
439
        this.unit = state.getInt("unit");
440
        this.sizeOption = state.getInt("sizeOption");
426 441

  
427
		this.outlineWidth = state.getInt("outlineWidth");
428
		this.referenceSystem = state.getInt("referenceSystem");
429
		this.sizeFrom = state.getInt("sizeFrom");
430
		this.sizeTo = state.getInt("sizeTo");
431
		this.unit = state.getInt("unit");
432
		this.sizeOption = state.getInt("sizeOption");
442
        this.outlineColor = (Color) state.get("outlineColor");
443
        this.symbol = (IChartSymbol) state.get("symbol");
444
        this.featSelection = (FeatureSelection) state.get("featSelection");
433 445

  
434
		this.outlineColor = (Color) state.get("outlineColor");
435
		this.symbol = (IChartSymbol) state.get("symbol");
436
		this.featSelection = (FeatureSelection) state.get("featSelection");
446
        this.fieldSize = state.getString("fieldSize");
447
        this.fieldNormalize = state.getString("fieldNormalize");
437 448

  
438
		this.fieldSize = state.getString("fieldSize");
439
		this.fieldNormalize = state.getString("fieldNormalize");
449
        this.minFeature = state.getDouble("minFeature");
450
        this.maxFeature = state.getDouble("maxFeature");
451
        this.maxField = state.getDouble("maxField");
452
    }
440 453

  
441
		this.minFeature = state.getDouble("minFeature");
442
		this.maxFeature = state.getDouble("maxFeature");
443
		this.maxField = state.getDouble("maxField");
444
	}
454
    @Override
455
    public void saveToState(PersistentState state) throws PersistenceException {
456
        // Save parent properties
457
        super.saveToState(state);
458
        // Save own properties
459
        state.set(FIELD_NAMES, this.fields);
460
        state.set(FIELD_LABEL_NAMES, this.labels);
461
        state.set(FIELD_LABEL_COLOR, this.colors);
445 462

  
446
	public void saveToState(PersistentState state) throws PersistenceException {
447
		// Save parent properties
448
		super.saveToState(state);
449
		// Save own properties
450
		state.set(FIELD_NAMES, this.fields);
451
		state.set(FIELD_LABEL_NAMES, this.labels);
452
		state.set(FIELD_LABEL_COLOR, this.colors);
463
        state.set("backgroundSymbol", this.backgroundSymbol);
464
        state.set("size", this.size);
465
        state.set("is3D", this.is3D);
453 466

  
454
		state.set("backgroundSymbol", this.backgroundSymbol);
455
		state.set("size", this.size);
456
		state.set("is3D", this.is3D);
467
        state.set("isOutlineShow", this.isOutlineShow);
468
        state.set("onlySelection", this.onlySelection);
469
        state.set("isActiveLimits", this.isActiveLimits);
457 470

  
458
		state.set("isOutlineShow", this.isOutlineShow);
459
		state.set("onlySelection", this.onlySelection);
460
		state.set("isActiveLimits", this.isActiveLimits);
471
        state.set("outlineWidth", this.outlineWidth);
472
        state.set("referenceSystem", this.referenceSystem);
473
        state.set("sizeFrom", this.sizeFrom);
474
        state.set("sizeTo", this.sizeTo);
475
        state.set("unit", this.unit);
476
        state.set("sizeOption", this.sizeOption);
461 477

  
462
		state.set("outlineWidth", this.outlineWidth);
463
		state.set("referenceSystem", this.referenceSystem);
464
		state.set("sizeFrom", this.sizeFrom);
465
		state.set("sizeTo", this.sizeTo);
466
		state.set("unit", this.unit);
467
		state.set("sizeOption", this.sizeOption);
478
        state.set("outlineColor", this.outlineColor);
479
        state.set("symbol", this.symbol);
480
        state.set("featSelection", this.featSelection);
468 481

  
469
		state.set("outlineColor", this.outlineColor);
470
		state.set("symbol", this.symbol);
471
		state.set("featSelection", this.featSelection);
482
        state.set("fieldSize", this.fieldSize);
483
        state.set("fieldNormalize", this.fieldNormalize);
472 484

  
473
		state.set("fieldSize", this.fieldSize);
474
		state.set("fieldNormalize", this.fieldNormalize);
485
        state.set("minFeature", this.minFeature);
486
        state.set("maxFeature", this.maxFeature);
487
        state.set("maxField", this.maxField);
475 488

  
476
		state.set("minFeature", this.minFeature);
477
		state.set("maxFeature", this.maxFeature);
478
		state.set("maxField", this.maxField);
489
    }
479 490

  
480
	}
491
    public static class RegisterPersistence implements Callable {
481 492

  
482
	public static class RegisterPersistence implements Callable {
493
        @Override
494
        public Object call() throws Exception {
495
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
496
            if (manager.getDefinition(BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
497
                DynStruct definition = manager.addDefinition(
498
                        BarsChartLegend.class,
499
                        BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME,
500
                        BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
501
                        null,
502
                        null
503
                );
504
                // Extend the Classified Vector Legend base definition
505
                definition.extend(manager.getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
483 506

  
484
		public Object call() throws Exception {
485
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
486
			if( manager.getDefinition(BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) {
487
				DynStruct definition = manager.addDefinition(
488
						BarsChartLegend.class,
489
						BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME,
490
						BARS_CHART_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
491
						null,
492
						null
493
				);
494
				// Extend the Classified Vector Legend base definition
495
				definition.extend(manager.getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
507
                // Field names
508
                definition.addDynFieldArray(FIELD_NAMES)
509
                        .setClassOfItems(String.class);
510
                definition.addDynFieldArray(FIELD_LABEL_NAMES)
511
                        .setClassOfItems(String.class);
512
                definition.addDynFieldArray(FIELD_LABEL_COLOR)
513
                        .setClassOfItems(Color.class);
496 514

  
497
				// Field names
498
				definition.addDynFieldArray(FIELD_NAMES)
499
				.setClassOfItems(String.class);
500
				definition.addDynFieldArray(FIELD_LABEL_NAMES)
501
					.setClassOfItems(String.class);
502
				definition.addDynFieldArray(FIELD_LABEL_COLOR)
503
				.setClassOfItems(Color.class);
515
                definition.addDynField("backgroundSymbol").setClassOfValue(ISymbol.class);
516
                definition.addDynFieldInt("size");
517
                definition.addDynFieldBoolean("is3D");
504 518

  
505
				definition.addDynField("backgroundSymbol").setClassOfValue(ISymbol.class);
506
				definition.addDynFieldInt("size");
507
				definition.addDynFieldBoolean("is3D");
519
                definition.addDynFieldBoolean("isOutlineShow");
520
                definition.addDynFieldBoolean("onlySelection");
521
                definition.addDynFieldBoolean("isActiveLimits");
508 522

  
509
				definition.addDynFieldBoolean("isOutlineShow");
510
				definition.addDynFieldBoolean("onlySelection");
511
				definition.addDynFieldBoolean("isActiveLimits");
523
                definition.addDynFieldInt("outlineWidth");
524
                definition.addDynFieldInt("referenceSystem");
525
                definition.addDynFieldInt("sizeFrom");
526
                definition.addDynFieldInt("sizeTo");
527
                definition.addDynFieldInt("unit");
528
                definition.addDynFieldInt("sizeOption");
512 529

  
513
				definition.addDynFieldInt("outlineWidth");
514
				definition.addDynFieldInt("referenceSystem");
515
				definition.addDynFieldInt("sizeFrom");
516
				definition.addDynFieldInt("sizeTo");
517
				definition.addDynFieldInt("unit");
518
				definition.addDynFieldInt("sizeOption");
530
                definition.addDynFieldObject("outlineColor").setClassOfValue(Color.class);
531
                definition.addDynFieldObject("symbol").setClassOfValue(IChartSymbol.class);
532
                definition.addDynFieldObject("featSelection").setClassOfValue(FeatureSelection.class);
519 533

  
520
				definition.addDynFieldObject("outlineColor").setClassOfValue(Color.class);
521
				definition.addDynFieldObject("symbol").setClassOfValue(IChartSymbol.class);
522
				definition.addDynFieldObject("featSelection").setClassOfValue(FeatureSelection.class);
534
                definition.addDynFieldString("fieldSize");
535
                definition.addDynFieldString("fieldNormalize");
523 536

  
524
				definition.addDynFieldString("fieldSize");
525
				definition.addDynFieldString("fieldNormalize");
537
                definition.addDynFieldDouble("minFeature");
538
                definition.addDynFieldDouble("maxFeature");
539
                definition.addDynFieldDouble("maxField");
540
            }
541
            return Boolean.TRUE;
542
        }
526 543

  
527
				definition.addDynFieldDouble("minFeature");
528
				definition.addDynFieldDouble("maxFeature");
529
				definition.addDynFieldDouble("maxField");
530
			}
531
			return Boolean.TRUE;
532
		}
544
    }
533 545

  
534
	}
535

  
536 546
    protected void updateSymbols() {
537 547
        ISymbol[] symbols = getSymbols();
538
        for (int i = 0; i < symbols.length; i++) {
539
            delSymbol(getSymbolKey(symbols[i]));
548
        for (ISymbol symbol1 : symbols) {
549
            delSymbol(getSymbolKey(symbol1));
540 550
        }
541 551
        if (fields != null && colors != null && labels != null) {
542 552

  
543 553
            if (fields.length != colors.length) {
544
                LOG.warn("The length of fields and colors isn't the same: fields.length = " + fields.length
545
                    + " colors.length = " + colors.length);
554
                LOGGER.warn("The length of fields and colors isn't the same: fields.length = " + fields.length
555
                        + " colors.length = " + colors.length);
546 556
            }
547 557

  
548 558
            if (fields.length != labels.length) {
549
                LOG.warn("The length of fields and labels isn't the same: fields.length = " + fields.length
550
                    + " labels.length = " + labels.length);
559
                LOGGER.warn("The length of fields and labels isn't the same: fields.length = " + fields.length
560
                        + " labels.length = " + labels.length);
551 561
            }
552 562

  
553 563
            for (int i = 0; i < Math.min(fields.length, Math.min(labels.length, colors.length)); i++) {
554
                ISimpleFillSymbol symbol = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
555
                symbol.setColor(colors[i]);
556
                symbol.setDescription(labels[i]);
557
                addSymbol(fields[i], symbol);
564
                ISimpleFillSymbol symbol1 = SymbologyLocator.getSymbologyManager().createSimpleFillSymbol();
565
                symbol1.setColor(colors[i]);
566
                symbol1.setDescription(labels[i]);
567
                addSymbol(fields[i], symbol1);
558 568
            }
559 569
        }
560 570
    }

Also available in: Unified diff