📄 senddialog.java
字号:
/** * JHylaFax - A java client for HylaFAX. * * Copyright (C) 2005 by Steffen Pingel <steffenp@gmx.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package net.sf.jhylafax;import static net.sf.jhylafax.JHylaFAX.i18n;import gnu.hylafax.HylaFAXClient;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedInputStream;import java.io.ByteArrayInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.Iterator;import java.util.List;import javax.swing.Action;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import net.sf.jhylafax.fax.FaxCover;import net.sf.jhylafax.fax.FaxJob;import net.sf.jhylafax.fax.HylaFAXClientHelper;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.xnap.commons.gui.Builder;import org.xnap.commons.gui.Dialogs;import org.xnap.commons.gui.ErrorDialog;import org.xnap.commons.gui.FileChooserPanel;import org.xnap.commons.gui.action.AbstractXNapAction;import org.xnap.commons.io.Job;import org.xnap.commons.io.ProgressMonitor;import org.xnap.commons.io.SubTaskProgressMonitor;import org.xnap.commons.io.UserAbortException;import com.jgoodies.forms.builder.DefaultFormBuilder;import com.jgoodies.forms.layout.CellConstraints;import com.jgoodies.forms.layout.FormLayout;/** * A dialog for sending faxes. * * @author Steffen Pingel */public class SendDialog extends AbstractFaxDialog { private final static Log logger = LogFactory.getLog(AbstractQueuePanel.class); private JLabel documentLabel; private JPanel coverPanel; private JTextField coverSenderTextField; private JLabel coverSenderLabel; private JTextField coverRecepientTextField; private JLabel coverRecepientLabel; private JTextField coverSubjectTextField; private JLabel coverSubjectLabel; private JTextArea coverCommentTextArea; private JLabel coverCommentLabel; private JPanel documentPanel; private DefaultFormBuilder documentPanelBuilder; private List<FileChooserPanel> documentFileChooserPanels; private JCheckBox includeCoverCheckBox; private JLabel includeCoverLabel; private JScrollPane coverCommentScrollPane; private PreviewCoverAction previewCoverAction; private MoreDocumentsAction moreDocumentsAction; private boolean quitAfterSending; public SendDialog(JFrame owner) { super(owner); moreDocumentsAction = new MoreDocumentsAction(); previewCoverAction = new PreviewCoverAction(); addNumberTextField(); addDocumentsPanel(); builder.append("", Builder.createButton(moreDocumentsAction)); builder.nextLine(); addDateControls(); includeCoverCheckBox = new JCheckBox(); includeCoverLabel = builder.append("", includeCoverCheckBox); builder.nextLine(); initializeCoverPanel(); coverPanel.setVisible(false); previewCoverAction.setEnabled(false); includeCoverCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { coverPanel.setVisible(includeCoverCheckBox.isSelected()); previewCoverAction.setEnabled(includeCoverCheckBox.isSelected()); pack(); } }); getButtonPanel().add(Builder.createButton(previewCoverAction), 0); FaxJob job = new FaxJob(); HylaFAXClientHelper.initializeFromSettings(job); setJob(job); updateLabels(); pack(); } private void addDocumentsPanel() { documentFileChooserPanels = new ArrayList<FileChooserPanel>(); FormLayout layout = new FormLayout("left:max(40dlu;pref), 3dlu, pref:grow", ""); documentPanelBuilder = new DefaultFormBuilder(layout); FileChooserPanel documentFileChooserPanel = new MyFileChooserPanel(DEFAULT_COLUMNS); documentFileChooserPanel.getFileChooser().setMultiSelectionEnabled(true); documentFileChooserPanels.add(documentFileChooserPanel); documentLabel = documentPanelBuilder.append("", documentFileChooserPanel); this.builder.appendRow(builder.getLineGapSpec()); this.builder.nextLine(); this.builder.appendRow("fill:pref:grow"); this.builder.append(documentPanelBuilder.getPanel(), 6); builder.nextLine(); } private void initializeCoverPanel() { FormLayout layout = new FormLayout("left:max(40dlu;pref), 3dlu, pref:grow", ""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); coverPanel = builder.getPanel(); this.builder.appendRow(builder.getLineGapSpec()); this.builder.nextLine(); this.builder.appendRow("fill:pref:grow"); this.builder.append(coverPanel, 6); coverSenderTextField = new JTextField(DEFAULT_COLUMNS); coverSenderTextField.setText(Settings.FULLNAME.getValue()); coverSenderLabel = builder.append("", coverSenderTextField); builder.nextLine(); coverRecepientTextField = new JTextField(DEFAULT_COLUMNS); coverRecepientLabel = builder.append("", coverRecepientTextField); builder.nextLine(); coverSubjectTextField = new JTextField(DEFAULT_COLUMNS); coverSubjectLabel = builder.append("", coverSubjectTextField); builder.nextLine(); coverCommentTextArea= new JTextArea(3, DEFAULT_COLUMNS); coverCommentLabel = builder.append(""); builder.appendRow("fill:pref:grow"); // second row for text area CellConstraints cc = new CellConstraints(); coverCommentScrollPane = new JScrollPane(coverCommentTextArea); builder.add(coverCommentScrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 1, 2)); builder.nextLine(2); } @Override public boolean apply() { if (!super.apply()) { return false; } if (!includeCoverCheckBox.isSelected()) { boolean filenameProvided = false; for (FileChooserPanel documentFileChooserPanel : documentFileChooserPanels) { if (documentFileChooserPanel.getTextField().getText().trim().length() != 0) { filenameProvided = true; if (Settings.CONFIRM_NONPS.getValue()) { if (!checkPostScript(documentFileChooserPanel.getTextField().getText())) { documentFileChooserPanel.getTextField().requestFocus(); return false; } } } } if (!filenameProvided) { Dialogs.showError(this, i18n.tr("You must at least send a document or a cover"), i18n.tr("JHylaFAX Error")); documentFileChooserPanels.get(0).getTextField().requestFocus(); return false; } } Fax fax = createFax(); if (fax != null) { if (send(fax)) { if (quitAfterSending) { JHylaFAX.getInstance().exit(); } return true; } } return false; } private boolean checkPostScript(String filename) { try { if (!HylaFAXClientHelper.isPostscript(filename)) { if (Dialogs.showConfirmDialog(this, i18n.tr("Do you really want to send the non PostScript file \"{0}\"?", filename), i18n.tr("JHylaFAX - Send non PostScript file"), JOptionPane.YES_NO_OPTION, Settings.CONFIRM_NONPS) == JOptionPane.NO_OPTION) { return false; } } } catch (IOException e) { logger.debug("Error checking for PostScript", e); ErrorDialog.showError(this, i18n.tr("Could not check for PostScript"), i18n.tr("JHylaFAX Error"), e); return false; } return true; } private Fax createFax() { Fax fax = new Fax(); for (FileChooserPanel documentFileChooserPanel : documentFileChooserPanels) { String filename = documentFileChooserPanel.getTextField().getText(); if (filename.trim().length() > 0) { File file = new File(filename); fax.documents.add(file); } } if (includeCoverCheckBox.isSelected() && !createFaxCover(fax)) { return null; } return fax; } private boolean createFaxCover(Fax fax) { if (fax == null) { throw new IllegalArgumentException("value may not be null"); } String filename; if (Settings.USE_INTERNAL_COVER.getValue()) { filename = "faxcover.ps"; fax.coverIn = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); } else { filename = Settings.COVER_PATH.getValue(); try { fax.coverIn = new FileInputStream(filename); } catch (FileNotFoundException e) { fax.coverIn = null; } } if (fax.coverIn == null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -