From 91383d8d020026dee17b8ce0c6a42fd48344a2d7 Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 30 Dec 2022 13:38:05 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-13094=20=E6=94=AF=E6=8C=81frm=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6copy=E5=88=B0fvs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beans/models/ClipboardProvider.java | 18 ++++++++ .../models/DashboardClipboardManager.java | 45 +++++++++++++++++++ .../beans/models/FormSelectionClipboard.java | 45 +++++++++++++++++++ .../designer/beans/models/SelectionModel.java | 26 ++++++----- 4 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java create mode 100644 designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java create mode 100644 designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java new file mode 100644 index 0000000000..4382fc35f7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java @@ -0,0 +1,18 @@ +package com.fr.design.designer.beans.models; + +public interface ClipboardProvider { + + /** + * 剪切到剪贴板 + * + * @param o 剪切对象 + */ + void cut2Clipboard(Object o); + + /** + * 复制到剪贴板 + * + * @param o 复制对象 + */ + void copy2Clipboard(Object o); +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java new file mode 100644 index 0000000000..55cf2f12c7 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java @@ -0,0 +1,45 @@ +package com.fr.design.designer.beans.models; + +import java.util.ArrayList; +import java.util.List; + +/** + * 用来管理不同剪贴板,以及之间的数据同步 + */ +public class DashboardClipboardManager { + private static class Holder { + private static final DashboardClipboardManager HOLDER = new DashboardClipboardManager(); + } + + private static final List CLIPBOARD_LIST = new ArrayList<>(); + + + public void registerDashboardClipboard(ClipboardProvider clipboard) { + CLIPBOARD_LIST.add(clipboard); + } + + public void removeDashboardClipboard(ClipboardProvider clipboard) { + CLIPBOARD_LIST.remove(clipboard); + } + + public static DashboardClipboardManager getInstance() { + return Holder.HOLDER; + } + + private DashboardClipboardManager() { + } + + public void cut2Clipboard(Object o) { + for (ClipboardProvider clipboard : CLIPBOARD_LIST) { + //同步其他剪贴板 + clipboard.cut2Clipboard(o); + } + } + + public void copy2Clipboard(Object o) { + for (ClipboardProvider clipboard : CLIPBOARD_LIST) { + //同步其他剪贴板 + clipboard.copy2Clipboard(o); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java new file mode 100644 index 0000000000..a190532769 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java @@ -0,0 +1,45 @@ +package com.fr.design.designer.beans.models; + +import com.fr.design.mainframe.FormSelection; + +public class FormSelectionClipboard implements ClipboardProvider { + private static final FormSelection FRM_CLIPBOARD = new FormSelection(); + + static { + DashboardClipboardManager.getInstance().registerDashboardClipboard(FormSelectionClipboard.getInstance()); + } + + private static class Holder { + private static final FormSelectionClipboard HOLDER = new FormSelectionClipboard(); + } + + public static FormSelectionClipboard getInstance() { + return Holder.HOLDER; + } + + private FormSelectionClipboard() { + } + + + public boolean isEmpty() { + return FRM_CLIPBOARD.isEmpty(); + } + + public FormSelection getClipboard() { + return FRM_CLIPBOARD; + } + + @Override + public void cut2Clipboard(Object o) { + if (o instanceof FormSelection) { + ((FormSelection) o).cut2ClipBoard(FRM_CLIPBOARD); + } + } + + @Override + public void copy2Clipboard(Object o) { + if (o instanceof FormSelection) { + ((FormSelection) o).copy2ClipBoard(FRM_CLIPBOARD); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java index f75e08d723..807325a3b4 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java @@ -46,12 +46,14 @@ public class SelectionModel { //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 private static final double OFFSET_RELATIVE = 0.80; - private static FormSelection clipboard = new FormSelection(); + private static FormSelectionClipboard formClipboard = FormSelectionClipboard.getInstance(); private FormDesigner designer; private FormSelection selection; private Rectangle hotspotBounds; private FormWidgetOptionProvider provider; + + public SelectionModel(FormDesigner designer) { this.designer = designer; selection = new FormSelection(); @@ -71,7 +73,7 @@ public class SelectionModel { * @return 是否为空 */ public static boolean isEmpty() { - return clipboard.isEmpty(); + return formClipboard.isEmpty(); } /** @@ -161,7 +163,7 @@ public class SelectionModel { if (hasSelectionComponent()) { FormSelection cutSelection = ClipboardFilter.cut(selection); if (cutSelection != null) { - cutSelection.cut2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().cut2Clipboard(cutSelection); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); setSelectedCreator(hasSelectedParaComponent() ? designer.getParaComponent() : designer.getRootComponent()); designer.repaint(); @@ -192,7 +194,7 @@ public class SelectionModel { if (!selection.isEmpty()) { FormSelection copySelection = ClipboardFilter.copy(selection); if (copySelection != null) { - copySelection.copy2ClipBoard(clipboard); + DashboardClipboardManager.getInstance().copy2Clipboard(copySelection); } } } @@ -203,7 +205,7 @@ public class SelectionModel { * @return 否 */ public boolean pasteFromClipBoard() { - FormSelection pasteSelection = ClipboardFilter.paste(clipboard); + FormSelection pasteSelection = ClipboardFilter.paste(formClipboard.getClipboard()); if (pasteSelection != null && !pasteSelection.isEmpty()) { if (!hasSelectedPasteSource()) { //未选 @@ -240,7 +242,7 @@ public class SelectionModel { //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //当前选择的就是编辑器表层 FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -248,7 +250,7 @@ public class SelectionModel { //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 //使用selection.getSelectedCreator()也应该是可以获取到的。 FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), DELTA_X_Y, DELTA_X_Y); } @@ -266,7 +268,7 @@ public class SelectionModel { if (hasSelectedPasteSource()) { selectedPaste(); } else { - FormSelectionUtils.paste2Container(designer, container, clipboard, + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -281,7 +283,7 @@ public class SelectionModel { selectedPaste(); } else { FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), - clipboard, + formClipboard.getClipboard(), rectangle.x + rectangle.width / 2, rectangle.y + DELTA_X_Y); } @@ -314,13 +316,13 @@ public class SelectionModel { positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); } - FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), positionX, positionY); } else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) { //绝对布局 Rectangle rec = selection.getSelctionBounds(); - FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); + FormSelectionUtils.paste2Container(designer, container, formClipboard.getClipboard(), rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); } else if (isExtraContainer(container)) { - provider.paste2Container(clipboard); + provider.paste2Container(formClipboard.getClipboard()); } }