diff --git a/designer_base/src/com/fr/design/actions/edit/CopyAction.java b/designer_base/src/com/fr/design/actions/edit/CopyAction.java index 6f7ec1c4d..a9e685552 100644 --- a/designer_base/src/com/fr/design/actions/edit/CopyAction.java +++ b/designer_base/src/com/fr/design/actions/edit/CopyAction.java @@ -18,7 +18,7 @@ import com.fr.general.Inter; public class CopyAction extends TemplateComponentAction { public CopyAction(TargetComponent t) { super(t); - + this.setName(Inter.getLocText("M_Edit-Copy")); this.setMnemonic('C'); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); diff --git a/designer_base/src/com/fr/design/beans/location/MoveUtils.java b/designer_base/src/com/fr/design/beans/location/MoveUtils.java index d89848446..4ba477ffa 100644 --- a/designer_base/src/com/fr/design/beans/location/MoveUtils.java +++ b/designer_base/src/com/fr/design/beans/location/MoveUtils.java @@ -279,13 +279,13 @@ public class MoveUtils { } } - public static void displayForbidWindow(int x, int y) { - widgetForbidWindow.showWindow(x, y); - } +// public static void displayForbidWindow(int x, int y) { +// widgetForbidWindow.showWindow(x, y); +// } - public static void hideForbidWindow() { - widgetForbidWindow.hideWindow(); - } +// public static void hideForbidWindow() { +// widgetForbidWindow.hideWindow(); +// } /** * 吸附 @@ -319,24 +319,24 @@ public class MoveUtils { java.util.List cacheRecs = new ArrayList(); //是否存在控件重叠 - boolean isWidgetsIntersects = false; +// boolean isWidgetsIntersects = false; while (iterator.hasNext()) { Rectangle bounds = iterator.nextRectangle(); cacheRecs.add(bounds); - boolean isIntersects = operatingRectangle.intersects(bounds); +// boolean isIntersects = operatingRectangle.intersects(bounds); findX(px, bounds, left, right, width); findY(py, bounds, top, bottom, height); if(!isParameterLayout){ - if(isIntersects) { - isWidgetsIntersects = true; - } - else{ +// if(isIntersects) { +// isWidgetsIntersects = true; +// } +// else{ findEquidistantLine(bounds, left, top, height, width); - } +// } } } - showForbiddenWindow(designer, x, y, isWidgetsIntersects); + //showForbiddenWindow(designer, x, y, isWidgetsIntersects); createXAbsorptionline(px, designer, width, cacheRecs); createYAbsorptionline(py, designer, height, cacheRecs); @@ -353,18 +353,18 @@ public class MoveUtils { return sorptionPoint; } - public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){ - if (isIntersects){ - if(designer.getDesignerLocationOnScreen() != null) { - displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y); - } - designer.setWidgetsIntersected(true); - } - else{ - designer.setWidgetsIntersected(false); - hideForbidWindow(); - } - } +// public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){ +// if (isIntersects){ +// if(designer.getDesignerLocationOnScreen() != null) { +// displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y); +// } +// designer.setWidgetsIntersected(true); +// } +// else{ +// designer.setWidgetsIntersected(false); +// hideForbidWindow(); +// } +// } private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List cacheRecs) { Absorptionline line = null; diff --git a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java b/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java index acf934e25..9ff080afb 100644 --- a/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java +++ b/designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java @@ -17,32 +17,32 @@ public class WidgetForbidWindow extends JWindow { private UIButton promptButton = new UIButton(Inter.getLocText("FR-Designer_Forbid_Widgets_Intersects"), BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH)); - /** - * 构造函数 - */ - public WidgetForbidWindow() { - this.add(promptButton); - - this.setSize(WIDTH, HEIGHT); - } - - /** - * 在指定位置显示窗口, 默认将window的中心点放到指定位置上 - * - * @param x x坐标 - * @param y y坐标 - * - */ - public void showWindow(int x, int y){ - this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); - this.setVisible(true); - } - - /** - * 隐藏当前窗口 - * - */ - public void hideWindow(){ - this.setVisible(false); - } +// /** +// * 构造函数 +// */ +// public WidgetForbidWindow() { +// this.add(promptButton); +// +// this.setSize(WIDTH, HEIGHT); +// } +// +// /** +// * 在指定位置显示窗口, 默认将window的中心点放到指定位置上 +// * +// * @param x x坐标 +// * @param y y坐标 +// * +// */ +// public void showWindow(int x, int y){ +// this.setLocation(x - WIDTH / 2, y - HEIGHT / 2); +// this.setVisible(true); +// } +// +// /** +// * 隐藏当前窗口 +// * +// */ +// public void hideWindow(){ +// this.setVisible(false); +// } } diff --git a/designer_base/src/com/fr/design/mainframe/BaseJForm.java b/designer_base/src/com/fr/design/mainframe/BaseJForm.java index c0fd09f17..a666af38b 100644 --- a/designer_base/src/com/fr/design/mainframe/BaseJForm.java +++ b/designer_base/src/com/fr/design/mainframe/BaseJForm.java @@ -1 +1 @@ -package com.fr.design.mainframe; import javax.swing.JComponent; import com.fr.form.FormElementCaseContainerProvider; /** * Author : Shockway * Date: 13-7-15 * Time: 上午10:28 */ public interface BaseJForm extends JTemplateProvider{ public static final String XML_TAG = "JForm"; public static final int FORM_TAB = 0; public static final int ELEMENTCASE_TAB = 1; public static final int ELEMENTCASE_CHANGE_TAB = 2; /** * 刷新所有控件 */ public void refreshAllNameWidgets(); /** * 刷新参数 */ public void populateParameter(); /** * 刷新选中的控件 */ public void refreshSelectedWidget(); /** * 获取当前的Target */ public Object getTarget(); /** * 执行撤销 * * @param o 之前保存的状态 */ public void applyUndoState4Form(BaseUndoState o); /** * 获取当前编辑的组件 */ public JComponent getEditingPane(); /** * 只在Form和ElementCase之间切换 * @param index 切换位置 */ public void tabChanged(int index); /** * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 * @param index 切换位置 * @param ecContainer ElementCase所在container */ public void tabChanged(int index, FormElementCaseContainerProvider ecContainer); } \ No newline at end of file +package com.fr.design.mainframe; import javax.swing.JComponent; import com.fr.form.FormElementCaseContainerProvider; /** * Author : Shockway * Date: 13-7-15 * Time: 上午10:28 */ public interface BaseJForm extends JTemplateProvider { String XML_TAG = "JForm"; int FORM_TAB = 0; int ELEMENTCASE_TAB = 1; int ELEMENTCASE_CHANGE_TAB = 2; /** * 刷新所有控件 */ void refreshAllNameWidgets(); /** * 刷新参数 */ void populateParameter(); /** * 刷新选中的控件 */ void refreshSelectedWidget(); /** * 获取当前的Target */ Object getTarget(); /** * 执行撤销 * * @param o 之前保存的状态 */ void applyUndoState4Form(BaseUndoState o); /** * 获取当前编辑的组件 */ JComponent getEditingPane(); /** * 只在Form和ElementCase之间切换 * * @param index 切换位置 */ void tabChanged(int index); /** * 在Form和ElementCase, 以及ElementCase和ElementCase之间切换 * * @param index 切换位置 * @param ecContainer ElementCase所在container */ void tabChanged(int index, FormElementCaseContainerProvider ecContainer); } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java index 6c85ce214..ada075aeb 100644 --- a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java +++ b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java @@ -12,52 +12,52 @@ public interface ToolBarMenuDockPlus { * * @return 工具 */ - public ToolBarDef[] toolbars4Target(); + ToolBarDef[] toolbars4Target(); /** * 文件菜单的子菜单 * * @return 子菜单 */ - public ShortCut[] shortcut4FileMenu(); + ShortCut[] shortcut4FileMenu(); /** * 目标的菜单 * * @return 菜单 */ - public MenuDef[] menus4Target(); + MenuDef[] menus4Target(); /** * 表单的工具栏 * * @return 表单工具栏 */ - public JPanel[] toolbarPanes4Form(); + JPanel[] toolbarPanes4Form(); /** * 表单的工具按钮 * * @return 工具按钮 */ - public JComponent[] toolBarButton4Form(); + JComponent[] toolBarButton4Form(); /** * 权限细粒度状态下的工具面板 * * @return 工具面板 */ - public JComponent toolBar4Authority(); + JComponent toolBar4Authority(); - public int getMenuState(); + int getMenuState(); - public int getToolBarHeight(); + int getToolBarHeight(); /** * 导出菜单的子菜单 ,目前用于图表设计器 * * @return 子菜单 */ - public ShortCut[] shortcut4ExportMenu(); - + ShortCut[] shortcut4ExportMenu(); + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java b/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java index 2e2743048..a812238b7 100644 --- a/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java +++ b/designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java @@ -1 +1 @@ -package com.fr.design.parameter; import com.fr.base.Parameter; import com.fr.base.parameter.ParameterUI; import com.fr.design.mainframe.AuthorityEditPane; import javax.swing.*; import java.awt.*; /** * 参数设计界面接口 */ public interface ParameterDesignerProvider { public void addListener(ParaDefinitePane paraDefinitePane); public Component createWrapper(); public void setDesignHeight(int height); public Dimension getDesignSize(); public Dimension getPreferredSize(); public void populate(ParameterUI p); public void refreshAllNameWidgets(); public void refresh4TableData(String oldName, String newName); public void refreshParameter(ParaDefinitePane paraDefinitePane); public boolean isWithQueryButton(); public java.util.List getAllXCreatorNameList(); public boolean isWithoutParaXCreator(Parameter[] ps); public boolean isBlank(); public ParameterUI getParaTarget(); public boolean addingParameter2Editor(Parameter parameter, int index); public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); public JPanel[] toolbarPanes4Form(); public JComponent[] toolBarButton4Form(); public void initBeforeUpEdit(); public void populateParameterPropertyPane(ParaDefinitePane p); public void initWidgetToolbarPane(); public AuthorityEditPane getAuthorityEditPane(); public JPanel getEastUpPane(); public JPanel getEastDownPane(); public boolean isSupportAuthority(); public void removeSelection(); public ParameterBridge getParaComponent(); } \ No newline at end of file +package com.fr.design.parameter; import com.fr.base.Parameter; import com.fr.base.parameter.ParameterUI; import com.fr.design.mainframe.AuthorityEditPane; import javax.swing.*; import java.awt.*; /** * 参数设计界面接口 */ public interface ParameterDesignerProvider { void addListener(ParaDefinitePane paraDefinitePane); Component createWrapper(); void setDesignHeight(int height); Dimension getDesignSize(); Dimension getPreferredSize(); void populate(ParameterUI p); void refreshAllNameWidgets(); void refresh4TableData(String oldName, String newName); void refreshParameter(ParaDefinitePane paraDefinitePane); boolean isWithQueryButton(); java.util.List getAllXCreatorNameList(); boolean isWithoutParaXCreator(Parameter[] ps); boolean isBlank(); ParameterUI getParaTarget(); boolean addingParameter2Editor(Parameter parameter, int index); boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); JPanel[] toolbarPanes4Form(); JComponent[] toolBarButton4Form(); void initBeforeUpEdit(); void populateParameterPropertyPane(ParaDefinitePane p); void initWidgetToolbarPane(); AuthorityEditPane getAuthorityEditPane(); JPanel getEastUpPane(); JPanel getEastDownPane(); boolean isSupportAuthority(); void removeSelection(); ParameterBridge getParaComponent(); } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java b/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java index e32ece18e..de36cde9b 100644 --- a/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java +++ b/designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java @@ -11,21 +11,21 @@ import com.fr.design.mainframe.FormDesigner; public class CopyAction extends FormEditAction { - public CopyAction(FormDesigner t) { - super(t); - this.setName(Inter.getLocText("M_Edit-Copy")); - this.setMnemonic('C'); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); - this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); - } + public CopyAction(FormDesigner t) { + super(t); + this.setName(Inter.getLocText("M_Edit-Copy")); + this.setMnemonic('C'); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); + this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); + } - @Override - public boolean executeActionReturnUndoRecordNeeded() { - FormDesigner tc = getEditingComponent(); - if (tc != null) { - tc.copy(); - } - return false; - } + @Override + public boolean executeActionReturnUndoRecordNeeded() { + FormDesigner tc = getEditingComponent(); + if (tc != null) { + tc.copy(); + } + return false; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java index d5232d26a..54d6abab4 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java @@ -23,32 +23,35 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { this.container = container; this.layout = container.getLayout(); } - + /** * 是否使用控件备份大小 + * * @param xCreator 控件 * @return 所在容器相同,且支持备份的话返回true */ public boolean whetherUseBackupSize(XCreator xCreator) { - Class clazz = container.getClass(); - Class bkClazz = null; - if(xCreator.getBackupParent() != null) { - bkClazz = xCreator.getBackupParent().getClass(); - } - return ComparatorUtils.equals(bkClazz, clazz) - && supportBackupSize(); - } - + Class clazz = container.getClass(); + Class bkClazz = null; + if (xCreator.getBackupParent() != null) { + bkClazz = xCreator.getBackupParent().getClass(); + } + return ComparatorUtils.equals(bkClazz, clazz) + && supportBackupSize(); + } + /** * 是否支持用备份大小 + * * @return 否 */ public boolean supportBackupSize() { - return false; + return false; } /** * 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 + * * @param creator 组件 */ public void fix(XCreator creator) { @@ -56,48 +59,52 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { /** * 显示parent的字组件child,解决CardLayout中显示某个非显示组件的特殊情况 + * * @param child 组件 */ @Override public void showComponent(XCreator child) { - child.setVisible(true); + child.setVisible(true); } - + /** * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 + * * @param creator 被添加的新组件 - * @param x 添加的位置x,该位置是相对于container的 - * @param y 添加的位置y,该位置是相对于container的 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 * @return 是否添加成功,成功返回true,否则false */ @Override - public boolean addBean(XCreator creator, int x, int y) { - if (!accept(creator, x, y)) { - return false; - } - addComp(creator, x, y); - ((XWidgetCreator) creator).recalculateChildrenSize(); - return true; - } - + public boolean addBean(XCreator creator, int x, int y) { + if (!accept(creator, x, y)) { + return false; + } + addComp(creator, x, y); + ((XWidgetCreator) creator).recalculateChildrenSize(); + return true; + } + /** * 删除组件 - * @param creator 组件 - * @param initWidth 组件之前宽度 - * @param initHeight 组件之前高度 + * + * @param creator 组件 + * @param creatorWidth + * @param creatorHeight */ public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) { - delete(creator, creatorWidth, creatorHeight); + delete(creator, creatorWidth, creatorHeight); } - + protected void delete(XCreator creator, int creatorWidth, int creatorHeight) { } - + protected abstract void addComp(XCreator creator, int x, int y); /** * 增加下一个组件 + * * @param dragged 组件 */ @Override @@ -108,8 +115,9 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { /** * 目标控件位置插入组件 + * * @param target 目标 - * @param added 增加组件 + * @param added 增加组件 */ @Override public void addBefore(XCreator target, XCreator added) { @@ -126,8 +134,9 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { /** * 插在目标组件后面 + * * @param target 目标 - * @param added 增加组件 + * @param added 增加组件 */ @Override public void addAfter(XCreator target, XCreator added) { @@ -147,14 +156,15 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { LayoutUtils.layoutRootContainer(container); } - + @Override public HoverPainter getPainter() { return new NullPainter(container); } - + /** * 是否能接收更多的组件 + * * @return 能则返回true */ @Override @@ -171,4 +181,9 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter { public GroupModel getLayoutProperties() { return null; } + + + public XLayoutContainer getContainer() { + return this.container; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index 140204e75..58c07b045 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -17,338 +17,347 @@ import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { - //是不是添加到父容器上 - private boolean isAdd2ParentLayout = false; - private HoverPainter painter; + //是不是添加到父容器上 + private boolean isAdd2ParentLayout = false; + private HoverPainter painter; public FRAbsoluteLayoutAdapter(XLayoutContainer container) { super(container); - painter = new FRAbsoluteLayoutPainter(container); - initMinSize(); + painter = new FRAbsoluteLayoutPainter(container); + initMinSize(); } - private void initMinSize() { - XWAbsoluteLayout layout = (XWAbsoluteLayout) container; - minWidth = layout.getActualMinWidth(); - minHeight = layout.getActualMinHeight(); - actualVal = layout.getAcualInterval(); - margin = layout.toData().getMargin(); - } + private void initMinSize() { + XWAbsoluteLayout layout = (XWAbsoluteLayout) container; + minWidth = layout.getActualMinWidth(); + minHeight = layout.getActualMinHeight(); + actualVal = layout.getAcualInterval(); + margin = layout.toData().getMargin(); + } + + @Override + public HoverPainter getPainter() { + return painter; + } - @Override - public HoverPainter getPainter() { - return painter; - } - /** * 是否能在指定位置添加组件 + * * @param creator 组件 - * @param x 坐标x - * @param y 坐标y + * @param x 坐标x + * @param y 坐标y * @return 能则返回true */ - //这个地方的逻辑非常复杂, - // 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围, - // 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套) - // 3.当前绝对布局可编辑,那么控件添加 + //这个地方的逻辑非常复杂, + // 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围, + // 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套) + // 3.当前绝对布局可编辑,那么控件添加 @Override - public boolean accept(XCreator creator, int x, int y) { - Component comp = container.getComponentAt(x, y); - //布局控件要先判断是不是可编辑 - //可以编辑,按原有逻辑判断 - //不可编辑,当成一整个控件处理 - if (comp == null){ - return false; - } - //参数面板内的组件不允许拖往绝对布局中 - if (creator.getParent() != null && ((XCreator)creator.getParent()).acceptType(XWParameterLayout.class)){ - Rectangle rec = creator.getBounds(); - rec.y = creator.getParent().getHeight() - rec.height; - creator.setBounds(rec); - return false; - } - //判断下组件能不能拖入绝对布局 - if (!creator.canEnterIntoAbsolutePane()){ - return false; - } - XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout(); - if(topLayout != null){ - if (topLayout.isEditable()){ - return topLayoutAccept(creator, x, y, topLayout); - } - //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 - else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { - return false; - } - else { - return acceptWidget(creator, x, y); - } - } - else{ - FRLogger.getLogger().error("top layout is null!"); - } - - return false; - } + public boolean accept(XCreator creator, int x, int y) { + Component comp = container.getComponentAt(x, y); + //布局控件要先判断是不是可编辑 + //可以编辑,按原有逻辑判断 + //不可编辑,当成一整个控件处理 + if (comp == null) { + return false; + } + //参数面板内的组件不允许拖往绝对布局中 + if (creator.getParent() != null && ((XCreator) creator.getParent()).acceptType(XWParameterLayout.class)) { + Rectangle rec = creator.getBounds(); + rec.y = creator.getParent().getHeight() - rec.height; + creator.setBounds(rec); + return false; + } + //判断组件能不能拖入绝对布局 + if (!creator.canEnterIntoAbsolutePane()) { + return false; + } + XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout(); + if (topLayout != null) { + if (topLayout.isEditable()) { + return topLayoutAccept(creator, x, y, topLayout); + } + //绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局 + else if (((XLayoutContainer) topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) { + return false; + } else { + return acceptWidget(creator, x, y); + } + } else { + FRLogger.getLogger().error("top layout is null!"); + } - //toplayout假如可以编辑的话就往里面添加组件 - private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { - //判断有没有和当前控件重叠 - //先计算当前控件的位置 - int creatorX, creatorY; - if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { + return false; + } + //topLayout假如可以编辑的话就往里面添加组件 + private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) { + //允许组件重叠,可以不判断有没有和当前控件重叠 + //先计算当前控件的位置 + int creatorX, creatorY; + if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); creatorX = creatorRectangle.x; creatorY = creatorRectangle.y; } else { + //这边计算得到的组件其实位置是正确的, + //因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的, + // 例如高度为21,那么就是+10-10; + // 高度为20,那么就是+10-10; 没区别 int w = creator.getWidth() / 2; int h = creator.getHeight() / 2; creatorX = x - w; creatorY = y - h; } - //再判断和布局中其他控件重叠 - Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight()); - WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData(); - for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) { - BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i); - Rectangle rectangle = temp.getBounds(); - if (curRec.intersects(rectangle)){ - return false; - } - } - if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { + //frm 组件复用允许组件重叠 + //无须再判断和布局中其他控件重叠 + //Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight()); + //WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout) topLayout.toData(); + //for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) { + //BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i); + //Rectangle rectangle = temp.getBounds(); + //if (curRec.intersects(rectangle)) { + //允许组件重叠 + //return false; + //} + //} + if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) { return false; } - if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()){ + if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()) { return false; } - return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() + return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() && creator.getWidth() <= container.getWidth(); - } + } - /** - * 判断是否鼠标在组件的三等分区域,如果组件在布局管理器中间,上下左右都可能会三等分 - * @param parentComp 鼠标所在区域的组件 - * @param x 坐标x - * @param y 坐标y - * @return 是则返回true - */ - public boolean isTrisectionArea(Component parentComp, int x, int y) { - XCreator creator = (XCreator)parentComp; - trisectAreaDirect = 0; - if (container.getComponentCount()<=1) { - return false; - } - int maxWidth = parentComp.getWidth(); - int maxHeight = parentComp.getHeight(); - int xL = parentComp.getX(); - int yL = parentComp.getY(); - // 组件宽高的十分之一和默认值取大 - int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); - int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH); - if(yyL+maxHeight-minRangeHeight) { - // 在组件下侧三等分 - trisectAreaDirect = COMP_BOTTOM; - } else if (xxL+maxWidth-minRangeWidth) { - // 在组件右侧三等分 - trisectAreaDirect = COMP_RIGHT; - } - // tab布局的边界特殊处理,不进行三等分 - if(!creator.getTargetChildrenList().isEmpty()){ - return false; - } + /** + * 判断是否鼠标在组件的三等分区域,如果组件在布局管理器中间,上下左右都可能会三等分 + * + * @param parentComp 鼠标所在区域的组件 + * @param x 坐标x + * @param y 坐标y + * @return 是则返回true + */ + public boolean isTrisectionArea(Component parentComp, int x, int y) { + XCreator creator = (XCreator) parentComp; + trisectAreaDirect = 0; + if (container.getComponentCount() <= 1) { + return false; + } + int maxWidth = parentComp.getWidth(); + int maxHeight = parentComp.getHeight(); + int xL = parentComp.getX(); + int yL = parentComp.getY(); + // 组件宽高的十分之一和默认值取大 + int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); + int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH); + if (y < yL + minRangeHeight) { + // 在组件上侧三等分 + trisectAreaDirect = COMP_TOP; + } else if (y > yL + maxHeight - minRangeHeight) { + // 在组件下侧三等分 + trisectAreaDirect = COMP_BOTTOM; + } else if (x < xL + minRangeWidth) { + // 在组件左侧三等分 + trisectAreaDirect = COMP_LEFT; + } else if (x > xL + maxWidth - minRangeWidth) { + // 在组件右侧三等分 + trisectAreaDirect = COMP_RIGHT; + } + // tab布局的边界特殊处理,不进行三等分 + if (!creator.getTargetChildrenList().isEmpty()) { + return false; + } - return !ComparatorUtils.equals(trisectAreaDirect, 0); - } + return !ComparatorUtils.equals(trisectAreaDirect, 0); + } - //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 - private boolean acceptWidget(XCreator creator, int x, int y){ - isFindRelatedComps = false; - //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 - Component comp = container.getComponentAt(x, y); - boolean isMatchEdge = false; - //如果当前处于边缘地带, 那么就把他贴到父容器上 - XLayoutContainer parent = container.findNearestFit(); - container = parent != null ? parent : container; - isAdd2ParentLayout = true; + //当前绝对布局不可编辑,就当成一个控件,组件添加在周围 + private boolean acceptWidget(XCreator creator, int x, int y) { + isFindRelatedComps = false; + //拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域 + Component comp = container.getComponentAt(x, y); + boolean isMatchEdge = false; + //如果当前处于边缘地带, 那么就把他贴到父容器上 + XLayoutContainer parent = container.findNearestFit(); + container = parent != null ? parent : container; + isAdd2ParentLayout = true; - int componentHeight = comp.getHeight(); - int componentWidth = comp.getWidth(); - //上半部分高度 - int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); - //下半部分高度 - int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY(); + int componentHeight = comp.getHeight(); + int componentWidth = comp.getWidth(); + //上半部分高度 + int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY(); + //下半部分高度 + int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY(); - if (isCrossPointArea(comp, x, y)) { - return canAcceptWhileCrossPoint(comp, x, y); - } + if (isCrossPointArea(comp, x, y)) { + return canAcceptWhileCrossPoint(comp, x, y); + } - if (isTrisectionArea(comp, x, y)) { - return canAcceptWhileTrisection(comp, x, y); - } + if (isTrisectionArea(comp, x, y)) { + return canAcceptWhileTrisection(comp, x, y); + } - boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; - boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; - return y > upHeight && y < downHeight ? horizonValid : verticalValid; - } + boolean horizonValid = componentWidth >= minWidth * 2 + actualVal; + boolean verticalValid = componentHeight >= minHeight * 2 + actualVal; + return y > upHeight && y < downHeight ? horizonValid : verticalValid; + } - /** - * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 - * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 - * - * @param creator 被添加的新组件 - * @param x 添加的位置x,该位置是相对于container的 - * @param y 添加的位置y,该位置是相对于container的 - * @return 是否添加成功,成功返回true,否则false - */ - @Override - public boolean addBean(XCreator creator, int x, int y) { - Rectangle rect = ComponentUtils.getRelativeBounds(container); + /** + * 组件的ComponentAdapter在添加组件时,如果发现布局管理器不为空,会继而调用该布局管理器的 + * addComp方法来完成组件的具体添加。在该方法内,布局管理器可以提供额外的功能。 + * + * @param creator 被添加的新组件 + * @param x 添加的位置x,该位置是相对于container的 + * @param y 添加的位置y,该位置是相对于container的 + * @return 是否添加成功,成功返回true,否则false + */ + @Override + public boolean addBean(XCreator creator, int x, int y) { + Rectangle rect = ComponentUtils.getRelativeBounds(container); - int posX = x + rect.x; - int posY = y + rect.y; - if (!accept(creator, x, y)) { - return false; - } - addComp(creator, posX, posY); - ((XWidgetCreator) creator).recalculateChildrenSize(); - return true; - } + int posX = x + rect.x; + int posY = y + rect.y; + if (!accept(creator, x, y)) { + return false; + } + addComp(creator, posX, posY); + ((XWidgetCreator) creator).recalculateChildrenSize(); + return true; + } - @Override - protected void addComp(XCreator creator, int x, int y) { - if(!isAdd2ParentLayout) { - Rectangle r = ComponentUtils.getRelativeBounds(container); - x = x - r.x; - y = y - r.y; - if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { + @Override + protected void addComp(XCreator creator, int x, int y) { + if (!isAdd2ParentLayout) { + Rectangle r = ComponentUtils.getRelativeBounds(container); + x = x - r.x; + y = y - r.y; + if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { - Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); - x = creatorRectangle.x - r.x; - y = creatorRectangle.y - r.y; - } else { - int w = creator.getWidth() / 2; - int h = creator.getHeight() / 2; - x = x - w; - y = y - h; - } - fix(creator, x, y); + Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator); + x = creatorRectangle.x - r.x; + y = creatorRectangle.y - r.y; + } else { + int w = creator.getWidth() / 2; + int h = creator.getHeight() / 2; + x = x - w; + y = y - h; + } + fix(creator, x, y); - if (creator.hasTitleStyle()) { - addParentCreator(creator); - } else { - container.add(creator, creator.toData().getWidgetName()); - } - XWAbsoluteLayout layout = (XWAbsoluteLayout) container; - layout.updateBoundsWidget(creator); - updateCreatorBackBound(); - LayoutUtils.layoutRootContainer(container); - }else{ - fixAbsolute(creator, x, y); - if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { - addParentCreator(creator); - } else { - container.add(creator, creator.toData().getWidgetName()); - } - XWFitLayout layout = (XWFitLayout) container; - // 更新对应的BoundsWidget - layout.updateBoundsWidget(); - updateCreatorBackBound(); - } - } + if (creator.hasTitleStyle()) { + addParentCreator(creator); + } else { + container.add(creator, creator.toData().getWidgetName()); + } + XWAbsoluteLayout layout = (XWAbsoluteLayout) container; + layout.updateBoundsWidget(creator); + updateCreatorBackBound(); + LayoutUtils.layoutRootContainer(container); + } else { + fixAbsolute(creator, x, y); + if (creator.shouldScaleCreator() || creator.hasTitleStyle()) { + addParentCreator(creator); + } else { + container.add(creator, creator.toData().getWidgetName()); + } + XWFitLayout layout = (XWFitLayout) container; + // 更新对应的BoundsWidget + layout.updateBoundsWidget(); + updateCreatorBackBound(); + } + } - private void updateCreatorBackBound() { - for (int i=0,size=container.getComponentCount(); i container.getWidth()) { - width = container.getWidth() - x; - } + public void fix(XCreator creator, int x, int y) { + int height = creator.getHeight(); + int width = creator.getWidth(); + if (x < 0) { + width += x; + x = 0; + } else if (x + creator.getWidth() > container.getWidth()) { + width = container.getWidth() - x; + } - if (y < 0) { - height += y; - y = 0; - } else if (y + creator.getHeight() > container.getHeight()) { - height = container.getHeight() - y; - } + if (y < 0) { + height += y; + y = 0; + } else if (y + creator.getHeight() > container.getHeight()) { + height = container.getHeight() - y; + } - creator.setBounds(x, y, width, height); + creator.setBounds(x, y, width, height); } @Override public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { - return new BoundsGroupModel((XWAbsoluteLayout)container, creator); + return new BoundsGroupModel((XWAbsoluteLayout) container, creator); } - @Override - public GroupModel getLayoutProperties() { - XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; - return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); - } + @Override + public GroupModel getLayoutProperties() { + XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container; + return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java index a2a57c4ff..161fe6bd5 100644 --- a/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java @@ -69,7 +69,7 @@ public abstract class AccessDirection implements Direction { boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false; WAbsoluteLayout layout =getLayout(designer); FormSelection selection = designer.getSelectionModel().getSelection(); - boolean isWidgetsIntersect = false; +// boolean isWidgetsIntersect = false; for (int i = 0, count = layout.getWidgetCount(); i < count; i++) { BoundsWidget temp = (BoundsWidget) layout.getWidget(i); if (!temp.isVisible() || selection.contains(temp.getWidget())) { @@ -105,13 +105,13 @@ public abstract class AccessDirection implements Direction { break; } - if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){ - isWidgetsIntersect = true; - } - } - processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); - setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point); - } +// if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)) { +// isWidgetsIntersect = true; +// } + } +// processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect); + setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point); + } private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) { designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); @@ -131,18 +131,18 @@ public abstract class AccessDirection implements Direction { return relativeRec; } - private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){ - if(isIntersects){ - if(designer.getLocationOnScreen() != null) { - MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y); - } - designer.setWidgetsIntersect(true); - } - else{ - MoveUtils.hideForbidWindow(); - designer.setWidgetsIntersect(false); - } - } +// private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){ +// if(isIntersects){ +// if(designer.getLocationOnScreen() != null) { +// MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y); +// } +// designer.setWidgetsIntersect(true); +// } +// else{ +// MoveUtils.hideForbidWindow(); +// designer.setWidgetsIntersect(false); +// } +// } private WAbsoluteLayout getLayout(final FormDesigner designer){ XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( diff --git a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java index 834b28d74..75bacfff5 100644 --- a/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java @@ -11,11 +11,7 @@ import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.location.Direction; import com.fr.design.designer.beans.location.Location; -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.XWFitLayout; -import com.fr.design.designer.creator.XWParameterLayout; +import com.fr.design.designer.creator.*; import com.fr.design.form.util.XCreatorConstants; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormSelection; @@ -27,302 +23,342 @@ import com.fr.stable.ArrayUtils; * 该model保存当前选择的组件和剪切版信息 */ public class SelectionModel { + //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 - private static FormSelection CLIP_BOARD = new FormSelection(); - private FormDesigner designer; - private FormSelection selection; - private Rectangle hotspot_bounds; + private static FormSelection CLIP_BOARD = new FormSelection(); + private FormDesigner designer; + private FormSelection selection; + private Rectangle hotspot_bounds; - public SelectionModel(FormDesigner designer) { - this.designer = designer; - selection = new FormSelection(); - } + public SelectionModel(FormDesigner designer) { + this.designer = designer; + selection = new FormSelection(); + } - /** - * 重置。清空formSelction以及选择区域 - */ - public void reset() { - selection.reset(); - hotspot_bounds = null; - } - - /** - * formSelction是否为空 - * @return 是否为空 - */ - public static boolean isEmpty(){ - return CLIP_BOARD.isEmpty(); - } + /** + * 重置。清空formSelction以及选择区域 + */ + public void reset() { + selection.reset(); + hotspot_bounds = null; + } - /** - * 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 - * @param e 鼠标事件 - */ - public void selectACreatorAtMouseEvent(MouseEvent e) { - if (!e.isControlDown() && !e.isShiftDown()) { - // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 - selection.reset(); - } + /** + * formSelction是否为空 + * + * @return 是否为空 + */ + public static boolean isEmpty() { + return CLIP_BOARD.isEmpty(); + } - // 获取e所在的组件 - XCreator comp = designer.getComponentAt(e); + /** + * 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 + * + * @param e 鼠标事件 + */ + public void selectACreatorAtMouseEvent(MouseEvent e) { + if (!e.isControlDown() && !e.isShiftDown()) { + // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 + selection.reset(); + } - //布局组件的顶层布局如不可编辑,要获取其顶层布局 - XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); - if(topLayout != null && !topLayout.isEditable()){ - comp = topLayout; - } + // 获取e所在的组件 + XCreator comp = designer.getComponentAt(e); - // 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的 - if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { - XCreator parentContainer = (XCreator) comp.getParent(); - comp = parentContainer.isDedicateContainer() ? parentContainer : comp; - } - if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { - designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); - designer.repaint(); - } - } + //布局组件的顶层布局如不可编辑,要获取其顶层布局 + XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); + if (topLayout != null && !topLayout.isEditable()) { + comp = topLayout; + } - /** - * 将所选组件剪切到剪切板上 - */ - public void cutSelectedCreator2ClipBoard() { - if (hasSelectionComponent()) { - selection.cut2ClipBoard(CLIP_BOARD); - designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); - designer.repaint(); - } - } + // 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的 + if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { + XCreator parentContainer = (XCreator) comp.getParent(); + comp = parentContainer.isDedicateContainer() ? parentContainer : comp; + } + if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { + designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); + designer.repaint(); + } + } - /** - * 复制当前选中的组件到剪切板 - */ - public void copySelectedCreator2ClipBoard() { - if (!selection.isEmpty()) { - selection.copy2ClipBoard(CLIP_BOARD); - } - } + /** + * 将所选组件剪切到剪切板上 + */ + public void cutSelectedCreator2ClipBoard() { + if (hasSelectionComponent()) { + selection.cut2ClipBoard(CLIP_BOARD); + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); + designer.repaint(); + } + } - /** - * 从剪切板粘帖组件 - * @return 否 - */ - public boolean pasteFromClipBoard() { - if (!CLIP_BOARD.isEmpty()) { - XLayoutContainer parent = null; - if (!hasSelectionComponent()) { - FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),CLIP_BOARD, DELTA_X_Y, DELTA_X_Y); - } else { - parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); - if (parent != null) { - Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, parent,CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); - } - } - } else { - Toolkit.getDefaultToolkit().beep(); - } - return false; - } + /** + * 复制当前选中的组件到剪切板 + */ + public void copySelectedCreator2ClipBoard() { + if (!selection.isEmpty()) { + selection.copy2ClipBoard(CLIP_BOARD); + } + } - public FormSelection getSelection() { - return selection; - } + /** + * 从剪切板粘帖组件 + * + * @return 否 + */ + public boolean pasteFromClipBoard() { + if (!CLIP_BOARD.isEmpty()) { + XLayoutContainer parent = null; + if (!hasSelectionComponent()) { + if (designer.getClass().equals(FormDesigner.class)) { + //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 + //当前选择的就是编辑器表层 + FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), + CLIP_BOARD, + DELTA_X_Y, + DELTA_X_Y); + } else { + //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 + //使用selection.getSelectedCreator()也应该是可以获取到的。 + FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), + CLIP_BOARD, + DELTA_X_Y, + DELTA_X_Y); + } + } else { + //获取到编辑器的表层容器(已选的组件的父容器就是表层容器) + parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); + if (parent != null) { + Rectangle rec = selection.getSelctionBounds(); + FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + } + } + } else { + Toolkit.getDefaultToolkit().beep(); + } + return false; + } + + public FormSelection getSelection() { + return selection; + } - /** - * 删除当前所有选择的组件 - */ - public void deleteSelection() { - XCreator[] roots = selection.getSelectedCreators(); + /** + * 删除当前所有选择的组件 + */ + public void deleteSelection() { + XCreator[] roots = selection.getSelectedCreators(); - if (roots.length > 0) { - for (XCreator creator : roots) { - if(creator.acceptType(XWParameterLayout.class)){ + if (roots.length > 0) { + for (XCreator creator : roots) { + if (creator.acceptType(XWParameterLayout.class)) { designer.removeParaComponent(); } - - removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); - creator.removeAll(); - // 清除被选中的组件 + + removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); + creator.removeAll(); + // 清除被选中的组件 selection.reset(); - } + } setSelectedCreator(designer.getRootComponent()); - // 触发事件 - designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); - designer.repaint(); - } - } + // 触发事件 + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); + designer.repaint(); + } + } - /** - * 从选择组件中删除某组件 - * - * @param creator 组件 - * @param creatorWidth 组件之前宽度 - * @param creatorHeight 组件之前高度 - */ - public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { - selection.removeCreator(creator); - removeCreatorFromContainer(creator, creatorWidth, creatorHeight); - designer.repaint(); - } + /** + * 从选择组件中删除某组件 + * + * @param creator 组件 + * @param creatorWidth 组件之前宽度 + * @param creatorHeight 组件之前高度 + */ + public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { + selection.removeCreator(creator); + removeCreatorFromContainer(creator, creatorWidth, creatorHeight); + designer.repaint(); + } - /** - * 设置选择区域 - */ - public void setHotspotBounds(Rectangle rect) { - hotspot_bounds = rect; - } + /** + * 设置选择区域 + */ + public void setHotspotBounds(Rectangle rect) { + hotspot_bounds = rect; + } - /** - * 获得当前选择区域 - */ - public Rectangle getHotspotBounds() { - return hotspot_bounds; - } + /** + * 获得当前选择区域 + */ + public Rectangle getHotspotBounds() { + return hotspot_bounds; + } - private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { - XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); - if (parent == null) { - return; - } - boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); - if (parent.acceptType(XWFitLayout.class) && changeCreator) { - creator = (XCreator) creator.getParent(); - } - parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); - // 删除其根组件,同时就删除了同时被选择的叶子组件 - parent.remove(creator); - LayoutManager layout = parent.getLayout(); + private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { + XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); + if (parent == null) { + return; + } + boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); + if (parent.acceptType(XWFitLayout.class) && changeCreator) { + creator = (XCreator) creator.getParent(); + } + parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); + // 删除其根组件,同时就删除了同时被选择的叶子组件 + parent.remove(creator); + LayoutManager layout = parent.getLayout(); - if (layout != null) { - // 刷新组件容器的布局 - LayoutUtils.layoutContainer(parent); - } - } + if (layout != null) { + // 刷新组件容器的布局 + LayoutUtils.layoutContainer(parent); + } + } - /** - * 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 - * @return 是则返回true - */ - public boolean hasSelectionComponent() { - return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null; - } + /** + * 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 + * + * @return 是则返回true + * yaoh.wu 不应该通过判断是否是最底层容器来判断是否选择了组件 + * 而是应该判断选择的容器是否是编辑器的最表层容器,也就是点击空白地方选择的容器 + * 但是直接判断选择的容器是否是编辑器最表层类型又会引发拖动时选不上的情况, + * 因此通过判断父容器来实现 + *

+ * 举例:frm组件复用 绝对布局情况下,不选择时有三层容器: + * 底层@see {@link com.fr.design.designer.creator.XWBorderLayout} + * 中层@see {@link XWFitLayout} + * 表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout} + *

+ * 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout}, + * 其他两层不是靠添加组件就可以编辑的。 + */ + public boolean hasSelectionComponent() { + if (designer.getClass().equals(FormDesigner.class)) { + //frm组件复用选择 + return selection.getSelectedCreator() != null && !(selection.getSelectedCreator().getParent() instanceof + XWFitLayout); + } else { + //cpt本地组件复用 + return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null; + } + } - /** - * 移动组件至指定位置 - * @param x 坐标x - * @param y 坐标y - */ - public void move(int x, int y) { - for (XCreator creator : selection.getSelectedCreators()) { - creator.setLocation(creator.getX() + x, creator.getY() + y); - LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); - if (layoutAdapter != null) { - layoutAdapter.fix(creator); - } - } - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_SELECTED); - } + /** + * 移动组件至指定位置 + * + * @param x 坐标x + * @param y 坐标y + */ + public void move(int x, int y) { + for (XCreator creator : selection.getSelectedCreators()) { + creator.setLocation(creator.getX() + x, creator.getY() + y); + LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); + if (layoutAdapter != null) { + layoutAdapter.fix(creator); + } + } + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_SELECTED); + } - /** - * 释放捕获 - */ - public void releaseDragging() { - designer.setPainter(null); - selection.fixCreator(designer); - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_RESIZED); - } + /** + * 释放捕获 + */ + public void releaseDragging() { + designer.setPainter(null); + selection.fixCreator(designer); + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_RESIZED); + } - public Direction getDirectionAt(MouseEvent e) { - Direction dir; - if (e.isControlDown() || e.isShiftDown()) { - XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); - if (creator != designer.getRootComponent() && selection.addedable(creator)) { - return Location.add; - } - } - if (hasSelectionComponent()) { - int x = e.getX() + designer.getArea().getHorizontalValue(); - int y = e.getY() + designer.getArea().getVerticalValue(); - dir = getDirection(selection.getRelativeBounds(), x, y); - if (selection.size() == 1) { - if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) { - dir = Location.outer; - } - } - } else { - dir = Location.outer; - } + public Direction getDirectionAt(MouseEvent e) { + Direction dir; + if (e.isControlDown() || e.isShiftDown()) { + XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); + if (creator != designer.getRootComponent() && selection.addedable(creator)) { + return Location.add; + } + } + if (hasSelectionComponent()) { + int x = e.getX() + designer.getArea().getHorizontalValue(); + int y = e.getY() + designer.getArea().getVerticalValue(); + dir = getDirection(selection.getRelativeBounds(), x, y); + if (selection.size() == 1) { + if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) { + dir = Location.outer; + } + } + } else { + dir = Location.outer; + } - if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { - dir = designer.getLoc2Root(e); - } - return dir; - } + if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { + dir = designer.getLoc2Root(e); + } + return dir; + } - private Direction getDirection(Rectangle bounds, int x, int y) { - if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.left_top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.left; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.left_bottom; - } else { - return Location.outer; - } - } else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.inner; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.bottom; - } else { - return Location.outer; - } - } else if ((x >= (bounds.x + bounds.width)) - && (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { - if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { - return Location.outer; - } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { - return Location.right_top; - } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { - return Location.right; - } else if ((y >= (bounds.y + bounds.height)) - && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { - return Location.right_bottom; - } else { - return Location.outer; - } - } else { - return Location.outer; - } - } + private Direction getDirection(Rectangle bounds, int x, int y) { + if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.left_top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.left; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.left_bottom; + } else { + return Location.outer; + } + } else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.inner; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.bottom; + } else { + return Location.outer; + } + } else if ((x >= (bounds.x + bounds.width)) + && (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { + if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { + return Location.outer; + } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { + return Location.right_top; + } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { + return Location.right; + } else if ((y >= (bounds.y + bounds.height)) + && (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { + return Location.right_bottom; + } else { + return Location.outer; + } + } else { + return Location.outer; + } + } - private void fireCreatorSelected() { - designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), - DesignerEvent.CREATOR_SELECTED); - } + private void fireCreatorSelected() { + designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), + DesignerEvent.CREATOR_SELECTED); + } - public void setSelectedCreator(XCreator rootComponent) { - selection.setSelectedCreator(rootComponent); - fireCreatorSelected(); - } + public void setSelectedCreator(XCreator rootComponent) { + selection.setSelectedCreator(rootComponent); + fireCreatorSelected(); + } - public void setSelectedCreators(ArrayList rebuildSelection) { - selection.setSelectedCreators(rebuildSelection); - fireCreatorSelected(); - } + public void setSelectedCreators(ArrayList rebuildSelection) { + selection.setSelectedCreators(rebuildSelection); + fireCreatorSelected(); + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java b/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java index 692359bbd..1c6150d36 100644 --- a/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java +++ b/designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java @@ -71,619 +71,631 @@ import com.fr.stable.ArrayUtils; */ // TODO ALEX_SEP FormDesigner和FormParaDesignEditor应该共用Form的编辑,但是FormParaDesignEditor不应该直接就是FormDesigner public class FormParaDesigner extends FormDesigner implements ParameterDesignerProvider { - private static final int NUM_IN_A_LINE = 4; - private static final int H_COMPONENT_GAP = 165; - private static final int V_COMPONENT_GAP = 25; - private static final int FIRST_V_LOCATION = 35; - private static final int FIRST_H_LOCATION = 90; - private static final int SECOND_H_LOCATION = 170; - private static final int ADD_HEIGHT = 20; - private static final int H_GAP = 105; - - private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png"); - - public FormParaDesigner() { - this(new FormParameterUI()); - } - - public FormParaDesigner(FormParameterUI ui) { - super(gen(ui)); - } - - private static Form gen(Form form) { - WLayout container = form.getContainer(); - if (container == null) { - container = new WParameterLayout(); - } - container.setWidgetName("para"); - form.setContainer(container); - return form; - } - - protected FormDesignerModeForSpecial createFormDesignerTargetMode() { - return new FormParaTargetMode(this); - } - - /** - * 开始编辑参数面板的时候进行的初始化 - */ - public void initBeforeUpEdit() { - WidgetToolBarPane.getInstance(this); - EastRegionContainerPane.getInstance().replaceDownPane( - FormWidgetDetailPane.getInstance(this)); - if (!BaseUtils.isAuthorityEditing()) { - EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(this)); - EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); - EastRegionContainerPane.getInstance().replaceUpPane( - WidgetPropertyPane.getInstance(this)); - } else { - EastRegionContainerPane.getInstance().removeParameterPane(); - showAuthorityEditPane(); - } - - } - - /** - * 创建权限编辑面板 - * @return 面板 - */ - public AuthorityEditPane createAuthorityEditPane() { - return new FormWidgetAuthorityEditPane(this); - } - - /** - * 内容属性表面板 - * @return 内容属性表面板 - */ - public JPanel getEastUpPane() { - return WidgetPropertyPane.getInstance(this); - } - - /** - * 参数属性表 - * @return 参数属性表 - */ - - public JPanel getEastDownPane() { - return FormWidgetDetailPane.getInstance(this); - } - - /** - * 权限编辑面板 - * @return 权限编辑面板 - */ - public AuthorityEditPane getAuthorityEditPane() { - FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(this); - formWidgetAuthorityEditPane.populateDetials(); - return formWidgetAuthorityEditPane; - } - - /** - * 给包含此FormParaDesigner的ParameterDefinitePane添加事件 - * - * @param paraDefinitePane 面板 - */ - public void addListener(final ParaDefinitePane paraDefinitePane) { - this.getEditListenerTable().addListener(new DesignerEditListener() { - - @Override - public void fireCreatorModified(DesignerEvent evt) { - if (evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED - || evt.getCreatorEventID() == DesignerEvent.CREATOR_RENAMED) { - paraDefinitePane.setParameterArray( - paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); - paraDefinitePane.refreshParameter(); - } - } - }); - } - - /** - * 包裹一层FormArea - * - * @return 区域 - */ - public Component createWrapper() { - FormArea area = new FormArea(this, false); - area.setBorder(BorderFactory.createEmptyBorder(0, 13, 0, 0)); - return area; - } - - /** - * 刷新控件 - */ - public void refreshAllNameWidgets() { - XCreatorUtils.refreshAllNameWidgets(this.getRootComponent()); - } - - /** - * 刷新tableData - * - * @param oldName 旧名称 - * @param newName 新名称 - */ - public void refresh4TableData(String oldName, String newName) { - this.getTarget().renameTableData(oldName, newName); - this.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); - } - - /** - * 刷新参数 - * - * @param p 参数面板 - */ - public void refreshParameter(ParaDefinitePane p) { - XLayoutContainer rootContainer = this.getRootComponent(); - java.util.List namelist = getAllXCreatorNameList(rootContainer); - // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 - // 与已有的参数列表比较 如果已经存在 就除去 - Parameter[] ps = p.getParameterArray(); - if (ps != null) { - for (Parameter parameter : ps) { - for (String name : namelist) { - if (name.equalsIgnoreCase(parameter.getName())) { - p.setParameterArray((Parameter[]) ArrayUtils.removeElement(p.getParameterArray(), parameter)); - } - } - } - } - ParameterPropertyPane.getInstance().getParameterToolbarPane().populateBean( - p.getParameterArray() == null ? new Parameter[0] : p.getParameterArray()); - EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance().getPreferredSize().height); - - } - - /** - * 判断这个参数面板是否没有控件 - * - * @return 参数面板是否没有控件 - */ - public boolean isBlank() { - XLayoutContainer rootContainer = this.getRootComponent(); - List xx = getAllXCreatorNameList(rootContainer); - return xx.isEmpty(); - } - - protected void setToolbarButtons(boolean flag) { - DesignerContext.getDesignerFrame().checkCombineUp(!flag, NAME_ARRAY_LIST); - } - - /** - * 看看参数面板中的控件是否有和模板参数同名的 - * - * @param allParameters 参数 - * @return 是否有同名 - */ - public boolean isWithoutParaXCreator(Parameter[] allParameters) { - XLayoutContainer rootContainer = this.getRootComponent(); - List xx = getAllXCreatorNameList(rootContainer); - for (Parameter parameter : allParameters) { - for (String name : xx) { - if (name.equalsIgnoreCase(parameter.getName())) { - return false; - } - } - } - - return true; - } - - /** - * 参数面板控件的名字 - * - * @return 名字 - */ - public List getAllXCreatorNameList() { - XLayoutContainer rootContainer = this.getRootComponent(); - List namelist = new ArrayList(); - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); - } else { - namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); - } - } - return namelist; - } - - private List getAllXCreatorNameList(XLayoutContainer rootContainer) { - List namelist = new ArrayList(); - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); - } else { - namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); - } - } - return namelist; - } - - /** - * 是否有查询按钮 - * - * @return 有无查询按钮 - */ - public boolean isWithQueryButton() { - XLayoutContainer rootContainer = this.getRootComponent(); - return SearchQueryCreators(rootContainer); - } - - /** - * 返回复制粘贴删除等动作 - * @return 同上 - */ - public Action[] getActions() { - if (designer_actions == null) { - designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), - new FormDeleteAction(this)}; - } - return designer_actions; - } - - private boolean SearchQueryCreators(XLayoutContainer rootContainer) { - boolean b = false; - for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { - if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { - b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i)); - } else if (rootContainer.getXCreator(i) instanceof XFormSubmit) { - b = true; - } - } - return b; - } - - /** - * 就是getTarget 为了返回ParameterUI接口而不冲突另写个 - * - * @return - */ - public ParameterUI getParaTarget() { - return (FormParameterUI) super.getTarget(); - } - - /** - * ParameterDefinitePane通过ParaDesigner来调用ParameterPropertyPane - * - * @param p 面板 - */ - public void populateParameterPropertyPane(ParaDefinitePane p) { - ParameterPropertyPane.getInstance().populateBean(p); - } - - /** - * 初始化 - */ - public void initWidgetToolbarPane() { - WidgetToolBarPane.getInstance(this); - } - - /** - * populate - * - * @param ui - */ - public void populate(ParameterUI ui) { - if (ui == null) { - return; - } - if (this.getTarget() == ui) { - repaint(); - return; - } - this.setTarget((FormParameterUI) ui.convert()); - this.refreshRoot(); - } - - /** - * 报表直接判断底层是否是绝对布局 - * @return 是则返回true - */ - public boolean hasWAbsoluteLayout() { - return this.getTarget().getContainer() instanceof WAbsoluteLayout; - } - - /** - * 刷新底层容器 - */ - public void refreshRoot() { - XLayoutContainer layoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget() - .getContainer()); - if (layoutContainer == null) { - layoutContainer = new XWParameterLayout(); - } - layoutContainer.setSize(LARGE_PREFERRED_SIZE); - setRootComponent(layoutContainer); - } - - /** - * 是否是报表的参数面板 - * @return 是 - */ - public boolean isFormParaDesigner(){ - return true; - } - - public XLayoutContainer getParaComponent() { - return getRootComponent(); - } - - private void paintLinkParameters(Graphics clipg) { - Parameter[] paras = DesignModelAdapter.getCurrentModelAdapter().getParameters(); - if (paras == null || paras.length == 0) { - return; - } - Graphics g = clipg.create(); - g.setColor(Color.RED); - if (!(this.getRootComponent() instanceof XWAbsoluteLayout)) { - return; - } - XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); - for (int i = 0; i < layout.getXCreatorCount(); i++) { - XCreator creator = layout.getXCreator(i); - if (!creator.isVisible()) { - continue; - } - for (Parameter p : paras) { - if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) { - g.drawImage(paraImage, creator.getX() - 4, creator.getY() + 2, null); - break; - } - } - } - } - - /** - * 得到合适的大小 - * - * @return - */ - public Dimension getPreferredSize() { - return getDesignSize(); - } - - public Dimension getDesignSize() { - return ((FormParameterUI) getTarget()).getDesignSize(); - } - - /** - * 设置高度 - * - * @param height - */ - public void setDesignHeight(int height) { - Dimension dim = getPreferredSize(); - dim.height = height; - ((FormParameterUI) getTarget()).setDesignSize(dim); - } - - /** - * paintContent - * - * @param clipg - */ - public void paintContent(Graphics clipg) { - Dimension dim; - dim = ((FormParameterUI) getTarget()).getDesignSize(); - getRootComponent().setSize(dim); - getRootComponent().paint(clipg); - paintLinkParameters(clipg); - paintOp(clipg, getOutlineBounds()); - } - - private void paintOp(Graphics offg, Rectangle bounds) { - Color oldColor = offg.getColor(); - Insets insets = getOutlineInsets(); - offg.setColor(XCreatorConstants.OP_COLOR); - offg.fillRect(bounds.x, bounds.y + bounds.height, bounds.width + insets.right, insets.bottom); - offg.fillRect(bounds.x + bounds.width, bounds.y, insets.right, bounds.height); - offg.setColor(oldColor); - } - - protected void setRootComponent(XLayoutContainer component) { - component.setDirections(new int[]{Direction.BOTTOM, Direction.RIGHT}); - super.setRootComponent(component); - } - - /** - * 刷新尺寸 - */ - public void populateRootSize() { - ((FormParameterUI) getTarget()).setDesignSize(getRootComponent().getSize()); - if (getParaComponent().acceptType(XWParameterLayout.class)) { - WParameterLayout layout = (WParameterLayout)getParaComponent().toData(); - layout.setDesignWidth(getRootComponent().getWidth()); - } - } - - /** - * 保存参数界面的宽度 - * - * @param width 指定的宽度 - */ - public void updateWidth(int width) { - FormParameterUI parameterUI = ((FormParameterUI) getTarget()); - parameterUI.setDesignSize(new Dimension(width, parameterUI.getDesignSize().height)); - } - - /** - * 保存参数界面的高度 - * - * @param height 指定的高度 - */ - public void updateHeight(int height) { - FormParameterUI parameterUI = ((FormParameterUI) getTarget()); - parameterUI.setDesignSize(new Dimension(parameterUI.getDesignSize().width, height)); - } - - /** - * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 - * - * @param creator 组件 z - * @param x 长度 - * @param y 长度 c - * @param layout 布局 - * @return 是否扩展 - */ - public boolean prepareForAdd(XCreator creator, int x, int y, XWAbsoluteLayout layout) { - // 参数界面,自动扩展 - if (!isRoot(layout)) { - return false; - } - - Dimension size = layout.getSize(); - Boolean needResize = false; - - if (creator.getWidth() / 2 + x > layout.getWidth()) { - size.width = creator.getWidth() / 2 + x + ADD_HEIGHT; - needResize = true; - } - if (creator.getHeight() / 2 + y > layout.getHeight()) { - size.height = creator.getHeight() / 2 + y + ADD_HEIGHT; - needResize = true; - } - if (needResize) { - layout.setSize(size); - populateRootSize(); - } - return true; - } - - /** - * 加入参数 - * @param parameter 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public boolean addingParameter2Editor(Parameter parameter, int currentIndex) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - String name = parameter.getName(); - label.setWidgetName("Label" + name); - label.setWidgetValue(new WidgetValue(name + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - EditorHolder editor = new EditorHolder(parameter); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - return true; - } - - - /** - * 加入参数 - * @param parameter 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int currentIndex) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - String name = parameter.getName(); - label.setWidgetName("Label" + name); - label.setWidgetValue(new WidgetValue(name + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - if (!(this.autoAddComponent(xCreator, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - EditorHolder editor = new EditorHolder(parameter); - editor.setWidgetName(name); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - FormSubmitButton formSubmitButton = new FormSubmitButton(); - formSubmitButton.setWidgetName("Search"); - formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); - xCreator = XCreatorUtils.createXCreator(formSubmitButton); - if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP - * (currentIndex / NUM_IN_A_LINE)))) { - return false; - } - return true; - } - - /** - * 加入参数 - * @param parameterArray 参数 c - * @param currentIndex 位置 w - * @return 是否加入 s - */ - public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex) { - for (int i = 0; i < parameterArray.length; i++) { - com.fr.form.ui.Label label = new com.fr.form.ui.Label(); - label.setWidgetName("Label" + parameterArray[i].getName()); - label.setWidgetValue(new WidgetValue(parameterArray[i].getName() + ":")); - XCreator xCreator = XCreatorUtils.createXCreator(label); - - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - break; - } - // 每行显示5组 - EditorHolder editor = new EditorHolder(parameterArray[i]); - editor.setWidgetName(parameterArray[i].getName()); - xCreator = XCreatorUtils.createXCreator(editor); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) - + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - break; - } - currentIndex++; - } - if (!isWithQueryButton()) { - FormSubmitButton formSubmitButton = new FormSubmitButton(); - formSubmitButton.setWidgetName("Search"); - formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); - XCreator xCreator = XCreatorUtils.createXCreator(formSubmitButton); - if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * 3 + H_GAP, FIRST_V_LOCATION - + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return; - } - } - } - - /** - * 自动添加 - * - * @param xCreator 组件 z - * @param x 位置 w - * @param y 位置 - * @return 是否添加 s - */ - public boolean autoAddComponent(XCreator xCreator, int x, int y) { - XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); - FRAbsoluteLayoutAdapter adapter = (FRAbsoluteLayoutAdapter) layout.getLayoutAdapter(); - if (prepareForAdd(xCreator, x, y, layout)) { - adapter.addBean(xCreator, x, y); - } - this.getSelectionModel().setSelectedCreator(xCreator); - repaint(); - return true; - } - - /** - * 工具栏 - * @return 工具栏面板 g - */ - public JPanel[] toolbarPanes4Form() { - return new JPanel[]{FormParaPane.getInstance(this)}; - } - - /** - * 复制等按钮 - * @return 按钮组 a - */ - public JComponent[] toolBarButton4Form() { - return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), - new FormDeleteAction(this).createToolBarComponent()}; - } + private static final int NUM_IN_A_LINE = 4; + private static final int H_COMPONENT_GAP = 165; + private static final int V_COMPONENT_GAP = 25; + private static final int FIRST_V_LOCATION = 35; + private static final int FIRST_H_LOCATION = 90; + private static final int SECOND_H_LOCATION = 170; + private static final int ADD_HEIGHT = 20; + private static final int H_GAP = 105; + + private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png"); + + public FormParaDesigner() { + this(new FormParameterUI()); + } + + public FormParaDesigner(FormParameterUI ui) { + super(gen(ui)); + } + + private static Form gen(Form form) { + WLayout container = form.getContainer(); + if (container == null) { + container = new WParameterLayout(); + } + container.setWidgetName("para"); + form.setContainer(container); + return form; + } + + protected FormDesignerModeForSpecial createFormDesignerTargetMode() { + return new FormParaTargetMode(this); + } + + /** + * 开始编辑参数面板的时候进行的初始化 + */ + public void initBeforeUpEdit() { + WidgetToolBarPane.getInstance(this); + EastRegionContainerPane.getInstance().replaceDownPane( + FormWidgetDetailPane.getInstance(this)); + if (!BaseUtils.isAuthorityEditing()) { + EastRegionContainerPane.getInstance().addParameterPane(ParameterPropertyPane.getInstance(this)); + EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); + EastRegionContainerPane.getInstance().replaceUpPane( + WidgetPropertyPane.getInstance(this)); + } else { + EastRegionContainerPane.getInstance().removeParameterPane(); + showAuthorityEditPane(); + } + + } + + /** + * 创建权限编辑面板 + * + * @return 面板 + */ + public AuthorityEditPane createAuthorityEditPane() { + return new FormWidgetAuthorityEditPane(this); + } + + /** + * 内容属性表面板 + * + * @return 内容属性表面板 + */ + public JPanel getEastUpPane() { + return WidgetPropertyPane.getInstance(this); + } + + /** + * 参数属性表 + * + * @return 参数属性表 + */ + + public JPanel getEastDownPane() { + return FormWidgetDetailPane.getInstance(this); + } + + /** + * 权限编辑面板 + * + * @return 权限编辑面板 + */ + public AuthorityEditPane getAuthorityEditPane() { + FormWidgetAuthorityEditPane formWidgetAuthorityEditPane = new FormWidgetAuthorityEditPane(this); + formWidgetAuthorityEditPane.populateDetials(); + return formWidgetAuthorityEditPane; + } + + /** + * 给包含此FormParaDesigner的ParameterDefinitePane添加事件 + * + * @param paraDefinitePane 面板 + */ + public void addListener(final ParaDefinitePane paraDefinitePane) { + this.getEditListenerTable().addListener(new DesignerEditListener() { + + @Override + public void fireCreatorModified(DesignerEvent evt) { + if (evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED + || evt.getCreatorEventID() == DesignerEvent.CREATOR_RENAMED) { + paraDefinitePane.setParameterArray( + paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); + paraDefinitePane.refreshParameter(); + } + } + }); + } + + /** + * 包裹一层FormArea + * + * @return 区域 + */ + public Component createWrapper() { + FormArea area = new FormArea(this, false); + area.setBorder(BorderFactory.createEmptyBorder(0, 13, 0, 0)); + return area; + } + + /** + * 刷新控件 + */ + public void refreshAllNameWidgets() { + XCreatorUtils.refreshAllNameWidgets(this.getRootComponent()); + } + + /** + * 刷新tableData + * + * @param oldName 旧名称 + * @param newName 新名称 + */ + public void refresh4TableData(String oldName, String newName) { + this.getTarget().renameTableData(oldName, newName); + this.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); + } + + /** + * 刷新参数 + * + * @param p 参数面板 + */ + public void refreshParameter(ParaDefinitePane p) { + XLayoutContainer rootContainer = this.getRootComponent(); + java.util.List namelist = getAllXCreatorNameList(rootContainer); + // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 + // 与已有的参数列表比较 如果已经存在 就除去 + Parameter[] ps = p.getParameterArray(); + if (ps != null) { + for (Parameter parameter : ps) { + for (String name : namelist) { + if (name.equalsIgnoreCase(parameter.getName())) { + p.setParameterArray((Parameter[]) ArrayUtils.removeElement(p.getParameterArray(), parameter)); + } + } + } + } + ParameterPropertyPane.getInstance().getParameterToolbarPane().populateBean( + p.getParameterArray() == null ? new Parameter[0] : p.getParameterArray()); + EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance().getPreferredSize().height); + + } + + /** + * 判断这个参数面板是否没有控件 + * + * @return 参数面板是否没有控件 + */ + public boolean isBlank() { + XLayoutContainer rootContainer = this.getRootComponent(); + List xx = getAllXCreatorNameList(rootContainer); + return xx.isEmpty(); + } + + protected void setToolbarButtons(boolean flag) { + DesignerContext.getDesignerFrame().checkCombineUp(!flag, NAME_ARRAY_LIST); + } + + /** + * 看看参数面板中的控件是否有和模板参数同名的 + * + * @param allParameters 参数 + * @return 是否有同名 + */ + public boolean isWithoutParaXCreator(Parameter[] allParameters) { + XLayoutContainer rootContainer = this.getRootComponent(); + List xx = getAllXCreatorNameList(rootContainer); + for (Parameter parameter : allParameters) { + for (String name : xx) { + if (name.equalsIgnoreCase(parameter.getName())) { + return false; + } + } + } + + return true; + } + + /** + * 参数面板控件的名字 + * + * @return 名字 + */ + public List getAllXCreatorNameList() { + XLayoutContainer rootContainer = this.getRootComponent(); + List namelist = new ArrayList(); + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); + } else { + namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); + } + } + return namelist; + } + + private List getAllXCreatorNameList(XLayoutContainer rootContainer) { + List namelist = new ArrayList(); + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + namelist.addAll(getAllXCreatorNameList((XLayoutContainer) rootContainer.getXCreator(i))); + } else { + namelist.add(rootContainer.getXCreator(i).toData().getWidgetName()); + } + } + return namelist; + } + + /** + * 是否有查询按钮 + * + * @return 有无查询按钮 + */ + public boolean isWithQueryButton() { + XLayoutContainer rootContainer = this.getRootComponent(); + return SearchQueryCreators(rootContainer); + } + + /** + * 返回复制粘贴删除等动作 + * + * @return 同上 + */ + public Action[] getActions() { + if (designer_actions == null) { + designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + new FormDeleteAction(this)}; + } + return designer_actions; + } + + private boolean SearchQueryCreators(XLayoutContainer rootContainer) { + boolean b = false; + for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { + if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { + b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i)); + } else if (rootContainer.getXCreator(i) instanceof XFormSubmit) { + b = true; + } + } + return b; + } + + /** + * 就是getTarget 为了返回ParameterUI接口而不冲突另写个 + * + * @return + */ + public ParameterUI getParaTarget() { + return (FormParameterUI) super.getTarget(); + } + + /** + * ParameterDefinitePane通过ParaDesigner来调用ParameterPropertyPane + * + * @param p 面板 + */ + public void populateParameterPropertyPane(ParaDefinitePane p) { + ParameterPropertyPane.getInstance().populateBean(p); + } + + /** + * 初始化 + */ + public void initWidgetToolbarPane() { + WidgetToolBarPane.getInstance(this); + } + + /** + * populate + * + * @param ui + */ + public void populate(ParameterUI ui) { + if (ui == null) { + return; + } + if (this.getTarget() == ui) { + repaint(); + return; + } + this.setTarget((FormParameterUI) ui.convert()); + this.refreshRoot(); + } + + /** + * 报表直接判断底层是否是绝对布局 + * + * @return 是则返回true + */ + public boolean hasWAbsoluteLayout() { + return this.getTarget().getContainer() instanceof WAbsoluteLayout; + } + + /** + * 刷新底层容器 + */ + public void refreshRoot() { + XLayoutContainer layoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget() + .getContainer()); + if (layoutContainer == null) { + layoutContainer = new XWParameterLayout(); + } + layoutContainer.setSize(LARGE_PREFERRED_SIZE); + setRootComponent(layoutContainer); + } + + /** + * 是否是报表的参数面板 + * + * @return 是 + */ + public boolean isFormParaDesigner() { + return true; + } + + public XLayoutContainer getParaComponent() { + return getRootComponent(); + } + + private void paintLinkParameters(Graphics clipg) { + Parameter[] paras = DesignModelAdapter.getCurrentModelAdapter().getParameters(); + if (paras == null || paras.length == 0) { + return; + } + Graphics g = clipg.create(); + g.setColor(Color.RED); + if (!(this.getRootComponent() instanceof XWAbsoluteLayout)) { + return; + } + XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); + for (int i = 0; i < layout.getXCreatorCount(); i++) { + XCreator creator = layout.getXCreator(i); + if (!creator.isVisible()) { + continue; + } + for (Parameter p : paras) { + if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) { + g.drawImage(paraImage, creator.getX() - 4, creator.getY() + 2, null); + break; + } + } + } + } + + /** + * 得到合适的大小 + * + * @return + */ + public Dimension getPreferredSize() { + return getDesignSize(); + } + + public Dimension getDesignSize() { + return ((FormParameterUI) getTarget()).getDesignSize(); + } + + /** + * 设置高度 + * + * @param height + */ + public void setDesignHeight(int height) { + Dimension dim = getPreferredSize(); + dim.height = height; + ((FormParameterUI) getTarget()).setDesignSize(dim); + } + + /** + * paintContent + * + * @param clipg + */ + public void paintContent(Graphics clipg) { + Dimension dim; + dim = ((FormParameterUI) getTarget()).getDesignSize(); + getRootComponent().setSize(dim); + getRootComponent().paint(clipg); + paintLinkParameters(clipg); + paintOp(clipg, getOutlineBounds()); + } + + private void paintOp(Graphics offg, Rectangle bounds) { + Color oldColor = offg.getColor(); + Insets insets = getOutlineInsets(); + offg.setColor(XCreatorConstants.OP_COLOR); + offg.fillRect(bounds.x, bounds.y + bounds.height, bounds.width + insets.right, insets.bottom); + offg.fillRect(bounds.x + bounds.width, bounds.y, insets.right, bounds.height); + offg.setColor(oldColor); + } + + protected void setRootComponent(XLayoutContainer component) { + component.setDirections(new int[]{Direction.BOTTOM, Direction.RIGHT}); + super.setRootComponent(component); + } + + /** + * 刷新尺寸 + */ + public void populateRootSize() { + ((FormParameterUI) getTarget()).setDesignSize(getRootComponent().getSize()); + if (getParaComponent().acceptType(XWParameterLayout.class)) { + WParameterLayout layout = (WParameterLayout) getParaComponent().toData(); + layout.setDesignWidth(getRootComponent().getWidth()); + } + } + + /** + * 保存参数界面的宽度 + * + * @param width 指定的宽度 + */ + public void updateWidth(int width) { + FormParameterUI parameterUI = ((FormParameterUI) getTarget()); + parameterUI.setDesignSize(new Dimension(width, parameterUI.getDesignSize().height)); + } + + /** + * 保存参数界面的高度 + * + * @param height 指定的高度 + */ + public void updateHeight(int height) { + FormParameterUI parameterUI = ((FormParameterUI) getTarget()); + parameterUI.setDesignSize(new Dimension(parameterUI.getDesignSize().width, height)); + } + + /** + * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 + * + * @param creator 组件 z + * @param x 长度 + * @param y 长度 c + * @param layout 布局 + * @return 是否扩展 + */ + public boolean prepareForAdd(XCreator creator, int x, int y, XWAbsoluteLayout layout) { + // 参数界面,自动扩展 + if (!isRoot(layout)) { + return false; + } + + Dimension size = layout.getSize(); + Boolean needResize = false; + + if (creator.getWidth() / 2 + x > layout.getWidth()) { + size.width = creator.getWidth() / 2 + x + ADD_HEIGHT; + needResize = true; + } + if (creator.getHeight() / 2 + y > layout.getHeight()) { + size.height = creator.getHeight() / 2 + y + ADD_HEIGHT; + needResize = true; + } + if (needResize) { + layout.setSize(size); + populateRootSize(); + } + return true; + } + + /** + * 加入参数 + * + * @param parameter 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public boolean addingParameter2Editor(Parameter parameter, int currentIndex) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + String name = parameter.getName(); + label.setWidgetName("Label" + name); + label.setWidgetValue(new WidgetValue(name + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + EditorHolder editor = new EditorHolder(parameter); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + return true; + } + + + /** + * 加入参数 + * + * @param parameter 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public boolean addingParameter2EditorWithQueryButton(Parameter parameter, int currentIndex) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + String name = parameter.getName(); + label.setWidgetName("Label" + name); + label.setWidgetValue(new WidgetValue(name + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + if (!(this.autoAddComponent(xCreator, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + EditorHolder editor = new EditorHolder(parameter); + editor.setWidgetName(name); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + FormSubmitButton formSubmitButton = new FormSubmitButton(); + formSubmitButton.setWidgetName("Search"); + formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); + xCreator = XCreatorUtils.createXCreator(formSubmitButton); + if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP + * (currentIndex / NUM_IN_A_LINE)))) { + return false; + } + return true; + } + + /** + * 加入参数 + * + * @param parameterArray 参数 c + * @param currentIndex 位置 w + * @return 是否加入 s + */ + public void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex) { + for (int i = 0; i < parameterArray.length; i++) { + com.fr.form.ui.Label label = new com.fr.form.ui.Label(); + label.setWidgetName("Label" + parameterArray[i].getName()); + label.setWidgetValue(new WidgetValue(parameterArray[i].getName() + ":")); + XCreator xCreator = XCreatorUtils.createXCreator(label); + + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + break; + } + // 每行显示5组 + EditorHolder editor = new EditorHolder(parameterArray[i]); + editor.setWidgetName(parameterArray[i].getName()); + xCreator = XCreatorUtils.createXCreator(editor); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + break; + } + currentIndex++; + } + if (!isWithQueryButton()) { + FormSubmitButton formSubmitButton = new FormSubmitButton(); + formSubmitButton.setWidgetName("Search"); + formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); + XCreator xCreator = XCreatorUtils.createXCreator(formSubmitButton); + if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * 3 + H_GAP, FIRST_V_LOCATION + + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { + return; + } + } + } + + /** + * 自动添加 + * + * @param xCreator 组件 z + * @param x 位置 w + * @param y 位置 + * @return 是否添加 s + */ + public boolean autoAddComponent(XCreator xCreator, int x, int y) { + XWAbsoluteLayout layout = (XWAbsoluteLayout) this.getRootComponent(); + FRAbsoluteLayoutAdapter adapter = (FRAbsoluteLayoutAdapter) layout.getLayoutAdapter(); + if (prepareForAdd(xCreator, x, y, layout)) { + adapter.addBean(xCreator, x, y); + } + this.getSelectionModel().setSelectedCreator(xCreator); + repaint(); + return true; + } + + /** + * 工具栏 + * + * @return 工具栏面板 g + */ + public JPanel[] toolbarPanes4Form() { + return new JPanel[]{FormParaPane.getInstance(this)}; + } + + /** + * 复制等按钮 + * + * @return 按钮组 a + */ + public JComponent[] toolBarButton4Form() { + return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), + new FormDeleteAction(this).createToolBarComponent()}; + } } \ 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 88dc9268f..9b4ccfeeb 100644 --- a/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java +++ b/designer_form/src/com/fr/design/mainframe/EditingMouseListener.java @@ -202,7 +202,7 @@ public class EditingMouseListener extends MouseInputAdapter { XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); if(selectionXCreator != null){ selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height); - MoveUtils.hideForbidWindow(); +// MoveUtils.hideForbidWindow(); } } dragBackupBounds = null; diff --git a/designer_form/src/com/fr/design/mainframe/FormDesigner.java b/designer_form/src/com/fr/design/mainframe/FormDesigner.java index a3b197e91..d78cb5557 100644 --- a/designer_form/src/com/fr/design/mainframe/FormDesigner.java +++ b/designer_form/src/com/fr/design/mainframe/FormDesigner.java @@ -6,7 +6,10 @@ import com.fr.design.DesignState; import com.fr.design.designer.TargetComponent; import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.Painter; +import com.fr.design.designer.beans.actions.CopyAction; +import com.fr.design.designer.beans.actions.CutAction; import com.fr.design.designer.beans.actions.FormDeleteAction; +import com.fr.design.designer.beans.actions.PasteAction; import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter; import com.fr.design.designer.beans.events.CreatorEventListenerTable; import com.fr.design.designer.beans.events.DesignerEditListener; @@ -65,7 +68,7 @@ import java.util.List; /** * 设计界面组件。该组件是界面设计工具的核心,主要负责的是被设计界面的显示,界面设计操作状态的 显示,编辑状态的显示等等。 */ -public class FormDesigner extends TargetComponent

implements TreeSelectionListener, InvocationHandler, BaseFormDesigner ,ParaDefinitePane{ +public class FormDesigner extends TargetComponent implements TreeSelectionListener, InvocationHandler, BaseFormDesigner, ParaDefinitePane { protected static final ArrayList NAME_ARRAY_LIST = new ArrayList( Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")}) ); @@ -159,7 +162,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection ParameterPropertyPane.getInstance().populateBean(this); } - public Parameter[] getNoRepeatParas(Parameter[] paras){ + public Parameter[] getNoRepeatParas(Parameter[] paras) { List paraList = new ArrayList(); java.util.Set set = new java.util.HashSet(); for (Parameter p : paras) { @@ -171,23 +174,23 @@ public class FormDesigner extends TargetComponent implements TreeSelection return paraList.toArray(new Parameter[paraList.size()]); } - public void setParameterArray(Parameter[] ps){ + public void setParameterArray(Parameter[] ps) { parameterArray = ps; } - public Parameter[] getParameterArray(){ + public Parameter[] getParameterArray() { return parameterArray; } /** * 刷新参数 */ - public void refreshParameter(){ + public void refreshParameter() { XLayoutContainer rootContainer = this.getParaComponent(); - if (rootContainer != null){ + if (rootContainer != null) { java.util.List namelist = new ArrayList(); - rootContainer.getAllXCreatorNameList(rootContainer,namelist); + rootContainer.getAllXCreatorNameList(rootContainer, namelist); // parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名 // 与已有的参数列表比较 如果已经存在 就除去 Parameter[] ps = getParameterArray(); @@ -201,7 +204,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height); } - private void removeSame(Parameter[] parameters, List namelist){ + private void removeSame(Parameter[] parameters, List namelist) { for (Parameter parameter : parameters) { for (String name : namelist) { if (name.equalsIgnoreCase(parameter.getName())) { @@ -214,20 +217,22 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否有查询按钮 - * @return 有无查询按钮 + * + * @return 有无查询按钮 */ - public boolean isWithQueryButton(){ + public boolean isWithQueryButton() { XLayoutContainer rootContainer = this.getParaComponent(); return rootContainer != null && rootContainer.SearchQueryCreators(rootContainer); } /** * 加入参数到参数面板 + * * @param parameter 参数 * @return 是否加入 */ - public void addingParameter2Editor(Parameter parameter){ - if(getParaComponent() == null){ + public void addingParameter2Editor(Parameter parameter) { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -242,11 +247,11 @@ public class FormDesigner extends TargetComponent implements TreeSelection if (!(this.autoAddComponent(xLabel, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE) + SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } currentIndex++; parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter); @@ -256,11 +261,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 加入参数到参数面板,有查询按钮 + * * @param parameter 参数 * @return 是否加入 */ - public void addingParameter2EditorWithQueryButton(Parameter parameter){ - if(getParaComponent() == null){ + public void addingParameter2EditorWithQueryButton(Parameter parameter) { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -276,12 +282,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection if (!(this.autoAddComponent(xLabel, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } FormSubmitButton formSubmitButton = new FormSubmitButton(); formSubmitButton.setWidgetName("Search"); @@ -289,7 +295,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection xCreator = XCreatorUtils.createXCreator(formSubmitButton); if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) { - return ; + return; } currentIndex = currentIndex + NUM_IN_A_LINE - currentIndex % NUM_IN_A_LINE; parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter); @@ -300,8 +306,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 一键添加所有参数 */ - public void addingAllParameter2Editor(){ - if(getParaComponent() == null){ + public void addingAllParameter2Editor() { + if (getParaComponent() == null) { addParaPaneTooltips(); return; } @@ -350,16 +356,17 @@ public class FormDesigner extends TargetComponent implements TreeSelection EastRegionContainerPane.getInstance().refreshDownPane(); } - private void addParaPaneTooltips(){ - JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"), + private void addParaPaneTooltips() { + JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"), Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); } /** * 自动添加组件 - * @param xCreator 组件 - * @param x 横坐标 - * @param y 纵坐标 + * + * @param xCreator 组件 + * @param x 横坐标 + * @param y 纵坐标 * @return 是否添加成功 */ public boolean autoAddComponent(XCreator xCreator, int x, int y) { @@ -375,10 +382,11 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 在参数很多时,全部添加的时候,可以向下一次排版,若去掉就会在参数面板堆到一起 + * * @param creator 组件 - * @param x 长度 - * @param y 长度 - * @param layout 布局 + * @param x 长度 + * @param y 长度 + * @param layout 布局 * @return 是否扩展 */ public boolean prepareForAdd(XCreator creator, int x, int y, XWParameterLayout layout) { @@ -404,9 +412,9 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 加入参数面板 */ - public void addParaComponent(){ + public void addParaComponent() { if (paraComponent != null) { - return ; + return; } paraHeight = WBorderLayout.DEFAULT_SIZE; paraComponent = new XWParameterLayout(); @@ -414,7 +422,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection paraComponent.setSize(paraComponent.initEditorSize()); XWBorderLayout formLayoutContainer = (XWBorderLayout) rootComponent.getParent(); formLayoutContainer.toData().setNorthSize(paraHeight); - formLayoutContainer.add(paraComponent,WBorderLayout.NORTH); + formLayoutContainer.add(paraComponent, WBorderLayout.NORTH); //设下northSize,增加para后,重置border大小,这时候para和root的大小会自适应调整 formLayoutContainer.setSize(formLayoutContainer.getWidth(), formLayoutContainer.getHeight() + paraHeight); selectionModel.reset(); @@ -424,30 +432,33 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 返回根节点父容器 - * @return 父容器 + * 返回根节点父容器 + * + * @return 父容器 */ - public Component getTopContainer(){ - if(rootComponent != null){ + public Component getTopContainer() { + if (rootComponent != null) { // 返回root所在的父容器,非designer return LayoutUtils.getTopContainer(rootComponent); } - return XCreatorUtils.createXCreator(this.getTarget().getContainer()); + return XCreatorUtils.createXCreator(this.getTarget().getContainer()); } /** * 返回参数界面高度 - * @return para高度 + * + * @return para高度 */ - public int getParaHeight(){ + public int getParaHeight() { return paraHeight; } /** * 重置para的高度 - * @param height 高度 + * + * @param height 高度 */ - public void setParaHeight(int height){ + public void setParaHeight(int height) { XWBorderLayout container = (XWBorderLayout) getTopContainer(); container.toData().setNorthSize(height); container.setSize(container.getWidth(), container.getHeight() + height - getParaHeight()); @@ -457,7 +468,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 删除参数界面 */ - public void removeParaComponent(){ + public void removeParaComponent() { XWBorderLayout formLayoutContainer = (XWBorderLayout) getTopContainer(); formLayoutContainer.toData().removeWidget(paraComponent.toData()); paraHeight = 0; @@ -472,41 +483,42 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 切换 - * @param elementCaseContainer 容器 + * + * @param elementCaseContainer 容器 */ - public void switchTab(FormElementCaseContainerProvider elementCaseContainer){ - if(this.switchAction == null){ + public void switchTab(FormElementCaseContainerProvider elementCaseContainer) { + if (this.switchAction == null) { return; } this.elementCaseContainer = elementCaseContainer; this.switchAction.actionPerformed(null); } - public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer){ + public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer) { this.elementCaseContainer = elementCaseContainer; } - public FormElementCaseProvider getElementCase(){ + public FormElementCaseProvider getElementCase() { return this.elementCaseContainer.getElementCase(); } - public String getElementCaseContainerName(){ + public String getElementCaseContainerName() { return this.elementCaseContainer.getElementCaseContainerName(); } - public void setElementCase(FormElementCaseProvider elementCase){ + public void setElementCase(FormElementCaseProvider elementCase) { this.elementCaseContainer.setElementCase(elementCase); } - public void setElementCaseBackground(BufferedImage image){ + public void setElementCaseBackground(BufferedImage image) { this.elementCaseContainer.setBackground(image); } - public Dimension getElementCaseContainerSize(){ + public Dimension getElementCaseContainerSize() { return this.elementCaseContainer.getSize(); } - public FormElementCaseContainerProvider getElementCaseContainer(){ + public FormElementCaseContainerProvider getElementCaseContainer() { return this.elementCaseContainer; } @@ -524,6 +536,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 增加监听事件 + * * @param listener 界面组件编辑事件 */ public void addDesignerEditListener(DesignerEditListener listener) { @@ -539,15 +552,15 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 表单则判断参数面板是否为绝对布局 + * * @return 是则返回true */ public boolean hasWAbsoluteLayout() { - if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)){ + if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)) { return true; - } - else{ + } else { if (this.getSelectionModel().getSelection().getSelectedCreator().getParent() != null - && ((XLayoutContainer)this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)){ + && ((XLayoutContainer) this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)) { return true; } } @@ -555,7 +568,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 设置是否为报表块编辑 + * 设置是否为报表块编辑 + * * @param isEditing 是否为报表块编辑 */ public void setReportBlockEditing(boolean isEditing) { @@ -564,25 +578,27 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否为报表块编辑 + * * @return 是否为报表块编辑 */ public boolean isReportBlockEditing() { return this.isReportBlockEditing; } - public void setWidgetsIntersect(boolean isWidgetsIntersect){ + public void setWidgetsIntersect(boolean isWidgetsIntersect) { this.isWidgetsIntersect = isWidgetsIntersect; } - public boolean isWidgetsIntersect(){ + public boolean isWidgetsIntersect() { return this.isWidgetsIntersect; } /** * 是否重命名控件 + * * @param creator 组件 * @param newName 新的组件名 - * @return 组件名有变化,且不和其他一样返回true + * @return 组件名有变化,且不和其他一样返回true */ public boolean renameCreator(XCreator creator, String newName) { if (ComparatorUtils.equals(creator.toData().getWidgetName(), newName)) { @@ -609,16 +625,17 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 更新界面布局,重绘 - * @param proxy 动态代理类 + * + * @param proxy 动态代理类 * @param method 接口方法 - * @param args 参数 + * @param args 参数 * @return 不返回任何对象 */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if(rootComponent != null){ + if (rootComponent != null) { LayoutUtils.layoutRootContainer(rootComponent); } - if(paraComponent != null){ + if (paraComponent != null) { LayoutUtils.layoutRootContainer(paraComponent); } repaint(); @@ -654,6 +671,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 增加组件事件 + * * @param h 动态代理 */ public void addInvocationHandler(InvocationHandler h) { @@ -678,7 +696,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 设置其UI类为DesignerUI,负责渲染 + * 设置其UI类为DesignerUI,负责渲染 */ @Override public void updateUI() { @@ -741,6 +759,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 更新边框线状态 + * * @param e 鼠标事件 */ public void updateDrawLineMode(MouseEvent e) { @@ -761,7 +780,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection // 撤销恢复操作都会refreshRoot,这时候的target.getContainer里的widget会和之前不一样,所以不用root判断来取 XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget().getContainer()); // 布局默认都是1,底层的border改为0,不然没意义 - this.getTarget().getContainer().setMargin(new PaddingMargin(0,0,0,0)); + this.getTarget().getContainer().setMargin(new PaddingMargin(0, 0, 0, 0)); formLayoutContainer.setBorder(null); if (formLayoutContainer.acceptType(XWBorderLayout.class)) { WBorderLayout borderLayout = (WBorderLayout) formLayoutContainer.toData(); @@ -774,7 +793,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection refreshNorth(northWidget, formLayoutContainer); refreshCenter(centerWidget, formLayoutContainer); - } else { + } else { formLayoutContainer.setSize(LARGE_PREFERRED_SIZE); setRootComponent(formLayoutContainer); } @@ -790,9 +809,9 @@ public class FormDesigner extends TargetComponent implements TreeSelection } XLayoutContainer northContainer = (XLayoutContainer) XCreatorUtils.createXCreator(northWidget); - paraHeight = ((XWBorderLayout)formLayoutContainer).toData().getNorthSize(); + paraHeight = ((XWBorderLayout) formLayoutContainer).toData().getNorthSize(); paraComponent = northContainer; - northContainer.setSize(0,paraHeight); + northContainer.setSize(0, paraHeight); formLayoutContainer.add(northContainer, WBorderLayout.NORTH); } @@ -841,14 +860,16 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否是报表的参数面板 - * @return 否(表单的) + * + * @return 否(表单的) */ - public boolean isFormParaDesigner(){ + public boolean isFormParaDesigner() { return false; } /** - * 是否为底层容器 + * 是否为底层容器 + * * @param comp 组件 * @return 是则返回true */ @@ -923,10 +944,10 @@ public class FormDesigner extends TargetComponent implements TreeSelection } public SelectionModel getSelectionModel() { - if (paraComponent!=null){ - paraComponent.setSize(paraComponent.getWidth(),getParaHeight()); + if (paraComponent != null) { + paraComponent.setSize(paraComponent.getWidth(), getParaHeight()); Rectangle rec = rootComponent.getBounds(); - rootComponent.setBounds(rec.x,getParaHeight(),rec.width,rec.height); + rootComponent.setBounds(rec.x, getParaHeight(), rec.width, rec.height); } return selectionModel; } @@ -941,6 +962,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 拖拽准备 + * * @param xCreator 组件 */ public void startDraggingBean(XCreator xCreator) { @@ -953,11 +975,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 拖拽时相关处理 - * @param xCreator 组件 + * 拖拽时相关处理 + * + * @param xCreator 组件 * @param lastPressEvent 鼠标事件 - * @param x 坐标x - * @param y 坐标y + * @param x 坐标x + * @param y 坐标y */ public void startDraggingComponent(XCreator xCreator, MouseEvent lastPressEvent, int x, int y) { // 根据所选择的组件的BeanInfo生成相应的AddingModel @@ -978,6 +1001,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 改变组件值 + * * @param e 组件选择事件 */ @Override @@ -1024,6 +1048,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 是否支持权限编辑 + * * @return 是则返回true */ public boolean isSupportAuthority() { @@ -1048,7 +1073,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 是否含有action名 + * 是否含有action名 + * * @param name action名 * @return 有则返回true */ @@ -1058,6 +1084,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 显示组件 + * * @param comp 组件 */ public void makeVisible(XCreator comp) { @@ -1088,14 +1115,14 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回复制粘贴删除等动作 + * 鼠标右键菜单 + * * @return 同上 */ public Action[] getActions() { if (designer_actions == null) { - //先把复制粘贴按钮去掉,只留下删除 -// designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), -// new FormDeleteAction(this)}; - designer_actions = new Action[]{new FormDeleteAction(this)}; + designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), + new FormDeleteAction(this)}; } return designer_actions; } @@ -1120,6 +1147,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回表单区域 + * * @return 表单区域 */ public FormArea getArea() { @@ -1128,6 +1156,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 设置上层区域 + * * @param formArea 表单区域 */ public void setParent(FormArea formArea) { @@ -1136,14 +1165,15 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 绘制组件根节点 + * * @param clipg 图形 */ public void paintContent(Graphics clipg) { rootComponent.paint(clipg); } - public void paintPara(Graphics clipg){ - if(paraComponent != null){ + public void paintPara(Graphics clipg) { + if (paraComponent != null) { paraComponent.paint(clipg); } } @@ -1157,6 +1187,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回连线类 + * * @return ConnectorHelper类 */ public ConnectorHelper getDrawLineHelper() { @@ -1164,7 +1195,8 @@ public class FormDesigner extends TargetComponent implements TreeSelection } /** - * 是否画线模式 + * 是否画线模式 + * * @return 是则返回true */ public boolean isDrawLineMode() { @@ -1173,6 +1205,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 设置DrawLineMode + * * @param mode 是or或 */ public void setDrawLineMode(boolean mode) { @@ -1199,6 +1232,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回表单控件权限编辑pane + * * @return 同上 */ public AuthorityEditPane createAuthorityEditPane() { @@ -1249,6 +1283,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 粘贴 + * * @return 否 */ @Override @@ -1259,6 +1294,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 剪切 + * * @return 否 */ @Override @@ -1273,6 +1309,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 工具栏菜单 + * * @return 同上 */ @Override @@ -1286,6 +1323,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 模版菜单 + * * @return 同上 */ @Override @@ -1295,6 +1333,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 权限菜单 + * * @return 同上 */ public ShortCut[] shortCuts4Authority() { @@ -1304,6 +1343,7 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回ToolBarDef + * * @return 同上 */ @Override @@ -1313,10 +1353,12 @@ public class FormDesigner extends TargetComponent implements TreeSelection /** * 返回工具栏按钮组件 + * * @return 同上 */ public JComponent[] toolBarButton4Form() { - return new JComponent[0]; + return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(), + new FormDeleteAction(this).createToolBarComponent()}; } diff --git a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java index fc6391225..202537c4a 100644 --- a/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java +++ b/designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java @@ -1,13 +1,13 @@ package com.fr.design.mainframe; -import java.awt.Component; -import java.awt.Rectangle; -import java.awt.Toolkit; +import java.awt.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import com.fr.base.FRContext; +import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; +import com.fr.form.ui.container.WLayout; import com.fr.general.ComparatorUtils; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.events.DesignerEvent; @@ -15,112 +15,199 @@ 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.XWAbsoluteLayout; -import com.fr.form.main.ClonedWidgetCreator; import com.fr.form.ui.Widget; public class FormSelectionUtils { - public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection selection, int x, - int y) { - LayoutAdapter adapter = parent.getLayoutAdapter(); - if (selection.size() == 1) { - try { - XCreator creator = selection.getSelectedCreator(); - Widget cloned = new ClonedWidgetCreator(designer.getTarget()).clonedWidgetWithNoRepeatName(creator - .toData()); - XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); - if (adapter.addBean(clondCreator, x + clondCreator.getWidth() / 2, y + clondCreator.getHeight() / 2)) { - designer.getSelectionModel().getSelection().setSelectedCreator(clondCreator); - designer.getEditListenerTable().fireCreatorModified(clondCreator, DesignerEvent.CREATOR_PASTED); - return; - } - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } else if (selection.size() > 1) { - if (parent instanceof XWAbsoluteLayout) { - designer.getSelectionModel().getSelection().reset(); - Rectangle rec = selection.getSelctionBounds(); - for (XCreator creator : selection.getSelectedCreators()) { - try { - Widget cloned = new ClonedWidgetCreator(designer.getTarget()) - .clonedWidgetWithNoRepeatName(creator.toData()); - XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); - // 设置位置,移动20x20,防止被粘帖的组件重叠,照顾表单布局情况下 - adapter.addBean(clondCreator, x + creator.getX() - rec.x + clondCreator.getWidth() / 2, y - + creator.getY() - rec.y + clondCreator.getHeight() / 2); - designer.getSelectionModel().getSelection().addSelectedCreator(clondCreator); - } catch (CloneNotSupportedException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - designer.getEditListenerTable().fireCreatorModified( - designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); - return; - } - } - Toolkit.getDefaultToolkit().beep(); - } - - public static void rebuildSelection(FormDesigner designer) { - ArrayList newSelection = new ArrayList(); - List widgetList = new ArrayList(); - for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { - widgetList.add(comp.toData()); - } - designer.getSelectionModel().setSelectedCreators( - rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); - } - - public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { - List selectionWidget = new ArrayList(); - if(selectWidgets != null){ - selectionWidget.addAll(Arrays.asList(selectWidgets)); - } - return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); - } - - private static ArrayList rebuildSelection(XCreator rootComponent, List selectionWidget, - ArrayList newSelection) { - FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); - if (newSelection.isEmpty()) { - newSelection.add(rootComponent); - } - return newSelection; - } - - private static void _rebuild(XCreator root, List selectionWidget, List newSelection) { - if (selectionWidget.isEmpty()) { - return; - } - for (Widget x : selectionWidget) { - if (ComparatorUtils.equals(x, root.toData())) { - if (!newSelection.contains(root)) { - newSelection.add(root); - selectionWidget.remove(x); - } - break; - } - } - - int count = root.getComponentCount(); - for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { - Component c = root.getComponent(i); - if (c instanceof XCreator) { - XCreator creator = (XCreator) c; - for (Widget x : selectionWidget) { - if (ComparatorUtils.equals(x, creator.toData())) { - newSelection.add(creator); - selectionWidget.remove(x); - break; - } - } - if (c instanceof XLayoutContainer) { - _rebuild((XLayoutContainer) c, selectionWidget, newSelection); - } else { - continue; - } - } - } - } + //组件复制时坐标偏移 + private static final int DELAY_X = 20; + private static final int DELAY_Y = 20; + + //组件复制时是否已经向左上偏移 + private static boolean BACK_OFFSET = false; + + //组件重命名后缀 + private static final String postfix = "_c"; + + /** + * @param designer 编辑器 + * @param parent 粘贴依据的组件 + * @param clipBoard 剪贴板内容 + * @param x x + * @param y y + */ + public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection clipBoard, int x, + int y) { + LayoutAdapter adapter = parent.getLayoutAdapter(); + if (parent instanceof XWAbsoluteLayout) { + designer.getSelectionModel().getSelection().reset(); + Rectangle rec = clipBoard.getSelctionBounds(); + for (XCreator creator : clipBoard.getSelectedCreators()) { + try { + Widget copied = copyWidget(designer, creator.toData()); + XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); + // 获取位置 + Point point = getPasteLocation((AbstractLayoutAdapter) adapter, + copiedCreator, + x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, + y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); + boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y); + + if (addSuccess) { + designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); + } + + } catch (CloneNotSupportedException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + } + rebuildSelection(designer); + designer.getEditListenerTable().fireCreatorModified( + designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); + return; + } + Toolkit.getDefaultToolkit().beep(); + } + + /** + * 组件复用绝对布局获取粘贴组件位置 + * + * @param layoutAdapter 绝对布局容器AbstractLayoutAdapter + * @param copiedCreator 复制的组件 + * @param x x=组件x + clonedCreator.getWidth() / 2 + * @param y y=组件y + clonedCreator.getHeight() / 2 + * 除2的步骤会导致当宽度或者高度为奇数是,中心点向左上各偏移一个像素 + * 由于中心点向左上各偏移一个像素,依赖中心点计算的右下点就会相应的想做上偏移一个像素,导致结果不准确 + * @return 新位置坐标 + */ + private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) { + //当宽度为奇数时 设置偏移 + int x_offset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0; + //当高度为奇数时 设置偏移 + int y_offset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0; + + if (!layoutAdapter.accept(copiedCreator, x, y)) { + XLayoutContainer container = layoutAdapter.getContainer(); + boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + x_offset > container.getWidth(); + boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + y_offset > container.getHeight(); + /* + * 组件原始位置位于布局的右下角, + * 和布局右下边界线紧挨, + * 粘贴时组件在原始位置向左错开20像素。 + * x,y同时越界 + */ + if (xOut && yOut) { + x = BACK_OFFSET ? container.getWidth() - copiedCreator.getWidth() / 2 - x_offset + : container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - x_offset; + y = BACK_OFFSET ? + container.getHeight() - copiedCreator.getHeight() / 2 - y_offset + : container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - y_offset; + BACK_OFFSET = !BACK_OFFSET; + return new Point(x, y); + } + /* + * 组件原始位置与布局边界距离小于20像素(下边界&右边界同时小于或者任意一个边界小于), + * 则粘贴时距离小于20像素一侧直接贴近布局边界, + * 距离大于20像素的一侧正常错开。 + * x,y中只有一个越界 + */ + else if ((xOut || yOut)) { + x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - x_offset : x; + y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - y_offset : y; + return new Point(x, y); + } + } + return new Point(x, y); + } + + + private static Widget copyWidget(FormDesigner formDesigner, Widget widget) throws + CloneNotSupportedException { + ArrayList clonedNameList = new ArrayList(); + Widget copied = (Widget) widget.clone(); + //重命名拷贝的组件 + setCopiedName(formDesigner, copied, clonedNameList); + if (copied instanceof WLayout) { + for (int i = 0; i < ((WLayout) copied).getWidgetCount(); i++) { + setCopiedName(formDesigner, ((WLayout) copied).getWidget(i), clonedNameList); + } + } + return copied; + } + + /** + * 组件拷贝命名规则 + * + * @param formDesigner + * @param copied + * @param clonedNameList + */ + private static void setCopiedName(FormDesigner formDesigner, Widget copied, ArrayList clonedNameList) { + String name = copied.getWidgetName(); + do { + name += postfix; + } while (formDesigner.getTarget().isNameExist(name) || clonedNameList.contains(name)); + copied.setWidgetName(name); + clonedNameList.add(name); + } + + public static void rebuildSelection(FormDesigner designer) { + ArrayList newSelection = new ArrayList(); + List widgetList = new ArrayList(); + for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { + widgetList.add(comp.toData()); + } + designer.getSelectionModel().setSelectedCreators( + rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); + } + + public static ArrayList rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { + List selectionWidget = new ArrayList(); + if (selectWidgets != null) { + selectionWidget.addAll(Arrays.asList(selectWidgets)); + } + return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList()); + } + + private static ArrayList rebuildSelection(XCreator rootComponent, List selectionWidget, + ArrayList newSelection) { + FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); + if (newSelection.isEmpty()) { + newSelection.add(rootComponent); + } + return newSelection; + } + + private static void _rebuild(XCreator root, List selectionWidget, List newSelection) { + if (selectionWidget.isEmpty()) { + return; + } + for (Widget x : selectionWidget) { + if (ComparatorUtils.equals(x, root.toData())) { + if (!newSelection.contains(root)) { + newSelection.add(root); + selectionWidget.remove(x); + } + break; + } + } + + int count = root.getComponentCount(); + for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { + Component c = root.getComponent(i); + if (c instanceof XCreator) { + XCreator creator = (XCreator) c; + for (Widget x : selectionWidget) { + if (ComparatorUtils.equals(x, creator.toData())) { + newSelection.add(creator); + selectionWidget.remove(x); + break; + } + } + if (c instanceof XLayoutContainer) { + _rebuild((XLayoutContainer) c, selectionWidget, newSelection); + } + } + } + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/mainframe/JForm.java b/designer_form/src/com/fr/design/mainframe/JForm.java index 7c912ede0..5fafd28e2 100644 --- a/designer_form/src/com/fr/design/mainframe/JForm.java +++ b/designer_form/src/com/fr/design/mainframe/JForm.java @@ -4,10 +4,12 @@ import com.fr.base.BaseUtils; import com.fr.design.DesignState; import com.fr.design.actions.core.WorkBookSupportable; import com.fr.design.actions.file.WebPreviewUtils; -import com.fr.design.mainframe.actions.FormMobileAttrAction; import com.fr.design.cell.FloatElementsProvider; import com.fr.design.constants.UIConstants; +import com.fr.design.designer.beans.actions.CopyAction; +import com.fr.design.designer.beans.actions.CutAction; import com.fr.design.designer.beans.actions.FormDeleteAction; +import com.fr.design.designer.beans.actions.PasteAction; import com.fr.design.designer.beans.events.DesignerEditListener; import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.creator.*; @@ -20,6 +22,7 @@ import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.xpane.FormHyperlinkGroupPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.actions.EmbeddedFormExportExportAction; +import com.fr.design.mainframe.actions.FormMobileAttrAction; import com.fr.design.mainframe.actions.TemplateParameterAction; import com.fr.design.mainframe.form.FormECCompositeProvider; import com.fr.design.mainframe.form.FormECDesignerProvider; @@ -264,10 +267,10 @@ public class JForm extends JTemplate implements BaseJForm { } - @Override /** - *焦点放到JForm + * 焦点放到JForm */ + @Override public void requestFocus() { super.requestFocus(); formDesign.requestFocus(); @@ -281,12 +284,12 @@ public class JForm extends JTemplate implements BaseJForm { formDesign.requestFocus(); } - @Override /** * 保存文件的后缀名 * * @return 返回后缀名 */ + @Override public String suffix() { // daniel改成三个字 return ".frm"; @@ -319,30 +322,33 @@ public class JForm extends JTemplate implements BaseJForm { formDesign.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED); } - @Override + /** - *复制 f + * 复制 */ + @Override public void copy() { this.formDesign.copy(); } - @Override + /** - * * 粘贴 + * * @return 是否成功 */ + @Override public boolean paste() { return this.formDesign.paste(); } - @Override + /** - * * 剪切 + * * @return 是否成功 */ + @Override public boolean cut() { return this.formDesign.cut(); } @@ -352,36 +358,38 @@ public class JForm extends JTemplate implements BaseJForm { // //////////////////////////////////////////////////////////////////// - @Override /** * 目标菜单 * * @return 菜单 */ + @Override public MenuDef[] menus4Target() { return this.index == FORM_TAB ? (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.formDesign.menus4Target()) : (MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.elementCaseDesign.menus4Target()); } - @Override + /** - * 模板的工具 + * 模板的工具 * * @return 工具 */ + @Override public ToolBarDef[] toolbars4Target() { return this.index == FORM_TAB ? this.formDesign.toolbars4Target() : this.elementCaseDesign.toolbars4Target(); } - @Override + /** * 模板菜单 * * @return 返回菜单 */ + @Override public ShortCut[] shortcut4TemplateMenu() { if (this.index == FORM_TAB) { return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{ @@ -407,11 +415,6 @@ public class JForm extends JTemplate implements BaseJForm { } @Override - /** - * undo的表单state - * - * @return 表单State - */ protected FormUndoState createUndoState() { FormUndoState cur = new FormUndoState(this, this.formDesign.getArea()); if (this.formDesign.isReportBlockEditing()) { @@ -445,17 +448,15 @@ public class JForm extends JTemplate implements BaseJForm { // 假如当前body是绝对布局的话就返回绝对布局body private XLayoutContainer selectedBodyLayout() { XLayoutContainer rootLayout = formDesign.getRootComponent(); - for (int i = 0; i < rootLayout.getComponentCount(); i++){ - if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)){ - rootLayout = (XWAbsoluteBodyLayout)rootLayout.getXCreator(i); + for (int i = 0; i < rootLayout.getComponentCount(); i++) { + if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)) { + rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(i); } } return rootLayout; } + @Override - /** - * 应用undoState的表单数据 - */ protected void applyUndoState(FormUndoState u) { try { //JForm的target重置 @@ -487,19 +488,11 @@ public class JForm extends JTemplate implements BaseJForm { } @Override - /** - * - */ protected FormModelAdapter createDesignModel() { return new FormModelAdapter(this); } @Override - /** - * 表单的工具栏 - * - * @return 表单工具栏 - */ public JPanel[] toolbarPanes4Form() { return this.index == FORM_TAB ? new JPanel[]{FormParaWidgetPane.getInstance(formDesign)} : @@ -514,10 +507,9 @@ public class JForm extends JTemplate implements BaseJForm { public JComponent[] toolBarButton4Form() { return this.index == FORM_TAB ? new JComponent[]{ - //自适应布局里的复制粘贴意义不大, 先屏蔽掉 -// new CutAction(formDesign).createToolBarComponent(), -// new CopyAction(formDesign).createToolBarComponent(), -// new PasteAction(formDesign).createToolBarComponent(), + new CutAction(formDesign).createToolBarComponent(), + new CopyAction(formDesign).createToolBarComponent(), + new PasteAction(formDesign).createToolBarComponent(), new FormDeleteAction(formDesign).createToolBarComponent()} : elementCaseDesign.toolBarButton4Form(); } diff --git a/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java b/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java index f79eca1a9..ac46da031 100644 --- a/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java +++ b/designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java @@ -251,7 +251,8 @@ public class MobileWidgetTable extends JTable { } //选择的控件 - Widget selectedModel = designer.getSelectionModel().getSelection().getSelectedCreator().toData(); + XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); + Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null; if(selectedModel == null){ return new String[0][0]; diff --git a/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java b/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java index 33736ac0a..9ea163d65 100644 --- a/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java +++ b/designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java @@ -155,11 +155,11 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper //只有放到JScrollPanel中去表头才能正常显示,这就是MobileWidgetTable中定义了表头却没有显示的原因! //解决方案:MobileWidgetTable实在无法直接放到JScrollPanel中去的时候,应该把表头get出来单独作为一个组件显示 - if(hasSelectParaPane(designer)){ - cardLayout.show(centerPane,PARA); + if (hasSelectParaPane(designer)) { + cardLayout.show(centerPane, PARA); header = mobileParaWidgetTable.getTableHeader(); } else { - cardLayout.show(centerPane,BODY); + cardLayout.show(centerPane, BODY); header = mobileWidgetTable.getTableHeader(); } downPanel = new UIScrollPane(centerPane); @@ -200,6 +200,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper /** * 判断是将拓展的tab放入属性表还是将原来的tab放入属性表 + * * @param widgetAttrProviders 拓展的tab */ private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) { @@ -219,6 +220,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper /** * 如果是body的拓展属性表,那么要额外加上一张控件顺序表 + * * @return */ private Component getExtraBodyTable(AbstractPropertyTable abstractPropertyTable) { @@ -243,18 +245,20 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp); } - // + /** * 选中的组件是否在参数面板里 - * @param designer 设计器 - * @return 是则返回true + * + * @param designer 设计器 + * @return 是则返回true */ - public boolean hasSelectParaPane(FormDesigner designer){ + public boolean hasSelectParaPane(FormDesigner designer) { XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator(); - if(xCreator == null){ + if (xCreator == null) { xCreator = designer.getRootComponent(); } XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator); + //TODO container可能为空,引发空指针异常 return xCreator.acceptType(XWParameterLayout.class) || container.acceptType(XWParameterLayout.class); } @@ -334,8 +338,9 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper } /** - * 响应界面改变事件 - * @param evt 事件 + * 响应界面改变事件 + * + * @param evt 事件 */ public void fireCreatorModified(DesignerEvent evt) { if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED @@ -343,11 +348,11 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper || evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED || evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) { int value = downPanel.getVerticalScrollBar().getValue(); - if(hasSelectParaPane(getEditingFormDesigner())){ - cardLayout.show(centerPane,PARA); + if (hasSelectParaPane(getEditingFormDesigner())) { + cardLayout.show(centerPane, PARA); mobileParaWidgetTable.refreshData(); } else { - cardLayout.show(centerPane,BODY); + cardLayout.show(centerPane, BODY); mobileWidgetTable.refreshData(); } //出现滚动条