Révision 47
tmp/org.txm.chartsengine.svgbatik.rcp/build.properties (revision 47) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
.,\ |
|
5 |
plugin.xml |
|
0 | 6 |
tmp/org.txm.chartsengine.svgbatik.rcp/plugin.xml (revision 47) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.txm.rcp.swtchartscomponentsprovider"> |
|
6 |
<SWTChartsComponentsProvider |
|
7 |
class="org.txm.chartsengine.svgbatik.rcp.SVGSWTChartsComponentsProvider" |
|
8 |
inputFormat="svg" |
|
9 |
name="SVG Batik SWT Charts Components Provider"> |
|
10 |
</SWTChartsComponentsProvider> |
|
11 |
</extension> |
|
12 |
|
|
13 |
</plugin> |
|
0 | 14 |
tmp/org.txm.chartsengine.svgbatik.rcp/.settings/org.eclipse.jdt.core.prefs (revision 47) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.chartsengine.svgbatik.rcp/.classpath (revision 47) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.chartsengine.svgbatik.rcp/META-INF/MANIFEST.MF (revision 47) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: SVG Batik Charts Engine Editors |
|
4 |
Bundle-SymbolicName: org.txm.chartsengine.svgbatik.rcp;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
7 |
Require-Bundle: org.txm.chartsengine.rcp;bundle-version="1.0.0";visibility:=reexport, |
|
8 |
org.txm.toolbox;bundle-version="0.7.0", |
|
9 |
org.txm.rcpapplication;bundle-version="0.7.8" |
|
10 |
Export-Package: org.txm.chartsengine.svgbatik.rcp, |
|
11 |
org.txm.chartsengine.svgbatik.rcp.editors, |
|
12 |
org.txm.chartsengine.svgbatik.rcp.swing, |
|
13 |
org.txm.chartsengine.svgbatik.rcp.swt |
|
14 |
Bundle-Vendor: TXM |
|
0 | 15 |
tmp/org.txm.chartsengine.svgbatik.rcp/.project (revision 47) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.chartsengine.svgbatik.rcp</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/SVGSWTChartsComponentsProvider.java (revision 47) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp; |
|
2 |
|
|
3 |
import java.awt.Graphics2D; |
|
4 |
import java.awt.image.BufferedImage; |
|
5 |
import java.io.BufferedOutputStream; |
|
6 |
import java.io.File; |
|
7 |
import java.io.FileNotFoundException; |
|
8 |
import java.io.FileOutputStream; |
|
9 |
import java.io.FileWriter; |
|
10 |
import java.io.IOException; |
|
11 |
import java.util.ArrayList; |
|
12 |
|
|
13 |
import org.apache.batik.transcoder.AbstractTranscoder; |
|
14 |
import org.apache.batik.transcoder.TranscoderException; |
|
15 |
import org.apache.batik.transcoder.TranscoderInput; |
|
16 |
import org.apache.batik.transcoder.TranscoderOutput; |
|
17 |
import org.apache.batik.transcoder.svg2svg.SVGTranscoder; |
|
18 |
import org.eclipse.swt.SWT; |
|
19 |
import org.eclipse.swt.layout.FormAttachment; |
|
20 |
import org.eclipse.swt.layout.FormData; |
|
21 |
import org.eclipse.swt.widgets.Composite; |
|
22 |
import org.txm.chartsengine.core.ChartCreator; |
|
23 |
import org.txm.chartsengine.core.ChartsEngine; |
|
24 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
25 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput; |
|
26 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
27 |
import org.txm.chartsengine.rcp.swt.ChartComposite; |
|
28 |
import org.txm.chartsengine.svgbatik.rcp.editors.___SVGChartEditorPart; |
|
29 |
import org.txm.chartsengine.svgbatik.rcp.swt.SVGComposite; |
|
30 |
import org.txm.functions.TXMResult; |
|
31 |
import org.w3c.dom.Element; |
|
32 |
|
|
33 |
import com.lowagie.text.Document; |
|
34 |
import com.lowagie.text.Rectangle; |
|
35 |
import com.lowagie.text.pdf.PdfContentByte; |
|
36 |
import com.lowagie.text.pdf.PdfWriter; |
|
37 |
|
|
38 |
/** |
|
39 |
* Batik SVG charts component provider. |
|
40 |
* @author sjacquot |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class SVGSWTChartsComponentsProvider extends SWTChartsComponentsProvider { |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* |
|
48 |
*/ |
|
49 |
public SVGSWTChartsComponentsProvider() { |
|
50 |
super(); |
|
51 |
} |
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
// @Override |
|
56 |
// public ChartEditorPart createChartEditor(String editorInputName, TXMResult resultData, String preferencesNode, String chartType) { |
|
57 |
// ChartEditorPart editor = new ChartEditorPart(this, editorInputName, resultData, preferencesNode, chartType, this.getChartsEngine().getChartCreator(resultData.getClass(), chartType).createChartFile(resultData, preferencesNode)); |
|
58 |
// |
|
59 |
// // sets and updates the local preferences node qualifier from the result data |
|
60 |
// editor.getEditorInput().syncLocalPreferencesNode(); |
|
61 |
// |
|
62 |
// return editor; |
|
63 |
// } |
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
@Override |
|
69 |
public boolean createChart(ChartsEngine chartsEngine, ChartEditorInput chartEditorInput, TXMResult resultData, String preferencesNode, String chartType) { |
|
70 |
ChartCreator chartCreator = chartsEngine.getChartCreator(resultData.getClass(), chartType); |
|
71 |
if(chartCreator != null) { |
|
72 |
chartEditorInput.setChartContainer(chartCreator.createChartFile(resultData, preferencesNode)); |
|
73 |
|
|
74 |
// sets and updates the local preferences node qualifier from the result data |
|
75 |
chartEditorInput.syncLocalPreferencesNode(); |
|
76 |
|
|
77 |
return true; |
|
78 |
} |
|
79 |
return false; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Create a <code>SVGGraphicEditorPart</code> from specified file. |
|
84 |
* @param editorName the editor namer |
|
85 |
* @param titleImage the image drawn in editor title |
|
86 |
* @param file the SVG file |
|
87 |
* @return |
|
88 |
*/ |
|
89 |
public ChartEditorPart createSVGGraphicEditorPart(String editorName, File file, TXMResult resultData, String preferencesNodeQualifier, String chartType) { |
|
90 |
|
|
91 |
___SVGChartEditorPart editorPart = new ___SVGChartEditorPart(this, file, editorName, resultData, preferencesNodeQualifier, chartType); |
|
92 |
|
|
93 |
return editorPart; |
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 |
// @Override |
|
98 |
// public ChartEditorPart createDimensionsPartitionChartEditorPart(Image titleImage, Partition partition, boolean sortPartsBySize) { |
|
99 |
// File file = this.chartsEngine.createDimensionsPartitionChartFile(partition, sortPartsBySize); |
|
100 |
// return this.createSVGGraphicEditorPart(Messages.bind(Messages.PartsSize_18, partition.getName()), titleImage, file, partition); |
|
101 |
// } |
|
102 |
|
|
103 |
|
|
104 |
// @Override |
|
105 |
// public ChartEditorPart createSpecificitiesChartEditorPart(Image titleImage, SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean monochrome) { |
|
106 |
// File file = this.chartsEngine.createSpecificitiesChartFile(specificitiesResult, transpose, drawBars, drawLines, banalite, monochrome); |
|
107 |
// return this.createSVGGraphicEditorPart(Messages.SpecificitiesTableEditor_16 + specificitiesResult.getName(), titleImage, file, specificitiesResult); |
|
108 |
// } |
|
109 |
|
|
110 |
// @Override |
|
111 |
// public ChartEditorPart createCASingularValuesBarChartEditorPart(CA ca) { |
|
112 |
// File file = this.chartsEngine.createCASingularValuesBarChartFile(ca); |
|
113 |
// return this.createSVGGraphicEditorPart("CA singular values bar chart", null, file, null); |
|
114 |
// } |
|
115 |
|
|
116 |
|
|
117 |
// @Override |
|
118 |
// public ChartEditorPart createProgressionChartEditorPart(Image titleImage, Progression progression, boolean monochrome, boolean monostyle, boolean doCumulative) { |
|
119 |
// File file = this.chartsEngine.createProgressionChartFile(progression, monochrome, monostyle, doCumulative); |
|
120 |
// return this.createSVGGraphicEditorPart(progression.getCorpus().getName() + ": " + progression.getName(), titleImage, file, progression); |
|
121 |
// } |
|
122 |
|
|
123 |
|
|
124 |
// @Override |
|
125 |
// public ChartEditorPart createCAFactorialMapChartEditorPart(CA ca) { |
|
126 |
// File file = this.chartsEngine.createCAFactorialMapChartFile(ca); |
|
127 |
// |
|
128 |
// ChartEditorPart chartEditor = new CAFactorialMapChartEditor(new SVGChartEditorInput(this, file, ca)); |
|
129 |
// return chartEditor; |
|
130 |
// } |
|
131 |
// |
|
132 |
// |
|
133 |
// @Override |
|
134 |
// public ChartEditorPart createCAHChartEditorPart(Image titleImage, CAH cah) { |
|
135 |
// |
|
136 |
// File file = this.chartsEngine.createCAHChartFile(cah, cah.isDisplay2D()); |
|
137 |
// |
|
138 |
// ChartEditorPart chartEditor = new CAHChartEditor(new SVGChartEditorInput(this, file, Messages.bind(Messages.CAHEditor_PART_NAME_PREFIX, cah.getName()) , titleImage, cah)); |
|
139 |
// return chartEditor; |
|
140 |
// } |
|
141 |
|
|
142 |
|
|
143 |
@Override |
|
144 |
public ChartComposite createComposite(ChartEditorPart chartEditor, Composite parent) { |
|
145 |
return SVGSWTChartsComponentsProvider.createCompositeStatic(chartEditor, parent); |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
/** |
|
150 |
* Creates the chart drawing area composite. |
|
151 |
* @param chartEditor |
|
152 |
* @param parent |
|
153 |
* @return |
|
154 |
*/ |
|
155 |
public static SVGComposite createCompositeStatic(ChartEditorPart chartEditor, Composite parent) { |
|
156 |
|
|
157 |
SVGComposite composite = new SVGComposite(chartEditor, parent, SWT.EMBEDDED | SWT.NO_BACKGROUND); |
|
158 |
FormData formData = new FormData(); |
|
159 |
|
|
160 |
//formData.top = new FormAttachment(chartEditor.getToolBar()); |
|
161 |
formData.top = new FormAttachment(chartEditor.getParametersComposite()); |
|
162 |
formData.bottom = new FormAttachment(100); |
|
163 |
formData.left = new FormAttachment(0); |
|
164 |
formData.right = new FormAttachment(100); |
|
165 |
composite.setLayoutData(formData); |
|
166 |
|
|
167 |
// Link the composite to the chart editor (need to be done before initializing the AWT delegation events) |
|
168 |
chartEditor.setComposite(composite); |
|
169 |
|
|
170 |
// Initialize Swing/AWT events |
|
171 |
SWTChartsComponentsProvider.initializeAWTDelegationListeners(chartEditor, composite.getPanel().getSVGCanvas()); |
|
172 |
|
|
173 |
// Load the chart in composite |
|
174 |
if(chartEditor.getEditorInput().getChartContainer() != null) { |
|
175 |
composite.loadChart(chartEditor.getEditorInput().getChartContainer()); |
|
176 |
} |
|
177 |
|
|
178 |
return composite; |
|
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
@Override |
|
183 |
public ArrayList<String> getEditorSupportedExportFileFormats() { |
|
184 |
|
|
185 |
ArrayList<String> supportedExportFileFormats = new ArrayList<String>(5); |
|
186 |
|
|
187 |
supportedExportFileFormats.add(ChartsEngine.OUTPUT_FORMAT_SVG); // Default format |
|
188 |
supportedExportFileFormats.add(ChartsEngine.OUTPUT_FORMAT_PDF); |
|
189 |
|
|
190 |
// Auto-populate supported output file raster formats from available image writers |
|
191 |
ChartsEngine.populateSupportedOutputRasterFileFormats(supportedExportFileFormats); |
|
192 |
|
|
193 |
|
|
194 |
return supportedExportFileFormats; |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
@Override |
|
201 |
public ArrayList<String> getChartsEngineSupportedExportFileFormats() { |
|
202 |
return this.chartsEngine.getSupportedOutputFileFormats(); |
|
203 |
} |
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
@Override |
|
208 |
public File exportView(ChartEditorPart chartEditor, File file, String fileFormat) { |
|
209 |
return SVGSWTChartsComponentsProvider.exportViewStatic(chartEditor, file, fileFormat); |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
/** |
|
214 |
* Export the current view of chart editor in the specified file. |
|
215 |
* @param chartEditor |
|
216 |
* @param file |
|
217 |
* @param fileFormat |
|
218 |
* @return |
|
219 |
*/ |
|
220 |
public static File exportViewStatic(ChartEditorPart chartEditor, File file, String fileFormat) { |
|
221 |
|
|
222 |
SVGComposite composite = ((SVGComposite) chartEditor.getComposite()); |
|
223 |
|
|
224 |
// SVG |
|
225 |
if(fileFormat == ChartsEngine.OUTPUT_FORMAT_SVG) { |
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
// FIXME : Batik transcoder version |
|
230 |
// FIXME : the cropping to match view in SVG doesn't work |
|
231 |
try { |
|
232 |
//AbstractTranscoder imageTranscoder = this.getImageTranscoder(fileFormat); |
|
233 |
AbstractTranscoder imageTranscoder = new SVGTranscoder(); |
|
234 |
|
|
235 |
|
|
236 |
// Transcoder configuration |
|
237 |
//imageTranscoder.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Integer(300)); |
|
238 |
|
|
239 |
|
|
240 |
// SVG Cropping tests |
|
241 |
// Rectangle area = new Rectangle(200, 200, 300, 500); // FIXME : how to get the correct area after the charts has been zoomed or moved ? |
|
242 |
//// imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(this.composite.getPanel().getWidth())); |
|
243 |
//// imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(this.composite.getPanel().getHeight())); |
|
244 |
// imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(20)); |
|
245 |
// imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(20)); |
|
246 |
// imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_AOI, area); |
|
247 |
|
|
248 |
|
|
249 |
// Add a viewbox attribute |
|
250 |
//((Element)this.composite.getSVGDocument().getFirstChild()).setAttribute("viewBox", "20 20 400 350"); // FIXME : how to get the correct area after the charts has been zoomed or moved ? |
|
251 |
|
|
252 |
// Adjust dimensions from component |
|
253 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("width", String.valueOf(composite.getPanel().getSVGCanvas().getWidth())); |
|
254 |
((Element)composite.getSVGDocument().getFirstChild()).setAttribute("height", String.valueOf(composite.getPanel().getSVGCanvas().getHeight())); |
|
255 |
|
|
256 |
|
|
257 |
TranscoderInput input = new TranscoderInput(composite.getSVGDocument()); |
|
258 |
|
|
259 |
// SVGTranscoder needs an OutputStreamWriter, not an OutputStream |
|
260 |
if(imageTranscoder instanceof SVGTranscoder) { |
|
261 |
|
|
262 |
FileWriter outputStreamWriter = new FileWriter(file); |
|
263 |
imageTranscoder.transcode(input, new TranscoderOutput(outputStreamWriter)); |
|
264 |
|
|
265 |
outputStreamWriter.flush(); |
|
266 |
outputStreamWriter.close(); |
|
267 |
} |
|
268 |
// else { |
|
269 |
// OutputStream outputStream = new FileOutputStream(file); |
|
270 |
// TranscoderOutput output = new TranscoderOutput(outputStream); |
|
271 |
// |
|
272 |
// imageTranscoder.transcode(input, output); |
|
273 |
// |
|
274 |
// outputStream.flush(); |
|
275 |
// outputStream.close(); |
|
276 |
// } |
|
277 |
} |
|
278 |
catch(FileNotFoundException e) { |
|
279 |
// TODO Auto-generated catch block |
|
280 |
e.printStackTrace(); |
|
281 |
} |
|
282 |
catch(TranscoderException e) { |
|
283 |
// TODO Auto-generated catch block |
|
284 |
e.printStackTrace(); |
|
285 |
} |
|
286 |
catch(IOException e) { |
|
287 |
// TODO Auto-generated catch block |
|
288 |
e.printStackTrace(); |
|
289 |
} |
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
// FIXME : SVG via Batik |
|
294 |
// FIXME : it saves the JPanel content as image raster tag in the SVG instead of creating real SVG shapes tag |
|
295 |
|
|
296 |
// // Get a DOMImplementation |
|
297 |
// DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); |
|
298 |
// |
|
299 |
// String svgNS = "http://www.w3.org/2000/svg"; |
|
300 |
// Document document = domImpl.createDocument(svgNS, "svg", null); |
|
301 |
// |
|
302 |
// SVGGraphics2D svgGenerator = new SVGGraphics2D(document); |
|
303 |
// |
|
304 |
// // Paint in the SVGGraphics2D implementation |
|
305 |
// //this.composite.getPanel().getSVGCanvas().paint(svgGenerator); |
|
306 |
// this.composite.getPanel().paint(svgGenerator); |
|
307 |
// |
|
308 |
// boolean useCSS = true; |
|
309 |
// |
|
310 |
// try { |
|
311 |
// Writer out = new FileWriter(file); |
|
312 |
// svgGenerator.stream(out, useCSS); |
|
313 |
// } |
|
314 |
// catch(UnsupportedEncodingException e) { |
|
315 |
// // TODO Auto-generated catch block |
|
316 |
// e.printStackTrace(); |
|
317 |
// } |
|
318 |
// catch(SVGGraphics2DIOException e) { |
|
319 |
// // TODO Auto-generated catch block |
|
320 |
// e.printStackTrace(); |
|
321 |
// } |
|
322 |
// catch(IOException e) { |
|
323 |
// // TODO Auto-generated catch block |
|
324 |
// e.printStackTrace(); |
|
325 |
// } |
|
326 |
// |
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
// FIXME : SVG via JFreeSVG : doesn't work |
|
331 |
// SVGGraphics2D g2 = new SVGGraphics2D(this.composite.getPanel().getWidth(), this.composite.getPanel().getHeight()); |
|
332 |
// |
|
333 |
// // suppress shadow generation, because SVG is a vector format and |
|
334 |
// // the shadow effect is applied via bitmap effects... |
|
335 |
// g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true); |
|
336 |
// String svg = null; |
|
337 |
// this.composite. |
|
338 |
// getPanel(). |
|
339 |
// paintAll(g2); |
|
340 |
// svg = g2.getSVGElement(); |
|
341 |
// |
|
342 |
// if (file != null) { |
|
343 |
// BufferedWriter writer = null; |
|
344 |
// try { |
|
345 |
// writer = new BufferedWriter(new FileWriter(file)); |
|
346 |
// writer.write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); |
|
347 |
// writer.write(svg + "\n"); |
|
348 |
// writer.flush(); |
|
349 |
// } |
|
350 |
// catch(IOException e) { |
|
351 |
// // TODO Auto-generated catch block |
|
352 |
// e.printStackTrace(); |
|
353 |
// } |
|
354 |
// finally { |
|
355 |
// try { |
|
356 |
// if (writer != null) { |
|
357 |
// writer.close(); |
|
358 |
// } |
|
359 |
// } |
|
360 |
// catch (IOException ex) { |
|
361 |
// throw new RuntimeException(ex); |
|
362 |
// } |
|
363 |
// } |
|
364 |
// |
|
365 |
// } |
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
} |
|
371 |
// PDF (using Lowagie iTtext lib) |
|
372 |
else if(fileFormat == ChartsEngine.OUTPUT_FORMAT_PDF) { |
|
373 |
|
|
374 |
Document document = new Document(new Rectangle(0, 0, composite.getPanel().getWidth(), composite.getPanel().getHeight())); |
|
375 |
try { |
|
376 |
|
|
377 |
PdfWriter writer = PdfWriter.getInstance(document, new BufferedOutputStream(new FileOutputStream(file))); |
|
378 |
document.open(); |
|
379 |
PdfContentByte cb = writer.getDirectContent(); |
|
380 |
|
|
381 |
Graphics2D g = cb.createGraphics(composite.getPanel().getWidth(), composite.getPanel().getHeight()); |
|
382 |
composite.getPanel().printAll(g); |
|
383 |
g.dispose(); |
|
384 |
} |
|
385 |
catch (Exception e) { |
|
386 |
e.printStackTrace(); |
|
387 |
} |
|
388 |
document.close(); |
|
389 |
} |
|
390 |
// Raster (using AWT/Swing methods) |
|
391 |
else { |
|
392 |
BufferedImage image = new BufferedImage(composite.getPanel().getWidth(), composite.getPanel().getHeight(), BufferedImage.TYPE_INT_RGB); |
|
393 |
Graphics2D g = image.createGraphics(); |
|
394 |
composite.getPanel().printAll(g); |
|
395 |
g.dispose(); |
|
396 |
try { |
|
397 |
javax.imageio.ImageIO.write(image, fileFormat, file); |
|
398 |
} |
|
399 |
catch (IOException e) { |
|
400 |
e.printStackTrace(); |
|
401 |
} |
|
402 |
} |
|
403 |
|
|
404 |
return file; |
|
405 |
} |
|
406 |
|
|
407 |
} |
|
0 | 408 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swing/SVGPanel.java (revision 47) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.chartsengine.svgbatik.rcp.swing; |
|
29 |
|
|
30 |
|
|
31 |
import java.awt.BorderLayout; |
|
32 |
import java.awt.Frame; |
|
33 |
import java.awt.event.InputEvent; |
|
34 |
import java.awt.event.MouseEvent; |
|
35 |
import java.awt.event.MouseWheelEvent; |
|
36 |
import java.awt.event.MouseWheelListener; |
|
37 |
import java.awt.geom.AffineTransform; |
|
38 |
import java.util.List; |
|
39 |
|
|
40 |
import javax.swing.JPanel; |
|
41 |
|
|
42 |
import org.apache.batik.swing.JSVGCanvas; |
|
43 |
import org.apache.batik.swing.gvt.AbstractImageZoomInteractor; |
|
44 |
import org.apache.batik.swing.gvt.AbstractPanInteractor; |
|
45 |
import org.apache.batik.swing.gvt.AbstractResetTransformInteractor; |
|
46 |
import org.apache.batik.swing.gvt.AbstractZoomInteractor; |
|
47 |
import org.apache.batik.swing.gvt.Interactor; |
|
48 |
import org.txm.chartsengine.rcp.IChartComponent; |
|
49 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
50 |
import org.txm.chartsengine.rcp.events.ChartKeyListener; |
|
51 |
import org.txm.chartsengine.rcp.events.EventCallBackHandler; |
|
52 |
import org.txm.chartsengine.rcp.events.ItemsKeyboardSelectionCallBack; |
|
53 |
import org.txm.chartsengine.rcp.events.ZoomAndPanCallBack; |
|
54 |
import org.txm.rcpapplication.Application; |
|
55 |
import org.w3c.dom.svg.SVGDocument; |
|
56 |
|
|
57 |
/** |
|
58 |
* SVG Batik Swing panel. |
|
59 |
*/ |
|
60 |
public class SVGPanel extends JPanel implements IChartComponent { |
|
61 |
|
|
62 |
|
|
63 |
/** |
|
64 |
* The linked editor. |
|
65 |
*/ |
|
66 |
protected ChartEditorPart editor; |
|
67 |
|
|
68 |
/** |
|
69 |
* The Constant serialVersionUID. |
|
70 |
*/ |
|
71 |
private static final long serialVersionUID = -4381954167495751486L; |
|
72 |
|
|
73 |
/** |
|
74 |
* The Batik SVG canvas. |
|
75 |
*/ |
|
76 |
protected JSVGCanvas svgCanvas; |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* Current zoom value. |
|
81 |
*/ |
|
82 |
int zoom = 0; |
|
83 |
|
|
84 |
/** |
|
85 |
* Key pressed pan factor. |
|
86 |
*/ |
|
87 |
protected double keyPressedPanFactor = 0.5; |
|
88 |
|
|
89 |
|
|
90 |
/** |
|
91 |
* Instantiates a new SVG panel. |
|
92 |
* |
|
93 |
* @param frame the frame |
|
94 |
*/ |
|
95 |
public SVGPanel(ChartEditorPart editor, Frame frame) { |
|
96 |
super(new BorderLayout()); |
|
97 |
|
|
98 |
this.editor = editor; |
|
99 |
|
|
100 |
this.svgCanvas = new JSVGCanvas(null, true, false); |
|
101 |
this.add("Center", svgCanvas); //$NON-NLS-1$ |
|
102 |
|
|
103 |
// FIXME : needed for automatic refresh after dynamically modifying the SVG DOM |
|
104 |
//svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); |
|
105 |
|
|
106 |
List<Interactor> list = svgCanvas.getInteractors(); |
|
107 |
list.clear(); |
|
108 |
|
|
109 |
|
|
110 |
// FIXME : test for constant text label font size (only work with the SVG produced by the SVGGraphicsDevice of R, not with CairoSVG because it doesn't produces text tag, only glyph paths) |
|
111 |
//svgCanvas.addMouseWheelListener(new ___AbstractImageZoomInteractor()); |
|
112 |
|
|
113 |
list.add(zoomInteractor); |
|
114 |
list.add(imageZoomInteractor); |
|
115 |
list.add(panInteractor); |
|
116 |
list.add(resetTransformInteractor); |
|
117 |
|
|
118 |
this.addMouseWheelListener(new MouseWheelListener() { |
|
119 |
|
|
120 |
@Override |
|
121 |
public void mouseWheelMoved(MouseWheelEvent e) { |
|
122 |
|
|
123 |
|
|
124 |
// FIXME : test zoom by viewbox attribute |
|
125 |
// final MouseWheelEvent mwe = e; |
|
126 |
// svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new Runnable() { |
|
127 |
// |
|
128 |
// @Override |
|
129 |
// public void run() { |
|
130 |
// // TODO Auto-generated method stub |
|
131 |
// |
|
132 |
// //System.out.println("SVGPanel.SVGPanel(...).new MouseWheelListener() {...}.mouseWheelMoved(): " + ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox")); |
|
133 |
// |
|
134 |
// String[] viewBox = ((Element)getSVGDocument().getFirstChild()).getAttribute("viewBox").split(" "); |
|
135 |
// |
|
136 |
// int x = Integer.valueOf(viewBox[0]); |
|
137 |
// int y = Integer.valueOf(viewBox[1]); |
|
138 |
// int width = Integer.valueOf(viewBox[2]); |
|
139 |
// int height = Integer.valueOf(viewBox[3]); |
|
140 |
// |
|
141 |
// if (mwe.getUnitsToScroll() < 0) { |
|
142 |
// |
|
143 |
// x += 10; |
|
144 |
// y += 10; |
|
145 |
// width -= 10; |
|
146 |
// height -= 10; |
|
147 |
// |
|
148 |
// |
|
149 |
// |
|
150 |
// } |
|
151 |
// else { |
|
152 |
// |
|
153 |
// x -= 10; |
|
154 |
// y -= 10; |
|
155 |
// width += 10; |
|
156 |
// height += 10; |
|
157 |
// |
|
158 |
// } |
|
159 |
// ((Element)getSVGDocument().getFirstChild()).setAttribute("viewBox", x + " " + y + " " + width + " " + height); |
|
160 |
// } |
|
161 |
// }); |
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
// FIXME : tests for constant text font size |
|
167 |
// FIXME : only work with SVG generated with text tag |
|
168 |
// FIXME : do not work properly |
|
169 |
// NodeList elements = svgCanvas.getSVGDocument().getElementsByTagName("text"); |
|
170 |
// Element element; |
|
171 |
// for (int i = 0; i < elements.getLength(); i++) { |
|
172 |
// element = (Element) elements.item(i); |
|
173 |
// |
|
174 |
// // TODO : Debug : Affichage des attributs de l'�l�ment |
|
175 |
//// NamedNodeMap attributes = element.getAttributes(); |
|
176 |
//// int numAttrs = attributes.getLength(); |
|
177 |
//// System.out.println(""); |
|
178 |
//// for (int j = 0; j < numAttrs; j++) { |
|
179 |
//// |
|
180 |
//// Attr attr = (Attr) attributes.item(j); |
|
181 |
//// |
|
182 |
//// String attrName = attr.getNodeName(); |
|
183 |
//// String attrValue = attr.getNodeValue(); |
|
184 |
//// System.out.print(" " + attrName + "=" + attrValue); |
|
185 |
//// } |
|
186 |
// |
|
187 |
// // TODO : test de modif de l'attribut font-size du texte |
|
188 |
// // TODO : Fonctionne mais prend beaucoup plus de ressources que la modification directe de la shape GVT |
|
189 |
// element.removeAttribute("style"); |
|
190 |
// //element.setAttribute("style", "font-size:" + (8 * 1d / zoom)); |
|
191 |
// |
|
192 |
// if(zoom != 0) { |
|
193 |
// double fontSize = (8 * 1d / zoom); |
|
194 |
// element.setAttribute("font-size", fontSize + "px"); |
|
195 |
// } |
|
196 |
// |
|
197 |
// } |
|
198 |
|
|
199 |
|
|
200 |
// FIXME : old version by matrix transformation |
|
201 |
if (e.getUnitsToScroll() < 0) { |
|
202 |
zoom(e.getX(), e.getY(), true); |
|
203 |
} |
|
204 |
else { |
|
205 |
zoom(e.getX(), e.getY(), false); |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
} |
|
210 |
}); |
|
211 |
|
|
212 |
// add default chart key listener |
|
213 |
this.addKeyListener(new ChartKeyListener(Application.swtComponentProvider2, this, 10.5)); |
|
214 |
|
|
215 |
|
|
216 |
} |
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
/** |
|
225 |
* Loads SVG document from the specified URL. |
|
226 |
* |
|
227 |
* @param url the url |
|
228 |
*/ |
|
229 |
public void loadSVGDocument(String url) { |
|
230 |
this.svgCanvas.loadSVGDocument(url); |
|
231 |
} |
|
232 |
|
|
233 |
|
|
234 |
/** |
|
235 |
* Returns the SVG document. |
|
236 |
* @return |
|
237 |
*/ |
|
238 |
public SVGDocument getSVGDocument() { |
|
239 |
return this.svgCanvas.getSVGDocument(); |
|
240 |
} |
|
241 |
|
|
242 |
|
|
243 |
// ---------------------------------------------------------------------- |
|
244 |
// Interactors |
|
245 |
// ---------------------------------------------------------------------- |
|
246 |
|
|
247 |
/** |
|
248 |
* An interactor to perform a zoom. |
|
249 |
* <p>Binding: BUTTON1 + CTRL Key</p> |
|
250 |
*/ |
|
251 |
protected Interactor zoomInteractor = new AbstractZoomInteractor() { |
|
252 |
@Override |
|
253 |
public boolean startInteraction(InputEvent ie) { |
|
254 |
int mods = ie.getModifiers(); |
|
255 |
return |
|
256 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
257 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
258 |
(mods & InputEvent.CTRL_MASK) != 0; |
|
259 |
} |
|
260 |
}; |
|
261 |
|
|
262 |
/** |
|
263 |
* An interactor to perform a realtime zoom. |
|
264 |
* <p>Binding: BUTTON3 + SHif T Key</p> |
|
265 |
*/ |
|
266 |
protected Interactor imageZoomInteractor = new AbstractImageZoomInteractor() { |
|
267 |
@Override |
|
268 |
public boolean startInteraction(InputEvent ie) { |
|
269 |
int mods = ie.getModifiers(); |
|
270 |
return |
|
271 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
272 |
(mods & InputEvent.BUTTON3_MASK) != 0 && |
|
273 |
(mods & InputEvent.SHIFT_MASK) != 0; |
|
274 |
} |
|
275 |
}; |
|
276 |
|
|
277 |
/** |
|
278 |
* An interactor to perform a translation. |
|
279 |
* <p>Binding: BUTTON1 + SHif T Key</p> |
|
280 |
*/ |
|
281 |
protected Interactor panInteractor = new AbstractPanInteractor() { |
|
282 |
@Override |
|
283 |
public boolean startInteraction(InputEvent ie) { |
|
284 |
int mods = ie.getModifiers(); |
|
285 |
return |
|
286 |
ie.getID() == MouseEvent.MOUSE_PRESSED && |
|
287 |
(mods & InputEvent.BUTTON1_MASK) != 0 && |
|
288 |
(mods & InputEvent.SHIFT_MASK) != 1; |
|
289 |
} |
|
290 |
}; |
|
291 |
|
|
292 |
/** |
|
293 |
* An interactor to reset the rendering transform. |
|
294 |
* <p>Binding: CTRL+SHif T+BUTTON3</p> |
|
295 |
*/ |
|
296 |
protected Interactor resetTransformInteractor = new AbstractResetTransformInteractor() { |
|
297 |
@Override |
|
298 |
public boolean startInteraction(InputEvent ie) { |
|
299 |
int mods = ie.getModifiers(); |
|
300 |
return |
|
301 |
ie.getID() == MouseEvent.MOUSE_CLICKED && |
|
302 |
(mods & InputEvent.BUTTON2_MASK) != 0 && |
|
303 |
(mods & InputEvent.SHIFT_MASK) != 1 && |
|
304 |
(mods & InputEvent.CTRL_MASK) != 1; |
|
305 |
} |
|
306 |
}; |
|
307 |
|
|
308 |
|
|
309 |
/** |
|
310 |
* @return the svgCanvas |
|
311 |
*/ |
|
312 |
public JSVGCanvas getSVGCanvas() { |
|
313 |
return svgCanvas; |
|
314 |
} |
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
/** |
|
320 |
* Resets pan and zoom. |
|
321 |
*/ |
|
322 |
public void resetView() { |
|
323 |
this.zoom = 0; |
|
324 |
AffineTransform trans = AffineTransform.getTranslateInstance(0, 0); |
|
325 |
trans.scale(1, 1); |
|
326 |
this.svgCanvas.setRenderingTransform(trans); |
|
327 |
} |
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
@Override |
|
332 |
public void zoom(double x, double y, boolean zoomIn) { |
|
333 |
|
|
334 |
// FIXME: zoom tests. reset the pan |
|
335 |
|
|
336 |
// TODO Auto-generated method stub |
|
337 |
// x += this.svgCanvas.getRenderingTransform().getTranslateX(); |
|
338 |
// y += this.svgCanvas.getRenderingTransform().getTranslateY(); |
|
339 |
|
|
340 |
|
|
341 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
342 |
|
|
343 |
|
|
344 |
if(zoomIn) { |
|
345 |
trans.scale(this.svgCanvas.getRenderingTransform().getScaleX() * 1.1, this.svgCanvas.getRenderingTransform().getScaleY() * 1.1); |
|
346 |
} |
|
347 |
else { |
|
348 |
trans.scale(this.svgCanvas.getRenderingTransform().getScaleX() * 0.9, this.svgCanvas.getRenderingTransform().getScaleY() * 0.9); |
|
349 |
} |
|
350 |
|
|
351 |
// trans.translate(-x + this.svgCanvas.getRenderingTransform().getTranslateX(), -y + this.svgCanvas.getRenderingTransform().getTranslateY()); |
|
352 |
|
|
353 |
// System.out.println("SVGPanel.zoom2(): " + this.svgCanvas.getRenderingTransform().getTranslateX()); |
|
354 |
|
|
355 |
trans.translate(-x, -y); |
|
356 |
|
|
357 |
|
|
358 |
if(trans.getDeterminant() != 0) { |
|
359 |
this.svgCanvas.setRenderingTransform(trans); |
|
360 |
} |
|
361 |
} |
|
362 |
|
|
363 |
// FIXME: tests zoom |
|
364 |
/** |
|
365 |
* Zoom in or zoom out the panel at the specified origin point coordinates. |
|
366 |
* @param x |
|
367 |
* @param y |
|
368 |
* @param zoom |
|
369 |
*/ |
|
370 |
public void zoom(double x, double y, int zoom) { |
|
371 |
|
|
372 |
// FIXME: the zoom does nothing when zoom is equal to 0 and 1. |
|
373 |
|
|
374 |
AffineTransform trans = AffineTransform.getTranslateInstance(x, y); |
|
375 |
|
|
376 |
int dy = zoom; |
|
377 |
double s; |
|
378 |
if(dy < 0) { |
|
379 |
s = -1f / dy; |
|
380 |
} |
|
381 |
else { |
|
382 |
s = dy; |
|
383 |
} |
|
384 |
|
|
385 |
trans.scale(s, s); |
|
386 |
|
|
387 |
trans.translate(-x, -y); |
|
388 |
|
|
389 |
if(trans.getDeterminant() != 0) { |
|
390 |
this.svgCanvas.setRenderingTransform(trans); |
|
391 |
} |
|
392 |
} |
|
393 |
|
|
394 |
|
|
395 |
@Override |
|
396 |
public void pan(double srcX, double srcY, double dstX, double dstY, double panFactor) { |
|
397 |
|
|
398 |
AffineTransform trans = this.svgCanvas.getRenderingTransform(); |
|
399 |
trans.translate(-dstX * panFactor, dstY * panFactor); |
|
400 |
this.svgCanvas.setRenderingTransform(trans); |
|
401 |
|
|
402 |
} |
|
403 |
|
|
404 |
@Override |
|
405 |
public ChartEditorPart getChartEditor() { |
|
406 |
return this.editor; |
|
407 |
} |
|
408 |
|
|
409 |
@Override |
|
410 |
public void setChartEditor(ChartEditorPart editor) { |
|
411 |
this.editor = editor; |
|
412 |
} |
|
413 |
|
|
414 |
@Override |
|
415 |
public void updateMouseOverItem(MouseEvent event) { |
|
416 |
// TODO Auto-generated method stub |
|
417 |
|
|
418 |
} |
|
419 |
|
|
420 |
|
|
421 |
} |
|
0 | 422 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/editors/___SVGChartEditorInput.java (revision 47) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp.editors; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
6 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput; |
|
7 |
import org.txm.functions.TXMResult; |
|
8 |
|
|
9 |
/** |
|
10 |
* Batik SVG <code>IEditorInput</code> implementation. |
|
11 |
* @author sjacquot |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class ___SVGChartEditorInput extends ChartEditorInput { |
|
15 |
|
|
16 |
|
|
17 |
/** |
|
18 |
* Creates an <code>SVGGraphicEditorInput</code> linked to the specified <code>File</code>. |
|
19 |
* @param file |
|
20 |
* @param resultData |
|
21 |
*/ |
|
22 |
public ___SVGChartEditorInput(SWTChartsComponentsProvider swtComponentsProvider, File file, TXMResult resultData, String preferencesNodeQualifier, String chartType) { |
|
23 |
this(swtComponentsProvider, file, "SVG Batik chart editor input", resultData, preferencesNodeQualifier, chartType); |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* Creates an <code>SVGGraphicEditorInput</code> linked to the specified <code>File</code>. |
|
30 |
* |
|
31 |
* @param file the file |
|
32 |
* @param name the name |
|
33 |
* @param titleImage the tile image |
|
34 |
*/ |
|
35 |
public ___SVGChartEditorInput(SWTChartsComponentsProvider swtComponentsProvider, File file, String name, TXMResult resultData, String preferencesNodeQualifier, String chartType) { |
|
36 |
super(swtComponentsProvider, name, resultData, preferencesNodeQualifier, chartType, file); |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
} |
|
0 | 41 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/editors/___SVGChartEditorPart.java (revision 47) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp.editors; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
6 |
import org.txm.chartsengine.rcp.editors.ChartEditorInput; |
|
7 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
8 |
import org.txm.chartsengine.svgbatik.rcp.swt.SVGComposite; |
|
9 |
import org.txm.functions.TXMResult; |
|
10 |
import org.w3c.dom.svg.SVGDocument; |
|
11 |
|
|
12 |
/** |
|
13 |
* Batik SVG <code>EditorPart</code> containing an <code>SVGComposite</code>. |
|
14 |
* @author sjacquot |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class ___SVGChartEditorPart extends ChartEditorPart { |
|
18 |
|
|
19 |
|
|
20 |
/** |
|
21 |
* The <code>EditorPart</code> ID constant. |
|
22 |
*/ |
|
23 |
protected static final String ID = ___SVGChartEditorPart.class.getCanonicalName(); |
|
24 |
|
|
25 |
|
|
26 |
/** |
|
27 |
* Creates an empty <code>SVGGraphicEditorPart</code>. |
|
28 |
*/ |
|
29 |
public ___SVGChartEditorPart() { |
|
30 |
super(); |
|
31 |
} |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Creates a <code>SVGGraphicEditorPart</code> and links it to the specified result data. |
|
36 |
* @param file the file to display in the editor |
|
37 |
* @param editorInputName the editor input name |
|
38 |
* @param titleImage the title image |
|
39 |
* @param resultData the linked result data |
|
40 |
*/ |
|
41 |
public ___SVGChartEditorPart(SWTChartsComponentsProvider swtComponentsProvider, File file, String editorInputName, TXMResult resultData, String preferencesNodeQualifier, String chartType) { |
|
42 |
this(); |
|
43 |
this.setInput(new ChartEditorInput(swtComponentsProvider, editorInputName, resultData, preferencesNodeQualifier, chartType, file)); |
|
44 |
this.setPartName(editorInputName); |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
/** |
|
50 |
* Creates the context menu. |
|
51 |
*/ |
|
52 |
protected void createContextMenu() { |
|
53 |
// FIXME |
|
54 |
/* |
|
55 |
* Menu menu = new Menu(parent.getShell()); MenuItem item = new MenuItem |
|
56 |
* (menu, SWT.PUSH); item.setText ("Popup"); svgComp.setMenu (menu); |
|
57 |
*/ |
|
58 |
|
|
59 |
/* |
|
60 |
* // Set the MenuManager getSite().registerContextMenu(menuManager, |
|
61 |
* svgComp); // Make the selection available |
|
62 |
* getSite().setSelectionProvider(svgComp); |
|
63 |
*/ |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
@Override |
|
68 |
public String getID() { |
|
69 |
return ___SVGChartEditorPart.ID; |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
@Override |
|
74 |
public SVGComposite getComposite() { |
|
75 |
return (SVGComposite) this.chartComposite; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* Returns the SVG document. |
|
81 |
* @return |
|
82 |
*/ |
|
83 |
public SVGDocument getSVGDocument() { |
|
84 |
return ((SVGComposite) this.chartComposite).getSVGDocument(); |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
} |
|
0 | 90 |
tmp/org.txm.chartsengine.svgbatik.rcp/src/org/txm/chartsengine/svgbatik/rcp/swt/SVGComposite.java (revision 47) | ||
---|---|---|
1 |
package org.txm.chartsengine.svgbatik.rcp.swt; |
|
2 |
import java.awt.BorderLayout; |
|
3 |
import java.awt.EventQueue; |
|
4 |
import java.awt.Frame; |
|
5 |
import java.awt.Panel; |
|
6 |
import java.io.File; |
|
7 |
import java.net.MalformedURLException; |
|
8 |
|
|
9 |
import org.eclipse.swt.awt.SWT_AWT; |
|
10 |
import org.eclipse.swt.widgets.Composite; |
|
11 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
12 |
import org.txm.chartsengine.rcp.events.EventCallBackHandler; |
|
13 |
import org.txm.chartsengine.rcp.swt.ChartComposite; |
|
14 |
import org.txm.chartsengine.svgbatik.rcp.swing.SVGPanel; |
|
15 |
import org.txm.utils.logger.Log; |
|
16 |
import org.w3c.dom.svg.SVGDocument; |
|
17 |
|
|
18 |
|
|
19 |
/** |
|
20 |
* Batik SVG SWT composite. |
|
21 |
* @author sjacquot |
|
22 |
* |
|
23 |
*/ |
|
24 |
public class SVGComposite extends ChartComposite { |
|
25 |
|
|
26 |
// FIXME: useless ? for reducing the flickering on resize under Window but it doesn't seem to work |
|
27 |
// static |
|
28 |
// { |
|
29 |
// System.setProperty("sun.awt.noerasebackground", "true"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
30 |
// } |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* The loaded SVG file. |
|
36 |
*/ |
|
37 |
protected File file; |
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
/** |
|
42 |
* Creates a Batik SVG composite. |
|
43 |
* @param parent |
|
44 |
* @param style |
|
45 |
*/ |
|
46 |
public SVGComposite(ChartEditorPart chartEditor, Composite parent, int style) { |
|
47 |
super(chartEditor, parent, style); |
|
48 |
|
|
49 |
|
|
50 |
this.file = null; |
|
51 |
|
|
52 |
Frame frame = SWT_AWT.new_Frame(this); |
|
53 |
|
|
54 |
// Need to add an AWT Panel to fix mouse events and mouse cursors changes on Swing JPanel |
|
55 |
Panel rootPanel = new Panel(new BorderLayout()); |
|
56 |
this.chartComponent = new SVGPanel(chartEditor, frame); |
|
57 |
rootPanel.add(this.getPanel()); |
|
58 |
frame.add(rootPanel); |
|
59 |
frame.pack(); |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
/** |
|
66 |
* Loads a SVG document from the specified file. |
|
67 |
* @param file the file to load |
|
68 |
*/ |
|
69 |
public void loadSVGDocument(File file) { |
|
70 |
if(file == null) { |
|
71 |
Log.severe("SVG File doesn't exist."); |
|
72 |
return; |
|
73 |
} |
|
74 |
this.file = file; |
|
75 |
Log.info("Loading SVG document from file: " + file); |
|
76 |
try { |
|
77 |
this.getPanel().loadSVGDocument(file.toURL().toExternalForm()); |
|
78 |
} |
|
79 |
catch(MalformedURLException e) { |
|
80 |
Log.severe("Can't load SVG document from file: " + file + e); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
/** |
|
87 |
* Gets the SVG document. |
|
88 |
* @return |
|
89 |
*/ |
|
90 |
public SVGDocument getSVGDocument() { |
|
91 |
return this.getPanel().getSVGDocument(); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Gets the SVG panel. |
|
96 |
* @return the panel |
|
97 |
*/ |
|
98 |
public SVGPanel getPanel() { |
|
99 |
return (SVGPanel) this.chartComponent; |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
@Override |
|
104 |
public void requestFocusInComposite() { |
|
105 |
EventQueue.invokeLater(new Runnable () { |
|
106 |
public void run () { |
|
107 |
getPanel().requestFocusInWindow(); |
|
108 |
} |
|
109 |
}); |
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
@Override |
|
114 |
public void reloadChart() { |
|
115 |
// Reload the file if exists |
|
116 |
// if(this.file != null) { |
|
117 |
// this.loadSVGDocument(this.file); |
|
118 |
// } |
|
119 |
// else { |
|
120 |
this.file = (File) this.chartEditor.getEditorInput().getChartContainer(); |
|
121 |
this.loadSVGDocument(this.file); |
|
122 |
// } |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
@Override |
|
127 |
public void loadChart(Object data) { |
|
128 |
this.loadSVGDocument((File) data); |
|
129 |
} |
|
130 |
|
|
131 |
@Override |
|
132 |
public Object getChart() { |
|
133 |
return this.file; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
@Override |
|
138 |
public EventCallBackHandler getMouseCallBackHandler() { |
|
139 |
return super.getMouseCallBackHandler(this.getPanel()); |
|
140 |
} |
|
141 |
|
|
142 |
|
|
143 |
@Override |
|
144 |
public EventCallBackHandler getKeyCallBackHandler() { |
|
145 |
return super.getKeyCallBackHandler(this.getPanel()); |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
} |
|
0 | 151 |
Formats disponibles : Unified diff