Browse Source

Everywhere: Move calls to internal API SwingUtilities2::stringWidth into SwingUtil.

pull/245/head
weisj 4 years ago
parent
commit
75db998db6
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 6
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java
  2. 7
      core/src/main/java/com/github/weisj/darklaf/ui/internalframe/DarkInternalFrameTitlePane.java
  3. 2
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java
  4. 4
      core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java

6
core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java

@ -25,8 +25,6 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.util.SwingUtil; import com.github.weisj.darklaf.util.SwingUtil;
import com.github.weisj.darklaf.util.graphics.GraphicsContext; import com.github.weisj.darklaf.util.graphics.GraphicsContext;
import com.github.weisj.darklaf.util.graphics.GraphicsUtil; import com.github.weisj.darklaf.util.graphics.GraphicsUtil;
@ -69,7 +67,7 @@ public class DarkPreviewPanel extends JPanel {
FontMetrics fm = host.getFontMetrics(getFont()); FontMetrics fm = host.getFontMetrics(getFont());
int height = fm.getHeight(); 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 y = height * 3 + TEXT_GAP * 3;
int x = SQUARE_SIZE * 3 + SQUARE_GAP * 2 + SWATCH_WIDTH + width + 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 ascent = fm.getAscent();
int height = fm.getHeight(); int height = fm.getHeight();
int width = SwingUtilities2.stringWidth(host, fm, getSampleText()); int width = SwingUtil.stringWidth(host, fm, getSampleText());
int textXOffset = offsetX + TEXT_GAP; int textXOffset = offsetX + TEXT_GAP;
Color color = getForeground(); Color color = getForeground();

7
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.*;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.components.tooltip.ToolTipStyle; import com.github.weisj.darklaf.components.tooltip.ToolTipStyle;
import com.github.weisj.darklaf.components.uiresource.JButtonUIResource; import com.github.weisj.darklaf.components.uiresource.JButtonUIResource;
import com.github.weisj.darklaf.icons.ToggleIcon; import com.github.weisj.darklaf.icons.ToggleIcon;
import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.ui.button.DarkButtonUI;
import com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI; import com.github.weisj.darklaf.ui.tooltip.DarkToolTipUI;
import com.github.weisj.darklaf.util.SwingUtil;
/** @author Jannis Weis */ /** @author Jannis Weis */
public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane implements PropertyChangeListener { public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane implements PropertyChangeListener {
@ -338,12 +337,12 @@ public class DarkInternalFrameTitlePane extends BasicInternalFrameTitlePane impl
} }
String frameTitle = frame.getTitle(); 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; int titleLength = frameTitle != null ? frameTitle.length() : 0;
// Leave room for three characters in the title. // Leave room for three characters in the title.
if (titleLength > 3) { 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); width += Math.min(titleWidth, subtitle_w);
} else { } else {
width += titleWidth; width += titleWidth;

2
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 { } else {
// plain text // plain text
String title = tabPane.getTitleAt(tabIndex); String title = tabPane.getTitleAt(tabIndex);
width += SwingUtilities2.stringWidth(tabPane, metrics, title); width += SwingUtil.stringWidth(tabPane, metrics, title);
} }
} }
return width; return width;

4
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) { public static void drawString(final JComponent c, final Graphics g, final String text, int x, int y) {
SwingUtilities2.drawString(c, g, text, x, 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);
}
} }

Loading…
Cancel
Save