KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > forum > gui > MessageWindow


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.forum.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.GridLayout JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 import javax.swing.JButton JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JTextField JavaDoc;
30
31 import org.lucane.applications.forum.ForumPlugin;
32 import org.lucane.applications.forum.model.ForumMessage;
33 import org.lucane.client.Client;
34 import org.lucane.client.widgets.DialogBox;
35 import org.lucane.client.widgets.HTMLEditor;
36 import org.lucane.client.widgets.ManagedWindow;
37
38 public class MessageWindow extends ManagedWindow
39 implements ActionListener JavaDoc
40 {
41     private ForumPlugin plugin;
42     private MainWindow ui;
43     private String JavaDoc forum;
44     
45     private JTextField JavaDoc title;
46     private HTMLEditor content;
47     private JButton JavaDoc btnPost;
48     private JButton JavaDoc btnClose;
49     
50     private ForumMessage parent;
51     private boolean edit;
52     
53     public MessageWindow(ForumPlugin plugin, MainWindow ui, String JavaDoc forum, ForumMessage parent, boolean edit)
54     {
55         super(plugin, plugin.getTitle());
56         setName("messageWindow");
57         this.plugin = plugin;
58         this.ui = ui;
59         this.forum = forum;
60         
61         this.parent = parent;
62         this.edit = edit;
63         
64         title = new JTextField JavaDoc();
65         content = new HTMLEditor();
66         
67         btnPost = new JButton JavaDoc(plugin.tr("btn.post"), Client.getImageIcon("ok.png"));
68         btnPost.addActionListener(this);
69         btnClose = new JButton JavaDoc(plugin.tr("btn.close"), Client.getImageIcon("cancel.png"));
70         btnClose.addActionListener(this);
71         JPanel JavaDoc buttons = new JPanel JavaDoc(new BorderLayout JavaDoc());
72         JPanel JavaDoc container = new JPanel JavaDoc(new GridLayout JavaDoc(1, 2));
73         container.add(btnPost);
74         container.add(btnClose);
75         buttons.add(container, BorderLayout.EAST);
76         
77         
78         if(parent != null)
79             title.setText(parent.getTitle());
80         if(edit)
81             content.setText(parent.getContent());
82         
83         getContentPane().add(title, BorderLayout.NORTH);
84         getContentPane().add(content, BorderLayout.CENTER);
85         getContentPane().add(buttons, BorderLayout.SOUTH);
86         
87         setPreferredSize(new Dimension JavaDoc(600, 400));
88     }
89     
90     public ForumMessage createForumMessage()
91     {
92         if(edit)
93         {
94             return new ForumMessage(parent.getId(), parent.getIdRef(), title.getText(),
95                     parent.getDate(), parent.getAuthor(), content.getText(),
96                     parent.isVisible());
97         }
98         
99         int idRef = -1;
100         if(parent != null)
101             idRef = parent.getId();
102         
103         return new ForumMessage(idRef, title.getText(),
104                 Client.getInstance().getMyInfos().getName(),
105                 content.getText());
106     }
107     
108     public void actionPerformed(ActionEvent JavaDoc ae)
109     {
110         if(ae.getSource() == btnPost)
111         {
112             try {
113                 plugin.post(forum, createForumMessage());
114                 ui.updateMessages(plugin.getMessageList(ui.getForumList().getSelectedForum()));
115                 dispose();
116             } catch (Exception JavaDoc e) {
117                 DialogBox.error(plugin.tr("err.unableToPostMessage") + e);
118                 e.printStackTrace();
119             }
120         }
121         else if(ae.getSource() == btnClose)
122             dispose();
123     }
124 }
Popular Tags