EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation]

COVERAGE SUMMARY FOR SOURCE FILE [AbstractJFreeChartChart.java]

nameclass, %method, %block, %line, %
AbstractJFreeChartChart.java0%   (0/4)0%   (0/9)0%   (0/272)0%   (0/65)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractJFreeChartChart0%   (0/1)0%   (0/3)0%   (0/47)0%   (0/12)
AbstractJFreeChartChart (Composite, int): void 0%   (0/1)0%   (0/7)0%   (0/3)
createPopupMenu (boolean, boolean, boolean, boolean): Menu 0%   (0/1)0%   (0/21)0%   (0/5)
initializeContextMenu (MenuManager): void 0%   (0/1)0%   (0/19)0%   (0/4)
     
class SaveImageAsAction0%   (0/1)0%   (0/2)0%   (0/71)0%   (0/16)
SaveImageAsAction (AbstractJFreeChartChart): void 0%   (0/1)0%   (0/9)0%   (0/4)
run (): void 0%   (0/1)0%   (0/62)0%   (0/12)
     
class SaveSVGAsAction0%   (0/1)0%   (0/2)0%   (0/115)0%   (0/25)
SaveSVGAsAction (AbstractJFreeChartChart): void 0%   (0/1)0%   (0/9)0%   (0/4)
run (): void 0%   (0/1)0%   (0/106)0%   (0/21)
     
class ToggleLegendAction0%   (0/1)0%   (0/2)0%   (0/39)0%   (0/12)
ToggleLegendAction (AbstractJFreeChartChart): void 0%   (0/1)0%   (0/12)0%   (0/5)
run (): void 0%   (0/1)0%   (0/27)0%   (0/7)

1package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation;
2 
3import java.awt.Color;
4import java.awt.Paint;
5import java.awt.Rectangle;
6import java.io.File;
7import java.io.FileOutputStream;
8import java.io.IOException;
9import java.io.OutputStreamWriter;
10import java.io.Writer;
11import java.util.Collection;
12 
13import org.apache.batik.dom.GenericDOMImplementation;
14import org.apache.batik.svggen.SVGGraphics2D;
15import org.eclipse.jface.action.Action;
16import org.eclipse.jface.action.MenuManager;
17import org.eclipse.swt.SWT;
18import org.eclipse.swt.widgets.Composite;
19import org.eclipse.swt.widgets.FileDialog;
20import org.eclipse.swt.widgets.Menu;
21import org.eclipse.ui.PlatformUI;
22import org.jfree.chart.ChartUtilities;
23import org.jfree.chart.JFreeChart;
24import org.jfree.chart.title.LegendTitle;
25import org.jfree.experimental.chart.swt.ChartComposite;
26import org.w3c.dom.DOMImplementation;
27import org.w3c.dom.Document;
28 
29class SaveImageAsAction extends Action {
30 
31 
32        private AbstractJFreeChartChart<?> chartViewer;
33 
34        public SaveImageAsAction(AbstractJFreeChartChart<?> abstractJFreeChartChart) {
35                super();
36                setText("Save Chart as PNG...");
37                this.chartViewer = abstractJFreeChartChart;
38        }
39        
40        @Override
41        public void run() {
42                FileDialog dialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
43                dialog.setFilterExtensions(new String[]{"*.png"});
44                dialog.setText("Enter the image file name");
45                dialog.open();
46                if (dialog.getFileName() != null){
47                        String filename = dialog.getFilterPath()+File.separator+dialog.getFileName();
48                        File f = new File(filename);
49                        JFreeChart chart = chartViewer.getChart();
50                        try {
51                                ChartUtilities.saveChartAsPNG(f, chart, chartViewer.getBounds().width, chartViewer.getBounds().height);
52                        } catch (IOException e) {
53                                // TODO Auto-generated catch block
54                                e.printStackTrace();
55                        }
56                }
57        }
58}
59 
60class ToggleLegendAction extends Action {
61 
62 
63        private AbstractJFreeChartChart<?> chartViewer;
64        private LegendTitle chartLegend;
65 
66        public ToggleLegendAction(AbstractJFreeChartChart<?> abstractJFreeChartChart) {
67                super();
68                setText("Enable/Disable Legend");
69                this.chartViewer = abstractJFreeChartChart;
70                this.chartLegend = null;
71        }
72        
73        @Override
74        public void run() {
75                if (chartLegend == null) {
76                        chartLegend = this.chartViewer.getChart().getLegend();
77                        this.chartViewer.getChart().removeLegend();
78                } else {
79                        this.chartViewer.getChart().addLegend(chartLegend);
80                        chartLegend = null;
81                }
82                this.chartViewer.forceRedraw();
83        }
84}
85 
86class SaveSVGAsAction extends Action {
87 
88 
89        private AbstractJFreeChartChart<?> chartViewer;
90 
91        public SaveSVGAsAction(AbstractJFreeChartChart<?> abstractJFreeChartChart) {
92                super();
93                setText("Save Chart as SVG...");
94                this.chartViewer = abstractJFreeChartChart;
95        }
96        
97        @Override
98        public void run() {
99                FileDialog dialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
100                dialog.setFilterExtensions(new String[]{"*.svg"});
101                dialog.setText("Enter the image file name");
102                dialog.open();
103                if (dialog.getFileName() != null){
104                        String filename = dialog.getFilterPath()+File.separator+dialog.getFileName();
105                        File f = new File(filename);
106                        JFreeChart chart = chartViewer.getChart();
107                        try {
108                                DOMImplementation domI = new GenericDOMImplementation();
109                                Document doc = domI.createDocument(null, "svg", null);
110                                SVGGraphics2D svgRenderer = new SVGGraphics2D(doc);
111                                Paint p = chart.getBackgroundPaint();
112                                chart.setBackgroundPaint(new Color(0, 0, 0, 0));
113                                chart.draw(svgRenderer, new Rectangle(0,0,640,480));
114                                chart.setBackgroundPaint(p);
115                                Writer out = new OutputStreamWriter(new FileOutputStream(f),"UTF-8");
116                                svgRenderer.stream(out,true);
117                                out.close();
118                        } catch (IOException e) {
119                                e.printStackTrace();
120                        }
121                }
122        }
123}
124 
125public abstract class AbstractJFreeChartChart<T> extends ChartComposite {
126        protected JFreeChart chart;
127        
128        @Override
129        protected Menu createPopupMenu(boolean arg0, boolean arg1, boolean arg2,
130                        boolean arg3) {
131                Menu parentMenu = super.createPopupMenu(arg0, arg1, arg2, arg3);
132                MenuManager menu_manager = new MenuManager("Additional Functions");
133            initializeContextMenu(menu_manager);
134            menu_manager.fill(parentMenu,SWT.NONE);
135            return parentMenu;
136        }
137 
138        public AbstractJFreeChartChart(Composite parent, int style) {
139                super(parent, style);
140                // final Graphics2DRenderer renderer = new Graphics2DRenderer();
141                initChart();
142 
143//            
144//                addPaintListener(new PaintListener() {
145//
146//                        public void paintControl(org.eclipse.swt.events.PaintEvent e) {
147//                            Point controlSize = ((Control) e.getSource()).getSize();
148//
149//                            GC gc = e.gc; // gets the SWT graphics context from the event
150//
151//                            renderer.prepareRendering(gc); // prepares the Graphics2D renderer
152//
153//                            // gets the Graphics2D context and switch on the antialiasing
154//                            Graphics2D g2d = renderer.getGraphics2D();
155//                            
156//                                if(myChart != null)
157//                                        myChart.draw(g2d, new Rectangle(0,0,controlSize.x,controlSize.y));
158//                                else
159//                                        g2d.drawString("No data yet", 5, 20);
160//                            // now that we are done with Java 2D, renders Graphics2D operation
161//                            // on the SWT graphics context
162//                            renderer.render(gc);
163//                            
164//                          }
165//                });
166        }
167        
168        protected void initializeContextMenu(MenuManager menu_manager) {
169                menu_manager.add(new ToggleLegendAction(this));
170                menu_manager.add(new SaveImageAsAction(this));
171                menu_manager.add(new SaveSVGAsAction(this));
172        }
173 
174        protected abstract void initChart();
175        
176        public abstract void setData(Collection<T> data);
177        
178}

[all classes][de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov