Source Code Cross Referenced for DisplayContainer.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:
027:        package com.sun.midp.lcdui;
028:
029:        import java.util.Vector;
030:
031:        import com.sun.midp.security.Permissions;
032:        import com.sun.midp.security.SecurityToken;
033:
034:        /**
035:         * Stores array of active displays that either belong to MIdlets, 
036:         * or dynamically created for display preemption.
037:         */
038:        public class DisplayContainer {
039:
040:            /** ID of the Isolate this instance is created in */
041:            private final int isolateId;
042:
043:            /** Last local Display count used to create Display ID */
044:            private int lastLocalDisplayId;
045:
046:            /** Active displays. */
047:            private Vector displays = new Vector(5, 5);
048:
049:            /** 
050:             * Default constructor.
051:             *
052:             * @param token security token for initilaization
053:             * @param isolateId id of the Isolate this instance is created in
054:             */
055:            public DisplayContainer(SecurityToken token, int isolateId) {
056:                token.checkIfPermissionAllowed(Permissions.MIDP);
057:                this .isolateId = isolateId;
058:            }
059:
060:            /**
061:             * Adds a display object to the container and sets a the display's ID to
062:             * new unique value for this isolate, as a single atomic operation.
063:             * <p>
064:             * Intended to be called from Display constructor.
065:             *
066:             * @param da display object to add
067:             */
068:            public synchronized void addDisplay(DisplayAccess da) {
069:                if (displays.indexOf(da) == -1) {
070:                    int newId = createDisplayId();
071:                    da.setDisplayId(newId);
072:                    displays.addElement(da);
073:                }
074:            }
075:
076:            /**
077:             * Get a display to request the foreground on behalf of the MIDlet.
078:             *
079:             * @param nameOfOwner class name of the MIDlet that owns this display
080:             */
081:            public void requestForegroundForDisplay(String nameOfOwner) {
082:                DisplayAccess da = findDisplayByOwner(nameOfOwner);
083:
084:                da.requestForeground();
085:            }
086:
087:            /**
088:             * Removes display object from the container.
089:             *
090:             * @param nameOfOwner class name of the MIDlet that owns this display
091:             *
092:             * @return true if display has been succcessfully removed, 
093:             *         false, if display object has not been found in the container.
094:             */
095:            public synchronized boolean removeDisplay(String nameOfOwner) {
096:                DisplayAccess da = findDisplayByOwner(nameOfOwner);
097:
098:                return displays.removeElement(da);
099:            }
100:
101:            /**
102:             * Find a display by ID.
103:             *
104:             * @param displayId ID of the display
105:             *
106:             * @return a display access object or null if not found
107:             */
108:            synchronized DisplayAccess findDisplayById(int displayId) {
109:                int size = displays.size();
110:
111:                for (int i = 0; i < size; i++) {
112:                    DisplayAccess current = (DisplayAccess) displays
113:                            .elementAt(i);
114:
115:                    if (current.getDisplayId() == displayId) {
116:                        return current;
117:                    }
118:                }
119:
120:                return null;
121:            }
122:
123:            /**
124:             * Find a display by owner.
125:             *
126:             * @param nameOfOwner class name of the MIDlet that owns this display
127:             *
128:             * @return a display access object or null if not found
129:             */
130:            public synchronized DisplayAccess findDisplayByOwner(
131:                    String nameOfOwner) {
132:                int size = displays.size();
133:
134:                for (int i = 0; i < size; i++) {
135:                    DisplayAccess current = (DisplayAccess) displays
136:                            .elementAt(i);
137:
138:                    if (current.getNameOfOwner().equals(nameOfOwner)) {
139:                        return current;
140:                    }
141:                }
142:
143:                return null;
144:            }
145:
146:            /**
147:             * Find a display event consumer by ID.
148:             *
149:             * @param displayId ID of the display
150:             *
151:             * @return a display event consumer object or null if not found
152:             */
153:            public DisplayEventConsumer findDisplayEventConsumer(int displayId) {
154:                DisplayAccess da = findDisplayById(displayId);
155:
156:                if (da == null) {
157:                    return null;
158:                }
159:
160:                return da.getDisplayEventConsumer();
161:            }
162:
163:            /**
164:             * Find a foreground event consumer by ID.
165:             *
166:             * @param displayId ID of the display
167:             *
168:             * @return a foreground event consumer object or null if not found
169:             */
170:            public ForegroundEventConsumer findForegroundEventConsumer(
171:                    int displayId) {
172:                DisplayAccess da = findDisplayById(displayId);
173:
174:                if (da == null) {
175:                    return null;
176:                }
177:
178:                return da.getForegroundEventConsumer();
179:            }
180:
181:            /**
182:             * Creates an Display Id that is unique across all Isolates.
183:             * Graphics subsystem depends on this uniqueness, which allows
184:             * quick check on whether a Display is in the foreground
185:             * without having to check Isolate id.
186:             *
187:             * @return a new unique display Id with high 8 bits as Isolate ID,
188:             *		low 24 bits as local display counter.
189:             */
190:            private int createDisplayId() {
191:                int id;
192:
193:                do {
194:                    lastLocalDisplayId++;
195:                    // [high 8 bits: isolate id][low 24 bits: display id]]
196:                    id = ((isolateId & 0xff) << 24)
197:                            | (lastLocalDisplayId & 0x00ffffff);
198:                } while (findDisplayById(id) != null);
199:
200:                return id;
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.