⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfviewer.java

📁 Java生成PDF Java生成PDF Java生成PDF
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    public synchronized KeyStoreManager getKeyStoreManager() {        if (keystoremanager==null) {            keystoremanager = KeyStoreManager.createDefaultKeyStoreManager(this);        }        return keystoremanager;    }    /**     * Set the {@link KeyStoreManager} used by this PDFViewer     * @since 2.8.3     */    public void setKeyStoreManager(KeyStoreManager manager) {        this.keystoremanager = keystoremanager;    }    /**     * Return true if the Viewer has a certain feature enabled.     * @param feature the feature to look for     */    public boolean hasFeature(ViewerFeature feature) {        return features.contains(feature);    }    /**     * Return true if the Viewer has a certain feature enabled.     * @param feature the name of the feature to look for     */    public boolean hasFeature(String feature) {        for (Iterator i = features.iterator();i.hasNext();) {            if (((ViewerFeature)i.next()).getName().equals(feature)) return true;        }        return false;    }    /**     * Return the list of all features set in the viewer     */    public ViewerFeature[] getFeatures() {        return (ViewerFeature[])new ArrayList(features).toArray(new ViewerFeature[0]);    }    /**     * Return the specified <code>ViewerFeature</code>, or <code>null</code>     * if it doesn't exist for this viewer     * @since 2.8.5     */    public ViewerFeature getFeature(String feature) {        for (Iterator i = features.iterator();i.hasNext();) {            ViewerFeature f = (ViewerFeature)i.next();            if (f.getName().equals(feature)) return f;        }        return null;    }    //-------------------------------------------------------------------------------    // Methods to be called by Features when they're adding themselves to this Viewer    //-------------------------------------------------------------------------------    /**     * Return the specifeid ToolBar. If the toolbar doesn't exist, it's created.     * @param name the name of the ToolBar     * @param enabled whether the toolbar is enabled or not     * @param always whether the toolbar is always in it's enabled state     */    final JComponent getToolBar(String name, boolean enabled, boolean enabledalways, boolean floatable, boolean floating) {        name = name.trim();        if (enabledalways) name=name+" ";        if (floating) {            final String nname = name;            final JInternalFrame toolbar = new JInternalFrame(name, false, true);            if (hasFeature(ToolbarDisabling.getInstance())) {                toolbar.addInternalFrameListener(new InternalFrameListener() {                    public void internalFrameClosing(InternalFrameEvent e) {                        JMenu menu = (JMenu)getMenu(SuperJOptionPane.getLocalizedString("View")).getItem(0);                        for (int i=0;i<menu.getItemCount();i++) {                            if (nname.equals(menu.getItem(i).getText())) {                                ((JCheckBoxMenuItem)menu.getItem(i)).setState(false);                            }                        }                        toolbar.dispose();                    }                    public void internalFrameActivated(InternalFrameEvent e) { }                    public void internalFrameDeactivated(InternalFrameEvent e) { }                    public void internalFrameDeiconified(InternalFrameEvent e) { }                    public void internalFrameIconified(InternalFrameEvent e) { }                    public void internalFrameOpened(InternalFrameEvent e) { }                    public void internalFrameClosed(InternalFrameEvent e) { }                });            }            toolbar.setLocation(100+(toolbars.size()*20), 60+(toolbars.size()*20));            toolbar.setVisible(enabled);            toolbars.put(name, toolbar);            return toolbar;        } else {            JToolBar toolbar = (JToolBar)toolbars.get(name);            if (toolbar==null) {                toolbar = new JToolBar();                toolbar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));                toolbar.setBorder(BorderFactory.createEtchedBorder());                toolbar.setFloatable(floatable && hasFeature(ToolbarFloating.getInstance()));                toolbar.setVisible(enabled);                toolbars.put(name, toolbar);            }            return toolbar;        }    }    /**     * Return the specified Menu. If the menu doesn't exist, it's created     * @param name the name of the Menu     */    final JMenu getMenu(String name) {        JMenu menu = (JMenu)menus.get(name);        if (menu==null) {            menu = new JMenu(name);            menus.put(name, menu);        }        return menu;    }    /**     * Add a named component to the viewers list     */    void putNamedComponent(String name, JComponent value) {        components.put(name, value);    }    /**     * Add a component to the list of those that require a valid PDF to be open     */    void addDocumentDependentComponent(JComponent component) {        pdfcomponents.add(component);    }    /**     * Return a Component created by a {@link ViewerFeature}     */    public JComponent getNamedComponent(String name) {        return (JComponent)components.get(name);    }    /**     * Get the Frame this Viewer is inside. Used for dialogs     */    Frame getFrame() {        return JOptionPane.getFrameForComponent(this);    }    //-------------------------------------------------------------------------------    // Methods for loading a PDF or changing the active PDF    //-------------------------------------------------------------------------------    /**     * Load a PDF into the viewer from a file using a {@link PasswordPromptEncryptionHandler},     * which will prompt for the password if required.     * @param file the PDF file to load, or <code>null</code> to select it with a chooser     * @since 2.7.1     */    public void loadPDF(File file) {        EncryptionHandler[] handlers = new EncryptionHandler[2];        handlers[0] = new PasswordPromptEncryptionHandler(this);        handlers[1] = new PublicKeyPromptEncryptionHandler(this, getKeyStoreManager());        loadPDF(file, handlers);    }    /**     * Load a PDF into the viewer from a file using the specified {@link EncryptionHandler}.     * @param file the PDF file to load, or <code>null</code> to select it with a chooser     * @param handler the EncryptionHandler to load the PDF with     * @since 2.8     */    public void loadPDF(File file, EncryptionHandler handler) {        loadPDF(file, new EncryptionHandler[] { handler });    }    /**     * Load a PDF into the viewer from a file using the specified list of {@link EncryptionHandler}s.     * @param file the PDF file to load, or <code>null</code> to select it with a chooser     * @param handlers the EncryptionHandler to load the PDF with     * @since 2.8     */    public void loadPDF(File file, EncryptionHandler[] handlers) {        if (file == null) {            int returnVal = filechooser.showOpenDialog(this);            if (returnVal == JFileChooser.APPROVE_OPTION) {                repaint();                file = filechooser.getSelectedFile();            }        }        if (file!=null) {            try {                loadPDF(new FileInputStream(file), handlers, file.getName(), file);            } catch (IOException e) {                SuperJOptionPane.displayThrowable(SuperJOptionPane.getLocalizedString("Error"), e, getFrame());            }        }    }    /**     * Load a PDF into the viewer from an InputStream.     * @param in the InputStream to load the PDF from     * @param handler the EncryptionHandler to load the PDF with     * @param title The name of the window. May be null.     * @param file If using a save dialog, the file to set the save dialog to. May be null.     * @since 2.8     */    public void loadPDF(InputStream in, EncryptionHandler handler, String title, File file) {        loadPDF(in, new EncryptionHandler[] { handler }, title, file);    }    /**     * Load a PDF into the viewer from an InputStream. Note that this method will     * return immediately, which means the calling thread <i>must not close</i> the     * InputStream. Doing so will result in an Exception. The stream will be closed     * by the reading thread when it is completed.     *     * @param in the InputStream to load the PDF from     * @param handlers the list of EncryptionHandler to attempt to load the PDF with.     * @param title The name of the window. May be null.     * @param file If using a save dialog, the file to set the save dialog to. May be null.     * @since 2.8.3     */    public void loadPDF(final InputStream in, final EncryptionHandler[] handlers, final String title, final File file) {        final JDialog dialog = new JDialog(getFrame());        dialog.setModal(false);        final JProgressBar progress = new JProgressBar(0, 100);        JPanel content = new JPanel(new BorderLayout(10, 0));        content.setBorder(new EmptyBorder(10, 10, 10, 10));        dialog.setContentPane(content);        dialog.getContentPane().add(new JLabel(SuperJOptionPane.getLocalizedString("Loading")), BorderLayout.WEST);        dialog.getContentPane().add(progress, BorderLayout.CENTER);        dialog.setUndecorated(true);        dialog.setResizable(false);        dialog.pack();        dialog.setLocationRelativeTo(this);        final float[] progressnum = new float[1];        final Timer timer = new Timer();        timer.schedule(new TimerTask() {            public void run() {                if (!dialog.isVisible()) {                    new Thread() {                        public void run() {                            dialog.setVisible(true);                        }                    }.start();                }                progress.setValue((int)(progressnum[0]*100));            }        }, 1000, 100);        new Thread () {            public void run() {                try {                    PDFReader reader = new PDFReader(in, handlers, progressnum);                    in.close();                    timer.cancel();                    PDF pdf = new PDF(reader);                    if (dialog.isVisible()) dialog.dispose();                    String ftitle = title;                    if ("true".equals(pdf.getOption("view.displayDocTitle"))) {                        ftitle = pdf.getInfo("Title");                    }                    if (ftitle==null) ftitle = "BFO";                    addDocumentPanel(pdf, ftitle, file);                    if ("true".equals(pdf.getOption("view.fullscreen"))) {                        activedocument.runAction(PDFAction.named("FullScreen"));                    }                } catch (Exception e) {                    timer.cancel();                    if (dialog.isVisible()) dialog.dispose();                    SuperJOptionPane.displayThrowable(SuperJOptionPane.getLocalizedString("Error"), e, getFrame());                }            }        }.start();    }    /**     * Load a pre-loaded PDF into the viewer.     * @param pdf the PDF to load     * @param name the name of the PDF, to display in the title bar.     * @since 2.7.1     */    public void loadPDF(final PDF pdf, final String name) {        if (pdf!=null) {            SwingUtilities.invokeLater(new Runnable() {                public void run() {                    File file = null;                    try {                        if (name!=null) file = new File(name);

⌨️ 快捷键说明

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