Author: kmorin Date: 2014-05-16 16:46:47 +0200 (Fri, 16 May 2014) New Revision: 79 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/79 Log: - add error messages - set some fields not editable according to the status - validation of the reply form - pdf rotation - fix bug of the app which does not close of a popup is open Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.jaxx trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.jaxx trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorNoteUI.jaxx trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/JImagePanel.java trunk/faxtomail-ui-swing/src/main/resources/i18n/faxtomail-ui-swing_fr_FR.properties Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-05-16 14:46:47 UTC (rev 79) @@ -45,6 +45,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.EmailConstants; +import org.apache.commons.mail.EmailException; import org.apache.commons.mail.MultiPartEmail; import com.franciaflex.faxtomail.persistence.entities.Attachment; @@ -72,6 +73,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import javax.mail.MessagingException; + import static org.nuiton.i18n.I18n.t; /** @@ -149,9 +152,9 @@ Set<String> fieldSet = Sets.newHashSet(modifiedFields); if (email.getDemandStatus() == DemandStatus.UNTREATED - && fieldSet.containsAll(Sets.newHashSet(Email.PROPERTY_CLIENT, - Email.PROPERTY_DEMAND_TYPE, - Email.PROPERTY_PROJECT_REFERENCE))) { + && email.getClient() != null + && email.getDemandType() != null + && email.getProjectReference() != null) { email.setDemandStatus(DemandStatus.IN_PROGRESS); transmitDemandToEdi(email); } @@ -409,75 +412,68 @@ public Email reply(String from, String to, String subject, String content, Collection<File> attachments, - String originalEmailId, FaxToMailUser user) { + String originalEmailId, FaxToMailUser user) throws EmailException, MessagingException, IOException { Email email = getEmailById(originalEmailId); - try { - Properties properties = new Properties(); + Properties properties = new Properties(); - try { - URL smtpPropertiesURL = ClassLoader.getSystemResource("smtp.properties"); - if (smtpPropertiesURL != null) { - properties.load(smtpPropertiesURL.openStream()); - } - } catch(Exception e) { - log.error("error getting the smtp properties", e); + try { + URL smtpPropertiesURL = ClassLoader.getSystemResource("smtp.properties"); + if (smtpPropertiesURL != null) { + properties.load(smtpPropertiesURL.openStream()); } + } catch(Exception e) { + log.error("error getting the smtp properties", e); + } - final String smtpUser = properties.getProperty("mail.user"); - final String password = properties.getProperty("mail.password"); + final String smtpUser = properties.getProperty("mail.user"); + final String password = properties.getProperty("mail.password"); - MultiPartEmail message = new MultiPartEmail(); - message.setHostName(properties.getProperty("mail.smtp.host")); - message.setSmtpPort(Integer.parseInt(properties.getProperty("mail.smtp.port"))); - message.setAuthenticator(new DefaultAuthenticator(smtpUser, password)); - message.setSSLOnConnect(true); + MultiPartEmail message = new MultiPartEmail(); + message.setHostName(properties.getProperty("mail.smtp.host")); + message.setSmtpPort(Integer.parseInt(properties.getProperty("mail.smtp.port"))); + message.setAuthenticator(new DefaultAuthenticator(smtpUser, password)); + message.setSSLOnConnect(true); - message.setCharset(EmailConstants.UTF_8); - message.setFrom(from); - message.addTo(to); - message.setSubject(subject); - message.setMsg(content); + message.setCharset(EmailConstants.UTF_8); + message.setFrom(from); + message.addTo(to); + message.setSubject(subject); + message.setMsg(content); - for (File attachment : attachments) { - // Create the attachment - message.attach(attachment); - } + for (File attachment : attachments) { + // Create the attachment + message.attach(attachment); + } - String emailId = message.send(); + String emailId = message.send(); - ReplyTopiaDao replyTopiaDao = getPersistenceContext().getReplyDao(); - Date now = new Date(); + ReplyTopiaDao replyTopiaDao = getPersistenceContext().getReplyDao(); + Date now = new Date(); - StringBuilder emailSource = new StringBuilder(); - Enumeration<String> headerLines = message.getMimeMessage().getAllHeaderLines(); - while (headerLines.hasMoreElements()) { - String headerLine = headerLines.nextElement(); - emailSource.append(headerLine).append("\n"); - } - emailSource.append("\n").append(IOUtils.toString(message.getMimeMessage().getInputStream())); + StringBuilder emailSource = new StringBuilder(); + Enumeration<String> headerLines = message.getMimeMessage().getAllHeaderLines(); + while (headerLines.hasMoreElements()) { + String headerLine = headerLines.nextElement(); + emailSource.append(headerLine).append("\n"); + } + emailSource.append("\n").append(IOUtils.toString(message.getMimeMessage().getInputStream())); - Reply reply = replyTopiaDao.create(Reply.PROPERTY_EMAIL_SOURCE, emailSource.toString(), - Reply.PROPERTY_SENT_DATE, now, - Reply.PROPERTY_SUBJECT, subject); + Reply reply = replyTopiaDao.create(Reply.PROPERTY_EMAIL_SOURCE, emailSource.toString(), + Reply.PROPERTY_SENT_DATE, now, + Reply.PROPERTY_SUBJECT, subject); - email.addReplies(reply); + email.addReplies(reply); - HistoryTopiaDao historyDao = getPersistenceContext().getHistoryDao(); - History history = historyDao.create(History.PROPERTY_TYPE, HistoryType.REPLY, - History.PROPERTY_FAX_TO_MAIL_USER, user, - History.PROPERTY_MODIFICATION_DATE, now); - email.addHistory(history); + HistoryTopiaDao historyDao = getPersistenceContext().getHistoryDao(); + History history = historyDao.create(History.PROPERTY_TYPE, HistoryType.REPLY, + History.PROPERTY_FAX_TO_MAIL_USER, user, + History.PROPERTY_MODIFICATION_DATE, now); + email.addHistory(history); - email = saveEmail(email, user); + email = saveEmail(email, user); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("", e); - } - } - return email; } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java 2014-05-16 14:46:47 UTC (rev 79) @@ -42,6 +42,9 @@ import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfAction; import com.itextpdf.text.pdf.PdfContentByte; +import com.itextpdf.text.pdf.PdfDictionary; +import com.itextpdf.text.pdf.PdfName; +import com.itextpdf.text.pdf.PdfNumber; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import com.itextpdf.text.pdf.PdfWriter; @@ -54,6 +57,8 @@ import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.css.Rect; import javax.media.jai.PlanarImage; @@ -74,6 +79,8 @@ */ public class GenerateAnnotatedAttachmentAction extends AbstractFaxToMailAction<PDFEditorUIModel, PDFEditorUI, PDFEditorUIHandler> { + private static final Log log = LogFactory.getLog(GenerateAnnotatedAttachmentAction.class); + public GenerateAnnotatedAttachmentAction(PDFEditorUIHandler handler) { super(handler, true); } @@ -81,8 +88,10 @@ @Override public void doAction() throws Exception { - File file = getModel().getNotNullFile(); + PDFEditorUIModel model = getModel(); + File file = model.getNotNullFile(); + // InputStream inputStream; // if (FaxToMailUIUtil.isFileAPDF(file)) { // inputStream = new FileInputStream(file); @@ -99,17 +108,21 @@ PdfReader pdfReader = new PdfReader(inputStream); - File target = new File(FileUtils.getTempDirectory(), getModel().getOriginalFile().getName() + "-annoté.pdf"); + File target = new File(FileUtils.getTempDirectory(), model.getOriginalFile().getName() + "-annoté.pdf"); FileOutputStream fos = new FileOutputStream(target); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); - int pageNb = getModel().getPages().length; + int pageNb = model.getPages().length; + float zoom = model.getZoom(); + int rotation = model.getRotation(); for (int i = 0 ; i < pageNb ; i++) { PdfContentByte cb = pdfStamper.getOverContent(i + 1); - PDFEditorUIModel model = getModel(); - float zoom = model.getZoom(); + PdfDictionary pageDict; + pageDict = pdfReader.getPageN(i + 1); + int pageRotation = pdfReader.getPageRotation(i + 1); + pageDict.put(PdfName.ROTATE, new PdfNumber((360 + pageRotation + rotation) % 360)); for (PDFEditorNoteUI note : model.getPages()[i].getNotes()) { @@ -151,7 +164,7 @@ cb.restoreState(); } - for (JImagePanel panel : model.getPages()[i].getCrosses()) { + for (PDFEditorCrossUI panel : model.getPages()[i].getCrosses()) { Point location = panel.getLocation(); int width = (int) (panel.getWidth() / zoom); @@ -160,10 +173,13 @@ int y = (int) ((getUI().getContainer().getHeight() - location.y) / zoom) - height; cb.saveState(); - Image cross = Image.getInstance(JAXXUtil.class.getResource(SwingUtil.DEFAULT_ICON_PATH + PDFEditorCrossUI.CROSS_IMAGE_FILE)); - cross.scaleAbsolute(width, height); - cross.setAbsolutePosition(x, y); - cb.addImage(cross); + 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(); } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.css 2014-05-16 14:46:47 UTC (rev 79) @@ -39,6 +39,10 @@ font-style: "italic"; } +.unmodifiableFields { + editable: { DemandStatus.UNTREATED.equals(model.getDemandStatus()) }; +} + #topToolBar { floatable: false; opaque: false; Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.jaxx =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.jaxx 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUI.jaxx 2014-05-16 14:46:47 UTC (rev 79) @@ -112,6 +112,7 @@ </cell> <cell weightx='1' columns="3"> <JTextField id='objectField' + styleClass="unmodifiableFields" onKeyReleased='handler.setText(event, "object")'/> </cell> </row> @@ -121,6 +122,7 @@ </cell> <cell weightx='1'> <JTextField id='clientField' + styleClass="unmodifiableFields" onKeyReleased='handler.setText(event, "clientCode")'/> </cell> <cell> @@ -138,6 +140,7 @@ </cell> <cell weightx='1' columns="3"> <BeanFilterableComboBox id='docTypeComboBox' + styleClass="unmodifiableFields" constructorParams='this' genericType="DemandType"/> </cell> @@ -270,7 +273,7 @@ <JLabel id="savNbField"/> </JPanel> <JScrollPane constraints="BorderLayout.CENTER"> - <JXTable id='rangeTable'/> + <JXTable id='rangeTable' styleClass="unmodifiableFields"/> </JScrollPane> </JPanel> Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -322,7 +322,7 @@ Color color = new Color(255, 51, 51); table.addHighlighter(new ColorHighlighter(rowIsInvalidPredicate, color, Color.WHITE, color.darker(), Color.WHITE)); - SwingValidator validator = this.ui.getValidator(); + SwingValidator validator = getValidator(); listenValidatorValid(validator, model); // if new fishingOperation can already cancel his creation @@ -387,7 +387,6 @@ log.debug("closing: " + ui); } clearValidators(); - closeButtonPopups(); } public void closeButtonPopups() { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java 2014-05-16 14:46:47 UTC (rev 79) @@ -817,6 +817,7 @@ } } catch (Exception e) { + //TODO kmorin 20140516 do something when we use the real data if (log.isErrorEnabled()) { log.error("", e); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandesUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -124,7 +124,7 @@ @Override public void onCloseUI() { - closeButtonPopups(); +// closeButtonPopups(); int tabCount = getTabPanel().getTabCount(); for (int i = 0 ; i < tabCount ; i++) { DemandeUIHandler tabHandler = (DemandeUIHandler) getTabHandler(i); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -199,9 +199,7 @@ openFrame(dialogContent, t("faxtomail.reply.title", getModel().getSubject()), new Dimension(800, 600)); } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("", e); - } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.demandReplies.error")); } // FaxToMailUIContext context = getContext(); Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.css 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.css 2014-05-16 14:46:47 UTC (rev 79) @@ -22,8 +22,11 @@ * #L% */ #crossPanel { - scaleImageToFitPanel: { true }; + //scaleImageToFitPanel: { true }; border: { BorderFactory.createDashedBorder(null) }; + opaque: false; + background: { null }; + size: { new Dimension(100, 100) }; } #removeButton { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.jaxx =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.jaxx 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.jaxx 2014-05-16 14:46:47 UTC (rev 79) @@ -21,14 +21,18 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<com.franciaflex.faxtomail.ui.swing.util.JImagePanel id='crossPanel'> +<JPanel id='crossPanel' layout='{new FlowLayout(FlowLayout.TRAILING)}'> <import> + java.awt.BasicStroke java.awt.Color java.awt.Dimension + java.awt.FlowLayout java.awt.Font + java.awt.Graphics + java.awt.Graphics2D javax.swing.BorderFactory - com.franciaflex.faxtomail.ui.swing.util.JImagePanel + javax.swing.JPanel </import> <script><![CDATA[ @@ -36,18 +40,30 @@ public static final String CROSS_IMAGE_FILE = "cross_blue.png"; public PDFEditorCrossUI() { - setImage(SwingUtil.createImageIcon(CROSS_IMAGE_FILE).getImage()); + //setImage(SwingUtil.createImageIcon(CROSS_IMAGE_FILE).getImage()); } protected void removeCross() { - JImagePanel container = getParentContainer(JImagePanel.class); + JPanel container = getParentContainer(JPanel.class); container.remove(this); container.updateUI(); } + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D g2 = (Graphics2D) g.create(); + g2.setStroke(new BasicStroke(1)); + g2.setColor(Color.BLUE); + g2.drawLine(0, 0, getWidth(), getHeight()); + g2.drawLine(getWidth(), 0, 0, getHeight()); + g2.dispose(); + } + ]]></script> <JButton id="removeButton" onActionPerformed="removeCross()"/> -</com.franciaflex.faxtomail.ui.swing.util.JImagePanel> \ No newline at end of file +</JPanel> \ No newline at end of file Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorNoteUI.jaxx =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorNoteUI.jaxx 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorNoteUI.jaxx 2014-05-16 14:46:47 UTC (rev 79) @@ -30,6 +30,7 @@ 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> @@ -41,7 +42,7 @@ protected void textTyped() { setText(getNoteText().getText()); - JImagePanel container = getParentContainer(JImagePanel.class); + JPanel container = getParentContainer(JPanel.class); Point location = getLocation(); Insets insets = container.getInsets(); Dimension size = getPreferredSize(); @@ -50,7 +51,7 @@ } protected void removeNote() { - JImagePanel container = getParentContainer(JImagePanel.class); + JPanel container = getParentContainer(JPanel.class); container.remove(this); container.updateUI(); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.css =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.css 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.css 2014-05-16 14:46:47 UTC (rev 79) @@ -21,6 +21,10 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ +JSeparator { + border: { BorderFactory.createEmptyBorder(0, 5, 0, 5) }; +} + #toolbar { floatable: false; margin: {new java.awt.Insets(5, 0, 0, 5)}; @@ -29,18 +33,18 @@ #noteButton { actionIcon: note; - toolTipText: "faxtomail.pdfEitor.button.addNote.tip"; + toolTipText: "faxtomail.pdfEditor.button.addNote.tip"; } #crossButton { actionIcon: cross; - toolTipText: "faxtomail.pdfEitor.button.addCross.tip"; + toolTipText: "faxtomail.pdfEditor.button.addCross.tip"; } #prevPageButton { actionIcon: left; enabled: { getModel().getCurrentPageIndex() > 1 }; - toolTipText: "faxtomail.pdfEitor.button.previousPage"; + toolTipText: "faxtomail.pdfEditor.button.previousPage"; } #pageNumber { @@ -62,7 +66,7 @@ #nextPageButton { actionIcon: right; enabled: { getModel().getCurrentPageIndex() < getModel().getPages().length }; - toolTipText: "faxtomail.pdfEitor.button.nextPage"; + toolTipText: "faxtomail.pdfEditor.button.nextPage"; } #zoomOutButton { @@ -85,15 +89,19 @@ actionIcon: rotate-anticlockwise } +#printButton { + actionIcon: print; +} + #cancelButton { actionIcon: cancel; - text: "faxtomail.pdfEitor.action.cancel"; - toolTipText: "faxtomail.pdfEitor.action.cancel.tip"; + text: "faxtomail.pdfEditor.action.cancel"; + toolTipText: "faxtomail.pdfEditor.action.cancel.tip"; } #validateButton { actionIcon: validate; - text: "faxtomail.pdfEitor.action.validate"; - toolTipText: "faxtomail.pdfEitor.action.validate.tip"; + text: "faxtomail.pdfEditor.action.validate"; + toolTipText: "faxtomail.pdfEditor.action.validate.tip"; _applicationAction: {com.franciaflex.faxtomail.ui.swing.actions.GenerateAnnotatedAttachmentAction.class}; } \ No newline at end of file Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx 2014-05-16 14:46:47 UTC (rev 79) @@ -75,12 +75,19 @@ <JButton id="rotateAntiClockwiseButton" onActionPerformed="handler.rotateAntiClockwise()"/> + <JSeparator constructorParams="SwingConstants.VERTICAL"/> + + <JButton id="printButton" + onActionPerformed="handler.print()"/> + </JToolBar> <JScrollPane constraints='BorderLayout.CENTER'> <JPanel> - <JImagePanel id="container"> - </JImagePanel> + <JPanel id="container" layout="{null}"> + <JImagePanel id="documentPanel"> + </JImagePanel> + </JPanel> </JPanel> </JScrollPane> Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -69,6 +69,8 @@ import java.nio.channels.FileChannel; import java.util.Date; +import static org.nuiton.i18n.I18n.t; + /** * @author Kevin Morin (Code Lutin) * @since x.x @@ -146,10 +148,13 @@ if (log.isErrorEnabled()) { log.error("", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); + } catch (DocumentException e) { if (log.isErrorEnabled()) { log.error("", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.convertToPdf.error")); } } if (FaxToMailUIUtil.isFileAPDF(file)) { @@ -166,6 +171,7 @@ if (log.isErrorEnabled()) { log.error("", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.pdfEditor.readPdf.error")); } } getUI().setCursor(Cursor.getDefaultCursor()); @@ -178,14 +184,18 @@ model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ZOOM, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - displayPage(model.getCurrentPageIndex(), (Float) evt.getOldValue()); + displayPage(model.getCurrentPageIndex(), + (Float) evt.getOldValue(), + model.getRotation()); } }); model.addPropertyChangeListener(PDFEditorUIModel.PROPERTY_ROTATION, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - displayPage(model.getCurrentPageIndex(), model.getZoom()); + displayPage(model.getCurrentPageIndex(), + model.getZoom(), + (Integer) evt.getOldValue()); } }); } @@ -219,7 +229,7 @@ } protected void addPanel(JPanel panel) { - JImagePanel container = ui.getContainer(); + JPanel container = ui.getContainer(); container.add(panel, 0); Insets insets = container.getInsets(); @@ -246,12 +256,12 @@ } } - displayPage(pageNb, getModel().getZoom()); + displayPage(pageNb, getModel().getZoom(), getModel().getRotation()); } } } - protected void displayPage(int pageNb, float previousZoom) { + protected void displayPage(int pageNb, float previousZoom, int previousRotation) { PDFPage page = pdf.getPage(pageNb); // create the image Rectangle2D bBox = page.getBBox(); @@ -270,36 +280,79 @@ true // block until drawing is done ); - JImagePanel container = getUI().getContainer(); + JPanel container = getUI().getContainer(); + Dimension containerSize = new Dimension(rotation % 180 == 0 ? width : height, + rotation % 180 == 0 ? height : width); + container.setPreferredSize(containerSize); + container.setMinimumSize(containerSize); + container.setMaximumSize(containerSize); + container.setSize(containerSize); - container.setImage(image, rotation); + JImagePanel documentPanel = ui.getDocumentPanel(); + documentPanel.setRotation(rotation); + documentPanel.setImage(image); Insets insets = container.getInsets(); - rect = container.getVisibleRect(); + rect = container.getBounds(); + float zoomRatio = zoom / previousZoom; + int rotationDiff = rotation - previousRotation; + PDFEditorUIModel.Page p = getModel().getPage(pageNb); + for (PDFEditorNoteUI panel : p.getNotes()) { panel.setVisible(true); panel.setZoom(zoom); - Dimension size = panel.getPreferredSize(); - float ratio = zoom / previousZoom; Rectangle bounds = panel.getBounds(); - panel.setBounds((int)(ratio * bounds.x) + rect.x + insets.left, - (int)(ratio * bounds.y) + rect.y + insets.top, - (int)(ratio * size.width), (int)(ratio * size.height)); + int x, y; + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; + + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - bounds.height / 2 - bounds.width / 2 - bounds.y; + y = bounds.x + bounds.width / 2 - bounds.height / 2; + + } else { + x = bounds.y + bounds.height / 2 - bounds.width / 2; + y = rect.height - bounds.height / 2 - bounds.width / 2 - bounds.x; + } + + panel.setBounds((int)(zoomRatio * x) + insets.left, + (int)(zoomRatio * y) + insets.top, + (int)(zoomRatio * bounds.width), (int)(zoomRatio * bounds.height)); + } - for (JImagePanel panel : p.getCrosses()) { + for (PDFEditorCrossUI panel : p.getCrosses()) { panel.setVisible(true); - Dimension size = panel.getSize(); - float ratio = zoom / previousZoom; Rectangle bounds = panel.getBounds(); - panel.setBounds((int)(ratio * bounds.x) + rect.x + insets.left, - (int)(ratio * bounds.y) + rect.y + insets.top, - (int)(ratio * size.width), (int)(ratio * size.height)); + + int newWidth = Math.abs(rotationDiff) % 180 == 0 ? bounds.width : bounds.height; + int newHeight = Math.abs(rotationDiff) % 180 == 0 ? bounds.height : bounds.width; + + int x, y; + + if (rotationDiff == 0) { + x = bounds.x; + y = bounds.y; + + } else if (rotationDiff == 90 || rotationDiff == -270) { + x = rect.width - newWidth - bounds.y; + y = bounds.x; + + } else { + x = bounds.y; + y = rect.height - newHeight - bounds.x; + } + + panel.setBounds((int) (zoomRatio * x) + insets.left, + (int) (zoomRatio * y) + insets.top, + (int) (zoomRatio * newWidth), (int) (zoomRatio * newHeight)); + } container.updateUI(); @@ -381,4 +434,8 @@ int rotation = getModel().getRotation(); getModel().setRotation((360 + rotation - 90) % 360); } + + public void print() { + FaxToMailUIUtil.print(getModel().getEditedFile()); + } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java 2014-05-16 14:46:47 UTC (rev 79) @@ -52,7 +52,7 @@ public class Page { protected List<PDFEditorNoteUI> notes = new ArrayList<PDFEditorNoteUI>(); - protected List<JImagePanel> crosses = new ArrayList<JImagePanel>(); + protected List<PDFEditorCrossUI> crosses = new ArrayList<PDFEditorCrossUI>(); public List<PDFEditorNoteUI> getNotes() { return notes; @@ -66,11 +66,11 @@ notes.remove(note); } - public List<JImagePanel> getCrosses() { + public List<PDFEditorCrossUI> getCrosses() { return crosses; } - public void addCross(JImagePanel cross) { + public void addCross(PDFEditorCrossUI cross) { crosses.add(cross); } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/reply/ReplyFormUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -41,6 +41,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.validator.bean.simple.SimpleBeanValidator; import javax.swing.*; import javax.swing.plaf.basic.BasicComboBoxEditor; @@ -156,6 +157,20 @@ JComboBox addAttachmentFile = ui.getAddAttachmentFile(); addAttachmentFile.setRenderer(new DecoratorListCellRenderer(getDecorator(File.class, null))); addAttachmentFile.setEditor(new FileComboBoxEditor()); + + getValidator().addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + ReplyFormUIModel model = getModel(); + if (log.isDebugEnabled()) { + log.debug("Model [" + model + + "] pass to valid state [" + + evt.getNewValue() + "]"); + } + model.setValid((Boolean) evt.getNewValue()); + } + }); } @Override @@ -169,7 +184,7 @@ @Override public SwingValidator<ReplyFormUIModel> getValidator() { - return null; + return getUI().getValidator(); } @Override @@ -237,9 +252,8 @@ } public void openAttachment(File attachment) { - Desktop desktop = FaxToMailUIUtil.getDesktopForBrowse(); + Desktop desktop = FaxToMailUIUtil.getDesktopForOpen(); try { -// desktop.browse(file.toURI()); desktop.open(attachment); } catch (IOException e) { Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchToGroupUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -188,6 +188,7 @@ if (log.isErrorEnabled()) { log.error("error while searching", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.search.action.error")); } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/search/SearchUIHandler.java 2014-05-16 14:46:47 UTC (rev 79) @@ -188,6 +188,7 @@ if (log.isErrorEnabled()) { log.error("error while searching", e); } + getContext().getErrorHelper().showErrorDialog(t("faxtomail.search.action.error")); } } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/FaxToMailUIUtil.java 2014-05-16 14:46:47 UTC (rev 79) @@ -34,6 +34,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.nuiton.jaxx.application.swing.util.ApplicationUIUtil; import org.nuiton.util.FileUtil; @@ -51,8 +52,10 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; +import java.awt.*; import java.io.File; import java.io.FileOutputStream; +import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -61,6 +64,8 @@ import java.util.List; import java.util.Map; +import static org.nuiton.i18n.I18n.t; + /** * @author tchemit <chemit@codelutin.com> * @since 0.1 @@ -215,4 +220,36 @@ textPane.setText(content); } + public static Desktop getDesktopForPrint() { + + if (!Desktop.isDesktopSupported()) { + throw new ApplicationTechnicalException( + t("jaxx.application.error.desktop.not.supported")); + } + + Desktop desktop = Desktop.getDesktop(); + + if (!desktop.isSupported(Desktop.Action.PRINT)) { + + throw new ApplicationTechnicalException( + t("jaxx.application.error.desktop.print.not.supported")); + } + + return desktop; + } + + public static void print(File file) { + + Desktop desktop = getDesktopForPrint(); + + try { + desktop.print(file); + + } catch (Exception e) { + + throw new ApplicationTechnicalException( + t("jaxx.application.error.cannot.print"), e); + } + } + } Modified: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/JImagePanel.java =================================================================== --- trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/JImagePanel.java 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/util/JImagePanel.java 2014-05-16 14:46:47 UTC (rev 79) @@ -56,7 +56,7 @@ protected Image image; protected Image scaledImage; - protected int rotation; + protected int rotation = 0; protected boolean scaleImageToFitPanel; @@ -65,14 +65,18 @@ public void componentResized(ComponentEvent e) { Component component = e.getComponent(); if (image != null) { - scaledImage = image.getScaledInstance(component.getWidth(), component.getHeight(), Image.SCALE_SMOOTH); + int srcWidth = component.getWidth(); + int srcHeight = component.getHeight(); + int newWidth = rotation % 180 == 0 ? srcWidth : srcHeight; + int newHeight = rotation % 180 == 0 ? srcHeight : srcWidth; + scaledImage = image.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH); } repaint(); } }; - public JImagePanel() { - setLayout(null); + public void setRotation(int rotation) { + this.rotation = rotation; } public boolean isScaleImageToFitPanel() { @@ -108,22 +112,16 @@ bufferedImage = null; } if (bufferedImage != null) { - setImage(bufferedImage, 0); + setImage(bufferedImage); } } public void setImage(Image img) { - setImage(img, 0); - } - - public void setImage(Image img, int rotation) { this.image = img; this.scaledImage = img; - this.rotation = rotation; int srcWidth = img.getWidth(null); int srcHeight = img.getHeight(null); - int newWidth = rotation % 180 == 0 ? srcWidth : srcHeight; int newHeight = rotation % 180 == 0 ? srcHeight : srcWidth; @@ -135,7 +133,7 @@ } public void setImage(String img) { - setImage(new ImageIcon(img).getImage(), 0); + setImage(new ImageIcon(img).getImage()); } @Override Modified: trunk/faxtomail-ui-swing/src/main/resources/i18n/faxtomail-ui-swing_fr_FR.properties =================================================================== --- trunk/faxtomail-ui-swing/src/main/resources/i18n/faxtomail-ui-swing_fr_FR.properties 2014-05-15 16:05:08 UTC (rev 78) +++ trunk/faxtomail-ui-swing/src/main/resources/i18n/faxtomail-ui-swing_fr_FR.properties 2014-05-16 14:46:47 UTC (rev 79) @@ -193,14 +193,14 @@ faxtomail.main.title.application=FaxToMail faxtomail.main.title.applicationName=FaxToMail faxtomail.main.title.nodb= -faxtomail.pdfEitor.action.cancel=Annuler -faxtomail.pdfEitor.action.cancel.tip=Ne pas enregistrer les changements et fermer -faxtomail.pdfEitor.action.validate=Enregistrer -faxtomail.pdfEitor.action.validate.tip=Enregistrer les changements et fermer -faxtomail.pdfEitor.button.addCross.tip=Ajouter une croix -faxtomail.pdfEitor.button.addNote.tip=Ajouter une note -faxtomail.pdfEitor.button.nextPage=Page suivante -faxtomail.pdfEitor.button.previousPage=Page précédente +faxtomail.pdfEditor.action.cancel=Annuler +faxtomail.pdfEditor.action.cancel.tip=Ne pas enregistrer les changements et fermer +faxtomail.pdfEditor.action.validate=Enregistrer +faxtomail.pdfEditor.action.validate.tip=Enregistrer les changements et fermer +faxtomail.pdfEditor.button.addCross.tip=Ajouter une croix +faxtomail.pdfEditor.button.addNote.tip=Ajouter une note +faxtomail.pdfEditor.button.nextPage=Page suivante +faxtomail.pdfEditor.button.previousPage=Page précédente faxtomail.quantitiesByRange.button.text=OK faxtomail.quantitiesByRange.title=Quantités par gamme faxtomail.rangeRows.table.header.commandNumber=N° commande / devis @@ -251,5 +251,10 @@ faxtomail.validator.error.email.clientCode.required=Code client requis faxtomail.validator.error.email.demandType.required=Type de demande requis faxtomail.validator.error.email.projectReference.required=Référence chantier requise +faxtomail.validator.error.reply.from.required= +faxtomail.validator.error.reply.to.required= +jaxx.application.error.cannot.print= +jaxx.application.error.desktop.not.supported= +jaxx.application.error.desktop.print.not.supported= swing.error.cannot.open.file= test=