// Path: src/main/net/sf/portecle/FPortecle.java
// public static final ResourceBundle RB = ResourceBundle.getBundle(RB_BASENAME);
// 
// Path: src/main/net/sf/portecle/crypto/KeyPairType.java
// public enum KeyPairType
// {
//     /** RSA key pair type. */
// 	RSA,
// 	/** DSA key pair type. */
// 	DSA,
// 	/** ECDSA key pair type. */
// 	ECDSA;
// }
// 
// Path: src/main/net/sf/portecle/gui/SwingHelper.java
// public final class SwingHelper
// {
// 	/** Not needed. */
// 	private SwingHelper()
// 	{
// 		// Ignored
// 	}
// 
// 	/**
// 	 * Makes the given Window visible and waits for it to return.
// 	 * 
// 	 * @param window The window
// 	 */
// 	public static void showAndWait(final Window window)
// 	{
// 		if (SwingUtilities.isEventDispatchThread())
// 		{
// 			window.setVisible(true);
// 		}
// 		else
// 		{
// 			try
// 			{
// 				SwingUtilities.invokeAndWait(new Runnable()
// 				{
// 					@Override
// 					public void run()
// 					{
// 						window.setVisible(true);
// 					}
// 				});
// 			}
// 			catch (InterruptedException | InvocationTargetException e)
// 			{
// 				LOG.log(Level.WARNING, "Error setting window visible", e); // TODO?
// 			}
// 		}
// 	}
// 
// 	/**
// 	 * Select all text in a text component and focus it.
// 	 * 
// 	 * @param component the text component
// 	 */
// 	public static void selectAndFocus(JComponent component)
// 	{
// 		JTextComponent textComponent = null;
// 		if (component instanceof JTextComponent)
// 		{
// 			textComponent = (JTextComponent) component;
// 		}
// 		if (component instanceof JComboBox)
// 		{
// 			Component editorComponent = ((JComboBox<?>) component).getEditor().getEditorComponent();
// 			if (editorComponent instanceof JTextComponent)
// 			{
// 				textComponent = (JTextComponent) editorComponent;
// 			}
// 		}
// 		if (textComponent != null)
// 		{
// 			textComponent.select(0, textComponent.getText().length());
// 		}
// 		component.requestFocusInWindow();
// 	}
// 
// 	/**
// 	 * Shows a simple yes/no confirmation dialog, with the "no" option selected by default. This method exists only
// 	 * because there's apparently no easy way to accomplish that with JOptionPane's static helper methods.
// 	 * 
// 	 * @param parentComponent
// 	 * @param message
// 	 * @param title
// 	 * @see JOptionPane#showConfirmDialog(Component, Object, String, int)
// 	 */
// 	public static int showConfirmDialog(Component parentComponent, Object message, String title)
// 	{
// 		String[] options = { "Yes", "No" };
// 		return JOptionPane.showOptionDialog(parentComponent, message, title, JOptionPane.YES_NO_OPTION,
// 		    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
// 	}
// }


import static net.sf.portecle.FPortecle.RB;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import net.sf.portecle.crypto.KeyPairType;
import net.sf.portecle.gui.IntegerDocumentFilter;
import net.sf.portecle.gui.SwingHelper;
/*
 * DGenerateKeyPair.java
 * This file is part of Portecle, a multipurpose keystore and certificate tool.
 *
 * Copyright © 2004 Wayne Grant, waynedgrant@hotmail.com
 *             2008 Ville Skyttä, ville.skytta@iki.fi
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package net.sf.portecle;





/**
 * Modal dialog used to choose the parameters required for key pair generation. The user may select an asymmetric key
 * generation algorithm of DSA or RSA and enter a key size in bits.
 */
class DGenerateKeyPair
    extends PortecleJDialog
{
	/** Indicator for an invalid key size */
	private static final int BAD_KEYSIZE = -1;

	/** Radio button for the DSA key algorithm */
	private JRadioButton m_jrbDSA;

	/** Radio button for the RSA key algorithm */
	private JRadioButton m_jrbRSA;

	/** Key size combo box */
	private JComboBox<String> m_jcbKeySize;

	/** Key pair type chosen for generation */
	private KeyPairType m_keyPairType;

	/** Key size chosen */
	private int m_iKeySize;

	/** Records whether or not correct parameters are entered */
	private boolean m_bSuccess;

	/**
	 * Creates new DGenerateKeyPair dialog.
	 * 
	 * @param parent The parent window
	 */
	public DGenerateKeyPair(Window parent)
	{
// Path: src/main/net/sf/portecle/FPortecle.java
// public static final ResourceBundle RB = ResourceBundle.getBundle(RB_BASENAME);
// 
// Path: src/main/net/sf/portecle/crypto/KeyPairType.java
// public enum KeyPairType
// {
//     /** RSA key pair type. */
// 	RSA,
// 	/** DSA key pair type. */
// 	DSA,
// 	/** ECDSA key pair type. */
// 	ECDSA;
// }
// 
// Path: src/main/net/sf/portecle/gui/SwingHelper.java
// public final class SwingHelper
// {
// 	/** Not needed. */
// 	private SwingHelper()
// 	{
// 		// Ignored
// 	}
// 
// 	/**
// 	 * Makes the given Window visible and waits for it to return.
// 	 * 
// 	 * @param window The window
// 	 */
// 	public static void showAndWait(final Window window)
// 	{
// 		if (SwingUtilities.isEventDispatchThread())
// 		{
// 			window.setVisible(true);
// 		}
// 		else
// 		{
// 			try
// 			{
// 				SwingUtilities.invokeAndWait(new Runnable()
// 				{
// 					@Override
// 					public void run()
// 					{
// 						window.setVisible(true);
// 					}
// 				});
// 			}
// 			catch (InterruptedException | InvocationTargetException e)
// 			{
// 				LOG.log(Level.WARNING, "Error setting window visible", e); // TODO?
// 			}
// 		}
// 	}
// 
// 	/**
// 	 * Select all text in a text component and focus it.
// 	 * 
// 	 * @param component the text component
// 	 */
// 	public static void selectAndFocus(JComponent component)
// 	{
// 		JTextComponent textComponent = null;
// 		if (component instanceof JTextComponent)
// 		{
// 			textComponent = (JTextComponent) component;
// 		}
// 		if (component instanceof JComboBox)
// 		{
// 			Component editorComponent = ((JComboBox<?>) component).getEditor().getEditorComponent();
// 			if (editorComponent instanceof JTextComponent)
// 			{
// 				textComponent = (JTextComponent) editorComponent;
// 			}
// 		}
// 		if (textComponent != null)
// 		{
// 			textComponent.select(0, textComponent.getText().length());
// 		}
// 		component.requestFocusInWindow();
// 	}
// 
// 	/**
// 	 * Shows a simple yes/no confirmation dialog, with the "no" option selected by default. This method exists only
// 	 * because there's apparently no easy way to accomplish that with JOptionPane's static helper methods.
// 	 * 
// 	 * @param parentComponent
// 	 * @param message
// 	 * @param title
// 	 * @see JOptionPane#showConfirmDialog(Component, Object, String, int)
// 	 */
// 	public static int showConfirmDialog(Component parentComponent, Object message, String title)
// 	{
// 		String[] options = { "Yes", "No" };
// 		return JOptionPane.showOptionDialog(parentComponent, message, title, JOptionPane.YES_NO_OPTION,
// 		    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
// 	}
// }


// Path: src/main/net/sf/portecle/DGenerateKeyPair.java
import static net.sf.portecle.FPortecle.RB;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import net.sf.portecle.crypto.KeyPairType;
import net.sf.portecle.gui.IntegerDocumentFilter;
import net.sf.portecle.gui.SwingHelper;

/*
 * DGenerateKeyPair.java
 * This file is part of Portecle, a multipurpose keystore and certificate tool.
 *
 * Copyright © 2004 Wayne Grant, waynedgrant@hotmail.com
 *             2008 Ville Skyttä, ville.skytta@iki.fi
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package net.sf.portecle;





/**
 * Modal dialog used to choose the parameters required for key pair generation. The user may select an asymmetric key
 * generation algorithm of DSA or RSA and enter a key size in bits.
 */
class DGenerateKeyPair
    extends PortecleJDialog
{
	/** Indicator for an invalid key size */
	private static final int BAD_KEYSIZE = -1;

	/** Radio button for the DSA key algorithm */
	private JRadioButton m_jrbDSA;

	/** Radio button for the RSA key algorithm */
	private JRadioButton m_jrbRSA;

	/** Key size combo box */
	private JComboBox<String> m_jcbKeySize;

	/** Key pair type chosen for generation */
	private KeyPairType m_keyPairType;

	/** Key size chosen */
	private int m_iKeySize;

	/** Records whether or not correct parameters are entered */
	private boolean m_bSuccess;

	/**
	 * Creates new DGenerateKeyPair dialog.
	 * 
	 * @param parent The parent window
	 */
	public DGenerateKeyPair(Window parent)
	{
		super(parent, true);