diff --git a/designer_base/src/com/fr/design/images/control/combobox.png b/designer_base/src/com/fr/design/images/control/combobox.png new file mode 100644 index 0000000000..6e5be84e73 Binary files /dev/null and b/designer_base/src/com/fr/design/images/control/combobox.png differ diff --git a/designer_base/src/com/fr/design/utils/DesignUtils.java b/designer_base/src/com/fr/design/utils/DesignUtils.java index d6a2ab8a58..8ed8aa6175 100644 --- a/designer_base/src/com/fr/design/utils/DesignUtils.java +++ b/designer_base/src/com/fr/design/utils/DesignUtils.java @@ -230,15 +230,12 @@ public class DesignUtils { private static FRFont getCurrentLocaleFont(){ FRFont guiFRFont; - Locale defaultLocale = FRContext.getLocale(); + Locale defaultLocale = Locale.getDefault(); if (isDisplaySimSun(defaultLocale)) { guiFRFont = getNamedFont("SimSun"); } else if(isDisplayDialog(defaultLocale)) { guiFRFont = getNamedFont("Dialog"); - } else if(isDisplayJapaneseFont(defaultLocale)){ - //日文设计器默认用MS Mincho字体渲染 - guiFRFont = getNamedFont("MS Mincho"); } else { guiFRFont = getNamedFont("Tahoma"); } @@ -270,14 +267,11 @@ public class DesignUtils { private static boolean isDisplaySimSun(Locale defaultLocale){ return ComparatorUtils.equals(defaultLocale, Locale.SIMPLIFIED_CHINESE); } - - private static boolean isDisplayJapaneseFont(Locale defaultLocale){ - return ComparatorUtils.equals(defaultLocale, Locale.JAPANESE) - || ComparatorUtils.equals(defaultLocale, Locale.JAPAN); - } private static boolean isDisplayDialog(Locale defaultLocale){ - return ComparatorUtils.equals(defaultLocale, Locale.TRADITIONAL_CHINESE) + return ComparatorUtils.equals(defaultLocale, Locale.TRADITIONAL_CHINESE) + || ComparatorUtils.equals(defaultLocale, Locale.JAPANESE) + || ComparatorUtils.equals(defaultLocale, Locale.JAPAN) || ComparatorUtils.equals(defaultLocale, Locale.KOREAN) || ComparatorUtils.equals(defaultLocale, Locale.KOREA); } diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteBodyLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteBodyLayoutAdapter.java new file mode 100644 index 0000000000..e06bb74634 --- /dev/null +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteBodyLayoutAdapter.java @@ -0,0 +1,30 @@ +package com.fr.design.designer.beans.adapters.layout; + +import com.fr.design.beans.GroupModel; +import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWAbsoluteBodyLayout; +import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.designer.creator.XWFitLayout; +import com.fr.design.designer.properties.FRAbsoluteBodyLayoutPropertiesGroupModel; +import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; +import com.fr.form.ui.container.WBodyLayoutType; + +/** + * Created by zhouping on 2016/10/14. + */ +public class FRAbsoluteBodyLayoutAdapter extends FRAbsoluteLayoutAdapter { + public FRAbsoluteBodyLayoutAdapter(XLayoutContainer container) { + super(container); + } + + @Override + public GroupModel getLayoutProperties() { + XWAbsoluteBodyLayout xwAbsoluteBodyLayout = (XWAbsoluteBodyLayout) container; + //如果body是绝对布局,那么获取原来自适应body的属性--布局类型 + WBodyLayoutType layoutType = WBodyLayoutType.FIT; + if (container.getParent() != null) { + layoutType = ((XWFitLayout)container.getParent()).toData().getBodyLayoutType(); + } + return new FRAbsoluteBodyLayoutPropertiesGroupModel(xwAbsoluteBodyLayout, layoutType); + } +} diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index 8e0a725cd4..c49ecf0f38 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -331,15 +331,6 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { @Override public GroupModel getLayoutProperties() { XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; - if (xwAbsoluteLayout.toData().isAbsoluteLayoutAsBody()){ - //如果body是绝对布局,那么获取原来自适应body的属性--布局类型 - WBodyLayoutType layoutType = WBodyLayoutType.FIT; - if (container.getParent() != null) { - layoutType = ((XWFitLayout)container.getParent()).toData().getBodyLayoutType(); - } - return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout, layoutType); - } else { - return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); - } + return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java b/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java index 19cfe2d8d1..e0fc683552 100644 --- a/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java @@ -77,6 +77,7 @@ public class XCreatorUtils { xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class); xLayoutMap.put(WParameterLayout.class, XWParameterLayout.class); + xLayoutMap.put(WAbsoluteBodyLayout.class, XWAbsoluteBodyLayout.class); xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class); xLayoutMap.put(WHorizontalBoxLayout.class, XWHorizontalBoxLayout.class); xLayoutMap.put(WBorderLayout.class, XWBorderLayout.class); diff --git a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java new file mode 100644 index 0000000000..b9fea0a0bf --- /dev/null +++ b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java @@ -0,0 +1,45 @@ +package com.fr.design.designer.creator; + +import com.fr.design.designer.beans.LayoutAdapter; +import com.fr.design.designer.beans.adapters.layout.FRAbsoluteBodyLayoutAdapter; +import com.fr.form.ui.container.WAbsoluteBodyLayout; + +import java.awt.*; + +/** + * Created by zhouping on 2016/10/14. + * 用作body的绝对布局 + */ +public class XWAbsoluteBodyLayout extends XWAbsoluteLayout { + public XWAbsoluteBodyLayout(WAbsoluteBodyLayout widget, Dimension initSize) { + super(widget, initSize); + this.editable = true; + } + + /** + * 返回对应的widget容器 + * + * @return 返回WAbsoluteLayout + */ + @Override + public WAbsoluteBodyLayout toData() { + return (WAbsoluteBodyLayout)data; + } + + @Override + public LayoutAdapter getLayoutAdapter() { + return new FRAbsoluteBodyLayoutAdapter(this); + } + + + + /** + * 假如是body的话,始终要能编辑,不会出现蒙层 + * + * @param isEditable 可否编辑 + */ + @Override + public void setEditable(boolean isEditable) { + super.setEditable(true); + } +} diff --git a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java index 9ac9addc7f..210343f8ed 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java @@ -75,15 +75,7 @@ public class XWAbsoluteLayout extends XLayoutContainer { xConnectorMap.put(connector, new XConnector(connector, this)); } - this.editable = widget.isAbsoluteLayoutAsBody(); - - initPercent(); - } - - public XWAbsoluteLayout(WAbsoluteLayout widget, Dimension initSize, boolean isAbsoluteLayoutAsBody) { - this(widget, initSize); - widget.setAbsoluteLayoutAsBody(isAbsoluteLayoutAsBody); - this.editable = isAbsoluteLayoutAsBody; + initPercent(widget); } /** @@ -97,13 +89,14 @@ public class XWAbsoluteLayout extends XLayoutContainer { } //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% - private void initPercent(){ + private void initPercent(WAbsoluteLayout widget){ Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension scrnsize = toolkit.getScreenSize(); double screenValue = FRScreen.getByDimension(scrnsize).getValue(); if(screenValue != FormArea.DEFAULT_SLIDER){ this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER); } + widget.setDesigningResolution(scrnsize); } /** @@ -451,15 +444,4 @@ public class XWAbsoluteLayout extends XLayoutContainer { } } } - - /** - * 设置布局是否可编辑,不可则显示编辑蒙层 - * 假如是body的话,始终要能编辑,不会出现蒙层 - * - * @param isEditable 可否编辑 - */ - @Override - public void setEditable(boolean isEditable) { - super.setEditable(toData().isAbsoluteLayoutAsBody() || isEditable); - } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java b/designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java index 4cc770eec8..e58c7f8abd 100644 --- a/designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java +++ b/designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java @@ -1,11 +1,10 @@ package com.fr.design.designer.properties; -import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer; - /** * Created by zhouping on 2016/8/1. */ -public class AbsoluteStateRenderer extends EncoderCellRenderer { +public class AbsoluteStateRenderer extends BodyLayoutAttrRenderer { + public AbsoluteStateRenderer() { super(new AbsoluteStateWrapper()); } diff --git a/designer_form/src/com/fr/design/designer/properties/BodyLayoutAttrRenderer.java b/designer_form/src/com/fr/design/designer/properties/BodyLayoutAttrRenderer.java new file mode 100644 index 0000000000..be05e45986 --- /dev/null +++ b/designer_form/src/com/fr/design/designer/properties/BodyLayoutAttrRenderer.java @@ -0,0 +1,23 @@ +package com.fr.design.designer.properties; + +import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer; +import com.fr.general.IOUtils; + +import java.awt.*; +import java.awt.image.BufferedImage; + +/** + * Created by zhouping on 2016/10/14. + */ +public class BodyLayoutAttrRenderer extends EncoderCellRenderer { + public BodyLayoutAttrRenderer(Encoder encoder) { + super(encoder); + } + + @Override + public void paint(Graphics g) { + super.paint(g); + BufferedImage image = IOUtils.readImage("com/fr/design/images/control/combobox.png"); + g.drawImage(image, getWidth() - image.getWidth(), 0, image.getWidth(), image.getHeight(), null, this); + } +} diff --git a/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java new file mode 100644 index 0000000000..1a7ab03d3f --- /dev/null +++ b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java @@ -0,0 +1,239 @@ +package com.fr.design.designer.properties; + +import com.fr.design.designer.creator.XWAbsoluteBodyLayout; +import com.fr.design.designer.creator.XWFitLayout; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormSelectionUtils; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.mainframe.widget.editors.LayoutTypeEditor; +import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.ui.Widget; +import com.fr.form.ui.container.WBodyLayoutType; +import com.fr.general.FRScreen; +import com.fr.general.Inter; + +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import java.awt.*; +import java.awt.geom.Arc2D; +import java.util.Arrays; +import java.util.Comparator; + +/** + * Created by zhouping on 2016/10/14. + */ +public class FRAbsoluteBodyLayoutPropertiesGroupModel extends FRAbsoluteLayoutPropertiesGroupModel { + private LayoutTypeEditor layoutTypeEditor; + private LayoutTypeRenderer layoutTypeRenderer; + //默认body是0,自适应布局;1,绝对布局. + private WBodyLayoutType layoutType = WBodyLayoutType.ABSOLUTE; + public FRAbsoluteBodyLayoutPropertiesGroupModel(XWAbsoluteBodyLayout xwAbsoluteBodyLayout) { + super(xwAbsoluteBodyLayout); + } + + public FRAbsoluteBodyLayoutPropertiesGroupModel(XWAbsoluteBodyLayout xwAbsoluteBodyLayout, WBodyLayoutType layoutType){ + this(xwAbsoluteBodyLayout); + this.layoutTypeEditor = new LayoutTypeEditor(); + this.layoutTypeRenderer = new LayoutTypeRenderer(); + this.layoutType = layoutType; + } + + /** + * 布局管理器自己的属性 + */ + @Override + public String getGroupName() { + return Inter.getLocText("FR-Designer_Attr_Layout"); + } + + @Override + public int getRowCount() { + return 2; + } + + @Override + public TableCellRenderer getRenderer(int row) { + return row == 0 ? layoutTypeRenderer : stateRenderer; + } + + @Override + public TableCellEditor getEditor(int row) { + return row == 0 ? layoutTypeEditor : stateEditor; + } + + @Override + public Object getValue(int row, int column) { + if (column == 0) { + switch (row) { + case 0: + return Inter.getLocText("FR-Designer_Attr_Layout_Type"); + default: + return Inter.getLocText("FR-Designer-Widget_Scaling_Mode"); + } + } else { + switch (row) { + case 0: + return layoutType.getTypeValue(); + default: + return layout.getCompState(); + } + } + } + + @Override + public boolean setValue(Object value, int row, int column) { + if (layoutType == WBodyLayoutType.ABSOLUTE){ + int state = 0; + if(value instanceof Integer) { + state = (Integer)value; + } + if (column == 0 || state < 0) { + return false; + } else { + if (row == 0) { + if (state == WBodyLayoutType.FIT.getTypeValue()) { + XWFitLayout xfl = (XWFitLayout) xwAbsoluteLayout.getBackupParent(); + Component[] components = xwAbsoluteLayout.getComponents(); + + Arrays.sort(components, new ComparatorComponentLocation()); + + xfl.getLayoutAdapter().removeBean(xwAbsoluteLayout, xwAbsoluteLayout.getWidth(), xwAbsoluteLayout.getHeight()); + xfl.remove(xwAbsoluteLayout); + xfl.toData().setLayoutType(WBodyLayoutType.FIT); + + for (Component comp : components) { + xfl.add(comp); + } + moveComponents2FitLayout(xfl, components); + FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + formDesigner.getSelectionModel().setSelectedCreators( + FormSelectionUtils.rebuildSelection(xfl, new Widget[]{xfl.toData()})); + xfl.convert(); + LayoutUtils.layoutContainer(xfl); + xfl.adjustCreatorsWhileSlide(xfl.getContainerPercent() - 1.0); + return true; + } + } + if (row == 1) { + layout.setCompState(state); + return true; + } + return false; + } + } + int state = 0; + if(value instanceof Integer) { + state = (Integer)value; + } + if (column == 0 || state < 0) { + return false; + } else { + if (row == 0) { + layout.setCompState(state); + return true; + } + return false; + } + } + + /** + * 是否可编辑 + * @param row 行 + * @return 否 + */ + @Override + public boolean isEditable(int row) { + return true; + } + + //把绝对布局中的元素按规则移动到自适应布局中 + private void moveComponents2FitLayout(XWFitLayout xwFitLayout, Component[] components) { + int eachRowCount = 4; + if (components.length <= 1){ + return; + } + int layoutWidth = xwFitLayout.getWidth() - xwFitLayout.toData().getMargin().getLeft() - xwFitLayout.toData().getMargin().getRight(); + int layoutHeight = xwFitLayout.getHeight() - xwFitLayout.toData().getMargin().getTop() - xwFitLayout.toData().getMargin().getBottom(); + int leftMargin = xwFitLayout.toData().getMargin().getLeft(); + int topMargin = xwFitLayout.toData().getMargin().getTop(); + int row = (components.length / eachRowCount) + (components.length % eachRowCount == 0 ? 0 : 1); + //最后一行的列数不定 + int column = components.length % eachRowCount == 0 ? eachRowCount : components.length % eachRowCount; + int componentWidth = layoutWidth / eachRowCount; + int componentHeight = layoutHeight / row; + for(int i = 0;i < row - 1;i++){ + for(int j = 0;j < eachRowCount;j++){ + components[eachRowCount * i + j].setBounds( + leftMargin + componentWidth * j, + topMargin + componentHeight * i, + j == eachRowCount - 1 ? layoutWidth - componentWidth * (eachRowCount - 1) : componentWidth, + componentHeight + ); + } + } + //最后一行列数是特殊的,要单独处理 + int lastRowWidth = layoutWidth / column; + int lastRowHeight = layoutHeight - componentHeight * (row - 1); + for (int i = 0;i < column;i++) { + components[eachRowCount * (row - 1) + i].setBounds( + leftMargin + lastRowWidth * i, + topMargin + componentHeight * (row - 1), + i == column - 1 ? layoutWidth - lastRowWidth * (column - 1) : lastRowWidth, + lastRowHeight + ); + } + xwFitLayout.updateBoundsWidget(); + } + + private class ComponentLocationInfo{ + private Component component; + private int horizontalNO; + private int verticalNO; + + public ComponentLocationInfo(Component component, int horizontalNO, int verticalNO){ + this.component = component; + this.horizontalNO = horizontalNO; + this.verticalNO = verticalNO; + } + + public int getHorizontalNO() { + return this.horizontalNO; + } + + public int getVerticalNO() { + return this.verticalNO; + } + + public void setHorizontalNO(int horizontalNO){ + this.horizontalNO = horizontalNO; + } + + public void setVerticalNO(int verticalNO){ + this.verticalNO = verticalNO; + } + } + + //以组件的位置来确定先后顺序,y小的在前,x小的在前 + private class ComparatorComponentLocation implements Comparator { + @Override + public int compare(Object o1, Object o2) { + if(((Component)o1).getY() < ((Component)o2).getY()){ + return -1; + } + else if (((Component)o1).getY() > ((Component)o2).getY()) { + return 1; + } + else { + if (((Component)o1).getX() < ((Component)o2).getX()){ + return -1; + } + else if (((Component)o1).getX() > ((Component)o2).getX()) { + return 1; + } + else{ + return 0; + } + } + } + } +} diff --git a/designer_form/src/com/fr/design/designer/properties/FRAbsoluteLayoutPropertiesGroupModel.java b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteLayoutPropertiesGroupModel.java index f8b695a333..66540fe068 100644 --- a/designer_form/src/com/fr/design/designer/properties/FRAbsoluteLayoutPropertiesGroupModel.java +++ b/designer_form/src/com/fr/design/designer/properties/FRAbsoluteLayoutPropertiesGroupModel.java @@ -2,40 +2,27 @@ package com.fr.design.designer.properties; import com.fr.design.beans.GroupModel; import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.designer.creator.XWFitLayout; -import com.fr.design.mainframe.FormDesigner; -import com.fr.design.mainframe.FormSelectionUtils; -import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.mainframe.widget.editors.AbsoluteLayoutDirectionEditor; import com.fr.design.mainframe.widget.editors.IntegerPropertyEditor; -import com.fr.design.mainframe.widget.editors.LayoutTypeEditor; import com.fr.design.mainframe.widget.editors.PropertyCellEditor; -import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; -import com.fr.form.ui.container.WBodyLayoutType; import com.fr.general.Inter; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; -import java.awt.*; -import java.util.Arrays; -import java.util.Comparator; /** * Created by zhouping on 2016/8/1. */ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel { + private PropertyCellEditor editor; private DefaultTableCellRenderer renderer; - private AbsoluteLayoutDirectionEditor stateEditor; - private AbsoluteStateRenderer stateRenderer; - private WAbsoluteLayout layout; - private XWAbsoluteLayout xwAbsoluteLayout; - private LayoutTypeEditor layoutTypeEditor; - private LayoutTypeRenderer layoutTypeRenderer; - //默认body是0,自适应布局;1,绝对布局. - private WBodyLayoutType layoutType = WBodyLayoutType.FIT; + protected AbsoluteLayoutDirectionEditor stateEditor; + protected AbsoluteStateRenderer stateRenderer; + protected WAbsoluteLayout layout; + protected XWAbsoluteLayout xwAbsoluteLayout; public FRAbsoluteLayoutPropertiesGroupModel(XWAbsoluteLayout xwAbsoluteLayout){ this.xwAbsoluteLayout = xwAbsoluteLayout; @@ -46,65 +33,31 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel { stateRenderer = new AbsoluteStateRenderer(); } - public FRAbsoluteLayoutPropertiesGroupModel(XWAbsoluteLayout xwAbsoluteLayout, WBodyLayoutType layoutType){ - this(xwAbsoluteLayout); - this.layoutTypeEditor = new LayoutTypeEditor(); - this.layoutTypeRenderer = new LayoutTypeRenderer(); - this.layoutType = layoutType; - } - /** * 布局管理器自己的属性 */ @Override public String getGroupName() { - return Inter.getLocText(layoutType == WBodyLayoutType.ABSOLUTE ? "FR-Designer_Attr_Layout" : "FR-Designer-Widget_Area_Scaling"); + return Inter.getLocText("FR-Designer-Widget_Area_Scaling"); } @Override public int getRowCount() { - return layoutType == WBodyLayoutType.ABSOLUTE ? 2 : 1; + return 1; } @Override public TableCellRenderer getRenderer(int row) { - if (layoutType == WBodyLayoutType.ABSOLUTE) { - return row == 0 ? layoutTypeRenderer : stateRenderer; - } - else { - return stateRenderer; - } + return stateRenderer; } @Override public TableCellEditor getEditor(int row) { - if (layoutType == WBodyLayoutType.ABSOLUTE) { - return row == 0 ? layoutTypeEditor : stateEditor; - } - else{ - return stateEditor; - } + return stateEditor; } @Override public Object getValue(int row, int column) { - if (layoutType == WBodyLayoutType.ABSOLUTE){ - if (column == 0) { - switch (row) { - case 0: - return Inter.getLocText("FR-Designer_Attr_Layout_Type"); - default: - return Inter.getLocText("FR-Designer-Widget_Scaling_Mode"); - } - } else { - switch (row) { - case 0: - return layoutType.getTypeValue(); - default: - return layout.getCompState(); - } - } - } if (column == 0) { return Inter.getLocText("FR-Designer-Widget_Scaling_Mode"); } else { @@ -114,42 +67,6 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel { @Override public boolean setValue(Object value, int row, int column) { - if (layoutType == WBodyLayoutType.ABSOLUTE){ - int state = 0; - if(value instanceof Integer) { - state = (Integer)value; - } - if (column == 0 || state < 0) { - return false; - } else { - if (row == 0) { - if (state == WBodyLayoutType.FIT.getTypeValue()) { - XWFitLayout xfl = (XWFitLayout) xwAbsoluteLayout.getBackupParent(); - Component[] components = xwAbsoluteLayout.getComponents(); - - Arrays.sort(components, new ComparatorComponentLocation()); - - xfl.getLayoutAdapter().removeBean(xwAbsoluteLayout, xwAbsoluteLayout.getWidth(), xwAbsoluteLayout.getHeight()); - xfl.remove(xwAbsoluteLayout); - xfl.toData().setLayoutType(WBodyLayoutType.FIT); - - for (Component comp : components) { - xfl.add(comp); - } - moveComponents2FitLayout(xfl, components); - FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); - formDesigner.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xfl, new Widget[]{xfl.toData()})); - return true; - } - } - if (row == 1) { - layout.setCompState(state); - return true; - } - return false; - } - } int state = 0; if(value instanceof Integer) { state = (Integer)value; @@ -174,95 +91,4 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel { public boolean isEditable(int row) { return true; } - - //把绝对布局中的元素按规则移动到自适应布局中 - private void moveComponents2FitLayout(XWFitLayout xwFitLayout, Component[] components) { - int eachRowCount = 4; - if (components.length <= 1){ - return; - } - int layoutWidth = xwFitLayout.getWidth() - xwFitLayout.toData().getMargin().getLeft() - xwFitLayout.toData().getMargin().getRight(); - int layoutHeight = xwFitLayout.getHeight() - xwFitLayout.toData().getMargin().getTop() - xwFitLayout.toData().getMargin().getBottom(); - int leftMargin = xwFitLayout.toData().getMargin().getLeft(); - int topMargin = xwFitLayout.toData().getMargin().getTop(); - int row = (components.length / eachRowCount) + (components.length % eachRowCount == 0 ? 0 : 1); - //最后一行的列数不定 - int column = components.length % eachRowCount; - int componentWidth = layoutWidth / eachRowCount; - int componentHeight = layoutHeight / row; - for(int i = 0;i < row - 1;i++){ - for(int j = 0;j < eachRowCount;j++){ - components[eachRowCount * i + j].setBounds( - leftMargin + componentWidth * j, - topMargin + componentHeight * i, - j == eachRowCount - 1 ? layoutWidth - componentWidth * (eachRowCount-1) : componentWidth, - componentHeight - ); - } - } - //最后一行列数是特殊的,要单独处理 - int lastRowWidth = layoutWidth / column; - int lastRowHeight = layoutHeight - componentHeight * (row - 1); - for (int i = 0;i < column;i++) { - components[eachRowCount * (row - 1) + i].setBounds( - leftMargin + lastRowWidth * i, - topMargin + componentHeight * (row - 1), - i == column - 1 ? layoutWidth - lastRowWidth * (column-1) : lastRowWidth, - lastRowHeight - ); - } - xwFitLayout.updateBoundsWidget(); - } - - private class ComponentLocationInfo{ - private Component component; - private int horizontalNO; - private int verticalNO; - - public ComponentLocationInfo(Component component, int horizontalNO, int verticalNO){ - this.component = component; - this.horizontalNO = horizontalNO; - this.verticalNO = verticalNO; - } - - public int getHorizontalNO() { - return this.horizontalNO; - } - - public int getVerticalNO() { - return this.verticalNO; - } - - public void setHorizontalNO(int horizontalNO){ - this.horizontalNO = horizontalNO; - } - - public void setVerticalNO(int verticalNO){ - this.verticalNO = verticalNO; - } - } - - //以组件的位置来确定先后顺序,y小的在前,x小的在前 - private class ComparatorComponentLocation implements Comparator { - @Override - public int compare(Object o1, Object o2) { - if(((Component)o1).getY() < ((Component)o2).getY()){ - return -1; - } - else if (((Component)o1).getY() > ((Component)o2).getY()) { - return 1; - } - else { - if (((Component)o1).getX() < ((Component)o2).getX()){ - return -1; - } - else if (((Component)o1).getX() > ((Component)o2).getX()) { - return 1; - } - else{ - return 0; - } - } - } - } } diff --git a/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java b/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java index 25680581c0..f6b8ccaf22 100644 --- a/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java +++ b/designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java @@ -4,7 +4,7 @@ package com.fr.design.designer.properties; import com.fr.design.beans.GroupModel; -import com.fr.design.designer.creator.XWAbsoluteLayout; +import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelectionUtils; @@ -14,6 +14,7 @@ import com.fr.design.mainframe.widget.editors.LayoutTypeEditor; import com.fr.design.mainframe.widget.editors.IntegerPropertyEditor; import com.fr.design.mainframe.widget.editors.PropertyCellEditor; 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; @@ -132,18 +133,18 @@ public class FRFitLayoutPropertiesGroupModel implements GroupModel { }else if (row == 0) { layout.setLayoutType(WBodyLayoutType.parse(state)); if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) { - WAbsoluteLayout wAbsoluteLayout = new WAbsoluteLayout("body"); - wAbsoluteLayout.setCompState(WAbsoluteLayout.STATE_FIXED); + WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body"); + wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED); Component[] components = xfl.getComponents(); xfl.removeAll(); - XWAbsoluteLayout xwAbsoluteLayout = new XWAbsoluteLayout(wAbsoluteLayout, new Dimension(0,0), true); - xfl.getLayoutAdapter().addBean(xwAbsoluteLayout, 0, 0); + XWAbsoluteBodyLayout xwAbsoluteBodyLayout = new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0,0)); + xfl.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0); for (Component component : components) { - xwAbsoluteLayout.add(component); + xwAbsoluteBodyLayout.add(component); } FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); formDesigner.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteLayout})); + FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteBodyLayout})); } else { FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); diff --git a/designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java b/designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java index dfaa1939b6..933c0d17ce 100644 --- a/designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java +++ b/designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java @@ -3,13 +3,11 @@ */ package com.fr.design.designer.properties; -import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer; - /** * @author jim * @date 2014-7-31 */ -public class FitStateRenderer extends EncoderCellRenderer{ +public class FitStateRenderer extends BodyLayoutAttrRenderer{ /** * @param encoder diff --git a/designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java b/designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java index 033552028b..4061245d75 100644 --- a/designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java +++ b/designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java @@ -1,11 +1,9 @@ package com.fr.design.designer.properties; -import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer; - /** * Created by zhouping on 2016/9/18. */ -public class LayoutTypeRenderer extends EncoderCellRenderer { +public class LayoutTypeRenderer extends BodyLayoutAttrRenderer { public LayoutTypeRenderer() { super(new LayoutTypeWrapper()); diff --git a/designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java b/designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java index e94ea1ad05..c39ea73b51 100644 --- a/designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java +++ b/designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java @@ -148,8 +148,7 @@ public class ComponentTreeModel implements TreeModel { XWFitLayout bodyFitLayout = (XWFitLayout)xCreator; for (int i = 0;i < bodyFitLayout.getXCreatorCount();i++){ //类型是绝对布局并且还是body - if (bodyFitLayout.getXCreator(i).acceptType(XWAbsoluteLayout.class) - && ((XWAbsoluteLayout)bodyFitLayout.getXCreator(i)).toData().isAbsoluteLayoutAsBody()){ + if (bodyFitLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)){ index = i; } } diff --git a/designer_form/src/com/fr/design/mainframe/ComponentTree.java b/designer_form/src/com/fr/design/mainframe/ComponentTree.java index 2b490e8bef..cc242f3695 100644 --- a/designer_form/src/com/fr/design/mainframe/ComponentTree.java +++ b/designer_form/src/com/fr/design/mainframe/ComponentTree.java @@ -16,10 +16,7 @@ import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEvent; -import com.fr.design.designer.creator.XCreator; -import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; -import com.fr.design.designer.creator.XWFitLayout; +import com.fr.design.designer.creator.*; import com.fr.design.designer.treeview.ComponentTreeCellRenderer; import com.fr.design.designer.treeview.ComponentTreeModel; import com.fr.stable.StringUtils; @@ -280,10 +277,9 @@ public class ComponentTree extends JTree { creator.notShowInComponentTree(path); } //绝对布局作为body的时候不显示自适应布局父层 - if (((XCreator) parent).acceptType(XWAbsoluteLayout.class) + if (((XCreator) parent).acceptType(XWAbsoluteBodyLayout.class) && (parent.getParent() != null) - && ((XCreator)parent.getParent()).acceptType(XWFitLayout.class) - && ((XWAbsoluteLayout)parent).toData().isAbsoluteLayoutAsBody()){ + && ((XCreator)parent.getParent()).acceptType(XWFitLayout.class)){ parent = parent.getParent().getParent(); continue; }