diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index ff89f059ba..49e0f94d29 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -77,12 +77,14 @@ public class SelectionModel { * @param e 鼠标事件 */ public void selectACreatorAtMouseEvent(MouseEvent e) { + //单选因为要先从已选择的组件中筛选一遍,所以先选择再reset + XCreator comp = designer.getComponentAt(e); if (e.getButton() == MouseEvent.BUTTON3 || (!InputEventBaseOnOS.isControlDown(e) && !e.isShiftDown())) { // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 selection.reset(); } else { //按下Ctrl或者shift键时鼠标可以进行多选,两次点击同一控件就取消选中 - XCreator comp = designer.getComponentAt(e); + //XCreator comp = designer.getComponentAt(e); XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); if (topLayout != null && !topLayout.isEditable()) { comp = topLayout; @@ -93,9 +95,10 @@ public class SelectionModel { selection.removeCreator(selected); } } + comp = designer.getComponentAt(e); } // 获取e所在的组件 - XCreator comp = designer.getComponentAt(e); + //XCreator comp = designer.getComponentAt(e); selectACreator(comp); } @@ -309,6 +312,7 @@ public class SelectionModel { designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); setSelectedCreator(isInPara ? designer.getParaComponent() : designer.getRootComponent()); + designer.getTopXCreators().refresh(); // 触发事件 diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java index 44996df8cd..5f5bb73b22 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java @@ -14,6 +14,7 @@ import com.fr.design.mainframe.widget.editors.ImgBackgroundEditor; import com.fr.design.mainframe.widget.editors.ShortCutTextEditor; import com.fr.design.mainframe.widget.renderer.FontCellRenderer; import com.fr.design.mainframe.widget.renderer.IconCellRenderer; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; import com.fr.form.parameter.FormSubmitButton; import com.fr.form.ui.Button; import com.fr.form.ui.FreeButton; @@ -309,4 +310,18 @@ public class XButton extends XWidgetCreator { } +/* @Override + public BasicTopCreator getTopXCreator(){ + return new BasicTopXCreator(this) { + @Override + protected void initEditor() { + XButton(XButton.this.toData(),this.getSize() + + } + } + + //return new XButton((Button)this.toData(),this.getSize()); + + }*/ + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java index b0f6e11589..0ca125e930 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java @@ -17,6 +17,8 @@ import com.fr.design.mainframe.CoverReportPane; import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.HelpDialogManager; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; +import com.fr.design.mainframe.widget.topxcreator.TopXCreator; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.module.DesignModuleFactory; import com.fr.form.ui.BaseChartEditor; @@ -258,6 +260,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator { (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR); displayCoverPane(!isEditing); selectionModel.selectACreatorAtMouseEvent(e); + editingMouseListener.refreshTopXCreator(isEditing); if (editingMouseListener.stopEditing()) { if (this != (XCreator) designer.getRootComponent()) { @@ -357,4 +360,35 @@ public class XChartEditor extends XBorderStyleWidgetCreator { public boolean supportMobileStyle() { return false; } + + @Override + public BasicTopXCreator getTopXCreator() { + return new TopXChart(this); + } + + private class TopXChart extends TopXCreator{ + private final DesignerEditor designerEditor; + + public TopXChart(XCreator creator) { + super(creator); + designerEditor = creator.getDesignerEditor(); + Rectangle bounds=getBounds(); + designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); + } + + /** + * 更新designerEditor的大小 + * */ + protected void resetSize(Rectangle bounds){ + super.resetSize(bounds); + designerEditor.getEditorTarget().setBounds(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); + } + + @Override + public void paint(Graphics g) { + designerEditor.paintEditor(g, this.getSize()); + super.paint(g); + } + } + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java index dcb6938836..0496d74787 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java @@ -19,6 +19,7 @@ import com.fr.design.mainframe.CoverReportPane; import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.NoSupportAuthorityEdit; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; import com.fr.design.mainframe.WidgetPropertyPane; import com.fr.design.utils.gui.LayoutUtils; import com.fr.form.ui.Widget; @@ -798,10 +799,16 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo /** * 是否支持共享-现只支持报表块、图表、tab块、绝对布局 - * @return */ public boolean isSupportShared() { return false; } + /** + * 获得该组件的顶层显示组件 + */ + public BasicTopXCreator getTopXCreator() { + return null; + } + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java index ec06a1597d..a9fd877168 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XElementCase.java @@ -13,6 +13,8 @@ import com.fr.design.mainframe.widget.editors.ElementCaseToolBarEditor; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.propertypane.BrowserFitPropertyEditor; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; +import com.fr.design.mainframe.widget.topxcreator.TopXCreator; import com.fr.form.FormElementCaseContainerProvider; import com.fr.form.FormElementCaseProvider; import com.fr.form.FormProvider; @@ -319,6 +321,7 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ HelpDialogManager.getInstance().setPane(coverPanel); super.respondClick(editingMouseListener, e); + editingMouseListener.refreshTopXCreator(); if (this.isHelpBtnOnFocus()) { coverPanel.setMsgDisplay(e); } else { @@ -370,4 +373,23 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme public boolean isSupportShared() { return true; } + + @Override + public BasicTopXCreator getTopXCreator() { + return new TopXElementCase(this); + } + + private class TopXElementCase extends TopXCreator { + private UILabel imageLabel; + + public TopXElementCase(XCreator creator) { + super(creator); + if (creator instanceof XElementCase) { + XElementCase elementCase = (XElementCase) creator; + imageLabel = elementCase.initImageBackground(); + add(imageLabel); + } + } + } + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java index 6190ffaebb..5db000e189 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java @@ -7,6 +7,7 @@ import com.fr.design.form.util.XCreatorConstants; import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; import com.fr.form.ui.container.WAbsoluteBodyLayout; import com.fr.stable.core.PropertyChangeAdapter; @@ -130,4 +131,9 @@ public class XWAbsoluteBodyLayout extends XWAbsoluteLayout { public boolean isSupportShared() { return false; } + + @Override + public BasicTopXCreator getTopXCreator() { + return null; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java index b98c2a952d..98143a7ea0 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWAbsoluteLayout.java @@ -25,6 +25,8 @@ import com.fr.design.mainframe.FormArea; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetHelpDialog; import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; +import com.fr.design.mainframe.widget.topxcreator.TopXCreator; import com.fr.form.ui.Connector; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WAbsoluteLayout; @@ -542,6 +544,7 @@ public class XWAbsoluteLayout extends XLayoutContainer { selectionModel.selectACreatorAtMouseEvent(e); designer.repaint(); + editingMouseListener.refreshTopXCreator(isEditing); if (editingMouseListener.stopEditing()) { if (this != designer.getRootComponent()) { @@ -606,4 +609,9 @@ public class XWAbsoluteLayout extends XLayoutContainer { return super.getWidgetPropertyUIProviders(); } } + + @Override + public BasicTopXCreator getTopXCreator() { + return new TopXCreator(this); + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java index cb288c98cc..384ee07b64 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWParameterLayout.java @@ -15,6 +15,7 @@ import com.fr.design.mainframe.widget.editors.BooleanEditor; import com.fr.design.mainframe.widget.editors.WidgetDisplayPosition; import com.fr.design.mainframe.widget.renderer.BackgroundRenderer; import com.fr.design.mainframe.widget.renderer.WidgetDisplayPositionRender; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; import com.fr.form.ui.container.WBorderLayout; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WParameterLayout; @@ -251,4 +252,10 @@ public class XWParameterLayout extends XWAbsoluteLayout { return false; } + @Override + public BasicTopXCreator getTopXCreator() { + return null; + } + + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java index 2cc56ee9ba..b8fe8f0049 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWTitleLayout.java @@ -7,6 +7,7 @@ import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRTitleLayoutAdapter; import com.fr.design.form.layout.FRTitleLayout; import com.fr.design.fun.WidgetPropertyUIProvider; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; import com.fr.form.ui.Label; import com.fr.form.ui.Widget; import com.fr.form.ui.WidgetTitle; @@ -189,4 +190,9 @@ public class XWTitleLayout extends DedicateLayoutContainer { XCreator creator = getPropertyDescriptorCreator(); return creator.getWidgetPropertyUIProviders(); } + + @Override + public BasicTopXCreator getTopXCreator() { + return getEditingChildCreator().getTopXCreator(); + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java index 25da3e7754..3ad1463b97 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardMainBorderLayout.java @@ -16,16 +16,15 @@ 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.designer.creator.XWidgetCreator; -import com.fr.design.designer.properties.mobile.MobileBooKMarkUsePropertyUI; -import com.fr.design.form.util.FormDesignerUtils; import com.fr.design.form.util.XCreatorConstants; -import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.icon.IconPathConstants; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.WidgetHelpDialog; import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.mainframe.widget.topxcreator.BasicTopXCreator; +import com.fr.design.mainframe.widget.topxcreator.TopXCreator; import com.fr.form.event.Listener; import com.fr.form.ui.CardSwitchButton; import com.fr.form.ui.LayoutBorderStyle; @@ -438,6 +437,7 @@ public class XWCardMainBorderLayout extends XWBorderLayout { setEditable(isEditing); selectionModel.selectACreatorAtMouseEvent(e); + editingMouseListener.refreshTopXCreator(isEditing); designer.repaint(); if (editingMouseListener.stopEditing()) { @@ -514,4 +514,9 @@ public class XWCardMainBorderLayout extends XWBorderLayout { public boolean isSupportShared() { return true; } + + @Override + public BasicTopXCreator getTopXCreator() { + return new TopXCreator(this); + } } 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 49f246256c..010a382178 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 @@ -248,6 +248,7 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout { if (e.getClickCount() <= 1) { selectionModel.selectACreatorAtMouseEvent(e); } + editingMouseListener.refreshTopXCreator(); if (editingMouseListener.stopEditing()) { if (this != designer.getRootComponent()) { ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java index babc54b316..f6f6b2b411 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XWCardTitleLayout.java @@ -204,6 +204,7 @@ public class XWCardTitleLayout extends XWBorderLayout { if (e.getClickCount() <= 1) { selectionModel.selectACreatorAtMouseEvent(e); } + editingMouseListener.refreshTopXCreator(); if (editingMouseListener.stopEditing()) { if (this != designer.getRootComponent()) { diff --git a/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java b/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java index a2f295f87d..cbf6852558 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/ComponentTree.java @@ -2,6 +2,7 @@ package com.fr.design.mainframe; import com.fr.design.constants.UIConstants; 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.treeview.ComponentTreeCellRenderer; import com.fr.design.designer.treeview.ComponentTreeModel; @@ -15,7 +16,9 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTree; import javax.swing.SwingUtilities; +import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellRenderer; +import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import java.awt.BorderLayout; @@ -30,6 +33,9 @@ import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; public class ComponentTree extends JTree { @@ -81,6 +87,7 @@ public class ComponentTree extends JTree { public void setSelectionPath(TreePath path) { // 不管点击哪一项,都要先退出编辑状态(图表、报表块、绝对布局、tab块) designer.stopEditing(path); + designer.getTopXCreators().refresh(); super.setSelectionPath(path); } @@ -129,6 +136,7 @@ public class ComponentTree extends JTree { setSelectionPaths(treepath); if (treepath.length > 0) { scrollPathToVisible(treepath[0]); + //expandPath(treepath[0]); } } @@ -228,6 +236,64 @@ public class ComponentTree extends JTree { repaint(); } + public void expandTree() { + TreePath[] paths = getSelectedTreePath(); + if (paths.length > 0) { + expandPath(getSelectedTreePath()[0]); + } + } + public void getExpandNodes(List searchList) { + getExpandNodes((XLayoutContainer)designer.getTopContainer(),searchList); + } + + public void getExpandNodes(XLayoutContainer container, List searchList) { + for (int i = 0, size = container.getXCreatorCount(); i < size; i++) { + XCreator creator = container.getXCreator(i); + TreePath treePath=buildTreePath(creator); + if(isExpanded(treePath)) searchList.add(treePath); + if (creator instanceof XLayoutContainer) { + getExpandNodes((XLayoutContainer) creator, searchList); + } + } + } + public void expandNodes(List list){ + for(TreePath treePath:list) { + if (treePath.getLastPathComponent() instanceof XLayoutContainer) { + XLayoutContainer creator= (XLayoutContainer) treePath.getLastPathComponent(); + if (XCreatorUtils.getParentXLayoutContainer(creator) == null) { + continue; + } + expandPath(treePath); + } + } + } +/* private void expandNode(JTree myTree, DefaultMutableTreeNode currNode, List list){ + if(currNode.getParent()==null){ + list.remove(0); + } + if(list.size()<=0) return; + + int childCount = currNode.getChildCount(); + String strNode = vNode.elementAt(0).toString(); + DefaultMutableTreeNode child = null; + boolean flag=false; + for(int i=0; i0){ + expandNode(myTree,child, vNode); + }else{ + myTree.expandPath(new TreePath(child.getPath())); + } + } + }*/ + private TreePath buildTreePath(Component comp) { ArrayList path = new ArrayList(); Component parent = comp; diff --git a/designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java b/designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java index d692eaa5ea..5aa4f93ad5 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/CoverPane.java @@ -8,7 +8,7 @@ import com.fr.general.IOUtils; import com.fr.stable.Constants; -import javax.swing.JPanel; +import javax.swing.JComponent; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Component; @@ -28,7 +28,7 @@ import java.awt.Rectangle; * Date: 14-7-24 * Time: 上午9:09 */ -public class CoverPane extends JPanel { +public class CoverPane extends JComponent { private UIButton editButton; private AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); @@ -94,6 +94,7 @@ public class CoverPane extends JPanel { int preferWidth = editButton.getPreferredSize().width; int preferHeight = editButton.getPreferredSize().height; editButton.setBounds((width - preferWidth) / 2, (height - preferHeight) / 2, preferWidth, preferHeight); + System.out.println(width+"---"+height); } @Override diff --git a/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java b/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java index 183c0b08c6..c59d37eaab 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java @@ -308,6 +308,7 @@ public class EditingMouseListener extends MouseInputAdapter { XCreator component = designer.getComponentAt(e); setCoverPaneNotDisplay(component, e, false); + designer.getTopXCreators().displayCoverPane(e); if (processTopLayoutMouseMove(component, e)) { return; @@ -692,6 +693,7 @@ public class EditingMouseListener extends MouseInputAdapter { currentXCreator.stopEditing(); currentXCreator = null; currentEditor = null; + refreshTopXCreator(); return true; } return true; @@ -719,4 +721,19 @@ public class EditingMouseListener extends MouseInputAdapter { } currentEditor.getEditorTarget().setBounds(bounds); } + + /** + * 刷新顶层组件 + * */ + public void refreshTopXCreator(boolean isEditing){ + designer.refreshTopXCreator(isEditing); + } + + /** + * 刷新顶层组件 + * */ + public void refreshTopXCreator(){ + refreshTopXCreator(false); + } + } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index e5ce0f726f..191425df22 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -35,7 +35,9 @@ import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.XWBorderLayout; +import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.creator.XWTitleLayout; import com.fr.design.designer.properties.FormWidgetAuthorityEditPane; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.event.DesignerOpenedListener; @@ -43,6 +45,7 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.fun.RightSelectionHandlerProvider; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; +import com.fr.design.mainframe.widget.topxcreator.TopXCreators; import com.fr.design.menu.MenuDef; import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; @@ -121,6 +124,7 @@ public class FormDesigner extends TargetComponent
implements TreeSelection private FormArea formArea; private ConnectorHelper connectorHelper; private boolean isReportBlockEditing = false; + private TopXCreators topXCreators; //组件重叠 private boolean isWidgetsIntersect = false; @@ -184,6 +188,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection new FormDesignerDropTarget(this);// 添加Drag and Drop. this.switchAction = switchAction; + topXCreators=new TopXCreators(this); + add(topXCreators); // 必须刷新"参数/控件树"面板,否则,若最近一次打开模版为 cpt,重启设计器,打开 frm,控件树消失 populateParameterPropertyPane(); @@ -825,6 +831,39 @@ public class FormDesigner extends TargetComponent implements TreeSelection return null; } + /** + * 从已选择的组件中找x,y所在的组件 + */ + private XCreator xCreatorAt(int x, int y, XCreator[] xCreators) { + for (XCreator creator : xCreators) { + if (creator == null || !creator.isVisible()) { + continue; + } + if (creator instanceof XWAbsoluteBodyLayout || creator instanceof XWFitLayout || creator instanceof XWParameterLayout) { + continue; + } + x -= creator.getX(); + y -= creator.getY(); + Rectangle rect = ComponentUtils.computeVisibleRect(creator); + // 判断是否处于交叉区域 + if (isIntersectArea(x, y, rect)) { + if (creator instanceof XWTitleLayout) { + return creator.getEditingChildCreator(); + } + return creator; + } + } + return null; + } + + /** + * 刷新顶层组件 + * */ + public void refreshTopXCreator(boolean isEditing){ + topXCreators.refresh(); + topXCreators.setVisible(!isEditing); + } + private boolean isIntersectArea(int x, int y, Rectangle rect) { return x >= rect.getX() && (x <= (rect.getX() + rect.getWidth())) && (y >= rect.getY()) && (y <= (rect.getY() + rect.getHeight())); @@ -984,6 +1023,10 @@ public class FormDesigner extends TargetComponent implements TreeSelection invalidateLayout(); } + public TopXCreators getTopXCreators() { + return topXCreators; + } + public StateModel getStateModel() { return stateModel; } @@ -1001,9 +1044,19 @@ public class FormDesigner extends TargetComponent implements TreeSelection return getComponentAt(p.x, p.y); } + /** + * 先从已选择则的组件中去找,再遍历root去找 + * */ @Override public XCreator getComponentAt(int x, int y) { - return getComponentAt(x, y, null); + 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, selectionModel.getSelection().getSelectedCreators()); + return result == null ? getComponentAt(x, y, null) : result; } @Nullable @@ -1311,6 +1364,10 @@ public class FormDesigner extends TargetComponent implements TreeSelection } } + public void paintTopCreators(Graphics clipg){ + topXCreators.paint(clipg); + } + /** * 重置组件边界 */ diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java index 26547229bb..2a8e255e83 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java @@ -84,6 +84,7 @@ public class FormDesignerUI extends ComponentUI { // 设计参数面板 repaintPara(g, paraComponent, c); } + repaintTopXCreators(g); if (designer.isDrawLineMode() && designer.getDrawLineHelper().drawLining()) { designer.getDrawLineHelper().drawAuxiliaryLine(g); @@ -445,4 +446,8 @@ public class FormDesignerUI extends ComponentUI { ComponentUtils.resetBuffer(dbcomponents); } + private void repaintTopXCreators(Graphics g){ + designer.paintTopCreators(g); + } + } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java b/designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java index 6822422b29..0695813eb4 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java @@ -24,12 +24,14 @@ import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.tree.TreePath; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.ArrayList; +import java.util.List; /** @@ -89,10 +91,13 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree /** * 刷新 */ + //TODO 太乱了,需要重写,监听器里加了监听器是什么意思,每次调用该方法都会添加一个新的监听器 public void refreshDockingView() { FormDesigner formDesigner = this.getEditingFormDesigner(); + Listlist=new ArrayList<>(); removeAll(); if (this.componentTree != null) { + componentTree.getExpandNodes(list); this.componentTree.removeAll(); } if (formDesigner == null) { @@ -100,6 +105,8 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree return; } componentTree = new ComponentTree(formDesigner); + //保证删除组件后组件树不收起 + componentTree.expandNodes(list); formDesigner.addDesignerEditListener(new DesignerEditListener() { @Override public void fireCreatorModified(DesignerEvent evt) { diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java new file mode 100644 index 0000000000..1b248a9d1b --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/BasicTopXCreator.java @@ -0,0 +1,72 @@ +package com.fr.design.mainframe.widget.topxcreator; + +import com.fr.design.designer.creator.XCreator; +import com.fr.design.mainframe.CoverReportPane; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.utils.ComponentUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; + +/** + * @Author: Yuan.Wang + * @Date: 2020/8/31 + */ +public class BasicTopXCreator extends JComponent { + private FormDesigner designer; + private XCreator creator; + + private JComponent editor; + + public BasicTopXCreator(XCreator creator) { + this.designer = WidgetPropertyPane.getInstance().getEditingFormDesigner(); + this.creator = creator; + init(); + } + + private void init() { + setOpaque(false); + setBackground(null); + setLayout(null); + setBounds(calculateBounds(creator)); + initEditor(); + if(editor!=null) { + add(editor); + } + } + + + //子类可能会重写该方法 + protected void resetSize(Rectangle bounds) { + //do nothing + } + + protected void initEditor() { + + } + + /** + * 重新设置组件大小 + * */ + public void resizeTopXCreator() { + Rectangle bounds=calculateBounds(creator); + setBounds(bounds); + resetSize(bounds); + } + + public void displayCoverPane(MouseEvent e, boolean visible) {} + + /** + * 计算显示大小 + * */ + private Rectangle calculateBounds(XCreator xCreator) { + Rectangle rect = ComponentUtils.getRelativeBounds(creator); + Rectangle bounds = new Rectangle(0, 0, creator.getWidth(), creator.getHeight()); + bounds.x += (rect.x - designer.getHorizontalScaleValue()); + bounds.y += (rect.y - designer.getVerticalScaleValue()); + return bounds; + } + +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java new file mode 100644 index 0000000000..6218fe83f7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreator.java @@ -0,0 +1,54 @@ +package com.fr.design.mainframe.widget.topxcreator; + +import com.fr.design.designer.creator.XCreator; +import com.fr.design.mainframe.CoverReportPane; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.WidgetPropertyPane; +import com.fr.design.utils.ComponentUtils; + +import java.awt.*; +import java.awt.event.MouseEvent; + +/** + * @Author: Yuan.Wang + * @Date: 2020/8/26 + */ +public class TopXCreator extends BasicTopXCreator { + + private final CoverReportPane coverPanel; + + public TopXCreator(XCreator creator) { + super(creator); + coverPanel = new CoverReportPane(); + init(); + } + + private void init() { + coverPanel.setSize(getSize()); + coverPanel.setVisible(false); + add(coverPanel); + } + + + protected void resetSize(Rectangle bounds) { + coverPanel.setSize(getSize()); + } + + public void setCoverPaneVisible(boolean visible) { + coverPanel.setVisible(visible); + } + + public void displayCoverPane(MouseEvent event, boolean visible) { + if (!visible) { + setVisible(false); + return; + } + Rectangle rect = getBounds(); + if (rect.contains(event.getX(), event.getY())) { + coverPanel.setVisible(true); + } else { + coverPanel.setVisible(false); + } + } + +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java new file mode 100644 index 0000000000..2f8ae3b406 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/topxcreator/TopXCreators.java @@ -0,0 +1,95 @@ +package com.fr.design.mainframe.widget.topxcreator; + +import com.fr.design.designer.beans.models.SelectionModel; +import com.fr.design.designer.creator.XCreator; +import com.fr.design.mainframe.FormDesigner; + +import java.awt.event.MouseEvent; + +import javax.swing.*; +import java.awt.*; + + +/** + * 需要显示顶层的组件层 + * + * @Author: Yuan.Wang + * @Date: 2020/8/25 + */ +public class TopXCreators extends JComponent { + final private FormDesigner designer; + + public TopXCreators(FormDesigner designer) { + this.designer = designer; + init(); + } + + private void init() { + setLayout(null); + setVisible(false); + setBackground(null); + setOpaque(false); + } + + /** + * 选中的组件有变化时刷新 + */ + public void refresh() { + removeAll(); + addXCreators(); + } + + @Override + public void paint(Graphics g) { + setSize(designer.getSize()); + resizeTopXCreators(); + super.paint(g); + } + + @Override + public void setVisible(boolean aFlag) { + super.setVisible(aFlag); + for (int i = 0, count = getComponentCount(); i < count; i++) { + if (getComponent(i) instanceof TopXCreator) { + TopXCreator xCreator = (TopXCreator) getComponent(i); + xCreator.setCoverPaneVisible(aFlag); + } + } + repaint(); + } + + /** + * 依据MouseEvent坐标来设置是否显示蒙层 + */ + public void displayCoverPane(MouseEvent e) { + for (int i = 0, count = getComponentCount(); i < count; i++) { + BasicTopXCreator xCreator = (BasicTopXCreator) getComponent(i); + xCreator.displayCoverPane(e, isVisible()); + } + } + + /** + * 加入被选择的组件 + */ + private void addXCreators() { + SelectionModel selectionModel = designer.getSelectionModel(); + XCreator[] xCreators = selectionModel.getSelection().getSelectedCreators(); + for (XCreator creator : xCreators) { + BasicTopXCreator topXCreator = creator.getTopXCreator(); + if (topXCreator != null) { + add(topXCreator); + } + } + } + + /** + * 更新顶层组件的位置和大小 + */ + private void resizeTopXCreators() { + for (int i = 0, count = getComponentCount(); i < count; i++) { + BasicTopXCreator topXCreator = (BasicTopXCreator) getComponent(i); + topXCreator.resizeTopXCreator(); + } + repaint(); + } +}