Search in sources :

Example 1 with MImage

use of org.compiere.model.MImage in project adempiere by adempiere.

the class SmjPdfReport method generate.

/**
	 * genera el PDF en un ByteArrayOutputStream ** Generate PDF Report into
	 * ByteArrayOutputStream
	 * 
	 * @return ByteArrayOutputStream
	 */
public ByteArrayOutputStream generate(LinkedList<ReportTO> dataReport, String nameTrx, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String codeFont, String city, Integer logoId) {
    baosPDF = new ByteArrayOutputStream();
    data = dataReport;
    String[] fontPar = codeFont.split("-");
    Integer lFont = Integer.parseInt(fontPar[2]);
    titleFont = FontFactory.getFont(fontPar[0], lFont + 5, Font.BOLDITALIC);
    titleTableFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLDITALIC);
    catFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLD);
    subFont = FontFactory.getFont(fontPar[0], lFont, Font.NORMAL);
    try {
        // izq-der-arrib
        document = new Document(PageSize.LETTER, 20, 20, 20, 40);
        writer = PdfWriter.getInstance(document, baosPDF);
        document.open();
        // metadata del documento
        document.addTitle(generalTitle[0]);
        document.addAuthor("SmartJSP S.A.S.");
        document.addCreator("SmartJSP S.A.S.");
        onOpenDocument(writer, document);
        onEndPage(writer, document);
        // //////////////////////////////////////////////////////////////////////////////////////
        // agrega el logo
        // add logo
        java.awt.Image img;
        if (logoId > 0) {
            MImage mimage = MImage.get(Env.getCtx(), logoId);
            byte[] imageData = mimage.getData();
            img = Toolkit.getDefaultToolkit().createImage(imageData);
        } else {
            // 48x15
            img = org.compiere.Adempiere.getImageLogoSmall(true);
        }
        com.lowagie.text.Image logo = com.lowagie.text.Image.getInstance(img, null);
        logo.scaleToFit(100, 30);
        document.add(logo);
        // Titulo General - general Title
        Paragraph genTitle = new Paragraph(dataNull(generalTitle[0]).toUpperCase(), titleFont);
        genTitle.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(genTitle);
        // empresa - Company
        Paragraph clitName = new Paragraph(dataNull(clientName).toUpperCase(), titleFont);
        clitName.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(clitName);
        // Ciudad - City
        Paragraph cliCity = new Paragraph(dataNull(city).toUpperCase(), titleFont);
        cliCity.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(cliCity);
        // NIT
        Paragraph cliNIT = new Paragraph(dataNull(clientNIT).toUpperCase(), titleFont);
        cliNIT.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(cliNIT);
        // periodo - Period
        String pn = "";
        if (generalTitle[1] != null && generalTitle[1].length() > 0) {
            pn = generalTitle[1] + " " + periodName;
        } else {
            pn = periodName;
        }
        if (generalTitle[2] != null && generalTitle[2].length() > 0) {
            pn = pn + " " + generalTitle[2];
        }
        Paragraph perName = new Paragraph(dataNull(pn).toUpperCase(), titleTableFont);
        perName.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(perName);
        // tipo moneda - currency
        Paragraph currency = new Paragraph(dataNull(currencyName), titleTableFont);
        currency.setAlignment(Paragraph.ALIGN_CENTER);
        addEmptyLine(currency, 2);
        document.add(currency);
        cols = m_columns.length + 2;
        float[] columnWidths = new float[cols];
        columnWidths[0] = 1f;
        columnWidths[1] = 3f;
        for (int i = 2; i < cols; i++) {
            columnWidths[i] = 1f;
        }
        table = new PdfPTable(columnWidths);
        // //Titulos de la tabla - Table titles
        // Nombre - name
        PdfPCell cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "name").toUpperCase(), catFont));
        cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
        cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cellTitle);
        // Desripcion - description
        cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "description").toUpperCase(), catFont));
        cellTitle.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
        cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cellTitle);
        // columnas de valores - Value Columns
        for (MReportColumn mcol : m_columns) {
            String colName = mcol.getName();
            cellTitle = new PdfPCell(new Paragraph(colName.toUpperCase(), catFont));
            cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
            cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
            table.addCell(cellTitle);
        }
        //for columnas
        // TABLA DEL REPORTE - REPORT TABLE
        reportTable();
        document.add(table);
        // funciones que ponen el pie del porte - put footer
        onEndPage(writer, document);
        onCloseDocument(writer, document);
        document.close();
    } catch (Exception e) {
        System.out.println("SMpdfReport(generar)ERROR:: al crear el documento PDF");
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    return baosPDF;
}
Also used : PdfPCell(com.lowagie.text.pdf.PdfPCell) MReportColumn(org.compiere.report.MReportColumn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Paragraph(com.lowagie.text.Paragraph) MImage(org.compiere.model.MImage) PdfPTable(com.lowagie.text.pdf.PdfPTable)

Example 2 with MImage

use of org.compiere.model.MImage in project adempiere by adempiere.

the class ImageElement method loadFromDB.

//	getURL;
/**
	 * 	Load from DB
	 * 	@param record_ID record id
	 */
private void loadFromDB(int record_ID) {
    MImage mimage = MImage.get(Env.getCtx(), record_ID);
    if (mimage == null) {
        log.log(Level.WARNING, "No Image - record_ID=" + record_ID);
        return;
    }
    byte[] imageData = mimage.getData();
    if (imageData != null)
        try {
            BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData));
            m_image = bufferedImage;
        } catch (Exception e) {
            log.log(Level.WARNING, "(byteArray)", e);
        }
    if (m_image != null)
        log.fine(mimage.toString() + " - Size=" + imageData.length);
    else
        log.log(Level.WARNING, mimage.toString() + " - not loaded (must be gif or jpg) - record_ID=" + record_ID);
}
Also used : MImage(org.compiere.model.MImage) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedImage(java.awt.image.BufferedImage) MalformedURLException(java.net.MalformedURLException)

Example 3 with MImage

use of org.compiere.model.MImage 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 MImage

use of org.compiere.model.MImage in project adempiere by adempiere.

the class ImportEmployee method importEmployeeImages.

/**
     * import employee images based on import employee table
     * @param importEmployee
     */
private void importEmployeeImages(X_I_HR_Employee importEmployee) {
    String fileName = importEmployee.getFile_Directory();
    String imageEmployeeName = importEmployee.getBPartnerValue();
    String logoEmployeeName = "Logo" + importEmployee.getBPartnerValue();
    String thumbEmployeeName = "Thumb" + importEmployee.getBPartnerValue();
    String path = fileName + "/" + imageEmployeeName;
    byte[] imageEmployee = getImage(path + ".jpg");
    if (imageEmployee == null)
        imageEmployee = getImage(path + ".JPG");
    if (imageEmployee == null)
        imageEmployee = getImage(path + ".png");
    if (imageEmployee == null)
        imageEmployee = getImage(path + ".PNG");
    if (imageEmployee != null && imageEmployee.length > 0) {
        MImage image = MImage.get(Env.getCtx(), 0);
        image.setName(imageEmployeeName);
        image.setImageURL(imageEmployeeName);
        image.setBinaryData(imageEmployee);
        image.saveEx();
        importEmployee.setEmployeeImage_ID(image.getAD_Image_ID());
        importEmployee.saveEx();
    }
    path = fileName + "/" + logoEmployeeName;
    byte[] logoEmployee = getImage(path + ".jpg");
    if (logoEmployee == null)
        logoEmployee = getImage(path + ".JPG");
    if (logoEmployee == null)
        logoEmployee = getImage(path + ".png");
    if (logoEmployee == null)
        logoEmployee = getImage(path + ".PNG");
    if (logoEmployee != null && logoEmployee.length > 0) {
        MImage image = MImage.get(Env.getCtx(), 0);
        image.setName(logoEmployeeName);
        image.setImageURL(logoEmployeeName);
        image.setBinaryData(logoEmployee);
        image.saveEx();
        importEmployee.setLogo_ID(image.getAD_Image_ID());
        importEmployee.saveEx();
    }
    path = fileName + "/" + thumbEmployeeName;
    byte[] thumbEmployee = getImage(path + ".jpg");
    if (thumbEmployee == null)
        thumbEmployee = getImage(path + ".JPG");
    if (thumbEmployee == null)
        thumbEmployee = getImage(path + ".png");
    if (thumbEmployee == null)
        thumbEmployee = getImage(path + ".PNG");
    if (thumbEmployee != null && thumbEmployee.length > 0) {
        MImage image = MImage.get(Env.getCtx(), 0);
        image.setName(thumbEmployeeName);
        image.setImageURL(thumbEmployeeName);
        image.setBinaryData(thumbEmployee);
        image.saveEx();
        importEmployee.setThumbImage_ID(image.getAD_Image_ID());
        importEmployee.saveEx();
    }
}
Also used : MImage(org.compiere.model.MImage)

Example 5 with MImage

use of org.compiere.model.MImage 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

MImage (org.compiere.model.MImage)11 Color (java.awt.Color)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 MPOSKey (org.compiere.model.MPOSKey)3 MPOSKeyLayout (org.compiere.model.MPOSKeyLayout)3 MPrintColor (org.compiere.print.MPrintColor)3 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)2 Dimension (java.awt.Dimension)2 Font (java.awt.Font)2 BufferedImage (java.awt.image.BufferedImage)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MigLayout (net.miginfocom.swing.MigLayout)2 MPrintFont (org.compiere.print.MPrintFont)2 CButton (org.compiere.swing.CButton)2 CPanel (org.compiere.swing.CPanel)2 CScrollPane (org.compiere.swing.CScrollPane)2 Document (com.lowagie.text.Document)1 Paragraph (com.lowagie.text.Paragraph)1