|  |  |  | @@ -2,14 +2,16 @@ package envoy.client.ui; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import java.awt.*; | 
		
	
		
			
				|  |  |  |  | import java.awt.event.ItemEvent; | 
		
	
		
			
				|  |  |  |  | import java.awt.event.ItemListener; | 
		
	
		
			
				|  |  |  |  | import java.security.NoSuchAlgorithmException; | 
		
	
		
			
				|  |  |  |  | import java.util.Arrays; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import javax.swing.*; | 
		
	
		
			
				|  |  |  |  | import javax.swing.border.EmptyBorder; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import envoy.client.event.HandshakeSuccessfulEvent; | 
		
	
		
			
				|  |  |  |  | import envoy.data.LoginCredentials; | 
		
	
		
			
				|  |  |  |  | import envoy.event.EventBus; | 
		
	
		
			
				|  |  |  |  | import envoy.event.HandshakeRejectionEvent; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | /** | 
		
	
		
			
				|  |  |  |  |  * Project: <strong>envoy-client</strong><br> | 
		
	
	
		
			
				
					
					|  |  |  | @@ -28,8 +30,11 @@ public class LoginDialog extends JDialog { | 
		
	
		
			
				|  |  |  |  | 	private JTextField			textField; | 
		
	
		
			
				|  |  |  |  | 	private JPasswordField		passwordField; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private JPasswordField		repeatPasswordField; | 
		
	
		
			
				|  |  |  |  | 	private JLabel				lblRepeatPassword; | 
		
	
		
			
				|  |  |  |  | 	private JPasswordField	repeatPasswordField; | 
		
	
		
			
				|  |  |  |  | 	private JLabel			lblRepeatPassword; | 
		
	
		
			
				|  |  |  |  | 	private JLabel			errorMessage; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private GridBagConstraints	gbc_errorMessage; | 
		
	
		
			
				|  |  |  |  | 	private GridBagConstraints	gbc_lblRepeatPassword; | 
		
	
		
			
				|  |  |  |  | 	private GridBagConstraints	gbc_repeatPasswordField; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -97,12 +102,27 @@ public class LoginDialog extends JDialog { | 
		
	
		
			
				|  |  |  |  | 			gbc_lblRepeatPassword.gridy		= 2; | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		{ | 
		
	
		
			
				|  |  |  |  | 			repeatPasswordField = new JPasswordField(); | 
		
	
		
			
				|  |  |  |  | 			repeatPasswordField				= new JPasswordField(); | 
		
	
		
			
				|  |  |  |  | 			gbc_repeatPasswordField			= new GridBagConstraints(); | 
		
	
		
			
				|  |  |  |  | 			gbc_repeatPasswordField.fill	= GridBagConstraints.HORIZONTAL; | 
		
	
		
			
				|  |  |  |  | 			gbc_repeatPasswordField.gridx	= 1; | 
		
	
		
			
				|  |  |  |  | 			gbc_repeatPasswordField.gridy	= 2; | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		{ | 
		
	
		
			
				|  |  |  |  | 			EventBus.getInstance().register(HandshakeRejectionEvent.class, evt -> { | 
		
	
		
			
				|  |  |  |  | 				contentPanel.remove(errorMessage); | 
		
	
		
			
				|  |  |  |  | 				clearPasswordFields(); | 
		
	
		
			
				|  |  |  |  | 				// TODO delete - only for testing purposes | 
		
	
		
			
				|  |  |  |  | 				System.out.println("Caught HandshakeRejectionEvent with reason" + ((HandshakeRejectionEvent) evt).get()); | 
		
	
		
			
				|  |  |  |  | 				errorMessage			= new JLabel(((HandshakeRejectionEvent) evt).get()); | 
		
	
		
			
				|  |  |  |  | 				gbc_errorMessage		= new GridBagConstraints(); | 
		
	
		
			
				|  |  |  |  | 				gbc_errorMessage.gridx	= 2; | 
		
	
		
			
				|  |  |  |  | 				gbc_errorMessage.gridy	= 0; | 
		
	
		
			
				|  |  |  |  | 				gbc_errorMessage.fill	= GridBagConstraints.HORIZONTAL; | 
		
	
		
			
				|  |  |  |  | 				gbc_errorMessage.insets	= new Insets(5, 5, 5, 5); | 
		
	
		
			
				|  |  |  |  | 				contentPanel.add(errorMessage, gbc_errorMessage); | 
		
	
		
			
				|  |  |  |  | 			}); | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		{ | 
		
	
		
			
				|  |  |  |  | 			JPanel buttonPane = new JPanel(); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -114,30 +134,24 @@ public class LoginDialog extends JDialog { | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 			JCheckBox registerCheckBox = new JCheckBox(); | 
		
	
		
			
				|  |  |  |  | 			registerCheckBox.setAlignmentX(LEFT_ALIGNMENT); | 
		
	
		
			
				|  |  |  |  | 			registerCheckBox.addItemListener(new ItemListener() { | 
		
	
		
			
				|  |  |  |  | 			registerCheckBox.addItemListener(e -> { | 
		
	
		
			
				|  |  |  |  | 				switch (e.getStateChange()) { | 
		
	
		
			
				|  |  |  |  | 					case ItemEvent.SELECTED: | 
		
	
		
			
				|  |  |  |  | 						contentPanel.add(lblRepeatPassword, gbc_lblRepeatPassword); | 
		
	
		
			
				|  |  |  |  | 						contentPanel.add(repeatPasswordField, gbc_repeatPasswordField); | 
		
	
		
			
				|  |  |  |  | 						setSize(338, 160); | 
		
	
		
			
				|  |  |  |  | 						break; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 				@Override | 
		
	
		
			
				|  |  |  |  | 				public void itemStateChanged(ItemEvent e) { | 
		
	
		
			
				|  |  |  |  | 					switch (e.getStateChange()) { | 
		
	
		
			
				|  |  |  |  | 						case ItemEvent.SELECTED: | 
		
	
		
			
				|  |  |  |  | 							contentPanel.add(lblRepeatPassword, gbc_lblRepeatPassword); | 
		
	
		
			
				|  |  |  |  | 							contentPanel.add(repeatPasswordField, gbc_repeatPasswordField); | 
		
	
		
			
				|  |  |  |  | 							setSize(338, 160); | 
		
	
		
			
				|  |  |  |  | 							contentPanel.revalidate(); | 
		
	
		
			
				|  |  |  |  | 							contentPanel.repaint(); | 
		
	
		
			
				|  |  |  |  | 							break; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 						case ItemEvent.DESELECTED: | 
		
	
		
			
				|  |  |  |  | 							if (repeatPasswordField.getParent() == contentPanel) { | 
		
	
		
			
				|  |  |  |  | 								contentPanel.remove(lblRepeatPassword); | 
		
	
		
			
				|  |  |  |  | 								contentPanel.remove(repeatPasswordField); | 
		
	
		
			
				|  |  |  |  | 								setSize(338, 123); | 
		
	
		
			
				|  |  |  |  | 								contentPanel.revalidate(); | 
		
	
		
			
				|  |  |  |  | 								contentPanel.repaint(); | 
		
	
		
			
				|  |  |  |  | 							} | 
		
	
		
			
				|  |  |  |  | 							break; | 
		
	
		
			
				|  |  |  |  | 					} | 
		
	
		
			
				|  |  |  |  | 					case ItemEvent.DESELECTED: | 
		
	
		
			
				|  |  |  |  | 						if (repeatPasswordField.getParent() == contentPanel) { | 
		
	
		
			
				|  |  |  |  | 							contentPanel.remove(lblRepeatPassword); | 
		
	
		
			
				|  |  |  |  | 							contentPanel.remove(repeatPasswordField); | 
		
	
		
			
				|  |  |  |  | 							setSize(338, 123); | 
		
	
		
			
				|  |  |  |  | 						} | 
		
	
		
			
				|  |  |  |  | 						break; | 
		
	
		
			
				|  |  |  |  | 				} | 
		
	
		
			
				|  |  |  |  | 				contentPanel.revalidate(); | 
		
	
		
			
				|  |  |  |  | 				contentPanel.repaint(); | 
		
	
		
			
				|  |  |  |  | 			}); | 
		
	
		
			
				|  |  |  |  | 			buttonPane.add(registerCheckBox); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
	
		
			
				
					
					|  |  |  | @@ -148,18 +162,14 @@ public class LoginDialog extends JDialog { | 
		
	
		
			
				|  |  |  |  | 				okButton.addActionListener((evt) -> { | 
		
	
		
			
				|  |  |  |  | 					try { | 
		
	
		
			
				|  |  |  |  | 						if (registerCheckBox.isSelected()) { | 
		
	
		
			
				|  |  |  |  | 							if (Arrays.equals(passwordField.getPassword(), repeatPasswordField.getPassword())) { | 
		
	
		
			
				|  |  |  |  | 							// password checking | 
		
	
		
			
				|  |  |  |  | 							if (Arrays.equals(passwordField.getPassword(), repeatPasswordField.getPassword())) | 
		
	
		
			
				|  |  |  |  | 								credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), true); | 
		
	
		
			
				|  |  |  |  | 								dispose(); | 
		
	
		
			
				|  |  |  |  | 							} else { | 
		
	
		
			
				|  |  |  |  | 								JOptionPane.showMessageDialog(this, "The repeated password is unequal to the origional password!"); | 
		
	
		
			
				|  |  |  |  | 								passwordField.setText(null); | 
		
	
		
			
				|  |  |  |  | 								repeatPasswordField.setText(null); | 
		
	
		
			
				|  |  |  |  | 							else { | 
		
	
		
			
				|  |  |  |  | 								JOptionPane.showMessageDialog(this, "The repeated password is not the origional password!"); | 
		
	
		
			
				|  |  |  |  | 								clearPasswordFields(); | 
		
	
		
			
				|  |  |  |  | 							} | 
		
	
		
			
				|  |  |  |  | 						} else { | 
		
	
		
			
				|  |  |  |  | 							credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), false); | 
		
	
		
			
				|  |  |  |  | 							dispose(); | 
		
	
		
			
				|  |  |  |  | 						} | 
		
	
		
			
				|  |  |  |  | 						} else credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), false); | 
		
	
		
			
				|  |  |  |  | 					} catch (NoSuchAlgorithmException e) { | 
		
	
		
			
				|  |  |  |  | 						e.printStackTrace(); | 
		
	
		
			
				|  |  |  |  | 					} | 
		
	
	
		
			
				
					
					|  |  |  | @@ -178,6 +188,17 @@ public class LoginDialog extends JDialog { | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 		setModal(true); | 
		
	
		
			
				|  |  |  |  | 		setVisible(true); | 
		
	
		
			
				|  |  |  |  | 		EventBus.getInstance().register(HandshakeSuccessfulEvent.class, evt -> this.dispose()); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
		
			
				|  |  |  |  | 	 * Resets the text stored by this | 
		
	
		
			
				|  |  |  |  | 	 * | 
		
	
		
			
				|  |  |  |  | 	 * @since Envoy v0.3-alpha | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public void clearPasswordFields() { | 
		
	
		
			
				|  |  |  |  | 		passwordField.setText(null); | 
		
	
		
			
				|  |  |  |  | 		repeatPasswordField.setText(null); | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
	
		
			
				
					
					|  |  |  |   |