1 | package fr.mael.jiwigo.ui.mainframe; |
---|
2 | |
---|
3 | import java.awt.Dimension; |
---|
4 | import java.awt.FlowLayout; |
---|
5 | |
---|
6 | import javax.swing.JOptionPane; |
---|
7 | import javax.swing.JPanel; |
---|
8 | |
---|
9 | import fr.mael.jiwigo.om.Image; |
---|
10 | import fr.mael.jiwigo.service.ImageService; |
---|
11 | import fr.mael.jiwigo.transverse.util.Messages; |
---|
12 | import fr.mael.jiwigo.transverse.util.Outil; |
---|
13 | import fr.mael.jiwigo.transverse.util.filedrop.FileDrop; |
---|
14 | import fr.mael.jiwigo.ui.ImagesManagement; |
---|
15 | |
---|
16 | /** |
---|
17 | Copyright (c) 2010, Mael |
---|
18 | All rights reserved. |
---|
19 | |
---|
20 | Redistribution and use in source and binary forms, with or without |
---|
21 | modification, are permitted provided that the following conditions are met: |
---|
22 | * Redistributions of source code must retain the above copyright |
---|
23 | notice, this list of conditions and the following disclaimer. |
---|
24 | * Redistributions in binary form must reproduce the above copyright |
---|
25 | notice, this list of conditions and the following disclaimer in the |
---|
26 | documentation and/or other materials provided with the distribution. |
---|
27 | * Neither the name of jiwigo nor the |
---|
28 | names of its contributors may be used to endorse or promote products |
---|
29 | derived from this software without specific prior written permission. |
---|
30 | |
---|
31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
32 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
33 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
34 | DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY |
---|
35 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
36 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
37 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
38 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
39 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
40 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
41 | |
---|
42 | * @author mael |
---|
43 | * Classe qui affiche toutes les miniatures d'une catégorie |
---|
44 | */ |
---|
45 | public class ThumbnailCategoryPanel extends JPanel { |
---|
46 | /** |
---|
47 | * Logger |
---|
48 | */ |
---|
49 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
50 | .getLog(ThumbnailCategoryPanel.class); |
---|
51 | /** |
---|
52 | * L'id de la catégorie pour laquelle les miniatures doivent être affichées |
---|
53 | */ |
---|
54 | private Integer categoryId; |
---|
55 | |
---|
56 | /** |
---|
57 | * Constructeur |
---|
58 | * @param categoryId l'id de la catégorie |
---|
59 | */ |
---|
60 | public ThumbnailCategoryPanel(Integer categoryId) { |
---|
61 | this.categoryId = categoryId; |
---|
62 | this.setLayout(new FlowLayout()); |
---|
63 | this.setPreferredSize(new Dimension(1000, 750)); |
---|
64 | if (categoryId != null) { |
---|
65 | rafraichir(categoryId, false); |
---|
66 | } |
---|
67 | //gestion du drag'n drop |
---|
68 | new FileDrop(System.out, this, new FileDrop.Listener() { |
---|
69 | public void filesDropped(final java.io.File[] files) { |
---|
70 | for (int i = 0; i < files.length; i++) { |
---|
71 | try { |
---|
72 | ImageService.getInstance().creer(files[i].getCanonicalPath(), getCategoryId()); |
---|
73 | //on rafraichit |
---|
74 | rafraichir(getCategoryId(), true); |
---|
75 | } catch (Exception e) { |
---|
76 | LOG.error(Outil.getStackTrace(e)); |
---|
77 | //s'il y a une erreur lors de l'envoi |
---|
78 | JOptionPane.showMessageDialog(null, Messages.getMessage("sendingError") + files[i].getName(), |
---|
79 | Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|
84 | }); |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * rafraichissement, afin d'afficher les nouvelles images |
---|
90 | * @param categoryId |
---|
91 | */ |
---|
92 | public void rafraichir(Integer categoryId, boolean rafraichir) { |
---|
93 | this.categoryId = categoryId; |
---|
94 | this.removeAll(); |
---|
95 | try { |
---|
96 | ImagesManagement.LIST_IMAGE = ImageService.getInstance().listerParCategory(categoryId, rafraichir); |
---|
97 | for (Image image : ImagesManagement.LIST_IMAGE) { |
---|
98 | try { |
---|
99 | // MiniatureLabel label = new MiniatureLabel(image, this); |
---|
100 | ThumbnailPanel panel = new ThumbnailPanel(image); |
---|
101 | this.add(panel); |
---|
102 | } catch (Exception e) { |
---|
103 | |
---|
104 | } |
---|
105 | } |
---|
106 | this.repaint(); |
---|
107 | this.revalidate(); |
---|
108 | } catch (Exception e) { |
---|
109 | LOG.error(Outil.getStackTrace(e)); |
---|
110 | JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), |
---|
111 | Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * @return the categoryId |
---|
117 | */ |
---|
118 | public Integer getCategoryId() { |
---|
119 | return categoryId; |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * @param categoryId the categoryId to set |
---|
124 | */ |
---|
125 | public void setCategoryId(Integer categoryId) { |
---|
126 | this.categoryId = categoryId; |
---|
127 | } |
---|
128 | |
---|
129 | } |
---|