Author: kmorin Date: 2014-05-16 18:05:30 +0200 (Fri, 16 May 2014) New Revision: 81 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/81 Log: add a line component in the pdf editor Added: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.css trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.jaxx trunk/faxtomail-ui-swing/src/main/resources/icons/action-line.png 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/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/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/resources/i18n/faxtomail-ui-swing_fr_FR.properties trunk/pom.xml 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/GenerateAnnotatedAttachmentAction.java 2014-05-16 16:05:30 UTC (rev 81) @@ -25,6 +25,7 @@ */ import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorCrossUI; +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.PDFEditorUI; import com.franciaflex.faxtomail.ui.swing.content.pdfeditor.PDFEditorUIHandler; @@ -182,6 +183,32 @@ cb.stroke(); cb.restoreState(); } + + for (PDFEditorLineUI panel : model.getPages()[i].getLines()) { + + Point location = panel.getLocation(); + int width = (int) (panel.getWidth() / zoom); + int height = (int) (panel.getHeight() / zoom); + int x = (int) (location.x / zoom); + int y = (int) ((getUI().getContainer().getHeight() - location.y) / zoom) - height; + + if (panel.isHorizontal()) { + y += height / 2; + } else { + x += width / 2; + } + + cb.saveState(); + cb.setColorStroke(BaseColor.BLUE); + cb.moveTo(x, y); + if (panel.isHorizontal()) { + cb.lineTo(x + width, y); + } else { + cb.lineTo(x, y + height); + } + cb.stroke(); + cb.restoreState(); + } } pdfStamper.close(); 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.css 2014-05-16 16:05:30 UTC (rev 81) @@ -26,7 +26,7 @@ border: { BorderFactory.createDashedBorder(null) }; opaque: false; background: { null }; - size: { new Dimension(100, 100) }; + size: { new Dimension(500, 200) }; } #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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorCrossUI.jaxx 2014-05-16 16:05:30 UTC (rev 81) @@ -37,12 +37,6 @@ <script><![CDATA[ - public static final String CROSS_IMAGE_FILE = "cross_blue.png"; - - public PDFEditorCrossUI() { - //setImage(SwingUtil.createImageIcon(CROSS_IMAGE_FILE).getImage()); - } - protected void removeCross() { JPanel container = getParentContainer(JPanel.class); container.remove(this); Copied: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.css (from rev 79, 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/PDFEditorLineUI.css (rev 0) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.css 2014-05-16 16:05:30 UTC (rev 81) @@ -0,0 +1,37 @@ +/* + * #%L + * FaxToMail :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2014 Franciaflex, 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% + */ +#linePanel { + border: { BorderFactory.createDashedBorder(null) }; + opaque: false; + background: { null }; + size: { new Dimension(500, 100) }; +} + +#removeButton { + text: "X"; + //borderPainted: { false }; + //border: { null }; + //opaque : { false }; + //background: { null }; +} \ No newline at end of file Copied: trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.jaxx (from rev 79, 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/PDFEditorLineUI.jaxx (rev 0) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorLineUI.jaxx 2014-05-16 16:05:30 UTC (rev 81) @@ -0,0 +1,69 @@ +<!-- + #%L + FaxToMail :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2014 Franciaflex, 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='linePanel' 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 + javax.swing.JPanel + </import> + + <script><![CDATA[ + + protected void removeLine() { + 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); + if (Boolean.TRUE.equals(horizontal)) { + g2.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); + + } else { + g2.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); + } + g2.dispose(); + } + + ]]></script> + + <Boolean id="horizontal" javaBean="true"/> + + <JButton id="removeButton" + onActionPerformed="removeLine()"/> + +</JPanel> \ No newline at end of file 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.css 2014-05-16 16:05:30 UTC (rev 81) @@ -41,6 +41,11 @@ toolTipText: "faxtomail.pdfEditor.button.addCross.tip"; } +#lineButton { + actionIcon: line; + toolTipText: "faxtomail.pdfEditor.button.addLine.tip"; +} + #prevPageButton { actionIcon: left; enabled: { getModel().getCurrentPageIndex() > 1 }; 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUI.jaxx 2014-05-16 16:05:30 UTC (rev 81) @@ -53,6 +53,8 @@ onActionPerformed="handler.addNote()"/> <JButton id='crossButton' onActionPerformed="handler.addCross()"/> + <JButton id='lineButton' + onActionPerformed="handler.addLine()"/> <JSeparator constructorParams="SwingConstants.VERTICAL"/> 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIHandler.java 2014-05-16 16:05:30 UTC (rev 81) @@ -68,6 +68,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.Date; +import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -103,6 +104,9 @@ } else if (child.getClass().isAssignableFrom(PDFEditorCrossUI.class)) { currentPage.addCross((PDFEditorCrossUI) child); + + } else if (child.getClass().isAssignableFrom(PDFEditorLineUI.class)) { + currentPage.addLine((PDFEditorLineUI) child); } } @@ -115,6 +119,9 @@ } else if (child.getClass().isAssignableFrom(PDFEditorCrossUI.class)) { currentPage.removeCross((PDFEditorCrossUI) child); + + } else if (child.getClass().isAssignableFrom(PDFEditorLineUI.class)) { + currentPage.removeLine((PDFEditorLineUI) child); } } }); @@ -228,6 +235,12 @@ cr.registerComponent(cross); } + public void addLine() { + PDFEditorLineUI line = new PDFEditorLineUI(); + addPanel(line); + cr.registerComponent(ComponentResizer.DIRECTION_HORIZONTAL, line); + } + protected void addPanel(JPanel panel) { JPanel container = ui.getContainer(); container.add(panel, 0); @@ -326,13 +339,15 @@ } + boolean orientation180 = Math.abs(rotationDiff) % 180 == 0; + for (PDFEditorCrossUI panel : p.getCrosses()) { panel.setVisible(true); Rectangle bounds = panel.getBounds(); - int newWidth = Math.abs(rotationDiff) % 180 == 0 ? bounds.width : bounds.height; - int newHeight = Math.abs(rotationDiff) % 180 == 0 ? bounds.height : bounds.width; + int newWidth = orientation180 ? bounds.width : bounds.height; + int newHeight = orientation180 ? bounds.height : bounds.width; int x, y; @@ -355,6 +370,43 @@ } + List<PDFEditorLineUI> lines = p.getLines(); + cr.deregisterComponent(lines.toArray(new PDFEditorLineUI[lines.size()])); + + for (PDFEditorLineUI panel : lines) { + panel.setVisible(true); + + Rectangle bounds = panel.getBounds(); + + boolean horizontal = panel.isHorizontal(); + panel.setHorizontal(orientation180 ? horizontal : ! horizontal); + + int newWidth = orientation180 ? bounds.width : bounds.height; + int newHeight = orientation180 ? 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)); + + cr.registerComponent(panel.isHorizontal() ? ComponentResizer.DIRECTION_HORIZONTAL : ComponentResizer.DIRECTION_VERTICAL, + panel); + } + container.updateUI(); } 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/pdfeditor/PDFEditorUIModel.java 2014-05-16 16:05:30 UTC (rev 81) @@ -53,6 +53,7 @@ protected List<PDFEditorNoteUI> notes = new ArrayList<PDFEditorNoteUI>(); protected List<PDFEditorCrossUI> crosses = new ArrayList<PDFEditorCrossUI>(); + protected List<PDFEditorLineUI> lines = new ArrayList<PDFEditorLineUI>(); public List<PDFEditorNoteUI> getNotes() { return notes; @@ -74,9 +75,21 @@ crosses.add(cross); } - public void removeCross(JPanel cross) { + public void removeCross(PDFEditorCrossUI cross) { crosses.remove(cross); } + + public List<PDFEditorLineUI> getLines() { + return lines; + } + + public void addLine(PDFEditorLineUI line) { + lines.add(line); + } + + public void removeLine(PDFEditorLineUI line) { + lines.remove(line); + } } protected Page[] pages; 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-16 14:48:31 UTC (rev 80) +++ trunk/faxtomail-ui-swing/src/main/resources/i18n/faxtomail-ui-swing_fr_FR.properties 2014-05-16 16:05:30 UTC (rev 81) @@ -198,9 +198,12 @@ 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.addLine.tip=Ajouter une ligne faxtomail.pdfEditor.button.addNote.tip=Ajouter une note faxtomail.pdfEditor.button.nextPage=Page suivante faxtomail.pdfEditor.button.previousPage=Page précédente +faxtomail.pdfEditor.convertToPdf.error= +faxtomail.pdfEditor.readPdf.error= faxtomail.quantitiesByRange.button.text=OK faxtomail.quantitiesByRange.title=Quantités par gamme faxtomail.rangeRows.table.header.commandNumber=N° commande / devis Added: trunk/faxtomail-ui-swing/src/main/resources/icons/action-line.png =================================================================== (Binary files differ) Property changes on: trunk/faxtomail-ui-swing/src/main/resources/icons/action-line.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-05-16 14:48:31 UTC (rev 80) +++ trunk/pom.xml 2014-05-16 16:05:30 UTC (rev 81) @@ -109,7 +109,7 @@ <hibernateVersion>4.3.5.Final</hibernateVersion> <h2Version>1.3.176</h2Version> - <jaxxVersion>2.8.5</jaxxVersion> + <jaxxVersion>2.8.6-SNAPSHOT</jaxxVersion> <swingXVersion>1.6.5-1</swingXVersion> <xworkVersion>2.3.15.1</xworkVersion>