Source Code Cross Referenced for FormManager.java in  » Web-Server » Jigsaw » org » w3c » tools » forms » 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 Server » Jigsaw » org.w3c.tools.forms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // FormManager.java
002:        // $Id: FormManager.java,v 1.4 2000/08/16 21:37:49 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1996.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.tools.forms;
007:
008:        import java.awt.Component;
009:        import java.awt.Container;
010:        import java.awt.Dimension;
011:        import java.awt.Frame;
012:        import java.awt.Panel;
013:        import java.awt.Window;
014:
015:        import java.util.Vector;
016:
017:        public class FormManager {
018:            /**
019:             * Our list of field, at description time.
020:             */
021:            protected Vector vfields = null;
022:            /**
023:             * Our list of fields, at runtime.
024:             */
025:            protected FormField fields[] = null;
026:            /**
027:             * The current field being edited, as an index in our fields.
028:             */
029:            protected int cursor = 0;
030:            /**
031:             * Is this form description completed ?
032:             */
033:            protected boolean finished = false;
034:            /**
035:             * The form's title.
036:             */
037:            protected String title = null;
038:            /**
039:             * The form grphical UI.
040:             */
041:            protected FormPanel panel = null;
042:
043:            /**
044:             * Callback for field value's change.
045:             * @param field The field that changed.
046:             */
047:
048:            public void notifyChange(FormField field) {
049:                return;
050:            }
051:
052:            /**
053:             * Construct the Panel to edit the form.
054:             * @return A Panel instance, layed out for this form edition.
055:             */
056:
057:            protected FormPanel createPanel() {
058:                panel = new FormPanel(this );
059:                for (int i = 0; i < fields.length; i++)
060:                    panel.addField(fields[i].getTitle(), fields[i].getEditor());
061:                return panel;
062:            }
063:
064:            /**
065:             * Move to the field whose index is given.
066:             * @param n The field to move to.
067:             */
068:
069:            public void gotoField(int idx) {
070:                if ((idx < 0) || (idx >= fields.length))
071:                    throw new RuntimeException("invalid form cursor:" + cursor);
072:                cursor = idx;
073:                fields[cursor].getEditor().requestFocus();
074:            }
075:
076:            /**
077:             * Move the focus to the next editable field.
078:             */
079:
080:            public void nextField() {
081:                gotoField((cursor + 1) % fields.length);
082:            }
083:
084:            /**
085:             * Some of our field got the focus, update our cursor.
086:             * @param field The field that now has the focus.
087:             */
088:
089:            protected void gotFocus(FormField field) {
090:                for (int i = 0; i < fields.length; i++) {
091:                    if (fields[i] == field) {
092:                        cursor = i;
093:                        break;
094:                    }
095:                }
096:            }
097:
098:            /**
099:             * Add a field to the form.
100:             * @param name The field name (the key by wich this field will be 
101:             *    accessible.)
102:             * @param field The field to be created.
103:             */
104:
105:            public void addField(FormField field) {
106:                if (finished)
107:                    throw new RuntimeException("This form has been finished.");
108:                vfields.addElement(field);
109:            }
110:
111:            /**
112:             * Mark the description of the form as completed.
113:             * Once this method is called, no more fields can be added to the form.
114:             * This method will perform any required compilation of the form.
115:             */
116:
117:            public void finish() {
118:                if (finished)
119:                    return;
120:                finished = true;
121:                // Compile the vfields into fields, for fast access and no casts:
122:                fields = new FormField[vfields.size()];
123:                vfields.copyInto(fields);
124:                vfields = null;
125:            }
126:
127:            /**
128:             * Get the graphical object for editing the form.
129:             */
130:
131:            public Panel getPanel() {
132:                if (!finished)
133:                    finish();
134:                if (panel == null)
135:                    panel = createPanel();
136:                return panel;
137:            }
138:
139:            /**
140:             * Create a new, empty form.
141:             * @param title The form's title.
142:             */
143:
144:            public FormManager(String title) {
145:                this .title = title;
146:                this .vfields = new Vector();
147:            }
148:
149:            /**
150:             * Test.
151:             * @exception IllegalFieldValueException test
152:             */
153:
154:            public static void main(String args[])
155:                    throws IllegalFieldValueException {
156:                FormManager manager = new FormManager("test");
157:                FormField field = null;
158:                // Create the first field:
159:                field = new StringField(manager, "field-1", "title-1",
160:                        "value-1");
161:                manager.addField(field);
162:                // Create the second field:
163:                field = new StringField(manager, "field-2", "title-2",
164:                        "value-2");
165:                manager.addField(field);
166:                // Create an Integer field;
167:                field = new IntegerField(manager, "field-3", "title-3", 10);
168:                manager.addField(field);
169:                // Create an option field:
170:                String opts[] = { "option-1", "option-2", "foo", "bar", "etc" };
171:                field = new OptionField(manager, "field-4", "title-4", opts, 0);
172:                manager.addField(field);
173:                // Create a boolean field.
174:                field = new BooleanField(manager, "field-5", "title-5", true);
175:                manager.addField(field);
176:                // Create a RangedInteger
177:                field = new RangedIntegerField(manager, "field-6", "title-6",
178:                        0, 10000, 5000);
179:                manager.addField(field);
180:                // Display the resulting GUI:
181:                Panel p = manager.getPanel();
182:                Frame toplevel = new Frame("form test");
183:                toplevel.add("Center", p);
184:                toplevel.pack();
185:                toplevel.resize(toplevel.preferredSize());
186:                toplevel.show();
187:
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.