Source Code Cross Referenced for TimeModel.java in  » Development » rapla » org » rapla » components » calendar » 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 » Development » rapla » org.rapla.components.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--------------------------------------------------------------------------*
002:         | Copyright (C) 2006 Christopher Kohlhaas                                  |
003:         |                                                                          |
004:         | This program is free software; you can redistribute it and/or modify     |
005:         | it under the terms of the GNU General Public License as published by the |
006:         | Free Software Foundation. A copy of the license has been included with   |
007:         | these distribution in the COPYING file, if not go to www.fsf.org         |
008:         |                                                                          |
009:         | As a special exception, you are granted the permissions to link this     |
010:         | program with every library, which license fulfills the Open Source       |
011:         | Definition as published by the Open Source Initiative (OSI).             |
012:         *--------------------------------------------------------------------------*/
013:
014:        package org.rapla.components.calendar;
015:
016:        import java.util.Calendar;
017:        import java.util.ArrayList;
018:        import java.util.Locale;
019:        import java.util.Date;
020:        import java.util.TimeZone;
021:
022:        /** The model of the obligatory MVC approach is a wrapper arround an Calendar object.
023:         */
024:        final class TimeModel {
025:            Calendar m_calendar;
026:            Locale m_locale;
027:
028:            ArrayList m_listenerList = new ArrayList();
029:
030:            public TimeModel(Locale locale, TimeZone timeZone) {
031:                m_locale = locale;
032:                m_calendar = Calendar.getInstance(timeZone, m_locale);
033:                trim(m_calendar);
034:                m_calendar.setLenient(true);
035:            }
036:
037:            public void addDateChangeListener(DateChangeListener listener) {
038:                m_listenerList.add(listener);
039:            }
040:
041:            public void removeDateChangeListener(DateChangeListener listener) {
042:                m_listenerList.remove(listener);
043:            }
044:
045:            public Locale getLocale() {
046:                return m_locale;
047:            }
048:
049:            public Date getTime() {
050:                return m_calendar.getTime();
051:            }
052:
053:            // #TODO Property change listener for TimeZone
054:            public void setTimeZone(TimeZone timeZone) {
055:                m_calendar.setTimeZone(timeZone);
056:            }
057:
058:            public TimeZone getTimeZone() {
059:                return m_calendar.getTimeZone();
060:            }
061:
062:            public void setTime(int hours, int minutes) {
063:                m_calendar.set(Calendar.HOUR_OF_DAY, hours);
064:                m_calendar.set(Calendar.MINUTE, minutes);
065:                trim(m_calendar);
066:                fireDateChanged();
067:            }
068:
069:            public void setTime(Date date) {
070:                m_calendar.setTime(date);
071:                trim(m_calendar);
072:                fireDateChanged();
073:            }
074:
075:            public boolean sameTime(Date date) {
076:                Calendar calendar = Calendar.getInstance(getTimeZone(),
077:                        getLocale());
078:                calendar.setTime(date);
079:                trim(calendar);
080:                return calendar.getTime().equals(getTime());
081:            }
082:
083:            private void trim(Calendar calendar) {
084:                calendar.set(Calendar.DATE, 0);
085:                calendar.set(Calendar.MONTH, 0);
086:                calendar.set(Calendar.YEAR, 0);
087:                calendar.set(Calendar.SECOND, 0);
088:                calendar.set(Calendar.MILLISECOND, 0);
089:            }
090:
091:            public DateChangeListener[] getDateChangeListeners() {
092:                return (DateChangeListener[]) m_listenerList
093:                        .toArray(new DateChangeListener[] {});
094:            }
095:
096:            protected void fireDateChanged() {
097:                DateChangeListener[] listeners = getDateChangeListeners();
098:                DateChangeEvent evt = new DateChangeEvent(this , getTime());
099:                for (int i = 0; i < listeners.length; i++) {
100:                    listeners[i].dateChanged(evt);
101:                }
102:            }
103:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.