Source Code Cross Referenced for Timebox.java in  » Ajax » zk » org » zkoss » zul » 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 » Ajax » zk » org.zkoss.zul 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Timebox.java
002:
003:         {{IS_NOTE
004:         Purpose:
005:         
006:         Description:
007:         
008:         History:
009:         	Jul 9, 2007 10:03:38 AM , Created by Dennis Chen
010:         }}IS_NOTE
011:
012:         Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:         {{IS_RIGHT
015:         This program is distributed under GPL Version 2.0 in the hope that
016:         it will be useful, but WITHOUT ANY WARRANTY.
017:         }}IS_RIGHT
018:         */
019:        package org.zkoss.zul;
020:
021:        import java.text.DateFormat;
022:        import java.text.ParseException;
023:        import java.text.SimpleDateFormat;
024:        import java.util.Date;
025:        import java.util.TimeZone;
026:
027:        import org.zkoss.lang.Objects;
028:        import org.zkoss.util.Locales;
029:        import org.zkoss.util.TimeZones;
030:
031:        import org.zkoss.xml.HTMLs;
032:        import org.zkoss.zk.ui.WrongValueException;
033:        import org.zkoss.zul.impl.InputElement;
034:        import org.zkoss.zul.mesg.MZul;
035:
036:        /**
037:         * An edit box for holding a time (a java.util.Date Object , but only Hour & Minute are used.
038:         *
039:         * <p>Default {@link #getSclass}: datebox.
040:         *
041:         * <p>timebox doens't support customized format. It support HH:mm formate, where HH is hour of day and mm is minute of hour.
042:         * 
043:         * <p>timebox supports below key events.
044:         * <lu>
045:         *  <li>0-9 : set the time digit depend on the position on the inner text box.
046:         * 	<li>up : increase time digit depend on the position on the inner text box.
047:         *  <li>down : decrease time digit depend on the position on the inner text box.
048:         * 	<li>delete : clear the time to empty (null)
049:         * </lu>
050:         * @author Dennis Chen
051:         * @since 3.0.0
052:         */
053:        public class Timebox extends InputElement {
054:            private static final String DEFAULT_IMAGE = "~./zul/img/updnbtn.gif";
055:            private String _img;
056:            private TimeZone _tzone;
057:            private boolean _btnVisible = true;
058:
059:            public Timebox() {
060:                setCols(5);
061:                setMaxlength(5);
062:            }
063:
064:            public Timebox(Date date) throws WrongValueException {
065:                this ();
066:                setValue(date);
067:            }
068:
069:            /** Returns the value (in Date), might be null unless
070:             *  a constraint stops it. And, only Hour and Mintue field is effective.
071:             * @exception WrongValueException if user entered a wrong value
072:             */
073:            public Date getValue() throws WrongValueException {
074:                return (Date) getTargetValue();
075:            }
076:
077:            /** Sets the value (in Date).
078:             * If value is null, then an empty will be sent(render) to client.
079:             * If else, only the Hour and Mintue field will be sent(render) to client. 
080:             * 
081:             * @exception WrongValueException if value is wrong
082:             */
083:            public void setValue(Date value) throws WrongValueException {
084:                validate(value);
085:                setRawValue(value);
086:            }
087:
088:            /** Returns whether the button (on the right of the textbox) is visible.
089:             * <p>Default: true.
090:             */
091:            public boolean isButtonVisible() {
092:                return _btnVisible;
093:            }
094:
095:            /** Sets whether the button (on the right of the textbox) is visible.
096:             */
097:            public void setButtonVisible(boolean visible) {
098:                if (_btnVisible != visible) {
099:                    _btnVisible = visible;
100:                    smartUpdate("z.btnVisi", visible);
101:                }
102:            }
103:
104:            /** Returns the URI of the button image.
105:             */
106:            public String getImage() {
107:                return _img != null ? _img : DEFAULT_IMAGE;
108:            }
109:
110:            /** Sets the URI of the button image.
111:             *
112:             * @param img the URI of the button image. If null or empty, the default
113:             * URI is used.
114:             */
115:            public void setImage(String img) {
116:                if (img != null
117:                        && (img.length() == 0 || DEFAULT_IMAGE.equals(img)))
118:                    img = null;
119:                if (!Objects.equals(_img, img)) {
120:                    _img = img;
121:                    invalidate();
122:                }
123:            }
124:
125:            public String getInnerAttrs() {
126:                final String attrs = super .getInnerAttrs();
127:                final String style = getInnerStyle();
128:                return style.length() > 0 ? attrs + " style=\"" + style + '"'
129:                        : attrs;
130:            }
131:
132:            private String getInnerStyle() {
133:                final StringBuffer sb = new StringBuffer(32).append(HTMLs
134:                        .getTextRelevantStyle(getRealStyle()));
135:                HTMLs.appendStyle(sb, "width", getWidth());
136:                HTMLs.appendStyle(sb, "height", getHeight());
137:                return sb.toString();
138:            }
139:
140:            /** Returns the time zone that this time box belongs to, or null if
141:             * the default time zone is used.
142:             * <p>The default time zone is determined by {@link TimeZones#getCurrent}.
143:             */
144:            public TimeZone getTimeZone() {
145:                return _tzone;
146:            }
147:
148:            /** Sets the time zone that this time box belongs to, or null if
149:             * the default time zone is used.
150:             * <p>The default time zone is determined by {@link TimeZones#getCurrent}.
151:             */
152:            public void setTimeZone(TimeZone tzone) {
153:                _tzone = tzone;
154:            }
155:
156:            protected Object coerceFromString(String value)
157:                    throws WrongValueException {
158:                //null or empty string,
159:                if (value == null || value.length() == 0) {
160:                    return null;
161:                }
162:
163:                final DateFormat df = getDateFormat();
164:                final Date date;
165:                try {
166:                    date = df.parse(value);
167:                } catch (ParseException ex) {
168:                    throw showCustomError(new WrongValueException(this ,
169:                            MZul.DATE_REQUIRED, new Object[] { value, "HH:mm" }));
170:                }
171:                return date;
172:            }
173:
174:            protected String coerceToString(Object value) {
175:                if (value == null)
176:                    return "";
177:                final DateFormat df = getDateFormat();
178:                return value != null ? df.format((Date) value) : "";
179:            }
180:
181:            /** Returns the date format of the time only,
182:             *
183:             * <p>Default: it uses SimpleDateFormat to format the date.
184:             */
185:            protected DateFormat getDateFormat() {
186:                String fmt = "HH:mm";
187:                final DateFormat df = new SimpleDateFormat(fmt, Locales
188:                        .getCurrent());
189:                final TimeZone tz = _tzone != null ? _tzone : TimeZones
190:                        .getCurrent();
191:                df.setTimeZone(tz);
192:                return df;
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.