Changeset 6968 for extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
- Timestamp:
- Sep 19, 2010, 9:27:31 PM (14 years ago)
- Location:
- extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/dao/ImageDao.java
r6831 r6968 204 204 } 205 205 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 206 219 private void suppressionFichierTemporaires() { 207 220 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 9 9 10 10 import fr.mael.jiwigo.Main; 11 import fr.mael.jiwigo.om.Image; 11 12 import fr.mael.jiwigo.om.Tag; 12 13 import fr.mael.jiwigo.transverse.enumeration.MethodsEnum; … … 78 79 Document doc = Main.sessionManager.executerReturnDocument(MethodsEnum.LISTER_TAGS.getLabel()); 79 80 // 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 81 92 List<Element> listElement = (List<Element>) element.getChildren("tag"); 82 93 ArrayList<Tag> tags = new ArrayList<Tag>(); … … 86 97 } 87 98 return tags; 99 88 100 } 89 101 … … 103 115 } 104 116 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 105 129 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/om/Tag.java
r6964 r6968 3 3 import org.jdom.Element; 4 4 5 import fr.mael.jiwigo.transverse.enumeration.TagEnum; 6 7 /** 8 Copyright (c) 2010, Mael 9 All rights reserved. 10 11 Redistribution and use in source and binary forms, with or without 12 modification, 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 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY 26 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 ON 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 31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 33 * @author mael 34 * 35 */ 5 36 public class Tag { 6 37 /** 7 38 * Name of the tag 8 39 */ 9 String nom; 40 private String nom; 41 42 /** 43 * Id of the tag 44 */ 45 private Integer identifiant; 10 46 11 47 /** … … 19 55 */ 20 56 public Tag(Element element) { 21 57 this.identifiant = Integer.valueOf(element.getAttributeValue(TagEnum.ID.getLabel())); 58 this.nom = element.getAttributeValue(TagEnum.NAME.getLabel()); 22 59 } 23 60 … … 43 80 } 44 81 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 } 45 101 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/ImageService.java
r6840 r6968 120 120 } 121 121 122 public boolean addTags(Image image, String tagId) throws IOException { 123 return ImageDao.getInstance().addTags(image.getIdentifiant(), tagId); 124 } 125 122 126 /** 123 127 * Deletes the file extension -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/service/TagService.java
r6964 r6968 5 5 6 6 import fr.mael.jiwigo.dao.TagDao; 7 import fr.mael.jiwigo.om.Image; 7 8 import fr.mael.jiwigo.om.Tag; 8 9 … … 53 54 } 54 55 56 /** 57 * private constructor 58 */ 55 59 private TagService() { 56 60 57 61 } 58 62 63 /** 64 * Lists all tags 65 * @return le list of tags 66 * @throws IOException 67 */ 59 68 public List<Tag> lister() throws IOException { 60 69 return TagDao.getInstance().lister(); 61 70 } 62 71 72 /** 73 * Creates a tag 74 * @param nom name of the tag 75 * @return true if the tag is created 76 * @throws IOException 77 */ 63 78 public boolean creer(String nom) throws IOException { 64 79 Tag tag = new Tag(nom); … … 66 81 } 67 82 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 68 93 } -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/transverse/enumeration/MethodsEnum.java
r6964 r6968 38 38 LOGIN("pwg.session.login"), LISTER_CATEGORIES("pwg.categories.getList"), LISTER_IMAGES("pwg.categories.getImages"), GET_INFO( 39 39 "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"); 41 42 42 43 protected String label; -
extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailPanel.java
r6965 r6968 1 1 package fr.mael.jiwigo.ui.mainframe; 2 2 3 import java.awt.BorderLayout; 3 4 import java.awt.Cursor; 4 5 import java.awt.Dimension; 6 import java.awt.FlowLayout; 5 7 import java.awt.Graphics; 6 8 import java.awt.Graphics2D; … … 10 12 import java.awt.event.MouseEvent; 11 13 import java.awt.event.MouseListener; 12 14 import java.io.IOException; 15 import java.util.List; 16 17 import javax.swing.JButton; 18 import javax.swing.JDialog; 13 19 import javax.swing.JLabel; 20 import javax.swing.JList; 14 21 import javax.swing.JMenuItem; 22 import javax.swing.JOptionPane; 23 import javax.swing.JPanel; 15 24 import javax.swing.JPopupMenu; 25 import javax.swing.JScrollPane; 26 import javax.swing.ListSelectionModel; 16 27 17 28 import fr.mael.jiwigo.om.Image; 29 import fr.mael.jiwigo.om.Tag; 30 import fr.mael.jiwigo.service.ImageService; 31 import fr.mael.jiwigo.service.TagService; 18 32 import fr.mael.jiwigo.transverse.util.Messages; 19 33 import fr.mael.jiwigo.ui.ImagesManagement; 20 34 import fr.mael.jiwigo.ui.browser.BrowserFrame; 35 import fr.mael.jiwigo.ui.layout.VerticalLayout; 21 36 22 37 /** … … 64 79 * Popup menu to edit images info 65 80 */ 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; 67 97 68 98 /** … … 98 128 @Override 99 129 public void mouseClicked(MouseEvent paramMouseEvent) { 100 System.out.println(paramMouseEvent.getButton());101 130 // on affiche l'image en grand 102 131 ImagesManagement.setCurrentImage(image); … … 106 135 } else if (paramMouseEvent.getButton() == 3) { 107 136 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); 110 140 popup.show(this, paramMouseEvent.getX(), paramMouseEvent.getY()); 111 141 } … … 140 170 @Override 141 171 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 } 145 235 }
Note: See TracChangeset
for help on using the changeset viewer.