|
|
|
@ -1,6 +1,13 @@
|
|
|
|
|
package com.fr.design.mainframe; |
|
|
|
|
|
|
|
|
|
import com.fr.design.designer.creator.XChartEditor; |
|
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
|
import com.fr.design.designer.creator.XCreatorUtils; |
|
|
|
|
import com.fr.design.designer.creator.XElementCase; |
|
|
|
|
import com.fr.design.designer.creator.XLayoutContainer; |
|
|
|
|
import com.fr.design.designer.creator.XWParameterLayout; |
|
|
|
|
import com.fr.design.form.parameter.FormParaDesigner; |
|
|
|
|
import com.fr.design.form.util.FormDesignerUtils; |
|
|
|
|
import com.fr.design.utils.ComponentUtils; |
|
|
|
|
import com.fr.stable.Constants; |
|
|
|
|
import com.fr.stable.GraphDrawHelper; |
|
|
|
@ -17,9 +24,10 @@ import java.awt.geom.RoundRectangle2D;
|
|
|
|
|
public class FormSpacingLineDrawer { |
|
|
|
|
private static final Color LINE_COLOR = new Color(230, 82, 81); |
|
|
|
|
private static final Color TEXT_COLOR = new Color(255, 255, 255); |
|
|
|
|
private static final int TEXT_PADDING_HORIZONTAL = 6; |
|
|
|
|
private static final int TEXT_PADDING_VERTICAL = 1; |
|
|
|
|
private static final int TEXT_PADDING_HORIZONTAL = 8; |
|
|
|
|
private static final int TEXT_PADDING_VERTICAL = 2; |
|
|
|
|
private static final int MIN_SPACING = 10; |
|
|
|
|
private static final float TIP_FONT_SIZE = 10F; |
|
|
|
|
|
|
|
|
|
private FormDesigner designer; |
|
|
|
|
private XCreator hoverCreator = null; |
|
|
|
@ -34,7 +42,7 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
public void updateMouseEvent(MouseEvent e, boolean isMouseMoveEvent) { |
|
|
|
|
XCreator creator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
if (creator != null) { |
|
|
|
|
this.hoverCreator = designer.getComponentAt(e.getX(), e.getY(), creator.getLevel()); |
|
|
|
|
this.hoverCreator = getHoverComponentAt(e.getX(), e.getY()); |
|
|
|
|
} |
|
|
|
|
this.isMouseMoveEvent = isMouseMoveEvent; |
|
|
|
|
} |
|
|
|
@ -80,10 +88,10 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int startX = (int) nearestSides[0].getStartPointOnVerticalCenterLine().getX(); |
|
|
|
|
int startY = (int) nearestSides[0].getStartPointOnVerticalCenterLine().getY(); |
|
|
|
|
int endX = (int) nearestSides[0].getEndPointOnVerticalCenterLine(nearestSides[1].getParallelValue()).getX(); |
|
|
|
|
int endY = (int) nearestSides[0].getEndPointOnVerticalCenterLine(nearestSides[1].getParallelValue()).getY(); |
|
|
|
|
int startX = (int) nearestSides[0].getStartPointOnVerticalCenterLine().getX() - designer.getHorizontalScaleValue(); |
|
|
|
|
int startY = (int) nearestSides[0].getStartPointOnVerticalCenterLine().getY() - designer.getVerticalScaleValue(); |
|
|
|
|
int endX = (int) nearestSides[0].getEndPointOnVerticalCenterLine(nearestSides[1].getParallelValue()).getX() - designer.getHorizontalScaleValue(); |
|
|
|
|
int endY = (int) nearestSides[0].getEndPointOnVerticalCenterLine(nearestSides[1].getParallelValue()).getY() - designer.getVerticalScaleValue(); |
|
|
|
|
|
|
|
|
|
drawSpacingLine(g, startX, startY, endX, endY); |
|
|
|
|
drawSpacingText(g, String.valueOf(gap), (startX + endX) / 2, (startY + endY) / 2); |
|
|
|
@ -98,10 +106,10 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
|
|
|
|
|
private void drawExtendedLine(Graphics g, AbstractFormParallelLine[] nearestSides) { |
|
|
|
|
if (isNeedExtendedLine(nearestSides)) { |
|
|
|
|
int startX = (int) nearestSides[1].getExtendedLineStartPoint(nearestSides[0]).getX(); |
|
|
|
|
int startY = (int) nearestSides[1].getExtendedLineStartPoint(nearestSides[0]).getY(); |
|
|
|
|
int endX = (int) nearestSides[1].getExtendedLineEndPoint(nearestSides[0]).getX(); |
|
|
|
|
int endY = (int) nearestSides[1].getExtendedLineEndPoint(nearestSides[0]).getY(); |
|
|
|
|
int startX = (int) nearestSides[1].getExtendedLineStartPoint(nearestSides[0]).getX() - designer.getHorizontalScaleValue(); |
|
|
|
|
int startY = (int) nearestSides[1].getExtendedLineStartPoint(nearestSides[0]).getY() - designer.getVerticalScaleValue(); |
|
|
|
|
int endX = (int) nearestSides[1].getExtendedLineEndPoint(nearestSides[0]).getX() - designer.getHorizontalScaleValue(); |
|
|
|
|
int endY = (int) nearestSides[1].getExtendedLineEndPoint(nearestSides[0]).getY() - designer.getVerticalScaleValue(); |
|
|
|
|
drawExtendedLine(g, startX, startY, endX, endY); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -109,7 +117,7 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
private void drawSpacingText(Graphics g, String text, int x, int y) { |
|
|
|
|
Graphics2D g2d = (Graphics2D) g.create(); |
|
|
|
|
g2d.setColor(LINE_COLOR); |
|
|
|
|
Font newFont = g2d.getFont().deriveFont(8F).deriveFont(Font.BOLD); |
|
|
|
|
Font newFont = g2d.getFont().deriveFont(TIP_FONT_SIZE).deriveFont(Font.BOLD); |
|
|
|
|
g2d.setFont(newFont); |
|
|
|
|
FontMetrics metrics = g2d.getFontMetrics(); |
|
|
|
|
int lineHeight = metrics.getAscent(); // 这里由于都是数字,要居中必须忽略掉leading和descent的高度
|
|
|
|
@ -128,14 +136,16 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
GraphDrawHelper.drawString(g2d, text, labelX, labelY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedParaComponent() { |
|
|
|
|
return designer.getParaComponent() == designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedRootComponent() { |
|
|
|
|
return designer.getSelectionModel().getSelection().size() == 1 && |
|
|
|
|
designer.isRoot(designer.getSelectionModel().getSelection().getSelectedCreator()); |
|
|
|
|
return designer.isRoot(designer.getSelectionModel().getSelection().getSelectedCreator()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedForm() { |
|
|
|
|
return designer.getSelectionModel().getSelection().size() == 1 && |
|
|
|
|
designer.getSelectionModel().getSelection().getSelectedCreator().getParent() == null; |
|
|
|
|
return designer.getSelectionModel().getSelection().getSelectedCreator().getParent() == null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isNeedExtendedLine(AbstractFormParallelLine[] nearestSides) { |
|
|
|
@ -143,16 +153,38 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedRootPane() { |
|
|
|
|
return isSelectedForm() || isSelectedRootComponent(); |
|
|
|
|
// form、body、para这三个选中了,都不要画任何间距线
|
|
|
|
|
return isSelectedForm() || isSelectedRootComponent() || isSelectedParaComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 当前组件是否在参数面板里面
|
|
|
|
|
private boolean isCompInPara(XCreator creator) { |
|
|
|
|
XLayoutContainer container = XCreatorUtils.getHotspotContainer(creator); |
|
|
|
|
|
|
|
|
|
boolean xCreatorAccept = creator.acceptType(XWParameterLayout.class); |
|
|
|
|
boolean containerAccept = container != null && container.acceptType(XWParameterLayout.class); |
|
|
|
|
|
|
|
|
|
return xCreatorAccept || containerAccept; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isBodyAbsoluteLayout() { |
|
|
|
|
return !(designer instanceof FormParaDesigner) && FormDesignerUtils.isBodyAbsolute(designer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedCompInPara() { |
|
|
|
|
return isCompInPara(designer.getSelectionModel().getSelection().getSelectedCreator()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedCreatorSameParentWithHoveredCreator() { |
|
|
|
|
XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); |
|
|
|
|
return selectedCreator != null && hoverCreator != null && selectedCreator.getParent() == hoverCreator.getParent(); |
|
|
|
|
private boolean isHoveredCompInPara() { |
|
|
|
|
return isCompInPara(hoverCreator); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isSelectedCompOrHoveredCompInPara() { |
|
|
|
|
return isSelectedCompInPara() || isHoveredCompInPara(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isDrawSpacingLine() { |
|
|
|
|
return !isSelectedRootPane() && isSelectedCreatorSameParentWithHoveredCreator() && isMouseMoveEvent; |
|
|
|
|
return isBodyAbsoluteLayout() && !isSelectedRootPane() && hoverCreator != null && !isSelectedCompOrHoveredCompInPara() && isMouseMoveEvent; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private AbstractFormParallelLine[] getNearestHorizontalSide() { |
|
|
|
@ -196,4 +228,25 @@ public class FormSpacingLineDrawer {
|
|
|
|
|
} |
|
|
|
|
return nearestSides; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private XCreator getHoverComponentAt(int x, int y) { |
|
|
|
|
XCreator component = designer.getComponentAt(x, y); |
|
|
|
|
XLayoutContainer parent = XCreatorUtils.getHotspotContainer(component).getTopLayout(); |
|
|
|
|
if (parent != null) { |
|
|
|
|
if (!parent.isEditable()) { |
|
|
|
|
return parent; |
|
|
|
|
} else { |
|
|
|
|
if (parent == component) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (component instanceof XChartEditor || component instanceof XElementCase) { |
|
|
|
|
return (XCreator) component.getParent(); |
|
|
|
|
} |
|
|
|
|
return component; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return component; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|