htmlexportdialog.java

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

JAVA
1,476
字号
/**
 * ========================================
 * 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.
 *
 * ---------------------
 * HTMLExportDialog.java
 * ---------------------
 * (C)opyright 2003, by Heiko Evermann and Contributors.
 *
 * Original Author:  Heiko Evermann (for Hawesko GmbH & Co KG) based on PDFSaveDialog;
 * Contributor(s):   Thomas Morgner;
 *                   David Gilbert (for Simba Management Limited);
 *
 * $Id: HtmlExportDialog.java,v 1.8 2003/09/09 21:31:48 taqua Exp $
 *
 * Changes
 * -------
 * 02-Jan-2003 : Initial version
 * 25-Feb-2003 : Updated Javadocs (DG);
 *
 */

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

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.text.MessageFormat;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

import org.jfree.io.IOUtils;
import org.jfree.report.JFreeReport;
import org.jfree.report.modules.gui.base.components.ActionButton;
import org.jfree.report.modules.gui.base.components.EncodingComboBoxModel;
import org.jfree.report.modules.gui.base.components.ExceptionDialog;
import org.jfree.report.modules.gui.base.components.FilesystemFilter;
import org.jfree.report.modules.gui.html.resources.HtmlExportResources;
import org.jfree.report.modules.output.table.base.TableProcessor;
import org.jfree.report.modules.output.table.html.HtmlProcessor;
import org.jfree.report.modules.output.table.html.HtmlProducer;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.report.util.StringUtil;

/**
 * A dialog that is used to perform the printing of a report into an HTML file.
 *
 * @author Heiko Evermann
 */
public class HtmlExportDialog extends JDialog
{
  /** The 'HTML encoding' property key. */
  public static final String HTML_OUTPUT_ENCODING
      = "org.jfree.report.modules.output.table.html.Encoding";
  /** A default value of the 'HTML encoding' property key. */
  public static final String HTML_OUTPUT_ENCODING_DEFAULT = "UTF-16";

  /** Export to a single stream or file. */
  public static final int EXPORT_STREAM = 0;

  /** Export to a directory. */
  public static final int EXPORT_DIR = 1;

  /** Export to a ZIP file. */
  public static final int EXPORT_ZIP = 2;

  /**
   * Internal action class to confirm the dialog and to validate the input.
   */
  private class ActionConfirmZip extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionConfirmZip()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.confirm"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      if (performValidateZip())
      {
        setConfirmed(true);
        setVisible(false);
      }
    }
  }

  /**
   * Internal action class to confirm the dialog and to validate the input.
   */
  private class ActionConfirmDir extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionConfirmDir()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.confirm"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      if (performValidateDir())
      {
        setConfirmed(true);
        setVisible(false);
      }
    }
  }

  /**
   * Internal action class to confirm the dialog and to validate the input.
   */
  private class ActionConfirmStream extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionConfirmStream()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.confirm"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      if (performValidateStream())
      {
        setConfirmed(true);
        setVisible(false);
      }
    }
  }

  /**
   * Internal action class to cancel the report processing.
   */
  private class ActionCancel extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionCancel()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.cancel"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setConfirmed(false);
      setVisible(false);
    }
  }

  /**
   * Internal action class to select a target file.
   */
  private class ActionSelectZipFile extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionSelectZipFile()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.selectZipFile"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      performSelectFileZip();
    }
  }

  /**
   * An action to select a directory.
   */
  private class ActionSelectDirFile extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionSelectDirFile()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.selectDirFile"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      performSelectFileDir();
    }
  }

  /**
   * An action to select a file for the single-stream report.
   */
  private class ActionSelectStreamFile extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionSelectStreamFile()
    {
      putValue(Action.NAME, getResources().getString("htmlexportdialog.selectStreamFile"));
    }

    /**
     * Receives notification that the action has occurred.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      performSelectFileStream();
    }
  }

  /** Cancel action. */
  private Action actionCancel;

  /** Filename text field. */
  private JTextField txStreamFilename;

  /** ZIP filename text field. */
  private JTextField txZipFilename;

  /** Directory filename text field. */
  private JTextField txDirFilename;

  /** ZIP data file name. */
  private JTextField txZipDataFilename;

  /** Directory data file name text field. */
  private JTextField txDirDataFilename;

  /** Title text field. */
  private JTextField txTitle;

  /** Author text field. */
  private JTextField txAuthor;

  /** A combo-box for selecting the encoding. */
  private JComboBox cbEncoding;

  /** The encoding data model. */
  private EncodingComboBoxModel encodingModel;

  /** A check-box for selecting 'strict layout'. */
  private JCheckBox cbxStrictLayout;

  /** A radio button for selecting XHTML. */
  private JRadioButton rbGenerateXHTML;

  /** A radio button for selecting HTML4. */
  private JRadioButton rbGenerateHTML4;

  /** A check-box for... */
  private JCheckBox cbxCopyExternalReferencesZip;

  /** A check-boc for... */
  private JCheckBox cbxCopyExternalReferencesDir;

  /** Confirmed flag. */
  private boolean confirmed;

  /** A file chooser for a ZIP file. */
  private JFileChooser fileChooserZip;

  /** A file chooser for a directory. */
  private JFileChooser fileChooserDir;

  /** A file chooser for a stream. */
  private JFileChooser fileChooserStream;

  /** Tabs for the export selection. */
  private JTabbedPane exportSelection;

  /** Localised resources. */
  private ResourceBundle resources;

  /** The base resource class. */
  public static final String BASE_RESOURCE_CLASS =
      HtmlExportResources.class.getName();

  /**
   * Creates a new HTML save dialog.
   *
   * @param owner  the dialog owner.
   */
  public HtmlExportDialog(final Frame owner)
  {
    super(owner);
    initConstructor();
  }

  /**
   * Creates a new HTML export dialog.
   *
   * @param owner  the dialog owner.
   */
  public HtmlExportDialog(final Dialog owner)
  {
    super(owner);
    initConstructor();
  }

  /**
   * Creates a new HTML save dialog.  The created dialog is modal.
   */
  public HtmlExportDialog()
  {
    initConstructor();
  }

  /**
   * Initialisation.
   */
  private void initConstructor()
  {
    setModal(true);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    setTitle(getResources().getString("htmlexportdialog.dialogtitle"));
    initialize();
    clear();

    addWindowListener(new WindowAdapter()
    {
      public void windowClosing(final WindowEvent e)
      {
        getCancelAction().actionPerformed(null);
      }
    }
    );
  }

  /**
   * Returns the cancel action.
   *
   * @return the cancel action.
   */
  protected Action getCancelAction()
  {
    return actionCancel;
  }

  /**
   * Retrieves the resources for this dialog. If the resources are not initialized,
   * they get loaded on the first call to this method.
   *
   * @return this frames ResourceBundle.
   */
  protected ResourceBundle getResources()
  {
    if (resources == null)
    {
      resources = ResourceBundle.getBundle(BASE_RESOURCE_CLASS);
    }
    return resources;
  }

  /**
   * Initializes the Swing components of this dialog.
   */
  private void initialize()
  {
    actionCancel = new ActionCancel();

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());
    contentPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    final JLabel lblAuthor = new JLabel(getResources().getString("htmlexportdialog.author"));
    final JLabel lblTitel = new JLabel(getResources().getString("htmlexportdialog.title"));
    final JLabel lblEncoding = new JLabel(getResources().getString("htmlexportdialog.encoding"));

    txAuthor = new JTextField();
    txTitle = new JTextField();

    encodingModel = EncodingComboBoxModel.createDefaultModel();
    encodingModel.sort();
    cbEncoding = new JComboBox(encodingModel);
    cbxStrictLayout = new JCheckBox(getResources().getString("htmlexportdialog.strict-layout"));
    rbGenerateHTML4 = new JRadioButton(getResources().getString("htmlexportdialog.generate-html4"));
    rbGenerateXHTML = new JRadioButton(getResources().getString("htmlexportdialog.generate-xhtml"));
    final ButtonGroup bg = new ButtonGroup();
    bg.add(rbGenerateHTML4);
    bg.add(rbGenerateXHTML);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(3, 1, 1, 1);
    contentPane.add(lblTitel, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(lblAuthor, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(lblEncoding, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.ipadx = 120;
    gbc.insets = new Insets(3, 1, 1, 1);
    contentPane.add(txTitle, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;

⌨️ 快捷键说明

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