JDK-6726690 fixed the issue whereby

> SwingUtilities.replaceUIInputMap() and SwingUtilities.replaceUIActionMap() 
> were not actually removing/uninstalling previously installed maps
>  contrary to what their Javadoc indicates, if null is passed as 
> uiInputMap/uiActionMap

 by adding map.clear() to the traversal whenever the replacement argument was 
null.
 So, the old bindings were erased, however, it turned out it also deleted 
bindings belonging to the application.
 
 Basically, it is found that map traversal starts at the component’s own 
application map.
 Consequently, the new clearing operation deletes application entries _before_ 
reaching the UI-owned parent,
 and it can also clear application-provided intermediate parent maps.

 The methods have no information that a particular entry belongs to the 
application; it simply clears whichever map it is currently visiting.
 This becomes a regression because Swing itself calls these removal methods 
`replaceUIInputMap()`, `replaceUIActionMap()` during normal UI changes.
 When `updateComponentTreeUI()` updates a component, Swing uninstalls its old 
UI delegate and installs the current look-and-feel delegate.
 During uninstallation, delegates remove their keyboard bindings by calling 
`replaceUIInputMap(..., null)` and `replaceUIActionMap(..., null)`.
 With unconditional clearing, those cleanup calls erase application shortcuts 
too. 
That is the failure reported here.
 
 This patch introduces a temporary record of which components are undergoing UI 
installation or uninstallation
 The existing callback calls in JComponent go through newly added helper 
methods in SwingUtilities2.
 Before invoking the delegate, the helper method `installUI()` records the 
component UI-change context.
 After the delegate returns, it restores the previous record in` changeUI()`.
 The actual delegate still performs its normal installation or cleanup.
 The helper method` isChangingUI()` then consult that record before clearing a 
map, that is,
 checks whether the component has an active UI-change context.
 `SwingUtilities.replaceUIInputMap()` and `replaceUIActionMap()` use this to 
decide whether to skip map.clear().
 If the component is undergoing one of these managed UI callbacks, the methods 
skip map.clear().
 
 The application’s own entries remain available throughout the operation,
 so its call to `updateComponentTreeUI()` reaches the guarded delegate 
callbacks.
 When those callbacks request UI-map removal, clearing is suppressed, so 
application entries survive
 but explicit removal calls done in JDK-6726690 happen outside those guarded 
callbacks so clearing remains enabled there.



---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - test fix
 - Fix
 - 8394820: Look and feel change clears the key bindings applications put in 
components' own InputMap and ActionMap (regression from JDK-6726690)

Changes: https://git.openjdk.org/jdk/pull/34034/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34034&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8394820
  Stats: 175 lines in 4 files changed: 170 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/34034.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/34034/head:pull/34034

PR: https://git.openjdk.org/jdk/pull/34034

Reply via email to