mengao
8 years ago
18 changed files with 1219 additions and 1151 deletions
@ -1,133 +1,141 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import java.awt.Rectangle; |
import java.awt.Rectangle; |
||||||
|
|
||||||
import com.fr.design.designer.creator.XWAbsoluteLayout; |
import com.fr.design.designer.creator.XWAbsoluteLayout; |
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.designer.beans.AdapterBus; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import com.fr.design.designer.beans.ComponentAdapter; |
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.designer.creator.XCreator; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
import com.fr.design.designer.creator.XWParameterLayout; |
import com.fr.design.designer.creator.XWParameterLayout; |
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
import com.fr.general.ComparatorUtils; |
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* 添加状态下的model |
* 添加状态下的model |
||||||
*/ |
*/ |
||||||
public class AddingModel { |
public class AddingModel { |
||||||
|
|
||||||
// 当前要添加的组件
|
// 当前要添加的组件
|
||||||
private XCreator creator; |
private XCreator creator; |
||||||
// 记录当前鼠标的位置信息
|
// 记录当前鼠标的位置信息
|
||||||
private int current_x; |
private int currentX; |
||||||
private int current_y; |
private int currentY; |
||||||
private boolean added; |
private boolean added; |
||||||
|
|
||||||
public AddingModel(FormDesigner designer, XCreator xCreator) { |
public AddingModel(FormDesigner designer, XCreator xCreator) { |
||||||
String creatorName = getXCreatorName(designer, xCreator); |
String creatorName = getXCreatorName(designer, xCreator); |
||||||
this.creator = xCreator; |
this.creator = xCreator; |
||||||
instantiateCreator(designer, creatorName); |
instantiateCreator(designer, creatorName); |
||||||
// 初始的时候隐藏该组件的图标
|
// 初始的时候隐藏该组件的图标
|
||||||
current_x = -this.creator.getWidth(); |
currentY = -this.creator.getWidth(); |
||||||
current_y = -this.creator.getHeight(); |
currentX = -this.creator.getHeight(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 待说明 |
* 待说明 |
||||||
* @param designer 设计器 |
* |
||||||
* @param creatorName 组件名 |
* @param designer 设计器 |
||||||
*/ |
* @param creatorName 组件名 |
||||||
public void instantiateCreator(FormDesigner designer, String creatorName) { |
*/ |
||||||
creator.toData().setWidgetName(creatorName); |
public void instantiateCreator(FormDesigner designer, String creatorName) { |
||||||
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); |
creator.toData().setWidgetName(creatorName); |
||||||
adapter.initialize(); |
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator); |
||||||
creator.addNotify(); |
adapter.initialize(); |
||||||
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); |
creator.addNotify(); |
||||||
} |
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter); |
||||||
|
} |
||||||
public AddingModel(XCreator xCreator, int x, int y) { |
|
||||||
this.creator = xCreator; |
public AddingModel(XCreator xCreator, int x, int y) { |
||||||
this.creator.backupCurrentSize(); |
this.creator = xCreator; |
||||||
this.creator.backupParent(); |
this.creator.backupCurrentSize(); |
||||||
this.creator.setSize(xCreator.initEditorSize()); |
this.creator.backupParent(); |
||||||
current_x = x - (xCreator.getWidth() / 2); |
this.creator.setSize(xCreator.initEditorSize()); |
||||||
current_y = y - (xCreator.getHeight() / 2); |
currentX = x - (xCreator.getWidth() / 2); |
||||||
} |
currentY = y - (xCreator.getHeight() / 2); |
||||||
|
} |
||||||
/** |
|
||||||
* 隐藏当前组件的图标 |
/** |
||||||
*/ |
* 隐藏当前组件的图标 |
||||||
public void reset() { |
*/ |
||||||
current_x = -this.creator.getWidth(); |
public void reset() { |
||||||
current_y = -this.creator.getHeight(); |
currentX = -this.creator.getWidth(); |
||||||
} |
currentY = -this.creator.getHeight(); |
||||||
|
} |
||||||
public String getXCreatorName(FormDesigner designer,XCreator x){ |
|
||||||
String def= x.createDefaultName(); |
public String getXCreatorName(FormDesigner designer, XCreator x) { |
||||||
if (x.acceptType(XWParameterLayout.class)) { |
String def = x.createDefaultName(); |
||||||
return def; |
if (x.acceptType(XWParameterLayout.class)) { |
||||||
} |
return def; |
||||||
int i = 0; |
} |
||||||
while (designer.getTarget().isNameExist(def + i)) { |
int i = 0; |
||||||
i++; |
while (designer.getTarget().isNameExist(def + i)) { |
||||||
} |
i++; |
||||||
return def+i; |
} |
||||||
} |
return def + i; |
||||||
|
} |
||||||
public int getCurrentX() { |
|
||||||
return current_x; |
public int getCurrentX() { |
||||||
} |
return currentX; |
||||||
|
} |
||||||
public int getCurrentY() { |
|
||||||
return current_y; |
public int getCurrentY() { |
||||||
} |
return currentY; |
||||||
|
} |
||||||
|
|
||||||
/** |
|
||||||
* 移动组件图标到鼠标事件发生的位置 |
/** |
||||||
* @param x 坐标 |
* 移动组件图标到鼠标事件发生的位置 |
||||||
* @param y 坐标 |
* |
||||||
*/ |
* @param x 坐标 |
||||||
public void moveTo(int x, int y) { |
* @param y 坐标 |
||||||
current_x = x - (this.creator.getWidth() / 2); |
*/ |
||||||
current_y = y - (this.creator.getHeight() / 2); |
public void moveTo(int x, int y) { |
||||||
} |
currentX = x - (this.creator.getWidth() / 2); |
||||||
|
currentY = y - (this.creator.getHeight() / 2); |
||||||
public XCreator getXCreator() { |
} |
||||||
return this.creator; |
|
||||||
} |
public XCreator getXCreator() { |
||||||
|
return this.creator; |
||||||
/** |
} |
||||||
* 当前组件是否已经添加到某个容器中 |
|
||||||
* @return 是返回true |
/** |
||||||
*/ |
* 当前组件是否已经添加到某个容器中 |
||||||
public boolean isCreatorAdded() { |
* |
||||||
return added; |
* @return 是返回true |
||||||
} |
*/ |
||||||
|
public boolean isCreatorAdded() { |
||||||
/** |
return added; |
||||||
* 加入容器 |
} |
||||||
* @param designer 设计器 |
|
||||||
* @param container 容器 |
/** |
||||||
* @param x 坐标 |
* 加入容器 |
||||||
* @param y 坐标 |
* |
||||||
* @return 成功返回true |
* @param designer 设计器 |
||||||
*/ |
* @param container 容器 |
||||||
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { |
* @param x 坐标 |
||||||
//考虑不同布局嵌套的情况,获取顶层容器
|
* @param y 坐标 |
||||||
XLayoutContainer xLayoutContainer = container.getTopLayout(); |
* @return 成功返回true |
||||||
if(xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)){ |
*/ |
||||||
container = xLayoutContainer; |
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { |
||||||
} |
//考虑不同布局嵌套的情况,获取顶层容器
|
||||||
|
XLayoutContainer xLayoutContainer = container.getTopLayout(); |
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { |
||||||
if(!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())){ |
container = xLayoutContainer; |
||||||
return added = container.getLayoutAdapter().addBean(creator, x + designer.getArea().getHorizontalValue(), y + designer.getArea().getVerticalValue()); |
} |
||||||
} |
|
||||||
return added = container.getLayoutAdapter().addBean(creator, |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
x + designer.getArea().getHorizontalValue() - rect.x, |
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { |
||||||
y + designer.getArea().getVerticalValue() - rect.y); |
added = container.getLayoutAdapter().addBean(creator, |
||||||
} |
x + designer.getArea().getHorizontalValue(), |
||||||
|
y + designer.getArea().getVerticalValue()); |
||||||
|
return added; |
||||||
|
} |
||||||
|
added = container.getLayoutAdapter().addBean(creator, |
||||||
|
x + designer.getArea().getHorizontalValue() - rect.x, |
||||||
|
y + designer.getArea().getVerticalValue() - rect.y); |
||||||
|
return added; |
||||||
|
} |
||||||
} |
} |
@ -1,446 +1,476 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import java.awt.Component; |
import com.fr.design.beans.location.Absorptionline; |
||||||
import java.awt.Cursor; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import java.awt.Graphics; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import java.awt.Point; |
import com.fr.design.designer.beans.LayoutAdapter; |
||||||
import java.awt.Rectangle; |
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
import java.awt.Toolkit; |
import com.fr.design.designer.beans.location.Direction; |
||||||
import java.awt.event.MouseEvent; |
import com.fr.design.designer.beans.location.Location; |
||||||
import java.util.ArrayList; |
import com.fr.design.designer.creator.*; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.beans.location.Absorptionline; |
import com.fr.design.mainframe.FormSelectionUtils; |
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.utils.ComponentUtils; |
||||||
import com.fr.design.mainframe.FormSelectionUtils; |
|
||||||
import com.fr.design.designer.beans.AdapterBus; |
import java.awt.*; |
||||||
import com.fr.design.designer.beans.HoverPainter; |
import java.awt.event.MouseEvent; |
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
import java.util.ArrayList; |
||||||
import com.fr.design.designer.beans.events.DesignerEvent; |
|
||||||
import com.fr.design.designer.beans.location.Direction; |
/** |
||||||
import com.fr.design.designer.beans.location.Location; |
* 普通模式下的状态model |
||||||
import com.fr.design.designer.creator.XConnector; |
*/ |
||||||
import com.fr.design.designer.creator.XCreator; |
public class StateModel { |
||||||
import com.fr.design.designer.creator.XCreatorUtils; |
// 对应的selection model
|
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
|
||||||
import com.fr.design.designer.creator.XWAbsoluteLayout; |
private SelectionModel selectionModel; |
||||||
import com.fr.design.utils.ComponentUtils; |
// 当前鼠标进入拖拽区域的位置类型
|
||||||
|
private Direction driection; |
||||||
/** |
|
||||||
* 普通模式下的状态model |
// 当前拖拽的起始位置
|
||||||
*/ |
private int currentX; |
||||||
public class StateModel { |
private int currentY; |
||||||
// 对应的selection model
|
|
||||||
|
//拖拽组件原始位置大小备份
|
||||||
private SelectionModel selectionModel; |
private Rectangle selectedPositionBackup; |
||||||
// 当前鼠标进入拖拽区域的位置类型
|
|
||||||
private Direction driection; |
private Point startPoint = new Point(); |
||||||
|
private Point currentPoint = new Point(); |
||||||
// 当前拖拽的起始位置
|
|
||||||
private int current_x; |
private Absorptionline lineInX; |
||||||
private int current_y; |
private Absorptionline lineInY; |
||||||
|
//等距线
|
||||||
private Point startPoint = new Point(); |
private Absorptionline lineEquidistant; |
||||||
private Point currentPoint = new Point(); |
|
||||||
|
// 当前是否处于拖拽选择状态
|
||||||
private Absorptionline lineInX; |
private boolean selecting; |
||||||
private Absorptionline lineInY; |
private boolean dragging; |
||||||
//等距线
|
|
||||||
private Absorptionline lineEquidistant; |
private boolean addable; |
||||||
|
|
||||||
// 当前是否处于拖拽选择状态
|
private FormDesigner designer; |
||||||
private boolean selecting; |
|
||||||
private boolean dragging; |
public StateModel(FormDesigner designer) { |
||||||
|
this.designer = designer; |
||||||
private boolean addable; |
selectionModel = designer.getSelectionModel(); |
||||||
|
} |
||||||
private FormDesigner designer; |
|
||||||
|
/** |
||||||
public StateModel(FormDesigner designer) { |
* 返回direction |
||||||
this.designer = designer; |
* |
||||||
selectionModel = designer.getSelectionModel(); |
* @return direction方向 |
||||||
} |
*/ |
||||||
|
public Direction getDirection() { |
||||||
/** |
return driection; |
||||||
* 返回direction |
} |
||||||
* @return direction方向 |
|
||||||
*/ |
/** |
||||||
public Direction getDirection() { |
* 是否有组件正被选中 |
||||||
return driection; |
* |
||||||
} |
* @return true 如果至少一个组件被选中 |
||||||
|
*/ |
||||||
/** |
public boolean isSelecting() { |
||||||
* 是否有组件正被选中 |
return selecting; |
||||||
* |
} |
||||||
* @return true 如果至少一个组件被选中 |
|
||||||
*/ |
/** |
||||||
public boolean isSelecting() { |
* 是否能拖拽 |
||||||
return selecting; |
* |
||||||
} |
* @return 非outer且选中为空 |
||||||
|
*/ |
||||||
/** |
public boolean dragable() { |
||||||
*是否能拖拽 |
return ((driection != Location.outer) && !selecting); |
||||||
* @return 非outer且选中为空 |
} |
||||||
*/ |
|
||||||
public boolean dragable() { |
/** |
||||||
return ((driection != Location.outer) && !selecting); |
* 拖拽中是否可以转换为添加模式: |
||||||
} |
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
||||||
|
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
||||||
/** |
*/ |
||||||
* 拖拽中是否可以转换为添加模式: |
private void checkAddable(MouseEvent e) { |
||||||
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
addable = false; |
||||||
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
designer.setPainter(null); |
||||||
*/ |
|
||||||
private void checkAddable(MouseEvent e) { |
if (driection != Location.inner) { |
||||||
addable = false; |
return; |
||||||
designer.setPainter(null); |
} |
||||||
|
|
||||||
if (driection != Location.inner) { |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
return; |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
} |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
|
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
if (creatorContainer != null && creatorContainer != container |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
designer.setPainter(painter); |
||||||
if (creatorContainer != null && creatorContainer != container |
if (painter != null) { |
||||||
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
rect.x -= designer.getArea().getHorizontalValue(); |
||||||
designer.setPainter(painter); |
rect.y -= designer.getArea().getVerticalValue(); |
||||||
if (painter != null) { |
painter.setRenderingBounds(rect); |
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
rect.x -= designer.getArea().getHorizontalValue(); |
painter.setCreator(creator); |
||||||
rect.y -= designer.getArea().getVerticalValue(); |
} |
||||||
painter.setRenderingBounds(rect); |
addable = true; |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
} |
||||||
painter.setCreator(creator); |
} |
||||||
} |
|
||||||
addable = true; |
/** |
||||||
} |
* @param container 容器 |
||||||
} |
* @param mouseX 鼠标释放位置X |
||||||
|
* @param mouseY 鼠标释放位置Y |
||||||
private boolean addBean(XLayoutContainer container, int x, int y) { |
* @return 是否成功 |
||||||
LayoutAdapter adapter = container.getLayoutAdapter(); |
*/ |
||||||
Rectangle r = ComponentUtils.getRelativeBounds(container); |
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
||||||
if (selectionModel.getSelection().size() == 1) { |
LayoutAdapter adapter = container.getLayoutAdapter(); |
||||||
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x |
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
||||||
+ designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y); |
if (selectionModel.getSelection().size() == 1) { |
||||||
} |
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
||||||
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y); |
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
} |
} |
||||||
return true; |
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
||||||
} |
adapter.addBean(creator, |
||||||
|
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
private void adding(int x, int y) { |
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
// 当前鼠标所在的组件
|
} |
||||||
XCreator hoveredComponent = designer.getComponentAt(x, y, selectionModel.getSelection().getSelectedCreators()); |
return true; |
||||||
|
} |
||||||
// 获取该组件所在的焦点容器
|
|
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
/** |
||||||
|
* @param mouseReleasedX 鼠标释放位置X |
||||||
boolean success = false; |
* @param mouseReleasedY 鼠标释放位置Y |
||||||
|
*/ |
||||||
if (container != null) { |
private void adding(int mouseReleasedX, int mouseReleasedY) { |
||||||
// 如果是容器,则调用其acceptComponent接受组件
|
// 当前鼠标所在的组件
|
||||||
success = addBean(container, x, y); |
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); |
||||||
} |
|
||||||
|
// 获取该组件所在的焦点容器
|
||||||
if (success) { |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
||||||
FormSelectionUtils.rebuildSelection(designer); |
|
||||||
designer.getEditListenerTable().fireCreatorModified( |
boolean success = false; |
||||||
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
|
||||||
} else { |
if (container != null) { |
||||||
Toolkit.getDefaultToolkit().beep(); |
// 如果是容器,则调用其acceptComponent接受组件
|
||||||
} |
success = addBean(container, mouseReleasedX, mouseReleasedY); |
||||||
|
} |
||||||
// 取消提示
|
|
||||||
designer.setPainter(null); |
if (success) { |
||||||
} |
FormSelectionUtils.rebuildSelection(designer); |
||||||
|
designer.getEditListenerTable().fireCreatorModified( |
||||||
/** |
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
||||||
*是否拖拽 |
} else { |
||||||
* @return dragging状态 |
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
||||||
*/ |
Toolkit.getDefaultToolkit().beep(); |
||||||
public boolean isDragging() { |
} |
||||||
return dragging; |
// 取消提示
|
||||||
} |
designer.setPainter(null); |
||||||
|
} |
||||||
/** |
|
||||||
*是否可以开始画线 |
/** |
||||||
* @return startPoint不为空返回true |
* 是否拖拽 |
||||||
*/ |
* |
||||||
public boolean prepareForDrawLining() { |
* @return dragging状态 |
||||||
return startPoint != null; |
*/ |
||||||
} |
public boolean isDragging() { |
||||||
|
return dragging; |
||||||
/** |
} |
||||||
*设置开始位置 |
|
||||||
* @param p point位置 |
/** |
||||||
*/ |
* 是否可以开始画线 |
||||||
public void setStartPoint(Point p) { |
* |
||||||
this.startPoint = p; |
* @return startPoint不为空返回true |
||||||
} |
*/ |
||||||
|
public boolean prepareForDrawLining() { |
||||||
/** |
return startPoint != null; |
||||||
*返回开始位置 |
} |
||||||
* @return 点位置 |
|
||||||
*/ |
/** |
||||||
public Point getStartPoint() { |
* 设置开始位置 |
||||||
return startPoint; |
* |
||||||
} |
* @param p point位置 |
||||||
|
*/ |
||||||
/** |
public void setStartPoint(Point p) { |
||||||
*返回当前点位置 |
this.startPoint = p; |
||||||
* @return 点位置 |
} |
||||||
*/ |
|
||||||
public Point getEndPoint() { |
/** |
||||||
return currentPoint; |
* 返回开始位置 |
||||||
} |
* |
||||||
|
* @return 点位置 |
||||||
/** |
*/ |
||||||
*当前选中组件 |
public Point getStartPoint() { |
||||||
* @param e 鼠标事件 |
return startPoint; |
||||||
*/ |
} |
||||||
public void startSelecting(MouseEvent e) { |
|
||||||
selecting = true; |
/** |
||||||
selectionModel.setHotspotBounds(new Rectangle()); |
* 返回当前点位置 |
||||||
current_x = getMouseXY(e).x; |
* |
||||||
current_y = getMouseXY(e).y; |
* @return 点位置 |
||||||
} |
*/ |
||||||
|
public Point getEndPoint() { |
||||||
/** |
return currentPoint; |
||||||
*当前鼠标的xy |
} |
||||||
* @param e 鼠标事件 |
|
||||||
*/ |
/** |
||||||
public void startResizing(MouseEvent e) { |
* 当前选中组件 |
||||||
if (!selectionModel.getSelection().isEmpty()) { |
* |
||||||
driection.backupBounds(designer); |
* @param e 鼠标事件 |
||||||
} |
*/ |
||||||
current_x = getMouseXY(e).x; |
public void startSelecting(MouseEvent e) { |
||||||
current_y = getMouseXY(e).y; |
selecting = true; |
||||||
} |
selectionModel.setHotspotBounds(new Rectangle()); |
||||||
|
currentX = getMouseXY(e).x; |
||||||
/** |
currentY = getMouseXY(e).y; |
||||||
*起始点开始DrawLine |
} |
||||||
* @param p 点位置 |
|
||||||
*/ |
/** |
||||||
public void startDrawLine(Point p) { |
* 当前鼠标的xy |
||||||
this.startPoint = p; |
* |
||||||
if(p != null) { |
* @param e 鼠标事件 |
||||||
try { |
*/ |
||||||
designer.setCursor(XConnector.connectorCursor); |
public void startResizing(MouseEvent e) { |
||||||
} catch (Exception e) { |
if (!selectionModel.getSelection().isEmpty()) { |
||||||
} |
driection.backupBounds(designer); |
||||||
} else { |
} |
||||||
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
currentX = getMouseXY(e).x; |
||||||
} |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*鼠标释放时所在的区域及圈中的组件 |
* 起始点开始DrawLine |
||||||
* @param e 鼠标事件 |
* |
||||||
*/ |
* @param p 点位置 |
||||||
public void selectCreators(MouseEvent e) { |
*/ |
||||||
int x = getMouseXY(e).x; |
public void startDrawLine(Point p) { |
||||||
int y = getMouseXY(e).y; |
this.startPoint = p; |
||||||
|
if (p != null) { |
||||||
Rectangle bounds = createCurrentBounds(x, y); |
try { |
||||||
|
designer.setCursor(XConnector.connectorCursor); |
||||||
if ((x != current_x) || (y != current_y)) { |
} catch (Exception e) { |
||||||
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
} |
||||||
} |
} else { |
||||||
selectionModel.setHotspotBounds(null); |
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
*画所在区域线 |
/** |
||||||
* @param e 鼠标事件 |
* 鼠标释放时所在的区域及圈中的组件 |
||||||
*/ |
* |
||||||
public void drawLine(MouseEvent e) { |
* @param e 鼠标事件 |
||||||
designer.getDrawLineHelper().setDrawLine(true); |
*/ |
||||||
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
public void selectCreators(MouseEvent e) { |
||||||
if (p != null) { |
int x = getMouseXY(e).x; |
||||||
currentPoint = p; |
int y = getMouseXY(e).y; |
||||||
} else { |
|
||||||
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
Rectangle bounds = createCurrentBounds(x, y); |
||||||
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
|
||||||
} |
if ((x != currentX) || (y != currentY)) { |
||||||
} |
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
||||||
|
} |
||||||
private Rectangle createCurrentBounds(int x, int y) { |
selectionModel.setHotspotBounds(null); |
||||||
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; |
* @param e 鼠标事件 |
||||||
|
*/ |
||||||
return bounds; |
public void drawLine(MouseEvent e) { |
||||||
} |
designer.getDrawLineHelper().setDrawLine(true); |
||||||
|
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
||||||
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
if (p != null) { |
||||||
ArrayList<XCreator> creators = new ArrayList<XCreator>(); |
currentPoint = p; |
||||||
|
} else { |
||||||
if (!root.isVisible() && !designer.isRoot(root)) { |
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
||||||
return creators; |
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
||||||
} |
} |
||||||
|
} |
||||||
if (root instanceof XLayoutContainer) { |
|
||||||
XLayoutContainer container = (XLayoutContainer) root; |
private Rectangle createCurrentBounds(int x, int y) { |
||||||
int count = container.getXCreatorCount(); |
Rectangle bounds = new Rectangle(); |
||||||
Rectangle clipped = new Rectangle(selection); |
|
||||||
|
bounds.x = Math.min(x, currentX); |
||||||
for (int i = count - 1; i >= 0; i--) { |
bounds.y = Math.min(y, currentY); |
||||||
XCreator child = container.getXCreator(i); |
bounds.width = Math.max(x, currentX) - bounds.x; |
||||||
|
bounds.height = Math.max(y, currentY) - bounds.y; |
||||||
if (selection.contains(child.getBounds())) { |
|
||||||
creators.add(child); |
return bounds; |
||||||
} else { |
} |
||||||
clipped.x = selection.x - child.getX(); |
|
||||||
clipped.y = selection.y - child.getY(); |
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
||||||
creators.addAll(getHotspotCreators(clipped, child)); |
ArrayList<XCreator> creators = new ArrayList<>(); |
||||||
} |
|
||||||
} |
if (!root.isVisible() && !designer.isRoot(root)) { |
||||||
} |
return creators; |
||||||
|
} |
||||||
return creators; |
|
||||||
} |
if (root instanceof XLayoutContainer) { |
||||||
|
XLayoutContainer container = (XLayoutContainer) root; |
||||||
|
int count = container.getXCreatorCount(); |
||||||
/** |
Rectangle clipped = new Rectangle(selection); |
||||||
*重置model |
|
||||||
*/ |
for (int i = count - 1; i >= 0; i--) { |
||||||
public void resetModel() { |
XCreator child = container.getXCreator(i); |
||||||
dragging = false; |
|
||||||
selecting = false; |
if (selection.contains(child.getBounds())) { |
||||||
} |
creators.add(child); |
||||||
|
} else { |
||||||
/** |
clipped.x = selection.x - child.getX(); |
||||||
*重置 |
clipped.y = selection.y - child.getY(); |
||||||
*/ |
creators.addAll(getHotspotCreators(clipped, child)); |
||||||
public void reset() { |
} |
||||||
driection = Location.outer; |
} |
||||||
dragging = false; |
} |
||||||
selecting = false; |
|
||||||
} |
return creators; |
||||||
|
} |
||||||
/** |
|
||||||
*取消拖拽 |
|
||||||
*/ |
/** |
||||||
public void draggingCancel() { |
* 重置model |
||||||
designer.repaint(); |
*/ |
||||||
reset(); |
public void resetModel() { |
||||||
} |
dragging = false; |
||||||
|
selecting = false; |
||||||
/** |
} |
||||||
*设置可拉伸方向 |
|
||||||
* @param dir 拉伸方向 |
/** |
||||||
*/ |
* 重置 |
||||||
public void setDirection(Direction dir) { |
*/ |
||||||
if(driection != dir) { |
public void reset() { |
||||||
this.driection = dir; |
driection = Location.outer; |
||||||
driection.updateCursor(designer); |
dragging = false; |
||||||
} |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*x吸附线赋值 |
* 取消拖拽 |
||||||
* @param line 线 |
*/ |
||||||
*/ |
public void draggingCancel() { |
||||||
public void setXAbsorptionline(Absorptionline line) { |
designer.repaint(); |
||||||
this.lineInX = line; |
reset(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*y吸附线赋值 |
* 设置可拉伸方向 |
||||||
* @param line 线 |
* |
||||||
*/ |
* @param dir 拉伸方向 |
||||||
public void setYAbsorptionline(Absorptionline line) { |
*/ |
||||||
this.lineInY = line; |
public void setDirection(Direction dir) { |
||||||
} |
if (driection != dir) { |
||||||
|
this.driection = dir; |
||||||
/** |
driection.updateCursor(designer); |
||||||
* 等距线赋值 |
} |
||||||
* @param line 线 |
} |
||||||
*/ |
|
||||||
public void setEquidistantLine(Absorptionline line){ |
/** |
||||||
this.lineEquidistant = line; |
* x吸附线赋值 |
||||||
} |
* |
||||||
|
* @param line 线 |
||||||
/** |
*/ |
||||||
*画吸附线 |
public void setXAbsorptionline(Absorptionline line) { |
||||||
* @param g Graphics类 |
this.lineInX = line; |
||||||
*/ |
} |
||||||
public void paintAbsorptionline(Graphics g) { |
|
||||||
if(lineInX != null) { |
/** |
||||||
lineInX.paint(g,designer.getArea()); |
* y吸附线赋值 |
||||||
} |
* |
||||||
if(lineInY != null) { |
* @param line 线 |
||||||
lineInY.paint(g,designer.getArea()); |
*/ |
||||||
} |
public void setYAbsorptionline(Absorptionline line) { |
||||||
if(lineEquidistant != null){ |
this.lineInY = line; |
||||||
lineEquidistant.paint(g,designer.getArea()); |
} |
||||||
} |
|
||||||
} |
/** |
||||||
|
* 等距线赋值 |
||||||
/** |
* |
||||||
*拖拽 |
* @param line 线 |
||||||
* @param e 鼠标事件 |
*/ |
||||||
*/ |
public void setEquidistantLine(Absorptionline line) { |
||||||
public void dragging(MouseEvent e) { |
this.lineEquidistant = line; |
||||||
checkAddable(e); |
} |
||||||
setDependLinePainter(e); |
|
||||||
driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer); |
/** |
||||||
this.dragging = true; |
* 画吸附线 |
||||||
} |
* |
||||||
|
* @param g Graphics类 |
||||||
// 拖拽时画依附线用到的painter
|
*/ |
||||||
private void setDependLinePainter(MouseEvent e){ |
public void paintAbsorptionline(Graphics g) { |
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
if (lineInX != null) { |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
lineInX.paint(g, designer.getArea()); |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
} |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
if (lineInY != null) { |
||||||
designer.setPainter(painter); |
lineInY.paint(g, designer.getArea()); |
||||||
if (painter != null) { |
} |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
if (lineEquidistant != null) { |
||||||
painter.setCreator(creator); |
lineEquidistant.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*释放捕获 |
* 拖拽 |
||||||
* @param e 鼠标事件 |
* |
||||||
*/ |
* @param e 鼠标事件 |
||||||
public void releaseDragging(MouseEvent e) { |
*/ |
||||||
this.dragging = false; |
public void dragging(MouseEvent e) { |
||||||
if (addable) { |
//进入dragging状态时备份组件大小和位置
|
||||||
adding(e.getX(), e.getY()); |
if (!dragging) { |
||||||
} else if (!selectionModel.getSelection().isEmpty()) { |
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
||||||
selectionModel.releaseDragging(); |
} |
||||||
} |
checkAddable(e); |
||||||
designer.repaint(); |
setDependLinePainter(e); |
||||||
} |
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
||||||
|
this.dragging = true; |
||||||
/** |
} |
||||||
*改变选择区域 |
|
||||||
* |
// 拖拽时画依附线用到的painter
|
||||||
* @param e 鼠标事件 |
private void setDependLinePainter(MouseEvent e) { |
||||||
*/ |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
public void changeSelection(MouseEvent e) { |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
selectionModel.setHotspotBounds(bounds); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
} |
designer.setPainter(painter); |
||||||
|
if (painter != null) { |
||||||
/** |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
*返回鼠标所在的x、y 考虑滚动条的值 |
painter.setCreator(creator); |
||||||
* |
} |
||||||
* @param e 鼠标事件 |
} |
||||||
* @return xy值 |
|
||||||
*/ |
/** |
||||||
public Point getMouseXY(MouseEvent e) { |
* 释放捕获 |
||||||
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
* |
||||||
+ designer.getArea().getVerticalValue()); |
* @param e 鼠标事件 |
||||||
return p1; |
*/ |
||||||
} |
public void releaseDragging(MouseEvent e) { |
||||||
|
this.dragging = false; |
||||||
|
if (addable) { |
||||||
|
adding(e.getX(), e.getY()); |
||||||
|
} else if (!selectionModel.getSelection().isEmpty()) { |
||||||
|
selectionModel.releaseDragging(); |
||||||
|
} |
||||||
|
designer.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 改变选择区域 |
||||||
|
* |
||||||
|
* @param e 鼠标事件 |
||||||
|
*/ |
||||||
|
public void changeSelection(MouseEvent e) { |
||||||
|
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
||||||
|
selectionModel.setHotspotBounds(bounds); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回鼠标所在的x、y 考虑滚动条的值 |
||||||
|
* |
||||||
|
* @param e 鼠标事件 |
||||||
|
* @return xy值 |
||||||
|
*/ |
||||||
|
public Point getMouseXY(MouseEvent e) { |
||||||
|
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
||||||
|
+ designer.getArea().getVerticalValue()); |
||||||
|
return p1; |
||||||
|
} |
||||||
|
|
||||||
} |
} |
@ -1,93 +1,96 @@ |
|||||||
package com.fr.design.designer.beans.painters; |
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
import java.awt.Color; |
import java.awt.Color; |
||||||
import java.awt.Graphics; |
import java.awt.Graphics; |
||||||
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
||||||
import java.awt.Point; |
import java.awt.Point; |
||||||
import java.awt.Rectangle; |
import java.awt.Rectangle; |
||||||
import java.awt.Stroke; |
import java.awt.Stroke; |
||||||
|
|
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.designer.creator.XCreator; |
||||||
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.form.util.XCreatorConstants; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
public abstract class AbstractPainter implements HoverPainter { |
public abstract class AbstractPainter implements HoverPainter { |
||||||
|
|
||||||
protected Point hotspot; |
protected Point hotspot; |
||||||
protected Rectangle hotspot_bounds; |
protected Rectangle hotspot_bounds; |
||||||
protected XLayoutContainer container; |
protected XLayoutContainer container; |
||||||
protected XCreator creator; |
protected XCreator creator; |
||||||
|
|
||||||
/** |
/** |
||||||
* 构造函数 |
* 构造函数 |
||||||
* @param container 容器 |
* |
||||||
*/ |
* @param container 容器 |
||||||
public AbstractPainter(XLayoutContainer container) { |
*/ |
||||||
this.container = container; |
public AbstractPainter(XLayoutContainer container) { |
||||||
} |
this.container = container; |
||||||
|
} |
||||||
@Override |
|
||||||
public void setHotspot(Point p) { |
@Override |
||||||
hotspot = p; |
public void setHotspot(Point p) { |
||||||
} |
hotspot = p; |
||||||
|
} |
||||||
/** |
|
||||||
* 画初始区域 |
/** |
||||||
* @param g 画图类 |
* 画初始区域 |
||||||
* @param startX 起始x位置 |
* |
||||||
* @param startY 起始y位置 |
* @param g 画图类 |
||||||
*/ |
* @param startX 起始x位置 |
||||||
public void paint(Graphics g, int startX, int startY) { |
* @param startY 起始y位置 |
||||||
if(hotspot_bounds != null){ |
*/ |
||||||
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); |
public void paint(Graphics g, int startX, int startY) { |
||||||
} |
if (hotspot_bounds != null) { |
||||||
} |
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false); |
||||||
|
} |
||||||
/** |
} |
||||||
* 设置边界 |
|
||||||
* @param rect 位置 |
/** |
||||||
*/ |
* 设置边界 |
||||||
@Override |
* |
||||||
public void setRenderingBounds(Rectangle rect) { |
* @param rect 位置 |
||||||
hotspot_bounds = rect; |
*/ |
||||||
} |
@Override |
||||||
|
public void setRenderingBounds(Rectangle rect) { |
||||||
@Override |
hotspot_bounds = rect; |
||||||
public void setCreator(XCreator component) { |
} |
||||||
this.creator = component; |
|
||||||
} |
@Override |
||||||
|
public void setCreator(XCreator component) { |
||||||
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { |
this.creator = component; |
||||||
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; |
} |
||||||
drawHotspot(g, x, y, width, height, bColor, accept, false); |
|
||||||
} |
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { |
||||||
|
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; |
||||||
/** |
drawHotspot(g, x, y, width, height, bColor, accept, false); |
||||||
* 自适应布局那边渲染提示,要画整个背景,不是画边框 |
} |
||||||
*/ |
|
||||||
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { |
/** |
||||||
drawHotspot(g, x, y, width, height, bColor, accept, true); |
* 自适应布局那边渲染提示,要画整个背景,不是画边框 |
||||||
} |
*/ |
||||||
|
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) { |
||||||
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { |
drawHotspot(g, x, y, width, height, bColor, accept, true); |
||||||
Graphics2D g2d = (Graphics2D) g; |
} |
||||||
Color color = g2d.getColor(); |
|
||||||
Stroke backup = g2d.getStroke(); |
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { |
||||||
// 设置线条的样式
|
Graphics2D g2d = (Graphics2D) g; |
||||||
g2d.setStroke(XCreatorConstants.STROKE); |
Color color = g2d.getColor(); |
||||||
g2d.setColor(bColor); |
Stroke backup = g2d.getStroke(); |
||||||
if (!accept) { |
// 设置线条的样式
|
||||||
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); |
g2d.setStroke(XCreatorConstants.STROKE); |
||||||
} else if (drawBackground) { |
g2d.setColor(bColor); |
||||||
g2d.fillRect(x, y, width, height); |
if (!accept) { |
||||||
} else { |
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2); |
||||||
g2d.drawRect(x, y, width, height); |
} else if (drawBackground) { |
||||||
} |
g2d.fillRect(x, y, width, height); |
||||||
g2d.setStroke(backup); |
} else { |
||||||
g2d.setColor(color); |
g2d.drawRect(x, y, width, height); |
||||||
} |
} |
||||||
|
g2d.setStroke(backup); |
||||||
|
g2d.setColor(color); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue