Browse Source

Everywhere: Move calls to internal API SwingUtilities2::drawStringUnderlineCharAt and SwingUtilities2::drawString into SwingUtil.

pull/245/head
weisj 4 years ago
parent
commit
a265ef96b9
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 6
      core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java
  2. 6
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java
  3. 4
      core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java
  4. 11
      core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java

6
core/src/main/java/com/github/weisj/darklaf/graphics/StringPainter.java

@ -32,8 +32,6 @@ import javax.swing.*;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.color.ColorUtil;
import com.github.weisj.darklaf.ui.OpacityBufferedUI;
import com.github.weisj.darklaf.util.*;
@ -162,9 +160,9 @@ public final class StringPainter {
} else {
int textY = textRect.y + asc;
if (mnemIndex >= 0) {
SwingUtilities2.drawStringUnderlineCharAt(c, drawingGraphics, text, mnemIndex, textRect.x, textY);
SwingUtil.drawStringUnderlineCharAt(c, drawingGraphics, text, mnemIndex, textRect.x, textY);
} else {
SwingUtilities2.drawString(c, drawingGraphics, text, textRect.x, textY);
SwingUtil.drawString(c, drawingGraphics, text, textRect.x, textY);
}
}

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

@ -143,12 +143,12 @@ public class DarkPreviewPanel extends JPanel {
Color color = getForeground();
g.setColor(color);
SwingUtilities2.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2), ascent);
SwingUtil.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2), ascent);
g.fillRect(textXOffset, (height) + TEXT_GAP, width + (TEXT_GAP), height + 2);
g.setColor(Color.black);
SwingUtilities2.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2),
SwingUtil.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2),
height + ascent + TEXT_GAP + 2);
g.setColor(Color.white);
@ -156,7 +156,7 @@ public class DarkPreviewPanel extends JPanel {
g.fillRect(textXOffset, (height + TEXT_GAP) * 2, width + (TEXT_GAP), height + 2);
g.setColor(color);
SwingUtilities2.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2),
SwingUtil.drawString(host, g, getSampleText(), textXOffset + (TEXT_GAP / 2),
((height + TEXT_GAP) * 2) + ascent + 2);
config.restore();

4
core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java

@ -29,12 +29,12 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicMenuItemUI;
import sun.swing.MenuItemLayoutHelper;
import sun.swing.SwingUtilities2;
import sun.swing.UIAction;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.StringUtil;
import com.github.weisj.darklaf.util.SwingUtil;
import com.github.weisj.darklaf.util.graphics.GraphicsContext;
import com.github.weisj.darklaf.util.graphics.GraphicsUtil;
@ -148,7 +148,7 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI {
if (!StringUtil.isBlank(lh.getAccText())) {
g.setFont(lh.getAccFontMetrics().getFont());
g.setColor(getAcceleratorForeground(mi));
SwingUtilities2.drawString(mi, g, lh.getAccText(), lr.getAccRect().x,
SwingUtil.drawString(mi, g, lh.getAccText(), lr.getAccRect().x,
lr.getAccRect().y + lh.getAccFontMetrics().getAscent());
}
config.restore();

11
core/src/main/java/com/github/weisj/darklaf/util/SwingUtil.java

@ -27,6 +27,8 @@ import java.awt.Graphics;
import javax.swing.JComponent;
import sun.swing.SwingUtilities2;
public final class SwingUtil {
private SwingUtil() {}
@ -44,4 +46,13 @@ public final class SwingUtil {
// mismatches when printing.
return c.getFontMetrics(font);
}
public static void drawStringUnderlineCharAt(JComponent c, Graphics g,
String text, int underlinedIndex, int x, int y) {
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, underlinedIndex, x, 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);
}
}

Loading…
Cancel
Save