Source Code Cross Referenced for HtmlCalendar.java in  » J2EE » Sofia » com » salmonllc » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        //** Copyright Statement ***************************************************
0002:        //The Salmon Open Framework for Internet Applications (SOFIA)
0003:        // Copyright (C) 1999 - 2002, Salmon LLC
0004:        //
0005:        // This program is free software; you can redistribute it and/or
0006:        // modify it under the terms of the GNU General Public License version 2
0007:        // as published by the Free Software Foundation;
0008:        //
0009:        // This program is distributed in the hope that it will be useful,
0010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012:        // GNU General Public License for more details.
0013:        //
0014:        // You should have received a copy of the GNU General Public License
0015:        // along with this program; if not, write to the Free Software
0016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0017:        //
0018:        // For more information please visit http://www.salmonllc.com
0019:        //** End Copyright Statement ***************************************************
0020:        package com.salmonllc.html;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlCalendar.java $
0024:        //$Author: Dan $
0025:        //$Revision: 23 $
0026:        //$Modtime: 11/05/04 10:02a $
0027:        /////////////////////////
0028:
0029:        import com.salmonllc.html.events.*;
0030:        import com.salmonllc.jsp.JspController;
0031:        import com.salmonllc.properties.*;
0032:        import com.salmonllc.localizer.LanguagePreferences;
0033:        import com.salmonllc.localizer.LanguageResourceFinder;
0034:
0035:        import java.text.SimpleDateFormat;
0036:        import java.util.*;
0037:
0038:        /**
0039:         * This component will generate Html resembling a calendar. The user can page
0040:         * through months and select days.
0041:         */
0042:        public class HtmlCalendar extends HtmlComponent {
0043:
0044:            public static final int SIZE_LARGE = 1;
0045:            public static final int SIZE_SMALL = 2;
0046:
0047:            public static final int SIZE_PERCENT = 0;
0048:            public static final int SIZE_PIXELS = 1;
0049:
0050:            private String _headingBackgroundColor, _headingForegroundColor,
0051:                    _weekBackgroundColor, _weekForegroundColor,
0052:                    _dayBackgroundColor, _dayForegroundDeemphisis,
0053:                    _dayForegroundNormal, _dayForegroundCurrent, _fontFace;
0054:            private int _largeFontSize, _smallFontSize;
0055:            private int _currentMonth, _currentYear;
0056:            private int _displaySize = SIZE_LARGE;
0057:            private int _width = 1;
0058:            private int _sizeOption = SIZE_PERCENT;
0059:            private int _border = 0;
0060:            private int _firstDayofWeek = 0;
0061:
0062:            private String _dayLongNames[] = { "Sunday", "Monday", "Tuesday",
0063:                    "Wednesday", "Thursday", "Friday", "Saturday" };
0064:            private String _dayShortNames[] = { "Sun", "Mon", "Tue", "Wed",
0065:                    "Thu", "Fri", "Sat" };
0066:
0067:            private String _monthLongNames[] = { "January", "February",
0068:                    "March", "April", "May", "June", "July", "August",
0069:                    "September", "October", "November", "December" };
0070:            private String _monthShortNames[] = { "Jan", "Feb", "Mar", "Apr",
0071:                    "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };
0072:
0073:            private boolean _updateLocale = true;
0074:            private Vector _listeners;
0075:            private java.awt.AWTEvent _calEvent;
0076:
0077:            private Vector _dayHighlights = new Vector();
0078:            private int _nextDay = 0;
0079:            private String _theme = null;
0080:            boolean _scrollTo;
0081:            private String _headingStyleClass;
0082:            private String _weekStyleClass;
0083:            private String _dayNormalStyleClassName;
0084:            private String _dayDeemphisisClassName;
0085:            private String _dayCurrentStyleClassName;
0086:            private String[] _fontSizes = { "xx-small", "xx-small", "x-small",
0087:                    "small", "medium", "large", "larger", "x-large", "xx-large" };
0088:            private int _fontSizeUnit;
0089:
0090:            public static final int FONT_SIZE_RELATIVE = 0;
0091:            public static final int FONT_SIZE_IN_POINTS = 1;
0092:            public static final int FONT_SIZE_IN_PIXELS = 2;
0093:
0094:            /**
0095:             * Constructs a new HtmlCalendar
0096:             * 
0097:             * @param name
0098:             *            The name of the calendar in the page
0099:             * @param p
0100:             *            The page the calendar will be in
0101:             */
0102:            public HtmlCalendar(String name, HtmlPage p) {
0103:                this (name, null, p);
0104:            }
0105:
0106:            /**
0107:             * Constructs a new HtmlCalendar
0108:             * 
0109:             * @param name
0110:             *            The name of the calendar in the page
0111:             * @param theme
0112:             *            The theme to use for loading properties.
0113:             * @param p
0114:             *            The page the calendar will be in
0115:             */
0116:            public HtmlCalendar(String name, String theme, HtmlPage p) {
0117:                super (name, p);
0118:
0119:                GregorianCalendar currentDate = new GregorianCalendar();
0120:                _currentYear = currentDate.get(Calendar.YEAR);
0121:                _currentMonth = currentDate.get(Calendar.MONTH);
0122:
0123:                setTheme(theme);
0124:            }
0125:
0126:            /**
0127:             * This method adds a listener the will be notified when this component
0128:             * causes the page its in to be submitted.
0129:             */
0130:            public void addCalendarListener(CalendarListener l) {
0131:                if (_listeners == null)
0132:                    _listeners = new Vector();
0133:
0134:                for (int i = 0; i < _listeners.size(); i++) {
0135:                    if (((SubmitListener) _listeners.elementAt(i)) == l)
0136:                        return;
0137:                }
0138:
0139:                _listeners.addElement(l);
0140:            }
0141:
0142:            /**
0143:             * This method adds a new day to highlight in the calendar. That day will be
0144:             * displayed in the highlight font. Note: Month is 0 based, 0 = Jan, 1=Feb
0145:             * etc..
0146:             */
0147:            public void addDayHighlight(int year, int month, int day) {
0148:                GregorianCalendar g = new GregorianCalendar(year, month, day);
0149:                addDayHighlight(g);
0150:            }
0151:
0152:            /**
0153:             * This method adds a new day to highlight to the calendar. That day will be
0154:             * displayed in the highlight font.
0155:             */
0156:            public void addDayHighlight(java.sql.Date d) {
0157:                GregorianCalendar g = new GregorianCalendar();
0158:                g.setTime(d);
0159:                addDayHighlight(g);
0160:            }
0161:
0162:            /**
0163:             * This method adds a new day to highlight to the calendar.
0164:             */
0165:            public void addDayHighlight(GregorianCalendar g) {
0166:                int max = _dayHighlights.size();
0167:                GregorianCalendar g2 = null;
0168:                for (int i = 0; i < max; i++) {
0169:                    g2 = (GregorianCalendar) _dayHighlights.elementAt(i);
0170:                    if (g.equals(g2))
0171:                        return;
0172:                    else if (g2.after(g)) {
0173:                        _dayHighlights.insertElementAt(g, i);
0174:                        return;
0175:                    }
0176:                }
0177:
0178:                _dayHighlights.addElement(g);
0179:            }
0180:
0181:            /**
0182:             * This method clears out the list of days to highlight.
0183:             */
0184:            public void clearDayHighLights() {
0185:                _dayHighlights.removeAllElements();
0186:            }
0187:
0188:            /**
0189:             * This method was created in VisualAge.
0190:             * 
0191:             * @return boolean
0192:             * @param g
0193:             *            java.util.GregorianCalendar
0194:             */
0195:            private boolean dayHighlighted(GregorianCalendar g) {
0196:                GregorianCalendar g2 = null;
0197:                for (; _nextDay < _dayHighlights.size(); _nextDay++) {
0198:                    g2 = (GregorianCalendar) _dayHighlights.elementAt(_nextDay);
0199:                    if (g2.equals(g))
0200:                        return true;
0201:                    else if (g2.after(g))
0202:                        return false;
0203:                }
0204:                return false;
0205:            }
0206:
0207:            public boolean executeEvent(int type) throws Exception {
0208:                if (type != EVENT_SUBMIT)
0209:                    return true;
0210:                if (_listeners != null) {
0211:                    CalendarListener l = null;
0212:                    for (int i = 0; i < _listeners.size(); i++) {
0213:                        l = (CalendarListener) _listeners.elementAt(i);
0214:                        if (_calEvent instanceof  CalendarMonthChangeEvent) {
0215:                            if (!l
0216:                                    .monthChanged((CalendarMonthChangeEvent) _calEvent))
0217:                                return false;
0218:                        } else {
0219:                            l
0220:                                    .dateSelected((CalendarDateSelectedEvent) _calEvent);
0221:                        }
0222:                    }
0223:                }
0224:                if (_calEvent instanceof  CalendarMonthChangeEvent) {
0225:                    _currentMonth = ((CalendarMonthChangeEvent) _calEvent)
0226:                            .getNewMonth();
0227:                    _currentYear = ((CalendarMonthChangeEvent) _calEvent)
0228:                            .getNewYear();
0229:                }
0230:                return true;
0231:            }
0232:
0233:            public void generateHTML(java.io.PrintWriter p, int rowNo)
0234:                    throws Exception {
0235:                processLocaleInfo();
0236:                String days[] = _displaySize == SIZE_LARGE ? _dayLongNames
0237:                        : _dayShortNames;
0238:                String months[] = _displaySize == SIZE_LARGE ? _monthLongNames
0239:                        : _monthShortNames;
0240:                int sz = _displaySize == SIZE_LARGE ? _largeFontSize
0241:                        : _smallFontSize;
0242:                String size = "";
0243:                if (_fontSizeUnit == FONT_SIZE_IN_POINTS)
0244:                    size = sz + "pt";
0245:                else if (_fontSizeUnit == FONT_SIZE_IN_PIXELS)
0246:                    size = sz + "px";
0247:                else
0248:                    size = _fontSizes[sz];
0249:
0250:                //HiddenComponent & javascript
0251:                p.println("<INPUT TYPE=\"HIDDEN\" NAME=\"" + getFullName()
0252:                        + "\">");
0253:                p.println("<SCRIPT>");
0254:                p.println("  function " + getFullName()
0255:                        + "_changeMonth(months) {");
0256:                p.println(getFormString() + getFullName()
0257:                        + ".value='changeMonth:' + months;");
0258:                p.println(getFormString() + "submit();");
0259:                p.println(" }");
0260:                p.println("  function " + getFullName()
0261:                        + "_selectDate(day,year) {");
0262:                p.println(getFormString() + getFullName()
0263:                        + ".value='selectDate:' + day + '-' + year;");
0264:                p.println(getFormString() + "submit();");
0265:                p.println(" }");
0266:                p.println("</SCRIPT>");
0267:
0268:                p.println("<A NAME=\"" + getFullName() + "CalStart\"></a>");
0269:
0270:                //Table Heading
0271:                p.print("<TABLE BORDER=" + _border
0272:                        + " CELLSPACING=0 CELLPADDING=0 COLS=1 ");
0273:                if (_width > -1) {
0274:                    p.print("WIDTH=\"" + _width);
0275:                    if (_sizeOption == SIZE_PERCENT)
0276:                        p.print("%");
0277:                    p.print("\"");
0278:                }
0279:                p.println(">");
0280:
0281:                /*
0282:                 * String hFontStart = " <FONT"; if (_fontFace != null) hFontStart += "
0283:                 * FACE=\"" + _fontFace + "\""; hFontStart += " SIZE=\"" + size + "\"";
0284:                 * if (_headingForegroundColor != null) hFontStart += " COLOR=\"" +
0285:                 * _headingForegroundColor + "\""; hFontStart += "> <B>"; String
0286:                 * hFontEnd = " </B> </FONT>";
0287:                 */
0288:
0289:                String hFontStart = "<SPAN style=\"";
0290:                if (_fontFace != null)
0291:                    hFontStart += "font-family:" + _fontFace
0292:                            + ";text-decoration:none;font-size:" + size + ";";
0293:                if (_headingForegroundColor != null)
0294:                    hFontStart += "color:" + _headingForegroundColor + ";";
0295:                hFontStart += "\"><B>";
0296:                String hFontEnd = "</B></SPAN>";
0297:
0298:                p.print("<TR><TD>");
0299:
0300:                p
0301:                        .print("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 COLS=3 WIDTH=\"100%\"");
0302:                if (_headingBackgroundColor != null)
0303:                    p.print(" BGCOLOR=\"" + _headingBackgroundColor + "\"");
0304:                p.print("> <TR");
0305:                if (_headingStyleClass != null)
0306:                    p.print(" CLASS=\"" + _headingStyleClass + "\"");
0307:                p.println(">");
0308:
0309:                p.println("<TD WIDTH=\"20%\" ALIGN=\"LEFT\">");
0310:                p.println("<A HREF=\"javascript:" + getFullName()
0311:                        + "_changeMonth(-12);\">");
0312:                p.print(hFontStart + "&lt;&lt;" + hFontEnd);
0313:                p.println("</A>");
0314:                p.println("<A HREF=\"javascript:" + getFullName()
0315:                        + "_changeMonth(-1);\">");
0316:                p.print(hFontStart + "&lt;" + hFontEnd);
0317:                p.println("</A></TD>");
0318:
0319:                p.println("<TD ALIGN=\"CENTER\" WIDTH=\"00%\">" + hFontStart);
0320:                p.print(months[_currentMonth] + " " + _currentYear + hFontEnd
0321:                        + "</TD>");
0322:
0323:                p.println("<TD ALIGN=\"RIGHT\" WIDTH=\"20%\" >");
0324:                p.println("<A HREF=\"javascript:" + getFullName()
0325:                        + "_changeMonth(1);\">");
0326:                p.print(hFontStart + "&gt;" + hFontEnd);
0327:                p.println("</A>");
0328:                p.println("<A HREF=\"javascript:" + getFullName()
0329:                        + "_changeMonth(12);\">");
0330:                p.print(hFontStart + "&gt;&gt;" + hFontEnd);
0331:                p.println("</A>");
0332:
0333:                p.println("</TD>");
0334:                p.println("</TR></TABLE>");
0335:
0336:                //calendar
0337:                //weeks
0338:                p
0339:                        .print("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 COLS=7 WIDTH=\"100%\"");
0340:                p.println(">");
0341:
0342:                p.print("<TR");
0343:                if (_weekStyleClass != null)
0344:                    p.print(" CLASS=\"" + _weekStyleClass + "\"");
0345:                p.println(">");
0346:                int numDays = 0;
0347:                int i = getFirstDayOfWeek();
0348:                while (numDays < 7) {
0349:                    p.print("<TD ALIGN=\"CENTER\"");
0350:                    if (_weekBackgroundColor != null)
0351:                        p.print(" BGCOLOR=\"" + _weekBackgroundColor + "\"");
0352:                    p.print("><SPAN style=\"");
0353:                    if (_fontFace != null)
0354:                        p.print("font-family:" + _fontFace + ";font-size:"
0355:                                + size + ";");
0356:                    if (_weekForegroundColor != null)
0357:                        p.print("color:" + _headingForegroundColor + ";");
0358:                    p.print("\">");
0359:
0360:                    if (_displaySize == SIZE_SMALL)
0361:                        p.println("<B>");
0362:                    p.print(days[i]);
0363:                    if (_displaySize == SIZE_SMALL)
0364:                        p.println("</B>");
0365:                    p.println("</SPAN></TD>");
0366:                    if (i < 6)
0367:                        i++;
0368:                    else
0369:                        i = 0;
0370:                    numDays++;
0371:
0372:                }
0373:                p.println("</TR>");
0374:
0375:                //days
0376:                int subtract = getFirstDayOfWeek();
0377:                GregorianCalendar today = new GregorianCalendar();
0378:                GregorianCalendar date = getFirstDayOnCalendar();
0379:                date.add(Calendar.DATE, subtract);
0380:                _nextDay = 0;
0381:
0382:                for (i = 0; i < 6; i++) {
0383:                    p.println("<TR>");
0384:                    for (int j = 0; j < 7; j++) {
0385:                        p.print("<TD ALIGN=\"CENTER\"");
0386:
0387:                        if (_dayBackgroundColor != null)
0388:                            p.print(" BGCOLOR=\"" + _dayBackgroundColor + "\"");
0389:                        p.print(">");
0390:                        p.print("<A HREF=\"javascript:" + getFullName()
0391:                                + "_selectDate("
0392:                                + date.get(Calendar.DAY_OF_YEAR) + ","
0393:                                + date.get(Calendar.YEAR) + ");\">");
0394:
0395:                        p.print("<SPAN ");
0396:                        String fontStyle = " style=\"";
0397:                        if (_fontFace != null)
0398:                            fontStyle += "text-decoration:none;font-family:"
0399:                                    + _fontFace + ";font-size:" + size + ";";
0400:                        if (date.get(Calendar.DAY_OF_YEAR) == today
0401:                                .get(Calendar.DAY_OF_YEAR)
0402:                                && date.get(Calendar.YEAR) == today
0403:                                        .get(Calendar.YEAR)
0404:                                && _dayForegroundCurrent != null)
0405:                            fontStyle += "color:" + _dayForegroundCurrent + ";";
0406:                        else if (date.get(Calendar.MONTH) != _currentMonth
0407:                                && _dayForegroundDeemphisis != null)
0408:                            fontStyle += "color:" + _dayForegroundDeemphisis
0409:                                    + ";";
0410:                        else if (_dayForegroundNormal != null)
0411:                            fontStyle += "color:" + _dayForegroundNormal + ";";
0412:                        fontStyle += "\"";
0413:
0414:                        //p.print("<FONT");
0415:                        //if (_fontFace != null)
0416:                        //	p.print(" FACE=\"" + _fontFace + "\"");
0417:                        //p.print(" SIZE=\"" + size + "\"");
0418:                        //if (date.get(Calendar.DAY_OF_YEAR) ==
0419:                        // today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) ==
0420:                        // today.get(Calendar.YEAR) && _dayForegroundCurrent != null)
0421:                        //	p.print(" COLOR=\"" + _dayForegroundCurrent + "\"");
0422:                        //else if (date.get(Calendar.MONTH) != _currentMonth &&
0423:                        // _dayForegroundDeemphisis != null)
0424:                        //	p.print(" COLOR=\"" + _dayForegroundDeemphisis + "\"");
0425:                        //else if (_dayForegroundNormal != null)
0426:                        //	p.print(" COLOR=\"" + _dayForegroundNormal + "\"");
0427:                        //p.print(">");
0428:
0429:                        //String spanStart = "";
0430:                        //if (date.get(Calendar.DAY_OF_YEAR) ==
0431:                        // today.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) ==
0432:                        // today.get(Calendar.YEAR) && _dayCurrentStyleClassName !=
0433:                        // null)
0434:                        //	spanStart = "<SPAN CLASS=\"" + _dayCurrentStyleClassName +
0435:                        // "\">";
0436:                        //else if (date.get(Calendar.MONTH) != _currentMonth &&
0437:                        // _dayDeemphisisClassName != null)
0438:                        //	spanStart = "<SPAN CLASS=\"" + _dayDeemphisisClassName +
0439:                        // "\">";
0440:                        //else if (_dayNormalStyleClassName != null)
0441:                        //	spanStart = "<SPAN CLASS=\"" + _dayNormalStyleClassName +
0442:                        // "\">";
0443:                        //String spanEnd = (spanStart.length() == 0 ? "" : "</SPAN>");
0444:
0445:                        if (date.get(Calendar.DAY_OF_YEAR) == today
0446:                                .get(Calendar.DAY_OF_YEAR)
0447:                                && date.get(Calendar.YEAR) == today
0448:                                        .get(Calendar.YEAR)
0449:                                && _dayCurrentStyleClassName != null)
0450:                            p.print("class=\"" + _dayCurrentStyleClassName
0451:                                    + "\"");
0452:                        else if (date.get(Calendar.MONTH) != _currentMonth
0453:                                && _dayDeemphisisClassName != null)
0454:                            p
0455:                                    .print("class=\"" + _dayDeemphisisClassName
0456:                                            + "\"");
0457:                        else if (_dayNormalStyleClassName != null)
0458:                            p.print("class=\"" + _dayNormalStyleClassName
0459:                                    + "\"");
0460:                        else
0461:                            p.print(fontStyle);
0462:                        p.print(">");
0463:
0464:                        String boldStart = "";
0465:                        String boldEnd = "";
0466:                        if (dayHighlighted(date)) {
0467:                            boldStart = "<B>";
0468:                            boldEnd = "</B>";
0469:                        }
0470:
0471:                        p.print(boldStart + date.get(Calendar.DAY_OF_MONTH)
0472:                                + boldEnd);
0473:                        date.add(Calendar.DATE, 1);
0474:                        p.print("</SPAN></A></TD>");
0475:                    }
0476:                    p.println("</TR>");
0477:                }
0478:
0479:                //end of tables
0480:                p.println("</TABLE>");
0481:                p.println("</TD></TR></TABLE>");
0482:
0483:                if (_scrollTo) {
0484:                    //		getPage().scrollToItem(getFullName() + "CalStart");
0485:                    _scrollTo = false;
0486:                }
0487:
0488:            }
0489:
0490:            /**
0491:             * This method gets the border width of the calendar.
0492:             */
0493:            public int getBorder() {
0494:                return _border;
0495:            }
0496:
0497:            /**
0498:             * This method returns the current month displayed in the calendar.
0499:             */
0500:            public int getCalendarMonth() {
0501:                return _currentMonth;
0502:            }
0503:
0504:            /**
0505:             * This method returns the current year displayed in the calendar.
0506:             */
0507:            public int getCalendarYear() {
0508:                return _currentYear;
0509:            }
0510:
0511:            /**
0512:             * This method gets the background color for the days of the month.
0513:             */
0514:            public String getDayBackgroundColor() {
0515:                return _dayBackgroundColor;
0516:            }
0517:
0518:            /**
0519:             * This method gets the text color for the day that is today's date.
0520:             */
0521:            public String getDayForegroundCurrentColor() {
0522:                return _dayForegroundCurrent;
0523:            }
0524:
0525:            /**
0526:             * This method gets the text color for days on the calendar that aren't in
0527:             * the current month.
0528:             */
0529:            public String getDayForegroundDeemphisisColor() {
0530:                return _dayForegroundDeemphisis;
0531:            }
0532:
0533:            /**
0534:             * This method gets the text color for days on the calendar that are in the
0535:             * current month.
0536:             */
0537:            public String getDayForegroundNormalColor() {
0538:                return _dayForegroundNormal;
0539:            }
0540:
0541:            /**
0542:             * This returns the display size of the calendar. Valid options are
0543:             * SIZE_LARGE and SIZE_SMALL.
0544:             */
0545:            public int getDisplaySize() {
0546:                return _displaySize;
0547:            }
0548:
0549:            /**
0550:             * This method returns the first day displayed on the calendar.
0551:             * 
0552:             * @return java.util.GregorianCalendar
0553:             */
0554:            public GregorianCalendar getFirstDayOnCalendar() {
0555:
0556:                GregorianCalendar g = new GregorianCalendar(_currentYear,
0557:                        _currentMonth, 1);
0558:                int dow = g.get(Calendar.DAY_OF_WEEK);
0559:
0560:                if (dow != 1)
0561:                    g.add(Calendar.DATE, ((dow - 1) * -1));
0562:
0563:                return g;
0564:            }
0565:
0566:            /**
0567:             * This method gets the font face for everything in the calendar.
0568:             */
0569:            public String getFontFace() {
0570:                return _fontFace;
0571:            }
0572:
0573:            /**
0574:             * This method gets the font size used if the calender display size is
0575:             * SIZE_LARGE;
0576:             */
0577:            public int getFontSizeLarge() {
0578:                return _largeFontSize;
0579:            }
0580:
0581:            /**
0582:             * This method gets the font size used if the calender display size is
0583:             * SIZE_SMALL;
0584:             */
0585:            public int getFontSizeSmall() {
0586:                return _smallFontSize;
0587:            }
0588:
0589:            /**
0590:             * This method gets the background color for the calendar heading.
0591:             */
0592:            public String getHeadingBackgroundColor() {
0593:                return _headingBackgroundColor;
0594:            }
0595:
0596:            /**
0597:             * This method gets the text color for the calendar heading.
0598:             */
0599:            public String getHeadingForegroundColor() {
0600:                return _headingForegroundColor;
0601:            }
0602:
0603:            /**
0604:             * This method returns the last day displayed on the calendar.
0605:             */
0606:            public GregorianCalendar getLastDayOnCalendar() {
0607:                GregorianCalendar g = getFirstDayOnCalendar();
0608:                g.add(Calendar.DATE, 41);
0609:                return g;
0610:            }
0611:
0612:            /**
0613:             * This method returns the size option for the Calendar. Valid return values
0614:             * are SIZE_PIXELS or SIZE_PERCENT.
0615:             */
0616:            public int getSizeOption() {
0617:                return _sizeOption;
0618:            }
0619:
0620:            /**
0621:             * This method returns the property theme for the component.
0622:             */
0623:            public String getTheme() {
0624:                return _theme;
0625:            }
0626:
0627:            /**
0628:             * This method gets the background color for the days of the week headings.
0629:             */
0630:            public String getWeekBackgroundColor() {
0631:                return _weekBackgroundColor;
0632:            }
0633:
0634:            /**
0635:             * This method gets the text color for the days of the week headings.
0636:             */
0637:            public String getWeekForegroundColor() {
0638:                return _weekForegroundColor;
0639:            }
0640:
0641:            /**
0642:             * This method gets the width of the calendar.
0643:             */
0644:            public int getWidth() {
0645:                return _width;
0646:            }
0647:
0648:            /**
0649:             * This method should be implemented in any subclasses of this component
0650:             * interested in processing parameters from an html post operation. The
0651:             * component should interogate the HttpServletRequest for any parameters it
0652:             * is interested in and change its internal state to reflect the parms.
0653:             * 
0654:             * @return true if this component is the one that submitted the page and
0655:             *         false if not.
0656:             * @param parms
0657:             *            a HashTable containing all the parameters for the servlet.
0658:             */
0659:            public boolean processParms(Hashtable parms, int rowNo)
0660:                    throws Exception {
0661:
0662:                Object parm = parms.get(getFullName());
0663:                if (parm == null)
0664:                    return false;
0665:
0666:                String[] command = (String[]) parm;
0667:
0668:                if (command[0] == null || command[0].trim().equals(""))
0669:                    return false;
0670:
0671:                String st[] = getLookupComponent();
0672:                if (command[0].startsWith("changeMonth:")) {
0673:                    int monthInc = Integer.parseInt(command[0].substring(12));
0674:                    GregorianCalendar g = new GregorianCalendar(_currentYear,
0675:                            _currentMonth, 1);
0676:                    g.add(Calendar.MONTH, monthInc);
0677:                    CalendarMonthChangeEvent e = new CalendarMonthChangeEvent(
0678:                            this , _currentMonth, _currentYear, g
0679:                                    .get(Calendar.MONTH), g.get(Calendar.YEAR));
0680:                    _calEvent = e;
0681:                    if (st != null) {
0682:                        _scrollTo = true;
0683:                        getPage().scrollToItem(getFullName() + "CalStart");
0684:                    }
0685:                } else if (command[0].startsWith("selectDate:")) {
0686:                    String newDate = command[0].substring(11);
0687:                    int pos = newDate.indexOf("-");
0688:                    String day = newDate.substring(0, pos);
0689:                    String year = newDate.substring(pos + 1);
0690:
0691:                    int dayInt = Integer.parseInt(day);
0692:                    int yearInt = Integer.parseInt(year);
0693:
0694:                    GregorianCalendar g = new GregorianCalendar();
0695:                    g.set(Calendar.YEAR, yearInt);
0696:                    g.set(Calendar.DAY_OF_YEAR, dayInt);
0697:
0698:                    java.sql.Date d = new java.sql.Date(g.getTime().getTime());
0699:                    CalendarDateSelectedEvent e = new CalendarDateSelectedEvent(
0700:                            this , g, d);
0701:
0702:                    _calEvent = e;
0703:
0704:                    if (st == null) {
0705:                        _scrollTo = true;
0706:                        getPage().scrollToItem(getFullName() + "CalStart");
0707:                    } else {
0708:                        HtmlScriptGenerator gen = new HtmlScriptGenerator(
0709:                                getPage());
0710:                        String format = st[1];
0711:                        String dtString = null;
0712:                        if (format != null) {
0713:                            SimpleDateFormat df = new SimpleDateFormat(format);
0714:                            dtString = df.format(d);
0715:                        } else {
0716:                            dtString = d.toString();
0717:                        }
0718:                        getPage().writeScript(
0719:                                gen.generateReturnValueToLookupScript(dtString,
0720:                                        ""));
0721:                    }
0722:                }
0723:
0724:                return true;
0725:
0726:            }
0727:
0728:            /**
0729:             * This method removes a listener from the list that will be notified if
0730:             * this component causes the page to be submitted.
0731:             * 
0732:             * @param l
0733:             *            The listener to remove.
0734:             */
0735:            public void removeCalendarListener(CalendarListener l) {
0736:                if (_listeners == null)
0737:                    return;
0738:
0739:                for (int i = 0; i < _listeners.size(); i++) {
0740:                    if (((CalendarListener) _listeners.elementAt(i)) == l) {
0741:                        _listeners.removeElementAt(i);
0742:                        return;
0743:                    }
0744:                }
0745:            }
0746:
0747:            /**
0748:             * This method sets the border width of the calendar.
0749:             */
0750:            public void setBorder(int border) {
0751:                _border = border;
0752:            }
0753:
0754:            /**
0755:             * This method sets the current month displayed in the calendar.
0756:             */
0757:            public void setCalendarMonth(int month) {
0758:                _currentMonth = month;
0759:            }
0760:
0761:            /**
0762:             * This method sets the current year displayed in the calendar.
0763:             */
0764:            public void setCalendarYear(int year) {
0765:                _currentYear = year;
0766:            }
0767:
0768:            /**
0769:             * This method sets the background color for the days of the month.
0770:             */
0771:            public void setDayBackgroundColor(String color) {
0772:                _dayBackgroundColor = color;
0773:            }
0774:
0775:            /**
0776:             * This method sets the text color for day that is today's date.
0777:             */
0778:            public void setDayForegroundCurrentColor(String color) {
0779:                _dayForegroundCurrent = color;
0780:            }
0781:
0782:            /**
0783:             * This method sets the text color for days on the calendar that aren't in
0784:             * the current month.
0785:             */
0786:            public void setDayForegroundDeemphisisColor(String color) {
0787:                _dayForegroundDeemphisis = color;
0788:            }
0789:
0790:            /**
0791:             * This method sets the text color for days on the calendar that are in the
0792:             * current month.
0793:             */
0794:            public void setDayForegroundNormalColor(String color) {
0795:                _dayForegroundNormal = color;
0796:            }
0797:
0798:            /**
0799:             * This sets the display size of the calendar. Valid options are SIZE_LARGE
0800:             * and SIZE_SMALL.
0801:             */
0802:            public void setDisplaySize(int size) {
0803:                _displaySize = size;
0804:            }
0805:
0806:            /**
0807:             * This method sets the font face for all text in the calendar.
0808:             */
0809:            public void setFontFace(String face) {
0810:                _fontFace = face;
0811:            }
0812:
0813:            /**
0814:             * This method sets the font size used if the calender display size is
0815:             * SIZE_LARGE;
0816:             */
0817:            public void setFontSizeLarge(int size) {
0818:                _largeFontSize = size;
0819:
0820:            }
0821:
0822:            /**
0823:             * This method sets the font size used if the calender display size is
0824:             * SIZE_SMALL;
0825:             */
0826:            public void setFontSizeSmall(int size) {
0827:                _smallFontSize = size;
0828:
0829:            }
0830:
0831:            /**
0832:             * This method sets the background color for the calendar heading.
0833:             */
0834:            public void setHeadingBackgroundColor(String color) {
0835:                _headingBackgroundColor = color;
0836:            }
0837:
0838:            /**
0839:             * This method sets the text color for the calendar heading.
0840:             */
0841:            public void setHeadingForegroundColor(String color) {
0842:                _headingForegroundColor = color;
0843:            }
0844:
0845:            /**
0846:             * This method sets the size option Calendar. Valid return values are
0847:             * SIZE_PIXELS or SIZE_PERCENT.
0848:             */
0849:            public void setSizeOption(int option) {
0850:                _sizeOption = option;
0851:            }
0852:
0853:            /**
0854:             * This method sets the property theme for the component.
0855:             * 
0856:             * @param theme
0857:             *            The theme to use.
0858:             */
0859:            public void setTheme(String theme) {
0860:
0861:                Props pr = getPage().getPageProperties();
0862:
0863:                _headingBackgroundColor = pr.getThemeProperty(theme,
0864:                        Props.CAL_HEADING_BACKGROUND_COLOR);
0865:                _headingForegroundColor = pr.getThemeProperty(theme,
0866:                        Props.CAL_HEADING_FOREGROUND_COLOR);
0867:                _weekBackgroundColor = pr.getThemeProperty(theme,
0868:                        Props.CAL_WEEK_BACKGROUND_COLOR);
0869:                _weekForegroundColor = pr.getThemeProperty(theme,
0870:                        Props.CAL_WEEK_FOREGROUND_COLOR);
0871:                _dayBackgroundColor = pr.getThemeProperty(theme,
0872:                        Props.CAL_DAY_BACKGROUND_COLOR);
0873:                _dayForegroundDeemphisis = pr.getThemeProperty(theme,
0874:                        Props.CAL_DAY_FOREGROUND_DEEMPHISIS);
0875:                _dayForegroundNormal = pr.getThemeProperty(theme,
0876:                        Props.CAL_DAY_FOREGROUND_NORMAL);
0877:                _dayForegroundCurrent = pr.getThemeProperty(theme,
0878:                        Props.CAL_DAY_FOREGROUND_CURRENT);
0879:                _fontFace = pr.getThemeProperty(theme, Props.CAL_FONT_FACE);
0880:
0881:                String ft = pr.getThemeProperty(theme, Props.CAL_FONT_LARGE);
0882:                if (ft != null) {
0883:                    if (ft.endsWith("pt")) {
0884:                        _fontSizeUnit = FONT_SIZE_IN_POINTS;
0885:                        _largeFontSize = Integer.parseInt(ft.substring(0, ft
0886:                                .length() - 2));
0887:                    } else if (ft.endsWith("px")) {
0888:                        _fontSizeUnit = FONT_SIZE_IN_PIXELS;
0889:                        _largeFontSize = Integer.parseInt(ft.substring(0, ft
0890:                                .length() - 2));
0891:                    } else {
0892:                        _largeFontSize = Integer.parseInt(ft);
0893:                    }
0894:                }
0895:
0896:                ft = pr.getThemeProperty(theme, Props.CAL_FONT_SMALL);
0897:                if (ft != null) {
0898:                    if (ft.endsWith("pt")) {
0899:                        _fontSizeUnit = FONT_SIZE_IN_POINTS;
0900:                        _smallFontSize = Integer.parseInt(ft.substring(0, ft
0901:                                .length() - 2));
0902:                    } else if (ft.endsWith("px")) {
0903:                        _fontSizeUnit = FONT_SIZE_IN_PIXELS;
0904:                        _smallFontSize = Integer.parseInt(ft.substring(0, ft
0905:                                .length() - 2));
0906:                    } else {
0907:                        _smallFontSize = Integer.parseInt(ft);
0908:                    }
0909:                }
0910:
0911:                _theme = theme;
0912:            }
0913:
0914:            /**
0915:             * This method sets the background color for the days of the week headings.
0916:             */
0917:            public void setWeekBackgroundColor(String color) {
0918:                _weekBackgroundColor = color;
0919:            }
0920:
0921:            /**
0922:             * This method sets the text color for the days of the week headings.
0923:             */
0924:            public void setWeekForegroundColor(String color) {
0925:                _weekForegroundColor = color;
0926:            }
0927:
0928:            /**
0929:             * This method sets the width of the calendar.
0930:             */
0931:            public void setWidth(int width) {
0932:                _width = width;
0933:            }
0934:
0935:            /**
0936:             * returns the short name for the month passed
0937:             */
0938:            public String getMonthShortName(int monthIndex) {
0939:                return _monthShortNames[monthIndex];
0940:            }
0941:
0942:            /**
0943:             * returns the long name for the month passed
0944:             */
0945:            public String getMonthLongName(int monthIndex) {
0946:                return _monthLongNames[monthIndex];
0947:            }
0948:
0949:            /**
0950:             * Sets the short name for the month number passed
0951:             */
0952:            public void setMonthShortName(int monthIndex, String val) {
0953:                _monthShortNames[monthIndex] = val;
0954:            }
0955:
0956:            /**
0957:             * Sets the long name for the month number passed
0958:             */
0959:            public void setMonthLongName(int monthIndex, String val) {
0960:                _monthLongNames[monthIndex] = val;
0961:            }
0962:
0963:            /**
0964:             * Set day long name for the day number passed
0965:             */
0966:            public void setDayLongName(int dayIndex, String val) {
0967:                _dayLongNames[dayIndex] = val;
0968:            }
0969:
0970:            /**
0971:             * Set day long name for the day number passed
0972:             */
0973:            public void setDayShortName(int dayIndex, String val) {
0974:                _dayShortNames[dayIndex] = val;
0975:            }
0976:
0977:            /**
0978:             * Updates the month and day names for the current language The language
0979:             * property file must have the following key structure
0980:             * HtmlCalendar.month.short.0 to HtmlCalendar.month.short.11 represents the
0981:             * month short names from jan to dec HtmlCalendar.month.long.0 to
0982:             * HtmlCalendar.month.long.11 represents the month long names from January
0983:             * to December HtmlCalendar.day.short.0 to HtmlCalendar.day.short.6
0984:             * represents the day short names from Sun to Sat HtmlCalendar.day.long.0 to
0985:             * HtmlCalendar.day.long.6 represents the day long names from Sunday to
0986:             * Saturday
0987:             */
0988:            public void updateLocale() {
0989:                _updateLocale = true;
0990:            }
0991:
0992:            private void processLocaleInfo() {
0993:                if (_updateLocale) {
0994:                    _updateLocale = false;
0995:                    LanguagePreferences p = getPage().getLanguagePreferences();
0996:                    String appName = getPage().getApplicationName();
0997:                    StringBuffer key = new StringBuffer(
0998:                            "HtmlCalendar.month.short.0");
0999:                    boolean shortOK = (LanguageResourceFinder.getResource(
1000:                            appName, key.toString(), p) != null);
1001:                    key.setLength(0);
1002:                    key.append("HtmlCalendar.month.long.0");
1003:                    boolean longOK = (LanguageResourceFinder.getResource(
1004:                            appName, key.toString(), p) != null);
1005:
1006:                    if (shortOK) {
1007:                        processLocaleArray(_monthShortNames,
1008:                                "HtmlCalendar.month.short.", appName, p, key);
1009:                        processLocaleArray(_dayShortNames,
1010:                                "HtmlCalendar.day.short.", appName, p, key);
1011:                    }
1012:
1013:                    if (longOK) {
1014:                        processLocaleArray(_monthLongNames,
1015:                                "HtmlCalendar.month.long.", appName, p, key);
1016:                        processLocaleArray(_dayLongNames,
1017:                                "HtmlCalendar.day.long.", appName, p, key);
1018:                    }
1019:                }
1020:            }
1021:
1022:            private void processLocaleArray(String[] ar, String key,
1023:                    String appName, LanguagePreferences p, StringBuffer sb) {
1024:                for (int i = 0; i < ar.length; i++) {
1025:                    sb.setLength(0);
1026:                    sb.append(key);
1027:                    sb.append(new Integer(i).toString());
1028:                    String val = LanguageResourceFinder.getResource(appName, sb
1029:                            .toString(), p);
1030:                    if (val != null)
1031:                        ar[i] = val;
1032:                }
1033:            }
1034:
1035:            /**
1036:             * @return
1037:             */
1038:            public String getHeadingStyleClassName() {
1039:                return _headingStyleClass;
1040:            }
1041:
1042:            /**
1043:             * @param string
1044:             */
1045:            public void setHeadingStyleClassName(String string) {
1046:                _headingStyleClass = string;
1047:            }
1048:
1049:            /**
1050:             * @return
1051:             */
1052:            public String getWeekStyleClassName() {
1053:                return _weekStyleClass;
1054:            }
1055:
1056:            /**
1057:             * @param string
1058:             */
1059:            public void setWeekStyleClassName(String string) {
1060:                _weekStyleClass = string;
1061:            }
1062:
1063:            /**
1064:             * @return
1065:             */
1066:            public String getDayCurrentStyleClassName() {
1067:                return _dayCurrentStyleClassName;
1068:            }
1069:
1070:            /**
1071:             * @return
1072:             */
1073:            public String getDayDeemphisisStyleClassName() {
1074:                return _dayDeemphisisClassName;
1075:            }
1076:
1077:            /**
1078:             * @return
1079:             */
1080:            public String getDayNormalStyleClassName() {
1081:                return _dayNormalStyleClassName;
1082:            }
1083:
1084:            /**
1085:             * @param string
1086:             */
1087:            public void setDayCurrentStyleClassName(String string) {
1088:                _dayCurrentStyleClassName = string;
1089:            }
1090:
1091:            /**
1092:             * @param string
1093:             */
1094:            public void setDayDeemphisisStyleClassName(String string) {
1095:                _dayDeemphisisClassName = string;
1096:            }
1097:
1098:            /**
1099:             * @param string
1100:             */
1101:            public void setDayNormalStyleClassName(String string) {
1102:                _dayNormalStyleClassName = string;
1103:            }
1104:
1105:            private String[] getLookupComponent() {
1106:                String lookupComponent = null;
1107:                String lookupFormat = null;
1108:                String formString = null;
1109:                String popup = null;
1110:                String callingController = getPage().getParameter(
1111:                        HtmlLookUpComponent.PARAM_LOOKUP_CONTROLLER);
1112:                if (callingController != null) {
1113:                    try {
1114:                        JspController this Cont = (JspController) getPage();
1115:                        JspController otherCont = (JspController) this Cont
1116:                                .getSession().getAttribute(callingController);
1117:                        if (otherCont != null) {
1118:                            HtmlLookUpComponent luComp = (HtmlLookUpComponent) otherCont
1119:                                    .getComponent(this Cont
1120:                                            .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_COMPONENT));
1121:                            String luName = luComp.getEditField().getFullName();
1122:                            int luRow = Integer
1123:                                    .parseInt(this Cont
1124:                                            .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_ROW));
1125:                            if (luRow > -1)
1126:                                luName += "_" + luRow;
1127:                            lookupComponent = luName;
1128:                            if (luComp.getUsePopup()) {
1129:                                popup = "win";
1130:                                if (luComp.getUseDiv())
1131:                                    popup = "div";
1132:                            }
1133:
1134:                            lookupFormat = luComp.getEditField()
1135:                                    .getDisplayFormat();
1136:                            formString = luComp.getEditField().getFormString();
1137:                        }
1138:                    } catch (Exception ex) {
1139:                    }
1140:                }
1141:                if (lookupComponent == null)
1142:                    return null;
1143:                String st[] = new String[4];
1144:                st[0] = lookupComponent;
1145:                st[1] = lookupFormat;
1146:                st[2] = formString;
1147:                st[3] = popup;
1148:                return st;
1149:            }
1150:
1151:            /**
1152:             * Valid values are FONT_SIZE_IN_POINTS,FONT_SIZE_IN_PIXELS,FONT_SIZE_RELATIVE
1153:             */
1154:            public int getFontSizeUnits() {
1155:                return _fontSizeUnit;
1156:            }
1157:
1158:            /**
1159:             * Valid values are FONT_SIZE_IN_POINTS,FONT_SIZE_IN_PIXELS,FONT_SIZE_RELATIVE
1160:             */
1161:            public void setFontSizeUnits(int i) {
1162:                _fontSizeUnit = i;
1163:            }
1164:
1165:            /**
1166:             * Returns the first day of the week displayed on the calendar (0=Sunday,1=Monday)
1167:             */
1168:            public int getFirstDayOfWeek() {
1169:                return (_firstDayofWeek);
1170:            }
1171:
1172:            /**
1173:             * Sets the first day of the week displayed on the calendar (0=Sunday,1=Monday)
1174:             */
1175:            public void setFirstDayOfWeek(int firstDayofWeek) {
1176:                if (firstDayofWeek >= 0 && _firstDayofWeek <= 1)
1177:                    _firstDayofWeek = firstDayofWeek;
1178:            }
1179:
1180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.