Source Code Cross Referenced for TickerLayer.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » chameleon » layers » 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.chameleon.layers 
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:
027:        package com.sun.midp.chameleon.layers;
028:
029:        import com.sun.midp.chameleon.*;
030:
031:        import javax.microedition.lcdui.*;
032:        import java.util.*;
033:
034:        import com.sun.midp.chameleon.skins.TickerSkin;
035:        import com.sun.midp.chameleon.skins.ScreenSkin;
036:        import com.sun.midp.chameleon.skins.SoftButtonSkin;
037:
038:        /**
039:         *
040:         */
041:        public class TickerLayer extends CLayer {
042:            protected String text;
043:
044:            protected int textLoc;
045:            protected int textLen;
046:
047:            /**
048:             * A Timer which will handle firing repaints of the TickerPainter
049:             */
050:            protected Timer tickerTimer;
051:
052:            /**
053:             * A TimerTask which will repaint the Ticker on a repeated basis
054:             */
055:            protected TickerPainter tickerPainter;
056:
057:            public TickerLayer() {
058:                super (TickerSkin.IMAGE_BG, TickerSkin.COLOR_BG);
059:            }
060:
061:            public void toggleAlert(boolean alertUp) {
062:                if (alertUp && TickerSkin.IMAGE_AU_BG != null) {
063:                    super .setBackground(TickerSkin.IMAGE_AU_BG, 0);
064:                } else if (!alertUp) {
065:                    super .setBackground(TickerSkin.IMAGE_BG,
066:                            TickerSkin.COLOR_BG);
067:                }
068:            }
069:
070:            protected void initialize() {
071:                super .initialize();
072:
073:                setAnchor();
074:                tickerTimer = new Timer();
075:            }
076:
077:            public void setAnchor() {
078:                bounds[X] = 0;
079:                bounds[W] = ScreenSkin.WIDTH;
080:                bounds[H] = TickerSkin.HEIGHT;
081:                switch (TickerSkin.ALIGN) {
082:                case (Graphics.TOP):
083:                    bounds[Y] = 0;
084:                    break;
085:                case (Graphics.BOTTOM):
086:                default:
087:                    bounds[Y] = ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT
088:                            - bounds[H];
089:                }
090:            }
091:
092:            /**
093:             * Set the ticker of this ticker layer.
094:             * @param text the text to be displayed on the ticker
095:             * @return * @return true if visability of layer was changed
096:             */
097:            public boolean setText(String text) {
098:                boolean oldVisable = super .visible;
099:                synchronized (this ) {
100:                    this .text = text;
101:                    super .visible = (text != null && text.trim().length() > 0);
102:                    textLoc = bounds[X] + bounds[W];
103:                    textLen = (text == null) ? 0 : TickerSkin.FONT
104:                            .stringWidth(text);
105:                    setDirty();
106:                }
107:                return (oldVisable != super .visible);
108:            }
109:
110:            public String getText() {
111:                return text;
112:            }
113:
114:            protected void paintBody(Graphics g) {
115:                synchronized (this ) {
116:                    if (text == null) {
117:                        return;
118:                    }
119:                    g.setFont(TickerSkin.FONT);
120:                    if (TickerSkin.COLOR_FG_SHD != TickerSkin.COLOR_FG) {
121:                        int x = textLoc;
122:                        int y = TickerSkin.TEXT_ANCHOR_Y;
123:                        switch (TickerSkin.TEXT_SHD_ALIGN) {
124:                        case (Graphics.TOP | Graphics.LEFT):
125:                            x -= 1;
126:                            y -= 1;
127:                            break;
128:                        case (Graphics.TOP | Graphics.RIGHT):
129:                            x += 1;
130:                            y -= 1;
131:                            break;
132:                        case (Graphics.BOTTOM | Graphics.LEFT):
133:                            x -= 1;
134:                            y += 1;
135:                            break;
136:                        case (Graphics.BOTTOM | Graphics.RIGHT):
137:                        default:
138:                            x += 1;
139:                            y += 1;
140:                            break;
141:                        }
142:                        g.setColor(TickerSkin.COLOR_FG_SHD);
143:                        g.drawString(text, x, y, Graphics.TOP
144:                                | TickerSkin.DIRECTION);
145:                    }
146:                    g.setColor(TickerSkin.COLOR_FG);
147:                    g.drawString(text, textLoc, TickerSkin.TEXT_ANCHOR_Y,
148:                            Graphics.TOP | TickerSkin.DIRECTION);
149:
150:                    if (tickerPainter == null) {
151:                        startTicker();
152:                    }
153:                }
154:            }
155:
156:            public void startTicker() {
157:                if (!visible) {
158:                    return;
159:                }
160:
161:                stopTicker();
162:                tickerPainter = new TickerPainter();
163:                tickerTimer.schedule(tickerPainter, 0, TickerSkin.RATE);
164:            }
165:
166:            /**
167:             * Stop the ticking of the ticker.
168:             */
169:            public void stopTicker() {
170:                if (tickerPainter == null) {
171:                    return;
172:                }
173:                tickerPainter.cancel();
174:                tickerPainter = null;
175:            }
176:
177:            /**
178:             * Update bounds of layer
179:             *
180:             * @param layers - current layer can be dependant on this parameter
181:             */
182:            public void update(CLayer[] layers) {
183:                super .update(layers);
184:                setAnchor();
185:            }
186:
187:            /**
188:             * A special helper class to repaint the Ticker
189:             * if one has been set
190:             */
191:            private class TickerPainter extends TimerTask {
192:                /**
193:                 * Repaint the ticker area of this Screen
194:                 */
195:                public final void run() {
196:                    if (!visible) {
197:                        stopTicker();
198:                    } else {
199:                        requestRepaint();
200:                        switch (TickerSkin.DIRECTION) {
201:                        case Graphics.RIGHT:
202:                            textLoc += TickerSkin.SPEED;
203:                            if (textLoc >= (bounds[W] + textLen)) {
204:                                textLoc = -(textLen);
205:                            }
206:                            break;
207:                        case Graphics.LEFT:
208:                        default:
209:                            textLoc -= TickerSkin.SPEED;
210:                            if (textLoc <= -(textLen)) {
211:                                textLoc = bounds[X] + bounds[W];
212:                            }
213:                        }
214:                    }
215:                }
216:            }
217:
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.