jdk/src/macosx/classes/sun/lwawt/LWKeyboardFocusManagerPeer.java
changeset 13648 90effcfc064f
parent 12047 320a714614e9
child 18241 3e009b5be123
equal deleted inserted replaced
13647:de61414bbcf2 13648:90effcfc064f
    24  */
    24  */
    25 
    25 
    26 package sun.lwawt;
    26 package sun.lwawt;
    27 
    27 
    28 import java.awt.Component;
    28 import java.awt.Component;
    29 import java.awt.KeyboardFocusManager;
       
    30 import java.awt.Window;
    29 import java.awt.Window;
    31 
       
    32 import java.util.Map;
       
    33 import java.util.HashMap;
       
    34 
       
    35 import sun.awt.AWTAccessor;
       
    36 import sun.awt.AppContext;
       
    37 import sun.awt.KeyboardFocusManagerPeerImpl;
    30 import sun.awt.KeyboardFocusManagerPeerImpl;
    38 
    31 
    39 public class LWKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
    32 public class LWKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl {
       
    33     private static final LWKeyboardFocusManagerPeer inst = new LWKeyboardFocusManagerPeer();
    40 
    34 
    41     private Object lock = new Object();
    35     private Window focusedWindow;
    42     private LWWindowPeer focusedWindow;
    36     private Component focusOwner;
    43     private LWComponentPeer focusOwner;
       
    44 
    37 
    45     private static Map<KeyboardFocusManager, LWKeyboardFocusManagerPeer> instances =
    38     public static LWKeyboardFocusManagerPeer getInstance() {
    46         new HashMap<KeyboardFocusManager, LWKeyboardFocusManagerPeer>();
    39         return inst;
    47 
       
    48     public static synchronized LWKeyboardFocusManagerPeer getInstance(AppContext ctx) {
       
    49         return getInstance(AWTAccessor.getKeyboardFocusManagerAccessor().
       
    50                            getCurrentKeyboardFocusManager(ctx));
       
    51     }
    40     }
    52 
    41 
    53     public static synchronized LWKeyboardFocusManagerPeer getInstance(KeyboardFocusManager manager) {
    42     private LWKeyboardFocusManagerPeer() {
    54         LWKeyboardFocusManagerPeer instance = instances.get(manager);
       
    55         if (instance == null) {
       
    56             instance = new LWKeyboardFocusManagerPeer(manager);
       
    57             instances.put(manager, instance);
       
    58         }
       
    59         return instance;
       
    60     }
    43     }
    61 
    44 
    62     public LWKeyboardFocusManagerPeer(KeyboardFocusManager manager) {
    45     @Override
    63         super(manager);
    46     public void setCurrentFocusedWindow(Window win) {
       
    47         synchronized (this) {
       
    48             focusedWindow = win;
       
    49         }
    64     }
    50     }
    65 
    51 
    66     @Override
    52     @Override
    67     public Window getCurrentFocusedWindow() {
    53     public Window getCurrentFocusedWindow() {
    68         synchronized (lock) {
    54         synchronized (this) {
    69             return (focusedWindow != null) ? (Window)focusedWindow.getTarget() : null;
    55             return focusedWindow;
    70         }
    56         }
    71     }
    57     }
    72 
    58 
    73     @Override
    59     @Override
    74     public Component getCurrentFocusOwner() {
    60     public Component getCurrentFocusOwner() {
    75         synchronized (lock) {
    61         synchronized (this) {
    76             return (focusOwner != null) ? focusOwner.getTarget() : null;
    62             return focusOwner;
    77         }
    63         }
    78     }
    64     }
    79 
    65 
    80     @Override
    66     @Override
    81     public void setCurrentFocusOwner(Component comp) {
    67     public void setCurrentFocusOwner(Component comp) {
    82         synchronized (lock) {
    68         synchronized (this) {
    83             focusOwner = (comp != null) ? (LWComponentPeer)comp.getPeer() : null;
    69             focusOwner = comp;
    84         }
       
    85     }
       
    86 
       
    87     void setFocusedWindow(LWWindowPeer peer) {
       
    88         synchronized (lock) {
       
    89             focusedWindow = peer;
       
    90         }
       
    91     }
       
    92 
       
    93     LWWindowPeer getFocusedWindow() {
       
    94         synchronized (lock) {
       
    95             return focusedWindow;
       
    96         }
       
    97     }
       
    98 
       
    99     void setFocusOwner(LWComponentPeer peer) {
       
   100         synchronized (lock) {
       
   101             focusOwner = peer;
       
   102         }
       
   103     }
       
   104 
       
   105     LWComponentPeer getFocusOwner() {
       
   106         synchronized (lock) {
       
   107             return focusOwner;
       
   108         }
    70         }
   109     }
    71     }
   110 }
    72 }