Browse Source

Icons: Inherit visual padding from icons in StateIcon

pull/336/head
Jannis Weis 2 years ago
parent
commit
b59813a48b
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 17
      property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java

17
property-loader/src/main/java/com/github/weisj/darklaf/properties/icons/StateIcon.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2019-2021 Jannis Weis * Copyright (c) 2019-2023 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, * associated documentation files (the "Software"), to deal in the Software without restriction,
@ -25,8 +25,12 @@ import java.util.List;
import javax.swing.*; import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import com.github.weisj.swingdsl.visualpadding.VisualPaddingProvider;
/** Icon that should be used with JCheckBox or JRadioButton. All icons should have the same size. */ /** Icon that should be used with JCheckBox or JRadioButton. All icons should have the same size. */
public class StateIcon implements Icon { public class StateIcon implements Icon, VisualPaddingProvider {
private final Icon icon; private final Icon icon;
private final Icon disabledIcon; private final Icon disabledIcon;
@ -87,4 +91,13 @@ public class StateIcon implements Icon {
public int getIconHeight() { public int getIconHeight() {
return icon.getIconHeight(); return icon.getIconHeight();
} }
@Override
public @NotNull Insets getVisualPaddings(@NotNull Component component) {
Icon icon = getIcon(component);
if (icon instanceof VisualPaddingProvider) {
return ((VisualPaddingProvider) icon).getVisualPaddings(component);
}
return new Insets(0, 0, 0, 0);
}
} }

Loading…
Cancel
Save