diff --git a/base/src/org/compiere/print/MPrintTableFormat.java b/base/src/org/compiere/print/MPrintTableFormat.java index 5555f44453..2ed9ac2d4f 100644 --- a/base/src/org/compiere/print/MPrintTableFormat.java +++ b/base/src/org/compiere/print/MPrintTableFormat.java @@ -49,6 +49,8 @@ import org.compiere.util.Env; */ public class MPrintTableFormat extends X_AD_PrintTableFormat { + private static final long serialVersionUID = 1L; + /** * Standard Constructor * @param ctx context @@ -603,56 +605,6 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat } return tf; } // get - - /** - * Load Attachment - * @param AD_PrintFormatItem_ID record id - * @throws MalformedURLException - */ - private void loadImages(int AD_PrintTableFormatItem_ID) - { - if(this.isImageIsAttached()) - { - MAttachment attachment = MAttachment.get(Env.getCtx(), - MPrintFormatItem.Table_ID, AD_PrintTableFormatItem_ID); - if (attachment == null) - { - log.log(Level.WARNING, "No Attachment - AD_PrintFormatItem_ID=" + AD_PrintTableFormatItem_ID); - return; - } - if (attachment.getEntryCount() != 1) - { - log.log(Level.WARNING, "Need just 1 Attachment Entry = " + attachment.getEntryCount()); - return; - } - byte[] imageData = attachment.getEntryData(0); - if (imageData != null) - m_image = Toolkit.getDefaultToolkit().createImage(imageData); - if (m_image != null) - log.fine(attachment.getEntryName(0) - + " - Size=" + imageData.length); - else - log.log(Level.WARNING, attachment.getEntryName(0) - + " - not loaded (must be gif or jpg) - AD_PrintFormatItem_ID=" + AD_PrintTableFormatItem_ID); - } - else if (getImageURL()!= null) - { - URL url; - try - { - url = new URL(getImageURL()); - Toolkit tk = Toolkit.getDefaultToolkit(); - m_image = tk.getImage(url); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - else if(getAD_Image_ID() > 0) - m_image_water_mark = MImage.get(getCtx(), getAD_Image_ID()).getImage(); - - } // loadAttachment - /** * Get the Image @@ -660,9 +612,52 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat */ public Image getImage() { - if(m_image==null) - loadImages(getAD_PrintTableFormat_ID()); - + if(m_image != null) + { + return m_image; + } + // + if(isImageIsAttached()) + { + MAttachment attachment = MAttachment.get(getCtx(), Table_ID, get_ID()); + if (attachment == null) + { + log.log(Level.WARNING, "No Attachment - ID=" + get_ID()); + return null; + } + if (attachment.getEntryCount() != 1) + { + log.log(Level.WARNING, "Need just 1 Attachment Entry = " + attachment.getEntryCount()); + return null; + } + byte[] imageData = attachment.getEntryData(0); + if (imageData != null) + { + m_image = Toolkit.getDefaultToolkit().createImage(imageData); + } + if (m_image != null) + { + log.fine(attachment.getEntryName(0) + " - Size=" + imageData.length); + } + else + { + log.log(Level.WARNING, attachment.getEntryName(0) + " - not loaded (must be gif or jpg) - ID=" + get_ID()); + } + } + else if (getImageURL() != null) + { + URL url; + try + { + url = new URL(getImageURL()); + Toolkit tk = Toolkit.getDefaultToolkit(); + m_image = tk.getImage(url); + } + catch (MalformedURLException e) + { + log.log(Level.WARNING, "Malformed URL - "+getImageURL(), e); + } + } return m_image; } // getImage @@ -672,8 +667,15 @@ public class MPrintTableFormat extends X_AD_PrintTableFormat */ public Image getImageWaterMark() { - if(m_image_water_mark==null) - loadImages(getAD_PrintTableFormat_ID()); + if(m_image_water_mark != null) + { + return m_image_water_mark; + } + // + if(getAD_Image_ID() > 0) + { + m_image_water_mark = MImage.get(getCtx(), getAD_Image_ID()).getImage(); + } return m_image_water_mark; } // getImage } // MPrintTableFormat diff --git a/base/src/org/compiere/print/layout/LayoutEngine.java b/base/src/org/compiere/print/layout/LayoutEngine.java index 519a54c912..4e5c9ebb21 100644 --- a/base/src/org/compiere/print/layout/LayoutEngine.java +++ b/base/src/org/compiere/print/layout/LayoutEngine.java @@ -472,26 +472,25 @@ public class LayoutEngine implements Pageable, Printable, Doc Env.setContext(m_printCtx, Page.CONTEXT_TIME, DisplayType.getDateFormat(DisplayType.DateTime, m_format.getLanguage()).format(now)); - /*Page Background Image*/ + // + // Page Background Image Image image = null; - MPrintTableFormat tf = new MPrintTableFormat(getCtx(), m_format.getAD_PrintTableFormat_ID(), m_TrxName); - if (tf==null) - tf = MPrintTableFormat.getDefault(getCtx()); - - String table_name = MTable.getTableName(getCtx(), getPrintInfo().getAD_Table_ID()); - String sql = "SELECT AD_Column_ID FROM AD_Column WHERE ColumnName='IsPrinted' AND AD_Table_ID="+ getPrintInfo().getAD_Table_ID(); - int AD_Column_ID = DB.getSQLValue(m_TrxName, sql); - if(AD_Column_ID > 0) + MPrintTableFormat tf = m_format.getTableFormat(); + MTable table = MTable.get(getCtx(), getPrintInfo().getAD_Table_ID()); + if(table.getColumn("IsPrinted") != null) { - sql = "SELECT IsPrinted FROM "+table_name + " WHERE " +table_name+"_ID="+ getPrintInfo().getRecord_ID(); - if("Y".equals(DB.getSQLValueString(m_TrxName, sql))) + String tableName = table.getTableName(); + final String sql = "SELECT IsPrinted FROM "+tableName+" WHERE "+tableName+"_ID=?"; + boolean isPrinted = "Y".equals(DB.getSQLValueStringEx(m_TrxName, sql, getPrintInfo().getRecord_ID())); + isPrinted =true; + if(isPrinted) { image = tf.getImageWaterMark(); } } else { - image = tf.getImage(); + image = tf.getImage(); } // Update Page Info diff --git a/base/src/org/compiere/print/layout/Page.java b/base/src/org/compiere/print/layout/Page.java index 9654c9dc9e..5bf478e051 100644 --- a/base/src/org/compiere/print/layout/Page.java +++ b/base/src/org/compiere/print/layout/Page.java @@ -169,11 +169,10 @@ public class Page g2D.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); // //backgroundImage - if(m_image!=null) + if(m_image != null) { int x = (bounds.width/2) - (m_image.getWidth(null)/2); int y = (bounds.height/2) - (m_image.getHeight(null)/2); - g2D.drawImage(m_image, x ,y ,null); } //