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;
}
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());
}
}
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;
}
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);
}
Aggregations