Browse Source

Fixed incorrect pointer side if multiple tooltips are present.

pull/15/head
weisj 5 years ago
parent
commit
0715841389
  1. 7
      src/main/java/com/weis/darklaf/components/tooltip/DarkToolTip.java
  2. 1
      src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java
  3. 37
      src/main/java/com/weis/darklaf/ui/tooltip/DarkDefaultToolTipBorder.java
  4. 4
      src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java
  5. 14
      src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipUI.java
  6. 2
      src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties
  7. 13
      src/test/java/GenerateColors.java

7
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) { public void setAlignment(final Alignment alignment) {
putClientProperty("JToolTip.pointerLocation", alignment); putClientProperty("JToolTip.pointerLocation", alignment);
} }

1
src/main/java/com/weis/darklaf/components/tooltip/ToolTipContext.java

@ -429,7 +429,6 @@ public class ToolTipContext implements ToolTipListener {
if (valid && !updatePosition if (valid && !updatePosition
&& lastPos != null && lastPos != null
&& !Objects.equals(rect, lastRect)) { && !Objects.equals(rect, lastRect)) {
System.out.println("here");
return lastPos; return lastPos;
} }
getToolTip().setTipText(c.getToolTipText(event)); getToolTip().setTipText(c.getToolTipText(event));

37
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"));
}
}

4
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.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import java.awt.*; import java.awt.*;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
@ -17,7 +16,7 @@ import java.awt.geom.Rectangle2D;
/** /**
* @author Jannis Weis * @author Jannis Weis
*/ */
public class DarkTooltipBorder implements Border, UIResource { public class DarkTooltipBorder implements Border {
private final DropShadowBorder shadowBorder = new DropShadowBorder(Color.BLACK, private final DropShadowBorder shadowBorder = new DropShadowBorder(Color.BLACK,
10, 0.2f, 10, 10, 0.2f, 10,
@ -55,7 +54,6 @@ public class DarkTooltipBorder implements Border, UIResource {
return; return;
} }
if (c instanceof JToolTip && ((JToolTip) c).getTipText() == null) return; if (c instanceof JToolTip && ((JToolTip) c).getTipText() == null) return;
System.out.println(bubbleBorder.getPointerSide());
var ins = shadowBorder.getBorderInsets(c); var ins = shadowBorder.getBorderInsets(c);
adjustInsets(ins); adjustInsets(ins);
var bubbleArea = bubbleBorder.getInnerArea(x + ins.left, y + ins.top, var bubbleArea = bubbleBorder.getInnerArea(x + ins.left, y + ins.top,

14
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) { public void installUI(final JComponent c) {
toolTip = (JToolTip) c; toolTip = (JToolTip) c;
super.installUI(c); super.installUI(c);
toolTip.setBorder(new DarkTooltipBorder());
} }
@Override @Override
@ -189,6 +190,7 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
} }
} }
@Override @Override
public void propertyChange(@NotNull final PropertyChangeEvent evt) { public void propertyChange(@NotNull final PropertyChangeEvent evt) {
var key = evt.getPropertyName(); var key = evt.getPropertyName();
@ -203,19 +205,19 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
} else { } else {
border.setPointerLocation(Alignment.CENTER); border.setPointerLocation(Alignment.CENTER);
} }
tooltip.setComponent(tooltip.getComponent()); updateSize();
} else if ("JToolTip.pointerHeight".equals(key)) { } else if ("JToolTip.pointerHeight".equals(key)) {
if (newVal instanceof Integer) { if (newVal instanceof Integer) {
border.setPointerHeight((Integer) newVal); border.setPointerHeight((Integer) newVal);
} }
tooltip.setComponent(tooltip.getComponent()); updateSize();
} else if ("JToolTip.pointerWidth".equals(key)) { } else if ("JToolTip.pointerWidth".equals(key)) {
if (newVal instanceof Integer) { if (newVal instanceof Integer) {
border.setPointerWidth((Integer) newVal); border.setPointerWidth((Integer) newVal);
} }
tooltip.setComponent(tooltip.getComponent()); updateSize();
} else if ("JToolTip.insets".equals(key)) { } else if ("JToolTip.insets".equals(key)) {
tooltip.setComponent(tooltip.getComponent()); updateSize();
} else if ("component".equals(key)) { } else if ("component".equals(key)) {
var oldComp = evt.getOldValue(); var oldComp = evt.getOldValue();
if (oldComp instanceof Component) { 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));
}
} }

2
src/main/resources/com/weis/darklaf/properties/ui/toolTip.properties

@ -24,5 +24,5 @@
ToolTipUI = com.weis.darklaf.ui.tooltip.DarkTooltipUI ToolTipUI = com.weis.darklaf.ui.tooltip.DarkTooltipUI
ToolTip.background = %backgroundToolTip ToolTip.background = %backgroundToolTip
ToolTip.borderColor = %borderTertiary ToolTip.borderColor = %borderTertiary
ToolTip.border = com.weis.darklaf.ui.tooltip.DarkTooltipBorder ToolTip.border = com.weis.darklaf.ui.tooltip.DarkDefaultToolTipBorder
ToolTip.borderShadowColor = %shadow ToolTip.borderShadowColor = %shadow

13
src/test/java/GenerateColors.java

@ -10,19 +10,24 @@ public final class GenerateColors {
public static void main(final String[] args) { public static void main(final String[] args) {
int cols = 30; int cols = 30;
int rows = 15; int rows = 15;
System.out.println("{"); StringBuilder builder = new StringBuilder("{");
int r; int r;
int g; int g;
int b; int b;
for (int i = 1; i < rows + 1; i++) { for (int i = 1; i < rows + 1; i++) {
r = g = b = (int) ((i - 1) * 255.0 / (rows - 1)); 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++) { for (int j = 0; j < cols - 1; j++) {
var c = colorFromPos(j, i, rows + 1, cols); 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) { private static Color colorFromPos(final int x, final int y, final int height, final int width) {

Loading…
Cancel
Save