<?xml version="1.0" encoding="UTF-8"?>\r
-<?eclipse version="3.4"?>\r<!--\r
+<?eclipse version="3.4"?>\r
+<!--\r
Copyright (c) 2010 Association for Decentralized Information Management in\r
Industry THTH ry.\r
All rights reserved. This program and the accompanying materials\r
Contributors:\r
VTT Technical Research Centre of Finland - initial API and implementation\r
-->\r
-
+\r
<plugin>\r
<extension\r
point="org.eclipse.ui.editors">\r
style="toggle"\r
tooltip="Pins the trend so that it does not react to selection changes">\r
</command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.trend.view.png"\r
+ icon="icons/images.png"\r
+ label="Export to PNG"\r
+ style="push"\r
+ tooltip="Exports the trend to PNG file">\r
+ </command>\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.trend.view.svg"\r
+ icon="icons/map.png"\r
+ label="Export to SVG"\r
+ style="push"\r
+ tooltip="Exports the trend to SVG file">\r
+ </command>\r
</menuContribution>\r
<menuContribution\r
locationURI="popup:#SysdynBrowserPopup?after=wbStart">\r
id="org.simantics.sysdyn.ui.trend.view.pin.state">\r
</state>\r
</command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.trend.view.png"\r
+ name="Export to PNG">\r
+ </command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.trend.view.svg"\r
+ name="Export to SVG">\r
+ </command>\r
<command\r
id="org.simantics.sysdyn.ui.showModule"\r
name="Show Module">\r
class="org.simantics.sysdyn.ui.trend.PinTrend"\r
commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.trend.TrendToPng"\r
+ commandId="org.simantics.sysdyn.ui.trend.view.png">\r
+ </handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.trend.TrendToSvg"\r
+ commandId="org.simantics.sysdyn.ui.trend.view.svg">\r
+ </handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.ShowModuleHandler"\r
commandId="org.simantics.sysdyn.ui.showModule">\r
--- /dev/null
+package org.simantics.sysdyn.ui.trend;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.jfree.chart.ChartUtilities;\r
+import org.jfree.chart.JFreeChart;\r
+\r
+public class TrendToPng extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ int width = TrendView.panel.getSize().width;\r
+ int height = TrendView.panel.getSize().height;\r
+ int compressionLevel = 0;\r
+ \r
+ final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Export trend to PNG");\r
+ String[] ext = {"*.png"};\r
+ fd.setFilterExtensions(ext);\r
+ String selected = fd.open();\r
+ \r
+ if (!(selected == null)){\r
+ File file = new File(selected);\r
+ JFreeChart chart = TrendView.chart;\r
+\r
+ try {\r
+ ChartUtilities.saveChartAsPNG(file, chart, width, height, null, true, compressionLevel);\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.sysdyn.ui.trend;\r
+\r
+//import java.awt.geom.Rectangle2D;\r
+//import java.io.File;\r
+//import java.io.FileNotFoundException;\r
+//import java.io.FileOutputStream;\r
+//import java.io.OutputStreamWriter;\r
+//import java.io.UnsupportedEncodingException;\r
+//import java.io.Writer;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+//import org.eclipse.swt.SWT;\r
+//import org.eclipse.swt.widgets.FileDialog;\r
+//import org.eclipse.swt.widgets.Shell;\r
+//import org.eclipse.ui.handlers.HandlerUtil;\r
+//import org.jfree.chart.JFreeChart;\r
+//import org.w3c.dom.DOMImplementation;\r
+//import org.w3c.dom.Document;\r
+//import org.apache.batik.*;\r
+//import org.apache.batik.dom.GenericDOMImplementation;\r
+//import org.apache.batik.svggen.SVGGraphics2D;\r
+//import org.apache.batik.svggen.SVGGraphics2DIOException;\r
+\r
+//This class needs Batik libraries to be imported, if SVG picture is really needed.\r
+\r
+public class TrendToSvg extends AbstractHandler {\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+// final Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+// FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+// fd.setText("Export trend to PNG");\r
+// String[] ext = {"*.svg"};\r
+// fd.setFilterExtensions(ext);\r
+// String selected = fd.open();\r
+// \r
+// File file = new File(selected);\r
+// JFreeChart chart = TrendView.chart;\r
+// \r
+// DOMImplementation domImpl\r
+// = GenericDOMImplementation.getDOMImplementation();\r
+// // Create an instance of org.w3c.dom.Document\r
+// Document document = domImpl.createDocument(null, "svg", null);\r
+// // Create an instance of the SVG Generator\r
+// SVGGraphics2D svgGenerator = new SVGGraphics2D(document);\r
+// // set the precision to avoid a null pointer exception in Batik 1.5\r
+// svgGenerator.getGeneratorContext().setPrecision(6);\r
+// // Ask the chart to render into the SVG Graphics2D implementation\r
+// chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);\r
+// // Finally, stream out SVG to a file using UTF-8 character to\r
+// // byte encoding\r
+// boolean useCSS = true;\r
+// Writer out = null;\r
+// try {\r
+// out = new OutputStreamWriter(\r
+// new FileOutputStream(file), "UTF-8");\r
+// } catch (UnsupportedEncodingException e) {\r
+// e.printStackTrace();\r
+// } catch (FileNotFoundException e) {\r
+// e.printStackTrace();\r
+// }\r
+// try {\r
+// svgGenerator.stream(out, useCSS);\r
+// } catch (SVGGraphics2DIOException e) {\r
+// e.printStackTrace();\r
+// }\r
+ System.out.println("Add Batik-libraries");\r
+ return null;\r
+ }\r
+ \r
+}
\ No newline at end of file
public class TrendView extends ViewPart {\r
\r
Frame frame;\r
- ChartPanel panel;\r
+ public static ChartPanel panel;\r
SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
SysdynDatasetSelectionListener sysdynDatasetSelectionListener;\r
+ public static JFreeChart chart;\r
\r
@SuppressWarnings("serial")\r
class SysdynDatasets extends AbstractXYDataset {\r
new XYLineAndShapeRenderer(true, false)\r
);\r
\r
- JFreeChart chart = new JFreeChart(plot);\r
+ chart = new JFreeChart(plot);\r
panel = new ChartPanel(chart);\r
frame.add(panel);\r
-\r
panel.requestFocus();\r
}\r
\r
if(panel != null)\r
panel.requestFocus();\r
}\r
+ \r
+\r
\r
\r
}\r