Ignore:
Timestamp:
Jan 21, 2011, 7:18:42 PM (13 years ago)
Author:
mlg
Message:

Changes ImagesManagement access from static to object.

File:
1 edited

Legend:

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

    r7223 r8829  
    55import java.util.HashMap;
    66import java.util.List;
     7
    78import javax.imageio.ImageIO;
     9
    810import fr.mael.jiwigo.om.Image;
    911import fr.mael.jiwigo.transverse.util.Outil;
    10 
    1112
    1213/**
     
    4041 */
    4142public class ImagesManagement {
    42 
    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;
    59 
    60         /**
    61          * cache allows to keep the images in the ram
    62          */
    63         private static HashMap<Integer, BufferedImage> IMAGES_CACHE = new HashMap<Integer, BufferedImage>();
    64 
    65         /**
    66          * cache allows to keep the thumbnails in the ram
    67          */
    68         private static HashMap<Integer, BufferedImage> MINIATURE_CACHE = new HashMap<Integer, BufferedImage>();
    69 
    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;
    75 
    76         /**
    77          * the privacy level to apply to the pictures
    78          */
    79         public static int privacyLevel = 1;
    80 
    81         /**
    82          * boolean that defines if the application is sending files
    83          *
    84          */
    85         public static boolean sendingFiles = false;
    86 
    87 
    88         /**
    89          * gets the current image
    90          * @return the image
    91          */
    92         public static Image getCurrentImage() {
    93                 //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    94                 return CURRENT_IMAGE;
    95         }
    96 
    97 
    98         /**
    99          * next image
    100          */
    101         public static void next() {
    102                 if (CURRENT_IMAGE_INDEX != LIST_IMAGE.size() - 1) {
    103                         CURRENT_IMAGE_INDEX++;
    104                 } else {
    105                         CURRENT_IMAGE_INDEX = 0;
    106                 }
    107                 CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    108         }
    109 
    110 
    111         /**
    112          * previous image
    113          */
    114         public static void previous() {
    115                 if (CURRENT_IMAGE_INDEX != 0) {
    116                         CURRENT_IMAGE_INDEX--;
    117                 } else {
    118                         CURRENT_IMAGE_INDEX = LIST_IMAGE.size() - 1;
    119                 }
    120                 CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
    121         }
    122 
    123 
    124         /**
    125          *
    126          * @param image the current image
    127          */
    128         public static void setCurrentImage(Image image) {
    129                 CURRENT_IMAGE = image;
    130                 int compteur = 0;
    131                 for (Image im : LIST_IMAGE) {
    132                         if (im.equals(image)) {
    133                                 CURRENT_IMAGE_INDEX = compteur;
    134                         }
    135                         compteur++;
    136                 }
    137         }
    138 
    139 
    140         /**
    141          * Function that allows to load images once
    142          * to decrease response delays
    143          * @return the image
    144          */
    145         public static BufferedImage getCurrentBufferedImage() {
    146                 if (IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant()) == null) {
    147                         try {
    148                                 BufferedImage img = ImageIO.read(new URL(CURRENT_IMAGE.getUrl()));
    149                                 IMAGES_CACHE.put(CURRENT_IMAGE.getIdentifiant(), img);
    150                         } catch (Exception e) {
    151                                 LOG.error(Outil.getStackTrace(e));
    152                         }
    153                 }
    154                 return IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant());
    155         }
    156 
    157 
    158         /**
    159          * Function that allows to load thimbnails once
    160          * to decrease response delays
    161          * @return the image
    162          */
    163         public static BufferedImage getMiniatureBufferedImage(Image image) {
    164                 if (MINIATURE_CACHE.get(image.getIdentifiant()) == null) {
    165                         try {
    166                                 BufferedImage img = ImageIO.read(new URL(image.getMiniature()));
    167                                 MINIATURE_CACHE.put(image.getIdentifiant(), img);
    168                         } catch (Exception e) {
    169                                 LOG.error(Outil.getStackTrace(e));
    170                         }
    171                 }
    172 
    173                 return MINIATURE_CACHE.get(image.getIdentifiant());
    174         }
     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    private int currentImageIndex;
     52    /**
     53     * the current image
     54     */
     55    private Image currentImage;
     56    /**
     57     * images list
     58     */
     59    private List<Image> listImage;
     60
     61    /**
     62     * cache allows to keep the images in the ram
     63     */
     64    private HashMap<Integer, BufferedImage> imageCache = new HashMap<Integer, BufferedImage>();
     65
     66    /**
     67     * cache allows to keep the thumbnails in the ram
     68     */
     69    private HashMap<Integer, BufferedImage> thumbnailsCache = new HashMap<Integer, BufferedImage>();
     70
     71    /**
     72     * If true : the application won't ask the privacy level
     73     * to the user each time he adds pictures
     74     */
     75    private boolean rememberPrivacyLevel = false;
     76
     77    /**
     78     * if true : the user is currently uploading pictures
     79     */
     80    private boolean isUploading = false;
     81    /**
     82     * the privacy level to apply to the pictures
     83     */
     84    private int privacyLevel = 1;
     85    /**
     86     * boolean that defines if the application is sending files
     87     *
     88     */
     89    private boolean sendingFiles = false;
     90
     91    /**
     92     * singleton
     93     */
     94    private static ImagesManagement instance;
     95
     96    private ImagesManagement() {
     97    }
     98
     99    public static ImagesManagement getInstance() {
     100        if (instance == null) {
     101            instance = new ImagesManagement();
     102        }
     103        return instance;
     104    }
     105
     106    /**
     107     * gets the current image
     108     * @return the image
     109     */
     110    public Image getCurrentImage() {
     111        //return LIST_IMAGE.get(CURRENT_IMAGE_INDEX);
     112        return currentImage;
     113    }
     114
     115    /**
     116     * next image
     117     */
     118    public void next() {
     119        if (currentImageIndex != listImage.size() - 1) {
     120            currentImageIndex++;
     121        } else {
     122            currentImageIndex = 0;
     123        }
     124        currentImage = listImage.get(currentImageIndex);
     125    }
     126
     127    /**
     128     * previous image
     129     */
     130    public void previous() {
     131        if (currentImageIndex != 0) {
     132            currentImageIndex--;
     133        } else {
     134            currentImageIndex = listImage.size() - 1;
     135        }
     136        currentImage = listImage.get(currentImageIndex);
     137    }
     138
     139    /**
     140     *
     141     * @param image the current image
     142     */
     143    public void setCurrentImage(Image image) {
     144        currentImage = image;
     145        int compteur = 0;
     146        for (Image im : listImage) {
     147            if (im.equals(image)) {
     148                currentImageIndex = compteur;
     149            }
     150            compteur++;
     151        }
     152    }
     153
     154    /**
     155     * Function that allows to load images once
     156     * to decrease response delays
     157     * @return the image
     158     */
     159    public BufferedImage getCurrentBufferedImage() {
     160        if (imageCache.get(currentImage.getIdentifiant()) == null) {
     161            try {
     162                BufferedImage img = ImageIO.read(new URL(currentImage.getUrl()));
     163                imageCache.put(currentImage.getIdentifiant(), img);
     164            } catch (Exception e) {
     165                LOG.error(Outil.getStackTrace(e));
     166            }
     167        }
     168        return imageCache.get(currentImage.getIdentifiant());
     169    }
     170
     171    /**
     172     * Function that allows to load thimbnails once
     173     * to decrease response delays
     174     * @return the image
     175     */
     176    public BufferedImage getMiniatureBufferedImage(Image image) {
     177        if (thumbnailsCache.get(image.getIdentifiant()) == null) {
     178            try {
     179                BufferedImage img = ImageIO.read(new URL(image.getMiniature()));
     180                thumbnailsCache.put(image.getIdentifiant(), img);
     181            } catch (Exception e) {
     182                LOG.error(Outil.getStackTrace(e));
     183            }
     184        }
     185
     186        return thumbnailsCache.get(image.getIdentifiant());
     187    }
     188
     189    /**
     190     * @return the listImage
     191     */
     192    public List<Image> getListImage() {
     193        return listImage;
     194    }
     195
     196    /**
     197     * @param listImage the listImage to set
     198     */
     199    public void setListImage(List<Image> listImage) {
     200        this.listImage = listImage;
     201    }
     202
     203    /**
     204     * @return the rememberPrivacyLevel
     205     */
     206    public boolean isRememberPrivacyLevel() {
     207        return rememberPrivacyLevel;
     208    }
     209
     210    /**
     211     * @param rememberPrivacyLevel the rememberPrivacyLevel to set
     212     */
     213    public void setRememberPrivacyLevel(boolean rememberPrivacyLevel) {
     214        this.rememberPrivacyLevel = rememberPrivacyLevel;
     215    }
     216
     217    /**
     218     * @return the sendingFiles
     219     */
     220    public boolean isSendingFiles() {
     221        return sendingFiles;
     222    }
     223
     224    /**
     225     * @param sendingFiles the sendingFiles to set
     226     */
     227    public void setSendingFiles(boolean sendingFiles) {
     228        this.sendingFiles = sendingFiles;
     229    }
     230
     231    /**
     232     * @return the privacyLevel
     233     */
     234    public int getPrivacyLevel() {
     235        return privacyLevel;
     236    }
     237
     238    /**
     239     * @param privacyLevel the privacyLevel to set
     240     */
     241    public void setPrivacyLevel(int privacyLevel) {
     242        this.privacyLevel = privacyLevel;
     243    }
     244
    175245}
Note: See TracChangeset for help on using the changeset viewer.