source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/comments/CommentsDialog.java @ 6821

Last change on this file since 6821 was 6821, checked in by mlg, 14 years ago

Premier commit. Actuellement, l'application gère :
-Listing des catégories
-Affichage des miniatures
-Ajout de commentaires
-gestion d'un cache pour ne pas télécharger les images plusieurs fois
-gestion d'un zoom dans le navigateur d'images
-navigateur d'images complètement refait, je viens de tester sur un grand écran, à priori, c'est beaucoup mieux
-meilleure gestion des exceptions, avec affichage de messages d'erreurs
-ajout d'un "logger" qui enregistre toutes les exceptions dans un fichier de log
-possibilité de ne pas mettre le "http://" dans l'écran de connexion
-gestion de transformations d'images dans le navigateur d'images : "flip" horizontal et vertical, rotations
-menu dans le navigateur d'images, qui permet d'effectuer toutes les actions, avec en plus, la possibilité d'imprimer une image

en cours d'implémentation : gestion des préférences de l'utilisateur. Actuellement, le fichier xml permettant d'écrire les préférences est géré,
il reste à faire un écran de gestion des préférences, avec un maximum d'options, afin que l'appli soit configurable.

File size: 6.4 KB
Line 
1package fr.mael.jiwigo.ui.comments;
2
3import java.awt.BorderLayout;
4import java.awt.Color;
5import java.awt.Dimension;
6import java.awt.FlowLayout;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9import java.awt.Insets;
10import java.awt.event.ActionEvent;
11import java.awt.event.ActionListener;
12import java.io.IOException;
13import java.util.List;
14
15import javax.swing.JButton;
16import javax.swing.JDialog;
17import javax.swing.JFrame;
18import javax.swing.JOptionPane;
19import javax.swing.JPanel;
20import javax.swing.JScrollPane;
21import javax.swing.JTextArea;
22
23import fr.mael.jiwigo.Main;
24import fr.mael.jiwigo.om.Comment;
25import fr.mael.jiwigo.service.CommentService;
26import fr.mael.jiwigo.transverse.util.Messages;
27import fr.mael.jiwigo.transverse.util.Outil;
28
29/**
30   Copyright (c) 2010, Mael
31   All rights reserved.
32
33   Redistribution and use in source and binary forms, with or without
34   modification, are permitted provided that the following conditions are met:
35    * Redistributions of source code must retain the above copyright
36      notice, this list of conditions and the following disclaimer.
37    * Redistributions in binary form must reproduce the above copyright
38      notice, this list of conditions and the following disclaimer in the
39      documentation and/or other materials provided with the distribution.
40    * Neither the name of jiwigo nor the
41      names of its contributors may be used to endorse or promote products
42      derived from this software without specific prior written permission.
43
44   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
45   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
46   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
47   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
48   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
53   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54   
55 * @author mael
56 * dialog affichant les commentaires d'une image et permettant d'en ajouter un
57 */
58public class CommentsDialog extends JDialog implements ActionListener {
59    /**
60     * Logger
61     */
62    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
63            .getLog(CommentsDialog.class);
64    /**
65     * booleen permettant d'alterner les couleurs des commentaires
66     */
67    private boolean alternate = true;
68    /**
69     * area permettant d'écrire un nouveau commentaire
70     */
71    private JTextArea textArea = new JTextArea();
72    /**
73     * bouton d'envoi d'un commentaire
74     */
75    private JButton boutonEnvoyer = new JButton("Ok");
76
77    /**
78     * id de l'image
79     */
80    private Integer imageId;
81    /**
82     * panel qui permet de scroller sur les commentaires
83     */
84    private JPanel panelScrollCommentaires = new JPanel(new GridBagLayout());
85    /**
86     * panel qui permet d'ajouter un commentaire
87     */
88    private JPanel panelAjouterCommentaire = new JPanel(new FlowLayout());
89
90    /**
91     * Scrollpane qui permet de scroller sur l'area
92     */
93    private JScrollPane scrollPaneArea;
94    /**
95     * scrollpane qui permet de scroller sur les commentaires
96     */
97    private JScrollPane scrollPaneCommentaires;
98
99    /**
100     * Constructeur
101     * @param imageId id de l'image
102     */
103    public CommentsDialog(JFrame parent, Integer imageId) {
104        super(parent);
105        this.imageId = imageId;
106        this.setTitle(Messages.getMessage("commentaires"));
107
108        panelScrollCommentaires.setOpaque(true);
109        scrollPaneCommentaires = new JScrollPane(panelScrollCommentaires, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
110                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
111        scrollPaneArea = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
112                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
113        scrollPaneArea.setPreferredSize(new Dimension(400, 100));
114        scrollPaneCommentaires.setPreferredSize(new Dimension(700, 500));
115        rafraichir();
116        this.setSize(new Dimension(700, 700));
117        this.setLocationRelativeTo(null);
118        this.setVisible(true);
119
120    }
121
122    private void rafraichir() {
123        this.getContentPane().removeAll();
124        try {
125            List<Comment> commentsForImage = CommentService.getInstance().lister(imageId);
126            GridBagConstraints c = new GridBagConstraints();
127            c.insets = new Insets(3, 3, 3, 3);
128            c.gridx = 0;
129            c.gridy = 0;
130            //boucle sur tous les commentaires
131            for (Comment comment : commentsForImage) {
132                CommentPanel panel;
133                if (alternate) {
134                    panel = new CommentPanel(new Color(153, 204, 51), comment.getContent(), comment.getAuthor(),
135                            comment.getDate());
136                } else {
137                    panel = new CommentPanel(new Color(77, 204, 51), comment.getContent(), comment.getAuthor(), comment
138                            .getDate());
139                }
140                alternate = !alternate;
141                panelScrollCommentaires.add(panel, c);
142                c.gridy++;
143            }
144        } catch (Exception e) {
145            LOG.error(Outil.getStackTrace(e));
146            JOptionPane.showMessageDialog(null, Messages.getMessage("commentListingError"), Messages
147                    .getMessage("error"), JOptionPane.ERROR_MESSAGE);
148        }
149        panelAjouterCommentaire.add(scrollPaneArea);
150        boutonEnvoyer.addActionListener(this);
151        panelAjouterCommentaire.add(boutonEnvoyer);
152        this.getContentPane().setLayout(new BorderLayout());
153        this.getContentPane().add(scrollPaneCommentaires, BorderLayout.NORTH);
154        this.getContentPane().add(panelAjouterCommentaire, BorderLayout.CENTER);
155        this.getContentPane().repaint();
156        ((JPanel) this.getContentPane()).revalidate();
157    }
158
159    @Override
160    public void actionPerformed(ActionEvent arg0) {
161        String text = textArea.getText();
162        //on n'envoie pas de commentaire vide
163        if (text.equals("")) {
164            JOptionPane.showMessageDialog(null, Messages.getMessage("emptyCommentError"), Messages.getMessage("error"),
165                    JOptionPane.ERROR_MESSAGE);
166        } else {
167            boolean reussite = true;
168            try {
169                reussite = CommentService.getInstance().creer(text, this.imageId, Main.sessionManager.getLogin());
170            } catch (IOException e) {
171                reussite = false;
172                LOG.error(Outil.getStackTrace(e));
173            }
174            if (reussite) {
175                rafraichir();
176            } else {
177                JOptionPane.showMessageDialog(null, Messages.getMessage("addCommentError"), Messages
178                        .getMessage("error"), JOptionPane.ERROR_MESSAGE);
179            }
180        }
181
182    }
183}
Note: See TracBrowser for help on using the repository browser.