package de.tudresden.inf.lat.born.gui;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
 * This manages the icons.
 * 
 * @author Julian Mendez
 *
 */
public class BornIcon {

	public static final String OPEN_FILE_PATH = "icons/openfolder.png";
	public static final String SAVE_FILE_PATH = "icons/floppydisk.png";
	public static final String RUN_PATH = "icons/play.png";
	public static final String REFRESH_PATH = "icons/refresh.png";

	public static final int DEFAULT_ICON_SIZE = 24;

	public static final ImageIcon OPEN_FILE = createIcon(OPEN_FILE_PATH, DEFAULT_ICON_SIZE);
	public static final ImageIcon SAVE_FILE = createIcon(SAVE_FILE_PATH, DEFAULT_ICON_SIZE);
	public static final ImageIcon RUN = createIcon(RUN_PATH, DEFAULT_ICON_SIZE);
	public static final ImageIcon REFRESH = createIcon(REFRESH_PATH, DEFAULT_ICON_SIZE);

	/**
	 * Creates an icon with the given size. If the path is invalid, this method
	 * returns <code>null</code>.
	 * 
	 * @param path
	 *            path of icon
	 * @param size
	 *            size of icon
	 * @return an icon with the given size, or <code>null</code> if the path is
	 *         invalid
	 */
	public static ImageIcon createIcon(String path, int size) {
		ImageIcon ret = null;
		try {
			URL url = BornIcon.class.getClassLoader().getResource(path);
			if (url == null) {
				try {
					throw new IllegalArgumentException("Icon has an invalid path: '" + path + "'.");
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				}

			} else {
				BufferedImage img = ImageIO.read(url);
				ret = new ImageIcon(img.getScaledInstance(size, size, Image.SCALE_SMOOTH));

			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return ret;
	}

}

@@ -324,16 +324,21 @@
  String 
+PATH_
 OPEN_FIL
@@ -334,29 +334,24 @@
 TH_OPEN_FILE
-_PATH
  = %22icons/op
@@ -393,16 +393,21 @@
  String 
+PATH_
 SAVE_FIL
@@ -407,21 +407,16 @@
 AVE_FILE
-_PATH
  = %22icon
@@ -462,24 +462,24 @@
  String 
-RUN_
 PATH
+_RUN
  = %22icon
@@ -519,28 +519,28 @@
  String 
+PATH_
 REFRESH
-_PATH
  = %22icon
@@ -660,24 +660,29 @@
 ateIcon(
+PATH_
 OPEN_FIL
 E_PATH, 
@@ -677,32 +677,8 @@
 _FIL
-E_PATH, DEFAULT_ICON_SIZ
 E);%0A
@@ -731,16 +731,21 @@
 ateIcon(
+PATH_
 SAVE_FIL
@@ -749,32 +749,8 @@
 FILE
-_PATH, DEFAULT_ICON_SIZE
 );%0A%09
@@ -800,35 +800,16 @@
 con(
-RUN_PATH, DEFAULT_ICON_SIZE
+PATH_RUN
 );%0A%09
@@ -863,39 +863,20 @@
 con(
+PATH_
 REFRESH
-_PATH, DEFAULT_ICON_SIZE
 );%0A%0A
@@ -1749,10 +1749,219 @@
 et;%0A%09%7D%0A%0A
+%09/**%0A%09 * Returns an icon created with the default size for the given path.%0A%09 * %0A%09 * @path path of icon%0A%09 */%0A%09public static ImageIcon createIcon(String path) %7B%0A%09%09return createIcon(path, DEFAULT_ICON_SIZE);%0A%09%7D%0A%0A
 %7D%0A

Simplify creation of icons