info.java

来自「Java生成PDF Java生成PDF Java生成PDF」· Java 代码 · 共 171 行

JAVA
171
字号
// $Id: Info.java,v 1.13 2007/11/08 09:44:18 mike Exp $package org.faceless.pdf2.viewer2.feature;import org.faceless.pdf2.viewer2.*;import org.faceless.pdf2.*;import javax.swing.*;import java.awt.*;import java.util.*;/** * Create a button and menu item to display information about the PDF. * The name of this feature is "GeneralInfo". * <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 Info extends ViewerWidget{    public Info() {        super("GeneralInfo");        setButton("Document", "resources/icons/info.png", "tt.GeneralInfo");        setMenu("File\tDocumentProperties");    }    public void action(ViewerEvent event) {        PDF pdf = event.getPDF();        if (pdf != null) {            displayInfoPanel(pdf, event.getViewer());        }    }    public void displayInfoPanel(PDF pdf, Component parent) {        JTabbedPane comp = new JTabbedPane(JTabbedPane.LEFT);        comp.setTabPlacement(JTabbedPane.TOP);        comp.addTab(SuperJOptionPane.getLocalizedString("Info"), null, new JScrollPane(getInfoPanel(pdf)), null);        if (pdf.getEncryptionHandler() instanceof StandardEncryptionHandler) {            comp.addTab(SuperJOptionPane.getLocalizedString("Encryption"), null, new JScrollPane(getStandardEncryptionPanel(pdf)), null);        } else if (pdf.getEncryptionHandler() instanceof PublicKeyEncryptionHandler) {            comp.addTab(SuperJOptionPane.getLocalizedString("Encryption"), null, new JScrollPane(getPublicKeyEncryptionPanel(pdf)), null);        }        comp.addTab(SuperJOptionPane.getLocalizedString("Features"), null, new JScrollPane(getProfilePanel(pdf)), null);        comp.setPreferredSize(new Dimension(500,300));        JOptionPane.showMessageDialog(parent, comp, SuperJOptionPane.getLocalizedString("About"), JOptionPane.PLAIN_MESSAGE, null);    }    public JComponent getInfoPanel(PDF pdf) {        String out = "";        for (Iterator i = pdf.getInfo().entrySet().iterator();i.hasNext();) {            Map.Entry e = (Map.Entry)i.next();            String key = (String)e.getKey();            if (!(e.getValue() instanceof Calendar)) {                if (key.equals("ModDate")) {                    key = SuperJOptionPane.getLocalizedString("Modified");                } else if (key.equals("CreateDate")) {                    key = SuperJOptionPane.getLocalizedString("Created");                }                out+="<tr><th>"+key+"</th><td>"+e.getValue()+"</td></tr>\n";            }        }        out = "<html><head><style>th { text-align:left; margin-right:30px }</style></head><table>"+out+"</table></html>";        return new JLabel(out);    }    public JComponent getStandardEncryptionPanel(PDF pdf) {        final StandardEncryptionHandler handler = (StandardEncryptionHandler)pdf.getEncryptionHandler();        int fchange = handler.getChange();        int fprint = handler.getPrint();        int fextract = handler.getExtract();        return getGeneralEncryptionPanel(fchange, fprint, fextract, "PasswordSecurity", handler.getDescription());    }    public JComponent getPublicKeyEncryptionPanel(PDF pdf) {        final PublicKeyEncryptionHandler handler = (PublicKeyEncryptionHandler)pdf.getEncryptionHandler();        int fchange = handler.getChange();        int fprint = handler.getPrint();        int fextract = handler.getExtract();        return getGeneralEncryptionPanel(fchange, fprint, fextract, "CertificateSecurity", null);    }    private JComponent getGeneralEncryptionPanel(int fchange, int fprint, int fextract, String type, String algorithm) {        String print, change, form, comment, copy, copyac;        switch (fprint) {          case StandardEncryptionHandler.PRINT_NONE:            print = "NotAllowed";            break;          case StandardEncryptionHandler.PRINT_LOWRES:            print = "LowResolution";            break;          default:            print = "Allowed";            break;        }        switch (fextract) {          case StandardEncryptionHandler.EXTRACT_NONE:            copy = "NotAllowed";            copyac = "NotAllowed";            break;          case StandardEncryptionHandler.EXTRACT_ACCESSIBILITY:            copy = "NotAllowed";            copyac = "Allowed";            break;          default:            copy = "Allowed";            copyac = "Allowed";            break;        }        switch (fchange) {          case StandardEncryptionHandler.CHANGE_NONE:            change = "NotAllowed";            form = "NotAllowed";            comment = "NotAllowed";            break;          case StandardEncryptionHandler.CHANGE_LAYOUT:            change = "Allowed";            form = "NotAllowed";            comment = "NotAllowed";            break;          case StandardEncryptionHandler.CHANGE_ANNOTATIONS:            change = "NotAllowed";            form = "NotAllowed";            comment = "Allowed";            break;          case StandardEncryptionHandler.CHANGE_FORMS:            change = "NotAllowed";            form = "Allowed";            comment = "Allowed";            break;          default:            change = "Allowed";            form = "Allowed";            comment = "Allowed";        }        print = SuperJOptionPane.getLocalizedString(print);        change = SuperJOptionPane.getLocalizedString(change);        form = SuperJOptionPane.getLocalizedString(form);        comment = SuperJOptionPane.getLocalizedString(comment);        String out = "";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("Security")+"</th><td>"+SuperJOptionPane.getLocalizedString(type)+"</td></tr>\n";        if (algorithm!=null) {            out += "<tr><th>"+SuperJOptionPane.getLocalizedString("Algorithm")+"</th><td>"+algorithm+"</td></tr>\n";        }        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("Printing")+"</th><td>"+print+"</td></tr>\n";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("ChangingDocument")+"</th><td>"+change+"</td></tr>\n";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("ContentCopying")+"</th><td>"+copy+"</td></tr>\n";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("ContentCopyingAcc")+"</th><td>"+copyac+"</td></tr>\n";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("Commenting")+"</th><td>"+comment+"</td></tr>\n";        out += "<tr><th>"+SuperJOptionPane.getLocalizedString("FormFilling")+"</th><td>"+form+"</td></tr>\n";        out = "<html><head><style>th { text-align:right; margin-right:30px }</style></head><body><table>"+out+"</table></body></html>";        return new JLabel(out);    }    public JComponent getProfilePanel(final PDF pdf) {        final JLabel info = new JLabel(SuperJOptionPane.getLocalizedString("Loading"));        new Thread() {            public void run() {                OutputProfile profile = pdf.getFullOutputProfile();                StringBuffer s = new StringBuffer("<html><body><ul>");                for (int i=0;i<OutputProfile.Feature.ALL.length;i++) {                    OutputProfile.Feature feature = OutputProfile.Feature.ALL[i];                    if (profile.isSet(feature)) {                        s.append("<li>"+feature+"</li>\n");                    }                }                s.append("</ul></body></html>");                info.setText(s.toString());            }        }.start();        return info;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?