package e3d.gui.icons;

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

import javax.imageio.ImageIO;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import e3d.visualization.image.E3DImage;
import e3d.visualization.image.E3DImageAWT;
import e3d.visualization.image.E3DImageSWT;


/**
 * Class used for Loading icons
 * 
 * @author Patrick Rammelt
 */
public class Icons 
{
  // ICONS ================================================================================

  public static final String[] PROGRAM_ICONS = {"e3d_40x40.png",
                                                "e3d_30x30.png",
                                                "e3d_20x20.png",
                                                "e3d_15x15.png"};
  private static final Image[] PROGRAM_ICON_IMAGES = new Image[PROGRAM_ICONS.length];

  public static final String WELCOME = "e3d_persp.png";
  public static final String MOSAIC = "e3d_mosaic.png";
    
  public static final String POWER_FOCUS = "power_focus.png";
  
  public static final String START = "start.png";
  public static final String STOP  = "stop.png";
  public static final String LOAD  = "load.png";
  public static final String SAVE  = "save.png";
  public static final String HELP  = "help.png";

  public static final String START_FOCUS = "start_focus.png";
  public static final String STOP_FOCUS = "stop_focus.png";
  public static final String LOAD_FOCUS = "load_focus.png";
  public static final String SAVE_FOCUS = "save_focus.png";
  public static final String HELP_FOCUS = "help_focus.png";

  public static final String START_PRESSED = "start_pressed.png";
  public static final String STOP_PRESSED = "stop_pressed.png";
  public static final String LOAD_PRESSED = "load_pressed.png";
  public static final String SAVE_PRESSED = "save_pressed.png";
  public static final String HELP_PRESSED = "help_pressed.png";
  
  public static final String CHOOSE         = "choose.png";
  public static final String CHOOSE_FOCUS   = "choose_focus.png";
  public static final String CHOOSE_PRESSED = "choose_pressed.png";
  
  public static final String GET         = "get.png";
  public static final String GET_FOCUS   = "get_focus.png";
  public static final String GET_PRESSED = "get_pressed.png";
  
  public static final String ADD         = "add.png";
  public static final String ADD_FOCUS   = "add_focus.png";
  public static final String ADD_PRESSED = "add_pressed.png";

  public static final String DELETE         = "delete.png";
  public static final String DELETE_FOCUS   = "delete_focus.png";
  public static final String DELETE_PRESSED = "delete_pressed.png";

  public static final String NONE         = "none.png";
  public static final String NONE_FOCUS   = "none_focus.png";
  public static final String NONE_PRESSED = "none_pressed.png";

  public static final String ALL         = "all.png";
  public static final String ALL_FOCUS   = "all_focus.png";
  public static final String ALL_PRESSED = "all_pressed.png";

  public static final String QUADRATIC               = "quadratic.png";
  public static final String QUADRATIC_FOCUS         = "quadratic_focus.png";
  public static final String QUADRATIC_PRESSED       = "quadratic_pressed.png";
  public static final String QUADRATIC_PRESSED_FOCUS = "quadratic_pressed_focus.png";

  public static final String AND               = "and.png";
  public static final String AND_FOCUS         = "and_focus.png";
  public static final String AND_PRESSED       = "and_pressed.png";
  public static final String AND_PRESSED_FOCUS = "and_pressed_focus.png";

  public static final String OR               = "or.png";
  public static final String OR_FOCUS         = "or_focus.png";
  public static final String OR_PRESSED       = "or_pressed.png";
  public static final String OR_PRESSED_FOCUS = "or_pressed_focus.png";

  public static final String MESH               = "mesh.png";
  public static final String MESH_FOCUS         = "mesh_focus.png";
  public static final String MESH_PRESSED       = "mesh_pressed.png";
  public static final String MESH_PRESSED_FOCUS = "mesh_pressed_focus.png";

  public static final String BEZIER               = "bezier.png";
  public static final String BEZIER_FOCUS         = "bezier_focus.png";
  public static final String BEZIER_PRESSED       = "bezier_pressed.png";
  public static final String BEZIER_PRESSED_FOCUS = "bezier_pressed_focus.png";

  public static final String DISTANCE_FOCUS = "distance_focus.png";

  public static final String EDIT_FOCUS = "edit_focus.png";
  public static final String SELECT_FOCUS = "select_focus.png";

  public static final String GLOSS_FOCUS = "gloss_focus.png";
  public static final String MIRROR_FOCUS = "mirror_focus.png";

  public static final String COLS_FOCUS       = "cols_focus.png";
  public static final String ROWS_FOCUS       = "rows_focus.png";
  public static final String LONGITUDES_FOCUS = "longitudes_focus.png";

  public static final String DENSITY_FOCUS = "density_focus.png";
  public static final String SCALE_FOCUS   = "scale_focus.png";
  public static final String SPLIT_FOCUS   = "split_focus.png";
  public static final String MINSIZE_FOCUS = "minsize_focus.png";

  public static final String THICKNESS_FOCUS   = "thickness_focus.png";
  public static final String GROUNDLIGHT_FOCUS = "groundlight_focus.png";
  public static final String REFLECTION_FOCUS  = "reflection_focus.png";
  public static final String DIFFUSION_FOCUS   = "diffusion_focus.png";
  public static final String MINLIGHT_FOCUS    = "minlight_focus.png";

  public static final String X_FOCUS = "x_focus.png";
  public static final String Y_FOCUS = "y_focus.png";
  public static final String Z_FOCUS = "z_focus.png";
  public static final String T_FOCUS = "t_focus.png";

  public static final String WIDTH_FOCUS  = "width_focus.png";
  public static final String HEIGHT_FOCUS = "height_focus.png";
  public static final String DEPTH_FOCUS  = "depth_focus.png";

  public static final String ZOOM_FOCUS = "zoom_focus.png";

  public static final String RADIUS_FOCUS = "radius_focus.png";
  
  public static final String OPACITY_FOCUS = "opacity_focus.png";
  
  public static final String UP           = "up.png";
  public static final String UP_FOCUS     = "up_focus.png";
  public static final String UP_PRESSED   = "up_pressed.png";

  public static final String DOWN         = "down.png";
  public static final String DOWN_FOCUS   = "down_focus.png";
  public static final String DOWN_PRESSED = "down_pressed.png";

  public static final String LEFT         = "left.png";
  public static final String LEFT_FOCUS   = "left_focus.png";
  public static final String LEFT_PRESSED = "left_pressed.png";

  public static final String RIGHT         = "right.png";
  public static final String RIGHT_FOCUS   = "right_focus.png";
  public static final String RIGHT_PRESSED = "right_pressed.png";

  public static final String ROUNDNESS_FOCUS = "roundness_focus.png";
  
  public static final String ROTATION_FOCUS = "rotate_focus.png";
  public static final String NOITATOR_FOCUS = "etator_focus.png";

  public static final String VERTICAL_FOCUS     = "vertical_focus.png";
  public static final String HORIZONTAL_FOCUS   = "horizontal_focus.png";
  public static final String LONGITUDINAL_FOCUS = "longitudinal_focus.png";

  public static final String HUE_FOCUS        = "hue_focus.png";
  public static final String SATURATION_FOCUS = "saturation_focus.png";
  public static final String BRIGHTNESS_FOCUS = "brightness_focus.png";

  public static final String RED_FOCUS   = "red_focus.png";
  public static final String GREEN_FOCUS = "green_focus.png";
  public static final String BLUE_FOCUS  = "blue_focus.png";
  public static final String ALPHA_FOCUS = "alpha_focus.png";

  public static final String TILE_SIZE_FOCUS    = "size_focus.png";
  public static final String TILE_OVERLAP_FOCUS = "overlap_focus.png";

  public static final String MAX_FOCUS = "max_focus.png";

  public static final String PERCENT100_FOCUS = "percent_focus.png";

  public static final String BLUR_MAX_DELTA_FOCUS = "delta_focus.png";
  public static final String BLUR_RADIUS_FOCUS    = "radius_focus.png";
  public static final String BLUR_LEVELS_FOCUS    = "levels_focus.png";

  public static final String TARGET = "target.png";

  public static final String RECTANGLE_BIG  = "rectangle_big.png";
  public static final String CYLINDER_BIG   = "cylinder_big.png";
  public static final String SPHERE_BIG     = "sphere_big.png";
  public static final String CIRCLE_BIG     = "circle_big.png";

  public static final String MASK1x1        = "mask_1x1.png";
  public static final String MASK3x3        = "mask_3x3.png";
  public static final String MASK5x5        = "mask_5x5.png";
  public static final String MASK7x7        = "mask_7x7.png";
  public static final String MASK9x9        = "mask_9x9.png";
  public static final String MASK11x11      = "mask_11x11.png";
  public static final String MASK13x13      = "mask_13x13.png";
  public static final String MASK15x15      = "mask_15x15.png";
  public static final String MASK17x17      = "mask_17x17.png";
  public static final String MASK19x19      = "mask_19x19.png";
  public static final String MASK3x3FUZZY   = "mask_3x3_fuzzy.png";
  public static final String MASK5x5FUZZY   = "mask_5x5_fuzzy.png";
  public static final String MASK7x7FUZZY   = "mask_7x7_fuzzy.png";
  public static final String MASK9x9FUZZY   = "mask_9x9_fuzzy.png";
  public static final String MASK11x11FUZZY = "mask_11x11_fuzzy.png";
  public static final String MASK13x13FUZZY = "mask_13x13_fuzzy.png";
  public static final String MASK15x15FUZZY = "mask_15x15_fuzzy.png";
  public static final String MASK17x17FUZZY = "mask_17x17_fuzzy.png";
  public static final String MASK19x19FUZZY = "mask_19x19_fuzzy.png";
  
  public static final String[] MASKS = new String[]{MASK1x1, 
                                                    MASK3x3, 
                                                    MASK5x5, 
                                                    MASK7x7, 
                                                    MASK9x9, 
                                                    MASK11x11, 
                                                    MASK13x13, 
                                                    MASK15x15, 
                                                    MASK17x17, 
                                                    MASK19x19,
                                                    MASK1x1,       // the same for fuzzy / non-fuzzy
                                                    MASK3x3FUZZY, 
                                                    MASK5x5FUZZY, 
                                                    MASK7x7FUZZY,
                                                    MASK9x9FUZZY, 
                                                    MASK11x11FUZZY, 
                                                    MASK13x13FUZZY,
                                                    MASK15x15FUZZY, 
                                                    MASK17x17FUZZY, 
                                                    MASK19x19FUZZY};
  
  
  // GET ICONS ============================================================================

  // SWT ----------------------------------------------------------------------------------

  /**
   * Get (load) an icon as a SWT image  
   * @param display  {@link Display}
   * @param name     name of the icon (relative to this class {@link Icons})
   * @return         the icon as an {@link Image}
   */
  public static Image getSWTImage (final Display display, final String name) 
  {
    return (new Image(display, Icons.class.getResourceAsStream(name)));
  }

  
  /**
   * Get (load) an array of icons as SWT images  
   * @param display  {@link Display}
   * @param name     name(s) of the icon(s) (relative to this class {@link Icons})
   * @return         {@link Image} array of icons
   */
  public static Image[] getSWTImages (final Display display, final String... names) 
  {
    final Image[] images = new Image[names.length];
    for (int i = 0; i < names.length; i++) {
      images[i] = getSWTImage(display, names[i]); 
    }
    return (images);
  }

  // AWT ----------------------------------------------------------------------------------

  /**
   * Get (load) an icon as an AWT image  
   * @param name  name of the icon (relative to this class {@link Icons})
   * @return      the icon as an {@link BufferedImage}
   */
  public static BufferedImage getAWTImage (final String name) throws IOException 
  {
    return (ImageIO.read(Icons.class.getResourceAsStream(name)));
  }
  
  
  /**
   * Get (load) an array of icons as AWT images  
   * @param name  name(s) of icon(s) (relative to this class {@link Icons})
   * @return      {@link BufferedImage} array of icons 
   */
  public static BufferedImage[] getAWTImages (final String... names) throws IOException 
  {
    final BufferedImage[] images = new BufferedImage[names.length];
    for (int i = 0; i < names.length; i++) {
      images[i] = getAWTImage(names[i]); 
    }
    return (images);
  }

  // E3D (SWT) ----------------------------------------------------------------------------

  /**
   * Get (load) an icon as a E3D image  
   * (internally using a SWT representation)
   * @param name  name of the icon (relative to this class {@link Icons})
   * @return      the icon as an {@link Image}
   */
  public static E3DImage getE3DImageSWT (final String name) throws Exception 
  {
    return (new E3DImageSWT(Icons.class.getResourceAsStream(name)));
  }

  
  /**
   * Get (load) an array of icons as E3D images 
   * (internally using a AWT representation)  
   * @param name  name(s) of the icon(s) (relative to this class {@link Icons})
   * @return      {@link Image} array of icons
   */
  public static E3DImage[] getE3DImagesSWT (final String... names) throws Exception 
  {
    final E3DImage[] images = new E3DImage[names.length];
    for (int i = 0; i < names.length; i++) {
      images[i] = getE3DImageSWT(names[i]); 
    }
    return (images);
  }

  // E3D (AWT) ----------------------------------------------------------------------------
  
  /**
   * Get (load) an icon as a E3D image  
   * (internally using a AWT representation)
   * @param name  name of the icon (relative to this class {@link Icons})
   * @return      the icon as an {@link Image}
   */
  public static E3DImage getE3DImageAWT (final String name) throws Exception 
  {
    return (new E3DImageAWT(Icons.class.getResourceAsStream(name)));
  }

  
  /**
   * Get (load) an array of icons as E3D images 
   * (internally using a AWT representation)  
   * @param name  name(s) of the icon(s) (relative to this class {@link Icons})
   * @return      {@link Image} array of icons
   */
  public static E3DImage[] getE3DImagesAWT (final String... names) throws Exception 
  {
    final E3DImage[] images = new E3DImage[names.length];
    for (int i = 0; i < names.length; i++) {
      images[i] = getE3DImageAWT(names[i]); 
    }
    return (images);
  }

  
  // SET ICONS ============================================================================
  
  /** Set program icons for the given shell */
  public static void setIcons (Shell shell)
  {
    for (int i = 0; i < PROGRAM_ICONS.length; i++) { 
      if (PROGRAM_ICON_IMAGES[i] == null) {
        PROGRAM_ICON_IMAGES[i] = getSWTImage(shell.getDisplay(), PROGRAM_ICONS[i]);
      }
    } 
    shell.setImages(PROGRAM_ICON_IMAGES);
  }

}
