Source Code Cross Referenced for JXDatePickerFormatterFactory.java in  » Project-Management » OpenProj » org » jdesktop » swing » 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 » Project Management » OpenProj » org.jdesktop.swing.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: JXDatePickerFormatterFactory.java,v 1.1 2007/08/15 23:28:24 suricate Exp $
003:         * 
004:         * This code comes from the dormant jdnc project at https://jdnc.dev.java.net/. It is licensed with the LGPL
005:         * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 
006:         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
007:         */
008:        package org.jdesktop.swing.calendar;
009:
010:        import java.text.ParseException;
011:        import java.text.SimpleDateFormat;
012:
013:        import javax.swing.JFormattedTextField;
014:        import javax.swing.UIManager;
015:        import javax.swing.JFormattedTextField.AbstractFormatter;
016:        import javax.swing.JFormattedTextField.AbstractFormatterFactory;
017:
018:        /**
019:         * Default formatter factory for the JXDatePicker component.  This factory
020:         * creates and returns a formatter that can handle a variety of date formats.
021:         *
022:         * @author Joshua Outwater
023:         */
024:        public class JXDatePickerFormatterFactory extends
025:                AbstractFormatterFactory {
026:            /** Cached formatter */
027:            protected AbstractFormatter formatter = null;
028:
029:            /**
030:             * {@inheritDoc}
031:             */
032:            public AbstractFormatter getFormatter(JFormattedTextField ftf) {
033:                if (formatter == null) {
034:                    formatter = new JXDatePickerFormatter();
035:                }
036:                return formatter;
037:            }
038:
039:            /**
040:             * Default formatter class for the JXDatePicker component.  This formatter
041:             * supports the following three default formats:
042:             * <ul>
043:             * <li>EEE MM/dd/yyyy (Fri 04/09/2004)
044:             * <li>MM/dd/yyyy     (04/09/2004)
045:             * <li>dd/yy          (04/09)
046:             * </ul>
047:             * These formats are localizable and fields may be re-arranged, such as
048:             * swapping the month and day fields.  The keys for localizing these fields
049:             * are:
050:             * <ul>
051:             * <li>JXDatePicker.longFormat
052:             * <li>JXDatePicker.mediumFormat
053:             * <li>JXDatePicker.shortFormat
054:             * </ul>
055:             * It is important to order the formats in the order of most complex to
056:             * least complex as it is possible for less complex formats to match more
057:             * complex strings.
058:             */
059:            private class JXDatePickerFormatter extends
060:                    JFormattedTextField.AbstractFormatter {
061:                private SimpleDateFormat _formats[] = null;
062:                private int _formatIndex = 0;
063:
064:                public JXDatePickerFormatter() {
065:                    _formats = new SimpleDateFormat[3];
066:                    String format = UIManager
067:                            .getString("JXDatePicker.longFormat");
068:                    if (format == null) {
069:                        format = "EEE MM/dd/yyyy";
070:                    }
071:                    _formats[0] = new SimpleDateFormat(format);
072:
073:                    format = UIManager.getString("JXDatePicker.mediumFormat");
074:                    if (format == null) {
075:                        format = "MM/dd/yyyy";
076:                    }
077:                    _formats[1] = new SimpleDateFormat(format);
078:
079:                    format = UIManager.getString("JXDatePicker.shortFormat");
080:                    if (format == null) {
081:                        format = "MM/dd";
082:                    }
083:                    _formats[2] = new SimpleDateFormat(format);
084:                }
085:
086:                /**
087:                 * {@inheritDoc}
088:                 */
089:                public Object stringToValue(String text) throws ParseException {
090:                    Object result = null;
091:                    ParseException pex = null;
092:
093:                    if (text == null) {
094:                        return null;
095:                    }
096:
097:                    // Try the current formatter first.
098:                    try {
099:                        result = _formats[_formatIndex].parse(text);
100:                    } catch (ParseException ex) {
101:                        pex = ex;
102:                    }
103:
104:                    // If the current formatter did not work loop through the other
105:                    // formatters and see if any of them can parse the string passed
106:                    // in.
107:                    if (result == null) {
108:                        for (int i = 0; i < _formats.length; i++) {
109:                            if (i == _formatIndex) {
110:                                continue;
111:                            }
112:
113:                            try {
114:                                result = ((SimpleDateFormat) _formats[i])
115:                                        .parse(text);
116:
117:                                // We got a successful formatter.  Update the current
118:                                // formatter index.
119:                                _formatIndex = i;
120:                                pex = null;
121:                                break;
122:                            } catch (ParseException ex) {
123:                                pex = ex;
124:                            }
125:                        }
126:                    }
127:
128:                    if (pex != null) {
129:                        throw pex;
130:                    }
131:
132:                    return result;
133:                }
134:
135:                /**
136:                 * {@inheritDoc}
137:                 */
138:                public String valueToString(Object value) throws ParseException {
139:                    if (value != null) {
140:                        return _formats[_formatIndex].format(value);
141:                    }
142:                    return null;
143:                }
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.