You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/07/06 23:47:15 UTC
svn commit: r674351 [7/11] - in /jakarta/jmeter/trunk/src:
components/org/apache/jmeter/config/ components/org/apache/jmeter/control/
components/org/apache/jmeter/control/gui/
components/org/apache/jmeter/extractor/
components/org/apache/jmeter/extract...
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java Sun Jul 6 14:47:12 2008
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -48,402 +48,402 @@
* This class implements a statistical analyser that calculates both the average
* and the standard deviation of the sampling process and outputs them as
* autoscaling plots.
- *
+ *
* Created February 8, 2001
- *
+ *
*/
public class GraphVisualizer extends AbstractVisualizer implements ImageVisualizer, ItemListener, Clearable {
-
- private static final String ZERO = "0"; //$NON-NLS-1$
-
- private NumberFormat nf = NumberFormat.getInstance(); // OK, because used in synchronised method
-
- private SamplingStatCalculator model;
-
- private JTextField maxYField = null;
-
- private JTextField minYField = null;
-
- private JTextField noSamplesField = null;
-
- private String minute = JMeterUtils.getResString("minute"); // $NON-NLS-1$
-
- private Graph graph;
-
- private JCheckBox data;
-
- private JCheckBox average;
-
- private JCheckBox deviation;
-
- private JCheckBox throughput;
-
- private JCheckBox median;
-
- private JTextField dataField;
-
- private JTextField averageField;
-
- private JTextField deviationField;
-
- private JTextField throughputField;
-
- private JTextField medianField;
-
- /**
- * Constructor for the GraphVisualizer object.
- */
- public GraphVisualizer() {
- model = new SamplingStatCalculator("Graph");
- graph = new Graph(model);
- init();
- }
-
- /**
- * Gets the Image attribute of the GraphVisualizer object.
- *
- * @return the Image value
- */
- public Image getImage() {
- Image result = graph.createImage(graph.getWidth(), graph.getHeight());
-
- graph.paintComponent(result.getGraphics());
-
- return result;
- }
-
- public synchronized void updateGui(Sample s) {
- // We have received one more sample
- graph.updateGui(s);
- noSamplesField.setText(Long.toString(s.getCount()));
- dataField.setText(Long.toString(s.getData()));
- averageField.setText(Long.toString(s.getAverage()));
- deviationField.setText(Long.toString(s.getDeviation()));
- throughputField.setText(nf.format(60 * s.getThroughput()) + "/" + minute); // $NON-NLS-1$
- medianField.setText(Long.toString(s.getMedian()));
- updateYAxis();
- }
-
- public void add(SampleResult res) {
- updateGui(model.addSample(res));
- }
-
- public String getLabelResource() {
- return "graph_results_title"; // $NON-NLS-1$
- }
-
- public void itemStateChanged(ItemEvent e) {
- if (e.getItem() == data) {
- this.graph.enableData(e.getStateChange() == ItemEvent.SELECTED);
- } else if (e.getItem() == average) {
- this.graph.enableAverage(e.getStateChange() == ItemEvent.SELECTED);
- } else if (e.getItem() == deviation) {
- this.graph.enableDeviation(e.getStateChange() == ItemEvent.SELECTED);
- } else if (e.getItem() == throughput) {
- this.graph.enableThroughput(e.getStateChange() == ItemEvent.SELECTED);
- } else if (e.getItem() == median) {
- this.graph.enableMedian(e.getStateChange() == ItemEvent.SELECTED);
- }
- this.graph.repaint();
- }
-
- public void clearData() {
- graph.clearData();
- model.clear();
- dataField.setText(ZERO);
- averageField.setText(ZERO);
- deviationField.setText(ZERO);
- throughputField.setText("0/" + minute); //$NON-NLS-1$
- medianField.setText(ZERO);
- noSamplesField.setText(ZERO);
- updateYAxis();
- repaint();
- }
-
- public String toString() {
- return "Show the samples analysis as dot plots";
- }
-
- /**
- * Update the max and min value of the Y axis.
- */
- private void updateYAxis() {
- maxYField.setText(Long.toString(graph.getGraphMax()));
- minYField.setText(ZERO);
- }
-
- /**
- * Initialize the GUI.
- */
- private void init() {
- this.setLayout(new BorderLayout());
-
- // MAIN PANEL
- Border margin = new EmptyBorder(10, 10, 5, 10);
-
- this.setBorder(margin);
-
- // Set up the graph with header, footer, Y axis and graph display
- JPanel graphPanel = new JPanel(new BorderLayout());
- graphPanel.add(createYAxis(), BorderLayout.WEST);
- graphPanel.add(createChoosePanel(), BorderLayout.NORTH);
- graphPanel.add(createGraphPanel(), BorderLayout.CENTER);
- graphPanel.add(createGraphInfoPanel(), BorderLayout.SOUTH);
-
- // Add the main panel and the graph
- this.add(makeTitlePanel(), BorderLayout.NORTH);
- this.add(graphPanel, BorderLayout.CENTER);
- }
-
- // Methods used in creating the GUI
-
- /**
- * Creates the panel containing the graph's Y axis labels.
- *
- * @return the Y axis panel
- */
- private JPanel createYAxis() {
- JPanel graphYAxisPanel = new JPanel();
-
- graphYAxisPanel.setLayout(new BorderLayout());
-
- maxYField = createYAxisField(5);
- minYField = createYAxisField(3);
-
- graphYAxisPanel.add(createYAxisPanel("graph_results_ms", maxYField), BorderLayout.NORTH); // $NON-NLS-1$
- graphYAxisPanel.add(createYAxisPanel("graph_results_ms", minYField), BorderLayout.SOUTH); // $NON-NLS-1$
-
- return graphYAxisPanel;
- }
-
- /**
- * Creates a text field to be used for the value of a Y axis label. These
- * fields hold the minimum and maximum values for the graph. The units are
- * kept in a separate label outside of this field.
- *
- * @param length
- * the number of characters which the field will use to calculate
- * its preferred width. This should be set to the maximum number
- * of digits that are expected to be necessary to hold the label
- * value.
- *
- * @see #createYAxisPanel(String, JTextField)
- *
- * @return a text field configured to be used in the Y axis
- */
- private JTextField createYAxisField(int length) {
- JTextField field = new JTextField(length);
- field.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
- field.setEditable(false);
- field.setForeground(Color.black);
- field.setBackground(getBackground());
- field.setHorizontalAlignment(JTextField.RIGHT);
- return field;
- }
-
- /**
- * Creates a panel for an entire Y axis label. This includes the dynamic
- * value as well as the unit label.
- *
- * @param labelResourceName
- * the name of the label resource. This is used to look up the
- * label text using {@link JMeterUtils#getResString(String)}.
- *
- * @return a panel containing both the dynamic and static parts of a Y axis
- * label
- */
- private JPanel createYAxisPanel(String labelResourceName, JTextField field) {
- JPanel panel = new JPanel(new FlowLayout());
- JLabel label = new JLabel(JMeterUtils.getResString(labelResourceName));
-
- panel.add(field);
- panel.add(label);
- return panel;
- }
-
- /**
- * Creates a panel which allows the user to choose which graphs to display.
- * This panel consists of a check box for each type of graph (current
- * sample, average, deviation, and throughput).
- *
- * @return a panel allowing the user to choose which graphs to display
- */
- private JPanel createChoosePanel() {
- JPanel chooseGraphsPanel = new JPanel();
-
- chooseGraphsPanel.setLayout(new FlowLayout());
- JLabel selectGraphsLabel = new JLabel(JMeterUtils.getResString("graph_choose_graphs")); //$NON-NLS-1$
- data = createChooseCheckBox("graph_results_data", Color.black); // $NON-NLS-1$
- average = createChooseCheckBox("graph_results_average", Color.blue); // $NON-NLS-1$
- deviation = createChooseCheckBox("graph_results_deviation", Color.red); // $NON-NLS-1$
- throughput = createChooseCheckBox("graph_results_throughput", JMeterColor.dark_green); // $NON-NLS-1$
- median = createChooseCheckBox("graph_results_median", JMeterColor.purple); // $NON-NLS-1$
-
- chooseGraphsPanel.add(selectGraphsLabel);
- chooseGraphsPanel.add(data);
- chooseGraphsPanel.add(average);
- chooseGraphsPanel.add(median);
- chooseGraphsPanel.add(deviation);
- chooseGraphsPanel.add(throughput);
- return chooseGraphsPanel;
- }
-
- /**
- * Creates a check box configured to be used to in the choose panel allowing
- * the user to select whether or not a particular kind of graph data will be
- * displayed.
- *
- * @param labelResourceName
- * the name of the label resource. This is used to look up the
- * label text using {@link JMeterUtils#getResString(String)}.
- * @param color
- * the color used for the checkbox text. By convention this is
- * the same color that is used to draw the graph and for the
- * corresponding info field.
- *
- * @return a checkbox allowing the user to select whether or not a kind of
- * graph data will be displayed
- */
- private JCheckBox createChooseCheckBox(String labelResourceName, Color color) {
- JCheckBox checkBox = new JCheckBox(JMeterUtils.getResString(labelResourceName));
- checkBox.setSelected(true);
- checkBox.addItemListener(this);
- checkBox.setForeground(color);
- return checkBox;
- }
-
- /**
- * Creates a scroll pane containing the actual graph of the results.
- *
- * @return a scroll pane containing the graph
- */
- private Component createGraphPanel() {
- JScrollPane graphScrollPanel = makeScrollPane(graph, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
- graphScrollPanel.setViewportBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
- graphScrollPanel.setPreferredSize(graphScrollPanel.getMinimumSize());
-
- return graphScrollPanel;
- }
-
- /**
- * Creates a panel which numerically displays the current graph values.
- *
- * @return a panel showing the current graph values
- */
- private Box createGraphInfoPanel() {
- Box graphInfoPanel = Box.createHorizontalBox();
-
- noSamplesField = createInfoField(Color.black, 6);
- dataField = createInfoField(Color.black, 5);
- averageField = createInfoField(Color.blue, 5);
- deviationField = createInfoField(Color.red, 5);
- throughputField = createInfoField(JMeterColor.dark_green, 15);
- medianField = createInfoField(JMeterColor.purple, 5);
-
- graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_no_samples", noSamplesField), // $NON-NLS-1$
- noSamplesField, createInfoLabel("graph_results_deviation", deviationField), deviationField)); // $NON-NLS-1$
- graphInfoPanel.add(Box.createHorizontalGlue());
-
- graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_latest_sample", dataField), dataField, // $NON-NLS-1$
- createInfoLabel("graph_results_throughput", throughputField), throughputField)); // $NON-NLS-1$
- graphInfoPanel.add(Box.createHorizontalGlue());
-
- graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_average", averageField), averageField, // $NON-NLS-1$
- createInfoLabel("graph_results_median", medianField), medianField)); // $NON-NLS-1$
- graphInfoPanel.add(Box.createHorizontalGlue());
- return graphInfoPanel;
- }
-
- /**
- * Creates one of the fields used to display the graph's current values.
- *
- * @param color
- * the color used to draw the value. By convention this is the
- * same color that is used to draw the graph for this value and
- * in the choose panel.
- * @param length
- * the number of digits which the field should be able to display
- *
- * @return a text field configured to display one of the current graph
- * values
- */
- private JTextField createInfoField(Color color, int length) {
- JTextField field = new JTextField(length);
- field.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
- field.setEditable(false);
- field.setForeground(color);
- field.setBackground(getBackground());
-
- // The text field should expand horizontally, but have
- // a fixed height
- field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getPreferredSize().height));
- return field;
- }
-
- /**
- * Creates a label for one of the fields used to display the graph's current
- * values. Neither the label created by this method or the
- * <code>field</code> passed as a parameter is added to the GUI here.
- *
- * @param labelResourceName
- * the name of the label resource. This is used to look up the
- * label text using {@link JMeterUtils#getResString(String)}.
- * @param field
- * the field this label is being created for.
- */
- private JLabel createInfoLabel(String labelResourceName, JTextField field) {
- JLabel label = new JLabel(JMeterUtils.getResString(labelResourceName));
- label.setForeground(field.getForeground());
- label.setLabelFor(field);
- return label;
- }
-
- /**
- * Creates a panel containing two pairs of labels and fields for displaying
- * the current graph values. This method exists to help with laying out the
- * fields in columns. If one or more components are null then these
- * components will be represented by blank space.
- *
- * @param label1
- * the label for the first field. This label will be placed in
- * the upper left section of the panel. If this parameter is
- * null, this section of the panel will be left blank.
- * @param field1
- * the field corresponding to the first label. This field will be
- * placed in the upper right section of the panel. If this
- * parameter is null, this section of the panel will be left
- * blank.
- * @param label2
- * the label for the second field. This label will be placed in
- * the lower left section of the panel. If this parameter is
- * null, this section of the panel will be left blank.
- * @param field2
- * the field corresponding to the second label. This field will
- * be placed in the lower right section of the panel. If this
- * parameter is null, this section of the panel will be left
- * blank.
- */
- private Box createInfoColumn(JLabel label1, JTextField field1, JLabel label2, JTextField field2) {
- // This column actually consists of a row with two sub-columns
- // The first column contains the labels, and the second
- // column contains the fields.
- Box row = Box.createHorizontalBox();
- Box col = Box.createVerticalBox();
- col.add(label1 != null ? label1 : Box.createVerticalGlue());
- col.add(label2 != null ? label2 : Box.createVerticalGlue());
- row.add(col);
-
- row.add(Box.createHorizontalStrut(5));
-
- col = Box.createVerticalBox();
- col.add(field1 != null ? field1 : Box.createVerticalGlue());
- col.add(field2 != null ? field2 : Box.createVerticalGlue());
- row.add(col);
- row.add(Box.createHorizontalStrut(5));
+ private static final String ZERO = "0"; //$NON-NLS-1$
- return row;
- }
+ private NumberFormat nf = NumberFormat.getInstance(); // OK, because used in synchronised method
+
+ private SamplingStatCalculator model;
+
+ private JTextField maxYField = null;
+
+ private JTextField minYField = null;
+
+ private JTextField noSamplesField = null;
+
+ private String minute = JMeterUtils.getResString("minute"); // $NON-NLS-1$
+
+ private Graph graph;
+
+ private JCheckBox data;
+
+ private JCheckBox average;
+
+ private JCheckBox deviation;
+
+ private JCheckBox throughput;
+
+ private JCheckBox median;
+
+ private JTextField dataField;
+
+ private JTextField averageField;
+
+ private JTextField deviationField;
+
+ private JTextField throughputField;
+
+ private JTextField medianField;
+
+ /**
+ * Constructor for the GraphVisualizer object.
+ */
+ public GraphVisualizer() {
+ model = new SamplingStatCalculator("Graph");
+ graph = new Graph(model);
+ init();
+ }
+
+ /**
+ * Gets the Image attribute of the GraphVisualizer object.
+ *
+ * @return the Image value
+ */
+ public Image getImage() {
+ Image result = graph.createImage(graph.getWidth(), graph.getHeight());
+
+ graph.paintComponent(result.getGraphics());
+
+ return result;
+ }
+
+ public synchronized void updateGui(Sample s) {
+ // We have received one more sample
+ graph.updateGui(s);
+ noSamplesField.setText(Long.toString(s.getCount()));
+ dataField.setText(Long.toString(s.getData()));
+ averageField.setText(Long.toString(s.getAverage()));
+ deviationField.setText(Long.toString(s.getDeviation()));
+ throughputField.setText(nf.format(60 * s.getThroughput()) + "/" + minute); // $NON-NLS-1$
+ medianField.setText(Long.toString(s.getMedian()));
+ updateYAxis();
+ }
+
+ public void add(SampleResult res) {
+ updateGui(model.addSample(res));
+ }
+
+ public String getLabelResource() {
+ return "graph_results_title"; // $NON-NLS-1$
+ }
+
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getItem() == data) {
+ this.graph.enableData(e.getStateChange() == ItemEvent.SELECTED);
+ } else if (e.getItem() == average) {
+ this.graph.enableAverage(e.getStateChange() == ItemEvent.SELECTED);
+ } else if (e.getItem() == deviation) {
+ this.graph.enableDeviation(e.getStateChange() == ItemEvent.SELECTED);
+ } else if (e.getItem() == throughput) {
+ this.graph.enableThroughput(e.getStateChange() == ItemEvent.SELECTED);
+ } else if (e.getItem() == median) {
+ this.graph.enableMedian(e.getStateChange() == ItemEvent.SELECTED);
+ }
+ this.graph.repaint();
+ }
+
+ public void clearData() {
+ graph.clearData();
+ model.clear();
+ dataField.setText(ZERO);
+ averageField.setText(ZERO);
+ deviationField.setText(ZERO);
+ throughputField.setText("0/" + minute); //$NON-NLS-1$
+ medianField.setText(ZERO);
+ noSamplesField.setText(ZERO);
+ updateYAxis();
+ repaint();
+ }
+
+ public String toString() {
+ return "Show the samples analysis as dot plots";
+ }
+
+ /**
+ * Update the max and min value of the Y axis.
+ */
+ private void updateYAxis() {
+ maxYField.setText(Long.toString(graph.getGraphMax()));
+ minYField.setText(ZERO);
+ }
+
+ /**
+ * Initialize the GUI.
+ */
+ private void init() {
+ this.setLayout(new BorderLayout());
+
+ // MAIN PANEL
+ Border margin = new EmptyBorder(10, 10, 5, 10);
+
+ this.setBorder(margin);
+
+ // Set up the graph with header, footer, Y axis and graph display
+ JPanel graphPanel = new JPanel(new BorderLayout());
+ graphPanel.add(createYAxis(), BorderLayout.WEST);
+ graphPanel.add(createChoosePanel(), BorderLayout.NORTH);
+ graphPanel.add(createGraphPanel(), BorderLayout.CENTER);
+ graphPanel.add(createGraphInfoPanel(), BorderLayout.SOUTH);
+
+ // Add the main panel and the graph
+ this.add(makeTitlePanel(), BorderLayout.NORTH);
+ this.add(graphPanel, BorderLayout.CENTER);
+ }
+
+ // Methods used in creating the GUI
+
+ /**
+ * Creates the panel containing the graph's Y axis labels.
+ *
+ * @return the Y axis panel
+ */
+ private JPanel createYAxis() {
+ JPanel graphYAxisPanel = new JPanel();
+
+ graphYAxisPanel.setLayout(new BorderLayout());
+
+ maxYField = createYAxisField(5);
+ minYField = createYAxisField(3);
+
+ graphYAxisPanel.add(createYAxisPanel("graph_results_ms", maxYField), BorderLayout.NORTH); // $NON-NLS-1$
+ graphYAxisPanel.add(createYAxisPanel("graph_results_ms", minYField), BorderLayout.SOUTH); // $NON-NLS-1$
+
+ return graphYAxisPanel;
+ }
+
+ /**
+ * Creates a text field to be used for the value of a Y axis label. These
+ * fields hold the minimum and maximum values for the graph. The units are
+ * kept in a separate label outside of this field.
+ *
+ * @param length
+ * the number of characters which the field will use to calculate
+ * its preferred width. This should be set to the maximum number
+ * of digits that are expected to be necessary to hold the label
+ * value.
+ *
+ * @see #createYAxisPanel(String, JTextField)
+ *
+ * @return a text field configured to be used in the Y axis
+ */
+ private JTextField createYAxisField(int length) {
+ JTextField field = new JTextField(length);
+ field.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
+ field.setEditable(false);
+ field.setForeground(Color.black);
+ field.setBackground(getBackground());
+ field.setHorizontalAlignment(JTextField.RIGHT);
+ return field;
+ }
+
+ /**
+ * Creates a panel for an entire Y axis label. This includes the dynamic
+ * value as well as the unit label.
+ *
+ * @param labelResourceName
+ * the name of the label resource. This is used to look up the
+ * label text using {@link JMeterUtils#getResString(String)}.
+ *
+ * @return a panel containing both the dynamic and static parts of a Y axis
+ * label
+ */
+ private JPanel createYAxisPanel(String labelResourceName, JTextField field) {
+ JPanel panel = new JPanel(new FlowLayout());
+ JLabel label = new JLabel(JMeterUtils.getResString(labelResourceName));
+
+ panel.add(field);
+ panel.add(label);
+ return panel;
+ }
+
+ /**
+ * Creates a panel which allows the user to choose which graphs to display.
+ * This panel consists of a check box for each type of graph (current
+ * sample, average, deviation, and throughput).
+ *
+ * @return a panel allowing the user to choose which graphs to display
+ */
+ private JPanel createChoosePanel() {
+ JPanel chooseGraphsPanel = new JPanel();
+
+ chooseGraphsPanel.setLayout(new FlowLayout());
+ JLabel selectGraphsLabel = new JLabel(JMeterUtils.getResString("graph_choose_graphs")); //$NON-NLS-1$
+ data = createChooseCheckBox("graph_results_data", Color.black); // $NON-NLS-1$
+ average = createChooseCheckBox("graph_results_average", Color.blue); // $NON-NLS-1$
+ deviation = createChooseCheckBox("graph_results_deviation", Color.red); // $NON-NLS-1$
+ throughput = createChooseCheckBox("graph_results_throughput", JMeterColor.dark_green); // $NON-NLS-1$
+ median = createChooseCheckBox("graph_results_median", JMeterColor.purple); // $NON-NLS-1$
+
+ chooseGraphsPanel.add(selectGraphsLabel);
+ chooseGraphsPanel.add(data);
+ chooseGraphsPanel.add(average);
+ chooseGraphsPanel.add(median);
+ chooseGraphsPanel.add(deviation);
+ chooseGraphsPanel.add(throughput);
+ return chooseGraphsPanel;
+ }
+
+ /**
+ * Creates a check box configured to be used to in the choose panel allowing
+ * the user to select whether or not a particular kind of graph data will be
+ * displayed.
+ *
+ * @param labelResourceName
+ * the name of the label resource. This is used to look up the
+ * label text using {@link JMeterUtils#getResString(String)}.
+ * @param color
+ * the color used for the checkbox text. By convention this is
+ * the same color that is used to draw the graph and for the
+ * corresponding info field.
+ *
+ * @return a checkbox allowing the user to select whether or not a kind of
+ * graph data will be displayed
+ */
+ private JCheckBox createChooseCheckBox(String labelResourceName, Color color) {
+ JCheckBox checkBox = new JCheckBox(JMeterUtils.getResString(labelResourceName));
+ checkBox.setSelected(true);
+ checkBox.addItemListener(this);
+ checkBox.setForeground(color);
+ return checkBox;
+ }
+
+ /**
+ * Creates a scroll pane containing the actual graph of the results.
+ *
+ * @return a scroll pane containing the graph
+ */
+ private Component createGraphPanel() {
+ JScrollPane graphScrollPanel = makeScrollPane(graph, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ graphScrollPanel.setViewportBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
+ graphScrollPanel.setPreferredSize(graphScrollPanel.getMinimumSize());
+
+ return graphScrollPanel;
+ }
+
+ /**
+ * Creates a panel which numerically displays the current graph values.
+ *
+ * @return a panel showing the current graph values
+ */
+ private Box createGraphInfoPanel() {
+ Box graphInfoPanel = Box.createHorizontalBox();
+
+ noSamplesField = createInfoField(Color.black, 6);
+ dataField = createInfoField(Color.black, 5);
+ averageField = createInfoField(Color.blue, 5);
+ deviationField = createInfoField(Color.red, 5);
+ throughputField = createInfoField(JMeterColor.dark_green, 15);
+ medianField = createInfoField(JMeterColor.purple, 5);
+
+ graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_no_samples", noSamplesField), // $NON-NLS-1$
+ noSamplesField, createInfoLabel("graph_results_deviation", deviationField), deviationField)); // $NON-NLS-1$
+ graphInfoPanel.add(Box.createHorizontalGlue());
+
+ graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_latest_sample", dataField), dataField, // $NON-NLS-1$
+ createInfoLabel("graph_results_throughput", throughputField), throughputField)); // $NON-NLS-1$
+ graphInfoPanel.add(Box.createHorizontalGlue());
+
+ graphInfoPanel.add(createInfoColumn(createInfoLabel("graph_results_average", averageField), averageField, // $NON-NLS-1$
+ createInfoLabel("graph_results_median", medianField), medianField)); // $NON-NLS-1$
+ graphInfoPanel.add(Box.createHorizontalGlue());
+ return graphInfoPanel;
+ }
+
+ /**
+ * Creates one of the fields used to display the graph's current values.
+ *
+ * @param color
+ * the color used to draw the value. By convention this is the
+ * same color that is used to draw the graph for this value and
+ * in the choose panel.
+ * @param length
+ * the number of digits which the field should be able to display
+ *
+ * @return a text field configured to display one of the current graph
+ * values
+ */
+ private JTextField createInfoField(Color color, int length) {
+ JTextField field = new JTextField(length);
+ field.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
+ field.setEditable(false);
+ field.setForeground(color);
+ field.setBackground(getBackground());
+
+ // The text field should expand horizontally, but have
+ // a fixed height
+ field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getPreferredSize().height));
+ return field;
+ }
+
+ /**
+ * Creates a label for one of the fields used to display the graph's current
+ * values. Neither the label created by this method or the
+ * <code>field</code> passed as a parameter is added to the GUI here.
+ *
+ * @param labelResourceName
+ * the name of the label resource. This is used to look up the
+ * label text using {@link JMeterUtils#getResString(String)}.
+ * @param field
+ * the field this label is being created for.
+ */
+ private JLabel createInfoLabel(String labelResourceName, JTextField field) {
+ JLabel label = new JLabel(JMeterUtils.getResString(labelResourceName));
+ label.setForeground(field.getForeground());
+ label.setLabelFor(field);
+ return label;
+ }
+
+ /**
+ * Creates a panel containing two pairs of labels and fields for displaying
+ * the current graph values. This method exists to help with laying out the
+ * fields in columns. If one or more components are null then these
+ * components will be represented by blank space.
+ *
+ * @param label1
+ * the label for the first field. This label will be placed in
+ * the upper left section of the panel. If this parameter is
+ * null, this section of the panel will be left blank.
+ * @param field1
+ * the field corresponding to the first label. This field will be
+ * placed in the upper right section of the panel. If this
+ * parameter is null, this section of the panel will be left
+ * blank.
+ * @param label2
+ * the label for the second field. This label will be placed in
+ * the lower left section of the panel. If this parameter is
+ * null, this section of the panel will be left blank.
+ * @param field2
+ * the field corresponding to the second label. This field will
+ * be placed in the lower right section of the panel. If this
+ * parameter is null, this section of the panel will be left
+ * blank.
+ */
+ private Box createInfoColumn(JLabel label1, JTextField field1, JLabel label2, JTextField field2) {
+ // This column actually consists of a row with two sub-columns
+ // The first column contains the labels, and the second
+ // column contains the fields.
+ Box row = Box.createHorizontalBox();
+ Box col = Box.createVerticalBox();
+ col.add(label1 != null ? label1 : Box.createVerticalGlue());
+ col.add(label2 != null ? label2 : Box.createVerticalGlue());
+ row.add(col);
+
+ row.add(Box.createHorizontalStrut(5));
+
+ col = Box.createVerticalBox();
+ col.add(field1 != null ? field1 : Box.createVerticalGlue());
+ col.add(field2 != null ? field2 : Box.createVerticalGlue());
+ row.add(col);
+
+ row.add(Box.createHorizontalStrut(5));
+
+ return row;
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/LineGraph.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/LineGraph.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/LineGraph.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/LineGraph.java Sun Jul 6 14:47:12 2008
@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -55,14 +55,14 @@
protected String title, xAxisTitle, yAxisTitle;
protected String[] xAxisLabels, yAxisLabel;
protected int width, height;
-
+
private static final Shape[] SHAPE_ARRAY = {PointChartProperties.SHAPE_CIRCLE,
PointChartProperties.SHAPE_DIAMOND,PointChartProperties.SHAPE_SQUARE,
PointChartProperties.SHAPE_TRIANGLE};
/**
* 12 basic colors for line graphs. If we need more colors than this,
- * we can add more. Though more than 12 lines per graph will look
+ * we can add more. Though more than 12 lines per graph will look
* rather busy and be hard to read.
*/
private static final Paint[] PAINT_ARRAY = {Color.black,
@@ -73,59 +73,59 @@
protected int paint_counter = -1;
/**
- *
- */
- public LineGraph() {
- super();
- }
-
- /**
- * @param layout
- */
- public LineGraph(LayoutManager layout) {
- super(layout);
- }
-
- /**
- * @param layout
- * @param isDoubleBuffered
- */
- public LineGraph(LayoutManager layout, boolean isDoubleBuffered) {
- super(layout, isDoubleBuffered);
- }
-
+ *
+ */
+ public LineGraph() {
+ super();
+ }
+
+ /**
+ * @param layout
+ */
+ public LineGraph(LayoutManager layout) {
+ super(layout);
+ }
+
+ /**
+ * @param layout
+ * @param isDoubleBuffered
+ */
+ public LineGraph(LayoutManager layout, boolean isDoubleBuffered) {
+ super(layout, isDoubleBuffered);
+ }
+
public void setData(double[][] data) {
this.data = data;
}
-
+
public void setTitle(String title) {
this.title = title;
}
-
+
public void setXAxisTitle(String title) {
this.xAxisTitle = title;
}
-
+
public void setYAxisTitle(String title) {
this.yAxisTitle = title;
}
-
+
public void setXAxisLabels(String[] labels) {
this.xAxisLabels = labels;
}
-
+
public void setYAxisLabels(String[] label) {
this.yAxisLabel = label;
}
-
+
public void setWidth(int w) {
this.width = w;
}
-
+
public void setHeight(int h) {
this.height = h;
}
-
+
public void paintComponent(Graphics g) {
// reset the paint counter
this.paint_counter = -1;
@@ -136,7 +136,7 @@
this.yAxisTitle,this.data,this.width,this.height,g);
}
}
-
+
private void drawSample(String _title, String[] _xAxisLabels, String _xAxisTitle,
String _yAxisTitle, double[][] _data, int _width, int _height, Graphics g) {
try {
@@ -153,10 +153,10 @@
Shape[] shapes = createShapes(_data.length);
Stroke[] lstrokes = createStrokes(_data.length);
LineChartProperties lineChartProperties= new LineChartProperties(lstrokes,shapes);
- AxisChartDataSet axisChartDataSet= new AxisChartDataSet( _data,
- legendLabels,
- paints,
- ChartType.LINE,
+ AxisChartDataSet axisChartDataSet= new AxisChartDataSet( _data,
+ legendLabels,
+ paints,
+ ChartType.LINE,
lineChartProperties );
dataSeries.addIAxisPlotDataSet( axisChartDataSet );
@@ -169,16 +169,16 @@
DataAxisProperties daxp = (DataAxisProperties)axisProperties.getYAxisProperties();
daxp.setRoundToNearest(1);
LegendProperties legendProperties = new LegendProperties();
- AxisChart axisChart = new AxisChart(
- dataSeries, chartProperties, axisProperties,
+ AxisChart axisChart = new AxisChart(
+ dataSeries, chartProperties, axisProperties,
legendProperties, _width, _height );
axisChart.setGraphics2D((Graphics2D) g);
axisChart.render();
} catch (Exception e) {
- log.error(e.getMessage());
+ log.error(e.getMessage());
}
}
-
+
/**
* Since we only have 4 shapes, the method will start with the
* first shape and keep cycling through the shapes in order.
@@ -192,7 +192,7 @@
}
return shapes;
}
-
+
/**
* Return the next shape
* @return the next shape
@@ -204,9 +204,9 @@
}
return SHAPE_ARRAY[shape_counter];
}
-
+
/**
- *
+ *
* @param count
* @return the first count strokes
*/
@@ -217,7 +217,7 @@
}
return str;
}
-
+
/**
* method always return a new BasicStroke with 1.0f weight
* @return a new BasicStroke with 1.0f weight
@@ -225,7 +225,7 @@
public Stroke nextStroke() {
return new BasicStroke(1.0f);
}
-
+
/**
* return an array of Paint with different colors. The current
* implementation will cycle through 12 colors if a line graph
@@ -240,7 +240,7 @@
}
return pts;
}
-
+
/**
* The method will return the next paint color in the PAINT_ARRAY.
* Rather than return a random color, we want it to always go through
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java Sun Jul 6 14:47:12 2008
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -57,311 +57,311 @@
/**
* This class implements a visualizer that mails a message when an error occurs.
- *
+ *
*/
public class MailerVisualizer extends AbstractVisualizer implements ActionListener, Clearable, ChangeListener {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
- private JButton testerButton;
+ private JButton testerButton;
- private JTextField addressField;
+ private JTextField addressField;
- private JTextField fromField;
+ private JTextField fromField;
- private JTextField smtpHostField;
-
- private JTextField failureSubjectField;
-
- private JTextField successSubjectField;
-
- private JTextField failureField;
-
- private JTextField failureLimitField;
-
- private JTextField successLimitField;
-
- // private JPanel mainPanel;
- // private JLabel panelTitleLabel;
-
- /**
- * Constructs the MailerVisualizer and initializes its GUI.
- */
- public MailerVisualizer() {
- super();
- setModel(new MailerResultCollector());
- // initialize GUI.
- initGui();
- }
-
- public JPanel getControlPanel() {
- return this;
- }
-
- /**
- * Clears any stored sampling-informations.
- */
- public synchronized void clearData() {
- if (getModel() != null) {
- ((MailerResultCollector) getModel()).getMailerModel().clear();
- }
- }
-
- public void add(SampleResult res) {
- }
-
- public String toString() {
- return "E-Mail Notification";
- }
-
- /**
- * Initializes the GUI. Lays out components and adds them to the container.
- */
- private void initGui() {
- this.setLayout(new BorderLayout());
-
- // MAIN PANEL
- JPanel mainPanel = new VerticalPanel();
- Border margin = new EmptyBorder(10, 10, 5, 10);
-
- this.setBorder(margin);
-
- // NAME
- mainPanel.add(makeTitlePanel());
-
- // mailer panel
- JPanel mailerPanel = new JPanel();
-
- mailerPanel.setBorder(BorderFactory
- .createTitledBorder(BorderFactory.createEtchedBorder(), getAttributesTitle()));
- GridBagLayout g = new GridBagLayout();
-
- mailerPanel.setLayout(g);
- GridBagConstraints c = new GridBagConstraints();
-
- c.anchor = GridBagConstraints.NORTHWEST;
- c.insets = new Insets(0, 0, 0, 0);
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("From:"));
-
- fromField = new JTextField(25);
- fromField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(fromField, c);
- mailerPanel.add(fromField);
-
- c.anchor = GridBagConstraints.NORTHWEST;
- c.insets = new Insets(0, 0, 0, 0);
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Addressee(s):"));
-
- addressField = new JTextField(25);
- addressField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(addressField, c);
- mailerPanel.add(addressField);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("SMTP Host:"));
-
- smtpHostField = new JTextField(25);
- smtpHostField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(smtpHostField, c);
- mailerPanel.add(smtpHostField);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Failure Subject:"));
-
- failureSubjectField = new JTextField(25);
- failureSubjectField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(failureSubjectField, c);
- mailerPanel.add(failureSubjectField);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Success Subject:"));
-
- successSubjectField = new JTextField(25);
- successSubjectField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(successSubjectField, c);
- mailerPanel.add(successSubjectField);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Failure Limit:"));
-
- failureLimitField = new JTextField("2", 25);
- failureLimitField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(failureLimitField, c);
- mailerPanel.add(failureLimitField);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Success Limit:"));
-
- successLimitField = new JTextField("2", 25);
- successLimitField.setEditable(true);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(successLimitField, c);
- mailerPanel.add(successLimitField);
-
- testerButton = new JButton("Test Mail");
- testerButton.addActionListener(this);
- testerButton.setEnabled(true);
- c.gridwidth = 1;
- g.setConstraints(testerButton, c);
- mailerPanel.add(testerButton);
-
- c.gridwidth = 1;
- mailerPanel.add(new JLabel("Failures:"));
- failureField = new JTextField(6);
- failureField.setEditable(false);
- c.gridwidth = GridBagConstraints.REMAINDER;
- g.setConstraints(failureField, c);
- mailerPanel.add(failureField);
-
- mainPanel.add(mailerPanel);
-
- this.add(mainPanel, BorderLayout.WEST);
- }
-
- public String getLabelResource() {
- return "mailer_visualizer_title"; //$NON-NLS-1$
- }
-
- /**
- * Returns a String for the title of the attributes-panel as set up in the
- * properties-file using the lookup-constant "mailer_attributes_panel".
- *
- * @return The title of the component.
- */
- public String getAttributesTitle() {
- return JMeterUtils.getResString("mailer_attributes_panel"); //$NON-NLS-1$
- }
-
- // ////////////////////////////////////////////////////////////
- //
- // Implementation of the ActionListener-Interface.
- //
- // ////////////////////////////////////////////////////////////
-
- /**
- * Reacts on an ActionEvent (like pressing a button).
- *
- * @param e
- * The ActionEvent with information about the event and its
- * source.
- */
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == testerButton) {
- ResultCollector testElement = getModel();
- modifyTestElement(testElement);
- try {
- MailerModel model = ((MailerResultCollector) testElement).getMailerModel();
- model.sendTestMail();
- displayMessage(JMeterUtils.getResString("mail_sent"), false); //$NON-NLS-1$
- } catch (AddressException ex) {
- log.error("Invalid mail address ", ex);
- displayMessage(JMeterUtils.getResString("invalid_mail_address") //$NON-NLS-1$
- + "\n" + ex.getMessage(), true); //$NON-NLS-1$
- } catch (MessagingException ex) {
- log.error("Couldn't send mail...", ex);
- displayMessage(JMeterUtils.getResString("invalid_mail") //$NON-NLS-1$
- + "\n" + ex.getMessage(), true); //$NON-NLS-1$
- }
- }
- }
-
- // ////////////////////////////////////////////////////////////
- //
- // Methods used to store and retrieve the MailerVisualizer.
- //
- // ////////////////////////////////////////////////////////////
-
- /**
- * Restores MailerVisualizer.
- */
- public void configure(TestElement el) {
- super.configure(el);
- updateVisualizer(((MailerResultCollector) el).getMailerModel());
- }
-
- /**
- * Makes MailerVisualizer storable.
- */
- public TestElement createTestElement() {
- if (getModel() == null) {
- setModel(new MailerResultCollector());
- }
- modifyTestElement(getModel());
- return getModel();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
- */
- public void modifyTestElement(TestElement c) {
- super.modifyTestElement(c);
- MailerModel mailerModel = ((MailerResultCollector) c).getMailerModel();
- mailerModel.setFailureLimit(failureLimitField.getText());
- mailerModel.setFailureSubject(failureSubjectField.getText());
- mailerModel.setFromAddress(fromField.getText());
- mailerModel.setSmtpHost(smtpHostField.getText());
- mailerModel.setSuccessLimit(successLimitField.getText());
- mailerModel.setSuccessSubject(successSubjectField.getText());
- mailerModel.setToAddress(addressField.getText());
- }
-
- // ////////////////////////////////////////////////////////////
- //
- // Methods to implement the ModelListener.
- //
- // ////////////////////////////////////////////////////////////
-
- /**
- * Notifies this Visualizer about model-changes. Causes the Visualizer to
- * query the model about its new state.
- */
- public void updateVisualizer(MailerModel model) {
- addressField.setText(model.getToAddress());
- fromField.setText(model.getFromAddress());
- smtpHostField.setText(model.getSmtpHost());
- successSubjectField.setText(model.getSuccessSubject());
- failureSubjectField.setText(model.getFailureSubject());
- failureLimitField.setText(String.valueOf(model.getFailureLimit()));
- failureField.setText(String.valueOf(model.getFailureCount()));
- successLimitField.setText(String.valueOf(model.getSuccessLimit()));
- repaint();
- }
-
- /**
- * Shows a message using a DialogBox.
- */
- private void displayMessage(String message, boolean isError) {
- int type = 0;
-
- if (isError) {
- type = JOptionPane.ERROR_MESSAGE;
- } else {
- type = JOptionPane.INFORMATION_MESSAGE;
- }
- JOptionPane.showMessageDialog(null, message, isError ? "Error" : "Information", type);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see ChangeListener#stateChanged(ChangeEvent)
- */
- public void stateChanged(ChangeEvent e) {
- if (e.getSource() instanceof MailerModel) {
- MailerModel testModel = (MailerModel) e.getSource();
- updateVisualizer(testModel);
- } else {
- super.stateChanged(e);
- }
- }
+ private JTextField smtpHostField;
+
+ private JTextField failureSubjectField;
+
+ private JTextField successSubjectField;
+
+ private JTextField failureField;
+
+ private JTextField failureLimitField;
+
+ private JTextField successLimitField;
+
+ // private JPanel mainPanel;
+ // private JLabel panelTitleLabel;
+
+ /**
+ * Constructs the MailerVisualizer and initializes its GUI.
+ */
+ public MailerVisualizer() {
+ super();
+ setModel(new MailerResultCollector());
+ // initialize GUI.
+ initGui();
+ }
+
+ public JPanel getControlPanel() {
+ return this;
+ }
+
+ /**
+ * Clears any stored sampling-informations.
+ */
+ public synchronized void clearData() {
+ if (getModel() != null) {
+ ((MailerResultCollector) getModel()).getMailerModel().clear();
+ }
+ }
+
+ public void add(SampleResult res) {
+ }
+
+ public String toString() {
+ return "E-Mail Notification";
+ }
+
+ /**
+ * Initializes the GUI. Lays out components and adds them to the container.
+ */
+ private void initGui() {
+ this.setLayout(new BorderLayout());
+
+ // MAIN PANEL
+ JPanel mainPanel = new VerticalPanel();
+ Border margin = new EmptyBorder(10, 10, 5, 10);
+
+ this.setBorder(margin);
+
+ // NAME
+ mainPanel.add(makeTitlePanel());
+
+ // mailer panel
+ JPanel mailerPanel = new JPanel();
+
+ mailerPanel.setBorder(BorderFactory
+ .createTitledBorder(BorderFactory.createEtchedBorder(), getAttributesTitle()));
+ GridBagLayout g = new GridBagLayout();
+
+ mailerPanel.setLayout(g);
+ GridBagConstraints c = new GridBagConstraints();
+
+ c.anchor = GridBagConstraints.NORTHWEST;
+ c.insets = new Insets(0, 0, 0, 0);
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("From:"));
+
+ fromField = new JTextField(25);
+ fromField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(fromField, c);
+ mailerPanel.add(fromField);
+
+ c.anchor = GridBagConstraints.NORTHWEST;
+ c.insets = new Insets(0, 0, 0, 0);
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Addressee(s):"));
+
+ addressField = new JTextField(25);
+ addressField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(addressField, c);
+ mailerPanel.add(addressField);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("SMTP Host:"));
+
+ smtpHostField = new JTextField(25);
+ smtpHostField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(smtpHostField, c);
+ mailerPanel.add(smtpHostField);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Failure Subject:"));
+
+ failureSubjectField = new JTextField(25);
+ failureSubjectField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(failureSubjectField, c);
+ mailerPanel.add(failureSubjectField);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Success Subject:"));
+
+ successSubjectField = new JTextField(25);
+ successSubjectField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(successSubjectField, c);
+ mailerPanel.add(successSubjectField);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Failure Limit:"));
+
+ failureLimitField = new JTextField("2", 25);
+ failureLimitField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(failureLimitField, c);
+ mailerPanel.add(failureLimitField);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Success Limit:"));
+
+ successLimitField = new JTextField("2", 25);
+ successLimitField.setEditable(true);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(successLimitField, c);
+ mailerPanel.add(successLimitField);
+
+ testerButton = new JButton("Test Mail");
+ testerButton.addActionListener(this);
+ testerButton.setEnabled(true);
+ c.gridwidth = 1;
+ g.setConstraints(testerButton, c);
+ mailerPanel.add(testerButton);
+
+ c.gridwidth = 1;
+ mailerPanel.add(new JLabel("Failures:"));
+ failureField = new JTextField(6);
+ failureField.setEditable(false);
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ g.setConstraints(failureField, c);
+ mailerPanel.add(failureField);
+
+ mainPanel.add(mailerPanel);
+
+ this.add(mainPanel, BorderLayout.WEST);
+ }
+
+ public String getLabelResource() {
+ return "mailer_visualizer_title"; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns a String for the title of the attributes-panel as set up in the
+ * properties-file using the lookup-constant "mailer_attributes_panel".
+ *
+ * @return The title of the component.
+ */
+ public String getAttributesTitle() {
+ return JMeterUtils.getResString("mailer_attributes_panel"); //$NON-NLS-1$
+ }
+
+ // ////////////////////////////////////////////////////////////
+ //
+ // Implementation of the ActionListener-Interface.
+ //
+ // ////////////////////////////////////////////////////////////
+
+ /**
+ * Reacts on an ActionEvent (like pressing a button).
+ *
+ * @param e
+ * The ActionEvent with information about the event and its
+ * source.
+ */
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == testerButton) {
+ ResultCollector testElement = getModel();
+ modifyTestElement(testElement);
+ try {
+ MailerModel model = ((MailerResultCollector) testElement).getMailerModel();
+ model.sendTestMail();
+ displayMessage(JMeterUtils.getResString("mail_sent"), false); //$NON-NLS-1$
+ } catch (AddressException ex) {
+ log.error("Invalid mail address ", ex);
+ displayMessage(JMeterUtils.getResString("invalid_mail_address") //$NON-NLS-1$
+ + "\n" + ex.getMessage(), true); //$NON-NLS-1$
+ } catch (MessagingException ex) {
+ log.error("Couldn't send mail...", ex);
+ displayMessage(JMeterUtils.getResString("invalid_mail") //$NON-NLS-1$
+ + "\n" + ex.getMessage(), true); //$NON-NLS-1$
+ }
+ }
+ }
+
+ // ////////////////////////////////////////////////////////////
+ //
+ // Methods used to store and retrieve the MailerVisualizer.
+ //
+ // ////////////////////////////////////////////////////////////
+
+ /**
+ * Restores MailerVisualizer.
+ */
+ public void configure(TestElement el) {
+ super.configure(el);
+ updateVisualizer(((MailerResultCollector) el).getMailerModel());
+ }
+
+ /**
+ * Makes MailerVisualizer storable.
+ */
+ public TestElement createTestElement() {
+ if (getModel() == null) {
+ setModel(new MailerResultCollector());
+ }
+ modifyTestElement(getModel());
+ return getModel();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
+ */
+ public void modifyTestElement(TestElement c) {
+ super.modifyTestElement(c);
+ MailerModel mailerModel = ((MailerResultCollector) c).getMailerModel();
+ mailerModel.setFailureLimit(failureLimitField.getText());
+ mailerModel.setFailureSubject(failureSubjectField.getText());
+ mailerModel.setFromAddress(fromField.getText());
+ mailerModel.setSmtpHost(smtpHostField.getText());
+ mailerModel.setSuccessLimit(successLimitField.getText());
+ mailerModel.setSuccessSubject(successSubjectField.getText());
+ mailerModel.setToAddress(addressField.getText());
+ }
+
+ // ////////////////////////////////////////////////////////////
+ //
+ // Methods to implement the ModelListener.
+ //
+ // ////////////////////////////////////////////////////////////
+
+ /**
+ * Notifies this Visualizer about model-changes. Causes the Visualizer to
+ * query the model about its new state.
+ */
+ public void updateVisualizer(MailerModel model) {
+ addressField.setText(model.getToAddress());
+ fromField.setText(model.getFromAddress());
+ smtpHostField.setText(model.getSmtpHost());
+ successSubjectField.setText(model.getSuccessSubject());
+ failureSubjectField.setText(model.getFailureSubject());
+ failureLimitField.setText(String.valueOf(model.getFailureLimit()));
+ failureField.setText(String.valueOf(model.getFailureCount()));
+ successLimitField.setText(String.valueOf(model.getSuccessLimit()));
+ repaint();
+ }
+
+ /**
+ * Shows a message using a DialogBox.
+ */
+ private void displayMessage(String message, boolean isError) {
+ int type = 0;
+
+ if (isError) {
+ type = JOptionPane.ERROR_MESSAGE;
+ } else {
+ type = JOptionPane.INFORMATION_MESSAGE;
+ }
+ JOptionPane.showMessageDialog(null, message, isError ? "Error" : "Information", type);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see ChangeListener#stateChanged(ChangeEvent)
+ */
+ public void stateChanged(ChangeEvent e) {
+ if (e.getSource() instanceof MailerModel) {
+ MailerModel testModel = (MailerModel) e.getSource();
+ updateVisualizer(testModel);
+ } else {
+ super.stateChanged(e);
+ }
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/ModelListener.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/ModelListener.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/ModelListener.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/ModelListener.java Sun Jul 6 14:47:12 2008
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -21,19 +21,19 @@
/**
* The Interface to be implemented by any class that wants to be notified by
* model which makes use of this callback-Interface.
- *
+ *
* @author <a href="mailto:wolfram.rittmeyer@web.de">Wolfram Rittmeyer</a>
* @version $Revision$ $Date$
*/
public interface ModelListener {
- /**
- * Informs the Visualizer that the model has changed.
- */
- public void updateVisualizer();
+ /**
+ * Informs the Visualizer that the model has changed.
+ */
+ public void updateVisualizer();
- /**
- * Informs the Visualizer that a message should be displayed.
- */
- public void displayMessage(String messageString, boolean isError);
+ /**
+ * Informs the Visualizer that a message should be displayed.
+ */
+ public void displayMessage(String messageString, boolean isError);
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/PropertyControlGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/PropertyControlGui.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/PropertyControlGui.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/PropertyControlGui.java Sun Jul 6 14:47:12 2008
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -56,197 +56,197 @@
public class PropertyControlGui extends AbstractConfigGui
implements ActionListener, UnsharedComponent {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private static final String COLUMN_NAMES_0 = JMeterUtils.getResString("name"); // $NON-NLS-1$
+ private static final String COLUMN_NAMES_0 = JMeterUtils.getResString("name"); // $NON-NLS-1$
- private static final String COLUMN_NAMES_1 = JMeterUtils.getResString("value"); // $NON-NLS-1$
+ private static final String COLUMN_NAMES_1 = JMeterUtils.getResString("value"); // $NON-NLS-1$
- // TODO: add and delete not currently supported
- private static final String ADD = "add"; // $NON-NLS-1$
+ // TODO: add and delete not currently supported
+ private static final String ADD = "add"; // $NON-NLS-1$
- private static final String DELETE = "delete"; // $NON-NLS-1$
-
- private static final String SYSTEM = "system"; // $NON-NLS-1$
-
- private static final String JMETER = "jmeter"; // $NON-NLS-1$
-
- private JCheckBox systemButton = new JCheckBox("System");
- private JCheckBox jmeterButton = new JCheckBox("JMeter");
-
- private JLabel tableLabel = new JLabel("Properties");
-
- /** The table containing the list of arguments. */
- private transient JTable table;
-
- /** The model for the arguments table. */
- protected transient ObjectTableModel tableModel;
-
- /** A button for adding new arguments to the table. */
- private JButton add;
-
- /** A button for removing arguments from the table. */
- private JButton delete;
-
- public PropertyControlGui() {
- super();
- init();
- }
-
- public String getLabelResource() {
- return "property_visualiser_title"; // $NON-NLS-1$
- }
-
- public Collection getMenuCategories() {
- return Arrays.asList(new String[] { MenuFactory.NON_TEST_ELEMENTS });
- }
-
- public void actionPerformed(ActionEvent action) {
- String command = action.getActionCommand();
- if (ADD.equals(command)){
- return;
- }
- if (DELETE.equals(command)){
- return;
- }
- if (SYSTEM.equals(command)){
- setUpData();
- return;
- }
- if (JMETER.equals(command)){
- setUpData();
- return;
- }
-
- }
-
- public void add(SampleResult sample) {
- }
-
- public TestElement createTestElement() {
- TestElement el = new ConfigTestElement();// TODO replace with simpler version?
- modifyTestElement(el);
- return el;
- }
- public void configure(TestElement element) {
- super.configure(element);
- setUpData();
- }
-
- private void setUpData(){
- tableModel.clearData();
- Properties p=null;
- if (systemButton.isSelected()){
- p = System.getProperties();
- }
- if (jmeterButton.isSelected()) {
- p = JMeterUtils.getJMeterProperties();
- }
- if (p == null) {
- return;
- }
- Set s = p.entrySet();
- ArrayList al = new ArrayList(s);
- Collections.sort(al, new Comparator(){
- public int compare(Object o1, Object o2) {
- String m1,m2;
- m1=(String)((Map.Entry)o1).getKey();
- m2=(String)((Map.Entry)o2).getKey();
- return m1.compareTo(m2);
- }
- });
- Iterator i = al.iterator();
- while(i.hasNext()){
- tableModel.addRow(i.next());
- }
-
- }
-
- public void modifyTestElement(TestElement element) {
- configureTestElement(element);
- }
- private Component makeMainPanel() {
- initializeTableModel();
- table = new JTable(tableModel);
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- return makeScrollPane(table);
- }
-
- /**
- * Create a panel containing the title label for the table.
- *
- * @return a panel containing the title label
- */
- private Component makeLabelPanel() {
- JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
- ButtonGroup bg = new ButtonGroup();
- bg.add(systemButton);
- bg.add(jmeterButton);
- jmeterButton.setSelected(true);
- systemButton.setActionCommand(SYSTEM);
- jmeterButton.setActionCommand(JMETER);
- systemButton.addActionListener(this);
- jmeterButton.addActionListener(this);
-
- labelPanel.add(systemButton);
- labelPanel.add(jmeterButton);
- labelPanel.add(tableLabel);
- return labelPanel;
- }
-
- /**
- * Create a panel containing the add and delete buttons.
- *
- * @return a GUI panel containing the buttons
- */
- private JPanel makeButtonPanel() {// Not currently used
- add = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$
- add.setActionCommand(ADD);
- add.setEnabled(true);
-
- delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
- delete.setActionCommand(DELETE);
-
- JPanel buttonPanel = new JPanel();
- buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
- add.addActionListener(this);
- delete.addActionListener(this);
- buttonPanel.add(add);
- buttonPanel.add(delete);
- return buttonPanel;
- }
-
- /**
- * Initialize the components and layout of this component.
- */
- private void init() {
- JPanel p = this;
-
- setLayout(new BorderLayout(0, 5));
- setBorder(makeBorder());
- add(makeTitlePanel(), BorderLayout.NORTH);
- p = new JPanel();
-
- p.setLayout(new BorderLayout());
-
- p.add(makeLabelPanel(), BorderLayout.NORTH);
- p.add(makeMainPanel(), BorderLayout.CENTER);
- // Force a minimum table height of 70 pixels
- p.add(Box.createVerticalStrut(70), BorderLayout.WEST);
- //p.add(makeButtonPanel(), BorderLayout.SOUTH);
-
- add(p, BorderLayout.CENTER);
- table.revalidate();
- }
- private void initializeTableModel() {
- tableModel = new ObjectTableModel(new String[] { COLUMN_NAMES_0, COLUMN_NAMES_1 },
- new Functor[] {
- new Functor(Map.Entry.class, "getKey"), // $NON-NLS-1$
- new Functor(Map.Entry.class, "getValue") }, // $NON-NLS-1$
- new Functor[] {
- null, //new Functor("setName"), // $NON-NLS-1$
- new Functor(Map.Entry.class,"setValue", new Class[] { Object.class }) // $NON-NLS-1$
- },
- new Class[] { String.class, String.class });
- }
+ private static final String DELETE = "delete"; // $NON-NLS-1$
+
+ private static final String SYSTEM = "system"; // $NON-NLS-1$
+
+ private static final String JMETER = "jmeter"; // $NON-NLS-1$
+
+ private JCheckBox systemButton = new JCheckBox("System");
+ private JCheckBox jmeterButton = new JCheckBox("JMeter");
+
+ private JLabel tableLabel = new JLabel("Properties");
+
+ /** The table containing the list of arguments. */
+ private transient JTable table;
+
+ /** The model for the arguments table. */
+ protected transient ObjectTableModel tableModel;
+
+ /** A button for adding new arguments to the table. */
+ private JButton add;
+
+ /** A button for removing arguments from the table. */
+ private JButton delete;
+
+ public PropertyControlGui() {
+ super();
+ init();
+ }
+
+ public String getLabelResource() {
+ return "property_visualiser_title"; // $NON-NLS-1$
+ }
+
+ public Collection getMenuCategories() {
+ return Arrays.asList(new String[] { MenuFactory.NON_TEST_ELEMENTS });
+ }
+
+ public void actionPerformed(ActionEvent action) {
+ String command = action.getActionCommand();
+ if (ADD.equals(command)){
+ return;
+ }
+ if (DELETE.equals(command)){
+ return;
+ }
+ if (SYSTEM.equals(command)){
+ setUpData();
+ return;
+ }
+ if (JMETER.equals(command)){
+ setUpData();
+ return;
+ }
+
+ }
+
+ public void add(SampleResult sample) {
+ }
+
+ public TestElement createTestElement() {
+ TestElement el = new ConfigTestElement();// TODO replace with simpler version?
+ modifyTestElement(el);
+ return el;
+ }
+ public void configure(TestElement element) {
+ super.configure(element);
+ setUpData();
+ }
+
+ private void setUpData(){
+ tableModel.clearData();
+ Properties p=null;
+ if (systemButton.isSelected()){
+ p = System.getProperties();
+ }
+ if (jmeterButton.isSelected()) {
+ p = JMeterUtils.getJMeterProperties();
+ }
+ if (p == null) {
+ return;
+ }
+ Set s = p.entrySet();
+ ArrayList al = new ArrayList(s);
+ Collections.sort(al, new Comparator(){
+ public int compare(Object o1, Object o2) {
+ String m1,m2;
+ m1=(String)((Map.Entry)o1).getKey();
+ m2=(String)((Map.Entry)o2).getKey();
+ return m1.compareTo(m2);
+ }
+ });
+ Iterator i = al.iterator();
+ while(i.hasNext()){
+ tableModel.addRow(i.next());
+ }
+
+ }
+
+ public void modifyTestElement(TestElement element) {
+ configureTestElement(element);
+ }
+ private Component makeMainPanel() {
+ initializeTableModel();
+ table = new JTable(tableModel);
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ return makeScrollPane(table);
+ }
+
+ /**
+ * Create a panel containing the title label for the table.
+ *
+ * @return a panel containing the title label
+ */
+ private Component makeLabelPanel() {
+ JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
+ ButtonGroup bg = new ButtonGroup();
+ bg.add(systemButton);
+ bg.add(jmeterButton);
+ jmeterButton.setSelected(true);
+ systemButton.setActionCommand(SYSTEM);
+ jmeterButton.setActionCommand(JMETER);
+ systemButton.addActionListener(this);
+ jmeterButton.addActionListener(this);
+
+ labelPanel.add(systemButton);
+ labelPanel.add(jmeterButton);
+ labelPanel.add(tableLabel);
+ return labelPanel;
+ }
+
+ /**
+ * Create a panel containing the add and delete buttons.
+ *
+ * @return a GUI panel containing the buttons
+ */
+ private JPanel makeButtonPanel() {// Not currently used
+ add = new JButton(JMeterUtils.getResString("add")); // $NON-NLS-1$
+ add.setActionCommand(ADD);
+ add.setEnabled(true);
+
+ delete = new JButton(JMeterUtils.getResString("delete")); // $NON-NLS-1$
+ delete.setActionCommand(DELETE);
+
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
+ add.addActionListener(this);
+ delete.addActionListener(this);
+ buttonPanel.add(add);
+ buttonPanel.add(delete);
+ return buttonPanel;
+ }
+
+ /**
+ * Initialize the components and layout of this component.
+ */
+ private void init() {
+ JPanel p = this;
+
+ setLayout(new BorderLayout(0, 5));
+ setBorder(makeBorder());
+ add(makeTitlePanel(), BorderLayout.NORTH);
+ p = new JPanel();
+
+ p.setLayout(new BorderLayout());
+
+ p.add(makeLabelPanel(), BorderLayout.NORTH);
+ p.add(makeMainPanel(), BorderLayout.CENTER);
+ // Force a minimum table height of 70 pixels
+ p.add(Box.createVerticalStrut(70), BorderLayout.WEST);
+ //p.add(makeButtonPanel(), BorderLayout.SOUTH);
+
+ add(p, BorderLayout.CENTER);
+ table.revalidate();
+ }
+ private void initializeTableModel() {
+ tableModel = new ObjectTableModel(new String[] { COLUMN_NAMES_0, COLUMN_NAMES_1 },
+ new Functor[] {
+ new Functor(Map.Entry.class, "getKey"), // $NON-NLS-1$
+ new Functor(Map.Entry.class, "getValue") }, // $NON-NLS-1$
+ new Functor[] {
+ null, //new Functor("setName"), // $NON-NLS-1$
+ new Functor(Map.Entry.class,"setValue", new Class[] { Object.class }) // $NON-NLS-1$
+ },
+ new Class[] { String.class, String.class });
+ }
}
\ No newline at end of file
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SimpleDataWriter.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SimpleDataWriter.java?rev=674351&r1=674350&r2=674351&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SimpleDataWriter.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/visualizers/SimpleDataWriter.java Sun Jul 6 14:47:12 2008
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
*/
package org.apache.jmeter.visualizers;
@@ -26,48 +26,48 @@
/*******************************************************************************
* This listener can record results to a file but not to the UI. It is meant to
* provide an efficient means of recording data by eliminating GUI overhead.
- *
+ *
******************************************************************************/
public class SimpleDataWriter extends AbstractVisualizer {
- /***************************************************************************
- * Create the SimpleDataWriter.
- **************************************************************************/
-
- public SimpleDataWriter() {
- init();
- setName(getStaticLabel());
- }
-
- public String getLabelResource() {
- return "simple_data_writer_title"; // $NON-NLS-1$
- }
-
- /**
- * Initialize the component in the UI
- */
-
- private void init() {
- setLayout(new BorderLayout());
- setBorder(makeBorder());
-
- add(makeTitlePanel(), BorderLayout.NORTH);
- }
-
- /**
- * Does nothing, but required by interface.
- */
-
- public void clearData() {
- }
-
- /**
- * Does nothing, but required by interface.
- *
- * @param sample
- * ignored
- */
+ /***************************************************************************
+ * Create the SimpleDataWriter.
+ **************************************************************************/
+
+ public SimpleDataWriter() {
+ init();
+ setName(getStaticLabel());
+ }
+
+ public String getLabelResource() {
+ return "simple_data_writer_title"; // $NON-NLS-1$
+ }
+
+ /**
+ * Initialize the component in the UI
+ */
+
+ private void init() {
+ setLayout(new BorderLayout());
+ setBorder(makeBorder());
+
+ add(makeTitlePanel(), BorderLayout.NORTH);
+ }
+
+ /**
+ * Does nothing, but required by interface.
+ */
+
+ public void clearData() {
+ }
+
+ /**
+ * Does nothing, but required by interface.
+ *
+ * @param sample
+ * ignored
+ */
- public void add(SampleResult sample) {
- }
+ public void add(SampleResult sample) {
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org