fullscreenmode.java

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

JAVA
79
字号
// $Id: FullScreenMode.java,v 1.3 2007/11/05 14:54:57 mike Exp $package org.faceless.pdf2.viewer2.feature;import org.faceless.pdf2.viewer2.*;import org.faceless.pdf2.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * Create a menu item that will display the Document in "Full Screen" mode. * Pressing escape will exit form this mode. This feature may also be run * as the result of a named action or the documents initial view setting * (see {@link PDF#setOption PDF.setOption("view.fullscreen")}). * The name of this feature is "FullScreen". * <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.2 */public class FullScreenMode extends ViewerWidget implements KeyListener{    private DocumentViewport viewport;    private Container parent;    private int index;    public FullScreenMode() {        super("FullScreen");        setMenu("View\tDisplay\tFullScreenMode");    }    public void initialize(PDFViewer viewer) {        super.initialize(viewer);    }    public void action(ViewerEvent event) {        GraphicsDevice device = event.getViewer().getGraphicsConfiguration().getDevice();        if (device.isFullScreenSupported()) {            if (parent==null) {                viewport = event.getDocumentPanel().getViewport();                parent = viewport.getParent();                for (int i=0;i<parent.getComponentCount();i++) {                    if (parent.getComponent(i)==viewport) {                        index = i;                        break;                    }                }                JFrame fullscreenframe = new JFrame(device.getDefaultConfiguration());                fullscreenframe.setUndecorated(true);                fullscreenframe.setResizable(false);                fullscreenframe.setContentPane(viewport);                device.setFullScreenWindow(fullscreenframe);                fullscreenframe.validate();                viewport.addKeyListener(this);                viewport.setFocusable(true);                viewport.requestFocusInWindow();                viewport.getDocumentPanel().runAction(PDFAction.goToFit(viewport.getPage()));            } else {                viewport.removeKeyListener(this);                if (index==0) {                    parent.add(viewport);                } else {                    parent.add(viewport, index);                }                device.setFullScreenWindow(null);                parent.validate();                parent = null;            }        }    }    public void keyPressed(KeyEvent e) { }    public void keyTyped(KeyEvent e) { }    public void keyReleased(KeyEvent e) {        if (e.getKeyCode()==e.VK_ESCAPE) {            action(new ViewerEvent(getViewer(), null));        }    }}

⌨️ 快捷键说明

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