|
|
|
@ -1,30 +1,21 @@
|
|
|
|
|
package com.fr.design.designer.beans.models; |
|
|
|
|
|
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Cursor; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.Point; |
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
import java.awt.Toolkit; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
import com.fr.design.beans.location.Absorptionline; |
|
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
|
import com.fr.design.mainframe.FormSelectionUtils; |
|
|
|
|
import com.fr.design.designer.beans.AdapterBus; |
|
|
|
|
import com.fr.design.designer.beans.HoverPainter; |
|
|
|
|
import com.fr.design.designer.beans.LayoutAdapter; |
|
|
|
|
import com.fr.design.designer.beans.events.DesignerEvent; |
|
|
|
|
import com.fr.design.designer.beans.location.Direction; |
|
|
|
|
import com.fr.design.designer.beans.location.Location; |
|
|
|
|
import com.fr.design.designer.creator.XConnector; |
|
|
|
|
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.XWAbsoluteLayout; |
|
|
|
|
import com.fr.design.designer.creator.*; |
|
|
|
|
import com.fr.design.mainframe.FormDesigner; |
|
|
|
|
import com.fr.design.mainframe.FormSelectionUtils; |
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 普通模式下的状态model |
|
|
|
|
*/ |
|
|
|
@ -36,8 +27,11 @@ public class StateModel {
|
|
|
|
|
private Direction driection; |
|
|
|
|
|
|
|
|
|
// 当前拖拽的起始位置
|
|
|
|
|
private int current_x; |
|
|
|
|
private int current_y; |
|
|
|
|
private int currentX; |
|
|
|
|
private int currentY; |
|
|
|
|
|
|
|
|
|
//拖拽组件原始位置大小备份
|
|
|
|
|
private Rectangle selectedPositionBackup; |
|
|
|
|
|
|
|
|
|
private Point startPoint = new Point(); |
|
|
|
|
private Point currentPoint = new Point(); |
|
|
|
@ -62,6 +56,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回direction |
|
|
|
|
* |
|
|
|
|
* @return direction方向 |
|
|
|
|
*/ |
|
|
|
|
public Direction getDirection() { |
|
|
|
@ -79,6 +74,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否能拖拽 |
|
|
|
|
* |
|
|
|
|
* @return 非outer且选中为空 |
|
|
|
|
*/ |
|
|
|
|
public boolean dragable() { |
|
|
|
@ -118,22 +114,35 @@ public class StateModel {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean addBean(XLayoutContainer container, int x, int y) { |
|
|
|
|
/** |
|
|
|
|
* @param container 容器 |
|
|
|
|
* @param mouseX 鼠标释放位置X |
|
|
|
|
* @param mouseY 鼠标释放位置Y |
|
|
|
|
* @return 是否成功 |
|
|
|
|
*/ |
|
|
|
|
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
|
|
|
|
LayoutAdapter adapter = container.getLayoutAdapter(); |
|
|
|
|
Rectangle r = ComponentUtils.getRelativeBounds(container); |
|
|
|
|
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
|
|
|
|
if (selectionModel.getSelection().size() == 1) { |
|
|
|
|
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x |
|
|
|
|
+ designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y); |
|
|
|
|
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
|
|
|
|
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
|
|
|
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
|
|
|
|
} |
|
|
|
|
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
|
|
|
|
adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y); |
|
|
|
|
adapter.addBean(creator, |
|
|
|
|
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
|
|
|
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void adding(int x, int y) { |
|
|
|
|
/** |
|
|
|
|
* @param mouseReleasedX 鼠标释放位置X |
|
|
|
|
* @param mouseReleasedY 鼠标释放位置Y |
|
|
|
|
*/ |
|
|
|
|
private void adding(int mouseReleasedX, int mouseReleasedY) { |
|
|
|
|
// 当前鼠标所在的组件
|
|
|
|
|
XCreator hoveredComponent = designer.getComponentAt(x, y, selectionModel.getSelection().getSelectedCreators()); |
|
|
|
|
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); |
|
|
|
|
|
|
|
|
|
// 获取该组件所在的焦点容器
|
|
|
|
|
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
|
|
|
@ -142,7 +151,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
if (container != null) { |
|
|
|
|
// 如果是容器,则调用其acceptComponent接受组件
|
|
|
|
|
success = addBean(container, x, y); |
|
|
|
|
success = addBean(container, mouseReleasedX, mouseReleasedY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (success) { |
|
|
|
@ -150,15 +159,16 @@ public class StateModel {
|
|
|
|
|
designer.getEditListenerTable().fireCreatorModified( |
|
|
|
|
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
|
|
|
|
} else { |
|
|
|
|
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
|
|
|
|
Toolkit.getDefaultToolkit().beep(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 取消提示
|
|
|
|
|
designer.setPainter(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否拖拽 |
|
|
|
|
* |
|
|
|
|
* @return dragging状态 |
|
|
|
|
*/ |
|
|
|
|
public boolean isDragging() { |
|
|
|
@ -167,6 +177,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否可以开始画线 |
|
|
|
|
* |
|
|
|
|
* @return startPoint不为空返回true |
|
|
|
|
*/ |
|
|
|
|
public boolean prepareForDrawLining() { |
|
|
|
@ -175,6 +186,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置开始位置 |
|
|
|
|
* |
|
|
|
|
* @param p point位置 |
|
|
|
|
*/ |
|
|
|
|
public void setStartPoint(Point p) { |
|
|
|
@ -183,6 +195,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回开始位置 |
|
|
|
|
* |
|
|
|
|
* @return 点位置 |
|
|
|
|
*/ |
|
|
|
|
public Point getStartPoint() { |
|
|
|
@ -191,6 +204,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回当前点位置 |
|
|
|
|
* |
|
|
|
|
* @return 点位置 |
|
|
|
|
*/ |
|
|
|
|
public Point getEndPoint() { |
|
|
|
@ -199,29 +213,32 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前选中组件 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void startSelecting(MouseEvent e) { |
|
|
|
|
selecting = true; |
|
|
|
|
selectionModel.setHotspotBounds(new Rectangle()); |
|
|
|
|
current_x = getMouseXY(e).x; |
|
|
|
|
current_y = getMouseXY(e).y; |
|
|
|
|
currentX = getMouseXY(e).x; |
|
|
|
|
currentY = getMouseXY(e).y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前鼠标的xy |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void startResizing(MouseEvent e) { |
|
|
|
|
if (!selectionModel.getSelection().isEmpty()) { |
|
|
|
|
driection.backupBounds(designer); |
|
|
|
|
} |
|
|
|
|
current_x = getMouseXY(e).x; |
|
|
|
|
current_y = getMouseXY(e).y; |
|
|
|
|
currentX = getMouseXY(e).x; |
|
|
|
|
currentY = getMouseXY(e).y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 起始点开始DrawLine |
|
|
|
|
* |
|
|
|
|
* @param p 点位置 |
|
|
|
|
*/ |
|
|
|
|
public void startDrawLine(Point p) { |
|
|
|
@ -238,6 +255,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 鼠标释放时所在的区域及圈中的组件 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void selectCreators(MouseEvent e) { |
|
|
|
@ -246,7 +264,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
Rectangle bounds = createCurrentBounds(x, y); |
|
|
|
|
|
|
|
|
|
if ((x != current_x) || (y != current_y)) { |
|
|
|
|
if ((x != currentX) || (y != currentY)) { |
|
|
|
|
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
|
|
|
|
} |
|
|
|
|
selectionModel.setHotspotBounds(null); |
|
|
|
@ -254,6 +272,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 画所在区域线 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void drawLine(MouseEvent e) { |
|
|
|
@ -270,16 +289,16 @@ public class StateModel {
|
|
|
|
|
private Rectangle createCurrentBounds(int x, int y) { |
|
|
|
|
Rectangle bounds = new Rectangle(); |
|
|
|
|
|
|
|
|
|
bounds.x = Math.min(x, current_x); |
|
|
|
|
bounds.y = Math.min(y, current_y); |
|
|
|
|
bounds.width = Math.max(x, current_x) - bounds.x; |
|
|
|
|
bounds.height = Math.max(y, current_y) - bounds.y; |
|
|
|
|
bounds.x = Math.min(x, currentX); |
|
|
|
|
bounds.y = Math.min(y, currentY); |
|
|
|
|
bounds.width = Math.max(x, currentX) - bounds.x; |
|
|
|
|
bounds.height = Math.max(y, currentY) - bounds.y; |
|
|
|
|
|
|
|
|
|
return bounds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
|
|
|
|
ArrayList<XCreator> creators = new ArrayList<XCreator>(); |
|
|
|
|
ArrayList<XCreator> creators = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (!root.isVisible() && !designer.isRoot(root)) { |
|
|
|
|
return creators; |
|
|
|
@ -334,6 +353,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置可拉伸方向 |
|
|
|
|
* |
|
|
|
|
* @param dir 拉伸方向 |
|
|
|
|
*/ |
|
|
|
|
public void setDirection(Direction dir) { |
|
|
|
@ -345,6 +365,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* x吸附线赋值 |
|
|
|
|
* |
|
|
|
|
* @param line 线 |
|
|
|
|
*/ |
|
|
|
|
public void setXAbsorptionline(Absorptionline line) { |
|
|
|
@ -353,6 +374,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* y吸附线赋值 |
|
|
|
|
* |
|
|
|
|
* @param line 线 |
|
|
|
|
*/ |
|
|
|
|
public void setYAbsorptionline(Absorptionline line) { |
|
|
|
@ -361,6 +383,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 等距线赋值 |
|
|
|
|
* |
|
|
|
|
* @param line 线 |
|
|
|
|
*/ |
|
|
|
|
public void setEquidistantLine(Absorptionline line) { |
|
|
|
@ -369,6 +392,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 画吸附线 |
|
|
|
|
* |
|
|
|
|
* @param g Graphics类 |
|
|
|
|
*/ |
|
|
|
|
public void paintAbsorptionline(Graphics g) { |
|
|
|
@ -385,12 +409,17 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拖拽 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void dragging(MouseEvent e) { |
|
|
|
|
//进入dragging状态时备份组件大小和位置
|
|
|
|
|
if (!dragging) { |
|
|
|
|
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
|
|
|
|
} |
|
|
|
|
checkAddable(e); |
|
|
|
|
setDependLinePainter(e); |
|
|
|
|
driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer); |
|
|
|
|
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
|
|
|
|
this.dragging = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -409,6 +438,7 @@ public class StateModel {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 释放捕获 |
|
|
|
|
* |
|
|
|
|
* @param e 鼠标事件 |
|
|
|
|
*/ |
|
|
|
|
public void releaseDragging(MouseEvent e) { |
|
|
|
|