Source Code Cross Referenced for Field.java in  » Web-Framework » jWic » de » jwic » base » 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 » Web Framework » jWic » de.jwic.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 jWic group (http://www.jwic.de)
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         *
016:         * de.jwic.base.Field
017:         * Created on 28.08.2005
018:         * $Id: Field.java,v 1.2 2006/08/14 09:34:59 lordsam Exp $
019:         */
020:        package de.jwic.base;
021:
022:        import java.io.Serializable;
023:        import java.util.Arrays;
024:
025:        import de.jwic.events.ValueChangedEvent;
026:        import de.jwic.events.ValueChangedListener;
027:        import de.jwic.util.StringTool;
028:
029:        /**
030:         * Represents a field on an HTML form that contains a string value or an array
031:         * of string values. A field is created for a control and is linked to it with
032:         * its name.<p> 
033:         * The field offers an ValueChangedEvent.
034:         * 
035:         * @author Florian Lippisch
036:         * @version $Revision: 1.2 $
037:         */
038:        public class Field implements  Serializable {
039:
040:            private static final long serialVersionUID = 1L;
041:
042:            private String name = null;
043:            private Control control = null;
044:            private String[] values = null;
045:
046:            private ValueChangedListener[] listeners = null;
047:
048:            /**
049:             * Creates a new field with an autogenerated name.
050:             * @param parent
051:             */
052:            public Field(Control parent) {
053:                this (parent, null);
054:            }
055:
056:            /**
057:             * Creates a new field with the given name.
058:             * @param parent
059:             * @param name
060:             */
061:            public Field(Control parent, String name) {
062:                this .control = parent;
063:                this .name = name;
064:                control.addField(this );
065:            }
066:
067:            /**
068:             * Removes the field from its container.
069:             *
070:             */
071:            public void destroy() {
072:                if (control != null) {
073:                    control.removeField(this );
074:                }
075:            }
076:
077:            /**
078:             * Add a ValueChangedListener to this field.
079:             * @param listener
080:             */
081:            public synchronized void addValueChangedListener(
082:                    ValueChangedListener listener) {
083:                if (listeners == null) {
084:                    listeners = new ValueChangedListener[] { listener };
085:                } else {
086:                    ValueChangedListener[] tmp = new ValueChangedListener[listeners.length + 1];
087:                    System.arraycopy(listeners, 0, tmp, 0, listeners.length);
088:                    tmp[listeners.length] = listener;
089:                    listeners = tmp;
090:                }
091:            }
092:
093:            /**
094:             * Removes the specified listener from the field.
095:             * @param listener
096:             */
097:            public synchronized void removeValueChangedListener(
098:                    ValueChangedListener listener) {
099:                if (listeners != null && listeners.length > 0) {
100:                    ValueChangedListener[] tmp = new ValueChangedListener[listeners.length - 1];
101:                    int idx = 0;
102:                    for (int i = 0; i < listeners.length; i++) {
103:                        if (listeners[i] != listener) {
104:                            if (idx == tmp.length) {
105:                                // the listener was not registerd
106:                                return; // early exit
107:                            }
108:                            tmp[idx++] = listeners[i];
109:                        }
110:                    }
111:                    listeners = tmp;
112:                }
113:            }
114:
115:            /**
116:             * Fires the value changed event.
117:             * @param event
118:             */
119:            protected void fireValueChangedEvent(ValueChangedEvent event) {
120:                if (listeners != null) {
121:                    for (int i = 0; i < listeners.length; i++) {
122:                        listeners[i].valueChanged(event);
123:                    }
124:                }
125:            }
126:
127:            /**
128:             * @return Returns the name.
129:             */
130:            public String getName() {
131:                return name;
132:            }
133:
134:            /**
135:             * @param name The name to set.
136:             */
137:            void setName(String name) {
138:                this .name = name;
139:            }
140:
141:            /**
142:             * Returns the id of the field. This property must return a unique id of
143:             * the field that can be used to identify the field when it is submited
144:             * by the browser.
145:             * @return
146:             */
147:            public String getId() {
148:                return "fld_" + control.getControlID() + "." + name;
149:            }
150:
151:            /**
152:             * Returns the values as a string. If the value is an array, the values
153:             * are seperated by a semmicolon.
154:             * @return
155:             */
156:            public String getValue() {
157:                return StringTool.getSingleString(values);
158:            }
159:
160:            /**
161:             * Returns the values as array.
162:             * @return Returns the values.
163:             */
164:            public String[] getValues() {
165:                return values;
166:            }
167:
168:            /**
169:             * Set the value of the field.
170:             * @param value
171:             */
172:            public void setValue(String value) {
173:                setValues(new String[] { value });
174:            }
175:
176:            /**
177:             * Sets the values as array.
178:             * @param values The values to set.
179:             */
180:            public void setValues(String[] values) {
181:                if (!Arrays.equals(this .values, values)) {
182:                    ValueChangedEvent event = new ValueChangedEvent(this ,
183:                            this .values, values);
184:                    this .values = values;
185:                    fireValueChangedEvent(event);
186:                }
187:            }
188:
189:            /**
190:             * Set the values of the field as array without fireing the ValueChangedEvent. The
191:             * event is added to the ValueChangedQueue for later processing.
192:             * @param values
193:             * @param queue
194:             */
195:            public void batchUpdate(String[] newValues, ValueChangedQueue queue) {
196:                if (!Arrays.equals(this .values, newValues)) {
197:                    ValueChangedEvent event = new ValueChangedEvent(this,
198:                            this.values, newValues);
199:                    this.values = newValues;
200:                    if (listeners != null) {
201:                        queue.valueChanged(listeners, event);
202:                    }
203:                }
204:            }
205:
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.