You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
3.9 KiB
140 lines
3.9 KiB
package com.fr.design.gui.ibutton; |
|
|
|
import javax.swing.Icon; |
|
import javax.swing.JPanel; |
|
import java.awt.BorderLayout; |
|
import java.awt.event.ActionEvent; |
|
import java.util.function.Consumer; |
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_BORDER; |
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_BORDER_LEFT_ROUND_RECT; |
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_BORDER_RIGHT_ROUND_RECT; |
|
import static com.fine.theme.utils.FineUIStyle.IN_TOOLBAR_LEFT; |
|
import static com.fine.theme.utils.FineUIStyle.IN_TOOLBAR_RIGHT; |
|
import static com.fine.theme.utils.FineUIStyle.STYLE_PRIMARY; |
|
import static com.fine.theme.utils.FineUIStyle.setStyle; |
|
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; |
|
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON; |
|
|
|
/** |
|
* 双按钮组件 |
|
* |
|
* @author vito |
|
* @since 11.0 |
|
* <p> |
|
* created by vito on 2023/12/28 |
|
**/ |
|
public class UICombinationButton extends JPanel { |
|
|
|
private static final String UI_CLASS_ID = "CombinationButtonUI"; |
|
|
|
protected UIButton leftButton; |
|
protected UIButton rightButton; |
|
|
|
|
|
private Consumer<ActionEvent> leftClickLister; |
|
private Consumer<ActionEvent> rightClickLister; |
|
|
|
protected void leftButtonClickEvent() { |
|
// 左边按钮点击事件 |
|
} |
|
|
|
protected void rightButtonClickEvent() { |
|
// 右边按钮点击事件 |
|
} |
|
|
|
public UICombinationButton() { |
|
this(new UIButton(), new UIButton()); |
|
} |
|
|
|
|
|
/** |
|
* 添加左按钮监听器 |
|
* |
|
* @param lister 监听 |
|
*/ |
|
public void addLeftActionListener(Consumer<ActionEvent> lister) { |
|
this.leftClickLister = lister; |
|
} |
|
|
|
/** |
|
* 添加右按钮监听器 |
|
* |
|
* @param lister 监听 |
|
*/ |
|
public void addRightActionListener(Consumer<ActionEvent> lister) { |
|
this.rightClickLister = lister; |
|
} |
|
|
|
public UICombinationButton(UIButton left, UIButton right) { |
|
setOpaque(false); |
|
leftButton = left; |
|
leftButton.putClientProperty(BUTTON_BORDER, BUTTON_BORDER_LEFT_ROUND_RECT); |
|
rightButton = right; |
|
rightButton.putClientProperty(BUTTON_BORDER, BUTTON_BORDER_RIGHT_ROUND_RECT); |
|
leftButton.addActionListener(e -> { |
|
if (leftClickLister != null) { |
|
leftClickLister.accept(e); |
|
} else { |
|
leftButtonClickEvent(); |
|
} |
|
}); |
|
rightButton.addActionListener(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 UIButton getRightButton() { |
|
return rightButton; |
|
} |
|
|
|
public void set4Toolbar() { |
|
leftButton.setBorderPainted(false); |
|
leftButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); |
|
setStyle(leftButton, IN_TOOLBAR_LEFT); |
|
rightButton.setBorderPainted(false); |
|
rightButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); |
|
setStyle(rightButton, IN_TOOLBAR_RIGHT); |
|
} |
|
} |