Source Code Cross Referenced for Toolkit.java in  » Apache-Harmony-Java-SE » java-package » java » 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 » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        package java.awt;
0019:
0020:        import java.awt.datatransfer.Clipboard;
0021:        import java.awt.dnd.DragGestureEvent;
0022:        import java.awt.dnd.DragGestureListener;
0023:        import java.awt.dnd.DragGestureRecognizer;
0024:        import java.awt.dnd.DragSource;
0025:        import java.awt.dnd.InvalidDnDOperationException;
0026:        import java.awt.dnd.MouseDragGestureRecognizer;
0027:        import java.awt.dnd.peer.DragSourceContextPeer;
0028:        import java.awt.event.AWTEventListener;
0029:        import java.awt.event.AWTEventListenerProxy;
0030:        import java.awt.event.InputEvent;
0031:        import java.awt.event.KeyEvent;
0032:        import java.awt.im.InputMethodHighlight;
0033:        import java.awt.image.ColorModel;
0034:        import java.awt.image.ImageObserver;
0035:        import java.awt.image.ImageProducer;
0036:        import java.awt.peer.ButtonPeer;
0037:        import java.awt.peer.CanvasPeer;
0038:        import java.awt.peer.CheckboxMenuItemPeer;
0039:        import java.awt.peer.CheckboxPeer;
0040:        import java.awt.peer.ChoicePeer;
0041:        import java.awt.peer.DialogPeer;
0042:        import java.awt.peer.FileDialogPeer;
0043:        import java.awt.peer.FontPeer;
0044:        import java.awt.peer.FramePeer;
0045:        import java.awt.peer.LabelPeer;
0046:        import java.awt.peer.LightweightPeer;
0047:        import java.awt.peer.ListPeer;
0048:        import java.awt.peer.MenuBarPeer;
0049:        import java.awt.peer.MenuItemPeer;
0050:        import java.awt.peer.MenuPeer;
0051:        import java.awt.peer.MouseInfoPeer;
0052:        import java.awt.peer.PanelPeer;
0053:        import java.awt.peer.PopupMenuPeer;
0054:        import java.awt.peer.ScrollPanePeer;
0055:        import java.awt.peer.ScrollbarPeer;
0056:        import java.awt.peer.TextAreaPeer;
0057:        import java.awt.peer.TextFieldPeer;
0058:        import java.awt.peer.WindowPeer;
0059:        import java.beans.PropertyChangeListener;
0060:        import java.beans.PropertyChangeSupport;
0061:        import java.lang.reflect.InvocationTargetException;
0062:        import java.net.URL;
0063:        import java.security.AccessController;
0064:        import java.security.PrivilegedAction;
0065:        import java.util.Collections;
0066:        import java.util.EventListener;
0067:        import java.util.HashMap;
0068:        import java.util.HashSet;
0069:        import java.util.Iterator;
0070:        import java.util.LinkedHashSet;
0071:        import java.util.Map;
0072:        import java.util.MissingResourceException;
0073:        import java.util.Properties;
0074:        import java.util.ResourceBundle;
0075:
0076:        import org.apache.harmony.awt.ChoiceStyle;
0077:        import org.apache.harmony.awt.ComponentInternals;
0078:        import org.apache.harmony.awt.ContextStorage;
0079:        import org.apache.harmony.awt.MouseEventPreprocessor;
0080:        import org.apache.harmony.awt.ReadOnlyIterator;
0081:        import org.apache.harmony.awt.Theme;
0082:        import org.apache.harmony.awt.datatransfer.DTK;
0083:        import org.apache.harmony.awt.datatransfer.NativeClipboard;
0084:        import org.apache.harmony.awt.gl.MultiRectArea;
0085:        import org.apache.harmony.awt.internal.nls.Messages;
0086:        import org.apache.harmony.awt.text.TextFieldKit;
0087:        import org.apache.harmony.awt.text.TextKit;
0088:        import org.apache.harmony.awt.wtk.CreationParams;
0089:        import org.apache.harmony.awt.wtk.GraphicsFactory;
0090:        import org.apache.harmony.awt.wtk.NativeCursor;
0091:        import org.apache.harmony.awt.wtk.NativeEventQueue;
0092:        import org.apache.harmony.awt.wtk.NativeEventThread;
0093:        import org.apache.harmony.awt.wtk.NativeMouseInfo;
0094:        import org.apache.harmony.awt.wtk.NativeWindow;
0095:        import org.apache.harmony.awt.wtk.ShutdownWatchdog;
0096:        import org.apache.harmony.awt.wtk.Synchronizer;
0097:        import org.apache.harmony.awt.wtk.WTK;
0098:        import org.apache.harmony.awt.wtk.WindowFactory;
0099:
0100:        public abstract class Toolkit {
0101:            private static final String RECOURCE_PATH = "org.apache.harmony.awt.resources.AWTProperties"; //$NON-NLS-1$
0102:
0103:            private static final ResourceBundle properties = loadResources(RECOURCE_PATH);
0104:
0105:            Dispatcher dispatcher;
0106:
0107:            private EventQueueCore systemEventQueueCore;
0108:
0109:            EventDispatchThread dispatchThread;
0110:
0111:            NativeEventThread nativeThread;
0112:
0113:            protected AWTEventsManager awtEventsManager;
0114:
0115:            /* key = nativeWindow, value = Component, should be Map<NativeWindow, Component> */
0116:            private final Map<NativeWindow, Object> windowComponentMap = new HashMap<NativeWindow, Object>();
0117:
0118:            /* key = nativeWindow, value = MenuComponent */
0119:            private final Map<NativeWindow, Object> windowPopupMap = new HashMap<NativeWindow, Object>();
0120:
0121:            private final Map<NativeWindow, Window> windowFocusProxyMap = new HashMap<NativeWindow, Window>();
0122:
0123:            private class AWTTreeLock {
0124:            }
0125:
0126:            final Object awtTreeLock = new AWTTreeLock();
0127:
0128:            private final Synchronizer synchronizer = ContextStorage
0129:                    .getSynchronizer();
0130:
0131:            final ShutdownWatchdog shutdownWatchdog = new ShutdownWatchdog();
0132:
0133:            final Theme theme = createTheme();
0134:
0135:            final AutoNumber autoNumber = new AutoNumber();
0136:
0137:            final AWTEvent.EventTypeLookup eventTypeLookup = new AWTEvent.EventTypeLookup();
0138:
0139:            final Frame.AllFrames allFrames = new Frame.AllFrames();
0140:
0141:            KeyboardFocusManager currentKeyboardFocusManager;
0142:
0143:            MouseEventPreprocessor mouseEventPreprocessor;
0144:
0145:            NativeClipboard systemClipboard = null;
0146:
0147:            private NativeClipboard systemSelection = null;
0148:
0149:            private boolean bDynamicLayoutSet = true;
0150:
0151:            /**
0152:             * The set of desktop properties that user set directly.
0153:             */
0154:            private final HashSet<String> userPropSet = new HashSet<String>();
0155:
0156:            protected final Map<String, Object> desktopProperties;
0157:
0158:            protected final PropertyChangeSupport desktopPropsSupport;
0159:
0160:            /**
0161:             * For this component the native window is being created
0162:             * It is used in the callback-driven window creation
0163:             * (e.g. on Windows in the handler of WM_CREATE event)
0164:             * to establish the connection between this component
0165:             * and its native window
0166:             */
0167:            private Object recentNativeWindowComponent;
0168:
0169:            final WindowList windows = new WindowList();
0170:
0171:            private WTK wtk;
0172:
0173:            DTK dtk;
0174:
0175:            final class ComponentInternalsImpl extends ComponentInternals {
0176:                @Override
0177:                public NativeWindow getNativeWindow(Component component) {
0178:                    lockAWT();
0179:                    try {
0180:                        return component != null ? component.getNativeWindow()
0181:                                : null;
0182:                    } finally {
0183:                        unlockAWT();
0184:                    }
0185:                }
0186:
0187:                @Override
0188:                public void startMouseGrab(Window grabWindow,
0189:                        Runnable whenCanceled) {
0190:                    lockAWT();
0191:                    try {
0192:                        dispatcher.mouseGrabManager.startGrab(grabWindow,
0193:                                whenCanceled);
0194:                    } finally {
0195:                        unlockAWT();
0196:                    }
0197:                }
0198:
0199:                @Override
0200:                public void endMouseGrab() {
0201:                    lockAWT();
0202:                    try {
0203:                        dispatcher.mouseGrabManager.endGrab();
0204:                    } finally {
0205:                        unlockAWT();
0206:                    }
0207:                }
0208:
0209:                @Override
0210:                public Window attachNativeWindow(long nativeWindowId) {
0211:                    lockAWT();
0212:                    try {
0213:                        Window window = new EmbeddedWindow(nativeWindowId);
0214:                        windowComponentMap
0215:                                .put(window.getNativeWindow(), window);
0216:                        windows.add(window);
0217:                        return window;
0218:                    } finally {
0219:                        unlockAWT();
0220:                    }
0221:                }
0222:
0223:                @Override
0224:                public void makePopup(Window window) {
0225:                    lockAWT();
0226:                    try {
0227:                        window.setPopup(true);
0228:                    } finally {
0229:                        unlockAWT();
0230:                    }
0231:                }
0232:
0233:                @Override
0234:                public void onDrawImage(Component comp, Image image,
0235:                        Point destLocation, Dimension destSize, Rectangle source) {
0236:                    lockAWT();
0237:                    try {
0238:                        comp.onDrawImage(image, destLocation, destSize, source);
0239:                    } finally {
0240:                        unlockAWT();
0241:                    }
0242:                }
0243:
0244:                @Override
0245:                public void setCaretPos(Component c, int x, int y) {
0246:                    c.setCaretPos(x, y);
0247:                }
0248:
0249:                @Override
0250:                public void unsafeInvokeAndWait(Runnable runnable)
0251:                        throws InterruptedException, InvocationTargetException {
0252:                    Toolkit.this .unsafeInvokeAndWait(runnable);
0253:                }
0254:
0255:                @Override
0256:                public TextKit getTextKit(Component comp) {
0257:                    lockAWT();
0258:                    try {
0259:                        return comp.getTextKit();
0260:                    } finally {
0261:                        unlockAWT();
0262:                    }
0263:                }
0264:
0265:                @Override
0266:                public void setTextKit(Component comp, TextKit kit) {
0267:                    lockAWT();
0268:                    try {
0269:                        comp.setTextKit(kit);
0270:                    } finally {
0271:                        unlockAWT();
0272:                    }
0273:                }
0274:
0275:                @Override
0276:                public TextFieldKit getTextFieldKit(Component comp) {
0277:                    lockAWT();
0278:                    try {
0279:                        return comp.getTextFieldKit();
0280:                    } finally {
0281:                        unlockAWT();
0282:                    }
0283:                }
0284:
0285:                @Override
0286:                public void setTextFieldKit(Component comp, TextFieldKit kit) {
0287:                    lockAWT();
0288:                    try {
0289:                        comp.setTextFieldKit(kit);
0290:                    } finally {
0291:                        unlockAWT();
0292:                    }
0293:                }
0294:
0295:                @Override
0296:                public void shutdown() {
0297:                    dispatchThread.shutdown();
0298:                }
0299:
0300:                @Override
0301:                public void setMouseEventPreprocessor(
0302:                        MouseEventPreprocessor preprocessor) {
0303:                    lockAWT();
0304:                    try {
0305:                        mouseEventPreprocessor = preprocessor;
0306:                    } finally {
0307:                        unlockAWT();
0308:                    }
0309:                }
0310:
0311:                @Override
0312:                public Choice createCustomChoice(ChoiceStyle style) {
0313:                    return new Choice(style);
0314:                }
0315:
0316:                @Override
0317:                public Insets getNativeInsets(Window w) {
0318:                    lockAWT();
0319:                    try {
0320:                        return (w != null) ? w.getNativeInsets() : new Insets(
0321:                                0, 0, 0, 0);
0322:                    } finally {
0323:                        unlockAWT();
0324:                    }
0325:                }
0326:
0327:                @Override
0328:                public MultiRectArea getRepaintRegion(Component c) {
0329:                    return c.repaintRegion;
0330:                }
0331:
0332:                @Override
0333:                public MultiRectArea subtractPendingRepaintRegion(Component c,
0334:                        MultiRectArea mra) {
0335:                    lockAWT();
0336:                    try {
0337:                        RedrawManager rm = c.getRedrawManager();
0338:                        if (rm == null) {
0339:                            return null;
0340:                        }
0341:                        return rm.subtractPendingRepaintRegion(c, mra);
0342:                    } finally {
0343:                        unlockAWT();
0344:                    }
0345:                }
0346:
0347:                @Override
0348:                public boolean wasPainted(Window w) {
0349:                    lockAWT();
0350:                    try {
0351:                        return w.painted;
0352:                    } finally {
0353:                        unlockAWT();
0354:                    }
0355:                }
0356:
0357:                @Override
0358:                public MultiRectArea getObscuredRegion(Component c) {
0359:                    return c.getObscuredRegion(null);
0360:                }
0361:
0362:                @Override
0363:                public void setDesktopProperty(String name, Object value) {
0364:                    Toolkit.this .setDesktopProperty(name, value);
0365:                }
0366:
0367:                @Override
0368:                public void runModalLoop(Dialog dlg) {
0369:                    dlg.runModalLoop();
0370:                }
0371:
0372:                @Override
0373:                public void endModalLoop(Dialog dlg) {
0374:                    dlg.endModalLoop();
0375:                }
0376:
0377:                @Override
0378:                public void setVisibleFlag(Component comp, boolean visible) {
0379:                    comp.visible = visible;
0380:                }
0381:
0382:                @Override
0383:                public void addObscuredRegions(MultiRectArea mra, Component c,
0384:                        Container container) {
0385:                    if (container != null) {
0386:                        container.addObscuredRegions(mra, c);
0387:                    }
0388:                }
0389:            }
0390:
0391:            /*
0392:             * A lot of methods must throw HeadlessException
0393:             * if <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>.
0394:             */
0395:            static void checkHeadless() throws HeadlessException {
0396:                if (GraphicsEnvironment.getLocalGraphicsEnvironment()
0397:                        .isHeadlessInstance())
0398:                    throw new HeadlessException();
0399:            }
0400:
0401:            final void lockAWT() {
0402:                synchronizer.lock();
0403:            }
0404:
0405:            static final void staticLockAWT() {
0406:                ContextStorage.getSynchronizer().lock();
0407:            }
0408:
0409:            final void unlockAWT() {
0410:                synchronizer.unlock();
0411:            }
0412:
0413:            static final void staticUnlockAWT() {
0414:                ContextStorage.getSynchronizer().unlock();
0415:            }
0416:
0417:            /**
0418:             * InvokeAndWait under AWT lock. W/o this method system can hang up.
0419:             * Added to support modality (Dialog.show() & PopupMenu.show()) from
0420:             * not event dispatch thread. Use in other cases is not recommended.
0421:             *
0422:             * Still can be called only for whole API methods that
0423:             * cannot be called from other classes API methods.
0424:             * Examples:
0425:             *      show() for modal dialogs    - correct, only user can call it,
0426:             *                                      directly or through setVisible(true)
0427:             *      setBounds() for components  - incorrect, setBounds()
0428:             *                                      can be called from layoutContainer()
0429:             *                                      for layout managers
0430:             */
0431:            final void unsafeInvokeAndWait(Runnable runnable)
0432:                    throws InterruptedException, InvocationTargetException {
0433:                synchronizer.storeStateAndFree();
0434:                try {
0435:                    EventQueue.invokeAndWait(runnable);
0436:                } finally {
0437:                    synchronizer.lockAndRestoreState();
0438:                }
0439:            }
0440:
0441:            final Synchronizer getSynchronizer() {
0442:                return synchronizer;
0443:            }
0444:
0445:            final WTK getWTK() {
0446:                return wtk;
0447:            }
0448:
0449:            public static String getProperty(String propName, String defVal) {
0450:                if (propName == null) {
0451:                    // awt.7D=Property name is null
0452:                    throw new NullPointerException(Messages.getString("awt.7D")); //$NON-NLS-1$
0453:                }
0454:                staticLockAWT();
0455:                try {
0456:                    String retVal = null;
0457:                    if (properties != null) {
0458:                        try {
0459:                            retVal = properties.getString(propName);
0460:                        } catch (MissingResourceException e) {
0461:                        } catch (ClassCastException e) {
0462:                        }
0463:                    }
0464:                    return (retVal == null) ? defVal : retVal;
0465:                } finally {
0466:                    staticUnlockAWT();
0467:                }
0468:            }
0469:
0470:            public static Toolkit getDefaultToolkit() {
0471:                synchronized (ContextStorage.getContextLock()) {
0472:                    if (ContextStorage.shutdownPending()) {
0473:                        return null;
0474:                    }
0475:                    Toolkit defToolkit = ContextStorage.getDefaultToolkit();
0476:                    if (defToolkit != null) {
0477:                        return defToolkit;
0478:                    }
0479:                    staticLockAWT();
0480:                    try {
0481:                        defToolkit = GraphicsEnvironment.isHeadless() ? new HeadlessToolkit()
0482:                                : new ToolkitImpl();
0483:                        ContextStorage.setDefaultToolkit(defToolkit);
0484:                        return defToolkit;
0485:                    } finally {
0486:                        staticUnlockAWT();
0487:                    }
0488:                    //TODO: read system property named awt.toolkit
0489:                    //and create an instance of the specified class,
0490:                    //by default use ToolkitImpl
0491:                }
0492:            }
0493:
0494:            Font getDefaultFont() {
0495:                return wtk.getSystemProperties().getDefaultFont();
0496:            }
0497:
0498:            private static ResourceBundle loadResources(String path) {
0499:                try {
0500:                    return ResourceBundle.getBundle(path);
0501:                } catch (MissingResourceException e) {
0502:                    return null;
0503:                }
0504:            }
0505:
0506:            private static String getWTKClassName() {
0507:                String osName = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
0508:                String packageBase = "org.apache.harmony.awt.wtk", win = "windows", lin = "linux"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
0509:                if (osName.startsWith(lin)) {
0510:                    return packageBase + "." + lin + ".LinuxWTK"; //$NON-NLS-1$ //$NON-NLS-2$
0511:                }
0512:                if (osName.startsWith(win)) {
0513:                    return packageBase + "." + win + ".WinWTK"; //$NON-NLS-1$ //$NON-NLS-2$
0514:                }
0515:                return null;
0516:            }
0517:
0518:            Component getComponentById(long id) {
0519:                if (id == 0) {
0520:                    return null;
0521:                }
0522:                return (Component) windowComponentMap.get(getWindowFactory()
0523:                        .getWindowById(id));
0524:            }
0525:
0526:            PopupBox getPopupBoxById(long id) {
0527:                if (id == 0) {
0528:                    return null;
0529:                }
0530:                return (PopupBox) windowPopupMap.get(getWindowFactory()
0531:                        .getWindowById(id));
0532:            }
0533:
0534:            Window getFocusProxyOwnerById(long id) {
0535:                if (id == 0) {
0536:                    return null;
0537:                }
0538:                return windowFocusProxyMap.get(getWindowFactory()
0539:                        .getWindowById(id));
0540:            }
0541:
0542:            WindowFactory getWindowFactory() {
0543:                return wtk.getWindowFactory();
0544:            }
0545:
0546:            GraphicsFactory getGraphicsFactory() {
0547:                return wtk.getGraphicsFactory();
0548:            }
0549:
0550:            public Toolkit() {
0551:                desktopProperties = new HashMap<String, Object>();
0552:                desktopPropsSupport = new PropertyChangeSupport(this );
0553:                init();
0554:            }
0555:
0556:            void init() {
0557:                lockAWT();
0558:                try {
0559:                    ComponentInternals
0560:                            .setComponentInternals(new ComponentInternalsImpl());
0561:                    new EventQueue(this ); // create the system EventQueue
0562:                    dispatcher = new Dispatcher(this );
0563:                    final String className = getWTKClassName();
0564:                    awtEventsManager = new AWTEventsManager();
0565:                    dispatchThread = new EventDispatchThread(this , dispatcher);
0566:                    nativeThread = new NativeEventThread();
0567:                    dtk = DTK.getDTK();
0568:                    NativeEventThread.Init init = new NativeEventThread.Init() {
0569:                        public WTK init() {
0570:                            wtk = createWTK(className);
0571:                            wtk.getNativeEventQueue().setShutdownWatchdog(
0572:                                    shutdownWatchdog);
0573:                            synchronizer.setEnvironment(wtk, dispatchThread);
0574:                            ContextStorage.setWTK(wtk);
0575:                            dtk.initDragAndDrop();
0576:                            return wtk;
0577:                        }
0578:                    };
0579:                    nativeThread.start(init);
0580:                    dispatchThread.start();
0581:                    wtk.getNativeEventQueue().awake();
0582:                } finally {
0583:                    unlockAWT();
0584:                }
0585:            }
0586:
0587:            public abstract void sync();
0588:
0589:            protected abstract TextAreaPeer createTextArea(TextArea a0)
0590:                    throws HeadlessException;
0591:
0592:            public abstract int checkImage(Image a0, int a1, int a2,
0593:                    ImageObserver a3);
0594:
0595:            public abstract Image createImage(ImageProducer a0);
0596:
0597:            public abstract Image createImage(byte[] a0, int a1, int a2);
0598:
0599:            public abstract Image createImage(URL a0);
0600:
0601:            public abstract Image createImage(String a0);
0602:
0603:            public abstract ColorModel getColorModel() throws HeadlessException;
0604:
0605:            /**
0606:             * @deprecated
0607:             */
0608:            @Deprecated
0609:            public abstract FontMetrics getFontMetrics(Font font);
0610:
0611:            public abstract boolean prepareImage(Image a0, int a1, int a2,
0612:                    ImageObserver a3);
0613:
0614:            public abstract void beep();
0615:
0616:            protected abstract ButtonPeer createButton(Button a0)
0617:                    throws HeadlessException;
0618:
0619:            protected abstract CanvasPeer createCanvas(Canvas a0);
0620:
0621:            protected abstract CheckboxPeer createCheckbox(Checkbox a0)
0622:                    throws HeadlessException;
0623:
0624:            protected abstract CheckboxMenuItemPeer createCheckboxMenuItem(
0625:                    CheckboxMenuItem a0) throws HeadlessException;
0626:
0627:            protected abstract ChoicePeer createChoice(Choice a0)
0628:                    throws HeadlessException;
0629:
0630:            protected abstract DialogPeer createDialog(Dialog a0)
0631:                    throws HeadlessException;
0632:
0633:            public abstract DragSourceContextPeer createDragSourceContextPeer(
0634:                    DragGestureEvent a0) throws InvalidDnDOperationException;
0635:
0636:            protected abstract FileDialogPeer createFileDialog(FileDialog a0)
0637:                    throws HeadlessException;
0638:
0639:            protected abstract FramePeer createFrame(Frame a0)
0640:                    throws HeadlessException;
0641:
0642:            protected abstract LabelPeer createLabel(Label a0)
0643:                    throws HeadlessException;
0644:
0645:            protected abstract ListPeer createList(List a0)
0646:                    throws HeadlessException;
0647:
0648:            protected abstract MenuPeer createMenu(Menu a0)
0649:                    throws HeadlessException;
0650:
0651:            protected abstract MenuBarPeer createMenuBar(MenuBar a0)
0652:                    throws HeadlessException;
0653:
0654:            protected abstract MenuItemPeer createMenuItem(MenuItem a0)
0655:                    throws HeadlessException;
0656:
0657:            protected abstract PanelPeer createPanel(Panel a0);
0658:
0659:            protected abstract PopupMenuPeer createPopupMenu(PopupMenu a0)
0660:                    throws HeadlessException;
0661:
0662:            protected abstract ScrollPanePeer createScrollPane(ScrollPane a0)
0663:                    throws HeadlessException;
0664:
0665:            protected abstract ScrollbarPeer createScrollbar(Scrollbar a0)
0666:                    throws HeadlessException;
0667:
0668:            protected abstract TextFieldPeer createTextField(TextField a0)
0669:                    throws HeadlessException;
0670:
0671:            protected abstract WindowPeer createWindow(Window a0)
0672:                    throws HeadlessException;
0673:
0674:            /**
0675:             * @deprecated
0676:             */
0677:            @Deprecated
0678:            public abstract String[] getFontList();
0679:
0680:            /**
0681:             * @deprecated
0682:             */
0683:            @Deprecated
0684:            protected abstract FontPeer getFontPeer(String a0, int a1);
0685:
0686:            public abstract Image getImage(String a0);
0687:
0688:            public abstract Image getImage(URL a0);
0689:
0690:            public abstract PrintJob getPrintJob(Frame a0, String a1,
0691:                    Properties a2);
0692:
0693:            public abstract int getScreenResolution() throws HeadlessException;
0694:
0695:            public abstract Dimension getScreenSize() throws HeadlessException;
0696:
0697:            public abstract Clipboard getSystemClipboard()
0698:                    throws HeadlessException;
0699:
0700:            protected abstract EventQueue getSystemEventQueueImpl();
0701:
0702:            public abstract Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
0703:                    InputMethodHighlight highlight) throws HeadlessException;
0704:
0705:            Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlightImpl(
0706:                    InputMethodHighlight highlight) throws HeadlessException {
0707:                HashMap<java.awt.font.TextAttribute, ?> map = new HashMap<java.awt.font.TextAttribute, Object>();
0708:                wtk.getSystemProperties().mapInputMethodHighlight(highlight,
0709:                        map);
0710:                return Collections
0711:                        .<java.awt.font.TextAttribute, Object> unmodifiableMap(map);
0712:            }
0713:
0714:            public void addPropertyChangeListener(String propName,
0715:                    PropertyChangeListener l) {
0716:                lockAWT();
0717:                try {
0718:                    if (desktopProperties.isEmpty()) {
0719:                        initializeDesktopProperties();
0720:                    }
0721:                } finally {
0722:                    unlockAWT();
0723:                }
0724:                if (l != null) { // there is no guarantee that null listener will not be added
0725:                    desktopPropsSupport.addPropertyChangeListener(propName, l);
0726:                }
0727:            }
0728:
0729:            protected java.awt.peer.MouseInfoPeer getMouseInfoPeer() {
0730:                return new MouseInfoPeer() {
0731:                };
0732:            }
0733:
0734:            protected LightweightPeer createComponent(Component a0)
0735:                    throws org.apache.harmony.luni.util.NotImplementedException {
0736:                lockAWT();
0737:                try {
0738:                } finally {
0739:                    unlockAWT();
0740:                }
0741:                if (true) {
0742:                    throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$
0743:                }
0744:                return null;
0745:            }
0746:
0747:            public Image createImage(byte[] imagedata) {
0748:                return createImage(imagedata, 0, imagedata.length);
0749:            }
0750:
0751:            protected static Container getNativeContainer(Component c) {
0752:                staticLockAWT();
0753:                try {
0754:                    //TODO: implement
0755:                    return c.getWindowAncestor();
0756:                } finally {
0757:                    staticUnlockAWT();
0758:                }
0759:            }
0760:
0761:            public PropertyChangeListener[] getPropertyChangeListeners() {
0762:                return desktopPropsSupport.getPropertyChangeListeners();
0763:            }
0764:
0765:            public PropertyChangeListener[] getPropertyChangeListeners(
0766:                    String propName) {
0767:                return desktopPropsSupport.getPropertyChangeListeners(propName);
0768:            }
0769:
0770:            public void removePropertyChangeListener(String propName,
0771:                    PropertyChangeListener l) {
0772:                desktopPropsSupport.removePropertyChangeListener(propName, l);
0773:            }
0774:
0775:            public Cursor createCustomCursor(Image img, Point hotSpot,
0776:                    String name) throws IndexOutOfBoundsException,
0777:                    HeadlessException {
0778:                lockAWT();
0779:                try {
0780:                    int w = img.getWidth(null);
0781:                    int h = img.getHeight(null);
0782:
0783:                    if (w < 0 || h < 0) {
0784:                        // Fix for HARMONY-4491
0785:                        hotSpot.x = 0;
0786:                        hotSpot.y = 0;
0787:                    } else if (hotSpot.x < 0 || hotSpot.x >= w || hotSpot.y < 0
0788:                            || hotSpot.y >= h) {
0789:                        // awt.7E=invalid hotSpot
0790:                        throw new IndexOutOfBoundsException(Messages
0791:                                .getString("awt.7E")); //$NON-NLS-1$
0792:                    }
0793:                    return new Cursor(name, img, hotSpot);
0794:                } finally {
0795:                    unlockAWT();
0796:                }
0797:            }
0798:
0799:            @SuppressWarnings("unchecked")
0800:            public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
0801:                    Class<T> recognizerAbstractClass, DragSource ds,
0802:                    Component c, int srcActions, DragGestureListener dgl) {
0803:                if (recognizerAbstractClass == null) {
0804:                    return null;
0805:                }
0806:                if (recognizerAbstractClass
0807:                        .isAssignableFrom(MouseDragGestureRecognizer.class)) {
0808:                    return (T) new DefaultMouseDragGestureRecognizer(ds, c,
0809:                            srcActions, dgl);
0810:                }
0811:                return null;
0812:            }
0813:
0814:            public Dimension getBestCursorSize(int prefWidth, int prefHeight)
0815:                    throws HeadlessException {
0816:                lockAWT();
0817:                try {
0818:                    return wtk.getCursorFactory().getBestCursorSize(prefWidth,
0819:                            prefHeight);
0820:                } finally {
0821:                    unlockAWT();
0822:                }
0823:            }
0824:
0825:            public final Object getDesktopProperty(String propName) {
0826:                lockAWT();
0827:                try {
0828:                    if (desktopProperties.isEmpty()) {
0829:                        initializeDesktopProperties();
0830:                    }
0831:                    if (propName.equals("awt.dynamicLayoutSupported")) { //$NON-NLS-1$
0832:                        // dynamicLayoutSupported is special case
0833:                        return Boolean.valueOf(isDynamicLayoutActive());
0834:                    }
0835:                    Object val = desktopProperties.get(propName);
0836:                    if (val == null) {
0837:                        // try to lazily load prop value
0838:                        // just for compatibility, our lazilyLoad is empty
0839:                        val = lazilyLoadDesktopProperty(propName);
0840:                    }
0841:                    return val;
0842:                } finally {
0843:                    unlockAWT();
0844:                }
0845:            }
0846:
0847:            public boolean getLockingKeyState(int keyCode)
0848:                    throws UnsupportedOperationException {
0849:
0850:                if (keyCode != KeyEvent.VK_CAPS_LOCK
0851:                        && keyCode != KeyEvent.VK_NUM_LOCK
0852:                        && keyCode != KeyEvent.VK_SCROLL_LOCK
0853:                        && keyCode != KeyEvent.VK_KANA_LOCK) {
0854:                    throw new IllegalArgumentException();
0855:                }
0856:
0857:                return wtk.getLockingState(keyCode);
0858:            }
0859:
0860:            public int getMaximumCursorColors() throws HeadlessException {
0861:                lockAWT();
0862:                try {
0863:                    return wtk.getCursorFactory().getMaximumCursorColors();
0864:                } finally {
0865:                    unlockAWT();
0866:                }
0867:            }
0868:
0869:            public int getMenuShortcutKeyMask() throws HeadlessException {
0870:                lockAWT();
0871:                try {
0872:                    return InputEvent.CTRL_MASK;
0873:                } finally {
0874:                    unlockAWT();
0875:                }
0876:            }
0877:
0878:            public PrintJob getPrintJob(Frame a0, String a1, JobAttributes a2,
0879:                    PageAttributes a3)
0880:                    throws org.apache.harmony.luni.util.NotImplementedException {
0881:                lockAWT();
0882:                try {
0883:                } finally {
0884:                    unlockAWT();
0885:                }
0886:                if (true) {
0887:                    throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$
0888:                }
0889:                return null;
0890:            }
0891:
0892:            public Insets getScreenInsets(GraphicsConfiguration gc)
0893:                    throws HeadlessException {
0894:                if (gc == null) {
0895:                    throw new NullPointerException();
0896:                }
0897:                lockAWT();
0898:                try {
0899:                    return new Insets(0, 0, 0, 0); //TODO: get real screen insets
0900:                } finally {
0901:                    unlockAWT();
0902:                }
0903:            }
0904:
0905:            public final EventQueue getSystemEventQueue() {
0906:                SecurityManager sm = System.getSecurityManager();
0907:                if (sm != null) {
0908:                    sm.checkAwtEventQueueAccess();
0909:                }
0910:                return getSystemEventQueueImpl();
0911:            }
0912:
0913:            EventQueueCore getSystemEventQueueCore() {
0914:                return systemEventQueueCore;
0915:            }
0916:
0917:            void setSystemEventQueueCore(EventQueueCore core) {
0918:                systemEventQueueCore = core;
0919:            }
0920:
0921:            public Clipboard getSystemSelection() throws HeadlessException {
0922:                lockAWT();
0923:                try {
0924:                    SecurityManager security = System.getSecurityManager();
0925:                    if (security != null) {
0926:                        security.checkSystemClipboardAccess();
0927:                    }
0928:                    if (systemSelection == null) {
0929:                        systemSelection = dtk.getNativeSelection();
0930:                    }
0931:                    return systemSelection;
0932:                } finally {
0933:                    unlockAWT();
0934:                }
0935:            }
0936:
0937:            protected void initializeDesktopProperties() {
0938:                lockAWT();
0939:                try {
0940:                    wtk.getSystemProperties().init(desktopProperties);
0941:                } finally {
0942:                    unlockAWT();
0943:                }
0944:            }
0945:
0946:            public boolean isDynamicLayoutActive() throws HeadlessException {
0947:                lockAWT();
0948:                try {
0949:                    // always return true
0950:                    return true;
0951:                } finally {
0952:                    unlockAWT();
0953:                }
0954:            }
0955:
0956:            protected boolean isDynamicLayoutSet() throws HeadlessException {
0957:                lockAWT();
0958:                try {
0959:                    return bDynamicLayoutSet;
0960:                } finally {
0961:                    unlockAWT();
0962:                }
0963:            }
0964:
0965:            public boolean isFrameStateSupported(int state)
0966:                    throws HeadlessException {
0967:                lockAWT();
0968:                try {
0969:                    return wtk.getWindowFactory().isWindowStateSupported(state);
0970:                } finally {
0971:                    unlockAWT();
0972:                }
0973:            }
0974:
0975:            protected Object lazilyLoadDesktopProperty(String propName) {
0976:                return null;
0977:            }
0978:
0979:            protected void loadSystemColors(int[] colors)
0980:                    throws HeadlessException {
0981:                lockAWT();
0982:                try {
0983:                } finally {
0984:                    unlockAWT();
0985:                }
0986:            }
0987:
0988:            protected final void setDesktopProperty(String propName,
0989:                    Object value) {
0990:                Object oldVal;
0991:                lockAWT();
0992:                try {
0993:                    oldVal = getDesktopProperty(propName);
0994:                    userPropSet.add(propName);
0995:                    desktopProperties.put(propName, value);
0996:                } finally {
0997:                    unlockAWT();
0998:                }
0999:                desktopPropsSupport.firePropertyChange(propName, oldVal, value);
1000:            }
1001:
1002:            public void setDynamicLayout(boolean dynamic)
1003:                    throws HeadlessException {
1004:                lockAWT();
1005:                try {
1006:                    bDynamicLayoutSet = dynamic;
1007:                } finally {
1008:                    unlockAWT();
1009:                }
1010:            }
1011:
1012:            public void setLockingKeyState(int keyCode, boolean on)
1013:                    throws UnsupportedOperationException {
1014:
1015:                if (keyCode != KeyEvent.VK_CAPS_LOCK
1016:                        && keyCode != KeyEvent.VK_NUM_LOCK
1017:                        && keyCode != KeyEvent.VK_SCROLL_LOCK
1018:                        && keyCode != KeyEvent.VK_KANA_LOCK) {
1019:                    throw new IllegalArgumentException();
1020:                }
1021:
1022:                wtk.setLockingState(keyCode, on);
1023:            }
1024:
1025:            void onQueueEmpty() {
1026:                if (windows.isEmpty()) {
1027:                    if (systemClipboard != null) {
1028:                        systemClipboard.onShutdown();
1029:                    }
1030:                    if (systemSelection != null) {
1031:                        systemSelection.onShutdown();
1032:                    }
1033:                    shutdownWatchdog.setWindowListEmpty(true);
1034:                } else {
1035:                    for (Iterator<?> i = windows.iterator(); i.hasNext();) {
1036:                        ((Window) i.next()).redrawAll();
1037:                    }
1038:                }
1039:            }
1040:
1041:            private WTK createWTK(String clsName) {
1042:                WTK newWTK = null;
1043:                try {
1044:                    newWTK = (WTK) Class.forName(clsName).newInstance();
1045:                } catch (Exception e) {
1046:                    throw new RuntimeException(e);
1047:                }
1048:                return newWTK;
1049:            }
1050:
1051:            /**
1052:             * Connect the component to its native window
1053:             * This method is called after the synchronous window creation,
1054:             * and also in the window creation callback if it exists (WM_CREATE on Windows)
1055:             * Calling this method twice is OK because in second time it just does nothing.
1056:             *
1057:             * This is done this way because on Windows the native window gets a series of native
1058:             * events before windowFactory.CreateWindow() returns, and the WinWindow object should be created
1059:             * to process them. The WM_CREATE message is guaranteed to be first in the series, so that the
1060:             * the WM_CREATE handler creates the WinWindow object and calls nativeWindowCreated()
1061:             * for it.
1062:             *
1063:             * @param win - native window just created
1064:             */
1065:            void nativeWindowCreated(NativeWindow win) {
1066:                if (recentNativeWindowComponent == null) {
1067:                    return;
1068:                }
1069:                if (recentNativeWindowComponent instanceof  Component) {
1070:                    windowComponentMap.put(win, recentNativeWindowComponent);
1071:                    ((Component) recentNativeWindowComponent)
1072:                            .nativeWindowCreated(win);
1073:                } else if (recentNativeWindowComponent instanceof  PopupBox) {
1074:                    windowPopupMap.put(win, recentNativeWindowComponent);
1075:                }
1076:                recentNativeWindowComponent = null;
1077:            }
1078:
1079:            /**
1080:             * Connect the component to its native window
1081:             * @param winId - id of native window just created
1082:             */
1083:            boolean onWindowCreated(long winId) {
1084:                nativeWindowCreated(getWindowFactory().getWindowById(winId));
1085:                return false;
1086:            }
1087:
1088:            NativeWindow createEmbeddedNativeWindow(EmbeddedWindow ew) {
1089:                windows.add(ew);
1090:                CreationParams cp = new CreationParams();
1091:                cp.child = true;
1092:                cp.disabled = false;
1093:                cp.name = "EmbeddedWindow"; //$NON-NLS-1$
1094:                cp.parentId = ew.nativeWindowId;
1095:                cp.x = 0;
1096:                cp.y = 0;
1097:                Dimension size = getWindowFactory().getWindowSizeById(
1098:                        ew.nativeWindowId);
1099:                cp.w = size.width;
1100:                cp.h = size.height;
1101:                recentNativeWindowComponent = ew;
1102:                NativeWindow win = getWindowFactory().createWindow(cp);
1103:                nativeWindowCreated(win);
1104:                shutdownWatchdog.setWindowListEmpty(false);
1105:                return win;
1106:            }
1107:
1108:            NativeWindow createNativeWindow(Component c) {
1109:                if (c instanceof  Window) {
1110:                    windows.add(c);
1111:                }
1112:                Component parent = null;
1113:                Point location = c.getLocation();
1114:                CreationParams cp = new CreationParams();
1115:                cp.child = !(c instanceof  Window);
1116:                cp.disabled = !c.isEnabled();
1117:                if (c instanceof  Window) {
1118:                    Window w = (Window) c;
1119:                    cp.resizable = w.isResizable();
1120:                    cp.undecorated = w.isUndecorated();
1121:                    parent = w.getOwner();
1122:                    cp.locationByPlatform = w.locationByPlatform;
1123:                    if (c instanceof  Frame) {
1124:                        Frame frame = (Frame) c;
1125:                        int state = frame.getExtendedState();
1126:                        cp.name = frame.getTitle();
1127:                        cp.iconified = (state & Frame.ICONIFIED) != 0;
1128:                        cp.maximizedState = 0;
1129:                        if ((state & Frame.MAXIMIZED_BOTH) != 0) {
1130:                            cp.maximizedState |= cp.MAXIMIZED;
1131:                        }
1132:                        if ((state & Frame.MAXIMIZED_HORIZ) != 0) {
1133:                            cp.maximizedState |= cp.MAXIMIZED_HORIZ;
1134:                        }
1135:                        if ((state & Frame.MAXIMIZED_VERT) != 0) {
1136:                            cp.maximizedState |= cp.MAXIMIZED_VERT;
1137:                        }
1138:                        cp.decorType = CreationParams.DECOR_TYPE_FRAME;
1139:                    } else if (c instanceof  Dialog) {
1140:                        Dialog dlg = (Dialog) c;
1141:                        cp.name = dlg.getTitle();
1142:                        cp.decorType = CreationParams.DECOR_TYPE_DIALOG;
1143:                    } else if (w.isPopup()) {
1144:                        cp.decorType = CreationParams.DECOR_TYPE_POPUP;
1145:                    } else {
1146:                        cp.decorType = CreationParams.DECOR_TYPE_UNDECOR;
1147:                    }
1148:                } else {
1149:                    parent = c.getHWAncestor();
1150:                    cp.name = c.getName();
1151:                    //set location relative to the nearest heavy weight ancestor
1152:                    location = MouseDispatcher.convertPoint(c, 0, 0, parent);
1153:                }
1154:                if (parent != null) {
1155:                    NativeWindow nativeParent = parent.getNativeWindow();
1156:                    if (nativeParent == null) {
1157:                        if (cp.child) {
1158:                            return null; //component's window will be created when its parent is created ???
1159:                        }
1160:                        parent.mapToDisplay(true); //TODO: verify it
1161:                        nativeParent = parent.getNativeWindow();
1162:                    }
1163:                    cp.parentId = nativeParent.getId();
1164:                }
1165:                cp.x = location.x;
1166:                cp.y = location.y;
1167:                cp.w = c.getWidth();
1168:                cp.h = c.getHeight();
1169:                recentNativeWindowComponent = c;
1170:                NativeWindow win = getWindowFactory().createWindow(cp);
1171:                nativeWindowCreated(win);
1172:                if (c instanceof  Window) {
1173:                    shutdownWatchdog.setWindowListEmpty(false);
1174:                }
1175:                return win;
1176:            }
1177:
1178:            void removeNativeWindow(NativeWindow w) {
1179:                Component comp = (Component) windowComponentMap.get(w);
1180:                if ((comp != null) && (comp instanceof  Window)) {
1181:                    windows.remove(comp);
1182:                }
1183:                windowComponentMap.remove(w);
1184:            }
1185:
1186:            NativeWindow createPopupNativeWindow(PopupBox popup) {
1187:                CreationParams cp = new CreationParams();
1188:                cp.child = popup.isMenuBar();
1189:                cp.disabled = false;
1190:                cp.resizable = false;
1191:                cp.undecorated = true;
1192:                cp.iconified = false;
1193:                cp.visible = false;
1194:                cp.maximizedState = 0;
1195:                cp.decorType = CreationParams.DECOR_TYPE_POPUP;
1196:                NativeWindow nativeParent;
1197:                if (popup.getParent() != null) {
1198:                    nativeParent = popup.getParent().getNativeWindow();
1199:                } else {
1200:                    nativeParent = popup.getOwner().getNativeWindow();
1201:                }
1202:                assert nativeParent != null;
1203:                cp.parentId = nativeParent.getId();
1204:                cp.x = popup.getLocation().x;
1205:                cp.y = popup.getLocation().y;
1206:                cp.w = popup.getSize().width;
1207:                cp.h = popup.getSize().height;
1208:                recentNativeWindowComponent = popup;
1209:                NativeWindow win = getWindowFactory().createWindow(cp);
1210:                nativeWindowCreated(win);
1211:                return win;
1212:            }
1213:
1214:            void removePopupNativeWindow(NativeWindow w) {
1215:                windowPopupMap.remove(w);
1216:            }
1217:
1218:            NativeWindow createFocusProxyNativeWindow(Window owner) {
1219:                CreationParams cp = new CreationParams();
1220:                cp.child = true;
1221:                cp.disabled = false;
1222:                cp.resizable = false;
1223:                cp.undecorated = true;
1224:                cp.iconified = false;
1225:                cp.visible = true;
1226:                cp.maximizedState = 0;
1227:                cp.decorType = CreationParams.DECOR_TYPE_NONE;
1228:                cp.parentId = owner.getNativeWindow().getId();
1229:                cp.x = -10;
1230:                cp.y = -10;
1231:                cp.w = 1;
1232:                cp.h = 1;
1233:                NativeWindow win = getWindowFactory().createWindow(cp);
1234:                windowFocusProxyMap.put(win, owner);
1235:                return win;
1236:            }
1237:
1238:            void removeFocusProxyNativeWindow(NativeWindow w) {
1239:                windowFocusProxyMap.remove(w);
1240:            }
1241:
1242:            NativeEventQueue getNativeEventQueue() {
1243:                return wtk.getNativeEventQueue();
1244:            }
1245:
1246:            Object getEventMonitor() {
1247:                return wtk.getNativeEventQueue().getEventMonitor();
1248:            }
1249:
1250:            /**
1251:             * Returns a shared instance of implementation of org.apache.harmony.awt.wtk.NativeCursor
1252:             * for current platform for
1253:             * @param type - Java Cursor type
1254:             * @return new instance of implementation of NativeCursor
1255:             */
1256:            NativeCursor createNativeCursor(int type) {
1257:                return wtk.getCursorFactory().getCursor(type);
1258:            }
1259:
1260:            /**
1261:             * Returns a shared instance of implementation of org.apache.harmony.awt.wtk.NativeCursor
1262:             * for current platform for custom cursor
1263:             * @param type - Java Cursor type
1264:             * @return new instance of implementation of NativeCursor
1265:             */
1266:            NativeCursor createCustomNativeCursor(Image img, Point hotSpot,
1267:                    String name) {
1268:                return wtk.getCursorFactory().createCustomCursor(img,
1269:                        hotSpot.x, hotSpot.y);
1270:            }
1271:
1272:            /**
1273:             * Returns implementation of org.apache.harmony.awt.wtk.NativeMouseInfo
1274:             * for current platform.
1275:             * @return implementation of NativeMouseInfo
1276:             */
1277:            NativeMouseInfo getNativeMouseInfo() {
1278:                return wtk.getNativeMouseInfo();
1279:            }
1280:
1281:            public void addAWTEventListener(AWTEventListener listener,
1282:                    long eventMask) {
1283:                lockAWT();
1284:                try {
1285:                    SecurityManager security = System.getSecurityManager();
1286:                    if (security != null) {
1287:                        security.checkPermission(awtEventsManager.permission);
1288:                    }
1289:                    awtEventsManager.addAWTEventListener(listener, eventMask);
1290:                } finally {
1291:                    unlockAWT();
1292:                }
1293:            }
1294:
1295:            public void removeAWTEventListener(AWTEventListener listener) {
1296:                lockAWT();
1297:                try {
1298:                    SecurityManager security = System.getSecurityManager();
1299:                    if (security != null) {
1300:                        security.checkPermission(awtEventsManager.permission);
1301:                    }
1302:                    awtEventsManager.removeAWTEventListener(listener);
1303:                } finally {
1304:                    unlockAWT();
1305:                }
1306:            }
1307:
1308:            public AWTEventListener[] getAWTEventListeners() {
1309:                lockAWT();
1310:                try {
1311:                    SecurityManager security = System.getSecurityManager();
1312:                    if (security != null) {
1313:                        security.checkPermission(awtEventsManager.permission);
1314:                    }
1315:                    return awtEventsManager.getAWTEventListeners();
1316:                } finally {
1317:                    unlockAWT();
1318:                }
1319:            }
1320:
1321:            public AWTEventListener[] getAWTEventListeners(long eventMask) {
1322:                lockAWT();
1323:                try {
1324:                    SecurityManager security = System.getSecurityManager();
1325:                    if (security != null) {
1326:                        security.checkPermission(awtEventsManager.permission);
1327:                    }
1328:                    return awtEventsManager.getAWTEventListeners(eventMask);
1329:                } finally {
1330:                    unlockAWT();
1331:                }
1332:            }
1333:
1334:            void dispatchAWTEvent(AWTEvent event) {
1335:                awtEventsManager.dispatchAWTEvent(event);
1336:            }
1337:
1338:            private static Theme createTheme() {
1339:                String osName = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
1340:                String packageBase = "org.apache.harmony.awt.theme", win = "windows", lin = "linux"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1341:                PrivilegedAction<String> action = new PrivilegedAction<String>() {
1342:                    public String run() {
1343:                        return System.getProperty("awt.theme"); //$NON-NLS-1$
1344:                    }
1345:                };
1346:                String className = AccessController.doPrivileged(action);
1347:                if (className == null) {
1348:                    if (osName.startsWith(lin)) {
1349:                        className = packageBase + "." + lin + ".LinuxTheme"; //$NON-NLS-1$ //$NON-NLS-2$
1350:                    } else if (osName.startsWith(win)) {
1351:                        className = packageBase + "." + win + ".WinTheme"; //$NON-NLS-1$ //$NON-NLS-2$
1352:                    }
1353:                }
1354:                if (className != null) {
1355:                    try {
1356:                        return (Theme) Class.forName(className).newInstance();
1357:                    } catch (Exception e) {
1358:                    }
1359:                }
1360:                return new Theme();
1361:            }
1362:
1363:            final class AWTEventsManager {
1364:                AWTPermission permission = new AWTPermission(
1365:                        "listenToAllAWTEvents"); //$NON-NLS-1$
1366:
1367:                private final AWTListenerList<AWTEventListenerProxy> listeners = new AWTListenerList<AWTEventListenerProxy>();
1368:
1369:                void addAWTEventListener(AWTEventListener listener,
1370:                        long eventMask) {
1371:                    if (listener != null) {
1372:                        listeners.addUserListener(new AWTEventListenerProxy(
1373:                                eventMask, listener));
1374:                    }
1375:                }
1376:
1377:                void removeAWTEventListener(AWTEventListener listener) {
1378:                    if (listener != null) {
1379:                        for (AWTEventListenerProxy proxy : listeners
1380:                                .getUserListeners()) {
1381:                            if (listener == proxy.getListener()) {
1382:                                listeners.removeUserListener(proxy);
1383:                                return;
1384:                            }
1385:                        }
1386:                    }
1387:                }
1388:
1389:                AWTEventListener[] getAWTEventListeners() {
1390:                    HashSet<EventListener> listenersSet = new HashSet<EventListener>();
1391:                    for (AWTEventListenerProxy proxy : listeners
1392:                            .getUserListeners()) {
1393:                        listenersSet.add(proxy.getListener());
1394:                    }
1395:                    return listenersSet
1396:                            .toArray(new AWTEventListener[listenersSet.size()]);
1397:                }
1398:
1399:                AWTEventListener[] getAWTEventListeners(long eventMask) {
1400:                    HashSet<EventListener> listenersSet = new HashSet<EventListener>();
1401:                    for (AWTEventListenerProxy proxy : listeners
1402:                            .getUserListeners()) {
1403:                        if ((proxy.getEventMask() & eventMask) == eventMask) {
1404:                            listenersSet.add(proxy.getListener());
1405:                        }
1406:                    }
1407:                    return listenersSet
1408:                            .toArray(new AWTEventListener[listenersSet.size()]);
1409:                }
1410:
1411:                void dispatchAWTEvent(AWTEvent event) {
1412:                    AWTEvent.EventDescriptor descriptor = eventTypeLookup
1413:                            .getEventDescriptor(event);
1414:                    if (descriptor == null) {
1415:                        return;
1416:                    }
1417:                    for (AWTEventListenerProxy proxy : listeners
1418:                            .getUserListeners()) {
1419:                        if ((proxy.getEventMask() & descriptor.eventMask) != 0) {
1420:                            proxy.eventDispatched(event);
1421:                        }
1422:                    }
1423:                }
1424:            }
1425:
1426:            static final class AutoNumber {
1427:                int nextComponent = 0;
1428:
1429:                int nextCanvas = 0;
1430:
1431:                int nextPanel = 0;
1432:
1433:                int nextWindow = 0;
1434:
1435:                int nextFrame = 0;
1436:
1437:                int nextDialog = 0;
1438:
1439:                int nextButton = 0;
1440:
1441:                int nextMenuComponent = 0;
1442:
1443:                int nextLabel = 0;
1444:
1445:                int nextCheckBox = 0;
1446:
1447:                int nextScrollbar = 0;
1448:
1449:                int nextScrollPane = 0;
1450:
1451:                int nextList = 0;
1452:
1453:                int nextChoice = 0;
1454:
1455:                int nextFileDialog = 0;
1456:
1457:                int nextTextArea = 0;
1458:
1459:                int nextTextField = 0;
1460:            }
1461:
1462:            /**
1463:             * Thread-safe collection of Window objects
1464:             */
1465:            static final class WindowList {
1466:                /**
1467:                 * If a non-dispatch thread adds/removes a window,
1468:                 * this set it is replaced to avoid the possible conflict
1469:                 * with concurrently running lock-free iterator loop
1470:                 */
1471:                private LinkedHashSet<Component> windows = new LinkedHashSet<Component>();
1472:
1473:                private class Lock {
1474:                }
1475:
1476:                private final Object lock = new Lock();
1477:
1478:                @SuppressWarnings("unchecked")
1479:                void add(Component w) {
1480:                    synchronized (lock) {
1481:                        if (isDispatchThread()) {
1482:                            windows.add(w);
1483:                        } else {
1484:                            windows = (LinkedHashSet<Component>) windows
1485:                                    .clone();
1486:                            windows.add(w);
1487:                        }
1488:                    }
1489:                }
1490:
1491:                @SuppressWarnings("unchecked")
1492:                void remove(Component w) {
1493:                    synchronized (lock) {
1494:                        if (isDispatchThread()) {
1495:                            windows.remove(w);
1496:                        } else {
1497:                            windows = (LinkedHashSet<Component>) windows
1498:                                    .clone();
1499:                            windows.remove(w);
1500:                        }
1501:                    }
1502:                }
1503:
1504:                Iterator<Component> iterator() {
1505:                    synchronized (lock) {
1506:                        return new ReadOnlyIterator<Component>(windows
1507:                                .iterator());
1508:                    }
1509:                }
1510:
1511:                boolean isEmpty() {
1512:                    synchronized (lock) {
1513:                        return windows.isEmpty();
1514:                    }
1515:                }
1516:
1517:                private boolean isDispatchThread() {
1518:                    return Thread.currentThread() instanceof  EventDispatchThread;
1519:                }
1520:            }
1521:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.