Source Code Cross Referenced for WingTimer.java in  » Web-Framework » wingS » com » javujavu » javux » wings » 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 » wingS » com.javujavu.javux.wings 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *	Javu WingS - Lightweight Java Component Set
003:         *	Copyright (c) 2005-2007 Krzysztof A. Sadlocha
004:         *	e-mail: ksadlocha@programics.com
005:         *
006:         *	This library is free software; you can redistribute it and/or
007:         *	modify it under the terms of the GNU Lesser General Public
008:         *	License as published by the Free Software Foundation; either
009:         *	version 2.1 of the License, or (at your option) any later version.
010:         *
011:         *	This library is distributed in the hope that it will be useful,
012:         *	but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *	Lesser General Public License for more details.
015:         *
016:         *	You should have received a copy of the GNU Lesser General Public
017:         *	License along with this library; if not, write to the Free Software
018:         *	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         */
020:
021:        package com.javujavu.javux.wings;
022:
023:        import java.awt.event.ActionEvent;
024:        import java.util.Vector;
025:
026:        /**
027:         * This class posts <code>ActionEvent</code>s at specified
028:         * intervals.
029:         * <br><br>
030:         * <strong>ActionEvents posted by WingTimer can be dispatched on thread AWT EventDispatchThread
031:         * and on thread WingTimer.thread.</strong><br>
032:         * Create timer with postOnEventThread=false for time critical timer events.<br>
033:         * <br>
034:         * <br>
035:         * <b>This is one of the core WingS classes required by all the components</b><br>
036:         * <br>
037:         * <b>This class is thread safe.</b>
038:         **/
039:        public class WingTimer implements  Runnable {
040:            protected static final Vector timers = new Vector();
041:            protected static Thread thread;
042:
043:            public void run() {
044:                WingTimer t;
045:                try {
046:                    while (true) {
047:                        synchronized (timers) {
048:                            if (timers.size() == 0) {
049:                                timers.wait();
050:                                continue;
051:                            } else {
052:                                t = (WingTimer) timers.firstElement();
053:                                long delay = t.time
054:                                        - System.currentTimeMillis();
055:                                if (delay > 0) {
056:                                    timers.wait(delay);
057:                                    continue;
058:                                }
059:                                removeTimer(t);
060:                            }
061:                        }
062:                        ActionEvent e = new ActionEvent(t,
063:                                ActionEvent.ACTION_PERFORMED, "timer");
064:                        WingComponent l1 = t.target;
065:                        if (l1 != null) {
066:                            if (t.poet)
067:                                l1.postOnEventThread(e);
068:                            else
069:                                l1.wingProcessActionEvent(e);
070:                        }
071:                        //				ActionListener l2= t.listener;
072:                        //				if(l2!=null) l2.actionPerformed(e);
073:
074:                        if (t.repeat)
075:                            addTimer(t);
076:                    }
077:                } catch (InterruptedException e) {
078:                }
079:
080:                synchronized (timers) {
081:                    thread = null;
082:                }
083:            }
084:
085:            protected static void addTimer(WingTimer timer) {
086:                synchronized (timers) {
087:                    removeTimer(timer);
088:
089:                    if (thread == null) {
090:                        thread = new Thread(
091:                                new WingTimer(0, false, null, false));
092:                        thread.setDaemon(true);
093:                        thread.start();
094:                    }
095:
096:                    timer.time = System.currentTimeMillis() + timer.delay;
097:                    int i;
098:                    for (i = 0; i < timers.size(); i++) {
099:                        if (timer.time < ((WingTimer) timers.elementAt(i)).time) {
100:                            break;
101:                        }
102:                    }
103:                    timers.insertElementAt(timer, i);
104:                    if (i == 0)
105:                        timers.notify();
106:                }
107:            }
108:
109:            protected static void removeTimer(WingTimer timer) {
110:                synchronized (timers) {
111:                    timers.removeElement(timer);
112:                    timer.time = 0;
113:                }
114:            }
115:
116:            private WingComponent target;
117:            //	private ActionListener listener;
118:            private int delay;
119:            private boolean repeat;
120:            private long time;
121:            private Object data;
122:            private boolean poet;
123:
124:            /**
125:             * Creates a <code>WingTimer</code> with the specified delay time,
126:             * repeat mode, and target component.
127:             * @param delay milliseconds for the delay
128:             * @param repeat specify <code>false</code> to make the timer
129:             *             stop after sending its first action event
130:             * @param target target component
131:             */
132:            public WingTimer(int delay, boolean repeat, WingComponent target) {
133:                this (delay, repeat, target, true);
134:            }
135:
136:            /**
137:             * Creates a <code>WingTimer</code> with the specified delay time,
138:             * repeat mode, and target component.
139:             * @param delay milliseconds for the delay
140:             * @param repeat specify <code>false</code> to make the timer
141:             *             stop after sending its first action event
142:             * @param target target component
143:             * @param postOnEventThread specifies whether the events are posted on event thread
144:             */
145:            public WingTimer(int delay, boolean repeat, WingComponent target,
146:                    boolean postOnEventThread) {
147:                this .delay = delay;
148:                this .repeat = repeat;
149:                this .target = target;
150:                this .poet = postOnEventThread;
151:            }
152:
153:            /**
154:             * Starts the timer
155:             */
156:            public void start() {
157:                addTimer(this );
158:            }
159:
160:            /**
161:             * Stops the timer
162:             */
163:            public void stop() {
164:                if (time != 0)
165:                    removeTimer(this );
166:            }
167:
168:            /**
169:             * Sets target component
170:             * @param target target component
171:             */
172:            public void setTarget(WingComponent target) {
173:                this .target = target;
174:            }
175:
176:            //	public void setListener(ActionListener listener)
177:            //	{
178:            //		this.listener= listener;
179:            //	}
180:            public WingComponent getTarget() {
181:                return target;
182:            }
183:
184:            public void setData(Object data) {
185:                this .data = data;
186:            }
187:
188:            public Object getData() {
189:                return data;
190:            }
191:
192:            public void setDelay(int delay) {
193:                this.delay = delay;
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.