Source Code Cross Referenced for XDateEdit.java in  » XML-UI » xui32 » com » xoetrope » awt » 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 » xui32 » com.xoetrope.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.awt;
002:
003:        import com.xoetrope.awt.date.XDateChooserDialog;
004:        import java.text.ParsePosition;
005:        import java.text.SimpleDateFormat;
006:        import java.util.Date;
007:
008:        import java.awt.BorderLayout;
009:        import java.awt.Dimension;
010:        import java.awt.Panel;
011:        import java.awt.Point;
012:        import java.awt.event.ActionEvent;
013:        import java.awt.event.ActionListener;
014:
015:        import net.xoetrope.awt.XButton;
016:        import net.xoetrope.awt.XEdit;
017:        import net.xoetrope.xui.XAttributedComponent;
018:        import net.xoetrope.xui.XTextHolder;
019:        import java.awt.event.FocusListener;
020:        import java.awt.event.FocusEvent;
021:        import java.text.DateFormat;
022:        import java.text.ParseException;
023:        import net.xoetrope.xui.XEventHandler;
024:        import net.xoetrope.xui.XPage;
025:
026:        /**
027:         * An edit control with a button that pops up a DateChooser. When the DateChooser
028:         * is displayed it will show the date entered in the edit control. The date will
029:         * also be updated when the chooser is closed.
030:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
031:         * the GNU Public License (GPL), please see license.txt for more details. If
032:         * you make commercial use of this software you must purchase a commercial
033:         * license from Xoetrope.</p>
034:         * <p>$Revision: 1.7 $</p>
035:         */
036:        public class XDateEdit extends Panel implements  XAttributedComponent,
037:                ActionListener, XTextHolder, FocusListener {
038:            XEdit dateEdit;
039:            XButton popupBtn;
040:            String dateFormat;
041:
042:            public XDateEdit() {
043:                dateFormat = "dd/MM/yyyy";
044:
045:                dateEdit = new XEdit();
046:                popupBtn = new XButton();
047:                popupBtn.setText("...");
048:
049:                setLayout(new BorderLayout());
050:                add(dateEdit, BorderLayout.CENTER);
051:                add(popupBtn, BorderLayout.EAST);
052:
053:                popupBtn.addActionListener(this );
054:            }
055:
056:            /**
057:             * Gets the content of the date field
058:             * @return the date edit value
059:             */
060:            public String getText() {
061:                return dateEdit.getText();
062:            }
063:
064:            /**
065:             * Gets the content of the date field as a date
066:             * @return the date value
067:             */
068:            public Date getDate() {
069:                try {
070:                    return DateFormat.getDateInstance().parse(
071:                            dateEdit.getText());
072:                } catch (ParseException pe) {
073:                }
074:                return null;
075:            }
076:
077:            /**
078:             * Sets the content of the edit field
079:             * @param s the new date string
080:             */
081:            public void setText(String s) {
082:                dateEdit.setText(s);
083:            }
084:
085:            /**
086:             * Set one or more attributes of the component. Currently this handles the
087:             * attributes
088:             * <OL>
089:             * <LI>format, value=the date format</LI>
090:             * </OL>
091:             * @param attribName the attribute name
092:             * @param attribValue the attribute value
093:             * @return 0 for success, non zero otherwise
094:             */
095:            public int setAttribute(String attribName, Object attribValue) {
096:                if (attribName.equalsIgnoreCase("format"))
097:                    dateFormat = (String) attribValue;
098:
099:                resize();
100:                return 0;
101:            }
102:
103:            /**
104:             * Respond to the button click by showing the date chooser control.
105:             * @param e
106:             */
107:            public void actionPerformed(ActionEvent e) {
108:                if (e.getSource() == popupBtn) {
109:                    Point pt = popupBtn.getLocationOnScreen();
110:                    XDateChooserDialog dpd = new XDateChooserDialog(pt);
111:                    try {
112:                        ParsePosition pp = new ParsePosition(0);
113:                        SimpleDateFormat formatter = new SimpleDateFormat(
114:                                dateFormat);
115:                        formatter.setLenient(false);
116:                        dpd.setDate(formatter.parse(dateEdit.getText(), pp));
117:                    } catch (Exception ex) {
118:                    }
119:                    dpd.showDialog(this , null);
120:                    dateEdit.setText(new SimpleDateFormat(dateFormat)
121:                            .format(dpd.getDate()));
122:                    repaint();
123:                }
124:            }
125:
126:            /**
127:             * Add a focus listener for the child edit controls
128:             * @param fl
129:             */
130:            public void addFocusListener(FocusListener fl) {
131:                dateEdit.addFocusListener(this );
132:            }
133:
134:            private void resize() {
135:                Dimension size = getSize();
136:                if (dateEdit.getHeight() == 0) {
137:                    dateEdit.setSize(size.width - 20, size.height);
138:                    popupBtn.setSize(20, size.height);
139:
140:                    doLayout();
141:                }
142:            }
143:
144:            /**
145:             * Trap the focus events and forward to the parent listner
146:             * @param e
147:             */
148:            public void focusLost(FocusEvent e) {
149:                //    FocusEvent e2 = new FocusEvent( this, e.getID(), e.isTemporary(), e.getOppositeComponent());
150:                FocusEvent e2 = new FocusEvent(this , e.getID(), e.isTemporary());
151:                ((XEventHandler) ((XPage) getParent()).getEventHandler())
152:                        .focusLost(e2);
153:            }
154:
155:            /**
156:             * Trap the focus events and forward to the parent listner
157:             * @param e
158:             */
159:            public void focusGained(FocusEvent e) {
160:                //    FocusEvent e2 = new FocusEvent( this, e.getID(), e.isTemporary(), e.getOppositeComponent());
161:                FocusEvent e2 = new FocusEvent(this , e.getID(), e.isTemporary());
162:                ((XEventHandler) ((XPage) getParent()).getEventHandler())
163:                        .focusGained(e2);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.