vito
11 months ago
10 changed files with 833 additions and 165 deletions
@ -0,0 +1,42 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatButtonBorder; |
||||
|
||||
import java.awt.Component; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.Paint; |
||||
|
||||
import static com.fine.theme.light.ui.FineButtonUI.isPartRoundButton; |
||||
|
||||
/** |
||||
* 按钮边框 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2023/12/20 |
||||
*/ |
||||
public class FineButtonBorder extends FlatButtonBorder { |
||||
|
||||
public FineButtonBorder() { |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
||||
if (isPartRoundButton(c)) { |
||||
Graphics2D g2 = (Graphics2D) g.create(); |
||||
Paint borderPaint = getBorderColor(c); |
||||
if (borderPaint == null) { |
||||
return; |
||||
} |
||||
g2.setPaint(borderPaint); |
||||
FineUIUtils.paintPartRoundButtonBorder(c, g2, x, y, width, height, borderWidth, (float) getArc(c)); |
||||
} else { |
||||
super.paintBorder(c, g, x, y, width, height); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,114 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineClientProperties; |
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatButtonUI; |
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
|
||||
import javax.swing.AbstractButton; |
||||
import javax.swing.JButton; |
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.geom.Path2D; |
||||
|
||||
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; |
||||
|
||||
/** |
||||
* 按钮UI |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2023/12/20 |
||||
*/ |
||||
public class FineButtonUI extends FlatButtonUI { |
||||
|
||||
/** |
||||
* @param shared |
||||
* @since 2 |
||||
*/ |
||||
protected FineButtonUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 是否左圆角矩形 |
||||
* |
||||
* @param c 组件 |
||||
* @return 是否左圆角矩形 |
||||
*/ |
||||
public static boolean isLeftRoundButton(Component c) { |
||||
return c instanceof JButton |
||||
&& FineClientProperties.BUTTON_TYPE_LEFT_ROUND_RECT.equals(getButtonTypeStr((JButton) c)); |
||||
} |
||||
|
||||
/** |
||||
* 是否右圆角矩形 |
||||
* |
||||
* @param c 组件 |
||||
* @return 是否右圆角矩形 |
||||
*/ |
||||
public static boolean isRightRoundButton(Component c) { |
||||
return c instanceof JButton |
||||
&& FineClientProperties.BUTTON_TYPE_RIGHT_ROUND_RECT.equals(getButtonTypeStr((JButton) c)); |
||||
} |
||||
|
||||
/** |
||||
* 是否部分圆角矩形 |
||||
* |
||||
* @param c 组件 |
||||
* @return 是否部分圆角矩形 |
||||
*/ |
||||
public static boolean isPartRoundButton(Component c) { |
||||
return isLeftRoundButton(c) || isRightRoundButton(c); |
||||
} |
||||
|
||||
protected void paintBackground(Graphics g, JComponent c) { |
||||
if (isPartRoundButton(c)) { |
||||
Color background = getBackground(c); |
||||
if (background == null) { |
||||
return; |
||||
} |
||||
|
||||
Graphics2D g2 = (Graphics2D) g.create(); |
||||
try { |
||||
FlatUIUtils.setRenderingHints(g2); |
||||
float arc = FlatUIUtils.getBorderArc(c); |
||||
int width = c.getWidth(); |
||||
int height = c.getHeight(); |
||||
|
||||
g2.setColor(FlatUIUtils.deriveColor(background, getBackgroundBase(c, false))); |
||||
Path2D path2DLeft; |
||||
if (isLeftRoundButton(c)) { |
||||
path2DLeft = FineUIUtils.createLeftRoundRectangle(0, 0, width, height, arc); |
||||
} else { |
||||
path2DLeft = FineUIUtils.createRightRoundRectangle(0, 0, width, height, arc); |
||||
} |
||||
g2.fill(path2DLeft); |
||||
} finally { |
||||
g2.dispose(); |
||||
} |
||||
} else { |
||||
super.paintBackground(g, c); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineButtonUI(false); |
||||
} |
||||
|
||||
static String getButtonTypeStr(AbstractButton c) { |
||||
Object value = c.getClientProperty(BUTTON_TYPE); |
||||
if (value instanceof String) { |
||||
return (String) value; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,88 @@
|
||||
package com.fine.theme.light.ui; |
||||
|
||||
import com.fine.theme.utils.FineClientProperties; |
||||
import com.fine.theme.utils.FineUIUtils; |
||||
import com.formdev.flatlaf.ui.FlatPanelUI; |
||||
import com.formdev.flatlaf.ui.FlatUIUtils; |
||||
import com.fr.design.gui.ibutton.UICombinationButton; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.plaf.ComponentUI; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
import java.beans.PropertyChangeEvent; |
||||
|
||||
import static com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; |
||||
|
||||
/** |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2023/12/21 |
||||
*/ |
||||
public class FineCombinationButtonUI extends FlatPanelUI { |
||||
@Styleable(dot = true) |
||||
protected Color background; |
||||
|
||||
@Styleable(dot = true) |
||||
protected int arc; |
||||
|
||||
@Styleable(dot = true) |
||||
protected Color borderColor; |
||||
|
||||
/** |
||||
* @param shared |
||||
* @since 2 |
||||
*/ |
||||
protected FineCombinationButtonUI(boolean shared) { |
||||
super(shared); |
||||
} |
||||
|
||||
/** |
||||
* 创建UI |
||||
* |
||||
* @param c 组件 |
||||
* @return ComponentUI |
||||
*/ |
||||
public static ComponentUI createUI(JComponent c) { |
||||
return new FineCombinationButtonUI(false); |
||||
} |
||||
|
||||
@Override |
||||
public void installUI(JComponent c) { |
||||
super.installUI(c); |
||||
background = FineUIUtils.getUIColor("CombinationButton.background", "desktop"); |
||||
borderColor = FineUIUtils.getUIColor("CombinationButton.borderColor", "CombinationButton.secondary.background"); |
||||
arc = FineUIUtils.getUIInt("CombinationButton.arc", "Component.arc"); |
||||
} |
||||
|
||||
@Override |
||||
public void uninstallUI(JComponent c) { |
||||
super.uninstallUI(c); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g, JComponent c) { |
||||
paintBackground(g, c); |
||||
super.paint(g, c); |
||||
} |
||||
|
||||
protected void paintBackground(Graphics g, JComponent c) { |
||||
FlatUIUtils.setRenderingHints(g); |
||||
g.setColor(background); |
||||
g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), arc, arc); |
||||
} |
||||
|
||||
@Override |
||||
public void propertyChange(PropertyChangeEvent e) { |
||||
super.propertyChange(e); |
||||
switch (e.getPropertyName()) { |
||||
case FineClientProperties.STYLE_CLASS: |
||||
UICombinationButton b = (UICombinationButton) e.getSource(); |
||||
b.setPrimary(); |
||||
b.repaint(); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
} |
@ -1,143 +1,163 @@
|
||||
package com.fr.design.gui.ibutton; |
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
|
||||
import javax.swing.Icon; |
||||
import javax.swing.JFrame; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JPopupMenu; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.function.Consumer; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.stable.Constants; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_LEFT_ROUND_RECT; |
||||
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_RIGHT_ROUND_RECT; |
||||
import static com.fine.theme.utils.FineClientProperties.STYLE_PRIMARY; |
||||
import static com.fine.theme.utils.FineClientProperties.setStyle; |
||||
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; |
||||
|
||||
public class UICombinationButton extends JPanel { |
||||
private static final String UI_CLASS_ID = "CombinationButtonUI"; |
||||
|
||||
protected UIButton leftButton; |
||||
protected UIButton rightButton; |
||||
|
||||
|
||||
private Consumer<MouseEvent> leftClickLister; |
||||
private Consumer<MouseEvent> rightClickLister; |
||||
|
||||
protected void leftButtonClickEvent() { |
||||
// 左边按钮点击事件
|
||||
} |
||||
|
||||
protected void rightButtonClickEvent() { |
||||
// 右边按钮点击事件
|
||||
} |
||||
|
||||
public UICombinationButton() { |
||||
this(new UIButton(), new UIButton()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 添加左按钮监听器 |
||||
* |
||||
* @param lister 监听 |
||||
*/ |
||||
public void addLeftClickLister(Consumer<MouseEvent> lister) { |
||||
this.leftClickLister = lister; |
||||
} |
||||
|
||||
/** |
||||
* 添加右按钮监听器 |
||||
* |
||||
* @param lister 监听 |
||||
*/ |
||||
public void addRightClickLister(Consumer<MouseEvent> lister) { |
||||
this.rightClickLister = lister; |
||||
} |
||||
|
||||
public UICombinationButton(UIButton left, UIButton right) { |
||||
leftButton = left; |
||||
leftButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_LEFT_ROUND_RECT); |
||||
rightButton = right; |
||||
rightButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_RIGHT_ROUND_RECT); |
||||
leftButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
if (leftClickLister != null) { |
||||
leftClickLister.accept(e); |
||||
} else { |
||||
leftButtonClickEvent(); |
||||
} |
||||
} |
||||
}); |
||||
rightButton.addMouseListener(new MouseAdapter() { |
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
if (rightClickLister != null) { |
||||
rightClickLister.accept(e); |
||||
} else { |
||||
rightButtonClickEvent(); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(leftButton, BorderLayout.WEST); |
||||
this.add(rightButton, BorderLayout.EAST); |
||||
} |
||||
|
||||
public UICombinationButton(String left, Icon right) { |
||||
this(); |
||||
leftButton.setText(left); |
||||
rightButton.setIcon(right); |
||||
} |
||||
|
||||
public UICombinationButton(String left, String right) { |
||||
this(); |
||||
leftButton.setText(left); |
||||
rightButton.setText(right); |
||||
} |
||||
|
||||
public UICombinationButton(Icon left, Icon right) { |
||||
this(); |
||||
leftButton.setIcon(left); |
||||
rightButton.setIcon(right); |
||||
} |
||||
|
||||
@Override |
||||
public String getUIClassID() { |
||||
return UI_CLASS_ID; |
||||
} |
||||
|
||||
public void setPrimary() { |
||||
setStyle(leftButton, STYLE_PRIMARY); |
||||
setStyle(rightButton, STYLE_PRIMARY); |
||||
} |
||||
|
||||
public UIButton getLeftButton() { |
||||
return leftButton; |
||||
} |
||||
|
||||
public void setExtraPainted(boolean isExtraPainted) { |
||||
// if (!isExtraPainted) {
|
||||
// leftButton.setBackground(null);
|
||||
// rightButton.setBackground(null);
|
||||
// leftButton.setOpaque(false);
|
||||
// rightButton.setOpaque(false);
|
||||
// }
|
||||
} |
||||
|
||||
public UIButton getRightButton() { |
||||
return rightButton; |
||||
} |
||||
|
||||
public void set4Toolbar() { |
||||
leftButton.setNormalPainted(false); |
||||
rightButton.setNormalPainted(false); |
||||
leftButton.setBorderPaintedOnlyWhenPressed(true); |
||||
rightButton.setBorderPaintedOnlyWhenPressed(true); |
||||
} |
||||
|
||||
protected void showPopWindow(JPopupMenu menu) { |
||||
GUICoreUtils.showPopupMenu(menu, this, 0, getY() + getHeight() - 3); |
||||
} |
||||
|
||||
public static void main(String... args) { |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel) jf.getContentPane(); |
||||
content.setLayout(null); |
||||
|
||||
public class UICombinationButton extends JPanel{ |
||||
protected UIButton leftButton; |
||||
protected UIButton rightButton; |
||||
|
||||
protected void leftButtonClickEvent() { |
||||
// 左边按钮点击事件
|
||||
} |
||||
|
||||
protected void rightButtonClickEvent() { |
||||
// 右边按钮点击事件
|
||||
} |
||||
|
||||
public UICombinationButton() { |
||||
this(new UIButton(), new UIButton()); |
||||
} |
||||
|
||||
public UICombinationButton(UIButton left, UIButton right) { |
||||
leftButton = left; |
||||
rightButton = right; |
||||
|
||||
leftButton.setRoundBorder(true, Constants.RIGHT); |
||||
rightButton.setRoundBorder(true, Constants.LEFT); |
||||
|
||||
leftButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
rightButton.getModel().setPressed(true); |
||||
rightButton.getModel().setSelected(true); |
||||
rightButton.repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
rightButton.getModel().setPressed(false); |
||||
rightButton.getModel().setSelected(false); |
||||
rightButton.repaint(); |
||||
} |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
leftButtonClickEvent(); |
||||
} |
||||
}); |
||||
rightButton.addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mousePressed(MouseEvent e) { |
||||
leftButton.getModel().setPressed(true); |
||||
leftButton.getModel().setSelected(true); |
||||
leftButton.repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseReleased(MouseEvent e) { |
||||
leftButton.getModel().setPressed(false); |
||||
leftButton.getModel().setSelected(false); |
||||
leftButton.repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
rightButtonClickEvent(); |
||||
} |
||||
}); |
||||
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(leftButton, BorderLayout.CENTER); |
||||
this.add(rightButton, BorderLayout.EAST); |
||||
} |
||||
|
||||
public UICombinationButton(String left, Icon right) { |
||||
this(); |
||||
leftButton.setText(left); |
||||
rightButton.setIcon(right); |
||||
} |
||||
|
||||
public UICombinationButton(String left, String right) { |
||||
this(); |
||||
leftButton.setText(left); |
||||
rightButton.setText(right); |
||||
} |
||||
|
||||
public UICombinationButton(Icon left, Icon right) { |
||||
this(); |
||||
leftButton.setIcon(left); |
||||
rightButton.setIcon(right); |
||||
} |
||||
|
||||
public UIButton getLeftButton() { |
||||
return leftButton; |
||||
} |
||||
|
||||
public void setExtraPainted(boolean isExtraPainted) { |
||||
if(!isExtraPainted) { |
||||
leftButton.setBackground(null); |
||||
rightButton.setBackground(null); |
||||
leftButton.setOpaque(false); |
||||
rightButton.setOpaque(false); |
||||
} |
||||
} |
||||
|
||||
public UIButton getRightButton() { |
||||
return rightButton; |
||||
} |
||||
|
||||
public void set4Toolbar() { |
||||
leftButton.setNormalPainted(false); |
||||
rightButton.setNormalPainted(false); |
||||
leftButton.setBorderPaintedOnlyWhenPressed(true); |
||||
rightButton.setBorderPaintedOnlyWhenPressed(true); |
||||
} |
||||
|
||||
protected void showPopWindow(JPopupMenu menu) { |
||||
GUICoreUtils.showPopupMenu(menu, this, 0, getY() + getHeight() - 3); |
||||
} |
||||
|
||||
public static void main(String... args) { |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel)jf.getContentPane(); |
||||
content.setLayout(null); |
||||
|
||||
UICombinationButton bb = new UICombinationButton("123455", UIConstants.ARROW_DOWN_ICON); |
||||
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
||||
content.add(bb); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(400, 400); |
||||
jf.setVisible(true); |
||||
} |
||||
UICombinationButton bb = new UICombinationButton("123455", UIConstants.ARROW_DOWN_ICON); |
||||
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
||||
content.add(bb); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(400, 400); |
||||
jf.setVisible(true); |
||||
} |
||||
} |
Loading…
Reference in new issue