plough
8 years ago
38 changed files with 7332 additions and 6742 deletions
@ -0,0 +1,70 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.7 |
||||
//指定生成jar包版本 |
||||
version='8.0' |
||||
//生成jar包重命名 |
||||
jar{ |
||||
baseName='fr-designer-core' |
||||
} |
||||
|
||||
|
||||
def srcDir="." |
||||
|
||||
//指定源码路径 |
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=["${srcDir}/src"] |
||||
} |
||||
} |
||||
} |
||||
//获取什么分支名 |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) |
||||
buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) |
||||
|
||||
//声明外部依赖 |
||||
dependencies{ |
||||
|
||||
compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") |
||||
|
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
//复制非.java文件到classes文件夹下参与打包 |
||||
task copyFile(type:Copy,dependsOn:compileJava){ |
||||
copy{ |
||||
from ("${srcDir}/src"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
} |
||||
into 'build/classes/main' |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
//压缩项目中的js文件 |
||||
task compressJS{ |
||||
ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ |
||||
classpath { |
||||
fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') |
||||
} |
||||
} |
||||
ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ |
||||
fileset (dir:"${srcDir}/src"){ |
||||
include (name:'**/*.js') |
||||
include (name:'**/*.css') |
||||
} |
||||
|
||||
} |
||||
} |
||||
jar.dependsOn compressJS |
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1 +1,66 @@
|
||||
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);
} |
||||
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); |
||||
} |
@ -1 +1,72 @@
|
||||
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<String> 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();
} |
||||
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<String> 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(); |
||||
|
||||
} |
@ -0,0 +1,85 @@
|
||||
|
||||
apply plugin: 'java' |
||||
tasks.withType(JavaCompile){ |
||||
options.encoding = 'UTF-8' |
||||
} |
||||
|
||||
buildscript { |
||||
repositories { |
||||
maven { |
||||
url "http://www.eveoh.nl/files/maven2" |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
classpath "nl.eveoh:gradle-aspectj:1.2" |
||||
} |
||||
} |
||||
|
||||
ext.aspectjVersion = '1.7.4' |
||||
apply plugin: 'aspectj' |
||||
|
||||
repositories { |
||||
mavenCentral() |
||||
} |
||||
//指定构建的jdk版本 |
||||
sourceCompatibility=1.7 |
||||
//指定生成jar包的版本 |
||||
version='8.0' |
||||
|
||||
def srcDir="." |
||||
|
||||
//对生成的jar包进行重命名 |
||||
|
||||
jar{ |
||||
baseName='fr-designer-chart' |
||||
} |
||||
|
||||
sourceSets{ |
||||
main{ |
||||
java{ |
||||
srcDirs=["${srcDir}/src"] |
||||
} |
||||
} |
||||
} |
||||
FileTree files =fileTree(dir:'./',include:'build.*.gradle') |
||||
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\')) |
||||
buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\')) |
||||
def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1) |
||||
|
||||
//指定外部依赖 |
||||
dependencies{ |
||||
compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar') |
||||
compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar") |
||||
|
||||
testCompile 'junit:junit:4.12' |
||||
} |
||||
//将非.java 文件复制到classes文件夹下参与打包 |
||||
task copyFile(type:Copy,dependsOn:compileJava){ |
||||
copy{ |
||||
from ("${srcDir}/src"){ |
||||
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' |
||||
|
||||
} |
||||
into 'build/classes/main' |
||||
} |
||||
|
||||
} |
||||
|
||||
//压缩项目中的js文件 |
||||
task compressJS{ |
||||
ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){ |
||||
classpath { |
||||
fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar') |
||||
} |
||||
} |
||||
ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){ |
||||
fileset (dir:"${srcDir}/src"){ |
||||
include (name:'**/*.js') |
||||
include (name:'**/*.css') |
||||
} |
||||
|
||||
} |
||||
} |
||||
jar.dependsOn compressJS |
||||
|
@ -1,31 +1,30 @@
|
||||
package com.fr.design.designer.beans.actions; |
||||
|
||||
import java.awt.event.InputEvent; |
||||
import java.awt.event.KeyEvent; |
||||
|
||||
import javax.swing.KeyStroke; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.design.mainframe.FormDesigner; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.event.InputEvent; |
||||
import java.awt.event.KeyEvent; |
||||
|
||||
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; |
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,126 +1,270 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import java.awt.Component; |
||||
import java.awt.Rectangle; |
||||
import java.awt.Toolkit; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.design.designer.beans.LayoutAdapter; |
||||
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter; |
||||
import com.fr.design.designer.beans.events.DesignerEvent; |
||||
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.design.designer.creator.*; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.form.ui.container.WTitleLayout; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
import java.awt.*; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
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<XCreator> newSelection = new ArrayList<XCreator>(); |
||||
List<Widget> widgetList = new ArrayList<Widget>(); |
||||
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { |
||||
widgetList.add(comp.toData()); |
||||
} |
||||
designer.getSelectionModel().setSelectedCreators( |
||||
rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); |
||||
} |
||||
|
||||
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { |
||||
List<Widget> selectionWidget = new ArrayList<Widget>(); |
||||
if(selectWidgets != null){ |
||||
selectionWidget.addAll(Arrays.asList(selectWidgets)); |
||||
} |
||||
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>()); |
||||
} |
||||
|
||||
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, |
||||
ArrayList<XCreator> newSelection) { |
||||
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); |
||||
if (newSelection.isEmpty()) { |
||||
newSelection.add(rootComponent); |
||||
} |
||||
return newSelection; |
||||
} |
||||
|
||||
private static void _rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> 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 backoffset = false; |
||||
|
||||
//组件重命名后缀
|
||||
private static final String POSTFIX = "_c"; |
||||
|
||||
private FormSelectionUtils() { |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @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) { |
||||
//绝对布局
|
||||
absolutePaste(designer, clipboard, adapter, x, y); |
||||
return; |
||||
} else if (parent instanceof XWFitLayout) { |
||||
//相对布局
|
||||
relativePaste(designer, clipboard, adapter, x, y); |
||||
return; |
||||
} |
||||
Toolkit.getDefaultToolkit().beep(); |
||||
} |
||||
|
||||
/** |
||||
* 绝对布局粘贴 |
||||
* |
||||
* @param designer |
||||
* @param clipboard |
||||
* @param adapter |
||||
* @param x |
||||
* @param y |
||||
*/ |
||||
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||
|
||||
designer.getSelectionModel().getSelection().reset(); |
||||
Rectangle rec = clipboard.getSelctionBounds(); |
||||
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||
try { |
||||
Widget copied = copyWidget(designer, creator); |
||||
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); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 相对布局粘贴 |
||||
* |
||||
* @param designer |
||||
* @param clipboard |
||||
* @param adapter |
||||
* @param x |
||||
* @param y |
||||
*/ |
||||
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||
designer.getSelectionModel().getSelection().reset(); |
||||
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||
try { |
||||
Widget copied = copyWidget(designer, creator); |
||||
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); |
||||
boolean addSuccess = adapter.addBean(copiedCreator, x, 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); |
||||
} |
||||
|
||||
/** |
||||
* 组件复用绝对布局获取粘贴组件位置 |
||||
* |
||||
* @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 xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0; |
||||
//当高度为奇数时 设置偏移
|
||||
int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0; |
||||
|
||||
if (!layoutAdapter.accept(copiedCreator, x, y)) { |
||||
XLayoutContainer container = layoutAdapter.getContainer(); |
||||
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth(); |
||||
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight(); |
||||
/* |
||||
* 组件原始位置位于布局的右下角, |
||||
* 和布局右下边界线紧挨, |
||||
* 粘贴时组件在原始位置向左错开20像素。 |
||||
* x,y同时越界 |
||||
*/ |
||||
if (xOut && yOut) { |
||||
x = backoffset ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset |
||||
: container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - xoffset; |
||||
y = backoffset ? |
||||
container.getHeight() - copiedCreator.getHeight() / 2 - yoffset |
||||
: container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - yoffset; |
||||
backoffset = !backoffset; |
||||
return new Point(x, y); |
||||
} |
||||
/* |
||||
* 组件原始位置与布局边界距离小于20像素(下边界&右边界同时小于或者任意一个边界小于), |
||||
* 则粘贴时距离小于20像素一侧直接贴近布局边界, |
||||
* 距离大于20像素的一侧正常错开。 |
||||
* x,y中只有一个越界 |
||||
*/ |
||||
else if ((xOut || yOut)) { |
||||
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x; |
||||
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y; |
||||
return new Point(x, y); |
||||
} |
||||
} |
||||
return new Point(x, y); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 拷贝组件 |
||||
* |
||||
* @param formDesigner |
||||
* @param xCreator |
||||
* @return |
||||
* @throws CloneNotSupportedException |
||||
*/ |
||||
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws |
||||
CloneNotSupportedException { |
||||
ArrayList<String> nameSpace = new ArrayList<String>(); |
||||
Widget copied = (Widget) xCreator.toData().clone(); |
||||
//重命名拷贝的组件
|
||||
String name = getCopiedName(formDesigner, copied, nameSpace); |
||||
if (copied instanceof WTitleLayout) { |
||||
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) copied, xCreator.getSize()); |
||||
xwTitleLayout.resetCreatorName(name); |
||||
} else { |
||||
copied.setWidgetName(name); |
||||
} |
||||
return copied; |
||||
} |
||||
|
||||
/** |
||||
* 组件拷贝命名规则 |
||||
* |
||||
* @param formDesigner |
||||
* @param copied |
||||
* @param nameSpace |
||||
* @return name |
||||
*/ |
||||
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) { |
||||
StringBuffer name = new StringBuffer(copied.getWidgetName()); |
||||
do { |
||||
name.append(POSTFIX); |
||||
} while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString())); |
||||
nameSpace.add(name.toString()); |
||||
return name.toString(); |
||||
} |
||||
|
||||
public static void rebuildSelection(FormDesigner designer) { |
||||
ArrayList<XCreator> newSelection = new ArrayList<XCreator>(); |
||||
List<Widget> widgetList = new ArrayList<Widget>(); |
||||
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { |
||||
widgetList.add(comp.toData()); |
||||
} |
||||
designer.getSelectionModel().setSelectedCreators( |
||||
rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); |
||||
} |
||||
|
||||
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { |
||||
List<Widget> selectionWidget = new ArrayList<Widget>(); |
||||
if (selectWidgets != null) { |
||||
selectionWidget.addAll(Arrays.asList(selectWidgets)); |
||||
} |
||||
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>()); |
||||
} |
||||
|
||||
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, |
||||
ArrayList<XCreator> newSelection) { |
||||
FormSelectionUtils.rebuild(rootComponent, selectionWidget, newSelection); |
||||
if (newSelection.isEmpty()) { |
||||
newSelection.add(rootComponent); |
||||
} |
||||
return newSelection; |
||||
} |
||||
|
||||
private static void rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> 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); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue