forked from fanruan/design
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; |
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.base.BaseUtils; |
||||||
import com.fr.general.Inter; |
|
||||||
import com.fr.design.mainframe.FormDesigner; |
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 class CopyAction extends FormEditAction { |
||||||
|
|
||||||
public CopyAction(FormDesigner t) { |
public CopyAction(FormDesigner t) { |
||||||
super(t); |
super(t); |
||||||
this.setName(Inter.getLocText("M_Edit-Copy")); |
this.setName(Inter.getLocText("M_Edit-Copy")); |
||||||
this.setMnemonic('C'); |
this.setMnemonic('C'); |
||||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); |
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png")); |
||||||
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); |
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public boolean executeActionReturnUndoRecordNeeded() { |
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
FormDesigner tc = getEditingComponent(); |
FormDesigner tc = getEditingComponent(); |
||||||
if (tc != null) { |
if (tc != null) { |
||||||
tc.copy(); |
tc.copy(); |
||||||
} |
} |
||||||
return false; |
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; |
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.base.FRContext; |
||||||
import com.fr.general.ComparatorUtils; |
|
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
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.beans.events.DesignerEvent; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.designer.creator.*; |
||||||
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; |
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 class FormSelectionUtils { |
||||||
|
|
||||||
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection selection, int x, |
//组件复制时坐标偏移
|
||||||
int y) { |
private static final int DELAY_X = 20; |
||||||
LayoutAdapter adapter = parent.getLayoutAdapter(); |
private static final int DELAY_Y = 20; |
||||||
if (selection.size() == 1) { |
|
||||||
try { |
//组件复制时是否已经向左上偏移
|
||||||
XCreator creator = selection.getSelectedCreator(); |
private static boolean backoffset = false; |
||||||
Widget cloned = new ClonedWidgetCreator(designer.getTarget()).clonedWidgetWithNoRepeatName(creator |
|
||||||
.toData()); |
//组件重命名后缀
|
||||||
XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); |
private static final String POSTFIX = "_c"; |
||||||
if (adapter.addBean(clondCreator, x + clondCreator.getWidth() / 2, y + clondCreator.getHeight() / 2)) { |
|
||||||
designer.getSelectionModel().getSelection().setSelectedCreator(clondCreator); |
private FormSelectionUtils() { |
||||||
designer.getEditListenerTable().fireCreatorModified(clondCreator, DesignerEvent.CREATOR_PASTED); |
|
||||||
return; |
} |
||||||
} |
|
||||||
} catch (CloneNotSupportedException e) { |
/** |
||||||
FRContext.getLogger().error(e.getMessage(), e); |
* @param designer 编辑器 |
||||||
} |
* @param parent 粘贴依据的组件 |
||||||
} else if (selection.size() > 1) { |
* @param clipboard 剪贴板内容 |
||||||
if (parent instanceof XWAbsoluteLayout) { |
* @param x x |
||||||
designer.getSelectionModel().getSelection().reset(); |
* @param y y |
||||||
Rectangle rec = selection.getSelctionBounds(); |
*/ |
||||||
for (XCreator creator : selection.getSelectedCreators()) { |
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, |
||||||
try { |
FormSelection clipboard, int x, int y) { |
||||||
Widget cloned = new ClonedWidgetCreator(designer.getTarget()) |
LayoutAdapter adapter = parent.getLayoutAdapter(); |
||||||
.clonedWidgetWithNoRepeatName(creator.toData()); |
if (parent instanceof XWAbsoluteLayout) { |
||||||
XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); |
//绝对布局
|
||||||
// 设置位置,移动20x20,防止被粘帖的组件重叠,照顾表单布局情况下
|
absolutePaste(designer, clipboard, adapter, x, y); |
||||||
adapter.addBean(clondCreator, x + creator.getX() - rec.x + clondCreator.getWidth() / 2, y |
return; |
||||||
+ creator.getY() - rec.y + clondCreator.getHeight() / 2); |
} else if (parent instanceof XWFitLayout) { |
||||||
designer.getSelectionModel().getSelection().addSelectedCreator(clondCreator); |
//相对布局
|
||||||
} catch (CloneNotSupportedException e) { |
relativePaste(designer, clipboard, adapter, x, y); |
||||||
FRContext.getLogger().error(e.getMessage(), e); |
return; |
||||||
} |
} |
||||||
} |
Toolkit.getDefaultToolkit().beep(); |
||||||
designer.getEditListenerTable().fireCreatorModified( |
} |
||||||
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
|
||||||
return; |
/** |
||||||
} |
* 绝对布局粘贴 |
||||||
} |
* |
||||||
Toolkit.getDefaultToolkit().beep(); |
* @param designer |
||||||
} |
* @param clipboard |
||||||
|
* @param adapter |
||||||
public static void rebuildSelection(FormDesigner designer) { |
* @param x |
||||||
ArrayList<XCreator> newSelection = new ArrayList<XCreator>(); |
* @param y |
||||||
List<Widget> widgetList = new ArrayList<Widget>(); |
*/ |
||||||
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { |
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||||
widgetList.add(comp.toData()); |
|
||||||
} |
designer.getSelectionModel().getSelection().reset(); |
||||||
designer.getSelectionModel().setSelectedCreators( |
Rectangle rec = clipboard.getSelctionBounds(); |
||||||
rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); |
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||||
} |
try { |
||||||
|
Widget copied = copyWidget(designer, creator); |
||||||
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { |
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); |
||||||
List<Widget> selectionWidget = new ArrayList<Widget>(); |
// 获取位置
|
||||||
if(selectWidgets != null){ |
Point point = getPasteLocation((AbstractLayoutAdapter) adapter, |
||||||
selectionWidget.addAll(Arrays.asList(selectWidgets)); |
copiedCreator, |
||||||
} |
x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, |
||||||
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>()); |
y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); |
||||||
} |
boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y); |
||||||
|
if (addSuccess) { |
||||||
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, |
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); |
||||||
ArrayList<XCreator> newSelection) { |
} |
||||||
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); |
} catch (CloneNotSupportedException e) { |
||||||
if (newSelection.isEmpty()) { |
FRContext.getLogger().error(e.getMessage(), e); |
||||||
newSelection.add(rootComponent); |
} |
||||||
} |
} |
||||||
return newSelection; |
rebuildSelection(designer); |
||||||
} |
designer.getEditListenerTable().fireCreatorModified( |
||||||
|
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
||||||
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)) { |
* @param designer |
||||||
newSelection.add(root); |
* @param clipboard |
||||||
selectionWidget.remove(x); |
* @param adapter |
||||||
} |
* @param x |
||||||
break; |
* @param y |
||||||
} |
*/ |
||||||
} |
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||||
|
designer.getSelectionModel().getSelection().reset(); |
||||||
int count = root.getComponentCount(); |
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||||
for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { |
try { |
||||||
Component c = root.getComponent(i); |
Widget copied = copyWidget(designer, creator); |
||||||
if (c instanceof XCreator) { |
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); |
||||||
XCreator creator = (XCreator) c; |
boolean addSuccess = adapter.addBean(copiedCreator, x, y); |
||||||
for (Widget x : selectionWidget) { |
if (addSuccess) { |
||||||
if (ComparatorUtils.equals(x, creator.toData())) { |
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); |
||||||
newSelection.add(creator); |
} |
||||||
selectionWidget.remove(x); |
} catch (CloneNotSupportedException e) { |
||||||
break; |
FRContext.getLogger().error(e.getMessage(), e); |
||||||
} |
} |
||||||
} |
} |
||||||
if (c instanceof XLayoutContainer) { |
rebuildSelection(designer); |
||||||
_rebuild((XLayoutContainer) c, selectionWidget, newSelection); |
designer.getEditListenerTable().fireCreatorModified( |
||||||
} else { |
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
||||||
continue; |
} |
||||||
} |
|
||||||
} |
/** |
||||||
} |
* 组件复用绝对布局获取粘贴组件位置 |
||||||
} |
* |
||||||
|
* @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