You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
276 lines
12 KiB
276 lines
12 KiB
package com.fr.design.widget.ui.designer.layout; |
|
|
|
import com.fr.base.io.IOFile; |
|
import com.fr.base.iofile.attr.WatermarkAttr; |
|
import com.fr.design.data.DataCreatorUI; |
|
import com.fr.design.designer.IntervalConstants; |
|
import com.fr.design.designer.creator.XCreator; |
|
import com.fr.design.designer.creator.XLayoutContainer; |
|
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; |
|
import com.fr.design.designer.creator.XWFitLayout; |
|
import com.fr.design.designer.creator.XWScaleLayout; |
|
import com.fr.design.designer.properties.items.FRFitConstraintsItems; |
|
import com.fr.design.designer.properties.items.FRLayoutTypeItems; |
|
import com.fr.design.designer.properties.items.Item; |
|
import com.fr.design.foldablepane.UIExpandablePane; |
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.gui.ispinner.UISpinner; |
|
import com.fr.design.gui.xpane.LayoutStylePane; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.layout.TableLayoutHelper; |
|
import com.fr.design.mainframe.FormDesigner; |
|
import com.fr.design.mainframe.FormSelectionUtils; |
|
import com.fr.design.mainframe.WidgetPropertyPane; |
|
import com.fr.design.mainframe.widget.accessibles.AccessibleBodyWatermarkEditor; |
|
import com.fr.design.utils.gui.UIComponentUtils; |
|
import com.fr.design.widget.FRWidgetFactory; |
|
import com.fr.design.widget.ui.designer.component.PaddingBoundPane; |
|
import com.fr.form.ui.LayoutBorderStyle; |
|
import com.fr.form.ui.Widget; |
|
import com.fr.form.ui.container.WAbsoluteBodyLayout; |
|
import com.fr.form.ui.container.WAbsoluteLayout; |
|
import com.fr.form.ui.container.WBodyLayoutType; |
|
import com.fr.form.ui.container.WFitLayout; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.general.act.BorderPacker; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.report.core.ReportUtils; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.DefaultComboBoxModel; |
|
import javax.swing.JPanel; |
|
import java.awt.BorderLayout; |
|
import java.awt.Component; |
|
import java.awt.Dimension; |
|
|
|
/** |
|
* Created by ibm on 2017/8/2. |
|
*/ |
|
public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout> { |
|
private static final int ADAPT_LABEL_MAX_WIDTH = 80; |
|
private XWFitLayout xWFitLayout; |
|
private WFitLayout wFitLayout; |
|
private UIComboBox layoutComboBox; |
|
private UIComboBox adaptComboBox; |
|
private UISpinner componentIntervel; |
|
private PaddingBoundPane paddingBound; |
|
private LayoutStylePane stylePane; |
|
private AccessibleBodyWatermarkEditor watermarkEditor; |
|
|
|
public FRFitLayoutDefinePane(XCreator xCreator) { |
|
super(xCreator); |
|
this.xWFitLayout = (XWFitLayout) xCreator; |
|
wFitLayout = xWFitLayout.toData(); |
|
initComponent(); |
|
} |
|
|
|
|
|
public void initComponent() { |
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
UIExpandablePane layoutExpandablePane = new UIExpandablePane( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout"), |
|
280, 20, |
|
createLayoutPane() |
|
); |
|
this.add(layoutExpandablePane, BorderLayout.NORTH); |
|
|
|
JPanel advancePane = createAdvancePane(); |
|
UIExpandablePane advanceExpandablePane = new UIExpandablePane( |
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), |
|
280, 20, |
|
advancePane |
|
); |
|
this.add(advanceExpandablePane, BorderLayout.CENTER); |
|
} |
|
|
|
public JPanel createAdvancePane() { |
|
JPanel contentPane0 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
stylePane = new LayoutStylePane(); |
|
contentPane0.add(stylePane, BorderLayout.NORTH); |
|
|
|
JPanel contentPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
contentPane0.add(contentPane1, BorderLayout.CENTER); |
|
|
|
watermarkEditor = new AccessibleBodyWatermarkEditor(); |
|
JPanel waterMarkPane = TableLayoutHelper.createGapTableLayoutPane( |
|
new Component[][]{ |
|
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark")), watermarkEditor} |
|
}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W3, IntervalConstants.INTERVAL_L1); |
|
waterMarkPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
|
contentPane1.add(waterMarkPane, BorderLayout.NORTH); |
|
|
|
paddingBound = new PaddingBoundPane(); |
|
contentPane1.add(paddingBound, BorderLayout.CENTER); |
|
|
|
return contentPane0; |
|
} |
|
|
|
public JPanel createLayoutPane() { |
|
JPanel containerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
layoutComboBox = initUIComboBox(FRLayoutTypeItems.ITEMS); |
|
adaptComboBox = initUIComboBox(FRFitConstraintsItems.ITEMS); |
|
JPanel adaptComboBoxPane = UIComponentUtils.wrapWithBorderLayoutPane(adaptComboBox); |
|
componentIntervel = new UISpinner(0, Integer.MAX_VALUE, 1, 0); |
|
JPanel componentIntervelPane = UIComponentUtils.wrapWithBorderLayoutPane(componentIntervel); |
|
|
|
UILabel adaptLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Component_Scale")); |
|
UILabel intervalLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Component_Interval")); |
|
|
|
JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane( |
|
new Component[][]{ |
|
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Layout_Type")), layoutComboBox}, |
|
{adaptLabel, adaptComboBoxPane}, |
|
{intervalLabel, componentIntervelPane} |
|
}, |
|
TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); |
|
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); |
|
containerPane.add(contentPane, BorderLayout.CENTER); |
|
|
|
return containerPane; |
|
} |
|
|
|
|
|
public UIComboBox initUIComboBox(Item[] items) { |
|
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
for (Item item : items) { |
|
model.addElement(item); |
|
} |
|
return new UIComboBox(model); |
|
} |
|
|
|
|
|
@Override |
|
public String title4PopupWindow() { |
|
return "fitLayout"; |
|
} |
|
|
|
@Override |
|
public void populateBean(WFitLayout ob) { |
|
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); |
|
XLayoutContainer rootLayout = selectedBodyLayout(formDesigner); |
|
if (rootLayout != formDesigner.getRootComponent() |
|
&& formDesigner.getSelectionModel().getSelection().getSelectedCreator() == formDesigner.getRootComponent()) { |
|
formDesigner.getSelectionModel().setSelectedCreators( |
|
FormSelectionUtils.rebuildSelection(xWFitLayout, new Widget[]{selectedBodyLayout(formDesigner).toData()})); |
|
|
|
} |
|
paddingBound.populate(ob); |
|
layoutComboBox.setSelectedIndex(ob.getBodyLayoutType().getTypeValue()); |
|
adaptComboBox.setSelectedIndex(ob.getCompState()); |
|
componentIntervel.setValue(ob.getCompInterval()); |
|
stylePane.populateBean((LayoutBorderStyle) ob.getBorderStyle()); |
|
watermarkEditor.setValue(ReportUtils.getWatermarkAttrFromTemplateAndGlobal(getCurrentIOFile())); |
|
} |
|
|
|
private XLayoutContainer selectedBodyLayout(FormDesigner formDesigner) { |
|
XLayoutContainer rootLayout = formDesigner.getRootComponent(); |
|
if (rootLayout.getComponentCount() == 1 && rootLayout.getXCreator(0).acceptType(XWAbsoluteBodyLayout.class)) { |
|
rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(0); |
|
} |
|
return rootLayout; |
|
} |
|
|
|
|
|
@Override |
|
public WFitLayout updateBean() { |
|
WFitLayout layout = (WFitLayout) creator.toData(); |
|
if (ComparatorUtils.equals(getGlobalName(), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Layout_Padding_Duplicate"))) { |
|
paddingBound.update(layout); |
|
} |
|
LayoutBorderStyle borderStyle = stylePane.updateBean(); |
|
if (borderStyle != null) { |
|
layout.setBorderStyle(borderStyle); |
|
} |
|
updateWatermark(); |
|
Item item = (Item) layoutComboBox.getSelectedItem(); |
|
Object value = item.getValue(); |
|
int state = 0; |
|
if (value instanceof Integer) { |
|
state = (Integer) value; |
|
} |
|
//todo 验证下 |
|
layout.setLayoutType(WBodyLayoutType.parse(state)); |
|
layout.setCompState(adaptComboBox.getSelectedIndex()); |
|
try { |
|
// 自适应布局切换到绝对布局 |
|
if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) { |
|
WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body"); |
|
wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED); |
|
// 切换布局类型时,保留body背景样式 |
|
wAbsoluteBodyLayout.setBorderStyle((BorderPacker) (layout.getBorderStyle().clone())); |
|
Component[] components = xWFitLayout.getComponents(); |
|
xWFitLayout.removeAll(); |
|
layout.resetStyle(); |
|
XWAbsoluteBodyLayout xwAbsoluteBodyLayout = xWFitLayout.getBackupParent() == null ? new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0, 0)) : (XWAbsoluteBodyLayout) xWFitLayout.getBackupParent(); |
|
xWFitLayout.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0); |
|
for (Component component : components) { |
|
XCreator xCreator = (XCreator) component; |
|
//部分控件被ScaleLayout包裹着,绝对布局里面要放出来 |
|
if (xCreator.acceptType(XWScaleLayout.class)) { |
|
if (xCreator.getComponentCount() > 0 && ((XCreator) xCreator.getComponent(0)).shouldScaleCreator()) { |
|
component = xCreator.getComponent(0); |
|
component.setBounds(xCreator.getBounds()); |
|
} |
|
} |
|
xwAbsoluteBodyLayout.add(component); |
|
} |
|
copyLayoutAttr(wFitLayout, xwAbsoluteBodyLayout.toData()); |
|
xWFitLayout.setBackupParent(xwAbsoluteBodyLayout); |
|
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); |
|
formDesigner.getSelectionModel().setSelectedCreators( |
|
FormSelectionUtils.rebuildSelection(xWFitLayout, new Widget[]{wAbsoluteBodyLayout})); |
|
|
|
if (xwAbsoluteBodyLayout.toData() != null) { |
|
xwAbsoluteBodyLayout.toData().setBorderStyle(wAbsoluteBodyLayout.getBorderStyle()); |
|
} |
|
xwAbsoluteBodyLayout.refreshStylePreviewEffect(); |
|
if (xWFitLayout.toData() != null) { |
|
xWFitLayout.toData().resetStyle(); |
|
} |
|
xWFitLayout.refreshStylePreviewEffect(); |
|
} |
|
} catch (Exception e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} |
|
|
|
int intervelValue = (int) componentIntervel.getValue(); |
|
if (xWFitLayout.canAddInterval(intervelValue)) { |
|
// 设置完间隔后,要同步处理界面组件,容器刷新后显示出对应效果 |
|
setLayoutGap(intervelValue); |
|
} |
|
|
|
return layout; |
|
} |
|
|
|
private void updateWatermark() { |
|
WatermarkAttr watermark = (WatermarkAttr) watermarkEditor.getValue(); |
|
if (watermark != null) { |
|
IOFile ioFile = getCurrentIOFile(); |
|
ioFile.addAttrMark(watermark); |
|
} |
|
} |
|
|
|
private IOFile getCurrentIOFile() { |
|
return WidgetPropertyPane.getInstance().getEditingFormDesigner().getTarget(); |
|
} |
|
|
|
private void setLayoutGap(int value) { |
|
int interval = wFitLayout.getCompInterval(); |
|
if (value != interval) { |
|
xWFitLayout.moveContainerMargin(); |
|
xWFitLayout.moveCompInterval(xWFitLayout.getAcualInterval()); |
|
wFitLayout.setCompInterval(value); |
|
xWFitLayout.addCompInterval(xWFitLayout.getAcualInterval()); |
|
} |
|
} |
|
|
|
@Override |
|
public DataCreatorUI dataUI() { |
|
return null; |
|
} |
|
|
|
}
|
|
|