Browse Source

Added ComboBox demo.

Fixed layout issues when combo box has RtL layout.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
b3d56cfa4f
  1. 2
      src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java
  2. 24
      src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java
  3. 2
      src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java
  4. 4
      src/test/java/demo/button/ToggleButtonDemo.java
  5. 4
      src/test/java/demo/checkBox/CheckBoxDemo.java
  6. 6
      src/test/java/demo/checkBox/TriCheckBoxDemo.java
  7. 75
      src/test/java/demo/comboBox/ComboBoxDemo.java
  8. 6
      src/test/java/demo/radioButton/RadioButtonDemo.java

2
src/main/java/com/github/weisj/darklaf/ui/checkbox/DarkCheckBoxUI.java

@ -330,7 +330,7 @@ public class DarkCheckBoxUI extends MetalCheckBoxUI implements PropertyChangeLis
String key = evt.getPropertyName();
if ("componentOrientation".equals(key)) {
checkBox.repaint();
} else if ("JToggleButton.isTreeCellEditor".equals(key)) {
} else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) {
checkBox.repaint();
}
}

24
src/main/java/com/github/weisj/darklaf/ui/combobox/DarkComboBoxUI.java

@ -46,12 +46,14 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Area;
import java.awt.geom.RoundRectangle2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
/**
* @author Konstantin Bulenkov
* @author Jannis Weis
*/
public class DarkComboBoxUI extends BasicComboBoxUI implements Border {
public class DarkComboBoxUI extends BasicComboBoxUI implements Border, PropertyChangeListener {
private static final int BUTTON_PAD = 7;
@ -108,12 +110,14 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border {
protected void installListeners() {
super.installListeners();
comboBox.addMouseListener(mouseListener);
comboBox.addPropertyChangeListener(this);
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
comboBox.removeMouseListener(mouseListener);
comboBox.removePropertyChangeListener(this);
}
@Override
@ -254,7 +258,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border {
@Override
protected Rectangle rectangleForCurrentValue() {
Rectangle rect = super.rectangleForCurrentValue();
if (!comboBox.getComponentOrientation().isLeftToRight()) {
if (comboBox.isEditable() && !comboBox.getComponentOrientation().isLeftToRight()) {
rect.x += borderSize;
rect.width -= borderSize;
}
@ -392,7 +396,7 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border {
}
}
protected Paint getArrowBackground(final JComboBox c) {
protected Paint getArrowBackground(@NotNull final JComboBox<?> c) {
if (!c.isEnabled()) return inactiveBackground;
if (c.isEditable()) {
return new GradientPaint(0, borderSize, arrowBackgroundStart,
@ -421,4 +425,18 @@ public class DarkComboBoxUI extends BasicComboBoxUI implements Border {
public void resetPopup() {
((DarkComboPopup) popup).reset();
}
@Override
public void propertyChange(@NotNull final PropertyChangeEvent evt) {
String key = evt.getPropertyName();
if ("componentOrientation".equals(key)) {
comboBox.doLayout();
comboBox.repaint();
// editor.setComponentOrientation(comboBox.getComponentOrientation());
} else if ("editable".equals(key)) {
comboBox.repaint();
} else if ("JComboBox.isTableCellEditor".equals(key) || "JComboBox.isTreeCellEditor".equals(key)) {
comboBox.repaint();
}
}
}

2
src/main/java/com/github/weisj/darklaf/ui/radiobutton/DarkRadioButtonUI.java

@ -270,7 +270,7 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha
String key = evt.getPropertyName();
if ("componentOrientation".equals(key)) {
radioButton.repaint();
} else if ("JToggleButton.isTreeCellEditor".equals(key)) {
} else if ("JToggleButton.isTreeCellEditor".equals(key) || "JToggleButton.isTableCellEditor".equals(key)) {
radioButton.repaint();
}
}

4
src/test/java/demo/button/ToggleButtonDemo.java

@ -72,6 +72,10 @@ public class ToggleButtonDemo implements ComponentDemo {
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected()));
}});
controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected()));
}});
return panel;
}

4
src/test/java/demo/checkBox/CheckBoxDemo.java

@ -58,6 +58,10 @@ public class CheckBoxDemo implements ComponentDemo {
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected()));
}});
controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected()));
}});
return panel;
}

6
src/test/java/demo/checkBox/TriCheckBoxDemo.java

@ -41,7 +41,7 @@ public class TriCheckBoxDemo implements ComponentDemo {
TristateCheckBox button = new TristateCheckBox("Test TriCheckBox");
DemoPanel panel = new DemoPanel(button);
JPanel controlPanel = panel.getControls();
controlPanel.setLayout(new GridLayout(2, 2));
controlPanel.setLayout(new GridLayout(3, 2));
controlPanel.add(new JCheckBox("enabled") {{
setSelected(button.isEnabled());
addActionListener(e -> button.setEnabled(isSelected()));
@ -59,6 +59,10 @@ public class TriCheckBoxDemo implements ComponentDemo {
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected()));
}});
controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected()));
}});
return panel;
}

75
src/test/java/demo/comboBox/ComboBoxDemo.java

@ -0,0 +1,75 @@
/*
* 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.comboBox;
import demo.ComponentDemo;
import demo.DemoPanel;
import javax.swing.*;
import java.awt.*;
public class ComboBoxDemo implements ComponentDemo {
public static void main(final String[] args) {
ComponentDemo.showDemo(new ComboBoxDemo());
}
@Override
public JComponent createComponent() {
JComboBox<String> comboBox = new JComboBox<>();
for (int i = 1; i <= 5; i++) {
comboBox.addItem("Item " + i);
}
DemoPanel panel = new DemoPanel(comboBox);
JPanel controlPanel = panel.getControls();
controlPanel.setLayout(new GridLayout(3, 2));
controlPanel.add(new JCheckBox("enabled") {{
setSelected(comboBox.isEnabled());
addActionListener(e -> comboBox.setEnabled(isSelected()));
}});
controlPanel.add(new JCheckBox("editable") {{
setSelected(comboBox.isEditable());
addActionListener(e -> comboBox.setEditable(isSelected()));
}});
controlPanel.add(new JCheckBox("LeftToRight") {{
setSelected(comboBox.getComponentOrientation().isLeftToRight());
addActionListener(e -> comboBox.setComponentOrientation(isSelected() ? ComponentOrientation.LEFT_TO_RIGHT
: ComponentOrientation.RIGHT_TO_LEFT));
}});
controlPanel.add(new JCheckBox("JComboBox.isTreeCellEditor") {{
setSelected(false);
addActionListener(e -> comboBox.putClientProperty("JComboBox.isTreeCellEditor", isSelected()));
}});
controlPanel.add(new JCheckBox("JComboBox.isTableCellEditor") {{
setSelected(false);
addActionListener(e -> comboBox.putClientProperty("JComboBox.isTableCellEditor", isSelected()));
}});
return panel;
}
@Override
public String getTitle() {
return "ComboBox Demo";
}
}

6
src/test/java/demo/radioButton/RadioButtonDemo.java

@ -40,7 +40,7 @@ public class RadioButtonDemo implements ComponentDemo {
JRadioButton button = new JRadioButton("Test RadioButton");
DemoPanel panel = new DemoPanel(button);
JPanel controlPanel = panel.getControls();
controlPanel.setLayout(new GridLayout(2, 2));
controlPanel.setLayout(new GridLayout(3, 2));
controlPanel.add(new JCheckBox("enabled") {{
setSelected(button.isEnabled());
addActionListener(e -> button.setEnabled(isSelected()));
@ -58,6 +58,10 @@ public class RadioButtonDemo implements ComponentDemo {
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTreeCellEditor", isSelected()));
}});
controlPanel.add(new JCheckBox("JToggleButton.isTableCellEditor") {{
setSelected(false);
addActionListener(e -> button.putClientProperty("JToggleButton.isTableCellEditor", isSelected()));
}});
return panel;
}

Loading…
Cancel
Save