插件开发工具库,推荐依赖该工具库。
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.

89 lines
2.0 KiB

package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UICheckBox;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示布尔值的编辑器
* TODO:待补充文档
*/
public class TypeBooleanEditor extends BaseEditor<Boolean> {
private UICheckBox booleanCheckBox;
public TypeBooleanEditor() {
this(Boolean.TRUE);
}
public TypeBooleanEditor(boolean b) {
this(Boolean.valueOf(b));
}
public TypeBooleanEditor(Boolean value) {
this.setLayout(new BorderLayout());
booleanCheckBox = new UICheckBox("true");
this.add(booleanCheckBox, BorderLayout.CENTER);
this.setValue(value);
this.setName(DesignKit.i18nText("Fine-Design_Basic_Parameter_Boolean"));
booleanCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
fireStateChanged();
}
});
}
public UICheckBox getSwingComponent() {
return booleanCheckBox;
}
@Override
public Boolean getValue() {
return this.booleanCheckBox.isSelected();
}
@Override
public void setValue(Boolean value) {
if (value == null) {
value = true;
}
this.booleanCheckBox.setSelected(value);
}
@Override
public void setEnabled(boolean enabled) {
this.booleanCheckBox.setEnabled(enabled);
}
@Override
public void requestFocus() {
this.booleanCheckBox.requestFocus();
}
@Override
protected void fireEditingStopped() {
this.setValue(this.booleanCheckBox.isSelected());
super.fireEditingStopped();
}
public String getIconName() {
return "type_bool";
}
@Override
public boolean accept(Object object) {
return object instanceof Boolean;
}
}