source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/ThumbnailSearchPanel.java @ 9385

Last change on this file since 9385 was 9385, checked in by mlg, 13 years ago

All services have been removed from this project to be integrated in a new project : jiwigo-ws-api (not yet on the svn).
The current project now uses jiwigo-ws-api as a maven dependency (explanations can be found here : http://www.jiwigo.com/api.html )

File size: 4.6 KB
Line 
1package fr.mael.jiwigo.ui.mainframe;
2
3import java.awt.FlowLayout;
4
5import javax.swing.JOptionPane;
6import javax.swing.JPanel;
7
8import fr.mael.jiwigo.Main;
9import fr.mael.jiwigo.om.Category;
10import fr.mael.jiwigo.om.Image;
11import fr.mael.jiwigo.service.ImageService;
12import fr.mael.jiwigo.transverse.ImagesManagement;
13import fr.mael.jiwigo.transverse.util.Messages;
14import fr.mael.jiwigo.transverse.util.Outil;
15import fr.mael.jiwigo.ui.layout.VerticalLayout;
16
17/**
18   Copyright (c) 2010, Mael
19   All rights reserved.
20
21   Redistribution and use in source and binary forms, with or without
22   modification, are permitted provided that the following conditions are met:
23    * Redistributions of source code must retain the above copyright
24      notice, this list of conditions and the following disclaimer.
25    * Redistributions in binary form must reproduce the above copyright
26      notice, this list of conditions and the following disclaimer in the
27      documentation and/or other materials provided with the distribution.
28    * Neither the name of jiwigo nor the
29      names of its contributors may be used to endorse or promote products
30      derived from this software without specific prior written permission.
31
32   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
36   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 * @author mael
44 * Classe qui affiche toutes les miniatures d'une catégorie
45 */
46public class ThumbnailSearchPanel extends JPanel implements IThumbnailPanel {
47    /**
48     * Logger
49     */
50    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
51            .getLog(ThumbnailSearchPanel.class);
52
53    /**
54     * fake category id = -1
55     */
56    private Integer categoryId;
57
58    /**
59     * fake category
60     */
61    private Category category;
62
63    /**
64     * query made by user
65     */
66    private String queryString;
67
68    /**
69     * Constructeur
70     * @param categoryId l'id de la catégorie
71     */
72    public ThumbnailSearchPanel(String queryString) {
73        this.categoryId = -1;
74        category = new Category();
75        category.setIdentifiant(-1);
76        category.setNom(Messages.getMessage("mainFrame_recherche"));
77        this.queryString = queryString;
78        this.setLayout(new VerticalLayout());
79        rechercher();
80    }
81
82    /**
83     *refreshes
84     * @param categoryId the id of the category
85     */
86    public void rechercher() {
87        this.removeAll();
88        int nb = 1;
89        JPanel panelh = new JPanel(new FlowLayout());
90        try {
91            MainFrame.getInstance().setMessage(Messages.getMessage("thumbviewer_loading"));
92            ImagesManagement.getInstance().setListImage(
93                    ImageService.getInstance(Main.sessionManager).search(queryString));
94            for (Image image : ImagesManagement.getInstance().getListImage()) {
95                try {
96
97                    if (nb == 7) {
98                        this.add(panelh);
99                        panelh = new JPanel(new FlowLayout());
100                        nb = 0;
101                    } else {
102                        ThumbnailPanel panel = new ThumbnailPanel(image);
103                        panelh.add(panel);
104                    }
105                    nb++;
106
107                } catch (Exception e) {
108
109                }
110            }
111            if (nb != 8) {
112                this.add(panelh);
113            }
114            this.repaint();
115            this.revalidate();
116            MainFrame.getInstance().setMessage(Messages.getMessage("loadingOk"));
117        } catch (Exception e) {
118            LOG.error(Outil.getStackTrace(e));
119            JOptionPane.showMessageDialog(null, Messages.getMessage("imagesListingError"),
120                    Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
121            MainFrame.getInstance().setMessage(Messages.getMessage("imagesListingError"));
122        }
123    }
124
125    /**
126     * @return the categoryId
127     */
128    public Integer getCategoryId() {
129        return categoryId;
130    }
131
132    /**
133     * @param categoryId the categoryId to set
134     */
135    public void setCategoryId(Integer categoryId) {
136        this.categoryId = categoryId;
137    }
138
139    /**
140     * @return the category
141     */
142    public Category getCategory() {
143        return category;
144    }
145
146    /**
147     * @param category the category to set
148     */
149    public void setCategory(Category category) {
150        this.category = category;
151    }
152
153    /**
154     * @return the queryString
155     */
156    public String getQueryString() {
157        return queryString;
158    }
159
160}
Note: See TracBrowser for help on using the repository browser.