Revision 820

View differences:

org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.chart.lib.impl</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.chart.lib.impl</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.chart.lib</artifactId>
10
		<version>1.0.151</version>
11
	</parent>
12

  
13
	<dependencies>
14
		<dependency>
15
			<groupId>org.gvsig</groupId>
16
			<artifactId>org.gvsig.chart.lib.api</artifactId>
17
			<scope>compile</scope>
18
		</dependency>
19
		<dependency>
20
			<groupId>org.jfree</groupId>
21
			<artifactId>jfreechart</artifactId>
22
		</dependency>
23
		 <dependency>
24
		   <groupId>com.itextpdf</groupId>
25
		   <artifactId>itextpdf</artifactId>
26
		   <type>jar</type>
27
		 </dependency>
28
		 <dependency>
29
		   <groupId>com.itextpdf.tool</groupId>
30
		   <artifactId>xmlworker</artifactId>
31
		   <type>jar</type>
32
		 </dependency>
33
		<dependency>
34
			<groupId>org.gvsig</groupId>
35
			<artifactId>org.gvsig.fmap.control</artifactId>
36
			<scope>compile</scope>
37
		</dependency>
38
		<dependency>
39
			<groupId>org.gvsig</groupId>
40
			<artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
41
			<scope>compile</scope>
42
		</dependency>
43
		<dependency>
44
			<groupId>org.gvsig</groupId>
45
			<artifactId>org.gvsig.fmap.geometry.api</artifactId>
46
			<scope>compile</scope>
47
		</dependency>
48
		<dependency>
49
			<groupId>org.gvsig</groupId>
50
			<artifactId>org.gvsig.fmap.dal.api</artifactId>
51
			<scope>compile</scope>
52
		</dependency>
53
		<dependency>
54
			<groupId>org.gvsig</groupId>
55
			<artifactId>org.gvsig.compat.api</artifactId>
56
            <scope>compile</scope>
57
		</dependency>		
58
		<dependency>
59
			<groupId>org.gvsig</groupId>
60
			<artifactId>org.gvsig.symbology.lib.api</artifactId>
61
			<scope>compile</scope>
62
		</dependency>
63
		<dependency>
64
			<groupId>org.gvsig</groupId>
65
			<artifactId>org.gvsig.symbology.lib.impl</artifactId>
66
			<scope>compile</scope>
67
		</dependency>	
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.projection.api</artifactId>  
71
            <scope>compile</scope>      
72
        </dependency>
73
		<dependency>
74
            <groupId>org.gvsig</groupId>
75
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>  
76
            <scope>compile</scope>      
77
        </dependency>  
78
	</dependencies>
79
</project>
0 80

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.chart">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="DEBUG" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/test/java/org/gvsig/chart/impl/TestChartDataSet.java
1
package org.gvsig.chart.impl;
2

  
3
import java.util.Arrays;
4
import java.util.Iterator;
5
import java.util.List;
6

  
7
import junit.framework.TestCase;
8

  
9
import org.gvsig.chart.impl.model.DefaultChartDataSet;
10
import org.gvsig.chart.model.ChartDataSet;
11

  
12

  
13
public class TestChartDataSet extends TestCase {
14
	
15
	public void testAddData() {
16
		ChartDataSet dataSet = new DefaultChartDataSet();
17
		
18
		String[] test = {"uno", "dos", "tres"};
19
		
20
		List t = Arrays.asList(test);
21
		
22
		dataSet.addData("test", t.iterator());
23
		
24
		Iterator<Object> it = dataSet.getValues("test");
25
		
26
		while (it.hasNext()) {
27
			System.out.println(it.next());
28
		}
29

  
30
		it = dataSet.getValues("test");
31
		
32
		while (it.hasNext()) {
33
			System.out.println("Segunda pasada:" + it.next());
34
		}
35

  
36
	}
37

  
38
}
0 39

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/test/java/org/gvsig/chart/impl/DefaultChartManagerTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.chart.impl;
23

  
24
import junit.framework.TestCase;
25

  
26
import org.gvsig.chart.ChartManager;
27

  
28
/**
29
 * {@link ChartManager} API compatibility tests for the
30
 * {@link DefaultChartManager} implementation.
31
 * 
32
 * @author gvSIG Team
33
 * @version $Id$
34
 */
35
public class DefaultChartManagerTest extends TestCase {
36

  
37
    // Nothing to add
38
}
0 39

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/DefaultChartManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.chart.impl;
23

  
24
import org.gvsig.chart.ChartLocator;
25
import org.gvsig.chart.ChartManager;
26
import org.gvsig.chart.ChartProperties;
27
import org.gvsig.chart.ChartService;
28
import org.gvsig.chart.GroupedCharts;
29
import org.gvsig.chart.impl.model.DefaultChartDataSet;
30
import org.gvsig.chart.lib.spi.ChartServiceManager;
31
import org.gvsig.chart.model.ChartDataSet;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DynObject;
34
import org.gvsig.tools.i18n.I18nManager;
35
import org.gvsig.tools.service.AbstractMultiServiceImplManager;
36
import org.gvsig.tools.service.Service;
37
import org.gvsig.tools.service.ServiceException;
38

  
39
/**
40
 * Default {@link ChartManager} implementation.
41
 * 
42
 * @author gvSIG Team
43
 * @version $Id$
44
 */
45
public class DefaultChartManager extends AbstractMultiServiceImplManager implements ChartManager {
46

  
47

  
48
	private I18nManager i18nmanager;
49

  
50
	public DefaultChartManager() {
51
		super(ChartLocator.getServiceManager());
52
		this.i18nmanager = ToolsLocator.getI18nManager();
53
		ChartLocator.getServiceManager().setChartManager(this);
54
	}
55

  
56
	public Service getService(DynObject parameters) throws ServiceException {
57
		return this.getServiceManager().createService(parameters);
58
	}
59

  
60
	public ChartProperties createProperties(String type) throws ServiceException {
61
		DynObject params = this.getServiceManager().createServiceParameters(type+"Properties");
62
		params.setDynValue("type", type);
63
		return (ChartProperties) params;
64
	}
65

  
66
	public ChartService createChart(ChartProperties properties) throws ServiceException {
67
		ChartService service = (ChartService)this.getService(properties);
68
		service.setChartDataSet(this.createChartDataSet());
69
		return service;
70
	}
71

  
72
	public ChartServiceManager getChartServiceManager() {
73
		return (ChartServiceManager)this.getServiceManager();
74
	}
75

  
76
	public GroupedCharts createGroupedCharts() {
77
		ChartProperties props;
78
		ChartService service;
79
		try {
80
			props = createProperties("GroupedCharts");
81
			service = createChart(props);
82
			if(service instanceof GroupedCharts){
83
				return (GroupedCharts)service;
84
			}
85
		} catch (ServiceException e) {
86
			// TODO Auto-generated catch block
87
			e.printStackTrace();
88
		}
89
		return null;
90
	}
91

  
92
	public ChartDataSet createChartDataSet() {
93
		return new DefaultChartDataSet();
94
	}
95
	
96
    public String getTranslation(String key) {
97
        return this.i18nmanager.getTranslation(key);
98
    }
99

  
100
}
0 101

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/FeatureDataSet.java
1
package org.gvsig.chart.impl;
2

  
3
public class FeatureDataSet {
4

  
5
}
0 6

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/items/DefaultChartLegendItem.java
1
package org.gvsig.chart.impl.items;
2

  
3
import java.awt.Font;
4
import java.awt.Graphics2D;
5
import java.awt.Paint;
6
import java.awt.geom.Rectangle2D;
7

  
8
import org.gvsig.chart.ChartLocator;
9
import org.gvsig.chart.ChartManager;
10
import org.gvsig.chart.items.ChartLegendItem;
11
import org.gvsig.tools.ToolsLocator;
12
import org.gvsig.tools.dynobject.DynStruct;
13
import org.gvsig.tools.persistence.PersistenceManager;
14
import org.gvsig.tools.persistence.PersistentState;
15
import org.gvsig.tools.persistence.exception.PersistenceException;
16
import org.gvsig.tools.util.Callable;
17
import org.jfree.chart.block.BlockBorder;
18
import org.jfree.chart.title.LegendTitle;
19
import org.jfree.ui.HorizontalAlignment;
20
import org.jfree.ui.RectangleEdge;
21
import org.jfree.ui.VerticalAlignment;
22

  
23
public class DefaultChartLegendItem implements ChartLegendItem{
24
	
25
	public LegendTitle legend;
26
	private int x;
27
	private int y;
28
	private String horizontal;
29
	private String vertical;
30
	
31
	public DefaultChartLegendItem(){
32
		this.legend = null;
33
		this.horizontal = null;
34
		this.vertical = null;
35
		this.x = 0;
36
		this.y = 0;
37
	}
38
	
39
	public DefaultChartLegendItem(LegendTitle legendTitle){
40
		this.legend = legendTitle;
41
		if(legend.getBounds()!=null){
42
			this.x = ((Double)legend.getBounds().getX()).intValue();
43
			this.y = ((Double)legend.getBounds().getY()).intValue();
44
		}
45
	}
46

  
47
	public Object getLegendItem(){
48
		return legend;
49
	}
50
	
51
	public void setLegendItem(Object leg){
52
		if(leg instanceof LegendTitle)
53
			this.legend = (LegendTitle) leg;
54
	}
55

  
56
	public Paint getBackground() {
57
		return legend.getBackgroundPaint();
58
	}
59

  
60
	public void setBackground(Paint paint) {
61
		legend.setBackgroundPaint(paint);
62
	}
63

  
64
	public void draw(Graphics2D g2, Rectangle2D area) {
65
		if(horizontal == null && vertical == null){
66
			area.setRect(getXPosition(), getYPosition(), legend.getWidth(), legend.getHeight());
67
			legend.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));
68
			legend.draw(g2, area);
69
		}else{
70
			this.setPosition(horizontal, vertical);
71
		}
72
	}
73

  
74
	public Font getItemFont() {
75
		return legend.getItemFont();
76
	}
77

  
78
	public boolean isVisible() {
79
		return legend.isVisible();
80
	}
81

  
82
	public void setVisible(boolean isVisible) {
83
		legend.setVisible(isVisible);
84
	}
85

  
86
	public int getXPosition() {
87
		return this.x;
88
	}
89
	
90
	public int getYPosition() {
91
		return this.y;
92
	}
93
	
94
	public void setPosition(int x, int y){
95
		this.horizontal = null;
96
		this.vertical = null;
97
		this.x = x;
98
		this.y = y;
99
	}
100
	
101
	public void setPosition(String vertical, String horizontal){
102
		this.horizontal = horizontal;
103
		this.vertical = vertical;
104
		ChartManager swingManager = ChartLocator.getServiceManager().getChartManager();
105
		
106
		if(vertical == swingManager.getTranslation("LEFT")){
107
			legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
108
		}
109
		if(vertical == swingManager.getTranslation("RIGHT")){
110
			legend.setHorizontalAlignment(HorizontalAlignment.RIGHT);
111
		}
112
		if(vertical == swingManager.getTranslation("CENTER")){
113
			if(horizontal == swingManager.getTranslation("TOP")||
114
					horizontal == swingManager.getTranslation("BOTTOM"))
115
				legend.setHorizontalAlignment(HorizontalAlignment.CENTER);
116
			if(horizontal == swingManager.getTranslation("LEFT") ||
117
					horizontal == swingManager.getTranslation("RIGHT"))
118
				legend.setVerticalAlignment(VerticalAlignment.CENTER);
119
		}
120
		if(vertical == swingManager.getTranslation("TOP")){
121
			legend.setVerticalAlignment(VerticalAlignment.TOP);
122
		}
123
		if(vertical == swingManager.getTranslation("BOTTOM")){
124
			legend.setVerticalAlignment(VerticalAlignment.BOTTOM);
125
		}
126
		if(horizontal == swingManager.getTranslation("TOP")){
127
			legend.setPosition(RectangleEdge.TOP);
128
		}
129
		if(horizontal == swingManager.getTranslation("BOTTOM")){
130
			legend.setPosition(RectangleEdge.BOTTOM);
131
		}
132
		if(horizontal == swingManager.getTranslation("LEFT")){
133
			legend.setPosition(RectangleEdge.LEFT);
134
		}
135
		if(horizontal == swingManager.getTranslation("RIGHT")){
136
		
137
			
138
			legend.setPosition(RectangleEdge.RIGHT);
139
		}
140
	}
141

  
142
	
143
	public void saveToState(PersistentState state) throws PersistenceException {
144
		//state.set("LegendItem", this.getLegendItem());
145
		state.set("XCoordinate", this.x);
146
		state.set("YCoordinate", this.y);
147
		state.set("Horizontal", this.horizontal);
148
		state.set("Vertical", this.vertical);
149
	}
150

  
151
	public void loadFromState(PersistentState state)
152
			throws PersistenceException {
153
		//this.setLegendItem(state.get("LegendItem"));
154
		this.setXCoordinate(state.getInt("XCoordinate"));
155
		this.setYCoordinate(state.getInt("YCoordinate"));
156
		this.setHorizontal(state.getString("Horizontal"));
157
		this.setVertical(state.getString("Vertical"));
158
	}
159
	
160
	
161
	
162
	private void setVertical(String string) {
163
		this.vertical = string;
164
	}
165

  
166
	private void setHorizontal(String string) {
167
		this.horizontal = string;
168
	}
169

  
170
	private void setYCoordinate(int double1) {
171
		this.y = double1;
172
	}
173

  
174
	private void setXCoordinate(int double1) {
175
		this.x = double1;
176
	}
177

  
178

  
179

  
180
	public static class RegisterPersistence implements Callable {
181

  
182
		public Object call() throws Exception {
183
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
184
			if(manager.getDefinition("ChartLegendItem")==null ) {
185
				DynStruct definition = manager.addDefinition(
186
						DefaultChartLegendItem.class,
187
						"ChartLegendItem",
188
						"ChartLegendItem"+" Persistence definition (FIXME check keys type)",
189
						null, 
190
						null
191
				);
192
				// Values
193
				definition.addDynFieldInt("XCoordinate");
194
				definition.addDynFieldInt("YCoordinate");
195
				definition.addDynFieldString("Horizontal");
196
				definition.addDynFieldString("Vertical");
197
				
198
				//definition.addDynFieldObject("LegendItem").setClassOfValue(LegendTitle.class);
199
			}
200
			return Boolean.TRUE;
201
		}
202
		
203
	}
204

  
205

  
206
}
0 207

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/overlay/OverlayChartFactory.java
1
package org.gvsig.chart.impl.overlay;
2

  
3
import org.gvsig.chart.lib.spi.AbstractChartFactory;
4
import org.gvsig.tools.ToolsLocator;
5
import org.gvsig.tools.dynobject.DynClass;
6
import org.gvsig.tools.dynobject.DynObject;
7
import org.gvsig.tools.dynobject.DynObjectManager;
8
import org.gvsig.tools.service.Service;
9
import org.gvsig.tools.service.ServiceException;
10
import org.gvsig.tools.service.spi.ServiceManager;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

  
14
public class OverlayChartFactory extends AbstractChartFactory {
15
	
16
	private static Logger logger = LoggerFactory.getLogger(OverlayChartFactory.class);
17
	public void initialize() {
18
	}
19

  
20
	@Override
21
	protected Service doCreate(DynObject parameters,
22
			ServiceManager serviceManager) throws ServiceException {
23
		
24
		return new OverlayChart(
25
				(OverlayChartProperties) parameters
26
				);
27
	}
28

  
29
	@Override
30
	protected DynClass createParametersDynClass() {
31
		DynObjectManager manager = ToolsLocator.getDynObjectManager();
32
		DynClass definition = manager.get("Chart","GroupedChartsProperties");
33
		if( definition==null ) {
34
			logger.info("Can't access to ChartProperties definition of OverlayChart");
35
		}
36
		return definition;
37
	}
38
	
39
	@Override
40
	public DynObject createParameters() {
41
		return new OverlayChartProperties();
42
	}
43
	
44
}
0 45

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/overlay/OverlayChartProperties.java
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
}
0 464

  
org.gvsig.chart/tags/org.gvsig.chart-1.0.151/org.gvsig.chart.lib/org.gvsig.chart.lib.impl/src/main/java/org/gvsig/chart/impl/overlay/OverlayChart.java
1
package org.gvsig.chart.impl.overlay;
2

  
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.Graphics2D;
6
import java.awt.Paint;
7
import java.awt.Rectangle;
8
import java.awt.geom.Rectangle2D;
9
import java.awt.image.BufferedImage;
10
import java.io.File;
11
import java.io.FileOutputStream;
12
import java.io.IOException;
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16

  
17
import javax.imageio.ImageIO;
18

  
19
import org.gvsig.chart.ChartLocator;
20
import org.gvsig.chart.ChartProperties;
21
import org.gvsig.chart.ChartService;
22
import org.gvsig.chart.GroupedCharts;
23
import org.gvsig.chart.GroupedChartsProperties;
24
import org.gvsig.chart.axis.CategoryAxis;
25
import org.gvsig.chart.axis.ChartAxis;
26
import org.gvsig.chart.axis.ValueAxis;
27
import org.gvsig.chart.impl.AbstractChart;
28
import org.gvsig.chart.impl.axis.ChartNumberAxis;
29
import org.gvsig.chart.impl.renderer.DefaultChartRenderer;
30
import org.gvsig.chart.impl.renderer.DefaultChartSerieEntity;
31
import org.gvsig.chart.model.ChartDataSet;
32
import org.gvsig.chart.renderer.ChartRenderer;
33
import org.gvsig.chart.renderer.ChartSerieEntity;
34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.tools.ToolsLocator;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.observer.Observable;
38
import org.gvsig.tools.observer.Observer;
39
import org.gvsig.tools.persistence.PersistenceManager;
40
import org.gvsig.tools.persistence.PersistentState;
41
import org.gvsig.tools.persistence.exception.PersistenceException;
42
import org.gvsig.tools.service.Manager;
43
import org.gvsig.tools.service.spi.ProviderManager;
44
import org.gvsig.tools.util.Callable;
45
import org.jfree.chart.JFreeChart;
46
import org.jfree.chart.LegendItemCollection;
47
import org.jfree.chart.LegendItemSource;
48
import org.jfree.chart.block.BlockBorder;
49
import org.jfree.chart.block.BlockContainer;
50
import org.jfree.chart.block.BorderArrangement;
51
import org.jfree.chart.block.LabelBlock;
52
import org.jfree.chart.plot.CategoryPlot;
53
import org.jfree.chart.plot.Plot;
54
import org.jfree.chart.plot.XYPlot;
55
import org.jfree.chart.renderer.AbstractRenderer;
56
import org.jfree.chart.title.LegendTitle;
57
import org.jfree.chart.title.TextTitle;
58
import org.jfree.chart.title.Title;
59
import org.jfree.ui.RectangleEdge;
60
import org.slf4j.Logger;
61
import org.slf4j.LoggerFactory;
62

  
63
import com.lowagie.text.Document;
64
import com.lowagie.text.PageSize;
65
import com.lowagie.text.pdf.DefaultFontMapper;
66
import com.lowagie.text.pdf.PdfContentByte;
67
import com.lowagie.text.pdf.PdfTemplate;
68
import com.lowagie.text.pdf.PdfWriter;
69

  
70
public class OverlayChart extends AbstractChart implements GroupedCharts, Observer {
71

  
72
	private static final Logger LOG = LoggerFactory
73
			.getLogger(OverlayChart.class);
74

  
75
	String type = "GroupedCharts";
76

  
77
	private boolean restored = false;
78

  
79
	private Font scaledFont = null;
80
	
81
	public OverlayChart(){
82
		this((OverlayChartProperties) ChartLocator.getServiceManager().getChartManager().createGroupedCharts().getGroupedChartsProperties());
83
	}
84

  
85
	public OverlayChart(OverlayChartProperties chartProps) {
86
		this.setChartProperties(chartProps);
87
	}
88

  
89
	public Manager getManager() {
90
		return null;
91
	}
92

  
93
	protected ProviderManager getProviderManager() {
94
		return null;
95
	}
96

  
97
	@Override
98
	protected JFreeChart getInternalChart() {
99
		if (getChartServices().size() > 0) {
100
			chart = (JFreeChart) getChartServices().get(0).getInnerChart();
101
			return chart;
102
		}
103
		return null;
104
	}
105
	
106
	protected JFreeChart getInternalChart(int i) {
107
		if (getChartServices().size() > i) {
108
			chart = (JFreeChart) getChartServices().get(i).getInnerChart();
109
			return chart;
110
		}
111
		return null;
112
	}
113

  
114
	@Override
115
	public void scaleFonts(double ratio) {
116
		if (getChartServices().size() > 0) {
117
			for (ChartService cs : getChartServices()) {
118
				cs.scaleFonts(ratio);
119
				if(!cs.getDomainAxis().isEmpty()){
120
					this.scaledFont =  cs.getDomainAxis().get(0).getLabelFont();
121
				}
122
			}
123
		}
124

  
125
	}
126
	
127
	public void setAxisVisibles(boolean visible) {
128
		if (getChartServices().size() > 0) {
129
			for (ChartService cs : getChartServices()) {
130
				if(cs.getDomainAxis() != null){
131
					Iterator it = cs.getDomainAxis().iterator();
132
					while(it.hasNext()){
133
						ChartAxis axis = (ChartAxis)it.next();
134
						axis.setIsChartAxisTitleVisible(visible);
135
					}
136
				}
137
				if(cs.getRangeAxis() != null){
138
					Iterator it = cs.getRangeAxis().iterator();
139
					while(it.hasNext()){
140
						ChartAxis axis = (ChartAxis)it.next();
141
						axis.setIsChartAxisTitleVisible(visible);
142
					}
143
				}
144
			}
145
		}
146

  
147
	}
148

  
149
	public void draw(Graphics2D g, Rectangle r) {
150
		LOG.info("Providers: " + this.type);
151
		if(this.restored){
152
			notifyObservers(this);
153
			this.restored = false;
154
		}
155
		
156
		OverlayChartProperties props = (OverlayChartProperties) getChartProperties();
157
		boolean isAnyGraphPainted = false;
158
		
159
		this.getSeries().clear();
160
		g.clearRect(r.x, r.y, r.width, r.height);
161

  
162
		if(!props.getHasPlotDefaultSize()){
163
			Rectangle customRec = new Rectangle(
164
					props.getMainChartXPosition(), 
165
					props.getMainChartYPosition(), 
166
					props.getMainChartWidth(), 
167
					props.getMainChartHeight());
168
			Rectangle resultRec = (Rectangle) customRec.createIntersection(r);
169
			r = resultRec;
170
		}
171
		
172
		// Pintamos el fondo
173
		if(props.getMainBackgroundTransparency()){
174
			g.clearRect(r.x, r.y, r.width, r.height);
175
		}else{
176
			if(props.getMainBackgroundColor() != null){
177
				g.setPaint(this.getGroupedChartsProperties().getMainBackgroundColor());
178
			}else{
179
				g.setPaint(Color.WHITE);
180
			}
181
			g.fillRect(r.x, r.y, r.width, r.height);
182
		}
183
		
184
		// Iteramos por los charts
185
		int firstChart = 0;
186
		if(getChartServices().size() > 0){
187
			// Cargamos todos los ejes
188
			this.rangeAxis = new ArrayList<ValueAxis>();
189
			this.domainAxis = new ArrayList<ChartAxis>();
190
			
191
			for (int i = 0; i < getChartServices().size(); i++) {
192
				ChartService cs = getChartServices().get(i);
193
				
194
				cs.getChartProperties().setIsChartVisibleIfNoData(
195
						this.getGroupedChartsProperties().isChartVisibleIfNoData());
196
				cs.getChartProperties().setNoDataMessageText(
197
						this.getGroupedChartsProperties().getNoDataMessageText());
198
				
199
				Iterator<ChartAxis> it = cs.getDomainAxis().iterator();
200
				while(it.hasNext()){
201
					ChartAxis axis =  (ChartAxis)it.next();
202
					if(axis.isAxisShared()){
203
						ChartService cs2 = axis.getSharedAxis().getChartService();
204
						if(cs2 != null){
205
							cs.getChartDataSet().combine(cs2.getChartDataSet());
206
							cs2.getChartDataSet().combine(cs.getChartDataSet());
207
						}
208
					}
209
				}
210
//				
211
//				Iterator<ValueAxis> it2 = cs.getRangeAxis().iterator();
212
//				while(it2.hasNext()){
213
//					ValueAxis axis =  (ValueAxis)it2.next();
214
//					((ChartNumberAxis)axis).setAssociatedAxis(false);
215
//				}
216
			}
217
			
218
			for (int i = 0; i < getChartServices().size(); i++) {
219
				ChartService cs = getChartServices().get(i);
220
				// Obtenemos los ejes
221
				if(cs.isVisible() && (cs.hasDomainAxis() || cs.hasRangeAxis())){
222
					if(cs.hasRangeAxis()){
223
						// Si es un eje compartido
224
						if(!cs.getRangeAxis().isEmpty() &&
225
								cs.getRangeAxis().get(0).isAxisShared() && 
226
								cs.getRangeAxis().get(0).getSharedAxis().isVisible()){
227
							int index = this.getRangeAxis().indexOf(cs.getRangeAxis().get(0).getSharedAxis());
228
							// Buscamos el eje con el que comparte, para combinarlo con ?l (debe ser anterior a ?l)
229
							if(index != -1){
230
								ChartAxis chartAxis = combinarAxis(this.getRangeAxis().get(index), cs.getRangeAxis().get(0));
231
								if(chartAxis instanceof ValueAxis){
232
									((ChartNumberAxis)this.getRangeAxis().get(index)).setAssociatedAxis(true);
233
									this.getRangeAxis().set(index, this.getRangeAxis().get(index));
234
									cs.setRangeAxis((ValueAxis) chartAxis);
235
									cs.getRangeAxis().get(0).setRange(((ValueAxis) chartAxis).getMin(), ((ValueAxis) chartAxis).getMax());
236
									cs.getRangeAxis().get(0).setVisible(false);
237
								}
238
							}
239
						// Si no es compartido
240
						}else{
241
							if(!cs.getRangeAxis().isEmpty())
242
								cs.getRangeAxis().get(0).setAutoRange(true);
243
								this.getRangeAxis().add(cs.getRangeAxis().get(0));
244
						}
245
					}
246
					if(cs.hasDomainAxis()){
247
						if(!cs.getDomainAxis().isEmpty() &&
248
								cs.getDomainAxis().get(0).isAxisShared() && 
249
								cs.getDomainAxis().get(0).getSharedAxis().isVisible()){
250
							int index = this.getDomainAxis().indexOf(cs.getDomainAxis().get(0).getSharedAxis());
251
							if(index != -1){
252
								ChartAxis chartAxis = combinarAxis(this.getDomainAxis().get(index), cs.getDomainAxis().get(0));
253
//								if(chartAxis instanceof ChartCategoryAxis){
254
//									this.getDomainAxis().set(index, this.getDomainAxis().get(index));
255
//									cs.setDomainAxis((ChartAxis) chartAxis);
256
//									cs.getDomainAxis().get(0).setVisible(false);
257
//								}
258
							}
259
						}else{
260
							if (cs.getDomainAxis().size() > 0) {
261
								cs.getDomainAxis().get(0).setCategoryLabelPositions(cs.getChartProperties().getDomainAxisPosition());
262
								this.getDomainAxis().add(cs.getDomainAxis().get(0));
263
							}
264
						}
265
					}
266
				}
267
			}
268
			for (int i = 0; i < getChartServices().size(); i++) {
269
				ChartService cs = getChartServices().get(i);
270
				// Inicializamos los ejes de cada chat
271
				cs.update();
272
				
273
				// Unificamos leyendas
274
				if(cs.isVisible() && cs.getChartProperties().getIsLegendVisible()){
275
					this.getSeries().addAll(cs.getChartDataSet().getSeries());
276
				}
277
				
278
			}
279
			// Pintamos usando los ejes creados
280
			firstChart = 0;
281
			
282
			for (int i = 0; i < getChartServices().size(); i++) {
283
				ChartService cs = getChartServices().get(i);
284
				if(cs.isVisible()){
285
					if (firstChart == 0) {
286
						boolean isFirstChartLegendVisible = cs.getChartProperties().getIsLegendVisible();
287
						cs.getChartProperties().setIsLegendVisible(true);
288
						if(props.isMainTitleVisible()){
289
							String titleText = props.getMainTitle();
290
							Font titleFont = props.getMainTitleFont();
291
							
292
							if(titleText != null){
293
								TextTitle title = null;
294
								if(titleFont != null)
295
									title = new TextTitle(titleText, titleFont);
296
								else
297
									title = new TextTitle(titleText);
298
								if(props.getMainTitleFontColor()!=null)
299
									title.setPaint(props.getMainTitleFontColor());
300
								if(props.getMainTitleBackgroundColor()!=null)
301
									title.setBackgroundPaint(props.getMainTitleBackgroundColor());
302
								this.getInternalChart().setTitle(title);
303
							}
304
						}else{
305
							this.getInternalChart().setTitle((TextTitle)null);
306
						}
307
						
308
						if(cs.hasDomainAxis()){
309
							cs.setDomainAxis(this.getDomainAxis());
310
						}
311
						if(cs.hasRangeAxis()){
312
							cs.setRangeAxis(this.getRangeAxis());
313
						}
314
						
315
						cs.setBackgroundPaint(null);
316
						((JFreeChart)cs.getInnerChart()).getPlot().setBackgroundPaint(null);
317
						cs.setBackgroundPaint(0.0f);
318
						
319
						cs.getChartProperties().setIsMandatoryChart(true);
320
						
321
						if(!this.getGroupedChartsProperties().getIsLegendVisible()){
322
							cs.getChartProperties().setIsLegendVisible(false);
323
						}
324

  
325
						((JFreeChart)cs.getInnerChart()).removeLegend();
326
						
327
							LegendTitle legend = new LegendTitle(new CustomLegendItemSource());
328
							legend.setPosition(RectangleEdge.BOTTOM);
329
	//						LegendTitle legend = createLegend(cs, g, r, null);
330
							setLegendParameters(cs);
331
							((JFreeChart)cs.getInnerChart()).addLegend(legend);
332
						
333
						cs.draw(g, r);
334
						
335
						Rectangle2D plotArea = cs.getChartRenderingInfo().getPlotArea();
336
						this.getChartRenderingInfo().setChartArea(cs.getChartRenderingInfo().getChartArea());
337
						this.getChartRenderingInfo().setPlotArea(plotArea);
338
						
339
						if(plotArea!=null){
340
							props.setPlotXPosition((int) plotArea.getMinX());
341
							props.setPlotYPosition((int) plotArea.getMinY());
342
							props.setPlotWidth((int) plotArea.getWidth());
343
							props.setPlotHeight((int) plotArea.getHeight());
344
						}
345
						
346
						cs.getChartProperties().setIsLegendVisible(isFirstChartLegendVisible);
347
					} else {
348
						cs.setBackgroundPaint(cs.getChartProperties().getPlotBackgroundColor());
349
						((JFreeChart)cs.getInnerChart()).getPlot().setBackgroundPaint(cs.getChartProperties().getPlotBackgroundColor());
350
						cs.setBackgroundPaint(cs.getChartProperties().getPlotBackgroundAlpha());
351
						
352
						cs.getChartProperties().setIsMandatoryChart(false);
353
						cs.getChartRenderingInfo().setPlotArea(this.getChartRenderingInfo().getPlotArea());
354
						cs.draw(g, (Rectangle) this.getChartRenderingInfo().getPlotArea());
355
					}
356
					if(cs.canBeOverlayed()){
357
						firstChart++;
358
					}else{
359
						isAnyGraphPainted = true;
360
					}
361
				}
362
			}
363
		}
364
		
365
		if ((getChartServices() == null) || (getChartServices().size() == 0)  || (firstChart==0 && !isAnyGraphPainted)) {
366
			if(this.getGroupedChartsProperties().getNoDataMessageColor() != null){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff