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


001:        /*
002:         * @(#)PeerBasedToolkit.java	1.15 04/12/20
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:        /*
029:         * Warning :
030:         * Two versions of this file exist in this workspace.
031:         * One for Personal Basis, and one for Personal Profile.
032:         * Don't edit the wrong one !!!
033:         */
034:
035:        package sun.awt;
036:
037:        import java.awt.*;
038:        import java.awt.image.*;
039:        import sun.awt.peer.*;
040:        import java.util.Hashtable;
041:
042:        import java.net.URL;
043:        import sun.misc.WeakCache;
044:        import sun.awt.image.ByteArrayImageSource;
045:        import sun.awt.image.FileImageSource;
046:        import sun.awt.image.URLImageSource;
047:
048:        /** The base class for any toolkits whose implementation is peer based. Peers represent
049:         the native component for an AWT component and are created only when needed. The AWT
050:         implementation provided in the <code>java.awt</code> package assumes the toolkit to
051:         be peer based. To use a toolkit with this AWT implementation it is necessary for the
052:         toolkit class to be a subclass of this class. If this is not the case then a
053:         ClassCastException will be thrown at run time by the AWT implementation. There is no
054:         requirement, however, that AWT be implemented using peers. To provide a peerless
055:         implementation of AWT it will be necessary to write a new implementation of the
056:         <code>java.awt</code> classes.
057:
058:         @author Nicholas Allen */
059:
060:        public abstract class PeerBasedToolkit extends SunToolkit {
061:            /**
062:             * Creates this toolkit's implementation of <code>Frame</code> using
063:             * the specified peer interface.
064:             * @param     target the frame to be implemented.
065:             * @return    this toolkit's implementation of <code>Frame</code>.
066:             * @see       java.awt.Frame
067:             * @see       sun.awt.peer.FramePeer
068:             * @since     JDK1.0
069:             */
070:            public abstract FramePeer createFrame(Frame target);
071:
072:            /** Gets the peer for the supplied component. */
073:            public static native ComponentPeer getComponentPeer(Component c);
074:
075:            /** Gets the peer for the supplied menu component. */
076:            public static native MenuComponentPeer getMenuComponentPeer(
077:                    MenuComponent m);
078:
079:            /**
080:             * Creates this toolkit's implementation of <code>Canvas</code> using
081:             * the specified peer interface.
082:             * @param     target the canvas to be implemented.
083:             * @return    this toolkit's implementation of <code>Canvas</code>.
084:             * @see       java.awt.Canvas
085:             * @see       sun.awt.peer.CanvasPeer
086:             * @since     JDK1.0
087:             */
088:            public abstract CanvasPeer createCanvas(Canvas target);
089:
090:            /**
091:             * Creates this toolkit's implementation of <code>Panel</code> using
092:             * the specified peer interface.
093:             * @param     target the panel to be implemented.
094:             * @return    this toolkit's implementation of <code>Panel</code>.
095:             * @see       java.awt.Panel
096:             * @see       sun.awt.peer.PanelPeer
097:             * @since     JDK1.0
098:             */
099:            public abstract PanelPeer createPanel(Panel target);
100:
101:            /**
102:             * Creates this toolkit's implementation of <code>Window</code> using
103:             * the specified peer interface.
104:             * @param     target the window to be implemented.
105:             * @return    this toolkit's implementation of <code>Window</code>.
106:             * @see       java.awt.Window
107:             * @see       sun.awt.peer.WindowPeer
108:             * @since     JDK1.0
109:             */
110:            public abstract WindowPeer createWindow(Window target);
111:
112:            /**
113:             * Creates this toolkit's implementation of <code>Dialog</code> using
114:             * the specified peer interface.
115:             * @param     target the dialog to be implemented.
116:             * @return    this toolkit's implementation of <code>Dialog</code>.
117:             * @see       java.awt.Dialog
118:             * @see       sun.awt.peer.DialogPeer
119:             * @since     JDK1.0
120:             */
121:            public abstract DialogPeer createDialog(Dialog target);
122:
123:            /**
124:             * Creates a peer for a component or container.  This peer is windowless
125:             * and allows the Component and Container classes to be extended directly
126:             * to create windowless components that are defined entirely in java.
127:             *
128:             * @param target The Component to be created.
129:             */
130:            public sun.awt.peer.LightweightPeer createComponent(Component target) {
131:                return new sun.awt.LightweightPeer(target);
132:            }
133:
134:            /**
135:             * Give native peers the ability to query the native container
136:             * given a native component (eg the direct parent may be lightweight).
137:             */
138:            public static Container getNativeContainer(Component c) {
139:                Container p = c.getParent();
140:                while (p != null
141:                        && getComponentPeer(p) instanceof  sun.awt.peer.LightweightPeer) {
142:                    p = p.getParent();
143:                }
144:                return p;
145:            }
146:
147:            /**
148:             * Creates this toolkit's implementation of <code>MenuBar</code> using
149:             * the specified peer interface.
150:             * @param     target the menu bar to be implemented.
151:             * @return    this toolkit's implementation of <code>MenuBar</code>.
152:             * @see       java.awt.MenuBar
153:             * @see       sun.awt.peer.MenuBarPeer
154:             * @since     JDK1.0
155:             */
156:            public abstract MenuBarPeer createMenuBar(MenuBar target);
157:
158:            /**
159:             * Creates this toolkit's implementation of <code>Menu</code> using
160:             * the specified peer interface.
161:             * @param     target the menu to be implemented.
162:             * @return    this toolkit's implementation of <code>Menu</code>.
163:             * @see       java.awt.Menu
164:             * @see       sun.awt.peer.MenuPeer
165:             * @since     JDK1.0
166:             */
167:            public abstract MenuPeer createMenu(Menu target);
168:
169:            /**
170:             * Creates this toolkit's implementation of <code>PopupMenu</code> using
171:             * the specified peer interface.
172:             * @param     target the popup menu to be implemented.
173:             * @return    this toolkit's implementation of <code>PopupMenu</code>.
174:             * @see       java.awt.PopupMenu
175:             * @see       sun.awt.peer.PopupMenuPeer
176:             * @since     JDK1.1
177:             */
178:            public abstract PopupMenuPeer createPopupMenu(PopupMenu target);
179:
180:            /**
181:             * Creates this toolkit's implementation of <code>MenuItem</code> using
182:             * the specified peer interface.
183:             * @param     target the menu item to be implemented.
184:             * @return    this toolkit's implementation of <code>MenuItem</code>.
185:             * @see       java.awt.MenuItem
186:             * @see       sun.awt.peer.MenuItemPeer
187:             * @since     JDK1.0
188:             */
189:            public abstract MenuItemPeer createMenuItem(MenuItem target);
190:
191:            /**
192:             * Creates this toolkit's implementation of <code>FileDialog</code> using
193:             * the specified peer interface.
194:             * @param     target the file dialog to be implemented.
195:             * @return    this toolkit's implementation of <code>FileDialog</code>.
196:             * @see       java.awt.FileDialog
197:             * @see       sun.awt.peer.FileDialogPeer
198:             * @since     JDK1.0
199:             */
200:            public abstract FileDialogPeer createFileDialog(FileDialog target);
201:
202:            /**
203:             * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using
204:             * the specified peer interface.
205:             * @param     target the checkbox menu item to be implemented.
206:             * @return    this toolkit's implementation of <code>CheckboxMenuItem</code>.
207:             * @see       java.awt.CheckboxMenuItem
208:             * @see       sun.awt.peer.CheckboxMenuItemPeer
209:             * @since     JDK1.0
210:             */
211:            public abstract CheckboxMenuItemPeer createCheckboxMenuItem(
212:                    CheckboxMenuItem target);
213:
214:            /**
215:             * Creates this toolkit's implementation of <code>Font</code> using
216:             * the specified peer interface.
217:             * @param     target the font to be implemented.
218:             * @return    this toolkit's implementation of <code>Font</code>.
219:             * @see       java.awt.Font
220:             * @see       sun.awt.peer.FontPeer
221:             * @since     JDK1.0
222:             */
223:            public abstract FontPeer getFontPeer(Font target);
224:
225:            /**
226:             * Creates this toolkit's implementation of <code>Button</code> using
227:             * the specified peer interface.
228:             * @param     target the button to be implemented.
229:             * @return    this toolkit's implementation of <code>Button</code>.
230:             * @see       java.awt.Button
231:             * @see       sun.awt.peer.ButtonPeer
232:             * @since     JDK1.0
233:             */
234:            public abstract ButtonPeer createButton(Button target);
235:
236:            /**
237:             * Creates this toolkit's implementation of <code>TextField</code> using
238:             * the specified peer interface.
239:             * @param     target the text field to be implemented.
240:             * @return    this toolkit's implementation of <code>TextField</code>.
241:             * @see       java.awt.TextField
242:             * @see       sun.awt.peer.TextFieldPeer
243:             * @since     JDK1.0
244:             */
245:            public abstract TextFieldPeer createTextField(TextField target);
246:
247:            /**
248:             * Creates this toolkit's implementation of <code>Label</code> using
249:             * the specified peer interface.
250:             * @param     target the label to be implemented.
251:             * @return    this toolkit's implementation of <code>Label</code>.
252:             * @see       java.awt.Label
253:             * @see       sun.awt.peer.LabelPeer
254:             * @since     JDK1.0
255:             */
256:            public abstract LabelPeer createLabel(Label target);
257:
258:            /**
259:             * Creates this toolkit's implementation of <code>List</code> using
260:             * the specified peer interface.
261:             * @param     target the list to be implemented.
262:             * @return    this toolkit's implementation of <code>List</code>.
263:             * @see       java.awt.List
264:             * @see       sun.awt.peer.ListPeer
265:             * @since     JDK1.0
266:             */
267:            public abstract ListPeer createList(List target);
268:
269:            /**
270:             * Creates this toolkit's implementation of <code>Checkbox</code> using
271:             * the specified peer interface.
272:             * @param     target the check box to be implemented.
273:             * @return    this toolkit's implementation of <code>Checkbox</code>.
274:             * @see       java.awt.Checkbox
275:             * @see       sun.awt.peer.CheckboxPeer
276:             * @since     JDK1.0
277:             */
278:            public abstract CheckboxPeer createCheckbox(Checkbox target);
279:
280:            /**
281:             * Creates this toolkit's implementation of <code>Scrollbar</code> using
282:             * the specified peer interface.
283:             * @param     target the scroll bar to be implemented.
284:             * @return    this toolkit's implementation of <code>Scrollbar</code>.
285:             * @see       java.awt.Scrollbar
286:             * @see       sun.awt.peer.ScrollbarPeer
287:             * @since     JDK1.0
288:             */
289:            public abstract ScrollbarPeer createScrollbar(Scrollbar target);
290:
291:            /**
292:             * Creates this toolkit's implementation of <code>ScrollPane</code> using
293:             * the specified peer interface.
294:             * @param     target the scroll pane to be implemented.
295:             * @return    this toolkit's implementation of <code>ScrollPane</code>.
296:             * @see       java.awt.ScrollPane
297:             * @see       sun.awt.peer.ScrollPanePeer
298:             * @since     JDK1.1
299:             */
300:            public abstract ScrollPanePeer createScrollPane(ScrollPane target);
301:
302:            /**
303:             * Creates this toolkit's implementation of <code>TextArea</code> using
304:             * the specified peer interface.
305:             * @param     target the text area to be implemented.
306:             * @return    this toolkit's implementation of <code>TextArea</code>.
307:             * @see       java.awt.TextArea
308:             * @see       sun.awt.peer.TextAreaPeer
309:             * @since     JDK1.0
310:             */
311:            public abstract TextAreaPeer createTextArea(TextArea target);
312:
313:            /**
314:             * Creates this toolkit's implementation of <code>Choice</code> using
315:             * the specified peer interface.
316:             * @param     target the choice to be implemented.
317:             * @return    this toolkit's implementation of <code>Choice</code>.
318:             * @see       java.awt.Choice
319:             * @see       sun.awt.peer.ChoicePeer
320:             * @since     JDK1.0
321:             */
322:            public abstract ChoicePeer createChoice(Choice target);
323:
324:            // mapping of components to peers, Hashtable<Component,Peer>
325:            protected static final Hashtable peerMap = new Hashtable();
326:
327:            /*
328:             * Fetch the peer associated with the given target (as specified
329:             * in the peer creation method).  This can be used to determine
330:             * things like what the parent peer is.  If the target is null
331:             * or the target can't be found (either because the a peer was
332:             * never created for it or the peer was disposed), a null will
333:             * be returned.
334:             */
335:            protected static Object targetToPeer(Object target) {
336:                if (target != null) {
337:                    return peerMap.get(target);
338:                }
339:                return null;
340:            }
341:
342:            protected static void targetDisposedPeer(Object target, Object peer) {
343:                if (target != null && peer != null) {
344:                    synchronized (peerMap) {
345:                        if (peerMap.get(target) == peer) {
346:                            peerMap.remove(target);
347:                        }
348:                    }
349:                }
350:            }
351:
352:            // Begin of: PBP/PP [6262553]
353:            // Take security fixes from J2SE SunToolkit.java into PBP/PP's SunToolkit.java.
354:
355:            //    /* These createImage/getImage impls are brought over from SunToolkit */
356:            //    public java.awt.Image createImage(String filename) {
357:            //        return createImage(new FileImageSource(filename));
358:            //    }
359:            //                                                                             
360:            //    /* These createImage/getImage impls are brought over from SunToolkit */
361:            //    public java.awt.Image createImage(URL url) {
362:            //        return createImage(new URLImageSource(url));
363:            //    }
364:            //                                                                             
365:            //    /* These createImage/getImage impls are brought over from SunToolkit */
366:            //    public java.awt.Image createImage(byte[] data, int offset, int length) {
367:            //        return createImage(new ByteArrayImageSource(data, offset, length));
368:            //    }
369:            //
370:            //    /* These createImage/getImage impls are brought over from SunToolkit */
371:            //    public java.awt.Image getImage(String filename) {
372:            //        return getImageFromCache(filename);
373:            //    }
374:            //
375:            //    /* These createImage/getImage impls are brought over from SunToolkit */
376:            //    public java.awt.Image getImage(URL url) {
377:            //        return getImageFromCache(url);
378:            //    }
379:            //
380:            //    private Hashtable imageMap = new WeakCache();
381:            //    private synchronized java.awt.Image getImageFromCache(Object key) {
382:            //        java.awt.Image img = (java.awt.Image) imageMap.get(key);
383:            //        if (img == null) {
384:            //            /* make sure we can create the image */
385:            //            img = (key instanceof URL)
386:            //                    ? createImage((URL) key)
387:            //                    : createImage((String) key);
388:            //            if (img != null) {
389:            //                imageMap.put(key, img);
390:            //            }
391:            //        }
392:            //        return img;
393:            //    }
394:
395:            // End of: PBP/PP [6262553]
396:
397:            /**
398:             * Returns the names of the available fonts in this toolkit.<p>
399:             * For 1.1, the following font names are deprecated (the replacement
400:             * name follows):
401:             * <ul>
402:             * <li>TimesRoman (use Serif)
403:             * <li>Helvetica (use SansSerif)
404:             * <li>Courier (use Monospaced)
405:             * </ul><p>
406:             * The ZapfDingbats font is also deprecated in 1.1, but only as a
407:             * separate fontname.  Unicode defines the ZapfDingbat characters
408:             * starting at \u2700, and as of 1.1 Java supports those characters.
409:             * @return    the names of the available fonts in this toolkit.
410:             * @since     JDK1.0
411:             */
412:            public String[] getFontList() {
413:                String[] hardwiredFontList = { "Dialog", "SansSerif", "Serif",
414:                        "Monospaced", "DialogInput"
415:
416:                // -- Obsolete font names from 1.0.2.  It was decided that
417:                // -- getFontList should not return these old names:
418:                // , "Helvetica", "TimesRoman", "Courier", "ZapfDingbats"
419:                };
420:                return hardwiredFontList;
421:            }
422:
423:        }
424:
425:        /**
426:         * Implements the LightweightPeer interface for use in lightweight components
427:         * that have no native window associated with them.  This gets created by
428:         * default in Component so that Component and Container can be directly
429:         * extended to create useful components written entirely in java.  These
430:         * components must be hosted somewhere higher up in the component tree by a
431:         * native container (such as a Frame).
432:         *
433:         * This implementation provides no useful semantics and serves only as a
434:         * marker.  One could provide alternative implementations in java that do
435:         * something useful for some of the other peer interfaces to minimize the
436:         * native code.
437:         *
438:         * @author Timothy Prinzing
439:         */
440:        class LightweightPeer implements  sun.awt.peer.LightweightPeer {
441:            public LightweightPeer(Component target) {
442:            }
443:
444:            public boolean isFocusTraversable() {
445:                return false;
446:            }
447:
448:            public boolean isDoubleBuffered() {
449:                return false;
450:            }
451:
452:            public void setVisible(boolean b) {
453:            }
454:
455:            public void show() {
456:            }
457:
458:            public void hide() {
459:            }
460:
461:            public void setEnabled(boolean b) {
462:            }
463:
464:            public void enable() {
465:            }
466:
467:            public void disable() {
468:            }
469:
470:            public void paint(Graphics g) {
471:            }
472:
473:            public void repaint(long tm, int x, int y, int width, int height) {
474:            }
475:
476:            public void print(Graphics g) {
477:            }
478:
479:            public void setBounds(int x, int y, int width, int height) {
480:            }
481:
482:            public void reshape(int x, int y, int width, int height) {
483:            }
484:
485:            public void handleEvent(java.awt.AWTEvent arg0) {
486:            }
487:
488:            public Dimension getPreferredSize() {
489:                return new Dimension(1, 1);
490:            }
491:
492:            public Dimension getMinimumSize() {
493:                return new Dimension(1, 1);
494:            }
495:
496:            public java.awt.Toolkit getToolkit() {
497:                return null;
498:            }
499:
500:            public ColorModel getColorModel() {
501:                return null;
502:            }
503:
504:            public Graphics getGraphics() {
505:                return null;
506:            }
507:
508:            public FontMetrics getFontMetrics(Font font) {
509:                return null;
510:            }
511:
512:            public void dispose() {// no native code
513:            }
514:
515:            public void setForeground(Color c) {
516:            }
517:
518:            public void setBackground(Color c) {
519:            }
520:
521:            public void setFont(Font f) {
522:            }
523:
524:            public void setCursor(Cursor cursor) {
525:            }
526:
527:            public boolean requestFocus(Component child, Window parent,
528:                    boolean temporary, boolean focusedWindowChangeAllowed,
529:                    long time) {
530:                return false;
531:            }
532:
533:            public Image createImage(ImageProducer producer) {
534:                return null;
535:            }
536:
537:            public Image createImage(int width, int height) {
538:                return null;
539:            }
540:
541:            public VolatileImage createVolatileImage(int width, int height) {
542:                return null;
543:            }
544:
545:            public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
546:                return false;
547:            }
548:
549:            public int checkImage(Image img, int w, int h, ImageObserver o) {
550:                return 0;
551:            }
552:
553:            public Dimension preferredSize() {
554:                return getPreferredSize();
555:            }
556:
557:            public Dimension minimumSize() {
558:                return getMinimumSize();
559:            }
560:
561:            public Point getLocationOnScreen() {
562:                return null;
563:            }
564:
565:            public void setFocusable(boolean focusable) {
566:            }
567:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.