/** * This method should be implemented in any subclasses of this component interested in processing * parameters from an html post operation. The component should interogate the HttpServletRequest * for any parameters it is interested in and change its internal state to reflect the parms. * * @return true if this component is the one that submitted the page and false if not. * @param parms a HashTable containing all the parameters for the servlet. */ public boolean processParms(Hashtable parms, int rowNo) throws Exception { Object parm = parms.get(getFullName()); if (parm == null) return false; String[] command = (String[]) parm; if (command[0] == null || command[0].trim().equals("")) return false; String st[] = getLookupComponent(); if (command[0].startsWith("changeMonth:")) { int monthInc = Integer.parseInt(command[0].substring(12)); GregorianCalendar g = new GregorianCalendar(_currentYear, _currentMonth, 1); g.add(Calendar.MONTH, monthInc); CalendarMonthChangeEvent e = new CalendarMonthChangeEvent( this, _currentMonth, _currentYear, g.get(Calendar.MONTH), g.get(Calendar.YEAR)); _calEvent = e; if (st != null) { _scrollTo = true; getPage().scrollToItem(getFullName() + "CalStart"); } } else if (command[0].startsWith("selectDate:")) { String newDate = command[0].substring(11); int pos = newDate.indexOf("-"); String day = newDate.substring(0, pos); String year = newDate.substring(pos + 1); int dayInt = Integer.parseInt(day); int yearInt = Integer.parseInt(year); GregorianCalendar g = new GregorianCalendar(); g.set(Calendar.YEAR, yearInt); g.set(Calendar.DAY_OF_YEAR, dayInt); java.sql.Date d = new java.sql.Date(g.getTime().getTime()); CalendarDateSelectedEvent e = new CalendarDateSelectedEvent(this, g, d); _calEvent = e; if (st == null) { _scrollTo = true; getPage().scrollToItem(getFullName() + "CalStart"); } else { HtmlScriptGenerator gen = new HtmlScriptGenerator(getPage()); String format = st[1]; String dtString = null; if (format != null) { SimpleDateFormat df = new SimpleDateFormat(format); dtString = df.format(d); } else { dtString = d.toString(); } getPage().writeScript(gen.generateReturnValueToLookupScript(dtString, "")); } } return true; }
/** * This method returns the first day displayed on the calendar. * * @return java.util.GregorianCalendar */ public GregorianCalendar getFirstDayOnCalendar() { GregorianCalendar g = new GregorianCalendar(_currentYear, _currentMonth, 1); int dow = g.get(Calendar.DAY_OF_WEEK); if (dow != 1) g.add(Calendar.DATE, ((dow - 1) * -1)); return g; }
/** This method returns the last day displayed on the calendar. */ public GregorianCalendar getLastDayOnCalendar() { GregorianCalendar g = getFirstDayOnCalendar(); g.add(Calendar.DATE, 41); return g; }
public void generateHTML(java.io.PrintWriter p, int rowNo) throws Exception { processLocaleInfo(); String days[] = _displaySize == SIZE_LARGE ? _dayLongNames : _dayShortNames; String months[] = _displaySize == SIZE_LARGE ? _monthLongNames : _monthShortNames; int sz = _displaySize == SIZE_LARGE ? _largeFontSize : _smallFontSize; String size = ""; if (_fontSizeUnit == FONT_SIZE_IN_POINTS) size = sz + "pt"; else if (_fontSizeUnit == FONT_SIZE_IN_PIXELS) size = sz + "px"; else size = _fontSizes[sz]; // HiddenComponent & javascript p.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + getFullName() + "\">"); p.println("<SCRIPT>"); p.println(" function " + getFullName() + "_changeMonth(months) {"); p.println(getFormString() + getFullName() + ".value='changeMonth:' + months;"); p.println(getFormString() + "submit();"); p.println(" }"); p.println(" function " + getFullName() + "_selectDate(day,year) {"); p.println(getFormString() + getFullName() + ".value='selectDate:' + day + '-' + year;"); p.println(getFormString() + "submit();"); p.println(" }"); p.println("</SCRIPT>"); p.println("<A NAME=\"" + getFullName() + "CalStart\"></a>"); // Table Heading p.print("<TABLE BORDER=" + _border + " CELLSPACING=0 CELLPADDING=0 COLS=1 "); if (_width > -1) { p.print("WIDTH=\"" + _width); if (_sizeOption == SIZE_PERCENT) p.print("%"); p.print("\""); } p.println(">"); /* * String hFontStart = " <FONT"; if (_fontFace != null) hFontStart += " * FACE=\"" + _fontFace + "\""; hFontStart += " SIZE=\"" + size + "\""; * if (_headingForegroundColor != null) hFontStart += " COLOR=\"" + * _headingForegroundColor + "\""; hFontStart += "> <B>"; String * hFontEnd = " </B> </FONT>"; */ String hFontStart = "<SPAN style=\""; if (_fontFace != null) hFontStart += "font-family:" + _fontFace + ";text-decoration:none;font-size:" + size + ";"; if (_headingForegroundColor != null) hFontStart += "color:" + _headingForegroundColor + ";"; hFontStart += "\"><B>"; String hFontEnd = "</B></SPAN>"; p.print("<TR><TD>"); p.print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 COLS=3 WIDTH=\"100%\""); if (_headingBackgroundColor != null) p.print(" BGCOLOR=\"" + _headingBackgroundColor + "\""); p.print("> <TR"); if (_headingStyleClass != null) p.print(" CLASS=\"" + _headingStyleClass + "\""); p.println(">"); p.println("<TD WIDTH=\"20%\" ALIGN=\"LEFT\">"); p.println("<A HREF=\"javascript:" + getFullName() + "_changeMonth(-12);\">"); p.print(hFontStart + "<<" + hFontEnd); p.println("</A>"); p.println("<A HREF=\"javascript:" + getFullName() + "_changeMonth(-1);\">"); p.print(hFontStart + "<" + hFontEnd); p.println("</A></TD>"); p.println("<TD ALIGN=\"CENTER\" WIDTH=\"00%\">" + hFontStart); p.print(months[_currentMonth] + " " + _currentYear + hFontEnd + "</TD>"); p.println("<TD ALIGN=\"RIGHT\" WIDTH=\"20%\" >"); p.println("<A HREF=\"javascript:" + getFullName() + "_changeMonth(1);\">"); p.print(hFontStart + ">" + hFontEnd); p.println("</A>"); p.println("<A HREF=\"javascript:" + getFullName() + "_changeMonth(12);\">"); p.print(hFontStart + ">>" + hFontEnd); p.println("</A>"); p.println("</TD>"); p.println("</TR></TABLE>"); // calendar // weeks p.print("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 COLS=7 WIDTH=\"100%\""); p.println(">"); p.print("<TR"); if (_weekStyleClass != null) p.print(" CLASS=\"" + _weekStyleClass + "\""); p.println(">"); int numDays = 0; int i = getFirstDayOfWeek(); while (numDays < 7) { p.print("<TD ALIGN=\"CENTER\""); if (_weekBackgroundColor != null) p.print(" BGCOLOR=\"" + _weekBackgroundColor + "\""); p.print("><SPAN style=\""); if (_fontFace != null) p.print("font-family:" + _fontFace + ";font-size:" + size + ";"); if (_weekForegroundColor != null) p.print("color:" + _headingForegroundColor + ";"); p.print("\">"); if (_displaySize == SIZE_SMALL) p.println("<B>"); p.print(days[i]); if (_displaySize == SIZE_SMALL) p.println("</B>"); p.println("</SPAN></TD>"); if (i < 6) i++; else i = 0; numDays++; } p.println("</TR>"); // days int subtract = getFirstDayOfWeek(); GregorianCalendar today = new GregorianCalendar(); GregorianCalendar date = getFirstDayOnCalendar(); date.add(Calendar.DATE, subtract); _nextDay = 0; for (i = 0; i < 6; i++) { p.println("<TR>"); for (int j = 0; j < 7; j++) { p.print("<TD ALIGN=\"CENTER\""); if (_dayBackgroundColor != null) p.print(" BGCOLOR=\"" + _dayBackgroundColor + "\""); p.print(">"); p.print( "<A HREF=\"javascript:" + getFullName() + "_selectDate(" + date.get(Calendar.DAY_OF_YEAR) + "," + date.get(Calendar.YEAR) + ");\">"); p.print("<SPAN "); String fontStyle = " style=\""; if (_fontFace != null) fontStyle += "text-decoration:none;font-family:" + _fontFace + ";font-size:" + size + ";"; if (date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == today.get(Calendar.YEAR) && _dayForegroundCurrent != null) fontStyle += "color:" + _dayForegroundCurrent + ";"; else if (date.get(Calendar.MONTH) != _currentMonth && _dayForegroundDeemphisis != null) fontStyle += "color:" + _dayForegroundDeemphisis + ";"; else if (_dayForegroundNormal != null) fontStyle += "color:" + _dayForegroundNormal + ";"; fontStyle += "\""; // p.print("<FONT"); // if (_fontFace != null) // p.print(" FACE=\"" + _fontFace + "\""); // p.print(" SIZE=\"" + size + "\""); // if (date.get(Calendar.DAY_OF_YEAR) == // today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == // today.get(Calendar.YEAR) && _dayForegroundCurrent != null) // p.print(" COLOR=\"" + _dayForegroundCurrent + "\""); // else if (date.get(Calendar.MONTH) != _currentMonth && // _dayForegroundDeemphisis != null) // p.print(" COLOR=\"" + _dayForegroundDeemphisis + "\""); // else if (_dayForegroundNormal != null) // p.print(" COLOR=\"" + _dayForegroundNormal + "\""); // p.print(">"); // String spanStart = ""; // if (date.get(Calendar.DAY_OF_YEAR) == // today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == // today.get(Calendar.YEAR) && _dayCurrentStyleClassName != // null) // spanStart = "<SPAN CLASS=\"" + _dayCurrentStyleClassName + // "\">"; // else if (date.get(Calendar.MONTH) != _currentMonth && // _dayDeemphisisClassName != null) // spanStart = "<SPAN CLASS=\"" + _dayDeemphisisClassName + // "\">"; // else if (_dayNormalStyleClassName != null) // spanStart = "<SPAN CLASS=\"" + _dayNormalStyleClassName + // "\">"; // String spanEnd = (spanStart.length() == 0 ? "" : "</SPAN>"); if (date.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == today.get(Calendar.YEAR) && _dayCurrentStyleClassName != null) p.print("class=\"" + _dayCurrentStyleClassName + "\""); else if (date.get(Calendar.MONTH) != _currentMonth && _dayDeemphisisClassName != null) p.print("class=\"" + _dayDeemphisisClassName + "\""); else if (_dayNormalStyleClassName != null) p.print("class=\"" + _dayNormalStyleClassName + "\""); else p.print(fontStyle); p.print(">"); String boldStart = ""; String boldEnd = ""; if (dayHighlighted(date)) { boldStart = "<B>"; boldEnd = "</B>"; } p.print(boldStart + date.get(Calendar.DAY_OF_MONTH) + boldEnd); date.add(Calendar.DATE, 1); p.print("</SPAN></A></TD>"); } p.println("</TR>"); } // end of tables p.println("</TABLE>"); p.println("</TD></TR></TABLE>"); if (_scrollTo) { // getPage().scrollToItem(getFullName() + "CalStart"); _scrollTo = false; } }