Browse Source
* commit '58fbac4e191af1d56f843ac75f020eba3f405c1c': report-1945组件复用bug 无jira任务,提交国际化master
superman
8 years ago
20 changed files with 990 additions and 917 deletions
@ -1,446 +1,476 @@ |
|||||||
package com.fr.design.designer.beans.models; |
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.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.AdapterBus; |
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
import com.fr.design.designer.beans.LayoutAdapter; |
||||||
import com.fr.design.designer.beans.events.DesignerEvent; |
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
import com.fr.design.designer.beans.location.Direction; |
import com.fr.design.designer.beans.location.Direction; |
||||||
import com.fr.design.designer.beans.location.Location; |
import com.fr.design.designer.beans.location.Location; |
||||||
import com.fr.design.designer.creator.XConnector; |
import com.fr.design.designer.creator.*; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.designer.creator.XCreatorUtils; |
import com.fr.design.mainframe.FormSelectionUtils; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
|
||||||
import com.fr.design.designer.creator.XWAbsoluteLayout; |
|
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
/** |
/** |
||||||
* 普通模式下的状态model |
* 普通模式下的状态model |
||||||
*/ |
*/ |
||||||
public class StateModel { |
public class StateModel { |
||||||
// 对应的selection model
|
// 对应的selection model
|
||||||
|
|
||||||
private SelectionModel selectionModel; |
private SelectionModel selectionModel; |
||||||
// 当前鼠标进入拖拽区域的位置类型
|
// 当前鼠标进入拖拽区域的位置类型
|
||||||
private Direction driection; |
private Direction driection; |
||||||
|
|
||||||
// 当前拖拽的起始位置
|
// 当前拖拽的起始位置
|
||||||
private int current_x; |
private int currentX; |
||||||
private int current_y; |
private int currentY; |
||||||
|
|
||||||
private Point startPoint = new Point(); |
//拖拽组件原始位置大小备份
|
||||||
private Point currentPoint = new Point(); |
private Rectangle selectedPositionBackup; |
||||||
|
|
||||||
private Absorptionline lineInX; |
private Point startPoint = new Point(); |
||||||
private Absorptionline lineInY; |
private Point currentPoint = new Point(); |
||||||
//等距线
|
|
||||||
private Absorptionline lineEquidistant; |
private Absorptionline lineInX; |
||||||
|
private Absorptionline lineInY; |
||||||
// 当前是否处于拖拽选择状态
|
//等距线
|
||||||
private boolean selecting; |
private Absorptionline lineEquidistant; |
||||||
private boolean dragging; |
|
||||||
|
// 当前是否处于拖拽选择状态
|
||||||
private boolean addable; |
private boolean selecting; |
||||||
|
private boolean dragging; |
||||||
private FormDesigner designer; |
|
||||||
|
private boolean addable; |
||||||
public StateModel(FormDesigner designer) { |
|
||||||
this.designer = designer; |
private FormDesigner designer; |
||||||
selectionModel = designer.getSelectionModel(); |
|
||||||
} |
public StateModel(FormDesigner designer) { |
||||||
|
this.designer = designer; |
||||||
/** |
selectionModel = designer.getSelectionModel(); |
||||||
* 返回direction |
} |
||||||
* @return direction方向 |
|
||||||
*/ |
|
||||||
public Direction getDirection() { |
|
||||||
return driection; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 是否有组件正被选中 |
|
||||||
* |
|
||||||
* @return true 如果至少一个组件被选中 |
|
||||||
*/ |
|
||||||
public boolean isSelecting() { |
|
||||||
return selecting; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
/** |
||||||
*是否能拖拽 |
* 返回direction |
||||||
|
* |
||||||
|
* @return direction方向 |
||||||
|
*/ |
||||||
|
public Direction getDirection() { |
||||||
|
return driection; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否有组件正被选中 |
||||||
|
* |
||||||
|
* @return true 如果至少一个组件被选中 |
||||||
|
*/ |
||||||
|
public boolean isSelecting() { |
||||||
|
return selecting; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否能拖拽 |
||||||
|
* |
||||||
* @return 非outer且选中为空 |
* @return 非outer且选中为空 |
||||||
*/ |
*/ |
||||||
public boolean dragable() { |
public boolean dragable() { |
||||||
return ((driection != Location.outer) && !selecting); |
return ((driection != Location.outer) && !selecting); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 拖拽中是否可以转换为添加模式: |
* 拖拽中是否可以转换为添加模式: |
||||||
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
||||||
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
||||||
*/ |
*/ |
||||||
private void checkAddable(MouseEvent e) { |
private void checkAddable(MouseEvent e) { |
||||||
addable = false; |
addable = false; |
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
|
|
||||||
if (driection != Location.inner) { |
if (driection != Location.inner) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
||||||
if (creatorContainer != null && creatorContainer != container |
if (creatorContainer != null && creatorContainer != container |
||||||
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
designer.setPainter(painter); |
designer.setPainter(painter); |
||||||
if (painter != null) { |
if (painter != null) { |
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
rect.x -= designer.getArea().getHorizontalValue(); |
rect.x -= designer.getArea().getHorizontalValue(); |
||||||
rect.y -= designer.getArea().getVerticalValue(); |
rect.y -= designer.getArea().getVerticalValue(); |
||||||
painter.setRenderingBounds(rect); |
painter.setRenderingBounds(rect); |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
painter.setCreator(creator); |
painter.setCreator(creator); |
||||||
} |
} |
||||||
addable = true; |
addable = true; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private boolean addBean(XLayoutContainer container, int x, int y) { |
/** |
||||||
LayoutAdapter adapter = container.getLayoutAdapter(); |
* @param container 容器 |
||||||
Rectangle r = ComponentUtils.getRelativeBounds(container); |
* @param mouseX 鼠标释放位置X |
||||||
if (selectionModel.getSelection().size() == 1) { |
* @param mouseY 鼠标释放位置Y |
||||||
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x |
* @return 是否成功 |
||||||
+ designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y); |
*/ |
||||||
} |
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
||||||
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
LayoutAdapter adapter = container.getLayoutAdapter(); |
||||||
adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y); |
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
||||||
} |
if (selectionModel.getSelection().size() == 1) { |
||||||
return true; |
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
||||||
} |
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
private void adding(int x, int y) { |
} |
||||||
|
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
||||||
|
adapter.addBean(creator, |
||||||
|
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @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); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
||||||
|
|
||||||
boolean success = false; |
boolean success = false; |
||||||
|
|
||||||
if (container != null) { |
if (container != null) { |
||||||
// 如果是容器,则调用其acceptComponent接受组件
|
// 如果是容器,则调用其acceptComponent接受组件
|
||||||
success = addBean(container, x, y); |
success = addBean(container, mouseReleasedX, mouseReleasedY); |
||||||
} |
} |
||||||
|
|
||||||
if (success) { |
if (success) { |
||||||
FormSelectionUtils.rebuildSelection(designer); |
FormSelectionUtils.rebuildSelection(designer); |
||||||
designer.getEditListenerTable().fireCreatorModified( |
designer.getEditListenerTable().fireCreatorModified( |
||||||
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
||||||
} else { |
} else { |
||||||
Toolkit.getDefaultToolkit().beep(); |
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
||||||
} |
Toolkit.getDefaultToolkit().beep(); |
||||||
|
} |
||||||
// 取消提示
|
// 取消提示
|
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*是否拖拽 |
* 是否拖拽 |
||||||
|
* |
||||||
* @return dragging状态 |
* @return dragging状态 |
||||||
*/ |
*/ |
||||||
public boolean isDragging() { |
public boolean isDragging() { |
||||||
return dragging; |
return dragging; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*是否可以开始画线 |
* 是否可以开始画线 |
||||||
|
* |
||||||
* @return startPoint不为空返回true |
* @return startPoint不为空返回true |
||||||
*/ |
*/ |
||||||
public boolean prepareForDrawLining() { |
public boolean prepareForDrawLining() { |
||||||
return startPoint != null; |
return startPoint != null; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*设置开始位置 |
* 设置开始位置 |
||||||
|
* |
||||||
* @param p point位置 |
* @param p point位置 |
||||||
*/ |
*/ |
||||||
public void setStartPoint(Point p) { |
public void setStartPoint(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回开始位置 |
* 返回开始位置 |
||||||
|
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getStartPoint() { |
public Point getStartPoint() { |
||||||
return startPoint; |
return startPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回当前点位置 |
* 返回当前点位置 |
||||||
|
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getEndPoint() { |
public Point getEndPoint() { |
||||||
return currentPoint; |
return currentPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*当前选中组件 |
* 当前选中组件 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startSelecting(MouseEvent e) { |
public void startSelecting(MouseEvent e) { |
||||||
selecting = true; |
selecting = true; |
||||||
selectionModel.setHotspotBounds(new Rectangle()); |
selectionModel.setHotspotBounds(new Rectangle()); |
||||||
current_x = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
current_y = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*当前鼠标的xy |
* 当前鼠标的xy |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startResizing(MouseEvent e) { |
public void startResizing(MouseEvent e) { |
||||||
if (!selectionModel.getSelection().isEmpty()) { |
if (!selectionModel.getSelection().isEmpty()) { |
||||||
driection.backupBounds(designer); |
driection.backupBounds(designer); |
||||||
} |
} |
||||||
current_x = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
current_y = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*起始点开始DrawLine |
* 起始点开始DrawLine |
||||||
|
* |
||||||
* @param p 点位置 |
* @param p 点位置 |
||||||
*/ |
*/ |
||||||
public void startDrawLine(Point p) { |
public void startDrawLine(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
if(p != null) { |
if (p != null) { |
||||||
try { |
try { |
||||||
designer.setCursor(XConnector.connectorCursor); |
designer.setCursor(XConnector.connectorCursor); |
||||||
} catch (Exception e) { |
} catch (Exception e) { |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*鼠标释放时所在的区域及圈中的组件 |
* 鼠标释放时所在的区域及圈中的组件 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void selectCreators(MouseEvent e) { |
public void selectCreators(MouseEvent e) { |
||||||
int x = getMouseXY(e).x; |
int x = getMouseXY(e).x; |
||||||
int y = getMouseXY(e).y; |
int y = getMouseXY(e).y; |
||||||
|
|
||||||
Rectangle bounds = createCurrentBounds(x, y); |
Rectangle bounds = createCurrentBounds(x, y); |
||||||
|
|
||||||
if ((x != current_x) || (y != current_y)) { |
if ((x != currentX) || (y != currentY)) { |
||||||
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
||||||
} |
} |
||||||
selectionModel.setHotspotBounds(null); |
selectionModel.setHotspotBounds(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*画所在区域线 |
* 画所在区域线 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void drawLine(MouseEvent e) { |
public void drawLine(MouseEvent e) { |
||||||
designer.getDrawLineHelper().setDrawLine(true); |
designer.getDrawLineHelper().setDrawLine(true); |
||||||
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
||||||
if (p != null) { |
if (p != null) { |
||||||
currentPoint = p; |
currentPoint = p; |
||||||
} else { |
} else { |
||||||
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
||||||
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private Rectangle createCurrentBounds(int x, int y) { |
private Rectangle createCurrentBounds(int x, int y) { |
||||||
Rectangle bounds = new Rectangle(); |
Rectangle bounds = new Rectangle(); |
||||||
|
|
||||||
bounds.x = Math.min(x, current_x); |
bounds.x = Math.min(x, currentX); |
||||||
bounds.y = Math.min(y, current_y); |
bounds.y = Math.min(y, currentY); |
||||||
bounds.width = Math.max(x, current_x) - bounds.x; |
bounds.width = Math.max(x, currentX) - bounds.x; |
||||||
bounds.height = Math.max(y, current_y) - bounds.y; |
bounds.height = Math.max(y, currentY) - bounds.y; |
||||||
|
|
||||||
return bounds; |
return bounds; |
||||||
} |
} |
||||||
|
|
||||||
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
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)) { |
if (!root.isVisible() && !designer.isRoot(root)) { |
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
if (root instanceof XLayoutContainer) { |
if (root instanceof XLayoutContainer) { |
||||||
XLayoutContainer container = (XLayoutContainer) root; |
XLayoutContainer container = (XLayoutContainer) root; |
||||||
int count = container.getXCreatorCount(); |
int count = container.getXCreatorCount(); |
||||||
Rectangle clipped = new Rectangle(selection); |
Rectangle clipped = new Rectangle(selection); |
||||||
|
|
||||||
for (int i = count - 1; i >= 0; i--) { |
for (int i = count - 1; i >= 0; i--) { |
||||||
XCreator child = container.getXCreator(i); |
XCreator child = container.getXCreator(i); |
||||||
|
|
||||||
if (selection.contains(child.getBounds())) { |
if (selection.contains(child.getBounds())) { |
||||||
creators.add(child); |
creators.add(child); |
||||||
} else { |
} else { |
||||||
clipped.x = selection.x - child.getX(); |
clipped.x = selection.x - child.getX(); |
||||||
clipped.y = selection.y - child.getY(); |
clipped.y = selection.y - child.getY(); |
||||||
creators.addAll(getHotspotCreators(clipped, child)); |
creators.addAll(getHotspotCreators(clipped, child)); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
*重置model |
* 重置model |
||||||
*/ |
*/ |
||||||
public void resetModel() { |
public void resetModel() { |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*重置 |
* 重置 |
||||||
*/ |
*/ |
||||||
public void reset() { |
public void reset() { |
||||||
driection = Location.outer; |
driection = Location.outer; |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*取消拖拽 |
* 取消拖拽 |
||||||
*/ |
*/ |
||||||
public void draggingCancel() { |
public void draggingCancel() { |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
reset(); |
reset(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*设置可拉伸方向 |
* 设置可拉伸方向 |
||||||
|
* |
||||||
* @param dir 拉伸方向 |
* @param dir 拉伸方向 |
||||||
*/ |
*/ |
||||||
public void setDirection(Direction dir) { |
public void setDirection(Direction dir) { |
||||||
if(driection != dir) { |
if (driection != dir) { |
||||||
this.driection = dir; |
this.driection = dir; |
||||||
driection.updateCursor(designer); |
driection.updateCursor(designer); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*x吸附线赋值 |
* x吸附线赋值 |
||||||
|
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setXAbsorptionline(Absorptionline line) { |
public void setXAbsorptionline(Absorptionline line) { |
||||||
this.lineInX = line; |
this.lineInX = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*y吸附线赋值 |
* y吸附线赋值 |
||||||
|
* |
||||||
|
* @param line 线 |
||||||
|
*/ |
||||||
|
public void setYAbsorptionline(Absorptionline line) { |
||||||
|
this.lineInY = line; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 等距线赋值 |
||||||
|
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setYAbsorptionline(Absorptionline line) { |
public void setEquidistantLine(Absorptionline line) { |
||||||
this.lineInY = line; |
this.lineEquidistant = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
|
||||||
* 等距线赋值 |
|
||||||
* @param line 线 |
|
||||||
*/ |
|
||||||
public void setEquidistantLine(Absorptionline line){ |
|
||||||
this.lineEquidistant = line; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
/** |
||||||
*画吸附线 |
* 画吸附线 |
||||||
|
* |
||||||
* @param g Graphics类 |
* @param g Graphics类 |
||||||
*/ |
*/ |
||||||
public void paintAbsorptionline(Graphics g) { |
public void paintAbsorptionline(Graphics g) { |
||||||
if(lineInX != null) { |
if (lineInX != null) { |
||||||
lineInX.paint(g,designer.getArea()); |
lineInX.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if(lineInY != null) { |
if (lineInY != null) { |
||||||
lineInY.paint(g,designer.getArea()); |
lineInY.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if(lineEquidistant != null){ |
if (lineEquidistant != null) { |
||||||
lineEquidistant.paint(g,designer.getArea()); |
lineEquidistant.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*拖拽 |
* 拖拽 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void dragging(MouseEvent e) { |
public void dragging(MouseEvent e) { |
||||||
checkAddable(e); |
//进入dragging状态时备份组件大小和位置
|
||||||
setDependLinePainter(e); |
if (!dragging) { |
||||||
driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer); |
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
||||||
this.dragging = true; |
} |
||||||
} |
checkAddable(e); |
||||||
|
setDependLinePainter(e); |
||||||
// 拖拽时画依附线用到的painter
|
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
||||||
private void setDependLinePainter(MouseEvent e){ |
this.dragging = true; |
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
} |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
|
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
// 拖拽时画依附线用到的painter
|
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
private void setDependLinePainter(MouseEvent e) { |
||||||
designer.setPainter(painter); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
if (painter != null) { |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
painter.setCreator(creator); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
} |
designer.setPainter(painter); |
||||||
} |
if (painter != null) { |
||||||
|
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
|
painter.setCreator(creator); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
/** |
/** |
||||||
*释放捕获 |
* 释放捕获 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void releaseDragging(MouseEvent e) { |
public void releaseDragging(MouseEvent e) { |
||||||
this.dragging = false; |
this.dragging = false; |
||||||
if (addable) { |
if (addable) { |
||||||
adding(e.getX(), e.getY()); |
adding(e.getX(), e.getY()); |
||||||
} else if (!selectionModel.getSelection().isEmpty()) { |
} else if (!selectionModel.getSelection().isEmpty()) { |
||||||
selectionModel.releaseDragging(); |
selectionModel.releaseDragging(); |
||||||
} |
} |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*改变选择区域 |
* 改变选择区域 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void changeSelection(MouseEvent e) { |
public void changeSelection(MouseEvent e) { |
||||||
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
||||||
selectionModel.setHotspotBounds(bounds); |
selectionModel.setHotspotBounds(bounds); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回鼠标所在的x、y 考虑滚动条的值 |
* 返回鼠标所在的x、y 考虑滚动条的值 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
* @return xy值 |
* @return xy值 |
||||||
*/ |
*/ |
||||||
public Point getMouseXY(MouseEvent e) { |
public Point getMouseXY(MouseEvent e) { |
||||||
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
||||||
+ designer.getArea().getVerticalValue()); |
+ designer.getArea().getVerticalValue()); |
||||||
return p1; |
return p1; |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue