package de.javasoft.synthetica.democenter.examples.tips.imageprocessing;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import de.javasoft.util.java2d.Synthetica2DUtils;

/**
 * Demonstrates how to colorize an existing image.  
 */
@SuppressWarnings("serial")
public class ColorizeIcon extends JFrame
{

  public ColorizeIcon() throws IOException
  {
    super("ColorizedIcon");

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setBorder(new EmptyBorder(10,10,10,10));

    BufferedImage icon = ImageIO.read(this.getClass().getResource("printer.png"));
    for (float i = 0.0f; i <= 1.0f; i += 0.10f)
    {  
      JLabel label = new JLabel(String.format("Alpha value for colorizing: %.2f", i));
      label.setHorizontalTextPosition(JLabel.LEADING);
//@highlight
      BufferedImage colorizedIcon = Synthetica2DUtils.createColorizedImage(icon, Color.RED, i); 
//@/highlight
      label.setIcon(new ImageIcon(colorizedIcon));
      panel.add(label);
    }
    getContentPane().add(panel);
    
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);        //center
    setVisible(true);
  }
  
  /**
   * Static main method for application startup. 
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel");
          new ColorizeIcon();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

}
