From f5b7cd4b48e0f12de400161f37f707534db31f13 Mon Sep 17 00:00:00 2001 From: richie Date: Thu, 12 Sep 2019 17:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E8=AE=BE=E8=AE=A1=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/work/form/creator/Attribute.java | 75 ++++++++++++ .../work/form/creator/OpacityButton.java | 80 ++++++++++++ .../work/form/creator/XFieldEditor.java | 38 ++++-- .../work/form/creator/XOpenCreator.java | 114 ++++++++++++++++++ 4 files changed, 300 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java create mode 100644 src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java create mode 100644 src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java diff --git a/src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java b/src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java new file mode 100644 index 0000000..9c8d7bc --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java @@ -0,0 +1,75 @@ +package com.fanruan.api.design.work.form.creator; + +import com.fanruan.api.log.LogKit; +import com.fr.design.designer.creator.CRPropertyDescriptor; + +import java.beans.IntrospectionException; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public class Attribute { + + private CRPropertyDescriptor descriptor; + + public static Attribute newAttribute(String name, Class beanClass) { + return new Attribute(name, beanClass); + } + + public static Attribute newAttribute(String name, Class beanClass, String readMethod, String writeMethod) { + return new Attribute(name, beanClass, readMethod, writeMethod); + } + + private Attribute(String name, Class beanClass) { + try { + descriptor = new CRPropertyDescriptor(name, beanClass); + } catch (IntrospectionException e) { + LogKit.error(e.getMessage(), e); + } + } + + private Attribute(String name, Class beanClass, String readMethod, String writeMethod) { + try { + descriptor = new CRPropertyDescriptor(name, beanClass, readMethod, writeMethod); + } catch (IntrospectionException e) { + LogKit.error(e.getMessage(), e); + } + } + + public Attribute keyValue(String name, Object value) { + if (descriptor != null) { + descriptor.putKeyValue(name, value); + } + return this; + } + + public Attribute i18n(String i18nName) { + if (descriptor != null) { + descriptor.setI18NName(i18nName); + } + return this; + } + + public Attribute editorClass(Class clazz) { + if (descriptor != null) { + descriptor.setEditorClass(clazz); + } + return this; + } + + public Attribute rendererClass(Class clazz) { + if (descriptor != null) { + descriptor.setRendererClass(clazz); + } + return this; + } + + /** + * 这个属于内部调用的方法,外部不应该调用 + */ + protected CRPropertyDescriptor toPropertyDescriptor() { + return descriptor; + } +} diff --git a/src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java b/src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java new file mode 100644 index 0000000..0ea17f5 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/creator/OpacityButton.java @@ -0,0 +1,80 @@ +package com.fanruan.api.design.work.form.creator; + +import com.fanruan.api.util.IOKit; + +import javax.swing.*; +import java.awt.*; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public class OpacityButton extends JButton { + + private static final float FULL_OPACITY = 1.0F; + private static final float HALF_OPACITY = 0.4F; + + private String name; + private String imagePath; + private float opacity; + + public OpacityButton(String name, String imagePath, float opacity) { + this.name = name; + this.imagePath = imagePath; + this.opacity = opacity; + this.draw(); + } + + private void draw() { + ImageIcon imageIcon = (ImageIcon) IOKit.readIcon(imagePath); + Image img = imageIcon.getImage(); + MediaTracker mt = new MediaTracker(this); + int w = 21; + int h = 21; + mt.addImage(img, 0); + try { + mt.waitForAll(); + } catch (InterruptedException ignore) { + return; + } + + GraphicsConfiguration gc = new JFrame().getGraphicsConfiguration(); // 本地图形设备 + Image image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);//建立透明画布 + Graphics2D g = (Graphics2D) image.getGraphics(); //在画布上创建画笔 + + Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); //指定透明度为半透明90% + g.setComposite(alpha); + g.drawImage(img, 0, 0, this); //注意是,将image画到g画笔所在的画布上 + g.setColor(Color.black);//设置颜色为黑色 + g.drawString(name, 25, 20);//写字 + g.dispose(); //释放内存 + + Composite alpha2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity); + Image image1 = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT); + g = (Graphics2D) image1.getGraphics(); + g.setComposite(alpha2); + g.drawImage(img, 2, 2, this); //改变图像起始位置,产生动态效果 + g.setColor(Color.black); + g.drawString(name, 25, 20); + g.dispose(); + + this.setIgnoreRepaint(true); + this.setFocusable(false);//设置没有焦点 + this.setBorder(null);//设置不画按钮边框 + this.setContentAreaFilled(false);//设置不画按钮背景 + this.setIcon(new ImageIcon(image1)); //把刚才生成的半透明image变成ImageIcon,贴到按钮上去 + this.setRolloverIcon(new ImageIcon(image1)); + this.setPressedIcon(new ImageIcon(image));//按下去的图标 + } + + /** + * 更改组件的可见性 + * + * @param visible 设置为true表示可见,设置为false表示不可见 + */ + public void makeVisible(boolean visible) { + this.opacity = visible ? FULL_OPACITY : HALF_OPACITY; + this.draw(); + } +} diff --git a/src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java b/src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java index 53afb63..8c13bb5 100644 --- a/src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java +++ b/src/main/java/com/fanruan/api/design/work/form/creator/XFieldEditor.java @@ -1,17 +1,41 @@ package com.fanruan.api.design.work.form.creator; -import com.fr.form.ui.FieldEditor; +import com.fanruan.api.design.DesignKit; +import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.mainframe.widget.editors.InChangeBooleanEditor; +import com.fr.form.ui.Widget; import java.awt.*; /** - * 控件树 - * @author Kalven + * @author richie * @version 10.0 - * Created by Kalven on 2019/9/3 + * Created by richie on 2019-09-10 + * 控件的UI展示和设计类 */ -public abstract class XFieldEditor extends com.fr.design.designer.creator.XFieldEditor { - public XFieldEditor(FieldEditor widget, Dimension initSize) { - super(widget, initSize); +public abstract class XFieldEditor extends XOpenCreator { + + public XFieldEditor(Widget fieldEditor, Dimension dimension) { + super(fieldEditor, dimension); + } + + @Override + public Attribute[] attributes() { + + Attribute allowBlank = Attribute.newAttribute("allowBlank", this.data.getClass()).i18n( + DesignKit.i18nText("Fine-Design_Form_Allow_Blank")) + .editorClass(InChangeBooleanEditor.class).keyValue( + XCreatorConstants.PROPERTY_VALIDATE, "Fine-Design_Basic_Validate"); + Attribute blankErrorMsg = Attribute.newAttribute("errorMessage", this.data.getClass()).i18n( + DesignKit.i18nText("Fine-Design_Report_Engine_Verify_Message")) + .keyValue(XCreatorConstants.PROPERTY_VALIDATE, "Fine-Design_Basic_Validate"); + Attribute fontSize = Attribute.newAttribute("fontSize", this.data.getClass(), "getFontSize", "setFontSize") + .i18n(DesignKit.i18nText("Fine-Design_Form_Font_Size")) + .keyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Report_Advanced"); + + return new Attribute[]{ + allowBlank, blankErrorMsg, fontSize + }; } + } diff --git a/src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java b/src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java new file mode 100644 index 0000000..66ba00d --- /dev/null +++ b/src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java @@ -0,0 +1,114 @@ +package com.fanruan.api.design.work.form.creator; + +import com.fanruan.api.design.DesignKit; +import com.fanruan.api.design.work.form.macro.XCreatorConstants; +import com.fanruan.api.util.ArrayKit; +import com.fr.design.designer.creator.CRPropertyDescriptor; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XWidgetCreator; +import com.fr.design.mainframe.FormDesigner; +import com.fr.form.ui.Widget; +import com.fr.stable.core.PropertyChangeAdapter; + +import javax.swing.*; +import java.awt.*; +import java.beans.IntrospectionException; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-10 + */ +public abstract class XOpenCreator extends XWidgetCreator { + + public XOpenCreator(Widget widget, Dimension size) { + super(widget, size); + } + + final public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + CRPropertyDescriptor[] basic = new CRPropertyDescriptor[]{ + new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(DesignKit.i18nText("Fine-Design_Form_Form_Widget_Name")), + new CRPropertyDescriptor("enabled", this.data.getClass()).setI18NName(DesignKit.i18nText("Fine-Design_Report_Enabled")) + .setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + setEnabled(toData().isEnabled()); + } + }), + new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName( + DesignKit.i18nText("Fine-Design_Form_Widget_Visible")).setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + makeVisible(toData().isVisible()); + } + }), + new CRPropertyDescriptor("labelName", this.data.getClass(), "getLabelName", "setLabelName") + .setI18NName(DesignKit.i18nText("Fine-Design_Form_Label_Name")) + .putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced") + }; + Attribute[] attributes = attributes(); + CRPropertyDescriptor[] current = new CRPropertyDescriptor[attributes.length]; + for (int i = 0, len = attributes.length; i < len; i++) { + current[i] = attributes[i].toPropertyDescriptor(); + } + return ArrayKit.addAll(basic, current); + } + + /** + * 控件支持的属性以及操作设置这些属性的方法,使用反射调用属性的设置方法。 + * 示例:如果不显示的传入读取和写入方法,则默认调用"get+属性名"或者"set+属性名"的方法。 + * + * @return 控件支持的属性以及操作设置这些属性的方法集合 + */ + public abstract Attribute[] attributes(); + + /** + * 待说明 + * + * @return 待说明 + */ + public Widget toData() { + return this.data; + } + + /** + * 根据Widget的属性值初始化XCreator的属性值 + */ + @Override + protected void initXCreatorProperties() { + this.setEnabled(toData().isEnabled()); + } + + /** + * 待说明 + */ + public void recalculateChildrenSize() { + } + + + protected void makeVisible(boolean visible) { + + } + + public void paint(Graphics g) { + AlphaComposite composite = this.data.isVisible() ? (AlphaComposite) ((Graphics2D) g).getComposite() : AlphaComposite.getInstance(AlphaComposite.SRC_OVER, HALF_OPACITY); + ((Graphics2D) g).setComposite(composite); + super.paint(g); + } + + /** + * 重命名 + * + * @param designer 表单设计器 + * @param creator 当前组件 + */ + public void ChangeCreatorName(FormDesigner designer, XCreator creator) { + String oldName = creator.toData().getWidgetName(); + String value = JOptionPane.showInputDialog(designer, DesignKit.i18nText("Fine-Design_Form_Change_Widget_Name_Discription"), oldName); + if (value != null) { + designer.renameCreator(creator, value); + } + } +}