| 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 |
0 |
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 |
0 |
return start; |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
public void setStart(Calendar start) { |
| 31 |
0 |
this.start = start; |
| 32 |
0 |
fixDates(); |
| 33 |
0 |
} |
| 34 |
|
|
| 35 |
|
public Calendar getEnd() { |
| 36 |
0 |
return end; |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
public void setEnd(Calendar end) { |
| 45 |
0 |
this.end = end; |
| 46 |
0 |
fixDates(); |
| 47 |
0 |
} |
| 48 |
|
|
| 49 |
|
public String getTitle() { |
| 50 |
0 |
return title; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
public void setTitle(String title) { |
| 54 |
0 |
this.title = title; |
| 55 |
0 |
} |
| 56 |
|
|
| 57 |
|
public String getLink() { |
| 58 |
0 |
return link; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public void setLink(String link) { |
| 62 |
0 |
this.link = link; |
| 63 |
0 |
} |
| 64 |
|
|
| 65 |
|
public String getDescription() { |
| 66 |
0 |
return description; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
public void setDescription(String description) { |
| 70 |
0 |
this.description = description; |
| 71 |
0 |
} |
| 72 |
|
|
| 73 |
|
private void fixDates() { |
| 74 |
0 |
if (start!=null && end!=null && start.after(end)) { |
| 75 |
0 |
Calendar temp = start; |
| 76 |
0 |
start = end; |
| 77 |
0 |
end = temp; |
| 78 |
|
} |
| 79 |
0 |
} |
| 80 |
|
|
| 81 |
|
private JSONLiteral toDate(Calendar date) { |
| 82 |
0 |
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 |
0 |
JSONObject event = new JSONObject(); |
| 90 |
0 |
event.put("start", toDate(start)); |
| 91 |
0 |
if (end!=null) { |
| 92 |
0 |
event.put("end", toDate(end)); |
| 93 |
|
} |
| 94 |
0 |
event.put("title", title) |
| 95 |
|
.put("link", link) |
| 96 |
|
.put("description", (description==null) ? "" : description); |
| 97 |
|
|
| 98 |
0 |
obj.accumulate("events", event); |
| 99 |
0 |
return obj; |
| 100 |
|
} |
| 101 |
|
} |