Search in sources :

Example 1 with UIAwareIcon

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;
}
Also used : UIAwareIcon(com.github.weisj.darklaf.properties.icons.UIAwareIcon) BaseComponentDemo(com.github.weisj.darklaf.ui.demo.BaseComponentDemo) LafManager(com.github.weisj.darklaf.LafManager) Theme(com.github.weisj.darklaf.theme.Theme) ThemeInstalledListener(com.github.weisj.darklaf.theme.event.ThemeInstalledListener) java.awt(java.awt) DemoExecutor(com.github.weisj.darklaf.ui.demo.DemoExecutor) LayoutHelper(com.github.weisj.darklaf.layout.LayoutHelper) IconLoader(com.github.weisj.darklaf.properties.icons.IconLoader) UIAwareIcon(com.github.weisj.darklaf.properties.icons.UIAwareIcon) DemoPanel(com.github.weisj.darklaf.ui.DemoPanel) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) DarkUIUtil(com.github.weisj.darklaf.ui.util.DarkUIUtil) javax.swing(javax.swing) ThemeInstalledListener(com.github.weisj.darklaf.theme.event.ThemeInstalledListener) DemoPanel(com.github.weisj.darklaf.ui.DemoPanel) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) UIAwareIcon(com.github.weisj.darklaf.properties.icons.UIAwareIcon) IconLoader(com.github.weisj.darklaf.properties.icons.IconLoader)

Example 2 with UIAwareIcon

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);
}
Also used : UIAwareIcon(com.github.weisj.darklaf.properties.icons.UIAwareIcon) Dimension(java.awt.Dimension) EmptyIcon(com.github.weisj.darklaf.properties.icons.EmptyIcon) Icon(javax.swing.Icon) UIAwareIcon(com.github.weisj.darklaf.properties.icons.UIAwareIcon) StateIcon(com.github.weisj.darklaf.properties.icons.StateIcon)

Aggregations

UIAwareIcon (com.github.weisj.darklaf.properties.icons.UIAwareIcon)2 LafManager (com.github.weisj.darklaf.LafManager)1 QuickColorChooser (com.github.weisj.darklaf.components.color.QuickColorChooser)1 LayoutHelper (com.github.weisj.darklaf.layout.LayoutHelper)1 EmptyIcon (com.github.weisj.darklaf.properties.icons.EmptyIcon)1 IconLoader (com.github.weisj.darklaf.properties.icons.IconLoader)1 StateIcon (com.github.weisj.darklaf.properties.icons.StateIcon)1 Theme (com.github.weisj.darklaf.theme.Theme)1 ThemeInstalledListener (com.github.weisj.darklaf.theme.event.ThemeInstalledListener)1 DemoPanel (com.github.weisj.darklaf.ui.DemoPanel)1 BaseComponentDemo (com.github.weisj.darklaf.ui.demo.BaseComponentDemo)1 DemoExecutor (com.github.weisj.darklaf.ui.demo.DemoExecutor)1 DarkUIUtil (com.github.weisj.darklaf.ui.util.DarkUIUtil)1 java.awt (java.awt)1 Dimension (java.awt.Dimension)1 javax.swing (javax.swing)1 Icon (javax.swing.Icon)1