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

92 lines
2.2 KiB

package com.fanruan.api.design.work.form.editor;
import com.fanruan.api.design.err.ValidationException;
import com.fanruan.api.design.ui.component.UIComboBox;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/10/30
* 通过下拉框选择特定值的编辑器
*/
public abstract class BaseComboEditor<T> extends BasePropertyEditor {
private UIComboBox<T> comboBox;
public BaseComboEditor() {
comboBox = new UIComboBox<>();
initComboBoxLookAndFeel();
ComboBoxModel<T> model = model();
if (model != null) {
comboBox.setModel(model);
}
ListCellRenderer cellRenderer = renderer();
if (cellRenderer != null) {
comboBox.setRenderer(cellRenderer);
}
}
public BaseComboEditor(T[] items) {
this(new UIComboBox<>(items));
}
public BaseComboEditor(Vector<T> items) {
this(new UIComboBox<>(items));
}
public BaseComboEditor(ComboBoxModel<T> model) {
this(new UIComboBox<>(model));
}
public BaseComboEditor(UIComboBox combo) {
comboBox = combo;
initComboBoxLookAndFeel();
}
private void initComboBoxLookAndFeel() {
comboBox.setEditable(false);
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
firePropertyChanged();
}
});
((JComponent) comboBox.getEditor().getEditorComponent()).setBorder(null);
comboBox.setBorder(null);
}
public ComboBoxModel model() {
return null;
}
public ListCellRenderer renderer() {
return null;
}
@Override
public void setValue(Object value) {
comboBox.setSelectedItem(value);
}
@Override
public Object getValue() {
return comboBox.getSelectedItem();
}
@Override
public Component getCustomEditor() {
return comboBox;
}
@Override
public void validateValue() throws ValidationException {
}
}