Source Code Cross Referenced for RestrictedTextField.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » util » 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 » Content Management System » contelligent » de.finix.contelligent.client.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.util;
019:
020:        import java.awt.Component;
021:        import java.lang.reflect.Method;
022:
023:        import javax.swing.ComboBoxEditor;
024:        import javax.swing.JTextField;
025:
026:        /**
027:         * {@link JTextField} that only allows a defined set of characters as input. It
028:         * used a {@ RestrictedDocument} for that purpose. Every check is done there.
029:         * 
030:         * @see RestrictedDocument
031:         */
032:        public class RestrictedTextField extends JTextField implements 
033:                ComboBoxEditor {
034:
035:            protected RestrictedDocument rDoc;
036:
037:            protected Object item = null;
038:
039:            /**
040:             * Creates a new empty RestrictedTextField.
041:             */
042:            public RestrictedTextField() {
043:                super ();
044:                init();
045:            }
046:
047:            /**
048:             * Creates a new RestrictedTextField initally containting <code>text</code>
049:             * 
050:             * @param text
051:             *            initial text
052:             */
053:            public RestrictedTextField(String text) {
054:                super (text);
055:                init();
056:                setText(text);
057:            }
058:
059:            /**
060:             * Sets the set of explicitely allowed characters in text field.
061:             */
062:            public void setAllowString(String allowString) {
063:                rDoc.setAllowString(allowString);
064:            }
065:
066:            /**
067:             * Gets the set of explicitely allowed characters in text field.
068:             */
069:            public String getAllowString() {
070:                String allow = rDoc.getAllowString();
071:                return (allow == null) ? "" : allow;
072:            }
073:
074:            /**
075:             * Sets the set of characters explicitely not allowed in text field.
076:             */
077:            public void setDenyString(String denyString) {
078:                rDoc.setDenyString(denyString);
079:            }
080:
081:            /**
082:             * Gets the set of characters explicitely not allowed in text field.
083:             */
084:            public String getDenyString() {
085:                String denyString = rDoc.getDenyString();
086:                return (denyString == null) ? "" : denyString;
087:            }
088:
089:            /**
090:             * Sets the the maximum length of characters allowed in text field.
091:             * 
092:             * @param maxLength
093:             *            the maximum length or <code>-1</code> if unlimited
094:             */
095:            public void setMaxLength(int maxLength) {
096:                rDoc.setMaxLength(maxLength);
097:            }
098:
099:            /**
100:             * Gets the the maximum length of characters allowed in text field.
101:             * 
102:             * @return the maximum length or <code>-1</code> if unlimited
103:             */
104:            public int getMaxLength() {
105:                return rDoc.getMaxLength();
106:            }
107:
108:            /**
109:             * Checks if the text of this text field is valid.
110:             */
111:            public boolean isStringValid() {
112:                return isStringValid(getText());
113:            }
114:
115:            /**
116:             * Checks if the given text is valid.
117:             */
118:            public boolean isStringValid(String text) {
119:                if (text == null) {
120:                    return true;
121:                }
122:                return rDoc.inputOK(text);
123:            }
124:
125:            protected void init() {
126:                rDoc = new RestrictedDocument();
127:                setDocument(rDoc);
128:            }
129:
130:            public Component getEditorComponent() {
131:                return this ;
132:            }
133:
134:            public void setItem(Object o) {
135:                if (o != null) {
136:                    setText(o.toString());
137:                    item = o;
138:                } else {
139:                    setText("");
140:                }
141:            }
142:
143:            // partly copied from BasicComboBoxEditor
144:            public Object getItem() {
145:                Object newValue = getText();
146:
147:                if (item != null && !(item instanceof  String)) {
148:                    // The original value is not a string. Should return the value in
149:                    // it's
150:                    // original type.
151:                    if (newValue.equals(item.toString())) {
152:                        return item;
153:                    } else {
154:                        // Must take the value from the editor and get the value and
155:                        // cast it to the new type.
156:                        Class clazz = item.getClass();
157:                        try {
158:                            Method method = clazz.getMethod("valueOf",
159:                                    new Class[] { String.class });
160:                            newValue = method.invoke(item,
161:                                    new Object[] { getText() });
162:                        } catch (Exception ex) {
163:                            // Fail silently and return the newValue (a String object)
164:                        }
165:                    }
166:                }
167:                return newValue;
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.