Source Code Cross Referenced for TextField.java in  » XML-UI » xmlgui » org » beryl » gui » widgets » 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 » XML UI » xmlgui » org.beryl.gui.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui.widgets;
023:
024:        import java.awt.Color;
025:        import java.awt.Component;
026:        import java.awt.Dimension;
027:        import java.awt.event.ActionEvent;
028:        import java.awt.event.ActionListener;
029:
030:        import javax.swing.JPasswordField;
031:        import javax.swing.JTextField;
032:        import javax.swing.event.DocumentEvent;
033:        import javax.swing.event.DocumentListener;
034:
035:        import org.beryl.gui.GUIEvent;
036:        import org.beryl.gui.GUIEventListener;
037:        import org.beryl.gui.GUIException;
038:        import org.beryl.gui.Widget;
039:        import org.beryl.gui.WidgetInfo;
040:        import org.beryl.gui.model.MapChangeEvent;
041:        import org.beryl.gui.model.MapDataModel;
042:        import org.beryl.gui.model.ModelChangeEvent;
043:        import org.beryl.gui.validators.ValidationException;
044:
045:        public class TextField extends Widget {
046:            protected static WidgetInfo textFieldInfo = null;
047:            public static final Color DEFAULT_COLOR = new Color(255, 255, 255);
048:            public static final Color ERROR_COLOR = new Color(255, 200, 200);
049:
050:            protected JTextField textField = null;
051:            private String key = null;
052:            private boolean sendEvents = true;
053:            private boolean processEvents = true;
054:
055:            static {
056:                textFieldInfo = new WidgetInfo(TextField.class, widgetInfo);
057:                textFieldInfo.addProperty("key", "string", "");
058:                textFieldInfo.addEvent("activated");
059:            };
060:
061:            public TextField(Widget parent, String name) throws GUIException {
062:                super (parent, name);
063:                textField = new JTextField();
064:            }
065:
066:            public void setProperty(String name, Object value)
067:                    throws GUIException {
068:                if ("key".equals(name))
069:                    key = (String) value;
070:                else
071:                    super .setProperty(name, value);
072:            }
073:
074:            private void reload() throws GUIException {
075:                MapDataModel model = getDataModel();
076:                if (model != null && key != null) {
077:                    try {
078:                        processEvents = false;
079:                        String value = (String) model.getValue(key);
080:                        if (value != null) {
081:                            textField.setText(value);
082:                        } else {
083:                            String text = null;
084:                            if (textField instanceof  JPasswordField)
085:                                text = new String(((JPasswordField) textField)
086:                                        .getPassword());
087:                            else
088:                                text = textField.getText();
089:                            model.setValue(TextField.this , key, text);
090:                        }
091:                    } finally {
092:                        processEvents = true;
093:                    }
094:                }
095:            }
096:
097:            public String getText() {
098:                return textField.getText();
099:            }
100:
101:            public void validate() throws ValidationException, GUIException {
102:                if (hasValidators()) {
103:                    try {
104:                        super .validate();
105:                        if (textField.getBackground() != DEFAULT_COLOR) {
106:                            textField.setBackground(DEFAULT_COLOR);
107:                        }
108:                        if (getParentWidget() instanceof  LabeledWidget) {
109:                            ((LabeledWidget) getParentWidget()).clearError();
110:                        }
111:                    } catch (ValidationException e) {
112:                        textField.setBackground(ERROR_COLOR);
113:                        if (getParentWidget() instanceof  LabeledWidget) {
114:                            ((LabeledWidget) getParentWidget()).setError(e);
115:                        }
116:                        throw e;
117:                    }
118:                }
119:            }
120:
121:            public void modelChanged(ModelChangeEvent e) throws GUIException {
122:                if (processEvents) {
123:                    sendEvents = false;
124:                    try {
125:                        if (e.getSource() == this ) {
126:                            /* New data model */
127:                            reload();
128:                            try {
129:                                validate();
130:                            } catch (ValidationException ex) {
131:                                /* Ignore, error status is displayed already */
132:                            }
133:                        } else if (e instanceof  MapChangeEvent) {
134:                            MapChangeEvent event = (MapChangeEvent) e;
135:                            if (event.getKey() == null) {
136:                                reload();
137:                            } else if (event.getKey().equals(key)) {
138:                                textField.setText((String) event.getNewValue());
139:                            }
140:                            try {
141:                                validate();
142:                            } catch (ValidationException ex) {
143:                                /* Ignore, error status is displayed already */
144:                            }
145:                        }
146:                    } finally {
147:                        sendEvents = true;
148:                    }
149:                }
150:            }
151:
152:            public void finalizeConstruction() {
153:                textField.setPreferredSize(new Dimension(MAX_WIDTH,
154:                        DEFAULT_HEIGHT));
155:                textField.getDocument().addDocumentListener(
156:                        new DocumentListener() {
157:                            public void insertUpdate(DocumentEvent e) {
158:                                changedUpdate(e);
159:                            }
160:
161:                            public void removeUpdate(DocumentEvent e) {
162:                                changedUpdate(e);
163:                            }
164:
165:                            public void changedUpdate(DocumentEvent e) {
166:                                if (sendEvents) {
167:                                    try {
168:                                        MapDataModel model = getDataModel();
169:                                        if (model != null && key != null) {
170:                                            String text = null;
171:                                            if (textField instanceof  JPasswordField)
172:                                                text = new String(
173:                                                        ((JPasswordField) textField)
174:                                                                .getPassword());
175:                                            else
176:                                                text = textField.getText();
177:                                            try {
178:                                                processEvents = false;
179:                                                model.setValue(TextField.this ,
180:                                                        key, text);
181:                                            } finally {
182:                                                processEvents = true;
183:                                            }
184:                                            try {
185:                                                validate();
186:                                            } catch (ValidationException ex) {
187:                                                /* Ignore, error status is displayed already */
188:                                            }
189:                                        }
190:                                    } catch (GUIException ex) {
191:                                        throw new RuntimeException(ex);
192:                                    }
193:                                }
194:                            }
195:                        });
196:            }
197:
198:            public void addListener(String event, final String name,
199:                    final GUIEventListener listener) throws GUIException {
200:                if ("activated".equals(event)) {
201:                    textField.addActionListener(new ActionListener() {
202:                        public void actionPerformed(ActionEvent e) {
203:                            listener.eventOccured(new GUIEvent(TextField.this ,
204:                                    name, e));
205:                        }
206:                    });
207:                } else {
208:                    super .addListener(event, name, listener);
209:                }
210:            }
211:
212:            public Component getWidget() {
213:                return textField;
214:            }
215:
216:            public WidgetInfo getWidgetInfo() {
217:                return textFieldInfo;
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.