forked from fanruan/finekit
richie
5 years ago
4 changed files with 295 additions and 1 deletions
@ -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() { |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue