Source Code Cross Referenced for GameCanvasLFImpl.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.Image;
029:        import javax.microedition.lcdui.Graphics;
030:        import javax.microedition.lcdui.game.GameCanvas;
031:
032:        /**
033:         * This is the look & feel implementation for GameCanvas.
034:         */
035:        public class GameCanvasLFImpl {
036:
037:            /**
038:             * The owner of this view.
039:             */
040:            GameCanvas owner;
041:
042:            /**
043:             * Currently every GameCanvas has one offscreen buffer 
044:             * Can be optimized so that we put a limit on number of 
045:             * offscreen buffers an application can have
046:             */
047:            private Image offscreenBuffer;
048:
049:            /** Cached reference to GraphicsAccess instance */
050:            private GraphicsAccess graphicsAccess;
051:
052:            /**
053:             * Create new implementation instance for the given GameCanvas
054:             * @param c GameCanvas instance to create the implementation for
055:             */
056:            public GameCanvasLFImpl(GameCanvas c) {
057:                owner = c;
058:                graphicsAccess = GameMap.getGraphicsAccess();
059:
060:                /* IMPL_NOTE: The initial off-screen buffer has the same width
061:                 *   and height as the entire screen. Further resizing will not
062:                 *   cause memory reallocation until new geometry is bigger than
063:                 *   the current one. Screen rotation is one of the cases the
064:                 *   reallocation is needed.
065:                 *
066:                 *   User can override the methods getWidth() and getHeight() of
067:                 *   GameCanvas, so they should not be used for off-screen buffer
068:                 *   initial allocation.
069:                 */
070:                offscreenBuffer = Image.createImage(graphicsAccess
071:                        .getScreenWidth(), graphicsAccess.getScreenHeight());
072:            }
073:
074:            /**
075:             * Handle screen size change event to update internal
076:             * state of the GameCanvas accordingly
077:             *
078:             * @param w new screen width
079:             * @param h new screen height
080:             */
081:            public void lCallSizeChanged(int w, int h) {
082:                // Resize off-screen buffer in the case it is not big enough only
083:                if (w > offscreenBuffer.getWidth()
084:                        || h > offscreenBuffer.getHeight()) {
085:
086:                    // OutOfMemoryError can be thrown
087:                    graphicsAccess.resizeImage(offscreenBuffer, w, h, true);
088:                }
089:            }
090:
091:            /**
092:             * Obtains the Graphics object for rendering a GameCanvas.  The returned
093:             * Graphics object renders to the off-screen buffer belonging to this
094:             * GameCanvas.
095:             *
096:             * IMPL_NOTE: The dimensions of the Graphics object are explicitly
097:             *   set to GameCanvas size, since off-screen buffer larger than
098:             *   GameCanvas can be used, while some JSR clients need to translate
099:             *   the coordinates regarding the GameCanvas size.
100:             *       Anyway if GameCanvas has zero width or height, the Graphics
101:             *   dimensions are set to entire off-screen buffer.
102:             *
103:             * @return  the Graphics object that renders to current GameCanvas
104:             */
105:            public Graphics getGraphics() {
106:                if (offscreenBuffer != null) {
107:                    int w = owner.getWidth();
108:                    int h = owner.getHeight();
109:
110:                    Graphics g = ((w <= 0) || (h <= 0)) ? offscreenBuffer
111:                            .getGraphics() : graphicsAccess.getImageGraphics(
112:                            offscreenBuffer, w, h);
113:
114:                    graphicsAccess.setGraphicsCreator(g, owner);
115:                    return g;
116:                }
117:
118:                return null;
119:            }
120:
121:            /**
122:             * Render the off-screen buffer content to the Graphics object
123:             * @param g the Graphics object to render off-screen buffer content
124:             */
125:            public void drawBuffer(Graphics g) {
126:                // NullPointerException will be thrown in drawImage if g == null
127:                if (offscreenBuffer != null) {
128:                    g.drawImage(offscreenBuffer, 0, 0, Graphics.TOP
129:                            | Graphics.LEFT);
130:                }
131:            }
132:
133:            /**
134:             * Flushes the off-screen buffer to the display. The size
135:             * of the flushed area is equal to the size of the GameCanvas.
136:             */
137:            public void flushGraphics() {
138:                DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
139:                if (displayAccess != null && offscreenBuffer != null) {
140:                    displayAccess.flush(owner, offscreenBuffer, 0, 0, owner
141:                            .getWidth(), owner.getHeight());
142:                }
143:            }
144:
145:            /**
146:             * Flushes the specified region of the off-screen buffer to the display.
147:             * @param x the left edge of the region to be flushed
148:             * @param y the top edge of the region to be flushed
149:             * @param width the width of the region to be flushed
150:             * @param height the height of the region to be flushed
151:             */
152:            public void flushGraphics(int x, int y, int width, int height) {
153:                if (width < 1 || height < 1) {
154:                    return;
155:                }
156:
157:                DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
158:                if (displayAccess != null && offscreenBuffer != null) {
159:                    displayAccess.flush(owner, offscreenBuffer, x, y, width,
160:                            height);
161:                }
162:            }
163:
164:            /**
165:             * Gets the states of the physical game keys.
166:             * @return An integer containing the key state information (one bit per
167:             * key), or 0 if the GameCanvas is not currently shown.
168:             */
169:            public int getKeyStates() {
170:                DisplayAccess displayAccess = GameMap.getDisplayAccess(owner);
171:                if (displayAccess != null) {
172:                    return displayAccess.getKeyMask();
173:                }
174:                return 0;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.