<commit_before>/*
 * Copyright 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.mail.sampler.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.apache.jmeter.gui.util.HorizontalPanel;
import org.apache.jmeter.protocol.mail.sampler.MailReaderSampler;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.layout.VerticalLayout;

/**
 * @author <NAME>
 */
public class MailReaderSamplerGui
	extends AbstractSamplerGui 
{
	// Gui Components
	private JComboBox serverTypeBox;
	private JTextField serverBox;
	private JTextField usernameBox;
	private JTextField passwordBox;
	private JTextField folderBox;
	private JLabel folderLabel;
	private JRadioButton allMessagesButton;
	private JRadioButton someMessagesButton;
	private JTextField someMessagesField;
	private JCheckBox deleteBox;
	
	// Labels
	private final static String title = JMeterUtils.getResString("mail_reader_title"); 
	private final static String POP3Label = JMeterUtils.getResString("mail_reader_pop3");
	private final static String IMAPLabel = JMeterUtils.getResString("mail_reader_imap");
	private final static String ServerTypeLabel = JMeterUtils.getResString("mail_reader_server_type");
	private final static String ServerLabel = JMeterUtils.getResString("mail_reader_server");
	private final static String AccountLabel = JMeterUtils.getResString("mail_reader_account");
	private final static String PasswordLabel = JMeterUtils.getResString("mail_reader_password");
	private final static String NumMessagesLabel = JMeterUtils.getResString("mail_reader_num_messages");
	private final static String AllMessagesLabel = JMeterUtils.getResString("mail_reader_all_messages");
	private final static String DeleteLabel = JMeterUtils.getResString("mail_reader_delete");
	private final static String FolderLabel = JMeterUtils.getResString("mail_reader_folder");
	
	private String type;
	private boolean delete;
	private int num_messages;

	public MailReaderSamplerGui()
	{
		type = MailReaderSampler.TYPE_POP3;
		delete = false;
		init();
	}

	/* (non-Javadoc)
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
	 */
	public String getStaticLabel()
	{
		return title;
	}

	/* (non-Javadoc)
	 * Copy the data from the test element to the GUI
	 * 
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(org.apache.jmeter.testelement.TestElement)
	 */
	public void configure(TestElement element)
	{
		MailReaderSampler mrs = (MailReaderSampler)element;
		if(mrs.getServerType() == MailReaderSampler.TYPE_POP3)
		{
			serverTypeBox.setSelectedItem(POP3Label);
			folderBox.setText("INBOX");
		}
		else
		{
			serverTypeBox.setSelectedItem(IMAPLabel);
			folderBox.setText(mrs.getFolder());
		}
		serverBox.setText(mrs.getServer());
		usernameBox.setText(mrs.getUserName());
		passwordBox.setText(mrs.getPassword());
		if (mrs.getNumMessages()==-1)
		{
			allMessagesButton.setSelected(true);
			someMessagesField.setText(Integer.toString(0));
		}
		else
		{
			someMessagesButton.setSelected(true);
			someMessagesField.setText(Integer.toString(mrs.getNumMessages()));
		}
		deleteBox.setSelected(mrs.getDeleteMessages());
		super.configure(element);
	}

	/* (non-Javadoc)
	 * Create the corresponding Test Element and set up its data
	 * 
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
	 */
	public TestElement createTestElement()
	{
		MailReaderSampler sampler = new MailReaderSampler();
		modifyTestElement(sampler);
		return sampler;
	}

	/* (non-Javadoc)
	 * Modifies a given TestElement to mirror the data in the gui components.
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
	 */
	public void modifyTestElement(TestElement te)
	{
		te.clear();
		configureTestElement(te);
		
		MailReaderSampler mrs = (MailReaderSampler)te;
		
		if(((String)serverTypeBox.getSelectedItem()) == POP3Label) 
			mrs.setServerType(MailReaderSampler.TYPE_POP3);
		else
			mrs.setServerType(MailReaderSampler.TYPE_IMAP);
		
		mrs.setFolder(folderBox.getText());
		mrs.setServer(serverBox.getText());
		mrs.setUserName(usernameBox.getText());
		mrs.setPassword(passwordBox.getText());
		if (allMessagesButton.isSelected())
			mrs.setNumMessages(-1);
		else
			mrs.setNumMessages(num_messages);
		mrs.setDeleteMessages(delete);
	}


	/*
	 * Helper method to set up the GUI screen
	 */
	private void init()
	{
		setLayout(<commit_msg>Compare strings with equals() rather than ==<commit_after>/*
 * Copyright 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.mail.sampler.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.apache.jmeter.gui.util.HorizontalPanel;
import org.apache.jmeter.protocol.mail.sampler.MailReaderSampler;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.layout.VerticalLayout;

/**
 * @author <NAME>
 */
public class MailReaderSamplerGui
	extends AbstractSamplerGui 
{
	// Gui Components
	private JComboBox serverTypeBox;
	private JTextField serverBox;
	private JTextField usernameBox;
	private JTextField passwordBox;
	private JTextField folderBox;
	private JLabel folderLabel;
	private JRadioButton allMessagesButton;
	private JRadioButton someMessagesButton;
	private JTextField someMessagesField;
	private JCheckBox deleteBox;
	
	// Labels
	private final static String title = JMeterUtils.getResString("mail_reader_title"); 
	private final static String POP3Label = JMeterUtils.getResString("mail_reader_pop3");
	private final static String IMAPLabel = JMeterUtils.getResString("mail_reader_imap");
	private final static String ServerTypeLabel = JMeterUtils.getResString("mail_reader_server_type");
	private final static String ServerLabel = JMeterUtils.getResString("mail_reader_server");
	private final static String AccountLabel = JMeterUtils.getResString("mail_reader_account");
	private final static String PasswordLabel = JMeterUtils.getResString("mail_reader_password");
	private final static String NumMessagesLabel = JMeterUtils.getResString("mail_reader_num_messages");
	private final static String AllMessagesLabel = JMeterUtils.getResString("mail_reader_all_messages");
	private final static String DeleteLabel = JMeterUtils.getResString("mail_reader_delete");
	private final static String FolderLabel = JMeterUtils.getResString("mail_reader_folder");
	
	private String type;
	private boolean delete;
	private int num_messages;

	public MailReaderSamplerGui()
	{
		type = MailReaderSampler.TYPE_POP3;
		delete = false;
		init();
	}

	/* (non-Javadoc)
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
	 */
	public String getStaticLabel()
	{
		return title;
	}

	/* (non-Javadoc)
	 * Copy the data from the test element to the GUI
	 * 
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(org.apache.jmeter.testelement.TestElement)
	 */
	public void configure(TestElement element)
	{
		MailReaderSampler mrs = (MailReaderSampler)element;
		if(mrs.getServerType().equals(MailReaderSampler.TYPE_POP3))
		{
			serverTypeBox.setSelectedItem(POP3Label);
			folderBox.setText("INBOX");
		}
		else
		{
			serverTypeBox.setSelectedItem(IMAPLabel);
			folderBox.setText(mrs.getFolder());
		}
		serverBox.setText(mrs.getServer());
		usernameBox.setText(mrs.getUserName());
		passwordBox.setText(mrs.getPassword());
		if (mrs.getNumMessages()==-1)
		{
			allMessagesButton.setSelected(true);
			someMessagesField.setText(Integer.toString(0));
		}
		else
		{
			someMessagesButton.setSelected(true);
			someMessagesField.setText(Integer.toString(mrs.getNumMessages()));
		}
		deleteBox.setSelected(mrs.getDeleteMessages());
		super.configure(element);
	}

	/* (non-Javadoc)
	 * Create the corresponding Test Element and set up its data
	 * 
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
	 */
	public TestElement createTestElement()
	{
		MailReaderSampler sampler = new MailReaderSampler();
		modifyTestElement(sampler);
		return sampler;
	}

	/* (non-Javadoc)
	 * Modifies a given TestElement to mirror the data in the gui components.
	 * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
	 */
	public void modifyTestElement(TestElement te)
	{
		te.clear();
		configureTestElement(te);
		
		MailReaderSampler mrs = (MailReaderSampler)te;
		
		if(((String)serverTypeBox.getSelectedItem()).equals(POP3Label)) 
			mrs.setServerType(MailReaderSampler.TYPE_POP3);
		else
			mrs.setServerType(MailReaderSampler.TYPE_IMAP);
		
		mrs.setFolder(folderBox.getText());
		mrs.setServer(serverBox.getText());
		mrs.setUserName(usernameBox.getText());
		mrs.setPassword(passwordBox.getText());
		if (allMessagesButton.isSelected())
			mrs.setNumMessages(-1);
		else
			mrs.setNumMessages(num_messages);
		mrs.setDeleteMessages(delete);
	}


	/*
	 * Helper method to set up the GUI screen
	 */
	private void init()
	{
		setLayout(
{'fraction_non_alphanumeric': 0.0992933178280705, 'fraction_numerical': 0.003220323821450935, 'mean_word_length': 5.355884025014213, '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': '6038849', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3401, 'n_words': 751}