Browse Source

Remove unnecessary reflection in DarkLaf

pull/97/head
Vladimir Sitnikov 5 years ago
parent
commit
3fe7403b08
  1. 61
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

61
core/src/main/java/com/github/weisj/darklaf/DarkLaf.java

@ -43,7 +43,6 @@ import java.awt.event.KeyEvent;
import java.awt.font.TextAttribute; import java.awt.font.TextAttribute;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.reflect.Method;
import java.text.AttributedCharacterIterator; import java.text.AttributedCharacterIterator;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -105,12 +104,9 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
@Override @Override
public UIDefaults getDefaults() { public UIDefaults getDefaults() {
final UIDefaults metalDefaults = new MetalLookAndFeel().getDefaults();
final UIDefaults defaults = base.getDefaults();
try { try {
final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
superMethod.setAccessible(true);
final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel());
final UIDefaults defaults = (UIDefaults) superMethod.invoke(base);
initInputMapDefaults(defaults); initInputMapDefaults(defaults);
loadThemeDefaults(defaults); loadThemeDefaults(defaults);
initIdeaDefaults(defaults); initIdeaDefaults(defaults);
@ -130,7 +126,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace()); LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace());
} }
return super.getDefaults(); return defaults;
} }
private void patchMacOSFonts(final UIDefaults defaults) { private void patchMacOSFonts(final UIDefaults defaults) {
@ -359,7 +355,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
* On macOS the default PopupFactory is overwritten with a custom one, which always uses heavyweight popups. * On macOS the default PopupFactory is overwritten with a custom one, which always uses heavyweight popups.
* This is disadvantageous for the behaviour of custom tooltips. * This is disadvantageous for the behaviour of custom tooltips.
*/ */
call("initialize"); base.initialize();
PopupFactory.setSharedInstance(new DarkPopupFactory()); PopupFactory.setSharedInstance(new DarkPopupFactory());
PropertyLoader.reset(); PropertyLoader.reset();
UIManager.addPropertyChangeListener(this); UIManager.addPropertyChangeListener(this);
@ -367,7 +363,7 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
@Override @Override
public void uninitialize() { public void uninitialize() {
call("uninitialize"); base.uninitialize();
AppContext context = AppContext.getAppContext(); AppContext context = AppContext.getAppContext();
UIManager.removePropertyChangeListener(this); UIManager.removePropertyChangeListener(this);
synchronized (DarkPopupMenuUI.MOUSE_GRABBER_KEY) { synchronized (DarkPopupMenuUI.MOUSE_GRABBER_KEY) {
@ -378,63 +374,16 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener
} }
} }
@Override
protected void initClassDefaults(final UIDefaults defaults) {
callInit("initClassDefaults", defaults);
}
@Override @Override
public boolean isNativeLookAndFeel() { public boolean isNativeLookAndFeel() {
return true; return true;
} }
@Override
protected void initSystemColorDefaults(final UIDefaults defaults) {
callInit("initSystemColorDefaults", defaults);
}
@Override
protected void loadSystemColors(final UIDefaults defaults, final String[] systemColors,
final boolean useNative) {
try {
final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(
"loadSystemColors", UIDefaults.class, String[].class, boolean.class);
superMethod.setAccessible(true);
superMethod.invoke(base, defaults, systemColors, useNative);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace());
}
}
public void initComponentDefaults(final UIDefaults defaults) {
callInit("initComponentDefaults", defaults);
}
@Override @Override
public boolean isSupportedLookAndFeel() { public boolean isSupportedLookAndFeel() {
return true; return true;
} }
private void callInit(final String method, final UIDefaults defaults) {
try {
final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method, UIDefaults.class);
superMethod.setAccessible(true);
superMethod.invoke(base, defaults);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace());
}
}
private void call(final String method) {
try {
final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod(method);
superMethod.setAccessible(true);
superMethod.invoke(base);
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.toString(), e.getStackTrace());
}
}
@Override @Override
public void propertyChange(final PropertyChangeEvent evt) { public void propertyChange(final PropertyChangeEvent evt) {
if (LOOK_AND_FEEL_PROPERTY.equals(evt.getPropertyName())) { if (LOOK_AND_FEEL_PROPERTY.equals(evt.getPropertyName())) {

Loading…
Cancel
Save