richie
5 years ago
9 changed files with 270 additions and 22 deletions
@ -0,0 +1,18 @@
|
||||
package com.fanruan.api.design.err; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/9/26 |
||||
* 用于标识设计器中控件值校验时发生的异常 |
||||
*/ |
||||
public class ValidationException extends com.fr.design.Exception.ValidationException { |
||||
|
||||
public ValidationException() { |
||||
super(); |
||||
} |
||||
|
||||
public ValidationException(String message) { |
||||
super(message); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
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 { |
||||
} |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.fanruan.api.design.work.form.editor; |
||||
|
||||
import com.fanruan.api.design.err.ValidationException; |
||||
import com.fr.design.mainframe.widget.editors.AbstractPropertyEditor; |
||||
|
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/10/30 |
||||
* 自定义属性编辑器接口 |
||||
*/ |
||||
public abstract class BasePropertyEditor extends AbstractPropertyEditor { |
||||
|
||||
/** |
||||
* 校验编辑器中输入值的合法性 |
||||
* |
||||
* @throws ValidationException 值不合法则抛出此异常 |
||||
*/ |
||||
@Override |
||||
public abstract void validateValue() throws ValidationException; |
||||
|
||||
/** |
||||
* 从外部给编辑器传入值 |
||||
* |
||||
* @param value 新值 |
||||
*/ |
||||
@Override |
||||
public abstract void setValue(Object value); |
||||
|
||||
/** |
||||
* 获取编辑器的值 |
||||
* |
||||
* @return 编辑器的值 |
||||
*/ |
||||
@Override |
||||
public abstract Object getValue(); |
||||
|
||||
/** |
||||
* 编辑器的UI控制器,是一个swing组件,比如:下拉框、复选框,用于设置做不同类别的属性设置 |
||||
* |
||||
* @return UI控制器 |
||||
*/ |
||||
@Override |
||||
public abstract Component getCustomEditor(); |
||||
} |
@ -1,14 +0,0 @@
|
||||
package com.fanruan.api.design.work.form.editor; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-05 |
||||
* 字符串编辑器 |
||||
*/ |
||||
public class StringEditor extends com.fr.design.mainframe.widget.editors.StringEditor { |
||||
|
||||
public StringEditor() { |
||||
super(); |
||||
} |
||||
} |
@ -0,0 +1,65 @@
|
||||
package com.fanruan.api.design.work.form.editor.impl; |
||||
|
||||
import com.fanruan.api.design.err.ValidationException; |
||||
import com.fanruan.api.design.ui.component.UITextField; |
||||
import com.fanruan.api.design.work.form.editor.BasePropertyEditor; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.DocumentEvent; |
||||
import javax.swing.event.DocumentListener; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-05 |
||||
* 字符串编辑器 |
||||
*/ |
||||
public class StringEditor extends BasePropertyEditor { |
||||
private JPanel panel; |
||||
private UITextField textField; |
||||
|
||||
public StringEditor() { |
||||
panel = new JPanel(new BorderLayout()); |
||||
textField = new UITextField(); |
||||
panel.add(textField, BorderLayout.CENTER); |
||||
textField.setBorder(null); |
||||
textField.getDocument().addDocumentListener(new DocumentListener() { |
||||
|
||||
@Override |
||||
public void removeUpdate(DocumentEvent e) { |
||||
firePropertyChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public void insertUpdate(DocumentEvent e) { |
||||
firePropertyChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public void changedUpdate(DocumentEvent e) { |
||||
firePropertyChanged(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void setValue(Object value) { |
||||
textField.setText((String) value); |
||||
} |
||||
|
||||
@Override |
||||
public Object getValue() { |
||||
return textField.getText(); |
||||
} |
||||
|
||||
@Override |
||||
public Component getCustomEditor() { |
||||
return textField; |
||||
} |
||||
|
||||
@Override |
||||
public void validateValue() throws ValidationException { |
||||
|
||||
} |
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.fanruan.api.design.work.form.editor; |
||||
package com.fanruan.api.design.work.form.editor.impl; |
||||
|
||||
/** |
||||
* @author Kalven |
@ -1,7 +0,0 @@
|
||||
package com.fanruan.api.err; |
||||
|
||||
/** |
||||
* 验证异常 |
||||
*/ |
||||
public class ValidationException extends com.fr.design.Exception.ValidationException { |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fanruan.api.generic.adapter; |
||||
|
||||
import com.fr.stable.core.PropertyChangeAdapter; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019/10/30 |
||||
* 事件适配器 |
||||
*/ |
||||
public class BasePropertyChangeAdapter<T> extends PropertyChangeAdapter<T> { |
||||
|
||||
/** |
||||
* 属性改变是执行的方法,根据不同的需求做不同的实现,不带参数 |
||||
*/ |
||||
public void propertyChange() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 属性改变是执行的方法,根据不同的需求做不同的实现,带一个参数 |
||||
* |
||||
* @param mark 执行具体操作时所携带的参数 |
||||
*/ |
||||
public void propertyChange(T mark) { |
||||
|
||||
} |
||||
|
||||
/*** |
||||
* 属性改变是执行的方法,根据不同的需求做不同的实现,带可变个参数 |
||||
* @param marks 参数 |
||||
*/ |
||||
public void propertyChange(T... marks) { |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue