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 javax.swing.border.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

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;
import org.apache.jmeter.util.JMeterUtils;

/**
* 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 PATH = "path";
  private static String POST = "post";
  private static String GET = "get";
  private static String HTTP = "http";
  private static String HTTPS = "https";
  private static String SEND_PARAM = "sendparam";

  private JTextField domain;
  private JTextField port;
  private JTextField path;
  private JRadioButton post;
  private JRadioButton get;
  private JRadioButton http;
  private JRadioButton https;

  protected NamePanel namePanel;
  protected boolean displayName = true;

  protected 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);
    }
    else // take the default of GET
    {
      get.setSelected(true);
      model.setMethod(UrlConfig.GET);
    }

    if (https.getText().equalsIgnoreCase(model.getProtocol()))
    {
      https.setSelected(true);
    }
    else if (http.getText().equalsIgnoreCase(model.getProtocol()))
    {
      http.setSelected(true);
    }
    else  // take the default of HTTP
    {
      http.setSelected(true);
      model.setProtocol(HTTP);
    }
  }

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

  protected void init()
  {
    this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));

    JPanel webServerPanel = new JPanel();
    webServerPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
    webServerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("web_server")));
    webServerPanel.add(getDomainPanel());
    webServerPanel.add(getPortPanel());

    JPanel webRequestPanel = new JPanel();
    webRequestPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP));
    webRequestPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("web_request")));
    webRequestPanel.add(getProtocolAndMethodPanel());
    webRequestPanel.add(getPathPanel());
    webRequestPanel.add(getParameterPanel());

    if (displayName)
    {
      // MAIN PANEL
      JPanel mainPanel = new JPanel();
      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("url_config_title"));
      Font curFont = panelTitleLabel.getFont();
      int curFontSize = curFont.getSize();
      curFontSize += 4;
      panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize));
      mainPanel.add(panelTitleLabel);

      // NAME
      namePanel = new NamePanel(model);
      mainPanel.add(namePanel);

      mainPanel.add(webServerPanel);
      mainPanel.add(webRequestPanel);

      this.add(mainPanel);
    }
    else
    {
      this.add(webServerPanel);
      this.add(webRequestPanel);
    }
  }

  protected JPanel getPortPanel()
  {
    JPanel portP = new JPanel();
    portP.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10));
    portP.add(new JLabel(JMeterUtils.getResString("web_server_port")));

    port = new JTextField(6);

    Object portI = model.getProperty(UrlConfig.PORT);
    if (portI != null)
    {
      port.setText(portI.toString());
    }

    port.setName(PORT);
    port.addKeyListener(this);
    portP.add(port);

    return portP;
  }

  protected JPanel getDomainPanel()
  {
    JPanel domainP = new JPanel();
    domainP.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10));
    domainP.add(new JLabel(JMeterUtils.getResString("web_server_domain")));

    domain = new JTextField(20);
    domain.setText((String)model.getProperty(UrlConfig.DOMAIN));
    domain.setName(DOMAIN);
    domain.addKeyListener(this);
    domainP.add(domain);

    return domainP;
  }

  protected JPanel getPathPanel()
  {
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10));
    panel.add(new JLabel(JMeterUtils.getResString("path")));

    path = new JTextField(20);
    path.setText((String)model.getProperty(UrlConfig.PATH));
    path.setName(PATH);
    path.addKeyListener(this);
    panel.add(path);

    return panel;
  }

  protected JPanel getProtocolAndMethodPanel()
  {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
   
    panel.add(new JLabel(JMeterUtils.getResString("protocol")));
    panel.add(Box.createRigidArea(new Dimension(5, 0)));

    // PROTOCOL
    http = new JRadioButton(JMeterUtils.getResString("url_config_http"));
    http.setActionCommand(HTTP);
    http.addActionListener(this);
    https = new JRadioButton(JMeterUtils.getResString("url_config_https"));
    https.setActionCommand(HTTPS);
    https.addActionListener(this);
    ButtonGroup protocolButtonGroup = new ButtonGroup();
    protocolButtonGroup.add(http);
    protocolButtonGroup.add(https);

    if (http.getText().equalsIgnoreCase(model.getProtocol()))
    {
      http.setSelected(true);
    }
    else if (https.getText().equalsIgnoreCase(model.getProtocol()))
    {
      https.setSelected(true);
    }

    panel.add(http);
    panel.add(https);

    panel.add(Box.createRigidArea(new Dimension(20, 0)));

    // METHOD
    post = new JRadioButton(JMeterUtils.getResString("url_config_post"));
    post.setActionCommand(POST);
    post.addActionListener(this);
    get = new JRadioButton(JMeterUtils.getResString("url_config_get"));
    get.setActionCommand(GET);
    get.addActionListener(this);
    ButtonGroup methodButtonGroup = new ButtonGroup();
    methodButtonGroup.add(post);
    methodButtonGroup.add(get);

    panel.add(new JLabel(JMeterUtils.getResString("method")));
    panel.add(Box.createRigidArea(new Dimension(5, 0)));

    if (UrlConfig.POST.equals(model.getProperty(UrlConfig.METHOD)))
    {
      post.setSelected(true);
    }
    else if (UrlConfig.GET.equals(model.getProperty(UrlConfig.METHOD)))
    {
      get.setSelected(true);
    }

    panel.add(get);
    panel.add(post);

    return panel;
  }

  protected JPanel getParameterPanel()
  {
    ArgumentsPanel argsPanel = new ArgumentsPanel();
    Arguments args = (Arguments)model.getProperty(UrlConfig.ARGUMENTS);

    if (args == null)
    {
      args = new Arguments();
      model.putProperty(UrlConfig.ARGUMENTS,args);
    }

    argsPanel.setModel(args);

    return argsPanel;
  }


  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.