Source Code Cross Referenced for GCIEventListener.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:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004:         * 
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License version
007:         * 2 only, as published by the Free Software Foundation.
008:         * 
009:         * This program is distributed in the hope that it will be useful, but
010:         * WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012:         * General Public License version 2 for more details (a copy is
013:         * included at /legal/license.txt).
014:         * 
015:         * You should have received a copy of the GNU General Public License
016:         * version 2 along with this work; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018:         * 02110-1301 USA
019:         * 
020:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021:         * Clara, CA 95054 or visit www.sun.com if you need additional
022:         * information or have any questions.
023:         */
024:
025:        package com.sun.midp.lcdui;
026:
027:        import com.sun.me.gci.windowsystem.*;
028:        import com.sun.me.gci.windowsystem.event.*;
029:
030:        import com.sun.midp.events.EventTypes;
031:        import com.sun.midp.events.NativeEvent;
032:        import com.sun.midp.events.EventQueue;
033:
034:        import com.sun.midp.configurator.Constants;
035:
036:        class GCIEventListener implements  GCIKeyEventListener,
037:                GCIPointerEventListener {
038:
039:            /** Preallocate KeyEvent */
040:            final NativeEvent keyEvent;
041:
042:            /** Preallocate Pointer Event */
043:            final NativeEvent pointerEvent;
044:
045:            /** Cached reference to the MIDP event queue. */
046:            private EventQueue eventQueue;
047:
048:            /**
049:             * The constructor for the GCIEventListener that 
050:             * gets key and pointer events from GCI,
051:             * does translate to LCDUI input events and posts them to 
052:             * LCDUI event queue.
053:             *
054:             * @param eventQueue the event queue
055:             */
056:            GCIEventListener(EventQueue eventQueue) {
057:                this .eventQueue = eventQueue;
058:                keyEvent = new NativeEvent(EventTypes.KEY_EVENT);
059:                pointerEvent = new NativeEvent(EventTypes.PEN_EVENT);
060:            }
061:
062:            /** 
063:             * Called when GCIKeyEvent is received. It will translate
064:             * the event into a corresponding MIDP NativeEvent and post
065:             * it to the event queue.
066:             *
067:             * @param event instance of GCIKeyEvent
068:             */
069:            public boolean keyEventReceived(GCIKeyEvent event) {
070:
071:                int type = 0;
072:                int keyCode = event.getKeyCode();
073:                int keyChar = event.getKeyChar();
074:
075:                switch (event.getID()) {
076:                case GCIKeyEvent.KEY_PRESSED:
077:                    type = EventConstants.PRESSED;
078:                    break;
079:
080:                case GCIKeyEvent.KEY_RELEASED:
081:                    type = EventConstants.RELEASED;
082:                    break;
083:
084:                default:
085:                    return false;
086:                }
087:
088:                boolean foundKeyCode = false;
089:                for (int i = keyMappingTable.length - 1; i >= 0; i--) {
090:                    if (keyCode == keyMappingTable[i][1]) {
091:                        keyCode = keyMappingTable[i][0];
092:                        foundKeyCode = true;
093:                    }
094:
095:                }
096:
097:                if (!foundKeyCode
098:                        && (keyCode == GCIKeyEvent.VK_UNDEFINED || keyChar == GCIKeyEvent.CHAR_UNDEFINED)) {
099:
100:                    return false;
101:                }
102:
103:                DisplayAccess displayAccess = (DisplayAccess) event
104:                        .getPeerEventTarget();
105:
106:                if (displayAccess == null) {
107:                    return false;
108:                }
109:
110:                keyEvent.intParam1 = type;
111:                keyEvent.intParam2 = keyCode;
112:                keyEvent.intParam4 = displayAccess.getDisplayId();
113:                eventQueue.post(keyEvent);
114:
115:                return true;
116:            }
117:
118:            /** 
119:             * Called when GCIPointerEvent is received. It will translate
120:             * the event into a corresponding MIDP NativeEvent and post
121:             * it to the event queue.
122:             *
123:             * @param event instance of GCIPointerEvent
124:             */
125:            public boolean pointerEventReceived(GCIPointerEvent event) {
126:                int id = event.getID();
127:                int x = event.getX();
128:                int y = event.getY();
129:                int button = event.getButton();
130:                int modifiers = event.getModifiers();
131:                long when = System.currentTimeMillis();
132:
133:                int type = 0;
134:
135:                switch (event.getID()) {
136:                case GCIPointerEvent.POINTER_PRESSED:
137:                    type = EventConstants.PRESSED;
138:                    break;
139:
140:                case GCIPointerEvent.POINTER_RELEASED:
141:                    type = EventConstants.RELEASED;
142:                    break;
143:
144:                case GCIPointerEvent.POINTER_MOVED:
145:                    type = EventConstants.DRAGGED;
146:                    break;
147:
148:                default:
149:                    return false;
150:                }
151:
152:                DisplayAccess displayAccess = (DisplayAccess) event
153:                        .getPeerEventTarget();
154:
155:                if (displayAccess == null) {
156:                    return false;
157:                }
158:
159:                pointerEvent.intParam1 = type;
160:                pointerEvent.intParam2 = event.getX();
161:                pointerEvent.intParam3 = event.getY();
162:                pointerEvent.intParam4 = displayAccess.getDisplayId();
163:                eventQueue.post(pointerEvent);
164:
165:                return true;
166:            }
167:
168:            /** Table used to key mapping */
169:            private int keyMappingTable[][] = { { Constants.KEYCODE_UP, 38 },
170:                    { Constants.KEYCODE_DOWN, 40 },
171:                    { Constants.KEYCODE_LEFT, 37 },
172:                    { Constants.KEYCODE_RIGHT, 39 },
173:                    { Constants.KEYCODE_SELECT, 10 } };
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.