001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package org.lucane.applications.calendar;
021:
022: import java.awt.*;
023: import java.io.*;
024: import java.util.*;
025:
026: import javax.swing.Icon;
027:
028: import org.lucane.applications.calendar.widget.*;
029: import org.lucane.client.PluginManager;
030:
031: public class Event implements Serializable, BasicEvent {
032: //-- recurrence
033: public static final int RECUR_NONE = 0;
034: public static final int RECUR_DAY = 1;
035: public static final int RECUR_WEEK = 2;
036: public static final int RECUR_MONTH = 3;
037: public static final int RECUR_YEAR = 4;
038:
039: //-- attributes
040: private int id;
041: private String title;
042: private String organizer;
043: private boolean isPublic;
044: private boolean isEditable;
045: private Date start;
046: private Date end;
047: private int recurrence;
048: private String description;
049:
050: private String type;
051: private int colorRed;
052: private int colorGreen;
053: private int colorBlue;
054: private String iconFile;
055:
056: private ArrayList attendees;
057: private ArrayList resources;
058:
059: /**
060: * Constructor
061: */
062: public Event(int id, String type, String title, String organizer,
063: boolean isPublic, boolean isEditable, long start, long end,
064: int recurence, String description) {
065: this .id = id;
066: this .type = type;
067: this .title = title;
068: this .organizer = organizer;
069: this .isPublic = isPublic;
070: this .isEditable = isEditable;
071: this .start = new Date(start);
072: this .end = new Date(end);
073: this .recurrence = recurence;
074: this .description = description;
075: this .attendees = new ArrayList();
076: this .resources = new ArrayList();
077: this .colorRed = 30;
078: this .colorGreen = 30;
079: this .colorBlue = 200;
080: this .iconFile = "default.png";
081: }
082:
083: //-- setters
084: public void setId(int id) {
085: this .id = id;
086: }
087:
088: public void setAttendees(ArrayList attendees) {
089: this .attendees = attendees;
090: }
091:
092: public void addAttendee(String user, boolean mandatory, int status) {
093: this .attendees.add(new Attendee(user, mandatory, status));
094: }
095:
096: public Attendee getAttendee(String user) {
097: Iterator i = getAttendees();
098: while (i.hasNext()) {
099: Attendee a = (Attendee) i.next();
100: if (a.getUser().equals(user))
101: return a;
102: }
103:
104: return null;
105: }
106:
107: public void removeAttendee(String user) {
108: attendees.remove(getAttendee(user));
109: }
110:
111: public boolean hasAttendee(String user) {
112: return getAttendee(user) != null;
113: }
114:
115: public void setResources(ArrayList resources) {
116: this .resources = resources;
117: }
118:
119: public void addResource(String resource) {
120: this .resources.add(resource);
121: }
122:
123: public void setStartDate(Date start) {
124: this .start = start;
125: }
126:
127: public void setEndDate(Date end) {
128: this .end = end;
129: }
130:
131: public void setColor(Color color) {
132: this .colorRed = color.getRed();
133: this .colorGreen = color.getGreen();
134: this .colorBlue = color.getBlue();
135: }
136:
137: public void setColor(int r, int g, int b) {
138: this .colorRed = r;
139: this .colorGreen = g;
140: this .colorBlue = b;
141: }
142:
143: public int getColorRed() {
144: return colorRed;
145: }
146:
147: public int getColorGreen() {
148: return colorGreen;
149: }
150:
151: public int getColorBlue() {
152: return colorBlue;
153: }
154:
155: //-- getters
156: public int getId() {
157: return this .id;
158: }
159:
160: public String getType() {
161: return this .type;
162: }
163:
164: public String getOrganizer() {
165: return this .organizer;
166: }
167:
168: public boolean isPublic() {
169: return this .isPublic;
170: }
171:
172: public boolean isEditable() {
173: return this .isEditable;
174: }
175:
176: public int getRecurrence() {
177: return this .recurrence;
178: }
179:
180: public String getDescription() {
181: return this .description;
182: }
183:
184: public Iterator getAttendees() {
185: return this .attendees.iterator();
186: }
187:
188: public ArrayList getAttendeeList() {
189: return this .attendees;
190: }
191:
192: public Iterator getResources() {
193: return this .resources.iterator();
194: }
195:
196: public ArrayList getResourceList() {
197: return this .resources;
198: }
199:
200: //-- getters for BasicEvent
201:
202: public String getTitle() {
203: return title;
204: }
205:
206: public Date getStartDate() {
207: return this .start;
208: }
209:
210: public Date getEndDate() {
211: return this .end;
212: }
213:
214: public int getStartHour() {
215: Calendar c = Calendar.getInstance();
216: c.setTime(start);
217: return c.get(Calendar.HOUR_OF_DAY);
218: }
219:
220: public int getStartMinute() {
221: Calendar c = Calendar.getInstance();
222: c.setTime(start);
223: return c.get(Calendar.MINUTE);
224: }
225:
226: public int getEndHour() {
227: Calendar c = Calendar.getInstance();
228: c.setTime(end);
229: return c.get(Calendar.HOUR_OF_DAY);
230: }
231:
232: public int getEndMinute() {
233: Calendar c = Calendar.getInstance();
234: c.setTime(end);
235: return c.get(Calendar.MINUTE);
236: }
237:
238: public boolean isMultiDay() {
239: Calendar start = Calendar.getInstance();
240: start.setTime(this .start);
241: Calendar end = Calendar.getInstance();
242: end.setTime(this .end);
243:
244: return end.get(Calendar.YEAR) > start.get(Calendar.YEAR)
245: || end.get(Calendar.DAY_OF_YEAR) > start
246: .get(Calendar.DAY_OF_YEAR);
247: }
248:
249: public Color getColor() {
250: return new Color(colorRed, colorGreen, colorBlue);
251: }
252:
253: public void setIconFile(String s) {
254: this .iconFile = s;
255: }
256:
257: public String getIconFile() {
258: return this .iconFile;
259: }
260:
261: public Icon getIcon() {
262: return PluginManager.getInstance().getPlugin(
263: "org.lucane.applications.calendar").getImageIcon(
264: "types/" + iconFile);
265: }
266:
267: public boolean equals(Object o) {
268: if (!(o instanceof Event))
269: return false;
270:
271: return ((Event) o).getId() == getId();
272: }
273:
274: public String toString() {
275: return "[" + id + ": " + title + "]";
276: }
277: }
|