package be.msyben.vinylManager.gui.icon;

import be.msyben.vinylManager.tools.Tools;
import be.msyben.vinylManager.tools.log.VinylManagerLogger;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
 * Cette classe permet de stocker les icones.
 * @author Mathieu Syben
 */
public final class Icons {

    /**
     * l'étoile vide
     */
    public ImageIcon etoileVide = new ImageIcon();
    /**
     * l'étoile pleine
     */
    public ImageIcon etoilePlein = new ImageIcon();
    /**
     * l'étoile mi pleine
     */
    public ImageIcon etoileDemi = new ImageIcon();
    /**
     * L'icône de fenetre
     */
    public ImageIcon icon = new ImageIcon();
    /**
     * L'icone de fleche
     */
    public ImageIcon fleche = new ImageIcon();
    /**
     * L'icone de poubelle
     */
    public ImageIcon poubelle = new ImageIcon();
    /**
     * L'icone de loupe
     */
    public ImageIcon loupe = new ImageIcon();
    /**
     * L'icone de up
     */
    public ImageIcon up = new ImageIcon();
    /**
     * L'icone de down
     */
    public ImageIcon down = new ImageIcon();
    /**
     * L'icone de folder
     */
    public ImageIcon folder = new ImageIcon();
    /**
     * L'icone de logo
     */
    public ImageIcon logo = new ImageIcon();
    /**
     * L'icone de stylo.
     */
    public ImageIcon pen = new ImageIcon();
    /**
     * L'icone de stylo vide.
     */
    public ImageIcon penVide = new ImageIcon();
    /**
     * L'icone de link.
     */
    public ImageIcon link = new ImageIcon();
    /**
     * L'icone de link vide.
     */
    public ImageIcon linkVide = new ImageIcon();
    public ImageIcon leftArrow = new ImageIcon();
    public ImageIcon rightArrow = new ImageIcon();
    /**
     * Instance.
     */
    private static Icons _instance = null;

    /**
     * Constructeur
     */
    private Icons() {
        loadImages();
    }

    /**
     * Récupère l'instance de la classe.
     * @return l'instance de la classe.
     */
    public static synchronized Icons getInstance() {
        if (_instance == null) {
            _instance = new Icons();
        }
        return _instance;
    }

    /**
     * Charge les images.
     */
    private void loadImages() {
        loadImage(etoilePlein, "/be/msyben/vinylManager/gui/icon/etplein.png");
        loadImage(etoileVide, "/be/msyben/vinylManager/gui/icon/etvide.png");
        loadImage(etoileDemi, "/be/msyben/vinylManager/gui/icon/etdemi.png");
        loadImage(icon, "/be/msyben/vinylManager/gui/icon/icon.png");
        loadImage(fleche, "/be/msyben/vinylManager/gui/icon/fleche.png");
        loadImage(poubelle, "/be/msyben/vinylManager/gui/icon/poubelle.png");
        loadImage(loupe, "/be/msyben/vinylManager/gui/icon/loupe.png");
        loadImage(up, "/be/msyben/vinylManager/gui/icon/up.png");
        loadImage(down, "/be/msyben/vinylManager/gui/icon/down.png");
        loadImage(folder, "/be/msyben/vinylManager/gui/icon/folder.png");
        loadImage(logo, "/be/msyben/vinylManager/gui/icon/logo.png");
        loadImage(pen, "/be/msyben/vinylManager/gui/icon/pen.png");
        loadImage(penVide, "/be/msyben/vinylManager/gui/icon/pen-vide.png");
        loadImage(link, "/be/msyben/vinylManager/gui/icon/link.png");
        loadImage(linkVide, "/be/msyben/vinylManager/gui/icon/link-vide.png");
        loadImage(leftArrow, "/be/msyben/vinylManager/gui/icon/leftArrow.png");
        loadImage(rightArrow, "/be/msyben/vinylManager/gui/icon/rightArrow.png");
    }

    /**
     * Charge une image.
     * @param ii L'image dans laquelle il faut charger.
     * @param resource La resource.
     */
    private void loadImage(ImageIcon ii, String resource) {
        
        InputStream is = null;
        try {
            is = this.getClass().getResourceAsStream(resource);
            ii.setImage(ImageIO.read(is));
        } catch (IOException ex) {
            VinylManagerLogger.log( ex);
        } finally {
            Tools.closeQuietly(is);
        }
    }
}
