mirror of https://github.com/weisJ/darklaf.git
Browse Source
Fixed text staying bold when the button is no longer a default button. Fixed text being approximately the same as the background while it is a default button and is a shadow variant. Fixed button not updating when properties change. Changed the thin property to be boolean based. Signed-off-by: weisj <weisj@arcor.de>pull/27/head
weisj
5 years ago
11 changed files with 375 additions and 28 deletions
@ -0,0 +1,106 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import com.github.weisj.darklaf.LafManager; |
||||
import com.github.weisj.darklaf.icons.IconLoader; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class ButtonDemo implements ComponentDemo { |
||||
|
||||
public static void main(final String[] args) { |
||||
SwingUtilities.invokeLater(() -> { |
||||
LafManager.install(); |
||||
JFrame frame = DemoPanel.createFrame(); |
||||
frame.setContentPane(new ButtonDemo().createComponent()); |
||||
frame.pack(); |
||||
frame.setVisible(true); |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public JComponent createComponent() { |
||||
Icon icon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); |
||||
JButton button = new JButton("Test Button", icon); |
||||
DemoPanel panel = new DemoPanel(button); |
||||
JPanel controlPanel = panel.getControls(); |
||||
controlPanel.setLayout(new GridLayout(5, 2)); |
||||
controlPanel.add(new JCheckBox("enabled") {{ |
||||
setSelected(button.isEnabled()); |
||||
addActionListener(e -> button.setEnabled(isSelected())); |
||||
}}); |
||||
controlPanel.add(new JCheckBox("default") {{ |
||||
setSelected(button.isDefaultButton()); |
||||
addActionListener(e -> SwingUtilities.getRootPane(button).setDefaultButton(isSelected() ? button |
||||
: null)); |
||||
}}); |
||||
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("JButton.square") {{ |
||||
setSelected(false); |
||||
addActionListener(e -> button.putClientProperty("JButton.square", isSelected())); |
||||
}}); |
||||
controlPanel.add(new JCheckBox("JButton.thin") {{ |
||||
setSelected(false); |
||||
addActionListener(e -> button.putClientProperty("JButton.thin", isSelected())); |
||||
}}); |
||||
controlPanel.add(new JCheckBox("JButton.alternativeArc") {{ |
||||
setSelected(false); |
||||
addActionListener(e -> button.putClientProperty("JButton.alternativeArc", isSelected())); |
||||
}}); |
||||
controlPanel.add(new JComboBox<String>() {{ |
||||
addItem("JButton.variant = onlyLabel"); |
||||
addItem("JButton.variant = shadow"); |
||||
addItem("JButton.variant = fullShadow"); |
||||
addItem("no JButton.variant"); |
||||
setSelectedItem("no JButton.variant"); |
||||
addItemListener(e -> { |
||||
if (e.getItem().equals("JButton.variant = onlyLabel")) { |
||||
button.putClientProperty("JButton.variant", "onlyLabel"); |
||||
} else if (e.getItem().equals("JButton.variant = shadow")) { |
||||
button.putClientProperty("JButton.variant", "shadow"); |
||||
} else if (e.getItem().equals("JButton.variant = fullShadow")) { |
||||
button.putClientProperty("JButton.variant", "fullShadow"); |
||||
} else { |
||||
button.putClientProperty("JButton.variant", null); |
||||
} |
||||
}); |
||||
}}); |
||||
controlPanel.add(new QuickColorChooser("JButton.shadow.hover", Color.BLACK, |
||||
(b, c) -> button.putClientProperty("JButton.shadow.hover", b ? c : null))); |
||||
controlPanel.add(new QuickColorChooser("JButton.shadow.click", Color.BLACK, |
||||
(b, c) -> button.putClientProperty("JButton.shadow.click", b ? c : null))); |
||||
return panel; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
public interface ComponentDemo { |
||||
|
||||
JComponent createComponent(); |
||||
} |
@ -0,0 +1,56 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import com.github.weisj.darklaf.components.border.DarkBorders; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
public class DemoPanel extends JPanel { |
||||
|
||||
private final JPanel controls; |
||||
|
||||
public DemoPanel(final JComponent component) { |
||||
super(new BorderLayout()); |
||||
JPanel content = new JPanel(new GridBagLayout()); |
||||
content.add(component, null); |
||||
add(content, BorderLayout.CENTER); |
||||
controls = new JPanel(); |
||||
controls.setBorder(DarkBorders.createLineBorder(1, 0, 0, 0)); |
||||
controls.setLayout(new BoxLayout(controls, BoxLayout.X_AXIS)); |
||||
add(controls, BorderLayout.SOUTH); |
||||
} |
||||
|
||||
public static JFrame createFrame() { |
||||
JFrame frame = new JFrame(); |
||||
frame.setLocationRelativeTo(null); |
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
||||
return frame; |
||||
} |
||||
|
||||
public JPanel getControls() { |
||||
return controls; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import com.github.weisj.darklaf.decorators.MouseClickListener; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.util.function.BiConsumer; |
||||
|
||||
public class QuickColorChooser extends JPanel { |
||||
|
||||
private final SolidColorIcon icon; |
||||
private final JCheckBox checkBox; |
||||
|
||||
public QuickColorChooser(final String title, final Color color, final BiConsumer<Boolean, Color> onStatusChange) { |
||||
super(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
||||
icon = new SolidColorIcon(color); |
||||
JLabel label = new JLabel(title, icon, JLabel.LEFT); |
||||
checkBox = new JCheckBox(); |
||||
checkBox.addActionListener(e -> onStatusChange.accept(isSelected(), getColor())); |
||||
label.addMouseListener((MouseClickListener) e -> { |
||||
Color c = JColorChooser.showDialog(QuickColorChooser.this, title, icon.getColor()); |
||||
onStatusChange.accept(isSelected(), c); |
||||
icon.setColor(c); |
||||
}); |
||||
add(checkBox); |
||||
add(label); |
||||
} |
||||
|
||||
public boolean isSelected() { |
||||
return checkBox.isSelected(); |
||||
} |
||||
|
||||
public Color getColor() { |
||||
return icon.getColor(); |
||||
} |
||||
} |
@ -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; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
final class SolidColorIcon implements Icon { |
||||
private final int width; |
||||
private final int height; |
||||
private Color color; |
||||
|
||||
SolidColorIcon(final Color color) { |
||||
this(color, 16, 16); |
||||
} |
||||
|
||||
private SolidColorIcon(final Color color, final int width, final int height) { |
||||
this.color = color; |
||||
this.width = width; |
||||
this.height = height; |
||||
} |
||||
|
||||
@Override |
||||
public void paintIcon(final Component c, @NotNull final Graphics g, final int x, final int y) { |
||||
g.setColor(color); |
||||
g.fillRect(x, y, getIconWidth(), getIconHeight()); |
||||
} |
||||
|
||||
@Override |
||||
public int getIconWidth() { |
||||
return width; |
||||
} |
||||
|
||||
@Override |
||||
public int getIconHeight() { |
||||
return height; |
||||
} |
||||
|
||||
public Color getColor() { |
||||
return color; |
||||
} |
||||
|
||||
public void setColor(final Color c) { |
||||
this.color = c; |
||||
} |
||||
} |
Loading…
Reference in new issue