|
|
|
@ -21,7 +21,11 @@ import java.awt.Rectangle;
|
|
|
|
|
* created by Harrison on 2020/03/22 |
|
|
|
|
**/ |
|
|
|
|
public class UIMenuItemUI extends BasicMenuItemUI { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int RTL_X = 5; |
|
|
|
|
private static final int ICON_WIDTH = 30; |
|
|
|
|
private static final int ARC = 7; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { |
|
|
|
|
if (menuItem.getIcon() == null) { |
|
|
|
@ -35,20 +39,28 @@ public class UIMenuItemUI extends BasicMenuItemUI {
|
|
|
|
|
|
|
|
|
|
g.setColor(UIConstants.NORMAL_BACKGROUND); |
|
|
|
|
g.fillRect(0, 0, menuWidth, menuHeight); |
|
|
|
|
int bidiX = BidiUtils.rtl() ? 5 : 30; |
|
|
|
|
int bidiX = BidiUtils.rtl() ? RTL_X : ICON_WIDTH; |
|
|
|
|
if (menuItem.isOpaque()) { |
|
|
|
|
if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); |
|
|
|
|
if (itemArmedOrSelected(model, menuItem)) { |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, ARC); |
|
|
|
|
} else { |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, menuItem.getBackground(), ARC); |
|
|
|
|
} |
|
|
|
|
g.setColor(oldColor); |
|
|
|
|
} else if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); |
|
|
|
|
} else if (itemArmedOrSelected(model, menuItem)) { |
|
|
|
|
GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, ARC); |
|
|
|
|
g.setColor(oldColor); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 按钮被触发,或菜单项被选中 |
|
|
|
|
* 抽个方法 |
|
|
|
|
*/ |
|
|
|
|
private boolean itemArmedOrSelected(ButtonModel model, JMenuItem menuItem) { |
|
|
|
|
return model.isArmed() || (menuItem instanceof JMenu && model.isSelected()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { |
|
|
|
|
ButtonModel model = menuItem.getModel(); |
|
|
|
|
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g); |
|
|
|
|