This is an automated email from the git hooks/post-receive script. New commit to branch feature/7424 in repository faxtomail. See http://git.codelutin.com/faxtomail.git commit 37d8f5bc7e5faf3c28a89a03b4b29e5b7282dd14 Author: Kevin Morin <morin@codelutin.com> Date: Wed Aug 12 18:03:17 2015 +0200 Ajout des tampons dans l'éditeur de pdf (seulement type texte) (refs #7424) --- .../services/service/MailFolderService.java | 3 + .../services/service/MailFolderServiceImpl.java | 18 ++ .../ui/swing/actions/EditAttachmentAction.java | 23 +- .../actions/GenerateAnnotatedAttachmentAction.java | 318 +++++++++++++-------- .../content/pdfeditor/PDFEditorStampTextUI.css | 47 +++ .../content/pdfeditor/PDFEditorStampTextUI.jaxx | 74 +++++ .../ui/swing/content/pdfeditor/PDFEditorUI.jaxx | 2 +- .../content/pdfeditor/PDFEditorUIHandler.java | 125 ++++++-- .../swing/content/pdfeditor/PDFEditorUIModel.java | 49 +++- .../src/main/resources/icons/stamp.png | Bin 0 -> 588 bytes 10 files changed, 492 insertions(+), 167 deletions(-) diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java index 94d126c..fa4ac0d 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java @@ -28,6 +28,7 @@ import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; import com.franciaflex.faxtomail.persistence.entities.MailFilter; import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.FaxToMailService; @@ -66,4 +67,6 @@ public interface MailFolderService extends FaxToMailService { MailFolder getMailFolder(String topiaId); MailFilter findMailFilter(Email email, Set<String> modifiedProperties, List<Address> recipients); + + Collection<Stamp> getPdfEditorStamps(String mailFolderId); } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java index 847dc31..13c7b87 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderServiceImpl.java @@ -31,6 +31,7 @@ import com.franciaflex.faxtomail.persistence.entities.MailFilter; import com.franciaflex.faxtomail.persistence.entities.MailFilterTopiaDao; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.persistence.entities.WaitingState; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import org.apache.commons.collections4.CollectionUtils; @@ -353,5 +354,22 @@ public class MailFolderServiceImpl extends FaxToMailServiceSupport implements Ma return filter; } + @Override + public Collection<Stamp> getPdfEditorStamps(String mailFolderId) { + MailFolder folder = getMailFolder(mailFolderId); + while (folder != null && !folder.isUseCurrentLevelPdfEditorStamps()) { + folder = folder.getParent(); + } + Collection<Stamp> pdfEditorStamps; + if (folder != null) { + pdfEditorStamps = folder.getPdfEditorStamps(); + Hibernate.initialize(pdfEditorStamps); + + } else { + pdfEditorStamps = null; + } + + return pdfEditorStamps; + } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/EditAttachmentAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/EditAttachmentAction.java index 8df83b6..c969411 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/EditAttachmentAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/EditAttachmentAction.java @@ -25,6 +25,9 @@ package com.franciaflex.faxtomail.ui.swing.actions; */ import com.franciaflex.faxtomail.persistence.entities.Attachment; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import com.franciaflex.faxtomail.persistence.entities.Stamp; +import com.franciaflex.faxtomail.services.service.MailFolderService; import com.franciaflex.faxtomail.ui.swing.content.MainUI; import com.franciaflex.faxtomail.ui.swing.content.attachment.AttachmentEditorUI; import com.franciaflex.faxtomail.ui.swing.content.attachment.AttachmentEditorUIHandler; @@ -36,6 +39,7 @@ import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.util.Collection; import static org.nuiton.i18n.I18n.t; @@ -46,7 +50,7 @@ import static org.nuiton.i18n.I18n.t; public class EditAttachmentAction extends AbstractFaxToMailAction<AttachmentEditorUIModel, AttachmentEditorUI, AttachmentEditorUIHandler> { protected Attachment attachment; - protected PDFEditorUI dialogContent; + protected Collection<Stamp> stamps; protected JFrame frame; public EditAttachmentAction(AttachmentEditorUIHandler handler, Attachment attachment) { @@ -59,18 +63,22 @@ public class EditAttachmentAction extends AbstractFaxToMailAction<AttachmentEdit @Override public void doAction() throws Exception { getModel().fireAttachmentOpened(attachment, false); - FaxToMailUIUtil.forceAttachmentFileLoading(getContext(), attachment); - - dialogContent = new PDFEditorUI(getUI()); - PDFEditorUIModel pdfEditorUIModel = dialogContent.getModel(); - pdfEditorUIModel.fromEntity(attachment); - pdfEditorUIModel.setDemand(getContext().getCurrentEmail()); + MailFolder mailFolder = attachment.getEmail().getMailFolder(); + MailFolderService mailFolderService = getContext().newServiceContext().getMailFolderService(); + stamps = mailFolderService.getPdfEditorStamps(mailFolder.getTopiaId()); } @Override public void postSuccessAction() { super.postSuccessAction(); + + final PDFEditorUI dialogContent = new PDFEditorUI(getUI()); + PDFEditorUIModel pdfEditorUIModel = dialogContent.getModel(); + pdfEditorUIModel.fromEntity(attachment); + pdfEditorUIModel.setDemand(getContext().getCurrentEmail()); + pdfEditorUIModel.setStamps(stamps); + MainUI mainUI = getContext().getMainUI(); frame = getHandler().openFrame(dialogContent, attachment.getOriginalFileName(), mainUI.getSize()); @@ -94,5 +102,6 @@ public class EditAttachmentAction extends AbstractFaxToMailAction<AttachmentEdit } } }); + stamps = null; } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java index a8f4279..92188eb 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java @@ -31,6 +31,7 @@ import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorCrossUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorHighlighterUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorLineUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorNoteUI; +import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorStampTextUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIHandler; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIModel; @@ -56,6 +57,7 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import static org.nuiton.i18n.I18n.t; @@ -95,156 +97,232 @@ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<P float zoom = model.getZoom(); int rotation = model.getRotation(); + for (int i = 1 ; i <= pageNb ; i++) { + PdfContentByte cb = pdfStamper.getOverContent(i); - for (int i = 0 ; i < pageNb ; i++) { - PdfContentByte cb = pdfStamper.getOverContent(i + 1); + PDFEditorUIModel.Page page = model.getPage(i); - for (PDFEditorNoteUI note : model.getPages()[i].getNotes()) { + for (PDFEditorNoteUI note : page.getNotes()) { + addNoteToPdf(zoom, rotation, cb, note); + } - int[] coordinates = computeCoordinates(note, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + for (PDFEditorCrossUI panel : page.getCrosses()) { + addCrossToPdf(zoom, rotation, cb, panel); + } - Insets insets = note.getInsets(); + for (PDFEditorLineUI panel : page.getLines()) { + addLineToPdf(zoom, rotation, cb, panel); + } - cb.saveState(); - cb.setColorFill(BaseColor.YELLOW); - cb.rectangle(x, y, width, height); - cb.fill(); - cb.restoreState(); + for (PDFEditorHighlighterUI panel : page.getHighlighters()) { + addHighlightToPdf(zoom, rotation, cb, panel); + } - cb.saveState(); - JTextArea textArea = note.getNoteText(); - float fontSize = textArea.getFont().getSize2D() / zoom; - BaseFont titleFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); - BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); + for (PDFEditorStampTextUI panel : page.getStamps()) { + addStampToPdf(zoom, rotation, cb, panel); + } + } - String text = note.getText(); - String[] rows = text.split("\n"); - int rowHeight = (int) ((textArea.getHeight() / rows.length) / zoom); + pdfStamper.close(); + pdfReader.close(); + + // convert content to blob + InputStream is = new BufferedInputStream(new FileInputStream(target)); + FaxToMailServiceContext serviceContext = getContext().newServiceContext(); + AttachmentFile attachmentFileNew = serviceContext.getEmailService().getAttachmentFileFromStream(is); + attachmentFileNew.setRotation(rotation); + String fileName = model.getOriginalFile().getFilename(); + attachmentFileNew.setFilename(FaxToMailUIUtil.getEditedFileName(fileName)); + model.setEditedFile(attachmentFileNew); + } - int xxx = x; - int yyy = y; - if (rotation == 0) { - xxx += insets.left; - yyy += height - rowHeight - insets.top / zoom; + protected void addHighlightToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorHighlighterUI panel) { + int[] coordinates = computeCoordinates(panel, rotation, zoom); + int width = coordinates[0]; + int height = coordinates[1]; + int x = coordinates[2]; + int y = coordinates[3]; + + cb.saveState(); + PdfGState gs1 = new PdfGState(); + gs1.setFillOpacity(0.4f); + cb.setGState(gs1); + + cb.setColorFill(BaseColor.YELLOW); + cb.rectangle(x, y, width, height); + cb.fill(); + cb.restoreState(); + } - } else if (rotation == 90) { - xxx += rowHeight + insets.top / zoom; - yyy += insets.left; + protected void addLineToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorLineUI panel) { + int[] coordinates = computeCoordinates(panel, rotation, zoom); + int width = coordinates[0]; + int height = coordinates[1]; + int x = coordinates[2]; + int y = coordinates[3]; - } else if (rotation == 180) { - xxx += width - insets.right / zoom; - yyy += rowHeight - insets.top / zoom; + if (rotation % 180 == 0 ^ !panel.isHorizontal()) { + y += height / 2; + } else { + x += width / 2; + } - } else if (rotation == 270) { - xxx += width - rowHeight - insets.left / zoom; - yyy += height - insets.top / zoom; - } + cb.saveState(); + cb.setColorStroke(BaseColor.BLUE); + cb.moveTo(x, y); + if (rotation % 180 == 0 ^ !panel.isHorizontal()) { + cb.lineTo(x + width, y); + } else { + cb.lineTo(x, y + height); + } + cb.stroke(); + cb.restoreState(); + } - showTextAligned(cb, note.getTitle(), xxx, yyy, rotation, titleFont, fontSize); + protected void addCrossToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorCrossUI panel) { + int[] coordinates = computeCoordinates(panel, rotation, zoom); + int width = coordinates[0]; + int height = coordinates[1]; + int x = coordinates[2]; + int y = coordinates[3]; + + cb.saveState(); + cb.setColorStroke(BaseColor.BLUE); + cb.moveTo(x, y); + cb.lineTo(x + width, y + height); + cb.stroke(); + cb.moveTo(x + width, y); + cb.lineTo(x, y + height); + cb.stroke(); + cb.restoreState(); + } - for (String s : rows) { - if (s.isEmpty()) { - s = " "; - } - if (rotation == 0) { - yyy -= rowHeight; + protected void addNoteToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorNoteUI note) throws DocumentException, IOException { + int[] coordinates = computeCoordinates(note, rotation, zoom); + int width = coordinates[0]; + int height = coordinates[1]; + int x = coordinates[2]; + int y = coordinates[3]; + + Insets insets = note.getInsets(); + + cb.saveState(); + cb.setColorFill(BaseColor.YELLOW); + cb.rectangle(x, y, width, height); + cb.fill(); + cb.restoreState(); + + cb.saveState(); + JTextArea textArea = note.getNoteText(); + float fontSize = textArea.getFont().getSize2D() / zoom; + BaseFont titleFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); + BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); + + String text = note.getText(); + String[] rows = text.split("\n"); + int rowHeight = (int) ((textArea.getHeight() / rows.length) / zoom); + + int xxx = x; + int yyy = y; + if (rotation == 0) { + xxx += insets.left; + yyy += height - rowHeight - insets.top / zoom; - } else if (rotation == 90) { - xxx += rowHeight; + } else if (rotation == 90) { + xxx += rowHeight + insets.top / zoom; + yyy += insets.left; - } else if (rotation == 180) { - yyy += rowHeight; + } else if (rotation == 180) { + xxx += width - insets.right / zoom; + yyy += rowHeight - insets.top / zoom; - } else if (rotation == 270) { - xxx -= rowHeight; - } - showTextAligned(cb, s, xxx, yyy, rotation, font, fontSize); - } + } else if (rotation == 270) { + xxx += width - rowHeight - insets.left / zoom; + yyy += height - insets.top / zoom; + } - cb.restoreState(); + showTextAligned(cb, note.getTitle(), xxx, yyy, rotation, titleFont, fontSize); + for (String s : rows) { + if (s.isEmpty()) { + s = " "; } + if (rotation == 0) { + yyy -= rowHeight; - for (PDFEditorCrossUI panel : model.getPages()[i].getCrosses()) { - - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; - - cb.saveState(); - cb.setColorStroke(BaseColor.BLUE); - cb.moveTo(x, y); - cb.lineTo(x + width, y + height); - cb.stroke(); - cb.moveTo(x + width, y); - cb.lineTo(x, y + height); - cb.stroke(); - cb.restoreState(); + } else if (rotation == 90) { + xxx += rowHeight; + + } else if (rotation == 180) { + yyy += rowHeight; + + } else if (rotation == 270) { + xxx -= rowHeight; } + showTextAligned(cb, s, xxx, yyy, rotation, font, fontSize); + } + + cb.restoreState(); + } + + protected void addStampToPdf(float zoom, int rotation, PdfContentByte cb, PDFEditorStampTextUI stamp) throws DocumentException, IOException { + int[] coordinates = computeCoordinates(stamp, rotation, zoom); + int width = coordinates[0]; + int height = coordinates[1]; + int x = coordinates[2]; + int y = coordinates[3]; + + Insets insets = stamp.getInsets(); + + cb.saveState(); + JLabel label = stamp.getStampText(); + float fontSize = label.getFont().getSize2D() / zoom; + BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); + + String text = stamp.getText(); + String[] rows = text.split("\n"); + int rowHeight = (int) ((stamp.getHeight() / rows.length) / zoom); + + int xxx = x; + int yyy = y; + if (rotation == 0) { + xxx += insets.left; + yyy += height - rowHeight - insets.top / zoom; + + } else if (rotation == 90) { + xxx += rowHeight + insets.top / zoom; + yyy += insets.left; + + } else if (rotation == 180) { + xxx += width - insets.right / zoom; + yyy += rowHeight - insets.top / zoom; - for (PDFEditorLineUI panel : model.getPages()[i].getLines()) { - - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; - - if (rotation % 180 == 0 ^ !panel.isHorizontal()) { - y += height / 2; - } else { - x += width / 2; - } - - cb.saveState(); - cb.setColorStroke(BaseColor.BLUE); - cb.moveTo(x, y); - if (rotation % 180 == 0 ^ !panel.isHorizontal()) { - cb.lineTo(x + width, y); - } else { - cb.lineTo(x, y + height); - } - cb.stroke(); - cb.restoreState(); + } else if (rotation == 270) { + xxx += width - rowHeight - insets.left / zoom; + yyy += height - insets.top / zoom; + } + + for (String s : rows) { + if (s.isEmpty()) { + s = " "; } + showTextAligned(cb, s, xxx, yyy, rotation, font, fontSize); - for (PDFEditorHighlighterUI panel : model.getPages()[i].getHighlighters()) { + if (rotation == 0) { + yyy -= rowHeight; - int[] coordinates = computeCoordinates(panel, rotation, zoom); - int width = coordinates[0]; - int height = coordinates[1]; - int x = coordinates[2]; - int y = coordinates[3]; + } else if (rotation == 90) { + xxx += rowHeight; - cb.saveState(); - PdfGState gs1 = new PdfGState(); - gs1.setFillOpacity(0.4f); - cb.setGState(gs1); + } else if (rotation == 180) { + yyy += rowHeight; - cb.setColorFill(BaseColor.YELLOW); - cb.rectangle(x, y, width, height); - cb.fill(); - cb.restoreState(); + } else if (rotation == 270) { + xxx -= rowHeight; } } - pdfStamper.close(); - pdfReader.close(); - - // convert content to blob - InputStream is = new BufferedInputStream(new FileInputStream(target)); - FaxToMailServiceContext serviceContext = getContext().newServiceContext(); - AttachmentFile attachmentFileNew = serviceContext.getEmailService().getAttachmentFileFromStream(is); - attachmentFileNew.setRotation(rotation); - String fileName = model.getOriginalFile().getFilename(); - attachmentFileNew.setFilename(FaxToMailUIUtil.getEditedFileName(fileName)); - model.setEditedFile(attachmentFileNew); + cb.restoreState(); } protected int[] computeCoordinates(Component panel, int rotation, float zoom) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.css b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.css new file mode 100644 index 0000000..6a98d85 --- /dev/null +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.css @@ -0,0 +1,47 @@ +/* + * #%L + * FaxToMail :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2014 Mac-Groupe, Code Lutin + * %% + * 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 3 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 o + * 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +Component { + opaque: false; + background: { null }; + +} + +#stampPanel { + border : { BorderFactory.createEmptyBorder(2, 2, 2, 2) }; +} + +#removeButton { + text: " X "; + border : { BorderFactory.createLineBorder(Color.BLACK, 1, false) }; + contentAreaFilled: false; + focusPainted: false; +} + +#stampText { + text: { "<html>" + getText().replaceAll("[\n\r]", "<br/>") + "</html>"}; + border: { null }; + font: { Font.decode(BaseFont.HELVETICA) }; + font-size: { (float)(DEFAULT_FONT_SIZE * getZoom()) }; +} diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.jaxx b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.jaxx new file mode 100644 index 0000000..297e52e --- /dev/null +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorStampTextUI.jaxx @@ -0,0 +1,74 @@ +<!-- + #%L + FaxToMail :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2014 Mac-Groupe, Code Lutin + %% + 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 3 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, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JPanel id='stampPanel' layout='{new BorderLayout()}' onComponentResized="pack()"> + + <import> + java.awt.Color + java.awt.Dimension + java.awt.Font + java.awt.Insets + java.awt.Point + javax.swing.BorderFactory + javax.swing.JPanel + com.itextpdf.text.pdf.BaseFont + com.franciaflex.faxtomail.ui.swing.util.JImagePanel + </import> + + <script><![CDATA[ + + public static final int DEFAULT_FONT_SIZE = 12; + + protected void pack() { + JPanel container = getParentContainer(JPanel.class); + Point location = getLocation(); + Insets containerInsets = container.getInsets(); + Dimension size = getPreferredSize(); + setBounds(location.x + containerInsets.left, + location.y + containerInsets.top, + size.width, // no real logical reason for 10, but otherwise, the text is sometimes cut in the end + size.height); + } + + protected void removeStamp() { + JPanel container = getParentContainer(JPanel.class); + container.remove(this); + container.updateUI(); + } + + ]]></script> + + <String id="text" javaBean=""/> + <Float id="zoom" javaBean="1.0f"/> + + <JPanel layout='{ new BorderLayout() }' + constraints="BorderLayout.EAST"> + <JButton id="removeButton" + constraints="BorderLayout.NORTH" + onActionPerformed="removeStamp()"/> + </JPanel> + + <JLabel id="stampText" + constraints="BorderLayout.CENTER"/> + +</JPanel> diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx index d6c71f0..156d8d6 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx @@ -60,7 +60,7 @@ <JToggleButton id='highlighterButton' buttonGroup="actionGroup" value="HIGHLIGHTER"/> <!--onActionPerformed="handler.addHighlighter()"/>--> - <JSeparator constructorParams="SwingConstants.VERTICAL"/> + <JSeparator id="actionGroupSeparator" constructorParams="SwingConstants.VERTICAL"/> <JButton id="prevPageButton" onActionPerformed="getModel().decPageIndex()"/> diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java index 55710af..0fd74c3 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java @@ -28,9 +28,12 @@ import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.HistoryType; +import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.services.FaxToMailServiceContext; import com.franciaflex.faxtomail.ui.swing.actions.GenerateAnnotatedAttachmentAction; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; +import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIModel.EditionComponent; +import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIModel.Page; import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailUIHandler; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import com.franciaflex.faxtomail.ui.swing.util.JImagePanel; @@ -38,6 +41,7 @@ import com.itextpdf.text.DocumentException; import jaxx.runtime.swing.ComponentMover; import jaxx.runtime.swing.ComponentResizer; import jaxx.runtime.swing.JAXXButtonGroup; +import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -58,6 +62,7 @@ import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -89,8 +94,16 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo actionGroup.addPropertyChangeListener(JAXXButtonGroup.SELECTED_VALUE_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - String value = (String) evt.getNewValue(); - model.setSelectedComponent(PDFEditorUIModel.EditionComponent.valueOf(value)); + Object newValue = evt.getNewValue(); + Object selectedComponent; + if (newValue instanceof String) { + String value = (String) newValue; + selectedComponent = PDFEditorUIModel.EditionComponent.valueOf(value); + + } else { + selectedComponent = newValue; + } + model.setSelectedComponent(selectedComponent); } }); @@ -101,36 +114,44 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo @Override public void componentAdded(ContainerEvent e) { Component child = e.getChild(); - PDFEditorUIModel.Page currentPage = model.getCurrentPage(); - if (child.getClass().isAssignableFrom(PDFEditorNoteUI.class)) { + Page currentPage = model.getCurrentPage(); + Class<? extends Component> childClass = child.getClass(); + if (childClass.isAssignableFrom(PDFEditorNoteUI.class)) { currentPage.addNote((PDFEditorNoteUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorCrossUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorCrossUI.class)) { currentPage.addCross((PDFEditorCrossUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorLineUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorLineUI.class)) { currentPage.addLine((PDFEditorLineUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorHighlighterUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorHighlighterUI.class)) { currentPage.addHighlighter((PDFEditorHighlighterUI) child); + + } else if (childClass.isAssignableFrom(PDFEditorStampTextUI.class)) { + currentPage.addStamp((PDFEditorStampTextUI) child); } } @Override public void componentRemoved(ContainerEvent e) { Component child = e.getChild(); - PDFEditorUIModel.Page currentPage = model.getCurrentPage(); - if (child.getClass().isAssignableFrom(PDFEditorNoteUI.class)) { + Page currentPage = model.getCurrentPage(); + Class<? extends Component> childClass = child.getClass(); + if (childClass.isAssignableFrom(PDFEditorNoteUI.class)) { currentPage.removeNote((PDFEditorNoteUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorCrossUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorCrossUI.class)) { currentPage.removeCross((PDFEditorCrossUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorLineUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorLineUI.class)) { currentPage.removeLine((PDFEditorLineUI) child); - } else if (child.getClass().isAssignableFrom(PDFEditorHighlighterUI.class)) { + } else if (childClass.isAssignableFrom(PDFEditorHighlighterUI.class)) { currentPage.removeHighlighter((PDFEditorHighlighterUI) child); + + } else if (childClass.isAssignableFrom(PDFEditorStampTextUI.class)) { + currentPage.removeStamp((PDFEditorStampTextUI) child); } } }); @@ -216,6 +237,14 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo (Integer) evt.getOldValue()); } }); + + model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_STAMPS, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + Collection<Stamp> stamps = (Collection<Stamp>) evt.getNewValue(); + updateStamps(stamps); + } + }); } @Override @@ -251,23 +280,32 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo } public void addEditionComponent(MouseEvent event) { - PDFEditorUIModel.EditionComponent editionComponent = getModel().getSelectedComponent(); - switch (editionComponent) { - case NOTE: - addNote(event.getX(), event.getY()); - break; - case CROSS: - addCross(event.getX(), event.getY()); - break; - case HLINE: - addHLine(event.getX(), event.getY()); - break; - case VLINE: - addVLine(event.getX(), event.getY()); - break; - case HIGHLIGHTER: - addHighlighter(event.getX(), event.getY()); - break; + Object selectedComponent = getModel().getSelectedComponent(); + + int x = event.getX(); + int y = event.getY(); + if (selectedComponent instanceof PDFEditorUIModel.EditionComponent) { + EditionComponent editionComponent = (EditionComponent) selectedComponent; + switch (editionComponent) { + case NOTE: + addNote(x, y); + break; + case CROSS: + addCross(x, y); + break; + case HLINE: + addHLine(x, y); + break; + case VLINE: + addVLine(x, y); + break; + case HIGHLIGHTER: + addHighlighter(x, y); + break; + } + + } else if (selectedComponent instanceof Stamp) { + addStamp((Stamp) selectedComponent, x, y); } } @@ -305,6 +343,13 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo cr.registerComponent(highlighter); } + public void addStamp(Stamp stamp, int x, int y) { + PDFEditorStampTextUI stampUI = new PDFEditorStampTextUI(); + stampUI.setText(stamp.getText()); + stampUI.setZoom(getModel().getZoom()); + addPanel(stampUI, x, y); + } + protected void addPanel(JPanel panel, int x, int y) { JPanel container = ui.getContainer(); container.add(panel, 0); @@ -322,7 +367,7 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo protected void updatePageNumber(Integer pageNb, Integer prevPageNb) { if (pageNb != null) { if (prevPageNb != null) { - PDFEditorUIModel.Page p = getModel().getPage(prevPageNb); + Page p = getModel().getPage(prevPageNb); for (JPanel panel : p.getNotes()) { panel.setVisible(false); } @@ -375,7 +420,7 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo float zoomRatio = zoom / previousZoom; int rotationDiff = rotation - previousRotation; - PDFEditorUIModel.Page p = getModel().getPage(pageNb); + Page p = getModel().getPage(pageNb); for (PDFEditorNoteUI panel : p.getNotes()) { panel.setVisible(true); @@ -510,6 +555,24 @@ public class PDFEditorUIHandler extends AbstractFaxToMailUIHandler<PDFEditorUIMo } } + protected void updateStamps(Collection<Stamp> stamps) { + PDFEditorUI ui = getUI(); + JAXXButtonGroup actionGroup = ui.getActionGroup(); + Icon stampIcon = JAXXWidgetUtil.createImageIcon("stamp.png"); + JToolBar toolbar = ui.getToolbar(); + + int i = toolbar.getComponentIndex(ui.getActionGroupSeparator()); + + for (Stamp stamp : stamps) { + JToggleButton button = new JToggleButton(stamp.getLabel(), stampIcon); + button.putClientProperty("$value", stamp); + + actionGroup.add(button); + + toolbar.add(button, i++); + } + } + public File convertFileToPdf(AttachmentFile attachmentFile) throws IOException, DocumentException { File target = FaxToMailUIUtil.convertFileToPdf(attachmentFile); // convert content to blob diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java index 8a4ff95..2a2ca5f 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java @@ -27,12 +27,15 @@ package com.franciaflex.faxtomail.ui.swing.content.pdfeditor; import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; import com.franciaflex.faxtomail.persistence.entities.AttachmentImpl; +import com.franciaflex.faxtomail.persistence.entities.Stamp; import com.franciaflex.faxtomail.ui.swing.content.demande.DemandeUIModel; import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailBeanUIModel; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; /** @@ -45,23 +48,27 @@ public class PDFEditorUIModel extends AbstractFaxToMailBeanUIModel<Attachment, P public static final String PROPERTY_CURRENT_PAGE_INDEX = "currentPageIndex"; public static final String PROPERTY_ZOOM = "zoom"; public static final String PROPERTY_ROTATION = "rotation"; + public static final String PROPERTY_STAMPS = "stamps"; protected final Attachment editObject = new AttachmentImpl(); protected DemandeUIModel demand; - protected EditionComponent selectedComponent; + protected Collection<Stamp> stamps = new HashSet<>(); - public static enum EditionComponent { + protected Object selectedComponent; + + public enum EditionComponent { NOTE, CROSS, HLINE, VLINE, HIGHLIGHTER } public class Page { - protected List<PDFEditorNoteUI> notes = new ArrayList<PDFEditorNoteUI>(); - protected List<PDFEditorCrossUI> crosses = new ArrayList<PDFEditorCrossUI>(); - protected List<PDFEditorLineUI> lines = new ArrayList<PDFEditorLineUI>(); - protected List<PDFEditorHighlighterUI> highlighters = new ArrayList<PDFEditorHighlighterUI>(); + protected List<PDFEditorNoteUI> notes = new ArrayList<>(); + protected List<PDFEditorCrossUI> crosses = new ArrayList<>(); + protected List<PDFEditorLineUI> lines = new ArrayList<>(); + protected List<PDFEditorHighlighterUI> highlighters = new ArrayList<>(); + protected List<PDFEditorStampTextUI> stamps = new ArrayList<>(); public List<PDFEditorNoteUI> getNotes() { return notes; @@ -118,6 +125,20 @@ public class PDFEditorUIModel extends AbstractFaxToMailBeanUIModel<Attachment, P highlighters.remove(highlighter); setModify(true); } + + public List<PDFEditorStampTextUI> getStamps() { + return stamps; + } + + public void addStamp(PDFEditorStampTextUI stamp) { + stamps.add(stamp); + setModify(true); + } + + public void removeStamp(PDFEditorStampTextUI stamp) { + stamps.remove(stamp); + setModify(true); + } } protected Page[] pages; @@ -257,11 +278,23 @@ public class PDFEditorUIModel extends AbstractFaxToMailBeanUIModel<Attachment, P this.demand = demand; } - public EditionComponent getSelectedComponent() { + public Collection<Stamp> getStamps() { + return stamps; + } + + public void setStamps(Collection<Stamp> stamps) { + this.stamps.clear(); + if (stamps != null) { + this.stamps.addAll(stamps); + } + firePropertyChange(PROPERTY_STAMPS, null, this.stamps); + } + + public Object getSelectedComponent() { return selectedComponent; } - public void setSelectedComponent(EditionComponent selectedComponent) { + public void setSelectedComponent(Object selectedComponent) { this.selectedComponent = selectedComponent; } diff --git a/faxtomail-ui-swing/src/main/resources/icons/stamp.png b/faxtomail-ui-swing/src/main/resources/icons/stamp.png new file mode 100644 index 0000000..71f59d1 Binary files /dev/null and b/faxtomail-ui-swing/src/main/resources/icons/stamp.png differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.