forked from fanruan/finekit
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.
55 lines
1.5 KiB
55 lines
1.5 KiB
package com.fanruan.api.design.ui.component; |
|
|
|
import com.fr.design.editlock.EditLockChangeEvent; |
|
import com.fr.design.editlock.EditLockChangeListener; |
|
import com.fr.design.editlock.EditLockUtils; |
|
import com.fr.report.LockItem; |
|
|
|
import javax.swing.*; |
|
|
|
/** |
|
* @author Yvan |
|
* @version 10.0 |
|
* Created by Yvan on 2021/1/20 |
|
*/ |
|
public class UILockButton extends UIButton implements EditLockChangeListener { |
|
|
|
/** |
|
* 锁定状态图标 |
|
*/ |
|
private final Icon lockedIcon; |
|
/** |
|
* 正常状态图标 |
|
*/ |
|
private final Icon normalIcon; |
|
/** |
|
* 锁定状态的提示信息 |
|
*/ |
|
private final String lockedTooltips; |
|
/** |
|
* 正常状态的提示信息 |
|
*/ |
|
private final String normalTooltips; |
|
|
|
public UILockButton(Icon lockedIcon, Icon normalIcon, String lockedTooltips, String normalTooltips) { |
|
super(); |
|
this.lockedIcon = lockedIcon; |
|
this.normalIcon = normalIcon; |
|
this.lockedTooltips = lockedTooltips; |
|
this.normalTooltips = normalTooltips; |
|
init(); |
|
} |
|
|
|
private void init() { |
|
boolean locked = EditLockUtils.isLocked(LockItem.CONNECTION); |
|
this.setIcon(locked ? lockedIcon : normalIcon); |
|
this.setToolTipText(locked ? lockedTooltips : normalTooltips); |
|
} |
|
|
|
@Override |
|
public void updateLockedState(EditLockChangeEvent event) { |
|
this.setIcon(event.isLocked() ? lockedIcon : normalIcon); |
|
this.setToolTipText(event.isLocked() ? lockedTooltips : normalTooltips); |
|
this.repaint(); |
|
} |
|
} |