genericnamedactionhandler.java

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

JAVA
58
字号
// $Id: GenericNamedActionHandler.java,v 1.7 2007/09/12 10:04:59 mike Exp $package org.faceless.pdf2.viewer2.feature;import org.faceless.pdf2.viewer2.*;import org.faceless.pdf2.*;import javax.swing.*;/** * Create an action handler to handle "Named" actions. Unlike most of the ActionHandler * features, this one will only work inside a {@link PDFViewer} - applying it to a * standalone {@link DocumentPanel} won't work. In addition this is intended as a generic * fallback handler, and so should always be added after any more specific handlers. * The name of this feature is "GenericNamedActionHandler". * <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 GenericNamedActionHandler extends ActionHandler{    private static GenericNamedActionHandler instance;        /**     * Return the GenericNamedActionHandler     */    public static GenericNamedActionHandler getInstance() {        if (instance==null) instance = new GenericNamedActionHandler();        return instance;    }    private GenericNamedActionHandler() {        super("GenericNamedActionHandler");    }    public boolean matches(DocumentPanel panel, PDFAction action) {        String type = action.getType();        return type.startsWith("Named:");    }    public void run(DocumentPanel docpanel, PDFAction action) {        PDFViewer viewer = docpanel.getViewer();        if (viewer!=null) {            String name = action.getType().substring(6);            ViewerFeature[] features = viewer.getFeatures();            for (int i=0;i<features.length;i++) {                ViewerFeature f = features[i];                if (name.equals(f.getName())) {                    if (f instanceof ViewerWidget) {                        ((ViewerWidget)f).action(new ViewerEvent(viewer, docpanel));                    } else if (f instanceof SidePanelFactory) {                        String panelname = ((SidePanelFactory)f).getDisplayName();                        docpanel.setSelectedSidePanel(panelname);                    }                }            }        }    }}

⌨️ 快捷键说明

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