zhouping
8 years ago
15 changed files with 367 additions and 239 deletions
After Width: | Height: | Size: 239 B |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
|
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue