Search in sources :

Example 1 with MPrintColor

use of org.compiere.print.MPrintColor 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 MPrintColor

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

the class LayoutEngine method createFieldElement.

//	createStringElement
/**
	 * 	Create Field Element
	 * 	@param item Format Item
	 * 	@param maxWidth max width
	 * 	@param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
	 * 	@param isForm true if document
	 * 	@return Print Element or null if nothing to print
	 */
private PrintElement createFieldElement(MPrintFormatItem item, int maxWidth, String FieldAlignmentType, boolean isForm) {
    //	Get Data
    Object obj = m_data.getNode(new Integer(item.getAD_Column_ID()));
    if (obj == null)
        return null;
    else if (obj instanceof PrintDataElement)
        ;
    else {
        log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
        return null;
    }
    //	Convert DataElement to String
    PrintDataElement data = (PrintDataElement) obj;
    if (data.isNull() && item.isSuppressNull())
        return null;
    String stringContent = data.getValueDisplay(m_format.getLanguage());
    if ((stringContent == null || stringContent.length() == 0) && item.isSuppressNull())
        return null;
    //	non-string
    Object content = stringContent;
    if (data.getValue() instanceof Boolean)
        content = data.getValue();
    //	Convert AmtInWords Content to alpha
    if (item.getColumnName().equals("AmtInWords")) {
        log.fine("AmtInWords: " + stringContent);
        stringContent = Msg.getAmtInWords(m_format.getLanguage(), stringContent);
        content = stringContent;
    }
    //	Label
    String label = item.getPrintName(m_format.getLanguage());
    String labelSuffix = item.getPrintNameSuffix(m_format.getLanguage());
    //	ID Type
    NamePair ID = null;
    if (data.isID()) {
        //	Record_ID/ColumnName
        Object value = data.getValue();
        if (value instanceof KeyNamePair)
            ID = new KeyNamePair(((KeyNamePair) value).getKey(), item.getColumnName());
        else if (value instanceof ValueNamePair)
            ID = new ValueNamePair(((ValueNamePair) value).getValue(), item.getColumnName());
    } else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Default.equals(FieldAlignmentType)) {
        if (data.isNumeric())
            FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
        else
            FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
    }
    //	Get Color/ Font
    //	default
    Color color = getColor();
    if (ID != null && !isForm)
        //	link color/underline handeled in PrintElement classes
        ;
    else if (item.getAD_PrintColor_ID() != 0 && m_printColor.get_ID() != item.getAD_PrintColor_ID()) {
        MPrintColor c = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
        if (c.getColor() != null)
            color = c.getColor();
    }
    //	default
    Font font = m_printFont.getFont();
    if (item.getAD_PrintFont_ID() != 0 && m_printFont.get_ID() != item.getAD_PrintFont_ID()) {
        MPrintFont f = MPrintFont.get(item.getAD_PrintFont_ID());
        if (f.getFont() != null)
            font = f.getFont();
    }
    //	Create String, HTML or Location
    PrintElement e = null;
    if (data.getDisplayType() == DisplayType.Location) {
        e = new LocationElement(m_printCtx, ((KeyNamePair) ID).getKey(), font, color, item.isHeightOneLine(), label, labelSuffix, m_format.getLanguage().getAD_Language());
        e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
    } else {
        if (HTMLElement.isHTML(stringContent))
            e = new HTMLElement(stringContent);
        else
            e = new StringElement(content, font, color, isForm ? null : ID, label, labelSuffix);
        e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
    }
    return e;
}
Also used : Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) MPrintFont(org.compiere.print.MPrintFont) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font) PrintDataElement(org.compiere.print.PrintDataElement) MPrintColor(org.compiere.print.MPrintColor) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

Example 3 with MPrintColor

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

the class POSKeyPanel method createCard.

/**
	 * @return
	 */
private CPanel createCard(int posKeyLayoutId) {
    // already added
    if (keyMaps.containsKey(posKeyLayoutId)) {
        return null;
    }
    CPanel card = new CPanel();
    card.setLayout(new MigLayout("fill, ins 0"));
    MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), posKeyLayoutId);
    Color stdColor = Color.lightGray;
    if (keyLayout.getAD_PrintColor_ID() != 0) {
        MPrintColor color = MPrintColor.get(Env.getCtx(), keyLayout.getAD_PrintColor_ID());
        stdColor = color.getColor();
    }
    Font stdFont = AdempierePLAF.getFont_Field();
    if (keyLayout.getAD_PrintFont_ID() != 0) {
        MPrintFont font = MPrintFont.get(keyLayout.getAD_PrintFont_ID());
        stdFont = font.getFont();
    }
    if (keyLayout.get_ID() == 0)
        return null;
    MPOSKey[] keys = keyLayout.getKeys(false);
    HashMap<Integer, MPOSKey> map = new HashMap<Integer, MPOSKey>(keys.length);
    keyMaps.put(posKeyLayoutId, map);
    //	Min Columns
    int COLUMNS = 3;
    //	Min Rows
    int ROWS = 3;
    int noKeys = keys.length;
    int cols = keyLayout.getColumns();
    if (cols == 0)
        cols = COLUMNS;
    int buttons = 0;
    log.fine("PosSubFunctionKeys.init - NoKeys=" + noKeys + ", Cols=" + cols);
    //	Content
    CPanel content = new CPanel(new MigLayout("fill, wrap " + Math.max(cols, 3)));
    String buttonSize = "h 50, w 50, growx, growy, sg button,";
    for (MPOSKey key : keys) {
        if (key.getSubKeyLayout_ID() > 0) {
            CPanel subCard = createCard(key.getSubKeyLayout_ID());
            if (subCard != null)
                add(subCard, Integer.toString(key.getSubKeyLayout_ID()));
        }
        map.put(key.getC_POSKey_ID(), key);
        Color keyColor = stdColor;
        Font keyFont = stdFont;
        StringBuffer buttonHTML = new StringBuffer("<html><p>");
        if (key.getAD_PrintColor_ID() != 0) {
            MPrintColor color = MPrintColor.get(Env.getCtx(), key.getAD_PrintColor_ID());
            keyColor = color.getColor();
        }
        if (key.getAD_PrintFont_ID() != 0) {
            MPrintFont font = MPrintFont.get(key.getAD_PrintFont_ID());
            keyFont = font.getFont();
        }
        buttonHTML.append(key.getName());
        buttonHTML.append("</p></html>");
        log.fine("#" + map.size() + " - " + keyColor);
        CButton button = new CButton(buttonHTML.toString());
        button.setBackground(keyColor);
        button.setFont(keyFont);
        if (key.getAD_Image_ID() != 0) {
            MImage image = MImage.get(Env.getCtx(), key.getAD_Image_ID());
            Image img = image.getImage();
            //	https://github.com/erpcya/AD-POS-WebUI/issues/29
            //	Change Image Size
            Image imgResized = img.getScaledInstance(IMAGE_SIZE, IMAGE_SIZE, Image.SCALE_SMOOTH);
            button.setIcon(new ImageIcon(imgResized));
            button.setVerticalTextPosition(SwingConstants.BOTTOM);
            button.setHorizontalTextPosition(SwingConstants.CENTER);
        }
        button.setFocusable(false);
        if (!key.isActive())
            button.setEnabled(false);
        button.setActionCommand(String.valueOf(key.getC_POSKey_ID()));
        button.addActionListener(this);
        String constraints = buttonSize;
        int size = 1;
        if (key.getSpanX() > 1) {
            constraints += "spanx " + key.getSpanX() + ",";
            size = key.getSpanX();
        }
        if (key.getSpanY() > 1) {
            constraints += "spany " + key.getSpanY() + ",";
            size = size * key.getSpanY();
        }
        buttons = buttons + size;
        content.add(button, constraints);
    }
    int rows = Math.max((buttons / cols), ROWS);
    if (buttons % cols > 0)
        rows = rows + 1;
    for (int i = buttons; i < rows * cols; i++) {
        CButton button = new CButton("");
        button.setFocusable(false);
        button.setReadWrite(false);
        content.add(button, buttonSize);
    }
    CScrollPane scroll = new CScrollPane(content);
    // scroll.setPreferredSize(new Dimension( 600 - 20, 400-20));
    card.add(scroll, "growx, growy");
    // increase scrollbar width for touchscreen
    scroll.getVerticalScrollBar().setPreferredSize(new Dimension(30, 0));
    scroll.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 30));
    return card;
}
Also used : ImageIcon(javax.swing.ImageIcon) HashMap(java.util.HashMap) MPOSKeyLayout(org.compiere.model.MPOSKeyLayout) CScrollPane(org.compiere.swing.CScrollPane) MigLayout(net.miginfocom.swing.MigLayout) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) CPanel(org.compiere.swing.CPanel) MPrintFont(org.compiere.print.MPrintFont) Dimension(java.awt.Dimension) Image(java.awt.Image) MImage(org.compiere.model.MImage) Font(java.awt.Font) MPrintFont(org.compiere.print.MPrintFont) MImage(org.compiere.model.MImage) MPrintColor(org.compiere.print.MPrintColor) MPOSKey(org.compiere.model.MPOSKey) CButton(org.compiere.swing.CButton)

Example 4 with MPrintColor

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

the class WPOSKeyPanel method createButton.

/**
	 * Create Buttton For Keyboard
	 * @param C_POSKeyLayout_ID
	 * @param m_txtCalc
	 * @return
	 * @return Panel
	 */
private Panel createButton(int C_POSKeyLayout_ID, String m_txtCalc) {
    // already added
    if (keymap.containsKey(C_POSKeyLayout_ID)) {
        return null;
    }
    Panel card = new Panel();
    MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), C_POSKeyLayout_ID);
    Color stdColor = Color.lightGray;
    if (keyLayout.getAD_PrintColor_ID() != 0) {
        MPrintColor color = MPrintColor.get(Env.getCtx(), keyLayout.getAD_PrintColor_ID());
        stdColor = color.getColor();
    }
    if (keyLayout.get_ID() == 0)
        return null;
    MPOSKey[] keys = keyLayout.getKeys(false);
    HashMap<Integer, MPOSKey> map = new HashMap<Integer, MPOSKey>(keys.length);
    keymap.put(C_POSKeyLayout_ID, map);
    //	Min Columns
    int COLUMNS = 3;
    //	Min Rows
    int ROWS = 3;
    int noKeys = keys.length;
    int cols = keyLayout.getColumns();
    if (cols == 0)
        cols = COLUMNS;
    int buttons = 0;
    log.fine("PosSubFunctionKeys.init - NoKeys=" + noKeys + ", Cols=" + cols);
    //	Content
    Panel content = new Panel();
    for (MPOSKey key : keys) {
        map.put(key.getC_POSKey_ID(), key);
        Color keyColor = stdColor;
        if (key.getAD_PrintColor_ID() != 0) {
            MPrintColor color = MPrintColor.get(Env.getCtx(), key.getAD_PrintColor_ID());
            keyColor = color.getColor();
        }
        log.fine("#" + map.size() + " - " + keyColor);
        Panel button = new Panel();
        Label label = new Label(key.getName());
        label.setStyle("margin: 25px 0px 00px 0px; top:20px; font-size:medium; font-weight: bold;");
        label.setHeight("100%");
        button.appendChild(label);
        button.setClass("z-button");
        button.setStyle("float:left; white-space: pre-line;text-align:center; margin:0.4% 1%; Background-color:rgb(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + "); border: 2px outset #CCC; " + "background: -moz-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);" + "background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(247,247,247,1)), color-stop(7%, rgba(255,255,255,0.93)), color-stop(15%, rgba(186,186,186,0.25)), color-stop(100%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1)));" + "background: -webkit-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);");
        button.setHeight("55px");
        button.setWidth("55px");
        button.setAction("onClick : text_action.textEvent('" + m_txtCalc + "', '" + key.getText() + "', '" + this.keyBoardType + "')");
        button.setId("" + key.getC_POSKey_ID());
        button.addEventListener("onClick", this);
        int size = 1;
        if (key.getSpanX() > 1) {
            size = key.getSpanX();
        }
        if (key.getSpanY() > 1) {
            size = size * key.getSpanY();
        }
        buttons = buttons + size;
        content.appendChild(button);
    }
    int rows = Math.max((buttons / cols), ROWS);
    if (buttons % cols > 0)
        rows = rows + 1;
    for (int i = buttons; i < rows * cols; i++) {
        Panel button = new Panel();
        button.setStyle("float:left; text-align:center; margin:0.4% 1%;");
        button.setHeight("55px");
        button.setWidth("55px");
        content.appendChild(button);
    }
    card.appendChild(content);
    return card;
}
Also used : Panel(org.adempiere.webui.component.Panel) HashMap(java.util.HashMap) MPOSKeyLayout(org.compiere.model.MPOSKeyLayout) MPrintColor(org.compiere.print.MPrintColor) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) Label(org.adempiere.webui.component.Label) MPOSKey(org.compiere.model.MPOSKey)

Example 5 with MPrintColor

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

the class WPOSKeyPanel method createButton.

/**
	 * Create Button
	 * @param C_POSKeyLayout_ID
	 * @return
	 * @return Panel
	 */
public Panel createButton(int C_POSKeyLayout_ID) {
    if (keymap.containsKey(C_POSKeyLayout_ID)) {
        return null;
    }
    Panel card = new Panel();
    card.setWidth("100%");
    MPOSKeyLayout keyLayout = MPOSKeyLayout.get(Env.getCtx(), C_POSKeyLayout_ID);
    Color stdColor = Color.lightGray;
    if (keyLayout.getAD_PrintColor_ID() != 0) {
        MPrintColor color = MPrintColor.get(Env.getCtx(), keyLayout.getAD_PrintColor_ID());
        stdColor = color.getColor();
    }
    if (keyLayout.get_ID() == 0)
        return null;
    MPOSKey[] keys = keyLayout.getKeys(false);
    HashMap<Integer, MPOSKey> map = new HashMap<Integer, MPOSKey>(keys.length);
    keymap.put(C_POSKeyLayout_ID, map);
    //	Min Columns
    int COLUMNS = 3;
    //	Min Rows
    int ROWS = 3;
    int noKeys = keys.length;
    int cols = keyLayout.getColumns();
    if (cols == 0)
        cols = COLUMNS;
    int buttons = 0;
    log.fine("PosSubFunctionKeys.init - NoKeys=" + noKeys + ", Cols=" + cols);
    //	Content
    Panel content = new Panel();
    for (MPOSKey key : keys) {
        if (!key.getName().equals("")) {
            map.put(key.getC_POSKey_ID(), key);
            Color keyColor = stdColor;
            if (key.getAD_PrintColor_ID() != 0) {
                MPrintColor color = MPrintColor.get(Env.getCtx(), key.getAD_PrintColor_ID());
                keyColor = color.getColor();
            }
            log.fine("#" + map.size() + " - " + keyColor);
            Panel button = new Panel();
            Label label = new Label(key.getName());
            Center nt = new Center();
            South st = new South();
            Borderlayout mainLayout = new Borderlayout();
            if (key.getAD_Image_ID() != 0) {
                MImage m_mImage = MImage.get(Env.getCtx(), key.getAD_Image_ID());
                AImage img = null;
                byte[] data = m_mImage.getData();
                if (data != null && data.length > 0) {
                    try {
                        img = new AImage(null, data);
                    } catch (Exception e) {
                    }
                }
                Image bImg = new Image();
                bImg.setContent(img);
                bImg.setWidth("66%");
                bImg.setHeight("80%");
                nt.appendChild(bImg);
            }
            label.setStyle("word-wrap: break-word; white-space: pre-line;margin: 25px 0px 0px 0px; top:20px; font-size:10pt; font-weight: bold;color: #FFF;");
            label.setHeight("100%");
            button.setHeight("100px");
            st.appendChild(label);
            button.setClass("z-button");
            button.setStyle("float:left; white-space: pre-line;text-align:center; margin:0.4% 1%; Background-color:rgb(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + "); border: 2px outset #CCC; " + "background: -moz-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);" + "background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(247,247,247,1)), color-stop(7%, rgba(255,255,255,0.93)), color-stop(15%, rgba(186,186,186,0.25)), color-stop(100%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1)));" + "background: -webkit-linear-gradient(top, rgba(247,247,247,1) 0%, rgba(255,255,255,0.93) 7%, rgba(186,186,186,0.25) 15%, rgba(" + keyColor.getRed() + "," + keyColor.getGreen() + "," + keyColor.getBlue() + ",1) 100%);");
            mainLayout.appendChild(nt);
            mainLayout.appendChild(st);
            mainLayout.setStyle("background-color: transparent");
            nt.setStyle("background-color: transparent");
            st.setStyle("clear: both; background-color: #333; opacity: 0.6;");
            st.setZindex(99);
            button.appendChild(mainLayout);
            button.setId("" + key.getC_POSKey_ID());
            button.addEventListener("onClick", this);
            int size = 1;
            if (key.getSpanX() > 1) {
                size = key.getSpanX();
                button.setWidth("96%");
            } else
                button.setWidth(90 / cols + "%");
            if (key.getSpanY() > 1) {
                size = size * key.getSpanY();
            }
            buttons = buttons + size;
            content.appendChild(button);
        }
    }
    int rows = Math.max((buttons / cols), ROWS);
    if (buttons % cols > 0)
        rows = rows + 1;
    card.appendChild(content);
    return card;
}
Also used : Center(org.zkoss.zkex.zul.Center) HashMap(java.util.HashMap) MPOSKeyLayout(org.compiere.model.MPOSKeyLayout) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) Label(org.adempiere.webui.component.Label) South(org.zkoss.zkex.zul.South) Borderlayout(org.adempiere.webui.component.Borderlayout) AImage(org.zkoss.image.AImage) Image(org.zkoss.zul.Image) MImage(org.compiere.model.MImage) Panel(org.adempiere.webui.component.Panel) MImage(org.compiere.model.MImage) MPrintColor(org.compiere.print.MPrintColor) AImage(org.zkoss.image.AImage) MPOSKey(org.compiere.model.MPOSKey)

Aggregations

MPrintColor (org.compiere.print.MPrintColor)9 Color (java.awt.Color)8 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 MPrintFont (org.compiere.print.MPrintFont)5 MPOSKey (org.compiere.model.MPOSKey)4 MPOSKeyLayout (org.compiere.model.MPOSKeyLayout)4 MImage (org.compiere.model.MImage)3 Dimension (java.awt.Dimension)2 MigLayout (net.miginfocom.swing.MigLayout)2 Label (org.adempiere.webui.component.Label)2 Panel (org.adempiere.webui.component.Panel)2 PrintDataElement (org.compiere.print.PrintDataElement)2 CButton (org.compiere.swing.CButton)2 CPanel (org.compiere.swing.CPanel)2 CScrollPane (org.compiere.swing.CScrollPane)2 KeyNamePair (org.compiere.util.KeyNamePair)2 ValueNamePair (org.compiere.util.ValueNamePair)2 Image (java.awt.Image)1 Point (java.awt.Point)1