Source Code Cross Referenced for ScrollArrowLayer.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.skins.SoftButtonSkin;
030:        import com.sun.midp.chameleon.skins.ScreenSkin;
031:
032:        import com.sun.midp.chameleon.*;
033:        import javax.microedition.lcdui.*;
034:        import com.sun.midp.chameleon.skins.ScrollIndSkin;
035:        import com.sun.midp.lcdui.EventConstants;
036:
037:        /**
038:         * A ScrollArrowLayer is a region of the display used for showing scroll indicator
039:         * status arrows.
040:         *
041:         */
042:        public class ScrollArrowLayer extends ScrollIndLayer {
043:            /**
044:             * True if up arrow is visible
045:             */
046:            protected boolean upViz;
047:
048:            /**
049:             * True if down arrow is visible
050:             */
051:            protected boolean downViz;
052:
053:            /**
054:             * Construct a new ScrollIndLayer, visible, but transparent :)
055:             */
056:            public ScrollArrowLayer(CLayer layer) {
057:                this (layer, null);
058:            }
059:
060:            /**
061:             * Additional constructor.
062:             * @param layer the scrollable controlling the scrolling layer 
063:             * @param listener the scrolling listener
064:             */
065:            public ScrollArrowLayer(CLayer layer, ScrollListener listener) {
066:                super (layer, listener);
067:            }
068:
069:            /**
070:             * Calculate layer bounds depending on the scrollable
071:             */
072:            public void setBounds() {
073:                bounds[H] = SoftButtonSkin.HEIGHT;
074:                if (ScrollIndSkin.IMAGE_UP != null) {
075:                    bounds[W] = ScrollIndSkin.IMAGE_UP.getWidth();
076:                    bounds[H] = (2 * ScrollIndSkin.IMAGE_UP.getHeight());
077:                    bounds[Y] = (SoftButtonSkin.HEIGHT - bounds[H]) / 3;
078:                    bounds[H] += bounds[Y];
079:                    bounds[Y] = ScreenSkin.HEIGHT - SoftButtonSkin.HEIGHT
080:                            + bounds[Y];
081:                } else {
082:                    bounds[W] = ScrollIndSkin.WIDTH;
083:                    bounds[Y] = 3;
084:                }
085:                bounds[X] = (ScreenSkin.WIDTH - bounds[W]) / 2;
086:            }
087:
088:            /**
089:             * Set the current vertical scroll position and proportion.
090:             *
091:             * @param scrollPosition vertical scroll position.
092:             * @param scrollProportion vertical scroll proportion.
093:             */
094:            public void setVerticalScroll(int scrollPosition,
095:                    int scrollProportion) {
096:                boolean up = upViz;
097:                boolean dn = downViz;
098:                if ((scrollable != null) && (scrollProportion < 100)) {
099:                    upViz = (scrollPosition > 0);
100:                    downViz = (scrollPosition < 100);
101:                } else {
102:                    upViz = downViz = false;
103:                }
104:                setVisible(upViz || downViz);
105:                if (up != upViz || dn != downViz) {
106:                    requestRepaint();
107:                }
108:            }
109:
110:            /**
111:             * Paint the scroll indicator.  The indicator arrows may be appear 
112:             * individually
113:             * or together, and may vary in appearance based on whether they appear
114:             * in the normalsoft button region or an alert's softbutton region.
115:             * The visible state is based on the state of the <code>alertMode</code>, 
116:             * <code>upViz</code>, and <code>downViz</code> variables set by the
117:             * <code>setVerticalScroll</code> method.
118:             * @param g the graphics context to paint in
119:             */
120:            protected void paintBody(Graphics g) {
121:                if (upViz) {
122:                    Image i = ScrollIndSkin.IMAGE_UP;
123:                    if (alertMode && ScrollIndSkin.IMAGE_AU_UP != null) {
124:                        i = ScrollIndSkin.IMAGE_AU_UP;
125:                    }
126:                    if (i != null) {
127:                        g.drawImage(i, 0, 0, Graphics.LEFT | Graphics.TOP);
128:                    }
129:                }
130:
131:                if (downViz) {
132:                    Image i = ScrollIndSkin.IMAGE_DN;
133:                    if (alertMode && ScrollIndSkin.IMAGE_AU_DN != null) {
134:                        i = ScrollIndSkin.IMAGE_AU_DN;
135:                    }
136:                    if (i != null) {
137:                        g.drawImage(i, 0, bounds[H]
138:                                - ScrollIndSkin.IMAGE_DN.getHeight(),
139:                                Graphics.LEFT | Graphics.TOP);
140:                    }
141:                }
142:            }
143:
144:            /**
145:             * Handle input from a pen tap. Parameters describe
146:             * the type of pen event and the x,y location in the
147:             * layer at which the event occurred. Important : the
148:             * x,y location of the pen tap will already be translated
149:             * into the coordinate space of the layer.
150:             *
151:             * @param type the type of pen event
152:             * @param x the x coordinate of the event
153:             * @param y the y coordinate of the event
154:             */
155:            public boolean pointerInput(int type, int x, int y) {
156:                switch (type) {
157:                case EventConstants.PRESSED:
158:                    // case EventConstants.HOLD:
159:                    // no action for tap-and-hold in scrollbar
160:                    // cancel timer for any press.
161:
162:                    int scrollType = getScrollType(x, y);
163:                    if (scrollType == SCROLL_LINEDOWN
164:                            || scrollType == SCROLL_LINEUP) {
165:                        listener.scrollContent(scrollType, 0);
166:                    }
167:                    break;
168:                case EventConstants.RELEASED:
169:                    // do nothing 
170:                    break;
171:                default:
172:                    break;
173:                }
174:
175:                /* we should process all of the pointer event inside scroll layer
176:                   and don't pass it to underlying layer */
177:                return true;
178:            }
179:
180:            /**
181:             * Determine he scroll type basing on the pointer coordinates
182:             * @param x - x coordinate 
183:             * @param y - y coordinate
184:             * @return the scroll type
185:             * The possible types of scrolling are 
186:             * @see #SCROLL_NONE
187:             * @see #SCROLL_LINEUP
188:             * @see #SCROLL_LINEDOWN
189:             */
190:            private int getScrollType(int x, int y) {
191:                int ret = SCROLL_NONE;
192:                if (x >= 0 && x <= bounds[W] && y >= 0 && y <= bounds[H]) {
193:                    if (upViz && y < bounds[H] / 2) {
194:                        ret = SCROLL_LINEUP;
195:                    } else if (downViz && y > bounds[H] / 2) {
196:                        ret = SCROLL_LINEDOWN;
197:                    }
198:                }
199:                return ret;
200:            }
201:
202:            /**
203:             * Set new scrollable 
204:             * @param layer new scrollable controlling the scrolling layer
205:             * @return true if the scrollable is changed, false - otherwise
206:             */
207:            public boolean setScrollable(CLayer layer) {
208:                boolean ret = super .setScrollable(layer);
209:                if (ret) {
210:                    alertMode |= scrollable instanceof  MenuLayer;
211:                }
212:                upViz = downViz = false;
213:                return ret;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.