Search in sources :

Example 1 with MPrintTableFormat

use of org.compiere.print.MPrintTableFormat in project adempiere by adempiere.

the class LayoutEngine method layoutTable.

//	getColor
/**************************************************************************
	 * 	Layout Table.
	 *	Convert PrintData into TableElement
	 *  @param format format to use
	 *  @param printData data to use
	 *  @param xOffset X Axis - offset (start of table) i.e. indentation
	 *  @return TableElement
	 */
private PrintElement layoutTable(MPrintFormat format, PrintData printData, int xOffset) {
    log.info(format.getName() + " - " + printData.getName());
    MPrintTableFormat tf = format.getTableFormat();
    //	Initial Values
    HashMap<Point, Font> rowColFont = new HashMap<Point, Font>();
    MPrintFont printFont = MPrintFont.get(format.getAD_PrintFont_ID());
    rowColFont.put(new Point(TableElement.ALL, TableElement.ALL), printFont.getFont());
    tf.setStandard_Font(printFont.getFont());
    rowColFont.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeader_Font());
    //
    HashMap<Point, Color> rowColColor = new HashMap<Point, Color>();
    MPrintColor printColor = MPrintColor.get(getCtx(), format.getAD_PrintColor_ID());
    rowColColor.put(new Point(TableElement.ALL, TableElement.ALL), printColor.getColor());
    rowColColor.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderFG_Color());
    //
    HashMap<Point, Color> rowColBackground = new HashMap<Point, Color>();
    rowColBackground.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderBG_Color());
    //	Sizes
    boolean multiLineHeader = tf.isMultiLineHeader();
    int pageNoStart = m_pageNo;
    int repeatedColumns = 1;
    Rectangle firstPage = new Rectangle(m_content);
    firstPage.x += xOffset;
    firstPage.width -= xOffset;
    int yOffset = (int) m_position[AREA_CONTENT].y - m_content.y;
    firstPage.y += yOffset;
    firstPage.height -= yOffset;
    Rectangle nextPages = new Rectangle(m_content);
    nextPages.x += xOffset;
    nextPages.width -= xOffset;
    //	Column count
    int columnCount = 0;
    for (int c = 0; c < format.getItemCount(); c++) {
        if (format.getItem(c).isPrinted())
            columnCount++;
    }
    //	System.out.println("Cols=" + cols);
    //	Header & Column Setup
    ValueNamePair[] columnHeader = new ValueNamePair[columnCount];
    int[] columnMaxWidth = new int[columnCount];
    int[] columnMaxHeight = new int[columnCount];
    boolean[] fixedWidth = new boolean[columnCount];
    boolean[] colSuppressRepeats = new boolean[columnCount];
    String[] columnJustification = new String[columnCount];
    HashMap<Integer, Integer> additionalLines = new HashMap<Integer, Integer>();
    int col = 0;
    for (int c = 0; c < format.getItemCount(); c++) {
        MPrintFormatItem item = format.getItem(c);
        if (item.isPrinted()) {
            if (item.isNextLine() && item.getBelowColumn() != 0) {
                additionalLines.put(new Integer(col), new Integer(item.getBelowColumn() - 1));
                if (!item.isSuppressNull()) {
                    //	display size will be set to 0 in TableElement
                    item.setIsSuppressNull(true);
                    item.saveEx();
                }
            }
            columnHeader[col] = new ValueNamePair(item.getColumnName(), item.getPrintName(format.getLanguage()));
            columnMaxWidth[col] = item.getMaxWidth();
            fixedWidth[col] = (columnMaxWidth[col] != 0 && item.isFixedWidth());
            colSuppressRepeats[col] = item.isSuppressRepeats();
            if (item.isSuppressNull()) {
                if (columnMaxWidth[col] == 0)
                    //	indication suppress if Null
                    columnMaxWidth[col] = -1;
                else
                    columnMaxWidth[col] *= -1;
            }
            columnMaxHeight[col] = item.getMaxHeight();
            if (item.isHeightOneLine())
                columnMaxHeight[col] = -1;
            columnJustification[col] = item.getFieldAlignmentType();
            if (columnJustification[col] == null || columnJustification[col].equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Default))
                //	when generated sets correct alignment
                columnJustification[col] = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
            //	Column Fonts
            if (item.getAD_PrintFont_ID() != 0 && item.getAD_PrintFont_ID() != format.getAD_PrintFont_ID()) {
                MPrintFont font = MPrintFont.get(item.getAD_PrintFont_ID());
                rowColFont.put(new Point(TableElement.ALL, col), font.getFont());
            }
            if (item.getAD_PrintColor_ID() != 0 && item.getAD_PrintColor_ID() != format.getAD_PrintColor_ID()) {
                MPrintColor color = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
                rowColColor.put(new Point(TableElement.ALL, col), color.getColor());
            }
            //
            col++;
        }
    }
    //	The Data
    int rows = printData.getRowCount();
    //	System.out.println("Rows=" + rows);
    Object[][] data = new Object[rows][columnCount];
    KeyNamePair[] pk = new KeyNamePair[rows];
    String pkColumnName = null;
    ArrayList<Integer> functionRows = new ArrayList<Integer>();
    ArrayList<Integer> pageBreak = new ArrayList<Integer>();
    //	for all rows
    for (int row = 0; row < rows; row++) {
        //	System.out.println("row=" + row);
        printData.setRowIndex(row);
        if (printData.isFunctionRow()) {
            functionRows.add(new Integer(row));
            rowColFont.put(new Point(row, TableElement.ALL), tf.getFunct_Font());
            rowColColor.put(new Point(row, TableElement.ALL), tf.getFunctFG_Color());
            rowColBackground.put(new Point(row, TableElement.ALL), tf.getFunctBG_Color());
            if (printData.isPageBreak()) {
                pageBreak.add(new Integer(row));
                log.finer("PageBreak row=" + row);
            }
        } else //	Summary/Line Levels for Finanial Reports
        {
            int levelNo = printData.getLineLevelNo();
            if (levelNo != 0) {
                if (levelNo < 0)
                    levelNo = -levelNo;
                Font base = printFont.getFont();
                if (levelNo == 1)
                    rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.ITALIC, base.getSize() - levelNo));
                else if (levelNo == 2)
                    rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.PLAIN, base.getSize() - levelNo));
            }
        }
        //	for all columns
        col = 0;
        for (int c = 0; c < format.getItemCount(); c++) {
            MPrintFormatItem item = format.getItem(c);
            Object dataElement = null;
            if (//	Text Columns
            item.isPrinted()) {
                if (item.isTypeImage()) {
                    if (item.isImageField())
                        data[row][col] = createImageElement(item);
                    else if (item.isImageIsAttached())
                        data[row][col] = ImageElement.get(item.get_ID());
                    else
                        data[row][col] = ImageElement.get(item.getImageURL());
                    // Image layout - teo_sarca, [ 1673548 ]
                    if (data[row][col] != null)
                        ((ImageElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
                } else if (item.isBarcode()) {
                    Object obj = null;
                    if (// teo_sarca, [ 1673542 ]
                    item.getAD_Column_ID() > 0)
                        obj = printData.getNode(new Integer(item.getAD_Column_ID()));
                    if (obj == null)
                        ;
                    else if (obj instanceof PrintDataElement) {
                        PrintDataElement pde = (PrintDataElement) obj;
                        // Get the PrintDataElement string value - teo_sarca [ 1673505 ]
                        String value = null;
                        Object o = pde.getValue();
                        if (o == null)
                            value = "";
                        if (o instanceof KeyNamePair)
                            value = ((KeyNamePair) o).getID();
                        else
                            value = o.toString();
                        BarcodeElement element = new BarcodeElement(value, item);
                        if (element.isValid())
                            data[row][col] = element;
                    }
                    if (data[row][col] != null)
                        ((BarcodeElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
                } else if (item.isTypeText()) {
                    data[row][col] = item.getPrintName(format.getLanguage());
                } else if (item.isTypeField()) {
                    Object obj = null;
                    if (// teo_sarca, [ 1673542 ]
                    item.getAD_Column_ID() > 0)
                        obj = printData.getNode(new Integer(item.getAD_Column_ID()));
                    if (obj == null)
                        ;
                    else if (obj instanceof PrintDataElement) {
                        PrintDataElement pde = (PrintDataElement) obj;
                        if (pde.isID() || pde.isYesNo())
                            dataElement = pde.getValue();
                        else
                            dataElement = pde.getValueDisplay(format.getLanguage());
                    } else
                        log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
                    //	System.out.println("  row=" + row + ",col=" + col + " - " + item.getAD_Column_ID() + " => " + dataElement);
                    data[row][col] = dataElement;
                } else if (item.isTypePrintFormat()) {
                    m_currPage.addElement(includeFormat(item, printData));
                } else // item.isTypeBox() or isTypePrintFormat()
                {
                    log.warning("Unsupported: " + (item.isTypeBox() ? "Box" : "PrintFormat") + " in Table: " + item);
                }
                col++;
            }
        //	printed
        }
        //	for all columns
        PrintDataElement pde = printData.getPKey();
        if (//	for FunctionRows
        pde != null) {
            pk[row] = (KeyNamePair) pde.getValue();
            if (pkColumnName == null)
                pkColumnName = pde.getColumnName();
        }
    //	else
    //		System.out.println("No PK " + printData);
    }
    //	for all rows
    //
    TableElement table = new TableElement(columnHeader, columnMaxWidth, columnMaxHeight, columnJustification, fixedWidth, functionRows, multiLineHeader, data, pk, pkColumnName, pageNoStart, firstPage, nextPages, repeatedColumns, additionalLines, rowColFont, rowColColor, rowColBackground, tf, pageBreak, colSuppressRepeats);
    table.layout(0, 0, false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
    if (m_tableElement == null)
        m_tableElement = table;
    return table;
}
Also used : HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font) ValueNamePair(org.compiere.util.ValueNamePair) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) MPrintFont(org.compiere.print.MPrintFont) MPrintFormatItem(org.compiere.print.MPrintFormatItem) Point(java.awt.Point) Point(java.awt.Point) PrintDataElement(org.compiere.print.PrintDataElement) MPrintTableFormat(org.compiere.print.MPrintTableFormat) MPrintColor(org.compiere.print.MPrintColor) KeyNamePair(org.compiere.util.KeyNamePair)

Example 2 with MPrintTableFormat

use of org.compiere.print.MPrintTableFormat in project adempiere by adempiere.

the class LayoutEngine method layout.

//	getPaper
/**************************************************************************
	 * 	Create Layout
	 */
private void layout() {
    //	Header/Footer
    m_headerFooter = new HeaderFooter(m_printCtx);
    if (!m_format.isForm() && m_format.isStandardHeaderFooter())
        createStandardHeaderFooter();
    //
    m_pageNo = 0;
    m_pages.clear();
    m_tableElement = null;
    //	initialize
    newPage(true, false);
    //
    if (m_format.isForm())
        layoutForm();
    else {
        //	Parameter
        PrintElement element = layoutParameter();
        if (element != null) {
            m_currPage.addElement(element);
            element.setLocation(m_position[AREA_CONTENT]);
            //	GAP
            m_position[AREA_CONTENT].y += element.getHeight() + 5;
        }
        // Process Instance Log (if any):
        element = layoutPInstanceLogs();
        if (element != null) {
            m_currPage.addElement(element);
            element.setLocation(m_position[AREA_CONTENT]);
            //	GAP
            m_position[AREA_CONTENT].y += element.getHeight() + 5;
        }
        //	Table
        if (m_data != null) {
            element = layoutTable(m_format, m_data, 0);
            element.setLocation(m_content.getLocation());
            for (int p = 1; p <= element.getPageCount(); p++) {
                if (p != 1)
                    newPage(true, false);
                m_currPage.addElement(element);
            }
        }
    }
    //
    String pageInfo = String.valueOf(m_pages.size()) + getPageInfo(m_pages.size());
    Env.setContext(m_printCtx, Page.CONTEXT_PAGECOUNT, pageInfo);
    Timestamp now = new Timestamp(System.currentTimeMillis());
    Env.setContext(m_printCtx, Page.CONTEXT_DATE, DisplayType.getDateFormat(DisplayType.Date, m_format.getLanguage()).format(now));
    Env.setContext(m_printCtx, Page.CONTEXT_TIME, DisplayType.getDateFormat(DisplayType.DateTime, m_format.getLanguage()).format(now));
    //
    // Page Background Image
    Image image = null;
    MPrintTableFormat tf = m_format.getTableFormat();
    MTable table = MTable.get(getCtx(), getPrintInfo().getAD_Table_ID());
    if (table.getColumn("IsPrinted") != null && !table.isView()) {
        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()));
        if (isPrinted) {
            image = tf.getImageWaterMark();
        }
    } else {
        image = tf.getImage();
    }
    //	Update Page Info
    int pages = m_pages.size();
    for (int i = 0; i < pages; i++) {
        Page page = m_pages.get(i);
        int pageNo = page.getPageNo();
        pageInfo = String.valueOf(pageNo) + getPageInfo(pageNo);
        page.setPageInfo(pageInfo);
        page.setPageCount(pages);
        page.setBackgroundImage(image);
    }
    m_hasLayout = true;
}
Also used : MTable(org.compiere.model.MTable) MPrintTableFormat(org.compiere.print.MPrintTableFormat) Image(java.awt.Image) Timestamp(java.sql.Timestamp) Point(java.awt.Point)

Example 3 with MPrintTableFormat

use of org.compiere.print.MPrintTableFormat in project adempiere by adempiere.

the class LayoutEngine method createStandardHeaderFooter.

//	isYspaceFor
/**************************************************************************
	 *	Create Standard Header/Footer
	 *  <pre>
	 *  title           C        Page x of x
	 *  Copyright      who         date&time
	 *  </pre>
	 */
private void createStandardHeaderFooter() {
    MClientInfo ci = MClientInfo.get(Env.getCtx());
    PrintElement element = null;
    if (ci.getLogoReport_ID() > 0) {
        element = new ImageElement(ci.getLogoReport_ID(), false);
    } else {
        //	48x15
        element = new ImageElement(org.compiere.Adempiere.getImageLogoSmall(true));
    }
    //	element = new ImageElement(org.compiere.Adempiere.getImageLogo());	//	100x30
    element.layout(48, 15, false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
    element.setLocation(m_header.getLocation());
    m_headerFooter.addElement(element);
    //
    MPrintTableFormat tf = m_format.getTableFormat();
    Font font = tf.getPageHeader_Font();
    Color color = tf.getPageHeaderFG_Color();
    //
    element = new StringElement("@*ReportName@", font, color, null, true);
    element.layout(m_header.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_Center);
    element.setLocation(m_header.getLocation());
    m_headerFooter.addElement(element);
    //
    //
    element = new StringElement("@Page@ @*Page@ @of@ @*PageCount@", font, color, null, true);
    element.layout(m_header.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight);
    element.setLocation(m_header.getLocation());
    m_headerFooter.addElement(element);
    //	Footer
    font = tf.getPageFooter_Font();
    color = tf.getPageFooterFG_Color();
    //
    element = new StringElement(Adempiere.ADEMPIERE_R, font, color, null, true);
    /** You can use the following to customize reports for your product name  */
    //	element = new StringElement(Adempiere.NAME, font, color, null, true);
    element.layout(m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
    Point ft = m_footer.getLocation();
    //	2pt above min
    ft.y += m_footer.height - element.getHeight() - 2;
    element.setLocation(ft);
    m_headerFooter.addElement(element);
    //
    element = new StringElement("@*Header@", font, color, null, true);
    element.layout(m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_Center);
    element.setLocation(ft);
    m_headerFooter.addElement(element);
    //
    element = new StringElement("@*CurrentDateTime@", font, color, null, true);
    element.layout(m_footer.width, 0, true, MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight);
    element.setLocation(ft);
    m_headerFooter.addElement(element);
}
Also used : MPrintTableFormat(org.compiere.print.MPrintTableFormat) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) MClientInfo(org.compiere.model.MClientInfo) Point(java.awt.Point) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font)

Aggregations

Point (java.awt.Point)3 MPrintTableFormat (org.compiere.print.MPrintTableFormat)3 Color (java.awt.Color)2 Font (java.awt.Font)2 MPrintColor (org.compiere.print.MPrintColor)2 MPrintFont (org.compiere.print.MPrintFont)2 Image (java.awt.Image)1 Rectangle (java.awt.Rectangle)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MClientInfo (org.compiere.model.MClientInfo)1 MTable (org.compiere.model.MTable)1 MPrintFormatItem (org.compiere.print.MPrintFormatItem)1 PrintDataElement (org.compiere.print.PrintDataElement)1 KeyNamePair (org.compiere.util.KeyNamePair)1 ValueNamePair (org.compiere.util.ValueNamePair)1