001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.activity;
018:
019: import java.util.Calendar;
020:
021: /**
022: * DOCUMENT ME!
023: *
024: */
025: public class CalendarView {
026: public static final int MONTH_VIEW = 0;
027: public static final int DAY_VIEW = 0;
028: public static final int WEEK_VIEW = 0;
029: private static final int currentMonth = Calendar.getInstance().get(
030: Calendar.MONTH) + 1;
031: private static final int currentYear = Calendar.getInstance().get(
032: Calendar.YEAR);
033: private static final int currentDay = Calendar.getInstance().get(
034: Calendar.DAY_OF_MONTH);
035:
036: public CalendarView() {
037: }
038:
039: /**
040: * DOCUMENT ME!
041: *
042: * @return
043: */
044: public static String getCalendar() {
045: return "";
046: }
047:
048: /**
049: * DOCUMENT ME!
050: *
051: * @param year
052: * @param month
053: * @param day
054: * @param destURL
055: *
056: * @return
057: */
058: public static String getSmallMonthCalendarHTML(int year, int month,
059: int day, String destURL) {
060: Calendar calendar = CalendarUtil.getCalendar(year, month, 1);
061: int firstDay = calendar.get(Calendar.DAY_OF_WEEK);
062: int rows;
063:
064: if (((CalendarUtil.daysInMonth[month] == 31) && (firstDay >= 6))
065: || ((CalendarUtil.daysInMonth[month] == 30) && (firstDay == 7))) {
066: rows = 6;
067: } else if ((CalendarUtil.daysInMonth[month] == 28)
068: && (firstDay == 1)) {
069: rows = 4;
070: } else {
071: rows = 5;
072: }
073:
074: StringBuffer returnString = new StringBuffer();
075: returnString
076: .append("<table class=\"tabularSectionTitleTable\" width=\"100%\">\n");
077: returnString.append(" <tr>\n");
078: returnString.append(" <td>\n");
079: returnString
080: .append(" " + smallMonthHeader(year, month) + "\n");
081: returnString.append(" </td>\n");
082: returnString.append(" </tr>\n");
083: returnString.append("</table>\n");
084: returnString
085: .append("<table class=\"tabularSectionDisplayTable\" width=\"100%\">\n");
086:
087: //style=\"border: 0.02cm solid black; border-collapse: collapse; table-layout: fixed; \" border=\"0\"
088: returnString.append(" <tr class=\"tabularSectionLabel\">\n");
089:
090: for (int i = 0; i < 7; i++) {
091: returnString.append(" <td>\n");
092: returnString.append(" "
093: + CalendarUtil.dayLabel[i].substring(0, 2) + "\n");
094: returnString.append(" </td>\n");
095: }
096:
097: returnString.append(" </tr>\n");
098:
099: int dayCounter = 1;
100: int loopCounter = 1;
101: String dayDetail = "";
102:
103: for (int j = 1; j <= rows; j++) {
104: returnString.append(" <tr>\n");
105:
106: for (int i = 1; i < 8; i++) {
107: returnString
108: .append(" <td class=\"tabularSectionField\"");
109:
110: // if it is a valid day of the month
111: if ((loopCounter >= firstDay)
112: && (dayCounter <= CalendarUtil.daysInMonth[month])) {
113: // if the counter is on today
114: if ((dayCounter == currentDay)
115: && (month == currentMonth)
116: && (year == currentYear)) {
117: returnString.append(" bgcolor=\"#C0C0C0\"");
118: }
119:
120: returnString.append(">\n");
121:
122: // See if this is the currently selected day.
123: if ((dayCounter == day) && (month == currentMonth)
124: && (year == currentYear)) {
125: returnString.append("<B>");
126: }
127:
128: returnString
129: .append(" <a href=\"/sfa/control/frontpage?action=day&day="
130: + dayCounter
131: + "&month="
132: + month
133: + "&year="
134: + year
135: + " \">\n");
136: returnString.append(" " + dayCounter + "\n");
137: returnString.append(" </a>\n");
138:
139: if ((dayCounter == day) && (month == currentMonth)
140: && (year == currentYear)) {
141: returnString.append("</B>");
142: }
143:
144: returnString.append(" <br>\n");
145: dayCounter++;
146: } else {
147: // not a valid day, make a blank cell
148: returnString.append(">\n");
149: returnString.append(" \n");
150: }
151:
152: returnString.append(" </td>\n");
153: loopCounter++;
154: }
155:
156: // returnString.append("<td align=\"center\"><div class=\"tabletext\"><a href=\"/sfa/control/activityCalendar?action=week&day=" + (dayCounter-1) + "&month=" + month + "&year=" + year + "\" >w<br>e<br>e<br>k</a></div></td>");
157: returnString.append(" </tr>\n");
158: }
159:
160: returnString.append("</table>");
161:
162: return returnString.toString();
163: }
164:
165: /**
166: * DOCUMENT ME!
167: *
168: * @param year
169: * @param month
170: *
171: * @return
172: */
173: private static String monthHeader(int year, int month) {
174: StringBuffer returnString = new StringBuffer();
175:
176: if (month == Calendar.FEBRUARY) {
177: CalendarUtil.daysInMonth[2] = (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0))) ? 29
178: : 28;
179: }
180:
181: returnString
182: .append("<a href=\"/sfa/control/activityCalendar?action=month&month="
183: + ((month != 1) ? (month - 1) : 12)
184: + "&year="
185: + ((month != 1) ? year : (year - 1))
186: + " \"><</a> ");
187: returnString.append(CalendarUtil.monthLabel[month]);
188: returnString.append(" ");
189: returnString.append(year);
190: returnString
191: .append(" <a href=\"/sfa/control/activityCalendar?action=month&month="
192: + ((month != 12) ? (month + 1) : 1)
193: + "&year="
194: + ((month != 12) ? year : (year + 1))
195: + " \">></a> ");
196:
197: return returnString.toString();
198: }
199:
200: /**
201: * DOCUMENT ME!
202: *
203: * @param year
204: * @param month
205: *
206: * @return
207: */
208: private static String smallMonthHeader(int year, int month) {
209: StringBuffer returnString = new StringBuffer();
210:
211: if (month == Calendar.FEBRUARY) {
212: CalendarUtil.daysInMonth[2] = (((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0))) ? 29
213: : 28;
214: }
215:
216: returnString
217: .append(" <a class=\"tabularSectionAnchorSelected\" href=\"/sfa/control/frontpage?action=month&month="
218: + ((month != 1) ? (month - 1) : 12)
219: + "&year="
220: + ((month != 1) ? year : (year - 1)) + " \">\n");
221: returnString.append(" <<\n");
222: returnString.append(" </a>\n");
223: returnString.append(" \n");
224: returnString.append(CalendarUtil.monthLabel[month]);
225: returnString.append(" ");
226: returnString.append(year);
227: returnString.append(" ");
228: returnString
229: .append(" <a class=\"tabularSectionAnchorSelected\" href=\"/sfa/control/frontpage?action=month&month="
230: + ((month != 12) ? (month + 1) : 1)
231: + "&year="
232: + ((month != 12) ? year : (year + 1))
233: + " \">\n");
234: returnString.append(" >>\n");
235: returnString.append(" </a>\n");
236: returnString.append(" \n");
237:
238: return returnString.toString();
239: }
240: }
|