|
|
@ -18,8 +18,6 @@ public class MoveUtils { |
|
|
|
public static final int SORPTION_UNIT = 5; |
|
|
|
public static final int SORPTION_UNIT = 5; |
|
|
|
private static final int EQUIDISTANTLINE_UNIT = 4; |
|
|
|
private static final int EQUIDISTANTLINE_UNIT = 4; |
|
|
|
|
|
|
|
|
|
|
|
public static WidgetForbidWindow widgetForbidWindow = new WidgetForbidWindow(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>(); |
|
|
|
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
private MoveUtils() { |
|
|
|
private MoveUtils() { |
|
|
@ -32,9 +30,7 @@ public class MoveUtils { |
|
|
|
* 获取块边界的迭代器 |
|
|
|
* 获取块边界的迭代器 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 块边界的迭代器 |
|
|
|
* @return 块边界的迭代器 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:43:47 |
|
|
|
* @date 2015-2-12-下午2:43:47 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RectangleIterator createRectangleIterator(); |
|
|
|
RectangleIterator createRectangleIterator(); |
|
|
|
|
|
|
|
|
|
|
@ -42,9 +38,7 @@ public class MoveUtils { |
|
|
|
* 设置X轴的线 |
|
|
|
* 设置X轴的线 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param line 连接线 |
|
|
|
* @param line 连接线 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:44:04 |
|
|
|
* @date 2015-2-12-下午2:44:04 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void setXAbsorptionline(Absorptionline line); |
|
|
|
void setXAbsorptionline(Absorptionline line); |
|
|
|
|
|
|
|
|
|
|
@ -52,9 +46,7 @@ public class MoveUtils { |
|
|
|
* 设置Y轴的线 |
|
|
|
* 设置Y轴的线 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param line 连接线 |
|
|
|
* @param line 连接线 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:44:04 |
|
|
|
* @date 2015-2-12-下午2:44:04 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void setYAbsorptionline(Absorptionline line); |
|
|
|
void setYAbsorptionline(Absorptionline line); |
|
|
|
|
|
|
|
|
|
|
@ -62,7 +54,6 @@ public class MoveUtils { |
|
|
|
* 获取当前选中块的垂直线数组 |
|
|
|
* 获取当前选中块的垂直线数组 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 块的垂直线数组 |
|
|
|
* @return 块的垂直线数组 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int[] getVerticalLine(); |
|
|
|
int[] getVerticalLine(); |
|
|
|
|
|
|
|
|
|
|
@ -70,42 +61,47 @@ public class MoveUtils { |
|
|
|
* 获取当前选中块的水平线数组 |
|
|
|
* 获取当前选中块的水平线数组 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 块的水平线数组 |
|
|
|
* @return 块的水平线数组 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int[] getHorizontalLine(); |
|
|
|
int[] getHorizontalLine(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置designer内部组件是否重叠的标志位 |
|
|
|
* 设置designer内部组件是否重叠的标志位 |
|
|
|
|
|
|
|
* |
|
|
|
* @param isIntersects 是否重叠 |
|
|
|
* @param isIntersects 是否重叠 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void setWidgetsIntersected(boolean isIntersects); |
|
|
|
void setWidgetsIntersected(boolean isIntersects); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取designer内部组件是否重叠的标志位 |
|
|
|
* 获取designer内部组件是否重叠的标志位 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 重叠 |
|
|
|
* @return 重叠 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean isWidgetsIntersected(); |
|
|
|
boolean isWidgetsIntersected(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取designer相对屏幕的位置 |
|
|
|
* 获取designer相对屏幕的位置 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 位置 |
|
|
|
* @return 位置 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Point getDesignerLocationOnScreen(); |
|
|
|
Point getDesignerLocationOnScreen(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 设置等距线 |
|
|
|
* 设置等距线 |
|
|
|
|
|
|
|
* |
|
|
|
* @param line 吸附线 |
|
|
|
* @param line 吸附线 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void setEquidistantLine(Absorptionline line); |
|
|
|
void setEquidistantLine(Absorptionline line); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取设计器垂直滚动条的值 |
|
|
|
* 获取设计器垂直滚动条的值 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 滚动条的值 |
|
|
|
* @return 滚动条的值 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int getDesignerScrollVerticalValue(); |
|
|
|
int getDesignerScrollVerticalValue(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取设计器水平滚动条的值 |
|
|
|
* 获取设计器水平滚动条的值 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 滚动条的值 |
|
|
|
* @return 滚动条的值 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int getDesignerScrollHorizontalValue(); |
|
|
|
int getDesignerScrollHorizontalValue(); |
|
|
@ -117,9 +113,7 @@ public class MoveUtils { |
|
|
|
* 是否存在下一个块 |
|
|
|
* 是否存在下一个块 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 是否存在下一个块 |
|
|
|
* @return 是否存在下一个块 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:41:32 |
|
|
|
* @date 2015-2-12-下午2:41:32 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean hasNext(); |
|
|
|
boolean hasNext(); |
|
|
|
|
|
|
|
|
|
|
@ -127,9 +121,7 @@ public class MoveUtils { |
|
|
|
* 获取下一个块的bounds |
|
|
|
* 获取下一个块的bounds |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 下一个块的bounds |
|
|
|
* @return 下一个块的bounds |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:41:55 |
|
|
|
* @date 2015-2-12-下午2:41:55 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Rectangle nextRectangle(); |
|
|
|
Rectangle nextRectangle(); |
|
|
|
|
|
|
|
|
|
|
@ -137,9 +129,7 @@ public class MoveUtils { |
|
|
|
* 获取块的垂直线数组 |
|
|
|
* 获取块的垂直线数组 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 块的垂直线数组 |
|
|
|
* @return 块的垂直线数组 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:42:27 |
|
|
|
* @date 2015-2-12-下午2:42:27 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int[] getVerticalLine(); |
|
|
|
int[] getVerticalLine(); |
|
|
|
|
|
|
|
|
|
|
@ -147,9 +137,7 @@ public class MoveUtils { |
|
|
|
* 获取块的水平线数组 |
|
|
|
* 获取块的水平线数组 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 块的水平线数组 |
|
|
|
* @return 块的水平线数组 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:42:27 |
|
|
|
* @date 2015-2-12-下午2:42:27 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int[] getHorizontalLine(); |
|
|
|
int[] getHorizontalLine(); |
|
|
|
} |
|
|
|
} |
|
|
@ -246,46 +234,38 @@ public class MoveUtils { |
|
|
|
//等距线从各边中点画出,先要判断是不是在范围内
|
|
|
|
//等距线从各边中点画出,先要判断是不是在范围内
|
|
|
|
int topMiddleX = left + width / 2; |
|
|
|
int topMiddleX = left + width / 2; |
|
|
|
int leftMiddleY = top + height / 2; |
|
|
|
int leftMiddleY = top + height / 2; |
|
|
|
if ((topMiddleX > bounds.getX()) && (topMiddleX < (bounds.getX() + bounds.getWidth()))){ |
|
|
|
if ((topMiddleX > bounds.getX()) && (topMiddleX < (bounds.getX() + bounds.getWidth()))) { |
|
|
|
//当前操作rec在bounds的下方
|
|
|
|
//当前操作rec在bounds的下方
|
|
|
|
if (top > (bounds.getY() + bounds.getHeight())){ |
|
|
|
if (top > (bounds.getY() + bounds.getHeight())) { |
|
|
|
equidistantLineInfo.setDistance(top - (bounds.y + bounds.height)); |
|
|
|
equidistantLineInfo.setDistance(top - (bounds.y + bounds.height)); |
|
|
|
equidistantLineInfo.setReference(bounds.y + bounds.height); |
|
|
|
equidistantLineInfo.setReference(bounds.y + bounds.height); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.TOP); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.TOP); |
|
|
|
} |
|
|
|
} |
|
|
|
//当前操作rec在bounds上方
|
|
|
|
//当前操作rec在bounds上方
|
|
|
|
if ((top + height) < bounds.getY()){ |
|
|
|
if ((top + height) < bounds.getY()) { |
|
|
|
equidistantLineInfo.setDistance(bounds.y - (top + height)); |
|
|
|
equidistantLineInfo.setDistance(bounds.y - (top + height)); |
|
|
|
equidistantLineInfo.setReference(bounds.y); |
|
|
|
equidistantLineInfo.setReference(bounds.y); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.BOTTOM); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.BOTTOM); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))) { |
|
|
|
else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))){ |
|
|
|
|
|
|
|
//当前操作rec在bounds的右侧
|
|
|
|
//当前操作rec在bounds的右侧
|
|
|
|
if (left > (bounds.getX() + bounds.getWidth())){ |
|
|
|
if (left > (bounds.getX() + bounds.getWidth())) { |
|
|
|
equidistantLineInfo.setDistance(left - (bounds.x + bounds.width)); |
|
|
|
equidistantLineInfo.setDistance(left - (bounds.x + bounds.width)); |
|
|
|
equidistantLineInfo.setReference(bounds.x + bounds.width); |
|
|
|
equidistantLineInfo.setReference(bounds.x + bounds.width); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.LEFT); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.LEFT); |
|
|
|
} |
|
|
|
} |
|
|
|
//当前操作rec在bounds的左侧
|
|
|
|
//当前操作rec在bounds的左侧
|
|
|
|
if ((left + width) < bounds.getX()){ |
|
|
|
if ((left + width) < bounds.getX()) { |
|
|
|
equidistantLineInfo.setDistance(bounds.x - (left + width)); |
|
|
|
equidistantLineInfo.setDistance(bounds.x - (left + width)); |
|
|
|
equidistantLineInfo.setReference(bounds.x); |
|
|
|
equidistantLineInfo.setReference(bounds.x); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.RIGHT); |
|
|
|
equidistantLineInfo.setDirection(SwingConstants.RIGHT); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(equidistantLineInfo.getDistance() > 0) { |
|
|
|
if (equidistantLineInfo.getDistance() > 0) { |
|
|
|
equidistantLines.add(equidistantLineInfo); |
|
|
|
equidistantLines.add(equidistantLineInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public static void displayForbidWindow(int x, int y) {
|
|
|
|
|
|
|
|
// widgetForbidWindow.showWindow(x, y);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public static void hideForbidWindow() {
|
|
|
|
|
|
|
|
// widgetForbidWindow.hideWindow();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 吸附 |
|
|
|
* 吸附 |
|
|
@ -295,11 +275,8 @@ public class MoveUtils { |
|
|
|
* @param width 宽度 |
|
|
|
* @param width 宽度 |
|
|
|
* @param height 高度 |
|
|
|
* @param height 高度 |
|
|
|
* @param designer 块设计器 |
|
|
|
* @param designer 块设计器 |
|
|
|
* |
|
|
|
|
|
|
|
* @return 吸附后坐标 |
|
|
|
* @return 吸附后坐标 |
|
|
|
* |
|
|
|
|
|
|
|
* @date 2015-2-12-下午2:39:16 |
|
|
|
* @date 2015-2-12-下午2:39:16 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static Point sorption(int x, int y, int width, int height, RectangleDesigner designer, boolean isParameterLayout) { |
|
|
|
public static Point sorption(int x, int y, int width, int height, RectangleDesigner designer, boolean isParameterLayout) { |
|
|
|
|
|
|
|
|
|
|
@ -318,53 +295,32 @@ public class MoveUtils { |
|
|
|
RectangleIterator iterator = designer.createRectangleIterator(); |
|
|
|
RectangleIterator iterator = designer.createRectangleIterator(); |
|
|
|
|
|
|
|
|
|
|
|
java.util.List<Rectangle> cacheRecs = new ArrayList<Rectangle>(); |
|
|
|
java.util.List<Rectangle> cacheRecs = new ArrayList<Rectangle>(); |
|
|
|
//是否存在控件重叠
|
|
|
|
|
|
|
|
// boolean isWidgetsIntersects = false;
|
|
|
|
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
while (iterator.hasNext()) { |
|
|
|
Rectangle bounds = iterator.nextRectangle(); |
|
|
|
Rectangle bounds = iterator.nextRectangle(); |
|
|
|
cacheRecs.add(bounds); |
|
|
|
cacheRecs.add(bounds); |
|
|
|
// boolean isIntersects = operatingRectangle.intersects(bounds);
|
|
|
|
|
|
|
|
findX(px, bounds, left, right, width); |
|
|
|
findX(px, bounds, left, right, width); |
|
|
|
findY(py, bounds, top, bottom, height); |
|
|
|
findY(py, bounds, top, bottom, height); |
|
|
|
|
|
|
|
|
|
|
|
if(!isParameterLayout){ |
|
|
|
if (!isParameterLayout) { |
|
|
|
// if(isIntersects) {
|
|
|
|
|
|
|
|
// isWidgetsIntersects = true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else{
|
|
|
|
|
|
|
|
findEquidistantLine(bounds, left, top, height, width); |
|
|
|
findEquidistantLine(bounds, left, top, height, width); |
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//showForbiddenWindow(designer, x, y, isWidgetsIntersects);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createXAbsorptionline(px, designer, width, cacheRecs); |
|
|
|
createXAbsorptionline(px, designer, width, cacheRecs); |
|
|
|
createYAbsorptionline(py, designer, height, cacheRecs); |
|
|
|
createYAbsorptionline(py, designer, height, cacheRecs); |
|
|
|
operatingRectangle.x = px.palce; |
|
|
|
operatingRectangle.x = px.palce; |
|
|
|
operatingRectangle.y = py.palce; |
|
|
|
operatingRectangle.y = py.palce; |
|
|
|
createEquidistantLine(pEquidistantX, pEquidistantY, operatingRectangle, designer); |
|
|
|
createEquidistantLine(pEquidistantX, pEquidistantY, operatingRectangle, designer); |
|
|
|
Point sorptionPoint = new Point(px.palce,py.palce); |
|
|
|
Point sorptionPoint = new Point(px.palce, py.palce); |
|
|
|
if (!px.isFind()){ |
|
|
|
if (!px.isFind()) { |
|
|
|
sorptionPoint.x = pEquidistantX.palce; |
|
|
|
sorptionPoint.x = pEquidistantX.palce; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!py.isFind()){ |
|
|
|
if (!py.isFind()) { |
|
|
|
sorptionPoint.y = pEquidistantY.palce; |
|
|
|
sorptionPoint.y = pEquidistantY.palce; |
|
|
|
} |
|
|
|
} |
|
|
|
return sorptionPoint; |
|
|
|
return sorptionPoint; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){
|
|
|
|
|
|
|
|
// if (isIntersects){
|
|
|
|
|
|
|
|
// if(designer.getDesignerLocationOnScreen() != null) {
|
|
|
|
|
|
|
|
// displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// designer.setWidgetsIntersected(true);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else{
|
|
|
|
|
|
|
|
// designer.setWidgetsIntersected(false);
|
|
|
|
|
|
|
|
// hideForbidWindow();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List<Rectangle> cacheRecs) { |
|
|
|
private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List<Rectangle> cacheRecs) { |
|
|
|
Absorptionline line = null; |
|
|
|
Absorptionline line = null; |
|
|
@ -446,25 +402,25 @@ public class MoveUtils { |
|
|
|
designer.setYAbsorptionline(line); |
|
|
|
designer.setYAbsorptionline(line); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void createEquidistantLine(PlacePointing px, PlacePointing py, Rectangle operatingRectangle, RectangleDesigner designer){ |
|
|
|
private static void createEquidistantLine(PlacePointing px, PlacePointing py, Rectangle operatingRectangle, RectangleDesigner designer) { |
|
|
|
processEquidistantLinesList(px, py, operatingRectangle); |
|
|
|
processEquidistantLinesList(px, py, operatingRectangle); |
|
|
|
Absorptionline line = null; |
|
|
|
Absorptionline line = null; |
|
|
|
if(equidistantLines.size() > 0) { |
|
|
|
if (equidistantLines.size() > 0) { |
|
|
|
int top = -1; |
|
|
|
int top = -1; |
|
|
|
int left = -1; |
|
|
|
int left = -1; |
|
|
|
int bottom = -1; |
|
|
|
int bottom = -1; |
|
|
|
int right = -1; |
|
|
|
int right = -1; |
|
|
|
for(int i = 0; i < equidistantLines.size(); i++){ |
|
|
|
for (int i = 0; i < equidistantLines.size(); i++) { |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.TOP){ |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.TOP) { |
|
|
|
top = equidistantLines.get(i).getReference(); |
|
|
|
top = equidistantLines.get(i).getReference(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.LEFT){ |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.LEFT) { |
|
|
|
left = equidistantLines.get(i).getReference(); |
|
|
|
left = equidistantLines.get(i).getReference(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.BOTTOM){ |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.BOTTOM) { |
|
|
|
bottom = equidistantLines.get(i).getReference(); |
|
|
|
bottom = equidistantLines.get(i).getReference(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.RIGHT){ |
|
|
|
if (equidistantLines.get(i).getDirection() == SwingConstants.RIGHT) { |
|
|
|
right = equidistantLines.get(i).getReference(); |
|
|
|
right = equidistantLines.get(i).getReference(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -479,13 +435,13 @@ public class MoveUtils { |
|
|
|
designer.setEquidistantLine(line); |
|
|
|
designer.setEquidistantLine(line); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void processEquidistantLinesList(PlacePointing pEquidistantX, PlacePointing pEquidistantY, Rectangle operatingRectangle){ |
|
|
|
private static void processEquidistantLinesList(PlacePointing pEquidistantX, PlacePointing pEquidistantY, Rectangle operatingRectangle) { |
|
|
|
EquidistantLine[] equidistantLines1 = new EquidistantLine[EQUIDISTANTLINE_UNIT]; |
|
|
|
EquidistantLine[] equidistantLines1 = new EquidistantLine[EQUIDISTANTLINE_UNIT]; |
|
|
|
//先按方向处理,只保留四个方向上距离最近
|
|
|
|
//先按方向处理,只保留四个方向上距离最近
|
|
|
|
for(int count = 0; count < equidistantLines.size(); count++){ |
|
|
|
for (int count = 0; count < equidistantLines.size(); count++) { |
|
|
|
for (int direction = 0; direction < EQUIDISTANTLINE_UNIT; direction++){ |
|
|
|
for (int direction = 0; direction < EQUIDISTANTLINE_UNIT; direction++) { |
|
|
|
if(equidistantLines.get(count).getDirection() == (direction + 1)){//direction 1,2,3,4 分别对应top,left,bottom,right
|
|
|
|
if (equidistantLines.get(count).getDirection() == (direction + 1)) {//direction 1,2,3,4 分别对应top,left,bottom,right
|
|
|
|
if(equidistantLines1[direction] != null |
|
|
|
if (equidistantLines1[direction] != null |
|
|
|
&& equidistantLines1[direction].getDistance() > equidistantLines.get(count).getDistance() |
|
|
|
&& equidistantLines1[direction].getDistance() > equidistantLines.get(count).getDistance() |
|
|
|
|| equidistantLines1[direction] == null) { |
|
|
|
|| equidistantLines1[direction] == null) { |
|
|
|
equidistantLines1[direction] = equidistantLines.get(count); |
|
|
|
equidistantLines1[direction] = equidistantLines.get(count); |
|
|
@ -496,9 +452,9 @@ public class MoveUtils { |
|
|
|
|
|
|
|
|
|
|
|
equidistantLines.clear(); |
|
|
|
equidistantLines.clear(); |
|
|
|
//找list中横纵分别等距的组合
|
|
|
|
//找list中横纵分别等距的组合
|
|
|
|
if (equidistantLines1[0] != null && equidistantLines1[2] != null){//top, bottom
|
|
|
|
if (equidistantLines1[0] != null && equidistantLines1[2] != null) {//top, bottom
|
|
|
|
int offset = equidistantLines1[0].getDistance() - equidistantLines1[2].getDistance(); |
|
|
|
int offset = equidistantLines1[0].getDistance() - equidistantLines1[2].getDistance(); |
|
|
|
if (Math.abs(offset) <= SORPTION_UNIT * 2){ |
|
|
|
if (Math.abs(offset) <= SORPTION_UNIT * 2) { |
|
|
|
pEquidistantY.direction = SwingConstants.TOP; |
|
|
|
pEquidistantY.direction = SwingConstants.TOP; |
|
|
|
equidistantLines.add(equidistantLines1[0]); |
|
|
|
equidistantLines.add(equidistantLines1[0]); |
|
|
|
equidistantLines.add(equidistantLines1[2]); |
|
|
|
equidistantLines.add(equidistantLines1[2]); |
|
|
@ -506,9 +462,9 @@ public class MoveUtils { |
|
|
|
operatingRectangle.y = pEquidistantY.palce; |
|
|
|
operatingRectangle.y = pEquidistantY.palce; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (equidistantLines1[1] != null && equidistantLines1[3] != null){//left, right
|
|
|
|
if (equidistantLines1[1] != null && equidistantLines1[3] != null) {//left, right
|
|
|
|
int offset = equidistantLines1[1].getDistance() - equidistantLines1[3].getDistance(); |
|
|
|
int offset = equidistantLines1[1].getDistance() - equidistantLines1[3].getDistance(); |
|
|
|
if (Math.abs(offset) <= SORPTION_UNIT * 2){ |
|
|
|
if (Math.abs(offset) <= SORPTION_UNIT * 2) { |
|
|
|
pEquidistantX.direction = SwingConstants.LEFT; |
|
|
|
pEquidistantX.direction = SwingConstants.LEFT; |
|
|
|
equidistantLines.add(equidistantLines1[1]); |
|
|
|
equidistantLines.add(equidistantLines1[1]); |
|
|
|
equidistantLines.add(equidistantLines1[3]); |
|
|
|
equidistantLines.add(equidistantLines1[3]); |
|
|
@ -519,26 +475,26 @@ public class MoveUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新纵向行列线
|
|
|
|
//更新纵向行列线
|
|
|
|
private static void updateVerticalLine(int[] selfVertical, RectangleIterator iterator, Absorptionline line){ |
|
|
|
private static void updateVerticalLine(int[] selfVertical, RectangleIterator iterator, Absorptionline line) { |
|
|
|
int[] targetArray = iterator.getVerticalLine(); |
|
|
|
int[] targetArray = iterator.getVerticalLine(); |
|
|
|
if (intersectArrays(targetArray, selfVertical)){ |
|
|
|
if (intersectArrays(targetArray, selfVertical)) { |
|
|
|
line.setVerticalLines(targetArray); |
|
|
|
line.setVerticalLines(targetArray); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新横向行列线
|
|
|
|
//更新横向行列线
|
|
|
|
private static void updateHorizontalLine(int[] selfHorizontal, RectangleIterator iterator, Absorptionline line){ |
|
|
|
private static void updateHorizontalLine(int[] selfHorizontal, RectangleIterator iterator, Absorptionline line) { |
|
|
|
int[] targetArray = iterator.getHorizontalLine(); |
|
|
|
int[] targetArray = iterator.getHorizontalLine(); |
|
|
|
if (intersectArrays(targetArray, selfHorizontal)){ |
|
|
|
if (intersectArrays(targetArray, selfHorizontal)) { |
|
|
|
line.setHorizontalLines(targetArray); |
|
|
|
line.setHorizontalLines(targetArray); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//检测两个数组是否有相交的部分
|
|
|
|
//检测两个数组是否有相交的部分
|
|
|
|
private static boolean intersectArrays(int[] targetArray, int[] selfArray){ |
|
|
|
private static boolean intersectArrays(int[] targetArray, int[] selfArray) { |
|
|
|
for (int i : targetArray) { |
|
|
|
for (int i : targetArray) { |
|
|
|
for (int j : selfArray) { |
|
|
|
for (int j : selfArray) { |
|
|
|
if(i == j){ |
|
|
|
if (i == j) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -547,7 +503,7 @@ public class MoveUtils { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class EquidistantLine{ |
|
|
|
private static class EquidistantLine { |
|
|
|
//与操作rectangle的距离
|
|
|
|
//与操作rectangle的距离
|
|
|
|
private int distance; |
|
|
|
private int distance; |
|
|
|
//参考rectangle的位置
|
|
|
|
//参考rectangle的位置
|
|
|
@ -555,33 +511,33 @@ public class MoveUtils { |
|
|
|
//等距线的方向
|
|
|
|
//等距线的方向
|
|
|
|
private int direction; |
|
|
|
private int direction; |
|
|
|
|
|
|
|
|
|
|
|
EquidistantLine(int distance, int reference, int direction){ |
|
|
|
EquidistantLine(int distance, int reference, int direction) { |
|
|
|
this.distance = distance; |
|
|
|
this.distance = distance; |
|
|
|
this.reference = reference; |
|
|
|
this.reference = reference; |
|
|
|
this.direction = direction; |
|
|
|
this.direction = direction; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setDistance(int distance){ |
|
|
|
public void setDistance(int distance) { |
|
|
|
this.distance = distance; |
|
|
|
this.distance = distance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getDistance(){ |
|
|
|
public int getDistance() { |
|
|
|
return this.distance; |
|
|
|
return this.distance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setReference(int reference){ |
|
|
|
public void setReference(int reference) { |
|
|
|
this.reference = reference; |
|
|
|
this.reference = reference; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getReference(){ |
|
|
|
public int getReference() { |
|
|
|
return this.reference; |
|
|
|
return this.reference; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setDirection(int direction){ |
|
|
|
public void setDirection(int direction) { |
|
|
|
this.direction = direction; |
|
|
|
this.direction = direction; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getDirection(){ |
|
|
|
public int getDirection() { |
|
|
|
return this.direction; |
|
|
|
return this.direction; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|