KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > visualizers > GraphAccumVisualizer


1 // $Header: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/GraphAccumVisualizer.java,v 1.14 2004/03/05 01:33:33 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.visualizers;
20
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.awt.Image JavaDoc;
25
26 import javax.swing.BorderFactory JavaDoc;
27 import javax.swing.BoxLayout JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31 import javax.swing.JSplitPane JavaDoc;
32 import javax.swing.border.Border JavaDoc;
33 import javax.swing.border.EmptyBorder JavaDoc;
34
35 import org.apache.jmeter.samplers.Clearable;
36 import org.apache.jmeter.samplers.SampleResult;
37 import org.apache.jmeter.util.JMeterUtils;
38 import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
39 import org.apache.jorphan.logging.LoggingManager;
40 import org.apache.log.Logger;
41
42
43 /**
44  * This class implements a statistical analyser that plots the accumulated time
45  * taken to load each set of pages. The number of plots is equivalent to the
46  * number of times the set of pages is configured to load.
47  *
48  *
49  * Created 2001/08/11
50  * @version $Revision: 1.14 $ $Date: 2004/03/05 01:33:33 $
51  */

52 public class GraphAccumVisualizer extends AbstractVisualizer
53         implements ImageVisualizer, GraphAccumListener, Clearable
54 {
55     transient private static Logger log = LoggingManager.getLoggerForClass();
56
57     protected transient GraphAccumModel model;
58     protected transient GraphAccum graph;
59     transient protected JPanel JavaDoc legendPanel;
60
61     /**
62      * Constructor.
63      */

64     public GraphAccumVisualizer()
65     {
66         super();
67         model = new GraphAccumModel();
68         model.addGraphAccumListener(this);
69         init();
70         log.debug("Start : GraphAccumVisualizer1");
71         log.debug("End : GraphAccumVisualizer1");
72     }
73
74     public String JavaDoc getLabelResource()
75     {
76         return "graph_full_results_title";
77     }
78
79     public void add(SampleResult res)
80     {
81         model.addNewSample(res);
82     }
83
84     /**
85      * Returns the panel where labels can be added.
86      *
87      * @return a panel where labels can be added
88      */

89     public Object JavaDoc getWhiteCanvas()
90     {
91         return legendPanel;
92     }
93
94     /**
95      * Gets the Image attribute of the GraphVisualizer object.
96      *
97      * @return the Image value
98      */

99     public Image JavaDoc getImage()
100     {
101         log.debug("Start : getImage1");
102         Image JavaDoc result = graph.createImage(graph.getWidth(), graph.getHeight());
103
104         graph.paintComponent(result.getGraphics());
105         log.debug("End : getImage1");
106         return result;
107     }
108
109     /**
110      * Updates the gui to reflect changes.
111      */

112     public void updateGui()
113     {
114         log.debug("Start : updateGui1");
115         graph.updateGui();
116         log.debug("End : updateGui1");
117     }
118
119     /**
120      * Updates gui to reflect small changes.
121      *
122      * @param s sample to be added to plot
123      */

124     public void updateGui(SampleResult s)
125     {
126         log.debug("Start : updateGui2");
127         log.debug("End : updateGui2");
128     }
129
130     /**
131      * Clear this visualizer data.
132      */

133     public synchronized void clear()
134     {
135         model.clear();
136         graph.clear();
137         log.debug("Start : clear1");
138         repaint();
139         log.debug("End : clear1");
140     }
141
142     /**
143      * Returns a description of this instance.
144      *
145      * @return description of this instance
146      */

147     public String JavaDoc toString()
148     {
149         String JavaDoc toString = "Show the samples analysys as dot plots";
150
151         log.debug("toString1 : Returning - " + toString);
152         return toString;
153     }
154
155     /**
156      * Setup all the swing components.
157      */

158     private void init()
159     {
160         log.debug("Start : init1");
161         graph = new GraphAccum(model);
162         graph.setVisualizer(this);
163
164         this.setLayout(new BorderLayout JavaDoc());
165
166         // MAIN PANEL
167
JPanel JavaDoc mainPanel = new JPanel JavaDoc();
168         Border JavaDoc margin = new EmptyBorder JavaDoc(10, 10, 5, 10);
169
170         mainPanel.setBorder(margin);
171         mainPanel.setLayout(new BoxLayout JavaDoc(mainPanel, BoxLayout.Y_AXIS));
172
173         // TITLE
174
JLabel JavaDoc panelTitleLabel =
175             new JLabel JavaDoc(JMeterUtils.getResString("graph_full_results_title"));
176         Font JavaDoc curFont = panelTitleLabel.getFont();
177         int curFontSize = curFont.getSize();
178
179         curFontSize += 4;
180         panelTitleLabel.setFont(
181             new Font JavaDoc(curFont.getFontName(), curFont.getStyle(), curFontSize));
182         mainPanel.add(panelTitleLabel);
183
184         mainPanel.add(getNamePanel());
185         mainPanel.add(getFilePanel());
186
187         JScrollPane JavaDoc graphScrollPanel = new
188                 JScrollPane JavaDoc(graph, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
189                 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
190
191         graphScrollPanel.setViewportBorder(
192                 BorderFactory.createEmptyBorder(2, 2, 2, 2));
193         legendPanel = new JPanel JavaDoc();
194
195         JScrollPane JavaDoc legendScrollPanel = new JScrollPane JavaDoc(legendPanel);
196         JSplitPane JavaDoc graphSplitPane = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT,
197                 graphScrollPanel, legendScrollPanel);
198
199         this.add(mainPanel, BorderLayout.NORTH);
200         this.add(graphSplitPane, BorderLayout.CENTER);
201         log.debug("End : init1");
202     }
203 }
204
Popular Tags