KickJava   Java API By Example, From Geeks To Geeks.

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


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.event.ActionEvent JavaDoc;
22 import java.awt.event.ActionListener JavaDoc;
23
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
26 import javax.swing.tree.TreePath JavaDoc;
27
28 import org.lucane.applications.forum.ForumPlugin;
29 import org.lucane.applications.forum.model.ForumMessage;
30 import org.lucane.client.widgets.DialogBox;
31
32 public class ButtonActionListener implements ActionListener JavaDoc
33 {
34     private ForumPlugin plugin;
35     private MainWindow ui;
36     
37     public ButtonActionListener(ForumPlugin plugin, MainWindow ui)
38     {
39         this.plugin = plugin;
40         this.ui = ui;
41     }
42     
43     public void actionPerformed(ActionEvent JavaDoc ae)
44     {
45         JButton JavaDoc source = (JButton JavaDoc)ae.getSource();
46         String JavaDoc forum = ui.getForumList().getSelectedForum().getName();
47         
48         if(source.getName().equals("mainWindow.btnRefresh"))
49         {
50             try {
51                 ui.getMessages().setCellRenderer(new MessageRenderer(plugin, forum));
52                 ui.updateMessages(plugin.getMessageList(ui.getForumList().getSelectedForum()));
53                 plugin.updateLastRefreshTime(forum);
54             } catch (Exception JavaDoc e) {
55                 DialogBox.error(plugin.tr("err.unableToRefresh") + e);
56                 e.printStackTrace();
57             }
58         }
59         else if(source.getName().equals("mainWindow.btnNewMessage"))
60         {
61             ui.showMessageWindow(plugin, forum, null, false);
62         }
63         else if(source.getName().equals("mainWindow.btnReply"))
64         {
65             TreePath JavaDoc selection = ui.getMessages().getSelectionPath();
66             DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)selection.getLastPathComponent();
67             ui.showMessageWindow(plugin, forum, (ForumMessage)node.getUserObject(), false);
68         }
69         else if(source.getName().equals("mainWindow.btnEdit"))
70         {
71             TreePath JavaDoc selection = ui.getMessages().getSelectionPath();
72             DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)selection.getLastPathComponent();
73             try {
74                 ForumMessage message = plugin.getMessageContent(forum, (ForumMessage)node.getUserObject());
75                 ui.showMessageWindow(plugin, forum, message, true);
76             } catch(Exception JavaDoc e) {
77                 DialogBox.error(plugin.tr("err.unableToRead") + e);
78                 e.printStackTrace();
79             }
80         }
81         else if(source.getName().equals("mainWindow.btnToggleVisible"))
82         {
83             TreePath JavaDoc selection = ui.getMessages().getSelectionPath();
84             DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc)selection.getLastPathComponent();
85             try {
86                 ForumMessage message = plugin.getMessageContent(forum, (ForumMessage)node.getUserObject());
87                 message.setVisible(!message.isVisible());
88                 plugin.post(forum, message);
89                 ui.updateMessages(plugin.getMessageList(ui.getForumList().getSelectedForum()));
90             } catch(Exception JavaDoc e) {
91                 DialogBox.error(plugin.tr("err.unableToToggleVisible") + e);
92                 e.printStackTrace();
93             }
94         }
95     }
96 }
Popular Tags