Revision 1993

tmp/org.txm.chartsengine.jfreechart.rcp/src/org/txm/chartsengine/jfreechart/rcp/swt/JFCComposite.java (revision 1993)
1
package org.txm.chartsengine.jfreechart.rcp.swt;
2

  
3
import java.awt.Component;
4
import java.io.File;
5
import java.util.ArrayList;
6

  
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.widgets.Composite;
9
import org.jfree.chart.ChartMouseListener;
10
import org.jfree.chart.ChartPanel;
11
import org.jfree.chart.JFreeChart;
12
import org.jfree.chart.plot.CategoryPlot;
13
import org.jfree.chart.plot.Plot;
14
import org.jfree.chart.plot.XYPlot;
15
import org.txm.chartsengine.jfreechart.core.JFCChartsEngine;
16
import org.txm.chartsengine.jfreechart.core.renderers.MouseOverItemSelector;
17
import org.txm.chartsengine.jfreechart.core.renderers.MultipleItemsSelector;
18
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IRendererWithItemSelection;
19
import org.txm.chartsengine.rcp.IChartComponent;
20
import org.txm.chartsengine.rcp.editors.ChartEditor;
21
import org.txm.chartsengine.rcp.events.EventCallBackHandler;
22
import org.txm.chartsengine.rcp.swt.SwingChartComposite;
23

  
24
/**
25
 * JFreeChart SWT composite.
26
 * 
27
 * @author sjacquot
28
 *
29
 */
30
public class JFCComposite extends SwingChartComposite {
31

  
32

  
33
	/**
34
	 * Creates a JFreeChart composite.
35
	 * @param parent
36
	 * @param panel
37
	 */
38
	public JFCComposite(ChartEditor chartEditor, Composite parent) {
39
		super(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
40
		//super(chartEditor, parent, SWT.EMBEDDED);
41
		//super(parent, SWT.EMBEDDED | SWT.NO_MERGE_PAINTS | SWT.NO_BACKGROUND); // do not fix the tooltips transparency problem
42
	}
43
	
44

  
45

  
46
	@Override
47
	public void loadChart(Object data) {
48
		((ChartPanel) this.chartComponent).setChart((JFreeChart) data);
49
		
50
		// FIXME: SJ: tests, restore the zoom from local node
51
		//this.zoom(x, y, zoomIn);
52
		// FIXME: SJ: tests, restoring current zoom from result node
53
//		if(this.getChart().getPlot() instanceof XYPlot)	{
54
//			System.err.println("JFCComposite.loadChart(): restoring current zoom.");
55
//			XYPlot plot = this.getChart().getXYPlot();
56
//			plot.getRangeAxis().setLowerBound(-4400);
57
//			plot.getRangeAxis().setUpperBound(-13000);
58
//		}
59
		
60
	}
61

  
62

  
63
	@Override
64
	protected IChartComponent _createChartComponent() {
65

  
66
		JFreeChart chart = (JFreeChart) this.chartEditor.getChart();
67
		ChartPanel chartPanel = ((JFCChartsEngine) this.chartEditor.getChartsEngine()).getJFCTheme().createChartPanel(chart);
68
		
69
		// Store the chart panel in the renderer (eg. can be needed to get the Graphics2D object to use in getItemShape() to compute the label text bounds and draw a background rectangle.)
70
		if(chart.getPlot() instanceof XYPlot && chart.getXYPlot().getRenderer() instanceof IRendererWithItemSelection)	{
71
			((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setChartPanel(chartPanel);
72
		}
73
		else if(chart.getPlot() instanceof CategoryPlot && chart.getCategoryPlot().getRenderer() instanceof IRendererWithItemSelection)	{
74
			((IRendererWithItemSelection) chart.getCategoryPlot().getRenderer()).getItemsSelector().setChartPanel(chartPanel);
75
		}
76
		return (IChartComponent) chartPanel;
77
	}
78

  
79
	
80
	
81
	@Override
82
	public void clearChartItemsSelection() {
83
		IRendererWithItemSelection renderer = null;
84
		if(this.getChart().getPlot() instanceof XYPlot && this.getChart().getXYPlot().getRenderer() instanceof IRendererWithItemSelection)	{
85
			renderer = (IRendererWithItemSelection) this.getChart().getXYPlot().getRenderer();
86
		}
87
		else if(this.getChart().getPlot() instanceof CategoryPlot && this.getChart().getCategoryPlot().getRenderer() instanceof IRendererWithItemSelection)	{
88
			renderer = (IRendererWithItemSelection) this.getChart().getCategoryPlot().getRenderer();
89
		}
90

  
91
		if(renderer != null && renderer.getItemsSelector() instanceof MultipleItemsSelector)	{
92
			((MultipleItemsSelector)renderer.getItemsSelector()).removeAllSelectedItems();
93
		}
94
	}
95

  
96

  
97
	
98
	@Override
99
	public void copyChartViewToClipboard() {
100
		((ChartPanel) this.chartComponent).doCopy();
101
	}
102

  
103

  
104

  
105
	@Override
106
	public EventCallBackHandler getMouseCallBackHandler()	{
107
		return this.getCallBackHandler(ChartMouseListener.class);
108
	}
109

  
110

  
111
	@Override
112
	public JFreeChart getChart()	{
113
		return (JFreeChart) super.getChart();
114
	}
115

  
116

  
117

  
118
	@Override
119
	public File exportView(File file, String fileFormat) {
120

  
121
		// Disable the item selection to not export the on over item modification
122
		MouseOverItemSelector mouseOverItemSelector = null;
123
		Plot plot = this.getChart().getPlot();
124
		if(plot instanceof XYPlot)	 {
125
	    	 XYPlot typedPlot = (XYPlot)plot;
126
	    	 mouseOverItemSelector = ((IRendererWithItemSelection) typedPlot.getRenderer()).getItemsSelector();
127
	   	}
128
	   	else if(plot instanceof CategoryPlot)	 {
129
	    	CategoryPlot typedPlot = (CategoryPlot)plot;
130
	    	mouseOverItemSelector = ((IRendererWithItemSelection) typedPlot.getRenderer()).getItemsSelector();
131
	   	}
132
		if(mouseOverItemSelector != null)	{
133
			mouseOverItemSelector.setActive(false);
134
		}
135

  
136
		// Export the chart
137
		file = JFCChartsEngine.export(this.getChart(), file, fileFormat, ((Component) this.getChartComponent()).getWidth(), ((Component) this.getChartComponent()).getHeight());
138

  
139
		// Enable back the item selection
140
		if(mouseOverItemSelector != null)	{
141
			mouseOverItemSelector.setActive(true);
142
		}
143

  
144
		return file;
145
	}
146

  
147

  
148
	@Override
149
	public ArrayList<String> getEditorSupportedExportFileFormats()	{
150
		return this.getChartsEngine().getSupportedOutputFileFormats();
151
	}
152
	
153
}
tmp/org.txm.chartsengine.jfreechart.rcp/src/org/txm/chartsengine/jfreechart/rcp/swt/JFCChartComposite.java (revision 1993)
1
package org.txm.chartsengine.jfreechart.rcp.swt;
2

  
3
import java.awt.Component;
4
import java.io.File;
5
import java.util.ArrayList;
6

  
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.widgets.Composite;
9
import org.jfree.chart.ChartMouseListener;
10
import org.jfree.chart.ChartPanel;
11
import org.jfree.chart.JFreeChart;
12
import org.jfree.chart.plot.CategoryPlot;
13
import org.jfree.chart.plot.Plot;
14
import org.jfree.chart.plot.XYPlot;
15
import org.txm.chartsengine.jfreechart.core.JFCChartsEngine;
16
import org.txm.chartsengine.jfreechart.core.renderers.MouseOverItemSelector;
17
import org.txm.chartsengine.jfreechart.core.renderers.MultipleItemsSelector;
18
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IRendererWithItemSelection;
19
import org.txm.chartsengine.rcp.IChartComponent;
20
import org.txm.chartsengine.rcp.editors.ChartEditor;
21
import org.txm.chartsengine.rcp.events.EventCallBackHandler;
22
import org.txm.chartsengine.rcp.swt.SwingChartComposite;
23

  
24
/**
25
 * JFreeChart SWT composite.
26
 * 
27
 * @author sjacquot
28
 *
29
 */
30
public class JFCChartComposite extends SwingChartComposite {
31

  
32

  
33
	/**
34
	 * Creates a JFreeChart composite.
35
	 * @param parent
36
	 * @param panel
37
	 */
38
	public JFCChartComposite(ChartEditor chartEditor, Composite parent) {
39
		super(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
40
		//super(chartEditor, parent, SWT.EMBEDDED);
41
		//super(parent, SWT.EMBEDDED | SWT.NO_MERGE_PAINTS | SWT.NO_BACKGROUND); // do not fix the tooltips transparency problem
42
	}
43
	
44

  
45

  
46
	@Override
47
	public void loadChart(Object chart) {
48
		((ChartPanel) this.chartComponent).setChart((JFreeChart) chart);
49
		
50
		// FIXME: SJ: tests, restore the zoom from local node
51
		//this.zoom(x, y, zoomIn);
52
		// FIXME: SJ: tests, restoring current zoom from result node
53
//		if(this.getChart().getPlot() instanceof XYPlot)	{
54
//			System.err.println("JFCComposite.loadChart(): restoring current zoom.");
55
//			XYPlot plot = this.getChart().getXYPlot();
56
//			plot.getRangeAxis().setLowerBound(-4400);
57
//			plot.getRangeAxis().setUpperBound(-13000);
58
//		}
59
		
60
	}
61

  
62

  
63
	@Override
64
	protected IChartComponent _createChartComponent() {
65

  
66
		JFreeChart chart = (JFreeChart) this.chartEditor.getChart();
67
		ChartPanel chartPanel = ((JFCChartsEngine) this.chartEditor.getChartsEngine()).getJFCTheme().createChartPanel(chart);
68
		
69
		// Store the chart panel in the renderer (eg. can be needed to get the Graphics2D object to use in getItemShape() to compute the label text bounds and draw a background rectangle.)
70
		if(chart.getPlot() instanceof XYPlot && chart.getXYPlot().getRenderer() instanceof IRendererWithItemSelection)	{
71
			((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setChartPanel(chartPanel);
72
		}
73
		else if(chart.getPlot() instanceof CategoryPlot && chart.getCategoryPlot().getRenderer() instanceof IRendererWithItemSelection)	{
74
			((IRendererWithItemSelection) chart.getCategoryPlot().getRenderer()).getItemsSelector().setChartPanel(chartPanel);
75
		}
76
		return (IChartComponent) chartPanel;
77
	}
78

  
79
	
80
	
81
	@Override
82
	public void clearChartItemsSelection() {
83
		IRendererWithItemSelection renderer = null;
84
		if(this.getChart().getPlot() instanceof XYPlot && this.getChart().getXYPlot().getRenderer() instanceof IRendererWithItemSelection)	{
85
			renderer = (IRendererWithItemSelection) this.getChart().getXYPlot().getRenderer();
86
		}
87
		else if(this.getChart().getPlot() instanceof CategoryPlot && this.getChart().getCategoryPlot().getRenderer() instanceof IRendererWithItemSelection)	{
88
			renderer = (IRendererWithItemSelection) this.getChart().getCategoryPlot().getRenderer();
89
		}
90

  
91
		if(renderer != null && renderer.getItemsSelector() instanceof MultipleItemsSelector)	{
92
			((MultipleItemsSelector)renderer.getItemsSelector()).removeAllSelectedItems();
93
		}
94
	}
95

  
96

  
97
	
98
	@Override
99
	public void copyChartViewToClipboard() {
100
		((ChartPanel) this.chartComponent).doCopy();
101
	}
102

  
103

  
104

  
105
	@Override
106
	public EventCallBackHandler getMouseCallBackHandler()	{
107
		return this.getCallBackHandler(ChartMouseListener.class);
108
	}
109

  
110

  
111
	@Override
112
	public JFreeChart getChart()	{
113
		return (JFreeChart) super.getChart();
114
	}
115

  
116

  
117

  
118
	@Override
119
	public File exportView(File file, String fileFormat) {
120

  
121
		// Disable the item selection to not export the on over item modification
122
		MouseOverItemSelector mouseOverItemSelector = null;
123
		Plot plot = this.getChart().getPlot();
124
		if(plot instanceof XYPlot)	 {
125
	    	 XYPlot typedPlot = (XYPlot)plot;
126
	    	 mouseOverItemSelector = ((IRendererWithItemSelection) typedPlot.getRenderer()).getItemsSelector();
127
	   	}
128
	   	else if(plot instanceof CategoryPlot)	 {
129
	    	CategoryPlot typedPlot = (CategoryPlot)plot;
130
	    	mouseOverItemSelector = ((IRendererWithItemSelection) typedPlot.getRenderer()).getItemsSelector();
131
	   	}
132
		if(mouseOverItemSelector != null)	{
133
			mouseOverItemSelector.setActive(false);
134
		}
135

  
136
		// Export the chart
137
		file = JFCChartsEngine.export(this.getChart(), file, fileFormat, ((Component) this.getChartComponent()).getWidth(), ((Component) this.getChartComponent()).getHeight());
138

  
139
		// Enable back the item selection
140
		if(mouseOverItemSelector != null)	{
141
			mouseOverItemSelector.setActive(true);
142
		}
143

  
144
		return file;
145
	}
146

  
147

  
148
	@Override
149
	public ArrayList<String> getEditorSupportedExportFileFormats()	{
150
		return this.getChartsEngine().getSupportedOutputFileFormats();
151
	}
152
	
153
}
0 154

  
tmp/org.txm.chartsengine.jfreechart.rcp/src/org/txm/chartsengine/jfreechart/rcp/JFCSWTChartsComponentsProvider.java (revision 1993)
10 10
import org.jfree.chart.plot.XYPlot;
11 11
import org.txm.chartsengine.core.ChartsEngine;
12 12
import org.txm.chartsengine.jfreechart.core.JFCChartsEngine;
13
import org.txm.chartsengine.jfreechart.rcp.swt.JFCComposite;
13
import org.txm.chartsengine.jfreechart.rcp.swt.JFCChartComposite;
14 14
import org.txm.chartsengine.jfreechart.rcp.themes.highcharts.HighchartsThemeSwing;
15 15
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
16 16
import org.txm.chartsengine.rcp.editors.ChartEditor;
......
49 49

  
50 50
	@Override
51 51
	public ChartComposite createComposite(ChartEditor chartEditor, Composite parent)	{
52
		return new JFCComposite(chartEditor, parent);
52
		return new JFCChartComposite(chartEditor, parent);
53 53
	}
54 54

  
55 55

  

Also available in: Unified diff