📄 about.java
字号:
// $Id: About.java,v 1.9 2007/11/21 07:32:11 mike Exp $package org.faceless.pdf2.viewer2.feature;import org.faceless.pdf2.viewer2.*;import org.faceless.pdf2.*;import javax.swing.*;import javax.swing.event.*;import java.awt.event.*;import javax.swing.border.*;import java.awt.*;import java.util.*;/** * Create a simple "About" dialog displaying information about the PDFViewer and the runtime environment. * The name of this feature is "About" * <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 About extends ViewerWidget{ private Map keys; private static Map statickeys; public About() { super("About"); setDocumentRequired(false); setMenu("Window\tAbout"); } protected About(String title) { super(title); } public void action(final ViewerEvent event) { showAboutDialog(event.getViewer(), true, 0); } private static synchronized void initializeStatic() { statickeys = new LinkedHashMap(); statickeys.put("Icon", PDFViewer.class.getResource("resources/BFOLogo.png")); statickeys.put("Title", "Java PDF Viewer"); statickeys.put("Main", "Big Faceless Organization \u00A9 2001-2007"); statickeys.put("PDF Library", PDF.VERSION); try { Object licensee = Class.forName("org.faceless.license.LicensePDF").getMethod("get", new Class[] { String.class }).invoke(null, new Object[] { "name" }); Object licensenumber = Class.forName("org.faceless.license.LicensePDF").getMethod("get", new Class[] { String.class }).invoke(null, new Object[] { "licensenumber" }); if (licensee!=null) { statickeys.put("Licensed To", licensee+" ("+licensenumber+")"); } } catch (Throwable e) { statickeys.put("Licensed To", "Unlicensed - Demo Version"); } statickeys.put("Java", System.getProperty("java.version")+" by "+System.getProperty("java.vendor")); } private synchronized void initialize() { if (statickeys==null) { initializeStatic(); if (!statickeys.containsKey("JavaScript")) { putStaticProperty("JavaScript", getViewer().getJSManager().getImplementationDescription()); } } keys = new LinkedHashMap(); } /** * Add a property to the "About" dialog. This method is static, which means that properties * set via this method will appear in all About dialogs created by this class and its subclasses. * Keys that have alreay been set and may be overridden include: * <table class="defn"> * <tr><th>Icon</th><td>The URL of the Icon to display in the dialog</td></tr> * <tr><th>Title</th><td>The Title displayed in the dialog</td></tr> * <tr><th>Main</th><td>The main line of text</td></tr> * <tr><th>PDF Viewer</th><td>The version of the PDF Viewer software</td></tr> * <tr><th>Java</th><td>The version of Java being run</td></tr> * <tr><th>JavaScript</th><td>The JavaScript implementation availabe to the Viewer</td></tr> * </table> * Any one of these keys may be overriden or have their value set to <code>null</code> to * suppress their display. * @since 2.9 */ public synchronized static Object putStaticProperty(String key, Object property) { if (statickeys==null) initializeStatic(); return statickeys.put(key, property); } /** * Add a property to the "About" dialog. This method only adds properties to About dialogs created * by this instance. Values set in this way will override values set via the {@link #putStaticProperty} * method. * @since 2.9 */ public synchronized Object putProperty(String key, Object property) { if (keys==null) initialize(); return keys.put(key, property); } /** * Show an "About" dialog in the viewer. * @param viewer the Viewer this about dialog relates to * @param featurelist whether to display the list of Features available to the viewer * @param autoclear the number of ms to wait before clearing the dialog. A value of 0 means * the dialog must be clicked to close. * @since 2.9 */ public void showAboutDialog(PDFViewer viewer, boolean featurelist, final int autoclear) { if (keys==null) initialize(); LinkedHashMap aboutkeys = new LinkedHashMap(); aboutkeys.putAll(statickeys); aboutkeys.putAll(keys); final JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(viewer)); dialog.setModal(false); JPanel content = new JPanel(new GridBagLayout()); content.setBackground(Color.white); content.setBorder(new EmptyBorder(20, 20, 20, 20)); GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbk = new GridBagConstraints(); gbc.fill = gbc.HORIZONTAL; gbk.fill = gbc.HORIZONTAL; gbk.gridwidth = 1; gbk.insets = new Insets(0, 0, 0, 20); gbc.gridwidth = gbc.REMAINDER; ImageIcon icon = aboutkeys.get("Icon")!=null ? new ImageIcon((java.net.URL)aboutkeys.get("Icon")) : null; content.add(new JLabel((String)aboutkeys.get("Title"), icon, SwingConstants.LEFT), gbc); if (aboutkeys.get("Main")!=null) { gbc.insets = new Insets(10, 0, 10, 0); content.add(new JLabel((String)aboutkeys.get("Main")), gbc); gbc.insets = new Insets(0, 0, 0, 0); } for (Iterator i = aboutkeys.entrySet().iterator();i.hasNext();) { Map.Entry e = (Map.Entry)i.next(); String key = (String)e.getKey(); if (!"Main".equals(key) && !"Icon".equals(key) && !"Title".equals(key) && e.getValue()!=null) { if (e.getValue().equals("")) { content.add(new JLabel(key), gbc); } else { content.add(new JLabel(key), gbk); content.add(new JLabel((String)e.getValue()), gbc); } } } if (featurelist) { gbc.insets = new Insets(10, 0, 0, 0); StringBuffer t = new StringBuffer("Available Features\n\n"); ViewerFeature[] x = viewer.getFeatures(); for (int i=0;i<x.length;i++) { t.append(x[i].toString()); if (i==x.length-1) t.append("\n"); } JTextArea featlabel = new JTextArea(t.toString()); featlabel.setLineWrap(true); featlabel.setFont(featlabel.getFont().deriveFont(9f)); JScrollPane scrollpane = new JScrollPane(featlabel); scrollpane.setPreferredSize(new Dimension(300, 70)); content.add(scrollpane, gbc); } dialog.setContentPane(content); dialog.setUndecorated(true); dialog.setResizable(false); dialog.pack(); dialog.setLocationRelativeTo(viewer); if (autoclear!=0) { new Thread() { public void run() { try { Thread.sleep(autoclear); } catch (InterruptedException e) { } dialog.setVisible(false); dialog.dispose(); } }.start(); dialog.addFocusListener(new FocusListener() { public void focusGained(FocusEvent event) {} public void focusLost(FocusEvent event) { dialog.setVisible(false); dialog.dispose(); } }); } content.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { dialog.setVisible(false); dialog.dispose(); } }); dialog.setVisible(true); dialog.requestFocus(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -