KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > gui > EventFrame


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
20 package org.lucane.applications.calendar.gui;
21
22 import javax.swing.*;
23 import java.awt.*;
24 import java.awt.event.*;
25
26 import org.lucane.client.Client;
27 import org.lucane.client.widgets.*;
28 import org.lucane.applications.calendar.*;
29 import org.lucane.applications.calendar.util.*;
30 import org.lucane.applications.calendar.Event;
31
32 public class EventFrame extends ManagedWindow
33 implements ActionListener
34 {
35     private transient CalendarPlugin plugin;
36     private Event event;
37     private DayPanel dayPanel;
38     private WeekPanel weekPanel;
39     private MonthPanel monthPanel;
40     
41     private JButton btnSave;
42     private JButton btnRemove;
43     private JButton btnClose;
44
45     private JButton btnAccept;
46     private JButton btnReject;
47     
48     private EventDescriptionPanel description;
49     private AttendeePanel attendees;
50         
51     public EventFrame(CalendarPlugin plugin, Event event, DayPanel day, WeekPanel week, MonthPanel month)
52     {
53         super(plugin, event.getTitle());
54         
55         this.plugin = plugin;
56         this.event = event;
57         this.dayPanel = day;
58         this.weekPanel = week;
59         this.monthPanel = month;
60         
61         
62         //-- panels
63
description = new EventDescriptionPanel(plugin, event);
64         attendees = new AttendeePanel(plugin, event, description);
65
66         //-- buttons
67
this.btnSave = new JButton(tr("btn.save"));
68         this.btnRemove = new JButton(tr("btn.remove"));
69         this.btnClose = new JButton(tr("btn.close"));
70         btnSave.addActionListener(this);
71         btnRemove.addActionListener(this);
72         btnClose.addActionListener(this);
73         
74         this.btnAccept = new JButton(tr("btn.accept"));
75         this.btnReject = new JButton(tr("btn.reject"));
76         btnAccept.setIcon(Client.getImageIcon("ok.png"));
77         btnReject.setIcon(Client.getImageIcon("cancel.png"));
78         btnAccept.addActionListener(this);
79         btnReject.addActionListener(this);
80                 
81         getContentPane().setLayout(new BorderLayout());
82         
83         //-- topbar
84
JPanel topbar = new JPanel(new BorderLayout());
85         initTopBar(topbar);
86         getContentPane().add(topbar, BorderLayout.NORTH);
87         
88         //-- tabbed pane
89
JTabbedPane tabs = new JTabbedPane();
90         tabs.add(tr("tab.description"), description);
91         tabs.add(tr("tab.attendees"), attendees);
92         //TODO uncomment this when ready
93
//tabs.add(tr("tab.resources"), new JPanel());
94
getContentPane().add(tabs, BorderLayout.CENTER);
95         
96         //-- save & close
97
JPanel buttonsContainer = new JPanel(new BorderLayout());
98         JPanel buttons = new JPanel(new GridLayout(1, 0));
99         String JavaDoc userName = Client.getInstance().getMyInfos().getName();
100         if(event.getOrganizer().equals(userName)
101                 || event.isEditable() && event.hasAttendee(userName))
102         {
103             buttons.add(btnSave);
104             buttons.add(btnRemove);
105         }
106         
107         buttons.add(btnClose);
108         buttonsContainer.add(buttons, BorderLayout.EAST);
109         getContentPane().add(buttonsContainer, BorderLayout.SOUTH);
110         
111         setPreferredSize(new Dimension(650, 500));
112     }
113     
114     private void initTopBar(JPanel bar)
115     {
116                 String JavaDoc userName = Client.getInstance().getMyInfos().getName();
117         String JavaDoc type = EventUtils.getUserType(userName, event);
118         bar.add(new JLabel(tr(type)), BorderLayout.WEST);
119
120         if(!type.equals("organizer") && !type.equals("external.viewer"))
121         {
122             JPanel buttons = new JPanel(new GridLayout(1, 2));
123             buttons.add(btnAccept);
124             buttons.add(btnReject);
125             bar.add(buttons, BorderLayout.EAST);
126             
127             Attendee a = event.getAttendee(userName);
128             btnAccept.setEnabled(a.getStatus() != Attendee.STATUS_ACCEPTED);
129             btnReject.setEnabled(a.getStatus() != Attendee.STATUS_REFUSED);
130         }
131     }
132
133     public void actionPerformed(ActionEvent ae)
134     {
135         //-- close & save
136
if(ae.getSource() == btnClose)
137             this.dispose();
138         else if(ae.getSource() == btnSave)
139         {
140             //TODO add resources to event
141
Event event = description.createEvent();
142             event.setAttendees(attendees.getAttendees());
143
144             try {
145                 plugin.storeEvent(event);
146                 DialogBox.info(tr("msg.eventStored"));
147                 this.dispose();
148             } catch(Exception JavaDoc e) {
149                 DialogBox.error(tr("err.unableToStoreEvent"));
150                 e.printStackTrace();
151             }
152             dayPanel.refreshView();
153             weekPanel.refreshView();
154             monthPanel.refreshView();
155         }
156         else if(ae.getSource() == btnRemove)
157         {
158             try {
159                 plugin.removeEvent(event);
160                 DialogBox.info(tr("msg.eventRemoved"));
161                 this.dispose();
162             } catch(Exception JavaDoc e) {
163                 DialogBox.error(tr("err.unableToRemoveEvent"));
164                 e.printStackTrace();
165             }
166             dayPanel.refreshView();
167             weekPanel.refreshView();
168             monthPanel.refreshView();
169         }
170         
171         //-- accept & refuse
172
else if(ae.getSource() == btnAccept || ae.getSource() == btnReject)
173         {
174             Attendee a = event.getAttendee(Client.getInstance().getMyInfos().getName());
175             if(ae.getSource() == btnAccept)
176                 a.setStatus(Attendee.STATUS_ACCEPTED);
177             else if(ae.getSource() == btnReject)
178                 a.setStatus(Attendee.STATUS_REFUSED);
179             
180             try {
181                 plugin.storeEvent(event);
182                 btnAccept.setEnabled(a.getStatus() != Attendee.STATUS_ACCEPTED);
183                 btnReject.setEnabled(a.getStatus() != Attendee.STATUS_REFUSED);
184                 attendees.refreshAttendees();
185                 DialogBox.info(tr("msg.statusChanged"));
186             } catch(Exception JavaDoc e) {
187                 DialogBox.error(tr("err.unableToChangeStatus"));
188                 e.printStackTrace();
189             }
190         }
191     }
192     
193     public String JavaDoc tr(String JavaDoc s)
194     {
195         return plugin.tr(s);
196     }
197 }
Popular Tags