Browse Source

REPORT-54885 布局优化 门槛用例没通过的bug

feature/10.0
方磊 3 years ago
parent
commit
4fbcdc4c84
  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() { public boolean isParentAbsolute() {
return ((XCreator) this.getParent()).acceptType(XWAbsoluteLayout.class); 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); offsetEventPoint(e);
XCreator component = designer.getComponentAt(e); XCreator component = designer.getComponentAt(e);
designer.getSpacingLineDrawer().updateMouseEvent(e, true);
setCoverPaneNotDisplay(component, e, false); setCoverPaneNotDisplay(component, e, false);
if (processTopLayoutMouseMove(component, e)) { if (processTopLayoutMouseMove(component, e)) {
@ -353,7 +355,6 @@ public class EditingMouseListener extends MouseInputAdapter {
return; return;
} }
designer.getSpacingLineDrawer().updateMouseEvent(e, true);
processChartEditorMouseMove(component, e); processChartEditorMouseMove(component, e);
e.translatePoint(oldX - e.getX(), oldY - e.getY()); e.translatePoint(oldX - e.getX(), oldY - e.getY());
designer.repaint(); 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; 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所在的组件 * 从已选择的组件中找x,y所在的组件
*/ */
@ -1095,25 +1127,38 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* */ * */
@Override @Override
public XCreator getComponentAt(int x, int y) { public XCreator getComponentAt(int x, int y) {
XLayoutContainer container = y < paraHeight - formArea.getVerticalValue() ? paraComponent : rootComponent; XLayoutContainer container = getRootContainer(y);
if (container == null) { XCreator result = xCreatorAt(getRelativeScaleX(x) - container.getX(), getRelativeScaleY(y) - container.getY(), container);
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);
return result == null ? getComponentAt(x, y, null) : result; return result == null ? getComponentAt(x, y, null) : result;
} }
@Nullable @Nullable
public XCreator getComponentAt(int x, int y, XCreator[] except) { 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; XLayoutContainer container = y < paraHeight - formArea.getVerticalValue() ? paraComponent : rootComponent;
if (container == null) { if (container == null) {
container = rootComponent; container = rootComponent;
} }
XCreator comp = xCreatorAt(x + (int)(formArea.getHorizontalValue()/scale), (int)(y + formArea.getVerticalValue()/scale), container, return container;
except); }
return comp == null ? container : comp;
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() { 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 static final int MIN_SPACING = 10;
private FormDesigner designer; private FormDesigner designer;
private XCreator hoverCreator; private XCreator hoverCreator = null;
private Rectangle selectedRec; private Rectangle selectedRec;
private boolean isMouseMoveEvent = false; private boolean isMouseMoveEvent = false;
@ -30,7 +30,10 @@ public class FormSpacingLineDrawer {
} }
public void updateMouseEvent(MouseEvent e, boolean isMouseMoveEvent) { 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; this.isMouseMoveEvent = isMouseMoveEvent;
} }
@ -131,14 +134,6 @@ public class FormSpacingLineDrawer {
designer.getSelectionModel().getSelection().getSelectedCreator().getParent() == null; 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) { private boolean isNeedExtendedLine(AbstractFormParallelLine[] nearestSides) {
return nearestSides[0].isVerticalCenterLineBeforeTheParallelLine(nearestSides[1]) || nearestSides[0].isVerticalCenterLineBehindTheParallelLine(nearestSides[1]); return nearestSides[0].isVerticalCenterLineBeforeTheParallelLine(nearestSides[1]) || nearestSides[0].isVerticalCenterLineBehindTheParallelLine(nearestSides[1]);
} }
@ -147,12 +142,13 @@ public class FormSpacingLineDrawer {
return isSelectedForm() || isSelectedRootComponent(); return isSelectedForm() || isSelectedRootComponent();
} }
private boolean isHoveredRootPane() { private boolean isSelectedCreatorSameParentWithHoveredCreator() {
return isHoveredForm() || isHoveredRootComponent(); XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
return selectedCreator != null && hoverCreator != null && selectedCreator.getParent() == hoverCreator.getParent();
} }
private boolean isDrawSpacingLine() { private boolean isDrawSpacingLine() {
return !isSelectedRootPane() && !isHoveredRootPane() && isMouseMoveEvent; return !isSelectedRootPane() && isSelectedCreatorSameParentWithHoveredCreator() && isMouseMoveEvent;
} }
private AbstractFormParallelLine[] getNearestHorizontalSide() { 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) { public FormMultiWidgetCardPane(FormDesigner designer) {
super(designer); super(designer);
arrangement = new MultiSelectionArrangement(designer);
} }
public void initPropertyPane() { public void initPropertyPane() {
arrangement = new MultiSelectionArrangement(designer);
content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
content.add(createArrangementLayoutPane(), BorderLayout.CENTER); content.add(createArrangementLayoutPane(), BorderLayout.CENTER);
} }

Loading…
Cancel
Save