Search in sources :

Example 1 with IconLoader

use of com.github.weisj.darklaf.properties.icons.IconLoader in project darklaf by weisJ.

the class IconCacheTest method testIconCacheGetsReleased.

@Test
void testIconCacheGetsReleased() {
    IconLoader iconLoader = (IconLoader) IconSet.iconLoader();
    iconLoader.clearCache();
    UIDefaults defaults = new DarkLaf().getDefaults();
    Assertions.assertFalse(iconLoader.isCacheEmpty());
    int size = iconLoader.cacheSize();
    defaults.clear();
    waitForGarbageCollection(() -> iconLoader.cacheSize() == size);
}
Also used : UIDefaults(javax.swing.UIDefaults) DarkLaf(com.github.weisj.darklaf.DarkLaf) IconLoader(com.github.weisj.darklaf.properties.icons.IconLoader) Test(org.junit.jupiter.api.Test)

Example 2 with IconLoader

use of com.github.weisj.darklaf.properties.icons.IconLoader 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)

Aggregations

IconLoader (com.github.weisj.darklaf.properties.icons.IconLoader)2 DarkLaf (com.github.weisj.darklaf.DarkLaf)1 LafManager (com.github.weisj.darklaf.LafManager)1 QuickColorChooser (com.github.weisj.darklaf.components.color.QuickColorChooser)1 LayoutHelper (com.github.weisj.darklaf.layout.LayoutHelper)1 UIAwareIcon (com.github.weisj.darklaf.properties.icons.UIAwareIcon)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 javax.swing (javax.swing)1 UIDefaults (javax.swing.UIDefaults)1 Test (org.junit.jupiter.api.Test)1