From 3f4465ff1d18f79681f786b3f872376513f3b731 Mon Sep 17 00:00:00 2001 From: zhouping Date: Wed, 20 Jul 2016 15:42:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E5=8D=95=E4=BA=A4=E4=BA=92=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=B5=8B=E8=AF=95bug=E4=BF=AE=E6=94=B9=201.=E4=BB=8Et?= =?UTF-8?q?oolbarbtn=E4=B8=8A=E6=8B=96=E4=B8=8Btab=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=90=8E=E5=BD=93=E5=89=8D=E7=9A=84=E9=80=89=E4=B8=AD=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=B9=B6=E9=9D=9E=E9=A1=B6=E5=B1=82=E5=B8=83=E5=B1=80?= =?UTF-8?q?=202.tab=E5=B8=83=E5=B1=80=E9=A1=B6=E5=B1=82=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E7=9A=84=E5=90=8D=E5=AD=97=E4=BF=AE=E6=94=B9=E4=B8=BAtablayout?= =?UTF-8?q?=203.=E6=94=AF=E6=8C=81tab=E5=B8=83=E5=B1=80=E7=9A=84=E5=B5=8C?= =?UTF-8?q?=E5=A5=97=E5=90=8E=E6=AD=A3=E7=A1=AE=E6=98=BE=E7=A4=BA=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../creator/cardlayout/XWCardLayout.java | 3 +- .../cardlayout/XWCardMainBorderLayout.java | 9 +++- .../mainframe/EditingMouseListener.java | 50 +++++++++++++++---- .../mainframe/FormCreatorDropTarget.java | 7 ++- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java index 621f4c5f5e..346a5ce3a7 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardLayout.java @@ -219,8 +219,7 @@ public class XWCardLayout extends XLayoutContainer { * */ protected void setWrapperName(XLayoutContainer parentPanel, String widgetName) { - //先随便set一个, 以后还是要隐藏的 - parentPanel.toData().setWidgetName("border_card_" + widgetName); + parentPanel.toData().setWidgetName("tablayout" + widgetName.replaceAll(createDefaultName(),"")); } /** diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java index b9039b1d6e..42a45c53c3 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java @@ -11,6 +11,7 @@ import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.models.SelectionModel; import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWBorderLayout; import com.fr.design.icon.IconPathConstants; @@ -263,6 +264,12 @@ public class XWCardMainBorderLayout extends XWBorderLayout{ */ @Override public XLayoutContainer getTopLayout() { - return this; + XLayoutContainer xTopLayout = XCreatorUtils.getParentXLayoutContainer(this).getTopLayout(); + if (xTopLayout != null && !xTopLayout.isEditable()){ + return xTopLayout; + } + else{ + return this; + } } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java index e66b37552a..a4ccae7c2f 100644 --- a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java @@ -1,9 +1,6 @@ package com.fr.design.mainframe; -import java.awt.Color; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Rectangle; +import java.awt.*; import java.awt.event.MouseEvent; import javax.swing.*; @@ -326,10 +323,12 @@ public class EditingMouseListener extends MouseInputAdapter { if (designer.getCursor().getType() == Cursor.HAND_CURSOR) { designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } - if (e.getX() > (parent.getX() + parent.getWidth() / 2 - EDIT_BTN_WIDTH / 2 - GAP) - && e.getX() < (parent.getX() + parent.getWidth() / 2 + EDIT_BTN_WIDTH / 2 + GAP)) { - if (e.getY() > (parent.getY() + parent.getHeight() / 2 - EDIT_BTN_HEIGHT / 2 - GAP) - && e.getY() < (parent.getY() + parent.getHeight() / 2 + EDIT_BTN_HEIGHT / 2 + GAP + designer.getParaHeight())) { + int minX = getParentPositionX(parent, parent.getX()) + parent.getWidth() / 2; + int minY = getParentPositionY(parent, parent.getY()) + parent.getHeight() / 2; + int offsetX = EDIT_BTN_WIDTH / 2 + GAP; + int offsetY = EDIT_BTN_HEIGHT / 2 + GAP; + if (e.getX() > (minX - offsetX) && e.getX() < (minX + offsetX)) { + if (e.getY() > (minY - offsetY) && e.getY() < (minY + offsetY + designer.getParaHeight())) { designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } } @@ -417,11 +416,43 @@ public class EditingMouseListener extends MouseInputAdapter { designer.repaint(); } + //当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑 + private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout){ + //双击的前后点击click为相同对象,过滤掉 + if (clickedTopLayout == null || clickedTopLayout == clickingTopLayout){ + return; + } + //位于同一层级的控件,父布局相同,过滤掉 + if (clickingTopLayout != null && clickedTopLayout.getParent() == clickingTopLayout.getParent()){ + return; + } + //前后点击的位于不同层级,要置为不可编辑 + XLayoutContainer xLayoutContainer = (XLayoutContainer)clickedTopLayout.getParent(); + if (xLayoutContainer == clickingTopLayout){ + return; + } + if (xLayoutContainer != null){ + xLayoutContainer.setEditable(false); + setTopLayoutUnEditable((XLayoutContainer) clickedTopLayout.getParent(), clickingTopLayout); + } + } + + private boolean isCreatorInLayout(XCreator creator, XCreator layout){ + if (creator == layout){ + return true; + } + if(layout.getParent() != null){ + return isCreatorInLayout(creator, (XCreator)layout.getParent()); + } + return false; + } + private XCreator processTopLayoutMouseClick(XCreator creator){ XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(creator).getTopLayout(); if(topLayout != null){ - if (clickTopLayout != null && clickTopLayout != topLayout){ + if (clickTopLayout != null && clickTopLayout != topLayout && !isCreatorInLayout(clickTopLayout, topLayout)){ clickTopLayout.setEditable(false); + setTopLayoutUnEditable(clickTopLayout, topLayout); } clickTopLayout = topLayout; if(!topLayout.isEditable()) { @@ -431,6 +462,7 @@ public class EditingMouseListener extends MouseInputAdapter { else{ if(clickTopLayout != null){ clickTopLayout.setEditable(false); + setTopLayoutUnEditable(clickTopLayout, null); } } diff --git a/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java index a90ba7fb6e..ed4cf4190a 100644 --- a/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -9,6 +9,7 @@ import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetEvent; +import java.util.ArrayList; import javax.swing.BorderFactory; import javax.swing.JWindow; @@ -85,8 +86,12 @@ public class FormCreatorDropTarget extends DropTarget { if (success) { // 如果添加成功,则触发相应事件 XCreator xCreator = container.acceptType(XWParameterLayout.class) ? designer.getParaComponent() : designer.getRootComponent(); + //SetSelection时要确保选中的是最顶层的布局 + //tab布局添加的时候是初始化了XWCardLayout,实际上最顶层的布局是XWCardMainBorderLayout + XCreator addingXCreator = addingModel.getXCreator(); + Widget widget = (addingXCreator.getTopLayout() != null) ? (addingXCreator.getTopLayout().toData()) : addingXCreator.toData(); designer.getSelectionModel().setSelectedCreators( - FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{addingModel.getXCreator().toData()})); + FormSelectionUtils.rebuildSelection(xCreator, new Widget[]{widget})); designer.getEditListenerTable().fireCreatorModified(addingModel.getXCreator(), DesignerEvent.CREATOR_ADDED); } else { Toolkit.getDefaultToolkit().beep();