📄 plaintextexportdialog.java
字号:
/**
* ========================================
* 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.19.2.2 2003/08/24 14:18:11 taqua Exp $
*
* Changes
* --------
* 25-Feb-2003 : Added standard header and Javadocs (DG);
*
*/
package com.jrefinery.report.preview;
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.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
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 com.jrefinery.report.JFreeReport;
import com.jrefinery.report.targets.pageable.PageableReportProcessor;
import com.jrefinery.report.targets.pageable.output.EpsonPrinterCommandSet;
import com.jrefinery.report.targets.pageable.output.IBMPrinterCommandSet;
import com.jrefinery.report.targets.pageable.output.PlainTextOutputTarget;
import com.jrefinery.report.targets.pageable.output.PrinterCommandSet;
import com.jrefinery.report.util.ActionButton;
import com.jrefinery.report.util.ActionRadioButton;
import com.jrefinery.report.util.ExceptionDialog;
import com.jrefinery.report.util.NullOutputStream;
import com.jrefinery.report.util.ReportConfiguration;
import com.jrefinery.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 =
"com.jrefinery.report.resources.JFreeReportResources";
/**
* 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);
init();
}
/**
* Initialise the dialog.
*/
private void init()
{
setModal(true);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setTitle(getResources().getString("plain-text-exportdialog.dialogtitle"));
plainTextCommandSet = new PrinterCommandSet(new NullOutputStream(),
new PageFormat(), 10, 6);
plainTextEncodingModel = createEncodingModel(plainTextCommandSet);
epsonPrinterCommandSet = new EpsonPrinterCommandSet(new NullOutputStream(),
new PageFormat(), 10, 6);
epsonPrinterEncodingModel = createEncodingModel(epsonPrinterCommandSet);
ibmPrinterCommandSet = new IBMPrinterCommandSet(new NullOutputStream(),
new PageFormat(), 10, 6);
ibmPrinterEncodingModel = createEncodingModel(ibmPrinterCommandSet);
selectedEncodingModel = plainTextEncodingModel;
cbEncoding = new JComboBox(selectedEncodingModel);
final Integer[] lpiModel = {
LPI_6,
LPI_10
};
final Integer[] cpiModel = {
CPI_10,
CPI_12,
CPI_15,
CPI_17,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -