Fangjie Hu 8 years ago
parent
commit
79bd3fbce9
  1. BIN
      designer_base/src/com/fr/design/images/control/combobox.png
  2. 14
      designer_base/src/com/fr/design/utils/DesignUtils.java
  3. 30
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteBodyLayoutAdapter.java
  4. 11
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  5. 1
      designer_form/src/com/fr/design/designer/creator/XCreatorUtils.java
  6. 45
      designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java
  7. 24
      designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java
  8. 5
      designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java
  9. 23
      designer_form/src/com/fr/design/designer/properties/BodyLayoutAttrRenderer.java
  10. 239
      designer_form/src/com/fr/design/designer/properties/FRAbsoluteBodyLayoutPropertiesGroupModel.java
  11. 192
      designer_form/src/com/fr/design/designer/properties/FRAbsoluteLayoutPropertiesGroupModel.java
  12. 15
      designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java
  13. 4
      designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java
  14. 4
      designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java
  15. 3
      designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java
  16. 10
      designer_form/src/com/fr/design/mainframe/ComponentTree.java

BIN
designer_base/src/com/fr/design/images/control/combobox.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

14
designer_base/src/com/fr/design/utils/DesignUtils.java

@ -230,15 +230,12 @@ public class DesignUtils {
private static FRFont getCurrentLocaleFont(){ private static FRFont getCurrentLocaleFont(){
FRFont guiFRFont; FRFont guiFRFont;
Locale defaultLocale = FRContext.getLocale(); Locale defaultLocale = Locale.getDefault();
if (isDisplaySimSun(defaultLocale)) { if (isDisplaySimSun(defaultLocale)) {
guiFRFont = getNamedFont("SimSun"); guiFRFont = getNamedFont("SimSun");
} else if(isDisplayDialog(defaultLocale)) { } else if(isDisplayDialog(defaultLocale)) {
guiFRFont = getNamedFont("Dialog"); guiFRFont = getNamedFont("Dialog");
} else if(isDisplayJapaneseFont(defaultLocale)){
//日文设计器默认用MS Mincho字体渲染
guiFRFont = getNamedFont("MS Mincho");
} else { } else {
guiFRFont = getNamedFont("Tahoma"); guiFRFont = getNamedFont("Tahoma");
} }
@ -270,14 +267,11 @@ public class DesignUtils {
private static boolean isDisplaySimSun(Locale defaultLocale){ private static boolean isDisplaySimSun(Locale defaultLocale){
return ComparatorUtils.equals(defaultLocale, Locale.SIMPLIFIED_CHINESE); 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){ 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.KOREAN)
|| ComparatorUtils.equals(defaultLocale, Locale.KOREA); || ComparatorUtils.equals(defaultLocale, Locale.KOREA);
} }

30
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);
}
}

11
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java

@ -331,15 +331,6 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override @Override
public GroupModel getLayoutProperties() { public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
if (xwAbsoluteLayout.toData().isAbsoluteLayoutAsBody()){ return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
//如果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);
}
} }
} }

1
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(WAbsoluteLayout.class, XWAbsoluteLayout.class);
xLayoutMap.put(WParameterLayout.class, XWParameterLayout.class); xLayoutMap.put(WParameterLayout.class, XWParameterLayout.class);
xLayoutMap.put(WAbsoluteBodyLayout.class, XWAbsoluteBodyLayout.class);
xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class); xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class);
xLayoutMap.put(WHorizontalBoxLayout.class, XWHorizontalBoxLayout.class); xLayoutMap.put(WHorizontalBoxLayout.class, XWHorizontalBoxLayout.class);
xLayoutMap.put(WBorderLayout.class, XWBorderLayout.class); xLayoutMap.put(WBorderLayout.class, XWBorderLayout.class);

45
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);
}
}

24
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)); xConnectorMap.put(connector, new XConnector(connector, this));
} }
this.editable = widget.isAbsoluteLayoutAsBody(); initPercent(widget);
initPercent();
}
public XWAbsoluteLayout(WAbsoluteLayout widget, Dimension initSize, boolean isAbsoluteLayoutAsBody) {
this(widget, initSize);
widget.setAbsoluteLayoutAsBody(isAbsoluteLayoutAsBody);
this.editable = isAbsoluteLayoutAsBody;
} }
/** /**
@ -97,13 +89,14 @@ public class XWAbsoluteLayout extends XLayoutContainer {
} }
//根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90% //根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90%
private void initPercent(){ private void initPercent(WAbsoluteLayout widget){
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scrnsize = toolkit.getScreenSize(); Dimension scrnsize = toolkit.getScreenSize();
double screenValue = FRScreen.getByDimension(scrnsize).getValue(); double screenValue = FRScreen.getByDimension(scrnsize).getValue();
if(screenValue != FormArea.DEFAULT_SLIDER){ if(screenValue != FormArea.DEFAULT_SLIDER){
this.setContainerPercent(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);
}
} }

5
designer_form/src/com/fr/design/designer/properties/AbsoluteStateRenderer.java

@ -1,11 +1,10 @@
package com.fr.design.designer.properties; package com.fr.design.designer.properties;
import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer;
/** /**
* Created by zhouping on 2016/8/1. * Created by zhouping on 2016/8/1.
*/ */
public class AbsoluteStateRenderer extends EncoderCellRenderer { public class AbsoluteStateRenderer extends BodyLayoutAttrRenderer {
public AbsoluteStateRenderer() { public AbsoluteStateRenderer() {
super(new AbsoluteStateWrapper()); super(new AbsoluteStateWrapper());
} }

23
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);
}
}

239
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;
}
}
}
}
}

192
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.beans.GroupModel;
import com.fr.design.designer.creator.XWAbsoluteLayout; 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.AbsoluteLayoutDirectionEditor;
import com.fr.design.mainframe.widget.editors.IntegerPropertyEditor; 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.design.mainframe.widget.editors.PropertyCellEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WBodyLayoutType;
import com.fr.general.Inter; import com.fr.general.Inter;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.util.Arrays;
import java.util.Comparator;
/** /**
* Created by zhouping on 2016/8/1. * Created by zhouping on 2016/8/1.
*/ */
public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel { public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel {
private PropertyCellEditor editor; private PropertyCellEditor editor;
private DefaultTableCellRenderer renderer; private DefaultTableCellRenderer renderer;
private AbsoluteLayoutDirectionEditor stateEditor; protected AbsoluteLayoutDirectionEditor stateEditor;
private AbsoluteStateRenderer stateRenderer; protected AbsoluteStateRenderer stateRenderer;
private WAbsoluteLayout layout; protected WAbsoluteLayout layout;
private XWAbsoluteLayout xwAbsoluteLayout; protected XWAbsoluteLayout xwAbsoluteLayout;
private LayoutTypeEditor layoutTypeEditor;
private LayoutTypeRenderer layoutTypeRenderer;
//默认body是0,自适应布局;1,绝对布局.
private WBodyLayoutType layoutType = WBodyLayoutType.FIT;
public FRAbsoluteLayoutPropertiesGroupModel(XWAbsoluteLayout xwAbsoluteLayout){ public FRAbsoluteLayoutPropertiesGroupModel(XWAbsoluteLayout xwAbsoluteLayout){
this.xwAbsoluteLayout = xwAbsoluteLayout; this.xwAbsoluteLayout = xwAbsoluteLayout;
@ -46,65 +33,31 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel {
stateRenderer = new AbsoluteStateRenderer(); stateRenderer = new AbsoluteStateRenderer();
} }
public FRAbsoluteLayoutPropertiesGroupModel(XWAbsoluteLayout xwAbsoluteLayout, WBodyLayoutType layoutType){
this(xwAbsoluteLayout);
this.layoutTypeEditor = new LayoutTypeEditor();
this.layoutTypeRenderer = new LayoutTypeRenderer();
this.layoutType = layoutType;
}
/** /**
* 布局管理器自己的属性 * 布局管理器自己的属性
*/ */
@Override @Override
public String getGroupName() { 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 @Override
public int getRowCount() { public int getRowCount() {
return layoutType == WBodyLayoutType.ABSOLUTE ? 2 : 1; return 1;
} }
@Override @Override
public TableCellRenderer getRenderer(int row) { public TableCellRenderer getRenderer(int row) {
if (layoutType == WBodyLayoutType.ABSOLUTE) { return stateRenderer;
return row == 0 ? layoutTypeRenderer : stateRenderer;
}
else {
return stateRenderer;
}
} }
@Override @Override
public TableCellEditor getEditor(int row) { public TableCellEditor getEditor(int row) {
if (layoutType == WBodyLayoutType.ABSOLUTE) { return stateEditor;
return row == 0 ? layoutTypeEditor : stateEditor;
}
else{
return stateEditor;
}
} }
@Override @Override
public Object getValue(int row, int column) { 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) { if (column == 0) {
return Inter.getLocText("FR-Designer-Widget_Scaling_Mode"); return Inter.getLocText("FR-Designer-Widget_Scaling_Mode");
} else { } else {
@ -114,42 +67,6 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel {
@Override @Override
public boolean setValue(Object value, int row, int column) { 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; int state = 0;
if(value instanceof Integer) { if(value instanceof Integer) {
state = (Integer)value; state = (Integer)value;
@ -174,95 +91,4 @@ public class FRAbsoluteLayoutPropertiesGroupModel implements GroupModel {
public boolean isEditable(int row) { public boolean isEditable(int row) {
return true; 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;
}
}
}
}
} }

15
designer_form/src/com/fr/design/designer/properties/FRFitLayoutPropertiesGroupModel.java

@ -4,7 +4,7 @@
package com.fr.design.designer.properties; package com.fr.design.designer.properties;
import com.fr.design.beans.GroupModel; 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.designer.creator.XWFitLayout;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelectionUtils; 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.IntegerPropertyEditor;
import com.fr.design.mainframe.widget.editors.PropertyCellEditor; import com.fr.design.mainframe.widget.editors.PropertyCellEditor;
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.WAbsoluteLayout;
import com.fr.form.ui.container.WBodyLayoutType; import com.fr.form.ui.container.WBodyLayoutType;
import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WFitLayout;
@ -132,18 +133,18 @@ public class FRFitLayoutPropertiesGroupModel implements GroupModel {
}else if (row == 0) { }else if (row == 0) {
layout.setLayoutType(WBodyLayoutType.parse(state)); layout.setLayoutType(WBodyLayoutType.parse(state));
if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) { if (state == WBodyLayoutType.ABSOLUTE.getTypeValue()) {
WAbsoluteLayout wAbsoluteLayout = new WAbsoluteLayout("body"); WAbsoluteBodyLayout wAbsoluteBodyLayout = new WAbsoluteBodyLayout("body");
wAbsoluteLayout.setCompState(WAbsoluteLayout.STATE_FIXED); wAbsoluteBodyLayout.setCompState(WAbsoluteLayout.STATE_FIXED);
Component[] components = xfl.getComponents(); Component[] components = xfl.getComponents();
xfl.removeAll(); xfl.removeAll();
XWAbsoluteLayout xwAbsoluteLayout = new XWAbsoluteLayout(wAbsoluteLayout, new Dimension(0,0), true); XWAbsoluteBodyLayout xwAbsoluteBodyLayout = new XWAbsoluteBodyLayout(wAbsoluteBodyLayout, new Dimension(0,0));
xfl.getLayoutAdapter().addBean(xwAbsoluteLayout, 0, 0); xfl.getLayoutAdapter().addBean(xwAbsoluteBodyLayout, 0, 0);
for (Component component : components) { for (Component component : components) {
xwAbsoluteLayout.add(component); xwAbsoluteBodyLayout.add(component);
} }
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();
formDesigner.getSelectionModel().setSelectedCreators( formDesigner.getSelectionModel().setSelectedCreators(
FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteLayout})); FormSelectionUtils.rebuildSelection(xfl, new Widget[]{wAbsoluteBodyLayout}));
} }
else { else {
FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner();

4
designer_form/src/com/fr/design/designer/properties/FitStateRenderer.java

@ -3,13 +3,11 @@
*/ */
package com.fr.design.designer.properties; package com.fr.design.designer.properties;
import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer;
/** /**
* @author jim * @author jim
* @date 2014-7-31 * @date 2014-7-31
*/ */
public class FitStateRenderer extends EncoderCellRenderer{ public class FitStateRenderer extends BodyLayoutAttrRenderer{
/** /**
* @param encoder * @param encoder

4
designer_form/src/com/fr/design/designer/properties/LayoutTypeRenderer.java

@ -1,11 +1,9 @@
package com.fr.design.designer.properties; package com.fr.design.designer.properties;
import com.fr.design.mainframe.widget.renderer.EncoderCellRenderer;
/** /**
* Created by zhouping on 2016/9/18. * Created by zhouping on 2016/9/18.
*/ */
public class LayoutTypeRenderer extends EncoderCellRenderer { public class LayoutTypeRenderer extends BodyLayoutAttrRenderer {
public LayoutTypeRenderer() { public LayoutTypeRenderer() {
super(new LayoutTypeWrapper()); super(new LayoutTypeWrapper());

3
designer_form/src/com/fr/design/designer/treeview/ComponentTreeModel.java

@ -148,8 +148,7 @@ public class ComponentTreeModel implements TreeModel {
XWFitLayout bodyFitLayout = (XWFitLayout)xCreator; XWFitLayout bodyFitLayout = (XWFitLayout)xCreator;
for (int i = 0;i < bodyFitLayout.getXCreatorCount();i++){ for (int i = 0;i < bodyFitLayout.getXCreatorCount();i++){
//类型是绝对布局并且还是body //类型是绝对布局并且还是body
if (bodyFitLayout.getXCreator(i).acceptType(XWAbsoluteLayout.class) if (bodyFitLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)){
&& ((XWAbsoluteLayout)bodyFitLayout.getXCreator(i)).toData().isAbsoluteLayoutAsBody()){
index = i; index = i;
} }
} }

10
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.ComponentAdapter;
import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.*;
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.treeview.ComponentTreeCellRenderer; import com.fr.design.designer.treeview.ComponentTreeCellRenderer;
import com.fr.design.designer.treeview.ComponentTreeModel; import com.fr.design.designer.treeview.ComponentTreeModel;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -280,10 +277,9 @@ public class ComponentTree extends JTree {
creator.notShowInComponentTree(path); creator.notShowInComponentTree(path);
} }
//绝对布局作为body的时候不显示自适应布局父层 //绝对布局作为body的时候不显示自适应布局父层
if (((XCreator) parent).acceptType(XWAbsoluteLayout.class) if (((XCreator) parent).acceptType(XWAbsoluteBodyLayout.class)
&& (parent.getParent() != null) && (parent.getParent() != null)
&& ((XCreator)parent.getParent()).acceptType(XWFitLayout.class) && ((XCreator)parent.getParent()).acceptType(XWFitLayout.class)){
&& ((XWAbsoluteLayout)parent).toData().isAbsoluteLayoutAsBody()){
parent = parent.getParent().getParent(); parent = parent.getParent().getParent();
continue; continue;
} }

Loading…
Cancel
Save