/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csa.gui.panels;

import csa.gui.border.ImageBorder;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;

/**
 *
 * @author salchr
 */
public class LateBorderPanel extends javax.swing.JPanel {

    
    ImageBorder lateBorder = null;
    
    /**
     * Creates new form LateBorderPanel
     */
    BufferedImage center = null;
    public LateBorderPanel() {
        initComponents();
        center = csa.util.UtilityImage.loadImage("images\\border\\clay_center.png");
        BufferedImage tc = csa.util.UtilityImage.loadImage("images\\border\\clay_t_c.png");
        BufferedImage rc = csa.util.UtilityImage.loadImage("images\\border\\clay_r_c.png");
        BufferedImage lc = csa.util.UtilityImage.loadImage("images\\border\\clay_l_c.png");
        BufferedImage bc = csa.util.UtilityImage.loadImage("images\\border\\clay_b_c.png");
        BufferedImage tr = csa.util.UtilityImage.loadImage("images\\border\\clay_t_r_alt.png");
        BufferedImage tl = csa.util.UtilityImage.loadImage("images\\border\\clay_t_l.png");
        BufferedImage br = csa.util.UtilityImage.loadImage("images\\border\\clay_b_r.png");
        BufferedImage bl = csa.util.UtilityImage.loadImage("images\\border\\clay_b_l.png");
        
        if (tc != null)
            lateBorder = new ImageBorder(tr,tc,tl,rc,lc,br,bc,bl);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables


    public void fillTexture(Graphics2D g2, BufferedImage buff, int x, int y, int w, int h) {
      Rectangle anchor = new Rectangle(x, y, buff.getWidth(null), buff.getHeight(null));
      TexturePaint paint = new TexturePaint(buff, anchor);
      g2.setPaint(paint);
      g2.fillRect(x, y, w, h);
    }
    /*
    public boolean isOptimizedDrawingEnabled()
    {
        return false;
    }
*/
    @Override public void paintComponent(Graphics g1)
    {
        super.paintComponent(g1);
    }
    @Override public void paintChildren(Graphics g1)
    {
        if (center!=null)
        {
            fillTexture((Graphics2D)g1, center, 0, 0, getWidth(), getHeight());
        }
        super.paintChildren(g1);
        if (lateBorder!=null)
        {
            lateBorder.paintLateBorder(this, g1, 0, 0, getWidth(), getHeight());
        }
    }

}
