Ignore:
Timestamp:
Oct 16, 2010, 1:08:28 PM (14 years ago)
Author:
mlg
Message:

implements feature : the number of thumbnails in the thumbnails viewer is adapted to the size of the frame
not perfect but better
feature:0001838

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/ImagesManagement.java

    r7070 r7221  
    55import java.util.HashMap;
    66import java.util.List;
    7 
    87import javax.imageio.ImageIO;
    9 
    108import fr.mael.jiwigo.om.Image;
    119import fr.mael.jiwigo.transverse.util.Outil;
     10
    1211
    1312/**
     
    4140 */
    4241public class ImagesManagement {
    43     /**
    44      * Logger
    45      */
    46     public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
    47             .getLog(ImagesManagement.class);
    48     /**
    49      * the index of the current image
    50      */
    51     public static int CURRENT_IMAGE_INDEX;
    52     /**
    53      * the current image
    54      */
    55     public static Image CURRENT_IMAGE;
    56     /**
    57      * images list
    58      */
    59     public static List<Image> LIST_IMAGE;
    6042
    61     /**
    62      * cache allows to keep the images in the ram
    63      */
    64     private static HashMap<Integer, BufferedImage> IMAGES_CACHE = new HashMap<Integer, BufferedImage>();
     43        /**
     44         * Logger
     45         */
     46        public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ImagesManagement.class);
     47        /**
     48         * the index of the current image
     49         */
     50        public static int CURRENT_IMAGE_INDEX;
     51        /**
     52         * the current image
     53         */
     54        public static Image CURRENT_IMAGE;
     55        /**
     56         * images list
     57         */
     58        public static List<Image> LIST_IMAGE;
    6559
    66     /**
    67      * cache allows to keep the thumbnails in the ram
    68     */
    69     private static HashMap<Integer, BufferedImage> MINIATURE_CACHE = new HashMap<Integer, BufferedImage>();
     60        /**
     61         * cache allows to keep the images in the ram
     62        */
     63        private static HashMap<Integer, BufferedImage> IMAGES_CACHE = new HashMap<Integer, BufferedImage>();
    7064
    71     /**
    72      * If true : the application won't ask the privacy level
    73      * to the user each time he adds pictures
    74      */
    75     public static boolean rememberPrivacyLevel = false;
     65        /**
     66         * cache allows to keep the thumbnails in the ram
     67         */
     68        private static HashMap<Integer, BufferedImage> MINIATURE_CACHE = new HashMap<Integer, BufferedImage>();
    7669
    77     /**
    78      * the privacy level to apply to the pictures
    79      */
    80     public static int privacyLevel = 1;
     70        /**
     71         * If true : the application won't ask the privacy level
     72         * to the user each time he adds pictures
     73         */
     74        public static boolean rememberPrivacyLevel = false;
    8175
    82     /**
    83      * gets the current image
    84      * @return the image
    85      */
    86     public static Image getCurrentImage() {
    87         //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    88         return CURRENT_IMAGE;
    89     }
     76        /**
     77         * the privacy level to apply to the pictures
     78         */
     79        public static int privacyLevel = 1;
    9080
    91     /**
    92      * next image
    93      */
    94     public static void next() {
    95         if (CURRENT_IMAGE_INDEX != LIST_IMAGE.size() - 1) {
    96             CURRENT_IMAGE_INDEX++;
    97         } else {
    98             CURRENT_IMAGE_INDEX = 0;
     81
     82        /**
     83         * gets the current image
     84         * @return the image
     85         */
     86        public static Image getCurrentImage() {
     87                //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
     88                return CURRENT_IMAGE;
    9989        }
    100         CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    101     }
    10290
    103     /**
    104      * previous image
    105      */
    106     public static void previous() {
    107         if (CURRENT_IMAGE_INDEX != 0) {
    108             CURRENT_IMAGE_INDEX--;
    109         } else {
    110             CURRENT_IMAGE_INDEX = LIST_IMAGE.size() - 1;
     91
     92        /**
     93         * next image
     94         */
     95        public static void next() {
     96                if (CURRENT_IMAGE_INDEX != LIST_IMAGE.size() - 1) {
     97                        CURRENT_IMAGE_INDEX++;
     98                } else {
     99                        CURRENT_IMAGE_INDEX = 0;
     100                }
     101                CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    111102        }
    112         CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    113     }
    114103
    115     /**
    116      *
    117      * @param image the current image
    118      */
    119     public static void setCurrentImage(Image image) {
    120         CURRENT_IMAGE = image;
    121         int compteur = 0;
    122         for (Image im : LIST_IMAGE) {
    123             if (im.equals(image)) {
    124                 CURRENT_IMAGE_INDEX = compteur;
    125             }
    126             compteur++;
     104
     105        /**
     106         * previous image
     107         */
     108        public static void previous() {
     109                if (CURRENT_IMAGE_INDEX != 0) {
     110                        CURRENT_IMAGE_INDEX--;
     111                } else {
     112                        CURRENT_IMAGE_INDEX = LIST_IMAGE.size() - 1;
     113                }
     114                CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    127115        }
    128     }
    129116
    130     /**
    131      * Function that allows to load images once
    132      * to decrease response delays
    133      * @return the image
    134      */
    135     public static BufferedImage getCurrentBufferedImage() {
    136         if (IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant()) == null) {
    137             try {
    138                 BufferedImage img = ImageIO.read(new URL(CURRENT_IMAGE.getUrl()));
    139                 IMAGES_CACHE.put(CURRENT_IMAGE.getIdentifiant(), img);
    140             } catch (Exception e) {
    141                 LOG.error(Outil.getStackTrace(e));
    142             }
     117
     118        /**
     119         *
     120         * @param image the current image
     121         */
     122        public static void setCurrentImage(Image image) {
     123                CURRENT_IMAGE = image;
     124                int compteur = 0;
     125                for (Image im : LIST_IMAGE) {
     126                        if (im.equals(image)) {
     127                                CURRENT_IMAGE_INDEX = compteur;
     128                        }
     129                        compteur++;
     130                }
    143131        }
    144         return IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant());
    145     }
    146132
    147     /**
    148      * Function that allows to load thimbnails once
    149      * to decrease response delays
    150      * @return the image
    151      */
    152     public static BufferedImage getMiniatureBufferedImage(Image image) {
    153         if (MINIATURE_CACHE.get(image.getIdentifiant()) == null) {
    154             try {
    155                 BufferedImage img = ImageIO.read(new URL(image.getMiniature()));
    156                 MINIATURE_CACHE.put(image.getIdentifiant(), img);
    157             } catch (Exception e) {
    158                 LOG.error(Outil.getStackTrace(e));
    159             }
     133
     134        /**
     135         * Function that allows to load images once
     136         * to decrease response delays
     137         * @return the image
     138         */
     139        public static BufferedImage getCurrentBufferedImage() {
     140                if (IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant()) == null) {
     141                        try {
     142                                BufferedImage img = ImageIO.read(new URL(CURRENT_IMAGE.getUrl()));
     143                                IMAGES_CACHE.put(CURRENT_IMAGE.getIdentifiant(), img);
     144                        } catch (Exception e) {
     145                                LOG.error(Outil.getStackTrace(e));
     146                        }
     147                }
     148                return IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant());
    160149        }
    161         return MINIATURE_CACHE.get(image.getIdentifiant());
    162     }
     150
     151
     152        /**
     153         * Function that allows to load thimbnails once
     154         * to decrease response delays
     155         * @return the image
     156         */
     157        public static BufferedImage getMiniatureBufferedImage(Image image) {
     158                if (MINIATURE_CACHE.get(image.getIdentifiant()) == null) {
     159                        try {
     160                                BufferedImage img = ImageIO.read(new URL(image.getMiniature()));
     161                                MINIATURE_CACHE.put(image.getIdentifiant(), img);
     162                        } catch (Exception e) {
     163                                LOG.error(Outil.getStackTrace(e));
     164                        }
     165                }
     166
     167                return MINIATURE_CACHE.get(image.getIdentifiant());
     168        }
    163169}
Note: See TracChangeset for help on using the changeset viewer.