📄 senddialog.java
字号:
Dialogs.showError(this, i18n.tr("Could not read cover file: {0}", filename), i18n.tr("JHylaFAX Error")); return false; } fax.cover = new FaxCover(Settings.PAPER.getValue()); fax.cover.from = coverSenderTextField.getText(); fax.cover.to = coverRecepientTextField.getText(); fax.cover.regarding = coverSubjectTextField.getText(); fax.cover.comments = coverCommentTextArea.getText(); fax.cover.todays_date = SimpleDateFormat.getDateTimeInstance().format(new Date()); for (Iterator<File> it = fax.documents.iterator(); it.hasNext();) { fax.cover.addDocument(it.next().getAbsolutePath()); } return true; } private boolean send(final Fax fax) { Job<?> ioJob = new Job() { public Object run(ProgressMonitor monitor) throws Exception { monitor.setTotalSteps(13 + fax.documents.size() * 10); HylaFAXClient client = JHylaFAX.getInstance().getConnection(monitor); monitor.work(1); client.mode(HylaFAXClient.MODE_STREAM); client.type(HylaFAXClient.TYPE_IMAGE); String serverCoverFilename = null; if (fax.cover != null && fax.coverIn != null) { monitor.setText(i18n.tr("Generating cover")); SubTaskProgressMonitor coverMonitor = new SubTaskProgressMonitor(monitor, 5, 0); StringBuffer data = fax.cover.generate(fax.coverIn, coverMonitor); coverMonitor.done(); // Cover senden byte[] buffer = data.toString().getBytes(FaxCover.CHARSET); TransferMonitor transferMonitor = new TransferMonitor(monitor, 5, buffer.length); client.addTransferListener(transferMonitor); InputStream in = new ByteArrayInputStream(buffer); try { serverCoverFilename = client.putTemporary(in); } finally { transferMonitor.transferCompleted(); client.removeTransferListener(transferMonitor); in.close(); } // check if monitor was cancelled monitor.work(0); } else { monitor.work(10); } monitor.setText(i18n.tr("Uploading documents")); List<String> serverFilenames = new ArrayList<String>(); for (File file : fax.documents) { TransferMonitor transferMonitor = new TransferMonitor(monitor, 10, file.length()); client.addTransferListener(transferMonitor); InputStream in = new BufferedInputStream(new FileInputStream(file)); try { serverFilenames.add(client.putTemporary(in)); } finally { transferMonitor.transferCompleted(); client.removeTransferListener(transferMonitor); in.close(); } // check if monitor was cancelled monitor.work(0); } gnu.hylafax.Job sendJob = client.createJob(); HylaFAXClientHelper.applyParameter(sendJob, getJob()); if (serverCoverFilename != null) { if (Settings.SEND_COVER_AS_DOCUMENT.getValue()) { sendJob.addDocument(serverCoverFilename); } else { sendJob.setProperty("COVER ", serverCoverFilename); } } for (String filename : serverFilenames) { sendJob.addDocument(filename); } monitor.work(1); client.submit(sendJob); monitor.work(1); return null; } }; try { JHylaFAX.getInstance().runJob(SendDialog.this, ioJob); JHylaFAX.getInstance().updateTables(); } catch (UserAbortException e) { return false; } catch (Exception e) { logger.debug("Error sending fax", e); ErrorDialog.showError(this, i18n.tr("Could not send fax"), i18n.tr("JHylaFAX Error"), e); return false; } return true; } private File saveCover(final Fax fax) { if (fax.cover == null || fax.coverIn == null) { throw new IllegalArgumentException("fax.cover and fax.coverIn must not be null"); } Job<File> ioJob = new Job<File>() { public File run(ProgressMonitor monitor) throws Exception { monitor.setTotalSteps(10); monitor.setText(i18n.tr("Generating cover")); SubTaskProgressMonitor coverMonitor = new SubTaskProgressMonitor(monitor, 5, 0); StringBuffer data = fax.cover.generate(fax.coverIn, coverMonitor); coverMonitor.done(); File outputFile = File.createTempFile("jhylafax", ".ps"); outputFile.deleteOnExit(); OutputStream out = new FileOutputStream(outputFile); monitor.setText(i18n.tr("Saving cover")); try { out.write(data.toString().getBytes(FaxCover.CHARSET)); } finally { out.close(); } monitor.work(5); return outputFile; } }; try { return JHylaFAX.getInstance().runJob(SendDialog.this, ioJob); } catch (UserAbortException e) { return null; } catch (Exception e) { logger.debug("Error previewing cover", e); ErrorDialog.showError(this, i18n.tr("Could not preview cover"), i18n.tr("JHylaFAX Error"), e); return null; } } public void updateLabels() { super.updateLabels(); setTitle(i18n.tr("Send Fax")); documentLabel.setText(i18n.tr("Document")); includeCoverLabel.setText(i18n.tr("Include Cover")); coverSenderLabel.setText(i18n.tr("Sender")); coverRecepientLabel.setText(i18n.tr("Recepient")); coverSubjectLabel.setText(i18n.tr("Subject")); coverCommentLabel.setText(i18n.tr("Comment")); previewCoverAction.updateLabels(); moreDocumentsAction.updateLabels(); } public void setDocument(String document) { documentFileChooserPanels.get(0).getTextField().setText(document); } /** * A container used for parameter passing. */ private class Fax { FaxCover cover; InputStream coverIn; List<File> documents = new ArrayList<File>(); } private class PreviewCoverAction extends AbstractXNapAction implements LocaleChangeListener{ public PreviewCoverAction() { //putValue(ICON_FILENAME, "configure.png"); } public void actionPerformed(ActionEvent event) { if (!includeCoverCheckBox.isSelected()) { throw new IllegalStateException("Cover page is not enabled"); } String viewerPath = JHylaFAXHelper.getViewerPath("docq"); if (viewerPath == null) { return; } Fax fax = createFax(); if (fax == null) { return; } File tempFile = saveCover(fax); if (tempFile != null) { JHylaFAXHelper.view(viewerPath, new File[] { tempFile }); } } public void updateLabels() { putValue(Action.NAME, i18n.tr("Preview Cover")); putValue(Action.SHORT_DESCRIPTION, i18n.tr("Opens an external programm to preview the cover page")); } } private class MoreDocumentsAction extends AbstractXNapAction implements LocaleChangeListener{ public MoreDocumentsAction() { } public void actionPerformed(ActionEvent event) { FileChooserPanel documentFileChooserPanel = addDocumentFileChooser(); documentFileChooserPanel.getTextField().requestFocus(); } public void updateLabels() { putValue(Action.NAME, i18n.tr("More")); putValue(Action.SHORT_DESCRIPTION, i18n.tr("Displays an additional field to enter a document filename")); } } private class MyFileChooserPanel extends FileChooserPanel { public MyFileChooserPanel(int columns) { super(columns); } @Override protected void fileSelected(File file) { File[] files = getFileChooser().getSelectedFiles(); if (files != null && files.length > 1) { // files[0] equals file and is handled by the panel for (int i = 1; i < files.length; i++) { // add a new panel for all other files FileChooserPanel chooser = addDocumentFileChooser(); chooser.setFile(files[i]); } } // reset selection getFileChooser().setSelectedFiles(null); } } protected FileChooserPanel addDocumentFileChooser() { FileChooserPanel documentFileChooserPanel = new MyFileChooserPanel(DEFAULT_COLUMNS); documentFileChooserPanel.setFileChooser(documentFileChooserPanels.get(0).getFileChooser()); documentFileChooserPanels.add(documentFileChooserPanel); documentPanelBuilder.append("", documentFileChooserPanel); documentPanelBuilder.nextLine(); pack(); return documentFileChooserPanel; } public void addDocument(String filename) { FileChooserPanel panel = addDocumentFileChooser(); panel.getTextField().setText(filename); } public void setQuitAfterSending(boolean quitAfterSending) { this.quitAfterSending = quitAfterSending; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -