1 | package fr.mael.jiwigo.ui.mainframe; |
---|
2 | |
---|
3 | import java.awt.FlowLayout; |
---|
4 | |
---|
5 | import javax.swing.JOptionPane; |
---|
6 | import javax.swing.JPanel; |
---|
7 | |
---|
8 | import fr.mael.jiwigo.om.Category; |
---|
9 | import fr.mael.jiwigo.om.Image; |
---|
10 | import fr.mael.jiwigo.service.ImageService; |
---|
11 | import fr.mael.jiwigo.transverse.ImagesManagement; |
---|
12 | import fr.mael.jiwigo.transverse.util.Messages; |
---|
13 | import fr.mael.jiwigo.transverse.util.Outil; |
---|
14 | import fr.mael.jiwigo.ui.layout.VerticalLayout; |
---|
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 ThumbnailSearchPanel extends JPanel implements IThumbnailPanel { |
---|
46 | /** |
---|
47 | * Logger |
---|
48 | */ |
---|
49 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
50 | .getLog(ThumbnailSearchPanel.class); |
---|
51 | |
---|
52 | /** |
---|
53 | * fake category id = -1 |
---|
54 | */ |
---|
55 | private Integer categoryId; |
---|
56 | |
---|
57 | /** |
---|
58 | * fake category |
---|
59 | */ |
---|
60 | private Category category; |
---|
61 | |
---|
62 | /** |
---|
63 | * query made by user |
---|
64 | */ |
---|
65 | private String queryString; |
---|
66 | |
---|
67 | /** |
---|
68 | * Constructeur |
---|
69 | * @param categoryId l'id de la catégorie |
---|
70 | */ |
---|
71 | public ThumbnailSearchPanel(String queryString) { |
---|
72 | this.categoryId = -1; |
---|
73 | category = new Category(); |
---|
74 | category.setIdentifiant(-1); |
---|
75 | category.setNom(Messages.getMessage("mainFrame_recherche")); |
---|
76 | this.queryString = queryString; |
---|
77 | this.setLayout(new VerticalLayout()); |
---|
78 | rechercher(); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | *refreshes |
---|
83 | * @param categoryId the id of the category |
---|
84 | */ |
---|
85 | public void rechercher() { |
---|
86 | this.removeAll(); |
---|
87 | int nb = 1; |
---|
88 | JPanel panelh = new JPanel(new FlowLayout()); |
---|
89 | try { |
---|
90 | MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading")); |
---|
91 | ImagesManagement.getInstance().setListImage(ImageService.getInstance().search(queryString)); |
---|
92 | for (Image image : ImagesManagement.getInstance().getListImage()) { |
---|
93 | try { |
---|
94 | |
---|
95 | if (nb == 7) { |
---|
96 | this.add(panelh); |
---|
97 | panelh = new JPanel(new FlowLayout()); |
---|
98 | nb = 0; |
---|
99 | } else { |
---|
100 | ThumbnailPanel panel = new ThumbnailPanel(image); |
---|
101 | panelh.add(panel); |
---|
102 | } |
---|
103 | nb++; |
---|
104 | |
---|
105 | } catch (Exception e) { |
---|
106 | |
---|
107 | } |
---|
108 | } |
---|
109 | if (nb != 8) { |
---|
110 | this.add(panelh); |
---|
111 | } |
---|
112 | this.repaint(); |
---|
113 | this.revalidate(); |
---|
114 | MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk")); |
---|
115 | } catch (Exception e) { |
---|
116 | LOG.error(Outil.getStackTrace(e)); |
---|
117 | JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"), |
---|
118 | Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE); |
---|
119 | MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError")); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * @return the categoryId |
---|
125 | */ |
---|
126 | public Integer getCategoryId() { |
---|
127 | return categoryId; |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * @param categoryId the categoryId to set |
---|
132 | */ |
---|
133 | public void setCategoryId(Integer categoryId) { |
---|
134 | this.categoryId = categoryId; |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * @return the category |
---|
139 | */ |
---|
140 | public Category getCategory() { |
---|
141 | return category; |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * @param category the category to set |
---|
146 | */ |
---|
147 | public void setCategory(Category category) { |
---|
148 | this.category = category; |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * @return the queryString |
---|
153 | */ |
---|
154 | public String getQueryString() { |
---|
155 | return queryString; |
---|
156 | } |
---|
157 | |
---|
158 | } |
---|