From eaf8616790a1dd5cadd1e7d4e4a029ba15b1ea8c Mon Sep 17 00:00:00 2001 From: "coral.chen@fanruan.com" Date: Thu, 11 May 2023 21:08:53 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-94629=20=E8=AE=BE=E8=AE=A1=E5=99=A8tab?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=93=8D=E4=BD=9C=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../creator/cardlayout/XCardSwitchButton.java | 63 ++++++++++++++----- .../creator/cardlayout/XWCardTagLayout.java | 39 +++++++++++- .../layout/WCardMainLayoutDefinePane.java | 6 +- .../layout/WCardTagLayoutDefinePane.java | 6 +- 4 files changed, 90 insertions(+), 24 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java index 85436c72fd..1c70ef870d 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java @@ -10,6 +10,7 @@ import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XButton; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; +import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.gui.ilable.UILabel; @@ -25,16 +26,27 @@ import com.fr.form.ui.container.WTabTextDirection; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; import com.fr.general.Background; -import com.fr.general.act.BorderPacker; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; +import com.fr.general.act.BorderPacker; import com.fr.general.act.TitlePacker; import com.fr.general.cardtag.TemplateStyle; import com.fr.stable.unit.PT; -import javax.swing.*; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.SwingUtilities; import javax.swing.plaf.basic.BasicLabelUI; -import java.awt.*; +import java.awt.Color; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.util.ArrayList; @@ -236,36 +248,54 @@ public class XCardSwitchButton extends XButton { //SwitchButton对应的XWCardLayout和XWCardTagLayout暂未存到xml中,重新打开时根据父子层关系获取 - private void initRelateLayout(){ - this.tagLayout = (XWCardTagLayout)this.getBackupParent(); + private void initRelateLayout() { + this.tagLayout = (XWCardTagLayout) this.getBackupParent(); XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.tagLayout.getBackupParent(); - XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent(); + XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent(); this.cardLayout = borderLayout.getCardPart(); } - //是否进入点击关闭按钮区域 - private boolean isSelectedClose(MouseEvent e, FormDesigner designer){ + /** + *

是否进入点击关闭按钮区域 + *

计算逻辑: + *

先得到鼠标的绝对坐标 -> tab布局的绝对坐标 -> 得到鼠标相对tab的坐标(有参数面板时要减去参数面板的高度) + *

再计算删除区域位置的相对坐标,通过对比判定鼠标是否在点击关闭按钮区域内 + * + * @param e 鼠标事件 + * @param designer 表单编辑对象 + * @return true/false 在内/不在 + */ + private boolean isSelectedClose(MouseEvent e, FormDesigner designer) { int diff = designer.getHorizontalScaleValue(); // mouse position + // 这里是鼠标的绝对位置 int ex = e.getX() + diff; int ey = e.getY(); - //获取tab布局的位置,鼠标相对于tab按钮的位置 + // 获取tab布局的位置,鼠标相对于tab按钮的位置 Container mainLayout = cardLayout.getBackupParent(); + // 这个point是当前tab布局的相对坐标,是相对于父容器的坐标 + // 比如父级是一个absolute块,放在左上角,现在得到的point就是(0,0) Point point = mainLayout.getLocation(); int y = 0; int x = 0; - //遍历一下,不然是相对位置,嵌套后位置不对 - while (mainLayout.getParent() != null){ - if(mainLayout instanceof XWCardLayout){ + // 遍历一下,不然是相对位置,嵌套后位置不对 + // 这里是要得到tab布局的绝对位置,所以要加上父组件的位置 + while (mainLayout.getParent() != null) { + if (mainLayout instanceof XWCardLayout) { y += mainLayout.getY(); } mainLayout = mainLayout.getParent(); - if(mainLayout instanceof XWCardMainBorderLayout){ + if (mainLayout instanceof XWCardMainBorderLayout) { + x += mainLayout.getX(); + y += mainLayout.getY(); + } + + if (mainLayout instanceof XWAbsoluteLayout) { x += mainLayout.getX(); y += mainLayout.getY(); } @@ -291,10 +321,11 @@ public class XCardSwitchButton extends XButton { int width = button.getWidth(); // 鼠标进入按钮右侧删除图标区域 - double recX = position.getX() + titlePoint.getX() + (width - CLOSE_ICON_RIGHT_OFFSET); + double recX = position.getX() + titlePoint.getX() + (width - CLOSE_ICON_RIGHT_OFFSET); double recY = position.getY() + titlePoint.getY() + CLOSE_ICON_TOP_OFFSET; - - return (recX < ex && ex < recX + CLOSE_ICON_RIGHT_OFFSET && ey < recY && ey > position.getY()); + // 比较的是相对位置的偏移量是否在一定距离内 + // 所以要得到鼠标相对于当前tab块的坐标 + return (recX < ex && ex < recX + CLOSE_ICON_RIGHT_OFFSET && ey < recY && ey > position.getY()); } //将当前switchButton改为选中状态 diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java index 0353d53dd0..a88b6847e4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java @@ -24,21 +24,25 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormHierarchyTreePane; import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.WTabDisplayPosition; import com.fr.form.ui.container.cardlayout.WCardTagLayout; import com.fr.form.ui.container.cardlayout.WTabFitLayout; -import com.fr.general.act.BorderPacker; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; +import com.fr.general.act.BorderPacker; import com.fr.general.cardtag.DefaultTemplateStyle; import com.fr.stable.StringUtils; import javax.swing.border.Border; -import java.awt.*; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Rectangle; import java.awt.event.ContainerEvent; import java.awt.event.MouseEvent; import java.util.HashMap; @@ -434,7 +438,7 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout { } - private void fixTitleLayout(XLayoutContainer parent){ + private void fixTitleLayout(XLayoutContainer parent) { FormDesigner formDesigner = WidgetPropertyPane.getInstance().getEditingFormDesigner(); LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(formDesigner, parent); if (layoutAdapter != null) { @@ -443,4 +447,33 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout { } } + /** + *

对于tab组件,WCardMainBorderLayout里面有两个子容器: + *

  • WCardTitleLayout,里面包含两个部分,一个是CardAddButton,另一个是WCardTagLayout - tabpane0
  • + *
  • WCardLayout,里面放的是WTabFitLayout - tab00、tab10
  • + *

    在右侧组件树选择删除WCardTagLayout时(tabpane0),按照现在的产品逻辑,应该删除整个tab组件 + * + * @param creator 组件 + * @param designer 表单设计器 + */ + @Override + public void deleteRelatedComponent(XCreator creator, FormDesigner designer) { + XWCardTagLayout tagLayout = (XWCardTagLayout) creator; + // 先删除所有tab按钮 + for (int i = 0; i < tagLayout.getComponentCount(); i++) { + tagLayout.remove(i); + } + //逐层回溯找出最外层的XWCardMainBorderLayout + XWCardTitleLayout cardTitleLayout = (XWCardTitleLayout) tagLayout.getBackupParent(); + XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout) cardTitleLayout.getBackupParent(); + // 删除tab布局 + SelectionModel selectionModel = designer.getSelectionModel(); + if (mainLayout != null) { + selectionModel.setSelectedCreator(mainLayout); + selectionModel.deleteSelection(); + } + LayoutUtils.layoutRootContainer(designer.getRootComponent()); + FormHierarchyTreePane.getInstance().refreshRoot(); + selectionModel.setSelectedCreator(designer.getRootComponent()); + } } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardMainLayoutDefinePane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardMainLayoutDefinePane.java index 2278b7b0f8..6276c3c2df 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardMainLayoutDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/layout/WCardMainLayoutDefinePane.java @@ -7,16 +7,13 @@ import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.gui.xpane.CardTagLayoutStylePane; -import com.fr.design.gui.xpane.LayoutStylePane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.widget.accessibles.AccessibleCardTagWLayoutBorderStyleEditor; import com.fr.design.widget.ui.designer.AbstractDataModify; import com.fr.form.ui.LayoutBorderStyle; import com.fr.form.ui.container.WCardLayout; import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; - import javax.swing.BorderFactory; import javax.swing.JPanel; import java.awt.BorderLayout; @@ -72,6 +69,9 @@ public class WCardMainLayoutDefinePane extends AbstractDataModify public void populateBean(WCardTagLayout ob) { //标题背景和字体属性设置在WCardLayout上做兼容 XLayoutContainer topLayout = creator.getTopLayout(); + if (topLayout.getComponentCount() == 0) { + // 没有子组件,不用做处理 + return; + } LayoutBorderStyle layoutBorderStyle = (LayoutBorderStyle) ((XWCardMainBorderLayout) topLayout).getCardPart().toData().getBorderStyle(); - displayPositionGroup.setSelectedIndex(ob.getDisplayPosition().getType()); textDirectionGroup.setSelectedIndex(ob.getTextDirection().getType()); backgroundEditor.setValue(layoutBorderStyle.getTitle().getBackground());