📄 pkcspassworddialog.java
字号:
/*** $Id: PKCSPasswordDialog.java,v 1.3 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail.smime;import java.awt.*;import java.awt.event.*;import java.net.InetAddress;import javax.swing.*;import javax.swing.border.*;import javax.mail.*;import org.icemail.util.AWTUtilities;public class PKCSPasswordDialog extends JDialog implements ActionListener{ private String password; private boolean clickedOK; private JPasswordField passField; public PKCSPasswordDialog( Frame parent, String title, String addr ) { super( parent, title, true ); this.establishContents( addr ); this.pack(); this.addWindowListener( new WindowAdapter() { public void windowActivated( WindowEvent event ) { passField.requestFocus(); passField.selectAll(); } } ); } public String getPassword() { return this.password; } public void actionPerformed( ActionEvent event ) { boolean doDispose = false; String command = event.getActionCommand(); if ( command.equals( "OK" ) ) { doDispose = true; this.clickedOK = true; this.password = new String( this.passField.getPassword() ); } else if ( command.equals( "CANCEL" ) ) { doDispose = true; this.clickedOK = false; this.password = null; } else if ( event.getSource() == this.passField ) { doDispose = true; this.clickedOK = true; this.password = new String( this.passField.getPassword() ); } if ( doDispose ) { this.dispose(); } } protected void establishContents( String addr ) { int row = 0; JLabel lbl = null; Container contentPane = this.getContentPane(); contentPane.setLayout( new GridBagLayout() ); JPanel content = new JPanel(); content.setLayout( new GridBagLayout() ); content.setBorder( new EmptyBorder( 5, 5, 5, 5 ) ); contentPane.add( content ); lbl = new NoFocusLabel( "EMail Address:" ); lbl.setForeground( Color.black ); lbl.setBorder( new EmptyBorder( 1, 1, 1, 4 ) ); AWTUtilities.constrain( content, lbl, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, row, 1, 1, 0.0, 0.0 ); JLabel addrLbl = new NoFocusLabel( addr ); addrLbl.setHorizontalAlignment( JLabel.LEFT ); addrLbl.setBorder( new CompoundBorder ( new EmptyBorder( 2, 0, 6, 0 ), new CompoundBorder ( new BevelBorder( BevelBorder.LOWERED ), new EmptyBorder( 1, 2, 1, 2 ) ) ) ); AWTUtilities.constrain( content, addrLbl, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = new NoFocusLabel( "Password:" ); lbl.setForeground( Color.black ); lbl.setBorder( new EmptyBorder( 1, 1, 1, 4 ) ); AWTUtilities.constrain( content, lbl, GridBagConstraints.NONE, GridBagConstraints.WEST, 0, row, 1, 1, 0.0, 0.0 ); this.passField = new JPasswordField( 20 ); this.passField.setEchoChar( '*' ); this.passField.addActionListener( this ); AWTUtilities.constrain( content, this.passField, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 ); AWTUtilities.constrain( content, new JSeparator( JSeparator.HORIZONTAL ), GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 0, row++, 2, 1, 1.0, 0.0, new Insets( 7, 0, 0, 0 ) ); JPanel ctlPan = new JPanel(); ctlPan.setLayout( new BorderLayout() ); AWTUtilities.constrain( content, ctlPan, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 0.0 ); JPanel btnPanel = new JPanel(); btnPanel.setLayout( new GridLayout( 1, 2, 25, 7 ) ); btnPanel.setBorder( new EmptyBorder( 8, 5, 1, 1 ) ); JButton okBtn = new JButton( "Ok" ); okBtn.setActionCommand( "OK" ); okBtn.addActionListener( this ); btnPanel.add( okBtn ); JButton canBtn = new JButton( "Cancel" ); canBtn.setActionCommand( "CANCEL" ); canBtn.addActionListener( this ); btnPanel.add( canBtn ); ctlPan.add( BorderLayout.EAST, btnPanel ); } private class NoFocusLabel extends JLabel { public NoFocusLabel( String text ) { super( text ); } public boolean isFocusTraversable() { return false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -