Changeset 7221 for extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/ImagesManagement.java
- Timestamp:
- Oct 16, 2010, 1:08:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/ImagesManagement.java
r7070 r7221 5 5 import java.util.HashMap; 6 6 import java.util.List; 7 8 7 import javax.imageio.ImageIO; 9 10 8 import fr.mael.jiwigo.om.Image; 11 9 import fr.mael.jiwigo.transverse.util.Outil; 10 12 11 13 12 /** … … 41 40 */ 42 41 public class ImagesManagement { 43 /**44 * Logger45 */46 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory47 .getLog(ImagesManagement.class);48 /**49 * the index of the current image50 */51 public static int CURRENT_IMAGE_INDEX;52 /**53 * the current image54 */55 public static Image CURRENT_IMAGE;56 /**57 * images list58 */59 public static List<Image> LIST_IMAGE;60 42 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; 65 59 66 67 * cache allows to keep the thumbnails in the ram68 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>(); 70 64 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>(); 76 69 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; 81 75 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; 90 80 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; 99 89 } 100 CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);101 }102 90 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); 111 102 } 112 CURRENT_IMAGE = LIST_IMAGE.get(CURRENT_IMAGE_INDEX);113 }114 103 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); 127 115 } 128 }129 116 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 } 143 131 } 144 return IMAGES_CACHE.get(CURRENT_IMAGE.getIdentifiant());145 }146 132 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()); 160 149 } 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 } 163 169 }
Note: See TracChangeset
for help on using the changeset viewer.