From 7726f974c3428b694a057a32c1812ca20829f1f8 Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 30 Oct 2019 14:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=92=91=E6=96=B0=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=BB=9A=E5=8A=A8=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/design/err/ValidationException.java | 18 ++++ .../work/form/editor/BaseComboEditor.java | 92 +++++++++++++++++++ .../work/form/editor/BasePropertyEditor.java | 47 ++++++++++ .../design/work/form/editor/StringEditor.java | 14 --- .../work/form/editor/impl/StringEditor.java | 65 +++++++++++++ .../editor/{ => impl}/WidgetValueEditor.java | 2 +- .../fanruan/api/err/ValidationException.java | 7 -- .../adapter/BasePropertyChangeAdapter.java | 36 ++++++++ .../java/com/fanruan/api/report/StyleKit.java | 11 +++ 9 files changed, 270 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/fanruan/api/design/err/ValidationException.java create mode 100644 src/main/java/com/fanruan/api/design/work/form/editor/BaseComboEditor.java create mode 100644 src/main/java/com/fanruan/api/design/work/form/editor/BasePropertyEditor.java delete mode 100644 src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java create mode 100644 src/main/java/com/fanruan/api/design/work/form/editor/impl/StringEditor.java rename src/main/java/com/fanruan/api/design/work/form/editor/{ => impl}/WidgetValueEditor.java (87%) delete mode 100644 src/main/java/com/fanruan/api/err/ValidationException.java create mode 100644 src/main/java/com/fanruan/api/generic/adapter/BasePropertyChangeAdapter.java diff --git a/src/main/java/com/fanruan/api/design/err/ValidationException.java b/src/main/java/com/fanruan/api/design/err/ValidationException.java new file mode 100644 index 0000000..a39356c --- /dev/null +++ b/src/main/java/com/fanruan/api/design/err/ValidationException.java @@ -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); + } +} diff --git a/src/main/java/com/fanruan/api/design/work/form/editor/BaseComboEditor.java b/src/main/java/com/fanruan/api/design/work/form/editor/BaseComboEditor.java new file mode 100644 index 0000000..26d02d1 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/editor/BaseComboEditor.java @@ -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 extends BasePropertyEditor { + + private UIComboBox comboBox; + + public BaseComboEditor() { + comboBox = new UIComboBox<>(); + initComboBoxLookAndFeel(); + ComboBoxModel 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 items) { + this(new UIComboBox<>(items)); + } + + public BaseComboEditor(ComboBoxModel 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 { + } +} diff --git a/src/main/java/com/fanruan/api/design/work/form/editor/BasePropertyEditor.java b/src/main/java/com/fanruan/api/design/work/form/editor/BasePropertyEditor.java new file mode 100644 index 0000000..293587d --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/editor/BasePropertyEditor.java @@ -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(); +} diff --git a/src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java b/src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java deleted file mode 100644 index e301eb7..0000000 --- a/src/main/java/com/fanruan/api/design/work/form/editor/StringEditor.java +++ /dev/null @@ -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(); - } -} diff --git a/src/main/java/com/fanruan/api/design/work/form/editor/impl/StringEditor.java b/src/main/java/com/fanruan/api/design/work/form/editor/impl/StringEditor.java new file mode 100644 index 0000000..2a9005b --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/editor/impl/StringEditor.java @@ -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 { + + } +} \ No newline at end of file diff --git a/src/main/java/com/fanruan/api/design/work/form/editor/WidgetValueEditor.java b/src/main/java/com/fanruan/api/design/work/form/editor/impl/WidgetValueEditor.java similarity index 87% rename from src/main/java/com/fanruan/api/design/work/form/editor/WidgetValueEditor.java rename to src/main/java/com/fanruan/api/design/work/form/editor/impl/WidgetValueEditor.java index 9204356..ef4d83a 100644 --- a/src/main/java/com/fanruan/api/design/work/form/editor/WidgetValueEditor.java +++ b/src/main/java/com/fanruan/api/design/work/form/editor/impl/WidgetValueEditor.java @@ -1,4 +1,4 @@ -package com.fanruan.api.design.work.form.editor; +package com.fanruan.api.design.work.form.editor.impl; /** * @author Kalven diff --git a/src/main/java/com/fanruan/api/err/ValidationException.java b/src/main/java/com/fanruan/api/err/ValidationException.java deleted file mode 100644 index 7da52c4..0000000 --- a/src/main/java/com/fanruan/api/err/ValidationException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.fanruan.api.err; - -/** - * 验证异常 - */ -public class ValidationException extends com.fr.design.Exception.ValidationException { -} diff --git a/src/main/java/com/fanruan/api/generic/adapter/BasePropertyChangeAdapter.java b/src/main/java/com/fanruan/api/generic/adapter/BasePropertyChangeAdapter.java new file mode 100644 index 0000000..76236be --- /dev/null +++ b/src/main/java/com/fanruan/api/generic/adapter/BasePropertyChangeAdapter.java @@ -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 extends PropertyChangeAdapter { + + /** + * 属性改变是执行的方法,根据不同的需求做不同的实现,不带参数 + */ + public void propertyChange() { + + } + + /** + * 属性改变是执行的方法,根据不同的需求做不同的实现,带一个参数 + * + * @param mark 执行具体操作时所携带的参数 + */ + public void propertyChange(T mark) { + + } + + /*** + * 属性改变是执行的方法,根据不同的需求做不同的实现,带可变个参数 + * @param marks 参数 + */ + public void propertyChange(T... marks) { + + } +} diff --git a/src/main/java/com/fanruan/api/report/StyleKit.java b/src/main/java/com/fanruan/api/report/StyleKit.java index 3b3b557..d23eb66 100644 --- a/src/main/java/com/fanruan/api/report/StyleKit.java +++ b/src/main/java/com/fanruan/api/report/StyleKit.java @@ -2,6 +2,7 @@ package com.fanruan.api.report; import com.fr.base.Style; import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; import com.fr.xml.SynchronizedStyleList; /** @@ -21,6 +22,16 @@ public class StyleKit { SynchronizedStyleList.getSynchronizedStyleList().xmlizeStyleList(writer); } + /** + * 反序列化样式列表 + * + * @param reader xml读取器 + */ + public static void deXmlizeStyleList(XMLableReader reader) { + SynchronizedStyleList.getSynchronizedStyleList().deXmlizeStyleList(reader); + } + + /** * 获取指定样式的序列 *