Changeset 6968


Ignore:
Timestamp:
Sep 19, 2010, 9:27:31 PM (14 years ago)
Author:
mlg
Message:

Feature :
Adds the ui to add tags. It's done in the thumbnail viewer (right click on the thumbnail)

Location:
extensions/jiwigo/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/pom.xml

    r6964 r6968  
    33  <groupId>Jiwigo</groupId>
    44  <artifactId>Jiwigo</artifactId>
    5   <version>0.2</version>
     5  <version>0.13</version>
    66 
    77
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/ImageDao.java

    r6831 r6968  
    204204    }
    205205
     206    /**
     207     * Add tags to an image
     208     * @param imageId id of the image
     209     * @param tagId ids of the tags
     210     * @throws IOException
     211     */
     212    public boolean addTags(Integer imageId, String tagId) throws IOException {
     213        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.SET_INFO.getLabel(), "image_id", String
     214                .valueOf(imageId), "tag_ids", tagId);
     215        return Outil.checkOk(doc);
     216
     217    }
     218
    206219    private void suppressionFichierTemporaires() {
    207220        File file = new File(System.getProperty("java.io.tmpdir") + "/originale.jpg");
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/TagDao.java

    r6964 r6968  
    99
    1010import fr.mael.jiwigo.Main;
     11import fr.mael.jiwigo.om.Image;
    1112import fr.mael.jiwigo.om.Tag;
    1213import fr.mael.jiwigo.transverse.enumeration.MethodsEnum;
     
    7879        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_TAGS.getLabel());
    7980        //      System.out.println(Outil.documentToString(doc));
    80         Element element = doc.getRootElement().getChild("tags");
     81        return getTagsFromDocument(doc.getRootElement().getChild("tags"));
     82
     83    }
     84
     85    /**
     86     * COnstructs a list of tags from a document
     87     * @param doc the document
     88     * @return the list of tags
     89     */
     90    private List<Tag> getTagsFromDocument(Element element) {
     91
    8192        List<Element> listElement = (List<Element>) element.getChildren("tag");
    8293        ArrayList<Tag> tags = new ArrayList<Tag>();
     
    8697        }
    8798        return tags;
     99
    88100    }
    89101
     
    103115    }
    104116
     117    /**
     118     * Function that returns the tags for an image
     119     * @param image the image
     120     * @return the tags list
     121     * @throws IOException
     122     */
     123    public List<Tag> tagsForImage(Image image) throws IOException {
     124        Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.GET_INFO.getLabel(), "image_id", String
     125                .valueOf(image.getIdentifiant()));
     126        return getTagsFromDocument(doc.getRootElement().getChild("image").getChild("tags"));
     127    }
     128
    105129}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/om/Tag.java

    r6964 r6968  
    33import org.jdom.Element;
    44
     5import fr.mael.jiwigo.transverse.enumeration.TagEnum;
     6
     7/**
     8Copyright (c) 2010, Mael
     9All rights reserved.
     10
     11Redistribution and use in source and binary forms, with or without
     12modification, are permitted provided that the following conditions are met:
     13 * Redistributions of source code must retain the above copyright
     14   notice, this list of conditions and the following disclaimer.
     15 * Redistributions in binary form must reproduce the above copyright
     16   notice, this list of conditions and the following disclaimer in the
     17   documentation and/or other materials provided with the distribution.
     18 * Neither the name of jiwigo nor the
     19   names of its contributors may be used to endorse or promote products
     20   derived from this software without specific prior written permission.
     21
     22THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     23ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
     26DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     29ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32
     33* @author mael
     34*
     35*/
    536public class Tag {
    637    /**
    738     * Name of the tag
    839     */
    9     String nom;
     40    private String nom;
     41
     42    /**
     43     * Id of the tag
     44     */
     45    private Integer identifiant;
    1046
    1147    /**
     
    1955     */
    2056    public Tag(Element element) {
    21 
     57        this.identifiant = Integer.valueOf(element.getAttributeValue(TagEnum.ID.getLabel()));
     58        this.nom = element.getAttributeValue(TagEnum.NAME.getLabel());
    2259    }
    2360
     
    4380    }
    4481
     82    /**
     83     * @return the id
     84     */
     85    public Integer getId() {
     86        return identifiant;
     87    }
     88
     89    /**
     90     * @param id the id to set
     91     */
     92    public void setId(Integer id) {
     93        this.identifiant = id;
     94    }
     95
     96    @Override
     97    public String toString() {
     98        // TODO Auto-generated method stub
     99        return nom;
     100    }
    45101}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/ImageService.java

    r6840 r6968  
    120120    }
    121121
     122    public boolean addTags(Image image, String tagId) throws IOException {
     123        return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId);
     124    }
     125
    122126    /**
    123127     * Deletes the file extension
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/TagService.java

    r6964 r6968  
    55
    66import fr.mael.jiwigo.dao.TagDao;
     7import fr.mael.jiwigo.om.Image;
    78import fr.mael.jiwigo.om.Tag;
    89
     
    5354    }
    5455
     56    /**
     57     * private constructor
     58     */
    5559    private TagService() {
    5660
    5761    }
    5862
     63    /**
     64     * Lists all tags
     65     * @return le list of tags
     66     * @throws IOException
     67     */
    5968    public List<Tag> lister() throws IOException {
    6069        return TagDao.getInstance().lister();
    6170    }
    6271
     72    /**
     73     * Creates a tag
     74     * @param nom name of the tag
     75     * @return true if the tag is created
     76     * @throws IOException
     77     */
    6378    public boolean creer(String nom) throws IOException {
    6479        Tag tag = new Tag(nom);
     
    6681    }
    6782
     83    /**
     84     * Returns all the tag for an image
     85     * @param image the image to check
     86     * @return the list of tags
     87     * @throws IOException
     88     */
     89    public List<Tag> tagsForImage(Image image) throws IOException {
     90        return TagDao.getInstance().tagsForImage(image);
     91    }
     92
    6893}
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java

    r6964 r6968  
    3838    LOGIN("pwg.session.login"), LISTER_CATEGORIES("pwg.categories.getList"), LISTER_IMAGES("pwg.categories.getImages"), GET_INFO(
    3939            "pwg.images.getInfo"), AJOUTER_CATEGORIE("pwg.categories.add"), AJOUTER_COMMENTAIRE("pwg.images.addComment"), LISTER_TAGS(
    40             "pwg.tags.getList"), TAGS_ADMIN_LIST("pwg.tags.getAdminList"), ADD_TAG("pwg.tags.add");
     40            "pwg.tags.getList"), TAGS_ADMIN_LIST("pwg.tags.getAdminList"), ADD_TAG("pwg.tags.add"), SET_INFO(
     41            "pwg.images.setInfo");
    4142
    4243    protected String label;
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java

    r6965 r6968  
    11package fr.mael.jiwigo.ui.mainframe;
    22
     3import java.awt.BorderLayout;
    34import java.awt.Cursor;
    45import java.awt.Dimension;
     6import java.awt.FlowLayout;
    57import java.awt.Graphics;
    68import java.awt.Graphics2D;
     
    1012import java.awt.event.MouseEvent;
    1113import java.awt.event.MouseListener;
    12 
     14import java.io.IOException;
     15import java.util.List;
     16
     17import javax.swing.JButton;
     18import javax.swing.JDialog;
    1319import javax.swing.JLabel;
     20import javax.swing.JList;
    1421import javax.swing.JMenuItem;
     22import javax.swing.JOptionPane;
     23import javax.swing.JPanel;
    1524import javax.swing.JPopupMenu;
     25import javax.swing.JScrollPane;
     26import javax.swing.ListSelectionModel;
    1627
    1728import fr.mael.jiwigo.om.Image;
     29import fr.mael.jiwigo.om.Tag;
     30import fr.mael.jiwigo.service.ImageService;
     31import fr.mael.jiwigo.service.TagService;
    1832import fr.mael.jiwigo.transverse.util.Messages;
    1933import fr.mael.jiwigo.ui.ImagesManagement;
    2034import fr.mael.jiwigo.ui.browser.BrowserFrame;
     35import fr.mael.jiwigo.ui.layout.VerticalLayout;
    2136
    2237/**
     
    6479     * Popup menu to edit images info
    6580     */
    66     private JMenuItem menuEditer;
     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;
    6797
    6898    /**
     
    98128    @Override
    99129    public void mouseClicked(MouseEvent paramMouseEvent) {
    100         System.out.println(paramMouseEvent.getButton());
    101130        // on affiche l'image en grand
    102131        ImagesManagement.setCurrentImage(image);
     
    106135            } else if (paramMouseEvent.getButton() == 3) {
    107136                JPopupMenu popup = new JPopupMenu();
    108                 JMenuItem menuEditer = new JMenuItem(Messages.getMessage("categories_add"));
    109                 menuEditer.addActionListener(this);
     137                menuAjouterTag = new JMenuItem(Messages.getMessage("thumbviewer_addTag"));
     138                menuAjouterTag.addActionListener(this);
     139                popup.add(menuAjouterTag);
    110140                popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY());
    111141            }
     
    140170    @Override
    141171    public void actionPerformed(ActionEvent arg0) {
    142 
    143     }
    144 
     172        if (arg0.getSource().equals(menuAjouterTag)) {
     173            try {
     174                //getting the list of tags
     175                List<Tag> tagsDispo = TagService.getInstance().lister();
     176                //list to array (cause fucking JList does not support Lists)
     177                Tag[] tableauTagDispo = (Tag[]) tagsDispo.toArray(new Tag[tagsDispo.size()]);
     178                //getting the image's tags to preselect them
     179                List<Tag> tagsDeLimage = TagService.getInstance().tagsForImage(image);
     180                listTags = new JList(tableauTagDispo);
     181                //multiple selection is allowed
     182                listTags.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     183                listTags.setPreferredSize(new Dimension(100, 200));
     184                //construct an array of the indices to select in the jlist
     185                int[] indices = new int[tagsDeLimage.size()];
     186                int compteur = 0;
     187                for (int i = 0; i < tableauTagDispo.length; i++) {
     188                    for (Tag tag : tagsDeLimage) {
     189                        if (tag.getId().equals(tableauTagDispo[i].getId())) {
     190                            indices[compteur++] = i;
     191
     192                        }
     193                    }
     194                }
     195                listTags.setSelectedIndices(indices);
     196
     197                JScrollPane scrollPane = new JScrollPane(listTags);
     198                dialogChoixTags = new JDialog();
     199                dialogChoixTags.setLayout(new BorderLayout());
     200                JPanel panelNorth = new JPanel(new VerticalLayout());
     201                panelNorth.add(new JLabel(Messages.getMessage("thumbviewer_selectTag")));
     202                panelNorth.add(scrollPane);
     203                dialogChoixTags.add(panelNorth, BorderLayout.NORTH);
     204                JPanel panelBouton = new JPanel(new FlowLayout());
     205                boutonOkAjouterTag = new JButton("Ok");
     206                panelBouton.add(boutonOkAjouterTag);
     207                boutonOkAjouterTag.addActionListener(this);
     208                dialogChoixTags.add(panelBouton, BorderLayout.CENTER);
     209                dialogChoixTags.setSize(new Dimension(400, 280));
     210                dialogChoixTags.setLocationRelativeTo(null);
     211                dialogChoixTags.setVisible(true);
     212            } catch (IOException e) {
     213                e.printStackTrace();
     214            }
     215        } else if (arg0.getSource().equals(boutonOkAjouterTag)) {
     216            StringBuffer tagIds = new StringBuffer("");
     217            for (Object object : listTags.getSelectedValues()) {
     218                Tag tag = (Tag) object;
     219                tagIds.append(tag.getId() + ",");
     220            }
     221            tagIds.deleteCharAt(tagIds.lastIndexOf(","));
     222            try {
     223                if (!ImageService.getInstance().addTags(image, tagIds.toString())) {
     224                    JOptionPane.showMessageDialog(this, Messages.getMessage("addingTagsError"), Messages
     225                            .getMessage("error"), JOptionPane.ERROR_MESSAGE);
     226                } else {
     227                    dialogChoixTags.dispose();
     228                }
     229            } catch (IOException e) {
     230                e.printStackTrace();
     231            }
     232
     233        }
     234    }
    145235}
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages.properties

    r6958 r6968  
    44error=Error
    55welcomeMessage=Welcome to Jiwigo
    6 version=0.11b
     6version=0.13
    77commentaires=Comments
    88loading=Loading...
     
    3636thumbviewer_closeOthers=Close others
    3737thumbviewer_closeAll=Close all
     38thumbviewer_addTag=Add tags
     39thumbviewer_selectTag=Select tags :
    3840
    3941#####################################################
     
    5153preferencesUnexpectedError=<html>An unexpected error happened. Preferences won't be updated</html>
    5254clippingError=Clipping does not work with zoom
     55listingTagsError=Error while getting tags
     56addingTagsError=Error while adding tags
    5357
    5458#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_de.properties

    r6841 r6968  
    44error=Fehler
    55welcomeMessage=Willkommen bei Jiwigo
    6 version=0.11b
     6version=0.13
    77commentaires=Kommentare
    88loading=Ladet...
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_en.properties

    r6958 r6968  
    44error=Error
    55welcomeMessage=Welcome to Jiwigo
    6 version=0.11b
     6version=0.13
    77commentaires=Comments
    88loading=Loading...
     
    3636thumbviewer_closeOthers=Close others
    3737thumbviewer_closeAll=Close all
     38thumbviewer_addTag=Add tags
     39thumbviewer_selectTag=Select tags :
    3840
    3941#####################################################
     
    5153preferencesUnexpectedError=<html>An unexpected error happened. Preferences won't be updated</html>
    5254clippingError=Clipping does not work with zoom
     55listingTagsError=Error while getting tags
     56addingTagsError=Error while adding tags
    5357
    5458#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_fr.properties

    r6966 r6968  
    44error=Erreur
    55welcomeMessage=Bienvenue dans Jiwigo
    6 version=0.11b
     6version=0.13
    77commentaires=Commentaires
    88loading=Chargement...
     
    3636thumbviewer_closeOthers=Fermer les autres
    3737thumbviewer_closeAll=Fermer tous
     38thumbviewer_addTag=Ajouter des tags
     39thumbviewer_selectTag=Veuillez sélectionner un (des) tag(s) :
    3840
    3941#####################################################
     
    5153preferencesUnexpectedError=<html>Une erreur inattendue s'est produite. Les préférences ne seront<br/>probablement pas mises à jour</html>
    5254clippingError=Le rognage ne fonctionne pas avec le zoom
     55listingTagsError=Erreur lors de la récupération des tags
     56addingTagsError=Erreur lors de l'ajout de tags
    5357
    5458#####################################################
  • extensions/jiwigo/trunk/src/main/resources/fr/mael/jiwigo/trad/messages_it.properties

    r6841 r6968  
    44error=Errore
    55welcomeMessage=Benvenuti su Jiwigo
    6 version=0.11b
     6version=0.13
    77commentaires=Commenti
    88loading=Caricamento in corso...
Note: See TracChangeset for help on using the changeset viewer.