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 BlurredIcon extends JFrame
{

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

    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("jyloo.png"));
    BufferedImage image = new BufferedImage(icon.getWidth(), icon.getHeight(), BufferedImage.TYPE_INT_ARGB);
    image.createGraphics().drawImage(icon, 0, 0, null);
    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 blurredIcon = Synthetica2DUtils.createBlurredImage(icon, i); 
      BufferedImage blurredIcon = Synthetica2DUtils.createBlurredImage(image, i);
//@/highlight
      label.setIcon(new ImageIcon(blurredIcon));
      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 BlurredIcon();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }

}
