previewproxybase.java

来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 2,255 行 · 第 1/5 页

JAVA
2,255
字号
/**
 * ========================================
 * JFreeReport : a free Java report library
 * ========================================
 *
 * Project Info:  http://www.jfree.org/jfreereport/index.html
 * Project Lead:  Thomas Morgner;
 *
 * (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * ---------------------
 * PreviewProxyBase.java
 * ---------------------
 * (C)opyright 2003, by Simba Management Limited and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: PreviewProxyBase.java,v 1.32.2.1 2003/12/21 23:28:44 taqua Exp $
 *
 * Changes
 * -------
 * 25-Feb-2003 : Added standard header and Javadocs (DG);
 *
 */

package org.jfree.report.modules.gui.base;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.RepaintManager;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;

import org.jfree.layout.CenterLayout;
import org.jfree.report.JFreeReport;
import org.jfree.report.ReportInterruptedException;
import org.jfree.report.ReportProcessingException;
import org.jfree.report.event.RepaginationListener;
import org.jfree.report.modules.gui.base.components.AbstractActionDowngrade;
import org.jfree.report.modules.gui.base.components.ActionButton;
import org.jfree.report.modules.gui.base.components.ActionDowngrade;
import org.jfree.report.modules.gui.base.components.ActionMenuItem;
import org.jfree.report.modules.gui.base.components.DowngradeActionMap;
import org.jfree.report.modules.gui.base.components.ExceptionDialog;
import org.jfree.report.modules.gui.base.components.FloatingButtonEnabler;
import org.jfree.report.modules.gui.base.resources.JFreeReportResources;
import org.jfree.report.util.ImageUtils;
import org.jfree.report.util.Log;
import org.jfree.report.util.Worker;
import org.jfree.report.util.WorkerPool;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.ui.RefineryUtilities;
import org.jfree.xml.ParserUtil;

/**
 * A preview proxy. This class is the backend for all preview components.
 *
 * @author Thomas Morgner.
 */
public class PreviewProxyBase extends JComponent
{
  /** The property name for the largeIconsEnabled property for the toolbar. */
  public static final String LARGE_ICONS_PROPERTY = "largeIconsEnabled";
  /** A key to query an action from the action map. */
  public static final String GOTO_ACTION_KEY = "GotoAction";
  /** A key to query an action from the action map. */
  public static final String ABOUT_ACTION_KEY = "AboutAction";
  /** A key to query an action from the action map. */
  public static final String CLOSE_ACTION_KEY = "CloseAction";
  /** A key to query an action from the action map. */
  public static final String FIRSTPAGE_ACTION_KEY = "FirstPageAction";
  /** A key to query an action from the action map. */
  public static final String LASTPAGE_ACTION_KEY = "LastPageAction";
  /** A key to query an action from the action map. */
  public static final String NEXT_PAGE_ACTION_KEY = "NextPageAction";
  /** A key to query an action from the action map. */
  public static final String PREV_PAGE_ACTION_KEY = "PreviousPageAction";
  /** A key to query an action from the action map. */
  public static final String ZOOM_IN_ACTION_KEY = "ZoomInAction";
  /** A key to query an action from the action map. */
  public static final String ZOOM_OUT_ACTION_KEY = "ZoomOutAction";

  /** The default width of the report pane. */
  public static final int DEFAULT_REPORT_PANE_WIDTH = 640;

  /** The default height of the report pane. */
  public static final int DEFAULT_REPORT_PANE_HEIGHT = 480;

  /** The preferred width key. */
  public static final String PREVIEW_PREFERRED_WIDTH
      = "org.jfree.report.modules.gui.base.PreferredWidth";

  /** The preferred height key. */
  public static final String PREVIEW_PREFERRED_HEIGHT
      = "org.jfree.report.modules.gui.base.PreferredHeight";

  /** The maximum width key. */
  public static final String PREVIEW_MAXIMUM_WIDTH
      = "org.jfree.report.modules.gui.base.MaximumWidth";

  /** The maximum height key. */
  public static final String PREVIEW_MAXIMUM_HEIGHT
      = "org.jfree.report.modules.gui.base.MaximumHeight";

  /** A configuration key to define whether large toolbar icons are enabled. */
  public static final String LARGE_ICONS_ENABLED_PROPERTY
      = "org.jfree.report.modules.gui.base.LargeIcons";

  /** A configuration key to define whether the toolbar is floatable. */
  public static final String TOOLBAR_FLOATABLE_PROPERTY
      = "org.jfree.report.modules.gui.base.ToolbarFloatable";

  /** A configuration key to define whether the toolbar is created. */
  public static final String CREATE_TOOLBAR_PROPERTY
      = "org.jfree.report.modules.gui.base.ToolbarAvailable";

  /** A configuration key to define whether the toolbar is floatable. */
  public static final String CREATE_MENUBAR_PROPERTY
      = "org.jfree.report.modules.gui.base.MenuBarAvailable";

  /** The property name for the toolbarFloatable property. */
  public static final String TOOLBAR_FLOATABLE_PROPERTYNAME
      = "toolbarFloatable";

  /**
   * A configuration key to define whether and how the about action
   * should be included. Can be set to "disable", "menu", "toolbar", "enable"
   */
  public static final String ACTION_ABOUT_PROPERTY
      = "org.jfree.report.modules.gui.base.About";

  /**
   * A configuration key to define whether and how the zoom actions
   * should be included. Can be set to "disable", "menu", "toolbar", "enable"
   */
  public static final String ACTION_ZOOM_PROPERTY
      = "org.jfree.report.modules.gui.base.Zoom";

  /**
   * A configuration key to define whether and how the navigation actions
   * should be included. Can be set to "disable", "menu", "toolbar", "enable"
   */
  public static final String ACTION_NAVIGATION_PROPERTY
      = "org.jfree.report.modules.gui.base.Navigate";

  /**
   * An property change handler for the toolbar. Handles the toolbarFloatable
   * and largeIconsEnabled properties.
   */
  private class ToolbarPropertyChangeListener implements PropertyChangeListener
  {
    /**
     * This method gets called when a bound property is changed.
     * @param evt A PropertyChangeEvent object describing the event source
     *        and the property that has changed.
     */
    public void propertyChange(final PropertyChangeEvent evt)
    {
      if (evt.getSource() == getToolbar())
      {
        if ("floatable".equals(evt.getPropertyName()))
        {
          setToolbarFloatable(getToolbar().isFloatable());
        }
      }
      else if (evt.getSource() == PreviewProxyBase.this)
      {
        if (TOOLBAR_FLOATABLE_PROPERTYNAME.equals(evt.getPropertyName()))
        {
          getToolbar().setFloatable(isToolbarFloatable());
        }
        else if (LARGE_ICONS_ENABLED_PROPERTY.equals(evt.getPropertyName()))
        {
          reinitialize();
        }
      }
    }
  }

  /**
   * A property change listener.
   */
  private class ReportPanePropertyChangeListener implements PropertyChangeListener
  {
    /**
     * Creates a new listener.
     */
    public ReportPanePropertyChangeListener()
    {
    }

    /**
     * Listen to the assigned reportPane.
     *
     * @param event  the property change event.
     */
    public void propertyChange(final PropertyChangeEvent event)
    {
      final String property = event.getPropertyName();
      final ReportPane reportPane = getReportPane();

      if (property.equals(ReportPane.PAGINATED_PROPERTY))
      {
        if (reportPane.isPaginated())
        {
          // is paginated ...
          final Object[] params = new Object[]{
            new Integer(reportPane.getPageNumber()),
            new Integer(reportPane.getNumberOfPages())
          };
          setStatusText(
              MessageFormat.format(
                  getResources().getString("statusline.pages"),
                  params
              )
          );
          validateButtons();
        }
        else
        {
          // is not paginated ... ignore event ...
        }
      }
      else if (property.equals(ReportPane.PAGENUMBER_PROPERTY)
          || property.equals(ReportPane.NUMBER_OF_PAGES_PROPERTY))
      {

        final Object[] params = new Object[]{
          new Integer(reportPane.getPageNumber()),
          new Integer(reportPane.getNumberOfPages())
        };
        setStatusText(
            MessageFormat.format(
                getResources().getString("statusline.pages"),
                params
            )
        );
        validateButtons();
      }
      else if (property.equals(ReportPane.ERROR_PROPERTY))
      {
        if (reportPane.hasError())
        {
          final Exception ex = reportPane.getError();

          ex.printStackTrace();
          setStatusText(
              MessageFormat.format(
                  getResources().getString("statusline.error"),
                  new Object[]{ex.getMessage()}
              )
          );
        }
        validateButtons();
      }
      else if (property.equals(ReportPane.ZOOMFACTOR_PROPERTY))
      {
        validateButtons();
        validate();
      }
    }
  }

  /**
   * Default 'first page' action.
   */
  private class DefaultFirstPageAction extends FirstPageAction
  {
    /**
     * Creates a 'first page' action.
     */
    public DefaultFirstPageAction()
    {
      super(getResources());
    }

    /**
     * Jump to the first page of the report.
     *
     * @param e The action event.
     *
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(final ActionEvent e)
    {
      firstPage();
    }
  }

  /**
   * Default 'next page' action for the frame.
   */
  private class DefaultNextPageAction extends NextPageAction
  {

    /**
     * Creates a 'next page' action.
     */
    public DefaultNextPageAction()
    {
      super(getResources());
    }

    /**
     * show the next page of the report.
     *
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      increasePageNumber();
    }
  }

  /**
   * Default 'previous page' action for the frame.
   */
  private class DefaultPreviousPageAction extends PreviousPageAction
  {
    /**
     * Creates a 'previous page' action.
     */
    public DefaultPreviousPageAction()
    {
      super(getResources());
    }

    /**
     * show the previous page of the report.
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      decreasePageNumber();
    }
  }

  /**
   * Default 'last page' action for the frame.
   */
  private class DefaultLastPageAction extends LastPageAction
  {
    /**
     * Creates a 'last page' action.
     */
    public DefaultLastPageAction()
    {
      super(getResources());
    }

    /**
     * jump to the last page of the report.
     *
     * @param e The action event.
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(final ActionEvent e)
    {
      lastPage();
    }
  }

  /**
   * Default 'zoom in' action for the frame.
   */
  private class DefaultZoomInAction extends ZoomInAction
  {

    /**
     * Creates a 'zoom in' action.
     */
    public DefaultZoomInAction()
    {
      super(getResources());
    }

    /**
     * increase zoom.
     * @param e The action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      increaseZoom();
    }
  }

  /**
   * Default 'zoom out' action for the frame.
   */
  private class DefaultZoomOutAction extends ZoomOutAction
  {
    /**
     * Creates a 'zoom out' action.
     */
    public DefaultZoomOutAction()
    {
      super(getResources());
    }

    /**
     * decrease zoom.

⌨️ 快捷键说明

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