1 package net.sf.tacos.components.timeline;
2
3 import java.util.Calendar;
4
5 import org.apache.tapestry.json.JSONObject;
6 import org.apache.tapestry.json.JSONLiteral;
7
8
9
10
11
12
13
14 public class TimelineEvent {
15 private Calendar start;
16 private Calendar end;
17 private String title;
18 private String link;
19 private String description;
20
21 public Calendar getStart() {
22 return start;
23 }
24
25
26
27
28
29
30 public void setStart(Calendar start) {
31 this.start = start;
32 fixDates();
33 }
34
35 public Calendar getEnd() {
36 return end;
37 }
38
39
40
41
42
43
44 public void setEnd(Calendar end) {
45 this.end = end;
46 fixDates();
47 }
48
49 public String getTitle() {
50 return title;
51 }
52
53 public void setTitle(String title) {
54 this.title = title;
55 }
56
57 public String getLink() {
58 return link;
59 }
60
61 public void setLink(String link) {
62 this.link = link;
63 }
64
65 public String getDescription() {
66 return description;
67 }
68
69 public void setDescription(String description) {
70 this.description = description;
71 }
72
73 private void fixDates() {
74 if (start!=null && end!=null && start.after(end)) {
75 Calendar temp = start;
76 start = end;
77 end = temp;
78 }
79 }
80
81 private JSONLiteral toDate(Calendar date) {
82 return new JSONLiteral("new Date(" + date.get(Calendar.YEAR)
83 + "," + date.get(Calendar.MONTH)
84 + "," + (date.get(Calendar.DAY_OF_MONTH) - 1)
85 + ")");
86 }
87
88 public JSONObject appendTo(JSONObject obj) {
89 JSONObject event = new JSONObject();
90 event.put("start", toDate(start));
91 if (end!=null) {
92 event.put("end", toDate(end));
93 }
94 event.put("title", title)
95 .put("link", link)
96 .put("description", (description==null) ? "" : description);
97
98 obj.accumulate("events", event);
99 return obj;
100 }
101 }