Browse Source

Pull request #11133: KERNEL-13094 支持frm的组件copy到fvs

Merge in DESIGN/design from ~KERRY/design_10.0:release/11.0 to release/11.0

* commit '91383d8d020026dee17b8ce0c6a42fd48344a2d7':
  KERNEL-13094 支持frm的组件copy到fvs
newui
kerry-王周勇 2 years ago
parent
commit
dbf0b84abe
  1. 18
      designer-form/src/main/java/com/fr/design/designer/beans/models/ClipboardProvider.java
  2. 45
      designer-form/src/main/java/com/fr/design/designer/beans/models/DashboardClipboardManager.java
  3. 45
      designer-form/src/main/java/com/fr/design/designer/beans/models/FormSelectionClipboard.java
  4. 26
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java

18
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);
}

45
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<ClipboardProvider> 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);
}
}
}

45
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);
}
}
}

26
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());
}
}

Loading…
Cancel
Save