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

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

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

import org.apache.jmeter.gui.VerticalLayout;
import org.apache.jmeter.gui.NamePanel;
import org.apache.jmeter.protocol.http.config.MultipartUrlConfig;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.util.JMeterUtils;

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

public class MultipartUrlConfigGui extends UrlConfigGui
{
  private static String FILENAME = "filename";
  private static String BROWSE = "browse";
  private static String PARAMNAME = "paramname";
  private static String MIMETYPE = "mimetype";

  JTextField filenameField;
  JTextField paramNameField;
  JTextField mimetypeField;
  JLabel filenameLabel;
  JLabel paramNameLabel;
  JLabel mimetypeLabel;
  JButton browseFileButton;

  public MultipartUrlConfigGui()
  {
  }

  public MultipartUrlConfigGui(boolean displayName)
  {
    super(displayName);
  }

  public void updateGui()
  {
    super.updateGui();
  }

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

    // WEB SERVER PANEL
    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());

    // WEB REQUEST PANEL
    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());
    webRequestPanel.add(getFilePanel());

    // If displayName is TRUE, then this GUI is not embedded in another GUI.
    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_full_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 // Embed this GUI in the parent GUI
    {
      this.add(webServerPanel);
      this.add(webRequestPanel);
    }
  }

  protected JPanel getFilePanel()
  {
    // FILE PANEL (all main components are add to this panel)
    JPanel filePanel = new JPanel();
    filePanel.setLayout(new VerticalLayout(1, VerticalLayout.LEFT));
    filePanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));

    // SEND FILE LABEL
    JLabel sendFileLabel = new JLabel(JMeterUtils.getResString("send_file"));
    filePanel.add(sendFileLabel);

    // FILENAME PANEL (contains filename label and text field and Browse button)
    JPanel filenamePanel = new JPanel();
    filenamePanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0));

    // --- FILENAME LABEL
    filenameLabel = new JLabel(JMeterUtils.getResString("send_file_filename_label"));
    filenameLabel.setEnabled(true);
   
    // --- FILENAME TEXT FIELD
    filenameField = new JTextField(15);
    filenameField.setEnabled(true);
    filenameField.setText(((MultipartUrlConfig)model).getFilename());
    filenameField.setName(FILENAME);
    filenameField.addKeyListener(this);

    // --- BROWSE BUTTON
    browseFileButton = new JButton(JMeterUtils.getResString("send_file_browse"));
    browseFileButton.setEnabled(true);
    browseFileButton.setActionCommand(BROWSE);
    browseFileButton.addActionListener(this);

    filenamePanel.add(filenameLabel);
    filenamePanel.add(filenameField);
    filenamePanel.add(browseFileButton);

    // PARAM NAME PANEL (contains param name label and text field)
    JPanel paramNamePanel = new JPanel();
    paramNamePanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0));

    // --- PARAM NAME LABEL
    paramNameLabel = new JLabel(JMeterUtils.getResString("send_file_param_name_label"));
    paramNameLabel.setEnabled(true);

    // --- PARAM NAME TEXT FIELD
    paramNameField = new JTextField(15);
    paramNameField.setText(((MultipartUrlConfig)model).getFileFieldName());
    paramNameField.setName(PARAMNAME);
    paramNameField.addKeyListener(this);
    paramNameField.setEnabled(true);

    paramNamePanel.add(paramNameLabel);
    paramNamePanel.add(paramNameField);

    // MIME TYPE PANEL (contains mime type label and text field)
    JPanel mimePanel = new JPanel();
    mimePanel.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0));

    // --- MIME TYPE LABEL
    mimetypeLabel = new JLabel(JMeterUtils.getResString("send_file_mime_label"));
    mimetypeLabel.setEnabled(true);

    // --- MIME TYPE TEXT FIELD
    mimetypeField = new JTextField(15);
    mimetypeField.setEnabled(true);
    mimetypeField.setText(((MultipartUrlConfig)model).getMimeType());
    mimetypeField.setName(MIMETYPE);
    mimetypeField.addKeyListener(this);

    mimePanel.add(mimetypeLabel);
    mimePanel.add(mimetypeField);

    filePanel.add(filenamePanel);
    filePanel.add(paramNamePanel);
    filePanel.add(mimePanel);

    return filePanel;
  }

  public void keyReleased(KeyEvent e)
  {
    super.keyReleased(e);
    String name = e.getComponent().getName();
    if(name.equals(FILENAME))
    {
      ((MultipartUrlConfig)model).setFilename(filenameField.getText());
    }
    else if(name.equals(PARAMNAME))
    {
      ((MultipartUrlConfig)model).setFileFieldName(paramNameField.getText());
    }
    else if (name.equals(MIMETYPE)) {
      ((MultipartUrlConfig)model).setMimeType(mimetypeField.getText());
    }
  }

  public void actionPerformed(ActionEvent e)
  {
    String name = e.getActionCommand();
    if (name.equals(BROWSE))
    {
      JFileChooser chooser = FileDialoger.promptToOpenFile();

      File file = chooser.getSelectedFile();
      if (file != null)
      {
        ((MultipartUrlConfig)model).setFilename(file.getPath());
        filenameField.setText(file.getPath());
      }
    }

    super.actionPerformed(e);
  }
}
TOP

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

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.