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


001:        /*
002:         * @(#)PPCToolkit.java	1.27 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:        package sun.awt.pocketpc;
028:
029:        import java.awt.*;
030:        import java.awt.image.*;
031:        import sun.awt.peer.*;
032:        import java.awt.datatransfer.Clipboard;
033:        import java.net.URL;
034:        import java.util.Properties;
035:        import sun.awt.im.*;
036:        import sun.awt.AppContext;
037:        import sun.awt.SunToolkit;
038:        import sun.awt.PeerBasedToolkit;
039:        import sun.awt.image.BufferedImagePeer;
040:        import sun.awt.image.ImageRepresentation;
041:
042:        public class PPCToolkit extends PeerBasedToolkit implements  Runnable {
043:
044:            private static native void initIDs();
045:
046:            static {
047:                java.security.AccessController
048:                        .doPrivileged(new sun.security.action.LoadLibraryAction(
049:                                "pocketpcawt"));
050:                initIDs();
051:            }
052:
053:            // Debugging properties
054:            static final boolean enableDebug = true;
055:
056:            // Print any AWT_TRACE statements
057:            boolean dbgTrace = false;
058:            private static final String propTrace = "WINAWT.Trace";
059:
060:            // Verify all components are in sync with their HWND state
061:            boolean dbgVerify = false;
062:            private static final String propVerify = "WINAWT.VerifyComponents";
063:
064:            // Enter debugger on assertion failure
065:            boolean dbgBreak = false;
066:            private static final String propBreak = "WINAWT.BreakOnFailure";
067:
068:            // Enable heap checking
069:            boolean dbgHeapCheck = false;
070:            private static final String propHeapCheck = "WINAWT.HeapCheck";
071:
072:            // System clipboard.
073:            PPCClipboard clipboard;
074:
075:            // Some members that are useful to some components
076:            // TODO: make static when move to JNI
077:            protected int frameWidth;
078:            protected int frameHeight;
079:            protected int vsbMinHeight;
080:            protected int vsbWidth;
081:            protected int hsbMinWidth;
082:            protected int hsbHeight;
083:
084:            public PPCToolkit() {
085:                InitializeDebuggingOptions();
086:
087:                // Startup toolkit thread
088:                synchronized (this ) {
089:
090:                    Thread t = new Thread(this , "AWT-Windows");
091:                    t.setDaemon(false); // Don't exit when main finishes.
092:                    t.start();
093:                    try {
094:                        wait();
095:                    } catch (InterruptedException x) {
096:                    }
097:                    // Create a thread to flush drawing events to the server
098:
099:                    FlushThread flushThread = new FlushThread(this );
100:
101:                    Runtime.getRuntime().addShutdownHook(
102:                            new ShutdownHook(t, flushThread));
103:                }
104:            }
105:
106:            private void InitializeDebuggingOptions() {
107:                String s = Toolkit.getProperty(propTrace, "false");
108:                dbgTrace = Boolean.valueOf(s).booleanValue();
109:                s = Toolkit.getProperty(propVerify, "false");
110:                dbgVerify = Boolean.valueOf(s).booleanValue();
111:                s = Toolkit.getProperty(propBreak, "false");
112:                dbgBreak = Boolean.valueOf(s).booleanValue();
113:                s = Toolkit.getProperty(propHeapCheck, "false");
114:                dbgHeapCheck = Boolean.valueOf(s).booleanValue();
115:            }
116:
117:            public native void init(Thread t);
118:
119:            public void run() {
120:                Thread t = Thread.currentThread();
121:                init(t);
122:                synchronized (this ) {
123:                    notifyAll();
124:                }
125:                eventLoop();
126:            }
127:
128:            /* 
129:             * Notifies the thread that started the server
130:             * to indicate that initialization is complete.
131:             * Then enters an infinite loop that retrieves and processes events.  
132:             */
133:            native void eventLoop();
134:
135:            public static void postEvent(AWTEvent event) {
136:                postEvent(targetToAppContext(event.getSource()), event);
137:            }
138:
139:            public static void postEvent(AppContext appContext, AWTEvent event) {
140:                if (appContext == null) {
141:                    appContext = AppContext.getAppContext();
142:                }
143:
144:                EventQueue theEventQueue = (EventQueue) appContext
145:                        .get(AppContext.EVENT_QUEUE_KEY);
146:
147:                theEventQueue.postEvent(event);
148:                Thread.yield();
149:            }
150:
151:            static native BufferedImagePeer getBufferedImagePeer(
152:                    BufferedImage image);
153:
154:            static native BufferedImage createBufferedImage(
155:                    BufferedImagePeer peer);
156:
157:            /*
158:             * Gets the default encoding used on the current platform
159:             * to transfer text (character) data. 
160:             */
161:            public String getDefaultCharacterEncoding() {
162:                return "iso8859-1";
163:            }
164:
165:            /*
166:             * Create peer objects.
167:             */
168:
169:            public ButtonPeer createButton(Button target) {
170:                ButtonPeer peer = new PPCButtonPeer(target);
171:                peerMap.put(target, peer);
172:                return peer;
173:            }
174:
175:            public TextFieldPeer createTextField(TextField target) {
176:                TextFieldPeer peer = new PPCTextFieldPeer(target);
177:                peerMap.put(target, peer);
178:                return peer;
179:            }
180:
181:            public LabelPeer createLabel(Label target) {
182:                LabelPeer peer = new PPCLabelPeer(target);
183:                peerMap.put(target, peer);
184:                return peer;
185:            }
186:
187:            public ListPeer createList(List target) {
188:                ListPeer peer = new PPCListPeer(target);
189:                peerMap.put(target, peer);
190:                return peer;
191:            }
192:
193:            public CheckboxPeer createCheckbox(Checkbox target) {
194:                CheckboxPeer peer = new PPCCheckboxPeer(target);
195:                peerMap.put(target, peer);
196:                return peer;
197:            }
198:
199:            public ScrollbarPeer createScrollbar(Scrollbar target) {
200:                ScrollbarPeer peer = new PPCScrollbarPeer(target);
201:                peerMap.put(target, peer);
202:                return peer;
203:            }
204:
205:            public ScrollPanePeer createScrollPane(ScrollPane target) {
206:                ScrollPanePeer peer = new PPCScrollPanePeer(target);
207:                peerMap.put(target, peer);
208:                return peer;
209:            }
210:
211:            public TextAreaPeer createTextArea(TextArea target) {
212:                TextAreaPeer peer = new PPCTextAreaPeer(target);
213:                peerMap.put(target, peer);
214:                return peer;
215:            }
216:
217:            static native int getComboHeightOffset();
218:
219:            public ChoicePeer createChoice(Choice target) {
220:                ChoicePeer peer = new PPCChoicePeer(target);
221:                peerMap.put(target, peer);
222:                return peer;
223:            }
224:
225:            public FramePeer createFrame(Frame target) {
226:                FramePeer peer = new PPCFramePeer(target);
227:                peerMap.put(target, peer);
228:                return peer;
229:            }
230:
231:            public CanvasPeer createCanvas(Canvas target) {
232:                CanvasPeer peer = new PPCCanvasPeer(target);
233:                peerMap.put(target, peer);
234:                return peer;
235:            }
236:
237:            public PanelPeer createPanel(Panel target) {
238:                PanelPeer peer = new PPCPanelPeer(target);
239:                peerMap.put(target, peer);
240:                return peer;
241:            }
242:
243:            public WindowPeer createWindow(Window target) {
244:                WindowPeer peer = new PPCWindowPeer(target);
245:                peerMap.put(target, peer);
246:                return peer;
247:            }
248:
249:            public DialogPeer createDialog(Dialog target) {
250:                DialogPeer peer = new PPCDialogPeer(target);
251:                peerMap.put(target, peer);
252:                return peer;
253:            }
254:
255:            public FileDialogPeer createFileDialog(FileDialog target) {
256:                FileDialogPeer peer = new PPCFileDialogPeer(target);
257:                peerMap.put(target, peer);
258:                return peer;
259:            }
260:
261:            public MenuBarPeer createMenuBar(MenuBar target) {
262:                MenuBarPeer peer = new PPCMenuBarPeer(target);
263:                peerMap.put(target, peer);
264:                return peer;
265:            }
266:
267:            public MenuPeer createMenu(Menu target) {
268:
269:                //Netscape : Changed this to 2-step construction to fix problem with 
270:                //creating empty top level menus.  Basically, we have to put the menupeer
271:                //into the peer map before we actually go out and create the peer, because
272:                //peer creation will try to look the peer up in the peer map.  This was 
273:                //causing a menus without items to be created at enormously ridculous
274:                //widths.
275:
276:                PPCMenuPeer peer = new PPCMenuPeer(target);
277:                peerMap.put(target, peer);
278:                peer.create();
279:                return peer;
280:            }
281:
282:            public PopupMenuPeer createPopupMenu(PopupMenu target) {
283:                PopupMenuPeer peer = new PPCPopupMenuPeer(target);
284:                peerMap.put(target, peer);
285:                return peer;
286:            }
287:
288:            public MenuItemPeer createMenuItem(MenuItem target) {
289:                MenuItemPeer peer = new PPCMenuItemPeer(target);
290:                peerMap.put(target, peer);
291:                return peer;
292:            }
293:
294:            public CheckboxMenuItemPeer createCheckboxMenuItem(
295:                    CheckboxMenuItem target) {
296:                CheckboxMenuItemPeer peer = new PPCCheckboxMenuItemPeer(target);
297:                peerMap.put(target, peer);
298:                return peer;
299:            }
300:
301:            /**
302:             * Creates this toolkit's implementation of <code>Font</code> using
303:             * the specified peer interface.
304:             * @param     target the font to be implemented.
305:             * @return    this toolkit's implementation of <code>Font</code>.
306:             * @see       java.awt.Font
307:             * @see       sun.awt.peer.FontPeer
308:             * @since     JDK1.0
309:             */
310:            public FontPeer getFontPeer(Font target) {
311:                return PPCFontPeer.getFontPeer(target);
312:            }
313:
314:            static boolean prepareScrImage(Image img, int w, int h,
315:                    ImageObserver o) {
316:                if (w == 0 || h == 0) {
317:                    return true;
318:                }
319:                PPCImage ximg = (PPCImage) img;
320:                if (ximg.hasError()) {
321:                    if (o != null) {
322:                        o.imageUpdate(img, ImageObserver.ERROR
323:                                | ImageObserver.ABORT, -1, -1, -1, -1);
324:                    }
325:                    return false;
326:                }
327:                ImageRepresentation ir = ximg.getImageRep();
328:                return ir.prepare(o);
329:                //return false;
330:            }
331:
332:            static int checkScrImage(Image img, int w, int h, ImageObserver o) {
333:                if (!(img instanceof  PPCImage)) {
334:                    return ImageObserver.ALLBITS;
335:                }
336:
337:                PPCImage ximg = (PPCImage) img;
338:                int repbits;
339:                if (w == 0 || h == 0) {
340:                    repbits = ImageObserver.ALLBITS;
341:                } else {
342:                    repbits = ximg.getImageRep().check(o);
343:                }
344:                return ximg.check(o) | repbits;
345:            }
346:
347:            public int checkImage(Image img, int w, int h, ImageObserver o) {
348:                return checkScrImage(img, w, h, o);
349:            }
350:
351:            public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
352:                return prepareScrImage(img, w, h, o);
353:            }
354:
355:            public Image createImage(ImageProducer producer) {
356:                return new PPCImage(producer);
357:            }
358:
359:            static native ColorModel makeColorModel();
360:
361:            static ColorModel screenmodel;
362:
363:            static ColorModel getStaticColorModel() {
364:                if (screenmodel == null) {
365:                    screenmodel = makeColorModel();
366:                }
367:                return screenmodel;
368:            }
369:
370:            public ColorModel getColorModel() {
371:                return getStaticColorModel();
372:            }
373:
374:            public native int getScreenResolution();
375:
376:            protected native int getScreenWidth();
377:
378:            protected native int getScreenHeight();
379:
380:            public FontMetrics getFontMetrics(Font font) {
381:                return PPCFontMetrics.getFontMetrics(font);
382:            }
383:
384:            public native void sync();
385:
386:            public native void beep();
387:
388:            public Clipboard getSystemClipboard() {
389:                SecurityManager security = System.getSecurityManager();
390:                if (security != null) {
391:                    security.checkSystemClipboardAccess();
392:                }
393:                if (clipboard == null) {
394:                    clipboard = new PPCClipboard();
395:                }
396:                return clipboard;
397:            }
398:
399:            protected native void loadSystemColors(int[] systemColors);
400:
401:            /**
402:             * Returns a new input method adapter for native input methods.
403:             */
404:            public InputMethod getInputMethodAdapter() {
405:                return null;
406:            }
407:
408:            /**
409:             * Returns whether enableInputMethods should be set to true for peered
410:             * TextComponent instances on this platform.
411:             */
412:            public boolean enableInputMethodsForTextComponent() {
413:                return true;
414:            }
415:
416:            /*
417:             * Get the java.awt.Component object which corresponds to the native
418:             * window handle argument.  If no Component is found, null is returned.
419:             * 
420:             * This method is used by the accessibility software on Win32.
421:             */
422:            public native Component getComponentFromNativeWindowHandle(int hwnd);
423:
424:            /*
425:             * Get the native window handle which corresponds to the given peer.
426:             */
427:            private native int getNativeWindowHandleFromPeer(
428:                    PPCComponentPeer peer);
429:
430:            /*
431:             * Get the native window handle which corresponds to the
432:             * java.awt.Component object.  If the Component is lightweight,
433:             * its native container's native window handle is returned.
434:             * 
435:             * This method is used by the accessibility software on Win32.
436:             */
437:            public int getNativeWindowHandleFromComponent(Component target) {
438:                // Find the native component's PPCComponentPeer, and call it for this
439:                sun.awt.peer.ComponentPeer peer = (sun.awt.peer.ComponentPeer) targetToPeer(target);
440:                while ((peer != null) && !(peer instanceof  PPCComponentPeer)) {
441:                    target = target.getParent();
442:                    if (target == null)
443:                        return 0; // No non-lightweight parent found
444:                    peer = (sun.awt.peer.ComponentPeer) targetToPeer(target);
445:                }
446:                if (peer == null)
447:                    return 0; // No suitable peer found -- maybe not created yet
448:                return getNativeWindowHandleFromPeer((PPCComponentPeer) peer);
449:            }
450:        }
451:
452:        /** A thread which periodically flushes any drawing calls to the server. */
453:
454:        class FlushThread extends Thread {
455:            public FlushThread(Toolkit toolkit) {
456:                this .toolkit = toolkit;
457:                start();
458:            }
459:
460:            public void run() {
461:                while (!isInterrupted()) {
462:                    try {
463:                        Thread.sleep(100);
464:                    } catch (InterruptedException e) {
465:                    }
466:
467:                    toolkit.sync();
468:                }
469:            }
470:
471:            private Toolkit toolkit;
472:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.