Changeset 8829


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

Changes ImagesManagement access from static to object.

Location:
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/ImageDao.java

    r7221 r8829  
    66import java.util.HashMap;
    77import java.util.List;
     8
    89import org.jdom.Document;
    910import org.jdom.Element;
     11import org.jdom.output.XMLOutputter;
     12
    1013import sun.misc.BASE64Encoder;
    1114import fr.mael.jiwigo.Main;
     
    1619import fr.mael.jiwigo.transverse.util.Outil;
    1720import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement;
    18 
    1921
    2022/**
     
    5052public class ImageDao {
    5153
    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         }
     54    /**
     55     * Logger
     56     */
     57    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     58            .getLog(ImageDao.class);
     59
     60    /**
     61     * Singleton
     62     */
     63    private static ImageDao instance;
     64
     65    /**
     66     * cache to avoid downloading image for each access
     67     */
     68    private HashMap<Integer, List<Image>> cache;
     69
     70    /**
     71     *
     72     */
     73    private Integer firstCatInCache;
     74
     75    /**
     76     * Private singleton, to use a singleton
     77     */
     78    private ImageDao() {
     79        cache = new HashMap<Integer, List<Image>>();
     80    }
     81
     82    /**
     83     * @return le singleton
     84     */
     85    public static ImageDao getInstance() {
     86        if (instance == null) {
     87            instance = new ImageDao();
     88        }
     89        return instance;
     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     * Listing of the images for a category
     103     * @param categoryId the id of the category
     104     * @return the list of images
     105     * @throws IOException
     106     */
     107    public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException {
     108        if (rafraichir || cache.get(categoryId) == null) {
     109            Document doc = null;
     110
     111            if (categoryId != null) {
     112                doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel(), "cat_id", String
     113                        .valueOf(categoryId));
     114            } else {
     115                doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_IMAGES.getLabel());
     116            }
     117            Element element = doc.getRootElement().getChild("images");
     118            List<Image> images = getImagesFromElement(element);
     119            cache.remove(categoryId);
     120            cache.put(categoryId, images);
     121            if (firstCatInCache == null) {
     122                firstCatInCache = categoryId;
     123            }
     124            return images;
     125        } else {
     126            return cache.get(categoryId);
     127        }
     128    }
     129
     130    /**
     131     * Creation of an image<br/>
     132     * Sequence : <br/>
     133     * <li>
     134     * <ul>sending of the thumbnail in base64, thanks to the method addchunk.</ul>
     135     * <ul>sending of the image in base64, thanks to the method addchunk</ul>
     136     * <ul>using of the add method to add the image to the database<ul>
     137     * </li>
     138     * Finally, the response of the webservice is checked
     139     *
     140     * @param the image to create
     141     * @return true if the creation of the image was the successful
     142     * @throws Exception
     143     */
     144    //TODO ne pas continuer si une des réponses précédentes est négative
     145    public boolean creer(Image image) throws Exception {
     146        //thumbnail converted to base64
     147        BASE64Encoder base64 = new BASE64Encoder();
     148
     149        String thumbnailBase64 = base64.encode(Outil.getBytesFromFile(image.getThumbnail()));
     150        //sends the thumbnail and gets the result
     151        Document reponseThumb = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data",
     152                thumbnailBase64, "type", "thumb", "position", "1", "original_sum", Outil.getMD5Checksum(image
     153                        .getOriginale().getAbsolutePath())));
     154
     155        //begin feature:0001827
     156        Double doubleChunk = Double.parseDouble(PreferencesManagement.getValue(PreferencesEnum.CHUNK_SIZE.getLabel())) * 1000 * 1024;
     157        int chunk = doubleChunk.intValue();
     158        ArrayList<File> fichiersAEnvoyer = Outil.splitFile(image.getOriginale(), chunk);
     159        boolean echec = false;
     160        for (int i = 0; i < fichiersAEnvoyer.size(); i++) {
     161            File fichierAEnvoyer = fichiersAEnvoyer.get(i);
     162            String originaleBase64 = base64.encode(Outil.getBytesFromFile(fichierAEnvoyer));
     163            Document reponseOriginale = (Main.sessionManager.executerReturnDocument("pwg.images.addChunk", "data",
     164                    originaleBase64, "type", "file", "position", String.valueOf(i), "original_sum", Outil
     165                            .getMD5Checksum(image.getOriginale().getAbsolutePath())));
     166            if (!Outil.checkOk(reponseOriginale)) {
     167                echec = true;
     168                break;
     169            }
     170        }
     171        //end
     172
     173        //add the image in the database and get the result of the webservice
     174        Document reponseAjout = (Main.sessionManager.executerReturnDocument("pwg.images.add", "file_sum", Outil
     175                .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image
     176                .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image
     177                .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image
     178                .getName(), "author", Main.sessionManager.getLogin(), "level", image.getPrivacyLevel()));
     179        LOG.debug("Response add : " + Outil.documentToString(reponseAjout));
     180        //      System.out.println(Main.sessionManager.executerReturnString("pwg.images.add", "file_sum", Outil
     181        //              .getMD5Checksum(image.getOriginale().getAbsolutePath()), "thumbnail_sum", Outil.getMD5Checksum(image
     182        //              .getThumbnail().getCanonicalPath()), "position", "1", "original_sum", Outil.getMD5Checksum(image
     183        //              .getOriginale().getAbsolutePath()), "categories", String.valueOf(image.getIdCategory()), "name", image
     184        //              .getName(), "author", Main.sessionManager.getLogin()));
     185        //      Document reponsePrivacy = null;
     186        //      if (Outil.checkOk(reponseAjout)) {
     187        //          reponsePrivacy = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_PRIVACY_LEVEL.getLabel());
     188        //      }
     189        boolean reussite = true;
     190        if (!Outil.checkOk(reponseThumb) || echec || !Outil.checkOk(reponseAjout)) {
     191            reussite = false;
     192        }
     193        suppressionFichierTemporaires();
     194        return reussite;
     195
     196    }
     197
     198    /**
     199     * Add tags to an image
     200     * @param imageId id of the image
     201     * @param tagId ids of the tags
     202     * @throws IOException
     203     */
     204    public boolean addTags(Integer imageId, String tagId) throws IOException {
     205        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String
     206                .valueOf(imageId), "tag_ids", tagId);
     207        return Outil.checkOk(doc);
     208
     209    }
     210
     211    /**
     212     * parse an element to find images
     213     * @param element the element to parse
     214     * @return the list of images
     215     */
     216    private List<Image> getImagesFromElement(Element element) {
     217        List<Element> listElement = (List<Element>) element.getChildren("image");
     218        ArrayList<Image> images = new ArrayList<Image>();
     219        for (Element im : listElement) {
     220            Image myImage = new Image();
     221            myImage.setMiniature(im.getAttributeValue("tn_url"));
     222            myImage.setUrl(im.getAttributeValue("element_url"));
     223            myImage.setWidth(Integer.valueOf(im.getAttributeValue("width")));
     224            myImage.setHeight(Integer.valueOf(im.getAttributeValue("height")));
     225            myImage.setFile(im.getAttributeValue("file"));
     226            myImage.setVue(Integer.valueOf(im.getAttributeValue("hit")));
     227            myImage.setIdentifiant(Integer.valueOf(im.getAttributeValue("id")));
     228            myImage.setName(im.getChildText("name"));
     229            System.out.println(new XMLOutputter().outputString(im));
     230            //      myImage.setIdCategory(Integer.valueOf(im.getChild("categories").getChild("category")
     231            //              .getAttributeValue("id")));
     232            if (myImage.getName() == null) {
     233                myImage.setName(myImage.getFile());
     234            }
     235            images.add(myImage);
     236        }
     237        return images;
     238    }
     239
     240    /**
     241     * Search images
     242     * @param searchString the string to search
     243     * @return the list of images matching the string
     244     * @throws IOException
     245     */
     246    public List<Image> search(String searchString) throws IOException {
     247        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SEARCH.getLabel(), "query", searchString);
     248        LOG.debug(doc);
     249        Element element = doc.getRootElement().getChild("images");
     250        return getImagesFromElement(element);
     251
     252    }
     253
     254    private void suppressionFichierTemporaires() {
     255        File file = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
     256        file.delete();
     257        file = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg");
     258        file.delete();
     259
     260    }
    265261
    266262}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/om/Image.java

    r6821 r8829  
    4545    private String auteur;
    4646    private File thumbnail;
     47    private String privacyLevel;
     48
     49    /**
     50     * @return the privacyLevel
     51     */
     52    public String getPrivacyLevel() {
     53        return privacyLevel;
     54    }
     55
     56    /**
     57     * @param privacyLevel the privacyLevel to set
     58     */
     59    public void setPrivacyLevel(String privacyLevel) {
     60        this.privacyLevel = privacyLevel;
     61    }
    4762
    4863    /**
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r7222 r8829  
    44import java.io.IOException;
    55import java.util.List;
     6
    67import fr.mael.jiwigo.dao.ImageDao;
    78import fr.mael.jiwigo.om.Image;
     
    1213import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement;
    1314import fr.mael.jiwigo.ui.mainframe.MainFrame;
    14 
    1515
    1616/**
     
    4646public class ImageService {
    4747
    48         /**
    49          * Logger
    50          */
    51         public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ImageService.class);
     48    /**
     49     * Logger
     50     */
     51    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     52            .getLog(ImageService.class);
    5253
    53         /**
    54         * Singleton
    55         */
    56         private static ImageService instance;
     54    /**
     55    * Singleton
     56    */
     57    private static ImageService instance;
    5758
     59    /**
     60     * @return the singleton
     61     */
     62    public static ImageService getInstance() {
     63        if (instance == null) {
     64            instance = new ImageService();
     65        }
     66        return instance;
     67    }
    5868
    59         /**
    60          * @return the singleton
    61          */
    62         public static ImageService getInstance() {
    63                 if (instance == null) {
    64                         instance = new ImageService();
    65                 }
    66                 return instance;
    67         }
     69    /**
     70     * private constructor to use a singleton
     71     */
     72    private ImageService() {
    6873
     74    }
    6975
    70         /**
    71          * private constructor to use a singleton
    72          */
    73         private ImageService() {
     76    /**
     77     * Lists all images for a category
     78     * @param categoryId the id of the category
     79     * @param rafraichir true : refresh the list of images
     80     * @return the list of images
     81     * @throws IOException
     82     */
     83    public List<Image> listerParCategory(Integer categoryId, boolean rafraichir) throws IOException {
     84        return ImageDao.getInstance().listerParCategory(categoryId, rafraichir);
     85    }
     86
     87    /**
     88     * Method called to send an image to the server.
     89     * @param filePath
     90     * @param idCategory
     91     * @return
     92     * @throws Exception
     93     */
     94    public boolean creer(String filePath, Integer idCategory) throws Exception {
     95        File originalFile = new File(filePath);
     96        MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_resizing") + " " + originalFile.getName());
     97        //get the byte array of the original file, to keep metadata
     98        byte[] bytesFichierOriginal = Outil.getBytesFromFile(originalFile);
     99
     100        //size taken from the user's preferences
     101        int widthOriginale = Integer
     102                .valueOf(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel()));
     103        int heightOriginale = Integer.valueOf(PreferencesManagement
     104                .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(
     118                    Messages.getMessage("mainFrame_addMetadata") + " " + originalFile.getName());
     119            try {
     120                byte[] fichierEnrichi = Outil.enrich(bytesFichierOriginal, Outil.getBytesFromFile(new File(System
     121                        .getProperty("java.io.tmpdir")
     122                        + "/originale.jpg")));
     123                Outil.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi);
     124            } catch (Exception e) {
     125            }
     126        } else {
     127            originale = originalFile;
    74128
    75129        }
     130        Image image = new Image();
     131        image.setName(getImageName(filePath));
     132        image.setThumbnail(thumbnail);
     133        image.setOriginale(originale);
     134        image.setIdCategory(idCategory);
     135        MainFrame.getInstance()
     136                .setMessage(Messages.getMessage("mainFrame_sendingFiles") + " " + originalFile.getName());
     137        //now we call the dao to send the image to the webservice
     138        return ImageDao.getInstance().creer(image);
     139    }
    76140
     141    /**
     142     * Add tags to an existing image
     143     * @param image the image
     144     * @param tagId the ids of the tags
     145     * @return true if successful
     146     * @throws IOException
     147     */
     148    public boolean addTags(Image image, String tagId) throws IOException {
     149        return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId);
     150    }
    77151
    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         }
     152    /**
     153     * Search images from a string
     154     * @param queryString the string
     155     * @return images matching the string
     156     * @throws IOException
     157     */
     158    public List<Image> search(String queryString) throws IOException {
     159        return ImageDao.getInstance().search(queryString);
     160    }
    88161
     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();
    89171
    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                 File originalFile = new File(filePath);
    99                 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_resizing") + " " + originalFile.getName());
    100                 //get the byte array of the original file, to keep metadata
    101                 byte[] bytesFichierOriginal = Outil.getBytesFromFile(originalFile);
    102 
    103                 //size taken from the user's preferences
    104                 int widthOriginale = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel()));
    105                 int heightOriginale = Integer.valueOf(PreferencesManagement.getValue(PreferencesEnum.HEIGHT_ORIGINAL.getLabel()));
    106                 //resize the picture (or not)
    107                 boolean originaleRedimensionnee = ImagesUtil.scale(filePath, "originale.jpg", widthOriginale, heightOriginale);
    108                 //create the thumbnail
    109                 ImagesUtil.scale(filePath, "thumb.jpg", 120, 90);
    110                 //get the thumbnail
    111                 File thumbnail = new File(System.getProperty("java.io.tmpdir") + "/thumb.jpg");
    112                 File originale = null;
    113                 if (originaleRedimensionnee) {
    114                         originale = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
    115                         //if the original file has been resized, we put the metadata in the resized file
    116                         //I use here a try catch because if the original file isn't a jpeg
    117                         //the methode Outil.enrich will fail, but the procedure has to continue
    118                         MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_addMetadata") + " " + originalFile.getName());
    119                         try {
    120                                 byte[] fichierEnrichi = Outil.enrich(bytesFichierOriginal,
    121                                                 Outil.getBytesFromFile(new File(System.getProperty("java.io.tmpdir") + "/originale.jpg")));
    122                                 Outil.byteToFile(System.getProperty("java.io.tmpdir") + "/originale.jpg", fichierEnrichi);
    123                         } catch (Exception e) {
    124                         }
    125                 } else {
    126                         originale = originalFile;
    127 
    128                 }
    129                 Image image = new Image();
    130                 image.setName(getImageName(filePath));
    131                 image.setThumbnail(thumbnail);
    132                 image.setOriginale(originale);
    133                 image.setIdCategory(idCategory);
    134                 MainFrame.getInstance().setMessage(Messages.getMessage("mainFrame_sendingFiles") + " " + originalFile.getName());
    135                 //now we call the dao to send the image to the webservice
    136                 return ImageDao.getInstance().creer(image);
    137         }
    138 
    139 
    140         /**
    141          * Add tags to an existing image
    142          * @param image the image
    143          * @param tagId the ids of the tags
    144          * @return true if successful
    145          * @throws IOException
    146          */
    147         public boolean addTags(Image image, String tagId) throws IOException {
    148                 return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId);
    149         }
    150 
    151 
    152         /**
    153          * Search images from a string
    154          * @param queryString the string
    155          * @return images matching the string
    156          * @throws IOException
    157          */
    158         public List<Image> search(String queryString) throws IOException {
    159                 return ImageDao.getInstance().search(queryString);
    160         }
    161 
    162 
    163         /**
    164          * Deletes the file extension
    165          * @param path
    166          * @return
    167          */
    168         private String getImageName(String path) {
    169                 File fichier = new File(path);
    170                 StringBuffer name = new StringBuffer(fichier.getName());
    171                 return (name.delete(name.lastIndexOf("."), name.length())).toString();
    172 
    173         }
     172    }
    174173
    175174}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/ImagesManagement.java

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

    r7221 r8829  
    88import java.awt.event.MouseListener;
    99import java.util.List;
     10
    1011import javax.swing.JMenuItem;
    1112import javax.swing.JOptionPane;
     
    2021import javax.swing.tree.TreePath;
    2122import javax.swing.tree.TreeSelectionModel;
     23
    2224import fr.mael.jiwigo.om.Category;
    2325import fr.mael.jiwigo.service.CategoryService;
    2426import fr.mael.jiwigo.transverse.util.Messages;
    2527import fr.mael.jiwigo.transverse.util.Outil;
    26 
    2728
    2829/**
     
    5758public class CategoriesTree extends JPanel implements TreeSelectionListener, MouseListener, ActionListener {
    5859
    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);
     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        if (!MainFrame.getInstance().isBrowserVisible()) {
     128            MainFrame.getInstance().setBrowserVisible();
     129        }
     130        MainFrame.getInstance().addTabb(new ThumbnailCategoryPanel(category));
     131    }
     132
     133    /**
     134     * creation of the nodes
     135     * @param root the root
     136     */
     137    private void createNodes(DefaultMutableTreeNode root) {
     138        DefaultMutableTreeNode category = null;
     139        try {
     140            List<Category> list = CategoryService.getInstance().construireArbre();
     141            for (Category cat : list) {
     142                if (cat.getCategoriesMeres().size() == 0) {
     143                    category = new DefaultMutableTreeNode(cat);
     144                    root.add(category);
     145                    recursiveNodeCreation(category, cat);
    152146                }
    153147
    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);
     148            }
     149        } catch (Exception e) {
     150            LOG.error(Outil.getStackTrace(e));
     151            JOptionPane.showMessageDialog(null, Messages.getMessage("treeCreationError"), Messages.getMessage("error"),
     152                    JOptionPane.ERROR_MESSAGE);
     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    @Override
     171    public void mouseClicked(MouseEvent arg0) {
     172
     173    }
     174
     175    @Override
     176    public void mouseEntered(MouseEvent arg0) {
     177        // TODO Auto-generated method stub
     178
     179    }
     180
     181    @Override
     182    public void mouseExited(MouseEvent arg0) {
     183        // TODO Auto-generated method stub
     184
     185    }
     186
     187    @Override
     188    public void mousePressed(MouseEvent e) {
     189        int selRow = tree.getRowForLocation(e.getX(), e.getY());
     190        TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
     191        //begin bug:0001832
     192        tree.setSelectionRow(selRow);
     193        //end
     194
     195        if (e.getButton() == 3) {
     196            JPopupMenu popup = new JPopupMenu();
     197            menuAjouter = new JMenuItem(Messages.getMessage("categories_add"));
     198            menuAjouter.addActionListener(this);
     199            popup.add(menuAjouter);
     200            menuActualiser = new JMenuItem(Messages.getMessage("categories_update"));
     201            menuActualiser.addActionListener(this);
     202            popup.add(menuActualiser);
     203            popup.show(tree, e.getX(), e.getY());
     204            if (selRow != -1) {
     205                DefaultMutableTreeNode node = (DefaultMutableTreeNode) (selPath.getLastPathComponent());
     206                this.selectedCategory = (Category) node.getUserObject();
     207            } else {
     208                this.selectedCategory = null;
     209            }
     210        }
     211
     212    }
     213
     214    @Override
     215    public void mouseReleased(MouseEvent arg0) {
     216        // TODO Auto-generated method stub
     217
     218    }
     219
     220    @Override
     221    public void actionPerformed(ActionEvent arg0) {
     222        if (arg0.getSource().equals(menuAjouter)) {
     223            String nomcategorie = JOptionPane.showInputDialog(null, Messages.getMessage("categories_enterName"),
     224                    Messages.getMessage("categories_add"), JOptionPane.INFORMATION_MESSAGE);
     225            //if the name of the category is not empty
     226            if (!(nomcategorie == null) && !nomcategorie.equals("")) {
     227                //if there is a parent category
     228                if (selectedCategory != null) {
     229                    //try to create a category
     230                    if (CategoryService.getInstance().creer(nomcategorie, selectedCategory.getIdentifiant())) {
     231                        setUpUi();
     232                    } else {
     233                        JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages
     234                                .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     235
     236                    }
     237                } else {
     238                    if (CategoryService.getInstance().creer(nomcategorie)) {
     239                        setUpUi();
     240                    } else {
     241                        JOptionPane.showMessageDialog(null, Messages.getMessage("categoryCreationError"), Messages
     242                                .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     243
     244                    }
    167245                }
    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)) {
    254                         setUpUi();
    255                 }
    256         }
     246            }
     247        } else if (arg0.getSource().equals(menuActualiser)) {
     248            setUpUi();
     249        }
     250    }
    257251}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/DialogPrivacyLevel.java

    r7070 r8829  
    101101    public void actionPerformed(ActionEvent arg0) {
    102102        if (arg0.getSource().equals(buttonOk)) {
    103             ImagesManagement.privacyLevel = comboPrivacyLevel.getSelectedIndex() + 1;
     103            ImagesManagement.getInstance().setPrivacyLevel(comboPrivacyLevel.getSelectedIndex() + 1);
    104104            if (checkBoxRemember.isSelected()) {
    105                 ImagesManagement.rememberPrivacyLevel = true;
     105                ImagesManagement.getInstance().setRememberPrivacyLevel(true);
    106106            }
    107107            this.dispose();
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/IThumbnailPanel.java

    r6972 r8829  
    33import fr.mael.jiwigo.om.Category;
    44
     5/**
     6    Copyright (c) 2010, Mael
     7   All rights reserved.
     8
     9   Redistribution and use in source and binary forms, with or without
     10   modification, are permitted provided that the following conditions are met:
     11    * Redistributions of source code must retain the above copyright
     12      notice, this list of conditions and the following disclaimer.
     13    * Redistributions in binary form must reproduce the above copyright
     14      notice, this list of conditions and the following disclaimer in the
     15      documentation and/or other materials provided with the distribution.
     16    * Neither the name of jiwigo nor the
     17      names of its contributors may be used to endorse or promote products
     18      derived from this software without specific prior written permission.
     19
     20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     21   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
     24   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     27   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     29   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 * @author mael
     31 * Interface for thumbnail panels
     32 */
    533public interface IThumbnailPanel {
    634    /**
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java

    r7222 r8829  
    99import java.awt.event.KeyListener;
    1010import java.util.HashMap;
     11
    1112import javax.swing.ImageIcon;
    1213import javax.swing.JComponent;
     
    2021import javax.swing.JScrollPane;
    2122import javax.swing.JSplitPane;
     23
    2224import fr.mael.jiwigo.transverse.util.Messages;
    2325import fr.mael.jiwigo.transverse.util.Outil;
     26import fr.mael.jiwigo.ui.MyCollapsiblePanel;
     27import fr.mael.jiwigo.ui.browser.BrowserPanel;
    2428import fr.mael.jiwigo.ui.field.HintTextField;
    2529import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
    26 
     30import fr.mael.jiwigo.ui.search.ImageSearchPanel;
    2731
    2832/**
     
    5761public class MainFrame extends JFrame implements ActionListener, KeyListener {
    5862
    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          * label that displays additional messages
    87          */
    88         private JLabel labelAdditionalMessage;
    89 
    90         /**
    91          * menu bar
    92          */
    93         private JMenuBar jMenuBar;
    94 
    95         /**
    96          * edition menu
    97          */
    98         private JMenu jMenuEdition;
    99 
    100         /**
    101          * preferences menu
    102          */
    103         private JMenuItem jMenuItemPreferences;
    104 
    105         /**
    106          * singleton
    107          */
    108         private static MainFrame instance;
    109 
    110         private JProgressBar progressBar;
    111 
    112         private JTabbedPaneWithCloseIcons tabbedPane;
    113 
    114         private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
    115 
    116         private HintTextField fieldSearch;
    117 
    118 
    119         /**
    120          * @return the singleton
    121          */
    122         public static MainFrame getInstance() {
    123                 if (instance == null) {
    124                         instance = new MainFrame();
     63    /**
     64     * Logger
     65     */
     66    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     67            .getLog(MainFrame.class);
     68    /**
     69     * the categories tree
     70     */
     71    private CategoriesTree categoriesTree;
     72    /**
     73     * Splitpane. On the left : the categories tree and on the right the thumbnails
     74     * for the current category
     75     */
     76    private JSplitPane splitPane;
     77    /**
     78     * Panel that contains the thumbnail of the current category
     79     */
     80    public static ThumbnailCategoryPanel imagesPanel;
     81    /**
     82     *  Scrollpane that contains the panel above
     83     */
     84    private JScrollPane scrollPaneImagesPanel;
     85    /**
     86     * label that displays messages
     87     */
     88    private JLabel labelMessage;
     89
     90    /**
     91     * label that displays additional messages
     92     */
     93    private JLabel labelAdditionalMessage;
     94
     95    /**
     96     * menu bar
     97     */
     98    private JMenuBar jMenuBar;
     99
     100    /**
     101     * edition menu
     102     */
     103    private JMenu jMenuEdition;
     104
     105    /**
     106     * preferences menu
     107     */
     108    private JMenuItem jMenuItemPreferences;
     109    /**
     110     * menu to search images
     111     */
     112    private JMenuItem jMenuItemSearch;
     113
     114    /**
     115     * singleton
     116     */
     117    private static MainFrame instance;
     118
     119    private JProgressBar progressBar;
     120
     121    private JTabbedPaneWithCloseIcons tabbedPane;
     122
     123    private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
     124
     125    private HintTextField fieldSearch;
     126
     127    private BrowserPanel browserPanel;
     128
     129    private MyCollapsiblePanel collapsiblePanel;
     130
     131    private ImageSearchPanel imageSearchPanel;
     132
     133    private boolean imageSearchPanelVisible = false;
     134
     135    private boolean browserVisible = false;
     136
     137    /**
     138     * @return the singleton
     139     */
     140    public static MainFrame getInstance() {
     141        if (instance == null) {
     142            instance = new MainFrame();
     143        }
     144        return instance;
     145    }
     146
     147    /**
     148     * private constructor to use a singleton
     149     */
     150    private MainFrame() {
     151        this.setTitle("Jiwigo v" + Messages.getMessage("version"));
     152        this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
     153        this.setLayout(new BorderLayout());
     154        jMenuBar = new JMenuBar();
     155        labelMessage = new JLabel(Messages.getMessage("welcomeMessage"));
     156        labelAdditionalMessage = new JLabel();
     157        splitPane = new JSplitPane();
     158        categoriesTree = new CategoriesTree();
     159        splitPane.setLeftComponent(categoriesTree);
     160
     161        imageSearchPanel = new ImageSearchPanel();
     162
     163        tabbedPane = new JTabbedPaneWithCloseIcons();
     164        collapsiblePanel = new MyCollapsiblePanel(tabbedPane);
     165        splitPane.setRightComponent(collapsiblePanel);
     166
     167        this.add(splitPane, BorderLayout.CENTER);
     168        JPanel panelBas = new JPanel(new BorderLayout());
     169        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     170        progressBar = new JProgressBar(0, 100);
     171        panel.add(progressBar);
     172        panel.add(labelAdditionalMessage);
     173        panel.add(labelMessage);
     174        panelBas.add(panel, BorderLayout.WEST);
     175
     176        fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche"));
     177        fieldSearch.setPreferredSize(new Dimension(150, 25));
     178        fieldSearch.addKeyListener(this);
     179        panelBas.add(fieldSearch, BorderLayout.EAST);
     180
     181        jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
     182        jMenuBar.add(jMenuEdition);
     183        jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu"));
     184        jMenuItemPreferences.addActionListener(this);
     185        jMenuEdition.add(jMenuItemPreferences);
     186        jMenuItemSearch = new JMenuItem("Search");
     187        jMenuItemSearch.addActionListener(this);
     188        jMenuEdition.add(jMenuItemSearch);
     189
     190        this.setJMenuBar(jMenuBar);
     191        this.add(panelBas, BorderLayout.SOUTH);
     192        this.setSize(900, 600);
     193        this.setLocationRelativeTo(null);
     194        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     195        this.setResizable(true);
     196    }
     197
     198    public void setBrowserVisible() {
     199        splitPane.setRightComponent(collapsiblePanel);
     200        splitPane.revalidate();
     201        splitPane.repaint();
     202        imageSearchPanelVisible = false;
     203        browserVisible = true;
     204    }
     205
     206    public void setImageSearchPanelVisible() {
     207        splitPane.setRightComponent(imageSearchPanel);
     208        splitPane.revalidate();
     209        splitPane.repaint();
     210        imageSearchPanelVisible = true;
     211        browserVisible = false;
     212    }
     213
     214    public void addTabb(IThumbnailPanel panel) {
     215        JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
     216                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     217        scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
     218        boolean found = false;
     219        boolean isSearch = false;
     220        if (panel instanceof ThumbnailSearchPanel) {
     221            isSearch = true;
     222        }
     223
     224        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
     225            JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
     226            IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0];
     227            if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
     228                //only if it's not for a re
     229                if (!(panel instanceof ThumbnailSearchPanel)) {
     230                    tabbedPane.setSelectedIndex(i);
     231                    found = true;
     232                    break;
    125233                }
    126                 return instance;
    127         }
    128 
    129 
    130         /**
    131          * private constructor to use a singleton
    132          */
    133         private MainFrame() {
    134                 this.setTitle("Jiwigo v" + Messages.getMessage("version"));
    135                 this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
    136                 this.setLayout(new BorderLayout());
    137                 jMenuBar = new JMenuBar();
    138                 labelMessage = new JLabel(Messages.getMessage("welcomeMessage"));
    139                 labelAdditionalMessage = new JLabel();
    140                 splitPane = new JSplitPane();
    141                 categoriesTree = new CategoriesTree();
    142                 splitPane.setLeftComponent(categoriesTree);
    143 
    144                 tabbedPane = new JTabbedPaneWithCloseIcons();
    145                 splitPane.setRightComponent(tabbedPane);
    146 
    147                 this.add(splitPane, BorderLayout.CENTER);
    148                 JPanel panelBas = new JPanel(new BorderLayout());
    149                 JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    150                 progressBar = new JProgressBar(0, 100);
    151                 panel.add(progressBar);
    152                 panel.add(labelAdditionalMessage);
    153                 panel.add(labelMessage);
    154                 panelBas.add(panel, BorderLayout.WEST);
    155 
    156                 fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche"));
    157                 fieldSearch.setPreferredSize(new Dimension(150, 25));
    158                 fieldSearch.addKeyListener(this);
    159                 panelBas.add(fieldSearch, BorderLayout.EAST);
    160 
    161                 jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
    162                 jMenuBar.add(jMenuEdition);
    163                 jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu"));
    164                 jMenuItemPreferences.addActionListener(this);
    165                 jMenuEdition.add(jMenuItemPreferences);
    166 
    167                 this.setJMenuBar(jMenuBar);
    168                 this.add(panelBas, BorderLayout.SOUTH);
    169                 this.setSize(900, 600);
    170                 this.setLocationRelativeTo(null);
    171                 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    172                 this.setResizable(true);
    173         }
    174 
    175 
    176         public void addTabb(IThumbnailPanel panel) {
    177                 JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    178                 scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
    179                 boolean found = false;
    180                 boolean isSearch = false;
    181                 if (panel instanceof ThumbnailSearchPanel) {
    182                         isSearch = true;
    183                 }
    184 
    185                 for (int i = 0; i < tabbedPane.getTabCount(); i++) {
    186                         JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
    187                         IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0];
    188                         if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
    189                                 //only if it's not for a re
    190                                 if (!(panel instanceof ThumbnailSearchPanel)) {
    191                                         tabbedPane.setSelectedIndex(i);
    192                                         found = true;
    193                                         break;
    194                                 }
    195                         }
    196                 }
    197                 //if it's not for a research, the title of the tab
    198                 //is the name of the category
    199                 if (!found && !isSearch) {
    200                         tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel,
    201                                         new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
    202                         //if it's for a research, the title of the tab
    203                         //if the query string
    204                 } else if (!found && isSearch) {
    205                         String queryString = ((ThumbnailSearchPanel) panel).getQueryString();
    206                         tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel,
    207                                         new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
    208                 }
    209 
    210         }
    211 
    212 
    213         /**
    214          * displays the frame
    215          */
    216         public void showUi() {
    217                 this.setVisible(true);
    218         }
    219 
    220 
    221         /**
    222          * Affichage d'un message de réussite
    223          * @param message
    224          */
    225         public void setMessage(String message) {
    226                 this.labelMessage.setText(message);
    227         }
    228 
    229 
    230         public void setAdditionalMessage(String additionalMessage) {
    231                 this.labelAdditionalMessage.setText(additionalMessage);
    232         }
    233 
    234 
    235         @Override
    236         public void actionPerformed(ActionEvent arg0) {
    237                 if (arg0.getSource().equals(jMenuItemPreferences)) {
    238                         new PreferencesDialog(this);
    239                 }
    240 
    241         }
    242 
    243 
    244         public static void reduceSizeOfComponent(JComponent comp) {
    245                 comp.setMaximumSize(comp.getPreferredSize());
    246         }
    247 
    248 
    249         /**
    250          * @return the progressBar
    251          */
    252         public JProgressBar getProgressBar() {
    253                 return progressBar;
    254         }
    255 
    256 
    257         /**
    258          * @return the mapsIdPos
    259          */
    260         public HashMap<Integer, Integer> getMapsIdPos() {
    261                 return mapsIdPos;
    262         }
    263 
    264 
    265         @Override
    266         public void keyPressed(KeyEvent paramKeyEvent) {
    267                 if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
    268                         String queryString = fieldSearch.getText();
    269                         ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString);
    270                         addTabb(searchPanel);
    271                 }
    272         }
    273 
    274 
    275         @Override
    276         public void keyReleased(KeyEvent paramKeyEvent) {
    277         }
    278 
    279 
    280         @Override
    281         public void keyTyped(KeyEvent paramKeyEvent) {
    282         }
     234            }
     235        }
     236        //if it's not for a research, the title of the tab
     237        //is the name of the category
     238        if (!found && !isSearch) {
     239            tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil
     240                    .getURL("fr/mael/jiwigo/img/closetab.png")));
     241            //if it's for a research, the title of the tab
     242            //if the query string
     243        } else if (!found && isSearch) {
     244            String queryString = ((ThumbnailSearchPanel) panel).getQueryString();
     245            tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel,
     246                    new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
     247        }
     248
     249    }
     250
     251    public void revalidate() {
     252
     253    }
     254
     255    /**
     256     * displays the frame
     257     */
     258    public void showUi() {
     259        this.setVisible(true);
     260    }
     261
     262    /**
     263     * Affichage d'un message de réussite
     264     * @param message
     265     */
     266    public void setMessage(String message) {
     267        this.labelMessage.setText(message);
     268    }
     269
     270    public void setAdditionalMessage(String additionalMessage) {
     271        this.labelAdditionalMessage.setText(additionalMessage);
     272    }
     273
     274    @Override
     275    public void actionPerformed(ActionEvent arg0) {
     276        if (arg0.getSource().equals(jMenuItemPreferences)) {
     277            new PreferencesDialog(this);
     278        } else if (arg0.getSource().equals(jMenuItemSearch)) {
     279            setImageSearchPanelVisible();
     280        }
     281
     282    }
     283
     284    public static void reduceSizeOfComponent(JComponent comp) {
     285        comp.setMaximumSize(comp.getPreferredSize());
     286    }
     287
     288    /**
     289     * @return the progressBar
     290     */
     291    public JProgressBar getProgressBar() {
     292        return progressBar;
     293    }
     294
     295    /**
     296     * @return the mapsIdPos
     297     */
     298    public HashMap<Integer, Integer> getMapsIdPos() {
     299        return mapsIdPos;
     300    }
     301
     302    @Override
     303    public void keyPressed(KeyEvent paramKeyEvent) {
     304        if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
     305            String queryString = fieldSearch.getText();
     306            ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString);
     307            addTabb(searchPanel);
     308        }
     309    }
     310
     311    @Override
     312    public void keyReleased(KeyEvent paramKeyEvent) {
     313    }
     314
     315    @Override
     316    public void keyTyped(KeyEvent paramKeyEvent) {
     317    }
     318
     319    /**
     320     * @return the collapsiblePanel
     321     */
     322    public MyCollapsiblePanel getCollapsiblePanel() {
     323        return collapsiblePanel;
     324    }
     325
     326    /**
     327     * @return the imageSearchPanelVisible
     328     */
     329    public boolean isImageSearchPanelVisible() {
     330        return imageSearchPanelVisible;
     331    }
     332
     333    /**
     334     * @return the browserVisible
     335     */
     336    public boolean isBrowserVisible() {
     337        return browserVisible;
     338    }
    283339
    284340}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailCategoryPanel.java

    r7223 r8829  
    66import java.io.File;
    77import java.io.IOException;
     8
    89import javax.swing.JOptionPane;
    910import javax.swing.JPanel;
     11
    1012import fr.mael.jiwigo.om.Category;
    1113import fr.mael.jiwigo.om.Image;
     
    1618import fr.mael.jiwigo.transverse.util.filedrop.FileDrop;
    1719import fr.mael.jiwigo.ui.layout.VerticalLayout;
    18 
    1920
    2021/**
     
    4950public class ThumbnailCategoryPanel extends JPanel implements IThumbnailPanel {
    5051
    51         /**
    52          * Logger
    53          */
    54         public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(ThumbnailCategoryPanel.class);
    55         /**
    56          * id of the category
    57          */
    58         private Integer categoryId;
    59 
    60         private Category category;
    61 
    62         /**
    63          * thumbnails per line
    64          */
    65         private int thumbnailPerLine = 7;
    66 
    67         /**
    68          * Saved dimension of the panel, used to define the number
    69          * of thumbnails on a line
    70          */
    71         private Dimension savedDimension = new Dimension();
    72 
    73 
    74         public ThumbnailCategoryPanel(Category category) {
    75                 this(category.getIdentifiant());
    76                 this.category = category;
    77         }
    78 
    79 
    80         /**
    81          * Constructor
    82          * @param categoryId id of the category
    83          */
    84         public ThumbnailCategoryPanel(Integer categoryId) {
    85                 this.categoryId = categoryId;
    86                 this.setLayout(new VerticalLayout());
    87                 if (categoryId != null) {
    88                         rafraichir(categoryId, false);
    89                 }
    90                 //gestion du drag'n drop
    91                 new FileDrop(System.out, this, new FileDrop.Listener() {
    92 
    93                         public void filesDropped(final java.io.File[] files) {
    94                                 if (!ImagesManagement.rememberPrivacyLevel) {
    95                                         new DialogPrivacyLevel();
    96                                 }
    97                                 if (ImagesManagement.sendingFiles) {
    98                                         JOptionPane.showMessageDialog(null, Messages.getMessage("alreadySendingError"), Messages.getMessage("error"),
    99                                                         JOptionPane.ERROR_MESSAGE);
    100                                 } else {
    101                                         new Thread(new ThreadEnvoiPhoto(files)).start();
    102                                 }
    103                         }
    104                 });
    105 
    106         }
    107 
     52    /**
     53     * Logger
     54     */
     55    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     56            .getLog(ThumbnailCategoryPanel.class);
     57    /**
     58     * id of the category
     59     */
     60    private Integer categoryId;
     61
     62    private Category category;
     63
     64    /**
     65     * thumbnails per line
     66     */
     67    private int thumbnailPerLine = 7;
     68
     69    /**
     70     * Saved dimension of the panel, used to define the number
     71     * of thumbnails on a line
     72     */
     73    private Dimension savedDimension = new Dimension();
     74
     75    private ImagesManagement imagesManagement;
     76
     77    private ThumbnailCategoryPanel() {
     78        // TODO Auto-generated constructor stub
     79        imagesManagement = ImagesManagement.getInstance();
     80    }
     81
     82    public ThumbnailCategoryPanel(Category category) {
     83        this(category.getIdentifiant());
     84        this.category = category;
     85    }
     86
     87    /**
     88     * Constructor
     89     * @param categoryId id of the category
     90     */
     91    public ThumbnailCategoryPanel(Integer categoryId) {
     92        this();
     93        this.categoryId = categoryId;
     94        this.setLayout(new VerticalLayout());
     95        if (categoryId != null) {
     96            rafraichir(categoryId, false);
     97        }
     98        //gestion du drag'n drop
     99        new FileDrop(System.out, this, new FileDrop.Listener() {
     100
     101            public void filesDropped(final java.io.File[] files) {
     102                if (!imagesManagement.isRememberPrivacyLevel()) {
     103                    new DialogPrivacyLevel();
     104                }
     105                if (imagesManagement.isSendingFiles()) {
     106                    JOptionPane.showMessageDialog(null, Messages.getMessage("alreadySendingError"), Messages
     107                            .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     108                } else {
     109                    new Thread(new ThreadEnvoiPhoto(files)).start();
     110                }
     111            }
     112        });
     113
     114    }
     115
     116    @Override
     117    public void paint(Graphics g) {
     118        super.paint(g);
     119        if (!MainFrame.getInstance().getSize().equals(savedDimension)) {
     120            //                  LOG.debug("paint " + getSize());
     121            savedDimension = MainFrame.getInstance().getSize();
     122            int width = savedDimension.width;
     123            thumbnailPerLine = width / 150;
     124            addThumbnails();
     125        }
     126    }
     127
     128    /**
     129     * refreshes the panel
     130     * @param categoryId the id of the category
     131     */
     132    public void rafraichir(Integer categoryId, boolean rafraichir) {
     133        this.categoryId = categoryId;
     134        try {
     135            MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading"));
     136            imagesManagement.setListImage(ImageService.getInstance().listerParCategory(categoryId, rafraichir));
     137            addThumbnails();
     138            this.repaint();
     139            this.revalidate();
     140            MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk"));
     141        } catch (Exception e) {
     142            LOG.error(Outil.getStackTrace(e));
     143            JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"),
     144                    Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
     145            MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError"));
     146        }
     147    }
     148
     149    /**
     150     * Adds the thumbnails to the panel
     151     */
     152    private void addThumbnails() {
     153        this.removeAll();
     154        int nb = 1;
     155        JPanel panelh = new JPanel(new FlowLayout());
     156        try {
     157            imagesManagement.setListImage(ImageService.getInstance().listerParCategory(categoryId, false));
     158        } catch (IOException e1) {
     159            e1.printStackTrace();
     160        }
     161        for (Image image : imagesManagement.getListImage()) {
     162            try {
     163
     164                if (nb == thumbnailPerLine) {
     165                    this.add(panelh);
     166                    panelh = new JPanel(new FlowLayout());
     167                    nb = 0;
     168                } else {
     169                    ThumbnailPanel panel = new ThumbnailPanel(image);
     170                    panelh.add(panel);
     171                }
     172                nb++;
     173
     174            } catch (Exception e) {
     175
     176            }
     177        }
     178        if (nb != thumbnailPerLine + 1) {
     179            this.add(panelh);
     180        }
     181    }
     182
     183    /**
     184     * @return the categoryId
     185     */
     186    public Integer getCategoryId() {
     187        return categoryId;
     188    }
     189
     190    /**
     191     * @param categoryId the categoryId to set
     192     */
     193    public void setCategoryId(Integer categoryId) {
     194        this.categoryId = categoryId;
     195    }
     196
     197    /**
     198     * @return the category
     199     */
     200    public Category getCategory() {
     201        return category;
     202    }
     203
     204    /**
     205     * @param category the category to set
     206     */
     207    public void setCategory(Category category) {
     208        this.category = category;
     209    }
     210
     211    /**
     212     * @author mael
     213     * Thread that send the photos
     214     */
     215    public class ThreadEnvoiPhoto implements Runnable {
     216
     217        private File[] files;
     218
     219        public ThreadEnvoiPhoto(File[] files) {
     220            this.files = files;
     221        }
    108222
    109223        @Override
    110         public void paint(Graphics g) {
    111                 super.paint(g);
    112                 if (!MainFrame.getInstance().getSize().equals(savedDimension)) {
    113                         //                      LOG.debug("paint " + getSize());
    114                         savedDimension = MainFrame.getInstance().getSize();
    115                         int width = savedDimension.width;
    116                         thumbnailPerLine = width / 150;
    117                         addThumbnails();
    118                 }
    119         }
    120 
    121 
    122         /**
    123          * refreshes the panel
    124          * @param categoryId the id of the category
    125          */
    126         public void rafraichir(Integer categoryId, boolean rafraichir) {
    127                 this.categoryId = categoryId;
     224        public void run() {
     225            imagesManagement.setSendingFiles(true);
     226            for (int i = 0; i < files.length; i++) {
     227                MainFrame.getInstance().setAdditionalMessage(
     228                        "<html><i>" + (i + 1) + "/" + files.length + " : </i></html>");
     229                int nbProgressBar = ((i + 1) * 100) / files.length;
    128230                try {
    129                         MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading"));
    130                         ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir);
    131                         addThumbnails();
    132                         this.repaint();
    133                         this.revalidate();
    134                         MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk"));
     231
     232                    ImageService.getInstance().creer(files[i].getCanonicalPath(), categoryId);
     233                    MainFrame.getInstance()
     234                            .setMessage(files[i].getName() + " " + Messages.getMessage("sendingSuccess"));
    135235                } catch (Exception e) {
    136                         LOG.error(Outil.getStackTrace(e));
    137                         JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), Messages.getMessage("error"),
    138                                         JOptionPane.ERROR_MESSAGE);
    139                         MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError"));
    140                 }
    141         }
    142 
    143 
    144         /**
    145          * Adds the thumbnails to the panel
    146          */
    147         private void addThumbnails() {
    148                 this.removeAll();
    149                 int nb = 1;
    150                 JPanel panelh = new JPanel(new FlowLayout());
    151                 try {
    152                         ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, false);
    153                 } catch (IOException e1) {
    154                         e1.printStackTrace();
    155                 }
    156                 for (Image image : ImagesManagement.LIST_IMAGE) {
    157                         try {
    158 
    159                                 if (nb == thumbnailPerLine) {
    160                                         this.add(panelh);
    161                                         panelh = new JPanel(new FlowLayout());
    162                                         nb = 0;
    163                                 } else {
    164                                         ThumbnailPanel panel = new ThumbnailPanel(image);
    165                                         panelh.add(panel);
    166                                 }
    167                                 nb++;
    168 
    169                         } catch (Exception e) {
    170 
    171                         }
    172                 }
    173                 if (nb != thumbnailPerLine + 1) {
    174                         this.add(panelh);
    175                 }
    176         }
    177 
    178 
    179         /**
    180          * @return the categoryId
    181          */
    182         public Integer getCategoryId() {
    183                 return categoryId;
    184         }
    185 
    186 
    187         /**
    188          * @param categoryId the categoryId to set
    189          */
    190         public void setCategoryId(Integer categoryId) {
    191                 this.categoryId = categoryId;
    192         }
    193 
    194 
    195         /**
    196          * @return the category
    197          */
    198         public Category getCategory() {
    199                 return category;
    200         }
    201 
    202 
    203         /**
    204          * @param category the category to set
    205          */
    206         public void setCategory(Category category) {
    207                 this.category = category;
    208         }
    209 
    210         /**
    211          * @author mael
    212          * Thread that send the photos
    213          */
    214         public class ThreadEnvoiPhoto implements Runnable {
    215 
    216                 private File[] files;
    217 
    218 
    219                 public ThreadEnvoiPhoto(File[] files) {
    220                         this.files = files;
    221                 }
    222 
    223 
    224                 @Override
    225                 public void run() {
    226                         ImagesManagement.sendingFiles = true;
    227                         for (int i = 0; i < files.length; i++) {
    228                                 MainFrame.getInstance().setAdditionalMessage("<html><i>" + (i + 1) + "/" + files.length + " : </i></html>");
    229                                 int nbProgressBar = ((i + 1) * 100) / files.length;
    230                                 try {
    231 
    232                                         ImageService.getInstance().creer(files[i].getCanonicalPath(), categoryId);
    233                                         MainFrame.getInstance().setMessage(files[i].getName() + " " + Messages.getMessage("sendingSuccess"));
    234                                 } catch (Exception e) {
    235                                         LOG.error(Outil.getStackTrace(e));
    236                                         //displays a dialog if there is an error
    237                                         JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(),
    238                                                         Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
    239                                         MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName());
    240                                 } finally {
    241                                         MainFrame.getInstance().getProgressBar().setValue(nbProgressBar);
    242                                 }
    243                         }
    244                         //refresh
    245                         MainFrame.getInstance().setAdditionalMessage("");
    246                         rafraichir(categoryId, true);
    247                         MainFrame.getInstance().getProgressBar().setValue(0);
    248                         ImagesManagement.sendingFiles = false;
    249                 }
    250         }
     236                    LOG.error(Outil.getStackTrace(e));
     237                    //displays a dialog if there is an error
     238                    JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(),
     239                            Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
     240                    MainFrame.getInstance().setMessage(Messages.getMessage("sendingError") + " " + files[i].getName());
     241                } finally {
     242                    MainFrame.getInstance().getProgressBar().setValue(nbProgressBar);
     243                }
     244            }
     245            //refresh
     246            MainFrame.getInstance().setAdditionalMessage("");
     247            rafraichir(categoryId, true);
     248            MainFrame.getInstance().getProgressBar().setValue(0);
     249            imagesManagement.setSendingFiles(true);
     250        }
     251    }
    251252
    252253}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java

    r7221 r8829  
    1414import java.io.IOException;
    1515import java.util.List;
     16
    1617import javax.swing.JButton;
    1718import javax.swing.JDialog;
     
    2425import javax.swing.JScrollPane;
    2526import javax.swing.ListSelectionModel;
     27
    2628import fr.mael.jiwigo.om.Image;
    2729import fr.mael.jiwigo.om.Tag;
     
    3032import fr.mael.jiwigo.transverse.ImagesManagement;
    3133import fr.mael.jiwigo.transverse.util.Messages;
    32 import fr.mael.jiwigo.ui.browser.BrowserFrame;
     34import fr.mael.jiwigo.ui.browser.BrowserPanel;
    3335import fr.mael.jiwigo.ui.layout.VerticalLayout;
    34 
    3536
    3637/**
     
    6566public class ThumbnailPanel extends JLabel implements MouseListener, ActionListener {
    6667
    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);
     68    /**
     69     * Logger
     70     */
     71    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     72            .getLog(ThumbnailPanel.class);
     73    /**
     74     * the image
     75     */
     76    private Image image;
     77
     78    /**
     79     * Popup menu to edit images info
     80     */
     81    private JMenuItem menuAjouterTag;
     82
     83    /**
     84     * Button to add tags
     85     */
     86    private JButton boutonOkAjouterTag;
     87
     88    /**
     89     * List of tags
     90     */
     91    private JList listTags;
     92
     93    /**
     94     * Dialog that allows to choose tags
     95     */
     96    private JDialog dialogChoixTags;
     97
     98    /**
     99     * Constructeur
     100     * @param image the image
     101     * @param imagesPanel the panel
     102     */
     103    public ThumbnailPanel(Image image) {
     104        this.image = image;
     105        setToolTipText("<html><center>" + image.getName() + "<br/>" + image.getVue() + " "
     106                + Messages.getMessage("hits") + "</center></html>");
     107        this.addMouseListener(this);
     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.getInstance().getMiniatureBufferedImage(image).getWidth()) / 2;
     115        double y = (getHeight() * ImagesManagement.getInstance().getMiniatureBufferedImage(image).getHeight()) / 2;
     116        g2.drawRenderedImage(ImagesManagement.getInstance().getMiniatureBufferedImage(image), null);
     117    }
     118
     119    /* (non-Javadoc)
     120     * @see javax.swing.JComponent#getPreferredSize()
     121     */
     122    public Dimension getPreferredSize() {
     123        int w = (int) (ImagesManagement.getInstance().getMiniatureBufferedImage(image).getWidth());
     124        int h = (int) (ImagesManagement.getInstance().getMiniatureBufferedImage(image).getHeight() + 10);
     125        return new Dimension(w, h);
     126    }
     127
     128    @Override
     129    public void mouseClicked(MouseEvent paramMouseEvent) {
     130        // on affiche l'image en grand
     131        ImagesManagement.getInstance().setCurrentImage(image);
     132        try {
     133            if (paramMouseEvent.getButton() == 1) {
     134                BrowserPanel.getInstance().changeImage();
     135            } else if (paramMouseEvent.getButton() == 3) {
     136                JPopupMenu popup = new JPopupMenu();
     137                menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag"));
     138                menuAjouterTag.addActionListener(this);
     139                popup.add(menuAjouterTag);
     140                popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY());
     141            }
     142        } catch (Exception e) {
     143            e.printStackTrace();
    107144        }
    108145
    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);
     146    }
     147
     148    @Override
     149    public void mouseEntered(MouseEvent paramMouseEvent) {
     150        this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
     151    }
     152
     153    @Override
     154    public void mouseExited(MouseEvent paramMouseEvent) {
     155    }
     156
     157    @Override
     158    public void mousePressed(MouseEvent paramMouseEvent) {
     159        // TODO Auto-generated method stub
     160
     161    }
     162
     163    @Override
     164    public void mouseReleased(MouseEvent paramMouseEvent) {
     165        // TODO Auto-generated method stub
     166
     167    }
     168
     169    @Override
     170    public void actionPerformed(ActionEvent arg0) {
     171        if (arg0.getSource().equals(menuAjouterTag)) {
     172            try {
     173                //getting the list of tags
     174                List<Tag> tagsDispo = TagService.getInstance().lister();
     175                //list to array (cause fucking JList does not support Lists)
     176                Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]);
     177                //getting the image's tags to preselect them
     178                List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image);
     179                listTags = new JList(tableauTagDispo);
     180                //multiple selection is allowed
     181                listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     182                listTags.setPreferredSize(new Dimension(100, 200));
     183                //construct an array of the indices to select in the jlist
     184                int[] indices = new int[tagsDeLimage.size()];
     185                int compteur = 0;
     186                for (int i = 0; i < tableauTagDispo.length; i++) {
     187                    for (Tag tag : tagsDeLimage) {
     188                        if (tag.getId().equals(tableauTagDispo[i].getId())) {
     189                            indices[compteur++] = i;
     190
     191                        }
     192                    }
     193                }
     194                listTags.setSelectedIndices(indices);
     195
     196                JScrollPane scrollPane = new JScrollPane(listTags);
     197                dialogChoixTags = new JDialog();
     198                dialogChoixTags.setLayout(new BorderLayout());
     199                JPanel panelNorth = new JPanel(new VerticalLayout());
     200                panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag")));
     201                panelNorth.add(scrollPane);
     202                dialogChoixTags.add(panelNorth, BorderLayout.NORTH);
     203                JPanel panelBouton = new JPanel(new FlowLayout());
     204                boutonOkAjouterTag = new JButton("Ok");
     205                panelBouton.add(boutonOkAjouterTag);
     206                boutonOkAjouterTag.addActionListener(this);
     207                dialogChoixTags.add(panelBouton, BorderLayout.CENTER);
     208                dialogChoixTags.setSize(new Dimension(400, 280));
     209                dialogChoixTags.setLocationRelativeTo(null);
     210                dialogChoixTags.setVisible(true);
     211            } catch (IOException e) {
     212                e.printStackTrace();
     213            }
     214        } else if (arg0.getSource().equals(boutonOkAjouterTag)) {
     215            StringBuffer tagIds = new StringBuffer("");
     216            for (Object object : listTags.getSelectedValues()) {
     217                Tag tag = (Tag) object;
     218                tagIds.append(tag.getId() + ",");
     219            }
     220            tagIds.deleteCharAt(tagIds.lastIndexOf(","));
     221            try {
     222                if (!ImageService.getInstance().addTags(image, tagIds.toString())) {
     223                    JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages
     224                            .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     225                } else {
     226                    dialogChoixTags.dispose();
     227                }
     228            } catch (IOException e) {
     229                e.printStackTrace();
     230            }
     231
    117232        }
    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();
    146                 }
    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 
    239                 }
    240         }
     233    }
    241234}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailSearchPanel.java

    r7070 r8829  
    8989        try {
    9090            MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading"));
    91             ImagesManagement.LIST_IMAGE = ImageService.getInstance().search(queryString);
    92             for (Image image : ImagesManagement.LIST_IMAGE) {
     91            ImagesManagement.getInstance().setListImage(ImageService.getInstance().search(queryString));
     92            for (Image image : ImagesManagement.getInstance().getListImage()) {
    9393                try {
    9494
Note: See TracChangeset for help on using the changeset viewer.