Browse Source

Moved string painting to utility method.

Refactored more clientproperty checking.
pull/154/head
weisj 5 years ago
parent
commit
cc32dda879
  1. 28
      core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/ui/button/ButtonConstants.java
  3. 7
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java
  4. 29
      core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java
  5. 1
      core/src/main/java/com/github/weisj/darklaf/ui/colorchooser/DarkPreviewPanel.java
  6. 21
      core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java
  7. 7
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarListener.java
  8. 4
      core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollBarConstants.java
  9. 4
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java
  10. 20
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java
  11. 6
      core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java
  12. 21
      core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java
  13. 13
      core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java
  14. 20
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java
  15. 3
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  16. 4
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java
  17. 21
      core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java
  18. 5
      core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java
  19. 9
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java
  20. 4
      core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java
  21. 2
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java
  22. 2
      property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java
  23. 67
      utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

28
core/src/main/java/com/github/weisj/darklaf/graphics/PaintUtil.java

@ -29,6 +29,11 @@ import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.*;
import javax.swing.text.View;
import com.github.weisj.darklaf.ui.html.DarkHTML;
public class PaintUtil {
public static final Color TRANSPARENT_COLOR = new Color(0x0, true);
@ -230,6 +235,29 @@ public class PaintUtil {
g.fillRect(x, y + height - thickness, width, thickness);
}
public static void drawString(final Graphics g, final JComponent c,
final String text, final Rectangle textRect,
final FontMetrics fm,
final PaintMethod paintMethod) {
GraphicsContext context = GraphicsUtil.setupAntialiasing(g);
g.setClip(textRect);
if (text != null && !text.equals("")) {
View v = (View) c.getClientProperty(DarkHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
textRect.y += fm.getAscent();
paintMethod.paintText(g, c, textRect, text);
}
}
context.restore();
}
public interface PaintMethod {
void paintText(final Graphics g, final JComponent c, final Rectangle rect, final String text);
}
public enum Outline {
error {
@Override

8
core/src/main/java/com/github/weisj/darklaf/ui/button/ButtonConstants.java

@ -74,8 +74,7 @@ public interface ButtonConstants {
static boolean isBorderlessVariant(final Component c) {
if (isBorderlessRectangular(c)) return true;
if (c instanceof JButton) {
JButton b = (JButton) c;
return PropertyUtil.isPropertyEqual(b, KEY_VARIANT, VARIANT_BORDERLESS)
return PropertyUtil.isPropertyEqual(c, KEY_VARIANT, VARIANT_BORDERLESS)
|| doConvertToBorderless((AbstractButton) c);
}
return false;
@ -104,9 +103,6 @@ public interface ButtonConstants {
}
static JComponent getNeighbour(final String key, final Component comp) {
if (!(comp instanceof JComponent)) return null;
Object obj = ((JComponent) comp).getClientProperty(key);
if (obj instanceof JComponent) return (JComponent) obj;
return null;
return PropertyUtil.getObject(comp, key, JComponent.class);
}
}

7
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonBorder.java

@ -37,6 +37,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.AlignmentExt;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Konstantin Bulenkov
@ -121,11 +122,7 @@ public class DarkButtonBorder implements Border, UIResource {
}
public static AlignmentExt getCornerFlag(final Component component) {
if (component instanceof JComponent) {
Object align = ((JComponent) component).getClientProperty(DarkButtonUI.KEY_CORNER);
return align instanceof AlignmentExt ? (AlignmentExt) align : null;
}
return null;
return PropertyUtil.getObject(component, DarkButtonUI.KEY_CORNER, AlignmentExt.class, null);
}
protected int getShadowSize(final JComponent c) {

29
core/src/main/java/com/github/weisj/darklaf/ui/button/DarkButtonUI.java

@ -35,8 +35,6 @@ import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicButtonListener;
import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
@ -46,7 +44,10 @@ import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonKeyHandler;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonFocusNavigationActions;
import com.github.weisj.darklaf.util.*;
import com.github.weisj.darklaf.util.AlignmentExt;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Konstantin Bulenkov
@ -265,29 +266,19 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
AbstractButton button = (AbstractButton) c;
ButtonModel model = button.getModel();
g.setColor(getForeground(button));
FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g);
int mnemonicIndex = button.getDisplayedMnemonicIndex();
if (!model.isEnabled()) {
mnemonicIndex = -1;
}
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex,
textRect.x + getTextShiftOffset(),
textRect.y + metrics.getAscent() + getTextShiftOffset());
textRect.y + getTextShiftOffset());
config.restore();
}
protected void paintText(final Graphics g, final AbstractButton b, final JComponent c, final String text) {
GraphicsContext context = GraphicsUtil.setupAntialiasing(g);
g.setClip(textRect);
if (text != null && !text.equals("")) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
paintText(g, b, textRect, text);
}
}
context.restore();
PaintUtil.drawString(g, b, text, textRect, SwingUtilities2.getFontMetrics(b, g),
(g1, c1, r1, t1) -> paintText(g1, b, r1, t1));
}
protected void paintIcon(final Graphics g, final AbstractButton b, final JComponent c) {
@ -360,11 +351,9 @@ public class DarkButtonUI extends BasicButtonUI implements ButtonConstants {
}
protected Color getBorderlessBackground(final AbstractButton c) {
Object colorHover = c.getClientProperty(KEY_HOVER_COLOR);
Object colorClick = c.getClientProperty(KEY_CLICK_COLOR);
boolean armed = c.getModel().isArmed();
return armed ? colorClick instanceof Color ? (Color) colorClick : borderlessClick
: colorHover instanceof Color ? (Color) colorHover : borderlessHover;
return armed ? PropertyUtil.getColor(c, KEY_CLICK_COLOR, borderlessClick)
: PropertyUtil.getColor(c, KEY_HOVER_COLOR, borderlessHover);
}
protected Color getBorderlessOutline(final AbstractButton c) {

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

@ -72,7 +72,6 @@ public class DarkPreviewPanel extends JPanel {
}
FontMetrics fm = host.getFontMetrics(getFont());
int ascent = fm.getAscent();
int height = fm.getHeight();
int width = SwingUtilities2.stringWidth(host, fm, getSampleText());

21
core/src/main/java/com/github/weisj/darklaf/ui/label/DarkLabelUI.java

@ -30,14 +30,13 @@ import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.plaf.basic.BasicLabelUI;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
@ -101,21 +100,13 @@ public class DarkLabelUI extends BasicLabelUI implements PropertyChangeListener
icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
}
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, paintTextR);
PaintUtil.drawString(g, c, clippedText, paintTextR, fm, (g2, c2, rect, t) -> {
if (label.isEnabled()) {
paintEnabledText(label, g2, t, rect.x, rect.y);
} else {
int textX = paintTextR.x;
int textY = paintTextR.y + fm.getAscent();
if (label.isEnabled()) {
paintEnabledText(label, g, clippedText, textX, textY);
} else {
paintDisabledText(label, g, clippedText, textX, textY);
}
paintDisabledText(label, g2, t, rect.x, rect.y);
}
}
});
config.restore();
}

7
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/DarkScrollBarListener.java

@ -30,6 +30,7 @@ import java.awt.event.*;
import javax.swing.*;
import com.github.weisj.darklaf.graphics.Animator;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkScrollBarListener extends MouseAdapter implements AdjustmentListener, ScrollBarConstants {
@ -88,12 +89,12 @@ public class DarkScrollBarListener extends MouseAdapter implements AdjustmentLis
if (scrollbar.getOrientation() == JScrollBar.VERTICAL && !e.isShiftDown()
|| scrollbar.getOrientation() == JScrollBar.HORIZONTAL && e.isShiftDown()) {
scrollbar.setValueIsAdjusting(true);
Object sp = scrollbar.getClientProperty(KEY_SCROLL_PANE_PARENT);
JScrollPane sp = PropertyUtil.getObject(scrollbar, KEY_SCROLL_PANE_PARENT, JScrollPane.class);
if (scrollbar.getParent() instanceof JScrollPane) {
ScrollBarUtil.doScroll(scrollbar, ((JScrollPane) scrollbar.getParent()).getViewport(), e,
scrollbar.getParent().getComponentOrientation().isLeftToRight());
} else if (sp instanceof JScrollPane) {
ScrollBarUtil.doScroll(scrollbar, ((JScrollPane) sp).getViewport(), e,
} else if (sp != null) {
ScrollBarUtil.doScroll(scrollbar, sp.getViewport(), e,
scrollbar.getParent().getComponentOrientation().isLeftToRight());
} else {
ScrollBarUtil.doScroll(scrollbar, null, e, scrollbar.getComponentOrientation().isLeftToRight());

4
core/src/main/java/com/github/weisj/darklaf/ui/scrollpane/ScrollBarConstants.java

@ -26,12 +26,14 @@ package com.github.weisj.darklaf.ui.scrollpane;
import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyUtil;
public interface ScrollBarConstants {
String KEY_SCROLL_PANE_PARENT = "JScrollBar.scrollPaneParent";
String KEY_FAST_WHEEL_SCROLLING = "JScrollBar.fastWheelScrolling";
String KEY_SMALL = "JComponent.small";
static boolean isSmall(final JScrollBar scrollBar) {
return scrollBar.getClientProperty(KEY_SMALL) == Boolean.TRUE;
return PropertyUtil.getBooleanProperty(scrollBar, KEY_SMALL);
}
}

4
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

@ -640,9 +640,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
}
protected boolean isPlainThumb() {
Boolean paintThumbArrowShape = (Boolean) slider.getClientProperty(KEY_THUMB_ARROW_SHAPE);
return (!slider.getPaintTicks() && paintThumbArrowShape == null) ||
paintThumbArrowShape == Boolean.FALSE;
return !slider.getPaintTicks() || !PropertyUtil.getBooleanProperty(slider, KEY_THUMB_ARROW_SHAPE, true);
}
private void paintSliderThumb(final Graphics2D g) {

20
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUI.java

@ -131,8 +131,7 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
}
protected Action getNewTabAction() {
Object action = tabPane.getClientProperty(KEY_NEW_TAB_ACTION);
return action instanceof Action ? (Action) action : null;
return PropertyUtil.getObject(tabPane, KEY_NEW_TAB_ACTION, Action.class);
}
@Override
@ -724,14 +723,9 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
moreTabsIcon = UIManager.getIcon("TabbedPane.moreTabs.icon");
newTabIcon = UIManager.getIcon("TabbedPane.newTab.icon");
Object ins = tabPane.getClientProperty(KEY_TAB_AREA_INSETS);
if (ins instanceof Insets) {
tabAreaInsets = (Insets) ins;
}
ins = tabPane.getClientProperty(KEY_CONTENT_BORDER_INSETS);
if (ins instanceof Insets) {
contentBorderInsets = (Insets) ins;
}
tabAreaInsets = PropertyUtil.getObject(tabPane, KEY_TAB_AREA_INSETS, Insets.class, tabAreaInsets);
contentBorderInsets = PropertyUtil.getObject(tabPane, KEY_CONTENT_BORDER_INSETS, Insets.class,
contentBorderInsets);
installComponent(KEY_LEADING_COMP, c -> leadingComp = c);
installComponent(KEY_TRAILING_COMP, c -> trailingComp = c);
installComponent(KEY_NORTH_COMP, c -> northComp = c);
@ -742,9 +736,9 @@ public class DarkTabbedPaneUI extends DarkTabbedPaneUIBridge {
}
protected void installComponent(final String key, final Consumer<Component> setter) {
Object comp = tabPane.getClientProperty(key);
if (comp instanceof Component) {
Component wrapped = wrapClientComponent((Component) comp);
Component comp = PropertyUtil.getObject(tabPane, key, Component.class);
if (comp != null) {
Component wrapped = wrapClientComponent(comp);
setter.accept(wrapped);
tabPane.add(wrapped);
}

6
core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/TabbedPaneHandler.java

@ -39,6 +39,7 @@ import javax.swing.text.View;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
public class TabbedPaneHandler implements ChangeListener, ContainerListener, FocusListener,
MouseListener, MouseMotionListener, PropertyChangeListener {
@ -261,9 +262,8 @@ public class TabbedPaneHandler implements ChangeListener, ContainerListener, Foc
// currently no IndexPropertyChangeEvent. Once
// IndexPropertyChangeEvents have been added this code should be
// modified to use it.
Integer indexObj = (Integer) tp.getClientProperty("__index_to_remove__");
if (indexObj != null) {
int index = indexObj;
int index = PropertyUtil.getInteger(tp, "__index_to_remove__", -1);
if (index >= 0) {
if (ui.htmlViews != null && ui.htmlViews.size() > index) {
ui.htmlViews.removeElementAt(index);
}

21
core/src/main/java/com/github/weisj/darklaf/ui/tabframe/DarkTabFrameTabLabelUI.java

@ -35,14 +35,13 @@ import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.components.tabframe.JTabFrame;
import com.github.weisj.darklaf.components.tabframe.TabFrameTab;
import com.github.weisj.darklaf.components.tabframe.TabFrameTabLabel;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.RotatableIcon;
import com.github.weisj.darklaf.listener.HoverListener;
import com.github.weisj.darklaf.ui.label.DarkLabelUI;
@ -98,21 +97,13 @@ public class DarkTabFrameTabLabelUI extends DarkLabelUI implements PropertyChang
icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
}
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, paintTextR);
PaintUtil.drawString(g, c, clippedText, paintTextR, fm, (g2, c2, rect, t) -> {
if (label.isEnabled()) {
paintEnabledText(label, g2, t, rect.x, rect.y);
} else {
int textX = paintTextR.x;
int textY = paintTextR.y + fm.getAscent();
if (label.isEnabled()) {
paintEnabledText(label, g, clippedText, textX, textY);
} else {
paintDisabledText(label, g, clippedText, textX, textY);
}
paintDisabledText(label, g2, t, rect.x, rect.y);
}
}
});
}
@Override

13
core/src/main/java/com/github/weisj/darklaf/ui/table/DarkTableUI.java

@ -44,6 +44,7 @@ import com.github.weisj.darklaf.components.OverlayScrollPane;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Jannis Weis
@ -485,17 +486,13 @@ public class DarkTableUI extends DarkTableUIBridge implements FocusListener {
}
protected JFileChooser getFileChooser() {
Object obj = table.getClientProperty(DarkTableUI.KEY_FILE_CHOOSER_PARENT);
if (obj instanceof Supplier<?>) {
Object supplied = ((Supplier<?>) obj).get();
return supplied instanceof JFileChooser ? (JFileChooser) supplied : null;
}
return null;
Object obj = PropertyUtil.getObject(table, DarkTableUI.KEY_FILE_CHOOSER_PARENT, Supplier.class, Object::new)
.get();
return obj instanceof JFileChooser ? (JFileChooser) obj : null;
}
protected Integer getFileNameColumnIndex() {
Object obj = table.getClientProperty(DarkTableUI.KEY_FILENAME_COLUMN_INDEX);
return obj instanceof Integer ? (Integer) obj : 0;
return PropertyUtil.getInteger(table, DarkTableUI.KEY_FILENAME_COLUMN_INDEX);
}
protected void startEditing(final int row, final int column) {

20
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkEditorPaneUI.java

@ -36,6 +36,7 @@ import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Jannis Weis
@ -79,16 +80,8 @@ public class DarkEditorPaneUI extends DarkTextUI {
void updateDisplayProperties(final Font font, final Color fg) {
JComponent c = getComponent();
Object honorDisplayPropertiesObject = c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
boolean honorDisplayProperties = false;
Object w3cLengthUnitsObject = c.getClientProperty(JEditorPane.W3C_LENGTH_UNITS);
boolean w3cLengthUnits = false;
if (honorDisplayPropertiesObject instanceof Boolean) {
honorDisplayProperties = (Boolean) honorDisplayPropertiesObject;
}
if (w3cLengthUnitsObject instanceof Boolean) {
w3cLengthUnits = (Boolean) w3cLengthUnitsObject;
}
boolean honorDisplayProperties = PropertyUtil.getBooleanProperty(c, JEditorPane.HONOR_DISPLAY_PROPERTIES);
boolean w3cLengthUnits = PropertyUtil.getBooleanProperty(c, JEditorPane.W3C_LENGTH_UNITS);
if (this instanceof DarkTextPaneUI || honorDisplayProperties) {
// using equals because can not use UIResource for Boolean
Document doc = getComponent().getDocument();
@ -318,12 +311,7 @@ public class DarkEditorPaneUI extends DarkTextUI {
modelChanged();
}
if (PropertyKey.FOREGROUND.equals(name)) {
Object honorDisplayPropertiesObject = c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
boolean honorDisplayProperties = false;
if (honorDisplayPropertiesObject instanceof Boolean) {
honorDisplayProperties = (Boolean) honorDisplayPropertiesObject;
}
if (honorDisplayProperties) {
if (PropertyUtil.getBooleanProperty(c, JEditorPane.HONOR_DISPLAY_PROPERTIES)) {
modelChanged();
}
}

3
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -147,8 +147,7 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
}
private static JPopupMenu getSearchPopup(final JComponent c) {
Object value = c.getClientProperty(KEY_FIND_POPUP);
return value instanceof JPopupMenu ? (JPopupMenu) value : null;
return PropertyUtil.getObject(c, KEY_FIND_POPUP, JPopupMenu.class);
}
protected Point getSearchIconCoord() {

4
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -50,6 +50,7 @@ import com.github.weisj.darklaf.ui.table.DarkTableCellBorder;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.tree.DarkTreeUI;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Jannis Weis
@ -257,8 +258,7 @@ public abstract class DarkTextUI extends BasicTextUI implements PropertyChangeLi
}
protected String getDefaultText() {
Object defaultText = editor.getClientProperty(KEY_DEFAULT_TEXT);
return defaultText instanceof String ? (String) defaultText : "";
return PropertyUtil.getString(editor, KEY_DEFAULT_TEXT, "");
}
protected boolean isEmpty() {

21
core/src/main/java/com/github/weisj/darklaf/ui/togglebutton/radiobutton/DarkRadioButtonUI.java

@ -34,14 +34,13 @@ import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonListener;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.plaf.metal.MetalRadioButtonUI;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonKeyHandler;
import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI;
import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants;
@ -165,19 +164,15 @@ public class DarkRadioButtonUI extends MetalRadioButtonUI implements PropertyCha
public static void paintText(final Graphics2D g, final AbstractButton b,
final Rectangle textRect, final String text, final FontMetrics fm,
final Color disabledTextColor) {
GraphicsContext context = GraphicsUtil.setupAntialiasing(g);
g.setFont(b.getFont());
View view = (View) b.getClientProperty(BasicHTML.propertyKey);
if (view != null) {
view.paint(g, textRect);
} else {
g.setColor(b.isEnabled() ? b.getForeground() : disabledTextColor);
SwingUtilities2.drawStringUnderlineCharAt(b, g, text,
g.setColor(b.isEnabled() ? b.getForeground() : disabledTextColor);
PaintUtil.drawString(g, b, text, textRect, fm, (g2, c2, rect, t) -> {
int textX = rect.x;
int textY = rect.y;
SwingUtilities2.drawStringUnderlineCharAt(b, g2, t,
b.getDisplayedMnemonicIndex(),
textRect.x,
textRect.y + fm.getAscent());
}
context.restore();
textX, textY);
});
}
protected Icon getStateIcon(final AbstractButton b) {

5
core/src/main/java/com/github/weisj/darklaf/ui/toolbar/DarkToolBarUIBridge.java

@ -47,6 +47,7 @@ import sun.swing.UIAction;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* A Basic L&amp;F implementation of ToolBarUI. This implementation is a "combined" view/controller.
@ -177,9 +178,7 @@ public abstract class DarkToolBarUIBridge extends ToolBarUI implements SwingCons
setOrientation(toolBar.getOrientation());
LookAndFeel.installProperty(c, PropertyKey.OPAQUE, Boolean.TRUE);
if (c.getClientProperty(FOCUSED_COMP_INDEX) != null) {
focusedCompIndex = (Integer) (c.getClientProperty(FOCUSED_COMP_INDEX));
}
focusedCompIndex = PropertyUtil.getInteger(c, FOCUSED_COMP_INDEX, focusedCompIndex);
}
public void uninstallUI(final JComponent c) {

9
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipBorder.java

@ -37,6 +37,7 @@ import com.github.weisj.darklaf.components.tooltip.ToolTipStyle;
import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.PropertyUtil;
/**
* @author Jannis Weis
@ -159,13 +160,7 @@ public class DarkTooltipBorder implements Border {
}
protected Insets getUserInsets(final Component c) {
if (c instanceof JComponent) {
Object obj = ((JComponent) c).getClientProperty(DarkTooltipUI.KEY_INSETS);
if (obj instanceof Insets) {
return (Insets) obj;
}
}
return margin;
return PropertyUtil.getObject(c, DarkTooltipUI.KEY_INSETS, Insets.class, margin);
}
@Override

4
core/src/main/java/com/github/weisj/darklaf/ui/tooltip/DarkTooltipUI.java

@ -125,8 +125,8 @@ public class DarkTooltipUI extends BasicToolTipUI implements PropertyChangeListe
fadeAnimator = new FadeInAnimator();
c.setOpaque(false);
DarkTooltipBorder border = new DarkTooltipBorder();
Alignment align = (Alignment) c.getClientProperty(KEY_POINTER_LOCATION);
border.setPointerLocation(align == null ? Alignment.CENTER : align);
Alignment align = PropertyUtil.getObject(c, KEY_POINTER_LOCATION, Alignment.class, Alignment.CENTER);
border.setPointerLocation(align);
toolTip.setBorder(border);
updateStyle();
}

2
core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeUI.java

@ -586,7 +586,7 @@ public class DarkTreeUI extends BasicTreeUI implements PropertyChangeListener {
}
protected String getLineStyle() {
return String.valueOf(tree.getClientProperty(KEY_LINE_STYLE));
return PropertyUtil.getString(tree, KEY_LINE_STYLE, "");
}
protected boolean selectedChildOf(final TreePath path) {

2
property-loader/src/main/java/com/github/weisj/darklaf/PropertyLoader.java

@ -149,7 +149,7 @@ public final class PropertyLoader {
final Predicate<Map.Entry<Object, T>> predicate,
final Function<Map.Entry<Object, T>, T> mapper) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (type == Object.class || type.isAssignableFrom(entry.getValue().getClass())) {
if (type == Object.class || type.isInstance(entry.getValue())) {
if (predicate.test((Map.Entry<Object, T>) entry)) {
T newValue = mapper.apply((Map.Entry<Object, T>) entry);
if (newValue != null) {

67
utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

@ -62,4 +62,71 @@ public class PropertyUtil {
Object obj = c.getClientProperty(property);
return Objects.equals(checkValue, obj);
}
public static <T> T getObject(final Component c, final String key, final Class<T> type, final T defaultValue) {
if (!(c instanceof JComponent)) return defaultValue;
return getObject((JComponent) c, key, type, defaultValue);
}
public static <T> T getObject(final JComponent c, final String key, final Class<T> type, final T defaultValue) {
Object obj = c.getClientProperty(key);
if (type.isInstance(obj)) return (T) obj;
return defaultValue;
}
public static Color getColor(final JComponent c, final String key, final Color defaultValue) {
return getObject(c, key, Color.class, defaultValue);
}
public static Color getColor(final Component c, final String key, final Color defaultValue) {
return getObject(c, key, Color.class, defaultValue);
}
public static String getString(final JComponent c, final String key, final String defaultValue) {
return getObject(c, key, String.class, defaultValue);
}
public static String getString(final Component c, final String key, final String defaultValue) {
return getObject(c, key, String.class, defaultValue);
}
public static <T> T getObject(final Component c, final String key, final Class<T> type) {
return getObject(c, key, type, null);
}
public static <T> T getObject(final JComponent c, final String key, final Class<T> type) {
return getObject(c, key, type, null);
}
public static Color getColor(final JComponent c, final String key) {
return getColor(c, key, null);
}
public static Color getColor(final Component c, final String key) {
return getColor(c, key, null);
}
public static String getString(final JComponent c, final String key) {
return getString(c, key, null);
}
public static String getString(final Component c, final String key) {
return getString(c, key, null);
}
public static Integer getInteger(final JComponent c, final String key, final int defaultValue) {
return getObject(c, key, Integer.class, defaultValue);
}
public static Integer getInteger(final Component c, final String key, final int defaultValue) {
return getObject(c, key, Integer.class, defaultValue);
}
public static Integer getInteger(final Component c, final String key) {
return getInteger(c, key, 0);
}
public static Integer getInteger(final JComponent c, final String key) {
return getInteger(c, key, 0);
}
}

Loading…
Cancel
Save