Statistics
| Revision:

root / org.gvsig.chart / trunk / org.gvsig.chart / org.gvsig.chart.lib / org.gvsig.chart.lib.impl / src / main / java / org / gvsig / chart / impl / overlay / OverlayChartProperties.java @ 569

History | View | Annotate | Download (17.1 KB)

1
package org.gvsig.chart.impl.overlay;
2

    
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.util.ArrayList;
6
import java.util.Iterator;
7
import java.util.List;
8

    
9
import org.gvsig.chart.ChartLocator;
10
import org.gvsig.chart.ChartService;
11
import org.gvsig.chart.GroupedChartsProperties;
12
import org.gvsig.chart.impl.AbstractChart;
13
import org.gvsig.chart.impl.AbstractChartProperties;
14
import org.gvsig.chart.renderer.ChartSerieEntity;
15
import org.gvsig.tools.ToolsLocator;
16
import org.gvsig.tools.dynobject.DynClass;
17
import org.gvsig.tools.dynobject.DynObjectManager;
18
import org.gvsig.tools.dynobject.DynStruct;
19
import org.gvsig.tools.persistence.PersistenceManager;
20
import org.gvsig.tools.persistence.PersistentState;
21
import org.gvsig.tools.persistence.exception.PersistenceException;
22
import org.gvsig.tools.util.Callable;
23

    
24
public class OverlayChartProperties extends AbstractChartProperties implements GroupedChartsProperties{
25
        
26
        List<ChartService> charts = new ArrayList<ChartService>();
27
        List<ChartSerieEntity> series = null;
28
        
29
        public OverlayChartProperties(){
30
                super("GroupedCharts");
31
                setChartType("GroupedCharts");
32
                setChartName("Gr?fico Compuesto.");
33
        }
34
        
35
        public static void registerDefinition(){
36
                DynObjectManager manager = ToolsLocator.getDynObjectManager();
37
                DynClass definition = manager.get("Chart","GroupedChartsProperties");
38
                if(definition == null){
39
                        definition = manager.createDynClass("Chart", "GroupedChartsProperties",
40
                                        "Gr?fico que est? compuesto de otros gr?ficos que se pintar?n unos sobre otros.");
41
                        
42
                        definition.addDynFieldList("charts").setClassOfItems(ChartService.class);
43
                        definition.addDynFieldList("series").setClassOfItems(ChartSerieEntity.class);;
44
                        
45
                        definition.addDynFieldString("MainTitle");
46
                        definition.addDynFieldBoolean("isMainTitleVisible").setMandatory(true).setDefaultFieldValue(true);
47
                        definition.addDynFieldObject("MainTitleFont").setClassOfValue(Font.class);
48
                        definition.addDynFieldObject("MainTitleFontColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.BLACK);
49
                        definition.addDynFieldObject("MainTitleBackgroundColor").setClassOfValue(Color.class);
50
                        
51
                        definition.addDynFieldObject("BackgroundColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.WHITE);
52
                        definition.addDynFieldBoolean("BackgroundTransparent").setDefaultFieldValue(false);
53
                        
54
                        definition.addDynFieldString("NoChartMessageText");
55
                        
56
                        definition.addDynFieldBoolean("isChartVisibleIfNoData").setMandatory(true).setDefaultFieldValue(true);
57

    
58
                        definition.addDynFieldString("NoDataMessageText");
59
                        definition.addDynFieldObject("NoDataMessageFont").setClassOfValue(Font.class);
60
                        definition.addDynFieldObject("NoDataMessageColor").setClassOfValue(Color.class);
61
                        definition.addDynFieldObject("NoDataMessageBackgroundColor").setClassOfValue(Color.class);
62

    
63
                        definition.addDynFieldInt("MainChartXPosition").setMandatory(true).setDefaultFieldValue(0);
64
                        definition.addDynFieldInt("MainChartYPosition").setMandatory(true).setDefaultFieldValue(0);
65
                        definition.addDynFieldInt("MainChartWidth").setMandatory(true).setDefaultFieldValue(0);
66
                        definition.addDynFieldInt("MainChartHeight").setMandatory(true).setDefaultFieldValue(0);
67
                        
68
                        //Legend
69
                        definition.addDynFieldBoolean("isMainLegendVisible").setMandatory(true).setDefaultFieldValue(true);
70
                        
71
                        definition.extend("Chart", "ChartProperties");
72
                        manager.add(definition);
73
                }
74
        }
75
        
76
//        public static void registerPersistentDefinition(){
77
//                PersistenceManager manager = ToolsLocator.getPersistenceManager();
78
//                DynStruct definition = manager.getDefinition("GroupedChartsProperties");
79
//                if(definition == null){
80
//                        definition = manager.addDefinition(
81
//                                        GroupedChartsProperties.class, 
82
//                                        "GroupedChartsProperties", 
83
//                                        "aqu? va la descripci?n", 
84
//                                        null, 
85
//                                        null);
86
//                        
87
//                        definition.addDynFieldArray("charts");
88
//                        definition.addDynFieldArray("series");
89
//                        
90
//                        definition.addDynFieldString("MainTitle");
91
//                        definition.addDynFieldBoolean("isMainTitleVisible").setMandatory(true).setDefaultFieldValue(true);
92
//                        definition.addDynFieldObject("MainTitleFont").setClassOfValue(Font.class);
93
//                        definition.addDynFieldObject("MainTitleFontColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.BLACK);
94
//                        definition.addDynFieldObject("MainTitleBackgroundColor").setClassOfValue(Color.class);
95
//
96
//                        definition.addDynFieldObject("BackgroundColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.WHITE);
97
//                        definition.addDynFieldBoolean("BackgroundTransparent").setDefaultFieldValue(false);
98
//
99
//                        definition.addDynFieldString("NoChartMessageText");
100
//                        
101
//                        definition.addDynFieldBoolean("isChartVisibleIfNoData").setMandatory(true).setDefaultFieldValue(true);
102
//
103
//                        definition.addDynFieldString("NoDataMessageText");
104
//                        definition.addDynFieldObject("NoDataMessageFont").setClassOfValue(Font.class);
105
//                        definition.addDynFieldObject("NoDataMessageColor").setClassOfValue(Color.class);
106
//                        definition.addDynFieldObject("NoDataMessageBackgroundColor").setClassOfValue(Color.class);
107
//
108
//                        definition.addDynFieldInt("MainChartXPosition").setMandatory(true).setDefaultFieldValue(0);
109
//                        definition.addDynFieldInt("MainChartYPosition").setMandatory(true).setDefaultFieldValue(0);
110
//                        definition.addDynFieldInt("MainChartWidth").setMandatory(true).setDefaultFieldValue(0);
111
//                        definition.addDynFieldInt("MainChartHeight").setMandatory(true).setDefaultFieldValue(0);
112
//                        
113
//                        //Legend
114
//                        definition.addDynFieldBoolean("isMainLegendVisible").setMandatory(true).setDefaultFieldValue(true);
115
//                        
116
//                        definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE,"ChartProperties");
117
//                }
118
//        }
119
                
120
        public List getCharts() {
121
                return  this.charts;
122
        }
123

    
124
        public void setCharts(List charts) {
125
                data.setDynValue("charts", charts);
126
                List<ChartService> services = new ArrayList<ChartService>();
127
                Iterator<ChartService> it = charts.iterator();
128
                while(it.hasNext()){
129
                        ChartService cs = (ChartService)it.next();
130
                        services.add(cs);
131
                }
132
                this.setChartServices(services);
133
        }
134
        
135
        public String getMainTitle() {
136
                return  (String) data.getDynValue("MainTitle");
137
        }
138

    
139
        public void setMainTitle(String charts) {
140
                data.setDynValue("MainTitle", charts);
141
        }
142
        
143
        public boolean isMainTitleVisible() {
144
                return  (Boolean) data.getDynValue("isMainTitleVisible");
145
        }
146

    
147
        public void setMainTitleVisibility(boolean charts) {
148
                data.setDynValue("isMainTitleVisible", charts);
149
        }
150
        
151
        public Font getMainTitleFont() {
152
                return  (Font) data.getDynValue("MainTitleFont");
153
        }
154

    
155
        public void setMainTitleFont(Font charts) {
156
                data.setDynValue("MainTitleFont", charts);
157
        }
158
        
159
        public Color getMainTitleFontColor(){
160
                return (Color) data.getDynValue("MainTitleFontColor");
161
        }
162
        
163
        public void setMainTitleFontColor(Color newColor) {
164
                data.setDynValue("MainTitleFontColor", newColor);
165
        }
166

    
167
        public Color getNoDataMessageBackgroundColor() {
168
                return (Color) data.getDynValue("NoDataMessageBackgroundColor");
169
        }
170

    
171
        public void setNoDataMessageBackgroundColor(Color newColor) {
172
                data.setDynValue("NoDataMessageBackgroundColor", newColor);
173
        }
174
        
175
        
176
        public String getNoDataMessageText() {
177
                return  (String) data.getDynValue("NoDataMessageText");
178
        }
179

    
180
        public void setNoDataMessageText(String text) {
181
                data.setDynValue("NoDataMessageText", text);
182
        }
183
        
184
        public String getNoChartMessageText() {
185
                return  (String) data.getDynValue("NoChartMessageText");
186
        }
187

    
188
        public void setNoChartMessageText(String text) {
189
                data.setDynValue("NoChartMessageText", text);
190
        }
191
        
192
        public boolean isChartVisibleIfNoData() {
193
                return  (Boolean) data.getDynValue("isChartVisibleIfNoData");
194
        }
195

    
196
        public void setIsChartVisibleIfNoData(boolean charts) {
197
                data.setDynValue("isChartVisibleIfNoData", charts);
198
        }
199
        
200
        public Font getNoDataMessageFont() {
201
                return  (Font) data.getDynValue("NoDataMessageFont");
202
        }
203

    
204
        public void setNoDataMessageFont(Font charts) {
205
                data.setDynValue("NoDataMessageFont", charts);
206
        }
207
        
208
        public Color getNoDataMessageColor(){
209
                return (Color) data.getDynValue("NoDataMessageColor");
210
        }
211
        
212
        public void setNoDataMessageColor(Color newColor) {
213
                data.setDynValue("NoDataMessageColor", newColor);
214
        }
215

    
216
        public Color getMainTitleBackgroundColor() {
217
                return (Color) data.getDynValue("MainTitleBackgroundColor");
218
        }
219

    
220
        public void setMainTitleBackgroundColor(Color newColor) {
221
                data.setDynValue("MainTitleBackgroundColor", newColor);
222
        }
223
        
224
        public Color getMainBackgroundColor() {
225
                return (Color) data.getDynValue("BackgroundColor");
226
        }
227

    
228
        public void setMainBackgroundColor(Color newColor) {
229
                data.setDynValue("BackgroundColor", newColor);
230
        }
231
        
232
        public boolean getMainBackgroundTransparency() {
233
                return (Boolean) data.getDynValue("BackgroundTransparent");
234
        }
235

    
236
        public void setMainBackgroundTransparency(boolean newColor) {
237
                data.setDynValue("BackgroundTransparent", newColor);
238
        }
239
        
240
        public int getMainChartXPosition() {
241
                return (Integer) data.getDynValue("MainChartXPosition");
242
        }
243
        
244
        public void setMainChartXPosition(int table) {
245
                data.setDynValue("MainChartXPosition", table);
246
        }
247
        
248
        public int getMainChartYPosition() {
249
                return (Integer) data.getDynValue("MainChartYPosition");
250
        }
251
        
252
        public void setMainChartYPosition(int table) {
253
                data.setDynValue("MainChartYPosition", table);
254
        }
255
        
256
        public int getMainChartWidth() {
257
                return (Integer) data.getDynValue("MainChartWidth");
258
        }
259
        
260
        public void setMainChartWidth(int table) {
261
                data.setDynValue("MainChartWidth", table);
262
        }
263
        
264
        public int getMainChartHeight() {
265
                return (Integer) data.getDynValue("MainChartHeight");
266
        }
267
        
268
        public void setMainChartHeight(int table) {
269
                data.setDynValue("MainChartHeight", table);
270
        }
271
        
272
        
273
        public void saveToState(PersistentState state) throws PersistenceException {
274
                // Save parent properties
275
                super.saveToState(state);
276
                // Save own properties
277
                state.set("charts", this.getCharts());
278
                
279
                state.set("MainTitle", this.getMainTitle());
280
                state.set("isMainTitleVisible", this.isMainTitleVisible());
281
                state.set("MainTitleFont", this.getMainTitleFont());
282
                state.set("MainTitleFontColor", this.getMainTitleFontColor());
283
                state.set("MainTitleBackgroundColor", this.getMainTitleBackgroundColor());
284
                
285
                state.set("BackgroundColor", this.getMainBackgroundColor());
286
                state.set("BackgroundTransparent", this.getMainBackgroundTransparency());
287

    
288
                state.set("isChartVisibleIfNoData", this.isChartVisibleIfNoData());
289
                
290
                state.set("NoChartMessageText", this.getNoChartMessageText());
291
                
292
                state.set("NoDataMessageText", this.getNoDataMessageText());
293
                state.set("NoDataMessageFont", this.getNoDataMessageFont());
294
                state.set("NoDataMessageColor", this.getNoDataMessageColor());
295
                state.set("NoDataMessageBackgroundColor", this.getNoDataMessageBackgroundColor());
296
                
297
                state.set("MainChartXPosition", this.getMainChartXPosition());
298
                state.set("MainChartYPosition", this.getMainChartYPosition());
299
                state.set("MainChartWidth", this.getMainChartWidth());
300
                state.set("MainChartHeight", this.getMainChartHeight());
301
                
302
                state.set("LegendOrientation", this.getLegendOrientation());
303
                state.set("LegendPosition", this.getLegendPosition());
304
                
305
                state.set("isMainLegendVisible", this.getIsLegendVisible());
306
        }
307

    
308

    
309
        public void loadFromState(PersistentState state)
310
                        throws PersistenceException {
311
                // Set parent properties
312
                super.loadFromState(state);
313
                // Set own properties
314
                this.setCharts(state.getList("charts"));
315
                
316
                this.setMainTitle(state.getString("MainTitle"));
317
                this.setMainTitleVisibility(state.getBoolean("isMainTitleVisible"));
318
                this.setMainTitleFont((Font)state.get("MainTitleFont"));
319
                this.setMainTitleFontColor((Color)(state.get("MainTitleFontColor")));
320
                this.setMainTitleBackgroundColor((Color)(state.get("MainTitleBackgroundColor")));
321
                
322
                this.setMainBackgroundColor((Color)(state.get("BackgroundColor")));
323
                this.setMainBackgroundTransparency(state.getBoolean("BackgroundTransparent"));
324
                
325
                this.setIsChartVisibleIfNoData(state.getBoolean("isChartVisibleIfNoData"));
326
                
327
                this.setNoChartMessageText(state.getString("NoChartMessageText"));
328

    
329
                this.setNoDataMessageText(state.getString("NoDataMessageText"));
330
                this.setNoDataMessageFont((Font)state.get("NoDataMessageFont"));
331
                this.setNoDataMessageColor((Color)state.get("NoDataMessageColor"));
332
                this.setNoDataMessageBackgroundColor((Color)state.get("NoDataMessageBackgroundColor"));
333
                
334
                this.setMainChartXPosition(state.getInt("MainChartXPosition"));
335
                this.setMainChartYPosition(state.getInt("MainChartYPosition"));
336
                this.setMainChartWidth(state.getInt("MainChartWidth"));
337
                this.setMainChartHeight(state.getInt("MainChartHeight"));
338
                
339
                this.setLegendOrientation(state.getString("LegendOrientation"));
340
                this.setLegendPosition(state.getString("LegendPosition"));
341
                
342
                this.setIsLegendVisible(state.getBoolean("isMainLegendVisible"));
343
        }
344
        
345
        public GroupedChartsProperties clone(){
346
                OverlayChartProperties ovProps = 
347
                        (OverlayChartProperties) ChartLocator.getServiceManager().getChartManager().createGroupedCharts().getGroupedChartsProperties();
348
                
349
                ovProps.setMainBackgroundColor(this.getMainBackgroundColor());
350
                ovProps.setMainBackgroundTransparency(this.getMainBackgroundTransparency());
351
                
352
                ovProps.setMainChartXPosition(this.getMainChartXPosition());
353
                ovProps.setMainChartYPosition(this.getMainChartYPosition());
354
                ovProps.setMainChartWidth(this.getMainChartWidth());
355
                ovProps.setMainChartHeight(this.getMainChartHeight());
356
                
357
                ovProps.setHasLegendCoordinates(this.getHasLegendCoordinates());
358
                ovProps.setLegendOrientation(this.getLegendOrientation());
359
                ovProps.setLegendPosition(this.getLegendPosition());
360
                ovProps.setLegendXCoordinate(this.getLegendXCoordinate());
361
                ovProps.setLegendYCoordinate(this.getLegendYCoordinate());
362
                ovProps.setLegendTitleText(this.getLegendTitleText());
363
                ovProps.setLegendTitleFont(this.getLegendTitleFont());
364
                ovProps.setLegendTitleIsVisible(this.getLegendTitleIsVisible());
365
                
366
                ovProps.setMainTitle(this.getMainTitle());
367
                ovProps.setMainTitleVisibility(this.isMainTitleVisible());
368
                ovProps.setMainTitleFont(this.getMainTitleFont());
369
                ovProps.setMainTitleFontColor(this.getMainTitleFontColor());
370
                ovProps.setMainTitleBackgroundColor(this.getMainTitleBackgroundColor());
371
                
372
                List services = new ArrayList();
373
                Iterator<ChartService> it = this.getChartServices().iterator();
374
                while(it.hasNext()){
375
                        ChartService cs = (ChartService)it.next();
376
                        services.add(cs.clone());
377
                }
378
                ovProps.setChartServices(services);
379
                
380
                List<ChartSerieEntity> colors = new ArrayList<ChartSerieEntity>();
381
                Iterator<ChartSerieEntity> it2 = this.getSeries().iterator();
382
                while(it2.hasNext()){
383
                        ChartSerieEntity cs = (ChartSerieEntity)it2.next();
384
                        colors.add(cs.clone());
385
                }
386
                ovProps.setSeries(colors);
387
                
388
                return ovProps;
389
        }
390

    
391
        public List getChartServices() {
392
                return this.charts;
393
        }
394

    
395
        public void setChartServices(List<ChartService> chartServ) {
396
                this.charts = chartServ;
397
        }
398

    
399
        public List<ChartSerieEntity> getSeries() {
400
                this.series = (List<ChartSerieEntity>) data.getDynValue("series");
401
                if(this.series == null){
402
                        this.series = new ArrayList<ChartSerieEntity>();
403
                        setSeries(this.series);
404
                }
405
                return this.series;
406
        }
407

    
408
        public void setSeries(List<ChartSerieEntity> colors) {
409
                data.setDynValue("series", colors);
410
        }
411

    
412
        public static class RegisterPersistence implements Callable {
413

    
414
                public Object call() throws Exception {
415
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
416
                        if(manager.getDefinition("GroupedChartsProperties")==null ) {
417
                                DynStruct definition = manager.addDefinition(
418
                                                OverlayChartProperties.class,
419
                                                "GroupedChartsProperties",
420
                                                "GroupedChartsProperties"+" Persistence definition (FIXME check keys type)",
421
                                                null, 
422
                                                null
423
                                );
424
//                                // Extend the Classified Vector Legend base definition
425
                                definition.extend(manager.getDefinition("ChartProperties"));
426
                                
427
                                // Values
428
                                definition.addDynFieldList("charts").setClassOfItems(ChartService.class);
429
                                definition.addDynFieldArray("series").setClassOfItems(ChartSerieEntity.class);
430
                                
431
                                definition.addDynFieldString("MainTitle");
432
                                definition.addDynFieldBoolean("isMainTitleVisible").setDefaultFieldValue(true);
433
                                definition.addDynFieldObject("MainTitleFont").setClassOfValue(Font.class);
434
                                definition.addDynFieldObject("MainTitleFontColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.BLACK);
435
                                definition.addDynFieldObject("MainTitleBackgroundColor").setClassOfValue(Color.class);
436

    
437
                                definition.addDynFieldObject("BackgroundColor").setClassOfValue(Color.class).setDefaultFieldValue(Color.WHITE);
438
                                definition.addDynFieldBoolean("BackgroundTransparent").setDefaultFieldValue(false);
439

    
440
                                definition.addDynFieldString("NoChartMessageText");
441
                                
442
                                definition.addDynFieldBoolean("isChartVisibleIfNoData").setDefaultFieldValue(true);
443

    
444
                                definition.addDynFieldString("NoDataMessageText");
445
                                definition.addDynFieldObject("NoDataMessageFont").setClassOfValue(Font.class);
446
                                definition.addDynFieldObject("NoDataMessageColor").setClassOfValue(Color.class);
447
                                definition.addDynFieldObject("NoDataMessageBackgroundColor").setClassOfValue(Color.class);
448

    
449
                                definition.addDynFieldInt("MainChartXPosition").setDefaultFieldValue(0);
450
                                definition.addDynFieldInt("MainChartYPosition").setDefaultFieldValue(0);
451
                                definition.addDynFieldInt("MainChartWidth").setDefaultFieldValue(0);
452
                                definition.addDynFieldInt("MainChartHeight").setDefaultFieldValue(0);
453
                                
454
                                //Legend
455
                                definition.addDynFieldBoolean("isMainLegendVisible").setDefaultFieldValue(true);
456
                                
457
                        }
458
                        return Boolean.TRUE;
459
                }
460
                
461
        }
462

    
463
}