Browse Source

表单绝对布局

master
zhouping 8 years ago
parent
commit
adb74f86c8
  1. 185
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  2. 1146
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java
  3. 1047
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  4. 4
      designer_form/src/com/fr/design/designer/beans/location/Inner.java
  5. 178
      designer_form/src/com/fr/design/designer/beans/painters/FRAbsoluteLayoutPainter.java
  6. 76
      designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java
  7. 5
      designer_form/src/com/fr/design/designer/creator/XWFitLayout.java
  8. 7
      designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java
  9. 2
      designer_form/src/com/fr/design/gui/core/FormWidgetOption.java
  10. 4
      designer_form/src/com/fr/design/mainframe/FormDesignerUI.java

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

@ -9,16 +9,29 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.designer.properties.BoundsGroupModel; import com.fr.design.designer.properties.BoundsGroupModel;
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel;
import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel;
import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter { public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上
private boolean isAdd2ParentLayout = false;
private HoverPainter painter; private HoverPainter painter;
public FRAbsoluteLayoutAdapter(XLayoutContainer container) { public FRAbsoluteLayoutAdapter(XLayoutContainer container) {
super(container); super(container);
painter = new FRAbsoluteLayoutPainter(container); painter = new FRAbsoluteLayoutPainter(container);
initMinSize();
}
private void initMinSize() {
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
minWidth = layout.getActualMinWidth();
minHeight = layout.getActualMinHeight();
actualVal = layout.getAcualInterval();
margin = layout.toData().getMargin();
} }
@Override @Override
@ -37,19 +50,130 @@ public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter {
public boolean accept(XCreator creator, int x, int y) { public boolean accept(XCreator creator, int x, int y) {
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
//布局控件要先判断是不是可编辑 //布局控件要先判断是不是可编辑
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); //可以编辑,按原有逻辑判断
if(topLayout != null && !topLayout.isEditable()){ //不可编辑,当成一整个控件处理
if (comp == null){
return false; return false;
} }
boolean isAccept = x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout();
if(topLayout != null){
if (topLayout.isEditable()){
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight()
&& creator.getWidth() <= container.getWidth(); && creator.getWidth() <= container.getWidth();
return isAccept; }
else {
return acceptWidget(creator, x, y);
}
}
else{
FRLogger.getLogger().error("top layout is null!");
}
return false;
}
/**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
* @param parentComp 鼠标所在区域的组件
* @param x 坐标x
* @param y 坐标y
* @return 是则返回true
*/
public boolean isTrisectionArea(Component parentComp, int x, int y) {
XCreator creator = (XCreator)parentComp;
trisectAreaDirect = 0;
if (container.getComponentCount()<=1) {
return false;
}
int maxWidth = parentComp.getWidth();
int maxHeight = parentComp.getHeight();
int xL = parentComp.getX();
int yL = parentComp.getY();
// 组件宽高的十分之一和默认值取大
int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
if(y<yL+minRangeHeight ) {
// 在组件上侧三等分
trisectAreaDirect = COMP_TOP;
} else if(y>yL+maxHeight-minRangeHeight) {
// 在组件下侧三等分
trisectAreaDirect = COMP_BOTTOM;
} else if (x<xL+minRangeWidth) {
// 在组件左侧三等分
trisectAreaDirect = COMP_LEFT;
} else if(x>xL+maxWidth-minRangeWidth) {
// 在组件右侧三等分
trisectAreaDirect = COMP_RIGHT;
}
// tab布局的边界特殊处理,不进行三等分
if(!creator.getTargetChildrenList().isEmpty()){
return false;
}
return !ComparatorUtils.equals(trisectAreaDirect, 0);
}
private boolean acceptWidget(XCreator creator, int x, int y){
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;
isAdd2ParentLayout = true;
int componentHeight = comp.getHeight();
int componentWidth = comp.getWidth();
//上半部分高度
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY();
//下半部分高度
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
if (isCrossPointArea(comp, x, y)) {
return canAcceptWhileCrossPoint(comp, x, y);
}
if (isTrisectionArea(comp, x, y)) {
return canAcceptWhileTrisection(comp, x, y);
}
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
return y > upHeight && y < downHeight ? horizonValid : verticalValid;
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
Rectangle rect = ComponentUtils.getRelativeBounds(container);
int posX = x + rect.x;
int posY = y + rect.y;
if (!accept(creator, x, y)) {
return false;
}
addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
} }
@Override @Override
protected void addComp(XCreator creator, int x, int y) { protected void addComp(XCreator creator, int x, int y) {
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { if(!isAdd2ParentLayout) {
Rectangle r = ComponentUtils.getRelativeBounds(container); Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x;
y = y - r.y;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
x = creatorRectangle.x - r.x; x = creatorRectangle.x - r.x;
y = creatorRectangle.y - r.y; y = creatorRectangle.y - r.y;
@ -59,10 +183,9 @@ public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter {
x = x - w; x = x - w;
y = y - h; y = y - h;
} }
fix(creator, x, y); fix(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { if (creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} else { } else {
container.add(creator, creator.toData().getWidgetName()); container.add(creator, creator.toData().getWidgetName());
@ -70,6 +193,26 @@ public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter {
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
LayoutUtils.layoutRootContainer(container); LayoutUtils.layoutRootContainer(container);
}else{
fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator);
} else {
container.add(creator, creator.toData().getWidgetName());
}
XWFitLayout layout = (XWFitLayout) container;
// 更新对应的BoundsWidget
layout.updateBoundsWidget();
updateCreatorBackBound();
}
}
private void updateCreatorBackBound() {
for (int i=0,size=container.getComponentCount(); i<size; i++) {
XCreator creator = (XCreator) container.getComponent(i);
creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds());
}
} }
private void addParentCreator(XCreator child) { private void addParentCreator(XCreator child) {
@ -77,6 +220,30 @@ public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter {
container.add(parentPanel, child.toData().getWidgetName()); container.add(parentPanel, child.toData().getWidgetName());
} }
/**
* 新拖入组件时计算调整其他关联组件位置大小
* @param child 新拖入的组件
* @param x 鼠标所在x坐标
* @param y 鼠标所在y坐标
*/
private void fixAbsolute(XCreator child, int x, int y) {
Component parentComp = container.getComponentAt(x, y);
if (container.getComponentCount()==0){
child.setLocation(0, 0);
child.setSize(parentComp.getWidth(), parentComp.getHeight());
} else if(isCrossPointArea(parentComp, x, y)){
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y);
return;
} else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了
fixTrisect(parentComp, child, x, y);
return;
} else{
fixHalve(parentComp, child, x, y);
}
}
/** /**
* 组件拖拽后调整大小 * 组件拖拽后调整大小
* @param creator 组件 * @param creator 组件

1146
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java

File diff suppressed because it is too large Load Diff

1047
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

File diff suppressed because it is too large Load Diff

4
designer_form/src/com/fr/design/designer/beans/location/Inner.java

@ -40,9 +40,9 @@ public class Inner extends AccessDirection {
} }
if (y < 0) { if (y < 0) {
y = 0; y = 0;
} else if (y + current_bounds.getHeight() > designer.getRootComponent().getHeight() } else if (y + current_bounds.getHeight() > (designer.getRootComponent().getHeight() + designer.getParaHeight())
&& designer.getSelectionModel().hasSelectionComponent()) { && designer.getSelectionModel().hasSelectionComponent()) {
y = designer.getRootComponent().getHeight() - current_bounds.height; y = designer.getRootComponent().getHeight() + designer.getParaHeight() - current_bounds.height;
} }
return new Point(x, y); return new Point(x, y);
} }

178
designer_form/src/com/fr/design/designer/beans/painters/FRAbsoluteLayoutPainter.java

@ -1,6 +1,13 @@
package com.fr.design.designer.beans.painters; package com.fr.design.designer.beans.painters;
import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.mainframe.FormDesigner;
import com.fr.general.FRLogger;
import java.awt.*; import java.awt.*;
@ -8,19 +15,188 @@ import java.awt.*;
* Created by zhouping on 2016/7/11. * Created by zhouping on 2016/7/11.
*/ */
public class FRAbsoluteLayoutPainter extends AbstractPainter { public class FRAbsoluteLayoutPainter extends AbstractPainter {
private static final int BORDER_PROPORTION = 10;
private static final int X = 0;
private static final int Y = 1;
private static final int WIDTH = 2;
private static final int HEIGHT = 3;
private static final Color DEPEND_LINE_COLOR = new Color(200, 200, 200);
private static final int DEPEND_LINE_SCOPE = 3;
/**
* 构造函数
* @param container
*/
public FRAbsoluteLayoutPainter(XLayoutContainer container) { public FRAbsoluteLayoutPainter(XLayoutContainer container) {
super(container); super(container);
} }
/** /**
* 组件渲染 * 组件渲染
*
* @param g 画图类 * @param g 画图类
* @param startX 开始位置x * @param startX 开始位置x
* @param startY 开始位置y * @param startY 开始位置y
*/ */
@Override @Override
public void paint(Graphics g, int startX, int startY) { public void paint(Graphics g, int startX, int startY) {
if(hotspot_bounds == null && creator != null && container != null){
drawDependingLine(g);
return;
}
super.paint(g, startX, startY); super.paint(g, startX, startY);
//如果absolute不可编辑那么就将之当普通控件处理,在周围添加控件,
//否则,只往内部添加,不需要出现蓝色悬浮提示框
if(container.isEditable()){
return;
}
int x = hotspot.x - hotspot_bounds.x;
int y = hotspot.y - hotspot_bounds.y;
FRAbsoluteLayoutAdapter adapter = (FRAbsoluteLayoutAdapter) container.getLayoutAdapter();
int[] hot_rec;
boolean accept = adapter.accept(creator, x, y);
Component currentComp = container.getComponentAt(x, y);
//不可编辑的时候要获取顶层的绝对布局容器
if (XCreatorUtils.getHotspotContainer((XCreator) currentComp) != null) {
currentComp = XCreatorUtils.getHotspotContainer((XCreator) currentComp).getTopLayout();
if (currentComp == null) {
FRLogger.getLogger().info("FRAbsoluteLayoutPainter get currentComp null!");
return;
}
}
else{
FRLogger.getLogger().info("FRAbsoluteLayoutPainter getHotspotContainer currentComp null!");
return;
}
Color bColor = XCreatorConstants.FIT_LAYOUT_HOTSPOT_COLOR;
if (accept) {
y = (y == container.getHeight()) ? y - 1 : y;
x = (x == container.getWidth()) ? x - 1 : x;
hot_rec = adapter.getChildPosition(currentComp, creator, x + hotspot_bounds.x, y + hotspot_bounds.y);
} else {
bColor = XCreatorConstants.LAYOUT_FORBIDDEN_COLOR;
Rectangle rec = currentComp.getBounds();
hot_rec = currentComp == container ? new int[]{x, y, 0, 0} : new int[]{rec.x, rec.y, rec.width, rec.height};
}
drawRegionBackground(g, hot_rec[X], hot_rec[Y] + startY, hot_rec[WIDTH], hot_rec[HEIGHT], bColor, accept);
if (accept) {
//画交叉区域和中间点区域
//拖入的区域也改为整个渲染,点区域的后画下,不然被遮住了
paintCrossPoint(currentComp, g, x, y);
}
}
private void paintCrossPoint(Component currentComp, Graphics g, int x, int y) {
if (currentComp == container) {
return;
}
Color bColor = XCreatorConstants.FIT_LAYOUT_POINT_COLOR;
int cX = currentComp.getX(), cY = currentComp.getY(), cH = currentComp.getHeight(), cW = currentComp.getWidth();
int defaultWidth = cW / BORDER_PROPORTION, defaultHeight = cH / BORDER_PROPORTION;
// 交叉点提示区域最大值为10px
int defaultLength = Math.min(BORDER_PROPORTION, Math.min(defaultWidth, defaultHeight));
Component topComp = container.getTopComp(cX, cY);
Component bottomComp = container.getBottomComp(cX, cY, cH);
Component rightComp = container.getRightComp(cX, cY, cW); //组件的左右组件要区分上侧和下侧
Component leftComp = container.getLeftComp(cX, cY);
boolean top = topComp != null && topComp != container, left = leftComp != null && leftComp != container,
bottom = bottomComp != null && bottomComp != container, right = rightComp != null && rightComp != container;
if (top || left) {
drawRegionBackground(g, cX + hotspot_bounds.x, cY + hotspot_bounds.y, defaultLength, defaultLength, bColor, true);
}
if (bottom || left) {
drawRegionBackground(g, cX + hotspot_bounds.x, cY + cH - defaultLength + hotspot_bounds.y, defaultLength, defaultLength, bColor,true);
}
if (top || right) {
drawRegionBackground(g, cX + cW - defaultLength + hotspot_bounds.x, cY + hotspot_bounds.y, defaultLength, defaultLength, bColor,true);
}
if (bottom || right) {
drawRegionBackground(g, cX + cW - defaultLength + hotspot_bounds.x, cY + cH - defaultLength + hotspot_bounds.y, defaultLength, defaultLength, bColor,true);
}
if (left && right) {
if (leftComp.getY() == cY && rightComp.getY() == cY) {
drawRegionBackground(g, cX + cW / 2 - defaultWidth + hotspot_bounds.x, cY + hotspot_bounds.y, defaultWidth * 2, defaultLength, bColor,true);
}
//底边线位置,左右组件都不为null且低端对齐,取左、右靠下侧组件判断
leftComp = container.getBottomLeftComp(cX, cY, cH);
rightComp = container.getBottomRightComp(cX, cY, cH, cW);
if ((leftComp.getY() + leftComp.getHeight() == cY + cH) && (rightComp.getY() + rightComp.getHeight()== cY + cH)) {
drawRegionBackground(g, cX + cW / 2 - defaultWidth + hotspot_bounds.x, cY + cH - defaultLength + hotspot_bounds.y, defaultWidth * 2, defaultLength, bColor,true);
}
}
if (top && bottom) {
if (topComp.getX() == cX && bottomComp.getX() == cX) {
drawRegionBackground(g, cX + hotspot_bounds.x, cY + cH / 2 - defaultHeight + hotspot_bounds.y, defaultLength, defaultHeight * 2, bColor,true);
}
// 右边线位置,上下组件不为null且右端对齐,取上、下靠右侧组件判断
topComp = container.getRightTopComp(cX, cY, cW);
bottomComp = container.getRightBottomComp(cX, cY, cH, cW);
if ((topComp.getX() + topComp.getWidth() == cX + cW) && (bottomComp.getX() + bottomComp.getWidth() == cX + cW)) {
drawRegionBackground(g, cX + cW - defaultLength + hotspot_bounds.x, cY + cH / 2 - defaultHeight + hotspot_bounds.y, defaultLength, defaultHeight * 2, bColor,true);
}
}
}
// 画依附线
private void drawDependingLine(Graphics g){
Graphics2D g2d = (Graphics2D) g;
Stroke backup = g2d.getStroke();
// 当前拖拽组件的坐标
int oriX = creator.getX();
int oriY = creator.getY();
// 拖拽位置的即时坐标
double x = hotspot.getX();
double y = hotspot.getY();
// 容器所有的内部组件的横纵坐标值
int[] posXs = container.getHors();
int[] posYs = container.getVeris();
// 依附线的坐标
int lineX = 0;
int lineY = 0;
// 根据拖拽位置调整依附线的坐标
lineX = getDependLinePos(lineX, posXs, oriX, x);
lineY = getDependLinePos(lineY, posYs, oriY, y);
g2d.setStroke(backup);
g2d.setColor(DEPEND_LINE_COLOR);
if(lineX != 0){
g2d.drawRect(lineX, 0, 0, container.getHeight());
}
if(lineY != 0){
g2d.drawRect(0, lineY, container.getWidth(), 0);
}
}
/**
* 根据容器内部组件的横纵坐标值画依附线
*
* @param lineCoordinate 依附线坐标值
* @param referCoordinates 容器内部所有组件坐标值
* @param oriCoordinate 当前拖拽组件坐标
* @param currentCoordinate 拖拽位置的即时坐标
* @return 依附线的坐标
*
*/
private int getDependLinePos(int lineCoordinate,int referCoordinates[],int oriCoordinate,double currentCoordinate){
for(int i = 0; i < referCoordinates.length; i++){
if(referCoordinates[i] == oriCoordinate){
continue;
}
if(currentCoordinate > referCoordinates[i] - DEPEND_LINE_SCOPE && currentCoordinate < referCoordinates[i] + DEPEND_LINE_SCOPE){
lineCoordinate = referCoordinates[i];
break;
}
}
return lineCoordinate;
} }
} }

76
designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java

@ -21,10 +21,9 @@ import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.form.layout.FRAbsoluteLayout; import com.fr.design.form.layout.FRAbsoluteLayout;
import com.fr.design.form.util.XCreatorConstants; import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.icon.IconPathConstants; import com.fr.design.icon.IconPathConstants;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.*;
import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor;
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor;
import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer; import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer;
@ -34,10 +33,14 @@ 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.WAbsoluteLayout.BoundsWidget; import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.general.FRScreen; import com.fr.general.FRScreen;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
import org.eclipse.swt.internal.gdip.Rect;
import javax.swing.*;
/** /**
* @author richer * @author richer
@ -47,6 +50,8 @@ public class XWAbsoluteLayout extends XLayoutContainer {
private static final int EDIT_BTN_WIDTH = 60; private static final int EDIT_BTN_WIDTH = 60;
private static final int EDIT_BTN_HEIGHT = 24; private static final int EDIT_BTN_HEIGHT = 24;
private int minWidth = WLayout.MIN_WIDTH;
private int minHeight = WLayout.MIN_HEIGHT;
//由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算 //由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算
protected double containerPercent = 1.0; protected double containerPercent = 1.0;
@ -97,6 +102,35 @@ public class XWAbsoluteLayout extends XLayoutContainer {
*/ */
public void setContainerPercent(double containerPercent) { public void setContainerPercent(double containerPercent) {
this.containerPercent = containerPercent; this.containerPercent = containerPercent;
minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH*containerPercent);
minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT*containerPercent);
}
/**
* 返回界面处根据百分比调整后的最小宽度
* @return 最小宽度
*/
public int getActualMinWidth() {
return this.minWidth;
}
/**
* 返回界面处根据百分比调整后的最小高度
* @return 最小高度
*/
public int getActualMinHeight() {
return this.minHeight;
}
/**
* 返回界面处根据百分比调整后的间隔大小且为偶数
* @return 间隔
*/
public int getAcualInterval() {
// adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数
int interval = (int) (toData().getCompInterval()*containerPercent);
int val = interval/2;
return val*2;
} }
/** /**
@ -114,16 +148,46 @@ public class XWAbsoluteLayout extends XLayoutContainer {
} }
/** /**
* 新增删除拉伸后更新每个组件的BoundsWidget * 新增删除拉伸后个组件的BoundsWidget
*/ */
public void updateBoundsWidget(XCreator xCreator) { public void updateBoundsWidget(XCreator xCreator) {
WAbsoluteLayout layout = this.toData(); WAbsoluteLayout layout = this.toData();
if (xCreator.shouldScaleCreator() || xCreator.hasTitleStyle()) { if (xCreator.hasTitleStyle()) {
xCreator = (XLayoutContainer)xCreator.getParent(); xCreator = (XLayoutContainer)xCreator.getParent();
} }
BoundsWidget boundsWidget = layout.getBoundsWidget(xCreator.toData()); BoundsWidget boundsWidget = layout.getBoundsWidget(xCreator.toData());
Rectangle rectangle = dealWidgetBound(xCreator.getBounds()); Rectangle rectangle = dealWidgetBound(xCreator.getBounds());
boundsWidget.setCalculatedBounds(rectangle); }
private Rectangle calculateBound(Rectangle rec, double pw, double ph){
Rectangle calRec = new Rectangle(0,0,0,0);
calRec.x = (int)(rec.x / pw);
calRec.y = (int)(rec.y / ph);
calRec.width = (int)(rec.width / pw);
calRec.height = (int)(rec.height / ph);
return calRec;
}
/**
* 新增删除拉伸后每个组件的BoundsWidget
*/
public void updateBoundsWidget() {
WAbsoluteLayout layout = this.toData();
Rectangle backupBound = this.getBackupBound();
Rectangle currentBound = this.getBounds();
if (backupBound != null && layout.getCompState() == WAbsoluteLayout.STATE_FIT) {
double percentW = ((double) backupBound.width / (double) currentBound.width);
double percentH = ((double) backupBound.height / (double) currentBound.height);
for (int index = 0, n = this.getComponentCount(); index < n; index++){
XCreator creator = (XCreator) this.getComponent(index);
BoundsWidget wgt = layout.getBoundsWidget(creator.toData());
// 用当前的显示大小计算后调正具体位置
Rectangle wgtBound = dealWidgetBound(creator.getBounds());
Rectangle rec = calculateBound(wgtBound, percentW, percentH);
wgt.setBounds(rec);
creator.setBounds(rec);
}
}
} }
/** /**

5
designer_form/src/com/fr/design/designer/creator/XWFitLayout.java

@ -744,6 +744,10 @@ public class XWFitLayout extends XLayoutContainer {
tabLayout.updateBoundsWidget(); tabLayout.updateBoundsWidget();
} }
} }
//如果子组件是绝对布局,则内部的widget也要更新
if (creator.acceptType(XWAbsoluteLayout.class)){
((XWAbsoluteLayout) creator).updateBoundsWidget();
}
} }
layout.setContainerHeight(containerHeight); layout.setContainerHeight(containerHeight);
layout.setContainerWidth(containerWidth); layout.setContainerWidth(containerWidth);
@ -801,6 +805,7 @@ public class XWFitLayout extends XLayoutContainer {
BoundsWidget bw = wlayout.getBoundsWidget(wgt); BoundsWidget bw = wlayout.getBoundsWidget(wgt);
wlayout.removeWidget(bw); wlayout.removeWidget(bw);
updateBoundsWidget(); updateBoundsWidget();
((FRFitLayoutAdapter)getLayoutAdapter()).updateCreatorBackBound();
} }
/** /**

7
designer_form/src/com/fr/design/designer/creator/XWParameterLayout.java

@ -183,4 +183,11 @@ public class XWParameterLayout extends XWAbsoluteLayout {
@Override @Override
public void updateBoundsWidget(XCreator xCreator) { public void updateBoundsWidget(XCreator xCreator) {
} }
/**
* 新增删除拉伸后每个组件的BoundsWidget
*/
@Override
public void updateBoundsWidget() {
}
} }

2
designer_form/src/com/fr/design/gui/core/FormWidgetOption.java

@ -1 +1 @@
package com.fr.design.gui.core; import javax.swing.Icon; import com.fr.base.BaseUtils; import com.fr.form.ui.ElementCaseEditor; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WHorizontalBoxLayout; import com.fr.form.ui.container.WParameterLayout; import com.fr.form.ui.container.WVerticalBoxLayout; import com.fr.general.Inter; /** * Author : Shockway * Date: 13-6-17 * Time: 上午10:40 */ public class FormWidgetOption extends WidgetOption { /** * 返回名字 * @return 名字 */ @Override public String optionName() { return null; } /** * 返回图标 * @return 图标 */ @Override public Icon optionIcon() { return null; } /** * 组件类 * @return 类 */ @Override public Class<? extends Widget> widgetClass() { return null; } /** * 返回组件 * @return 控件 */ @Override public Widget createWidget() { return null; } /* * 表单容器 */ public static WidgetOption[] getFormContainerInstance() { return new WidgetOption[] { ABSOLUTELAYOUTCONTAINER, BORDERLAYOUTCONTAINER, HORIZONTALBOXLAYOUTCONTAINER, VERTICALBOXLAYOUTCONTAINER, CARDLAYOUTCONTAINER, FITLAYOUTCONTAINER }; } /** * 表单工具栏上的布局 * @return 控件 */ public static WidgetOption[] getFormLayoutInstance() { return new WidgetOption[] {CARDLAYOUTCONTAINER/*, ABSOLUTELAYOUTCONTAINER*/}; } public static final WidgetOption ABSOLUTELAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_AbsoluteLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_absolute.png"), WAbsoluteLayout.class); public static final WidgetOption BORDERLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_BorderLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_border.png"), WBorderLayout.class); public static final WidgetOption CARDLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_CardLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/card_layout_16.png"), WCardLayout.class); public static final WidgetOption HORIZONTALBOXLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Layout-HBox"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_h_16.png"), WHorizontalBoxLayout.class); public static final WidgetOption VERTICALBOXLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_VerticalBoxLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_v_16.png"), WVerticalBoxLayout.class); public static final WidgetOption FITLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Designer-Layout_Adaptive_Layout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_v_16.png"), WFitLayout.class); public static final WidgetOption PARAMETERCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Para-Body"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_parameter.png"), WParameterLayout.class); public static final WidgetOption ELEMENTCASE = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Form-Report"), BaseUtils.readIcon("/com/fr/web/images/form/resources/report_16.png"), ElementCaseEditor.class); } package com.fr.design.gui.core; import javax.swing.Icon; import com.fr.base.BaseUtils; import com.fr.form.ui.ElementCaseEditor; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WHorizontalBoxLayout; import com.fr.form.ui.container.WParameterLayout; import com.fr.form.ui.container.WVerticalBoxLayout; import com.fr.general.Inter; /** * Author : Shockway * Date: 13-6-17 * Time: 上午10:40 */ public class FormWidgetOption extends WidgetOption { /** * 返回名字 * @return 名字 */ @Override public String optionName() { return null; } /** * 返回图标 * @return 图标 */ @Override public Icon optionIcon() { return null; } /** * 组件类 * @return 类 */ @Override public Class<? extends Widget> widgetClass() { return null; } /** * 返回组件 * @return 控件 */ @Override public Widget createWidget() { return null; } /* * 表单容器 */ public static WidgetOption[] getFormContainerInstance() { return new WidgetOption[] { ABSOLUTELAYOUTCONTAINER, BORDERLAYOUTCONTAINER, HORIZONTALBOXLAYOUTCONTAINER, VERTICALBOXLAYOUTCONTAINER, CARDLAYOUTCONTAINER, FITLAYOUTCONTAINER }; } /** * 表单工具栏上的布局 * @return 控件 */ public static WidgetOption[] getFormLayoutInstance() { return new WidgetOption[] {CARDLAYOUTCONTAINER, ABSOLUTELAYOUTCONTAINER}; } public static final WidgetOption ABSOLUTELAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_AbsoluteLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_absolute.png"), WAbsoluteLayout.class); public static final WidgetOption BORDERLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_BorderLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_border.png"), WBorderLayout.class); public static final WidgetOption CARDLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_CardLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/card_layout_16.png"), WCardLayout.class); public static final WidgetOption HORIZONTALBOXLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Layout-HBox"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_h_16.png"), WHorizontalBoxLayout.class); public static final WidgetOption VERTICALBOXLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_VerticalBoxLayout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_v_16.png"), WVerticalBoxLayout.class); public static final WidgetOption FITLAYOUTCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Designer-Layout_Adaptive_Layout"), BaseUtils.readIcon("/com/fr/web/images/form/resources/boxlayout_v_16.png"), WFitLayout.class); public static final WidgetOption PARAMETERCONTAINER = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Para-Body"), BaseUtils.readIcon("/com/fr/web/images/form/resources/layout_parameter.png"), WParameterLayout.class); public static final WidgetOption ELEMENTCASE = WidgetOptionFactory.createByWidgetClass(Inter .getLocText("FR-Designer_Form-Report"), BaseUtils.readIcon("/com/fr/web/images/form/resources/report_16.png"), ElementCaseEditor.class); }

4
designer_form/src/com/fr/design/mainframe/FormDesignerUI.java

@ -95,9 +95,9 @@ public class FormDesignerUI extends ComponentUI {
if (designer.getPainter() != null) { if (designer.getPainter() != null) {
// ComponentAdapter和LayoutAdapter提供的额外的Painter,该Painter一般用于提示作用, // ComponentAdapter和LayoutAdapter提供的额外的Painter,该Painter一般用于提示作用,
// 相当于一个浮动层 // 相当于一个浮动层, 要考虑参数面板的高度
designer.getPainter().paint(g, designer.getArea().getHorizontalValue(), designer.getPainter().paint(g, designer.getArea().getHorizontalValue(),
designer.getArea().getVerticalValue()); designer.getArea().getVerticalValue() + designer.getParaHeight());
} }
AddingModel addingModel = designer.getAddingModel(); AddingModel addingModel = designer.getAddingModel();

Loading…
Cancel
Save