<commit_before>// $Header$
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed 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.protocol.http.config.gui;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.jmeter.gui.util.FileDialoger;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;


/**
 * @author    <NAME>
 * @version   $Revision$
 */
public class MultipartUrlConfigGui
    extends UrlConfigGui
    implements ActionListener
{

    private JTextField filenameField;
    private JTextField paramNameField;
    private JTextField mimetypeField;

    private static String FILENAME = "filename";
    private static String BROWSE = "browse";
    private static String PARAMNAME = "paramname";
    private static String MIMETYPE = "mimetype";

    public MultipartUrlConfigGui()
    {
        super();
    }

    public TestElement createTestElement()
    {
        TestElement ce = super.createTestElement();

        configureTestElement(ce);
        ce.setProperty(HTTPSampler.MIMETYPE, mimetypeField.getText());
        ce.setProperty(HTTPSampler.FILE_NAME, filenameField.getText());
        ce.setProperty(HTTPSampler.FILE_FIELD, paramNameField.getText());
        return ce;
    }

    public void configureSampler(HTTPSampler sampler)
    {
        sampler.setMimetype(mimetypeField.getText());
        sampler.setFileField(paramNameField.getText());
        sampler.setFilename(filenameField.getText());
        super.configureSampler(sampler);
    }

    public void configure(TestElement el)
    {
        super.configure(el);
        mimetypeField.setText(el.getPropertyAsString(HTTPSampler.MIMETYPE));
        filenameField.setText(el.getPropertyAsString(HTTPSampler.FILE_NAME));
        paramNameField.setText(el.getPropertyAsString(HTTPSampler.FILE_FIELD));
    }

    public String getLabelResource()
    {
        return "url_multipart_config_title";
    }

    public void updateGui()
    {}

    public void actionPerformed(ActionEvent e)
    {
        String name = e.getActionCommand();

        if (name.equals(BROWSE))
        {
            JFileChooser chooser = FileDialoger.promptToOpenFile();

            if (chooser == null)
            {
                return;
            }
            File file = chooser.getSelectedFile();

            if (file != null)
            {
                filenameField.setText(file.getPath());
            }
        }
    }

    protected void init()
    {
        this.setLayout(new BorderLayout());

        // WEB SERVER PANEL
        VerticalPanel webServerPanel = new VerticalPanel();
        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 BoxLayout(webRequestPanel, BoxLayout.Y_AXIS));
        webRequestPanel.setBorder(
            BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder(),
                JMeterUtils.getResString("web_request")));
        
        webRequestPanel.add(getProtocolAndMethodPanel());
        webRequestPanel.add(getPathPanel());
        webRequestPanel.add(getParameterPanel());
        webRequestPanel.add(getFilePanel());
        
        this.add(webServerPanel, BorderLayout.NORTH);
        this.add(webRequestPanel, BorderLayout.CENTER);
    }

    protected JPanel getFilePanel()
    {
        JPanel filePanel = new VerticalPanel();
        filePanel.setBorder(
            BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder(),
                JMeterUtils.getResString("send_file")));

        filePanel.add(createFilenamePanel());
        filePanel.add(createFileParamNamePanel());
        filePanel.add(createFileMimeTypePanel());

        return filePanel;
    }

    private JPanel createFileMimeTypePanel()
    {
        mimetypeField = new JTextField(15);
        mimetypeField.setName(MIMETYPE);

        JLabel mimetypeLabel =
            new JLabel(JMeterUtils.getResString("send_file_mime_label"));
        mimetypeLabel.setLabelFor(mimetypeField);
        JPanel mimePanel = new JPanel(new BorderLayout(5, 0));
        mimePanel.add(mimetypeLabel, BorderLayout.WEST);
        mimePanel.add(mimetypeField, BorderLayout.CENTER);
        return mimePanel;
    }

    private JPanel createFileParamNamePanel()
    {
        paramNameField = new JTextField(15);
        paramNameField.setName(PARAMNAME);

        JLabel paramNameLabel =
            new JLabel(JMeterUtils.getResString("send_file_param_name_label"));
        paramNameLabel.setLabelFor(paramNameField);

        JPanel paramNamePanel = new JPanel(new BorderLayout(5, 0));        
        paramNamePanel.add(paramNameLabel, BorderLayout.WEST);
        paramNamePanel.add(paramNameField, BorderLayout.CENTER);
        return paramNamePanel;
    }

    private JPanel createFilenamePanel()
    {
        filenameField = new JTextField(15);
        filenameField.setName(FILENAME);

        JLabel filenameLabel =
            new JLabel(JMeterUtils.getResString("send_file_filename_label"));
        filenameLabel.setLabelFor(filenameField);

        JButton browseFileButton =
            new JButton(JMeterUtils.getResString("send_file_browse"));
        browseFileButton.setActionCommand(BROWSE);
        browseFileButton.addActionListener(this);
        

        JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));        
        filenamePanel.add(filenameLabel, BorderLayout.WEST);
        filenamePanel.add(filenameField, BorderLayout.CENTER);
        filenamePanel.add(browseFileButton, BorderLayout.EAST);
        return filenamePanel;
    }
    
    /* (non-Javadoc)
     * @see org.apache.jmeter.protocol.http.config.gui.UrlConfigGui#clear()
     */
    public void clear()
    {
        // TODO Auto-generated method stub
        super.clear();
        filenameField.setText("");
        mimetypeField.setText("");
        paramNameField.setText("");
    }
}
<commit_msg>configureSampler does not appear to be used<commit_after>// $Header$
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed 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.protocol.http.config.gui;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.jmeter.gui.util.FileDialoger;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;


/**
 * @author    <NAME>
 * @version   $Revision$
 */
public class MultipartUrlConfigGui
    extends UrlConfigGui
    implements ActionListener
{

    private JTextField filenameField;
    private JTextField paramNameField;
    private JTextField mimetypeField;

    private static String FILENAME = "filename";
    private static String BROWSE = "browse";
    private static String PARAMNAME = "paramname";
    private static String MIMETYPE = "mimetype";

    public MultipartUrlConfigGui()
    {
        super();
    }

    public TestElement createTestElement()
    {
        TestElement ce = super.createTestElement();

        configureTestElement(ce);
        ce.setProperty(HTTPSampler.MIMETYPE, mimetypeField.getText());
        ce.setProperty(HTTPSampler.FILE_NAME, filenameField.getText());
        ce.setProperty(HTTPSampler.FILE_FIELD, paramNameField.getText());
        return ce;
    }

// does not appear to be used
//    public void configureSampler(HTTPSampler sampler)
//    {
//        sampler.setMimetype(mimetypeField.getText());
//        sampler.setFileField(paramNameField.getText());
//        sampler.setFilename(filenameField.getText());
//        super.configureSampler(sampler);
//    }

    public void configure(TestElement el)
    {
        super.configure(el);
        mimetypeField.setText(el.getPropertyAsString(HTTPSampler.MIMETYPE));
        filenameField.setText(el.getPropertyAsString(HTTPSampler.FILE_NAME));
        paramNameField.setText(el.getPropertyAsString(HTTPSampler.FILE_FIELD));
    }

    public String getLabelResource()
    {
        return "url_multipart_config_title";
    }

    public void updateGui()
    {}

    public void actionPerformed(ActionEvent e)
    {
        String name = e.getActionCommand();

        if (name.equals(BROWSE))
        {
            JFileChooser chooser = FileDialoger.promptToOpenFile();

            if (chooser == null)
            {
                return;
            }
            File file = chooser.getSelectedFile();

            if (file != null)
            {
                filenameField.setText(file.getPath());
            }
        }
    }

    protected void init()
    {
        this.setLayout(new BorderLayout());

        // WEB SERVER PANEL
        VerticalPanel webServerPanel = new VerticalPanel();
        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 BoxLayout(webRequestPanel, BoxLayout.Y_AXIS));
        webRequestPanel.setBorder(
            BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder(),
                JMeterUtils.getResString("web_request")));
        
        webRequestPanel.add(getProtocolAndMethodPanel());
        webRequestPanel.add(getPathPanel());
        webRequestPanel.add(getParameterPanel());
        webRequestPanel.add(getFilePanel());
        
        this.add(webServerPanel, BorderLayout.NORTH);
        this.add(webRequestPanel, BorderLayout.CENTER);
    }

    protected JPanel getFilePanel()
    {
        JPanel filePanel = new VerticalPanel();
        filePanel.setBorder(
            BorderFactory.createTitledBorder(
                BorderFactory.createEtchedBorder(),
                JMeterUtils.getResString("send_file")));

        filePanel.add(createFilenamePanel());
        filePanel.add(createFileParamNamePanel());
        filePanel.add(createFileMimeTypePanel());

        return filePanel;
    }

    private JPanel createFileMimeTypePanel()
    {
        mimetypeField = new JTextField(15);
        mimetypeField.setName(MIMETYPE);

        JLabel mimetypeLabel =
            new JLabel(JMeterUtils.getResString("send_file_mime_label"));
        mimetypeLabel.setLabelFor(mimetypeField);
        JPanel mimePanel = new JPanel(new BorderLayout(5, 0));
        mimePanel.add(mimetypeLabel, BorderLayout.WEST);
        mimePanel.add(mimetypeField, BorderLayout.CENTER);
        return mimePanel;
    }

    private JPanel createFileParamNamePanel()
    {
        paramNameField = new JTextField(15);
        paramNameField.setName(PARAMNAME);

        JLabel paramNameLabel =
            new JLabel(JMeterUtils.getResString("send_file_param_name_label"));
        paramNameLabel.setLabelFor(paramNameField);

        JPanel paramNamePanel = new JPanel(new BorderLayout(5, 0));        
        paramNamePanel.add(paramNameLabel, BorderLayout.WEST);
        paramNamePanel.add(paramNameField, BorderLayout.CENTER);
        return paramNamePanel;
    }

    private JPanel createFilenamePanel()
    {
        filenameField = new JTextField(15);
        filenameField.setName(FILENAME);

        JLabel filenameLabel =
            new JLabel(JMeterUtils.getResString("send_file_filename_label"));
        filenameLabel.setLabelFor(filenameField);

        JButton browseFileButton =
            new JButton(JMeterUtils.getResString("send_file_browse"));
        browseFileButton.setActionCommand(BROWSE);
        browseFileButton.addActionListener(this);
        

        JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));        
        filenamePanel.add(filenameLabel, BorderLayout.WEST);
        filenamePanel.add(filenameField, BorderLayout.CENTER);
        filenamePanel.add(browseFileButton, BorderLayout.EAST);
        return filenamePanel;
    }
    
    /* (non-Javadoc)
     * @see org.apache.jmeter.protocol.http.config.gui.UrlConfigGui#clear()
     */
    public void clear()
    {
        // TODO Auto-generated method stub
        super.clear();
        filenameField.setText("");
        mimetypeField.setText("");
        paramNameField.setText("");
    }
}

{'fraction_non_alphanumeric': 0.09525128063131663, 'fraction_numerical': 0.003322719091790115, 'mean_word_length': 2.8320954907161804, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3440963', 'n_tokens_mistral': 4148, 'n_tokens_neox': 3966, 'n_words': 764}