001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.visualizers;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Font;
023: import java.awt.Image;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.BoxLayout;
027: import javax.swing.JLabel;
028: import javax.swing.JPanel;
029: import javax.swing.JScrollPane;
030: import javax.swing.JSplitPane;
031: import javax.swing.border.Border;
032: import javax.swing.border.EmptyBorder;
033:
034: import org.apache.jmeter.samplers.Clearable;
035: import org.apache.jmeter.samplers.SampleResult;
036: import org.apache.jmeter.util.JMeterUtils;
037: import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
038: import org.apache.jorphan.logging.LoggingManager;
039: import org.apache.log.Logger;
040:
041: /**
042: * This class implements a statistical analyser that plots the accumulated time
043: * taken to load each set of pages. The number of plots is equivalent to the
044: * number of times the set of pages is configured to load.
045: *
046: *
047: * Created 2001/08/11
048: */
049: public class GraphAccumVisualizer extends AbstractVisualizer implements
050: ImageVisualizer, GraphAccumListener, Clearable {
051: private static final Logger log = LoggingManager
052: .getLoggerForClass();
053:
054: protected transient GraphAccumModel model;
055:
056: protected transient GraphAccum graph;
057:
058: transient protected JPanel legendPanel;
059:
060: /**
061: * Constructor.
062: */
063: public GraphAccumVisualizer() {
064: super ();
065: model = new GraphAccumModel();
066: model.addGraphAccumListener(this );
067: init();
068: log.debug("Start : GraphAccumVisualizer1");
069: log.debug("End : GraphAccumVisualizer1");
070: }
071:
072: public String getLabelResource() {
073: return "graph_full_results_title"; // $NON-NLS-1$
074: }
075:
076: public void add(SampleResult res) {
077: model.addNewSample(res);
078: }
079:
080: /**
081: * Returns the panel where labels can be added.
082: *
083: * @return a panel where labels can be added
084: */
085: public Object getWhiteCanvas() {
086: return legendPanel;
087: }
088:
089: /**
090: * Gets the Image attribute of the GraphVisualizer object.
091: *
092: * @return the Image value
093: */
094: public Image getImage() {
095: log.debug("Start : getImage1");
096: Image result = graph.createImage(graph.getWidth(), graph
097: .getHeight());
098:
099: graph.paintComponent(result.getGraphics());
100: log.debug("End : getImage1");
101: return result;
102: }
103:
104: /**
105: * Updates the gui to reflect changes.
106: */
107: public void updateGui() {
108: log.debug("Start : updateGui1");
109: graph.updateGui();
110: log.debug("End : updateGui1");
111: }
112:
113: /**
114: * Updates gui to reflect small changes.
115: *
116: * @param s
117: * sample to be added to plot
118: */
119: public void updateGui(SampleResult s) {
120: log.debug("Start : updateGui2");
121: log.debug("End : updateGui2");
122: }
123:
124: /**
125: * Clear this visualizer data.
126: */
127: public synchronized void clearData() {
128: model.clearData();
129: graph.clearData();
130: log.debug("Start : clear1");
131: repaint();
132: log.debug("End : clear1");
133: }
134:
135: /**
136: * Returns a description of this instance.
137: *
138: * @return description of this instance
139: */
140: public String toString() {
141: String toString = "Show the samples analysys as dot plots";
142:
143: log.debug("toString1 : Returning - " + toString);
144: return toString;
145: }
146:
147: /**
148: * Setup all the swing components.
149: */
150: private void init() {
151: log.debug("Start : init1");
152: graph = new GraphAccum(model);
153: graph.setVisualizer(this );
154:
155: this .setLayout(new BorderLayout());
156:
157: // MAIN PANEL
158: JPanel mainPanel = new JPanel();
159: Border margin = new EmptyBorder(10, 10, 5, 10);
160:
161: mainPanel.setBorder(margin);
162: mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
163:
164: // TITLE
165: JLabel panelTitleLabel = new JLabel(JMeterUtils
166: .getResString("graph_full_results_title")); // $NON-NLS-1$
167: Font curFont = panelTitleLabel.getFont();
168: int curFontSize = curFont.getSize();
169:
170: curFontSize += 4;
171: panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont
172: .getStyle(), curFontSize));
173: mainPanel.add(panelTitleLabel);
174:
175: mainPanel.add(getNamePanel());
176: mainPanel.add(getFilePanel());
177:
178: JScrollPane graphScrollPanel = new JScrollPane(graph,
179: JScrollPane.VERTICAL_SCROLLBAR_NEVER,
180: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
181:
182: graphScrollPanel.setViewportBorder(BorderFactory
183: .createEmptyBorder(2, 2, 2, 2));
184: legendPanel = new JPanel();
185:
186: JScrollPane legendScrollPanel = new JScrollPane(legendPanel);
187: JSplitPane graphSplitPane = new JSplitPane(
188: JSplitPane.VERTICAL_SPLIT, graphScrollPanel,
189: legendScrollPanel);
190:
191: this .add(mainPanel, BorderLayout.NORTH);
192: this .add(graphSplitPane, BorderLayout.CENTER);
193: log.debug("End : init1");
194: }
195: }
|