Source Code Cross Referenced for WindowSystem.java in  » 6.0-JDK-Modules » j2me » sun » porting » windowsystem » 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 » sun.porting.windowsystem 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)WindowSystem.java	1.33 06/10/10
003:         *
004:         * Copyright  1990-2006 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:
028:        package sun.porting.windowsystem;
029:
030:        import sun.porting.graphicssystem.CursorImage;
031:        import sun.porting.graphicssystem.GraphicsSystem;
032:        import sun.porting.toolkit.ToolkitEventHandler;
033:        import java.awt.AWTError;
034:        import java.awt.Cursor;
035:        import java.awt.Dimension;
036:        import java.awt.Image;
037:        import java.awt.image.ColorModel;
038:        import java.security.AccessController;
039:        import sun.security.action.GetPropertyAction;
040:
041:        /**
042:         * This is the top-level entry point for a window system implementation.
043:         * It manages the creation of resources (windows, images, fonts, cursors)
044:         * and the delivery of input events.
045:         *
046:         * @version 1.28, 08/19/02
047:         */
048:        public abstract class WindowSystem {
049:            private static WindowSystem windowSystem = null;
050:            private static final int DRAWABLE_IMAGE_STATUS = java.awt.image.ImageObserver.WIDTH
051:                    | java.awt.image.ImageObserver.HEIGHT
052:                    | java.awt.image.ImageObserver.PROPERTIES
053:                    | java.awt.image.ImageObserver.ALLBITS;
054:
055:            /**
056:             * Obtain an object corresponding to the default window system.
057:             */
058:            public static WindowSystem getDefaultWindowSystem() {
059:                if (windowSystem == null) {
060:                    String nm = (String) AccessController
061:                            .doPrivileged(new GetPropertyAction(
062:                                    "sun.windowsystem",
063:                                    "sun.awt.aw.WindowSystem"));
064:                    try {
065:                        windowSystem = (WindowSystem) Class.forName(nm)
066:                                .newInstance();
067:                    } catch (ClassNotFoundException e) {
068:                        throw new AWTError("WindowSystem not found: " + nm);
069:                    } catch (InstantiationException e) {
070:                        throw new AWTError(
071:                                "Could not instantiate WindowSystem: " + nm);
072:                    } catch (IllegalAccessException e) {
073:                        throw new AWTError("Could not access WindowSystem: "
074:                                + nm);
075:                    }
076:                }
077:                return windowSystem;
078:            }
079:
080:            /**
081:             * Make a new <code>WindowSystem</code> object
082:             */
083:            public WindowSystem() {
084:                this (GraphicsSystem.getDefaultGraphicsSystem());
085:            }
086:
087:            /**
088:             * Make a new <code>WindowSystem</code> object running on top of the specified <code>GraphicsSystem</code>.
089:             */
090:            public WindowSystem(GraphicsSystem gfx) {
091:                gfxSys = gfx;
092:            }
093:
094:            protected GraphicsSystem gfxSys;
095:
096:            /**
097:             * Register a callback handler for receiving events.
098:             * @param h The callback handler, a <code>ToolkitEventHandler</code> object.
099:             * @throws IllegalStateException if there is already a handler
100:             * registered.
101:             */
102:            public abstract void registerToolkitEventHandler(
103:                    ToolkitEventHandler h) throws IllegalStateException;
104:
105:            /**
106:             * Change the factory object used to create windows.  (The factory
107:             * mechanism is used in case a subclass of <code>Window</code> is needed.) 
108:             * If factory is null, use the window system's default factory.
109:             */
110:            public abstract void setWindowFactory(WindowFactory factory);
111:
112:            /**
113:             * Start the window system running.  This will create the root
114:             * window, etc.  (A separate start mechanism is necessary in
115:             * order to break the mutual dependency between WindowSystem and
116:             * WindowFactory.)
117:             */
118:            public abstract void start();
119:
120:            /**
121:             * Return the root window.  Use with caution!
122:             */
123:            public abstract Window getRootWindow();
124:
125:            /**
126:             * Create a new window as a child of the given parent window,
127:             * and having the specified dimensions.  Uses the current 
128:             * <code>WindowFactory</code>.
129:             * @param parent The parent window.
130:             * @param x the x coordinate for the window's upper left hand corner,
131:             * in the coordinate system of the parent window.
132:             * @param y the y coordinate for the window's upper left hand corner,
133:             * in the coordinate system of the parent window.
134:             * @param w the width of the window
135:             * @param h the height of the window
136:             * @return The new <code>Window</code> object.
137:             */
138:            public abstract Window makeWindow(Window parent, int x, int y,
139:                    int w, int h);
140:
141:            /**
142:             * Create a new top-level window of the given type
143:             * and having the specified dimensions.  Uses the current 
144:             * <code>WindowFactory</code>.
145:             * @param windowType The type of the window
146:             * @param x the x coordinate for the window's upper left hand corner,
147:             * in the global coordinate system
148:             * @param y the y coordinate for the window's upper left hand corner,
149:             * in the global coordinate system
150:             * @param w the width of the window
151:             * @param h the height of the window
152:             * @return The new <code>Window</code> object.
153:             */
154:            public abstract Window makeTopLevelWindow(int windowType, int x,
155:                    int y, int w, int h);
156:
157:            /**
158:             * Get the window that has the keyboard input focus, or null if the
159:             * focus is not assigned to any window.
160:             * @return A <code>Window</code> object corresponding to the window that will receive
161:             * any keyboard events which occur.
162:             */
163:            public abstract Window getFocusWindow();
164:
165:            /**
166:             * Get the window that has grabbed input, or null if none has.
167:             * @return A <code>Window</code> object corresponding to the window that has grabbed
168:             * input events.  Note that the grabbing window will not have the keyboard
169:             * focus unless it has been specifically assigned to it.
170:             */
171:            public abstract Window getGrabbingWindow();
172:
173:            // these can be straight pass-throughs from graphics system, or not...
174:
175:            /**
176:             * Get a new rectangular region.
177:             * @param x The upper left x coordinate of the region
178:             * @param y The upper left y coordinate of the region
179:             * @param w The width of the region
180:             * @param h The height of the region
181:             * @return The newly-created <code>Region</code> object.
182:             */
183:            public sun.porting.graphicssystem.Region makeRegion(int x, int y,
184:                    int w, int h) {
185:                return gfxSys.makeRegion(x, y, w, h);
186:            }
187:
188:            /**
189:             * Get an implementation of a typeface with the given name and
190:             * style.  Style values are as in <code>java.awt.Font</code>.
191:             * @param name The name of the typeface
192:             * @param style The style (<code>PLAIN</code>, <code>BOLD</code>, <code>ITALIC</code>) of the font.
193:             * @return A <code>FontPeer</code> for the nearest matching font.
194:             * @see java.awt.Font
195:             */
196:            public sun.awt.peer.FontPeer getFont(String name, int style) {
197:                return gfxSys.getFont(name, style);
198:            }
199:
200:            /**
201:             * Get a valid <code>FontMetrics</code> object for the given font.
202:             * @param font The java font descriptor for the font
203:             * @return The corresponding <code>FontMetrics</code> object.
204:             * @see java.awt.Font
205:             */
206:            public java.awt.FontMetrics getFontMetrics(java.awt.Font font) {
207:                return gfxSys.getFontMetrics(font);
208:            }
209:
210:            /**
211:             * Get an implementation of an image that corresponds to the
212:             * given <code>ImageRepresentation</code> object.
213:             * @param image The <code>ImageRepresentation</code> object describing this image
214:             * @see java.awt.Image
215:             * @see sun.awt.ImageRepresentation
216:             * @return An image, initialized from the given <code>ImageRepresentation</code>.
217:             */
218:            public Image getImage(java.awt.image.ImageProducer producer) {
219:                // NOTE: If the system has to support multiple screens,
220:                // and the screens can have different underlying ColorModels,
221:                // we might have to carry around a "meta" ImageRepresentation
222:                // and program the system accordingly.  Some aspects of the
223:                // image implementation in sun.awt.image may have to change
224:                // to accomodate this.
225:                return gfxSys.getImage(producer);
226:            }
227:
228:            /**
229:             * Get an <code>Image</code> object for use as an offscreen
230:             * drawing area.  The object should have the specified size
231:             * and color model.
232:             * @param w The width of the offscreen image
233:             * @param h The height of the offscreen image
234:             * @return An offscreen image into which graphics can be drawn.
235:             */
236:            public Image makeDrawableImage(java.awt.Component c, int w, int h) {
237:                // NOTE: If the system has to support multiple screens,
238:                // and the screens can have different underlying ColorModels,
239:                // we might have to carry around a "meta" ImageRepresentation
240:                // and program the system accordingly.  Some aspects of the
241:                // image implementation in sun.awt.image may have to change
242:                // to accomodate this.
243:                return gfxSys.makeDrawableImage(c, w, h);
244:            }
245:
246:            /**
247:             * Set the visibility of the cursor.
248:             * @param visible Whether to make the cursor visible or hidden.
249:             */
250:            public void setCursorVisibility(boolean visible) {
251:                gfxSys.setCursorVisibility(visible);
252:            }
253:
254:            /**
255:             * Query the visibility of the cursor.
256:             * @return true if the cursor is currently visible.
257:             */
258:            public boolean isCursorVisible() {
259:                return gfxSys.isCursorVisible();
260:            }
261:
262:            /**
263:             * Create a new <code>CursorImage</code> object.
264:             */
265:            public CursorImage makeCursorImage(java.awt.Image img, int hotX,
266:                    int hotY) {
267:                return gfxSys.makeCursorImage(img, hotX, hotY);
268:            }
269:
270:            /**
271:             * Get a <code>CursorImage</code> object that corresponds to a standard 
272:             * "system" cursor.
273:             * @param c A Cursor object which specifies a standard system cursor.
274:             * @return The corresponding CursorImage.
275:             */
276:            public CursorImage getCursorImage(Cursor c) {
277:                return gfxSys.getCursorImage(c);
278:            }
279:
280:            /**
281:             * Set the cursor image to match the supplied <code>CursorImage</code>.
282:             * @param image The cursor image
283:             */
284:            public void setCursorImage(CursorImage image) {
285:                gfxSys.setCursorImage(image);
286:            }
287:
288:            /**
289:             * Get the maximum supported size for a cursor.
290:             * @return a Dimension object containing the maximum cursor size, or
291:             * null if there is no maximum.  A return value of null implies that
292:             * there is no maximum; it does not guarantee that all sizes are
293:             * supported because aspect ratio has not been taken into account.
294:             */
295:            public Dimension getMaximumCursorSize() {
296:                return gfxSys.getMaximumCursorSize();
297:            }
298:
299:            /**
300:             * Find the nearest supported cursor size.
301:             * @return true if the size is supported, false otherwise.
302:             */
303:            public Dimension getBestCursorSize(int width, int height) {
304:                return gfxSys.getBestCursorSize(width, height);
305:            }
306:
307:            /**
308:             * Returns the maximum number of colors allowed in a cursor.  "Transparent"
309:             * is not to be counted as a color.
310:             * @return the maximum number of colors supported in a cursor image.
311:             */
312:            public int getMaximumCursorColors() {
313:                return gfxSys.getMaximumCursorColors();
314:            }
315:
316:            /**
317:             * Get the color model of the screen.
318:             * @return The color model, as a java.awt.image.ColorModel object
319:             */
320:            public java.awt.image.ColorModel getScreenColorModel() {
321:                return gfxSys.getScreen().getColorModel();
322:            }
323:
324:            /**
325:             * Prepares an image for rendering. 
326:             * <p>
327:             * If the values of the width and height arguments are both 
328:             * <code>-1</code>, this method prepares the image for rendering 
329:             * on the default screen; otherwise, this method prepares an image 
330:             * for rendering on the default screen at the specified width and height. 
331:             * <p>
332:             * The image data is downloaded asynchronously in another thread, 
333:             * and an appropriately scaled screen representation of the image is 
334:             * generated. 
335:             * <p>
336:             * This method is called by components <code>prepareImage</code> 
337:             * methods. 
338:             * <p>
339:             * Information on the flags returned by this method can be found 
340:             * with the definition of the <code>ImageObserver</code> interface. 
341:
342:             * @param     image      the image for which to prepare a  
343:             *                           screen representation.
344:             * @param     width      the width of the desired screen 
345:             *                           representation, or <code>-1</code>.
346:             * @param     height     the height of the desired screen 
347:             *                           representation, or <code>-1</code>.
348:             * @param     observer   the <code>ImageObserver</code> 
349:             *                           object to be notified as the 
350:             *                           image is being prepared.
351:             * @return    <code>true</code> if the image has already been 
352:             *                 fully prepared; <code>false</code> otherwise.
353:             * @see       java.awt.Component#prepareImage(java.awt.Image, 
354:             *                 java.awt.image.ImageObserver)
355:             * @see       java.awt.Component#prepareImage(java.awt.Image, 
356:             *                 int, int, java.awt.image.ImageObserver)
357:             * @see       java.awt.image.ImageObserver
358:             * @since     JDK1.0
359:             */
360:            public boolean prepareScrImage(java.awt.Image image, int width,
361:                    int height, java.awt.image.ImageObserver observer) {
362:                if (image instanceof  sun.porting.graphicssystem.Drawable) {
363:                    return true;
364:                } else {
365:                    return gfxSys.prepareScrImage(image, width, height,
366:                            observer);
367:                }
368:            }
369:
370:            /**
371:             * Indicates the construction status of a specified image that is
372:             * being prepared for display.
373:             * <p>
374:             * If the values of the width and height arguments are both 
375:             * <code>-1</code>, this method returns the construction status of 
376:             * a screen representation of the specified image in this toolkit. 
377:             * Otherwise, this method returns the construction status of a
378:             * scaled representation of the image at the specified width 
379:             * and height.
380:             * <p>
381:             * This method does not cause the image to begin loading. 
382:             * An application must call <code>prepareImage</code> to force 
383:             * the loading of an image.
384:             * <p>
385:             * This method is called by the component's <code>checkImage</code>
386:             * methods.
387:             * <p>
388:             * Information on the flags returned by this method can be found
389:             * with the definition of the <code>ImageObserver</code> interface.
390:             * @param     image   the image whose status is being checked.
391:             * @param     width   the width of the scaled version whose status is
392:             *                 being checked, or <code>-1</code>.
393:             * @param     height  the height of the scaled version whose status
394:             *                 is being checked, or <code>-1</code>.
395:             * @param     observer   the <code>ImageObserver</code> object to be
396:             *                 notified as the image is being prepared.
397:             * @return    the bitwise inclusive <strong>OR</strong> of the
398:             *                 <code>ImageObserver</code> flags for the 
399:             *                 image data that is currently available.
400:             * @see       java.awt.Toolkit#prepareImage(java.awt.Image, 
401:             *                 int, int, java.awt.image.ImageObserver)
402:             * @see       java.awt.Component#checkImage(java.awt.Image, 
403:             *                 java.awt.image.ImageObserver)
404:             * @see       java.awt.Component#checkImage(java.awt.Image, 
405:             *                 int, int, java.awt.image.ImageObserver)
406:             * @see       java.awt.image.ImageObserver
407:             * @since     JDK1.0
408:             */
409:            public int checkScrImage(java.awt.Image image, int width,
410:                    int height, java.awt.image.ImageObserver observer) {
411:                if (image instanceof  sun.porting.graphicssystem.Drawable) {
412:                    return DRAWABLE_IMAGE_STATUS;
413:                } else {
414:                    return gfxSys.checkScrImage(image, width, height, observer);
415:                }
416:            }
417:
418:            /**
419:             * Return the resolution of the screen, in pixels per inch.
420:             */
421:            public int getScreenResolution() {
422:                return gfxSys.getScreenResolution();
423:            }
424:
425:            /**
426:             * Synchronizes the graphics state. Some systems may do buffering of graphics events;
427:             * this method ensures that the display is up-to-date. It is useful
428:             * for animation.
429:             */
430:            public void sync() {
431:                gfxSys.sync();
432:            }
433:
434:            /**
435:             * Emits an audio beep.
436:             */
437:            public void beep() {
438:                gfxSys.beep();
439:            }
440:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.