equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package sun.awt; |
25 package sun.awt; |
26 |
26 |
27 import java.awt.Component; |
27 import java.awt.Component; |
28 import java.awt.KeyboardFocusManager; |
|
29 import java.awt.Window; |
28 import java.awt.Window; |
30 import java.awt.Canvas; |
29 import java.awt.Canvas; |
31 import java.awt.Scrollbar; |
30 import java.awt.Scrollbar; |
32 import java.awt.Panel; |
31 import java.awt.Panel; |
33 |
32 |
34 import java.awt.event.FocusEvent; |
33 import java.awt.event.FocusEvent; |
35 |
34 |
36 import java.awt.peer.KeyboardFocusManagerPeer; |
35 import java.awt.peer.KeyboardFocusManagerPeer; |
37 import java.awt.peer.ComponentPeer; |
36 import java.awt.peer.ComponentPeer; |
38 |
37 |
39 import java.lang.reflect.InvocationTargetException; |
38 import sun.awt.AWTAccessor.ComponentAccessor; |
40 import java.lang.reflect.Method; |
|
41 |
|
42 import sun.util.logging.PlatformLogger; |
39 import sun.util.logging.PlatformLogger; |
43 |
40 |
44 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer { |
41 public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManagerPeer { |
45 |
42 |
46 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl"); |
43 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.focus.KeyboardFocusManagerPeerImpl"); |
73 * |
70 * |
74 * Checks if the component: |
71 * Checks if the component: |
75 * 1) accepts focus on click (in general) |
72 * 1) accepts focus on click (in general) |
76 * 2) may be a focus owner (in particular) |
73 * 2) may be a focus owner (in particular) |
77 */ |
74 */ |
78 @SuppressWarnings("deprecation") |
|
79 public static boolean shouldFocusOnClick(Component component) { |
75 public static boolean shouldFocusOnClick(Component component) { |
80 boolean acceptFocusOnClick = false; |
76 boolean acceptFocusOnClick = false; |
81 |
77 |
82 // A component is generally allowed to accept focus on click |
78 // A component is generally allowed to accept focus on click |
83 // if its peer is focusable. There're some exceptions though. |
79 // if its peer is focusable. There're some exceptions though. |
84 |
80 |
85 |
81 |
86 // CANVAS & SCROLLBAR accept focus on click |
82 // CANVAS & SCROLLBAR accept focus on click |
|
83 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); |
87 if (component instanceof Canvas || |
84 if (component instanceof Canvas || |
88 component instanceof Scrollbar) |
85 component instanceof Scrollbar) |
89 { |
86 { |
90 acceptFocusOnClick = true; |
87 acceptFocusOnClick = true; |
91 |
88 |
94 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0); |
91 acceptFocusOnClick = (((Panel)component).getComponentCount() == 0); |
95 |
92 |
96 |
93 |
97 // Other components |
94 // Other components |
98 } else { |
95 } else { |
99 ComponentPeer peer = (component != null ? component.getPeer() : null); |
96 ComponentPeer peer = (component != null ? acc.getPeer(component) : null); |
100 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false); |
97 acceptFocusOnClick = (peer != null ? peer.isFocusable() : false); |
101 } |
98 } |
102 return acceptFocusOnClick && |
99 return acceptFocusOnClick && acc.canBeFocusOwner(component); |
103 AWTAccessor.getComponentAccessor().canBeFocusOwner(component); |
|
104 } |
100 } |
105 |
101 |
106 /* |
102 /* |
107 * Posts proper lost/gain focus events to the event queue. |
103 * Posts proper lost/gain focus events to the event queue. |
108 */ |
104 */ |
118 if (lightweightChild == null) { |
114 if (lightweightChild == null) { |
119 lightweightChild = target; |
115 lightweightChild = target; |
120 } |
116 } |
121 |
117 |
122 Component currentOwner = currentFocusOwner; |
118 Component currentOwner = currentFocusOwner; |
123 if (currentOwner != null && currentOwner.getPeer() == null) { |
119 if (currentOwner != null && !currentOwner.isDisplayable()) { |
124 currentOwner = null; |
120 currentOwner = null; |
125 } |
121 } |
126 if (currentOwner != null) { |
122 if (currentOwner != null) { |
127 FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST, |
123 FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST, |
128 false, lightweightChild, cause); |
124 false, lightweightChild, cause); |