KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > Event


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 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;
21
22 import java.awt.*;
23 import java.io.*;
24 import java.util.*;
25
26 import javax.swing.Icon JavaDoc;
27
28 import org.lucane.applications.calendar.widget.*;
29 import org.lucane.client.PluginManager;
30
31 public class Event implements Serializable, BasicEvent
32 {
33     //-- recurrence
34
public static final int RECUR_NONE = 0;
35     public static final int RECUR_DAY = 1;
36     public static final int RECUR_WEEK = 2;
37     public static final int RECUR_MONTH = 3;
38     public static final int RECUR_YEAR = 4;
39     
40     //-- attributes
41
private int id;
42     private String JavaDoc title;
43     private String JavaDoc organizer;
44     private boolean isPublic;
45     private boolean isEditable;
46     private Date start;
47     private Date end;
48     private int recurrence;
49     private String JavaDoc description;
50     
51     private String JavaDoc type;
52     private int colorRed;
53     private int colorGreen;
54     private int colorBlue;
55     private String JavaDoc iconFile;
56
57     
58     private ArrayList attendees;
59     private ArrayList resources;
60     
61     /**
62      * Constructor
63      */

64     public Event(int id, String JavaDoc type, String JavaDoc title, String JavaDoc organizer,
65             boolean isPublic, boolean isEditable,
66             long start, long end, int recurence, String JavaDoc description)
67     {
68         this.id = id;
69         this.type = type;
70         this.title = title;
71         this.organizer = organizer;
72         this.isPublic = isPublic;
73         this.isEditable = isEditable;
74         this.start = new Date(start);
75         this.end = new Date(end);
76         this.recurrence = recurence;
77         this.description = description;
78         this.attendees = new ArrayList();
79         this.resources = new ArrayList();
80         this.colorRed = 30;
81         this.colorGreen = 30;
82         this.colorBlue = 200;
83         this.iconFile = "default.png";
84     }
85     
86     //-- setters
87
public void setId(int id)
88     {
89         this.id = id;
90     }
91     
92     public void setAttendees(ArrayList attendees)
93     {
94         this.attendees = attendees;
95     }
96     
97     public void addAttendee(String JavaDoc user, boolean mandatory, int status)
98     {
99         this.attendees.add(new Attendee(user, mandatory, status));
100     }
101     
102     public Attendee getAttendee(String JavaDoc user)
103     {
104         Iterator i = getAttendees();
105         while(i.hasNext())
106         {
107             Attendee a = (Attendee)i.next();
108             if(a.getUser().equals(user))
109                 return a;
110         }
111         
112         return null;
113     }
114     
115     public void removeAttendee(String JavaDoc user)
116     {
117         attendees.remove(getAttendee(user));
118     }
119     
120     public boolean hasAttendee(String JavaDoc user)
121     {
122         return getAttendee(user) != null;
123     }
124
125     public void setResources(ArrayList resources)
126     {
127         this.resources = resources;
128     }
129     
130     public void addResource(String JavaDoc resource)
131     {
132         this.resources.add(resource);
133     }
134     
135     public void setStartDate(Date start)
136     {
137         this.start = start;
138     }
139     
140     public void setEndDate(Date end)
141     {
142         this.end = end;
143     }
144     
145     public void setColor(Color color)
146     {
147         this.colorRed = color.getRed();
148         this.colorGreen = color.getGreen();
149         this.colorBlue = color.getBlue();
150     }
151     
152     public void setColor(int r, int g, int b)
153     {
154         this.colorRed = r;
155         this.colorGreen = g;
156         this.colorBlue = b;
157     }
158
159     public int getColorRed()
160     {
161         return colorRed;
162     }
163
164     public int getColorGreen()
165     {
166         return colorGreen;
167     }
168     
169     public int getColorBlue()
170     {
171         return colorBlue;
172     }
173     
174     //-- getters
175
public int getId()
176     {
177         return this.id;
178     }
179     
180     public String JavaDoc getType()
181     {
182         return this.type;
183     }
184     
185     public String JavaDoc getOrganizer()
186     {
187         return this.organizer;
188     }
189     
190     public boolean isPublic()
191     {
192         return this.isPublic;
193     }
194
195     public boolean isEditable()
196     {
197         return this.isEditable;
198     }
199     
200     public int getRecurrence()
201     {
202         return this.recurrence;
203     }
204     
205     public String JavaDoc getDescription()
206     {
207         return this.description;
208     }
209     
210     public Iterator getAttendees()
211     {
212         return this.attendees.iterator();
213     }
214     
215     public ArrayList getAttendeeList()
216     {
217         return this.attendees;
218     }
219     
220     public Iterator getResources()
221     {
222         return this.resources.iterator();
223     }
224     
225     public ArrayList getResourceList()
226     {
227         return this.resources;
228     }
229     
230     //-- getters for BasicEvent
231

232     public String JavaDoc getTitle()
233     {
234         return title;
235     }
236     
237     public Date getStartDate()
238     {
239         return this.start;
240     }
241     
242     public Date getEndDate()
243     {
244         return this.end;
245     }
246     
247     public int getStartHour()
248     {
249         Calendar c = Calendar.getInstance();
250         c.setTime(start);
251         return c.get(Calendar.HOUR_OF_DAY);
252     }
253
254     public int getStartMinute()
255     {
256         Calendar c = Calendar.getInstance();
257         c.setTime(start);
258         return c.get(Calendar.MINUTE);
259     }
260     
261     public int getEndHour()
262     {
263         Calendar c = Calendar.getInstance();
264         c.setTime(end);
265         return c.get(Calendar.HOUR_OF_DAY);
266     }
267
268     public int getEndMinute()
269     {
270         Calendar c = Calendar.getInstance();
271         c.setTime(end);
272         return c.get(Calendar.MINUTE);
273     }
274     
275     public boolean isMultiDay()
276     {
277         Calendar start = Calendar.getInstance();
278         start.setTime(this.start);
279         Calendar end = Calendar.getInstance();
280         end.setTime(this.end);
281         
282         return end.get(Calendar.YEAR) > start.get(Calendar.YEAR)
283             || end.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR);
284     }
285     
286     public Color getColor()
287     {
288         return new Color(colorRed, colorGreen, colorBlue);
289     }
290     
291     public void setIconFile(String JavaDoc s)
292     {
293         this.iconFile = s;
294     }
295     
296     public String JavaDoc getIconFile()
297     {
298         return this.iconFile;
299     }
300     
301     public Icon JavaDoc getIcon()
302     {
303         return PluginManager.getInstance().getPlugin("org.lucane.applications.calendar").
304             getImageIcon("types/" + iconFile);
305     }
306     
307     public boolean equals(Object JavaDoc o)
308     {
309         if(! (o instanceof Event))
310             return false;
311         
312         return ((Event)o).getId() == getId();
313     }
314     
315     public String JavaDoc toString()
316     {
317         return "[" + id + ": " + title +"]";
318     }
319 }
320
Popular Tags