001: package org.zkforge.timeline.data;
002:
003: import java.util.Date;
004:
005: import org.zkforge.json.simple.JSONObject;
006: import org.zkforge.timeline.util.TimelineUtil;
007:
008: public class OccurEvent implements Comparable {
009: private static int count = 0;
010:
011: // @Override
012: public String toString() {
013: // TODO Auto-generated method stub
014: JSONObject json = new JSONObject();
015: json.put("id", new Integer(_id));
016: if (_start != null)
017: json.put("start", TimelineUtil.formatDateTime(_start));
018: if (_end != null)
019: json.put("end", TimelineUtil.formatDateTime(_end));
020: if (_latestStart != null)
021: json.put("latestStart", TimelineUtil
022: .formatDateTime(_latestStart));
023: if (_earliestEnd != null)
024: json.put("earliestEnd", TimelineUtil
025: .formatDateTime(_earliestEnd));
026: json.put("duration", Boolean.valueOf(_duration));
027: if (_text != null)
028: json.put("text", _text);
029: if (_description != null)
030: json.put("description", _description);
031: if (_imageUrl != null)
032: json.put("image", _imageUrl);
033: if (_linkUrl != null)
034: json.put("link", _linkUrl);
035: if (_iconUrl != null)
036: json.put("icon", _iconUrl);
037: if (_wikiUrl != null)
038: json.put("wikiUrl", _wikiUrl);
039: if (_wikiSection != null)
040: json.put("wikiSection", _wikiSection);
041:
042: if (_color != null)
043: json.put("color", _color);
044: if (_textColor != null)
045: json.put("textColor", _textColor);
046: return json.toString();
047: }
048:
049: private Date _start = new Date();
050:
051: private Date _end = null;
052:
053: private Date _latestStart = null;
054:
055: private Date _earliestEnd = null;
056:
057: private String _text = "";
058:
059: private String _description = "";
060:
061: private String _imageUrl = "";
062:
063: private String _linkUrl = "";
064:
065: private String _iconUrl = "";
066:
067: private String _wikiUrl = null;
068:
069: private String _wikiSection = null;
070:
071: private boolean _duration = true;
072:
073: private String _color = null;
074:
075: private String _textColor = null;
076:
077: private int _id = count++;
078:
079: public String getColor() {
080: return _color;
081: }
082:
083: public void setColor(String color) {
084: this ._color = color;
085: }
086:
087: public String getDescription() {
088: return _description;
089: }
090:
091: public void setDescription(String description) {
092: this ._description = description;
093: }
094:
095: public boolean isDuration() {
096: return _duration;
097: }
098:
099: public void setDuration(boolean duration) {
100: this ._duration = duration;
101: }
102:
103: public Date getEarliestEnd() {
104: return _earliestEnd;
105: }
106:
107: public void setEarliestEnd(Date earliestEnd) {
108: this ._earliestEnd = earliestEnd;
109: }
110:
111: public Date getEnd() {
112: return _end;
113: }
114:
115: public void setEnd(Date end) {
116: this ._end = end;
117: }
118:
119: public String getImageUrl() {
120: return _imageUrl;
121: }
122:
123: public void setImageUrl(String imageUrl) {
124: this ._imageUrl = imageUrl;
125: }
126:
127: public Date getLatestStart() {
128: return _latestStart;
129: }
130:
131: public void setLatestStart(Date latestStart) {
132: this ._latestStart = latestStart;
133: }
134:
135: public String getLinkUrl() {
136: return _linkUrl;
137: }
138:
139: public void setLinkUrl(String linkUrl) {
140: this ._linkUrl = linkUrl;
141: }
142:
143: public Date getStart() {
144: return _start;
145: }
146:
147: public void setStart(Date start) {
148: this ._start = start;
149: }
150:
151: public String getText() {
152: return _text;
153: }
154:
155: public void setText(String text) {
156: this ._text = text;
157: }
158:
159: public String getTextColor() {
160: return _textColor;
161: }
162:
163: public void setTextColor(String textColor) {
164: this ._textColor = textColor;
165: }
166:
167: public String getWikiUrl() {
168: return _wikiUrl;
169: }
170:
171: public void setWikiUrl(String wikiUrl) {
172: this ._wikiUrl = wikiUrl;
173: }
174:
175: public String getIconUrl() {
176: return _iconUrl;
177: }
178:
179: public void setIconUrl(String iconUrl) {
180: this ._iconUrl = iconUrl;
181: }
182:
183: public String getId() {
184: return String.valueOf(_id);
185: }
186:
187: public int compareTo(Object target) {
188: // TODO Auto-generated method stub
189: // System.out.println(this);
190: // System.out.println(target);
191: int ret;
192: if (target == null)
193: ret = 1;
194: else {
195: OccurEvent evt = (OccurEvent) target;
196: int sc;// result of start date to compare
197: int ec;// result of end date to compare
198: if (getStart() == null && evt.getStart() != null)
199: sc = -1;
200: else if (getStart() != null && evt.getStart() == null)
201: sc = 1;
202: else if (getStart() == null && evt.getStart() == null)
203: sc = 0;
204: else
205: sc = getStart().compareTo(evt.getStart());
206:
207: if (getEnd() == null && evt.getEnd() != null)
208: ec = -1;
209: else if (getEnd() == null && evt.getEnd() == null)
210: ec = 0;
211: else if (getEnd() != null && evt.getEnd() == null)
212: ec = 1;
213: else
214: ec = getEnd().compareTo(evt.getEnd());
215:
216: if ((sc < 0) || (sc == 0 && ec < 0))
217: ret = -1;
218: else if ((sc > 0) || (sc == 0 && ec > 0))
219: ret = 1;
220: else
221: ret = 0;
222: }
223: // System.out.println(ret);
224: return ret;
225: }
226:
227: /**
228: * @return the _wikiSection
229: */
230: public String getWikiSection() {
231: return _wikiSection;
232: }
233:
234: /**
235: * @param wikiSection
236: * the _wikiSection to set
237: */
238: public void setWikiSection(String wikiSection) {
239: _wikiSection = wikiSection;
240: }
241: }
|