Browse Source

适配新插件

master
richie 5 years ago
parent
commit
964de31a59
  1. 51
      src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java
  2. 225
      src/main/java/com/fanruan/api/design/work/form/creator/XOpenBorderStyleCreator.java
  3. 4
      src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java
  4. 14
      src/main/java/com/fanruan/api/util/RenderKit.java

51
src/main/java/com/fanruan/api/design/work/form/creator/Attribute.java

@ -2,6 +2,7 @@ package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.log.LogKit;
import com.fr.design.designer.creator.CRPropertyDescriptor;
import com.fr.stable.core.PropertyChangeListener;
import java.beans.IntrospectionException;
@ -9,15 +10,32 @@ import java.beans.IntrospectionException;
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
* 属性设置帮助类
*/
public class Attribute {
private CRPropertyDescriptor descriptor;
/**
* 创建一个属性描述器
*
* @param name 属性名
* @param beanClass 属性所属的对象类
* @return 属性描述器
*/
public static Attribute newAttribute(String name, Class<?> beanClass) {
return new Attribute(name, beanClass);
}
/**
* 创建一个属性描述器
*
* @param name 属性名
* @param beanClass 属性所属的对象类
* @param readMethod 属性的读方法
* @param writeMethod 属性的写方法
* @return 属性描述器
*/
public static Attribute newAttribute(String name, Class<?> beanClass, String readMethod, String writeMethod) {
return new Attribute(name, beanClass, readMethod, writeMethod);
}
@ -38,6 +56,12 @@ public class Attribute {
}
}
/**
* 设置属性包含的键值对
*
* @param name 属性名
* @param value 属性值
*/
public Attribute keyValue(String name, Object value) {
if (descriptor != null) {
descriptor.putKeyValue(name, value);
@ -45,6 +69,11 @@ public class Attribute {
return this;
}
/**
* 设置属性的显示名字
*
* @param i18nName 显示名字
*/
public Attribute i18n(String i18nName) {
if (descriptor != null) {
descriptor.setI18NName(i18nName);
@ -52,6 +81,11 @@ public class Attribute {
return this;
}
/**
* 设置属性的编辑类
*
* @param clazz 编辑类
*/
public Attribute editorClass(Class<?> clazz) {
if (descriptor != null) {
descriptor.setEditorClass(clazz);
@ -59,6 +93,11 @@ public class Attribute {
return this;
}
/**
* 设置属性的渲染类
*
* @param clazz 渲染类
*/
public Attribute rendererClass(Class<?> clazz) {
if (descriptor != null) {
descriptor.setRendererClass(clazz);
@ -66,6 +105,18 @@ public class Attribute {
return this;
}
/**
* 给属性变化添加监听器
*
* @param listener 监听器
*/
public Attribute listener(PropertyChangeListener listener) {
if (descriptor != null) {
descriptor.setPropertyChangeListener(listener);
}
return this;
}
/**
* 这个属于内部调用的方法外部不应该调用
*/

225
src/main/java/com/fanruan/api/design/work/form/creator/XOpenBorderStyleCreator.java

@ -0,0 +1,225 @@
package com.fanruan.api.design.work.form.creator;
import com.fanruan.api.design.work.form.macro.XCreatorConstants;
import com.fanruan.api.report.form.category.BaseBorderStyleWidget;
import com.fanruan.api.util.AssistKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.BaseFormula;
import com.fr.common.annotations.Compatible;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.designer.creator.XLabel;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.creator.XWTitleLayout;
import com.fr.design.mainframe.widget.editors.BackgroundEditor;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.mainframe.widget.renderer.BackgroundRenderer;
import com.fr.form.ui.Label;
import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.PaddingMargin;
import com.fr.form.ui.WidgetTitle;
import com.fr.form.ui.WidgetValue;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.act.BorderPacker;
import com.fr.general.act.TitlePacker;
import com.fr.stable.Constants;
import com.fr.stable.core.PropertyChangeAdapter;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/10/28
* 带有样式和边框设置的控件操作类
*/
public abstract class XOpenBorderStyleCreator extends XOpenCreator {
private static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150);
public XOpenBorderStyleCreator(BaseBorderStyleWidget widget) {
super(widget, BORDER_PREFERRED_SIZE);
}
public XOpenBorderStyleCreator(BaseBorderStyleWidget widget, Dimension size) {
super(widget, size);
}
@Override
public Attribute[] attributes() {
return new Attribute[]{
Attribute.newAttribute("borderStyle", toData().getClass())
.editorClass(borderStyleEditorClass())
.i18n("Fine-Design_Report_Engine_Style")
.keyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced")
.listener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
initStyle();
}
}),
Attribute.newAttribute("background", toData().getClass())
.editorClass(backgroundEditorClass())
.rendererClass(backgroundRendererClass())
.i18n("Fine-Design_Basic_Background")
.keyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced")
.listener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
initStyle();
}
})
};
}
/**
* 边框和样式编辑器可以重载该方法自定义自己的样式编辑器
*
* @return 边框和样式编辑器
*/
protected Class<?> borderStyleEditorClass() {
return WLayoutBorderStyleEditor.class;
}
/**
* 背景编辑器可以重载该方法自定义自己的背景编辑器
*
* @return 背景编辑器
*/
protected Class<?> backgroundEditorClass() {
return BackgroundEditor.class;
}
/**
* 背景渲染器可以重载该方法自定义自己的背景渲染器
*
* @return 背景渲染器
*/
protected Class<?> backgroundRendererClass() {
return BackgroundRenderer.class;
}
@Override
public BaseBorderStyleWidget toData() {
return (BaseBorderStyleWidget) data;
}
@Compatible
protected void initStyle() {
BorderPacker style = toData().getBorderStyle();
initBorderStyle();
if (AssistKit.equals(style.getType(), LayoutBorderStyle.TITLE)) {
initTitleStyle(style);
} else {
clearTitleWidget();
}
}
@Compatible
protected void initBorderStyle() {
BorderPacker style = toData().getBorderStyle();
if (style != null && style.getBorder() != Constants.LINE_NONE) {
this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.getBorderRadius()));
} else {
this.setBorder(DEFAULT_BORDER);
}
}
private void clearTitleWidget() {
if (acceptType(XWFitLayout.class)) {
return;
}
XWTitleLayout parent = (XWTitleLayout) this.getParent();
if (parent.getComponentCount() > 1) {
parent.remove(parent.getTitleCreator());
}
}
/**
* 设置样式为标题样式时对应组件加上标题
*
* @param style 样式
*/
private void initTitleStyle(BorderPacker style) {
if (style.getTitle() == null || style.getTitle().getTextObject() == null) {
return;
}
XWTitleLayout parent = (XWTitleLayout) this.getParent();
if (parent.getComponentCount() > 1) {
XLabel title = (XLabel) parent.getTitleCreator();
Label widget = title.toData();
updateTitleWidgetStyle(widget, style);
initXLabel(title);
return;
}
// 初始化标题控件
XLabel title = new XLabel(new Label(), new Dimension());
Label label = title.toData();
updateTitleWidgetStyle(label, style);
parent.add(title, WTitleLayout.TITLE);
// 初始化标题边框
initXLabel(title);
WTitleLayout layout = parent.toData();
layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds());
}
private void initXLabel(XLabel xLabel) {
Label label = xLabel.toData();
xLabel.setEnabled(label.isEnabled());
if (label.getBorder() != 0) {
this.setBorder(new UIRoundedBorder(label.getBorder(), label.getColor(), label.isCorner() ? 15 : 0));
} else {
this.setBorder(DEFAULT_BORDER);
}
}
/**
* 更新标题控件所有的样式
*/
private void updateTitleWidgetStyle(Label title, BorderPacker style) {
//标题的边框样式目前是取对应的控件的边框样式
title.setBorder(style.getBorder());
title.setColor(style.getColor());
// title.setCorner(style.isCorner());
TitlePacker wTitle = style.getTitle();
//设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个
title.setWidgetName(WidgetTitle.TITLE_NAME_INDEX + this.toData().getWidgetName());
title.setWidgetValue(getTitleValue(wTitle));
title.setFont(wTitle.getFrFont());
title.setTextalign(wTitle.getPosition());
title.setBackground(wTitle.getBackground());
}
private WidgetValue getTitleValue(TitlePacker wTitle) {
String content = String.valueOf(wTitle.getTextObject());
Object value = content.startsWith("=") ? BaseFormula.createFormulaBuilder().build(content) : content;
return new WidgetValue(value);
}
@Override
protected String getIconName() {
return StringKit.EMPTY;
}
/**
* 内边距
*
* @return 同上
*/
@Override
public Insets getInsets() {
PaddingMargin padding = toData().getMargin();
if (padding == null) {
return new Insets(0, 0, 0, 0);
}
return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight());
}
/**
* data属性改变触发其他操作
*/
public void firePropertyChange() {
}
}

4
src/main/java/com/fanruan/api/design/work/form/creator/XOpenCreator.java

@ -11,6 +11,7 @@ import com.fr.form.ui.Widget;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.beans.IntrospectionException;
@ -18,9 +19,12 @@ import java.beans.IntrospectionException;
* @author richie
* @version 10.0
* Created by richie on 2019-09-10
* 基础的控件操作类所有插件实现的控件操作类都应该继承这个类类实现
*/
public abstract class XOpenCreator extends XWidgetCreator {
public static final Border DEFAULT_BORDER = BorderFactory.createLineBorder(new Color(210, 210, 210), 1);
public XOpenCreator(Widget widget, Dimension size) {
super(widget, size);
}

14
src/main/java/com/fanruan/api/util/RenderKit.java

@ -2,6 +2,7 @@ package com.fanruan.api.util;
import com.fr.base.TemplateUtils;
import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
import java.util.Map;
@ -10,6 +11,19 @@ import java.util.Map;
*/
public class RenderKit {
/**
* 计算可扩展的参数, 例如{=ds1.select(id)} + abc
* 得到的是数组ArrayProvider {1abc, 2abc....}
*
* @param ca 算子
* @param tpl 需要计算的参数
* @return 计算结果
*/
public static Object renderExtendTpl(CalculatorProvider ca, String tpl) {
return TemplateUtils.renderExtendTpl(ca, tpl);
}
/**
* 根据参数, 来计算文档字符串
*

Loading…
Cancel
Save