Package org.apache.jmeter.protocol.http.config.gui

Source Code of org.apache.jmeter.protocol.http.config.gui.UrlConfigGui

/*
* ====================================================================
* 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.protocol.http.config.gui;

import javax.swing.*;
import java.awt.event.*;

import org.apache.jmeter.gui.*;
import org.apache.jmeter.protocol.http.config.UrlConfig;
import org.apache.jmeter.config.gui.ArgumentsPanel;
import org.apache.jmeter.config.Arguments;

/**
* Title:        JMeter
* Description:
* Copyright:    Copyright (c) 2000
* Company:      Apache
* @author Michael Stover
* @version 1.0
*/

public class UrlConfigGui extends JPanel implements ModelSupported,KeyListener,ActionListener
{
  private static String DOMAIN = "domain";
   private static String PORT = "port";
  //private static String METHOD = "method";
  private static String PATH = "path";
  private static String POST = "post";
  private static String GET = "get";
  private static String HTTP = "http";
  private static String HTTPS = "https";

  private JTextField domain = new JTextField(30);
   private JTextField port = new JTextField(30);
  private JTextField path = new JTextField(30);
  private JRadioButton post = new JRadioButton("POST");
  private JRadioButton get = new JRadioButton("GET");
  private JRadioButton http = new JRadioButton("HTTP");
  private JRadioButton https = new JRadioButton("HTTPS");
  private NamePanel namePanel;
  private boolean displayName = true;

  private UrlConfig model;

  public UrlConfigGui()
  {
  }

  public UrlConfigGui(boolean displayNameField)
  {
    this.displayName = displayNameField;
  }

  public void updateGui()
  {
    domain.setText((String)model.getProperty(UrlConfig.DOMAIN));
    path.setText((String)model.getProperty(UrlConfig.PATH));
    Object portI = model.getProperty(UrlConfig.PORT);
    if (portI!=null)
       port.setText(portI.toString());
    if(namePanel != null)
             namePanel.updateGui();
    if(UrlConfig.POST.equals(model.getProperty(UrlConfig.METHOD)))
    {
      post.setSelected(true);
    }
    else if(UrlConfig.GET.equals(model.getProperty(UrlConfig.METHOD)))
    {
      get.setSelected(true);
    }
    if(http.getText().equalsIgnoreCase(model.getProtocol()))
    {
      http.setSelected(true);
    }
    else if(https.getText().equalsIgnoreCase(model.getProtocol()))
    {
      https.setSelected(true);
    }
  }

  public void setModel(Object model)
  {
    this.model = (UrlConfig)model;
    init();
  }

  private void init()
  {
    this.setLayout(new VerticalLayout(2,VerticalLayout.LEFT));
    if(displayName)
    {
      namePanel = new NamePanel();
      namePanel.setModel(model);
      this.add(namePanel);
    }
    this.add(getProtocolPanel());
    this.add(getDomainPanel());
    this.add(getPortPanel());
    this.add(getPathPanel());
    this.add(getMethodPanel());
    this.add(getParameterPanel());
  }

   private JPanel getPortPanel() {
  JPanel portP = new JPanel();
  portP.add(new JLabel("Port"));
  Object portI = model.getProperty(UrlConfig.PORT);
  if (portI!=null)
     port.setText(portI.toString());
  port.setName(PORT);
  port.addKeyListener(this);
  portP.add(port);
  return portP;
   }

  private JPanel getDomainPanel()
  {
    JPanel domainP = new JPanel();
    domainP.add(new JLabel("Domain"));
    domain.setText((String)model.getProperty(UrlConfig.DOMAIN));
    domain.setName(DOMAIN);
    domain.addKeyListener(this);
    domainP.add(domain);
    return domainP;
  }

  private JPanel getPathPanel()
  {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Path"));
    path.setText((String)model.getProperty(UrlConfig.PATH));
    path.setName(PATH);
    path.addKeyListener(this);
    panel.add(path);
    return panel;
  }

  private JPanel getProtocolPanel()
  {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Protocol: "));
    ButtonGroup group = new ButtonGroup();
    group.add(http);
    group.add(https);
    if(http.getText().equalsIgnoreCase(model.getProtocol()))
    {
      http.setSelected(true);
    }
    else if(https.getText().equalsIgnoreCase(model.getProtocol()))
    {
      https.setSelected(true);
    }
    http.setActionCommand(HTTP);
    https.setActionCommand(HTTPS);
    http.addActionListener(this);
    https.addActionListener(this);
    JPanel buttons = new JPanel();
    JPanel postButton = new JPanel();
    postButton.add(http);

    JPanel getButton = new JPanel();
    getButton.add(https);

    buttons.add(getButton);
    buttons.add(postButton);

    panel.add(buttons);
    return panel;
  }

  private JPanel getMethodPanel()
  {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Method: "));
    ButtonGroup group = new ButtonGroup();
    group.add(get);
    group.add(post);
    if(UrlConfig.POST.equals(model.getProperty(UrlConfig.METHOD)))
    {
      post.setSelected(true);
    }
    else if(UrlConfig.GET.equals(model.getProperty(UrlConfig.METHOD)))
    {
      get.setSelected(true);
    }
    post.setActionCommand(POST);
    get.setActionCommand(GET);
    post.addActionListener(this);
    get.addActionListener(this);
    JPanel buttons = new JPanel();
    JPanel postButton = new JPanel();
    postButton.add(post);

    JPanel getButton = new JPanel();
    getButton.add(get);

    buttons.add(getButton);
    buttons.add(postButton);

    panel.add(buttons);
    return panel;
  }

  private JPanel getParameterPanel()
  {
    ArgumentsPanel panel = new ArgumentsPanel();
    Arguments args = (Arguments)model.getProperty(UrlConfig.ARGUMENTS);
    if(args == null)
    {
      args = new Arguments();
      model.putProperty(UrlConfig.ARGUMENTS,args);
    }
    panel.setModel(args);
    return panel;
  }

  public void keyPressed(KeyEvent e)
  {
  }

  public void keyTyped(KeyEvent e)
  {
  }

  public void keyReleased(KeyEvent e)
  {
    String name = e.getComponent().getName();
    if(name.equals(DOMAIN))
    {
      model.putProperty(UrlConfig.DOMAIN,domain.getText());
    }
    else if(name.equals(PATH))
    {
      model.putProperty(UrlConfig.PATH,path.getText());
    }
    else if (name.equals(PORT)) {
      try
      {
        model.putProperty
      (UrlConfig.PORT, new Integer(port.getText()));
      }
      catch (Exception ex)
      {
        model.setPort(0);
      }
    }
  }

  public void actionPerformed(ActionEvent e)
  {
    String name = e.getActionCommand();
    if(name.equals(POST))
    {
      model.putProperty(UrlConfig.METHOD,UrlConfig.POST);
    }
    else if(name.equals(GET))
    {
      model.putProperty(UrlConfig.METHOD,UrlConfig.GET);
    }
    else if(name.equals(HTTP))
    {
      model.putProperty(UrlConfig.PROTOCOL,"http");
    }
    else if(name.equals(HTTPS))
    {
      model.putProperty(UrlConfig.PROTOCOL,"https");
    }
  }

}
TOP

Related Classes of org.apache.jmeter.protocol.http.config.gui.UrlConfigGui

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.