Browse Source

REPORT-64445 新老自适应配置面板修改

feature/x
kerry 3 years ago
parent
commit
510117c2a7
  1. 78
      designer-base/src/main/java/com/fr/design/gui/ilable/UIAutoChangeLineLabel.java
  2. 6
      designer-base/src/main/java/com/fr/design/report/fit/AdaptiveFrmFitAttrModel.java
  3. 130
      designer-base/src/main/java/com/fr/design/report/fit/BaseFitAttrPane.java
  4. 9
      designer-base/src/main/java/com/fr/design/report/fit/FitAttrModel.java
  5. 11
      designer-base/src/main/java/com/fr/design/report/fit/FitType.java
  6. 128
      designer-base/src/main/java/com/fr/design/report/fit/FormFitAttrModelType.java
  7. 59
      designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java
  8. 9
      designer-base/src/main/java/com/fr/design/report/fit/FrmFitAttrModel.java
  9. 71
      designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java
  10. 172
      designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java
  11. 85
      designer-form/src/main/java/com/fr/design/fit/FormFitAttrAction.java
  12. 377
      designer-form/src/main/java/com/fr/design/fit/FormFitAttrPane.java
  13. 14
      designer-form/src/main/java/com/fr/design/mainframe/JForm.java
  14. 110
      designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRAbsoluteBodyLayoutDefinePane.java
  15. 52
      designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRAbsoluteLayoutDefinePane.java
  16. 118
      designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRFitLayoutDefinePane.java

78
designer-base/src/main/java/com/fr/design/gui/ilable/UIAutoChangeLineLabel.java

@ -0,0 +1,78 @@
package com.fr.design.gui.ilable;
import javax.swing.JLabel;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.util.ArrayList;
import java.util.List;
public class UIAutoChangeLineLabel extends JLabel {
private final String text;
private final int width;
public UIAutoChangeLineLabel(String text, int width) {
super(text);
this.text = text;
this.width = width;
}
@Override
public void doLayout() {
super.doLayout();
this.setText(wrapperHtmlText());
}
private String wrapperHtmlText() {
List<String> stringList = autoChangeLine(this.getWidth());
StringBuilder builder = new StringBuilder("<html>");
for (String s : stringList) {
//用THML标签进行拼接,以实现自动换行
builder.append(s).append("<br/>");
}
builder.append("</html>");
return builder.toString();
}
private List<String> autoChangeLine(int width) {
List<String> result = new ArrayList<>();
if (width <= 0) {
result.add(this.text);
} else {
char[] chars = this.text.toCharArray();
//获取字体计算大小
FontMetrics fontMetrics = this.getFontMetrics(this.getFont());
int start = 0;
int len = 0;
while (start + len < this.text.length()) {
while (true) {
len++;
if (start + len > this.text.length())
break;
if (fontMetrics.charsWidth(chars, start, len)
> width) {
break;
}
}
result.add(String.copyValueOf(chars, start, len - 1));
start = start + len - 1;
len = 0;
}
if (this.text.length() - start > 0) {
result.add(String.copyValueOf(chars, start, this.text.length() - start));
}
}
return result;
}
@Override
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();
List<String> stringList = autoChangeLine(width);
FontMetrics fontMetrics = this.getFontMetrics(this.getFont());
return new Dimension(preferredSize.width, fontMetrics.getHeight() * stringList.size());
}
}

6
designer-base/src/main/java/com/fr/design/report/fit/AdaptiveFrmFitAttrModel.java

@ -13,11 +13,7 @@ import com.fr.report.fit.ReportFitAttr;
public class AdaptiveFrmFitAttrModel extends AbstractFitAttrModelProvider { public class AdaptiveFrmFitAttrModel extends AbstractFitAttrModelProvider {
public FitType[] getFitTypes() { public FitType[] getFitTypes() {
return new FitType[]{ return new FitType[0];
FitType.DOUBLE_FIT,
FitType.HORIZONTAL_FIT,
FitType.NOT_FIT
};
} }
public String getFitName() { public String getFitName() {

130
designer-base/src/main/java/com/fr/design/report/fit/BaseFitAttrPane.java

@ -2,27 +2,17 @@ package com.fr.design.report.fit;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.report.fit.menupane.FitPreviewPane;
import com.fr.design.report.fit.menupane.FitRadioGroup;
import com.fr.design.report.fit.menupane.FontRadioGroup;
import com.fr.design.report.fit.provider.FitAttrModelProvider; import com.fr.design.report.fit.provider.FitAttrModelProvider;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.report.fit.ReportFitAttr; import com.fr.report.fit.ReportFitAttr;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -35,11 +25,8 @@ public abstract class BaseFitAttrPane extends BasicBeanPane<ReportFitAttr> {
protected UILabel belowSetLabel; protected UILabel belowSetLabel;
protected UIComboBox itemChoose; protected UIComboBox itemChoose;
protected java.util.List<FitAttrModel> fitAttrModelList = new ArrayList<>(); protected java.util.List<FitAttrModel> fitAttrModelList = new ArrayList<>();
private ReportFitConfigPane fitConfigPane;
public FontRadioGroup fontRadioGroup;
public FitRadioGroup adaptRadioGroup;
public JPanel attrJPanel;
public FitPreviewPane previewJPanel;
public FitAttrModel fitAttrModel; public FitAttrModel fitAttrModel;
private static final int BELOW_SET_COMPONENT_HSPACE = 8; private static final int BELOW_SET_COMPONENT_HSPACE = 8;
@ -64,128 +51,27 @@ public abstract class BaseFitAttrPane extends BasicBeanPane<ReportFitAttr> {
protected void populateModel(FitAttrModel fitAttrModel) { protected void populateModel(FitAttrModel fitAttrModel) {
this.fitAttrModel = fitAttrModel; this.fitAttrModel = fitAttrModel;
if (attrJPanel != null) { if (fitConfigPane != null) {
contentJPanel.remove(attrJPanel); contentJPanel.remove(fitConfigPane);
} }
if (previewJPanel != null) { this.fitConfigPane = fitAttrModel instanceof CptFitAttrModel ? new ReportFitConfigPane(fitAttrModel, true) : new FormFitConfigPane(fitAttrModel, true);
contentJPanel.remove(previewJPanel); contentJPanel.add(fitConfigPane);
} }
fontRadioGroup = new FontRadioGroup();
adaptRadioGroup = new FitRadioGroup();
initAttrJPanel();
initPreviewJPanel();
}
protected void initAttrJPanel() {
int colCount = fitAttrModel.getFitTypes().length + 1;
Component[][] components = new Component[2][colCount];
initFitRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, components[0]);
initFitRadioGroup(adaptRadioGroup, fitAttrModel.getFitName(), Arrays.stream(fitAttrModel.getFitTypes()).map(FitType::description).toArray(String[]::new), components[1]);
double[] rowSize = new double[2];
double[] columnSize = new double[colCount];
for (int i = 0; i < rowSize.length; i++) {
rowSize[i] = 20;
}
for (int i = 0; i < columnSize.length; i++) {
if (i == 0) {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth();
} else {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.column").getWidth();
}
}
attrJPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
attrJPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
contentJPanel.add(attrJPanel);
}
private void initFitRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) {
components[0] = new UILabel(name);
for (int i = 0; i < options.length; i++) {
if (options[i] != null) {
UIRadioButton fontFitRadio = new UIRadioButton(options[i]);
fitRadioGroup.add(fontFitRadio);
components[i + 1] = fontFitRadio;
} else {
components[i + 1] = null;
}
}
fitRadioGroup.addActionListener(getPreviewActionListener());
}
protected ActionListener getPreviewActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshPreviewJPanel();
}
};
}
protected void refreshPreviewJPanel() {
String previewIndex = getPreviewIndex();
previewJPanel.refreshPreview(previewIndex, fontRadioGroup.isEnabled());
}
protected String getPreviewIndex() {
return getStateInPC(adaptRadioGroup.getSelectRadioIndex()) + "" + fontRadioGroup.getSelectRadioIndex();
}
protected void initPreviewJPanel() {
previewJPanel = new FitPreviewPane();
previewJPanel.setBorder(BorderFactory.createEmptyBorder(0, getPreviewJPanelLeft(), 0, 0));
contentJPanel.add(previewJPanel);
}
private int getPreviewJPanelLeft() {
int left = 0;
if (belowSetLabel.getPreferredSize() != null) {
left = belowSetLabel.getPreferredSize().width + BELOW_SET_COMPONENT_HSPACE;
}
return left;
}
protected int getStateInPC(int index) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
return fitTypes[index].getState();
}
protected int getOptionIndex(int state) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
for (int i = 0; i < fitTypes.length; i++) {
if (ComparatorUtils.equals(state, fitTypes[i].getState())) {
return i;
}
}
return 0;
}
@Override @Override
public void populateBean(ReportFitAttr ob) { public void populateBean(ReportFitAttr ob) {
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1); this.fitConfigPane.populateBean(ob);
adaptRadioGroup.selectIndexButton(getOptionIndex(ob.fitStateInPC()));
refreshPreviewJPanel();
} }
@Override @Override
public ReportFitAttr updateBean() { public ReportFitAttr updateBean() {
ReportFitAttr reportFitAttr = new ReportFitAttr(); return this.fitConfigPane.updateBean();
reportFitAttr.setFitFont(fontRadioGroup.isFontFit());
reportFitAttr.setFitStateInPC(getStateInPC(adaptRadioGroup.getSelectRadioIndex()));
return reportFitAttr;
} }
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
super.setEnabled(enabled); super.setEnabled(enabled);
fontRadioGroup.setEnabled(enabled); this.fitConfigPane.setEnabled(enabled);
adaptRadioGroup.setEnabled(enabled);
refreshPreviewJPanel();
} }
@Override @Override

9
designer-base/src/main/java/com/fr/design/report/fit/FitAttrModel.java

@ -3,6 +3,8 @@ package com.fr.design.report.fit;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.report.fit.ReportFitAttr; import com.fr.report.fit.ReportFitAttr;
import java.util.Arrays;
public interface FitAttrModel { public interface FitAttrModel {
/** /**
* @Description 名称比如普通报表决策报表等 * @Description 名称比如普通报表决策报表等
@ -19,6 +21,12 @@ public interface FitAttrModel {
**/ **/
FitType[] getFitTypes(); FitType[] getFitTypes();
/**
* @Description 表格自适应选项名称集合
**/
default String[] getFitTypeNames(){
return Arrays.stream(getFitTypes()).map(FitType::description).toArray(String[]::new);
}
/** /**
* @Description 获取全局的自适应属性 * @Description 获取全局的自适应属性
@ -41,4 +49,5 @@ public interface FitAttrModel {
* @param: jTemplate * @param: jTemplate
**/ **/
boolean isAvailable(JTemplate jTemplate); boolean isAvailable(JTemplate jTemplate);
} }

11
designer-base/src/main/java/com/fr/design/report/fit/FitType.java

@ -60,6 +60,17 @@ public enum FitType {
return DEFAULT; return DEFAULT;
} }
public static FitType parseByFitState(int state) {
for (FitType attrState : values()) {
if (attrState.state == state) {
return attrState;
}
}
return DEFAULT;
}
public int getState() { public int getState() {
return this.state; return this.state;
} }

128
designer-base/src/main/java/com/fr/design/report/fit/FormFitAttrModelType.java

@ -0,0 +1,128 @@
package com.fr.design.report.fit;
import com.fr.design.designer.properties.items.Item;
import com.fr.form.fit.common.LightTool;
import com.fr.form.main.BodyScaleAttrTransformer;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WBodyLayoutType;
import com.fr.form.ui.container.WFitLayout;
public enum FormFitAttrModelType {
PLAIN_FORM_FIT_ATTR_MODEL {
@Override
public FitAttrModel getFitAttrModel() {
return new FrmFitAttrModel();
}
@Override
public Item[] getFitLayoutScaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN)};
}
@Override
public Item[] getAbsoluteLayoutSaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode_Fit"), WAbsoluteLayout.STATE_FIT),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode_Fixed"), WAbsoluteLayout.STATE_FIXED)
};
}
@Override
public int getScaleAttrShowIndex(WFitLayout wFitLayout) {
int scale = wFitLayout.getScaleAttr();
if (wFitLayout.getBodyLayoutType() == WBodyLayoutType.FIT) {
return BodyScaleAttrTransformer.getFitBodyCompStateFromScaleAttr(scale);
} else {
return BodyScaleAttrTransformer.getAbsoluteBodyCompStateFromScaleAttr(scale);
}
}
@Override
public int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType) {
if (wBodyLayoutType == WBodyLayoutType.FIT) {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else {
return WFitLayout.SCALE_HOR;
}
} else {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else {
return WFitLayout.SCALE_NO;
}
}
}
},
NEW_FORM_FIT_ATTR_MODEL {
@Override
public FitAttrModel getFitAttrModel() {
return new AdaptiveFrmFitAttrModel();
}
@Override
public Item[] getFitLayoutScaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode_Fixed"), 2)};
}
@Override
public Item[] getAbsoluteLayoutSaleAttr() {
return new Item[]{
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Bidirectional_Adaptive"), WFitLayout.STATE_FULL),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Horizontal_Adaptive"), WFitLayout.STATE_ORIGIN),
new Item(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode_Fixed"), 2)};
}
@Override
public int getScaleAttrShowIndex(WFitLayout wFitLayout) {
int scale = wFitLayout.getScaleAttr();
if (scale == WFitLayout.SCALE_NO) {
return 2;
} else if (scale == WFitLayout.SCALE_HOR) {
return 1;
} else {
return 0;
}
}
@Override
public int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType) {
if (showIndex == 0) {
return WFitLayout.SCALE_FULL;
} else if (showIndex == 1) {
return WFitLayout.SCALE_HOR;
} else {
return WFitLayout.SCALE_NO;
}
}
};
public abstract FitAttrModel getFitAttrModel();
public abstract Item[] getFitLayoutScaleAttr();
public abstract Item[] getAbsoluteLayoutSaleAttr();
public abstract int getScaleAttrShowIndex(WFitLayout wFitLayout);
public abstract int parseScaleAttrFromShowIndex(int showIndex, WBodyLayoutType wBodyLayoutType);
public static FormFitAttrModelType parse(Form form) {
return LightTool.containNewFormFlag(form) ? NEW_FORM_FIT_ATTR_MODEL : PLAIN_FORM_FIT_ATTR_MODEL;
}
}

59
designer-base/src/main/java/com/fr/design/report/fit/FormFitConfigPane.java

@ -0,0 +1,59 @@
package com.fr.design.report.fit;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
public class FormFitConfigPane extends ReportFitConfigPane {
private static final int DEFAULT_ITEM = 0;
private static final int CUSTOM_ITEM = 1;
public FormFitConfigPane(FitAttrModel fitAttrModel) {
this(fitAttrModel, false);
}
public FormFitConfigPane(FitAttrModel fitAttrModel, boolean globalConfig) {
super(fitAttrModel, globalConfig);
}
protected JPanel initECConfigPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
if (fitAttrModel.getFitTypeNames().length != 0) {
Component[] ecComponents = new Component[fitAttrModel.getFitTypeNames().length + 1];
initRadioGroup(ecConfigRadioGroup, fitAttrModel.getFitName(), fitAttrModel.getFitTypeNames(), ecComponents);
jPanel.add(createSubAttrPane(ecComponents), BorderLayout.CENTER);
jPanel.add(createTipPane(), BorderLayout.SOUTH);
}
return jPanel;
}
private JPanel createTipPane() {
JPanel jPanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true);
UILabel label1 = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_Tip1"));
jPanel.add(label1);
label1.setForeground(Color.lightGray);
UILabel label2 = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_Tip2"));
jPanel.add(label2);
label2.setForeground(Color.lightGray);
return jPanel;
}
protected void refreshPreviewJPanel() {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit());
}
protected void populateECConfigRadioGroup(int fitStateInPC) {
ecConfigRadioGroup.selectIndexButton(fitStateInPC == 0 ? DEFAULT_ITEM : CUSTOM_ITEM);
}
protected void updateECConfigRadioGroup(ReportFitAttr reportFitAttr) {
reportFitAttr.setFitStateInPC(ecConfigRadioGroup.getSelectRadioIndex());
}
}

9
designer-base/src/main/java/com/fr/design/report/fit/FrmFitAttrModel.java

@ -17,7 +17,7 @@ public class FrmFitAttrModel implements FitAttrModel {
@Override @Override
public String getFitName() { public String getFitName() {
return Toolkit.i18nText("Fine-Designer_Fit-Element"); return Toolkit.i18nText("Fine-Design_Form_PC_FIT_Config_EC_Label");
} }
public FitType[] getFitTypes() { public FitType[] getFitTypes() {
@ -29,6 +29,13 @@ public class FrmFitAttrModel implements FitAttrModel {
}; };
} }
@Override
public String[] getFitTypeNames() {
return new String[]{
Toolkit.i18nText("Fine-Designer_Fit-Default"), Toolkit.i18nText("Fine-Design_Basic_Custom")
};
}
@Override @Override
public ReportFitAttr getGlobalReportFitAttr() { public ReportFitAttr getGlobalReportFitAttr() {
return ReportFitConfig.getInstance().getFrmFitAttr(); return ReportFitConfig.getInstance().getFrmFitAttr();

71
designer-base/src/main/java/com/fr/design/report/fit/NewFitPreviewPane.java

@ -0,0 +1,71 @@
package com.fr.design.report.fit;
import com.fr.base.GraphHelper;
import com.fr.general.FRFont;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
public class NewFitPreviewPane extends JPanel {
private boolean fitFont = false;
private FitType fitType = FitType.DOUBLE_FIT;
private static final Color DEFAULT_PAINT_COLOR = Color.decode("#419BF9");
private static final int FIT_FONT_SIZE = 15;
private static final int NO_FIT_FONT_SIZE = 9;
private static final Dimension NO_FIT_CONTAINER_DIMENSION = new Dimension(200, 136);
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.GRAY);
GraphHelper.drawRect(g, 1, 1, this.getWidth() - 2, this.getHeight() - 2);
g.setColor(DEFAULT_PAINT_COLOR);
FRFont textFont = FRFont.getInstance(FRFont.DEFAULT_FONTNAME, Font.PLAIN, fitFont ? FIT_FONT_SIZE : NO_FIT_FONT_SIZE);
g.setFont(textFont);
Dimension dimension = calculateCellDimension();
GraphHelper.drawLine(g, 1, dimension.height, dimension.width * 2 - 1, dimension.height);
GraphHelper.drawLine(g, dimension.width, 1, dimension.width, dimension.height * 2 - 1);
GraphHelper.drawRect(g, 1, 1, dimension.width * 2 - 2, dimension.height * 2 - 2);
double startX = calculateTextDrawStartX(dimension.width, this.getFontMetrics(textFont), "text1");
double startY = calculateTextDrawStartY(dimension.height);
GraphHelper.drawString(g, "text1", startX, startY);
GraphHelper.drawString(g, "text2", dimension.width + startX, startY);
GraphHelper.drawString(g, "text3", startX, dimension.height + startY);
GraphHelper.drawString(g, "text4", dimension.width + startX, dimension.height + startY);
}
private Dimension calculateCellDimension() {
if (fitType == FitType.DOUBLE_FIT) {
return new Dimension(this.getWidth() / 2, this.getHeight() / 2);
} else if (fitType == FitType.NOT_FIT) {
return new Dimension(NO_FIT_CONTAINER_DIMENSION.width / 2, NO_FIT_CONTAINER_DIMENSION.height / 2);
} else {
return new Dimension(this.getWidth() / 2, NO_FIT_CONTAINER_DIMENSION.height / 2);
}
}
private double calculateTextDrawStartX(int containerWidth, FontMetrics fontMetrics, String text) {
return (containerWidth - fontMetrics.stringWidth(text)) / 2.0D;
}
private double calculateTextDrawStartY(int containerHeight) {
return containerHeight / 2.0D;
}
public void refreshPreview(boolean fitFont, FitType fitType) {
this.fitFont = fitFont;
this.fitType = fitType;
repaint();
}
public void refreshPreview(boolean fitFont) {
this.fitFont = fitFont;
repaint();
}
}

172
designer-base/src/main/java/com/fr/design/report/fit/ReportFitConfigPane.java

@ -0,0 +1,172 @@
package com.fr.design.report.fit;
import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.report.fit.menupane.FitRadioGroup;
import com.fr.design.report.fit.menupane.FontRadioGroup;
import com.fr.general.ComparatorUtils;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static com.fr.design.i18n.Toolkit.i18nText;
public class ReportFitConfigPane extends JPanel {
public FontRadioGroup fontRadioGroup;
public FitRadioGroup ecConfigRadioGroup;
protected NewFitPreviewPane previewJPanel;
protected FitAttrModel fitAttrModel;
protected boolean globalConfig;
public ReportFitConfigPane(FitAttrModel fitAttrModel, boolean globalConfig) {
this.fitAttrModel = fitAttrModel;
this.globalConfig = globalConfig;
initComponent();
}
private void initComponent() {
JPanel contentJPanel = FRGUIPaneFactory.createVerticalFlowLayout_Pane(false, FlowLayout.LEFT, 0, 0);
this.add(contentJPanel);
fontRadioGroup = new FontRadioGroup();
ecConfigRadioGroup = new FitRadioGroup();
contentJPanel.add(initAttrJPanel());
contentJPanel.add(initPreviewJPanel());
}
private JPanel initAttrJPanel() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Component[] fontComponents = new Component[3];
initRadioGroup(fontRadioGroup, i18nText("Fine-Designer_Fit-Font"), new String[]{i18nText("Fine-Designer_Fit"), i18nText("Fine-Designer_Fit-No")}, fontComponents);
jPanel.add(createSubAttrPane(fontComponents), BorderLayout.NORTH);
jPanel.add(initECConfigPane(), BorderLayout.CENTER);
return jPanel;
}
protected JPanel initECConfigPane() {
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane();
Component[] ecComponents = new Component[fitAttrModel.getFitTypeNames().length + 1];
initRadioGroup(ecConfigRadioGroup, fitAttrModel.getFitName(), fitAttrModel.getFitTypeNames(), ecComponents);
jPanel.add(createSubAttrPane(ecComponents), BorderLayout.CENTER);
return jPanel;
}
protected JPanel createSubAttrPane(Component[] components) {
double[] rowSize = new double[]{20};
double[] columnSize = new double[components.length];
for (int i = 0; i < columnSize.length; i++) {
if (i == 0) {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth();
} else {
columnSize[i] = DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.column").getWidth();
}
}
JPanel attrJPanel = TableLayoutHelper.createTableLayoutPane(new Component[][]{components}, rowSize, columnSize);
attrJPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
return attrJPanel;
}
protected void initRadioGroup(FitRadioGroup fitRadioGroup, String name, String[] options, Component[] components) {
components[0] = new UILabel(name);
for (int i = 0; i < options.length; i++) {
if (options[i] != null) {
UIRadioButton fontFitRadio = new UIRadioButton(options[i]);
fitRadioGroup.add(fontFitRadio);
components[i + 1] = fontFitRadio;
} else {
components[i + 1] = null;
}
}
fitRadioGroup.addActionListener(getPreviewActionListener());
}
private ActionListener getPreviewActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshPreviewJPanel();
}
};
}
public void refreshPreviewJPanel(FitType fitType) {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), fitType);
}
protected void refreshPreviewJPanel() {
previewJPanel.refreshPreview(fontRadioGroup.isFontFit(), FitType.parse(updateBean()));
}
private JPanel initPreviewJPanel() {
JPanel wrapperPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
previewJPanel = new NewFitPreviewPane();
wrapperPane.add(previewJPanel, BorderLayout.CENTER);
int leftIndent = globalConfig ? (int) DesignSizeI18nManager.getInstance().i18nDimension("com.fr.design.report.fit.firstColumn").getWidth() : 0;
wrapperPane.setBorder(BorderFactory.createEmptyBorder(0, leftIndent, 0, 0));
wrapperPane.setPreferredSize(new Dimension(300 + leftIndent, 204));
return wrapperPane;
}
public void populateBean(ReportFitAttr ob) {
fontRadioGroup.selectIndexButton(ob.isFitFont() ? 0 : 1);
populateECConfigRadioGroup(ob.fitStateInPC());
refreshPreviewJPanel();
}
protected void populateECConfigRadioGroup(int fitStateInPC){
ecConfigRadioGroup.selectIndexButton(getOptionIndex(fitStateInPC));
}
protected void updateECConfigRadioGroup(ReportFitAttr reportFitAttr){
reportFitAttr.setFitStateInPC(getStateInPC(ecConfigRadioGroup.getSelectRadioIndex()));
}
public ReportFitAttr updateBean() {
ReportFitAttr reportFitAttr = new ReportFitAttr();
reportFitAttr.setFitFont(fontRadioGroup.isFontFit());
updateECConfigRadioGroup(reportFitAttr);
return reportFitAttr;
}
protected int getStateInPC(int index) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
if (index > fitTypes.length - 1) {
return index;
}
return fitTypes[index].getState();
}
protected int getOptionIndex(int state) {
FitType[] fitTypes = fitAttrModel.getFitTypes();
for (int i = 0; i < fitTypes.length; i++) {
if (ComparatorUtils.equals(state, fitTypes[i].getState())) {
return i;
}
}
return 0;
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
fontRadioGroup.setEnabled(enabled);
ecConfigRadioGroup.setEnabled(enabled);
}
}

85
designer-form/src/main/java/com/fr/design/fit/FormFitAttrAction.java

@ -0,0 +1,85 @@
package com.fr.design.fit;
import com.fr.design.actions.JTemplateAction;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.UIDialog;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.MenuKeySet;
import com.fr.design.report.fit.FormFitAttrModelType;
import com.fr.form.main.Form;
import com.fr.report.fit.FitProvider;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.KeyStroke;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
public class FormFitAttrAction extends JTemplateAction {
private static final MenuKeySet REPORT_FIT_ATTR = new MenuKeySet() {
@Override
public char getMnemonic() {
return 'T';
}
@Override
public String getMenuName() {
return Toolkit.i18nText("Fine-Designer_PC_Fit_Attr");
}
@Override
public KeyStroke getKeyStroke() {
return null;
}
};
public FormFitAttrAction(JTemplate jTemplate) {
super(jTemplate);
initMenuStyle();
}
private void initMenuStyle() {
this.setMenuKeySet(REPORT_FIT_ATTR);
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon("/com/fr/design/images/reportfit/fit");
}
/**
* Action触发事件
*
* @param e 事件
*/
@Override
public void actionPerformed(ActionEvent e) {
final JTemplate jwb = getEditingComponent();
if (jwb == null || !(jwb.getTarget() instanceof Form)) {
return;
}
JForm jForm = (JForm) jwb;
Form wbTpl = jForm.getTarget();
ReportFitAttr fitAttr = wbTpl.getReportFitAttr();
FormFitAttrPane formFitAttrPane = new FormFitAttrPane(jForm, FormFitAttrModelType.parse(wbTpl));
showReportFitDialog(fitAttr, jwb, wbTpl, formFitAttrPane);
}
private void showReportFitDialog(ReportFitAttr fitAttr, final JTemplate jwb, final FitProvider wbTpl, final BasicBeanPane<ReportFitAttr> attrPane) {
attrPane.populateBean(fitAttr);
UIDialog dialog = attrPane.showWindowWithCustomSize(DesignerContext.getDesignerFrame(), new DialogActionAdapter() {
@Override
public void doOk() {
fireEditingOk(jwb, wbTpl, attrPane.updateBean(), fitAttr);
}
}, new Dimension(660, 600));
dialog.setVisible(true);
}
private void fireEditingOk(final JTemplate jwb, final FitProvider wbTpl, ReportFitAttr newReportFitAttr, ReportFitAttr oldReportFitAttr) {
wbTpl.setReportFitAttr(newReportFitAttr);
jwb.fireTargetModified();
}
}

377
designer-form/src/main/java/com/fr/design/fit/FormFitAttrPane.java

@ -0,0 +1,377 @@
package com.fr.design.fit;
import com.fr.design.beans.BasicBeanPane;
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.XOccupiedLayout;
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.FRLayoutTypeItems;
import com.fr.design.designer.properties.items.Item;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
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.JForm;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.report.fit.FitType;
import com.fr.design.report.fit.FormFitAttrModelType;
import com.fr.design.report.fit.FormFitConfigPane;
import com.fr.design.report.fit.ReportFitConfigPane;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.form.main.Form;
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.form.ui.container.WSortLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.act.BorderPacker;
import com.fr.log.FineLoggerFactory;
import com.fr.report.fit.ReportFitAttr;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import static com.fr.design.i18n.Toolkit.i18nText;
import static javax.swing.JOptionPane.*;
public class FormFitAttrPane extends BasicBeanPane<ReportFitAttr> {
private UIComboBox layoutComboBox;
private UIComboBox scaleComboBox;
private FormFitAttrModelType fitAttrModelType;
protected UIComboBox itemChoose;
private JForm jForm;
private ReportFitConfigPane fitConfigPane;
public FormFitAttrPane(JForm jForm, FormFitAttrModelType fitAttrModelType) {
this.fitAttrModelType = fitAttrModelType;
this.jForm = jForm;
initComponents();
}
private void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(12, 5, 0, 5));
this.add(createReportFitSettingPane(), BorderLayout.CENTER);
this.add(createReportLayoutSettingPane(), BorderLayout.NORTH);
}
private JPanel createReportLayoutSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Form_PC_Fit_Config_Layout"));
jPanel.add(createAreaScalePane(), BorderLayout.CENTER);
jPanel.setPreferredSize(new Dimension(640, 84));
return jPanel;
}
protected String[] getItemNames() {
return new String[]{Toolkit.i18nText("Fine-Design_Report_Using_Server_Report_View_Settings"),
Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single")};
}
private JPanel createReportFitSettingPane() {
JPanel jPanel = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Form_PC_Fit_Config_Content_Attr"));
JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
jPanel.add(contentPane, BorderLayout.CENTER);
UILabel label = new UILabel(Toolkit.i18nText("Fine-Design_Form_PC_Fit_Config_Settings"));
label.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
contentPane.add(label, BorderLayout.WEST);
label.setPreferredSize(new Dimension(100, 0));
label.setVerticalAlignment(SwingConstants.TOP);
itemChoose = new UIComboBox(getItemNames());
itemChoose.setPreferredSize(new Dimension(160, 20));
Form form = jForm.getTarget();
itemChoose.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
if (isTemplateSingleSet()) {
if (form != null) {
ReportFitAttr fitAttr = form.getReportFitAttr();
populate(fitAttr);
}
} else {
populate(fitAttrModelType.getFitAttrModel().getGlobalReportFitAttr());
}
}
}
});
JPanel centerPane = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true);
centerPane.add(itemChoose);
centerPane.add(fitConfigPane = new FormFitConfigPane(this.fitAttrModelType.getFitAttrModel()));
contentPane.add(centerPane, BorderLayout.CENTER);
return jPanel;
}
public void populate(ReportFitAttr reportFitAttr) {
if (reportFitAttr == null) {
reportFitAttr = fitAttrModelType.getFitAttrModel().getGlobalReportFitAttr();
}
this.setEnabled(isTemplateSingleSet());
fitConfigPane.populateBean(reportFitAttr);
}
public ReportFitAttr updateBean() {
updateLayoutType();
if (!isTemplateSingleSet()) {
return null;
} else {
return fitConfigPane.updateBean();
}
}
private void updateLayoutType() {
XLayoutContainer xLayoutContainer = this.jForm.getRootComponent();
if (xLayoutContainer == null || !xLayoutContainer.acceptType(XWFitLayout.class)) {
return;
}
XWFitLayout xwFitLayout = (XWFitLayout) xLayoutContainer;
WFitLayout wFitLayout = xwFitLayout.toData();
int state = layoutComboBox.getSelectedIndex();
WBodyLayoutType selectType = WBodyLayoutType.parse(state);
if (selectType != wFitLayout.getBodyLayoutType()) {
wFitLayout.setLayoutType(selectType);
//从自适应布局切换到绝对布局
if (selectType == WBodyLayoutType.ABSOLUTE) {
switchLayoutFromFit2Absolute(xwFitLayout);
} else {
//从绝对布局切换到自适应布局
switchLayoutFromAbsolute2Fit(xwFitLayout);
}
}
wFitLayout.setCompatibleScaleAttr(fitAttrModelType.parseScaleAttrFromShowIndex(this.scaleComboBox.getSelectedIndex(), wFitLayout.getBodyLayoutType()));
}
private void switchLayoutFromFit2Absolute(XWFitLayout xWFitLayout) {
try {
WFitLayout layout = xWFitLayout.toData();
WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body");
wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED);
// 切换布局类型时,保留body背景样式
wAbsoluteBodyLayout.setBorderStyleFollowingTheme(layout.isBorderStyleFollowingTheme());
wAbsoluteBodyLayout.setBorderStyle((BorderPacker) (layout.getBorderStyle().clone()));
Component[] components = xWFitLayout.getComponents();
Rectangle[] backupBounds = getBackupBoundsFromFitLayout(xWFitLayout);
xWFitLayout.removeAll();
layout.resetStyle();
XWAbsoluteBodyLayout xwAbsoluteBodyLayout = xWFitLayout.getBackupParent() == null ? new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0, 0)) : (XWAbsoluteBodyLayout) xWFitLayout.getBackupParent();
xWFitLayout.setFixLayout(false);
xWFitLayout.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0);
for (int i = 0; i < components.length; i++) {
XCreator xCreator = (XCreator) components[i];
xCreator.setBounds(backupBounds[i]);
//部分控件被ScaleLayout包裹着,绝对布局里面要放出来
if (xCreator.acceptType(XWScaleLayout.class)) {
if (xCreator.getComponentCount() > 0 && ((XCreator) xCreator.getComponent(0)).shouldScaleCreator()) {
Component component = xCreator.getComponent(0);
component.setBounds(xCreator.getBounds());
}
}
if (!xCreator.acceptType(XOccupiedLayout.class)) {
xwAbsoluteBodyLayout.add(xCreator);
}
}
copyLayoutAttr(layout, 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().setBorderStyleFollowingTheme(wAbsoluteBodyLayout.isBorderStyleFollowingTheme());
xwAbsoluteBodyLayout.toData().setBorderStyle(wAbsoluteBodyLayout.getBorderStyle());
}
xwAbsoluteBodyLayout.refreshStylePreviewEffect();
if (xWFitLayout.toData() != null) {
xWFitLayout.toData().resetStyle();
}
xWFitLayout.refreshStylePreviewEffect();
formDesigner.switchBodyLayout(xwAbsoluteBodyLayout);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private Rectangle[] getBackupBoundsFromFitLayout(XWFitLayout xWFitLayout) {
int count = xWFitLayout.getComponentCount();
Rectangle[] rectangles = new Rectangle[count];
for (int i = 0; i < count; i++) {
rectangles[i] = xWFitLayout.getComponent(i).getBounds();
}
return rectangles;
}
protected void copyLayoutAttr(WSortLayout srcLayout, WSortLayout destLayout) {
destLayout.clearListeners();
destLayout.clearMobileWidgetList();
for (int i = 0, len = srcLayout.getMobileWidgetListSize(); i < len; i++) {
destLayout.addMobileWidget(srcLayout.getMobileWidget(i));
}
destLayout.setSorted(true);
for (int i = 0, len = srcLayout.getListenerSize(); i < len; i++) {
destLayout.addListener(srcLayout.getListener(i));
}
srcLayout.clearListeners();
srcLayout.clearMobileWidgetList();
}
private void switchLayoutFromAbsolute2Fit(XWFitLayout xwFitLayout) {
XWAbsoluteBodyLayout xwAbsoluteBodyLayout = getAbsoluteBodyLayout(xwFitLayout);
if (xwAbsoluteBodyLayout == null) {
return;
}
WAbsoluteBodyLayout layout = xwAbsoluteBodyLayout.toData();
WFitLayout wFitLayout = xwFitLayout.toData();
wFitLayout.resetStyle();
xwFitLayout.switch2FitBodyLayout(xwAbsoluteBodyLayout);
// 切换布局类型时,保留body背景样式
if (wFitLayout != null) {
wFitLayout.setBorderStyleFollowingTheme(layout.isBorderStyleFollowingTheme());
wFitLayout.setBorderStyle(layout.getBorderStyle());
}
copyLayoutAttr(layout, xwFitLayout.toData());
copyLayoutAttr(layout, xwFitLayout.toData());
xwFitLayout.refreshStylePreviewEffect();
}
private XWAbsoluteBodyLayout getAbsoluteBodyLayout(XWFitLayout xwFitLayout) {
if (xwFitLayout != null && xwFitLayout.getComponentCount() > 0) {
Component component = xwFitLayout.getComponent(0);
if (component instanceof XWAbsoluteBodyLayout) {
return (XWAbsoluteBodyLayout) component;
}
}
return null;
}
private JPanel createAreaScalePane() {
initLayoutComboBox();
UILabel layoutTypeLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Layout_Type"));
UILabel scaleModeLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_PC_Fit_Config_Scale_Setting"));
Component[][] components = new Component[][]{
{layoutTypeLabel, layoutComboBox},
{scaleModeLabel, scaleComboBox}
};
JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane(components,
TableLayoutHelper.FILL_LASTCOLUMN, 20, IntervalConstants.INTERVAL_L1);
JPanel containerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
containerPane.add(contentPane, BorderLayout.CENTER);
return containerPane;
}
public void initLayoutComboBox() {
Item[] items = FRLayoutTypeItems.ITEMS;
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Item item : items) {
model.addElement(item);
}
scaleComboBox = new UIComboBox(model);
scaleComboBox.setModel(new DefaultComboBoxModel(fitAttrModelType.getFitLayoutScaleAttr()));
layoutComboBox = new UIComboBox(model);
layoutComboBox.setPreferredSize(new Dimension(160, 20));
scaleComboBox.setPreferredSize(new Dimension(160, 20));
WFitLayout wFitLayout = jForm.getTarget().getWFitLayout();
layoutComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selectIndex = layoutComboBox.getSelectedIndex();
if (selectIndex == 0) {
if (wFitLayout.getBodyLayoutType() == WBodyLayoutType.ABSOLUTE) {
int selVal = FineJOptionPane.showConfirmDialog(
FormFitAttrPane.this,
Toolkit.i18nText("Fine-Design_Form_Layout_Switch_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Alert"),
OK_CANCEL_OPTION,
WARNING_MESSAGE
);
if (OK_OPTION != selVal) {
layoutComboBox.setSelectedIndex(1);
return;
}
}
scaleComboBox.setModel(new DefaultComboBoxModel(fitAttrModelType.getFitLayoutScaleAttr()));
} else {
scaleComboBox.setModel(new DefaultComboBoxModel(fitAttrModelType.getAbsoluteLayoutSaleAttr()));
}
scaleComboBox.setSelectedIndex(0);
}
});
scaleComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
WBodyLayoutType selectBodyType = WBodyLayoutType.parse(layoutComboBox.getSelectedIndex());
int state = fitAttrModelType.parseScaleAttrFromShowIndex(scaleComboBox.getSelectedIndex(), selectBodyType);
fitConfigPane.refreshPreviewJPanel(FitType.parseByFitState(state));
}
});
}
@Override
public void populateBean(ReportFitAttr reportFitAttr) {
WFitLayout wFitLayout = jForm.getTarget().getWFitLayout();
layoutComboBox.setSelectedIndex(wFitLayout.getBodyLayoutType().getTypeValue());
scaleComboBox.setSelectedIndex(fitAttrModelType.getScaleAttrShowIndex(wFitLayout));
if (reportFitAttr == null) {
itemChoose.setSelectedItem(Toolkit.i18nText("Fine-Design_Report_Using_Server_Report_View_Settings"));
} else {
itemChoose.setSelectedItem(Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"));
}
if (reportFitAttr == null) {
reportFitAttr = fitAttrModelType.getFitAttrModel().getGlobalReportFitAttr();
}
setEnabled(isTemplateSingleSet());
fitConfigPane.populateBean(reportFitAttr);
}
private boolean isTemplateSingleSet() {
return ComparatorUtils.equals(Toolkit.i18nText("Fine-Design_Report_I_Want_To_Set_Single"), itemChoose.getSelectedItem());
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
fitConfigPane.setEnabled(enabled);
}
@Override
protected String title4PopupWindow() {
return i18nText("Fine-Designer_PC_Fit_Attr");
}
}

14
designer-form/src/main/java/com/fr/design/mainframe/JForm.java

@ -14,7 +14,6 @@ import com.fr.base.vcs.DesignerMode;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
import com.fr.design.DesignState; import com.fr.design.DesignState;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.FormMobileAttrAction; import com.fr.design.actions.FormMobileAttrAction;
import com.fr.design.actions.TemplateParameterAction; import com.fr.design.actions.TemplateParameterAction;
import com.fr.design.actions.core.WorkBookSupportable; import com.fr.design.actions.core.WorkBookSupportable;
@ -37,7 +36,7 @@ import com.fr.design.designer.properties.FormWidgetAuthorityEditPane;
import com.fr.design.event.TargetModifiedEvent; import com.fr.design.event.TargetModifiedEvent;
import com.fr.design.event.TargetModifiedListener; import com.fr.design.event.TargetModifiedListener;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.fun.FormAdaptiveConfigUIProcessor; import com.fr.design.fit.FormFitAttrAction;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
import com.fr.design.fun.PropertyItemPaneProvider; import com.fr.design.fun.PropertyItemPaneProvider;
import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPane;
@ -66,7 +65,6 @@ import com.fr.design.menu.ToolBarDef;
import com.fr.design.parameter.ParameterPropertyPane; import com.fr.design.parameter.ParameterPropertyPane;
import com.fr.design.preview.FormPreview; import com.fr.design.preview.FormPreview;
import com.fr.design.preview.MobilePreview; import com.fr.design.preview.MobilePreview;
import com.fr.design.report.fit.menupane.ReportFitAttrAction;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane; import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.file.FILE; import com.fr.file.FILE;
@ -597,11 +595,7 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
protected ShortCut getReportFitAttrAction() { protected ShortCut getReportFitAttrAction() {
FormAdaptiveConfigUIProcessor adaptiveConfigUI = ExtraDesignClassManager.getInstance().getSingle(FormAdaptiveConfigUIProcessor.MARK_STRING); return new FormFitAttrAction(this);
if (adaptiveConfigUI != null) {
return adaptiveConfigUI.getConfigShortCut(this);
}
return new ReportFitAttrAction(this);
} }
/** /**
@ -1239,4 +1233,8 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm<F
public void setDesignerUIMode(){ public void setDesignerUIMode(){
DesignerUIModeConfig.getInstance().setSimulateWebUIMode(); DesignerUIModeConfig.getInstance().setSimulateWebUIMode();
} }
public XLayoutContainer getRootComponent(){
return this.formDesign.getRootComponent();
}
} }

110
designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRAbsoluteBodyLayoutDefinePane.java

@ -7,54 +7,36 @@ import com.fr.base.theme.TemplateTheme;
import com.fr.design.data.DataCreatorUI; import com.fr.design.data.DataCreatorUI;
import com.fr.design.designer.IntervalConstants; import com.fr.design.designer.IntervalConstants;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.properties.items.FRLayoutTypeItems;
import com.fr.design.designer.properties.items.Item;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.fit.common.TemplateTool;
import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.foldablepane.UIExpandablePane;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UIAutoChangeLineLabel;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.style.FollowingThemePane; import com.fr.design.gui.style.FollowingThemePane;
import com.fr.design.gui.xpane.LayoutStylePane; import com.fr.design.gui.xpane.LayoutStylePane;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.mainframe.widget.accessibles.AccessibleBodyWatermarkEditor; import com.fr.design.mainframe.widget.accessibles.AccessibleBodyWatermarkEditor;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.design.widget.ui.designer.component.WidgetBoundPane;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WAbsoluteBodyLayout; import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WAbsoluteLayout; 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.act.BorderPacker; import com.fr.general.act.BorderPacker;
import com.fr.report.core.ReportUtils; import com.fr.report.core.ReportUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import static javax.swing.JOptionPane.OK_CANCEL_OPTION;
import static javax.swing.JOptionPane.OK_OPTION;
import static javax.swing.JOptionPane.WARNING_MESSAGE;
/** /**
* Created by ibm on 2017/8/2. * Created by ibm on 2017/8/2.
*/ */
public class FRAbsoluteBodyLayoutDefinePane extends FRAbsoluteLayoutDefinePane { public class FRAbsoluteBodyLayoutDefinePane extends FRAbsoluteLayoutDefinePane {
private static final int MAX_LABEL_WIDTH = 80;
protected FollowingThemePane themePane; protected FollowingThemePane themePane;
private LayoutStylePane stylePane; private LayoutStylePane stylePane;
private AccessibleBodyWatermarkEditor watermarkEditor; private AccessibleBodyWatermarkEditor watermarkEditor;
private WidgetBoundPane boundPane;
private UIComboBox layoutCombox;
private WBodyLayoutType layoutType = WBodyLayoutType.ABSOLUTE;
public FRAbsoluteBodyLayoutDefinePane(XCreator xCreator) { public FRAbsoluteBodyLayoutDefinePane(XCreator xCreator) {
super(xCreator); super(xCreator);
@ -62,22 +44,9 @@ public class FRAbsoluteBodyLayoutDefinePane extends FRAbsoluteLayoutDefinePane {
public void initComponent() { public void initComponent() {
initUIComboBox();
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
boundPane = new WidgetBoundPane(creator);
if (!TemplateTool.isCurrentEditingNewJForm()){
this.add(boundPane, BorderLayout.NORTH);
}
JPanel panel1 = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel panel1 = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(panel1, BorderLayout.CENTER); this.add(panel1, BorderLayout.CENTER);
UIExpandablePane scalePane = new UIExpandablePane(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Area_Scaling"),
280, 20,
createAreaScalePane()
);
panel1.add(scalePane, BorderLayout.NORTH);
UIExpandablePane advancedPane = new UIExpandablePane( UIExpandablePane advancedPane = new UIExpandablePane(
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Advanced"),
280, 20, 280, 20,
@ -115,41 +84,15 @@ public class FRAbsoluteBodyLayoutDefinePane extends FRAbsoluteLayoutDefinePane {
}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W3, IntervalConstants.INTERVAL_L1); }, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W3, IntervalConstants.INTERVAL_L1);
watermarkPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, IntervalConstants.INTERVAL_L1, 0)); watermarkPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, IntervalConstants.INTERVAL_L1, 0));
advancedContentPane.add(watermarkPane, BorderLayout.CENTER); advancedContentPane.add(watermarkPane, BorderLayout.CENTER);
UIAutoChangeLineLabel tip = new UIAutoChangeLineLabel(Toolkit.i18nText("Fine-Design_Form_Body_Layout_Setting_Tip"), 216);
tip.setForeground(Color.lightGray);
advancedContentPane.add(tip, BorderLayout.SOUTH);
return advancedContentPane; return advancedContentPane;
} }
public JPanel createAreaScalePane() { @Override
initLayoutComboBox(); public void doLayout() {
super.doLayout();
UILabel layoutTypeLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Layout_Type"));
UILabel scaleModeLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode"));
Component[][] components = TemplateTool.isCurrentEditingNewJForm() ? new Component[][]{
{layoutTypeLabel, layoutCombox}
} : new Component[][]{
{layoutTypeLabel, layoutCombox},
{scaleModeLabel, comboBox}
};
JPanel contentPane = TableLayoutHelper.createGapTableLayoutPane(components,
TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1);
contentPane.setBorder(BorderFactory.createEmptyBorder(IntervalConstants.INTERVAL_L1, 0, IntervalConstants.INTERVAL_L1, 0));
JPanel containerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
containerPane.add(contentPane, BorderLayout.CENTER);
containerPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
return containerPane;
}
public void initLayoutComboBox() {
Item[] items = FRLayoutTypeItems.ITEMS;
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Item item : items) {
model.addElement(item);
}
layoutCombox = new UIComboBox(model);
layoutCombox.setSelectedIndex(1);
} }
@Override @Override
@ -158,51 +101,14 @@ public class FRAbsoluteBodyLayoutDefinePane extends FRAbsoluteLayoutDefinePane {
} }
public void populateSubPane(WAbsoluteLayout ob) { public void populateSubPane(WAbsoluteLayout ob) {
layoutCombox.setSelectedIndex(1);
themePane.supportFollowingTheme(ob.supportThemed()); themePane.supportFollowingTheme(ob.supportThemed());
themePane.setFollowingTheme(ob.isBorderStyleFollowingTheme()); themePane.setFollowingTheme(ob.isBorderStyleFollowingTheme());
stylePane.populateBean((LayoutBorderStyle) ob.getBorderStyle()); stylePane.populateBean((LayoutBorderStyle) ob.getBorderStyle());
boundPane.populate();
watermarkEditor.setValue(ReportUtils.getWatermarkAttrFromTemplate(getCurrentIOFile())); watermarkEditor.setValue(ReportUtils.getWatermarkAttrFromTemplate(getCurrentIOFile()));
} }
public WAbsoluteBodyLayout updateSubPane() { public WAbsoluteBodyLayout updateSubPane() {
WAbsoluteBodyLayout layout = (WAbsoluteBodyLayout) creator.toData(); WAbsoluteBodyLayout layout = (WAbsoluteBodyLayout) creator.toData();
boundPane.update();
Item item = (Item) layoutCombox.getSelectedItem();
Object value = item.getValue();
int state = 0;
if (value instanceof Integer) {
state = (Integer) value;
}
if (layoutType == WBodyLayoutType.ABSOLUTE) {
((XWFitLayout) creator.getBackupParent()).toData().resetStyle();
if (state == WBodyLayoutType.FIT.getTypeValue()) {
XWFitLayout xwFitLayout = ((XWFitLayout)creator.getBackupParent());
int selVal = FineJOptionPane.showConfirmDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Form_Layout_Switch_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Alert"),
OK_CANCEL_OPTION,
WARNING_MESSAGE
);
if(OK_OPTION == selVal){
xwFitLayout.switch2FitBodyLayout(creator);
WFitLayout wFitLayout = xwFitLayout.toData();
// 切换布局类型时,保留body背景样式
if (wFitLayout != null) {
wFitLayout.setBorderStyleFollowingTheme(layout.isBorderStyleFollowingTheme());
wFitLayout.setBorderStyle(layout.getBorderStyle());
}
copyLayoutAttr(layout, xwFitLayout.toData());
}else {
this.layoutCombox.setSelectedIndex(1);
}
copyLayoutAttr(layout, xwFitLayout.toData());
xwFitLayout.refreshStylePreviewEffect();
}
}
layout.setBorderStyleFollowingTheme(themePane.isFollowingTheme()); layout.setBorderStyleFollowingTheme(themePane.isFollowingTheme());
layout.setBorderStyle(stylePane.updateBean()); layout.setBorderStyle(stylePane.updateBean());
updateWatermark(); updateWatermark();

52
designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRAbsoluteLayoutDefinePane.java

@ -1,30 +1,15 @@
package com.fr.design.widget.ui.designer.layout; package com.fr.design.widget.ui.designer.layout;
import com.fr.design.data.DataCreatorUI; 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.XCreator;
import com.fr.design.designer.properties.items.FRAbsoluteConstraintsItems;
import com.fr.design.designer.properties.items.Item;
import com.fr.design.fit.common.TemplateTool;
import com.fr.design.foldablepane.UIExpandablePane;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
/** /**
* Created by ibm on 2017/8/2. * Created by ibm on 2017/8/2.
*/ */
public class FRAbsoluteLayoutDefinePane extends AbstractFRLayoutDefinePane<WAbsoluteLayout> { public class FRAbsoluteLayoutDefinePane extends AbstractFRLayoutDefinePane<WAbsoluteLayout> {
protected UIComboBox comboBox;
public FRAbsoluteLayoutDefinePane(XCreator xCreator) { public FRAbsoluteLayoutDefinePane(XCreator xCreator) {
super(xCreator); super(xCreator);
@ -34,41 +19,9 @@ public class FRAbsoluteLayoutDefinePane extends AbstractFRLayoutDefinePane<WAbso
public void initComponent() { public void initComponent() {
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
initUIComboBox();
JPanel thirdPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel jPanel = createThirdPane();
jPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
thirdPane.add(jPanel, BorderLayout.CENTER);
UIExpandablePane layoutExpandablePane = new UIExpandablePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Area_Scaling"), 280, 20, thirdPane);
if (!TemplateTool.isCurrentEditingNewJForm()){
this.add(layoutExpandablePane, BorderLayout.CENTER);
}
}
public JPanel createThirdPane() {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
double[] rowSize = {p};
double[] columnSize = {p, f};
int[][] rowCount = {{1, 1}};
Component[][] components = new Component[][]{
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Scaling_Mode")), comboBox},
};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1);
// panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
return panel;
} }
public void initUIComboBox() {
Item[] items = FRAbsoluteConstraintsItems.ITEMS;
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Item item : items) {
model.addElement(item);
}
comboBox = new UIComboBox(model);
}
@Override @Override
public String title4PopupWindow() { public String title4PopupWindow() {
return "absoluteLayout"; return "absoluteLayout";
@ -77,15 +30,12 @@ public class FRAbsoluteLayoutDefinePane extends AbstractFRLayoutDefinePane<WAbso
@Override @Override
public void populateBean(WAbsoluteLayout ob) { public void populateBean(WAbsoluteLayout ob) {
populateSubPane(ob); populateSubPane(ob);
comboBox.setSelectedIndex(ob.getCompState());
} }
@Override @Override
public WAbsoluteLayout updateBean() { public WAbsoluteLayout updateBean() {
WAbsoluteLayout wAbsoluteLayout = updateSubPane(); return updateSubPane();
wAbsoluteLayout.setCompState(comboBox.getSelectedIndex());
return wAbsoluteLayout;
} }

118
designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/FRFitLayoutDefinePane.java

@ -9,16 +9,10 @@ import com.fr.design.designer.IntervalConstants;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XOccupiedLayout;
import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteBodyLayout;
import com.fr.design.designer.creator.XWFitLayout; 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.fit.common.TemplateTool;
import com.fr.design.foldablepane.UIExpandablePane; import com.fr.design.foldablepane.UIExpandablePane;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UIAutoChangeLineLabel;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.gui.style.FollowingThemePane; import com.fr.design.gui.style.FollowingThemePane;
@ -35,13 +29,9 @@ import com.fr.design.widget.FRWidgetFactory;
import com.fr.design.widget.ui.designer.component.PaddingBoundPane; import com.fr.design.widget.ui.designer.component.PaddingBoundPane;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.Widget; 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.form.ui.container.WFitLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.act.BorderPacker; import com.fr.general.act.BorderPacker;
import com.fr.log.FineLoggerFactory;
import com.fr.report.core.ReportUtils; import com.fr.report.core.ReportUtils;
import javax.swing.*; import javax.swing.*;
@ -51,11 +41,8 @@ import java.awt.*;
* Created by ibm on 2017/8/2. * Created by ibm on 2017/8/2.
*/ */
public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout> { public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout> {
private static final int ADAPT_LABEL_MAX_WIDTH = 80;
private XWFitLayout xWFitLayout; private XWFitLayout xWFitLayout;
private WFitLayout wFitLayout; private WFitLayout wFitLayout;
private UIComboBox layoutComboBox;
private UIComboBox adaptComboBox;
private UISpinner componentIntervel; private UISpinner componentIntervel;
private PaddingBoundPane paddingBound; private PaddingBoundPane paddingBound;
private FollowingThemePane themePane; private FollowingThemePane themePane;
@ -119,11 +106,7 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark")), watermarkEditor} new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_WaterMark")), watermarkEditor}
}, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W3, IntervalConstants.INTERVAL_L1); }, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W3, IntervalConstants.INTERVAL_L1);
waterMarkPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); waterMarkPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
contentPane1.add(waterMarkPane, BorderLayout.NORTH); contentPane1.add(waterMarkPane, BorderLayout.CENTER);
paddingBound = new PaddingBoundPane();
contentPane1.add(paddingBound, BorderLayout.CENTER);
return contentPane0; return contentPane0;
} }
@ -137,22 +120,12 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
public JPanel createLayoutPane() { public JPanel createLayoutPane() {
JPanel containerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); 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, false); componentIntervel = new UISpinner(0, Integer.MAX_VALUE, 1, 0, false);
JPanel componentIntervelPane = UIComponentUtils.wrapWithBorderLayoutPane(componentIntervel); 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")); UILabel intervalLabel = FRWidgetFactory.createLineWrapLabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Component_Interval"));
Component[][] components = TemplateTool.isCurrentEditingNewJForm() ? new Component[][]{ Component[][] components = new Component[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Layout_Type")), layoutComboBox},
{intervalLabel, componentIntervelPane}
} : new Component[][]{
{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Attr_Layout_Type")), layoutComboBox},
{adaptLabel, adaptComboBoxPane},
{intervalLabel, componentIntervelPane} {intervalLabel, componentIntervelPane}
}; };
@ -160,19 +133,17 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
components, components,
TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1); TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W1, IntervalConstants.INTERVAL_L1);
contentPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
containerPane.add(contentPane, BorderLayout.CENTER); containerPane.add(contentPane, BorderLayout.NORTH);
paddingBound = new PaddingBoundPane();
containerPane.add(paddingBound, BorderLayout.CENTER);
UIAutoChangeLineLabel tip = new UIAutoChangeLineLabel(Toolkit.i18nText("Fine-Design_Form_Body_Layout_Setting_Tip"),216);
tip.setForeground(Color.lightGray);
containerPane.add(tip, BorderLayout.SOUTH);
return containerPane; return containerPane;
} }
public UIComboBox initUIComboBox(Item[] items) {
DefaultComboBoxModel model = new DefaultComboBoxModel();
for (Item item : items) {
model.addElement(item);
}
return new UIComboBox(model);
}
@Override @Override
@ -193,8 +164,6 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
paddingBound.populate(ob); paddingBound.populate(ob);
paddingBound.setEnabled(supportModifyInterval()); paddingBound.setEnabled(supportModifyInterval());
layoutComboBox.setSelectedIndex(ob.getBodyLayoutType().getTypeValue());
adaptComboBox.setSelectedIndex(ob.getCompState());
componentIntervel.setValue(ob.getCompInterval()); componentIntervel.setValue(ob.getCompInterval());
componentIntervel.setEnabled(supportModifyInterval()); componentIntervel.setEnabled(supportModifyInterval());
themePane.supportFollowingTheme(ob.supportThemed()); themePane.supportFollowingTheme(ob.supportThemed());
@ -224,67 +193,6 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
layout.setBorderStyle(borderStyle); layout.setBorderStyle(borderStyle);
} }
updateWatermark(); 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.setBorderStyleFollowingTheme(layout.isBorderStyleFollowingTheme());
wAbsoluteBodyLayout.setBorderStyle((BorderPacker) (layout.getBorderStyle().clone()));
Component[] components = xWFitLayout.getComponents();
Rectangle[] backupBounds = getBackupBoundsFromFitLayout();
xWFitLayout.removeAll();
layout.resetStyle();
XWAbsoluteBodyLayout xwAbsoluteBodyLayout = xWFitLayout.getBackupParent() == null ? new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0, 0)) : (XWAbsoluteBodyLayout) xWFitLayout.getBackupParent();
xWFitLayout.setFixLayout(false);
xWFitLayout.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0);
for (int i = 0; i < components.length; i++) {
XCreator xCreator = (XCreator) components[i];
xCreator.setBounds(backupBounds[i]);
//部分控件被ScaleLayout包裹着,绝对布局里面要放出来
if (xCreator.acceptType(XWScaleLayout.class)) {
if (xCreator.getComponentCount() > 0 && ((XCreator) xCreator.getComponent(0)).shouldScaleCreator()) {
Component component = xCreator.getComponent(0);
component.setBounds(xCreator.getBounds());
}
}
if (!xCreator.acceptType(XOccupiedLayout.class)){
xwAbsoluteBodyLayout.add(xCreator);
}
}
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().setBorderStyleFollowingTheme(wAbsoluteBodyLayout.isBorderStyleFollowingTheme());
xwAbsoluteBodyLayout.toData().setBorderStyle(wAbsoluteBodyLayout.getBorderStyle());
}
xwAbsoluteBodyLayout.refreshStylePreviewEffect();
if (xWFitLayout.toData() != null) {
xWFitLayout.toData().resetStyle();
}
xWFitLayout.refreshStylePreviewEffect();
formDesigner.switchBodyLayout(xwAbsoluteBodyLayout);
return layout;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
int intervelValue = (int) componentIntervel.getValue(); int intervelValue = (int) componentIntervel.getValue();
if (xWFitLayout.canAddInterval(intervelValue)) { if (xWFitLayout.canAddInterval(intervelValue)) {
// 设置完间隔后,要同步处理界面组件,容器刷新后显示出对应效果 // 设置完间隔后,要同步处理界面组件,容器刷新后显示出对应效果
@ -302,14 +210,6 @@ public class FRFitLayoutDefinePane extends AbstractFRLayoutDefinePane<WFitLayout
return layout; return layout;
} }
private Rectangle[] getBackupBoundsFromFitLayout() {
int count = xWFitLayout.getComponentCount();
Rectangle[] rectangles = new Rectangle[count];
for (int i = 0; i < count; i++) {
rectangles[i] = xWFitLayout.getComponent(i).getBounds();
}
return rectangles;
}
private void updateWatermark() { private void updateWatermark() {
WatermarkAttr watermark = (WatermarkAttr) watermarkEditor.getValue(); WatermarkAttr watermark = (WatermarkAttr) watermarkEditor.getValue();

Loading…
Cancel
Save