vito
10 months ago
13 changed files with 154 additions and 180 deletions
@ -0,0 +1,66 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
import com.fr.base.Utils; |
||||
import com.fr.design.gui.ibutton.UIColorButton; |
||||
|
||||
import javax.swing.ButtonModel; |
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Rectangle; |
||||
import java.awt.geom.RoundRectangle2D; |
||||
|
||||
import static com.fine.theme.utils.FineUIScale.scale; |
||||
|
||||
/** |
||||
* 颜色按钮 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/3 |
||||
*/ |
||||
public class FineColorButtonUI extends FineButtonUI { |
||||
|
||||
public static final float HEIGHT = 1.5f; |
||||
public static final float WIDTH = 13; |
||||
public static final float Y = 13.5f; |
||||
|
||||
/** |
||||
* @param shared |
||||
* @since 2 |
||||
*/ |
||||
protected FineColorButtonUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineColorButtonUI(false); |
||||
} |
||||
|
||||
@Override |
||||
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) { |
||||
super.paintIcon(g, c, iconRect); |
||||
UIColorButton b = (UIColorButton) c; |
||||
ButtonModel model = b.getModel(); |
||||
if (model.isEnabled()) { |
||||
g.setColor(b.getColor()); |
||||
} else { |
||||
g.setColor(new Color(Utils.filterRGB(b.getColor().getRGB(), 50))); |
||||
} |
||||
FlatUIUtils.setRenderingHints(g); |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
float height = scale(HEIGHT); |
||||
float width = scale(WIDTH); |
||||
// 计算实际大小与icon区域大小的偏移,用于居中调整
|
||||
float offsetX = (iconRect.width - width) / 2.0f; |
||||
RoundRectangle2D.Float colorRect = new RoundRectangle2D.Float( |
||||
iconRect.x + offsetX, iconRect.y + scale(Y), width, height, height, height); |
||||
g2d.fill(colorRect); |
||||
} |
||||
} |
Loading…
Reference in new issue