Source Code Cross Referenced for SwingMLModel.java in  » XML-UI » SwingML » org » swingml » 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 » SwingML » org.swingml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SwingML Copyright (C) 2002 SwingML Team
003:         * 
004:         * This library is free software; you can redistribute it and/or modify it under
005:         * the terms of the GNU Lesser General Public License as published by the Free
006:         * Software Foundation; either version 2 of the License, or (at your option) any
007:         * later version.
008:         * 
009:         * This library is distributed in the hope that it will be useful, but WITHOUT
010:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012:         * details.
013:         * 
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with this library; if not, write to the Free Software Foundation, Inc.,
016:         * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017:         * 
018:         * Authors: 
019:         * Ezequiel Cuellar <ecuellar@crosslogic.com> 
020:         * Robert Morris <robertj@morris.net>
021:         */
022:
023:        package org.swingml;
024:
025:        import java.util.*;
026:
027:        import org.swingml.component.*;
028:        import org.swingml.errors.*;
029:        import org.swingml.errors.handlers.*;
030:
031:        public class SwingMLModel extends AbstractSwingMLModel implements 
032:                ISwingMLErrorHandlerContainer {
033:
034:            private ColorComponent background;
035:            private Map errorHandlers;
036:            private String fontName;
037:            private String fontSize;
038:            private String fontStyle;
039:            private ColorComponent foreground;
040:            private String icon;
041:            private String orientation;
042:            private String text;
043:            private String tooltip;
044:            private boolean visible = true;
045:
046:            public SwingMLModel() {
047:                super ();
048:            }
049:
050:            public void addHandler(int errorType, ISwingMLErrorHandler handler) {
051:                Integer key = new Integer(errorType);
052:
053:                List handlers;
054:                if (getErrorHandlers().containsKey(key)) {
055:                    handlers = (List) getErrorHandlers().get(key);
056:                } else {
057:                    handlers = new ArrayList();
058:                }
059:                handlers.add(handler);
060:
061:                getErrorHandlers().put(key, handlers);
062:            }
063:
064:            /**
065:             * Find the appropriate error handlers for the given group of errors (Should all have same error type) and handle them.
066:             * @param errors
067:             */
068:            private void doHandleErrors(List errors) {
069:                if (errors != null && errors.size() > 0) {
070:                    // Find all registered handlers for this error type
071:                    int errorType = ((ISwingMLError) errors.get(0)).getType();
072:                    ISwingMLErrorHandler[] handlers = getHandlers(errorType);
073:                    ISwingMLErrorHandler handler;
074:                    if (handlers != null && handlers.length > 0) {
075:                        for (int y = 0; y < handlers.length; y++) {
076:                            handler = handlers[y];
077:                            // Tell this handler to handle this error
078:                            handler.handle(getContainer(),
079:                                    (ISwingMLError[]) errors
080:                                            .toArray(new ISwingMLError[errors
081:                                                    .size()]));
082:                        }
083:                    }
084:                }
085:            }
086:
087:            public ColorComponent getBackground() {
088:                return background;
089:            }
090:
091:            public Map getErrorHandlers() {
092:                if (errorHandlers == null) {
093:                    errorHandlers = new HashMap();
094:                }
095:                return errorHandlers;
096:            }
097:
098:            public String getFontName() {
099:                return fontName;
100:            }
101:
102:            public String getFontSize() {
103:                return fontSize;
104:            }
105:
106:            public String getFontStyle() {
107:                return fontStyle;
108:            }
109:
110:            public ColorComponent getForeground() {
111:                return foreground;
112:            }
113:
114:            public ISwingMLErrorHandler[] getHandlers(int errorType) {
115:                ISwingMLErrorHandler[] result = null;
116:
117:                List handlers = (List) getErrorHandlers().get(
118:                        new Integer(errorType));
119:                if (handlers != null) {
120:                    result = (ISwingMLErrorHandler[]) handlers
121:                            .toArray(new ISwingMLErrorHandler[handlers.size()]);
122:                }
123:
124:                if (result == null) {
125:                    // Use a DefaultErrorHandler
126:                    result = new ISwingMLErrorHandler[1];
127:                    result[0] = ErrorHandlerFactory.getDefaultHandler();
128:                }
129:
130:                return result;
131:            }
132:
133:            public String getIcon() {
134:                return this .icon;
135:            }
136:
137:            public String getOrientation() {
138:                return this .orientation;
139:            }
140:
141:            public String getText() {
142:                return this .text;
143:            }
144:
145:            public String getTooltip() {
146:                return this .tooltip;
147:            }
148:
149:            /**
150:             * Handle the given errors by delegating to the assigned ErrorHandler.
151:             */
152:            public void handle(ISwingMLError[] errors) {
153:                if (errors != null && errors.length > 0) {
154:                    // group by error type and handle each type as a group
155:                    List sortedErrors = Arrays.asList(errors);
156:                    Collections.sort(sortedErrors, new Comparator() {
157:
158:                        public int compare(Object o1, Object o2) {
159:                            ISwingMLError error1 = (ISwingMLError) o1;
160:                            ISwingMLError error2 = (ISwingMLError) o2;
161:                            if (error1.getType() < error2.getType()) {
162:                                return -1;
163:                            } else if (error1.getType() > error2.getType()) {
164:                                return 1;
165:                            } else {
166:                                return 0;
167:                            }
168:                        }
169:                    });
170:
171:                    // Iterate over all the errors
172:                    ISwingMLError error;
173:                    List errorGroup = new ArrayList();
174:                    int currentErrorType = ISwingMLError.ERROR_UNKNOWN;
175:                    Iterator schmiterator = sortedErrors.iterator();
176:                    while (schmiterator.hasNext()) {
177:                        error = (ISwingMLError) schmiterator.next();
178:                        if (error.getType() != currentErrorType) {
179:                            // process the errorGroup and start new
180:                            doHandleErrors(errorGroup);
181:
182:                            errorGroup.clear();
183:                            currentErrorType = error.getType();
184:                        }
185:                        errorGroup.add(error);
186:                    }
187:                    // handle the last group
188:                    doHandleErrors(errorGroup);
189:                }
190:            }
191:
192:            public boolean isVisible() {
193:                return this .visible;
194:            }
195:
196:            public void removeHandler(int errorType,
197:                    ISwingMLErrorHandler handler) {
198:                ISwingMLErrorHandler[] handlers = getHandlers(errorType);
199:                if (handlers != null && handlers.length > 0) {
200:                    List newHandlers = new ArrayList();
201:                    for (int x = 0; x < handlers.length; x++) {
202:                        if (!handlers[x].equals(handler)) {
203:                            newHandlers.add(handlers[x]);
204:                        }
205:                    }
206:                    getErrorHandlers().put(new Integer(errorType), newHandlers);
207:                }
208:            }
209:
210:            public void removeHandlers(int errorType) {
211:                getErrorHandlers().remove(new Integer(errorType));
212:            }
213:
214:            public void setBackground(ColorComponent component) {
215:                background = component;
216:            }
217:
218:            public void setErrorHandlers(Map handlers) {
219:                this .errorHandlers = handlers;
220:            }
221:
222:            public void setFontName(String string) {
223:                fontName = string;
224:            }
225:
226:            public void setFontSize(String string) {
227:                fontSize = string;
228:            }
229:
230:            public void setFontStyle(String string) {
231:                fontStyle = string;
232:            }
233:
234:            public void setForeground(ColorComponent component) {
235:                foreground = component;
236:            }
237:
238:            public void setIcon(String anIcon) {
239:                this .icon = anIcon;
240:            }
241:
242:            public void setOrientation(String anOrientation) {
243:                this .orientation = anOrientation;
244:            }
245:
246:            public void setText(String aText) {
247:                this .text = aText;
248:            }
249:
250:            public void setTooltip(String aTooltip) {
251:                this .tooltip = aTooltip;
252:            }
253:
254:            public void setVisible(boolean aVisible) {
255:                this .visible = aVisible;
256:            }
257:
258:            public void validate() {
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.