Source Code Cross Referenced for DateLabel.java in  » J2EE » wicket » org » apache » wicket » datetime » markup » html » basic » 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 » wicket » org.apache.wicket.datetime.markup.html.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.datetime.markup.html.basic;
018:
019:        import java.text.SimpleDateFormat;
020:
021:        import org.apache.wicket.datetime.DateConverter;
022:        import org.apache.wicket.datetime.PatternDateConverter;
023:        import org.apache.wicket.datetime.StyleDateConverter;
024:        import org.apache.wicket.markup.ComponentTag;
025:        import org.apache.wicket.markup.MarkupStream;
026:        import org.apache.wicket.markup.html.basic.Label;
027:        import org.apache.wicket.model.IModel;
028:        import org.apache.wicket.util.convert.IConverter;
029:        import org.joda.time.DateTime;
030:        import org.joda.time.DateTimeZone;
031:        import org.joda.time.format.DateTimeFormat;
032:
033:        /**
034:         * A label that is mapped to a <code>java.util.Date</code> object and that
035:         * uses Joda time to format values.
036:         * <p>
037:         * You can provide a date pattern in two of the constructors. When not provided,
038:         * {@link DateTimeFormat#shortDate()} will be used.
039:         * </p>
040:         * <p>
041:         * A special option is applyTimeZoneDifference which is an option that says
042:         * whether to correct for the difference between the client's time zone and
043:         * server's time zone. This is true by default.
044:         * </p>
045:         * 
046:         * @see DateTime
047:         * @see DateTimeFormat
048:         * @see DateTimeZone
049:         * 
050:         * @author eelcohillenius
051:         */
052:        public class DateLabel extends Label {
053:            private static final long serialVersionUID = 1L;
054:
055:            /**
056:             * Creates a new DateLabel defaulting to using a short date pattern
057:             * 
058:             * @param id
059:             *            The id of the text field
060:             * @param model
061:             *            The model
062:             * @param datePattern
063:             *            The pattern to use. Must be not null. See
064:             *            {@link SimpleDateFormat} for available patterns.
065:             * 
066:             * @see org.apache.wicket.markup.html.form.TextField
067:             */
068:            public static DateLabel forDatePattern(String id, IModel model,
069:                    String datePattern) {
070:                return new DateLabel(id, model, new PatternDateConverter(
071:                        datePattern, true));
072:            }
073:
074:            /**
075:             * Creates a new DateLabel defaulting to using a short date pattern
076:             * 
077:             * @param id
078:             *            The id of the text field
079:             * @param datePattern
080:             *            The pattern to use. Must be not null. See
081:             *            {@link SimpleDateFormat} for available patterns.
082:             * 
083:             * @see org.apache.wicket.markup.html.form.TextField
084:             */
085:            public static DateLabel forDatePattern(String id, String datePattern) {
086:                return forDatePattern(id, null, datePattern);
087:            }
088:
089:            /**
090:             * Creates a new DateLabel defaulting to using a short date pattern
091:             * 
092:             * @param id
093:             *            The id of the text field
094:             * @param model
095:             *            The model
096:             * @param dateStyle
097:             *            style to use in case no pattern is provided. Must be two
098:             *            characters from the set {"S", "M", "L", "F", "-"}. Must be not
099:             *            null. See {@link DateTimeFormat#forStyle(String)} for options.
100:             * 
101:             * @see org.apache.wicket.markup.html.form.TextField
102:             */
103:            public static DateLabel forDateStyle(String id, IModel model,
104:                    String dateStyle) {
105:                return new DateLabel(id, model, new StyleDateConverter(
106:                        dateStyle, true));
107:            }
108:
109:            /**
110:             * Creates a new DateLabel defaulting to using a short date pattern
111:             * 
112:             * @param id
113:             *            The id of the text field
114:             * @param dateStyle
115:             *            style to use in case no pattern is provided. Must be two
116:             *            characters from the set {"S", "M", "L", "F", "-"}. Must be not
117:             *            null. See {@link DateTimeFormat#forStyle(String)} for options.
118:             * 
119:             * @see org.apache.wicket.markup.html.form.TextField
120:             */
121:            public static DateLabel forDateStyle(String id, String dateStyle) {
122:                return forDateStyle(id, null, dateStyle);
123:            }
124:
125:            /**
126:             * Creates a new DateLabel defaulting to using a short date pattern
127:             * 
128:             * @param id
129:             *            The id of the text field
130:             * 
131:             * @see org.apache.wicket.markup.html.form.TextField
132:             */
133:            public static DateLabel forShortStyle(String id) {
134:                return forShortStyle(id, null);
135:            }
136:
137:            /**
138:             * Creates a new DateLabel defaulting to using a short date pattern
139:             * 
140:             * @param id
141:             *            The id of the text field
142:             * @param model
143:             *            The model
144:             * 
145:             * @see org.apache.wicket.markup.html.form.TextField
146:             */
147:            public static DateLabel forShortStyle(String id, IModel model) {
148:                return new DateLabel(id, model, new StyleDateConverter(true));
149:            }
150:
151:            /**
152:             * Creates a new DateLabel using the provided converter.
153:             * 
154:             * @param id
155:             *            The id of the text field
156:             * @param converter
157:             *            the date converter
158:             * 
159:             * @see org.apache.wicket.markup.html.form.TextField
160:             */
161:            public static DateLabel withConverter(String id,
162:                    DateConverter converter) {
163:                return withConverter(id, null, converter);
164:            }
165:
166:            /**
167:             * Creates a new DateLabel using the provided converter.
168:             * 
169:             * @param id
170:             *            The id of the text field
171:             * @param model
172:             *            The model
173:             * @param converter
174:             *            the date converter
175:             * 
176:             * @see org.apache.wicket.markup.html.form.TextField
177:             */
178:            public static DateLabel withConverter(String id, IModel model,
179:                    DateConverter converter) {
180:                return new DateLabel(id, model, converter);
181:            }
182:
183:            /** optionally prepend to label. */
184:            private String after;
185:
186:            /** optionally append to label. */
187:            private String before;
188:
189:            /**
190:             * The converter for the Label
191:             */
192:            private final DateConverter converter;
193:
194:            /**
195:             * Construct with a converter.
196:             * 
197:             * @param The
198:             *            component id
199:             * @param The
200:             *            model
201:             * @param converter
202:             *            The converter to use
203:             */
204:            public DateLabel(String id, IModel model, DateConverter converter) {
205:                super (id, model);
206:                if (converter == null) {
207:                    throw new IllegalStateException("converter may not be null");
208:                }
209:                converter.setComponent(this );
210:                this .converter = converter;
211:            }
212:
213:            /**
214:             * @return after append to label or null
215:             */
216:            public String getAfter() {
217:                return after;
218:            }
219:
220:            /**
221:             * @return before prepend to label or null
222:             */
223:            public String getBefore() {
224:                return before;
225:            }
226:
227:            /**
228:             * Returns the specialized converter.
229:             */
230:            public IConverter getConverter(Class clazz) {
231:                return converter;
232:            }
233:
234:            /**
235:             * @param after
236:             *            append to label
237:             */
238:            public void setAfter(String after) {
239:                this .after = after;
240:            }
241:
242:            /**
243:             * @param before
244:             *            prepend to label
245:             */
246:            public void setBefore(String before) {
247:                this .before = before;
248:            }
249:
250:            protected void onComponentTagBody(MarkupStream markupStream,
251:                    ComponentTag openTag) {
252:                String s = getModelObjectAsString();
253:                if (before != null) {
254:                    s = before + s;
255:                }
256:                if (after != null) {
257:                    s = s + after;
258:                }
259:                replaceComponentTagBody(markupStream, openTag, s);
260:            }
261:        }
w_w_w_.___j_a__v__a2s__._c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.