From bf8c24c879720cf30d2121c6cf715be4c800de0c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 20 Apr 2007 23:15:22 +0000 Subject: [PATCH] Bug [ 1704548 ] Non printing images from database --- .../compiere/print/layout/ImageElement.java | 39 +++++++++++++++++-- .../compiere/print/layout/LayoutEngine.java | 10 ++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/print/src/org/compiere/print/layout/ImageElement.java b/print/src/org/compiere/print/layout/ImageElement.java index eaeee39c1f..56b75758ce 100644 --- a/print/src/org/compiere/print/layout/ImageElement.java +++ b/print/src/org/compiere/print/layout/ImageElement.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * + * Product: Adempiere ERP & CRM Smart Business Solution * * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * * under the terms version 2 of the GNU General Public License as published * @@ -18,6 +18,7 @@ package org.compiere.print.layout; import java.awt.*; import java.awt.geom.*; +import java.math.BigDecimal; import java.net.*; import java.util.*; import java.util.logging.*; @@ -84,6 +85,38 @@ public class ImageElement extends PrintElement return new ImageElement(image.getImage()); } // get + /** + * Create Image from database column + * @param data the printdataelement, containing the reference + * @param imageURLString image url - containing just the AD_Image_ID reference + * @return image element + */ + public static ImageElement get(PrintDataElement data, String imageURLString) + { + Object key = imageURLString; + ImageElement image = (ImageElement)s_cache.get(key); + if (image == null) + { + BigDecimal imkeybd = (BigDecimal) data.getValue(); + MImage im = null; + if (imkeybd != null && imkeybd.intValue() > 0) { + im = new MImage(Env.getCtx(), imkeybd.intValue(), null); + } else { + im = null; + } + if (im != null) { + image = new ImageElement(im.getImage()); + s_cache.put(key, image); + } + } + if (image == null) { + Image imnull = null; + return new ImageElement(imnull); + } + else + return new ImageElement(image.getImage()); + } // get + /** 60 minute Cache */ private static CCache s_cache = new CCache("ImageElement", 10, 60); @@ -311,5 +344,5 @@ public class ImageElement extends PrintElement transform.scale(m_scaleFactor, m_scaleFactor); g2D.drawImage(m_image, transform, this); } // paint - -} // ImageElement + +} // ImageElement \ No newline at end of file diff --git a/print/src/org/compiere/print/layout/LayoutEngine.java b/print/src/org/compiere/print/layout/LayoutEngine.java index a29c902eaf..2bf1f15812 100644 --- a/print/src/org/compiere/print/layout/LayoutEngine.java +++ b/print/src/org/compiere/print/layout/LayoutEngine.java @@ -966,7 +966,8 @@ public class LayoutEngine implements Pageable, Printable, Doc element = ImageElement.get (item.get_ID()); else element = ImageElement.get (item.getImageURL()); - element.layout(maxWidth, item.getMaxHeight(), false, alignment); + if (element != null) + element.layout(maxWidth, item.getMaxHeight(), false, alignment); } else if (item.isTypeField()) //** Field { @@ -1321,7 +1322,12 @@ public class LayoutEngine implements Pageable, Printable, Doc else // should create an empty area return null; } - ImageElement element = ImageElement.get (url); + ImageElement element = null; + if (data.getDisplayType() == DisplayType.Image) { + element = ImageElement.get (data, url); + } else { + element = ImageElement.get (url); + } return element; } // createImageElement