From: <had...@us...> - 2009-02-13 19:15:35
|
Revision: 4470 http://fudaa.svn.sourceforge.net/fudaa/?rev=4470&view=rev Author: hadouxad Date: 2009-02-13 19:15:30 +0000 (Fri, 13 Feb 2009) Log Message: ----------- * Ajout des librairies pdf et ps pour les export (ps foireux....) * modification g?\195?\169n?\195?\169rales pour inclure ces formats dans tous les exports * ajout des formats a2,a3 et a4 ainsi que la possibilit?\195?\169 de choisir portrait ou landscape * calcul des pixels du format en fonction de la r?\195?\169solution ?\195?\169cran * pour la rotation :concat?\195?\169nation de 2 transformation affines * cr?\195?\169ation de m?\195?\169thode pour construire rapidement un rapport pdf * avancement sur les fl?\195?\168ches connectors. Modified Paths: -------------- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/ctulu_en.fr_txt branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageDimensionChooserPanel.java branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExport.java branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExportPanel.java Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluPdfPsExport.java Modified: branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/ctulu_en.fr_txt =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/ctulu_en.fr_txt 2009-02-13 15:45:15 UTC (rev 4469) +++ branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/ctulu_en.fr_txt 2009-02-13 19:15:30 UTC (rev 4470) @@ -277,4 +277,7 @@ Enregistrement dans le presse-papier=Save image in the clipboard Placer l'image de la fen\xEAtre active dans le presse-papier=Copy the image of the current frame in the clipboard Copier l'image dans le presse-papier=Copy the image in the clipboard -Cr\xE9er une image \xE0 partir de la fen\xEAtre active=Create an image from the current frama \ No newline at end of file +Cr\xE9er une image \xE0 partir de la fen\xEAtre active=Create an image from the current frama +Personalis\xE9=Personalised +Portrait=Portrait +payasage=landscape \ No newline at end of file Modified: branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageDimensionChooserPanel.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageDimensionChooserPanel.java 2009-02-13 15:45:15 UTC (rev 4469) +++ branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageDimensionChooserPanel.java 2009-02-13 19:15:30 UTC (rev 4470) @@ -8,10 +8,17 @@ package org.fudaa.ctulu.image; import java.awt.Dimension; +import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.print.attribute.standard.MediaSize; +import javax.print.attribute.standard.MediaSizeName; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JComponent; +import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -40,177 +47,309 @@ */ public class CtuluImageDimensionChooserPanel extends CtuluDialogPanel implements DocumentListener { - final JComponent tfWidth_; - final JComponent tfHeight_; - Dimension initDimension_; - final CtuluValueEditorInteger editor_; - final BuTransparentToggleButton cbLinked_; - float initRatio_; - final BuTransparentButton btDefaireWidth_; - final BuTransparentButton btDefaireHeight_; + final JComponent tfWidth_; + final JComponent tfHeight_; + Dimension initDimension_; + final CtuluValueEditorInteger editor_; + final BuTransparentToggleButton cbLinked_; + float initRatio_; + final BuTransparentButton btDefaireWidth_; + final BuTransparentButton btDefaireHeight_; + final JComboBox comboFormatStd_; + + private static String PERSONNALISE=CtuluResource.CTULU.getString("Personalis\xE9"); + private static String ISO_A4="A4"; + private static String ISO_A3="A3"; + private static String ISO_A2="A2"; + + private static String PORTRAIT=CtuluResource.CTULU.getString("Portrait"); + private static String LANDSCAPE=CtuluResource.CTULU.getString("Paysage"); + + JRadioButton typePortrait_=new JRadioButton(PORTRAIT,true); + JRadioButton typePaysage_=new JRadioButton(LANDSCAPE,false); + + + + String[] listeFormatSupported_={PERSONNALISE,ISO_A4,ISO_A3,ISO_A2}; - public CtuluImageDimensionChooserPanel() { - this(null); - } - public CtuluImageDimensionChooserPanel(final Dimension _init) { - super(); + public CtuluImageDimensionChooserPanel() { + this(null); + } - editor_ = new CtuluValueEditorInteger(false); - editor_.setEditable(true); - editor_.setVal(new CtuluValueValidator.IntMin(0)); - tfHeight_ = editor_.createEditorComponent(); - tfWidth_ = editor_.createEditorComponent(); - setLayout(new BuBorderLayout(0, 0, true, false)); - final BuPanel pn = new BuPanel(new BuGridLayout(2, 3, 3)); - addLabel(pn, CtuluLib.getS("Largeur")); - pn.add(tfWidth_); - addLabel(pn, CtuluLib.getS("Hauteur")); - pn.add(tfHeight_); - add(pn, BuBorderLayout.CENTER); - cbLinked_ = new BuTransparentToggleButton(CtuluResource.CTULU.getIcon("non-lie.png"), CtuluResource.CTULU - .getIcon("lie.png")); - cbLinked_.addActionListener(new ActionListener() { + public CtuluImageDimensionChooserPanel(final Dimension _init) { + super(); - public void actionPerformed(final ActionEvent _e) { - if (cbLinked_.isSelected()) { - widthValueChanged(); - } + editor_ = new CtuluValueEditorInteger(false); + editor_.setEditable(true); + editor_.setVal(new CtuluValueValidator.IntMin(0)); + tfHeight_ = editor_.createEditorComponent(); + tfWidth_ = editor_.createEditorComponent(); + setLayout(new BuBorderLayout(0, 0, true, false)); + final BuPanel pn = new BuPanel(new BuGridLayout(2, 3, 3)); + addLabel(pn, CtuluLib.getS("Format")); - } - }); - cbLinked_.setSelected(true); - add(cbLinked_, BuBorderLayout.EAST); - final BuIcon toolIcon = BuResource.BU.getToolIcon("defaire"); - btDefaireWidth_ = new BuTransparentButton(toolIcon); - btDefaireHeight_ = new BuTransparentButton(toolIcon); - final String tooltip = CtuluLib.getS("Reinitialiser avec la valeur initiale"); - btDefaireHeight_.setEnabled(false); - btDefaireWidth_.setEnabled(false); - tfWidth_.setLayout(new BuBorderLayout()); - tfWidth_.add(btDefaireWidth_, BuBorderLayout.EAST); - tfHeight_.setLayout(new BuBorderLayout()); - tfHeight_.add(btDefaireHeight_, BuBorderLayout.EAST); - btDefaireHeight_.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent _e) { - refreshHeight(); - } - }); - btDefaireWidth_.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent _e) { - refreshWidth(); - } - }); - ((BuTextField) tfHeight_).getDocument().addDocumentListener(this); - ((BuTextField) tfWidth_).getDocument().addDocumentListener(this); - setInitDimension(_init, true); - editor_.setValue(new Integer(initDimension_.width), tfWidth_); - editor_.setValue(new Integer(initDimension_.height), tfHeight_); - btDefaireWidth_.setToolTipText(tooltip + " (" + initDimension_.width + " )"); - btDefaireWidth_.setToolTipText(tooltip + " (" + initDimension_.height + " )"); - } - public final void setInitDimension(final Dimension _init, final boolean _force) { - initDimension_ = (_init == null || _init.width == 0 || _init.height == 0) ? new Dimension(100, 100) - : new Dimension(_init); - initRatio_ = CtuluLibImage.getRatio(initDimension_.width, initDimension_.height); - if (btDefaireHeight_ != null) { - updateBtHeight(); - } - if (btDefaireWidth_ != null) { - updateBtWidth(); - } - if (_force || !isWidthChanged() || !isHeigthChanged()) { - editor_.setValue(new Integer(initDimension_.width), tfWidth_); - editor_.setValue(new Integer(initDimension_.height), tfHeight_); - } - } + comboFormatStd_=new JComboBox(listeFormatSupported_); + comboFormatStd_.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e) { + selectionFormatStandard(comboFormatStd_.getSelectedIndex()); + } + }); + pn.add(comboFormatStd_); - public void changedUpdate(final DocumentEvent _e) { - update(_e.getDocument()); + ButtonGroup group=new ButtonGroup(); + group.add(typePaysage_); + group.add(typePortrait_); +// typePaysage_.addActionListener(new ActionListener(){ +// public void actionPerformed(ActionEvent e) { +// invertDimension(); +// } +// }); +// typePortrait_.addActionListener(new ActionListener(){ +// public void actionPerformed(ActionEvent e) { +// invertDimension(); +// } +// }); + addLabel(pn, CtuluLib.getS("Largeur")); + pn.add(tfWidth_); + addLabel(pn, CtuluLib.getS("Hauteur")); + pn.add(tfHeight_); + + pn.add(typePortrait_); + pn.add(typePaysage_); + + add(pn, BuBorderLayout.CENTER); + cbLinked_ = new BuTransparentToggleButton(CtuluResource.CTULU.getIcon("non-lie.png"), CtuluResource.CTULU + .getIcon("lie.png")); + cbLinked_.addActionListener(new ActionListener() { - } + public void actionPerformed(final ActionEvent _e) { + if (cbLinked_.isSelected()) { + widthValueChanged(); + } - public void insertUpdate(final DocumentEvent _e) { - update(_e.getDocument()); - } + } - public void removeUpdate(final DocumentEvent _e) { - update(_e.getDocument()); - } + }); + cbLinked_.setSelected(true); + add(cbLinked_, BuBorderLayout.EAST); + final BuIcon toolIcon = BuResource.BU.getToolIcon("defaire"); + btDefaireWidth_ = new BuTransparentButton(toolIcon); + btDefaireHeight_ = new BuTransparentButton(toolIcon); + final String tooltip = CtuluLib.getS("Reinitialiser avec la valeur initiale"); + btDefaireHeight_.setEnabled(false); + btDefaireWidth_.setEnabled(false); + tfWidth_.setLayout(new BuBorderLayout()); + tfWidth_.add(btDefaireWidth_, BuBorderLayout.EAST); + tfHeight_.setLayout(new BuBorderLayout()); + tfHeight_.add(btDefaireHeight_, BuBorderLayout.EAST); + btDefaireHeight_.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent _e) { + refreshHeight(); + } + }); + btDefaireWidth_.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent _e) { + refreshWidth(); + } + }); + ((BuTextField) tfHeight_).getDocument().addDocumentListener(this); + ((BuTextField) tfWidth_).getDocument().addDocumentListener(this); + setInitDimension(_init, true); + editor_.setValue(new Integer(initDimension_.width), tfWidth_); + editor_.setValue(new Integer(initDimension_.height), tfHeight_); + btDefaireWidth_.setToolTipText(tooltip + " (" + initDimension_.width + " )"); + btDefaireWidth_.setToolTipText(tooltip + " (" + initDimension_.height + " )"); - boolean update_; + } - private void update(final Document _src) { - if (_src == ((JTextField) tfHeight_).getDocument()) { - heightValueChanged(); - } else { - widthValueChanged(); - } + public final void setInitDimension(final Dimension _init, final boolean _force) { + initDimension_ = (_init == null || _init.width == 0 || _init.height == 0) ? new Dimension(100, 100) + : new Dimension(_init); + initRatio_ = CtuluLibImage.getRatio(initDimension_.width, initDimension_.height); + if (btDefaireHeight_ != null) { + updateBtHeight(); + } + if (btDefaireWidth_ != null) { + updateBtWidth(); + } + if (_force || !isWidthChanged() || !isHeigthChanged()) { + editor_.setValue(new Integer(initDimension_.width), tfWidth_); + editor_.setValue(new Integer(initDimension_.height), tfHeight_); + } + } - } + public void changedUpdate(final DocumentEvent _e) { + update(_e.getDocument()); - void widthValueChanged() { - updateBtWidth(); - if (!update_ && cbLinked_.isSelected()) { - update_ = true; - final Object integer = editor_.getValue(tfWidth_); - if (integer != null) { - editor_.setValue(new Integer((int) Math.floor(((Integer) integer).intValue() / initRatio_)), tfHeight_); - } - update_ = false; + } - } - } + public void insertUpdate(final DocumentEvent _e) { + update(_e.getDocument()); + } - void heightValueChanged() { - updateBtHeight(); - if (!update_ && cbLinked_.isSelected()) { - update_ = true; - final Object integer = editor_.getValue(tfHeight_); - if (integer != null) { - editor_.setValue(new Integer((int) Math.floor(initRatio_ * ((Integer) integer).intValue())), tfWidth_); - } - update_ = false; - } - } + public void removeUpdate(final DocumentEvent _e) { + update(_e.getDocument()); + } - final void updateBtWidth() { - btDefaireWidth_.setEnabled(isWidthChanged()); - } + boolean update_; - private boolean isWidthChanged() { - return initDimension_.width != getImageWidth(); - } + private void update(final Document _src) { + if (_src == ((JTextField) tfHeight_).getDocument()) { + heightValueChanged(); + } else { + widthValueChanged(); + } - final void updateBtHeight() { + } - btDefaireHeight_.setEnabled(isHeigthChanged()); - } + void widthValueChanged() { + updateBtWidth(); + if (!update_ && cbLinked_.isSelected()) { + update_ = true; + final Object integer = editor_.getValue(tfWidth_); + if (integer != null) { + editor_.setValue(new Integer((int) Math.floor(((Integer) integer).intValue() / initRatio_)), tfHeight_); + } + update_ = false; - private boolean isHeigthChanged() { - return initDimension_.height != getImageHeight(); - } + } + } - public int getImageHeight() { - final Object integer = editor_.getValue(tfHeight_); - return integer == null ? 0 : ((Integer) integer).intValue(); - } + void heightValueChanged() { + updateBtHeight(); + if (!update_ && cbLinked_.isSelected()) { + update_ = true; + final Object integer = editor_.getValue(tfHeight_); + if (integer != null) { + editor_.setValue(new Integer((int) Math.floor(initRatio_ * ((Integer) integer).intValue())), tfWidth_); + } + update_ = false; + } + } - public int getImageWidth() { - final Object integer = editor_.getValue(tfWidth_); - return integer == null ? 0 : ((Integer) integer).intValue(); - } + final void updateBtWidth() { + btDefaireWidth_.setEnabled(isWidthChanged()); + } - void refreshWidth() { - editor_.setValue(new Integer(initDimension_.width), tfWidth_); + private boolean isWidthChanged() { + return initDimension_.width != getImageWidth(); + } - } + final void updateBtHeight() { - void refreshHeight() { - editor_.setValue(new Integer(initDimension_.height), tfHeight_); - } + btDefaireHeight_.setEnabled(isHeigthChanged()); + } + private boolean isHeigthChanged() { + return initDimension_.height != getImageHeight(); + } + + public int getImageHeight() { + final Object integer = editor_.getValue(tfHeight_); + return integer == null ? 0 : ((Integer) integer).intValue(); + } + + public int getImageWidth() { + final Object integer = editor_.getValue(tfWidth_); + return integer == null ? 0 : ((Integer) integer).intValue(); + } + + void refreshWidth() { + editor_.setValue(new Integer(initDimension_.width), tfWidth_); + + } + + void refreshHeight() { + editor_.setValue(new Integer(initDimension_.height), tfHeight_); + } + + + + public boolean isPaysage(){ + return typePaysage_.isSelected(); + } + public boolean isPortrait(){ + return typePortrait_.isSelected(); + } + /** + * Classe qui remplit les param\xE8tres en fonction du format standard. + * @param selection + * @author Adrien Hadoux + */ + public void selectionFormatStandard(int selection) { + + if(selection==-1 || listeFormatSupported_.length<=selection) + return; + + //-- text bloqu\xE9 si on choisit un format standard --// + tfWidth_.setEnabled((selection==0)); + tfHeight_.setEnabled((selection==0)); + //-- cas personnalis\xE9 on ne fait plus rien, on a deja lib\xE9r\xE9 les textfields --// + if(selection==0){ + cbLinked_.setSelected(true); + return; + } + boolean lienProportionMemoire=cbLinked_.isSelected(); + //-- il faut enleever les proportions pour modifier proprement--// + cbLinked_.setSelected(false); + //-- recuperation des formats --// + MediaSize media=null; + + String format=listeFormatSupported_[selection]; + + if(ISO_A4.equals(format)){ + media=MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4); + }else + if(ISO_A3.equals(format)){ + media=MediaSize.getMediaSizeForName(MediaSizeName.ISO_A3); + }else + if(ISO_A2.equals(format)){ + media=MediaSize.getMediaSizeForName(MediaSizeName.ISO_A2); + } + + //-- mettre a jour les valeurs --// + float newWidth=media.getX(MediaSize.MM); + float nw=media.getX(MediaSize.INCH); + + float newHeight=media.getY(MediaSize.MM); + float nh=media.getY(MediaSize.INCH); + + //-- on a la r\xE9solution dpi de l'ecran --// + int pixelParpouce= Toolkit.getDefaultToolkit().getScreenResolution(); + + //-- [taille en pixels] / [r\xE9solution en dpi] * 2,54 = [taille en centim\xE8tres] --// + //-- [taille en pixels]=[taille en centim\xE8tres]*[r\xE9solution en dpi]/2.54 --// + + int pixelW= (int) (newWidth/10*pixelParpouce/2.54); + int pixelH= (int) (newHeight/10*pixelParpouce/2.54); + + + editor_.setValue(new Integer((int)pixelH),tfHeight_); + editor_.setValue(new Integer((int)pixelW),tfWidth_); + + + //-- on remet les proportions comme c'\xE9tait avant --// + cbLinked_.setSelected(lienProportionMemoire); + + } + + /** + * appel\xE9 pour inverser les dimensions dans le cas switch paysage/portrait + */ + private void invertDimension(){ + boolean lienProportionMemoire=cbLinked_.isSelected(); + //-- il faut enleever les proportions pour modifier proprement--// + cbLinked_.setSelected(false); + int h=getImageHeight(); + int w=getImageWidth(); + editor_.setValue(new Integer(w),tfHeight_); + editor_.setValue(new Integer(h),tfWidth_); + //-- on remet les proportions comme c'\xE9tait avant --// + cbLinked_.setSelected(lienProportionMemoire); + } + } Modified: branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExport.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExport.java 2009-02-13 15:45:15 UTC (rev 4469) +++ branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExport.java 2009-02-13 19:15:30 UTC (rev 4470) @@ -20,6 +20,11 @@ import javax.imageio.ImageIO; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.Paragraph; +import com.lowagie.text.pdf.PdfPCell; +import com.lowagie.text.pdf.PdfPTable; import com.memoire.bu.BuResource; import com.memoire.fu.FuLog; @@ -60,6 +65,12 @@ r.add(s); } } + + //-- ajout des formats pdf et ps --// + r.add(CtuluPdfPsExport.FORMATPdf); + r.add(CtuluPdfPsExport.FORMATPS); + + w = new String[r.size()]; r.toArray(w); Arrays.sort(w); @@ -85,10 +96,14 @@ public static boolean export(final RenderedImage _image, final File _targetFile, final String _format, final CtuluUI _ui) { try { - ImageIO.write(_image, _format, _targetFile); + if(CtuluPdfPsExport.isApdfPsFormat(_format)){ + CtuluPdfPsExport.write(_image, _targetFile, _format); + } + else + ImageIO.write(_image, _format, _targetFile); } catch (final IllegalArgumentException e) { return false; - } catch (final IOException _e) { + } catch (final Exception _e) { if (_ui == null) { FuLog.error("save image", _e); } else { @@ -97,6 +112,7 @@ return false; } + return true; } @@ -119,5 +135,10 @@ }); } + + + + + } \ No newline at end of file Modified: branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExportPanel.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExportPanel.java 2009-02-13 15:45:15 UTC (rev 4469) +++ branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluImageExportPanel.java 2009-02-13 19:15:30 UTC (rev 4470) @@ -7,6 +7,14 @@ */ package org.fudaa.ctulu.image; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.awt.image.BufferedImageOp; +import java.awt.image.Raster; import java.awt.image.RenderedImage; import java.io.File; @@ -85,15 +93,37 @@ return super.valide(); } + /** + * Applique la creation des images producer a partir des dimensions pass\xE9es en parametres. + */ public void apply() { final File dest = pnFile_.getFile(); - - final RenderedImage i = producer_.produceImage(pnDim_.getImageWidth(), pnDim_.getImageHeight(), null); + final RenderedImage imageResult ; + if(pnDim_.isPortrait()){ + //-- cas classique portrait --// + int w=pnDim_.getImageWidth(); + int h=pnDim_.getImageHeight(); + imageResult = producer_.produceImage(w, h, null); + } + else{ + //-- cas paysage: --// + int h=pnDim_.getImageHeight(); + int w=pnDim_.getImageWidth(); + BufferedImage img= producer_.produceImage(h, w, null); +// //-- on dessinne l'image avec la bonne forme --// +// BufferedImage imageRotation = new BufferedImage(w, h, img.getType()); +// Graphics2D graphicsImageRotation = (Graphics2D)imageRotation.getGraphics(); +// int centreX=w/2; +// int centreY=h/2; +// graphicsImageRotation.rotate(3*Math.PI/2,centreX,centreY); +// graphicsImageRotation.drawImage(img,0,0,null); + imageResult =getRotateImage(img);//imageRotation; + } final CtuluTaskDelegate delegate = ui_.createTask(dest.getName()); delegate.start(new Runnable() { public void run() { - if (CtuluImageExport.export(i, dest, ext_, ui_)) { + if (CtuluImageExport.export(imageResult, dest, ext_, ui_)) { BuLib.invokeLater(new Runnable() { public void run() { ui_.message(dest.getName(), CtuluLib.getS("Enregistrement image r\xE9ussi"), true); @@ -104,4 +134,46 @@ }); } + + + private BufferedImage getRotateImage(BufferedImage img){ + AffineTransform at = new AffineTransform(); + // scale image + at.scale(1.0, 1.0); + // -- rotation 90 deg --// + at.rotate( Math.PI / 2.0, img.getWidth() / 2.0, img + .getHeight() / 2.0); + + /* + * translate to make sure the rotation doesn't cut off any image data + */ + AffineTransform translationTransform; + translationTransform = findTranslation(at, img); + at.preConcatenate(translationTransform); + + // instantiate and apply affine transformation filter + BufferedImageOp bio; + bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); + + BufferedImage res = bio.filter(img, null); + + return res; + } + + + private AffineTransform findTranslation(AffineTransform at, BufferedImage bi) { + Point2D p2din, p2dout; + + p2din = new Point2D.Double(0.0, 0.0); + p2dout = at.transform(p2din, null); + double ytrans = p2dout.getY(); + + p2din = new Point2D.Double(0, bi.getHeight()); + p2dout = at.transform(p2din, null); + double xtrans = p2dout.getX(); + + AffineTransform tat = new AffineTransform(); + tat.translate(-xtrans, -ytrans); + return tat; + } } Added: branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluPdfPsExport.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluPdfPsExport.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/ctulu/src/org/fudaa/ctulu/image/CtuluPdfPsExport.java 2009-02-13 19:15:30 UTC (rev 4470) @@ -0,0 +1,263 @@ +package org.fudaa.ctulu.image; + +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.image.BufferedImage; +import java.awt.image.RenderedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collection; + +import javax.swing.JTable; + +import org.fudaa.ctulu.CtuluResource; + +import com.db4o.inside.Exceptions4; +import com.lowagie.text.Document; +import com.lowagie.text.DocumentException; +import com.lowagie.text.List; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Rectangle; +import com.lowagie.text.pdf.PdfContentByte; +import com.lowagie.text.pdf.PdfPCell; +import com.lowagie.text.pdf.PdfPTable; +import com.lowagie.text.pdf.PdfTemplate; +import com.lowagie.text.pdf.PdfWriter; +import com.rie.rieps.engine.Job; +import com.rie.rieps.engine.Page; +import com.rie.rieps.engine.image.SmallGrayImage; + +/** + * Classe qui g\xE8re l'exportation pdf et ps. + * utilise la librairie iText. + * @author Adrien Hadoux + */ +public class CtuluPdfPsExport { + + public static String FORMATPdf="pdf"; + public static String FORMATPS="ps"; + + /** + * Format A4 portait + */ + public static Rectangle FORMAT_A4_PORTRAIT=PageSize.A4.rotate(); + public static Rectangle FORMAT_A4=PageSize.A4; + + + public static void write(final RenderedImage _image, final File _targetFile, final String _format) throws DocumentException,IOException,Exception{ + + if(isApdfFormat(_format)) + writePDF(_image, _targetFile, _format); + else + if(isApsFormat(_format)) + writePostScript(_image, _targetFile, _format); + + } + /** + *Un lecteur pdf pour ecrire les images + *@author Adrien Hadoux + */ + public static void writePDF(final RenderedImage _image, final File _targetFile, final String _format) throws DocumentException,IOException{ + int w = _image.getWidth(); + int h = _image.getHeight(); + Document document = new Document(new Rectangle(w,h)); + //-- ajout des infos relatives au document --// + document.addTitle(CtuluResource.CTULU.getString("Exportation PDF")); + document.addAuthor("FUDAA generating document"); + try { + PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(_targetFile)); + document.open(); + PdfContentByte cb = writer.getDirectContent(); + PdfTemplate tp = cb.createTemplate(w, h); + Graphics2D graphics = tp.createGraphics(w, h); + //-- dessin de l'image --// + graphics.drawImage((BufferedImage)_image,0,0,null); + graphics.dispose(); + cb.addTemplate(tp, 0, 0); + } catch (DocumentException ex) { + throw ex; + } catch (IOException ex) { + throw ex; + }finally{ + document.close(); + } + } + + + + /** + *Un lecteur ps + *@author Adrien Hadoux + */ + public static void writePostScript(final RenderedImage _image, final File _targetFile, final String _format) throws Exception{ + //-- creaton de l'image ps--// + SmallGrayImage bwi = new SmallGrayImage(SmallGrayImage.CONVERT_MODE_AVERAGE); + bwi.load((BufferedImage) _image); + OutputStream os = new FileOutputStream(_targetFile); + + Job job = Job.createPSTopLeftOriginJob(os, 595, 842); + + // Set usable postscript fonts of the device + job.setAvailableDeviceFont(new String[]{"Times-Roman", "Helvetica", "Courier", "Times-Italic", "Times-Bold", "Helvetica-Bold"}); + + // Show the dialog box the link unkwown awt font to device postscript font + job.askForUnmappedAWTFont(true); + + // output the awt/postscript font links. + // The output is well formatted to be automatically loaded by the RiePS library + // for future jobs + job.echoFontMapping(true); + + // Open the job + job.open(); + + + // Create a 2 pages document into the job + com.rie.rieps.engine.Document doc = job.createDocument(1); + doc.open(); + + // create a page + Page p = doc.createPage(); + // insert the same page with a picture added + p.drawImage(500, 200, bwi, 100, 100); + doc.showPage(p); + + // close the document and the job + doc.close(); + job.close(); + + + } + + + /** + * Test si le format est un format pdf ou ps + * @param format + * @return + */ + public static boolean isApdfPsFormat(String format){ + return isApdfFormat(format) ||isApsFormat(format); + } + + public static boolean isApdfFormat(String format){ + return format.toLowerCase().equals(FORMATPdf); + } + + + + public static boolean isApsFormat(String format){ + return format.toLowerCase().equals(FORMATPS); + } + /** + * Methode qui ajoute le tableau de data dans le fichier pdf + * @param _data tableau de donn\xE9es + * @param _title titre du tableau + * @param _document document pdf + * @throws DocumentException + * @author Adrien Hadoux + */ + public static void addDataToDocPdf(Object[][] _data,String _title,Document _document) throws DocumentException{ + PdfPTable table = new PdfPTable(2); + //-- titre --// + PdfPCell cell = new PdfPCell(new Paragraph(_title)); + cell.setColspan(2); + table.addCell(cell); + //-- remplissage --// + for(int i=0;i<_data.length;i++) + for(int j=0;j<_data.length;i++) + table.addCell(_data[i][j].toString()); + _document.add(table); + } + + /** + * Methode qui ajoute le tableau de data dans le fichier pdf + * @param _data1 donnees colonnes 1 + * @param _data2 donnees colonnes 2 + * + * @param _title titre du tableau + * @param _document document pdf + * @throws DocumentException + * @author Adrien Hadoux + */ + public static void addDataToDocPdf(java.util.List _data1,java.util.List _data2,String _title,Document _document) throws DocumentException{ + + if(_data1.size()!=_data2.size()) + return; + + PdfPTable table = new PdfPTable(2); + //-- titre --// + PdfPCell cell = new PdfPCell(new Paragraph(_title)); + cell.setColspan(2); + table.addCell(cell); + //-- remplissage --// + for(int i=0;i<_data1.size();i++){ + table.addCell(_data1.get(i).toString()); + table.addCell(_data2.get(i).toString()); + + } + _document.add(table); + } + + /** + * Methode qui ajoute le tableau de data dans le fichier pdf + * @param data1 liste de listes + * @param title titre du tableau + * @param document document pdf + * @throws DocumentException + * @author Adrien Hadoux + */ + public static void addDataToDocPdf(java.util.List<java.util.List> _liste,String _title,Document _document) throws DocumentException{ + PdfPTable table = new PdfPTable(_liste.size()); + //-- titre --// + PdfPCell cell = new PdfPCell(new Paragraph(_title)); + cell.setColspan(_liste.size()); + table.addCell(cell); + //-- remplissage --// + for(java.util.List sousListe:_liste) + for(Object l:sousListe) + table.addCell(l.toString()); + + _document.add(table); + } + + + /** + * Methode qui ajoute le tableau jtable dans le fichier pdf + * @param jtable + * @author Adrien Hadoux + */ + + public static void addJTableToPdf(JTable _tableToadd,PdfWriter _writer){ + PdfContentByte cb = _writer.getDirectContent(); + cb.saveState(); + Graphics2D g2 = cb.createGraphicsShapes(500, 500); + cb.createGraphics(500, 500); + Shape oldClip = g2.getClip(); + g2.clipRect(0, 0, 500, 500); + _tableToadd.print(g2); + g2.setClip(oldClip); + g2.dispose(); + cb.restoreState(); + } + + + /** + * Methode qui ajoute une image dans le fichier pdf + * @param BufferedImage image a ins\xE9rer + * @author Adrien Hadoux + */ + public static void addImageToPdf(BufferedImage _img,PdfWriter _writer,int w,int h){ + PdfContentByte cb = _writer.getDirectContent(); + PdfTemplate tp = cb.createTemplate(w, h); + Graphics2D graphics = tp.createGraphics(w, h); + //-- dessin de l'image --// + graphics.drawImage(_img,0,0,null); + graphics.dispose(); + cb.addTemplate(tp, 0, 0); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |