Source Code Cross Referenced for NumericEditor.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » properties » editors » 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 » Swing Library » abeille forms designer » com.jeta.swingbuilder.gui.properties.editors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.gui.properties.editors;
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.Component;
023:        import java.awt.event.ActionEvent;
024:        import java.awt.event.ActionListener;
025:
026:        import javax.swing.JPanel;
027:        import javax.swing.JTextField;
028:
029:        import com.jeta.swingbuilder.gui.components.FloatDocument;
030:        import com.jeta.swingbuilder.gui.components.IntegerDocument;
031:        import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
032:        import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
033:
034:        public class NumericEditor extends JETAPropertyEditor {
035:            /**
036:             * Panel that is used to hold our editor
037:             */
038:            private JPanel m_panel;
039:
040:            /**
041:             * Text field that accepts only characters that are valid for floating point
042:             * values (i.e. digit, ., - )
043:             */
044:            private JTextField m_field = new JTextField();
045:
046:            /**
047:             * The type of value to expect (Integer.class, Long.class, Float.class,
048:             * Short.class, or Double.class )
049:             */
050:            private Class m_number_class;
051:
052:            /**
053:             * ctor
054:             * 
055:             * @param c
056:             *            the type of value to expect (Integer.class, Long.class,
057:             *            Float.class, Short.class, or Double.class )
058:             */
059:            public NumericEditor(Class c) {
060:                m_number_class = c;
061:                m_panel = new JPanel();
062:                m_panel.setLayout(new BorderLayout());
063:                m_panel.add(m_field, BorderLayout.CENTER);
064:
065:                m_panel.setBackground(javax.swing.UIManager
066:                        .getColor("Table.background"));
067:
068:                m_field.addActionListener(new ActionListener() {
069:                    public void actionPerformed(ActionEvent evt) {
070:                        setValue(m_field.getText());
071:                    }
072:                });
073:
074:                if (isIntegral())
075:                    m_field.setDocument(new IntegerDocument());
076:                else
077:                    m_field.setDocument(new FloatDocument());
078:            }
079:
080:            public Object convertValue(Object value) {
081:                if (value instanceof  Byte)
082:                    return value;
083:                else if (value instanceof  Short)
084:                    return value;
085:                else if (value instanceof  Integer)
086:                    return value;
087:                else if (value instanceof  Long)
088:                    return value;
089:                else if (value instanceof  Float)
090:                    return value;
091:                else if (value instanceof  Double)
092:                    return value;
093:                else if (value instanceof  String) {
094:                    if (isIntegral()) {
095:                        return new Long(toLong((String) value));
096:                    } else {
097:                        return new Double(toDouble((String) value));
098:                    }
099:                } else
100:                    return "0";
101:            }
102:
103:            /**
104:             * @return the custom editor
105:             */
106:            public Component getCustomEditor() {
107:                return m_panel;
108:            }
109:
110:            /**
111:             * @return true if this editor supports custom editing inline in the
112:             *         property table. Property types such as the Java primitives and
113:             *         Strings support inline editing.
114:             */
115:            public boolean supportsInlineEditing() {
116:                return true;
117:            }
118:
119:            /**
120:             * Sets the value
121:             */
122:            public void setValue(Object value) {
123:                value = convertValue(value);
124:                super .setValue(value);
125:                m_field.setText(value.toString());
126:            }
127:
128:            /**
129:             * @return the value represented by this field
130:             */
131:            public Object getValue() {
132:                String field_txt = FormDesignerUtils
133:                        .fastTrim(m_field.getText());
134:                if (isByte())
135:                    return new Byte((byte) toLong(field_txt));
136:                else if (isShort())
137:                    return new Short((short) toLong(field_txt));
138:                else if (isInteger())
139:                    return new Integer((int) toLong(field_txt));
140:                else if (isLong())
141:                    return new Long(toLong(field_txt));
142:                else if (isFloat())
143:                    return new Float((float) toDouble(field_txt));
144:                else if (isDouble())
145:                    return new Double(toDouble(field_txt));
146:                else {
147:                    assert (false);
148:                    return null;
149:                }
150:            }
151:
152:            private boolean isByte() {
153:                return (Byte.class == m_number_class);
154:            }
155:
156:            private boolean isInteger() {
157:                return (Integer.class == m_number_class);
158:            }
159:
160:            private boolean isShort() {
161:                return (Short.class == m_number_class);
162:            }
163:
164:            private boolean isLong() {
165:                return (Long.class == m_number_class);
166:            }
167:
168:            private boolean isIntegral() {
169:                return (isByte() || isInteger() || isShort() || isLong());
170:            }
171:
172:            private boolean isFloat() {
173:                return (Float.class == m_number_class);
174:            }
175:
176:            private boolean isDouble() {
177:                return (Double.class == m_number_class);
178:            }
179:
180:            /**
181:             * @return the given string converted to a double. If the string is not
182:             *         valid, 0 is returned.
183:             */
184:            private double toDouble(String sval) {
185:                try {
186:                    return Double.parseDouble(sval);
187:                } catch (Exception e) {
188:                    return 0.0;
189:                }
190:            }
191:
192:            /**
193:             * @return the given string converted to a long. If the string is not valid,
194:             *         0 is returned.
195:             */
196:            private long toLong(String sval) {
197:                try {
198:                    return Long.parseLong(sval);
199:                } catch (Exception e) {
200:                    return 0L;
201:                }
202:            }
203:
204:            public static class IntegerEditor extends NumericEditor {
205:                public IntegerEditor() {
206:                    super (Integer.class);
207:                }
208:            }
209:
210:            public static class ByteEditor extends NumericEditor {
211:                public ByteEditor() {
212:                    super (Byte.class);
213:                }
214:            }
215:
216:            public static class ShortEditor extends NumericEditor {
217:                public ShortEditor() {
218:                    super (Short.class);
219:                }
220:            }
221:
222:            public static class LongEditor extends NumericEditor {
223:                public LongEditor() {
224:                    super (Long.class);
225:                }
226:            }
227:
228:            public static class FloatEditor extends NumericEditor {
229:                public FloatEditor() {
230:                    super (Float.class);
231:                }
232:            }
233:
234:            public static class DoubleEditor extends NumericEditor {
235:                public DoubleEditor() {
236:                    super (Double.class);
237:                }
238:            }
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.