Browse Source

Added RadioButton and TristateCheckBox demos.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
5ce079f271
  1. 20
      src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java
  2. 39
      src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java
  3. 3
      src/test/java/demo/ComponentDemo.java
  4. 5
      src/test/java/demo/button/ButtonDemo.java
  5. 5
      src/test/java/demo/button/ToggleButtonDemo.java
  6. 5
      src/test/java/demo/checkBox/CheckBoxDemo.java
  7. 69
      src/test/java/demo/checkBox/TriCheckBoxDemo.java
  8. 69
      src/test/java/demo/radioButton/RadioButtonDemo.java

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

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

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

5
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";
}
}

5
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";
}
}

5
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";
}
}

69
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";
}
}

69
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";
}
}
Loading…
Cancel
Save