Source Code Cross Referenced for CalendarMonth.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » rave » web » ui » component » 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 » IDE Netbeans » visualweb.api.designer » com.sun.rave.web.ui.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package com.sun.rave.web.ui.component;
042:
043:        import java.io.Serializable;
044:        import java.text.DateFormat;
045:        import java.text.SimpleDateFormat;
046:        import java.util.Calendar;
047:        import java.util.Date;
048:        import java.util.Iterator;
049:        import java.util.Locale;
050:        import java.util.TimeZone;
051:
052:        import javax.faces.context.FacesContext;
053:        import javax.faces.component.UIComponent;
054:        import javax.faces.component.NamingContainer;
055:        import javax.faces.convert.IntegerConverter;
056:        import javax.faces.event.ActionEvent;
057:        import javax.faces.event.ActionListener;
058:        import javax.faces.event.ValueChangeEvent;
059:        import javax.faces.event.ValueChangeListener;
060:
061:        import com.sun.rave.web.ui.theme.Theme;
062:        import com.sun.rave.web.ui.theme.ThemeImages;
063:        import com.sun.rave.web.ui.model.Option;
064:        import com.sun.rave.web.ui.model.ScheduledEvent;
065:        import com.sun.rave.web.ui.util.ThemeUtilities;
066:
067:        /**
068:         * <p><strong>This class needs to be rewritten. Do not release as API.</strong></p>
069:         */
070:
071:        public class CalendarMonth extends CalendarMonthBase implements 
072:                NamingContainer {
073:
074:            public static final String MONTH_MENU_ID = "monthMenu";
075:            public static final String YEAR_MENU_ID = "yearMenu";
076:            public static final String PREVIOUS_MONTH_LINK_ID = "previousMonthLink";
077:            public static final String NEXT_MONTH_LINK_ID = "nextMonthLink";
078:            public static final String DATE_LINK_ID = "dateLink";
079:            public static final String DATE_FIELD_ID = "dateField";
080:            public static final String DATE_FORMAT_ATTR = "dateFormatAttr";
081:            public static final String DATE_FORMAT_PATTERN_ATTR = "dateFormatPatternAttr";
082:            private static final String TIME_ZONE_ATTR = "timeZoneAttr";
083:
084:            /**
085:             * <p>The java.util.Calendar object to use for this CalendarMonth component.</p>
086:             */
087:            protected java.util.Calendar calendar = null;
088:
089:            private static final boolean DEBUG = false;
090:
091:            public boolean isDateSelected(java.util.Calendar current,
092:                    java.util.Calendar endDate) {
093:
094:                if (DEBUG)
095:                    log("isDateSelected()");
096:
097:                Object value = getValue();
098:                if (value == null) {
099:                    if (DEBUG)
100:                        log("Value is null");
101:                    return false;
102:                } else if (value instanceof  Date) {
103:                    if (DEBUG)
104:                        log("Value is date");
105:                    Calendar calendar = getCalendar();
106:                    calendar.setTime((Date) value);
107:                    return compareDate(calendar, current);
108:                } else if (value instanceof  ScheduledEvent) {
109:                    if (DEBUG)
110:                        log("Value is ScheduledEvent");
111:                    if (DEBUG)
112:                        log("Checking dates before "
113:                                + endDate.getTime().toString());
114:                    Iterator dates = ((ScheduledEvent) value).getDates(endDate);
115:                    Calendar calendar = null;
116:
117:                    while (dates.hasNext()) {
118:                        calendar = (Calendar) (dates.next());
119:                        if (compareDate(calendar, current)) {
120:                            return true;
121:                        }
122:                    }
123:                    return false;
124:                }
125:                return false;
126:            }
127:
128:            public boolean compareDate(java.util.Calendar selected,
129:                    java.util.Calendar current) {
130:
131:                if (DEBUG)
132:                    log("Rendered data is " + current.getTime().toString());
133:                if (DEBUG)
134:                    log("Compare to " + selected.getTime().toString());
135:                if (selected.get(Calendar.YEAR) == current.get(Calendar.YEAR)
136:                        && selected.get(Calendar.MONTH) == current
137:                                .get(Calendar.MONTH)
138:                        && selected.get(Calendar.DAY_OF_MONTH) == current
139:                                .get(Calendar.DAY_OF_MONTH)) {
140:                    if (DEBUG)
141:                        log("Found match");
142:                    return true;
143:                }
144:                return false;
145:            }
146:
147:            /**
148:             * <p>Convenience function to return the locale of the current context.</p>
149:             */
150:            protected Locale getLocale() {
151:                FacesContext context = FacesContext.getCurrentInstance();
152:                return context.getViewRoot().getLocale();
153:            }
154:
155:            /**
156:             * <p>Returns a new Calendar instance.</p>
157:             *
158:             * @return java.util.Calendar A new Calendar instance with the correct
159:             * locale and time zone.
160:             */
161:            public java.util.Calendar getCalendar() {
162:                if (calendar == null) {
163:                    initializeCalendar();
164:                }
165:                return (java.util.Calendar) (calendar.clone());
166:            }
167:
168:            /**
169:             * <p>Returns a new Calendar instance.</p>
170:             *
171:             * @return java.util.Calendar A new Calendar instance with the correct
172:             * locale and time zone.
173:             */
174:            private void initializeCalendar() {
175:
176:                if (DEBUG)
177:                    log("initializeCalendar()");
178:                UIComponent parent = getParent();
179:                Locale locale = FacesContext.getCurrentInstance().getViewRoot()
180:                        .getLocale();
181:                if (parent instanceof  DateManager) {
182:                    TimeZone tz = ((DateManager) parent).getTimeZone();
183:                    if (tz == null) {
184:                        calendar = java.util.Calendar.getInstance(locale);
185:                        getAttributes().put(TIME_ZONE_ATTR,
186:                                calendar.getTimeZone());
187:                    } else {
188:                        calendar = java.util.Calendar.getInstance(tz, locale);
189:                        getAttributes().put(TIME_ZONE_ATTR, tz);
190:                    }
191:                } else {
192:                    calendar = java.util.Calendar.getInstance(locale);
193:                }
194:                if (DEBUG)
195:                    log("initializeCalendar() - END");
196:            }
197:
198:            /** <p>Return the DateFormat object for this CalendarMonth.</p> */
199:            public DateFormat getDateFormat() {
200:
201:                if (DEBUG)
202:                    log("getDateFormat()");
203:
204:                Object o = getAttributes().get(DATE_FORMAT_ATTR);
205:                DateFormat dateFormat = null;
206:                if (o != null && o instanceof  DateFormat) {
207:                    dateFormat = (DateFormat) o;
208:                    if (DEBUG)
209:                        log("DateFormat was already set");
210:                } else {
211:                    if (DEBUG)
212:                        log("Dateformat not calculated");
213:
214:                    dateFormat = SimpleDateFormat.getDateInstance(
215:                            DateFormat.SHORT, getLocale());
216:                    // We need to set the locale and the timeZone of the dateFormat. 
217:                    // I can't tell from the spec whether just setting the Calendar 
218:                    // does this correctly (the Calendar does know both). 
219:
220:                    dateFormat.setCalendar(getCalendar());
221:
222:                    if (DEBUG)
223:                        log("Set the Calendar");
224:                    String pattern = null;
225:                    UIComponent parent = getParent();
226:                    if (parent != null && parent instanceof  DateManager) {
227:                        pattern = ((DateManager) parent).getDateFormatPattern();
228:                    }
229:
230:                    if (pattern != null) {
231:                        ((SimpleDateFormat) dateFormat).applyPattern(pattern);
232:                        getAttributes().put(DATE_FORMAT_PATTERN_ATTR, pattern);
233:                    } else {
234:                        String defaultPattern = ((SimpleDateFormat) dateFormat)
235:                                .toPattern();
236:                        if (defaultPattern.indexOf("yyyy") == -1) {
237:                            defaultPattern = defaultPattern.replaceFirst("yy",
238:                                    "yyyy");
239:                        }
240:                        if (defaultPattern.indexOf("MM") == -1) {
241:                            defaultPattern = defaultPattern.replaceFirst("M",
242:                                    "MM");
243:                        }
244:                        if (defaultPattern.indexOf("dd") == -1) {
245:                            defaultPattern = defaultPattern.replaceFirst("d",
246:                                    "dd");
247:                        }
248:                        ((SimpleDateFormat) dateFormat)
249:                                .applyPattern(defaultPattern);
250:                        getAttributes().put(DATE_FORMAT_PATTERN_ATTR,
251:                                defaultPattern);
252:                    }
253:
254:                    getAttributes().put(DATE_FORMAT_ATTR, dateFormat);
255:                }
256:                return dateFormat;
257:            }
258:
259:            /** <p>Return the TimeZone object for this CalendarMonth.</p> */
260:            public TimeZone getTimeZone() {
261:
262:                if (DEBUG)
263:                    log("getDateFormat()");
264:
265:                Object o = getAttributes().get(TIME_ZONE_ATTR);
266:                if (o != null && o instanceof  TimeZone) {
267:                    return (TimeZone) o;
268:                }
269:
270:                initializeCalendar();
271:                o = getAttributes().get(TIME_ZONE_ATTR);
272:                if (o != null && o instanceof  TimeZone) {
273:                    return (TimeZone) o;
274:                }
275:                return TimeZone.getDefault();
276:            }
277:
278:            /**
279:             * <p>Get the DropDown menu instance to use for this CalendarMonths's year
280:             * menu.</p>
281:             * 
282:             * @return The DropDown instance to use for the year menu
283:             */
284:            public DropDown getMonthMenu() {
285:
286:                if (DEBUG)
287:                    log("getMonthMenu()");
288:
289:                UIComponent comp = getFacet(MONTH_MENU_ID);
290:                DropDown monthMenu = null;
291:
292:                if (comp == null || !(comp instanceof  DropDown)) {
293:
294:                    monthMenu = new DropDown();
295:                    monthMenu.setSubmitForm(true);
296:
297:                    monthMenu.setConverter(new IntegerConverter());
298:                    monthMenu.setId(MONTH_MENU_ID);
299:
300:                    // The year menu is controlled by JavaScript when
301:                    // this component is shown in popup mode. When used
302:                    // in the Scheduler, we need to do the following
303:                    // to control the behaviour on submit
304:                    if (!isPopup()) {
305:                        monthMenu.setImmediate(true);
306:                        //yearMenu.addValueChangeListener(new MonthListener());
307:                    }
308:
309:                    // add the year menu to the facet list
310:                    getFacets().put(MONTH_MENU_ID, monthMenu);
311:                } else {
312:                    monthMenu = (DropDown) comp;
313:                }
314:
315:                if (DEBUG)
316:                    log("getMonthMenu() - END");
317:                return monthMenu;
318:            }
319:
320:            /**
321:             * <p>Get the JumpDropDown menu instance to use for thie
322:             * CalendarMonth's year menu.</p>
323:             *
324:             * @return The JumpDropDown instance to use for the year menu
325:             */
326:            public DropDown getYearMenu() {
327:
328:                if (DEBUG)
329:                    log("getYearMenu()");
330:
331:                DropDown yearMenu = (DropDown) getFacets().get(YEAR_MENU_ID);
332:
333:                if (yearMenu == null) {
334:                    yearMenu = new DropDown();
335:                    yearMenu.setSubmitForm(true);
336:                    yearMenu.setId(YEAR_MENU_ID);
337:                    yearMenu.setConverter(new IntegerConverter());
338:
339:                    // The year menu is controlled by JavaScript when
340:                    // this component is shown in popup mode. When used
341:                    // in the Scheduler, we need to do the following 
342:                    // to control the behaviour on submit
343:                    if (!isPopup()) {
344:                        yearMenu.setImmediate(true);
345:                        //yearMenu.addValueChangeListener(new YearListener());
346:                    }
347:
348:                    // add the year menu to the facet list            
349:                    getFacets().put(YEAR_MENU_ID, yearMenu);
350:                }
351:
352:                return yearMenu;
353:            }
354:
355:            /**
356:             * <p>Get the IconHyperlink instance to use for the previous year
357:             * link.</p> 
358:             * @return The IconHyperlink instance to use for the previous year link
359:             */
360:            public IconHyperlink getPreviousMonthLink() {
361:                IconHyperlink link = (IconHyperlink) getFacets().get(
362:                        PREVIOUS_MONTH_LINK_ID);
363:
364:                if (link == null) {
365:                    link = new IconHyperlink();
366:                    link.setId(PREVIOUS_MONTH_LINK_ID);
367:                    link.setIcon(ThemeImages.SCHEDULER_BACKWARD);
368:                    link.setBorder(0);
369:
370:                    // The link is controlled by JavaScript when
371:                    // this component is shown in popup mode. When used
372:                    // in the Scheduler, we need to do the following
373:                    // to control the behaviour on submit
374:                    if (!isPopup()) {
375:                        link.setImmediate(true);
376:                        link.addActionListener(new PreviousMonthListener());
377:                    }
378:
379:                    getFacets().put(PREVIOUS_MONTH_LINK_ID, link);
380:                }
381:
382:                return (IconHyperlink) link;
383:            }
384:
385:            /**
386:             * <p>Get the IconHyperlink instance to use for the next year
387:             * link.</p> 
388:             * 
389:             * @return The IconHyperlink instance to use for the next year link
390:             */
391:            public IconHyperlink getNextMonthLink() {
392:                IconHyperlink link = (IconHyperlink) getFacets().get(
393:                        NEXT_MONTH_LINK_ID);
394:
395:                if (link == null) {
396:                    link = new IconHyperlink();
397:                    link.setId(NEXT_MONTH_LINK_ID);
398:
399:                    link.setIcon(ThemeImages.SCHEDULER_FORWARD);
400:                    link.setBorder(0);
401:
402:                    // The link is controlled by JavaScript when
403:                    // this component is shown in popup mode. When used
404:                    // in the Scheduler, we need to do the following
405:                    // to control the behaviour on submit
406:                    if (!isPopup()) {
407:                        link.addActionListener(new NextMonthListener());
408:                        link.setImmediate(true);
409:                    }
410:
411:                    getFacets().put(NEXT_MONTH_LINK_ID, link);
412:                }
413:
414:                return link;
415:            }
416:
417:            /** <p>Convience function to get the current Theme.</p> */
418:            protected Theme getTheme() {
419:                return ThemeUtilities.getTheme(FacesContext
420:                        .getCurrentInstance());
421:            }
422:
423:            public void initCalendarControls(String jsName) {
424:
425:                if (DEBUG)
426:                    log("initCalendarControls()");
427:
428:                StringBuffer js = new StringBuffer("javascript: ") //NOI18N
429:                        .append(jsName).append(
430:                                ".decreaseMonth(); return false;"); //NOI18N
431:
432:                // Don't set Javascript as the URL -- bugtraq #6306848.
433:                ImageHyperlink link = getPreviousMonthLink();
434:                link.setIcon(ThemeImages.CALENDAR_BACKWARD);
435:                link.setOnClick(js.toString());
436:
437:                js = new StringBuffer("javascript: ").append(jsName).append(
438:                        ".increaseMonth(); return false;");
439:
440:                // Don't set Javascript as the URL -- bugtraq #6306848.
441:                link = getNextMonthLink();
442:                link.setIcon(ThemeImages.CALENDAR_FORWARD);
443:                link.setOnClick(js.toString());
444:
445:                getMonthMenu().setOnChange(
446:                        jsName.concat(".redrawCalendar(false); return false;"));
447:                getYearMenu().setOnChange(
448:                        jsName.concat(".redrawCalendar(false); return false;"));
449:            }
450:
451:            public void showNextMonth() {
452:                Integer month = getCurrentMonth();
453:                DropDown monthMenu = getMonthMenu();
454:
455:                if (month.intValue() < 12) {
456:                    int newMonth = month.intValue() + 1;
457:                    monthMenu.setSubmittedValue(new String[] { String
458:                            .valueOf(newMonth) });
459:                } else if (showNextYear()) {
460:                    monthMenu.setSubmittedValue(new String[] { "1" });
461:                }
462:                // otherwise we do nothing
463:            }
464:
465:            public void showPreviousMonth() {
466:
467:                Integer month = getCurrentMonth();
468:                DropDown monthMenu = getMonthMenu();
469:
470:                if (month.intValue() > 1) {
471:                    int newMonth = month.intValue() - 1;
472:                    monthMenu.setSubmittedValue(new String[] { String
473:                            .valueOf(newMonth) });
474:                } else if (showPreviousYear()) {
475:                    monthMenu.setSubmittedValue(new String[] { "12" });
476:                }
477:                // otherwise we do nothing
478:            }
479:
480:            private boolean showNextYear() {
481:
482:                DropDown yearMenu = getYearMenu();
483:                int year = getCurrentYear().intValue();
484:                year++;
485:                Option[] options = yearMenu.getOptions();
486:                Integer lastYear = (Integer) (options[options.length - 1]
487:                        .getValue());
488:                if (lastYear.intValue() >= year) {
489:                    yearMenu.setSubmittedValue(new String[] { String
490:                            .valueOf(year) });
491:                    return true;
492:                }
493:                return false;
494:            }
495:
496:            private boolean showPreviousYear() {
497:
498:                DropDown yearMenu = getYearMenu();
499:                int year = getCurrentYear().intValue();
500:                year--;
501:
502:                Option[] options = yearMenu.getOptions();
503:                Integer firstYear = (Integer) (options[0].getValue());
504:                if (firstYear.intValue() <= year) {
505:                    yearMenu.setSubmittedValue(new String[] { String
506:                            .valueOf(year) });
507:                    return true;
508:                }
509:                return false;
510:            }
511:
512:            public Integer getCurrentMonth() {
513:                DropDown monthMenu = getMonthMenu();
514:                Object value = monthMenu.getSubmittedValue();
515:                Integer month = null;
516:                if (value != null) {
517:                    try {
518:                        String[] vals = (String[]) value;
519:                        month = Integer.decode(vals[0]);
520:                    } catch (Exception ex) {
521:                        // do nothing
522:                    }
523:                } else {
524:                    value = monthMenu.getValue();
525:                    if (value != null && value instanceof  Integer) {
526:                        month = ((Integer) value);
527:                    }
528:                }
529:                return month;
530:            }
531:
532:            public Integer getCurrentYear() {
533:                DropDown yearMenu = getYearMenu();
534:                Object value = yearMenu.getSubmittedValue();
535:                Integer year = null;
536:                if (value != null) {
537:                    try {
538:                        String[] vals = (String[]) value;
539:                        year = Integer.decode(vals[0]);
540:                    } catch (NumberFormatException ex) {
541:                        // do nothing
542:                    }
543:                } else {
544:                    value = yearMenu.getValue();
545:                    if (value != null && value instanceof  Integer) {
546:                        year = ((Integer) value);
547:                    }
548:                }
549:                return year;
550:            }
551:
552:            /**
553:             * Holds value of property javaScriptObject.
554:             */
555:            private String javaScriptObjectName = null;
556:
557:            /*
558:            public void setDisplayDateField(int calendarField, int newValue) {
559:                
560:                if(DEBUG) log("setDisplayDateField()");
561:                Object o = getAttributes().get(DISPLAY_DATE_ATTR);
562:                if(o instanceof Calendar) {
563:                    Calendar calendar = (Calendar)o;
564:                    calendar.set(calendarField, newValue);
565:                    calendar.getTime();
566:                    if(DEBUG) log("\tNew time is " + calendar.getTime().toString());
567:                }
568:                  
569:                if(DEBUG) log("setDisplayDateField() - END");
570:                FacesContext.getCurrentInstance().renderResponse();       
571:            }
572:
573:            public void updateDisplayDateField(int calendarField, int newValue) { 
574:                
575:               if(DEBUG) log("updateDisplayDateField()");
576:                Object o = getAttributes().get(DISPLAY_DATE_ATTR);
577:                if(o instanceof Calendar) {
578:                    Calendar calendar = (Calendar)o;
579:                    calendar.add(calendarField, newValue);
580:                    calendar.getTime();
581:                    if(DEBUG) log("\tNew time is " + calendar.getTime().toString());
582:                }
583:                  
584:                if(DEBUG) log("updateDisplayDateField() - END");
585:                FacesContext.getCurrentInstance().renderResponse();      
586:            }
587:
588:             */
589:
590:            /**
591:             * Getter for property javaScriptObject.
592:             * @return Value of property javaScriptObject.
593:             */
594:            public String getJavaScriptObjectName() {
595:
596:                return this .javaScriptObjectName;
597:            }
598:
599:            /**
600:             * Setter for property javaScriptObject.
601:             * @param javaScriptObject New value of property javaScriptObject.
602:             */
603:            public void setJavaScriptObjectName(String javaScriptObjectName) {
604:
605:                this .javaScriptObjectName = javaScriptObjectName;
606:            }
607:
608:            private void log(String s) {
609:                System.out.println(this .getClass().getName() + "::" + s);
610:            }
611:
612:            public String getDateFormatPattern() {
613:
614:                if (DEBUG)
615:                    log("calculatePattern()");
616:                Object o = getAttributes().get(DATE_FORMAT_PATTERN_ATTR);
617:                String pattern = null;
618:                if (o == null || !(o instanceof  String)) {
619:                    getDateFormat();
620:                    pattern = (String) (getAttributes()
621:                            .get(DATE_FORMAT_PATTERN_ATTR));
622:                } else {
623:                    pattern = (String) o;
624:                }
625:                return pattern;
626:            }
627:
628:            // Cause the month display to move to the current value, not what the 
629:            // use was looking at last time... 
630:            public void displayValue() {
631:
632:                if (DEBUG)
633:                    log("displayValue()");
634:                DropDown monthMenu = getMonthMenu();
635:                DropDown yearMenu = getYearMenu();
636:                Object value = getValue();
637:                if (value == null) {
638:                    if (DEBUG)
639:                        log("Value is null");
640:                    monthMenu.setValue(null);
641:                    yearMenu.setValue(null);
642:                } else if (value instanceof  Date) {
643:                    if (DEBUG)
644:                        log("Value is date");
645:                    Calendar calendar = getCalendar();
646:                    calendar.setTime((Date) value);
647:                    int newMonth = calendar.get(Calendar.MONTH) + 1;
648:                    if (DEBUG)
649:                        log("new month value " + String.valueOf(newMonth));
650:                    monthMenu.setValue(new Integer(newMonth));
651:
652:                    int newYear = calendar.get(Calendar.YEAR);
653:                    if (DEBUG)
654:                        log("new year value " + String.valueOf(newYear));
655:                    yearMenu.setValue(new Integer(newYear));
656:                } else if (value instanceof  ScheduledEvent) {
657:                    if (DEBUG)
658:                        log("Value is ScheduledEvent");
659:                    Date date = ((ScheduledEvent) value).getStartTime();
660:                    if (date != null) {
661:                        Calendar calendar = getCalendar();
662:                        calendar.setTime(date);
663:                        int newMonth = calendar.get(Calendar.MONTH) + 1;
664:                        if (DEBUG)
665:                            log("new month value " + String.valueOf(newMonth));
666:                        monthMenu.setValue(new Integer(newMonth));
667:
668:                        int newYear = calendar.get(Calendar.YEAR);
669:                        if (DEBUG)
670:                            log("new year value " + String.valueOf(newYear));
671:                        yearMenu.setValue(new Integer(newYear));
672:                    } else {
673:                        if (DEBUG)
674:                            log("Value is null");
675:                        monthMenu.setValue(null);
676:                        yearMenu.setValue(null);
677:                    }
678:                }
679:                monthMenu.setSubmittedValue(null);
680:                yearMenu.setSubmittedValue(null);
681:            }
682:        }
683:
684:        class PreviousMonthListener implements  ActionListener, Serializable {
685:
686:            public void processAction(ActionEvent event) {
687:
688:                FacesContext.getCurrentInstance().renderResponse();
689:                UIComponent comp = event.getComponent();
690:                comp = comp.getParent();
691:                if (comp instanceof  CalendarMonth) {
692:                    ((CalendarMonth) comp).showPreviousMonth();
693:                }
694:            }
695:        }
696:
697:        class NextMonthListener implements  ActionListener, Serializable {
698:
699:            public void processAction(ActionEvent event) {
700:
701:                FacesContext.getCurrentInstance().renderResponse();
702:                UIComponent comp = event.getComponent();
703:                comp = comp.getParent();
704:                if (comp instanceof  CalendarMonth) {
705:                    ((CalendarMonth) comp).showNextMonth();
706:                }
707:            }
708:        }
709:
710:        /*
711:         class MonthListener implements ValueChangeListener, Serializable {
712:        
713:         public void processValueChange(ValueChangeEvent event) {
714:        
715:         FacesContext.getCurrentInstance().renderResponse();
716:         Object value = event.getNewValue();
717:         System.out.println(value.toString());
718:         if(value != null && value instanceof Integer) {
719:         int newvalue = ((Integer)value).intValue() -1;
720:         UIComponent comp = event.getComponent();
721:         comp = comp.getParent();
722:         if(comp instanceof CalendarMonth) {
723:         ((CalendarMonth)comp).setDisplayDateField(Calendar.MONTH, newvalue);
724:         }
725:         }
726:         }
727:         } 
728:
729:         class YearListener implements ValueChangeListener, Serializable {
730:        
731:         public void processValueChange(ValueChangeEvent event) {
732:        
733:         FacesContext.getCurrentInstance().renderResponse();
734:         Object value = event.getNewValue();
735:         System.out.println(value.toString());
736:         if(value != null && value instanceof Integer) {
737:         int newvalue = ((Integer)value).intValue();
738:         UIComponent comp = event.getComponent();
739:         comp = comp.getParent();
740:         if(comp instanceof CalendarMonth) {
741:         ((CalendarMonth)comp).setDisplayDateField(Calendar.YEAR, newvalue);
742:         }
743:         }
744:         }   
745:         }
746:
747:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.