Browse Source

无任务 代码调整

master
yaoh.wu 8 years ago
parent
commit
2715c3c598
  1. 24
      designer_base/src/com/fr/design/actions/edit/CopyAction.java
  2. 2
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  3. 73
      designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java
  4. 11
      designer_base/src/com/fr/design/utils/ComponentUtils.java
  5. 11
      designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java
  6. 6
      designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java
  7. 28
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  8. 42
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  9. 3
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  10. 327
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  11. 92
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  12. 12
      designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java
  13. 160
      designer_form/src/com/fr/design/mainframe/ConnectorHelper.java
  14. 961
      designer_form/src/com/fr/design/mainframe/EditingMouseListener.java
  15. 23
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  16. 6
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java
  17. 1
      designer_form/src/com/fr/design/mainframe/JForm.java
  18. 63
      designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java

24
designer_base/src/com/fr/design/actions/edit/CopyAction.java

@ -3,35 +3,33 @@
*/
package com.fr.design.actions.edit;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import com.fr.base.BaseUtils;
import com.fr.design.actions.TemplateComponentAction;
import com.fr.design.designer.TargetComponent;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.event.KeyEvent;
/**
* Copy.
*/
public class CopyAction extends TemplateComponentAction {
public CopyAction(TargetComponent t) {
super(t);
public CopyAction(TargetComponent t) {
super(t);
this.setName(Inter.getLocText("M_Edit-Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
}
}
@Override
public boolean executeActionReturnUndoRecordNeeded() {
@Override
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc != null) {
tc.copy();
tc.copy();
}
return false;
}
return false;
}
}

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

@ -18,7 +18,7 @@ public class MoveUtils {
public static final int SORPTION_UNIT = 5;
private static final int EQUIDISTANTLINE_UNIT = 4;
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private MoveUtils() {

73
designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java

@ -1 +1,72 @@
package com.fr.design.parameter; import com.fr.base.Parameter; import com.fr.base.parameter.ParameterUI; import com.fr.design.mainframe.AuthorityEditPane; import javax.swing.*; import java.awt.*; /** * 参数设计界面接口 */ public interface ParameterDesignerProvider { void addListener(ParaDefinitePane paraDefinitePane); Component createWrapper(); void setDesignHeight(int height); Dimension getDesignSize(); Dimension getPreferredSize(); void populate(ParameterUI p); void refreshAllNameWidgets(); void refresh4TableData(String oldName, String newName); void refreshParameter(ParaDefinitePane paraDefinitePane); boolean isWithQueryButton(); java.util.List<String> getAllXCreatorNameList(); boolean isWithoutParaXCreator(Parameter[] ps); boolean isBlank(); ParameterUI getParaTarget(); boolean addingParameter2Editor(Parameter parameter, int index); boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); JPanel[] toolbarPanes4Form(); JComponent[] toolBarButton4Form(); void initBeforeUpEdit(); void populateParameterPropertyPane(ParaDefinitePane p); void initWidgetToolbarPane(); AuthorityEditPane getAuthorityEditPane(); JPanel getEastUpPane(); JPanel getEastDownPane(); boolean isSupportAuthority(); void removeSelection(); ParameterBridge getParaComponent(); }
package com.fr.design.parameter;
import com.fr.base.Parameter;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.mainframe.AuthorityEditPane;
import javax.swing.*;
import java.awt.*;
/**
* 参数设计界面接口
*/
public interface ParameterDesignerProvider {
void addListener(ParaDefinitePane paraDefinitePane);
Component createWrapper();
void setDesignHeight(int height);
Dimension getDesignSize();
Dimension getPreferredSize();
void populate(ParameterUI p);
void refreshAllNameWidgets();
void refresh4TableData(String oldName, String newName);
void refreshParameter(ParaDefinitePane paraDefinitePane);
boolean isWithQueryButton();
java.util.List<String> getAllXCreatorNameList();
boolean isWithoutParaXCreator(Parameter[] ps);
boolean isBlank();
ParameterUI getParaTarget();
boolean addingParameter2Editor(Parameter parameter, int index);
boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index);
void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex);
JPanel[] toolbarPanes4Form();
JComponent[] toolBarButton4Form();
void initBeforeUpEdit();
void populateParameterPropertyPane(ParaDefinitePane p);
void initWidgetToolbarPane();
AuthorityEditPane getAuthorityEditPane();
JPanel getEastUpPane();
JPanel getEastDownPane();
boolean isSupportAuthority();
void removeSelection();
ParameterBridge getParaComponent();
}

11
designer_base/src/com/fr/design/utils/ComponentUtils.java

@ -12,6 +12,9 @@ import java.util.ArrayList;
*/
public class ComponentUtils {
private ComponentUtils() {
}
public static boolean isComponentVisible(Component comp) {
if (!comp.isVisible() && !isRootComponent(comp)) {
return false;
@ -79,7 +82,7 @@ public class ComponentUtils {
for (int i = 0; i < count; i++) {
Component child = container.getComponent(i);
if (child == target) {
if (child.equals(target)) {
return i;
}
}
@ -105,10 +108,10 @@ public class ComponentUtils {
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRect(JComponent root) {
Rectangle root_bounds = ComponentUtils.getRelativeBounds(root);
Rectangle rootBounds = ComponentUtils.getRelativeBounds(root);
Rectangle rect = computeVisibleRectRel2Root(root);
rect.x -= root_bounds.x;
rect.y -= root_bounds.y;
rect.x -= rootBounds.x;
rect.y -= rootBounds.y;
return rect;
}

11
designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java

@ -1,13 +1,12 @@
package com.fr.design.designer.beans.actions;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import com.fr.base.BaseUtils;
import com.fr.general.Inter;
import com.fr.design.mainframe.FormDesigner;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class CopyAction extends FormEditAction {

6
designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java

@ -1,8 +1,5 @@
package com.fr.design.designer.beans.adapters.layout;
import java.awt.LayoutManager;
import com.fr.general.ComparatorUtils;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -13,6 +10,9 @@ import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.general.ComparatorUtils;
import java.awt.*;
public abstract class AbstractLayoutAdapter implements LayoutAdapter {

28
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java

@ -1,7 +1,5 @@
package com.fr.design.designer.beans.adapters.layout;
import java.awt.*;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -9,13 +7,14 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter;
import com.fr.design.designer.creator.*;
import com.fr.design.designer.properties.BoundsGroupModel;
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.widget.BoundsWidget;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import java.awt.*;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上
private boolean isAdd2ParentLayout = false;
@ -75,13 +74,13 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout();
if (topLayout != null) {
if (topLayout.isEditable()) {
return topLayoutAccept(creator, x, y, topLayout);
return topLayoutAccept(creator, x, y);
}
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
else if (((XLayoutContainer) topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
return false;
} else {
return acceptWidget(creator, x, y);
return acceptWidget(x, y);
}
} else {
FRLogger.getLogger().error("top layout is null!");
@ -91,7 +90,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
}
//topLayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) {
private boolean topLayoutAccept(XCreator creator, int x, int y) {
//允许组件重叠,可以不判断有没有和当前控件重叠
//先计算当前控件的位置
int creatorX, creatorY;
@ -109,18 +108,6 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
creatorX = x - w;
creatorY = y - h;
}
//frm 组件复用允许组件重叠
//无须再判断和布局中其他控件重叠
//Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight());
//WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout) topLayout.toData();
//for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) {
//BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i);
//Rectangle rectangle = temp.getBounds();
//if (curRec.intersects(rectangle)) {
//允许组件重叠
//return false;
//}
//}
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
return false;
}
@ -174,11 +161,10 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
}
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(XCreator creator, int x, int y) {
private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;

42
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

@ -3,12 +3,6 @@
*/
package com.fr.design.designer.beans.adapters.layout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -31,6 +25,10 @@ import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.widget.BoundsWidget;
import com.fr.general.ComparatorUtils;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* 自适应布局的容器适配器
*
@ -270,13 +268,6 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
return super.isCrossPointArea(currentComp, x, y);
}
protected void initCompsList() {
super.initCompsList();
}
protected void clearCompsList() {
super.clearCompsList();
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds();
@ -559,8 +550,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minWidth - getMinWidth(leftComps));
}
//重新计算左右两侧组件size、point
if (CalculateLefttRelatComponent(difference)) {
CalculateRightRelatComponent(objx + difference, -difference);
if (calculateLefttRelatComponent(difference)) {
calculateRightRelatComponent(objx + difference, -difference);
}
}
@ -675,10 +666,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minHeight - getMinHeight(upComps));
}
//重新计算上下两侧组件size、point
if (CalculateUpRelatComponent(difference)) {
CalculateDownRelatComponent(objY + difference, -difference);
if (calculateUpRelatComponent(difference)) {
calculateDownRelatComponent(objY + difference, -difference);
}
;
}
/**
@ -758,13 +748,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
int height = creatorHeight;
calculateRelatedComponent(x, y, width, height);
if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) {
CalculateRightRelatComponent(x, width + actualVal);
calculateRightRelatComponent(x, width + actualVal);
} else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) {
CalculateLefttRelatComponent(width + actualVal);
calculateLefttRelatComponent(width + actualVal);
} else if (!downComps.isEmpty() && getAllWidth(downComps) == width) {
CalculateDownRelatComponent(y, height + actualVal);
calculateDownRelatComponent(y, height + actualVal);
} else if (!upComps.isEmpty() && getAllWidth(upComps) == width) {
CalculateUpRelatComponent(height + actualVal);
calculateUpRelatComponent(height + actualVal);
} else {
// 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理
calculateNoRelatedComponent(x, y, width, height);
@ -1070,7 +1060,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param objX 调整后的坐标x
* @param objWidth 调整后的宽度
*/
protected void CalculateRightRelatComponent(int objX, int objWidth) {
protected void calculateRightRelatComponent(int objX, int objWidth) {
int count = rightComps.size();
for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) rightComps.get(i);
@ -1110,7 +1100,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/
protected boolean CalculateLefttRelatComponent(int objWidth) {
protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) {
return false;
}
@ -1128,7 +1118,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸下边框 调整下方的组件位置大小
*/
protected void CalculateDownRelatComponent(int objY, int objHeight) {
protected void calculateDownRelatComponent(int objY, int objHeight) {
int count = downComps.size();
for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) downComps.get(i);
@ -1168,7 +1158,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸上边框 调整上方的组件位置大小
*/
protected boolean CalculateUpRelatComponent(int objHeight) {
protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) {
return false;
}

3
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java

@ -7,7 +7,6 @@ package com.fr.design.designer.beans.adapters.layout;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
@ -28,8 +27,6 @@ import java.awt.*;
* @date 2014-6-24
*/
public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
//标题栏高度对tab布局内部组件的y坐标造成了偏移
private static int TAB_HEIGHT = 40;
/**
* 构造函数

327
designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java

@ -3,19 +3,17 @@
*/
package com.fr.design.designer.beans.location;
import java.awt.*;
import com.fr.design.beans.location.Absorptionline;
import com.fr.design.beans.location.MoveUtils;
import com.fr.design.designer.creator.*;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WParameterLayout;
import com.fr.form.ui.widget.BoundsWidget;
import java.awt.*;
/**
* @author richer
* @since 6.5.3
@ -26,197 +24,184 @@ public abstract class AccessDirection implements Direction {
private int ymin;
private int xmin;
abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer,
Rectangle oldbounds);
protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null);
designer.getStateModel().setXAbsorptionline(null);
designer.getStateModel().setYAbsorptionline(null);
return new int[] { x, y };
} else {
int posy = current_bounds.y;
Point relativePoint = getRelativePoint(x, y, current_bounds,designer);
sorptionPoint(relativePoint,current_bounds, designer);
return new int[] { relativePoint.x, relativePoint.y };
}
}
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) {
if (x < 0) {
x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
x = designer.getRootComponent().getWidth();
}
abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldBounds);
protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null);
designer.getStateModel().setXAbsorptionline(null);
designer.getStateModel().setYAbsorptionline(null);
return new int[]{x, y};
} else {
Point relativePoint = getRelativePoint(x, y, currentBounds, designer);
sorptionPoint(relativePoint, currentBounds, designer);
return new int[]{relativePoint.x, relativePoint.y};
}
}
protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) {
if (x < 0) {
x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
x = designer.getRootComponent().getWidth();
}
//参数面板可以无下限拉长
if (y < 0) {
y = 0;
} else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent()
if (y < 0) {
y = 0;
} else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent()
&& !designer.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWParameterLayout.class)) {
y = designer.getRootComponent().getHeight() + designer.getParaHeight();
}
return new Point(x, y);
}
protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) {
boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false;
boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false;
WAbsoluteLayout layout =getLayout(designer);
FormSelection selection = designer.getSelectionModel().getSelection();
// boolean isWidgetsIntersect = false;
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) {
continue;
}
Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection);
if (!findInX) {
int x1 = bounds.x;
if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x1;
findInX = true;
}
int x2 = bounds.x + bounds.width;
if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x2;
findInX = true;
}
}
if (!findInY) {
int y1 = bounds.y;
if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y1;
findInY = true;
}
int y2 = bounds.y + bounds.height;
if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y2;
findInY = true;
}
}
if (findInX && findInY) {
break;
}
// if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)) {
// isWidgetsIntersect = true;
// }
y = designer.getRootComponent().getHeight() + designer.getParaHeight();
}
// processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect);
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point);
return new Point(x, y);
}
protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) {
boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT;
boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT;
WAbsoluteLayout layout = getLayout(designer);
FormSelection selection = designer.getSelectionModel().getSelection();
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) {
continue;
}
Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection);
if (!findInX) {
int x1 = bounds.x;
if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x1;
findInX = true;
}
int x2 = bounds.x + bounds.width;
if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x2;
findInX = true;
}
}
if (!findInY) {
int y1 = bounds.y;
if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y1;
findInY = true;
}
int y2 = bounds.y + bounds.height;
if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y2;
findInY = true;
}
}
if (findInX && findInY) {
break;
}
}
setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
}
private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle
currentBounds, Point point) {
designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
designer.getStateModel().setEquidistantLine(null);
}
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) {
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
designer.getStateModel().setEquidistantLine(null);
}
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) {
return relativeRec;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
relativeRec.x += rec.x;
relativeRec.y += rec.y;
return relativeRec;
}
// private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){
// if(isIntersects){
// if(designer.getLocationOnScreen() != null) {
// MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y);
// }
// designer.setWidgetsIntersect(true);
// }
// else{
// MoveUtils.hideForbidWindow();
// designer.setWidgetsIntersect(false);
// }
// }
private WAbsoluteLayout getLayout(final FormDesigner designer){
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) {
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) {
return relativeRec;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
relativeRec.x += rec.x;
relativeRec.y += rec.y;
return relativeRec;
}
private WAbsoluteLayout getLayout(final FormDesigner designer) {
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(
designer.getTarget().getContainer());
WAbsoluteLayout layout;
if (formLayoutContainer.acceptType(XWBorderLayout.class)){//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if(container instanceof XWAbsoluteLayout){
layout = ((XWAbsoluteLayout)container).toData();
}
else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData();
}
} else{
if (formLayoutContainer.acceptType(XWBorderLayout.class)) {//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if (container instanceof XWAbsoluteLayout) {
layout = ((XWAbsoluteLayout) container).toData();
} else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData();
}
} else {
layout = (WAbsoluteLayout) designer.getTarget().getContainer();
}
return layout;
return layout;
}
/**
* 拖拽
* @param dx 坐标x
* @param dy 坐标y
* @param designer 设计界面
*/
public void drag(int dx, int dy, FormDesigner designer) {
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds());
/**
* 拖拽
*
* @param dx 坐标x
* @param dy 坐标y
* @param designer 设计界面
*/
public void drag(int dx, int dy, FormDesigner designer) {
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds());
if (rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
} else {
return;
}
//设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。
if(rec.height == MINHEIGHT){
if (rec.height == MINHEIGHT) {
ymin = rec.y;
}
if(rec.height == MINHEIGHT - 1){
if (rec.height == MINHEIGHT - 1) {
ymin = ymin == rec.y ? rec.y : rec.y - 1;
}
if(rec.height < MINHEIGHT){
if (rec.height < MINHEIGHT) {
rec.height = MINHEIGHT;
rec.y = ymin;
}
// 增加下宽度也设最小为21
if (rec.width == MINWIDTH) {
xmin = rec.x;
xmin = rec.x;
}
if(rec.width == MINWIDTH - 1){
xmin = xmin == rec.x ? rec.x : rec.x - 1;
if (rec.width == MINWIDTH - 1) {
xmin = xmin == rec.x ? rec.x : rec.x - 1;
}
if (rec.width < MINWIDTH) {
rec.width = MINWIDTH;
rec.x = xmin;
rec.width = MINWIDTH;
rec.x = xmin;
}
}
/**
* 更新鼠标指针形状
*
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
}
if(rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
}
}
/**
* 更新鼠标指针形状
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
}
}
/**
* 生成组件备用的bound
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {
formEditor.getSelectionModel().getSelection().backupBounds();
}
}
/**
* 生成组件备用的bound
*
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {
formEditor.getSelectionModel().getSelection().backupBounds();
}
}

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

@ -1,11 +1,5 @@
package com.fr.design.designer.beans.models;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
@ -20,9 +14,12 @@ import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.stable.ArrayUtils;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
* 该model保存当前选择的组件和剪切版信息
*/
@ -30,10 +27,10 @@ public class SelectionModel {
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
private static final int BORDER_PROPORTION = 20;
private static FormSelection CLIP_BOARD = new FormSelection();
private static FormSelection clipboard = new FormSelection();
private FormDesigner designer;
private FormSelection selection;
private Rectangle hotspot_bounds;
private Rectangle hotspotBounds;
public SelectionModel(FormDesigner designer) {
this.designer = designer;
@ -45,7 +42,7 @@ public class SelectionModel {
*/
public void reset() {
selection.reset();
hotspot_bounds = null;
hotspotBounds = null;
}
/**
@ -54,7 +51,7 @@ public class SelectionModel {
* @return 是否为空
*/
public static boolean isEmpty() {
return CLIP_BOARD.isEmpty();
return clipboard.isEmpty();
}
/**
@ -67,7 +64,6 @@ public class SelectionModel {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset();
}
// 获取e所在的组件
XCreator comp = designer.getComponentAt(e);
@ -93,7 +89,7 @@ public class SelectionModel {
*/
public void cutSelectedCreator2ClipBoard() {
if (hasSelectionComponent()) {
selection.cut2ClipBoard(CLIP_BOARD);
selection.cut2ClipBoard(clipboard);
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED);
designer.repaint();
}
@ -104,7 +100,7 @@ public class SelectionModel {
*/
public void copySelectedCreator2ClipBoard() {
if (!selection.isEmpty()) {
selection.copy2ClipBoard(CLIP_BOARD);
selection.copy2ClipBoard(clipboard);
}
}
@ -114,7 +110,7 @@ public class SelectionModel {
* @return
*/
public boolean pasteFromClipBoard() {
if (!CLIP_BOARD.isEmpty()) {
if (!clipboard.isEmpty()) {
XLayoutContainer parent = null;
//未选
if (!hasSelectionComponent()) {
@ -124,14 +120,14 @@ public class SelectionModel {
Rectangle rec = selection.getRelativeBounds();
//Tab布局
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD,
clipboard,
rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION);
} else {
Rectangle rec = selection.getRelativeBounds();
//自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
CLIP_BOARD,
clipboard,
rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION);
}
@ -140,7 +136,7 @@ public class SelectionModel {
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
//当前选择的就是编辑器表层
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD,
clipboard,
DELTA_X_Y,
DELTA_X_Y);
}
@ -148,7 +144,7 @@ public class SelectionModel {
//cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到
//使用selection.getSelectedCreator()也应该是可以获取到的。
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
CLIP_BOARD,
clipboard,
DELTA_X_Y,
DELTA_X_Y);
}
@ -157,19 +153,16 @@ public class SelectionModel {
else {
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
if (parent != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局
if (parent != null) {
Rectangle rec = selection.getRelativeBounds();
FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + rec.width / 2, rec.y +
rec.height - BORDER_PROPORTION);
}
} else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
Rectangle rec = selection.getRelativeBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + rec.width / 2, rec.y +
rec.height - BORDER_PROPORTION);
} else if (parent != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局
if (parent != null) {
Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
}
} else {
@ -223,14 +216,14 @@ public class SelectionModel {
* 设置选择区域
*/
public void setHotspotBounds(Rectangle rect) {
hotspot_bounds = rect;
hotspotBounds = rect;
}
/**
* 获得当前选择区域
*/
public Rectangle getHotspotBounds() {
return hotspot_bounds;
return hotspotBounds;
}
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) {
@ -271,22 +264,28 @@ public class SelectionModel {
* 其他两层不是靠添加组件就可以编辑的
*/
public boolean hasSelectionComponent() {
XCreator selectionXCreator = selection.getSelectedCreator();
if (designer.getClass().equals(FormDesigner.class)) {
//frm本地组件复用
return selection.getSelectedCreator() != null
&& !(
if (selectionXCreator != null) {
if (selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class)) {
//frm绝对布局编辑器
selection.getSelectedCreator().getClass().equals(XWAbsoluteBodyLayout.class)
//Tab布局编辑器
|| selection.getSelectedCreator().getClass().equals(XWCardMainBorderLayout.class)
|| selection.getSelectedCreator().getClass().equals(XWCardLayout.class)
|| selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)
//自适应布局编辑器
|| selection.getSelectedCreator().getClass().equals(XWFitLayout.class)
);
return false;
} else if (selectionXCreator.getClass().equals(XWCardMainBorderLayout.class)
|| selectionXCreator.getClass().equals(XWCardLayout.class)
|| selectionXCreator.getClass().equals(XWTabFitLayout.class)) {
//Tab布局编辑器
return false;
} else {
//自适应布局编辑器
return !selectionXCreator.getClass().equals(XWFitLayout.class);
}
} else {
return false;
}
} else {
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null;
return selectionXCreator != null && selectionXCreator.getParent() != null;
}
}
@ -330,10 +329,9 @@ public class SelectionModel {
int x = e.getX() + designer.getArea().getHorizontalValue();
int y = e.getY() + designer.getArea().getVerticalValue();
dir = getDirection(selection.getRelativeBounds(), x, y);
if (selection.size() == 1) {
if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) {
dir = Location.outer;
}
if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir
.getActual())) {
dir = Location.outer;
}
} else {
dir = Location.outer;

12
designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java

@ -313,7 +313,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
*/
public boolean isWithQueryButton() {
XLayoutContainer rootContainer = this.getRootComponent();
return SearchQueryCreators(rootContainer);
return searchQueryCreators(rootContainer);
}
/**
@ -322,18 +322,18 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
* @return 同上
*/
public Action[] getActions() {
if (designer_actions == null) {
designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
if (designerActions == null) {
designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)};
}
return designer_actions;
return designerActions;
}
private boolean SearchQueryCreators(XLayoutContainer rootContainer) {
private boolean searchQueryCreators(XLayoutContainer rootContainer) {
boolean b = false;
for (int i = 0; i < rootContainer.getXCreatorCount(); i++) {
if (rootContainer.getXCreator(i) instanceof XLayoutContainer) {
b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i));
b = searchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i));
} else if (rootContainer.getXCreator(i) instanceof XFormSubmit) {
b = true;
}

160
designer_form/src/com/fr/design/mainframe/ConnectorHelper.java

@ -15,96 +15,96 @@ import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.form.ui.Connector;
public class ConnectorHelper {
//这个类是用来画连接线的,暂时用不到
//这个类是用来画连接线的,暂时用不到
public static final int NEAR = 5;
private static double ratio = 0.5;
private final static int ADSORPTION = 15; // 吸附距离
private ArrayList<Point> drawingPoint;
private FormDesigner designer;
private boolean drawing;
public static final int NEAR = 5;
private static double ratio = 0.5;
private final static int ADSORPTION = 15; // 吸附距离
private ArrayList<Point> drawingPoint;
private FormDesigner designer;
private boolean drawing;
public ConnectorHelper(FormDesigner formEditor) {
this.designer = formEditor;
}
public ConnectorHelper(FormDesigner formEditor) {
this.designer = formEditor;
}
public void resetConnector(Connector connector) {
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(),connector.getStartPoint(),connector.getEndPoint());
connector.addAll(cc.createPointList());
}
public void resetConnector(Connector connector) {
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), connector.getStartPoint(), connector.getEndPoint());
connector.addAll(cc.createPointList());
}
public boolean drawLining() {
return this.drawing;
}
public boolean drawLining() {
return this.drawing;
}
public void setDrawLine(boolean d) {
this.drawing = d;
}
public void setDrawLine(boolean d) {
this.drawing = d;
}
private boolean near(Point p1, Point p2) {
return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR;
}
private boolean near(Point p1, Point p2) {
return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR;
}
private Point getNearPoint(MouseEvent e, Rectangle r) {
Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y);
Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio));
Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight()));
Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio)));
Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue());
if (near(p, p1)) {
return p1;
} else if (near(p, p2)) {
return p2;
} else if (near(p, p3)) {
return p3;
} else if (near(p, p4)) {
return p4;
}
return null;
}
private Point getNearPoint(MouseEvent e, Rectangle r) {
Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y);
Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio));
Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight()));
Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio)));
Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue());
if (near(p, p1)) {
return p1;
} else if (near(p, p2)) {
return p2;
} else if (near(p, p3)) {
return p3;
} else if (near(p, p4)) {
return p4;
}
return null;
}
private ArrayList<Point> createDefalutNode(Point startPoint, Point endPoint) {
long s = System.currentTimeMillis();
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint));
ArrayList<Point> p = cc.createPointList();
long e = System.currentTimeMillis();
return p;
}
private ArrayList<Point> createDefalutNode(Point startPoint, Point endPoint) {
long s = System.currentTimeMillis();
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint));
ArrayList<Point> p = cc.createPointList();
long e = System.currentTimeMillis();
return p;
}
public void drawAuxiliaryLine(Graphics g) {
Point startPoint = designer.getStateModel().getStartPoint();
Point endPoint = designer.getStateModel().getEndPoint();
drawingPoint = createDefalutNode(startPoint, endPoint);
Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]);
g.setColor(Color.green);
for (int i = 0; i < p.length - 1; i++) {
GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y
- designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(),
p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR);
}
}
public void drawAuxiliaryLine(Graphics g) {
Point startPoint = designer.getStateModel().getStartPoint();
Point endPoint = designer.getStateModel().getEndPoint();
drawingPoint = createDefalutNode(startPoint, endPoint);
Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]);
g.setColor(Color.green);
for (int i = 0; i < p.length - 1; i++) {
GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y
- designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(),
p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR);
}
}
public void createDefalutLine() {
if (drawingPoint != null
&& drawingPoint.size() > 1
&& ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > ADSORPTION) {
((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint));
}
drawingPoint = null;
}
public void createDefalutLine() {
if (drawingPoint != null
&& drawingPoint.size() > 1
&& ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > ADSORPTION) {
((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint));
}
drawingPoint = null;
}
public Point getNearWidgetPoint(MouseEvent e) {
BoundsWidget widget;
Point p = null;
for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) {
widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i));
if (widget.isVisible()) {
if ((p = getNearPoint(e, widget.getBounds())) != null) {
break;
}
}
}
return p;
}
public Point getNearWidgetPoint(MouseEvent e) {
BoundsWidget widget;
Point p = null;
for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) {
widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i));
if (widget.isVisible()) {
if ((p = getNearPoint(e, widget.getBounds())) != null) {
break;
}
}
}
return p;
}
}

961
designer_form/src/com/fr/design/mainframe/EditingMouseListener.java

File diff suppressed because it is too large Load Diff

23
designer_form/src/com/fr/design/mainframe/FormDesigner.java

@ -46,7 +46,6 @@ import com.fr.form.ui.container.WFitLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.ExtraClassManager;
import com.fr.stable.ArrayUtils;
import com.fr.stable.bridge.StableFactory;
@ -72,7 +71,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
protected static final ArrayList<String> NAME_ARRAY_LIST = new ArrayList<String>(
Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")})
);
private static final int BORDER_WIDTH = 6;
//底层容器的默认大小
protected static final Dimension LARGE_PREFERRED_SIZE = new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT);
private int paraHeight = 0;
@ -84,7 +82,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
private XLayoutContainer paraComponent;
private boolean drawLineMode;
private FormArea formArea;
private ConnectorHelper ConnectorHelper;
private ConnectorHelper connectorHelper;
private boolean isReportBlockEditing = false;
//组件重叠
@ -107,7 +105,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
// 编辑状态的事件表
private CreatorEventListenerTable edit;
protected Action[] designer_actions;
protected Action[] designerActions;
private FormDesignerModeForSpecial<?> desigerMode;
private Action switchAction;
private FormElementCaseContainerProvider elementCaseContainer;
@ -763,12 +761,9 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @param e 鼠标事件
*/
public void updateDrawLineMode(MouseEvent e) {
Point p = ConnectorHelper.getNearWidgetPoint(e);
if (p == null) {
XComponent comp = getComponentAt(e);
if (comp == rootComponent) {
p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
}
Point p = connectorHelper.getNearWidgetPoint(e);
if (p == null && getComponentAt(e) == rootComponent) {
p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
}
stateModel.startDrawLine(p);
}
@ -1120,11 +1115,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @return 同上
*/
public Action[] getActions() {
if (designer_actions == null) {
designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
if (designerActions == null) {
designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)};
}
return designer_actions;
return designerActions;
}
protected Border getOuterBorder() {
@ -1191,7 +1186,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @return ConnectorHelper类
*/
public ConnectorHelper getDrawLineHelper() {
return ConnectorHelper;
return connectorHelper;
}
/**

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

@ -204,14 +204,14 @@ public class FormSelectionUtils {
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,
ArrayList<XCreator> newSelection) {
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection);
FormSelectionUtils.rebuild(rootComponent, selectionWidget, newSelection);
if (newSelection.isEmpty()) {
newSelection.add(rootComponent);
}
return newSelection;
}
private static void _rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
private static void rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
if (selectionWidget.isEmpty()) {
return;
}
@ -238,7 +238,7 @@ public class FormSelectionUtils {
}
}
if (c instanceof XLayoutContainer) {
_rebuild((XLayoutContainer) c, selectionWidget, newSelection);
rebuild((XLayoutContainer) c, selectionWidget, newSelection);
}
}
}

1
designer_form/src/com/fr/design/mainframe/JForm.java

@ -43,7 +43,6 @@ import com.fr.form.FormElementCaseProvider;
import com.fr.form.main.Form;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;

63
designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java

@ -36,7 +36,7 @@ public class MobileWidgetTable extends JTable {
private static final int WIDGET_TABLE_ROW_HEIGHT = 22;
private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件
private int selectedRow = -1;
private int GAP = 11;
private static final int GAP = 11;
private boolean draging = false;
private boolean collapsed = false; // 控件列表是否折叠
@ -57,7 +57,7 @@ public class MobileWidgetTable extends JTable {
TableModel defaultModel = new BeanTableModel();
this.setModel(defaultModel);
this.repaint();
this.setDefaultRenderer(Object.class,new DefaultTableCellRenderer());
this.setDefaultRenderer(Object.class, new DefaultTableCellRenderer());
refreshData();
this.addMouseListener(mouseAdapter);
this.addMouseMotionListener(mouseAdapter);
@ -90,8 +90,8 @@ public class MobileWidgetTable extends JTable {
@Override
public void mousePressed(MouseEvent e) {
getInstance().setCellSelected();
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2){ // 如果是点击在第一行
toggleCollapse();
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2) { // 如果是点击在第一行
toggleCollapse();
}
}
@ -102,14 +102,14 @@ public class MobileWidgetTable extends JTable {
*/
@Override
public void mouseReleased(MouseEvent e) {
if(!draging){
if (!draging) {
return;
}
draging = false;
moveComponent.setVisible(false);
int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1;
int toIndex = e.getY() < GAP ? 0 : (int) Math.rint((e.getY() - GAP) / WIDGET_TABLE_ROW_HEIGHT) + 1;
//当鼠标放开时,将选中的容器调整至新的顺序
((WSortLayout)designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
((WSortLayout) designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
//拿取排序后表格数据,然后重绘表格
getInstance().refreshData();
getInstance().repaint();
@ -124,8 +124,8 @@ public class MobileWidgetTable extends JTable {
@Override
public void mouseMoved(MouseEvent e) {
int overRow = 0;
for (int i = 0;i < getRowCount();i++) {
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT){
for (int i = 0; i < getRowCount(); i++) {
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT) {
overRow = i; //判断鼠标在哪一行
}
}
@ -147,10 +147,10 @@ public class MobileWidgetTable extends JTable {
public void mouseDragged(MouseEvent e) {
int width = getColumnModel().getColumn(0).getWidth();
//如果当前选中的行的范围是合理的话,就可以拖动
if (selectedRow < getRowCount() && selectedRow > 0){
if (selectedRow < getRowCount() && selectedRow > 0) {
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
draging = true;
moveComponent.setText(getValueAt(selectedRow,0).toString());
moveComponent.setText(getValueAt(selectedRow, 0).toString());
moveComponent.setLocation(0, e.getY() - GAP);
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT));
moveComponent.setVisible(true);
@ -165,16 +165,16 @@ public class MobileWidgetTable extends JTable {
*/
@Override
public void mouseClicked(MouseEvent e) {
if(selectedRow > 0){
if (selectedRow > 0) {
//当前点击的控件的名字
String widgetName = cellData[selectedRow][0];
if (StringUtils.isNotEmpty(widgetName)){
if (StringUtils.isNotEmpty(widgetName)) {
//当前选择的容器
XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator();
WLayout selectedWidget = (WLayout)selectedContainer.toData();
XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator();
WLayout selectedWidget = (WLayout) selectedContainer.toData();
//当前选择的容器中的控件数量
int count = selectedWidget.getWidgetCount();
for (int i = 0;i < count ;i++){
for (int i = 0; i < count; i++) {
XCreator xCreator = (XCreator) selectedContainer.getComponent(i);
Widget widget = xCreator.toData();
if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) {
@ -182,7 +182,7 @@ public class MobileWidgetTable extends JTable {
}
}
}
} else if (selectedRow == 0){ // 如果是点击在第一行
} else if (selectedRow == 0) { // 如果是点击在第一行
if (!e.isPopupTrigger() && e.getClickCount() > 1) {
toggleCollapse();
}
@ -200,12 +200,12 @@ public class MobileWidgetTable extends JTable {
}
};
public MobileWidgetTable getInstance(){
public MobileWidgetTable getInstance() {
return this;
}
public FormDesigner getEditingDesigner(){
return designer;
public FormDesigner getEditingDesigner() {
return designer;
}
/**
@ -236,7 +236,7 @@ public class MobileWidgetTable extends JTable {
/**
* 重新get排序后的数据
*/
public void refreshData(){
public void refreshData() {
cellData = getData();
}
@ -245,8 +245,8 @@ public class MobileWidgetTable extends JTable {
*
* @return String[][] 二维数组[0][0]widgetName
*/
private String[][] getData(){
if(designer.isFormParaDesigner()){
private String[][] getData() {
if (designer.isFormParaDesigner()) {
return new String[0][0];
}
@ -254,13 +254,13 @@ public class MobileWidgetTable extends JTable {
XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null;
if(selectedModel == null){
if (selectedModel == null) {
return new String[0][0];
}
// 选择的控件有两种类型,一种是WLayout,代表容器,一种是Widget,代表控件
if (selectedModel.acceptType(WSortLayout.class)) {
List<String> mobileWidgetList = ((WSortLayout)selectedModel).getOrderedMobileWidgetList();
List<String> mobileWidgetList = ((WSortLayout) selectedModel).getOrderedMobileWidgetList();
String[][] widgetName = new String[mobileWidgetList.size() + 1][1];
widgetName[0][0] = Inter.getLocText("FR-Designer_WidgetOrder");
for (int i = 0; i < mobileWidgetList.size(); i++) {
@ -285,7 +285,7 @@ public class MobileWidgetTable extends JTable {
*/
public class BeanTableModel extends DefaultTableModel {
public BeanTableModel() {
super(cellData,headers);
super(cellData, headers);
}
@Override
@ -308,7 +308,7 @@ public class MobileWidgetTable extends JTable {
return null;
}
if (row == 0) {
return (isCollapsed()? "+" : "-") + cellData[row][0];
return (isCollapsed() ? "+" : "-") + cellData[row][0];
}
return cellData[row][0];
@ -333,13 +333,14 @@ public class MobileWidgetTable extends JTable {
}
/**
* 是否可编辑
* @param row 行号
* @param column 列号
* 是否可编辑
*
* @param row 行号
* @param column 列号
* @return 是否可编辑
*/
public boolean isCellEditable(int row, int column) {
return false;
return false;
}
}

Loading…
Cancel
Save