diff --git a/core/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java b/core/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java index f3bd2af1..53952a60 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/ArrowButton.java @@ -27,7 +27,7 @@ import javax.swing.*; import javax.swing.plaf.DimensionUIResource; import javax.swing.plaf.basic.BasicArrowButton; -import com.github.weisj.darklaf.ui.button.DarkButtonUI; +import com.github.weisj.darklaf.ui.button.ButtonConstants; /** @author Jannis Weis */ public final class ArrowButton implements SwingConstants { @@ -59,7 +59,7 @@ public final class ArrowButton implements SwingConstants { return new BasicArrowButton(orientation, null, null, null, null) { private final Insets ins = insets != null ? insets : new Insets(0, 0, 0, 0); { - putClientProperty(DarkButtonUI.KEY_NO_BORDERLESS_OVERWRITE, true); + putClientProperty(ButtonConstants.KEY_NO_BORDERLESS_OVERWRITE, true); setMargin(new Insets(0, 0, 0, 0)); setBorder(BorderFactory.createEmptyBorder()); } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBackedRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBackedRenderer.java new file mode 100644 index 00000000..b4b9f98b --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBackedRenderer.java @@ -0,0 +1,29 @@ +/* + * 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 com.github.weisj.darklaf.ui.cell; + +import javax.swing.*; + +public interface ComponentBackedRenderer { + + JComponent getRendererComponent(); +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTableCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTableCellRenderer.java new file mode 100644 index 00000000..1c36d2f1 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTableCellRenderer.java @@ -0,0 +1,28 @@ +/* + * 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 com.github.weisj.darklaf.ui.cell; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; + +public interface ComponentBasedTableCellRenderer extends TableCellRenderer, ComponentBackedRenderer { +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTreeCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTreeCellRenderer.java new file mode 100644 index 00000000..999e6afd --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/ComponentBasedTreeCellRenderer.java @@ -0,0 +1,27 @@ +/* + * 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 com.github.weisj.darklaf.ui.cell; + +import javax.swing.tree.TreeCellRenderer; + +public interface ComponentBasedTreeCellRenderer extends TreeCellRenderer, ComponentBackedRenderer { +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkBooleanCellRenderer.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkBooleanCellRenderer.java new file mode 100644 index 00000000..c7e29271 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkBooleanCellRenderer.java @@ -0,0 +1,79 @@ +/* + * 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 com.github.weisj.darklaf.ui.cell; + +import java.awt.*; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import javax.swing.tree.TreeCellRenderer; + +import com.github.weisj.darklaf.ui.table.TableConstants; +import com.github.weisj.darklaf.ui.tree.DarkTreeUI; +import com.github.weisj.darklaf.util.PropertyUtil; + +public class DarkBooleanCellRenderer implements TableCellRenderer, TreeCellRenderer { + + private final DarkCellRendererCheckBox checkBoxRenderer; + private final DarkCellRendererRadioButton radioRenderer; + + public DarkBooleanCellRenderer(final boolean opaque) { + checkBoxRenderer = new DarkCellRendererCheckBox(opaque); + radioRenderer = new DarkCellRendererRadioButton(opaque); + } + + @Override + public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, + final boolean hasFocus, final int row, final int column) { + return getBooleanRenderer(table).getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + + @Override + public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selected, + final boolean expanded, + final boolean leaf, final int row, final boolean hasFocus) { + return getBooleanRenderer(tree).getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, + hasFocus); + } + + protected ComponentBasedTableCellRenderer getBooleanRenderer(final JTable table) { + return getRenderer(PropertyUtil.isPropertyEqual(table, + TableConstants.KEY_BOOLEAN_RENDER_TYPE, CellConstants.RENDER_TYPE_RADIOBUTTON)); + } + + protected ComponentBasedTreeCellRenderer getBooleanRenderer(final JTree tree) { + return getRenderer(PropertyUtil.isPropertyEqual(tree, + DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE, CellConstants.RENDER_TYPE_RADIOBUTTON)); + } + + private DarkCellRendererToggleButton getRenderer(final boolean useRadioButton) { + return useRadioButton ? radioRenderer : checkBoxRenderer; + } + + public JComponent getRendererComponent(final JTree tree) { + return getBooleanRenderer(tree).getRendererComponent(); + } + + public JComponent getRendererComponent(final JTable table) { + return getBooleanRenderer(table).getRendererComponent(); + } +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java index 248ccc67..e3dcd46c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/DarkCellRendererToggleButton.java @@ -25,8 +25,6 @@ import java.awt.*; import javax.swing.*; import javax.swing.border.Border; -import javax.swing.table.TableCellRenderer; -import javax.swing.tree.TreeCellRenderer; import com.github.weisj.darklaf.components.tree.LabeledTreeNode; import com.github.weisj.darklaf.components.tristate.TristateCheckBox; @@ -36,7 +34,7 @@ import com.github.weisj.darklaf.util.DarkUIUtil; /** @author Jannis Weis */ public class DarkCellRendererToggleButton - implements TableCellRenderer, TreeCellRenderer, SwingConstants { + implements ComponentBasedTreeCellRenderer, ComponentBasedTableCellRenderer, SwingConstants { private final T toggleButton; private final Icon checkIcon; @@ -111,6 +109,11 @@ public class DarkCellRendererToggleButton getBooleanRenderer(final JTree tree) { - if (PropertyUtil.isPropertyEqual(tree, DarkTreeUI.KEY_BOOLEAN_RENDER_TYPE, - DarkTreeUI.RENDER_TYPE_RADIOBUTTON)) { - return radioRenderer; - } - return checkBoxRenderer; + protected DarkBooleanCellRenderer getBooleanRenderer() { + return booleanRenderer; } - protected DarkCellRendererToggleButton getTristateRenderer(final JTree tree) { + protected ComponentBasedTreeCellRenderer getTristateRenderer() { return tristateRenderer; }