diff --git a/src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java b/src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java index a46f528b..56b1cad5 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java @@ -83,10 +83,21 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis return new DarkCheckBoxUI(); } + @Override + public void installUI(final JComponent c) { + checkBox = (JCheckBox) c; + super.installUI(c); + } + + @Override + public void uninstallUI(final JComponent c) { + super.uninstallUI(c); + checkBox = null; + } + @Override public void installDefaults(final AbstractButton b) { super.installDefaults(b); - checkBox = (JCheckBox) b; LookAndFeel.installProperty(b, "opaque", false); checkBoxIcon = UIManager.getIcon("CheckBox.unchecked.icon"); checkBoxDisabledIcon = UIManager.getIcon("CheckBox.uncheckedDisabled.icon"); @@ -315,8 +326,11 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis } @Override - public void propertyChange(final PropertyChangeEvent evt) { - if ("componentOrientation".equals(evt.getPropertyName())) { + public void propertyChange(@NotNull final PropertyChangeEvent evt) { + String key = evt.getPropertyName(); + if ("componentOrientation".equals(key)) { + checkBox.repaint(); + } else if ("JToggleButton.isTreeCellEditor".equals(key)) { checkBox.repaint(); } } diff --git a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java index 3a6638ae..d485f9f7 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java +++ b/src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java @@ -38,12 +38,14 @@ import javax.swing.plaf.IconUIResource; import javax.swing.plaf.metal.MetalRadioButtonUI; import java.awt.*; import java.awt.geom.Ellipse2D; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; /** * @author Konstantin Bulenkov * @author Jannis Weis */ -public class DarkRadioButtonUI extends MetalRadioButtonUI { +public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyChangeListener { private static final int ICON_OFF = 4; private static final int SIZE = 13; @@ -53,6 +55,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI { private static final Rectangle textRect = new Rectangle(); private static Dimension size = new Dimension(); private final Ellipse2D hitArea = new Ellipse2D.Float(); + protected JRadioButton radioButton; protected Color background; protected Color inactiveBackground; protected Color focusBorderColor; @@ -77,6 +80,18 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI { return new DarkRadioButtonUI(); } + @Override + public void installUI(final JComponent c) { + radioButton = (JRadioButton) c; + super.installUI(c); + } + + @Override + public void uninstallUI(final JComponent c) { + super.uninstallUI(c); + radioButton = null; + } + @Override public void installDefaults(final AbstractButton b) { super.installDefaults(b); @@ -130,6 +145,18 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI { } } + @Override + protected void installListeners(final AbstractButton button) { + super.installListeners(button); + button.addPropertyChangeListener(this); + } + + @Override + protected void uninstallListeners(final AbstractButton button) { + super.uninstallListeners(button); + button.removePropertyChangeListener(this); + } + protected String layoutRadioButton(@NotNull final AbstractButton b, final FontMetrics fm) { Insets i = b.getInsets(); size = b.getSize(size); @@ -237,4 +264,14 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI { } return hitArea.contains(x, y); } + + @Override + public void propertyChange(@NotNull final PropertyChangeEvent evt) { + String key = evt.getPropertyName(); + if ("componentOrientation".equals(key)) { + radioButton.repaint(); + } else if ("JToggleButton.isTreeCellEditor".equals(key)) { + radioButton.repaint(); + } + } } diff --git a/src/test/java/demo/ComponentDemo.java b/src/test/java/demo/ComponentDemo.java index 42ce074f..be169913 100644 --- a/src/test/java/demo/ComponentDemo.java +++ b/src/test/java/demo/ComponentDemo.java @@ -35,9 +35,12 @@ public interface ComponentDemo { SwingUtilities.invokeLater(() -> { LafManager.install(); JFrame frame = DemoPanel.createFrame(); + frame.setTitle(demo.getTitle()); frame.setContentPane(demo.createComponent()); frame.pack(); frame.setVisible(true); }); } + + String getTitle(); } diff --git a/src/test/java/demo/button/ButtonDemo.java b/src/test/java/demo/button/ButtonDemo.java index 1fce8dd5..bc7dc524 100644 --- a/src/test/java/demo/button/ButtonDemo.java +++ b/src/test/java/demo/button/ButtonDemo.java @@ -99,4 +99,9 @@ public class ButtonDemo implements ComponentDemo { return panel; } + @Override + public String getTitle() { + return "Button Demo"; + } + } diff --git a/src/test/java/demo/button/ToggleButtonDemo.java b/src/test/java/demo/button/ToggleButtonDemo.java index 9960d50b..9c1304db 100644 --- a/src/test/java/demo/button/ToggleButtonDemo.java +++ b/src/test/java/demo/button/ToggleButtonDemo.java @@ -74,4 +74,9 @@ public class ToggleButtonDemo implements ComponentDemo { }}); return panel; } + + @Override + public String getTitle() { + return "ToggleButton Demo"; + } } diff --git a/src/test/java/demo/checkBox/CheckBoxDemo.java b/src/test/java/demo/checkBox/CheckBoxDemo.java index f101047b..443a03e9 100644 --- a/src/test/java/demo/checkBox/CheckBoxDemo.java +++ b/src/test/java/demo/checkBox/CheckBoxDemo.java @@ -61,4 +61,9 @@ public class CheckBoxDemo implements ComponentDemo { return panel; } + @Override + public String getTitle() { + return "CheckBox Demo"; + } + } diff --git a/src/test/java/demo/checkBox/TriCheckBoxDemo.java b/src/test/java/demo/checkBox/TriCheckBoxDemo.java new file mode 100644 index 00000000..750a8c52 --- /dev/null +++ b/src/test/java/demo/checkBox/TriCheckBoxDemo.java @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (c) 2020 Jannis Weis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package demo.checkBox; + +import com.github.weisj.darklaf.components.tristate.TristateCheckBox; +import demo.ComponentDemo; +import demo.DemoPanel; + +import javax.swing.*; +import java.awt.*; + +public class TriCheckBoxDemo implements ComponentDemo { + + public static void main(final String[] args) { + ComponentDemo.showDemo(new TriCheckBoxDemo()); + } + + @Override + public JComponent createComponent() { + TristateCheckBox button = new TristateCheckBox("Test TriCheckBox"); + DemoPanel panel = new DemoPanel(button); + JPanel controlPanel = panel.getControls(); + controlPanel.setLayout(new GridLayout(2, 2)); + controlPanel.add(new JCheckBox("enabled") {{ + setSelected(button.isEnabled()); + addActionListener(e -> button.setEnabled(isSelected())); + }}); + controlPanel.add(new JCheckBox("LeftToRight") {{ + setSelected(button.getComponentOrientation().isLeftToRight()); + addActionListener(e -> button.setComponentOrientation(isSelected() ? ComponentOrientation.LEFT_TO_RIGHT + : ComponentOrientation.RIGHT_TO_LEFT)); + }}); + controlPanel.add(new JCheckBox("Rollover") {{ + setSelected(button.isRolloverEnabled()); + addActionListener(e -> button.setRolloverEnabled(isSelected())); + }}); + controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + setSelected(false); + addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + }}); + return panel; + } + + @Override + public String getTitle() { + return "TriCheckBox Demo"; + } +} diff --git a/src/test/java/demo/radioButton/RadioButtonDemo.java b/src/test/java/demo/radioButton/RadioButtonDemo.java new file mode 100644 index 00000000..5a56a472 --- /dev/null +++ b/src/test/java/demo/radioButton/RadioButtonDemo.java @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (c) 2020 Jannis Weis + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package demo.radioButton; + +import demo.ComponentDemo; +import demo.DemoPanel; + +import javax.swing.*; +import java.awt.*; + +public class RadioButtonDemo implements ComponentDemo { + + public static void main(final String[] args) { + ComponentDemo.showDemo(new RadioButtonDemo()); + } + + @Override + public JComponent createComponent() { + JRadioButton button = new JRadioButton("Test RadioButton"); + DemoPanel panel = new DemoPanel(button); + JPanel controlPanel = panel.getControls(); + controlPanel.setLayout(new GridLayout(2, 2)); + controlPanel.add(new JCheckBox("enabled") {{ + setSelected(button.isEnabled()); + addActionListener(e -> button.setEnabled(isSelected())); + }}); + controlPanel.add(new JCheckBox("LeftToRight") {{ + setSelected(button.getComponentOrientation().isLeftToRight()); + addActionListener(e -> button.setComponentOrientation(isSelected() ? ComponentOrientation.LEFT_TO_RIGHT + : ComponentOrientation.RIGHT_TO_LEFT)); + }}); + controlPanel.add(new JCheckBox("Rollover") {{ + setSelected(button.isRolloverEnabled()); + addActionListener(e -> button.setRolloverEnabled(isSelected())); + }}); + controlPanel.add(new JCheckBox("JToggleButton.isTreeCellEditor") {{ + setSelected(false); + addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected())); + }}); + return panel; + } + + @Override + public String getTitle() { + return "RadioButton Demo"; + } + +}