/**
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 *
 * Copyright (C)
 * <a href="http://www.inab.org">Spanish National Institute of Bioinformatics (INB)</a>
 * <a href="http://www.bsc.es">Barcelona Supercomputing Center (BSC)</a>
 * <a href="http://inb.bsc.es">Computational Node 6</a>
 */

package org.inb.biomoby.client.gui.auxiliary;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import org.inb.biomoby.client.gui.swing.border.RoundedBorder;

/**
 * @author Dmitry Repchevsky
 */

public class ImageComponent extends JPanel
{
    private BufferedImage image;
    
    public ImageComponent(BufferedImage image)
    {
        this.image = image;
        
        setBorder(new RoundedBorder(4, Color.BLUE));
    }
    
    @Override
    public Dimension getPreferredSize()
    {
        if (image != null)
        {
           return new Dimension(image.getWidth(), image.getHeight());
        }
        
        return super.getPreferredSize();
    }
    
    @Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D)g.create();
        
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        if (image != null)
        {
            g2d.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
        }
    }
}
