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 CopyClipboardAsR extends Action { |
12 | |
13 | private ISeriesExporter viewer; |
14 | |
15 | public CopyClipboardAsR(ISeriesExporter freeChartHistogramViewer) { |
16 | super(); |
17 | setText("Copy Values to Clipboard using R format..."); |
18 | this.viewer = freeChartHistogramViewer; |
19 | } |
20 | |
21 | @Override |
22 | public void run() { |
23 | exportValues(viewer.getSeries()); |
24 | } |
25 | |
26 | private void exportValues(XYSeries series) { |
27 | Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay()); |
28 | StringBuffer plainText = new StringBuffer("c("); |
29 | for(Object item : series.getItems()){ |
30 | XYDataItem data = (XYDataItem) item; |
31 | plainText.append(data.getY()+","); |
32 | } |
33 | TextTransfer textTransfer = TextTransfer.getInstance(); |
34 | clipboard.setContents(new String[] { plainText.substring(0, plainText.length()-1)+")" }, |
35 | new Transfer[] { textTransfer }); |
36 | clipboard.dispose(); |
37 | } |
38 | } |