Source Code Cross Referenced for JCompareValidator.java in  » Web-Framework » webonswing » net » ar » webonswing » swing » components » validators » 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 Framework » webonswing » net.ar.webonswing.swing.components.validators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // WebOnSwing - Web Application Framework
002:        //Copyright (C) 2004 Fernando Damian Petrola
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:        package net.ar.webonswing.swing.components.validators;
019:
020:        import java.text.*;
021:
022:        import javax.swing.*;
023:
024:        import net.ar.webonswing.*;
025:        import net.ar.webonswing.helpers.*;
026:        import net.ar.webonswing.swing.components.validators.contributors.*;
027:
028:        public class JCompareValidator extends JValidator {
029:            protected Operation operation;
030:            protected Type type;
031:
032:            protected Object valueToCompare;
033:            protected JComponent componentToCompare;
034:
035:            public JCompareValidator() {
036:                WosFramework.assignContributor(this ,
037:                        CompareValidatorUIContributor.class);
038:            }
039:
040:            public JCompareValidator(JComponent aComponentToValidate,
041:                    String aMessage, String aGroupMessage,
042:                    boolean hasRemoteValidation, Object aValueToCompare,
043:                    JCompareValidator.Operation anOperation,
044:                    JCompareValidator.Type aType) {
045:                this (aComponentToValidate, aMessage, aGroupMessage,
046:                        hasRemoteValidation, anOperation, aType);
047:                valueToCompare = aValueToCompare;
048:            }
049:
050:            public JCompareValidator(JComponent aComponentToValidate,
051:                    String aMessage, String aGroupMessage,
052:                    boolean hasRemoteValidation,
053:                    JComponent aComponentToCompare,
054:                    JCompareValidator.Operation anOperation,
055:                    JCompareValidator.Type aType) {
056:                this (aComponentToValidate, aMessage, aGroupMessage,
057:                        hasRemoteValidation, anOperation, aType);
058:                componentToCompare = aComponentToCompare;
059:            }
060:
061:            public JCompareValidator(JComponent aComponentToValidate,
062:                    String aMessage, String aGroupMessage,
063:                    boolean hasRemoteValidation, JComponent aComponentToCompare) {
064:                this (aComponentToValidate, aMessage, aGroupMessage,
065:                        hasRemoteValidation, JCompareValidator.Operation.equal,
066:                        JCompareValidator.Type.STRING);
067:                componentToCompare = aComponentToCompare;
068:            }
069:
070:            public JCompareValidator(JComponent aComponentToValidate,
071:                    String aMessage, String aGroupMessage,
072:                    boolean hasRemoteValidation,
073:                    JCompareValidator.Operation anOperation,
074:                    JCompareValidator.Type aType) {
075:                super (aComponentToValidate, aMessage, aGroupMessage,
076:                        hasRemoteValidation);
077:
078:                operation = anOperation;
079:                type = aType;
080:
081:                WosFramework.assignContributor(this ,
082:                        CompareValidatorUIContributor.class);
083:            }
084:
085:            protected boolean performValidation() {
086:                try {
087:                    Comparable v1 = type
088:                            .getComparable(getComponentValue(componentToValidate));
089:
090:                    if (componentToCompare != null || valueToCompare != null) {
091:                        Comparable v2 = type
092:                                .getComparable(componentToCompare != null ? getComponentValue(componentToCompare)
093:                                        : valueToCompare);
094:                        return operation.compare(v1, v2);
095:                    } else
096:                        return true;
097:
098:                } catch (RuntimeException e) {
099:                    return false;
100:                }
101:            }
102:
103:            public static class Operation {
104:                protected int[] matchValues;
105:                protected String name;
106:
107:                public static Operation equal = new Operation(new int[] { 0, 0,
108:                        0 }, "equal");
109:                public static Operation notEqual = new Operation(new int[] {
110:                        -1, 1, 1 }, "not equal");
111:                public static Operation greaterThan = new Operation(new int[] {
112:                        1, 1, 1 }, "greater than");
113:                public static Operation greaterThanEqual = new Operation(
114:                        new int[] { 1, 0, 0 }, "greater than equal");
115:                public static Operation lessThan = new Operation(new int[] {
116:                        -1, -1, -1 }, "less than");
117:                public static Operation lessThanEqual = new Operation(
118:                        new int[] { -1, 0, 0 }, "less than equal");
119:                public static Operation dataTypeCheck = new Operation(
120:                        new int[] { -1, 0, 1 }, "data type check");
121:
122:                public Operation(int[] match, String aName) {
123:                    matchValues = match;
124:                    name = aName;
125:                }
126:
127:                public boolean compare(Comparable aValue,
128:                        Comparable aCompareValue) {
129:                    int comparison = aValue.compareTo(aCompareValue);
130:
131:                    if (comparison != 0)
132:                        comparison = comparison / Math.abs(comparison);
133:
134:                    return comparison == matchValues[0]
135:                            || comparison == matchValues[1]
136:                            || comparison == matchValues[2];
137:                }
138:
139:                public int[] getMatchValues() {
140:                    return matchValues;
141:                }
142:
143:                public void setMatchValues(int[] aIs) {
144:                    matchValues = aIs;
145:                }
146:
147:                public String toString() {
148:                    return name;
149:                }
150:            }
151:
152:            public static abstract class Type {
153:                public static Type STRING = new Type() {
154:                    public Comparable createComparableFromString(String aValue) {
155:                        return aValue;
156:                    }
157:
158:                    public String toString() {
159:                        return "string";
160:                    }
161:                };
162:
163:                public static Type INTEGER = new Type() {
164:                    public Comparable createComparableFromString(String aValue) {
165:                        return new Integer(aValue);
166:                    }
167:
168:                    public String toString() {
169:                        return "integer";
170:                    }
171:                };
172:
173:                public static Type DOUBLE = new Type() {
174:                    public Comparable createComparableFromString(String aValue) {
175:                        return new Double(aValue);
176:                    }
177:
178:                    public String toString() {
179:                        return "double";
180:                    }
181:                };
182:
183:                public static Type DATE = DATE("dd/MM/yyyy HH:mm:ss");
184:
185:                public static Type DATE(final String aPattern) {
186:                    return new Type() {
187:                        protected SimpleDateFormat format = new SimpleDateFormat(
188:                                aPattern);
189:
190:                        public Comparable createComparableFromString(
191:                                String aValue) {
192:                            try {
193:                                return format.parse(aValue);
194:                            } catch (ParseException e) {
195:                                throw new WebOnSwingException(e);
196:                            }
197:                        }
198:
199:                        protected String createStringFromComparable(
200:                                Object aValue) {
201:                            return format.format(aValue);
202:                        }
203:
204:                        public String getPattern() {
205:                            return format.toPattern();
206:                        }
207:
208:                        public String toString() {
209:                            return "date:" + format.toPattern();
210:                        }
211:                    };
212:                }
213:
214:                protected abstract Comparable createComparableFromString(
215:                        String aValue);
216:
217:                protected String createStringFromComparable(Object aValue) {
218:                    return aValue.toString();
219:                }
220:
221:                public Comparable getComparable(Object aValue) {
222:                    if (aValue instanceof  String)
223:                        return createComparableFromString((String) aValue);
224:                    else if (aValue instanceof  Comparable)
225:                        return (Comparable) aValue;
226:                    else
227:                        throw new WebOnSwingException(
228:                                "The value to compare does not implement Comparable interface");
229:                }
230:
231:                public String getString(Object aValue) {
232:                    if (aValue instanceof  String)
233:                        return (String) aValue;
234:                    else if (aValue instanceof  Comparable)
235:                        return createStringFromComparable(aValue);
236:                    else
237:                        throw new WebOnSwingException(
238:                                "The value to compare does not implement Comparable interface");
239:                }
240:            }
241:
242:            public JComponent getComponentToCompare() {
243:                return componentToCompare;
244:            }
245:
246:            public Operation getOperation() {
247:                return operation;
248:            }
249:
250:            public void setComponentToCompare(JComponent aComponent) {
251:                componentToCompare = aComponent;
252:            }
253:
254:            public void setOperation(Operation aOperation) {
255:                operation = aOperation;
256:            }
257:
258:            public Type getType() {
259:                return type;
260:            }
261:
262:            public void setType(Type aType) {
263:                type = aType;
264:            }
265:
266:            public Object getValueToCompare() {
267:                return valueToCompare;
268:            }
269:
270:            public void setValueToCompare(Object aObject) {
271:                valueToCompare = aObject;
272:            }
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.