plough 8 years ago
parent
commit
dcca839903
  1. 116
      designer_form/src/com/fr/design/designer/creator/XWAbsoluteLayout.java
  2. 4
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

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

@ -3,14 +3,6 @@
*/
package com.fr.design.designer.creator;
import java.awt.*;
import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.HashMap;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.LayoutAdapter;
@ -20,16 +12,26 @@ import com.fr.design.designer.beans.models.SelectionModel;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.form.layout.FRAbsoluteLayout;
import com.fr.design.icon.IconPathConstants;
import com.fr.design.mainframe.*;
import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormArea;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.ui.Connector;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.form.ui.container.WLayout;
import com.fr.general.FRScreen;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import java.awt.*;
import java.awt.event.ContainerEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author richer
* @since 6.5.3
@ -44,19 +46,19 @@ public class XWAbsoluteLayout extends XLayoutContainer {
//由于屏幕分辨率不同,界面上的容器大小可能不是默认的100%,此时拖入组件时,保存的大小按照100%时的计算
protected double containerPercent = 1.0;
private HashMap<Connector,XConnector> xConnectorMap;
private HashMap<Connector, XConnector> xConnectorMap;
public XWAbsoluteLayout() {
this(new WAbsoluteLayout(),new Dimension());
this(new WAbsoluteLayout(), new Dimension());
}
public XWAbsoluteLayout(WAbsoluteLayout widget) {
this(widget,new Dimension());
this(widget, new Dimension());
}
public XWAbsoluteLayout(WAbsoluteLayout widget, Dimension initSize) {
super(widget, initSize);
this.xConnectorMap = new HashMap<Connector,XConnector>();
this.xConnectorMap = new HashMap<Connector, XConnector>();
Connector connector;
for (int i = 0; i < widget.connectorCount(); i++) {
connector = widget.getConnectorIndex(i);
@ -77,17 +79,18 @@ public class XWAbsoluteLayout extends XLayoutContainer {
}
//根据屏幕大小来确定显示的百分比, 1440*900默认100%, 1366*768缩放90%
private void initPercent(WAbsoluteLayout widget){
private void initPercent(WAbsoluteLayout widget) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension scrnsize = toolkit.getScreenSize();
double screenValue = FRScreen.getByDimension(scrnsize).getValue();
if(screenValue != FormArea.DEFAULT_SLIDER){
if (screenValue != FormArea.DEFAULT_SLIDER) {
this.setContainerPercent(screenValue / FormArea.DEFAULT_SLIDER);
}
}
/**
* 返回容器大小的百分比
*
* @return the containerPercent
*/
public double getContainerPercent() {
@ -96,16 +99,18 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 设置容器大小的百分比
*
* @param containerPercent the containerPercent to set
*/
public void setContainerPercent(double containerPercent) {
this.containerPercent = containerPercent;
minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH*containerPercent);
minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT*containerPercent);
minWidth = (int) (XWAbsoluteLayout.MIN_WIDTH * containerPercent);
minHeight = (int) (XWAbsoluteLayout.MIN_HEIGHT * containerPercent);
}
/**
* 返回界面处根据百分比调整后的最小宽度
*
* @return 最小宽度
*/
public int getActualMinWidth() {
@ -114,6 +119,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 返回界面处根据百分比调整后的最小高度
*
* @return 最小高度
*/
public int getActualMinHeight() {
@ -122,13 +128,14 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 返回界面处根据百分比调整后的间隔大小且为偶数
*
* @return 间隔
*/
public int getAcualInterval() {
// adapter那边交叉三等分、删除都要判断是否对齐,所以间隔转为偶数
int interval = (int) (toData().getCompInterval()*containerPercent);
int val = interval/2;
return val*2;
int interval = (int) (toData().getCompInterval() * containerPercent);
int val = interval / 2;
return val * 2;
}
/**
@ -138,10 +145,10 @@ public class XWAbsoluteLayout extends XLayoutContainer {
if (containerPercent == 1.0) {
return rec;
}
rec.x = (int) (rec.x/containerPercent);
rec.y = (int) (rec.y/containerPercent);
rec.width = (int) (rec.width/containerPercent);
rec.height = (int) (rec.height/containerPercent);
rec.x = (int) (rec.x / containerPercent);
rec.y = (int) (rec.y / containerPercent);
rec.width = (int) (rec.width / containerPercent);
rec.height = (int) (rec.height / containerPercent);
return rec;
}
@ -151,28 +158,29 @@ public class XWAbsoluteLayout extends XLayoutContainer {
public void updateBoundsWidget(XCreator xCreator) {
WAbsoluteLayout layout = this.toData();
if (xCreator.hasTitleStyle()) {
xCreator = (XLayoutContainer)xCreator.getParent();
xCreator = (XLayoutContainer) xCreator.getParent();
}
if (xCreator.acceptType(XWAbsoluteLayout.class)){
if (xCreator.acceptType(XWAbsoluteLayout.class)) {
((XWAbsoluteLayout) xCreator).updateBoundsWidget();
}
// 如果子组件时tab布局,则tab布局内部的组件的wiget也要更新,否则保存后重新打开大小不对
ArrayList<?> childrenList = xCreator.getTargetChildrenList();
if(!childrenList.isEmpty()){
for(int i=0; i<childrenList.size(); i++){
if (!childrenList.isEmpty()) {
for (int i = 0; i < childrenList.size(); i++) {
XWTabFitLayout tabLayout = (XWTabFitLayout) childrenList.get(i);
tabLayout.updateBoundsWidget();
}
}
BoundsWidget boundsWidget = (BoundsWidget) layout.getBoundsWidget(xCreator.toData()); Rectangle rectangle = dealWidgetBound(xCreator.getBounds());
BoundsWidget boundsWidget = (BoundsWidget) layout.getBoundsWidget(xCreator.toData());
Rectangle rectangle = dealWidgetBound(xCreator.getBounds());
}
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);
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;
}
@ -186,7 +194,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
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++){
for (int index = 0, n = this.getComponentCount(); index < n; index++) {
XCreator creator = (XCreator) this.getComponent(index);
BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData());
// 用当前的显示大小计算后调正具体位置
@ -195,7 +203,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
wgt.setBounds(rec);
creator.setBounds(rec);
//绝对布局嵌套,要更新内部的绝对布局
if (creator.acceptType(XWAbsoluteLayout.class)){
if (creator.acceptType(XWAbsoluteLayout.class)) {
creator.setBackupBound(wgtBound);
((XWAbsoluteLayout) creator).updateBoundsWidget();
}
@ -207,6 +215,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
* 更新子组件的Bound
* 这边主要用于绝对布局子组件在适应区域选项时
* 涉及到的不同分辨率下缩放
*
* @param minHeight 最小高度
*/
@Override
@ -216,10 +225,10 @@ public class XWAbsoluteLayout extends XLayoutContainer {
for (int i = 0; i < this.getComponentCount(); i++) {
XCreator creator = getXCreator(i);
Rectangle rec = new Rectangle(creator.getBounds());
rec.x = (int)(rec.x / prevContainerPercent * containerPercent);
rec.y = (int)(rec.y / prevContainerPercent * containerPercent);
rec.height = (int)(rec.height / prevContainerPercent * containerPercent);
rec.width = (int)(rec.width / prevContainerPercent * containerPercent);
rec.x = (int) (rec.x / prevContainerPercent * containerPercent);
rec.y = (int) (rec.y / prevContainerPercent * containerPercent);
rec.height = (int) (rec.height / prevContainerPercent * containerPercent);
rec.width = (int) (rec.width / prevContainerPercent * containerPercent);
BoundsWidget wgt = (BoundsWidget) toData().getBoundsWidget(creator.toData());
wgt.setBounds(rec);
creator.setBounds(rec);
@ -231,6 +240,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 增加对齐线
*
* @param connector 对齐线
*/
public void addConnector(Connector connector) {
@ -244,6 +254,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 去除对齐线
*
* @param connector 对齐线
*/
public void removeConnector(Connector connector) {
@ -253,6 +264,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 返回对应的widget容器
*
* @return 返回WAbsoluteLayout
*/
@Override
@ -267,6 +279,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 返回默认的容器name
*
* @return 返回绝对布局容器名
*/
@Override
@ -308,10 +321,10 @@ public class XWAbsoluteLayout extends XLayoutContainer {
WAbsoluteLayout abs = toData();
this.removeAll();
for (int i = 0, count = abs.getWidgetCount(); i < count; i++) {
BoundsWidget bw = (BoundsWidget)abs.getWidget(i);
BoundsWidget bw = (BoundsWidget) abs.getWidget(i);
if (bw != null) {
Rectangle bounds = bw.getBounds();
XWidgetCreator comp = (XWidgetCreator)XCreatorUtils.createXCreator(bw.getWidget());
XWidgetCreator comp = (XWidgetCreator) XCreatorUtils.createXCreator(bw.getWidget());
if (!comp.acceptType(XWParameterLayout.class)) {
comp.setDirections(Direction.ALL);
}
@ -324,6 +337,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 当前组件zorder位置替换新的控件
*
* @param widget 控件
* @param oldcreator 旧组件
* @return 组件
@ -342,6 +356,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 组件增加
*
* @param e 容器事件
*/
@Override
@ -359,6 +374,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* 在设计界面中有组件移除的时候需要通知WLayout容器重新paint
*
* @param e 容器事件
*/
@Override
@ -386,21 +402,21 @@ public class XWAbsoluteLayout extends XLayoutContainer {
@Override
public XLayoutContainer getTopLayout() {
XLayoutContainer xTopLayout = XCreatorUtils.getParentXLayoutContainer(this).getTopLayout();
if (xTopLayout != null && !xTopLayout.isEditable()){
if (xTopLayout != null && !xTopLayout.isEditable()) {
return xTopLayout;
}
else{
} else {
return this;
}
}
/**
* 得到属性名
*
* @return 属性名
* @throws java.beans.IntrospectionException
*/
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[] {
return new CRPropertyDescriptor[]{
new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(
Inter.getLocText("FR-Designer_Form-Widget_Name"))
};
@ -448,7 +464,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
* @param editingMouseListener 鼠标点击位置处理器
* @param e 鼠标点击事件
*/
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){
public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
boolean isEditing = isEditable() || designer.getCursor().getType() == Cursor.HAND_CURSOR || e.getClickCount() == 2;
@ -468,6 +484,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* body大小手动调整的时候
* 按照比例调整组件的宽度
*
* @param percent 比例
*/
@Override
@ -484,6 +501,7 @@ public class XWAbsoluteLayout extends XLayoutContainer {
/**
* body大小手动调整的时候
* 按照比例调整组件的高度
*
* @param percent 比例
*/
@Override

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

@ -133,8 +133,10 @@ public class FormSelectionUtils {
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset)
&& (y - DELAY_X_Y == container.getHeight() - copiedCreator.getHeight() / 2 - yoffset);
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
boolean isEdge = (x - DELAY_X_Y == container.getWidth() - copiedCreator.getWidth() / 2 - xoffset);
if (xOut) {
if (isEdge) {
//向左偏移

Loading…
Cancel
Save