//store off existing value
String existingValue = "";
String existingTestUserPass = "";
JTextField current = fieldMappings.get("Password:");
if(current instanceof JPasswordField){
JPasswordField pass = ((JPasswordField)current);
if(pass!=null){
char[] charArray = pass.getPassword();
if(charArray.length>0){
existingValue = new String(charArray);
}
}
}else{
existingValue = current.getText();
}
//save off test user password as well
if(testUserPasswordValue instanceof JPasswordField){
JPasswordField pass = ((JPasswordField)testUserPasswordValue);
if(pass!=null){
char[] charArray = pass.getPassword();
if(charArray.length>0){
existingTestUserPass = new String(charArray);
}
}
}else{
existingTestUserPass=testUserPasswordValue.getText();
}
JTextField updatedContainer = null;
if(showPasswords.isSelected()){
updatedContainer = new JTextField(textBoxWidth);
updatedContainer.setText(existingValue);
testUserPasswordValue = new JTextField(textBoxWidth);
testUserPasswordValue.setText(existingTestUserPass);
}else{
updatedContainer = new JPasswordField(textBoxWidth);
updatedContainer.setText(existingValue);
testUserPasswordValue = new JPasswordField(textBoxWidth);
testUserPasswordValue.setText(existingTestUserPass);
}
//locate the JPanel and rebuild it Should be at index 3
JPanel passwordRow = (JPanel) top.getComponent(3);
// JTextField jf = (JTextField) passwordRow.getComponent(1);
//store off existing components
Component[] existing = new Component[passwordRow.getComponentCount()];
for(int i=0; i<passwordRow.getComponentCount();i++){
existing[i] = passwordRow.getComponent(i);
}
passwordRow.removeAll();
for(int j=0;j<existing.length;j++){
if(j==1){//insert new JTextField instead
passwordRow.add(updatedContainer);
}else{
passwordRow.add(existing[j]);
}
}
//reload testUserRegion
//store off existing components
Component[] existingTest = new Component[testUserRegion.getComponentCount()];
for(int i=0; i<testUserRegion.getComponentCount();i++){
existingTest[i] = testUserRegion.getComponent(i);
}
testUserRegion.removeAll();
for(int j=0;j<existingTest.length;j++){
if(j==3){//insert new JTextField instead
testUserRegion.add(testUserPasswordValue);
}else{
testUserRegion.add(existingTest[j]);
}
}
top.revalidate();
top.repaint();
}
});
}
});
securityPanel.add(showPasswords);
ssl = new JCheckBox("SSL:");
ssl.setEnabled(false);
securityPanel.add(ssl);
top.add(securityPanel);
// test user auth region
testUserRegion = new JPanel();
testUserRegion.setLayout(new FlowLayout(FlowLayout.LEFT));
LineBorder border = new LineBorder(Color.BLUE, 2);
TitledBorder tBorder = new TitledBorder(border, "Authentication/Authorization Check Credentials: (insert valid ldap user assigned to group)");
testUserRegion.setBorder(tBorder);
JLabel testUserName = new JLabel("Test UserName:");
testUserNameValue = new JTextField(textBoxWidth);
JLabel testUserPassword = new JLabel("Test Password:");
// testUserPasswordValue = new JTextField(textBoxWidth);
testUserPasswordValue = new JPasswordField(textBoxWidth);
testUserRegion.add(testUserName);
testUserRegion.add(testUserNameValue);
testUserRegion.add(testUserPassword);
testUserRegion.add(testUserPasswordValue);
top.add(testUserRegion);