Browse Source

无任务 调整代码

master
yaoh.wu 8 years ago
parent
commit
6a1e4bcca7
  1. 58
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  2. 53
      designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java
  3. 1
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  4. 74
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

58
designer_base/src/com/fr/design/beans/location/MoveUtils.java

@ -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();
} }
@ -259,8 +247,7 @@ public class MoveUtils {
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));
@ -279,13 +266,6 @@ public class MoveUtils {
} }
} }
// 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,25 +295,16 @@ 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);
@ -353,18 +321,6 @@ public class MoveUtils {
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;

53
designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java

@ -17,32 +17,29 @@ public class WidgetForbidWindow extends JWindow {
private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
// /** /**
// * 构造函数 * 构造函数
// */ */
// public WidgetForbidWindow() { public WidgetForbidWindow() {
// this.add(promptButton); this.add(promptButton);
// this.setSize(WIDTH, HEIGHT);
// this.setSize(WIDTH, HEIGHT); }
// }
// /**
// /** * 在指定位置显示窗口, 默认将window的中心点放到指定位置上
// * 在指定位置显示窗口, 默认将window的中心点放到指定位置上 *
// * * @param x x坐标
// * @param x x坐标 * @param y y坐标
// * @param y y坐标 */
// * public void showWindow(int x, int y) {
// */ this.setLocation(x - WIDTH / 2, y - HEIGHT / 2);
// public void showWindow(int x, int y){ this.setVisible(true);
// this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); }
// this.setVisible(true);
// } /**
// * 隐藏当前窗口
// /** */
// * 隐藏当前窗口 public void hideWindow() {
// * this.setVisible(false);
// */ }
// public void hideWindow(){
// this.setVisible(false);
// }
} }

1
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -123,7 +123,6 @@ public class SelectionModel {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) {
Rectangle rec = selection.getRelativeBounds(); Rectangle rec = selection.getRelativeBounds();
//Tab布局 //Tab布局
System.out.println("ADD: " + (rec.x + rec.width / 2) + "\t" + (rec.y + BORDER_PROPORTION));
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD, CLIP_BOARD,
rec.x + rec.width / 2, rec.x + rec.width / 2,

74
designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

@ -1,19 +1,18 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*; import com.fr.design.designer.creator.*;
import com.fr.form.ui.container.WLayout; import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout; import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent; import java.awt.*;
import com.fr.form.ui.Widget; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FormSelectionUtils { public class FormSelectionUtils {
@ -22,10 +21,14 @@ public class FormSelectionUtils {
private static final int DELAY_Y = 20; private static final int DELAY_Y = 20;
//组件复制时是否已经向左上偏移 //组件复制时是否已经向左上偏移
private static boolean BACK_OFFSET = false; private static boolean backoffset = false;
//组件重命名后缀 //组件重命名后缀
private static final String postfix = "_c"; private static final String POSTFIX = "_c";
private FormSelectionUtils() {
}
/** /**
* @param designer 编辑器 * @param designer 编辑器
@ -67,12 +70,10 @@ public class FormSelectionUtils {
} else if (parent instanceof XWFitLayout) { } else if (parent instanceof XWFitLayout) {
//相对布局 //相对布局
designer.getSelectionModel().getSelection().reset(); designer.getSelectionModel().getSelection().reset();
Rectangle rec = clipBoard.getSelctionBounds();
for (XCreator creator : clipBoard.getSelectedCreators()) { for (XCreator creator : clipBoard.getSelectedCreators()) {
try { try {
Widget copied = copyWidget(designer, creator); Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
// TODO 获取位置
boolean addSuccess = adapter.addBean(copiedCreator, x, y); boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) { if (addSuccess) {
@ -104,14 +105,14 @@ public class FormSelectionUtils {
*/ */
private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) { private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) {
//当宽度为奇数时 设置偏移 //当宽度为奇数时 设置偏移
int x_offset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0; int xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0;
//当高度为奇数时 设置偏移 //当高度为奇数时 设置偏移
int y_offset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0; int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0;
if (!layoutAdapter.accept(copiedCreator, x, y)) { if (!layoutAdapter.accept(copiedCreator, x, y)) {
XLayoutContainer container = layoutAdapter.getContainer(); XLayoutContainer container = layoutAdapter.getContainer();
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + x_offset > container.getWidth(); boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + y_offset > container.getHeight(); boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
/* /*
* 组件原始位置位于布局的右下角 * 组件原始位置位于布局的右下角
* 和布局右下边界线紧挨 * 和布局右下边界线紧挨
@ -119,12 +120,12 @@ public class FormSelectionUtils {
* x,y同时越界 * x,y同时越界
*/ */
if (xOut && yOut) { if (xOut && yOut) {
x = BACK_OFFSET ? container.getWidth() - copiedCreator.getWidth() / 2 - x_offset x = backoffset ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset
: container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - x_offset; : container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - xoffset;
y = BACK_OFFSET ? y = backoffset ?
container.getHeight() - copiedCreator.getHeight() / 2 - y_offset container.getHeight() - copiedCreator.getHeight() / 2 - yoffset
: container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - y_offset; : container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - yoffset;
BACK_OFFSET = !BACK_OFFSET; backoffset = !backoffset;
return new Point(x, y); return new Point(x, y);
} }
/* /*
@ -134,8 +135,8 @@ public class FormSelectionUtils {
* x,y中只有一个越界 * x,y中只有一个越界
*/ */
else if ((xOut || yOut)) { else if ((xOut || yOut)) {
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - x_offset : x; x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x;
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - y_offset : y; y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
return new Point(x, y); return new Point(x, y);
} }
} }
@ -143,6 +144,14 @@ public class FormSelectionUtils {
} }
/**
* 拷贝组件
*
* @param formDesigner
* @param xCreator
* @return
* @throws CloneNotSupportedException
*/
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws
CloneNotSupportedException { CloneNotSupportedException {
ArrayList<String> nameSpace = new ArrayList<String>(); ArrayList<String> nameSpace = new ArrayList<String>();
@ -155,11 +164,6 @@ public class FormSelectionUtils {
} else { } else {
copied.setWidgetName(name); copied.setWidgetName(name);
} }
// if (copied instanceof WLayout) {
// for (int i = 0; i < ((WLayout) copied).getWidgetCount(); i++) {
// setCopiedName(formDesigner, ((WLayout) copied).getWidget(i), clonedNameList);
// }
// }
return copied; return copied;
} }
@ -172,12 +176,12 @@ public class FormSelectionUtils {
* @return name * @return name
*/ */
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) { private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) {
String name = copied.getWidgetName(); StringBuffer name = new StringBuffer(copied.getWidgetName());
do { do {
name += postfix; name.append(POSTFIX);
} while (formDesigner.getTarget().isNameExist(name) || nameSpace.contains(name)); } while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString()));
nameSpace.add(name); nameSpace.add(name.toString());
return name; return name.toString();
} }
public static void rebuildSelection(FormDesigner designer) { public static void rebuildSelection(FormDesigner designer) {

Loading…
Cancel
Save