mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-21 20:05:32 +08:00
Merge remote-tracking branch
'origin/GP-6828-dragonmacher-theming-flat-border-fix' (Closes #9178)
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.UIDefaults.LazyValue;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||
@@ -674,6 +675,32 @@ public class UiDefaultsMapper {
|
||||
*/
|
||||
private List<String> getLookAndFeelIdsForType(Class<?> clazz) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
/*
|
||||
Note: the act of calling defaults.get(key) will cause LazyValues to get loaded and
|
||||
installed. This is a problem for any complex object that holds Color state. After this
|
||||
method is called we will install our GColor indirection mechanism. But, if the
|
||||
LazyValue gets created during this method, then that value may be holding Color objects
|
||||
that are not using our indirection, thus making them not responsive to theme changes.
|
||||
An example of this is a custom Border object with saved Color fields.
|
||||
|
||||
To work around this issue, we save off all LazyValues and then restore them after we get
|
||||
the value. By doing this, the LazyValue will get called again later after we have
|
||||
installed our indirection.
|
||||
*/
|
||||
|
||||
// 1) save all LazyValues so we can restore them later
|
||||
Map<Object, Object> lazyRestores = new HashMap<>();
|
||||
Set<Entry<Object, Object>> entries = defaults.entrySet();
|
||||
for (Entry<Object, Object> entry : entries) {
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof LazyValue) {
|
||||
lazyRestores.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) find all keys that map to the given 'clazz' passed to this method
|
||||
List<Object> keyList = IteratorUtils.toList(defaults.keys().asIterator());
|
||||
for (Object key : keyList) {
|
||||
if (key instanceof String) {
|
||||
@@ -681,8 +708,18 @@ public class UiDefaultsMapper {
|
||||
if (clazz.isInstance(value)) {
|
||||
ids.add((String) key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 3_ put the LazyValues back so we undo any items created while we were getting values
|
||||
Set<Entry<Object, Object>> restoreEntries = lazyRestores.entrySet();
|
||||
for (Entry<Object, Object> entry : restoreEntries) {
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
defaults.put(key, value);
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user