Search in sources :

Example 1 with QuickColorChooser

use of com.github.weisj.darklaf.components.color.QuickColorChooser in project darklaf by weisJ.

the class ForegroundGenerationDemo method createComponent.

@Override
public JComponent createComponent() {
    JPanel holder = new JPanel(new GridBagLayout());
    holder.setPreferredSize(new Dimension(300, 100));
    holder.setOpaque(true);
    JLabel label = new JLabel("Demo Readability Text");
    holder.add(label);
    DemoPanel panel = new DemoPanel(holder, new BorderLayout(), 0);
    JPanel controls = panel.addControls();
    Consumer<Color> updater = c -> SwingUtilities.invokeLater(() -> {
        holder.setBackground(c);
        label.setForeground(ForegroundColorGenerationTask.makeForeground(c));
        label.repaint();
    });
    Color current = UIManager.getColor("textCompSelectionBackground");
    updater.accept(current);
    QuickColorChooser quickColorChooser = new QuickColorChooser("Background", current, updater);
    controls.add(quickColorChooser);
    LafManager.addThemeChangeListener((ThemeInstalledListener) e -> {
        Color c = UIManager.getColor("textCompSelectionBackground");
        quickColorChooser.setColor(c);
        updater.accept(c);
    });
    return panel;
}
Also used : java.awt(java.awt) Consumer(java.util.function.Consumer) DemoExecutor(com.github.weisj.darklaf.ui.demo.DemoExecutor) BaseComponentDemo(com.github.weisj.darklaf.ui.demo.BaseComponentDemo) LafManager(com.github.weisj.darklaf.LafManager) ForegroundColorGenerationTask(com.github.weisj.darklaf.task.ForegroundColorGenerationTask) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) ThemeInstalledListener(com.github.weisj.darklaf.theme.event.ThemeInstalledListener) javax.swing(javax.swing) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser)

Example 2 with QuickColorChooser

use of com.github.weisj.darklaf.components.color.QuickColorChooser in project darklaf by weisJ.

the class IconEditorPanel method createValueEditor.

private JComponent createValueEditor(final String key, final Object value) {
    if (value instanceof Color) {
        Color color = (Color) value;
        JButton palette = createPaletteButton();
        AttachedPopupComponent.attachChooser(palette, () -> IconValues.getSwatchChooser(theme), c -> {
            if (c != null) {
                updateAction.get(key).accept(c);
                put(key, c);
            }
        }, () -> {
            Pair<Object, Color> entry = getEntry(key, Color.class);
            return new NamedColor(entry.getFirst().toString(), entry.getSecond());
        });
        if (pickerSize == null || spinnerInsets == null) {
            pickerSize = palette.getPreferredSize();
            JSpinner sp = new JSpinner(new SpinnerNumberModel(10, 0, 100, 1));
            spinnerInsets = sp.getBorder().getBorderInsets(sp);
            pickerSize.width = sp.getPreferredSize().width - spinnerInsets.left - spinnerInsets.right;
        }
        QuickColorChooser chooser = new QuickColorChooser(null, color, (b, c) -> put(key, c), false, pickerSize);
        chooser.setDragEnabled(true);
        DynamicUI.withLocalizedTooltip(chooser, "Labels.colorChooser");
        chooser.setBorder(LayoutHelper.createEmptyBorder(spinnerInsets));
        updateAction.put(key, o -> {
            if (o instanceof Color)
                chooser.setColor((Color) o, false);
        });
        return LayoutHelper.createHorizontalBox(GAP, chooser, palette);
    } else if (value instanceof Integer) {
        JButton palette = createPaletteButton();
        AttachedPopupComponent.attachChooser(palette, () -> IconValues.getOpacityChooser(theme), i -> {
            if (i != null) {
                updateAction.get(key).accept(i.getValue());
                put(key, i);
            }
        }, () -> {
            Pair<Object, Integer> entry = getEntry(key, Integer.class);
            return new NamedInt(entry.getFirst().toString(), entry.getSecond());
        });
        SpinnerNumberModel numberModel = new SpinnerNumberModel((int) value, 0, 100, 1);
        numberModel.addChangeListener(e -> put(key, numberModel.getValue()));
        updateAction.put(key, o -> {
            if (o instanceof Integer)
                numberModel.setValue(o);
        });
        return LayoutHelper.createHorizontalBox(GAP, new JSpinner(numberModel), palette);
    } else {
        return new JLabel(value.toString());
    }
}
Also used : Pair(com.github.weisj.darklaf.util.Pair) AttachedPopupComponent(com.github.weisj.darklaf.components.popup.AttachedPopupComponent) PropertyLoader(com.github.weisj.darklaf.properties.PropertyLoader) java.util(java.util) AllIcons(com.github.weisj.darklaf.iconset.AllIcons) ListChooser(com.github.weisj.darklaf.components.chooser.ListChooser) LafManager(com.github.weisj.darklaf.LafManager) DarkBorders(com.github.weisj.darklaf.components.border.DarkBorders) com.github.weisj.darklaf.properties.icons(com.github.weisj.darklaf.properties.icons) Collectors(java.util.stream.Collectors) Theme(com.github.weisj.darklaf.theme.Theme) SharedComponent(com.github.weisj.darklaf.components.popup.SharedComponent) java.awt(java.awt) Consumer(java.util.function.Consumer) LayoutHelper(com.github.weisj.darklaf.layout.LayoutHelper) List(java.util.List) SimpleListCellRenderer(com.github.weisj.darklaf.components.renderer.SimpleListCellRenderer) ComponentHelper(com.github.weisj.darklaf.components.ComponentHelper) DarkLaf(com.github.weisj.darklaf.DarkLaf) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) DarkUIUtil(com.github.weisj.darklaf.ui.util.DarkUIUtil) DynamicUI(com.github.weisj.darklaf.components.DynamicUI) javax.swing(javax.swing) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) Pair(com.github.weisj.darklaf.util.Pair)

Example 3 with QuickColorChooser

use of com.github.weisj.darklaf.components.color.QuickColorChooser 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 4 with QuickColorChooser

use of com.github.weisj.darklaf.components.color.QuickColorChooser in project darklaf by weisJ.

the class AbstractButtonDemo method init.

@Override
protected void init() {
    booleanSpec("enabled", JComponent::setEnabled, JComponent::isEnabled);
    booleanSpec("focusable", JComponent::setFocusable, JComponent::isFocusable);
    binaryOptionSpec("LeftToRight", JComponent::setComponentOrientation, JComponent::getComponentOrientation, ComponentOrientation.LEFT_TO_RIGHT, ComponentOrientation.RIGHT_TO_LEFT);
    booleanSpec("Rollover", AbstractButton::setRolloverEnabled, AbstractButton::isRolloverEnabled);
    booleanSpec("Content Area filled", AbstractButton::setContentAreaFilled, AbstractButton::isContentAreaFilled);
    booleanSpec("Border painted", AbstractButton::setBorderPainted, AbstractButton::isBorderPainted);
    booleanSpec("Focus painted", AbstractButton::setFocusPainted, AbstractButton::isFocusPainted);
    initBaseControls();
    spacer();
    booleanSpec(DarkButtonUI.KEY_SQUARE);
    booleanSpec(DarkButtonUI.KEY_ROUND);
    booleanSpec(DarkButtonUI.KEY_THIN);
    booleanSpec(DarkButtonUI.KEY_ALT_ARC);
    booleanSpec("Button.defaultButtonFollowsFocus", (c, b) -> UIManager.put("Button.defaultButtonFollowsFocus", b), c -> UIManager.getBoolean("Button.defaultButtonFollowsFocus"));
    spacer();
    customControls(cp -> {
        cp.add(new QuickColorChooser(DarkButtonUI.KEY_HOVER_COLOR, Color.BLACK, (b, c) -> getButton().putClientProperty(DarkButtonUI.KEY_HOVER_COLOR, b ? c : null)));
        cp.add(new QuickColorChooser(DarkButtonUI.KEY_CLICK_COLOR, Color.BLACK, (b, c) -> getButton().putClientProperty(DarkButtonUI.KEY_CLICK_COLOR, b ? c : null)));
    });
    spacer();
    binaryOptionSpec("Text enabled", AbstractButton::setText, AbstractButton::getText, "Test Button", null);
    binaryOptionSpec("Icon enabled", AbstractButton::setIcon, AbstractButton::getIcon, ((AbstractButton) getComponent()).getIcon(), null);
    spec(DarkButtonUI.KEY_VARIANT, DarkButtonUI.VARIANT_NONE, DarkButtonUI.VARIANT_BORDERLESS, DarkButtonUI.VARIANT_BORDERLESS_RECTANGULAR);
    enumSpecWithNone(DarkButtonUI.KEY_CORNER, AlignmentExt.class);
}
Also used : java.awt(java.awt) BaseComponentDemo(com.github.weisj.darklaf.ui.demo.BaseComponentDemo) AlignmentExt(com.github.weisj.darklaf.util.AlignmentExt) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser) javax.swing(javax.swing) QuickColorChooser(com.github.weisj.darklaf.components.color.QuickColorChooser)

Aggregations

QuickColorChooser (com.github.weisj.darklaf.components.color.QuickColorChooser)4 java.awt (java.awt)4 javax.swing (javax.swing)4 LafManager (com.github.weisj.darklaf.LafManager)3 BaseComponentDemo (com.github.weisj.darklaf.ui.demo.BaseComponentDemo)3 LayoutHelper (com.github.weisj.darklaf.layout.LayoutHelper)2 Theme (com.github.weisj.darklaf.theme.Theme)2 ThemeInstalledListener (com.github.weisj.darklaf.theme.event.ThemeInstalledListener)2 DemoExecutor (com.github.weisj.darklaf.ui.demo.DemoExecutor)2 DarkUIUtil (com.github.weisj.darklaf.ui.util.DarkUIUtil)2 Consumer (java.util.function.Consumer)2 DarkLaf (com.github.weisj.darklaf.DarkLaf)1 ComponentHelper (com.github.weisj.darklaf.components.ComponentHelper)1 DynamicUI (com.github.weisj.darklaf.components.DynamicUI)1 DarkBorders (com.github.weisj.darklaf.components.border.DarkBorders)1 ListChooser (com.github.weisj.darklaf.components.chooser.ListChooser)1 AttachedPopupComponent (com.github.weisj.darklaf.components.popup.AttachedPopupComponent)1 SharedComponent (com.github.weisj.darklaf.components.popup.SharedComponent)1 SimpleListCellRenderer (com.github.weisj.darklaf.components.renderer.SimpleListCellRenderer)1 AllIcons (com.github.weisj.darklaf.iconset.AllIcons)1