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

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 blur an existing image.  
 */
@SuppressWarnings("serial")
public class BluredIcon extends JFrame
{

  public BluredIcon() throws IOException
  {
    super("BluredIcon");

    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("javaCup.png"));
    for (int i = 1; i <= 5; i += 1)
    {  
      JLabel label = new JLabel(String.format("Used blur size: %d", i));
      label.setHorizontalTextPosition(JLabel.LEADING);
//@highlight
      BufferedImage bluredIcon = Synthetica2DUtils.createBluredImage(icon, i); 
//@/highlight
      label.setIcon(new ImageIcon(bluredIcon));
      panel.add(label);
    }
    getContentPane().add(panel);
    
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(300, 250);
    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 BluredIcon();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

}
