Source Code Cross Referenced for DisplayDeviceAccess.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » lcdui » 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 » 6.0 JDK Modules » j2me » com.sun.midp.lcdui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.midp.lcdui;
027:
028:        import javax.microedition.lcdui.Display;
029:        import java.util.Timer;
030:        import java.util.TimerTask;
031:
032:        /**
033:         * Class that allows Display to access 
034:         * Device specific calls in the native code
035:         * like flashBacklight.
036:         */
037:
038:        public class DisplayDeviceAccess {
039:
040:            /** 
041:             * The Timer to service TimerTasks. 
042:             */
043:            private static Timer timerService = new Timer();
044:
045:            /** 
046:             * A TimerTask. 
047:             */
048:            private TimerTask task = null;
049:
050:            /**
051:             * The interval, in microseconds between backlight 
052:             * toggles (in microseconds)
053:             */
054:            private static int BLINK_RATE = 250;
055:
056:            /**
057:             * Number of repetitions left in flash duration
058:             */
059:            private int flashCount = 0;
060:
061:            /**
062:             * We always want this to be false at the end of 
063:             * a flashBacklight call.
064:             */
065:            private boolean isLit = false;
066:
067:            /**
068:             * Requests a flashing effect for the device's backlight.
069:             *
070:             * @param displayId The display ID associated with this Display
071:             * @param duration the number of milliseconds the backlight should be 
072:             * flashed, or zero if the flashing should be stopped
073:             *
074:             * @return true if the backlight can be controlled
075:             */
076:            public boolean flashBacklight(int displayId, int duration) {
077:
078:                // Test for negative of duration is in public class
079:
080:                if (duration == 0) {
081:                    cancelTimer();
082:                    if (isLit) {
083:                        isLit = !isLit;
084:                        return toggleBacklight0(displayId);
085:                    } else {
086:                        return isBacklightSupported0(displayId);
087:                    }
088:                } else {
089:                    setTimer(displayId, duration);
090:                    isLit = !isLit;
091:                    return toggleBacklight0(displayId);
092:                }
093:            }
094:
095:            /**
096:             * Set a new timer.  Determine <code>flashCount</code> based on
097:             * <code>duration</code> divided by <code>BLINK_RATE</code>
098:             *
099:             * @param displayId The display ID associated with this Display
100:             * @param duration the number of milliseconds the timer should be run
101:             */
102:            private void setTimer(int displayId, int duration) {
103:                cancelTimer();
104:                try {
105:                    task = new TimerClient(displayId);
106:                    /* flash every <tt>BLINK_RATE</tt> miliseconds */
107:                    flashCount = duration / BLINK_RATE;
108:                    timerService.schedule(task, BLINK_RATE, BLINK_RATE);
109:                } catch (IllegalStateException e) {
110:                    cancelTimer();
111:                }
112:            }
113:
114:            /**
115:             * Cancel any running Timer.
116:             */
117:            private void cancelTimer() {
118:                if (task != null) {
119:                    task.cancel();
120:                    task = null;
121:                }
122:                flashCount = 0;
123:            }
124:
125:            /**
126:             * Inner class TimerTask
127:             *
128:             * Used to toggle the backlight and turn it off when
129:             * the duration of the timer is up
130:             */
131:            class TimerClient extends TimerTask {
132:
133:                /**
134:                 * Creates TimerClient to show backlight for 
135:                 * Display with passed displayId.
136:                 *
137:                 * @param displayId The display ID associated with the caller Display
138:                 */
139:                TimerClient(int displayId) {
140:                    this .displayId = displayId;
141:                }
142:
143:                /**
144:                 * If there are flashes left to perform, 
145:                 * simply toggle the backlight.
146:                 */
147:                public final void run() {
148:                    if (flashCount > 0) {
149:                        flashCount--;
150:                        isLit = !isLit;
151:                        toggleBacklight0(displayId);
152:                    } else {
153:                        if (isLit) {
154:                            isLit = !isLit;
155:                            toggleBacklight0(displayId);
156:                        }
157:                        this .cancel();
158:                    }
159:                }
160:
161:                /** The display ID associated with the caller Display */
162:                private int displayId;
163:            }
164:
165:            /**
166:             * Toggles backlight.
167:             *  
168:             * @param displayId The display ID associated with the caller Display
169:             * @return true if backlight control is supported, false otherwise        
170:             */
171:            private native boolean toggleBacklight0(int displayId);
172:
173:            /**
174:             * Tests if backlight is supported.
175:             *  
176:             * @param displayId The display ID associated with the caller Display
177:             * @return true if backlight control is supported, false otherwise        
178:             */
179:            private native boolean isBacklightSupported0(int displayId);
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.