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


001:        // IPTemplateAttributeEditor.java
002:        // $Id: IPTextField.java,v 1.7 2000/08/16 21:37:56 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1997.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.tools.widgets;
007:
008:        import java.awt.AWTEventMulticaster;
009:        import java.awt.Component;
010:        import java.awt.Container;
011:        import java.awt.Dimension;
012:        import java.awt.GridLayout;
013:        import java.awt.Panel;
014:        import java.awt.TextComponent;
015:        import java.awt.TextField;
016:
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.ActionListener;
019:        import java.awt.event.ComponentEvent;
020:        import java.awt.event.InputEvent;
021:        import java.awt.event.KeyAdapter;
022:        import java.awt.event.KeyEvent;
023:        import java.awt.event.TextEvent;
024:        import java.awt.event.TextListener;
025:
026:        import java.util.EventObject;
027:        import java.util.StringTokenizer;
028:
029:        /**
030:         * IPTextField :
031:         * @author Benoit Mahe <bmahe@sophia.inria.fr>
032:         */
033:
034:        public class IPTextField extends Panel implements  TextEditable {
035:
036:            class IntegerListener extends KeyAdapter {
037:
038:                IPTextField comp = null;
039:
040:                // filter the non-numeric char
041:                public void keyPressed(KeyEvent ke) {
042:                    if (ke.getKeyCode() == KeyEvent.VK_DELETE
043:                            || ke.getKeyCode() == KeyEvent.VK_BACK_SPACE
044:                            || ke.getKeyCode() == KeyEvent.VK_UP
045:                            || ke.getKeyCode() == KeyEvent.VK_DOWN
046:                            || ke.getKeyCode() == KeyEvent.VK_LEFT
047:                            || ke.getKeyCode() == KeyEvent.VK_RIGHT)
048:                        return;
049:                    //I'm sure of that
050:                    TextField target = (TextField) ke.getComponent();
051:                    if (ke.getKeyChar() == '*') {
052:                        ke.consume();
053:                        target.setText("*");
054:                        requestFocusOnNextField(target);
055:                    } else if (ke.getKeyCode() == KeyEvent.VK_SPACE) {
056:                        ke.consume();
057:                        requestFocusOnNextField(target);
058:                    } else if (ke.getKeyCode() == KeyEvent.VK_TAB
059:                            || ke.getKeyCode() == KeyEvent.VK_SPACE
060:                            || ke.getKeyCode() == KeyEvent.VK_ENTER) {
061:                        requestFocusOnNextField(target);
062:                    } else if (!(ke.getKeyChar() >= '0' && ke.getKeyChar() <= '9')) {
063:                        ke.consume();
064:                    }
065:                }
066:
067:                void requestFocusOnNextField(TextField target) {
068:                    if (target == comp.fields[0])
069:                        comp.fields[1].requestFocus();
070:                    else if (target == comp.fields[1])
071:                        comp.fields[2].requestFocus();
072:                    else if (target == comp.fields[2])
073:                        comp.fields[3].requestFocus();
074:                    else if (target == comp.fields[3]) {
075:                        comp.fireActionEvent();
076:                        comp.fields[0].requestFocus();
077:                        comp.fields[0].setText("");
078:                        comp.fields[1].setText("");
079:                        comp.fields[2].setText("");
080:                        comp.fields[3].setText("");
081:                    }
082:                }
083:
084:                IntegerListener(IPTextField comp) {
085:                    this .comp = comp;
086:                }
087:
088:            }
089:
090:            class IPListener implements  TextListener {
091:
092:                IPTextField comp = null;
093:
094:                public void textValueChanged(TextEvent e) {
095:                    // I'm sure of that
096:                    TextField target = (TextField) e.getSource();
097:                    String IP = target.getText();
098:
099:                    if (IP.length() < 3)
100:                        return;
101:                    if (IP.length() == 4) {
102:                        target.setText(IP.substring(3));
103:                        return;
104:                    }
105:
106:                    try {
107:                        short ip = Short.parseShort(IP);
108:                        if (ip > 255) {
109:                            target.setText("");
110:                            return;
111:                        }
112:                    } catch (NumberFormatException ex) {
113:                        target.setText("");
114:                        return;
115:                    }
116:                    if (target == comp.fields[0])
117:                        comp.fields[1].requestFocus();
118:                    else if (target == comp.fields[1])
119:                        comp.fields[2].requestFocus();
120:                    else if (target == comp.fields[2])
121:                        comp.fields[3].requestFocus();
122:                }
123:
124:                IPListener(IPTextField comp) {
125:                    this .comp = comp;
126:                }
127:            }
128:
129:            //////// The IPTextField itself
130:
131:            protected TextField[] fields = null;
132:            transient ActionListener actionListener;
133:            String command = "";
134:
135:            /**
136:             * Adds the specified action listener to recieve action events from 
137:             * this IPTextField. 
138:             * @param al - the action listener.
139:             */
140:            public synchronized void addActionListener(ActionListener al) {
141:                actionListener = AWTEventMulticaster.add(actionListener, al);
142:            }
143:
144:            /**
145:             * Removes the specified action listener so that it no longer receives 
146:             * action events from IPTextField. 
147:             * @param al - the action listener.
148:             */
149:            public synchronized void removeActionListener(ActionListener al) {
150:                actionListener = AWTEventMulticaster.remove(actionListener, al);
151:            }
152:
153:            /**
154:             * fire a new ActionEvent and process it, if some listeners are listening
155:             */
156:
157:            protected void fireActionEvent() {
158:                if (actionListener != null) {
159:                    ActionEvent ae = new ActionEvent(this ,
160:                            ActionEvent.ACTION_PERFORMED, command);
161:                    actionListener.actionPerformed(ae);
162:                }
163:            }
164:
165:            private String getFieldValue(TextField field) {
166:                String svalue = field.getText();
167:                if (svalue == null)
168:                    return "0";
169:                if (svalue.length() == 0)
170:                    return "0";
171:                else
172:                    return svalue;
173:            }
174:
175:            /**
176:             * Gets the text that is presented by this IPTextField.
177:             */
178:            public String getText() {
179:                return (getFieldValue(fields[0]) + "."
180:                        + getFieldValue(fields[1]) + "."
181:                        + getFieldValue(fields[2]) + "." + getFieldValue(fields[3]));
182:            }
183:
184:            /**
185:             * Sets the text that is presented by this IPTextField to be the specified 
186:             * text. 
187:             * @param text - the new text
188:             */
189:            public void setText(String IPT) {
190:                StringTokenizer st = new StringTokenizer(IPT, ".");
191:                int i = 0;
192:                while (i < 4 && st.hasMoreTokens())
193:                    fields[i++].setText(st.nextToken());
194:            }
195:
196:            /**
197:             * Check if the current text value and the default value are different.
198:             */
199:            public boolean updated() {
200:                return (!getText().equals("0.0.0.0"));
201:            }
202:
203:            /**
204:             * Sets the text at its default value
205:             */
206:            public void setDefault() {
207:                fields[0].setText("");
208:                fields[1].setText("");
209:                fields[2].setText("");
210:                fields[3].setText("");
211:            }
212:
213:            public Dimension getMinimumSize() {
214:                return new Dimension(4 * fields[0].getMinimumSize().width,
215:                        fields[0].getMinimumSize().height);
216:            }
217:
218:            public Dimension getPreferredSize() {
219:                return getMinimumSize();
220:            }
221:
222:            public IPTextField() {
223:                IntegerListener intlistener = new IntegerListener(this );
224:                IPListener iplistener = new IPListener(this );
225:
226:                fields = new TextField[4];
227:                for (int i = 0; i < fields.length; i++) {
228:                    fields[i] = new TextField(3);
229:                    fields[i].addTextListener(iplistener);
230:                    fields[i].addKeyListener(intlistener);
231:                }
232:                setLayout(new GridLayout(1, 4));
233:                add(fields[0]);
234:                add(fields[1]);
235:                add(fields[2]);
236:                add(fields[3]);
237:
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.