Changeset 7221 for extensions/jiwigo
- Timestamp:
- Oct 16, 2010, 1:08:28 PM (14 years ago)
- Location:
- extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/Main.java
r6980 r7221 3 3 import java.io.File; 4 4 import java.io.IOException; 5 6 5 import javax.swing.UIManager; 7 8 6 import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel; 9 10 7 import fr.mael.jiwigo.transverse.session.SessionManager; 11 8 import fr.mael.jiwigo.transverse.util.Outil; … … 13 10 import fr.mael.jiwigo.ui.ConnexionDialog; 14 11 import fr.mael.jiwigo.ui.mainframe.MainFrame; 12 15 13 16 14 /** … … 45 43 */ 46 44 public class Main { 47 /**48 * Logger49 */50 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(Main.class);51 /**52 * The login and session manager that allows to connect to53 * the webservice and to query it54 */55 public static SessionManager sessionManager;56 45 57 /** 58 * the main window 59 */ 60 private static MainFrame mainFrame; 46 /** 47 * Logger 48 */ 49 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(Main.class); 50 /** 51 * The login and session manager that allows to connect to 52 * the webservice and to query it 53 */ 54 public static SessionManager sessionManager; 61 55 62 public static void main(String[] args) { 63 try { 64 UIManager.setLookAndFeel(new NimbusLookAndFeel()); 65 } catch (Exception e) { 66 } 67 File dossierConfig = new File(System.getProperty("user.home") + "/.jiwigo"); 68 if (!dossierConfig.exists()) { 69 dossierConfig.mkdir(); 70 } 71 try { 72 PreferencesManagement.creerFichierParDefaut(); 73 //dialog de connexion 74 ConnexionDialog dialog = new ConnexionDialog(); 75 dialog.showDialog(); 76 } catch (IOException e) { 77 LOG.error(Outil.getStackTrace(e)); 56 /** 57 * the main window 58 */ 59 private static MainFrame mainFrame; 60 61 62 public static void main(String[] args) { 63 try { 64 UIManager.setLookAndFeel(new NimbusLookAndFeel()); 65 } catch (Exception e) { 66 } 67 File dossierConfig = new File(System.getProperty("user.home") + "/.jiwigo"); 68 if (!dossierConfig.exists()) { 69 dossierConfig.mkdir(); 70 } 71 try { 72 PreferencesManagement.creerFichierParDefaut(); 73 //dialog de connexion 74 ConnexionDialog dialog = new ConnexionDialog(); 75 dialog.showDialog(); 76 } catch (IOException e) { 77 LOG.error(Outil.getStackTrace(e)); 78 } 79 78 80 } 79 81 80 }81 82 82 83 public static void showFrame() { 83 84 84 if (mainFrame == null) { 85 mainFrame = MainFrame.getInstance(); 85 if (mainFrame == null) { 86 mainFrame = MainFrame.getInstance(); 87 } 88 if (!mainFrame.isVisible()) { 89 mainFrame.showUi(); 90 } 86 91 } 87 if (!mainFrame.isVisible()) {88 mainFrame.showUi();89 }90 }91 92 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/ImageDao.java
r7070 r7221 6 6 import java.util.HashMap; 7 7 import java.util.List; 8 9 8 import org.jdom.Document; 10 9 import org.jdom.Element; 11 12 10 import sun.misc.BASE64Encoder; 13 11 import fr.mael.jiwigo.Main; … … 18 16 import fr.mael.jiwigo.transverse.util.Outil; 19 17 import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement; 18 20 19 21 20 /** … … 50 49 */ 51 50 public class ImageDao { 52 /** 53 * Logger 54 */ 55 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 56 .getLog(ImageDao.class); 57 58 /** 59 * Singleton 60 */ 61 private static ImageDao instance; 62 63 /** 64 * cache to avoid downloading image for each access 65 */ 66 private HashMap<Integer, List<Image>> cache; 67 68 /** 69 * 70 */ 71 private Integer firstCatInCache; 72 73 /** 74 * Private singleton, to use a singleton 75 */ 76 private ImageDao() { 77 cache = new HashMap<Integer, List<Image>>(); 78 } 79 80 /** 81 * @return le singleton 82 */ 83 public static ImageDao getInstance() { 84 if (instance == null) { 85 instance = new ImageDao(); 86 } 87 return instance; 88 } 89 90 /** 91 * Lists all images 92 * @return the list of images 93 * @throws IOException 94 */ 95 public List<Image> lister(boolean rafraichir) throws IOException { 96 return listerParCategory(null, rafraichir); 97 } 98 99 /** 100 * Listing of the images for a category 101 * @param categoryId the id of the category 102 * @return the list of images 103 * @throws IOException 104 */ 105 public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException { 106 if (rafraichir || cache.get(categoryId) == null) { 107 Document doc = null; 108 if (categoryId != null) { 109 doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel(), "cat_id", String 110 .valueOf(categoryId)); 111 } else { 112 doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel()); 113 } 114 Element element = doc.getRootElement().getChild("images"); 115 List<Image> images = getImagesFromElement(element); 116 cache.remove(categoryId); 117 cache.put(categoryId, images); 118 if (firstCatInCache == null) { 119 firstCatInCache = categoryId; 120 } 121 return images; 122 } else { 123 return cache.get(categoryId); 124 } 125 } 126 127 /** 128 * Creation of an image<br/> 129 * Sequence : <br/> 130 * <li> 131 * <ul>sending of the thumbnail in base64, thanks to the method addchunk.</ul> 132 * <ul>sending of the image in base64, thanks to the method addchunk</ul> 133 * <ul>using of the add method to add the image to the database<ul> 134 * </li> 135 * Finally, the response of the webservice is checked 136 * 137 * @param the image to create 138 * @return true if the creation of the image was the successful 139 * @throws Exception 140 */ 141 //TODO ne pas continuer si une des réponses précédentes est négative 142 public boolean creer(Image image) throws Exception { 143 //thumbnail converted to base64 144 BASE64Encoder base64 = new BASE64Encoder(); 145 146 String thumbnailBase64 = base64.encode(Outil.getBytesFromFile(image.getThumbnail())); 147 //sends the thumbnail and gets the result 148 Document reponseThumb = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data", 149 thumbnailBase64, "type", "thumb", "position", "1", "original_sum", Outil.getMD5Checksum(image 150 .getOriginale().getAbsolutePath()))); 151 152 //begin feature:0001827 153 Double doubleChunk = Double.parseDouble(PreferencesManagement.getValue(PreferencesEnum.CHUNK_SIZE.getLabel())) * 1000 * 1024; 154 int chunk = doubleChunk.intValue(); 155 ArrayList<File> fichiersAEnvoyer = Outil.splitFile(image.getOriginale(), chunk); 156 boolean echec = false; 157 for (int i = 0; i < fichiersAEnvoyer.size(); i++) { 158 File fichierAEnvoyer = fichiersAEnvoyer.get(i); 159 String originaleBase64 = base64.encode(Outil.getBytesFromFile(fichierAEnvoyer)); 160 Document reponseOriginale = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data", 161 originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum", Outil 162 .getMD5Checksum(image.getOriginale().getAbsolutePath()))); 163 if (!Outil.checkOk(reponseOriginale)) { 164 echec = true; 165 break; 166 } 167 } 168 //end 169 170 //add the image in the database and get the result of the webservice 171 Document reponseAjout = (Main.sessionManager.executerReturnDocument("pwg.images.add", "file_sum", Outil 172 .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image 173 .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image 174 .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image 175 .getName(), "author", Main.sessionManager.getLogin(), "level", String 176 .valueOf(ImagesManagement.privacyLevel))); 177 LOG.debug("Response add : " + Outil.documentToString(reponseAjout)); 178 // System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil 179 // .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image 180 // .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image 181 // .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image 182 // .getName(), "author", Main.sessionManager.getLogin())); 183 // Document reponsePrivacy = null; 184 // if (Outil.checkOk(reponseAjout)) { 185 // reponsePrivacy = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_PRIVACY_LEVEL.getLabel()); 186 // } 187 boolean reussite = true; 188 if (!Outil.checkOk(reponseThumb) || echec || !Outil.checkOk(reponseAjout)) { 189 reussite = false; 190 } 191 suppressionFichierTemporaires(); 192 return reussite; 193 194 } 195 196 /** 197 * Add tags to an image 198 * @param imageId id of the image 199 * @param tagId ids of the tags 200 * @throws IOException 201 */ 202 public boolean addTags(Integer imageId, String tagId) throws IOException { 203 Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String 204 .valueOf(imageId), "tag_ids", tagId); 205 return Outil.checkOk(doc); 206 207 } 208 209 /** 210 * parse an element to find images 211 * @param element the element to parse 212 * @return the list of images 213 */ 214 private List<Image> getImagesFromElement(Element element) { 215 List<Element> listElement = (List<Element>) element.getChildren("image"); 216 ArrayList<Image> images = new ArrayList<Image>(); 217 for (Element im : listElement) { 218 Image myImage = new Image(); 219 myImage.setMiniature(im.getAttributeValue("tn_url")); 220 myImage.setUrl(im.getAttributeValue("element_url")); 221 myImage.setWidth(Integer.valueOf(im.getAttributeValue("width"))); 222 myImage.setHeight(Integer.valueOf(im.getAttributeValue("height"))); 223 myImage.setFile(im.getAttributeValue("file")); 224 myImage.setVue(Integer.valueOf(im.getAttributeValue("hit"))); 225 myImage.setIdentifiant(Integer.valueOf(im.getAttributeValue("id"))); 226 myImage.setName(im.getChildText("name")); 227 if (myImage.getName() == null) { 228 myImage.setName(myImage.getFile()); 229 } 230 images.add(myImage); 231 232 } 233 return images; 234 } 235 236 /** 237 * Search images 238 * @param searchString the string to search 239 * @return the list of images matching the string 240 * @throws IOException 241 */ 242 public List<Image> search(String searchString) throws IOException { 243 Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString); 244 LOG.debug(doc); 245 Element element = doc.getRootElement().getChild("images"); 246 return getImagesFromElement(element); 247 248 } 249 250 private void suppressionFichierTemporaires() { 251 File file = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg"); 252 file.delete(); 253 file = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg"); 254 file.delete(); 255 256 } 51 52 /** 53 * Logger 54 */ 55 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ImageDao.class); 56 57 /** 58 * Singleton 59 */ 60 private static ImageDao instance; 61 62 /** 63 * cache to avoid downloading image for each access 64 */ 65 private HashMap<Integer, List<Image>> cache; 66 67 /** 68 * 69 */ 70 private Integer firstCatInCache; 71 72 73 /** 74 * Private singleton, to use a singleton 75 */ 76 private ImageDao() { 77 cache = new HashMap<Integer, List<Image>>(); 78 } 79 80 81 /** 82 * @return le singleton 83 */ 84 public static ImageDao getInstance() { 85 if (instance == null) { 86 instance = new ImageDao(); 87 } 88 return instance; 89 } 90 91 92 /** 93 * Lists all images 94 * @return the list of images 95 * @throws IOException 96 */ 97 public List<Image> lister(boolean rafraichir) throws IOException { 98 return listerParCategory(null, rafraichir); 99 } 100 101 102 /** 103 * Listing of the images for a category 104 * @param categoryId the id of the category 105 * @return the list of images 106 * @throws IOException 107 */ 108 public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException { 109 if (rafraichir || cache.get(categoryId) == null) { 110 Document doc = null; 111 112 if (categoryId != null) { 113 doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel(), "cat_id", 114 String.valueOf(categoryId)); 115 } else { 116 doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel()); 117 } 118 Element element = doc.getRootElement().getChild("images"); 119 List<Image> images = getImagesFromElement(element); 120 cache.remove(categoryId); 121 cache.put(categoryId, images); 122 if (firstCatInCache == null) { 123 firstCatInCache = categoryId; 124 } 125 return images; 126 } else { 127 return cache.get(categoryId); 128 } 129 } 130 131 132 /** 133 * Creation of an image<br/> 134 * Sequence : <br/> 135 * <li> 136 * <ul>sending of the thumbnail in base64, thanks to the method addchunk.</ul> 137 * <ul>sending of the image in base64, thanks to the method addchunk</ul> 138 * <ul>using of the add method to add the image to the database<ul> 139 * </li> 140 * Finally, the response of the webservice is checked 141 * 142 * @param the image to create 143 * @return true if the creation of the image was the successful 144 * @throws Exception 145 */ 146 //TODO ne pas continuer si une des réponses précédentes est négative 147 public boolean creer(Image image) throws Exception { 148 //thumbnail converted to base64 149 BASE64Encoder base64 = new BASE64Encoder(); 150 151 String thumbnailBase64 = base64.encode(Outil.getBytesFromFile(image.getThumbnail())); 152 //sends the thumbnail and gets the result 153 Document reponseThumb = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data", thumbnailBase64, 154 "type", "thumb", "position", "1", "original_sum", Outil.getMD5Checksum(image.getOriginale().getAbsolutePath()))); 155 156 //begin feature:0001827 157 Double doubleChunk = Double.parseDouble(PreferencesManagement.getValue(PreferencesEnum.CHUNK_SIZE.getLabel())) * 1000 * 1024; 158 int chunk = doubleChunk.intValue(); 159 ArrayList<File> fichiersAEnvoyer = Outil.splitFile(image.getOriginale(), chunk); 160 boolean echec = false; 161 for (int i = 0; i < fichiersAEnvoyer.size(); i++) { 162 File fichierAEnvoyer = fichiersAEnvoyer.get(i); 163 String originaleBase64 = base64.encode(Outil.getBytesFromFile(fichierAEnvoyer)); 164 Document reponseOriginale = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data", 165 originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum", 166 Outil.getMD5Checksum(image.getOriginale().getAbsolutePath()))); 167 if (!Outil.checkOk(reponseOriginale)) { 168 echec = true; 169 break; 170 } 171 } 172 //end 173 174 //add the image in the database and get the result of the webservice 175 Document reponseAjout = (Main.sessionManager.executerReturnDocument("pwg.images.add", "file_sum", 176 Outil.getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", 177 Outil.getMD5Checksum(image.getThumbnail().getCanonicalPath()), "position", "1", "original_sum", 178 Outil.getMD5Checksum(image.getOriginale().getAbsolutePath()), "categories", 179 String.valueOf(image.getIdCategory()), "name", image.getName(), "author", Main.sessionManager.getLogin(), 180 "level", String.valueOf(ImagesManagement.privacyLevel))); 181 LOG.debug("Response add : " + Outil.documentToString(reponseAjout)); 182 // System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil 183 // .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image 184 // .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image 185 // .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image 186 // .getName(), "author", Main.sessionManager.getLogin())); 187 // Document reponsePrivacy = null; 188 // if (Outil.checkOk(reponseAjout)) { 189 // reponsePrivacy = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_PRIVACY_LEVEL.getLabel()); 190 // } 191 boolean reussite = true; 192 if (!Outil.checkOk(reponseThumb) || echec || !Outil.checkOk(reponseAjout)) { 193 reussite = false; 194 } 195 suppressionFichierTemporaires(); 196 return reussite; 197 198 } 199 200 201 /** 202 * Add tags to an image 203 * @param imageId id of the image 204 * @param tagId ids of the tags 205 * @throws IOException 206 */ 207 public boolean addTags(Integer imageId, String tagId) throws IOException { 208 Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", 209 String.valueOf(imageId), "tag_ids", tagId); 210 return Outil.checkOk(doc); 211 212 } 213 214 215 /** 216 * parse an element to find images 217 * @param element the element to parse 218 * @return the list of images 219 */ 220 private List<Image> getImagesFromElement(Element element) { 221 List<Element> listElement = (List<Element>) element.getChildren("image"); 222 ArrayList<Image> images = new ArrayList<Image>(); 223 for (Element im : listElement) { 224 Image myImage = new Image(); 225 myImage.setMiniature(im.getAttributeValue("tn_url")); 226 myImage.setUrl(im.getAttributeValue("element_url")); 227 myImage.setWidth(Integer.valueOf(im.getAttributeValue("width"))); 228 myImage.setHeight(Integer.valueOf(im.getAttributeValue("height"))); 229 myImage.setFile(im.getAttributeValue("file")); 230 myImage.setVue(Integer.valueOf(im.getAttributeValue("hit"))); 231 myImage.setIdentifiant(Integer.valueOf(im.getAttributeValue("id"))); 232 myImage.setName(im.getChildText("name")); 233 if (myImage.getName() == null) { 234 myImage.setName(myImage.getFile()); 235 } 236 images.add(myImage); 237 238 } 239 return images; 240 } 241 242 243 /** 244 * Search images 245 * @param searchString the string to search 246 * @return the list of images matching the string 247 * @throws IOException 248 */ 249 public List<Image> search(String searchString) throws IOException { 250 Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString); 251 LOG.debug(doc); 252 Element element = doc.getRootElement().getChild("images"); 253 return getImagesFromElement(element); 254 255 } 256 257 258 private void suppressionFichierTemporaires() { 259 File file = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg"); 260 file.delete(); 261 file = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg"); 262 file.delete(); 263 264 } 257 265 258 266 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/ImageService.java
r6980 r7221 4 4 import java.io.IOException; 5 5 import java.util.List; 6 7 6 import fr.mael.jiwigo.dao.ImageDao; 8 7 import fr.mael.jiwigo.om.Image; … … 13 12 import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement; 14 13 import fr.mael.jiwigo.ui.mainframe.MainFrame; 14 15 15 16 16 /** … … 45 45 */ 46 46 public class ImageService { 47 /**48 * Logger49 */50 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory51 .getLog(ImageService.class);52 47 53 54 * Singleton 55 56 private static ImageService instance;48 /** 49 * Logger 50 */ 51 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ImageService.class); 57 52 58 /** 59 * @return the singleton 60 */ 61 public static ImageService getInstance() { 62 if (instance == null) { 63 instance = new ImageService(); 53 /** 54 * Singleton 55 */ 56 private static ImageService instance; 57 58 59 /** 60 * @return the singleton 61 */ 62 public static ImageService getInstance() { 63 if (instance == null) { 64 instance = new ImageService(); 65 } 66 return instance; 64 67 } 65 return instance;66 }67 68 68 /**69 * private constructor to use a singleton70 */71 private ImageService() {72 69 73 } 74 75 /** 76 * Lists all images for a category 77 * @param categoryId the id of the category 78 * @param rafraichir true : refresh the list of images 79 * @return the list of images 80 * @throws IOException 81 */ 82 public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException { 83 return ImageDao.getInstance().listerParCategory(categoryId, rafraichir); 84 } 85 86 /** 87 * Method called to send an image to the server. 88 * @param filePath 89 * @param idCategory 90 * @return 91 * @throws Exception 92 */ 93 public boolean creer(String filePath, Integer idCategory) throws Exception { 94 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_resizing") + " " + filePath); 95 //get the byte array of the original file, to keep metadata 96 byte[] bytesFichierOriginal = Outil.getBytesFromFile(new File(filePath)); 97 98 //size taken from the user's preferences 99 int widthOriginale = Integer 100 .valueOf(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel())); 101 int heightOriginale = Integer.valueOf(PreferencesManagement 102 .getValue(PreferencesEnum.HEIGHT_ORIGINAL.getLabel())); 103 //resize the picture (or not) 104 boolean originaleRedimensionnee = ImagesUtil.scale(filePath, "originale.jpg", widthOriginale, heightOriginale); 105 //create the thumbnail 106 ImagesUtil.scale(filePath, "thumb.jpg", 120, 90); 107 //get the thumbnail 108 File thumbnail = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg"); 109 File originale = null; 110 if (originaleRedimensionnee) { 111 originale = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg"); 112 //if the original file has been resized, we put the metadata in the resized file 113 //I use here a try catch because if the original file isn't a jpeg 114 //the methode Outil.enrich will fail, but the procedure has to continue 115 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_addMetadata") + " " + filePath); 116 try { 117 byte[] fichierEnrichi = Outil.enrich(bytesFichierOriginal, Outil.getBytesFromFile(new File(System 118 .getProperty("java.io.tmpdir") 119 + "/originale.jpg"))); 120 Outil.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi); 121 } catch (Exception e) { 122 } 123 } else { 124 originale = new File(filePath); 70 /** 71 * private constructor to use a singleton 72 */ 73 private ImageService() { 125 74 126 75 } 127 Image image = new Image();128 image.setName(getImageName(filePath));129 image.setThumbnail(thumbnail);130 image.setOriginale(originale);131 image.setIdCategory(idCategory);132 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_sendingFiles") + " " + filePath);133 //now we call the dao to send the image to the webservice134 return ImageDao.getInstance().creer(image);135 }136 76 137 /**138 * Add tags to an existing image139 * @param image the image140 * @param tagId the ids of the tags141 * @return true if successful142 * @throws IOException143 */144 public boolean addTags(Image image, String tagId) throws IOException {145 return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId);146 }147 77 148 /** 149 * Search images from a string 150 * @param queryString the string 151 * @return images matching the string 152 * @throws IOException 153 */ 154 public List<Image> search(String queryString) throws IOException { 155 return ImageDao.getInstance().search(queryString); 156 } 78 /** 79 * Lists all images for a category 80 * @param categoryId the id of the category 81 * @param rafraichir true : refresh the list of images 82 * @return the list of images 83 * @throws IOException 84 */ 85 public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException { 86 return ImageDao.getInstance().listerParCategory(categoryId, rafraichir); 87 } 157 88 158 /**159 * Deletes the file extension160 * @param path161 * @return162 */163 private String getImageName(String path) {164 File fichier = new File(path);165 StringBuffer name = new StringBuffer(fichier.getName());166 return (name.delete(name.lastIndexOf("."), name.length())).toString();167 89 168 } 90 /** 91 * Method called to send an image to the server. 92 * @param filePath 93 * @param idCategory 94 * @return 95 * @throws Exception 96 */ 97 public boolean creer(String filePath, Integer idCategory) throws Exception { 98 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_resizing") + " " + filePath); 99 //get the byte array of the original file, to keep metadata 100 byte[] bytesFichierOriginal = Outil.getBytesFromFile(new File(filePath)); 101 102 //size taken from the user's preferences 103 int widthOriginale = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel())); 104 int heightOriginale = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.HEIGHT_ORIGINAL.getLabel())); 105 //resize the picture (or not) 106 boolean originaleRedimensionnee = ImagesUtil.scale(filePath, "originale.jpg", widthOriginale, heightOriginale); 107 //create the thumbnail 108 ImagesUtil.scale(filePath, "thumb.jpg", 120, 90); 109 //get the thumbnail 110 File thumbnail = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg"); 111 File originale = null; 112 if (originaleRedimensionnee) { 113 originale = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg"); 114 //if the original file has been resized, we put the metadata in the resized file 115 //I use here a try catch because if the original file isn't a jpeg 116 //the methode Outil.enrich will fail, but the procedure has to continue 117 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_addMetadata") + " " + filePath); 118 try { 119 byte[] fichierEnrichi = Outil.enrich(bytesFichierOriginal, 120 Outil.getBytesFromFile(new File(System.getProperty("java.io.tmpdir") + "/originale.jpg"))); 121 Outil.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi); 122 } catch (Exception e) { 123 } 124 } else { 125 originale = new File(filePath); 126 127 } 128 Image image = new Image(); 129 image.setName(getImageName(filePath)); 130 image.setThumbnail(thumbnail); 131 image.setOriginale(originale); 132 image.setIdCategory(idCategory); 133 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_sendingFiles") + " " + filePath); 134 //now we call the dao to send the image to the webservice 135 return ImageDao.getInstance().creer(image); 136 } 137 138 139 /** 140 * Add tags to an existing image 141 * @param image the image 142 * @param tagId the ids of the tags 143 * @return true if successful 144 * @throws IOException 145 */ 146 public boolean addTags(Image image, String tagId) throws IOException { 147 return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId); 148 } 149 150 151 /** 152 * Search images from a string 153 * @param queryString the string 154 * @return images matching the string 155 * @throws IOException 156 */ 157 public List<Image> search(String queryString) throws IOException { 158 return ImageDao.getInstance().search(queryString); 159 } 160 161 162 /** 163 * Deletes the file extension 164 * @param path 165 * @return 166 */ 167 private String getImageName(String path) { 168 File fichier = new File(path); 169 StringBuffer name = new StringBuffer(fichier.getName()); 170 return (name.delete(name.lastIndexOf("."), name.length())).toString(); 171 172 } 169 173 170 174 } -
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 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/ConnexionDialog.java
r7070 r7221 16 16 import java.util.Arrays; 17 17 import java.util.Locale; 18 19 18 import javax.swing.AbstractListModel; 20 19 import javax.swing.ComboBoxModel; … … 27 26 import javax.swing.JPasswordField; 28 27 import javax.swing.JTextField; 29 30 28 import fr.mael.jiwigo.Main; 31 29 import fr.mael.jiwigo.transverse.enumeration.PreferencesEnum; … … 33 31 import fr.mael.jiwigo.transverse.util.Messages; 34 32 import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement; 33 35 34 36 35 /** … … 64 63 */ 65 64 public class ConnexionDialog extends JDialog implements ActionListener, ItemListener, KeyListener, WindowListener { 66 /** 67 * Logger 68 */ 69 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 70 .getLog(ConnexionDialog.class); 71 /** 72 * field that contains the url 73 */ 74 private JTextField fieldUrl; 75 /** 76 * field that contains the login 77 */ 78 private JTextField loginField; 79 /** 80 * field that contains de password 81 */ 82 private JPasswordField passwordField; 83 /** 84 * label of the url field 85 */ 86 private JLabel labelUrl; 87 /** 88 * label of the login field 89 */ 90 private JLabel labelLogin; 91 /** 92 * label of the password field 93 */ 94 private JLabel labelPass; 95 /** 96 * ok button for the connection 97 */ 98 private JButton boutonOk; 99 100 /** 101 * Box that allows to save informations 102 */ 103 private JCheckBox checkBoxRetenir; 104 105 /** 106 * Combo containing all locales 107 */ 108 private JComboBox comboLocales; 109 110 /** 111 * Constructor 112 */ 113 public ConnexionDialog() { 114 Locale defautLocale = Messages.usedLocale; 115 labelUrl = new JLabel(Messages.getMessage("connexionDialog_urlSite")); 116 labelLogin = new JLabel(Messages.getMessage("connexionDialog_login")); 117 labelPass = new JLabel(Messages.getMessage("connexionDialog_pass")); 118 comboLocales = new JComboBox(); 119 boutonOk = new JButton("Ok"); 120 String url = PreferencesManagement.getValue(PreferencesEnum.URL_SITE.getLabel()); 121 String login = PreferencesManagement.getValue(PreferencesEnum.LOGIN.getLabel()); 122 String pass = PreferencesManagement.getValue(PreferencesEnum.PASSWORD.getLabel()); 123 fieldUrl = new JTextField(url); 124 loginField = new JTextField(login); 125 passwordField = new JPasswordField(pass); 126 checkBoxRetenir = new JCheckBox(Messages.getMessage("connexionDialog_sauvegarder")); 127 if (!url.equals("") && !login.equals("") && !pass.equals("")) { 128 checkBoxRetenir.setSelected(true); 129 } 130 Dimension fieldDimensions = new Dimension(300, 30); 131 fieldUrl.setPreferredSize(fieldDimensions); 132 fieldUrl.addActionListener(this); 133 loginField.setPreferredSize(fieldDimensions); 134 loginField.addActionListener(this); 135 passwordField.setPreferredSize(fieldDimensions); 136 passwordField.addActionListener(this); 137 this.getContentPane().setLayout(new GridBagLayout()); 138 GridBagConstraints constraints = new GridBagConstraints(); 139 constraints.gridx = 0; 140 constraints.gridy = 0; 141 constraints.insets = new Insets(3, 3, 3, 3); 142 this.getContentPane().add(labelUrl, constraints); 143 constraints.gridx++; 144 this.getContentPane().add(fieldUrl, constraints); 145 constraints.gridx = 0; 146 constraints.gridy++; 147 this.getContentPane().add(labelLogin, constraints); 148 constraints.gridx++; 149 this.getContentPane().add(loginField, constraints); 150 constraints.gridx = 0; 151 constraints.gridy++; 152 this.getContentPane().add(labelPass, constraints); 153 constraints.gridx++; 154 this.getContentPane().add(passwordField, constraints); 155 constraints.gridx = 0; 156 constraints.gridy++; 157 this.getContentPane().add(comboLocales, constraints); 158 constraints.gridx++; 159 this.getContentPane().add(checkBoxRetenir, constraints); 160 constraints.gridx = 0; 161 constraints.gridy++;// 162 // for (Locale locale : SimpleDateFormat.getAvailableLocales()) { 163 // comboLocales.addItem(locale.getDisplayName(Locale.ENGLISH)); 164 // } 165 comboLocales.setPreferredSize(new Dimension(130, 25)); 166 comboLocales.addItemListener(this); 167 localeModel model = new localeModel(); 168 comboLocales.setModel(model); 169 model.setSelectedItem(defautLocale.getDisplayLanguage(Locale.ENGLISH)); 170 this.getContentPane().add(boutonOk, constraints); 171 boutonOk.setPreferredSize(new Dimension(80, 30)); 172 boutonOk.addActionListener(this); 173 this.addWindowListener(this); 174 } 175 176 public void showDialog() { 177 this.pack(); 178 this.setLocationRelativeTo(null); 179 this.setVisible(true); 180 } 181 182 @Override 183 public void actionPerformed(ActionEvent paramActionEvent) { 184 //if one field is empty, an error is displayed 185 if (fieldUrl.getText().equals("") || loginField.getText().equals("") || passwordField.getText().equals("")) { 186 JOptionPane.showMessageDialog(null, Messages.getMessage("connexionDialog_emptyField"), Messages 187 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 188 } else { 189 if (!fieldUrl.getText().startsWith("http://")) { 190 fieldUrl.setText("http://" + fieldUrl.getText()); 191 } 192 //instanciation of the session manager 193 Main.sessionManager = new SessionManager(loginField.getText(), passwordField.getText(), fieldUrl.getText()); 194 if (checkBoxRetenir.isSelected()) { 195 PreferencesManagement.setValue(PreferencesEnum.LOGIN.getLabel(), loginField.getText()); 196 PreferencesManagement.setValue(PreferencesEnum.PASSWORD.getLabel(), passwordField.getText()); 197 PreferencesManagement.setValue(PreferencesEnum.URL_SITE.getLabel(), fieldUrl.getText()); 198 } else { 199 PreferencesManagement.setValue(PreferencesEnum.LOGIN.getLabel(), ""); 200 PreferencesManagement.setValue(PreferencesEnum.PASSWORD.getLabel(), ""); 201 PreferencesManagement.setValue(PreferencesEnum.URL_SITE.getLabel(), ""); 202 } 203 if (!Main.sessionManager.processLogin()) { 204 //if the login fails, an error is displayed 205 JOptionPane.showMessageDialog(null, Messages.getMessage("connexionDialog_connexionError"), Messages 206 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 207 } else { 208 // Locale.setDefault((Locale) comboLocales.getSelectedItem()); 209 Main.showFrame(); 210 //hides the dialog 211 this.dispose(); 212 } 213 } 214 } 215 216 /** 217 * @author mael 218 * Internal class that represents the model of the combobox that allows 219 * to choose a locale 220 */ 221 class localeModel extends AbstractListModel implements ComboBoxModel { 222 Locale[] locales = SimpleDateFormat.getAvailableLocales(); 223 //List<Locale> locales = Messages.getAvailableBundles(); 224 String[] localesNames; 225 226 String selection = null; 227 228 public localeModel() { 229 localesNames = new String[locales.length]; 230 int compteur = 0; 231 for (Locale locale : locales) { 232 localesNames[compteur] = locale.getDisplayName(Locale.ENGLISH); 233 compteur++; 234 } 235 Arrays.sort(localesNames); 236 } 237 238 public Object getElementAt(int index) { 239 return localesNames[index]; 240 } 241 242 public int getSize() { 243 return locales.length; 244 } 245 246 public void setSelectedItem(Object anItem) { 247 selection = (String) anItem; 248 } 249 250 public Object getSelectedItem() { 251 if (selection != null) 252 return selection; 253 else 254 return null; 255 } 256 } 257 258 @Override 259 public void itemStateChanged(ItemEvent paramItemEvent) { 260 for (Locale locale : SimpleDateFormat.getAvailableLocales()) { 261 if (locale.getDisplayName(Locale.ENGLISH).equals(paramItemEvent.getItem())) { 262 Messages.usedLocale = locale; 263 dispose(); 264 ConnexionDialog dial = new ConnexionDialog(); 265 dial.showDialog(); 266 267 } 268 269 } 270 } 271 272 @Override 273 public void keyPressed(KeyEvent arg0) { 274 } 275 276 @Override 277 public void keyReleased(KeyEvent arg0) { 278 279 } 280 281 @Override 282 public void keyTyped(KeyEvent arg0) { 283 } 284 285 @Override 286 public void windowActivated(WindowEvent e) { 287 // TODO Auto-generated method stub 288 289 } 290 291 @Override 292 public void windowClosed(WindowEvent e) { 293 System.out.println("closed"); 294 } 295 296 @Override 297 public void windowClosing(WindowEvent e) { 298 System.exit(0); 299 } 300 301 @Override 302 public void windowDeactivated(WindowEvent e) { 303 // TODO Auto-generated method stub 304 305 } 306 307 @Override 308 public void windowDeiconified(WindowEvent e) { 309 // TODO Auto-generated method stub 310 311 } 312 313 @Override 314 public void windowIconified(WindowEvent e) { 315 // TODO Auto-generated method stub 316 317 } 318 319 @Override 320 public void windowOpened(WindowEvent e) { 321 // TODO Auto-generated method stub 322 323 } 65 66 /** 67 * Logger 68 */ 69 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ConnexionDialog.class); 70 /** 71 * field that contains the url 72 */ 73 private JTextField fieldUrl; 74 /** 75 * field that contains the login 76 */ 77 private JTextField loginField; 78 /** 79 * field that contains de password 80 */ 81 private JPasswordField passwordField; 82 /** 83 * label of the url field 84 */ 85 private JLabel labelUrl; 86 /** 87 * label of the login field 88 */ 89 private JLabel labelLogin; 90 /** 91 * label of the password field 92 */ 93 private JLabel labelPass; 94 /** 95 * ok button for the connection 96 */ 97 private JButton boutonOk; 98 99 /** 100 * Box that allows to save informations 101 */ 102 private JCheckBox checkBoxRetenir; 103 104 /** 105 * Combo containing all locales 106 */ 107 private JComboBox comboLocales; 108 109 110 /** 111 * Constructor 112 */ 113 public ConnexionDialog() { 114 Locale defautLocale = Messages.usedLocale; 115 labelUrl = new JLabel(Messages.getMessage("connexionDialog_urlSite")); 116 labelLogin = new JLabel(Messages.getMessage("connexionDialog_login")); 117 labelPass = new JLabel(Messages.getMessage("connexionDialog_pass")); 118 comboLocales = new JComboBox(); 119 boutonOk = new JButton("Ok"); 120 String url = PreferencesManagement.getValue(PreferencesEnum.URL_SITE.getLabel()); 121 String login = PreferencesManagement.getValue(PreferencesEnum.LOGIN.getLabel()); 122 String pass = PreferencesManagement.getValue(PreferencesEnum.PASSWORD.getLabel()); 123 fieldUrl = new JTextField(url); 124 loginField = new JTextField(login); 125 passwordField = new JPasswordField(pass); 126 checkBoxRetenir = new JCheckBox(Messages.getMessage("connexionDialog_sauvegarder")); 127 if (!url.equals("") && !login.equals("") && !pass.equals("")) { 128 checkBoxRetenir.setSelected(true); 129 } 130 Dimension fieldDimensions = new Dimension(300, 30); 131 fieldUrl.setPreferredSize(fieldDimensions); 132 fieldUrl.addActionListener(this); 133 loginField.setPreferredSize(fieldDimensions); 134 loginField.addActionListener(this); 135 passwordField.setPreferredSize(fieldDimensions); 136 passwordField.addActionListener(this); 137 this.getContentPane().setLayout(new GridBagLayout()); 138 GridBagConstraints constraints = new GridBagConstraints(); 139 constraints.gridx = 0; 140 constraints.gridy = 0; 141 constraints.insets = new Insets(3, 3, 3, 3); 142 this.getContentPane().add(labelUrl, constraints); 143 constraints.gridx++; 144 this.getContentPane().add(fieldUrl, constraints); 145 constraints.gridx = 0; 146 constraints.gridy++; 147 this.getContentPane().add(labelLogin, constraints); 148 constraints.gridx++; 149 this.getContentPane().add(loginField, constraints); 150 constraints.gridx = 0; 151 constraints.gridy++; 152 this.getContentPane().add(labelPass, constraints); 153 constraints.gridx++; 154 this.getContentPane().add(passwordField, constraints); 155 constraints.gridx = 0; 156 constraints.gridy++; 157 this.getContentPane().add(comboLocales, constraints); 158 constraints.gridx++; 159 this.getContentPane().add(checkBoxRetenir, constraints); 160 constraints.gridx = 0; 161 constraints.gridy++;// 162 // for (Locale locale : SimpleDateFormat.getAvailableLocales()) { 163 // comboLocales.addItem(locale.getDisplayName(Locale.ENGLISH)); 164 // } 165 comboLocales.setPreferredSize(new Dimension(130, 25)); 166 comboLocales.addItemListener(this); 167 localeModel model = new localeModel(); 168 comboLocales.setModel(model); 169 model.setSelectedItem(defautLocale.getDisplayLanguage(Locale.ENGLISH)); 170 this.getContentPane().add(boutonOk, constraints); 171 boutonOk.setPreferredSize(new Dimension(80, 30)); 172 boutonOk.addActionListener(this); 173 this.addWindowListener(this); 174 } 175 176 177 public void showDialog() { 178 this.pack(); 179 this.setLocationRelativeTo(null); 180 this.setVisible(true); 181 } 182 183 184 @Override 185 public void actionPerformed(ActionEvent paramActionEvent) { 186 //if one field is empty, an error is displayed 187 if (fieldUrl.getText().equals("") || loginField.getText().equals("") || passwordField.getText().equals("")) { 188 JOptionPane.showMessageDialog(null, Messages.getMessage("connexionDialog_emptyField"), 189 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 190 } else { 191 if (!fieldUrl.getText().startsWith("http://")) { 192 fieldUrl.setText("http://" + fieldUrl.getText()); 193 } 194 //instanciation of the session manager 195 Main.sessionManager = new SessionManager(loginField.getText(), passwordField.getText(), fieldUrl.getText()); 196 if (checkBoxRetenir.isSelected()) { 197 PreferencesManagement.setValue(PreferencesEnum.LOGIN.getLabel(), loginField.getText()); 198 PreferencesManagement.setValue(PreferencesEnum.PASSWORD.getLabel(), passwordField.getText()); 199 PreferencesManagement.setValue(PreferencesEnum.URL_SITE.getLabel(), fieldUrl.getText()); 200 } else { 201 PreferencesManagement.setValue(PreferencesEnum.LOGIN.getLabel(), ""); 202 PreferencesManagement.setValue(PreferencesEnum.PASSWORD.getLabel(), ""); 203 PreferencesManagement.setValue(PreferencesEnum.URL_SITE.getLabel(), ""); 204 } 205 if (!Main.sessionManager.processLogin()) { 206 //if the login fails, an error is displayed 207 JOptionPane.showMessageDialog(null, Messages.getMessage("connexionDialog_connexionError"), 208 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 209 } else { 210 // Locale.setDefault((Locale) comboLocales.getSelectedItem()); 211 Main.showFrame(); 212 //hides the dialog 213 this.dispose(); 214 } 215 } 216 } 217 218 /** 219 * @author mael 220 * Internal class that represents the model of the combobox that allows 221 * to choose a locale 222 */ 223 class localeModel extends AbstractListModel implements ComboBoxModel { 224 225 Locale[] locales = SimpleDateFormat.getAvailableLocales(); 226 //List<Locale> locales = Messages.getAvailableBundles(); 227 String[] localesNames; 228 229 String selection = null; 230 231 232 public localeModel() { 233 localesNames = new String[locales.length]; 234 int compteur = 0; 235 for (Locale locale : locales) { 236 localesNames[compteur] = locale.getDisplayName(Locale.ENGLISH); 237 compteur++; 238 } 239 Arrays.sort(localesNames); 240 } 241 242 243 public Object getElementAt(int index) { 244 return localesNames[index]; 245 } 246 247 248 public int getSize() { 249 return locales.length; 250 } 251 252 253 public void setSelectedItem(Object anItem) { 254 selection = (String) anItem; 255 } 256 257 258 public Object getSelectedItem() { 259 if (selection != null) 260 return selection; 261 else 262 return null; 263 } 264 } 265 266 267 @Override 268 public void itemStateChanged(ItemEvent paramItemEvent) { 269 for (Locale locale : SimpleDateFormat.getAvailableLocales()) { 270 if (locale.getDisplayName(Locale.ENGLISH).equals(paramItemEvent.getItem())) { 271 Messages.usedLocale = locale; 272 dispose(); 273 ConnexionDialog dial = new ConnexionDialog(); 274 dial.showDialog(); 275 276 } 277 278 } 279 } 280 281 282 @Override 283 public void keyPressed(KeyEvent arg0) { 284 } 285 286 287 @Override 288 public void keyReleased(KeyEvent arg0) { 289 290 } 291 292 293 @Override 294 public void keyTyped(KeyEvent arg0) { 295 } 296 297 298 @Override 299 public void windowActivated(WindowEvent e) { 300 // TODO Auto-generated method stub 301 302 } 303 304 305 @Override 306 public void windowClosed(WindowEvent e) { 307 } 308 309 310 @Override 311 public void windowClosing(WindowEvent e) { 312 System.exit(0); 313 } 314 315 316 @Override 317 public void windowDeactivated(WindowEvent e) { 318 // TODO Auto-generated method stub 319 320 } 321 322 323 @Override 324 public void windowDeiconified(WindowEvent e) { 325 // TODO Auto-generated method stub 326 327 } 328 329 330 @Override 331 public void windowIconified(WindowEvent e) { 332 // TODO Auto-generated method stub 333 334 } 335 336 337 @Override 338 public void windowOpened(WindowEvent e) { 339 // TODO Auto-generated method stub 340 341 } 324 342 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/CategoriesTree.java
r6980 r7221 8 8 import java.awt.event.MouseListener; 9 9 import java.util.List; 10 11 10 import javax.swing.JMenuItem; 12 11 import javax.swing.JOptionPane; … … 21 20 import javax.swing.tree.TreePath; 22 21 import javax.swing.tree.TreeSelectionModel; 23 24 22 import fr.mael.jiwigo.om.Category; 25 23 import fr.mael.jiwigo.service.CategoryService; 26 24 import fr.mael.jiwigo.transverse.util.Messages; 27 25 import fr.mael.jiwigo.transverse.util.Outil; 26 28 27 29 28 /** … … 58 57 public class CategoriesTree extends JPanel implements TreeSelectionListener, MouseListener, ActionListener { 59 58 60 /** 61 * Logger 62 */ 63 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 64 .getLog(CategoriesTree.class); 65 /** 66 * the tree 67 */ 68 private JTree tree; 69 /** 70 * the menu to add a category 71 */ 72 private JMenuItem menuAjouter; 73 /** 74 * the menu to refresh the categories 75 */ 76 private JMenuItem menuActualiser; 77 /** 78 * the root of the tree which is not displayed 79 */ 80 private DefaultMutableTreeNode root = new DefaultMutableTreeNode(""); 81 /** 82 * the selected category 83 */ 84 private Category selectedCategory; 85 86 /** 87 * Constructor 88 */ 89 public CategoriesTree() { 90 super(new BorderLayout()); 91 //creation of the tree 92 createNodes(root); 93 tree = new JTree(root); 94 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 95 tree.addTreeSelectionListener(this); 96 tree.setRootVisible(false); 97 tree.addMouseListener(this); 98 JScrollPane treeView = new JScrollPane(tree); 99 Dimension minimumSize = new Dimension(100, 50); 100 treeView.setMinimumSize(minimumSize); 101 add(treeView, BorderLayout.CENTER); 102 } 103 104 /** 105 * Method that allows to update the tree 106 */ 107 public void setUpUi() { 108 //begin bug:0001830 109 root.removeAllChildren(); 110 createNodes(root); 111 ((DefaultTreeModel) tree.getModel()).reload(); 112 //end 113 114 } 115 116 /* (non-Javadoc) 117 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent) 118 */ 119 public void valueChanged(TreeSelectionEvent e) { 120 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); 121 // 122 if (node == null) 123 return; 124 Object catSelectionnee = node.getUserObject(); 125 Category category = (Category) catSelectionnee; 126 //MainFrame.imagesPanel.rafraichir(category.getIdentifiant(), false); 127 MainFrame.getInstance().addTabb(new ThumbnailCategoryPanel(category)); 128 } 129 130 /** 131 * creation of the nodes 132 * @param root the root 133 */ 134 private void createNodes(DefaultMutableTreeNode root) { 135 DefaultMutableTreeNode category = null; 136 try { 137 List<Category> list = CategoryService.getInstance().construireArbre(); 138 for (Category cat : list) { 139 if (cat.getCategoriesMeres().size() == 0) { 140 category = new DefaultMutableTreeNode(cat); 141 root.add(category); 142 recursiveNodeCreation(category, cat); 143 } 144 145 } 146 } catch (Exception e) { 147 LOG.error(Outil.getStackTrace(e)); 148 JOptionPane.showMessageDialog(null, Messages.getMessage("treeCreationError"), Messages.getMessage("error"), 149 JOptionPane.ERROR_MESSAGE); 150 } 151 152 } 153 154 /** 155 * recursive method for the creation of the nodes 156 * @param categoryNode 157 * @param category 158 */ 159 private void recursiveNodeCreation(DefaultMutableTreeNode categoryNode, Category category) { 160 for (Category cat : category.getCategoriesFilles()) { 161 DefaultMutableTreeNode node = new DefaultMutableTreeNode(cat); 162 categoryNode.add(node); 163 recursiveNodeCreation(node, cat); 164 } 165 } 166 167 @Override 168 public void mouseClicked(MouseEvent arg0) { 169 170 } 171 172 @Override 173 public void mouseEntered(MouseEvent arg0) { 174 // TODO Auto-generated method stub 175 176 } 177 178 @Override 179 public void mouseExited(MouseEvent arg0) { 180 // TODO Auto-generated method stub 181 182 } 183 184 @Override 185 public void mousePressed(MouseEvent e) { 186 int selRow = tree.getRowForLocation(e.getX(), e.getY()); 187 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 188 //begin bug:0001832 189 tree.setSelectionRow(selRow); 190 //end 191 192 if (e.getButton() == 3) { 193 JPopupMenu popup = new JPopupMenu(); 194 menuAjouter = new JMenuItem(Messages.getMessage("categories_add")); 195 menuAjouter.addActionListener(this); 196 popup.add(menuAjouter); 197 menuActualiser = new JMenuItem(Messages.getMessage("categories_update")); 198 menuActualiser.addActionListener(this); 199 popup.add(menuActualiser); 200 popup.show(tree, e.getX(), e.getY()); 201 if (selRow != -1) { 202 DefaultMutableTreeNode node = (DefaultMutableTreeNode) (selPath.getLastPathComponent()); 203 this.selectedCategory = (Category) node.getUserObject(); 204 } else { 205 this.selectedCategory = null; 206 } 207 } 208 209 } 210 211 @Override 212 public void mouseReleased(MouseEvent arg0) { 213 // TODO Auto-generated method stub 214 215 } 216 217 @Override 218 public void actionPerformed(ActionEvent arg0) { 219 if (arg0.getSource().equals(menuAjouter)) { 220 String nomcategorie = JOptionPane.showInputDialog(null, Messages.getMessage("categories_enterName"), 221 Messages.getMessage("categories_add"), JOptionPane.INFORMATION_MESSAGE); 222 //if the name of the category is not empty 223 if (!(nomcategorie == null) && !nomcategorie.equals("")) { 224 //if there is a parent category 225 if (selectedCategory != null) { 226 //try to create a category 227 if (CategoryService.getInstance().creer(nomcategorie, selectedCategory.getIdentifiant())) { 59 /** 60 * Logger 61 */ 62 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(CategoriesTree.class); 63 /** 64 * the tree 65 */ 66 private JTree tree; 67 /** 68 * the menu to add a category 69 */ 70 private JMenuItem menuAjouter; 71 /** 72 * the menu to refresh the categories 73 */ 74 private JMenuItem menuActualiser; 75 /** 76 * the root of the tree which is not displayed 77 */ 78 private DefaultMutableTreeNode root = new DefaultMutableTreeNode(""); 79 /** 80 * the selected category 81 */ 82 private Category selectedCategory; 83 84 85 /** 86 * Constructor 87 */ 88 public CategoriesTree() { 89 super(new BorderLayout()); 90 //creation of the tree 91 createNodes(root); 92 tree = new JTree(root); 93 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 94 tree.addTreeSelectionListener(this); 95 tree.setRootVisible(false); 96 tree.addMouseListener(this); 97 JScrollPane treeView = new JScrollPane(tree); 98 Dimension minimumSize = new Dimension(100, 50); 99 treeView.setMinimumSize(minimumSize); 100 add(treeView, BorderLayout.CENTER); 101 } 102 103 104 /** 105 * Method that allows to update the tree 106 */ 107 public void setUpUi() { 108 //begin bug:0001830 109 root.removeAllChildren(); 110 createNodes(root); 111 ((DefaultTreeModel) tree.getModel()).reload(); 112 //end 113 114 } 115 116 117 /* (non-Javadoc) 118 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent) 119 */ 120 public void valueChanged(TreeSelectionEvent e) { 121 DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); 122 // 123 if (node == null) 124 return; 125 Object catSelectionnee = node.getUserObject(); 126 Category category = (Category) catSelectionnee; 127 //MainFrame.imagesPanel.rafraichir(category.getIdentifiant(), false); 128 MainFrame.getInstance().addTabb(new ThumbnailCategoryPanel(category)); 129 } 130 131 132 /** 133 * creation of the nodes 134 * @param root the root 135 */ 136 private void createNodes(DefaultMutableTreeNode root) { 137 DefaultMutableTreeNode category = null; 138 try { 139 List<Category> list = CategoryService.getInstance().construireArbre(); 140 for (Category cat : list) { 141 if (cat.getCategoriesMeres().size() == 0) { 142 category = new DefaultMutableTreeNode(cat); 143 root.add(category); 144 recursiveNodeCreation(category, cat); 145 } 146 147 } 148 } catch (Exception e) { 149 LOG.error(Outil.getStackTrace(e)); 150 JOptionPane.showMessageDialog(null, Messages.getMessage("treeCreationError"), Messages.getMessage("error"), 151 JOptionPane.ERROR_MESSAGE); 152 } 153 154 } 155 156 157 /** 158 * recursive method for the creation of the nodes 159 * @param categoryNode 160 * @param category 161 */ 162 private void recursiveNodeCreation(DefaultMutableTreeNode categoryNode, Category category) { 163 for (Category cat : category.getCategoriesFilles()) { 164 DefaultMutableTreeNode node = new DefaultMutableTreeNode(cat); 165 categoryNode.add(node); 166 recursiveNodeCreation(node, cat); 167 } 168 } 169 170 171 @Override 172 public void mouseClicked(MouseEvent arg0) { 173 174 } 175 176 177 @Override 178 public void mouseEntered(MouseEvent arg0) { 179 // TODO Auto-generated method stub 180 181 } 182 183 184 @Override 185 public void mouseExited(MouseEvent arg0) { 186 // TODO Auto-generated method stub 187 188 } 189 190 191 @Override 192 public void mousePressed(MouseEvent e) { 193 int selRow = tree.getRowForLocation(e.getX(), e.getY()); 194 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 195 //begin bug:0001832 196 tree.setSelectionRow(selRow); 197 //end 198 199 if (e.getButton() == 3) { 200 JPopupMenu popup = new JPopupMenu(); 201 menuAjouter = new JMenuItem(Messages.getMessage("categories_add")); 202 menuAjouter.addActionListener(this); 203 popup.add(menuAjouter); 204 menuActualiser = new JMenuItem(Messages.getMessage("categories_update")); 205 menuActualiser.addActionListener(this); 206 popup.add(menuActualiser); 207 popup.show(tree, e.getX(), e.getY()); 208 if (selRow != -1) { 209 DefaultMutableTreeNode node = (DefaultMutableTreeNode) (selPath.getLastPathComponent()); 210 this.selectedCategory = (Category) node.getUserObject(); 211 } else { 212 this.selectedCategory = null; 213 } 214 } 215 216 } 217 218 219 @Override 220 public void mouseReleased(MouseEvent arg0) { 221 // TODO Auto-generated method stub 222 223 } 224 225 226 @Override 227 public void actionPerformed(ActionEvent arg0) { 228 if (arg0.getSource().equals(menuAjouter)) { 229 String nomcategorie = JOptionPane.showInputDialog(null, Messages.getMessage("categories_enterName"), 230 Messages.getMessage("categories_add"), JOptionPane.INFORMATION_MESSAGE); 231 //if the name of the category is not empty 232 if (!(nomcategorie == null) && !nomcategorie.equals("")) { 233 //if there is a parent category 234 if (selectedCategory != null) { 235 //try to create a category 236 if (CategoryService.getInstance().creer(nomcategorie, selectedCategory.getIdentifiant())) { 237 setUpUi(); 238 } else { 239 JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), 240 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 241 242 } 243 } else { 244 if (CategoryService.getInstance().creer(nomcategorie)) { 245 setUpUi(); 246 } else { 247 JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), 248 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 249 250 } 251 } 252 } 253 } else if (arg0.getSource().equals(menuActualiser)) { 228 254 setUpUi(); 229 } else { 230 JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages 231 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 232 233 } 234 } else { 235 if (CategoryService.getInstance().creer(nomcategorie)) { 236 setUpUi(); 237 } else { 238 JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages 239 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 240 241 } 242 } 243 } 244 } else if (arg0.getSource().equals(menuActualiser)) { 245 setUpUi(); 246 } 247 } 255 } 256 } 248 257 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java
r6980 r7221 9 9 import java.awt.event.KeyListener; 10 10 import java.util.HashMap; 11 12 11 import javax.swing.ImageIcon; 13 12 import javax.swing.JComponent; … … 21 20 import javax.swing.JScrollPane; 22 21 import javax.swing.JSplitPane; 23 24 22 import fr.mael.jiwigo.transverse.util.Messages; 25 23 import fr.mael.jiwigo.transverse.util.Outil; 26 24 import fr.mael.jiwigo.ui.field.HintTextField; 27 25 import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons; 26 28 27 29 28 /** … … 57 56 */ 58 57 public class MainFrame extends JFrame implements ActionListener, KeyListener { 59 /** 60 * Logger 61 */ 62 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 63 .getLog(MainFrame.class); 64 /** 65 * the categories tree 66 */ 67 private CategoriesTree categoriesTree; 68 /** 69 * Splitpane. On the left : the categories tree and on the right the thumbnails 70 * for the current category 71 */ 72 private JSplitPane splitPane; 73 /** 74 * Panel that contains the thumbnail of the current category 75 */ 76 public static ThumbnailCategoryPanel imagesPanel; 77 /** 78 * Scrollpane that contains the panel above 79 */ 80 private JScrollPane scrollPaneImagesPanel; 81 /** 82 * label that displays messages 83 */ 84 private JLabel labelMessage; 85 86 /** 87 * menu bar 88 */ 89 private JMenuBar jMenuBar; 90 91 /** 92 * edition menu 93 */ 94 private JMenu jMenuEdition; 95 96 /** 97 * preferences menu 98 */ 99 private JMenuItem jMenuItemPreferences; 100 101 /** 102 * singleton 103 */ 104 private static MainFrame instance; 105 106 private JProgressBar progressBar; 107 108 private JTabbedPaneWithCloseIcons tabbedPane; 109 110 private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>(); 111 112 private HintTextField fieldSearch; 113 114 /** 115 * @return the singleton 116 */ 117 public static MainFrame getInstance() { 118 if (instance == null) { 119 instance = new MainFrame(); 120 } 121 return instance; 122 } 123 124 /** 125 * private constructor to use a singleton 126 */ 127 private MainFrame() { 128 this.setTitle("Jiwigo v" + Messages.getMessage("version")); 129 this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png"))); 130 this.setLayout(new BorderLayout()); 131 jMenuBar = new JMenuBar(); 132 labelMessage = new JLabel(Messages.getMessage("welcomeMessage")); 133 splitPane = new JSplitPane(); 134 categoriesTree = new CategoriesTree(); 135 splitPane.setLeftComponent(categoriesTree); 136 137 tabbedPane = new JTabbedPaneWithCloseIcons(); 138 splitPane.setRightComponent(tabbedPane); 139 140 this.add(splitPane, BorderLayout.CENTER); 141 JPanel panelBas = new JPanel(new BorderLayout()); 142 JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 143 progressBar = new JProgressBar(0, 100); 144 panel.add(progressBar); 145 panel.add(labelMessage); 146 panelBas.add(panel, BorderLayout.WEST); 147 148 fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche")); 149 fieldSearch.setPreferredSize(new Dimension(150, 25)); 150 fieldSearch.addKeyListener(this); 151 panelBas.add(fieldSearch, BorderLayout.EAST); 152 153 jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu")); 154 jMenuBar.add(jMenuEdition); 155 jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu")); 156 jMenuItemPreferences.addActionListener(this); 157 jMenuEdition.add(jMenuItemPreferences); 158 159 this.setJMenuBar(jMenuBar); 160 this.add(panelBas, BorderLayout.SOUTH); 161 this.setSize(900, 600); 162 this.setLocationRelativeTo(null); 163 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 164 this.setResizable(true); 165 } 166 167 public void addTabb(IThumbnailPanel panel) { 168 JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 169 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 170 scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600)); 171 boolean found = false; 172 boolean isSearch = false; 173 if (panel instanceof ThumbnailSearchPanel) { 174 isSearch = true; 175 } 176 for (int i = 0; i < tabbedPane.getTabCount(); i++) { 177 JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i); 178 IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0]; 179 if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) { 180 //only if it's not for a re 181 if (!(panel instanceof ThumbnailSearchPanel)) { 182 tabbedPane.setSelectedIndex(i); 183 found = true; 184 break; 185 } 186 } 187 } 188 //if it's not for a research, the title of the tab 189 //is the name of the category 190 if (!found && !isSearch) { 191 tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil 192 .getURL("fr/mael/jiwigo/img/closetab.png"))); 193 //if it's for a research, the title of the tab 194 //if the query string 195 } else if (!found && isSearch) { 196 String queryString = ((ThumbnailSearchPanel) panel).getQueryString(); 197 tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel, 198 new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png"))); 199 } 200 201 } 202 203 /** 204 * displays the frame 205 */ 206 public void showUi() { 207 this.setVisible(true); 208 } 209 210 /** 211 * Affichage d'un message de réussite 212 * @param message 213 */ 214 public void setMessage(String message) { 215 this.labelMessage.setText(message); 216 } 217 218 @Override 219 public void actionPerformed(ActionEvent arg0) { 220 if (arg0.getSource().equals(jMenuItemPreferences)) { 221 new PreferencesDialog(this); 222 } 223 224 } 225 226 public static void reduceSizeOfComponent(JComponent comp) { 227 comp.setMaximumSize(comp.getPreferredSize()); 228 } 229 230 /** 231 * @return the progressBar 232 */ 233 public JProgressBar getProgressBar() { 234 return progressBar; 235 } 236 237 /** 238 * @return the mapsIdPos 239 */ 240 public HashMap<Integer, Integer> getMapsIdPos() { 241 return mapsIdPos; 242 } 243 244 @Override 245 public void keyPressed(KeyEvent paramKeyEvent) { 246 if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) { 247 String queryString = fieldSearch.getText(); 248 ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString); 249 addTabb(searchPanel); 250 } 251 } 252 253 @Override 254 public void keyReleased(KeyEvent paramKeyEvent) { 255 } 256 257 @Override 258 public void keyTyped(KeyEvent paramKeyEvent) { 259 } 58 59 /** 60 * Logger 61 */ 62 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(MainFrame.class); 63 /** 64 * the categories tree 65 */ 66 private CategoriesTree categoriesTree; 67 /** 68 * Splitpane. On the left : the categories tree and on the right the thumbnails 69 * for the current category 70 */ 71 private JSplitPane splitPane; 72 /** 73 * Panel that contains the thumbnail of the current category 74 */ 75 public static ThumbnailCategoryPanel imagesPanel; 76 /** 77 * Scrollpane that contains the panel above 78 */ 79 private JScrollPane scrollPaneImagesPanel; 80 /** 81 * label that displays messages 82 */ 83 private JLabel labelMessage; 84 85 /** 86 * menu bar 87 */ 88 private JMenuBar jMenuBar; 89 90 /** 91 * edition menu 92 */ 93 private JMenu jMenuEdition; 94 95 /** 96 * preferences menu 97 */ 98 private JMenuItem jMenuItemPreferences; 99 100 /** 101 * singleton 102 */ 103 private static MainFrame instance; 104 105 private JProgressBar progressBar; 106 107 private JTabbedPaneWithCloseIcons tabbedPane; 108 109 private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>(); 110 111 private HintTextField fieldSearch; 112 113 114 /** 115 * @return the singleton 116 */ 117 public static MainFrame getInstance() { 118 if (instance == null) { 119 instance = new MainFrame(); 120 } 121 return instance; 122 } 123 124 125 /** 126 * private constructor to use a singleton 127 */ 128 private MainFrame() { 129 this.setTitle("Jiwigo v" + Messages.getMessage("version")); 130 this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png"))); 131 this.setLayout(new BorderLayout()); 132 jMenuBar = new JMenuBar(); 133 labelMessage = new JLabel(Messages.getMessage("welcomeMessage")); 134 splitPane = new JSplitPane(); 135 categoriesTree = new CategoriesTree(); 136 splitPane.setLeftComponent(categoriesTree); 137 138 tabbedPane = new JTabbedPaneWithCloseIcons(); 139 splitPane.setRightComponent(tabbedPane); 140 141 this.add(splitPane, BorderLayout.CENTER); 142 JPanel panelBas = new JPanel(new BorderLayout()); 143 JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 144 progressBar = new JProgressBar(0, 100); 145 panel.add(progressBar); 146 panel.add(labelMessage); 147 panelBas.add(panel, BorderLayout.WEST); 148 149 fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche")); 150 fieldSearch.setPreferredSize(new Dimension(150, 25)); 151 fieldSearch.addKeyListener(this); 152 panelBas.add(fieldSearch, BorderLayout.EAST); 153 154 jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu")); 155 jMenuBar.add(jMenuEdition); 156 jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu")); 157 jMenuItemPreferences.addActionListener(this); 158 jMenuEdition.add(jMenuItemPreferences); 159 160 this.setJMenuBar(jMenuBar); 161 this.add(panelBas, BorderLayout.SOUTH); 162 this.setSize(900, 600); 163 this.setLocationRelativeTo(null); 164 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 165 this.setResizable(true); 166 } 167 168 169 public void addTabb(IThumbnailPanel panel) { 170 JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 171 scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600)); 172 boolean found = false; 173 boolean isSearch = false; 174 if (panel instanceof ThumbnailSearchPanel) { 175 isSearch = true; 176 } 177 178 for (int i = 0; i < tabbedPane.getTabCount(); i++) { 179 JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i); 180 IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0]; 181 if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) { 182 //only if it's not for a re 183 if (!(panel instanceof ThumbnailSearchPanel)) { 184 tabbedPane.setSelectedIndex(i); 185 found = true; 186 break; 187 } 188 } 189 } 190 //if it's not for a research, the title of the tab 191 //is the name of the category 192 if (!found && !isSearch) { 193 tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, 194 new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png"))); 195 //if it's for a research, the title of the tab 196 //if the query string 197 } else if (!found && isSearch) { 198 String queryString = ((ThumbnailSearchPanel) panel).getQueryString(); 199 tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel, 200 new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png"))); 201 } 202 203 } 204 205 206 /** 207 * displays the frame 208 */ 209 public void showUi() { 210 this.setVisible(true); 211 } 212 213 214 /** 215 * Affichage d'un message de réussite 216 * @param message 217 */ 218 public void setMessage(String message) { 219 this.labelMessage.setText(message); 220 } 221 222 223 @Override 224 public void actionPerformed(ActionEvent arg0) { 225 if (arg0.getSource().equals(jMenuItemPreferences)) { 226 new PreferencesDialog(this); 227 } 228 229 } 230 231 232 public static void reduceSizeOfComponent(JComponent comp) { 233 comp.setMaximumSize(comp.getPreferredSize()); 234 } 235 236 237 /** 238 * @return the progressBar 239 */ 240 public JProgressBar getProgressBar() { 241 return progressBar; 242 } 243 244 245 /** 246 * @return the mapsIdPos 247 */ 248 public HashMap<Integer, Integer> getMapsIdPos() { 249 return mapsIdPos; 250 } 251 252 253 @Override 254 public void keyPressed(KeyEvent paramKeyEvent) { 255 if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) { 256 String queryString = fieldSearch.getText(); 257 ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString); 258 addTabb(searchPanel); 259 } 260 } 261 262 263 @Override 264 public void keyReleased(KeyEvent paramKeyEvent) { 265 } 266 267 268 @Override 269 public void keyTyped(KeyEvent paramKeyEvent) { 270 } 260 271 261 272 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java
r7070 r7221 1 1 package fr.mael.jiwigo.ui.mainframe; 2 2 3 import java.awt.Dimension; 3 4 import java.awt.FlowLayout; 5 import java.awt.Graphics; 4 6 import java.io.File; 5 6 7 import javax.swing.JOptionPane; 7 8 import javax.swing.JPanel; 8 9 9 import fr.mael.jiwigo.om.Category; 10 10 import fr.mael.jiwigo.om.Image; … … 15 15 import fr.mael.jiwigo.transverse.util.filedrop.FileDrop; 16 16 import fr.mael.jiwigo.ui.layout.VerticalLayout; 17 17 18 18 19 /** … … 46 47 */ 47 48 public class ThumbnailCategoryPanel extends JPanel implements IThumbnailPanel { 48 /** 49 * Logger 50 */ 51 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 52 .getLog(ThumbnailCategoryPanel.class); 53 /** 54 * id of the category 55 */ 56 private Integer categoryId; 57 58 private Category category; 59 60 public ThumbnailCategoryPanel(Category category) { 61 this(category.getIdentifiant()); 62 this.category = category; 63 } 64 65 /** 66 * Constructor 67 * @param categoryId id of the category 68 */ 69 public ThumbnailCategoryPanel(Integer categoryId) { 70 this.categoryId = categoryId; 71 this.setLayout(new VerticalLayout()); 72 if (categoryId != null) { 73 rafraichir(categoryId, false); 74 } 75 //gestion du drag'n drop 76 new FileDrop(System.out, this, new FileDrop.Listener() { 77 public void filesDropped(final java.io.File[] files) { 78 if (!ImagesManagement.rememberPrivacyLevel) { 79 new DialogPrivacyLevel(); 80 } 81 new Thread(new ThreadEnvoiPhoto(files)).start(); 82 83 } 84 }); 85 86 } 87 88 /** 89 * refreshes the panel 90 * @param categoryId the id of the category 91 */ 92 public void rafraichir(Integer categoryId, boolean rafraichir) { 93 this.categoryId = categoryId; 94 new Thread(new ThreadLoadThumb(this, rafraichir)).start(); 95 } 96 97 /** 98 * @return the categoryId 99 */ 100 public Integer getCategoryId() { 101 return categoryId; 102 } 103 104 /** 105 * @param categoryId the categoryId to set 106 */ 107 public void setCategoryId(Integer categoryId) { 108 this.categoryId = categoryId; 109 } 110 111 /** 112 * @return the category 113 */ 114 public Category getCategory() { 115 return category; 116 } 117 118 /** 119 * @param category the category to set 120 */ 121 public void setCategory(Category category) { 122 this.category = category; 123 } 124 125 /** 126 * @author mael 127 * Thread that send the photos 128 */ 129 public class ThreadEnvoiPhoto implements Runnable { 130 private File[] files; 131 132 public ThreadEnvoiPhoto(File[] files) { 133 this.files = files; 134 } 49 50 /** 51 * Logger 52 */ 53 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ThumbnailCategoryPanel.class); 54 /** 55 * id of the category 56 */ 57 private Integer categoryId; 58 59 private Category category; 60 61 /** 62 * thumbnails per line 63 */ 64 private int thumbnailPerLine = 7; 65 66 /** 67 * Saved dimension of the panel, used to define the number 68 * of thumbnails on a line 69 */ 70 private Dimension savedDimension = new Dimension(); 71 72 73 public ThumbnailCategoryPanel(Category category) { 74 this(category.getIdentifiant()); 75 this.category = category; 76 } 77 78 79 /** 80 * Constructor 81 * @param categoryId id of the category 82 */ 83 public ThumbnailCategoryPanel(Integer categoryId) { 84 this.categoryId = categoryId; 85 this.setLayout(new VerticalLayout()); 86 if (categoryId != null) { 87 rafraichir(categoryId, false); 88 } 89 //gestion du drag'n drop 90 new FileDrop(System.out, this, new FileDrop.Listener() { 91 92 public void filesDropped(final java.io.File[] files) { 93 if (!ImagesManagement.rememberPrivacyLevel) { 94 new DialogPrivacyLevel(); 95 } 96 new Thread(new ThreadEnvoiPhoto(files)).start(); 97 98 } 99 }); 100 101 } 102 135 103 136 104 @Override 137 public void run() { 138 139 for (int i = 0; i < files.length; i++) { 140 int nbProgressBar = ((i + 1) * 100) / files.length; 105 public void paint(Graphics g) { 106 super.paint(g); 107 if (!MainFrame.getInstance().getSize().equals(savedDimension)) { 108 // LOG.debug("paint " + getSize()); 109 savedDimension = MainFrame.getInstance().getSize(); 110 int width = savedDimension.width; 111 thumbnailPerLine = width / 150; 112 addThumbnails(); 113 } 114 } 115 116 117 /** 118 * refreshes the panel 119 * @param categoryId the id of the category 120 */ 121 public void rafraichir(Integer categoryId, boolean rafraichir) { 122 this.categoryId = categoryId; 141 123 try { 142 143 ImageService.getInstance().creer(files[i].getCanonicalPath(), categoryId); 144 MainFrame.getInstance() 145 .setMessage(files[i].getName() + " " + Messages.getMessage("sendingSuccess")); 124 MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading")); 125 ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir); 126 addThumbnails(); 127 this.repaint(); 128 this.revalidate(); 129 MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk")); 146 130 } catch (Exception e) { 147 LOG.error(Outil.getStackTrace(e)); 148 //displays a dialog if there is an error 149 JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), 150 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 151 MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName()); 152 } finally { 153 MainFrame.getInstance().getProgressBar().setValue(nbProgressBar); 154 } 155 } 156 //refresh 157 rafraichir(categoryId, true); 158 MainFrame.getInstance().getProgressBar().setValue(0); 159 } 160 } 161 162 /** 163 * 164 * @author mael 165 * Thread that loads the thumbs and fills the thumb panel 166 */ 167 public class ThreadLoadThumb implements Runnable { 168 ThumbnailCategoryPanel panel; 169 boolean rafraichir; 170 171 public ThreadLoadThumb(ThumbnailCategoryPanel panel, boolean rafraichir) { 172 this.panel = panel; 173 this.rafraichir = rafraichir; 174 } 175 176 @Override 177 public void run() { 178 179 panel.removeAll(); 180 int nb = 1; 181 JPanel panelh = new JPanel(new FlowLayout()); 182 try { 183 MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading")); 184 ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir); 131 LOG.error(Outil.getStackTrace(e)); 132 JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), Messages.getMessage("error"), 133 JOptionPane.ERROR_MESSAGE); 134 MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError")); 135 } 136 } 137 138 139 /** 140 * Adds the thumbnails to the panel 141 */ 142 private void addThumbnails() { 143 this.removeAll(); 144 int nb = 1; 145 JPanel panelh = new JPanel(new FlowLayout()); 185 146 for (Image image : ImagesManagement.LIST_IMAGE) { 186 try { 187 188 if (nb == 7) { 189 panel.add(panelh); 190 panelh = new JPanel(new FlowLayout()); 191 nb = 0; 192 } else { 193 ThumbnailPanel panel = new ThumbnailPanel(image); 194 panelh.add(panel); 147 try { 148 149 if (nb == thumbnailPerLine) { 150 this.add(panelh); 151 panelh = new JPanel(new FlowLayout()); 152 nb = 0; 153 } else { 154 ThumbnailPanel panel = new ThumbnailPanel(image); 155 panelh.add(panel); 156 } 157 nb++; 158 159 } catch (Exception e) { 160 195 161 } 196 nb++; 197 198 } catch (Exception e) { 199 200 } 201 } 202 if (nb != 8) { 203 panel.add(panelh); 204 } 205 panel.repaint(); 206 panel.revalidate(); 207 MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk")); 208 } catch (Exception e) { 209 LOG.error(Outil.getStackTrace(e)); 210 JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), Messages 211 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 212 MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError")); 213 } 214 215 } 216 } 162 } 163 if (nb != thumbnailPerLine + 1) { 164 this.add(panelh); 165 } 166 } 167 168 169 /** 170 * @return the categoryId 171 */ 172 public Integer getCategoryId() { 173 return categoryId; 174 } 175 176 177 /** 178 * @param categoryId the categoryId to set 179 */ 180 public void setCategoryId(Integer categoryId) { 181 this.categoryId = categoryId; 182 } 183 184 185 /** 186 * @return the category 187 */ 188 public Category getCategory() { 189 return category; 190 } 191 192 193 /** 194 * @param category the category to set 195 */ 196 public void setCategory(Category category) { 197 this.category = category; 198 } 199 200 /** 201 * @author mael 202 * Thread that send the photos 203 */ 204 public class ThreadEnvoiPhoto implements Runnable { 205 206 private File[] files; 207 208 209 public ThreadEnvoiPhoto(File[] files) { 210 this.files = files; 211 } 212 213 214 @Override 215 public void run() { 216 217 for (int i = 0; i < files.length; i++) { 218 int nbProgressBar = ((i + 1) * 100) / files.length; 219 try { 220 221 ImageService.getInstance().creer(files[i].getCanonicalPath(), categoryId); 222 MainFrame.getInstance().setMessage(files[i].getName() + " " + Messages.getMessage("sendingSuccess")); 223 } catch (Exception e) { 224 LOG.error(Outil.getStackTrace(e)); 225 //displays a dialog if there is an error 226 JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), 227 Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); 228 MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName()); 229 } finally { 230 MainFrame.getInstance().getProgressBar().setValue(nbProgressBar); 231 } 232 } 233 //refresh 234 rafraichir(categoryId, true); 235 MainFrame.getInstance().getProgressBar().setValue(0); 236 } 237 } 217 238 218 239 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java
r7070 r7221 14 14 import java.io.IOException; 15 15 import java.util.List; 16 17 16 import javax.swing.JButton; 18 17 import javax.swing.JDialog; … … 25 24 import javax.swing.JScrollPane; 26 25 import javax.swing.ListSelectionModel; 27 28 26 import fr.mael.jiwigo.om.Image; 29 27 import fr.mael.jiwigo.om.Tag; … … 34 32 import fr.mael.jiwigo.ui.browser.BrowserFrame; 35 33 import fr.mael.jiwigo.ui.layout.VerticalLayout; 34 36 35 37 36 /** … … 65 64 */ 66 65 public class ThumbnailPanel extends JLabel implements MouseListener, ActionListener { 67 /** 68 * Logger 69 */ 70 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory 71 .getLog(ThumbnailPanel.class); 72 /** 73 * the image 74 */ 75 private Image image; 76 77 /** 78 * Popup menu to edit images info 79 */ 80 private JMenuItem menuAjouterTag; 81 82 /** 83 * Button to add tags 84 */ 85 private JButton boutonOkAjouterTag; 86 87 /** 88 * List of tags 89 */ 90 private JList listTags; 91 92 /** 93 * Dialog that allows to choose tags 94 */ 95 private JDialog dialogChoixTags; 96 97 /** 98 * Constructeur 99 * @param image the image 100 * @param imagesPanel the panel 101 */ 102 public ThumbnailPanel(Image image) { 103 this.image = image; 104 setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " " 105 + Messages.getMessage("hits") + "</center></html>"); 106 this.addMouseListener(this); 107 } 108 109 protected void paintComponent(Graphics g) { 110 super.paintComponent(g); 111 Graphics2D g2 = (Graphics2D) g; 112 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 113 double x = (getWidth() * ImagesManagement.getMiniatureBufferedImage(image).getWidth()) / 2; 114 double y = (getHeight() * ImagesManagement.getMiniatureBufferedImage(image).getHeight()) / 2; 115 g2.drawRenderedImage(ImagesManagement.getMiniatureBufferedImage(image), null); 116 } 117 118 /* (non-Javadoc) 119 * @see javax.swing.JComponent#getPreferredSize() 120 */ 121 public Dimension getPreferredSize() { 122 int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth()); 123 int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10); 124 return new Dimension(w, h); 125 } 126 127 @Override 128 public void mouseClicked(MouseEvent paramMouseEvent) { 129 // on affiche l'image en grand 130 ImagesManagement.setCurrentImage(image); 131 try { 132 if (paramMouseEvent.getButton() == 1) { 133 new BrowserFrame(image); 134 } else if (paramMouseEvent.getButton() == 3) { 135 JPopupMenu popup = new JPopupMenu(); 136 menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag")); 137 menuAjouterTag.addActionListener(this); 138 popup.add(menuAjouterTag); 139 popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY()); 140 } 141 } catch (Exception e) { 142 e.printStackTrace(); 143 } 144 145 } 146 147 @Override 148 public void mouseEntered(MouseEvent paramMouseEvent) { 149 this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 150 } 151 152 @Override 153 public void mouseExited(MouseEvent paramMouseEvent) { 154 } 155 156 @Override 157 public void mousePressed(MouseEvent paramMouseEvent) { 158 // TODO Auto-generated method stub 159 160 } 161 162 @Override 163 public void mouseReleased(MouseEvent paramMouseEvent) { 164 // TODO Auto-generated method stub 165 166 } 167 168 @Override 169 public void actionPerformed(ActionEvent arg0) { 170 if (arg0.getSource().equals(menuAjouterTag)) { 171 try { 172 //getting the list of tags 173 List<Tag> tagsDispo = TagService.getInstance().lister(); 174 //list to array (cause fucking JList does not support Lists) 175 Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]); 176 //getting the image's tags to preselect them 177 List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image); 178 listTags = new JList(tableauTagDispo); 179 //multiple selection is allowed 180 listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 181 listTags.setPreferredSize(new Dimension(100, 200)); 182 //construct an array of the indices to select in the jlist 183 int[] indices = new int[tagsDeLimage.size()]; 184 int compteur = 0; 185 for (int i = 0; i < tableauTagDispo.length; i++) { 186 for (Tag tag : tagsDeLimage) { 187 if (tag.getId().equals(tableauTagDispo[i].getId())) { 188 indices[compteur++] = i; 189 190 } 191 } 66 67 /** 68 * Logger 69 */ 70 public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ThumbnailPanel.class); 71 /** 72 * the image 73 */ 74 private Image image; 75 76 /** 77 * Popup menu to edit images info 78 */ 79 private JMenuItem menuAjouterTag; 80 81 /** 82 * Button to add tags 83 */ 84 private JButton boutonOkAjouterTag; 85 86 /** 87 * List of tags 88 */ 89 private JList listTags; 90 91 /** 92 * Dialog that allows to choose tags 93 */ 94 private JDialog dialogChoixTags; 95 96 97 /** 98 * Constructeur 99 * @param image the image 100 * @param imagesPanel the panel 101 */ 102 public ThumbnailPanel(Image image) { 103 this.image = image; 104 setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " " + Messages.getMessage("hits") 105 + "</center></html>"); 106 this.addMouseListener(this); 107 } 108 109 110 protected void paintComponent(Graphics g) { 111 super.paintComponent(g); 112 Graphics2D g2 = (Graphics2D) g; 113 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 114 double x = (getWidth() * ImagesManagement.getMiniatureBufferedImage(image).getWidth()) / 2; 115 double y = (getHeight() * ImagesManagement.getMiniatureBufferedImage(image).getHeight()) / 2; 116 g2.drawRenderedImage(ImagesManagement.getMiniatureBufferedImage(image), null); 117 } 118 119 120 /* (non-Javadoc) 121 * @see javax.swing.JComponent#getPreferredSize() 122 */ 123 public Dimension getPreferredSize() { 124 int w = (int) (ImagesManagement.getMiniatureBufferedImage(image).getWidth()); 125 int h = (int) (ImagesManagement.getMiniatureBufferedImage(image).getHeight() + 10); 126 return new Dimension(w, h); 127 } 128 129 130 @Override 131 public void mouseClicked(MouseEvent paramMouseEvent) { 132 // on affiche l'image en grand 133 ImagesManagement.setCurrentImage(image); 134 try { 135 if (paramMouseEvent.getButton() == 1) { 136 new BrowserFrame(image); 137 } else if (paramMouseEvent.getButton() == 3) { 138 JPopupMenu popup = new JPopupMenu(); 139 menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag")); 140 menuAjouterTag.addActionListener(this); 141 popup.add(menuAjouterTag); 142 popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY()); 143 } 144 } catch (Exception e) { 145 e.printStackTrace(); 192 146 } 193 listTags.setSelectedIndices(indices); 194 195 JScrollPane scrollPane = new JScrollPane(listTags); 196 dialogChoixTags = new JDialog(); 197 dialogChoixTags.setLayout(new BorderLayout()); 198 JPanel panelNorth = new JPanel(new VerticalLayout()); 199 panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag"))); 200 panelNorth.add(scrollPane); 201 dialogChoixTags.add(panelNorth, BorderLayout.NORTH); 202 JPanel panelBouton = new JPanel(new FlowLayout()); 203 boutonOkAjouterTag = new JButton("Ok"); 204 panelBouton.add(boutonOkAjouterTag); 205 boutonOkAjouterTag.addActionListener(this); 206 dialogChoixTags.add(panelBouton, BorderLayout.CENTER); 207 dialogChoixTags.setSize(new Dimension(400, 280)); 208 dialogChoixTags.setLocationRelativeTo(null); 209 dialogChoixTags.setVisible(true); 210 } catch (IOException e) { 211 e.printStackTrace(); 212 } 213 } else if (arg0.getSource().equals(boutonOkAjouterTag)) { 214 StringBuffer tagIds = new StringBuffer(""); 215 for (Object object : listTags.getSelectedValues()) { 216 Tag tag = (Tag) object; 217 tagIds.append(tag.getId() + ","); 218 } 219 tagIds.deleteCharAt(tagIds.lastIndexOf(",")); 220 try { 221 if (!ImageService.getInstance().addTags(image, tagIds.toString())) { 222 JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages 223 .getMessage("error"), JOptionPane.ERROR_MESSAGE); 224 } else { 225 dialogChoixTags.dispose(); 147 148 } 149 150 151 @Override 152 public void mouseEntered(MouseEvent paramMouseEvent) { 153 this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 154 } 155 156 157 @Override 158 public void mouseExited(MouseEvent paramMouseEvent) { 159 } 160 161 162 @Override 163 public void mousePressed(MouseEvent paramMouseEvent) { 164 // TODO Auto-generated method stub 165 166 } 167 168 169 @Override 170 public void mouseReleased(MouseEvent paramMouseEvent) { 171 // TODO Auto-generated method stub 172 173 } 174 175 176 @Override 177 public void actionPerformed(ActionEvent arg0) { 178 if (arg0.getSource().equals(menuAjouterTag)) { 179 try { 180 //getting the list of tags 181 List<Tag> tagsDispo = TagService.getInstance().lister(); 182 //list to array (cause fucking JList does not support Lists) 183 Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]); 184 //getting the image's tags to preselect them 185 List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image); 186 listTags = new JList(tableauTagDispo); 187 //multiple selection is allowed 188 listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 189 listTags.setPreferredSize(new Dimension(100, 200)); 190 //construct an array of the indices to select in the jlist 191 int[] indices = new int[tagsDeLimage.size()]; 192 int compteur = 0; 193 for (int i = 0; i < tableauTagDispo.length; i++) { 194 for (Tag tag : tagsDeLimage) { 195 if (tag.getId().equals(tableauTagDispo[i].getId())) { 196 indices[compteur++] = i; 197 198 } 199 } 200 } 201 listTags.setSelectedIndices(indices); 202 203 JScrollPane scrollPane = new JScrollPane(listTags); 204 dialogChoixTags = new JDialog(); 205 dialogChoixTags.setLayout(new BorderLayout()); 206 JPanel panelNorth = new JPanel(new VerticalLayout()); 207 panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag"))); 208 panelNorth.add(scrollPane); 209 dialogChoixTags.add(panelNorth, BorderLayout.NORTH); 210 JPanel panelBouton = new JPanel(new FlowLayout()); 211 boutonOkAjouterTag = new JButton("Ok"); 212 panelBouton.add(boutonOkAjouterTag); 213 boutonOkAjouterTag.addActionListener(this); 214 dialogChoixTags.add(panelBouton, BorderLayout.CENTER); 215 dialogChoixTags.setSize(new Dimension(400, 280)); 216 dialogChoixTags.setLocationRelativeTo(null); 217 dialogChoixTags.setVisible(true); 218 } catch (IOException e) { 219 e.printStackTrace(); 220 } 221 } else if (arg0.getSource().equals(boutonOkAjouterTag)) { 222 StringBuffer tagIds = new StringBuffer(""); 223 for (Object object : listTags.getSelectedValues()) { 224 Tag tag = (Tag) object; 225 tagIds.append(tag.getId() + ","); 226 } 227 tagIds.deleteCharAt(tagIds.lastIndexOf(",")); 228 try { 229 if (!ImageService.getInstance().addTags(image, tagIds.toString())) { 230 JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages.getMessage("error"), 231 JOptionPane.ERROR_MESSAGE); 232 } else { 233 dialogChoixTags.dispose(); 234 } 235 } catch (IOException e) { 236 e.printStackTrace(); 237 } 238 226 239 } 227 } catch (IOException e) { 228 e.printStackTrace(); 229 } 230 231 } 232 } 240 } 233 241 }
Note: See TracChangeset
for help on using the changeset viewer.