|
|
|
@ -3,18 +3,16 @@
|
|
|
|
|
*/ |
|
|
|
|
package com.fr.design.designer.beans.location; |
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
|
|
|
|
|
|
import com.fr.design.beans.location.Absorptionline; |
|
|
|
|
import com.fr.design.beans.location.MoveUtils; |
|
|
|
|
import com.fr.design.designer.creator.*; |
|
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
|
import com.fr.design.mainframe.FormSelection; |
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
|
import com.fr.form.main.Form; |
|
|
|
|
import com.fr.form.ui.container.WAbsoluteLayout; |
|
|
|
|
import com.fr.form.ui.container.WParameterLayout; |
|
|
|
|
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; |
|
|
|
|
import com.fr.form.ui.widget.BoundsWidget; |
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author richer |
|
|
|
@ -28,10 +26,10 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
|
|
|
|
|
abstract int getCursor(); |
|
|
|
|
|
|
|
|
|
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
|
|
|
|
Rectangle oldbounds); |
|
|
|
|
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer, |
|
|
|
|
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()) { |
|
|
|
|
designer.getStateModel().setEquidistantLine(null); |
|
|
|
@ -39,16 +37,14 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
designer.getStateModel().setYAbsorptionline(null); |
|
|
|
|
return new int[]{x, y}; |
|
|
|
|
} else { |
|
|
|
|
int posy = current_bounds.y; |
|
|
|
|
|
|
|
|
|
Point relativePoint = getRelativePoint(x, y, current_bounds,designer); |
|
|
|
|
sorptionPoint(relativePoint,current_bounds, designer); |
|
|
|
|
Point relativePoint = getRelativePoint(x, y, currentBounds, designer); |
|
|
|
|
sorptionPoint(relativePoint, currentBounds, designer); |
|
|
|
|
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) { |
|
|
|
|
x = 0; |
|
|
|
|
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) { |
|
|
|
@ -64,12 +60,11 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
return new Point(x, y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) { |
|
|
|
|
boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false; |
|
|
|
|
boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; |
|
|
|
|
protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) { |
|
|
|
|
boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT; |
|
|
|
|
boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT; |
|
|
|
|
WAbsoluteLayout layout = getLayout(designer); |
|
|
|
|
FormSelection selection = designer.getSelectionModel().getSelection(); |
|
|
|
|
boolean isWidgetsIntersect = false; |
|
|
|
|
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { |
|
|
|
|
BoundsWidget temp = (BoundsWidget) layout.getWidget(i); |
|
|
|
|
if (!temp.isVisible() || selection.contains(temp.getWidget())) { |
|
|
|
@ -105,17 +100,14 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){ |
|
|
|
|
isWidgetsIntersect = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); |
|
|
|
|
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point); |
|
|
|
|
setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { |
|
|
|
|
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); |
|
|
|
|
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); |
|
|
|
|
private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle |
|
|
|
|
currentBounds, Point point) { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -131,18 +123,6 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
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) { |
|
|
|
|
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( |
|
|
|
@ -152,8 +132,7 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent(); |
|
|
|
|
if (container instanceof XWAbsoluteLayout) { |
|
|
|
|
layout = ((XWAbsoluteLayout) container).toData(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
layout = (WAbsoluteLayout) designer.getParaComponent().toData(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -164,12 +143,18 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拖拽 |
|
|
|
|
* |
|
|
|
|
* @param dx 坐标x |
|
|
|
|
* @param dy 坐标y |
|
|
|
|
* @param designer 设计界面 |
|
|
|
|
*/ |
|
|
|
|
public void drag(int dx, int dy, FormDesigner designer) { |
|
|
|
|
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的变化使得控件不停的向上或向下移动。
|
|
|
|
|
if (rec.height == MINHEIGHT) { |
|
|
|
|
ymin = rec.y; |
|
|
|
@ -192,13 +177,12 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
rec.width = MINWIDTH; |
|
|
|
|
rec.x = xmin; |
|
|
|
|
} |
|
|
|
|
if(rec != null) { |
|
|
|
|
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 更新鼠标指针形状 |
|
|
|
|
* |
|
|
|
|
* @param formEditor 设计界面组件 |
|
|
|
|
*/ |
|
|
|
|
public void updateCursor(FormDesigner formEditor) { |
|
|
|
@ -214,6 +198,7 @@ public abstract class AccessDirection implements Direction {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成组件备用的bound |
|
|
|
|
* |
|
|
|
|
* @param formEditor 设计界面组件 |
|
|
|
|
*/ |
|
|
|
|
public void backupBounds(FormDesigner formEditor) { |
|
|
|
|