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

COVERAGE SUMMARY FOR SOURCE FILE [AbstractJFreeChartWidthReport.java]

nameclass, %method, %block, %line, %
AbstractJFreeChartWidthReport.java0%   (0/2)0%   (0/12)0%   (0/367)0%   (0/95)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractJFreeChartWidthReport0%   (0/1)0%   (0/10)0%   (0/336)0%   (0/86)
AbstractJFreeChartWidthReport (): void 0%   (0/1)0%   (0/9)0%   (0/4)
access$0 (AbstractJFreeChartWidthReport, double): void 0%   (0/1)0%   (0/4)0%   (0/1)
addInput (Collection): void 0%   (0/1)0%   (0/1)0%   (0/1)
createReportControls (Composite): void 0%   (0/1)0%   (0/121)0%   (0/29)
deleteInput (Collection): void 0%   (0/1)0%   (0/1)0%   (0/1)
generateVisualization (List): void 0%   (0/1)0%   (0/102)0%   (0/24)
isSameWidth (List): boolean 0%   (0/1)0%   (0/39)0%   (0/11)
setFocus (): void 0%   (0/1)0%   (0/5)0%   (0/2)
setInput (Collection): void 0%   (0/1)0%   (0/15)0%   (0/3)
updateHistogramWidth (double): void 0%   (0/1)0%   (0/39)0%   (0/10)
     
class AbstractJFreeChartWidthReport$10%   (0/1)0%   (0/2)0%   (0/31)0%   (0/10)
AbstractJFreeChartWidthReport$1 (AbstractJFreeChartWidthReport): void 0%   (0/1)0%   (0/6)0%   (0/2)
handleEvent (Event): void 0%   (0/1)0%   (0/25)0%   (0/8)

1package de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation.editor;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6import java.util.Properties;
7 
8import org.eclipse.swt.SWT;
9import org.eclipse.swt.layout.GridData;
10import org.eclipse.swt.layout.GridLayout;
11import org.eclipse.swt.layout.RowData;
12import org.eclipse.swt.layout.RowLayout;
13import org.eclipse.swt.widgets.Composite;
14import org.eclipse.swt.widgets.Event;
15import org.eclipse.swt.widgets.Label;
16import org.eclipse.swt.widgets.Listener;
17import org.eclipse.swt.widgets.Text;
18 
19import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.Histogram;
20import de.uka.ipd.sdq.sensorframework.adapter.DataAdapter;
21import de.uka.ipd.sdq.sensorframework.adapter.TimeSpanToHistogramAdapter;
22import de.uka.ipd.sdq.sensorframework.visualisation.IVisualisation;
23import de.uka.ipd.sdq.sensorframework.visualisation.editor.AbstractReportView;
24import de.uka.ipd.sdq.sensorframework.visualisation.jfreechartvisualisation.AbstractJFreeChartWidthViewer;
25 
26/**Report for Histograms.
27 * Provides the basic possibilities to generate histograms and change their classes width.
28 * @author groenda
29 */
30public abstract class AbstractJFreeChartWidthReport extends AbstractReportView implements IVisualisation<Histogram>{
31 
32        AbstractJFreeChartWidthViewer viewer;
33        protected Text widthInput;
34        protected double histogramWidth = Double.NaN;
35        private List<DataAdapter> adapterList = null;
36        
37        public AbstractJFreeChartWidthReport() {
38                super();
39        }
40        
41        protected abstract AbstractJFreeChartWidthViewer createViewer(Composite parent, int flags);
42 
43        /** {@inheritDoc}
44         */
45        @Override
46        protected void createReportControls(Composite parent) {
47                GridLayout gridLayout = new GridLayout();
48                gridLayout.numColumns = 1;
49                parent.setLayout(gridLayout);
50                Composite histogramWidthPanel = new Composite(parent, SWT.NONE);
51                GridData data = new GridData();
52                data.grabExcessHorizontalSpace = true;
53                histogramWidthPanel.setLayoutData(data);
54                RowLayout rowLayout = new RowLayout();
55                rowLayout.wrap = false;
56                rowLayout.pack = true;
57                histogramWidthPanel.setLayout(rowLayout);
58                Label label = new Label(histogramWidthPanel, SWT.CENTER);
59                label.setText("Sampling Rate");
60                label.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT));
61                widthInput = new Text(histogramWidthPanel, SWT.BORDER);
62                widthInput.setText(Double.toString(histogramWidth));
63                widthInput.setLayoutData(new RowData(60, SWT.DEFAULT));
64                Listener listener = new Listener() {
65 
66                        public void handleEvent(Event event) {
67                                switch (event.type) {
68                                case SWT.KeyDown:
69                                        if (event.character == SWT.CR)
70                                                updateHistogramWidth(Double.parseDouble(widthInput
71                                                        .getText()));
72                                        break;
73                                case SWT.FocusOut:
74                                        updateHistogramWidth(Double.parseDouble(widthInput
75                                                        .getText()));
76                                        break;
77                                }
78                        }
79 
80                };
81                widthInput.addListener(SWT.KeyDown, listener);
82                widthInput.addListener(SWT.FocusOut, listener);
83 
84                viewer = createViewer(parent, SWT.NONE);
85                GridData data2 = new GridData();
86                data2.grabExcessHorizontalSpace = true;
87                data2.grabExcessVerticalSpace = true;
88                data2.verticalAlignment = GridData.FILL;
89                data2.horizontalAlignment = GridData.FILL;
90                viewer.setLayoutData(data2);
91                histogramWidthPanel.setLayoutData(data);
92        }
93 
94        /**Updates the histogram width after a change on the gui.
95         * @param newWidth The new width to set.
96         */
97        private void updateHistogramWidth(double newWidth) {
98                this.histogramWidth = newWidth;
99 
100                setIgnoreDataSettingsChanged(true);
101                // Set new histogram width on all adapters of this report
102                for (DataAdapter adapter : adapterList) {
103                        Properties adapterProperties = adapter.getProperties();
104                        adapterProperties.put(TimeSpanToHistogramAdapter.HISTOGRAM_WIDTH, 
105                                        histogramWidth);
106                        adapter.setProperties(adapterProperties);
107                }
108                setIgnoreDataSettingsChanged(false);
109                generateVisualization(adapterList);
110        }
111        
112        /** {@inheritDoc}
113         */
114        public void setInput(Collection<Histogram> histograms) {
115                viewer.setData(histograms);
116                this.widthInput.setText(""+histogramWidth);
117        }
118 
119        /** {@inheritDoc}
120         */
121        @Override
122        protected void generateVisualization(List<DataAdapter> newList) {
123                if (newList == null || newList.isEmpty())
124                        throw new RuntimeException("Histogram reports must have at least one data input.");
125                Properties adapterProperties = null;
126                // Determine width of "old" histogram, if existing
127                double newWidth = Double.NaN;
128                if (adapterList != null && adapterList.isEmpty() == false) {
129                        DataAdapter adapter = adapterList.get(0);
130                        adapterProperties = adapter.getProperties();
131                        Double test = (Double) adapterProperties.get(TimeSpanToHistogramAdapter.HISTOGRAM_WIDTH); 
132                        newWidth = test;
133                } else {
134                        // this is the first data added
135                        DataAdapter adapter = newList.get(0);
136                        adapterProperties = adapter.getProperties();
137                        newWidth = (Double) adapterProperties.get(TimeSpanToHistogramAdapter.HISTOGRAM_WIDTH);
138                }
139                
140                boolean allSameWidth = isSameWidth(newList);
141                
142                /* Set all histograms to the same histogram width and add histograms
143                 * to the current view.
144                 */
145                ArrayList<Histogram> newHistogramList = new ArrayList<Histogram>();
146                for (DataAdapter adapter : newList) {
147                        if (!allSameWidth) {
148                                adapterProperties = adapter.getProperties();
149                                adapterProperties.put(TimeSpanToHistogramAdapter.HISTOGRAM_WIDTH, newWidth);
150                                // Note: The property change will notify all listeners, so be careful
151                                adapter.setProperties(adapterProperties);
152                        }
153                        newHistogramList.add((Histogram) adapter.getAdaptedObject());
154                }
155                histogramWidth = newWidth; // set view-local cached version to new value
156                adapterList = newList;
157 
158                this.setInput(newHistogramList);
159        }
160 
161        /**Checks if the adapters all have the same histogram width.
162         * @param adapterList The list of adapters to check.
163         * @return <code>true</code> if all have the same width.
164         */
165        private boolean isSameWidth(List<DataAdapter> adapterList) {
166                Properties adapterProperties;
167                boolean allSameWidth = true;
168                double width = Double.NaN;
169                double currentWidth = Double.NaN;
170                for (DataAdapter adapter : adapterList) {
171                        adapterProperties = adapter.getProperties();
172                        currentWidth = (Double) adapterProperties.get(TimeSpanToHistogramAdapter.HISTOGRAM_WIDTH);
173                        if (Double.isNaN(width)) {
174                                width = currentWidth;
175                        }
176                        if (width != currentWidth) {
177                                allSameWidth = false;
178                        }
179                }
180                return allSameWidth;
181        }
182 
183 
184        /** {@inheritDoc}
185         */
186        @Override
187        public void setFocus() {
188                viewer.setFocus();
189        }
190 
191        /** {@inheritDoc}
192         */
193        public void addInput(Collection<Histogram> c) {
194                // The implementation is not necessary.
195        }
196        
197        /** {@inheritDoc}
198         */
199        public void deleteInput(Collection<Histogram> c) {
200                // The implementation is not necessary.
201        }
202}

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