Source Code Cross Referenced for HtmlZipCodeComponent.java in  » J2EE » Sofia » com » salmonllc » html » 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 » Sofia » com.salmonllc.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.html;
002:
003:        /////////////////////////
004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlZipCodeComponent.java $
005:        //$Author: Dan $
006:        //$Revision: 11 $
007:        //$Modtime: 10/20/03 4:14p $
008:        /////////////////////////
009:
010:        import java.util.Hashtable;
011:
012:        import com.salmonllc.html.events.ValueChangedEvent;
013:
014:        /**
015:         * This class creates an edit for a zip code
016:         */
017:        public class HtmlZipCodeComponent extends HtmlFormComponent {
018:            protected HtmlTextEdit _editZip;
019:            private boolean _extendedZip = false;
020:            private String _zip, _zip5, _zip4;
021:
022:            /**
023:             * @param name		Name of component.
024:             * @param p			Page containing component.
025:             */
026:            public HtmlZipCodeComponent(String name, HtmlPage p) {
027:                this (name, p, false);
028:
029:            }
030:
031:            /** @param name java.lang.String
032:             * @param p com.salmonllc.html.HtmlPage
033:             * @param extendedZip boolean
034:             */
035:            public HtmlZipCodeComponent(String name, HtmlPage p,
036:                    boolean extendedZip) {
037:                super (name, p);
038:                _extendedZip = extendedZip;
039:                _editZip = new HtmlTextEdit(name, p);
040:                _editZip.setGenerateNewline(false);
041:                _editZip.setSize(_extendedZip ? 10 : 5);
042:                _editZip.setMaxLength(_extendedZip ? 10 : 5);
043:            }
044:
045:            public void generateHTML(java.io.PrintWriter p, int row)
046:                    throws Exception {
047:                // It is essential to call getValue() here because there may be a ValueChanged
048:                // event in the queue for this object, which needs to be removed, which getValue()
049:                // does.  The secondary calls to getValue() from the container will not
050:                // do this because there are no events associated with them.
051:                String val = getValue(row, true);
052:                if (val == null) {
053:                    _editZip.setValue(null, row);
054:                } else {
055:                    String sVal;
056:                    if (_dsBuff != null) {
057:                        if (row >= 0)
058:                            sVal = _dsBuff.getString(row, _dsColNo);
059:                        else
060:                            sVal = _dsBuff.getString(_dsColNo);
061:                    } else {
062:                        sVal = val;
063:                    }
064:                    _editZip.setValue(sVal, row);
065:                }
066:                _editZip.generateHTML(p, row);
067:                if (_visible && _enabled)
068:                    p.println("");
069:            }
070:
071:            /**
072:             * Returns the sub-component to be used for setting focus.
073:             * @return com.salmonllc.html.HtmlComponent
074:             */
075:            public HtmlComponent getFocus() {
076:                return _editZip;
077:            }
078:
079:            public boolean isNumeric(String s, int length) {
080:                for (int i = 0; i < length; i++) {
081:                    if (!Character.isDigit(s.charAt(i)))
082:                        return false;
083:                }
084:                return true;
085:            }
086:
087:            /**
088:             * Returns true if the zip code is valid
089:             */
090:            public boolean isValid() {
091:                _editZip.setValue(_zip);
092:                int length = _zip.length();
093:                if (length == 5) {
094:                    _zip5 = _zip.substring(0, 5);
095:                    _zip4 = "";
096:                    return isNumeric(_zip5, 5);
097:                } else if (length == 9) {
098:                    _zip5 = _zip.substring(0, 5);
099:                    _zip4 = _zip.substring(5);
100:                    return isNumeric(_zip5, 5) && isNumeric(_zip4, 4);
101:                } else if (length == 10 && _zip.indexOf('-') == 5) {
102:                    _zip5 = _zip.substring(0, 5);
103:                    _zip4 = _zip.substring(6);
104:                    return isNumeric(_zip5, 5) && isNumeric(_zip4, 4);
105:                } else {
106:                    return false;
107:                }
108:            }
109:
110:            public boolean processParms(Hashtable parms, int rowNo)
111:                    throws Exception {
112:
113:                if (!getVisible() || !getEnabled())
114:                    return false;
115:
116:                String oldValue;
117:                if (_dsBuff == null) {
118:                    oldValue = _editZip.getValue();
119:                } else {
120:                    String s;
121:                    if (rowNo > -1)
122:                        s = _dsBuff.getString(rowNo, _dsColNo);
123:                    else
124:                        s = _dsBuff.getString(_dsColNo);
125:                    if (s == null)
126:                        oldValue = null;
127:                    else
128:                        oldValue = s;
129:                }
130:
131:                String newValue;
132:                String name1 = _editZip.getFullName();
133:                if (rowNo > -1)
134:                    name1 += "_" + rowNo;
135:                String val[] = (String[]) parms.get(name1);
136:                if (val != null) {
137:                    _zip = newValue = val[0].trim();
138:                    if (newValue.equals(""))
139:                        newValue = null;
140:                } else {
141:                    newValue = null;
142:                }
143:
144:                // Compare old and new values and possibly create a ValueChangedEvent.
145:                if (!valuesEqual(oldValue, newValue)) {
146:                    ValueChangedEvent e = new ValueChangedEvent(getPage(),
147:                            this , getName(), getFullName(), oldValue, newValue,
148:                            rowNo, _dsColNo, _dsBuff);
149:                    addEvent(e);
150:                }
151:                return false;
152:            }
153:
154:            public void reset() {
155:                super .reset();
156:                _editZip.reset();
157:            }
158:
159:            public void setClassName(String sClass) {
160:                super .setClassName(sClass);
161:                if (_editZip != null)
162:                    _editZip.setClassName(sClass);
163:
164:            }
165:
166:            /**
167:             * Sets the font end tag for disabled mode.
168:             * @param tag java.lang.String
169:             */
170:            public void setDisabledFontEndTag(String tag) {
171:                _editZip.setDisabledFontEndTag(tag);
172:            }
173:
174:            /**
175:             * Sets the font tag for disabled mode.
176:             * @param tag java.lang.String
177:             */
178:            public void setDisabledFontStartTag(String tag) {
179:                _editZip.setDisabledFontStartTag(tag);
180:            }
181:
182:            public void setEnabled(boolean enabled) {
183:                super .setEnabled(enabled);
184:                _editZip.setEnabled(enabled);
185:            }
186:
187:            public void setParent(HtmlComponent parent) {
188:                super .setParent(parent);
189:                // This is necessary for the name to be generated correctly, else the leading
190:                // sequence of parent names will be lost.
191:                _editZip.setParent(parent);
192:
193:            }
194:
195:            public void setTheme(String sTheme) {
196:                if (sTheme == null)
197:                    return;
198:
199:                if (_editZip != null)
200:                    _editZip.setTheme(sTheme);
201:
202:            }
203:
204:            /**
205:             * @returns the access key html attribute
206:             */
207:            public String getAccessKey() {
208:                return _editZip.getAccessKey();
209:            }
210:
211:            /**
212:             * @returns the read only html attribute
213:             */
214:            public boolean getReadOnly() {
215:                return _editZip.getReadOnly();
216:            }
217:
218:            /**
219:             * @returns the tab index html attribute
220:             */
221:            public int getTabIndex() {
222:                return _editZip.getTabIndex();
223:            }
224:
225:            /**
226:             * @param sets the access key html attribute
227:             */
228:            public void setAccessKey(String val) {
229:                _editZip.setAccessKey(val);
230:
231:            }
232:
233:            /**
234:             * @param sets the read only html attribute
235:             */
236:            public void setReadOnly(boolean val) {
237:                _editZip.setReadOnly(val);
238:            }
239:
240:            /**
241:             * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
242:             */
243:            public void setTabIndex(int val) {
244:                _editZip.setTabIndex(val);
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.