1 | package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation; |
2 | |
3 | import org.eclipse.jface.action.Action; |
4 | import org.eclipse.swt.dnd.Clipboard; |
5 | import org.eclipse.swt.dnd.TextTransfer; |
6 | import org.eclipse.swt.dnd.Transfer; |
7 | import org.eclipse.ui.PlatformUI; |
8 | import org.jfree.data.xy.XYDataItem; |
9 | import org.jfree.data.xy.XYSeries; |
10 | |
11 | public class ExportDoublePDF extends Action { |
12 | |
13 | private IHistSeriesExporter viewer; |
14 | |
15 | public ExportDoublePDF(IHistSeriesExporter freeChartHistogramViewer) { |
16 | super(); |
17 | setText("Copy to Clipboard as DoublePDF..."); |
18 | this.viewer = freeChartHistogramViewer; |
19 | } |
20 | |
21 | @Override |
22 | public void run() { |
23 | String pdf = exportCSV(viewer.getSeries()); |
24 | Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay()); |
25 | TextTransfer textTransfer = TextTransfer.getInstance(); |
26 | clipboard.setContents(new String[] { pdf }, |
27 | new Transfer[] { textTransfer }); |
28 | clipboard.dispose(); |
29 | } |
30 | |
31 | private String exportCSV(XYSeries series) { |
32 | String result = "DoublePDF["; |
33 | double lastProb = 0; |
34 | double lastX = 0; |
35 | for(Object item : series.getItems()){ |
36 | XYDataItem data = (XYDataItem) item; |
37 | result += "(" + (data.getX().doubleValue() - viewer.getHistogramWidth() / 2) + ";" + lastProb + ")"; |
38 | lastProb = data.getY().doubleValue(); |
39 | lastX = data.getX().doubleValue(); |
40 | } |
41 | return result + "("+(lastX+viewer.getHistogramWidth()/2)+";"+lastProb+")]"; |
42 | } |
43 | } |