1
2
3
4
5 package net.stff.ical.beans;
6
7 import java.util.Calendar;
8 import java.util.Collection;
9 import java.util.Date;
10 import java.util.Iterator;
11
12 import net.stff.ical.persistance.ICalDAO;
13 import net.stff.ical.util.Converters;
14
15
16 /***
17 * @author buntekuh
18 *
19 */
20 public class IEvent extends net.stff.ical.beans.VEvent{
21 private ICal calendar;
22 private String oldCalendar;
23 private boolean allDay;
24 private int duration= 0;
25
26 public IEvent(){
27 super();
28 allDay= (dtend == null);
29 }
30
31 public IEvent(CommBean vb, CalendarData data){
32 Date d= Converters.constructDate(vb.getDate());
33 Calendar cal= Calendar.getInstance();
34
35 cal.setTime(d);
36 cal.set(Calendar.HOUR_OF_DAY, 12);
37 setDtstart(cal.getTime());
38 cal.add(Calendar.HOUR_OF_DAY, 1);
39 setDtend(cal.getTime());
40
41 calendar= data.getCurrentICal();
42 allDay= (dtend == null);
43 }
44
45 public boolean startsWithin(Date s, Date e, int which){
46 if (which == ICalDAO.ALLDAYEVENTS){
47 if (this.dtend != null) return false;
48 }
49 else if (which == ICalDAO.TIMEDEVENTS){
50 if (this.dtend == null) return false;
51 }
52 Date sDate= dtstart.getTime();
53 if ((sDate.after(s)) && (sDate.before(e))) return true;
54 if (isRecurs()){
55 Calendar cal= Calendar.getInstance();
56 Collection c= recurrence.getRecurrentDates(this);
57 Iterator i = c.iterator();
58 while(i.hasNext()){
59 Date d= (Date)i.next();
60 cal.setTime(d);
61 cal.set(Calendar.HOUR_OF_DAY, dtstart.get(Calendar.HOUR_OF_DAY));
62 cal.set(Calendar.MINUTE, dtstart.get(Calendar.MINUTE));
63 d= cal.getTime();
64 if ((d.after(s)) && (d.before(e))){
65
66 return true;
67 }
68 }
69 }
70 return false;
71 }
72 /***
73 * @return Returns if the event lasts all day. It DOES last all day if Dtend is not set
74 */
75 public boolean isAllday() {
76 return allDay;
77 }
78 /***
79 * @param allday The allday to set.
80 */
81 public void setAllday(boolean allday) {
82 this.allDay= allday;
83 if (allday) setDtend((Date)null);
84 }
85
86 public void setDtend(Date dtend){
87 super.setDtend(dtend);
88 allDay= (dtend == null);
89 }
90 /***
91 * @return Returns the color.
92 */
93 public String getColor() {
94 return calendar.getColor();
95 }
96 /***
97 * @param color The color to set.
98 */
99 /***
100 * @return Returns the calendar.
101 */
102 public ICal getCalendar() {
103 return calendar;
104 }
105 /***
106 * @param calendar The calendar to set.
107 */
108 public void setCalendar(ICal calendar) {
109 this.calendar = calendar;
110 }
111 public String getOldCalendar() {
112 return oldCalendar;
113 }
114 /***
115 * @param oldCalendar The oldCalendar to set.
116 */
117 public void setOldCalendar(String oldCalendar) {
118 this.oldCalendar = oldCalendar;
119 }
120
121 public String getWeekdayAsString(){
122 int w= dtstart.get(Calendar.DAY_OF_WEEK);
123 switch (w){
124 case Calendar.MONDAY:
125 return "MO";
126 case Calendar.TUESDAY:
127 return "TU";
128 case Calendar.WEDNESDAY:
129 return "WE";
130 case Calendar.THURSDAY:
131 return "TH";
132 case Calendar.FRIDAY:
133 return "FR";
134 case Calendar.SATURDAY:
135 return "SA";
136 default:
137 return "SU";
138
139 }
140 }
141
142 public static Calendar getStartOfDay(Date d){
143 Calendar c= Calendar.getInstance();
144 c.setTime(d);
145 c.set(Calendar.HOUR_OF_DAY, 0);
146 c.set(Calendar.MINUTE, 0);
147 c.set(Calendar.SECOND, 0);
148 c.set(Calendar.MILLISECOND, 0);
149 return c;
150 }
151 /***
152 * @return Returns the duration.
153 */
154 public int getDuration() {
155 return duration;
156 }
157 /***
158 * @param duration The duration to set.
159 */
160 public void setDuration(int duration) {
161 this.duration = duration;
162 }
163 public void endure(){
164 duration++;
165 }
166 }