<commit_before>package client;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ClientLogonDialog implements ActionListener, KeyEventDispatcher
{
	protected JDialog dialog;
	
	// Entry widgets
	protected JTextField entryServer, entryName;
	protected JPasswordField entryPassword;
	// Buttons
	protected JButton buttonOkay, buttonCancel;
	// Labels
	protected JLabel statusMessage, labelServer, labelName, labelPassword;
	
	// Results of the dialog
	protected String serverName;
	protected String userName;
	protected String serverPassword;
	protected boolean result;
	
	/*
	 * TODO: Fix key-detection code!
	 */
	
	public ClientLogonDialog(Frame owner)
	{
		dialog = new JDialog(owner, true);
		dialog.setContentPane(new JPanel(new BorderLayout()));
		
		entryServer = new JTextField();
		entryServer.addActionListener(this);
		entryName = new JTextField();
		entryName.addActionListener(this);
		entryPassword = new JPasswordField();
		entryPassword.addActionListener(this);
		statusMessage = new JLabel();
		statusMessage.setForeground(Color.red);
		statusMessage.setVisible(false);
		
		buttonOkay = new JButton("Login");
		buttonOkay.addActionListener(this);
		buttonOkay.setMnemonic('L');
		buttonCancel = new JButton("Quit");
		buttonCancel.addActionListener(this);
		buttonCancel.setMnemonic('Q');
		
		JPanel panel = new JPanel(new GridLayout(0, 2));
		panel.add(labelServer = new JLabel("Server IP or name:"));
		panel.add(entryServer);
		panel.add(labelName = new JLabel("User name:"));
		panel.add(entryName);
		panel.add(labelPassword = new JLabel("Server password:"));
		panel.add(entryPassword);
		
		dialog.getContentPane().add(panel, BorderLayout.CENTER);
		
		panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		panel.add(statusMessage);
		panel.add(buttonOkay);
		panel.add(buttonCancel);
		
		dialog.getContentPane().add(panel, BorderLayout.SOUTH);
		
		dialog.pack();
		KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		Object source = e.getSource();
		if (source.equals(buttonCancel))
		{
			cancel();
		}
		else if (source.equals(buttonOkay))
		{
			login();
		}
		else
		{
			dialog.transferFocus();
		}
	}
	
	public boolean show()
	{
		// Reset the labels
		labelServer.setForeground(Color.black);
		labelName.setForeground(Color.black);
		labelPassword.setForeground(Color.black);
		statusMessage.setVisible(false);
		// Center the dialog on the parent
		dialog.setLocationRelativeTo(dialog.getParent());
		dialog.setVisible(true);
		
		return result;
	}
	
	protected void cancel()
	{
		result = false;
		dialog.setVisible(false);
	}
	
	protected boolean login()
	{
		result = true;
		if (entryServer.getText().length() < 1)
		{
			statusMessage.setText("Need server name!");
			labelServer.setForeground(Color.red);
			result = false;
		}
		else
			labelServer.setForeground(Color.black);
		if (entryName.getText().length() < 1)
		{
			if (result)
				statusMessage.setText("Need user name!");
			else
				statusMessage.setText("Need server and user name!");
			labelName.setForeground(Color.red);
			result = false;
		}
		else
			labelName.setForeground(Color.black);
		
		if (result)
		{
			statusMessage.setVisible(false);
			serverName = entryServer.getText();
			serverPassword = new String(entryPassword.getPassword());
			userName = entryName.getText();
			
			dialog.setVisible(false);
		}
		else
			statusMessage.setVisible(true);
		
		return result;
	}

	public String getServerName()
	{
		return serverName;
	}
	
	public String getUserName()
	{
		return userName;
	}
	
	public String getPassword()
	{
		return serverPassword;
	}

	public boolean dispatchKeyEvent(KeyEvent e)
	{
		if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE)
			cancel();
		
		return false;<commit_msg>Now pressing Enter on any of the text fields is the same as pressing Login.<commit_after>package client;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class ClientLogonDialog implements ActionListener, KeyEventDispatcher
{
	protected JDialog dialog;
	
	// Entry widgets
	protected JTextField entryServer, entryName;
	protected JPasswordField entryPassword;
	// Buttons
	protected JButton buttonOkay, buttonCancel;
	// Labels
	protected JLabel statusMessage, labelServer, labelName, labelPassword;
	
	// Results of the dialog
	protected String serverName;
	protected String userName;
	protected String serverPassword;
	protected boolean result;
	
	/*
	 * TODO: Fix key-detection code!
	 */
	
	public ClientLogonDialog(Frame owner)
	{
		dialog = new JDialog(owner, true);
		dialog.setContentPane(new JPanel(new BorderLayout()));
		
		entryServer = new JTextField();
		entryServer.addActionListener(this);
		entryName = new JTextField();
		entryName.addActionListener(this);
		entryPassword = new JPasswordField();
		entryPassword.addActionListener(this);
		statusMessage = new JLabel();
		statusMessage.setForeground(Color.red);
		statusMessage.setVisible(false);
		
		buttonOkay = new JButton("Login");
		buttonOkay.addActionListener(this);
		buttonOkay.setMnemonic('L');
		buttonCancel = new JButton("Quit");
		buttonCancel.addActionListener(this);
		buttonCancel.setMnemonic('Q');
		
		JPanel panel = new JPanel(new GridLayout(0, 2));
		panel.add(labelServer = new JLabel("Server IP or name:"));
		panel.add(entryServer);
		panel.add(labelName = new JLabel("User name:"));
		panel.add(entryName);
		panel.add(labelPassword = new JLabel("Server password:"));
		panel.add(entryPassword);
		
		dialog.getContentPane().add(panel, BorderLayout.CENTER);
		
		panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		panel.add(statusMessage);
		panel.add(buttonOkay);
		panel.add(buttonCancel);
		
		dialog.getContentPane().add(panel, BorderLayout.SOUTH);
		
		dialog.pack();
		KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		Object source = e.getSource();
		if (source.equals(buttonCancel))
		{
			cancel();
		}
		else if (source.equals(buttonOkay) || source instanceof JTextField)
		{
			login();
		}
		else
		{
			dialog.transferFocus();
		}
	}
	
	public boolean show()
	{
		// Reset the labels
		labelServer.setForeground(Color.black);
		labelName.setForeground(Color.black);
		labelPassword.setForeground(Color.black);
		statusMessage.setVisible(false);
		// Center the dialog on the parent
		dialog.setLocationRelativeTo(dialog.getParent());
		dialog.setVisible(true);
		
		return result;
	}
	
	protected void cancel()
	{
		result = false;
		dialog.setVisible(false);
	}
	
	protected boolean login()
	{
		result = true;
		if (entryServer.getText().length() < 1)
		{
			statusMessage.setText("Need server name!");
			labelServer.setForeground(Color.red);
			result = false;
		}
		else
			labelServer.setForeground(Color.black);
		if (entryName.getText().length() < 1)
		{
			if (result)
				statusMessage.setText("Need user name!");
			else
				statusMessage.setText("Need server and user name!");
			labelName.setForeground(Color.red);
			result = false;
		}
		else
			labelName.setForeground(Color.black);
		
		if (result)
		{
			statusMessage.setVisible(false);
			serverName = entryServer.getText();
			serverPassword = new String(entryPassword.getPassword());
			userName = entryName.getText();
			
			dialog.setVisible(false);
		}
		else
			statusMessage.setVisible(true);
		
		return result;
	}

	public String getServerName()
	{
		return serverName;
	}
	
	public String getUserName()
	{
		return userName;
	}
	
	public String getPassword()
	{
		return serverPassword;
	}

	public boolean dispatchKeyEvent(KeyEvent e)
	{
		// If the Escape key was pressed, press the cancel button
		if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE)
			cancel();
		
		return false;
{'fraction_non_alphanumeric': 0.1182741116751269, 'fraction_numerical': 0.0010152284263959391, 'mean_word_length': 4.3430508474576275, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1437520', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2384, 'n_words': 526}