From ea22785147e7bd2191d55c2f22c312f1b8d13fe6 Mon Sep 17 00:00:00 2001 From: weisj Date: Wed, 17 Jun 2020 23:37:12 +0200 Subject: [PATCH] Localisation for JTabFrame close button. Removed automatic html conversion for tooltips. Set clip when painting text. --- .../java/com/github/weisj/darklaf/graphics/PaintUtil.java | 1 + .../weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java | 4 +++- .../github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java | 7 +------ .../weisj/darklaf/properties/ui/tabFrame.properties | 2 +- core/src/test/java/ui/toolTip/ToolTipDemo.java | 3 ++- .../java/com/github/weisj/darklaf/util/StringUtil.java | 8 ++++++++ 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java b/core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java index 3cc0f737..2fdb4b25 100644 --- a/core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java @@ -343,6 +343,7 @@ public class PaintUtil { drawingGraphics.fillRect(0, 0, img.getWidth(), img.getHeight()); drawingGraphics.setColor(g.getColor()); textRect.setLocation(0, 0); + drawingGraphics.setClip(0, 0, img.getWidth(), img.getHeight()); drawingGraphics.scale(scaleX, scaleY); } else { drawingGraphics.clipRect(textRect.x, textRect.y, textRect.width, textRect.height); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java index 15d53030..b23292b3 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkPanelPopupUI.java @@ -45,6 +45,7 @@ import com.github.weisj.darklaf.ui.panel.DarkPanelUI; import com.github.weisj.darklaf.ui.tooltip.ToolTipConstants; import com.github.weisj.darklaf.util.Alignment; import com.github.weisj.darklaf.util.DarkUIUtil; +import com.github.weisj.darklaf.util.ResourceUtil; public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListener, AWTEventListener, TabFramePopupUI { @@ -135,7 +136,8 @@ public class DarkPanelPopupUI extends DarkPanelUI implements PropertyChangeListe HeaderButton closeButton = new HeaderButton(UIManager.getIcon("TabFramePopup.close.icon"), this); closeButton.setBorder(new EmptyBorder(4, 4, 4, 4)); closeButton.addActionListener(e -> popupComponent.close()); - String tooltip = UIManager.getString("TabFramePopup.closeTooltipText"); + String tooltip = ResourceUtil.getResourceBundle("actions", popupComponent).getString("Actions.close"); + tooltip = tooltip + " (" + UIManager.getString("TabFramePopup.closeTooltipTextHint") + ")"; closeButton.setToolTipText(tooltip); return closeButton; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java index 7ee331c7..1bb9932f 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkToolTipUI.java @@ -349,12 +349,7 @@ public class DarkToolTipUI extends BasicToolTipUI implements PropertyChangeListe } protected void updateTipText(final JToolTip tooltip) { - String tipText = tooltip.getTipText(); - if (tipText != null && !tipText.startsWith("") && tipText.contains("\n")) { - effectiveTipText = "" + tipText.replaceAll("\n", "<\\br>") + ""; - } else { - effectiveTipText = tipText; - } + effectiveTipText = tooltip.getTipText(); if (effectiveTipText == null) effectiveTipText = ""; } diff --git a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabFrame.properties b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabFrame.properties index 60c21fed..350aa335 100644 --- a/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabFrame.properties +++ b/core/src/main/resources/com/github/weisj/darklaf/properties/ui/tabFrame.properties @@ -42,7 +42,7 @@ TabFramePopup.headerButtonFocusHoverBackground = %hoverHighlightColorful TabFramePopup.headerButtonFocusClickBackground = %clickHighlightColorful TabFramePopup.closeAccelerator = shift pressed ESCAPE -TabFramePopup.closeTooltipText = Close (shift ESC) +TabFramePopup.closeTooltipTextHint = shift ESC TabFramePopup.headerButton.tooltipInsets = 5,5,5,5 TabFramePopup.headerButton.insets = 1,1,1,1 diff --git a/core/src/test/java/ui/toolTip/ToolTipDemo.java b/core/src/test/java/ui/toolTip/ToolTipDemo.java index 9a1e3395..be996b87 100644 --- a/core/src/test/java/ui/toolTip/ToolTipDemo.java +++ b/core/src/test/java/ui/toolTip/ToolTipDemo.java @@ -35,6 +35,7 @@ import com.github.weisj.darklaf.components.tooltip.ToolTipContext; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; import com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI; import com.github.weisj.darklaf.util.Alignment; +import com.github.weisj.darklaf.util.StringUtil; public class ToolTipDemo implements ComponentDemo { @@ -49,7 +50,7 @@ public class ToolTipDemo implements ComponentDemo { ToolTipContext context = new ToolTipContext(button).setAlignment(Alignment.CENTER) .setCenterAlignment(Alignment.SOUTH); ToolTipContext.setDefaultContext(context); - button.setToolTipText("This is the ToolTip demo text!"); + button.setToolTipText(StringUtil.toHtml(StringUtil.repeat("This is the ToolTip demo text!\n", 3))); button.putClientProperty(DarkToolTipUI.KEY_STYLE, DarkToolTipUI.VARIANT_BALLOON); JPanel controlPanel = panel.addControls(3); diff --git a/utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java b/utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java index e757a508..1db8805b 100644 --- a/utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/StringUtil.java @@ -36,6 +36,14 @@ public final class StringUtil { private StringUtil() {} + public static String toHtml(final String text) { + if (text == null) return ""; + if (!text.startsWith("") && text.contains("\n")) { + return "" + text.replaceAll("\n", "<\\br>") + ""; + } + return text; + } + public static String toUpperCase(final String a) { return a == null ? null : toUpperCase((CharSequence) a).toString(); }