Source Code Cross Referenced for ValidationMessageKeysExample.java in  » Swing-Library » jgoodies-validation » com » jgoodies » validation » tutorial » basics » 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 » jgoodies validation » com.jgoodies.validation.tutorial.basics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2003-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         *  o Redistributions of source code must retain the above copyright notice,
008:         *    this list of conditions and the following disclaimer.
009:         *
010:         *  o Redistributions in binary form must reproduce the above copyright notice,
011:         *    this list of conditions and the following disclaimer in the documentation
012:         *    and/or other materials provided with the distribution.
013:         *
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of
015:         *    its contributors may be used to endorse or promote products derived
016:         *    from this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:
031:        package com.jgoodies.validation.tutorial.basics;
032:
033:        import java.awt.event.ActionEvent;
034:
035:        import javax.swing.*;
036:
037:        import com.jgoodies.forms.builder.PanelBuilder;
038:        import com.jgoodies.forms.factories.ButtonBarFactory;
039:        import com.jgoodies.forms.layout.CellConstraints;
040:        import com.jgoodies.forms.layout.FormLayout;
041:        import com.jgoodies.validation.Severity;
042:        import com.jgoodies.validation.ValidationResult;
043:        import com.jgoodies.validation.ValidationResultModel;
044:        import com.jgoodies.validation.message.SimpleValidationMessage;
045:        import com.jgoodies.validation.tutorial.util.IconFeedbackPanel;
046:        import com.jgoodies.validation.tutorial.util.TutorialUtils;
047:        import com.jgoodies.validation.util.DefaultValidationResultModel;
048:        import com.jgoodies.validation.view.ValidationComponentUtils;
049:        import com.jgoodies.validation.view.ValidationResultViewFactory;
050:
051:        /**
052:         * Demonstrates how to associate validation messages with UI components.
053:         * Provides buttons to set a couple of valid and invalid results.
054:         *
055:         * @author  Karsten Lentzsch
056:         * @version $Revision: 1.2 $
057:         */
058:        public final class ValidationMessageKeysExample {
059:
060:            private static final Object KEY1 = "key1";
061:            private static final Object KEY2 = "key2";
062:
063:            private final ValidationResultModel resultModel;
064:
065:            private JComponent noKeyField;
066:            private JComponent key1Field;
067:            private JComponent key2Field;
068:            private JComponent key1Key2Field;
069:
070:            private JButton validButton;
071:            private JButton errorsButton;
072:            private JButton warningsButton;
073:            private JButton mixedButton;
074:
075:            public static void main(String[] args) {
076:                try {
077:                    UIManager
078:                            .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
079:                } catch (Exception e) {
080:                    // Likely Plastic is not in the classpath; ignore it.
081:                }
082:                JFrame frame = new JFrame();
083:                frame.setTitle("Basics :: Validation Message Keys");
084:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
085:                JComponent panel = new ValidationMessageKeysExample()
086:                        .buildPanel();
087:                frame.getContentPane().add(panel);
088:                frame.pack();
089:                TutorialUtils.locateOnOpticalScreenCenter(frame);
090:                frame.setVisible(true);
091:            }
092:
093:            // Instance Creation ******************************************************
094:
095:            public ValidationMessageKeysExample() {
096:                resultModel = new DefaultValidationResultModel();
097:                resultModel.setResult(createResult1());
098:            }
099:
100:            // Component Creation and Initialization **********************************
101:
102:            private void initComponents() {
103:                noKeyField = new JTextField();
104:                key1Field = new JTextField();
105:                key2Field = new JTextField();
106:                key1Key2Field = new JTextField();
107:
108:                validButton = new JButton(new SetResultAction("Empty",
109:                        ValidationResult.EMPTY));
110:                errorsButton = new JButton(new SetResultAction("1 Only",
111:                        createResult1()));
112:                warningsButton = new JButton(new SetResultAction("2 Only",
113:                        createResult2()));
114:                mixedButton = new JButton(new SetResultAction("1 & 2",
115:                        createResult3()));
116:            }
117:
118:            private void initComponentAnnotations() {
119:                ValidationComponentUtils.setMessageKey(key1Field, KEY1);
120:                ValidationComponentUtils.setMessageKey(key2Field, KEY2);
121:                ValidationComponentUtils.setMessageKeys(key1Key2Field,
122:                        new Object[] { KEY1, KEY2 });
123:            }
124:
125:            // Building ***************************************************************
126:
127:            /**
128:             * Builds and returns the whole editor.
129:             */
130:            public JComponent buildPanel() {
131:                initComponents();
132:                initComponentAnnotations();
133:
134:                FormLayout layout = new FormLayout(
135:                        "right:max(65dlu;pref), 4dlu, 160dlu:grow",
136:                        "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu:grow, p");
137:
138:                PanelBuilder builder = new PanelBuilder(layout);
139:                builder.setDefaultDialogBorder();
140:                CellConstraints cc = new CellConstraints();
141:
142:                builder.addLabel("No key", cc.xy(1, 1));
143:                builder.add(noKeyField, cc.xy(3, 1));
144:                builder.addLabel("Key1", cc.xy(1, 3));
145:                builder.add(key1Field, cc.xy(3, 3));
146:                builder.addLabel("Key2", cc.xy(1, 5));
147:                builder.add(key2Field, cc.xy(3, 5));
148:                builder.addLabel("Key1, Key2", cc.xy(1, 7));
149:                builder.add(key1Key2Field, cc.xy(3, 7));
150:
151:                builder.addLabel("List", cc.xy(1, 9, "r, t"));
152:                builder.add(ValidationResultViewFactory
153:                        .createReportList(resultModel), cc.xy(3, 9));
154:
155:                builder.add(buildButtonBar(), cc.xyw(1, 11, 3));
156:
157:                return new IconFeedbackPanel(resultModel, builder.getPanel());
158:            }
159:
160:            private JComponent buildButtonBar() {
161:                return ButtonBarFactory.buildRightAlignedBar(validButton,
162:                        errorsButton, warningsButton, mixedButton);
163:            }
164:
165:            // Helper Code ************************************************************
166:
167:            /**
168:             * Sets the given ValidationResult as the resultModel's result
169:             * when performed. Used to create the 4 command buttons.
170:             */
171:            private final class SetResultAction extends AbstractAction {
172:
173:                private final ValidationResult result;
174:
175:                SetResultAction(String name, ValidationResult result) {
176:                    super (name);
177:                    this .result = result;
178:                }
179:
180:                public void actionPerformed(ActionEvent e) {
181:                    resultModel.setResult(result);
182:                }
183:
184:            }
185:
186:            private static ValidationResult createResult1() {
187:                ValidationResult result = new ValidationResult();
188:                result.add(new SimpleValidationMessage("Message1 for key1",
189:                        Severity.ERROR, KEY1));
190:                result.add(new SimpleValidationMessage("Message2 for key1",
191:                        Severity.WARNING, KEY1));
192:                return result;
193:            }
194:
195:            private static ValidationResult createResult2() {
196:                ValidationResult result = new ValidationResult();
197:                result.add(new SimpleValidationMessage("Message1 for key2",
198:                        Severity.ERROR, KEY2));
199:                result.add(new SimpleValidationMessage("Message2 for key2",
200:                        Severity.WARNING, KEY2));
201:                return result;
202:            }
203:
204:            private static ValidationResult createResult3() {
205:                ValidationResult result = new ValidationResult();
206:                result.add(new SimpleValidationMessage("Message1 for key1",
207:                        Severity.ERROR, KEY1));
208:                result.add(new SimpleValidationMessage("Message2 for key1",
209:                        Severity.WARNING, KEY1));
210:                result.add(new SimpleValidationMessage("Message1 for key2",
211:                        Severity.ERROR, KEY2));
212:                result.add(new SimpleValidationMessage("Message2 for key2",
213:                        Severity.WARNING, KEY2));
214:                return result;
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.