passwordpromptencryptionhandler.java
来自「Java生成PDF Java生成PDF Java生成PDF」· Java 代码 · 共 48 行
JAVA
48 行
// $Id: PasswordPromptEncryptionHandler.java,v 1.6 2007/11/05 14:54:57 mike Exp $package org.faceless.pdf2.viewer2;import org.faceless.pdf2.*;import javax.swing.*;import java.awt.*;import java.io.*;/** * An extension of the {@link StandardEncryptionHandler} that will pop up a * password dialog to request the password if necessary. * <p><i>This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.</i></p> * @since 2.8 */public class PasswordPromptEncryptionHandler extends StandardEncryptionHandler{ private Component parent; public PasswordPromptEncryptionHandler(Component parent) { this.parent = parent; } public void prepareToDecrypt() throws IOException { try { super.prepareToDecrypt(); } catch (PasswordException e) { boolean ok = false; do { Frame frame = JOptionPane.getFrameForComponent(parent); JPasswordField field = new JPasswordField(16); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(SuperJOptionPane.getLocalizedString("Password")), BorderLayout.WEST); panel.add(field, BorderLayout.CENTER); if (JOptionPane.showConfirmDialog(frame, panel, SuperJOptionPane.getLocalizedString("Password"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != 0) { throw new PasswordException(SuperJOptionPane.getLocalizedString("WrongPassword")); } else { setUserPassword(new String(field.getPassword())); try { super.prepareToDecrypt(); ok = true; } catch (PasswordException e2) { } } } while(!ok); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?