Source Code Cross Referenced for MessageSourceSupport.java in  » Swing-Library » swingx » org » jdesktop » swingx » event » 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 » swingx » org.jdesktop.swingx.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: MessageSourceSupport.java,v 1.4 2005/10/26 14:29:56 kleopatra Exp $
003:         *
004:         * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005:         * Santa Clara, California 95054, U.S.A. All rights reserved.
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         * 
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020:         */
021:
022:        package org.jdesktop.swingx.event;
023:
024:        import java.util.logging.Level;
025:
026:        import javax.swing.event.EventListenerList;
027:
028:        /**
029:         * A helper class which is an implementation of a message source and a progress
030:         * source. This class manages the listener list and has convenience methods to
031:         * fire MessageEvents and ProgressEvents.
032:         * 
033:         * @see MessageEvent
034:         * @see MessageSource
035:         * @see ProgressEvent
036:         * @see ProgressSource
037:         * @author Mark Davidson
038:         */
039:        public class MessageSourceSupport implements  MessageSource,
040:                ProgressSource {
041:
042:            private EventListenerList listeners;
043:
044:            private Object source;
045:
046:            /**
047:             * Creates an MessageSource instance using the source object as the source
048:             * of events.
049:             */
050:            public MessageSourceSupport(Object source) {
051:                if (source == null) {
052:                    throw new IllegalArgumentException(
053:                            "source Object cannot be null");
054:                }
055:                this .source = source;
056:                this .listeners = new EventListenerList();
057:            }
058:
059:            public void addMessageListener(MessageListener l) {
060:                if (l != null) {
061:                    listeners.add(MessageListener.class, l);
062:                }
063:            }
064:
065:            public void removeMessageListener(MessageListener l) {
066:                if (l != null) {
067:                    listeners.remove(MessageListener.class, l);
068:                }
069:            }
070:
071:            public MessageListener[] getMessageListeners() {
072:                return (MessageListener[]) listeners
073:                        .getListeners(MessageListener.class);
074:            }
075:
076:            // Perhaps the ProgressListener interface should be defined
077:
078:            public void addProgressListener(ProgressListener l) {
079:                if (l != null) {
080:                    listeners.add(ProgressListener.class, l);
081:                }
082:            }
083:
084:            public void removeProgressListener(ProgressListener l) {
085:                if (l != null) {
086:                    listeners.remove(ProgressListener.class, l);
087:                }
088:            }
089:
090:            public ProgressListener[] getProgressListeners() {
091:                return (ProgressListener[]) listeners
092:                        .getListeners(ProgressListener.class);
093:            }
094:
095:            /**
096:             * Indicates that a long operation is staring. For a determinite progress
097:             * operation, the minimum value should be less than the maximum value. For
098:             * inderminate operations, set minimum equal to maximum.
099:             * 
100:             * @param minimum the minimum value of the progress operation
101:             * @param maximum the maximum value of the progress operation
102:             */
103:            public void fireProgressStarted(int minimum, int maximum) {
104:                fireProgressStarted(new ProgressEvent(source, minimum, maximum));
105:            }
106:
107:            /**
108:             * Indicates that an increment of progress has occured.
109:             * 
110:             * @param progress total value of the progress operation. This value should
111:             *        be between the minimum and maximum values
112:             */
113:            public void fireProgressIncremented(int progress) {
114:                fireProgressIncremented(new ProgressEvent(source, progress));
115:            }
116:
117:            /**
118:             * Indicates that a progress operation has completed
119:             */
120:            public void fireProgressEnded() {
121:                fireProgressEnded(new ProgressEvent(source));
122:            }
123:
124:            /**
125:             * Create a SEVERE MessageEvent which represents an Exception.
126:             * <p>
127:             * <b>NOTE: This will create an event which is by default at Level.SEVERE</b>
128:             * 
129:             * @see java.util.logging.Level
130:             */
131:            public void fireException(Throwable t) {
132:                fireMessage(new MessageEvent(source, t, Level.SEVERE));
133:            }
134:
135:            /**
136:             * Send a Level.INFO, non-timestamped message to the list of listeners.
137:             * 
138:             * @param message a string of text to send
139:             */
140:            public void fireMessage(String message) {
141:                fireMessage(message, Level.INFO);
142:            }
143:
144:            /**
145:             * Send a non-timestamped message to the list of listeners.
146:             * 
147:             * @param value the contents of the message
148:             * @param level the level of message.
149:             */
150:            public void fireMessage(Object value, Level level) {
151:                fireMessage(value, level, 0L);
152:            }
153:
154:            /**
155:             * Send a message to the list of listeners with a timestamp.
156:             * 
157:             * @param value the contents of the message
158:             * @param level the level of message
159:             * @param when timestamp of when this event occured
160:             */
161:            public void fireMessage(Object value, Level level, long when) {
162:                fireMessage(new MessageEvent(source, value, level, when));
163:            }
164:
165:            /**
166:             * Send the MessageEvent to the list of listeners.
167:             * 
168:             * @param evt a non-null MessageEvent.
169:             */
170:            public void fireMessage(MessageEvent evt) {
171:                if (evt == null) {
172:                    throw new IllegalArgumentException(
173:                            "the event should not be null");
174:                }
175:
176:                MessageListener[] ls = getMessageListeners();
177:                for (int i = 0; i < ls.length; i++) {
178:                    ls[i].message(evt);
179:                }
180:            }
181:
182:            /**
183:             * Send the ProgessEvent to the list of listeners.
184:             * 
185:             * @param evt a non-null ProgressEvent
186:             */
187:            public void fireProgressIncremented(ProgressEvent evt) {
188:                if (evt == null) {
189:                    throw new IllegalArgumentException(
190:                            "the event should not be null");
191:                }
192:
193:                ProgressListener[] ls = getProgressListeners();
194:                for (int i = 0; i < ls.length; i++) {
195:                    ls[i].progressIncremented(evt);
196:                }
197:            }
198:
199:            /**
200:             * Send the ProgessEvent to the list of listeners.
201:             * 
202:             * @param evt a non-null ProgressEvent
203:             */
204:            public void fireProgressStarted(ProgressEvent evt) {
205:                if (evt == null) {
206:                    throw new IllegalArgumentException(
207:                            "the event should not be null");
208:                }
209:
210:                ProgressListener[] ls = getProgressListeners();
211:                for (int i = 0; i < ls.length; i++) {
212:                    ls[i].progressStarted(evt);
213:                }
214:            }
215:
216:            /**
217:             * Send the ProgessEvent to the list of listeners.
218:             * 
219:             * @param evt a non-null ProgressEvent
220:             */
221:            public void fireProgressEnded(ProgressEvent evt) {
222:                if (evt == null) {
223:                    throw new IllegalArgumentException(
224:                            "the event should not be null");
225:                }
226:
227:                ProgressListener[] ls = getProgressListeners();
228:                for (int i = 0; i < ls.length; i++) {
229:                    ls[i].progressEnded(evt);
230:                }
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.