Browse Source

Pull request #5317: REPORT-54885 布局优化 门槛用例没通过的bug

Merge in DESIGN/design from ~FANGLEI/design10.0:feature/10.0 to feature/10.0

* commit '02494a4e595c61d92e3336e85e4c58fe16b6f975':
  REPORT-54885 布局优化 门槛用例没通过的bug
feature/10.0
fanglei 3 years ago
parent
commit
fe4de4fe4f
  1. 7
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  2. 3
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java
  3. 65
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  4. 22
      designer-form/src/main/java/com/fr/design/mainframe/FormSpacingLineDrawer.java
  5. 2
      designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

7
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -865,4 +865,11 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
public boolean isParentAbsolute() {
return ((XCreator) this.getParent()).acceptType(XWAbsoluteLayout.class);
}
public int getLevel() {
if (this.getParent() == null) {
return 1;
}
return ((XCreator) this.getParent()).getLevel() + 1;
}
}

3
designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

@ -318,6 +318,8 @@ public class EditingMouseListener extends MouseInputAdapter {
offsetEventPoint(e);
XCreator component = designer.getComponentAt(e);
designer.getSpacingLineDrawer().updateMouseEvent(e, true);
setCoverPaneNotDisplay(component, e, false);
if (processTopLayoutMouseMove(component, e)) {
@ -353,7 +355,6 @@ public class EditingMouseListener extends MouseInputAdapter {
return;
}
designer.getSpacingLineDrawer().updateMouseEvent(e, true);
processChartEditorMouseMove(component, e);
e.translatePoint(oldX - e.getX(), oldY - e.getY());
designer.repaint();

65
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -835,6 +835,38 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return null;
}
/**
* 从root里面查找层级为level的控件
*/
private XCreator xCreatorAt(int x, int y, XCreator root, int level) {
if (root == null || !root.isVisible()) {
return null;
}
x -= root.getX();
y -= root.getY();
if (root instanceof XLayoutContainer) {
XLayoutContainer rootContainer = (XLayoutContainer) root;
int count = rootContainer.getXCreatorCount();
for (int i = 0; i < count; i++) {
XCreator child = rootContainer.getXCreator(i);
XCreator dest = xCreatorAt(x, y, child, level);
if (dest != null && dest.getLevel() == level) {
return dest;
}
}
}
Rectangle rect = ComponentUtils.computeVisibleRect(root);
if (isIntersectArea(x, y, rect)) {
// 判断是否处于交叉区域
return root;
}
return null;
}
/**
* 从已选择的组件中找x,y所在的组件
*/
@ -1095,25 +1127,38 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* */
@Override
public XCreator getComponentAt(int x, int y) {
XLayoutContainer container = y < paraHeight - formArea.getVerticalValue() ? paraComponent : rootComponent;
if (container == null) {
container = rootComponent;
}
int relativeX = x + (int) (formArea.getHorizontalValue() / scale) - container.getX();
int relativeY = y + (int) (formArea.getVerticalValue() / scale) - container.getY();
XCreator result = xCreatorAt(relativeX, relativeY, container);
XLayoutContainer container = getRootContainer(y);
XCreator result = xCreatorAt(getRelativeScaleX(x) - container.getX(), getRelativeScaleY(y) - container.getY(), container);
return result == null ? getComponentAt(x, y, null) : result;
}
@Nullable
public XCreator getComponentAt(int x, int y, XCreator[] except) {
XLayoutContainer container = getRootContainer(y);
XCreator comp = xCreatorAt(getRelativeScaleX(x), getRelativeScaleY(y), container, except);
return comp == null ? container : comp;
}
public XCreator getComponentAt(int x, int y, int level) {
XLayoutContainer container = getRootContainer(y);
XCreator comp = xCreatorAt(getRelativeScaleX(x), getRelativeScaleY(y), container, level);
return comp == null ? container : comp;
}
private XLayoutContainer getRootContainer(int y) {
XLayoutContainer container = y < paraHeight - formArea.getVerticalValue() ? paraComponent : rootComponent;
if (container == null) {
container = rootComponent;
}
XCreator comp = xCreatorAt(x + (int)(formArea.getHorizontalValue()/scale), (int)(y + formArea.getVerticalValue()/scale), container,
except);
return comp == null ? container : comp;
return container;
}
private int getRelativeScaleX(int x) {
return x + (int)(formArea.getHorizontalValue() / scale);
}
private int getRelativeScaleY(int y) {
return y + (int)(formArea.getVerticalValue() / scale);
}
public SelectionModel getSelectionModel() {

22
designer-form/src/main/java/com/fr/design/mainframe/FormSpacingLineDrawer.java

@ -21,7 +21,7 @@ public class FormSpacingLineDrawer {
private static final int MIN_SPACING = 10;
private FormDesigner designer;
private XCreator hoverCreator;
private XCreator hoverCreator = null;
private Rectangle selectedRec;
private boolean isMouseMoveEvent = false;
@ -30,7 +30,10 @@ public class FormSpacingLineDrawer {
}
public void updateMouseEvent(MouseEvent e, boolean isMouseMoveEvent) {
this.hoverCreator = designer.getComponentAt(e);
XCreator creator = designer.getSelectionModel().getSelection().getSelectedCreator();
if (creator != null) {
this.hoverCreator = designer.getComponentAt(e.getX(), e.getY(), creator.getLevel());
}
this.isMouseMoveEvent = isMouseMoveEvent;
}
@ -131,14 +134,6 @@ public class FormSpacingLineDrawer {
designer.getSelectionModel().getSelection().getSelectedCreator().getParent() == null;
}
private boolean isHoveredRootComponent() {
return designer.isRoot(hoverCreator);
}
private boolean isHoveredForm() {
return hoverCreator.getParent() == null;
}
private boolean isNeedExtendedLine(AbstractFormParallelLine[] nearestSides) {
return nearestSides[0].isVerticalCenterLineBeforeTheParallelLine(nearestSides[1]) || nearestSides[0].isVerticalCenterLineBehindTheParallelLine(nearestSides[1]);
}
@ -147,12 +142,13 @@ public class FormSpacingLineDrawer {
return isSelectedForm() || isSelectedRootComponent();
}
private boolean isHoveredRootPane() {
return isHoveredForm() || isHoveredRootComponent();
private boolean isSelectedCreatorSameParentWithHoveredCreator() {
XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
return selectedCreator != null && hoverCreator != null && selectedCreator.getParent() == hoverCreator.getParent();
}
private boolean isDrawSpacingLine() {
return !isSelectedRootPane() && !isHoveredRootPane() && isMouseMoveEvent;
return !isSelectedRootPane() && isSelectedCreatorSameParentWithHoveredCreator() && isMouseMoveEvent;
}
private AbstractFormParallelLine[] getNearestHorizontalSide() {

2
designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

@ -32,10 +32,10 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
public FormMultiWidgetCardPane(FormDesigner designer) {
super(designer);
arrangement = new MultiSelectionArrangement(designer);
}
public void initPropertyPane() {
arrangement = new MultiSelectionArrangement(designer);
content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
content.add(createArrangementLayoutPane(), BorderLayout.CENTER);
}

Loading…
Cancel
Save