Search in sources :

Example 6 with MPrintFormatItem

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

the class LayoutEngine method layoutForm.

//	createStandardHeaderFooter
/**************************************************************************
	 * 	Layout Form.
	 *  For every Row, loop through the Format
	 *  and calculate element size and position.
	 */
private void layoutForm() {
    //	log.info("layoutForm");
    m_columnCount = 0;
    if (m_data == null)
        return;
    //	for every row
    for (int row = 0; row < m_data.getRowCount(); row++) {
        log.info("Row=" + row);
        m_data.setRowIndex(row);
        //	prevent NL of nothing printed and supress null
        boolean somethingPrinted = true;
        //	for every item
        for (int i = 0; i < m_format.getItemCount(); i++) {
            MPrintFormatItem item = m_format.getItem(i);
            //	log.fine("layoutForm - Row=" + row + " - #" + i + " - " + item);
            if (!item.isPrinted())
                continue;
            //	log.fine("layoutForm - Row=" + row + " - #" + i + " - " + item);
            m_columnCount++;
            //	Read Header/Footer just once
            if (row > 0 && (item.isHeader() || item.isFooter()))
                continue;
            //	Position
            if (//	Area
            item.isHeader())
                setArea(AREA_HEADER);
            else if (item.isFooter())
                setArea(AREA_FOOTER);
            else
                setArea(AREA_CONTENT);
            //
            if (item.isSetNLPosition() && item.isRelativePosition())
                m_tempNLPositon = 0;
            //	New Page/Line
            if (//	new line
            item.isNextLine() && somethingPrinted) {
                newLine();
                somethingPrinted = false;
            } else {
                addX(m_lastWidth[m_area]);
            }
            if (//	item.isPageBreak()			//	new page
            item.isNextPage()) {
                newPage(false, false);
            }
            //	Relative Position space
            if (item.isRelativePosition()) {
                addX(item.getXSpace());
                addY(item.getYSpace());
            } else
                //	Absolute relative position
                setRelativePosition(item.getXPosition(), item.getYPosition());
            //	Temporary NL Position when absolute positioned
            if (item.isSetNLPosition() && !item.isRelativePosition())
                m_tempNLPositon = (int) getPosition().getX();
            //	line alignment
            String alignment = item.getFieldAlignmentType();
            int maxWidth = item.getMaxWidth();
            boolean lineAligned = false;
            if (item.isRelativePosition()) {
                if (item.isLineAlignLeading()) {
                    alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
                    maxWidth = getAreaBounds().width;
                    lineAligned = true;
                } else if (item.isLineAlignCenter()) {
                    alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_Center;
                    maxWidth = getAreaBounds().width;
                    lineAligned = true;
                } else if (item.isLineAlignTrailing()) {
                    alignment = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
                    maxWidth = getAreaBounds().width;
                    lineAligned = true;
                }
            }
            //	Type
            PrintElement element = null;
            if (//** included PrintFormat
            item.isTypePrintFormat()) {
                element = includeFormat(item, m_data);
            } else if (item.isBarcode()) {
                element = createBarcodeElement(item);
                if (element != null) {
                    element.layout(maxWidth, item.getMaxHeight(), false, alignment);
                }
            } else if (//**	Image
            item.isTypeImage()) {
                if (item.isImageField())
                    element = createImageElement(item);
                else if (item.isImageIsAttached())
                    element = ImageElement.get(item.get_ID());
                else
                    element = ImageElement.get(item.getImageURL());
                if (element != null)
                    element.layout(maxWidth, item.getMaxHeight(), false, alignment);
            } else if (//**	Field
            item.isTypeField()) {
                if (maxWidth == 0 && item.isFieldAlignBlock())
                    maxWidth = getAreaBounds().width;
                element = createFieldElement(item, maxWidth, alignment, m_format.isForm());
            } else if (//**	Line/Box
            item.isTypeBox()) {
                if (m_format.isForm())
                    element = createBoxElement(item);
                // Auto detect width - teo_sarca, BF [ 1825876 ]
                if (element != null && maxWidth == 0) {
                    maxWidth = getAreaBounds().width;
                    element.setMaxWidth(maxWidth);
                }
            } else //	(item.isTypeText())		//**	Text
            {
                if (maxWidth == 0 && item.isFieldAlignBlock())
                    maxWidth = getAreaBounds().width;
                element = createStringElement(item.getPrintName(m_format.getLanguage()), item.getAD_PrintColor_ID(), item.getAD_PrintFont_ID(), maxWidth, item.getMaxHeight(), item.isHeightOneLine(), alignment, true);
            }
            //	Printed - set last width/height
            if (element != null) {
                somethingPrinted = true;
                if (!lineAligned)
                    m_lastWidth[m_area] = element.getWidth();
                m_lastHeight[m_area] = element.getHeight();
            } else {
                somethingPrinted = false;
                m_lastWidth[m_area] = 0f;
                m_lastHeight[m_area] = 0f;
                // Fix problem when the element is not printed but X Space was previously added
                if (item.isRelativePosition()) {
                    addX(-item.getXSpace());
                    addY(-item.getYSpace());
                }
            // end globalqss
            }
            //	Does it fit?
            if (item.isRelativePosition() && !lineAligned) {
                if (!isXspaceFor(m_lastWidth[m_area])) {
                    log.finest("Not enough X space for " + m_lastWidth[m_area] + " - remaining " + getXspace() + " - Area=" + m_area);
                    newLine();
                }
                if (m_area == AREA_CONTENT && !isYspaceFor(m_lastHeight[m_area])) {
                    log.finest("Not enough Y space " + m_lastHeight[m_area] + " - remaining " + getYspace() + " - Area=" + m_area);
                    newPage(true, true);
                }
            }
            //		+ " w=" + lastWidth[m_area] + ",h=" + lastHeight[m_area] + " " + item);
            if (element != null)
                element.setLocation(m_position[m_area]);
            //	Add to Area
            if (m_area == AREA_CONTENT)
                m_currPage.addElement(element);
            else
                m_headerFooter.addElement(element);
            //
            if (m_lastHeight[m_area] > m_maxHeightSinceNewLine[m_area])
                m_maxHeightSinceNewLine[m_area] = m_lastHeight[m_area];
            // Reset maxHeightSinceNewLine if we have an absolute position - teo_sarca BF [ 1807917 ]
            if (!item.isRelativePosition())
                m_maxHeightSinceNewLine[m_area] = m_lastHeight[m_area];
        }
    //	for every item
    }
//	for every row
}
Also used : MPrintFormatItem(org.compiere.print.MPrintFormatItem) Point(java.awt.Point)

Example 7 with MPrintFormatItem

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

the class GenerateReplenishPlanReport method getPrintFormat.

/**
	 * @return
	 */
private MPrintFormat getPrintFormat() {
    MPrintFormat pf = null;
    if (Ini.isClient()) {
        pf = (MPrintFormat) getProcessInfo().getTransientObject();
    } else {
        pf = (MPrintFormat) getProcessInfo().getSerializableObject();
    }
    if (pf == null) {
        pf = MPrintFormat.get(getCtx(), 0, MTable.getTable_ID("M_ReplenishPlanLine"));
    }
    int count = pf.getItemCount();
    int weeksToDisplay = END_WEEK - START_WEEK + 1;
    int startIndx = START_WEEK;
    int endIndx = END_WEEK;
    for (int i = 0; i < count; i++) {
        MPrintFormatItem pfi = pf.getItem(i);
        String columnName = pfi.getColumnName().toLowerCase();
        if (columnName != null && columnName.startsWith("week")) {
            int index = Integer.parseInt(columnName.substring(4));
            if (index > weeksToDisplay) {
                if (pfi.isPrinted())
                    pfi.setIsPrinted(false);
            } else {
                int displayWeek = startIndx + (index - 1);
                String printName = weekDateInfo.get(displayWeek);
                pfi.setPrintName(printName);
                pfi.setIsPrinted(true);
                pfi.setIsSuppressNull(false);
                pfi.setIsSuppressRepeats(false);
                pfi.setMaxWidth(35);
                pfi.setIsFixedWidth(true);
                pfi.setIsHeightOneLine(false);
                // pfi.set_ValueOfColumn("DisplayLogic", "@" + columnName +
                // "@!0");
                pfi.setLineAlignmentType(X_AD_PrintFormatItem.LINEALIGNMENTTYPE_TrailingRight);
                pfi.setFieldAlignmentType(X_AD_PrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight);
                // Dynamic sequencing is required as we are showing & hiding
                // elements based on week difference.
                pfi.setSeqNo(50 + index * 10);
                if (displayWeek > (startIndx + 1) && displayWeek < (endIndx - 1)) {
                    pfi.setAD_PrintColor_ID(RED_AD_PrintColor_ID);
                } else {
                    pfi.setAD_PrintColor_ID(-1);
                }
            }
        }
        pfi.saveEx();
        log.fine(pfi.toString());
    }
    pf.setTranslation();
    // no
    pf = MPrintFormat.get(getCtx(), pf.getAD_PrintFormat_ID(), true);
    // cache
    return pf;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) MPrintFormatItem(org.compiere.print.MPrintFormatItem)

Aggregations

MPrintFormatItem (org.compiere.print.MPrintFormatItem)7 MPrintFormat (org.compiere.print.MPrintFormat)3 PrintDataElement (org.compiere.print.PrintDataElement)3 Point (java.awt.Point)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 XhtmlDocument (org.apache.ecs.XhtmlDocument)1 org.apache.ecs.xhtml.h1 (org.apache.ecs.xhtml.h1)1 org.apache.ecs.xhtml.i (org.apache.ecs.xhtml.i)1 org.apache.ecs.xhtml.style (org.apache.ecs.xhtml.style)1 org.apache.ecs.xhtml.table (org.apache.ecs.xhtml.table)1 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)1 org.apache.ecs.xhtml.th (org.apache.ecs.xhtml.th)1