// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:47:50
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   labelAImprimir.java

package project;

import java.awt.*;
import java.awt.geom.RectangularShape;
import java.awt.print.*;
import javax.swing.ImageIcon;
import traduccion.Traducir;

// Referenced classes of package project:
//            JLabel, AccederADatos, ImprimirCertificado, LeerConfiguracion

public class labelAImprimir extends JLabel
    implements Printable
{

    public labelAImprimir(ImprimirCertificado imprimirCertificado2)
    {
        paper = new Paper();
        imprimirCertificado = imprimirCertificado2;
    }

    public void imprime()
    {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        PageFormat pf = new PageFormat();
        paper.setSize(595D, 870D);
        paper.setImageableArea(30D, 18D, 535D, 809D);
        pf.setPaper(paper);
        printJob.setPrintable(this, pf);
        if(printJob.printDialog())
            try
            {
                printJob.print();
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
    }

    public int print(Graphics g, PageFormat pf, int pi)
        throws PrinterException
    {
        int tamaF1oFuente = 25;
        Font f1 = new Font("Arial", 1, tamaF1oFuente);
        if(pi >= 1)
            return 1;
        paint(g);
        ImageIcon icon = new ImageIcon((project.Frame1.class).getResource(Traducir.getTraduccion(AccederADatos.leer("h.proyecto"), "project.labelAImprimir", "200411221440", AccederADatos.idioma)));
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.drawImage(icon.getImage(), (int)pf.getImageableX(), (int)pf.getImageableY(), this);
        String text = imprimirCertificado.nb + " " + imprimirCertificado.ap1 + " " + imprimirCertificado.ap2;
        g.setFont(f1);
        java.awt.geom.Rectangle2D rect;
        for(rect = f1.getStringBounds(text, g2.getFontRenderContext()); rect.getWidth() > 426D && tamaF1oFuente > 1; rect = f1.getStringBounds(text, g2.getFontRenderContext()))
        {
            tamaF1oFuente--;
            f1 = new Font("Arial", 1, tamaF1oFuente);
            g.setFont(f1);
        }

        g.drawString(text, (int)(paper.getWidth() - (double)(int)rect.getWidth()) / 2, 250);
        tamaF1oFuente = 16;
        f1 = new Font("Arial", 1, tamaF1oFuente);
        g.setFont(f1);
        String array[] = Traducir.getTraduccion(AccederADatos.leer("h.proyecto"), "project.labelAImprimir", "200501181721", AccederADatos.idioma).split("-br-");
        for(int i = 0; i < array.length; i++)
        {
            text = array[i];
            for(rect = f1.getStringBounds(text, g2.getFontRenderContext()); rect.getWidth() > 426D && tamaF1oFuente > 1; rect = f1.getStringBounds(text, g2.getFontRenderContext()))
            {
                tamaF1oFuente--;
                f1 = new Font("Arial", 1, tamaF1oFuente);
                g.setFont(f1);
            }

            g.drawString(text, (int)(paper.getWidth() - (double)(int)rect.getWidth()) / 2, 325 + i * 25);
        }

        tamaF1oFuente = 25;
        f1 = new Font("Arial", 1, tamaF1oFuente);
        g.setFont(f1);
        text = imprimirCertificado.leerConfiguracion.NModulo + "................" + Traducir.getTraduccion(AccederADatos.leer("h.proyecto"), "project.labelAImprimir", "200501181647", AccederADatos.idioma) + " " + imprimirCertificado.Niv.substring(1);
        for(rect = f1.getStringBounds(text, g2.getFontRenderContext()); rect.getWidth() > 426D && tamaF1oFuente > 1; rect = f1.getStringBounds(text, g2.getFontRenderContext()))
        {
            tamaF1oFuente--;
            f1 = new Font("Arial", 1, tamaF1oFuente);
            g.setFont(f1);
        }

        g.drawString(text, (int)(paper.getWidth() - (double)(int)rect.getWidth()) / 2, 500);
        return 0;
    }

    ImprimirCertificado imprimirCertificado;
    Paper paper;
}