private void showButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showButtonActionPerformed if (!passwordVisible) { passwordVisible = true; originalFont = passwordField.getFont(); passwordField.setFont(usernameTextField.getFont()); originalEchoChar = passwordField.getEchoChar(); passwordField.setEchoChar((char) 0); Mnemonics.setLocalizedText(showButton, NbBundle.getMessage(CustomizerGeneral.class, "LBL_ShowButtonHide")); showButton.setToolTipText(NbBundle.getMessage(CustomizerGeneral.class, "LBL_ShowButtonHide_ToolTip")); } else { passwordVisible = false; passwordField.setFont(originalFont); passwordField.setEchoChar(originalEchoChar); Mnemonics.setLocalizedText(showButton, NbBundle.getMessage(CustomizerGeneral.class, "CustomizerGeneral.showButton.text")); showButton.setToolTipText(NbBundle.getMessage(CustomizerGeneral.class, "CustomizerGeneral.showButton.toolTipText")); } }//GEN-LAST:event_showButtonActionPerformed
public Shape modelToView( int pos, Shape a, Position.Bias b) throws BadLocationException { Container c = getContainer(); if ( c instanceof JPasswordField ) { JPasswordField f = (JPasswordField)c; if ( !f.echoCharIsSet() ) { return super.modelToView( pos, a, b); } char echoChar = f.getEchoChar(); int w = f.getFontMetrics( f.getFont()).charWidth( echoChar); w = ( w < ancho ? ancho : w) + hueco; Rectangle alloc = adjustAllocation( a).getBounds(); int dx = (pos - getStartOffset()) * w; alloc.x += dx - 2; if ( alloc.x <= 5 ) { alloc.x = 6; } alloc.width = 1; return alloc; } return null; }
public int viewToModel( float fx, float fy, Shape a, Position.Bias[] bias) { bias[0] = Position.Bias.Forward; int n = 0; Container c = getContainer(); if ( c instanceof JPasswordField ) { JPasswordField f = (JPasswordField)c; if ( !f.echoCharIsSet() ) { return super.viewToModel( fx, fy, a, bias); } char echoChar = f.getEchoChar(); int w = f.getFontMetrics( f.getFont()).charWidth( echoChar); w = ( w < ancho ? ancho : w) + hueco; a = adjustAllocation( a); Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds(); n = ((int)fx - alloc.x) / w; if (n < 0) { n = 0; } else if ( n > (getStartOffset() + getDocument().getLength()) ) { n = getDocument().getLength() - getStartOffset(); } } return getStartOffset() + n; } }