diff --git a/src/main/java/com/weis/darklaf/components/tooltip/DarkToolTip.java b/src/main/java/com/weis/darklaf/components/tooltip/DarkToolTip.java index 8c3ed6e2..65c149ee 100644 --- a/src/main/java/com/weis/darklaf/components/tooltip/DarkToolTip.java +++ b/src/main/java/com/weis/darklaf/components/tooltip/DarkToolTip.java @@ -67,13 +67,6 @@ public class DarkToolTip extends JToolTip implements PropertyChangeListener { }); } - @Override - public void setComponent(final JComponent c) { - super.setComponent(c); - setTipText(getTipText()); - setPreferredSize(getUI().getPreferredSize(this)); - } - public void setAlignment(final Alignment alignment) { putClientProperty("JToolTip.pointerLocation", alignment); } diff --git a/src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java b/src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java index b017af7d..7bea748c 100644 --- a/src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java +++ b/src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java @@ -429,7 +429,6 @@ public class ToolTipContext implements ToolTipListener { if (valid && !updatePosition && lastPos != null && !Objects.equals(rect, lastRect)) { - System.out.println("here"); return lastPos; } getToolTip().setTipText(c.getToolTipText(event)); diff --git a/src/main/java/com/weis/darklaf/ui/tooltip/DarkDefaultToolTipBorder.java b/src/main/java/com/weis/darklaf/ui/tooltip/DarkDefaultToolTipBorder.java new file mode 100644 index 00000000..69a4a11f --- /dev/null +++ b/src/main/java/com/weis/darklaf/ui/tooltip/DarkDefaultToolTipBorder.java @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2019 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.weis.darklaf.ui.tooltip; + +import com.weis.darklaf.components.border.MutableLineBorder; + +import javax.swing.*; +import javax.swing.plaf.UIResource; + +public class DarkDefaultToolTipBorder extends MutableLineBorder implements UIResource { + + public DarkDefaultToolTipBorder() { + super(1, 1, 1, 1, null); + setColor(UIManager.getColor("ToolTip.borderColor")); + } +} diff --git a/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java b/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java index ca35b19e..77ede4df 100644 --- a/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java +++ b/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; -import javax.swing.plaf.UIResource; import java.awt.*; import java.awt.geom.Area; import java.awt.geom.Rectangle2D; @@ -17,7 +16,7 @@ import java.awt.geom.Rectangle2D; /** * @author Jannis Weis */ -public class DarkTooltipBorder implements Border, UIResource { +public class DarkTooltipBorder implements Border { private final DropShadowBorder shadowBorder = new DropShadowBorder(Color.BLACK, 10, 0.2f, 10, @@ -55,7 +54,6 @@ public class DarkTooltipBorder implements Border, UIResource { return; } if (c instanceof JToolTip && ((JToolTip) c).getTipText() == null) return; - System.out.println(bubbleBorder.getPointerSide()); var ins = shadowBorder.getBorderInsets(c); adjustInsets(ins); var bubbleArea = bubbleBorder.getInnerArea(x + ins.left, y + ins.top, diff --git a/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipUI.java b/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipUI.java index 0b0c476a..f17f0201 100644 --- a/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipUI.java +++ b/src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipUI.java @@ -97,6 +97,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe public void installUI(final JComponent c) { toolTip = (JToolTip) c; super.installUI(c); + toolTip.setBorder(new DarkTooltipBorder()); } @Override @@ -189,6 +190,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } } + @Override public void propertyChange(@NotNull final PropertyChangeEvent evt) { var key = evt.getPropertyName(); @@ -203,19 +205,19 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } else { border.setPointerLocation(Alignment.CENTER); } - tooltip.setComponent(tooltip.getComponent()); + updateSize(); } else if ("JToolTip.pointerHeight".equals(key)) { if (newVal instanceof Integer) { border.setPointerHeight((Integer) newVal); } - tooltip.setComponent(tooltip.getComponent()); + updateSize(); } else if ("JToolTip.pointerWidth".equals(key)) { if (newVal instanceof Integer) { border.setPointerWidth((Integer) newVal); } - tooltip.setComponent(tooltip.getComponent()); + updateSize(); } else if ("JToolTip.insets".equals(key)) { - tooltip.setComponent(tooltip.getComponent()); + updateSize(); } else if ("component".equals(key)) { var oldComp = evt.getOldValue(); if (oldComp instanceof Component) { @@ -230,4 +232,8 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe } } + protected void updateSize() { + toolTip.setTipText(toolTip.getTipText()); + toolTip.setPreferredSize(getPreferredSize(toolTip)); + } } diff --git a/src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties b/src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties index 89a82d90..4292c7eb 100644 --- a/src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties +++ b/src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties @@ -24,5 +24,5 @@ ToolTipUI = com.weis.darklaf.ui.tooltip.DarkTooltipUI ToolTip.background = %backgroundToolTip ToolTip.borderColor = %borderTertiary -ToolTip.border = com.weis.darklaf.ui.tooltip.DarkTooltipBorder +ToolTip.border = com.weis.darklaf.ui.tooltip.DarkDefaultToolTipBorder ToolTip.borderShadowColor = %shadow \ No newline at end of file diff --git a/src/test/java/GenerateColors.java b/src/test/java/GenerateColors.java index 3e6b3792..3e6a266a 100644 --- a/src/test/java/GenerateColors.java +++ b/src/test/java/GenerateColors.java @@ -10,19 +10,24 @@ public final class GenerateColors { public static void main(final String[] args) { int cols = 30; int rows = 15; - System.out.println("{"); + StringBuilder builder = new StringBuilder("{"); int r; int g; int b; for (int i = 1; i < rows + 1; i++) { r = g = b = (int) ((i - 1) * 255.0 / (rows - 1)); - System.out.println(r + "," + g + "," + b + ","); + builder.append(r).append(",") + .append(g).append(",") + .append(b).append(","); for (int j = 0; j < cols - 1; j++) { var c = colorFromPos(j, i, rows + 1, cols); - System.out.println(c.getRed() + "," + c.getGreen() + "," + c.getBlue() + ","); + builder.append(c.getRed()).append(",") + .append(c.getGreen()).append(",") + .append(c.getBlue()).append(","); } } - System.out.println("};"); + builder.append("};"); + System.out.println(builder); } private static Color colorFromPos(final int x, final int y, final int height, final int width) {