Source Code Cross Referenced for IntegerPropertyEditor.java in  » Database-Client » SQL-Workbench » workbench » gui » components » 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 » Database Client » SQL Workbench » workbench.gui.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IntegerPropertyEditor.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.gui.components;
013:
014:        import java.awt.event.FocusEvent;
015:        import java.awt.event.FocusListener;
016:        import java.lang.reflect.Method;
017:
018:        import javax.swing.JTextField;
019:        import javax.swing.event.DocumentEvent;
020:        import javax.swing.event.DocumentListener;
021:
022:        import workbench.interfaces.SimplePropertyEditor;
023:        import workbench.log.LogMgr;
024:
025:        /**
026:         *
027:         * @author  support@sql-workbench.net
028:         */
029:        public class IntegerPropertyEditor extends JTextField implements 
030:                DocumentListener, SimplePropertyEditor, FocusListener {
031:            private Object source;
032:            private Method setter;
033:            private Method getter;
034:            private boolean changed;
035:            private boolean immediateUpdate = false;
036:
037:            private String propName;
038:
039:            public IntegerPropertyEditor() {
040:                super ();
041:                this .addFocusListener(this );
042:                this .addMouseListener(new TextComponentMouseListener());
043:            }
044:
045:            public void setSourceObject(Object aSource, String aProperty) {
046:                this .setSourceObject(aSource, aProperty, null);
047:            }
048:
049:            /**
050:             *	Return the value that the user entered
051:             *  as an int. If the user did not enter anything
052:             *  or not a number Integer.MIN_VALUE will be returned
053:             */
054:            public int getValue() {
055:                try {
056:                    return Integer.parseInt(this .getText());
057:                } catch (Exception e) {
058:                    return Integer.MIN_VALUE;
059:                }
060:            }
061:
062:            public void setSourceObject(Object aSource, String aProperty,
063:                    String initialText) {
064:                this .source = aSource;
065:                this .changed = false;
066:                this .propName = aProperty;
067:
068:                this .getDocument().removeDocumentListener(this );
069:
070:                if (this .source == null) {
071:                    this .setter = null;
072:                    this .getter = null;
073:                    this .setText("");
074:                    return;
075:                }
076:
077:                String propertyName = Character
078:                        .toUpperCase(aProperty.charAt(0))
079:                        + aProperty.substring(1);
080:
081:                if (initialText != null) {
082:                    this .setText(initialText);
083:                }
084:
085:                try {
086:                    String name = "get" + propertyName;
087:                    Class cls = aSource.getClass();
088:                    this .getter = cls.getMethod(name, (Class[]) null);
089:
090:                    name = "set" + propertyName;
091:                    Class[] parms = { Integer.class };
092:                    this .setter = cls.getMethod(name, parms);
093:
094:                    Integer value = (Integer) this .getter.invoke(this .source,
095:                            (Object[]) null);
096:                    if (value == null)
097:                        this .setText("");
098:                    else
099:                        this .setText(value.toString());
100:                } catch (Exception e) {
101:                    LogMgr.logError("IntegerPropertyEditor.setSourceObject()",
102:                            "Error during init", e);
103:                }
104:                this .getDocument().addDocumentListener(this );
105:            }
106:
107:            public void applyChanges() {
108:                if (!this .changed)
109:                    return;
110:                if (this .source == null)
111:                    return;
112:                if (this .setter == null)
113:                    return;
114:                Object args[] = new Object[1];
115:                try {
116:                    args[0] = new Integer(this .getValue());
117:                    this .setter.invoke(this .source, args);
118:                    this .changed = false;
119:                } catch (Exception e) {
120:                    LogMgr.logError("IntegerPropertyEditor.applyChanges()",
121:                            "Error setting value", e);
122:                }
123:            }
124:
125:            public boolean isChanged() {
126:                return this .changed;
127:            }
128:
129:            public void changedUpdate(DocumentEvent e) {
130:                documentChanged();
131:            }
132:
133:            public void insertUpdate(DocumentEvent e) {
134:                documentChanged();
135:            }
136:
137:            public void removeUpdate(DocumentEvent e) {
138:                documentChanged();
139:            }
140:
141:            private void documentChanged() {
142:                this .changed = true;
143:                if (this .immediateUpdate) {
144:                    this .applyChanges();
145:                }
146:                firePropertyChange(this .propName, null, null);
147:            }
148:
149:            public void setImmediateUpdate(boolean aFlag) {
150:                this .immediateUpdate = aFlag;
151:                if (aFlag)
152:                    this .applyChanges();
153:            }
154:
155:            public boolean getImmediateUpdate() {
156:                return this .immediateUpdate;
157:            }
158:
159:            /** Invoked when a component gains the keyboard focus.
160:             *
161:             */
162:            public void focusGained(FocusEvent e) {
163:            }
164:
165:            /** Invoked when a component loses the keyboard focus.
166:             *
167:             */
168:            public void focusLost(FocusEvent e) {
169:                if (!this.immediateUpdate)
170:                    this.applyChanges();
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.