Browse Source

Merge pull request #827 in BA/design from ~YAOH.WU/design_0407:dev to dev

* commit '5f9cf7bb3f52d5c077f8ed48f006a12103e7346e':
  无JIRA任务 组件复用之前master合到dev时丢失的代码以及组件复用近期bug修复
  无任务 代码调整
  report-1945frm本地组件复用:1、自适应或者tab布局时,不选中粘贴默认为上下平分左上角的组件;2、tab布局(有无参数面板)粘贴位置问题
master
superman 8 years ago
parent
commit
a28420f6a5
  1. 35
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  2. 45
      designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java
  3. 4
      designer_base/src/com/fr/design/locale/designer.properties
  4. 5
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  5. 2
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  6. 4
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  7. 2
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  8. 57
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  9. 59
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  10. 59
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  11. 53
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  12. 41
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

35
designer_base/src/com/fr/design/beans/location/MoveUtils.java

@ -18,9 +18,7 @@ public class MoveUtils {
public static final int SORPTION_UNIT = 5; public static final int SORPTION_UNIT = 5;
private static final int EQUIDISTANTLINE_UNIT = 4; private static final int EQUIDISTANTLINE_UNIT = 4;
public static WidgetForbidWindow widgetForbidWindow = new WidgetForbidWindow(); private static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private MoveUtils() { private MoveUtils() {
@ -259,8 +257,7 @@ public class MoveUtils {
equidistantLineInfo.setReference(bounds.y); equidistantLineInfo.setReference(bounds.y);
equidistantLineInfo.setDirection(SwingConstants.BOTTOM); equidistantLineInfo.setDirection(SwingConstants.BOTTOM);
} }
} } else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))) {
else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))){
//当前操作rec在bounds的右侧 //当前操作rec在bounds的右侧
if (left > (bounds.getX() + bounds.getWidth())){ if (left > (bounds.getX() + bounds.getWidth())){
equidistantLineInfo.setDistance(left - (bounds.x + bounds.width)); equidistantLineInfo.setDistance(left - (bounds.x + bounds.width));
@ -279,13 +276,6 @@ public class MoveUtils {
} }
} }
public static void displayForbidWindow(int x, int y) {
widgetForbidWindow.showWindow(x, y);
}
public static void hideForbidWindow() {
widgetForbidWindow.hideWindow();
}
/** /**
* 吸附 * 吸附
@ -318,25 +308,16 @@ public class MoveUtils {
RectangleIterator iterator = designer.createRectangleIterator(); RectangleIterator iterator = designer.createRectangleIterator();
java.util.List<Rectangle> cacheRecs = new ArrayList<Rectangle>(); java.util.List<Rectangle> cacheRecs = new ArrayList<Rectangle>();
//是否存在控件重叠
boolean isWidgetsIntersects = false;
while (iterator.hasNext()) { while (iterator.hasNext()) {
Rectangle bounds = iterator.nextRectangle(); Rectangle bounds = iterator.nextRectangle();
cacheRecs.add(bounds); cacheRecs.add(bounds);
boolean isIntersects = operatingRectangle.intersects(bounds);
findX(px, bounds, left, right, width); findX(px, bounds, left, right, width);
findY(py, bounds, top, bottom, height); findY(py, bounds, top, bottom, height);
if (!isParameterLayout) { if (!isParameterLayout) {
if(isIntersects) {
isWidgetsIntersects = true;
}
else{
findEquidistantLine(bounds, left, top, height, width); findEquidistantLine(bounds, left, top, height, width);
} }
} }
}
showForbiddenWindow(designer, x, y, isWidgetsIntersects);
createXAbsorptionline(px, designer, width, cacheRecs); createXAbsorptionline(px, designer, width, cacheRecs);
createYAbsorptionline(py, designer, height, cacheRecs); createYAbsorptionline(py, designer, height, cacheRecs);
@ -353,18 +334,6 @@ public class MoveUtils {
return sorptionPoint; return sorptionPoint;
} }
public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){
if (isIntersects){
if(designer.getDesignerLocationOnScreen() != null) {
displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y);
}
designer.setWidgetsIntersected(true);
}
else{
designer.setWidgetsIntersected(false);
hideForbidWindow();
}
}
private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List<Rectangle> cacheRecs) { private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List<Rectangle> cacheRecs) {
Absorptionline line = null; Absorptionline line = null;

45
designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java

@ -1,45 +0,0 @@
package com.fr.design.beans.location;
import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.icon.IconPathConstants;
import com.fr.general.Inter;
import javax.swing.*;
/**
* Created by zhouping on 2016/7/24.
*/
public class WidgetForbidWindow extends JWindow {
private static final int WIDTH = 150;
private static final int HEIGHT = 20;
private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
/**
* 构造函数
*/
public WidgetForbidWindow() {
this.add(promptButton);
this.setSize(WIDTH, HEIGHT);
}
/**
* 在指定位置显示窗口, 默认将window的中心点放到指定位置上
*
* @param x x坐标
* @param y y坐标
*/
public void showWindow(int x, int y) {
this.setLocation(x - WIDTH / 2, y - HEIGHT / 2);
this.setVisible(true);
}
/**
* 隐藏当前窗口
*/
public void hideWindow() {
this.setVisible(false);
}
}

4
designer_base/src/com/fr/design/locale/designer.properties

@ -588,6 +588,10 @@ FR-Designer-Move_Tab_First=move to first
FR-Designer-Move_Tab_End=move to end FR-Designer-Move_Tab_End=move to end
FR-Designer-Move_Tab_Next=move to next FR-Designer-Move_Tab_Next=move to next
FR-Designer-Move_Tab_Prev=move to previous FR-Designer-Move_Tab_Prev=move to previous
FR-Designer_Too_Large_To_Paste=too large to paste
FR-Designer_Too_Small_To_Paste=Too small to paste
FR-Designer_AxisReversed=AxisValue FR-Designer_AxisReversed=AxisValue
FR-Designer_Logarithmic=Logarithmic FR-Designer_Logarithmic=Logarithmic
FR-Designer_Chart_Log_Base=Log Base FR-Designer_Chart_Log_Base=Log Base

5
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -588,7 +588,12 @@ FR-Designer-Move_Tab_First=move to first
FR-Designer-Move_Tab_End=move to end FR-Designer-Move_Tab_End=move to end
FR-Designer-Move_Tab_Next=move to next FR-Designer-Move_Tab_Next=move to next
FR-Designer-Move_Tab_Prev=move to previous FR-Designer-Move_Tab_Prev=move to previous
FR-Designer_Too_Large_To_Paste=Too large to paste!
FR-Designer_Too_Small_To_Paste=Too small to paste!
FR-Designer_AxisReversed=Axis in reverse order FR-Designer_AxisReversed=Axis in reverse order
FR-Designer_Logarithmic=Log scale FR-Designer_Logarithmic=Log scale
FR-Designer_Chart_Log_Base=Log Base FR-Designer_Chart_Log_Base=Log Base
FR-Designer_Chart_F_Radar_Axis=Value Axis FR-Designer_Chart_F_Radar_Axis=Value Axis

2
designer_base/src/com/fr/design/locale/designer_ja_JP.properties

@ -553,6 +553,8 @@ FR-Designer_Background_Clear=
FR-Designer_Background_Image_Select= FR-Designer_Background_Image_Select=
FR-Designer_Initial_Background_Tips= FR-Designer_Initial_Background_Tips=
FR-Designer_Mouse_Move_Tips= FR-Designer_Mouse_Move_Tips=
FR-Designer_Too_Large_To_Paste=\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u30DC\u30FC\u30C0\u30FC\u306B\u8D85\u3048\u305F\u306E\u3067\u3001\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\uFF01
FR-Designer_Too_Small_To_Paste=\u8A72\u5F53\u51E6\u306B\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u9AD8\u3059\u304E\uFF01
FR-Designer_Mouse_Click_Tips= FR-Designer_Mouse_Click_Tips=
FR-Designer_Plugin_Should_Update_Please_Contact_Developer= FR-Designer_Plugin_Should_Update_Please_Contact_Developer=
FR-Designer_AxisReversed=\u8EF8\u9006\u9806 FR-Designer_AxisReversed=\u8EF8\u9006\u9806

4
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -588,6 +588,10 @@ FR-Designer_Background_Image_Select=\u9009\u62E9\u56FE\u7247
FR-Designer_Initial_Background_Tips=\u6309\u94AE\u7684\u521D\u59CB\u80CC\u666F FR-Designer_Initial_Background_Tips=\u6309\u94AE\u7684\u521D\u59CB\u80CC\u666F
FR-Designer_Mouse_Move_Tips=\u9F20\u6807\u79FB\u52A8\u5230\u6309\u94AE\u4E0A\u7684\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F FR-Designer_Mouse_Move_Tips=\u9F20\u6807\u79FB\u52A8\u5230\u6309\u94AE\u4E0A\u7684\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F
FR-Designer_Mouse_Click_Tips=\u9F20\u6807\u70B9\u51FB\u6309\u94AE\u65F6\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F FR-Designer_Mouse_Click_Tips=\u9F20\u6807\u70B9\u51FB\u6309\u94AE\u65F6\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F
FR-Designer_Too_Large_To_Paste=\u7EC4\u4EF6\u5927\u5C0F\u8D85\u51FA\u8FB9\u754C\uFF0C\u65E0\u6CD5\u7C98\u8D34\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u5904\u65E0\u6CD5\u7C98\u8D34\uFF0C\u5C0F\u4E8E\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01
FR-Designer_AxisReversed=\u8F74\u9006\u5E8F FR-Designer_AxisReversed=\u8F74\u9006\u5E8F
FR-Designer_Logarithmic=\u5BF9\u6570\u523B\u5EA6 FR-Designer_Logarithmic=\u5BF9\u6570\u523B\u5EA6
FR-Designer_Chart_Log_Base=\u5E95\u6570 FR-Designer_Chart_Log_Base=\u5E95\u6570

2
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -573,6 +573,8 @@ FR-Designer_Background_Gradient_Color=
FR-Designer_Background_Image= FR-Designer_Background_Image=
FR-Designer_Background_Clear= FR-Designer_Background_Clear=
FR-Designer_Background_Image_Select= FR-Designer_Background_Image_Select=
FR-Designer_Too_Large_To_Paste=\u7D44\u4EF6\u5927\u5C0F\u8D85\u51FA\u908A\u754C\uFF0C\u7121\u6CD5\u7C98\u8CBC\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u8655\u7121\u6CD5\u7C98\u8CBC\uFF0C\u5C0F\u65BC\u7D44\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01
FR-Designer_Initial_Background_Tips= FR-Designer_Initial_Background_Tips=
FR-Designer_Mouse_Move_Tips= FR-Designer_Mouse_Move_Tips=
FR-Designer_Mouse_Click_Tips= FR-Designer_Mouse_Click_Tips=

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

@ -1,7 +1,5 @@
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
import java.awt.*;
import com.fr.design.beans.GroupModel; import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
@ -9,13 +7,14 @@ 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.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.form.ui.container.WAbsoluteLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import java.awt.*;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上 //是不是添加到父容器上
private boolean isAdd2ParentLayout = false; private boolean isAdd2ParentLayout = false;
@ -74,48 +73,39 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout();
if(topLayout != null){ if(topLayout != null){
if (topLayout.isEditable()){ if (topLayout.isEditable()){
return topLayoutAccept(creator, x, y, topLayout); return topLayoutAccept(creator, x, y);
} }
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
return false; return false;
} else {
return acceptWidget(x, y);
} }
else { } else {
return acceptWidget(creator, x, y);
}
}
else{
FRLogger.getLogger().error("top layout is null!"); FRLogger.getLogger().error("top layout is null!");
} }
return false; return false;
} }
//toplayout假如可以编辑的话就往里面添加组件 //topLayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { private boolean topLayoutAccept(XCreator creator, int x, int y) {
//判断有没有和当前控件重叠 //允许组件重叠,可以不判断有没有和当前控件重叠
//先计算当前控件的位置 //先计算当前控件的位置
int creatorX, creatorY; int creatorX, creatorY;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
creatorX = creatorRectangle.x; creatorX = creatorRectangle.x;
creatorY = creatorRectangle.y; creatorY = creatorRectangle.y;
} else { } else {
//这边计算得到的组件其实位置是正确的,
//因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
// 例如高度为21,那么就是+10-10;
// 高度为20,那么就是+10-10; 没区别
int w = creator.getWidth() / 2; int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2; int h = creator.getHeight() / 2;
creatorX = x - w; creatorX = x - w;
creatorY = y - h; creatorY = y - h;
}
//再判断和布局中其他控件重叠
Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight());
WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData();
for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i);
Rectangle rectangle = temp.getBounds();
if (curRec.intersects(rectangle)){
return false;
}
} }
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
return false; return false;
@ -169,11 +159,10 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
} }
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围 //当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(XCreator creator, int x, int y){ private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit(); XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container; container = parent != null ? parent : container;
@ -244,7 +233,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
if (creator.hasTitleStyle()) { if (creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} else { } else {
container.add(creator, creator.toData().getWidgetName()); container.add(creator, creator.toData().getWidgetName(),0);
} }
XWAbsoluteLayout layout = (XWAbsoluteLayout) container; XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator); layout.updateBoundsWidget(creator);
@ -255,7 +244,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator); addParentCreator(creator);
} else { } else {
container.add(creator, creator.toData().getWidgetName()); container.add(creator, creator.toData().getWidgetName(),0);
} }
XWFitLayout layout = (XWFitLayout) container; XWFitLayout layout = (XWFitLayout) container;
// 更新对应的BoundsWidget // 更新对应的BoundsWidget
@ -274,7 +263,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
private void addParentCreator(XCreator child) { private void addParentCreator(XCreator child) {
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight()); XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
container.add(parentPanel, child.toData().getWidgetName()); container.add(parentPanel, child.toData().getWidgetName(),0);
} }
/** /**
@ -325,17 +314,15 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
int height = creator.getHeight(); int height = creator.getHeight();
int width = creator.getWidth(); int width = creator.getWidth();
if (x < 0) { if (x < 0) {
width += x; x = container.getX();
x = 0;
} else if (x + creator.getWidth() > container.getWidth()) { } else if (x + creator.getWidth() > container.getWidth()) {
width = container.getWidth() - x; x = container.getWidth() - width;
} }
if (y < 0) { if (y < 0) {
height += y; y = container.getY();
y = 0;
} else if (y + creator.getHeight() > container.getHeight()) { } else if (y + creator.getHeight() > container.getHeight()) {
height = container.getHeight() - y; y = container.getHeight() - height;
} }
creator.setBounds(x, y, width, height); creator.setBounds(x, y, width, height);

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

@ -3,12 +3,6 @@
*/ */
package com.fr.design.designer.beans.adapters.layout; package com.fr.design.designer.beans.adapters.layout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import com.fr.design.beans.GroupModel; import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel; import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter; import com.fr.design.designer.beans.HoverPainter;
@ -22,14 +16,16 @@ import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRFitLayoutConstraints; import com.fr.design.designer.properties.FRFitLayoutConstraints;
import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel; import com.fr.design.designer.properties.FRFitLayoutPropertiesGroupModel;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.JForm;
import com.fr.design.utils.ComponentUtils; import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* 自适应布局的容器适配器 * 自适应布局的容器适配器
@ -52,6 +48,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
public void setEdit(boolean edit) { public void setEdit(boolean edit) {
isEdit = edit; isEdit = edit;
} }
/** /**
* 构造函数 * 构造函数
* *
@ -134,7 +131,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
isFindRelatedComps = false; isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y); Component comp = container.getComponentAt(x, y);
if (checkInterval(comp)) { if (comp == null || checkInterval(comp)) {
return false; return false;
} }
//如果当前处于边缘地带, 那么就把他贴到父容器上 //如果当前处于边缘地带, 那么就把他贴到父容器上
@ -269,25 +266,14 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
return super.isCrossPointArea(currentComp, x, y); return super.isCrossPointArea(currentComp, x, y);
} }
protected void initCompsList() {
super.initCompsList();
}
protected void clearCompsList() {
super.clearCompsList();
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) { protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds(); return mainLayout.getBounds();
} }
private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) { private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) {
// 参数界面高度对纵坐标产生的影响 // zhouping: REPORT-2334 表单tab布局中图表放大缩小会明显
JForm jform = (JForm) (HistoryTemplateListPane.getInstance().getCurrentEditingTemplate()); // 这边不需要单独处理参数面板高度了,下面的方法中获取的是XWCardMainBorderLayout相对坐标
if (jform.getFormDesign().getParaComponent() != null) {
backupBound.y -= jform.getFormDesign().getParaHeight();
}
Rectangle rec = getLayoutBound(mainLayout); Rectangle rec = getLayoutBound(mainLayout);
// XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响 // XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响
// 减掉之后可以按照它原来的逻辑执行 // 减掉之后可以按照它原来的逻辑执行
@ -558,8 +544,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minWidth - getMinWidth(leftComps)); difference = Math.max(difference, minWidth - getMinWidth(leftComps));
} }
//重新计算左右两侧组件size、point //重新计算左右两侧组件size、point
if (CalculateLefttRelatComponent(difference)) { if (calculateLefttRelatComponent(difference)) {
CalculateRightRelatComponent(objx + difference, -difference); calculateRightRelatComponent(objx + difference, -difference);
} }
} }
@ -674,10 +660,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minHeight - getMinHeight(upComps)); difference = Math.max(difference, minHeight - getMinHeight(upComps));
} }
//重新计算上下两侧组件size、point //重新计算上下两侧组件size、point
if (CalculateUpRelatComponent(difference)) { if (calculateUpRelatComponent(difference)) {
CalculateDownRelatComponent(objY + difference, -difference); calculateDownRelatComponent(objY + difference, -difference);
} }
;
} }
/** /**
@ -757,13 +742,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
int height = creatorHeight; int height = creatorHeight;
calculateRelatedComponent(x, y, width, height); calculateRelatedComponent(x, y, width, height);
if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) { if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) {
CalculateRightRelatComponent(x, width + actualVal); calculateRightRelatComponent(x, width + actualVal);
} else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) { } else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) {
CalculateLefttRelatComponent(width + actualVal); calculateLefttRelatComponent(width + actualVal);
} else if (!downComps.isEmpty() && getAllWidth(downComps) == width) { } else if (!downComps.isEmpty() && getAllWidth(downComps) == width) {
CalculateDownRelatComponent(y, height + actualVal); calculateDownRelatComponent(y, height + actualVal);
} else if (!upComps.isEmpty() && getAllWidth(upComps) == width) { } else if (!upComps.isEmpty() && getAllWidth(upComps) == width) {
CalculateUpRelatComponent(height + actualVal); calculateUpRelatComponent(height + actualVal);
} else { } else {
// 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理 // 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理
calculateNoRelatedComponent(x, y, width, height); calculateNoRelatedComponent(x, y, width, height);
@ -1026,7 +1011,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
setAdjustedSize(tabLayout, offset, isHor); setAdjustedSize(tabLayout, offset, isHor);
for (int m = 0; m < tabLayout.getComponentCount(); m++) { for (int m = 0; m < tabLayout.getComponentCount(); m++) {
XCreator childCreator = tabLayout.getXCreator(m); XCreator childCreator = tabLayout.getXCreator(m);
BoundsWidget wgt = (BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData()); WAbsoluteLayout.BoundsWidget wgt = (WAbsoluteLayout.BoundsWidget) tabLayout.toData().getBoundsWidget(childCreator.toData());
wgt.setBounds(tabLayout.getComponent(m).getBounds()); wgt.setBounds(tabLayout.getComponent(m).getBounds());
} }
adjustCreatorsSize(percent, tabLayout, isHor); adjustCreatorsSize(percent, tabLayout, isHor);
@ -1069,7 +1054,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param objX 调整后的坐标x * @param objX 调整后的坐标x
* @param objWidth 调整后的宽度 * @param objWidth 调整后的宽度
*/ */
protected void CalculateRightRelatComponent(int objX, int objWidth) { protected void calculateRightRelatComponent(int objX, int objWidth) {
int count = rightComps.size(); int count = rightComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) rightComps.get(i); XCreator creator = (XCreator) rightComps.get(i);
@ -1109,7 +1094,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小 * 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/ */
protected boolean CalculateLefttRelatComponent(int objWidth) { protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) { if (isBeyondAdjustWidthScope(objWidth)) {
return false; return false;
} }
@ -1127,7 +1112,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸下边框 调整下方的组件位置大小 * 删除或拉伸下边框 调整下方的组件位置大小
*/ */
protected void CalculateDownRelatComponent(int objY, int objHeight) { protected void calculateDownRelatComponent(int objY, int objHeight) {
int count = downComps.size(); int count = downComps.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) downComps.get(i); XCreator creator = (XCreator) downComps.get(i);
@ -1167,7 +1152,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/** /**
* 删除或拉伸上边框 调整上方的组件位置大小 * 删除或拉伸上边框 调整上方的组件位置大小
*/ */
protected boolean CalculateUpRelatComponent(int objHeight) { protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) { if (isBeyondAdjustHeightScope(objHeight)) {
return false; return false;
} }

59
designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java

@ -27,10 +27,10 @@ public abstract class AccessDirection implements Direction {
abstract int getCursor(); abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldbounds); Rectangle oldBounds);
protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) { protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理 // 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) { if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null); designer.getStateModel().setEquidistantLine(null);
@ -38,16 +38,14 @@ public abstract class AccessDirection implements Direction {
designer.getStateModel().setYAbsorptionline(null); designer.getStateModel().setYAbsorptionline(null);
return new int[]{x, y}; return new int[]{x, y};
} else { } else {
int posy = current_bounds.y; Point relativePoint = getRelativePoint(x, y, currentBounds, designer);
sorptionPoint(relativePoint, currentBounds, designer);
Point relativePoint = getRelativePoint(x, y, current_bounds,designer);
sorptionPoint(relativePoint,current_bounds, designer);
return new int[]{relativePoint.x, relativePoint.y}; return new int[]{relativePoint.x, relativePoint.y};
} }
} }
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) { protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) {
if (x < 0) { if (x < 0) {
x = 0; x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { } else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
@ -63,12 +61,11 @@ public abstract class AccessDirection implements Direction {
return new Point(x, y); return new Point(x, y);
} }
protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) { protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) {
boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false; boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT;
boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT;
WAbsoluteLayout layout = getLayout(designer); WAbsoluteLayout layout = getLayout(designer);
FormSelection selection = designer.getSelectionModel().getSelection(); FormSelection selection = designer.getSelectionModel().getSelection();
boolean isWidgetsIntersect = false;
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i); BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) { if (!temp.isVisible() || selection.contains(temp.getWidget())) {
@ -104,17 +101,14 @@ public abstract class AccessDirection implements Direction {
break; break;
} }
if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){
isWidgetsIntersect = true;
}
} }
processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point);
} }
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); currentBounds, Point point) {
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
designer.getStateModel().setEquidistantLine(null); designer.getStateModel().setEquidistantLine(null);
} }
@ -130,18 +124,6 @@ public abstract class AccessDirection implements Direction {
return relativeRec; return relativeRec;
} }
private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){
if(isIntersects){
if(designer.getLocationOnScreen() != null) {
MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y);
}
designer.setWidgetsIntersect(true);
}
else{
MoveUtils.hideForbidWindow();
designer.setWidgetsIntersect(false);
}
}
private WAbsoluteLayout getLayout(final FormDesigner designer){ private WAbsoluteLayout getLayout(final FormDesigner designer){
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(
@ -151,8 +133,7 @@ public abstract class AccessDirection implements Direction {
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if (container instanceof XWAbsoluteLayout) { if (container instanceof XWAbsoluteLayout) {
layout = ((XWAbsoluteLayout) container).toData(); layout = ((XWAbsoluteLayout) container).toData();
} } else {
else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData(); layout = (WAbsoluteLayout) designer.getParaComponent().toData();
} }
} else { } else {
@ -163,12 +144,18 @@ public abstract class AccessDirection implements Direction {
/** /**
* 拖拽 * 拖拽
*
* @param dx 坐标x * @param dx 坐标x
* @param dy 坐标y * @param dy 坐标y
* @param designer 设计界面 * @param designer 设计界面
*/ */
public void drag(int dx, int dy, FormDesigner designer) { public void drag(int dx, int dy, FormDesigner designer) {
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds()); Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds());
if (rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
} else {
return;
}
//设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。 //设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。
if(rec.height == MINHEIGHT){ if(rec.height == MINHEIGHT){
ymin = rec.y; ymin = rec.y;
@ -191,9 +178,7 @@ public abstract class AccessDirection implements Direction {
rec.width = MINWIDTH; rec.width = MINWIDTH;
rec.x = xmin; rec.x = xmin;
} }
if(rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
}
} }
/** /**

53
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -136,19 +136,35 @@ public class SelectionModel {
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
if (selection.getSelectedCreator() instanceof XWFitLayout) { if (selection.getSelectedCreator() instanceof XWFitLayout) {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) {
Rectangle rec = selection.getRelativeBounds(); XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator();
//Tab布局 //tab布局编辑器内部左上角第一个坐标点
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), int leftUpX = container.toData().getMargin().getLeft() + 1;
clipboard, int leftUpY = container.toData().getMargin().getTop() + 1;
rec.x + rec.width / 2, //选中第一个坐标点坐在的组件
rec.y + DELTA_X_Y); selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, container, clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
} else {
//自适应布局编辑器内部左上角第一个坐标点
int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1;
int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else { } else {
Rectangle rec = selection.getRelativeBounds();
//自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard, clipboard,
rec.x + rec.width / 2, rectangle.x + rectangle.width / 2,
rec.y + DELTA_X_Y); rectangle.y + DELTA_X_Y);
}
} }
} else { } else {
//绝对布局 //绝对布局
@ -178,12 +194,23 @@ public class SelectionModel {
container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局 //自适应布局
Rectangle selectionRec = selection.getRelativeBounds(); Rectangle selectionRec = selection.getRelativeBounds();
//获取父容器位置,补充因参数面板高度导致的位置坐标计算偏移
Rectangle containerRec = ComponentUtils.getRelativeBounds(container); Rectangle containerRec = ComponentUtils.getRelativeBounds(container);
int positionX, positionY;
if (container.getClass().equals(XWTabFitLayout.class)) {
//tab内部粘贴不补充高度偏移
//且不计算参数面板造成的影响,因为在
//@see com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter#addBean中做了
positionX = selectionRec.x + selectionRec.width / 2;
positionY = (int) (selectionRec.y + selectionRec.height * OFFSET_RELATIVE);
} else {
//计算自适应布局位置 //计算自适应布局位置
int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; positionX = selectionRec.x - containerRec.x + selectionRec.width / 2;
int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE);
}
FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY);
} else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局 //绝对布局

41
designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

@ -3,8 +3,10 @@ package com.fr.design.mainframe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -83,15 +85,27 @@ public class FormSelectionUtils {
* 相对布局粘贴 * 相对布局粘贴
*/ */
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
//@see FRTabFitLayoutAdapter
Rectangle tabContainerRect = ComponentUtils.getRelativeBounds(designer.getSelectionModel().getSelection()
.getSelectedCreator().getParent());
designer.getSelectionModel().getSelection().reset(); designer.getSelectionModel().getSelection().reset();
for (XCreator creator : clipboard.getSelectedCreators()) { for (XCreator creator : clipboard.getSelectedCreators()) {
try { try {
Widget copied = copyWidget(designer, creator); Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) {
if (!adapter.accept(copiedCreator, x - tabContainerRect.x, y - tabContainerRect.y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
} else {
if (!adapter.accept(copiedCreator, x, y)) { if (!adapter.accept(copiedCreator, x, y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return; return;
} }
}
boolean addSuccess = adapter.addBean(copiedCreator, x, y); boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) { if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
@ -118,29 +132,18 @@ public class FormSelectionUtils {
XLayoutContainer container = layoutAdapter.getContainer(); XLayoutContainer container = layoutAdapter.getContainer();
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth(); boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight(); boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
/*
* 组件原始位置位于布局的右下角 y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
* 和布局右下边界线紧挨 boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset);
* 粘贴时组件在原始位置向左错开20像素 if (xOut) {
* x,y同时越界 if (isEdge) {
*/
if (xOut && yOut) {
//向左偏移 //向左偏移
x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset; x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset;
}
//紧贴下边界 //紧贴下边界
y = container.getHeight() - copiedCreator.getHeight() / 2 - yoffset; else {
return new Point(x, y); x = container.getWidth() - copiedCreator.getWidth() / 2 - xoffset;
} }
/*
* 组件原始位置与布局边界距离小于20像素下边界&右边界同时小于或者任意一个边界小于
* 则粘贴时距离小于20像素一侧直接贴近布局边界
* 距离大于20像素的一侧正常错开
* x,y中只有一个越界
*/
if ((xOut || yOut)) {
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x;
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
return new Point(x, y);
} }
} }
return new Point(x, y); return new Point(x, y);

Loading…
Cancel
Save