From 75db998db69e3fe69350cb35447300b53e5cd4d1 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Tue, 18 May 2021 18:01:56 +0200 Subject: [PATCH] Everywhere: Move calls to internal API SwingUtilities2::stringWidth into SwingUtil. --- .../weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java | 6 ++---- .../ui/internalframe/DarkInternalFrameTitlePane.java | 7 +++---- .../darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java | 2 +- .../main/java/com/github/weisj/darklaf/util/SwingUtil.java | 4 ++++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java index 2d0116b7..e8d7afa3 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java @@ -25,8 +25,6 @@ import java.awt.*; import javax.swing.*; -import sun.swing.SwingUtilities2; - import com.github.weisj.darklaf.util.SwingUtil; import com.github.weisj.darklaf.util.graphics.GraphicsContext; import com.github.weisj.darklaf.util.graphics.GraphicsUtil; @@ -69,7 +67,7 @@ public class DarkPreviewPanel extends JPanel { FontMetrics fm = host.getFontMetrics(getFont()); int height = fm.getHeight(); - int width = SwingUtilities2.stringWidth(host, fm, getSampleText()); + int width = SwingUtil.stringWidth(host, fm, getSampleText()); int y = height * 3 + TEXT_GAP * 3; int x = SQUARE_SIZE * 3 + SQUARE_GAP * 2 + SWATCH_WIDTH + width + TEXT_GAP * 3; @@ -138,7 +136,7 @@ public class DarkPreviewPanel extends JPanel { int ascent = fm.getAscent(); int height = fm.getHeight(); - int width = SwingUtilities2.stringWidth(host, fm, getSampleText()); + int width = SwingUtil.stringWidth(host, fm, getSampleText()); int textXOffset = offsetX + TEXT_GAP; Color color = getForeground(); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java b/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java index 1a9ce859..966df90e 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java @@ -30,13 +30,12 @@ import javax.accessibility.AccessibleContext; import javax.swing.*; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; -import sun.swing.SwingUtilities2; - import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; import com.github.weisj.darklaf.components.uiresource.JButtonUIResource; import com.github.weisj.darklaf.icons.ToggleIcon; import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI; +import com.github.weisj.darklaf.util.SwingUtil; /** @author Jannis Weis */ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane implements PropertyChangeListener { @@ -338,12 +337,12 @@ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane impl } String frameTitle = frame.getTitle(); - int titleWidth = frameTitle != null ? SwingUtilities2.stringWidth(frame, fm, frameTitle) : 0; + int titleWidth = frameTitle != null ? SwingUtil.stringWidth(frame, fm, frameTitle) : 0; int titleLength = frameTitle != null ? frameTitle.length() : 0; // Leave room for three characters in the title. if (titleLength > 3) { - int subtitle_w = SwingUtilities2.stringWidth(frame, fm, frameTitle.substring(0, 3) + "..."); + int subtitle_w = SwingUtil.stringWidth(frame, fm, frameTitle.substring(0, 3) + "..."); width += Math.min(titleWidth, subtitle_w); } else { width += titleWidth; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java index 06d809cf..e49a9020 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java @@ -1382,7 +1382,7 @@ public abstract class DarkTabbedPaneUIBridge extends TabbedPaneUI implements Swi } else { // plain text String title = tabPane.getTitleAt(tabIndex); - width += SwingUtilities2.stringWidth(tabPane, metrics, title); + width += SwingUtil.stringWidth(tabPane, metrics, title); } } return width; diff --git a/core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java b/core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java index b438171c..9e322cb7 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java @@ -55,4 +55,8 @@ public final class SwingUtil { public static void drawString(final JComponent c, final Graphics g, final String text, int x, int y) { SwingUtilities2.drawString(c, g, text, x, y); } + + public static int stringWidth(final JComponent c, final FontMetrics fm, final String string) { + return SwingUtilities2.stringWidth(c, fm, string); + } }