📄 pdfsavedialog.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.
*
* ------------------
* PDFSaveDialog.java
* ------------------
* (C)opyright 2002, 2003, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: PDFSaveDialog.java,v 1.38.2.4 2003/08/24 14:18:11 taqua Exp $
*
* Changes
* --------
* 26-Aug-2002 : Initial version
* 29-Aug-2002 : Downport to JDK 1.2.2
* 31-Aug-2002 : Documentation
* 01-Sep-2002 : Printing security was inaccurate; bug (exception in JOptionPane) when file exists
* More documentation
* 10-Dec-2002 : Minor Javadoc changes (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.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.JPasswordField;
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.PDFOutputTarget;
import com.jrefinery.report.util.ActionButton;
import com.jrefinery.report.util.ExceptionDialog;
import com.jrefinery.report.util.FilesystemFilter;
import com.jrefinery.report.util.ReportConfiguration;
import com.jrefinery.report.util.Log;
/**
* A dialog that is used to perform the printing of a report into a PDF file. It is primarily
* used to edit the properties of the {@link PDFOutputTarget} before the target is used to print
* the report.
* <p>
* The main method to call the dialog is PDFSaveDialog.savePDF(). Given a report and a pageformat,
* the dialog is shown and if the user approved the dialog, the pdf is saved using the settings
* made in the dialog.
*
* @author Thomas Morgner
*/
public class PDFSaveDialog extends JDialog
{
/** Useful constant. */
private static final int CBMODEL_NOPRINTING = 0;
/** Useful constant. */
private static final int CBMODEL_DEGRADED = 1;
/** Useful constant. */
private static final int CBMODEL_FULL = 2;
/**
* Internal action class to enable/disable the Security-Settings panel. Without encryption a
* pdf file cannot have any security settings enabled.
*/
private class ActionSecuritySelection extends AbstractAction
{
/**
* Default constructor.
*/
public ActionSecuritySelection()
{
}
/**
* Receives notification that the action has occurred.
*
* @param e the action event.
*/
public void actionPerformed(final ActionEvent e)
{
updateSecurityPanelEnabled();
}
}
/**
* 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("pdfsavedialog.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 cancel the report processing.
*/
private class ActionCancel extends AbstractAction
{
/**
* Default constructor.
*/
public ActionCancel()
{
putValue(Action.NAME, getResources().getString("pdfsavedialog.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 ActionSelectFile extends AbstractAction
{
/**
* Default constructor.
*/
public ActionSelectFile()
{
putValue(Action.NAME, getResources().getString("pdfsavedialog.selectFile"));
}
/**
* Receives notification that the action has occurred.
*
* @param e the action event.
*/
public void actionPerformed(final ActionEvent e)
{
performSelectFile();
}
}
/** Confirm action. */
private Action actionConfirm;
/** Cancel action. */
private Action actionCancel;
/** Security selection action. */
private Action actionSecuritySelection;
/** Select file action. */
private Action actionSelectFile;
/** Filename text field. */
private JTextField txFilename;
/** Author text field. */
private JTextField txAuthor;
/** Title text field. */
private JTextField txTitle;
/** Security (none) radio button. */
private JRadioButton rbSecurityNone;
/** Security (40 bit) radio button. */
private JRadioButton rbSecurity40Bit;
/** Security (128 bit) radio button. */
private JRadioButton rbSecurity128Bit;
/** User password text field. */
private JTextField txUserPassword;
/** Owner password text field. */
private JTextField txOwnerPassword;
/** Confirm user password text field. */
private JTextField txConfUserPassword;
/** Confirm ownder password text field. */
private JTextField txConfOwnerPassword;
/** Allow copy check box. */
private JCheckBox cxAllowCopy;
/** Allow screen readers check box. */
private JCheckBox cxAllowScreenReaders;
/** Allow printing check box. */
private JComboBox cbAllowPrinting;
/** Allow assembly check box. */
private JCheckBox cxAllowAssembly;
/** Allow modify contents check box. */
private JCheckBox cxAllowModifyContents;
/** Allow modify annotations check box. */
private JCheckBox cxAllowModifyAnnotations;
/** Allow fill in check box. */
private JCheckBox cxAllowFillIn;
/** Combo box for selecting the printing model. */
private DefaultComboBoxModel printingModel;
/** A combo-box for selecting the encoding. */
private JComboBox cbEncoding;
/** A model for the available encodings. */
private EncodingComboBoxModel encodingModel;
/** Confirmed flag. */
private boolean confirmed;
/** Confirm button. */
private JButton btnConfirm;
/** Cancel button. */
private JButton btnCancel;
/** Localised resources. */
private ResourceBundle resources;
/** A file chooser. */
private JFileChooser fileChooser;
/** The base resource class. */
public static final String BASE_RESOURCE_CLASS =
"com.jrefinery.report.resources.JFreeReportResources";
/**
* Creates a new PDF save dialog.
*
* @param owner the dialog owner.
*/
public PDFSaveDialog(final Frame owner)
{
super(owner);
initConstructor();
}
/**
* Creates a new PDF save dialog.
*
* @param owner the dialog owner.
*/
public PDFSaveDialog(final Dialog owner)
{
super(owner);
initConstructor();
}
/**
* Creates a new PDF save dialog. The created dialog is modal.
*/
public PDFSaveDialog()
{
initConstructor();
}
/**
* Updates the security panel state. If no encryption is selected, all security
* setting components will be disabled.
*/
protected void updateSecurityPanelEnabled ()
{
final boolean b = (rbSecurityNone.isSelected() == false);
txUserPassword.setEnabled(b);
txOwnerPassword.setEnabled(b);
txConfOwnerPassword.setEnabled(b);
txConfUserPassword.setEnabled(b);
cxAllowAssembly.setEnabled(b);
cxAllowCopy.setEnabled(b);
cbAllowPrinting.setEnabled(b);
cxAllowFillIn.setEnabled(b);
cxAllowModifyAnnotations.setEnabled(b);
cxAllowModifyContents.setEnabled(b);
cxAllowScreenReaders.setEnabled(b);
}
/**
* Initialisation.
*/
private void initConstructor()
{
setModal(true);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setTitle(getResources().getString("pdfsavedialog.dialogtitle"));
initialize();
clear();
addWindowListener(new WindowAdapter()
{
public void windowClosing(final WindowEvent e)
{
getActionCancel().actionPerformed(null);
}
}
);
}
/**
* Gets and initializes the the combobox model for the security setting "allowPrinting".
*
* @return the combobox model containing the different values for the allowPrinting option.
*/
private DefaultComboBoxModel getPrintingComboBoxModel()
{
if (printingModel == null)
{
final Object[] data = {
getResources().getString("pdfsavedialog.option.noprinting"),
getResources().getString("pdfsavedialog.option.degradedprinting"),
getResources().getString("pdfsavedialog.option.fullprinting")
};
printingModel = new DefaultComboBoxModel(data);
}
return printingModel;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -