use of com.github.weisj.darklaf.properties.icons.UIAwareIcon in project darklaf by weisJ.
the class IconDemo method createComponent.
@Override
public JComponent createComponent() {
iconPanel = new JPanel(new GridLayout(3, 2, LayoutHelper.getDefaultSpacing(), LayoutHelper.getDefaultSpacing()));
iconPanel.setBorder(LayoutHelper.createEmptyContainerBorder());
UIManager.put("TestIcon.color", new Color(255, 35, 181));
IconLoader iconLoader = IconLoader.get(IconDemo.class);
UIAwareIcon uiAwareImageIcon = iconLoader.getUIAwareIcon("aware_image_icon.png");
UIAwareIcon uiAwareImageIconDual = uiAwareImageIcon.getDual();
UIAwareIcon uiAwareIcon = iconLoader.getUIAwareIcon("aware_icon.svg");
UIAwareIcon uiAwareIconDual = uiAwareIcon.getDual();
Icon themedIcon = iconLoader.getIcon("themed_icon.svg", 16, 16, true);
Icon imageIcon = iconLoader.getIcon("image_icon.png");
iconPanel.add(new JLabel("Aware image icon", uiAwareImageIcon, JLabel.LEFT));
iconPanel.add(new JLabel("Aware image icon (dual)", uiAwareImageIconDual, JLabel.LEFT));
iconPanel.add(new JLabel("Aware svg icon", uiAwareIcon, JLabel.LEFT));
iconPanel.add(new JLabel("Aware svg icon (dual)", uiAwareIconDual, JLabel.LEFT));
iconPanel.add(new JLabel("Themed icon", themedIcon, JLabel.LEFT));
iconPanel.add(new JLabel("Image icon", imageIcon, JLabel.LEFT));
DemoPanel panel = new DemoPanel(iconPanel, new BorderLayout(), 0);
JPanel controlPanel = panel.addControls();
controlPanel.add(new JToggleButton("Light/Dark") {
{
LafManager.addThemeChangeListener((ThemeInstalledListener) e -> setSelected(Theme.isDark(e.getNewTheme())));
putClientProperty("JToggleButton.variant", "slider");
addActionListener(e -> updateAwareIconStyle());
}
});
controlPanel.add(new QuickColorChooser("Themed icon color", UIManager.getColor("TestIcon.color"), this::updateThemedIconColor));
return panel;
}
use of com.github.weisj.darklaf.properties.icons.UIAwareIcon in project darklaf by weisJ.
the class IconParser method doParse.
@Override
public ParseResult doParse(final ParseResult parseResult, final ParserContext context) {
if (parseResult.value.startsWith(String.valueOf(LIST_START)) && parseResult.value.endsWith(String.valueOf(LIST_END))) {
return parseStateIcon(parseResult, context);
}
Dimension dim = new Dimension(-1, -1);
if (parseResult.value.endsWith(String.valueOf(ARG_END))) {
List<Integer> dimensions = ParserUtil.parseDelimited(ARG_START, ARG_END, ARG_SEPARATOR, false, PropertyParser.of(Integer::parseInt), Integer.class, parseResult, context);
if (dimensions.size() != 2)
return ParserUtil.error(parseResult, "Invalid dimension.");
dim.width = dimensions.get(0);
dim.height = dimensions.get(1);
}
List<String> modifiers;
if (parseResult.value.endsWith(String.valueOf(MODIFIER_END))) {
modifiers = ParserUtil.parseDelimited(MODIFIER_START, MODIFIER_END, MODIFIER_DELIMITER, false, PropertyParser.of(s -> s), String.class, parseResult, context);
} else {
modifiers = Collections.emptyList();
}
boolean dual = modifiers.contains(DUAL_KEY);
boolean aware = modifiers.contains(AWARE_KEY);
boolean themed = modifiers.contains(THEMED_KEY);
if (aware && themed) {
return ParserUtil.error(parseResult, "Modifiers " + AWARE_KEY + " and " + THEMED_KEY + " are mutually exclusive.");
}
Icon icon;
if (ICON_EMPTY.equals(parseResult.value)) {
icon = EmptyIcon.create(dim.width, dim.height);
} else if (themed) {
icon = context.iconResolver.getIcon(parseResult.value, dim.width, dim.height, true);
} else if (dual || aware) {
UIAwareIcon awareIcon = context.iconResolver.getUIAwareIcon(parseResult.value, dim.width, dim.height);
if (dual) {
icon = awareIcon.getDual();
} else {
icon = awareIcon;
}
} else {
icon = context.iconResolver.getIcon(parseResult.value, dim.width, dim.height);
}
return ParserUtil.setNonNull(parseResult, icon);
}
Aggregations