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 ms...@apache.org on 2002/06/14 02:12:34 UTC

cvs commit: jakarta-jmeter/src_1/org/apache/jmeter/visualizers Graph.java

mstover1    2002/06/13 17:12:34

  Modified:    src_1/org/apache/jmeter/assertions Assertion.java
               src_1/org/apache/jmeter/assertions/gui AssertionGui.java
               src_1/org/apache/jmeter/gui/action Load.java
               src_1/org/apache/jmeter/gui/util JMeterColor.java
               src_1/org/apache/jmeter/protocol/jdbc/sampler
                        JDBCSampler.java
               src_1/org/apache/jmeter/save SaveService.java
               src_1/org/apache/jmeter/visualizers Graph.java
  Added:       src_1/org/apache/jmeter/gui/util PowerTableModel.java
               src_1/org/apache/jmeter/util Data.java
  Removed:     src_1/org/apache/jmeter/protocol/jdbc/util Data.java
  Log:
  Improving gui for Assertions
  Refactoring gui code
  
  Revision  Changes    Path
  1.7       +11 -1     jakarta-jmeter/src_1/org/apache/jmeter/assertions/Assertion.java
  
  Index: Assertion.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/assertions/Assertion.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Assertion.java	2 May 2002 22:54:58 -0000	1.6
  +++ Assertion.java	14 Jun 2002 00:12:33 -0000	1.7
  @@ -157,10 +157,20 @@
   	{
   		getTestStrings().add(testString);
   	}
  +	
  +	public void setTestString(String testString,int index)
  +	{
  +		getTestStrings().set(index,testString);
  +	}
   
   	public void removeTestString(String testString)
   	{
   		getTestStrings().remove(testString);
  +	}
  +	
  +	public void removeTestString(int index)
  +	{
  +		getTestStrings().remove(index);
   	}
   
   	public void clearTestStrings()
  
  
  
  1.6       +135 -110  jakarta-jmeter/src_1/org/apache/jmeter/assertions/gui/AssertionGui.java
  
  Index: AssertionGui.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/assertions/gui/AssertionGui.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AssertionGui.java	13 Jun 2002 00:45:15 -0000	1.5
  +++ AssertionGui.java	14 Jun 2002 00:12:33 -0000	1.6
  @@ -53,20 +53,38 @@
    * <http://www.apache.org/>.
    */
   package org.apache.jmeter.assertions.gui;
  -import java.awt.Component;
  +import java.awt.BorderLayout;
   import java.awt.Color;
  +import java.awt.Component;
   import java.awt.Font;
  -import java.awt.event.*;
  -import java.util.*;
  -import javax.swing.*;
  -import javax.swing.border.*;
  -import javax.swing.table.*;
  +import java.awt.GridBagConstraints;
  +import java.awt.GridBagLayout;
  +import java.awt.event.ActionEvent;
  +import java.awt.event.ActionListener;
  +import java.awt.event.FocusEvent;
  +import java.awt.event.FocusListener;
  +import java.util.Iterator;
  +
  +import javax.swing.BorderFactory;
  +import javax.swing.Box;
  +import javax.swing.ButtonGroup;
  +import javax.swing.DefaultListCellRenderer;
  +import javax.swing.JButton;
  +import javax.swing.JCheckBox;
  +import javax.swing.JLabel;
  +import javax.swing.JList;
  +import javax.swing.JPanel;
  +import javax.swing.JRadioButton;
  +import javax.swing.JScrollPane;
  +import javax.swing.JTable;
  +import javax.swing.border.Border;
  +import javax.swing.border.EmptyBorder;
  +import javax.swing.table.DefaultTableModel;
   import org.apache.jmeter.assertions.Assertion;
  -import org.apache.jmeter.gui.*;
  -import org.apache.jmeter.gui.util.VerticalLayout;
  -import org.apache.jmeter.samplers.SampleResult;
  -import org.apache.jmeter.util.JMeterUtils;
  +import org.apache.jmeter.gui.util.PowerTableModel;
   import org.apache.jmeter.testelement.TestElement;
  +import org.apache.jmeter.util.JMeterUtils;
  +
   
   /****************************************
    * Title: Jakarta-JMeter Description: Copyright: Copyright (c) 2001 Company:
  @@ -77,13 +95,15 @@
    *@version   1.0
    ***************************************/
   
  -public class AssertionGui extends AbstractAssertionGui
  +public class AssertionGui extends AbstractAssertionGui implements FocusListener
   {
  +	static final String COL_NAME = JMeterUtils.getResString("assertion_patterns_to_test");
  +	
   	private JRadioButton responseStringButton, labelButton, containsBox, matchesBox;
   	private JCheckBox notBox;
  -	private JTextArea addPatternField;
  -	private JList patternList;
  -	private JButton addPattern, clearPatterns;
  +	private JTable stringTable;
  +	private JButton addPattern,deletePattern;
  +	PowerTableModel tableModel;
   
   	/****************************************
   	 * !ToDo (Constructor description)
  @@ -100,7 +120,12 @@
   
   	public TestElement createTestElement()
   	{
  -		Assertion el = ((PatternListModel)patternList.getModel()).model;
  +		Assertion el = new Assertion();
  +		String[] testStrings = tableModel.getData().getColumn(COL_NAME);
  +		for(int i = 0;i < testStrings.length;i++)
  +		{
  +			el.addTestString(testStrings[i]);
  +		}
   		configureTestElement(el);
   		if(labelButton.isSelected())
   		{
  @@ -167,18 +192,35 @@
   			responseStringButton.setSelected(false);
   			labelButton.setSelected(true);
   		}
  -		((PatternListModel)patternList.getModel()).model = model;
  +		Iterator tests = model.getTestStrings().iterator();
  +		while(tests.hasNext())
  +		{
  +			tableModel.addRow(new Object[]{tests.next()});
  +		}
  +		tableModel.fireTableDataChanged();
   	}
   
   	private void init()
   	{
  -		this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
  +		this.setLayout(new GridBagLayout());
  +		GridBagConstraints gbc = new GridBagConstraints();
  +		gbc.anchor = gbc.WEST;
  +		gbc.fill = gbc.BOTH;
  +		gbc.gridheight = 1;
  +		gbc.gridwidth = 1;
  +		gbc.gridx = 0;
  +		gbc.gridy = 0;
  +		gbc.weightx = 1;
  +		gbc.weighty = 1;
   
   		// MAIN PANEL
   		JPanel mainPanel = new JPanel();
  +		add(mainPanel,gbc.clone());
  +		gbc.fill = gbc.NONE;
  +		gbc.weighty = 0;
  +		mainPanel.setLayout(new GridBagLayout());
   		Border margin = new EmptyBorder(10, 10, 5, 10);
   		mainPanel.setBorder(margin);
  -		mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
   
   		// TITLE
   		JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("assertion_title"));
  @@ -186,16 +228,25 @@
   		int curFontSize = curFont.getSize();
   		curFontSize += 4;
   		panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize));
  -		mainPanel.add(panelTitleLabel);
  +		mainPanel.add(panelTitleLabel,gbc.clone());
  +		gbc.gridy++;
   
   		// NAME
  -		mainPanel.add(getNamePanel());
  -
  -		mainPanel.add(createFieldPanel());
  -		mainPanel.add(createTypePanel());
  -		mainPanel.add(createStringPanel());
  -
  -		this.add(mainPanel);
  +		mainPanel.add(getNamePanel(),gbc.clone());
  +		gbc.gridx++;
  +		gbc.fill = gbc.HORIZONTAL;
  +		mainPanel.add(Box.createHorizontalGlue(),gbc.clone());
  +		gbc.gridx--;
  +		gbc.fill = gbc.NONE;
  +		gbc.gridy++;
  +		mainPanel.add(createFieldPanel(),gbc.clone());
  +		gbc.gridy++;
  +		mainPanel.add(createTypePanel(),gbc.clone());
  +		gbc.gridy++;
  +		gbc.fill = gbc.BOTH;
  +		gbc.weighty = 1;
  +		gbc.gridwidth = 2;
  +		mainPanel.add(createStringPanel(),gbc.clone());
   	}
   
   	private JPanel createFieldPanel()
  @@ -231,23 +282,49 @@
   		containsBox.setSelected(true);
   		return panel;
   	}
  +	
  +	/****************************************
  +	 * Description of the Method
  +	 *
  +	 *@param e  Description of Parameter
  +	 ***************************************/
  +	public void focusLost(FocusEvent e)
  +	{
  +		try
  +		{
  +			stringTable.getCellEditor().stopCellEditing();
  +		}
  +		catch(NullPointerException err){}
  +	}
  +
  +	/****************************************
  +	 * Description of the Method
  +	 *
  +	 *@param e  Description of Parameter
  +	 ***************************************/
  +	public void focusGained(FocusEvent e) { }
   
   	private JPanel createStringPanel()
   	{
   		JPanel panel = new JPanel();
  +		stringTable = new JTable(0,1);
  +		stringTable.addFocusListener(this);
  +		tableModel = new PowerTableModel(new String[]{COL_NAME},new Class[]{String.class});
  +		stringTable.setModel(tableModel);
  +		panel.setLayout(new BorderLayout());
   		panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
   				JMeterUtils.getResString("assertion_patterns_to_test")));
  -		patternList = new JList(new PatternListModel());
  -		addPatternField = new JTextArea(3, 25);
  +		panel.add(new JScrollPane(stringTable),BorderLayout.CENTER);
   		addPattern = new JButton(JMeterUtils.getResString("add"));
  +		deletePattern = new JButton(JMeterUtils.getResString("delete"));
   		addPattern.addActionListener(new AddPatternListener());
  -		patternList.setCellRenderer(new DefaultListCellRenderer());
  -		clearPatterns = new JButton(org.apache.jmeter.util.JMeterUtils.getResString("clear"));
  -		clearPatterns.addActionListener(new ClearPatternsListener());
  -		panel.add(addPatternField);
  -		panel.add(addPattern);
  -		panel.add(patternList);
  -		panel.add(clearPatterns);
  +		deletePattern.addActionListener(new ClearPatternsListener());
  +		JPanel buttonPanel = new JPanel();
  +		buttonPanel.add(addPattern);
  +		buttonPanel.add(deletePattern);
  +		panel.add(buttonPanel,BorderLayout.SOUTH);
  +		deletePattern.setEnabled(false);
  +		
   		return panel;
   	}
   
  @@ -267,7 +344,16 @@
   		 ***************************************/
   		public void actionPerformed(ActionEvent e)
   		{
  -			((PatternListModel)patternList.getModel()).clear();
  +			int index = stringTable.getSelectedRow();
  +			if(index > -1)
  +			{
  +				tableModel.removeRow(index);
  +				tableModel.fireTableDataChanged();
  +			}
  +			if(stringTable.getModel().getRowCount() == 0)
  +			{
  +				deletePattern.setEnabled(false);
  +			}
   		}
   	}
   
  @@ -287,9 +373,9 @@
   		 ***************************************/
   		public void actionPerformed(ActionEvent e)
   		{
  -			String pattern = addPatternField.getText();
  -			addPatternField.setText("");
  -			((PatternListModel)patternList.getModel()).addTestString(pattern);
  +			tableModel.addNewRow();
  +			deletePattern.setEnabled(true);
  +			tableModel.fireTableDataChanged();
   		}
   	}
   
  @@ -349,68 +435,7 @@
   		}
   	}
   
  -	/****************************************
  -	 * !ToDo (Class description)
  -	 *
  -	 *@author    $Author$
  -	 *@created   $Date$
  -	 *@version   $Revision$
  -	 ***************************************/
  -	private class PatternListModel extends AbstractListModel
  -	{
  -		Assertion model;
  -
  -		/****************************************
  -		 * !ToDo (Constructor description)
  -		 *
  -		 *@param model  !ToDo (Parameter description)
  -		 ***************************************/
  -		public PatternListModel()
  -		{
  -			super();
  -			model = new Assertion();
  -		}
  -
  -		/****************************************
  -		 * !ToDoo (Method description)
  -		 *
  -		 *@return   !ToDo (Return description)
  -		 ***************************************/
  -		public int getSize()
  -		{
  -			return model.getTestStrings().size();
  -		}
  -
  -		/****************************************
  -		 * !ToDo
  -		 *
  -		 *@param pattern  !ToDo
  -		 ***************************************/
  -		public void addTestString(String pattern)
  -		{
  -			model.addTestString(pattern);
  -			int size = model.getTestStrings().size();
  -			this.fireIntervalAdded(this, size - 1, size);
  -		}
  -
  -		/****************************************
  -		 * !ToDoo (Method description)
  -		 *
  -		 *@param index  !ToDo (Parameter description)
  -		 *@return       !ToDo (Return description)
  -		 ***************************************/
  -		public Object getElementAt(int index)
  -		{
  -			return model.getTestStrings().get(index);
  -		}
  -
  -		/****************************************
  -		 * !ToDo (Method description)
  -		 ***************************************/
  -		public void clear()
  -		{
  -			model.clearTestStrings();
  -			this.fireContentsChanged(this, 0, 0);
  -		}
  -	}
  +	
  +	
  +	
   }
  
  
  
  1.10      +4 -3      jakarta-jmeter/src_1/org/apache/jmeter/gui/action/Load.java
  
  Index: Load.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/gui/action/Load.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Load.java	13 Jun 2002 00:45:16 -0000	1.9
  +++ Load.java	14 Jun 2002 00:12:33 -0000	1.10
  @@ -142,7 +142,8 @@
   		}
   		catch(Throwable ex)
   		{
  -			try
  +			ex.printStackTrace();
  +			/*try
   			{
   				legacyLoad(f);
   			}
  @@ -151,7 +152,7 @@
   				//ex.printStackTrace();
   				err.printStackTrace();
   				JMeterUtils.reportErrorToUser("Couldn't load JMX file.  May have been corrupted");
  -			}
  +			}*/
   		}
   		finally
   		{
  
  
  
  1.3       +1 -0      jakarta-jmeter/src_1/org/apache/jmeter/gui/util/JMeterColor.java
  
  Index: JMeterColor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/gui/util/JMeterColor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JMeterColor.java	29 May 2002 22:52:35 -0000	1.2
  +++ JMeterColor.java	14 Jun 2002 00:12:33 -0000	1.3
  @@ -65,6 +65,7 @@
   public class JMeterColor extends Color {
   	
   	public final static Color dark_green = new JMeterColor(0F,.5F,0F);
  +	public final static Color YELLOW = new JMeterColor(1F,1F,0);
   	
   	public JMeterColor(float r,float g,float b)
   	{
  
  
  
  1.1                  jakarta-jmeter/src_1/org/apache/jmeter/gui/util/PowerTableModel.java
  
  Index: PowerTableModel.java
  ===================================================================
  package org.apache.jmeter.gui.util;
  
  import javax.swing.table.DefaultTableModel;
  
  import org.apache.jmeter.util.Data;
  
  /**
   * @author mstover
   *
   * To change this generated comment edit the template variable "typecomment":
   * Window>Preferences>Java>Templates.
   */
  public class PowerTableModel extends DefaultTableModel {
  	Data model = new Data();
  	Class[] columnClasses;
  
  	public PowerTableModel(String[] headers, Class[] cc) {
  		model.setHeaders(headers);
  		columnClasses = cc;
  	}
  
  	public void setRowValues(int row, Object[] values) {
  		model.setCurrentPos(row);
  		for (int i = 0; i < values.length; i++) {
  			model.addColumnValue(model.getHeaders()[i], values[i]);
  		}
  	}
  
  	public Data getData() {
  		return model;
  	}
  
  	/****************************************
  		 * Description of the Method
  		 *
  		 *@param row  Description of Parameter
  		 ***************************************/
  	public void removeRow(int row) {
  		if (model.size() > row) {
  			model.removeRow(row);
  		}
  	}
  
  	public void addRow(Object data[]) {
  		model.setCurrentPos(model.size());
  		for (int i = 0; i < data.length; i++) {
  			model.addColumnValue(model.getHeaders()[i], data[i]);
  		}
  	}
  
  	/****************************************
  	 ***************************************/
  	public void addNewRow() {
  		model.addRow();
  	}
  
  	/****************************************
  	 * required by table model interface
  	 *
  	 *@return   The RowCount value
  	 ***************************************/
  	public int getRowCount() {
  		if (model == null) {
  			return 0;
  		}
  		return model.size();
  	}
  
  	/****************************************
  	 * required by table model interface
  	 *
  	 *@return   The ColumnCount value
  	 ***************************************/
  	public int getColumnCount() {
  		return model.getHeaders().length;
  	}
  
  	/****************************************
  	 * required by table model interface
  	 *
  	 *@param column  Description of Parameter
  	 *@return        The ColumnName value
  	 ***************************************/
  	public String getColumnName(int column) {
  		return model.getHeaders()[column];
  	}
  
  	/****************************************
  	 * !ToDoo (Method description)
  	 *
  	 *@param row     !ToDo (Parameter description)
  	 *@param column  !ToDo (Parameter description)
  	 *@return        !ToDo (Return description)
  	 ***************************************/
  	public boolean isCellEditable(int row, int column) {
  		// all table cells are editable
  		return true;
  	}
  
  	/****************************************
  	 * !ToDoo (Method description)
  	 *
  	 *@param column  !ToDo (Parameter description)
  	 *@return        !ToDo (Return description)
  	 ***************************************/
  	public Class getColumnClass(int column) {
  		return columnClasses[column];
  	}
  
  	/****************************************
  	 * required by table model interface
  	 *
  	 *@param row     Description of Parameter
  	 *@param column  Description of Parameter
  	 *@return        The ValueAt value
  	 ***************************************/
  	public Object getValueAt(int row, int column) {
  		return model.getColumnValue(column, row);
  	}
  
  	/****************************************
  	 * Sets the ValueAt attribute of the Arguments object
  	 *
  	 *@param value   The new ValueAt value
  	 *@param row     The new ValueAt value
  	 *@param column  !ToDo (Parameter description)
  	 ***************************************/
  	public void setValueAt(Object value, int row, int column) {
  		model.setCurrentPos(row);
  		model.addColumnValue(model.getHeaders()[column], value);
  	}
  
  }
  
  
  1.10      +18 -9     jakarta-jmeter/src_1/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java
  
  Index: JDBCSampler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/protocol/jdbc/sampler/JDBCSampler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JDBCSampler.java	1 Jun 2002 13:21:27 -0000	1.9
  +++ JDBCSampler.java	14 Jun 2002 00:12:33 -0000	1.10
  @@ -54,18 +54,27 @@
    */
    package org.apache.jmeter.protocol.jdbc.sampler;
   
  -import java.sql.*;
  -import java.util.*;
  -import org.apache.jmeter.util.JMeterUtils;
  -import org.apache.jmeter.config.*;
  -import org.apache.jmeter.protocol.jdbc.config.*;
  +import java.net.URL;
  +import java.sql.Connection;
  +import java.sql.ResultSet;
  +import java.sql.ResultSetMetaData;
  +import java.sql.SQLException;
  +import java.sql.Statement;
  +import java.util.HashMap;
  +import java.util.Map;
   
  -import org.apache.jmeter.protocol.jdbc.util.*;
  +import org.apache.jmeter.config.ConfigTestElement;
  +import org.apache.jmeter.protocol.jdbc.config.DbConfig;
  +import org.apache.jmeter.protocol.jdbc.config.PoolConfig;
  +import org.apache.jmeter.protocol.jdbc.config.SqlConfig;
  +import org.apache.jmeter.protocol.jdbc.util.DBConnectionManager;
  +import org.apache.jmeter.protocol.jdbc.util.DBKey;
   import org.apache.jmeter.samplers.AbstractSampler;
  -import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.samplers.Entry;
  +import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jmeter.testelement.TestListener;
  +import org.apache.jmeter.util.Data;
   
   /************************************************************
    *  A sampler which understands JDBC database requests
  
  
  
  1.7       +1 -2      jakarta-jmeter/src_1/org/apache/jmeter/save/SaveService.java
  
  Index: SaveService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/save/SaveService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SaveService.java	13 Jun 2002 00:45:17 -0000	1.6
  +++ SaveService.java	14 Jun 2002 00:12:34 -0000	1.7
  @@ -23,7 +23,6 @@
   import org.apache.jmeter.samplers.SampleResult;
   import org.apache.jmeter.testelement.TestElement;
   import org.apache.jmeter.util.ListedHashTree;
  -import org.omg.PortableInterceptor.SUCCESSFUL;
   import org.xml.sax.SAXException;
   /**
    * <p>Title: </p>
  @@ -173,7 +172,7 @@
   		config.setAttribute(THREAD_NAME,result.getThreadName());
   		config.setAttribute(DATA_TYPE,result.getDataType());
   		config.setAttribute(TIME_STAMP,""+result.getTimeStamp());
  -		config.setAttribute(SUCCESSFUL,Boolean.toString(result.isSuccessful()));
  +		config.setAttribute(SUCCESSFUL,new Boolean(result.isSuccessful()).toString());
   		SampleResult[] subResults = result.getSubResults();
   		for(int i = 0;i < subResults.length;i++)
   		{
  
  
  
  1.1                  jakarta-jmeter/src_1/org/apache/jmeter/util/Data.java
  
  Index: Data.java
  ===================================================================
  /*
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   * notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   * notice, this list of conditions and the following disclaimer in
   * the documentation and/or other materials provided with the
   * distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   * if any, must include the following acknowledgment:
   * "This product includes software developed by the
   * Apache Software Foundation (http://www.apache.org/)."
   * Alternately, this acknowledgment may appear in the software itself,
   * if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   * "Apache JMeter" must not be used to endorse or promote products
   * derived from this software without prior written permission. For
   * written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   * "Apache JMeter", nor may "Apache" appear in their name, without
   * prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jmeter.util;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  
  /****************************************************************
   Use this class to store database-like data.  This class uses rows
   and columns to organize its data.  It has some convenience methods
   that allow fast loading and retrieval of the data into and out of
   string arrays.  It also can work closely with the DataTree class to
   sort string data.
  @author Michael Stover
  @version 1.0 10/14/1998
   ******************************************************************/
  public class Data
  {
    Map data;
    Map iterators = new HashMap();
   // Hashtable dataLine;
    ArrayList header;
    // saves current position in data Vector
    int currentPos,size;
  
  /*******************************************************************
   Constructor - takes no arguments.
  *****************************************************************/
    public Data()
    {
    	header = new ArrayList();
  	 data=new HashMap();
  	 currentPos=-1;
  	 size = currentPos+1;
    }
  
  /***************************************************************
    Replaces the given header name with a new header name.
  @param oldHeader Old header name.
  @param newHeader New header name.
  **************************************************************/
    public void replaceHeader(String oldHeader,String newHeader)
    {
  	 List tempList;
  	 int index=header.indexOf(oldHeader);
  	 header.set(index,newHeader);
  	 tempList = (List)data.remove(oldHeader);
  	 data.put(newHeader,tempList);
    }
  /*************************************************************
  Adds the rows of the given Data object to this Data object.
  @param d data object to be appended to this one.
  **************************************************************/
    public void append(Data d)
    {
  	 boolean valid=true;
  	 String[] headers=getHeaders();
  	 String[] dHeaders=d.getHeaders();
  	 if(headers.length!=dHeaders.length)
  		valid=false;
  	 else
  		for(int count = 0;count<headers.length && count<dHeaders.length;count++)
  		  if(JMeterUtils.findInArray(headers,dHeaders[count])<0)
  			 valid=false;
  	 if(valid)
  	 {
  		currentPos=size;
  		d.reset();
  		while(d.next())
  		{
  		  for(int count = 0;count<headers.length;count++)
  			 addColumnValue(headers[count],d.getColumnValue(headers[count]));
  		}
  	 }
    }
  
    /***********************************
  	Get the number of the current row.
  @return  Integer representing the current row.
    *************************************/
    public int getCurrentPos()
    {
  	 return currentPos;
    }// end method
  
    /******************************************************
    Removes the current row.
    ******************************************************/
    public void removeRow()
    {
  	 List tempList;
  	 Iterator it = data.keySet().iterator();
  	 if(currentPos>-1 && currentPos<size)
  	 {
  		while(it.hasNext())
  		{
  		  tempList = (List)data.get(it.next());
  		  tempList.remove(currentPos);
  		}
  		currentPos--;
  		size--;
  	 }
    } // End Method
    
    public void removeRow(int index)
    {
    	if(index < size)
    	{
    		setCurrentPos(index);
    		removeRow();
    	}
    }
    
    public void addRow()
    {
    	String[] headers = getHeaders();
    	List tempList = new ArrayList();
    	for(int i = 0;i < headers.length;i++)
    	{
    		if((tempList = (ArrayList)data.get(header.get(i))) == null)
  	 	{
  			tempList = new ArrayList();
  			data.put(headers[i],tempList);
  	 	}
  	 	tempList.add("");
    	}
    	size = tempList.size();
    	setCurrentPos(size - 1);
    }
  
    /******************************************************
    Sets the current pos. If value sent to method is not a valid number,
    the current position is set to one higher than the maximum.
  @param  r position to set to.
    ******************************************************/
    public void setCurrentPos(int r)
    {
  	 currentPos=r;
    } // End Method
  
    /******************************************************
    Sorts the data using a given row as the sorting criteria.  A boolean
  	value indicates whether to sort ascending or descending.
  @param column Name of column to use as sorting criteria.
  @param asc boolean value indicating whether to sort ascending or descending.  True for
  	asc, false for desc.  Currently this feature is not enabled and all sorts are asc.
    ******************************************************/
    public void sort(String column,boolean asc)
    {
  	 sortData(column,0,size);
    } // End Method
  
    private void swapRows(int row1,int row2)
    {
  	 List temp;
  	 Object o;
  	 Iterator it = data.keySet().iterator();
  	 while(it.hasNext())
  	 {
  		temp = (List)data.get(it.next());
  		o = temp.get(row1);
  		temp.set(row1,temp.get(row2));
  		temp.set(row2,o);
  	 }
    }
  
  	 /************************************************************
  	Private method that implements the quicksort algorithm to sort the rows of the Data object.
  @param column Name of column to use as sorting criteria.
  @param starting index (for quicksort algorithm).
  @param ending index (for quicksort algorithm).
  	***********************************************************/
    private void sortData(String column,int start,int end)
    {
  	 int x=start,y=end-1;
  	 String basis=((List)data.get(column)).get((int)((x+y)/2)).toString();
  	 Object temp;
  	 if(x==y)
  		return;
  	 while(x<=y)
  	 {
  		while(x<end && ((List)data.get(column)).get(x).toString().compareTo(basis)<0)
  		  x++;
  		while(y>=(start-1) && ((List)data.get(column)).get(y).toString().compareTo(basis)>0)
  		  y--;
  		if(x<=y)
  		{
  		  swapRows(x,y);
  		  x++;
  		  y--;
  		}
  	 }
  	 if(x==y)
  		x++;
  	 y=end-x;
  	 if(x>0)
  		sortData(column,start,x);
  	 if(y>0)
  		sortData(column,x,end);
    }
  
    /***********************************
  	Gets the number of rows in the Data object.
  @return   Returns number of rows in Data object.
    *************************************/
    public int size()
    {
  	 return size;
    }// end method
  
    /*******************************************************
  	Adds a value into the Data set at the current row, using a column name
  	to find the column in which to insert the new value.
  @param column The name of the column to set.
  @param value Value to set into column.
    **********************************************************/
    public void addColumnValue(String column,Object value)
    {
  	 ArrayList tempList;
  	 if((tempList = (ArrayList)data.get(column)) == null)
  	 {
  		tempList = new ArrayList();
  		data.put(column,tempList);
  	 }
  	 int s = tempList.size();
  	 if(currentPos==-1)
  		currentPos=size;
  	 if(currentPos>=size)
  		  size = currentPos+1;
  	 while(currentPos>s)
  	 {
  		s++;
  		tempList.add(null);
  	 }
  	 if(currentPos == s)
  		tempList.add(value);
  	 else
  		tempList.set(currentPos,value);
    }// end method
  
  /**************************************************************
  Returns the row number where a certain value is.
  @param column Column to be searched for value.
  @param value object in Search of.
  @return row # where value exists.
  **************************************************************/
    public int findValue(String column,Object value)
    {
  	 List list = (List)data.get(column);
  	 int ret=-1;
  	 ret = list.indexOf(value);
  	 return ret;
    }
  
    /*******************************************************
  	Sets the value in the Data set at the current row, using a column name
  	to find the column in which to insert the new value.
  @param column The name of the column to set.
  @param value Value to set into column.
    **********************************************************/
    public void setColumnValue(String column,Object value)
    {
  	 List tempList;
  	 if((tempList = (List)data.get(column)) == null)
  	 {
  		tempList = new ArrayList();
  		data.put(column,tempList);
  	 }
  	 if(currentPos==-1)
  		currentPos=0;
  	 if(currentPos>=size)
  	 {
  		  size++;
  		  tempList.add(value);
  	 }
  	 else
  		tempList.set(currentPos,value);
    }// end method
  
    /******************************************************
    Checks to see if a column exists in the Data object.
  @param  column Name of column header to check for.
  @return True or False depending on whether the column exists.
    ******************************************************/
    public boolean hasHeader(String column)
    {
  	 return data.containsKey(column);
    } // End Method
  
    /***********************************
  	Sets the current position of the Data set to the next row.
  @return  True if there is another row.  False if there are no more rows.
    *************************************/
    public boolean next()
    {
  	 if(++currentPos>=size)
  		return false;
  	 else return true;
    }// end method
  
    /***********************************
  	Sets the current position of the Data set to the previous row.
  @return  True if there is another row.  False if there are no more rows.
    *************************************/
    public boolean previous()
    {
  	 if(--currentPos<0)
  		return false;
  	 else return true;
    }// end method
  
    /***********************************
    Resets the current position of the data set to just before the first element.
    *************************************/
    public void reset()
    {
  	 currentPos=-1;
    }// end method
  
    /***********************************
    Gets the value in the current row of the given column.
  @param column Name of the column.
  @return Returns an Object which holds the value of the column.
    *************************************/
    public Object getColumnValue(String column)
    {
  
  	 try{
  		if(currentPos<size)
  		  return ((List)data.get(column)).get(currentPos);
  		else
  		  return null;
  	 }catch(Exception e){return null;}
    }// end method
  
  		  /***********************************
    Gets the value in the current row of the given column.
  @param column index of the column (starts at 0).
  @return Returns an Object which holds the value of the column.
    *************************************/
    public Object getColumnValue(int column)
    {
  	 String columnName = (String)header.get(column);
  	 try{
  		if(currentPos<size)
  		  return ((List)data.get(columnName)).get(currentPos);
  		else
  		  return null;
  	 }catch(Exception e){return null;}
    }// end method
    
    public Object getColumnValue(int column,int row)
    {
    	setCurrentPos(row);
    	return getColumnValue(column);
    }
  
  
  
    /*****************************************************************
  	Sets the headers for the data set.  Each header represents a column
  	of data.  Each row's data can be gotten with the column header name,
  	which will always be a string.
  @param h Array of strings representing the column headers.
  	**************************************************************/
    public void setHeaders(String[] h)
    {
  	 int x=0;
  	 header=new ArrayList(h.length);
  	 for(x = 0;x<h.length;x++)
  	 {
  		header.add(h[x]);
  		data.put(h[x],new ArrayList());
  	 }
    }
  
  
    /*****************************************************************
  	 Returns a String array of the column headers.
  @return Array of strings of the column headers.
    *****************************************************************/
    public String[] getHeaders()
    {
  	 String[] r=new String[header.size()];
  	 if ( r.length>0 )
  	 {
  		r=(String[])header.toArray(r);
  	 }
  	 return r;
    } //end of Method
  
    /*****************************************************************
  	 This method will retrieve every entry in a certain column.  It returns an array of Objects
  	from the column.
  @param columnName String value, name of the column.
  @return Array of Objects representing the data.
    *****************************************************************/
    public Object[] getColumnAsObjectArray(String columnName)
    {
  	 Object[] returnValue;
  	 Object o;
  	 List temp=(List)data.get(columnName);
  	 if(temp != null)
  		returnValue = temp.toArray();
  	 else
  		returnValue = new Object[0];
  	 return returnValue;
    }// end of Method
  
  
  
    /*****************************************************************
  	 This method will retrieve every entry in a certain column.  It returns an array of strings
  	from the column. Even if the data are not strings, they will be returned as
  	strings in this method.
  @param columnName String value, name of the column.
  @return Array of Strings representing the data.
    *****************************************************************/
    public String[] getColumn(String columnName)
    {
  	 String[] returnValue;
  	 Object o;
  	 List temp=(List)data.get(columnName);
  	 if(temp != null)
  	 {
  		returnValue = new String[temp.size()];
  		Iterator it = temp.iterator();
  		int index = 0;
  		while(it.hasNext())
  		{
  		  o = it.next();
  		  if(o != null)
  		  {
  			 if(o instanceof String)
  				returnValue[index++] = (String)o;
  			 else
  				returnValue[index++] = o.toString();
  		  }
  		}
  	 }
  	 else
  		returnValue = new String[0];
  	 return returnValue;
    }// end of Method
  
    /*****************************************************************
  	 Use this method to set the entire data set.  It takes an array of
  	strings.  It uses the first row as the headers, and the next rows
  	as the data elements.  Delimiter represents the delimiting character(s)
  	that separate each item in a data row.
  @param contents Array of strings, the first element is a list of the column
  	headers, the next elements each represent a single row of data.
  @param delimiter The delimiter character that separates columns within
  	the string array.
  	  *****************************************************************/
    public void setData(String[] contents, String delimiter)
    {
  		setHeaders(JMeterUtils.split(contents[0],delimiter));
  		int x=1;
  		while(x<contents.length)
  		{
  			setLine(JMeterUtils.split(contents[x++],delimiter));
  		}
  	 } //end of Method
  
    /*
  	Deletes a header from the Data object.
  	Takes the column name as input.  It will delete the entire
  	column.
  
    public void deleteHeader(String s)
    {
  
    }*/
  
  
    /***************************************************
  	Adds a header name to the Data object.
  @param s name of header.
  	*************************************************/
    public void addHeader(String s)
    {
  	header.add(s);
  	data.put(s,new ArrayList());
    }
  
    /************************************************************
  	Sets a row of data using an array of strings as input.  Each
  	value in the array represents a column's value in that row.
  	Assumes the order will be the same order in which the headers
  	were added to the data set.
  @param line array of strings representing column values.
  	*********************************************************/
    public void setLine(String[] line)
    {
  	 List tempList;
  	 String[] h = getHeaders();
  	 for(int count = 0;count<h.length;count++)
  	 {
  		tempList = (List)data.get(h[count]);
  		if(count<line.length && line[count].length()>0)
  		  tempList.add(line[count]);
  		else
  		  tempList.add("N/A");
  	 }
  	 size++;
    }
  
    /************************************************************
  	Sets a row of data using an array of strings as input.  Each
  	value in the array represents a column's value in that row.
  	Assumes the order will be the same order in which the headers
  	were added to the data set.
  @param line array of strings representing column values.
  @param deflt Default value to be placed in data if line is not as long as headers.
  	*********************************************************/
    public void setLine(String[] line,String deflt)
    {
  	 List tempList;
  	 String[] h = getHeaders();
  	 for(int count = 0;count<h.length;count++)
  	 {
  		tempList = (List)data.get(h[count]);
  		if(count<line.length && line[count].length()>0)
  		  tempList.add(line[count]);
  		else
  		  tempList.add(deflt);
  	 }
  	 size++;
    }
  
    /******************************************************************
  	Returns all the data in the Data set as an array of strings.  Each
  	array gives a row of data, each column separated by tabs.
  @return array of strings.
  
  	*******************************************************************/
    public String[] getDataAsText()
    {
  	 List tempList;
  	 StringBuffer temp=new StringBuffer("");
  	 String[] line=new String[size+1];
  	 String[] elements = getHeaders();
  	 for(int count = 0;count<elements.length;count++)
  	 {
  		temp.append(elements[count]);
  		if(count+1<elements.length)
  		  temp.append("\t");
  	 }
  	 line[0] = temp.toString();
  	 reset();
  	 int index = 1;
  	 while(next())
  	 {
  		temp = new StringBuffer("");
  		for(int count = 0;count<elements.length;count++)
  		{
  		  temp.append(getColumnValue(count));
  		  if(count+1<elements.length)
  			 temp.append("\t");
  		}
  		line[index++] = temp.toString();
  	 }
  	 return line;
    }
  
    public String toString()
    {
  	 String[] contents = getDataAsText();
  	 StringBuffer sb = new StringBuffer();
  	 boolean first = true;
  	 for(int x = 0;x < contents.length;x++)
  	 {
  		if(!first)
  		  sb.append("\n");
  		else first = false;
  		sb.append(contents[x]);
  	 }
  	 return sb.toString();
    }
  }
  
  
  
  1.6       +1 -1      jakarta-jmeter/src_1/org/apache/jmeter/visualizers/Graph.java
  
  Index: Graph.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src_1/org/apache/jmeter/visualizers/Graph.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Graph.java	13 Jun 2002 00:45:18 -0000	1.5
  +++ Graph.java	14 Jun 2002 00:12:34 -0000	1.6
  @@ -303,7 +303,7 @@
   			}
   			else
   			{
  -				g.setColor(Color.YELLOW);
  +				g.setColor(JMeterColor.YELLOW);
   			}
   			g.drawLine(x % width, d.height - data, x % width, d.height - data - 1);
   		}
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>