plaintextexportdialog.java

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

JAVA
1,075
字号
/**
 * ========================================
 * 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.
 *
 * --------------------------
 * PlainTextExportDialog.java
 * --------------------------
 * (C)opyright 2003, by Thomas Morgner and Contributors.
 *
 * Original Author:  Thomas Morgner;
 * Contributor(s):   David Gilbert (for Simba Management Limited);
 *
 * $Id: PlainTextExportDialog.java,v 1.8 2003/09/09 21:31:48 taqua Exp $
 *
 * Changes
 * --------
 * 25-Feb-2003 : Added standard header and Javadocs (DG);
 *
 */

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

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.awt.print.PageFormat;
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.DefaultComboBoxModel;
import javax.swing.JButton;
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.JTextField;
import javax.swing.KeyStroke;

import org.jfree.report.JFreeReport;
import org.jfree.report.modules.gui.base.components.ActionButton;
import org.jfree.report.modules.gui.base.components.ActionRadioButton;
import org.jfree.report.modules.gui.base.components.EncodingComboBoxModel;
import org.jfree.report.modules.gui.plaintext.resources.PlainTextExportResources;
import org.jfree.report.modules.output.pageable.plaintext.EpsonPrinterCommandSet;
import org.jfree.report.modules.output.pageable.plaintext.IBMPrinterCommandSet;
import org.jfree.report.modules.output.pageable.plaintext.PlainTextOutputTarget;
import org.jfree.report.modules.output.pageable.plaintext.PrinterCommandSet;
import org.jfree.report.util.NullOutputStream;
import org.jfree.report.util.ReportConfiguration;
import org.jfree.report.util.StringUtil;
import org.jfree.ui.ExtensionFileFilter;

/**
 * A dialog that is used to export reports to plain text.
 *
 * @author Thomas Morgner.
 */
public class PlainTextExportDialog extends JDialog
{
  /**
   * Internal action class to confirm the dialog and to validate the input.
   */
  private class ActionConfirm extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionConfirm()
    {
      putValue(Action.NAME, getResources().getString("plain-text-exportdialog.confirm"));
    }

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

  /**
   * Internal action class to confirm the dialog and to validate the input.
   */
  private class ActionCancel extends AbstractAction
  {
    /**
     * Default constructor.
     */
    public ActionCancel()
    {
      putValue(Action.NAME, getResources().getString("plain-text-exportdialog.cancel"));
    }

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

  /**
   * An action to select a file.
   */
  private class ActionSelectFile extends AbstractAction
  {
    /**
     * Defines an <code>Action</code> object with a default
     * description string and default icon.
     */
    public ActionSelectFile()
    {
      putValue(NAME, getResources().getString("plain-text-exportdialog.selectFile"));
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      performSelectFile();
    }
  }

  /**
   * An action to select a plain printer.
   */
  private class ActionSelectPlainPrinter extends AbstractAction
  {
    /**
     * Defines an <code>Action</code> object with a default
     * description string and default icon.
     */
    public ActionSelectPlainPrinter()
    {
      putValue(NAME, getResources().getString("plain-text-exportdialog.printer.plain"));
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setSelectedPrinter(TYPE_PLAIN_OUTPUT);
    }
  }

  /**
   * An action to select an Epson printer.
   */
  private class ActionSelectEpsonPrinter extends AbstractAction
  {
    /**
     * Defines an <code>Action</code> object with a default
     * description string and default icon.
     */
    public ActionSelectEpsonPrinter()
    {
      putValue(NAME, getResources().getString("plain-text-exportdialog.printer.epson"));
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  the action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setSelectedPrinter(TYPE_EPSON_OUTPUT);
    }
  }

  /**
   * An action to select an IBM printer.
   */
  private class ActionSelectIBMPrinter extends AbstractAction
  {
    /**
     * Defines an <code>Action</code> object with a default
     * description string and default icon.
     */
    public ActionSelectIBMPrinter()
    {
      putValue(NAME, getResources().getString("plain-text-exportdialog.printer.ibm"));
    }

    /**
     * Invoked when an action occurs.
     *
     * @param e  an action event.
     */
    public void actionPerformed(final ActionEvent e)
    {
      setSelectedPrinter(TYPE_IBM_OUTPUT);
    }
  }

  /** Plain text output. */
  public static final int TYPE_PLAIN_OUTPUT = 0;

  /** Epson printer output. */
  public static final int TYPE_EPSON_OUTPUT = 1;

  /** IBM printer output. */
  public static final int TYPE_IBM_OUTPUT = 2;

  /** 6 lines per inch. */
  public static final Integer LPI_6 = new Integer(6);

  /** 10 lines per inch. */
  public static final Integer LPI_10 = new Integer(10);

  /** 10 characters per inch. */
  public static final Integer CPI_10 = new Integer(10);

  /** 12 characters per inch. */
  public static final Integer CPI_12 = new Integer(12);

  /** 15 characters per inch. */
  public static final Integer CPI_15 = new Integer(15);

  /** 17 characters per inch. */
  public static final Integer CPI_17 = new Integer(17);

  /** 20 characters per inch. */
  public static final Integer CPI_20 = new Integer(20);

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

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

  /** The plain text encodings. */
  private EncodingComboBoxModel plainTextEncodingModel;

  /** The IBM printer encodings. */
  private EncodingComboBoxModel ibmPrinterEncodingModel;

  /** The Epson printer encodings. */
  private EncodingComboBoxModel epsonPrinterEncodingModel;

  /** The selected encoding model. */
  private EncodingComboBoxModel selectedEncodingModel;

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

  /** A radio button for selecting plain printer commands. */
  private JRadioButton rbPlainPrinterCommandSet;

  /** A radio button for selecting Epson printer commands. */
  private JRadioButton rbEpsonPrinterCommandSet;

  /** A radio button for selecting IBM printer commands. */
  private JRadioButton rbIBMPrinterCommandSet;

  /** The filename text field. */
  private JTextField txFilename;

  /** A combo-box for selecting lines per inch. */
  private JComboBox cbLinesPerInch;

  /** A combo-box for selecting characters per inch. */
  private JComboBox cbCharsPerInch;

  /** A file chooser. */
  private JFileChooser fileChooser;

  /** The printer command set for generic text printers. */
  private PrinterCommandSet plainTextCommandSet;
  /** The printer command set for ibm compatible text printers. */
  private PrinterCommandSet ibmPrinterCommandSet;
  /** The printer command set for epson compatible text printers. */
  private PrinterCommandSet epsonPrinterCommandSet;

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

  /**
   * Creates a non-modal dialog without a title and without
   * a specified Frame owner.  A shared, hidden frame will be
   * set as the owner of the Dialog.
   */
  public PlainTextExportDialog()
  {
    init();
  }

  /**
   * Creates a non-modal dialog without a title with the
   * specifed Frame as its owner.
   *
   * @param owner the Frame from which the dialog is displayed
   */
  public PlainTextExportDialog(final Frame owner)
  {
    super(owner);
    init();
  }

  /**
   * Creates a non-modal dialog without a title with the
   * specifed Dialog as its owner.
   *
   * @param owner the Dialog from which the dialog is displayed
   */
  public PlainTextExportDialog(final Dialog owner)
  {
    super(owner);

⌨️ 快捷键说明

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