List of usage examples for javax.swing JPasswordField addKeyListener
public synchronized void addKeyListener(KeyListener l)
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * // w w w . j ava 2s.c o m */ private void createAccount() { Institution inst = iPadDBExporter.getCurrentInstitution(); if (StringUtils.isEmpty(inst.getGuid())) { UIRegistry.showError("Institution must have a GUID value."); return; } loadAndPushResourceBundle(RESOURCE_NAME); final JTextField userNameTF = createTextField(15); final JPasswordField passwordTF = createPasswordField(); final JLabel statusLbl = createLabel(" "); ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd); JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT", "Password", passwordTF, statusLbl, imgIcon); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), getResourceString("CREATE_INST_IN_CLOUD"), true, CustomDialog.OKCANCEL, loginPanel) { @Override protected void okButtonPressed() { // NOTE: THis call should fail indicating is is not being used // so it if is OK then it is an error String uName = userNameTF.getText(); if (iPadCloud.isUserNameOK(uName)) { setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName)); } else { super.okButtonPressed(); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { String pwd = new String(passwordTF.getPassword()); boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && pwd.length() > 4; dlg.getOkBtn().setEnabled(isOK); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); dlg.setOkLabel(getResourceString("NEW_ACCOUNT")); dlg.createUI(); dlg.getOkBtn().setEnabled(false); centerAndShow(dlg); popResourceBundle(); if (!dlg.isCancelled()) { cloudInstId = iPadCloud.createInstitution(inst.getName(), inst.getUri(), inst.getCode(), inst.getGuid()); if (cloudInstId != null) { createAccountBtn.setEnabled(false); loginBtn.setEnabled(true); enableRemoveDatasetBtn(); checkInstitutionInfo(false); String uName = userNameTF.getText(); String pwd = new String(passwordTF.getPassword()); if (iPadCloud.addNewUser(uName, pwd, inst.getGuid())) { if (iPadCloud.login(uName, pwd)) { login(new Pair<String, String>(uName, pwd)); } } else { setErrorMsg(statusLbl, kErrorCreatingAcctMsg); } } else { UIRegistry.showError(kErrorCreatingAcctMsg); } } }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * @return/*from w ww.j av a2 s . co m*/ */ private Pair<String, String> getExportLoginCreds(final String userName, final boolean wasInError) { loginBtn.setEnabled(false); loadAndPushResourceBundle(RESOURCE_NAME); try { final JTextField userNameTF = createTextField(15); final JPasswordField passwordTF = createPasswordField(); final JLabel statusLbl = createLabel(" "); if (wasInError) { setErrorMsg(statusLbl, "Your username or password was not correct."); } ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd); JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT", "Password", passwordTF, statusLbl, imgIcon); if (!iPadDBExporter.IS_TESTING) // ZZZ { while (true) { userNameTF.setText(userName); final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(), getResourceString("iPad Cloud Login"), true, CustomDialog.OKCANCELAPPLY, loginPanel) { @Override protected void applyButtonPressed() { String uName = userNameTF.getText(); if (iPadCloud.isUserNameOK(uName)) { setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName)); } else { super.applyButtonPressed(); } } }; KeyAdapter ka = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && StringUtils.isNotEmpty(new String(passwordTF.getPassword())); dlg.getOkBtn().setEnabled(isOK); dlg.getApplyBtn().setEnabled(isOK); } }; userNameTF.addKeyListener(ka); passwordTF.addKeyListener(ka); dlg.setCloseOnApplyClk(true); dlg.setApplyLabel(getResourceString("NEW_USER")); dlg.setOkLabel(getResourceString("LOGIN")); dlg.createUI(); boolean enableBtns = StringUtils.isNotEmpty(userName); dlg.getOkBtn().setEnabled(enableBtns); dlg.getApplyBtn().setEnabled(enableBtns); centerAndShow(dlg); if (!dlg.isCancelled()) { boolean isOK = true; String uName = userNameTF.getText(); String pwd = new String(passwordTF.getPassword()); if (dlg.getBtnPressed() == CustomDialog.APPLY_BTN) { Institution inst = iPadDBExporter.getCurrentInstitution(); if (!iPadCloud.addNewUser(uName, pwd, inst.getGuid())) { setErrorMsg(statusLbl, kErrorCreatingAcctMsg); isOK = false; } } if (isOK) { return new Pair<String, String>(uName, pwd); } } else { return null; } } } return null;//new Pair<String, String>("testuser@ku.edu", "testuser@ku.edu"); } catch (Exception ex) { ex.printStackTrace(); } finally { popResourceBundle(); loginBtn.setEnabled(true); } return null; }