daniel
8 years ago
72 changed files with 6619 additions and 5733 deletions
@ -1,6 +1,5 @@ |
|||||||
package com.fr.design.mainframe.templateinfo; |
package com.fr.design.mainframe.templateinfo; |
||||||
|
|
||||||
import com.fr.base.io.IOFile; |
|
||||||
import com.fr.base.parameter.ParameterUI; |
import com.fr.base.parameter.ParameterUI; |
||||||
import com.fr.main.impl.WorkBook; |
import com.fr.main.impl.WorkBook; |
||||||
import com.fr.report.cellcase.CellCase; |
import com.fr.report.cellcase.CellCase; |
@ -0,0 +1,89 @@ |
|||||||
|
|
||||||
|
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' |
||||||
|
//生成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 |
||||||
|
|
||||||
|
|
||||||
|
|
@ -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; |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
@ -1,328 +1,434 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import java.awt.LayoutManager; |
|
||||||
import java.awt.Rectangle; |
|
||||||
import java.awt.Toolkit; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.util.ArrayList; |
|
||||||
|
|
||||||
import com.fr.design.designer.beans.AdapterBus; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
import com.fr.design.designer.beans.LayoutAdapter; |
||||||
import com.fr.design.designer.beans.events.DesignerEvent; |
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
import com.fr.design.designer.beans.location.Direction; |
import com.fr.design.designer.beans.location.Direction; |
||||||
import com.fr.design.designer.beans.location.Location; |
import com.fr.design.designer.beans.location.Location; |
||||||
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.cardlayout.XWCardLayout; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; |
||||||
import com.fr.design.designer.creator.XWFitLayout; |
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; |
||||||
import com.fr.design.designer.creator.XWParameterLayout; |
|
||||||
import com.fr.design.form.util.XCreatorConstants; |
import com.fr.design.form.util.XCreatorConstants; |
||||||
import com.fr.design.mainframe.FormDesigner; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.mainframe.FormSelection; |
import com.fr.design.mainframe.FormSelection; |
||||||
import com.fr.design.mainframe.FormSelectionUtils; |
import com.fr.design.mainframe.FormSelectionUtils; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
import com.fr.design.utils.gui.LayoutUtils; |
import com.fr.design.utils.gui.LayoutUtils; |
||||||
import com.fr.stable.ArrayUtils; |
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
/** |
/** |
||||||
* 该model保存当前选择的组件和剪切版信息 |
* 该model保存当前选择的组件和剪切版信息 |
||||||
*/ |
*/ |
||||||
public class SelectionModel { |
public class SelectionModel { |
||||||
|
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
|
||||||
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
|
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
|
||||||
private static FormSelection CLIP_BOARD = new FormSelection(); |
private static final double OFFSET_RELATIVE = 0.80; |
||||||
private FormDesigner designer; |
private static FormSelection clipboard = new FormSelection(); |
||||||
private FormSelection selection; |
private FormDesigner designer; |
||||||
private Rectangle hotspot_bounds; |
private FormSelection selection; |
||||||
|
private Rectangle hotspotBounds; |
||||||
public SelectionModel(FormDesigner designer) { |
|
||||||
this.designer = designer; |
public SelectionModel(FormDesigner designer) { |
||||||
selection = new FormSelection(); |
this.designer = designer; |
||||||
} |
selection = new FormSelection(); |
||||||
|
} |
||||||
/** |
|
||||||
* 重置。清空formSelction以及选择区域 |
/** |
||||||
*/ |
* 重置。清空formSelction以及选择区域 |
||||||
public void reset() { |
*/ |
||||||
selection.reset(); |
public void reset() { |
||||||
hotspot_bounds = null; |
selection.reset(); |
||||||
} |
hotspotBounds = null; |
||||||
|
} |
||||||
/** |
|
||||||
* formSelction是否为空 |
/** |
||||||
* @return 是否为空 |
* formSelction是否为空 |
||||||
*/ |
* |
||||||
public static boolean isEmpty(){ |
* @return 是否为空 |
||||||
return CLIP_BOARD.isEmpty(); |
*/ |
||||||
} |
public static boolean isEmpty() { |
||||||
|
return clipboard.isEmpty(); |
||||||
/** |
} |
||||||
* 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 |
|
||||||
* @param e 鼠标事件 |
/** |
||||||
*/ |
* 鼠标点击一下,所选中的单个组件。按下Ctrl或者shift键时鼠标可以进行多选 |
||||||
public void selectACreatorAtMouseEvent(MouseEvent e) { |
* |
||||||
if (!e.isControlDown() && !e.isShiftDown()) { |
* @param e 鼠标事件 |
||||||
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
|
*/ |
||||||
selection.reset(); |
public void selectACreatorAtMouseEvent(MouseEvent e) { |
||||||
} |
if (!e.isControlDown() && !e.isShiftDown()) { |
||||||
|
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
|
||||||
// 获取e所在的组件
|
selection.reset(); |
||||||
XCreator comp = designer.getComponentAt(e); |
} |
||||||
|
// 获取e所在的组件
|
||||||
//布局组件的顶层布局如不可编辑,要获取其顶层布局
|
XCreator comp = designer.getComponentAt(e); |
||||||
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); |
|
||||||
if(topLayout != null && !topLayout.isEditable()){ |
//布局组件的顶层布局如不可编辑,要获取其顶层布局
|
||||||
comp = topLayout; |
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout(); |
||||||
} |
if (topLayout != null && !topLayout.isEditable()) { |
||||||
|
comp = topLayout; |
||||||
// 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的
|
} |
||||||
if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { |
|
||||||
XCreator parentContainer = (XCreator) comp.getParent(); |
// 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的
|
||||||
comp = parentContainer.isDedicateContainer() ? parentContainer : comp; |
if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) { |
||||||
} |
XCreator parentContainer = (XCreator) comp.getParent(); |
||||||
if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { |
comp = parentContainer.isDedicateContainer() ? parentContainer : comp; |
||||||
designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); |
} |
||||||
designer.repaint(); |
if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) { |
||||||
} |
designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED); |
||||||
} |
designer.repaint(); |
||||||
|
} |
||||||
/** |
} |
||||||
* 将所选组件剪切到剪切板上 |
|
||||||
*/ |
/** |
||||||
public void cutSelectedCreator2ClipBoard() { |
* 将所选组件剪切到剪切板上 |
||||||
if (hasSelectionComponent()) { |
*/ |
||||||
selection.cut2ClipBoard(CLIP_BOARD); |
public void cutSelectedCreator2ClipBoard() { |
||||||
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); |
if (hasSelectionComponent()) { |
||||||
designer.repaint(); |
selection.cut2ClipBoard(clipboard); |
||||||
} |
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); |
||||||
} |
designer.repaint(); |
||||||
|
} |
||||||
/** |
} |
||||||
* 复制当前选中的组件到剪切板 |
|
||||||
*/ |
/** |
||||||
public void copySelectedCreator2ClipBoard() { |
* 复制当前选中的组件到剪切板 |
||||||
if (!selection.isEmpty()) { |
*/ |
||||||
selection.copy2ClipBoard(CLIP_BOARD); |
public void copySelectedCreator2ClipBoard() { |
||||||
} |
if (!selection.isEmpty()) { |
||||||
} |
selection.copy2ClipBoard(clipboard); |
||||||
|
} |
||||||
/** |
} |
||||||
* 从剪切板粘帖组件 |
|
||||||
* @return 否 |
/** |
||||||
*/ |
* 从剪切板粘帖组件 |
||||||
public boolean pasteFromClipBoard() { |
* |
||||||
if (!CLIP_BOARD.isEmpty()) { |
* @return 否 |
||||||
XLayoutContainer parent = null; |
*/ |
||||||
if (!hasSelectionComponent()) { |
public boolean pasteFromClipBoard() { |
||||||
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),CLIP_BOARD, DELTA_X_Y, DELTA_X_Y); |
if (!clipboard.isEmpty()) { |
||||||
} else { |
if (!hasSelectedPasteSource()) { |
||||||
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); |
//未选
|
||||||
if (parent != null) { |
unselectedPaste(); |
||||||
Rectangle rec = selection.getSelctionBounds(); |
} else { |
||||||
FormSelectionUtils.paste2Container(designer, parent,CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y); |
//已选
|
||||||
} |
selectedPaste(); |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
Toolkit.getDefaultToolkit().beep(); |
Toolkit.getDefaultToolkit().beep(); |
||||||
} |
} |
||||||
return false; |
return false; |
||||||
} |
} |
||||||
|
|
||||||
public FormSelection getSelection() { |
public FormSelection getSelection() { |
||||||
return selection; |
return selection; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 删除当前所有选择的组件 |
* 粘贴时未选择组件 |
||||||
*/ |
*/ |
||||||
public void deleteSelection() { |
private void unselectedPaste() { |
||||||
XCreator[] roots = selection.getSelectedCreators(); |
if (designer.getClass().equals(FormDesigner.class)) { |
||||||
|
if (selection.getSelectedCreator() instanceof XWFitLayout) { |
||||||
if (roots.length > 0) { |
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { |
||||||
for (XCreator creator : roots) { |
Rectangle rec = selection.getRelativeBounds(); |
||||||
if(creator.acceptType(XWParameterLayout.class)){ |
//Tab布局
|
||||||
designer.removeParaComponent(); |
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), |
||||||
|
clipboard, |
||||||
|
rec.x + rec.width / 2, |
||||||
|
rec.y + DELTA_X_Y); |
||||||
|
} else { |
||||||
|
Rectangle rec = selection.getRelativeBounds(); |
||||||
|
//自适应布局
|
||||||
|
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), |
||||||
|
clipboard, |
||||||
|
rec.x + rec.width / 2, |
||||||
|
rec.y + DELTA_X_Y); |
||||||
} |
} |
||||||
|
} else { |
||||||
|
//绝对布局
|
||||||
|
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
|
||||||
|
//当前选择的就是编辑器表层
|
||||||
|
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), |
||||||
|
clipboard, |
||||||
|
DELTA_X_Y, |
||||||
|
DELTA_X_Y); |
||||||
|
} |
||||||
|
} else { |
||||||
|
//cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到
|
||||||
|
//使用selection.getSelectedCreator()也应该是可以获取到的。
|
||||||
|
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), |
||||||
|
clipboard, |
||||||
|
DELTA_X_Y, |
||||||
|
DELTA_X_Y); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 粘贴时选择组件 |
||||||
|
*/ |
||||||
|
private void selectedPaste() { |
||||||
|
XLayoutContainer container = null; |
||||||
|
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
|
||||||
|
container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); |
||||||
|
if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) { |
||||||
|
//自适应布局
|
||||||
|
Rectangle selectionRec = selection.getRelativeBounds(); |
||||||
|
Rectangle containerRec = ComponentUtils.getRelativeBounds(container); |
||||||
|
//计算自适应布局位置
|
||||||
|
int positionX = selectionRec.x - containerRec.x + selectionRec.width / 2; |
||||||
|
int positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE); |
||||||
|
|
||||||
|
FormSelectionUtils.paste2Container(designer, container, clipboard, 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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); |
/** |
||||||
creator.removeAll(); |
* 删除当前所有选择的组件 |
||||||
// 清除被选中的组件
|
*/ |
||||||
|
public void deleteSelection() { |
||||||
|
XCreator[] roots = selection.getSelectedCreators(); |
||||||
|
|
||||||
|
if (roots.length > 0) { |
||||||
|
for (XCreator creator : roots) { |
||||||
|
if (creator.acceptType(XWParameterLayout.class)) { |
||||||
|
designer.removeParaComponent(); |
||||||
|
} |
||||||
|
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight()); |
||||||
|
creator.removeAll(); |
||||||
|
// 清除被选中的组件
|
||||||
selection.reset(); |
selection.reset(); |
||||||
} |
} |
||||||
setSelectedCreator(designer.getRootComponent()); |
setSelectedCreator(designer.getRootComponent()); |
||||||
// 触发事件
|
FormSelectionUtils.rebuildSelection(designer); |
||||||
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); |
// 触发事件
|
||||||
designer.repaint(); |
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED); |
||||||
} |
designer.repaint(); |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
* 从选择组件中删除某组件 |
/** |
||||||
* |
* 从选择组件中删除某组件 |
||||||
* @param creator 组件 |
* |
||||||
* @param creatorWidth 组件之前宽度 |
* @param creator 组件 |
||||||
* @param creatorHeight 组件之前高度 |
* @param creatorWidth 组件之前宽度 |
||||||
*/ |
* @param creatorHeight 组件之前高度 |
||||||
public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { |
*/ |
||||||
selection.removeCreator(creator); |
public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) { |
||||||
removeCreatorFromContainer(creator, creatorWidth, creatorHeight); |
selection.removeCreator(creator); |
||||||
designer.repaint(); |
removeCreatorFromContainer(creator, creatorWidth, creatorHeight); |
||||||
} |
designer.repaint(); |
||||||
|
} |
||||||
/** |
|
||||||
* 设置选择区域 |
/** |
||||||
*/ |
* 设置选择区域 |
||||||
public void setHotspotBounds(Rectangle rect) { |
*/ |
||||||
hotspot_bounds = rect; |
public void setHotspotBounds(Rectangle rect) { |
||||||
} |
hotspotBounds = rect; |
||||||
|
} |
||||||
/** |
|
||||||
* 获得当前选择区域 |
/** |
||||||
*/ |
* 获得当前选择区域 |
||||||
public Rectangle getHotspotBounds() { |
*/ |
||||||
return hotspot_bounds; |
public Rectangle getHotspotBounds() { |
||||||
} |
return hotspotBounds; |
||||||
|
} |
||||||
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { |
|
||||||
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); |
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { |
||||||
if (parent == null) { |
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator); |
||||||
return; |
if (parent == null) { |
||||||
} |
return; |
||||||
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); |
} |
||||||
if (parent.acceptType(XWFitLayout.class) && changeCreator) { |
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle(); |
||||||
creator = (XCreator) creator.getParent(); |
if (parent.acceptType(XWFitLayout.class) && changeCreator) { |
||||||
} |
creator = (XCreator) creator.getParent(); |
||||||
parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); |
} |
||||||
// 删除其根组件,同时就删除了同时被选择的叶子组件
|
parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight); |
||||||
parent.remove(creator); |
// 删除其根组件,同时就删除了同时被选择的叶子组件
|
||||||
LayoutManager layout = parent.getLayout(); |
parent.remove(creator); |
||||||
|
LayoutManager layout = parent.getLayout(); |
||||||
if (layout != null) { |
|
||||||
// 刷新组件容器的布局
|
if (layout != null) { |
||||||
LayoutUtils.layoutContainer(parent); |
// 刷新组件容器的布局
|
||||||
} |
LayoutUtils.layoutContainer(parent); |
||||||
} |
} |
||||||
|
} |
||||||
/** |
|
||||||
* 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 |
/** |
||||||
* @return 是则返回true |
* 是否有组件被选择。如果所选组件是最底层容器,也视为无选择 |
||||||
*/ |
* |
||||||
public boolean hasSelectionComponent() { |
* @return 是则返回true |
||||||
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null; |
* yaoh.wu 不应该通过判断是否是最底层容器来判断是否选择了组件 |
||||||
} |
* 而是应该判断选择的容器是否是编辑器的最表层容器,也就是点击空白地方选择的容器 |
||||||
|
* 但是直接判断选择的容器是否是编辑器最表层类型又会引发拖动时选不上的情况, |
||||||
/** |
* 因此通过判断父容器来实现 |
||||||
* 移动组件至指定位置 |
* <p> |
||||||
* @param x 坐标x |
* 举例:frm组件复用 绝对布局情况下,不选择时有三层容器: |
||||||
* @param y 坐标y |
* 底层@see {@link com.fr.design.designer.creator.XWBorderLayout} |
||||||
*/ |
* 中层@see {@link XWFitLayout} |
||||||
public void move(int x, int y) { |
* 表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout} |
||||||
for (XCreator creator : selection.getSelectedCreators()) { |
* <p> |
||||||
creator.setLocation(creator.getX() + x, creator.getY() + y); |
* 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout}, |
||||||
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); |
* 其他两层不是靠添加组件就可以编辑的。 |
||||||
if (layoutAdapter != null) { |
*/ |
||||||
layoutAdapter.fix(creator); |
public boolean hasSelectedPasteSource() { |
||||||
} |
XCreator selectionXCreator = selection.getSelectedCreator(); |
||||||
} |
if (designer.getClass().equals(FormDesigner.class)) { |
||||||
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), |
//frm本地组件复用
|
||||||
DesignerEvent.CREATOR_SELECTED); |
if (selectionXCreator != null) { |
||||||
} |
//选中的是否是tab布局编辑器本身
|
||||||
|
boolean tabEditor = selectionXCreator.getClass().equals(XWCardMainBorderLayout.class) |
||||||
/** |
|| selectionXCreator.getClass().equals(XWCardLayout.class) |
||||||
* 释放捕获 |
|| selectionXCreator.getClass().equals(XWTabFitLayout.class); |
||||||
*/ |
//选中的是否是frm绝对布局编辑器本身
|
||||||
public void releaseDragging() { |
boolean absoluteEditor = selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class); |
||||||
designer.setPainter(null); |
//选中是否是frm绝对画布块编辑器本身
|
||||||
selection.fixCreator(designer); |
boolean absoluteCanvas = selectionXCreator.getClass().equals(XWAbsoluteLayout.class); |
||||||
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), |
//选中的是否是相对布局编辑器本身
|
||||||
DesignerEvent.CREATOR_RESIZED); |
boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class); |
||||||
} |
|
||||||
|
return !(tabEditor || absoluteEditor || absoluteCanvas || relativeEditor); |
||||||
public Direction getDirectionAt(MouseEvent e) { |
} else { |
||||||
Direction dir; |
return false; |
||||||
if (e.isControlDown() || e.isShiftDown()) { |
} |
||||||
XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); |
} else { |
||||||
if (creator != designer.getRootComponent() && selection.addedable(creator)) { |
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
|
||||||
return Location.add; |
return selectionXCreator != null && selectionXCreator.getParent() != null; |
||||||
} |
} |
||||||
} |
} |
||||||
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) { |
* @return 是则返回true |
||||||
if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) { |
*/ |
||||||
dir = Location.outer; |
public boolean hasSelectionComponent() { |
||||||
} |
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null; |
||||||
} |
} |
||||||
} else { |
|
||||||
dir = Location.outer; |
/** |
||||||
} |
* 移动组件至指定位置 |
||||||
|
* |
||||||
if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { |
* @param x 坐标x |
||||||
dir = designer.getLoc2Root(e); |
* @param y 坐标y |
||||||
} |
*/ |
||||||
return dir; |
public void move(int x, int y) { |
||||||
} |
for (XCreator creator : selection.getSelectedCreators()) { |
||||||
|
creator.setLocation(creator.getX() + x, creator.getY() + y); |
||||||
private Direction getDirection(Rectangle bounds, int x, int y) { |
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); |
||||||
if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { |
if (layoutAdapter != null) { |
||||||
return Location.outer; |
layoutAdapter.fix(creator); |
||||||
} else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { |
} |
||||||
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { |
} |
||||||
return Location.outer; |
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), |
||||||
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { |
DesignerEvent.CREATOR_SELECTED); |
||||||
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; |
public void releaseDragging() { |
||||||
} else { |
designer.setPainter(null); |
||||||
return Location.outer; |
selection.fixCreator(designer); |
||||||
} |
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), |
||||||
} else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { |
DesignerEvent.CREATOR_RESIZED); |
||||||
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { |
} |
||||||
return Location.outer; |
|
||||||
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { |
public Direction getDirectionAt(MouseEvent e) { |
||||||
return Location.top; |
Direction dir; |
||||||
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { |
if (e.isControlDown() || e.isShiftDown()) { |
||||||
return Location.inner; |
XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators()); |
||||||
} else if ((y >= (bounds.y + bounds.height)) |
if (creator != designer.getRootComponent() && selection.addedable(creator)) { |
||||||
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { |
return Location.add; |
||||||
return Location.bottom; |
} |
||||||
} else { |
} |
||||||
return Location.outer; |
if (hasSelectionComponent()) { |
||||||
} |
int x = e.getX() + designer.getArea().getHorizontalValue(); |
||||||
} else if ((x >= (bounds.x + bounds.width)) |
int y = e.getY() + designer.getArea().getVerticalValue(); |
||||||
&& (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { |
dir = getDirection(selection.getRelativeBounds(), x, y); |
||||||
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { |
if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir |
||||||
return Location.outer; |
.getActual())) { |
||||||
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { |
dir = Location.outer; |
||||||
return Location.right_top; |
} |
||||||
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { |
} else { |
||||||
return Location.right; |
dir = Location.outer; |
||||||
} else if ((y >= (bounds.y + bounds.height)) |
} |
||||||
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { |
|
||||||
return Location.right_bottom; |
if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) { |
||||||
} else { |
dir = designer.getLoc2Root(e); |
||||||
return Location.outer; |
} |
||||||
} |
return dir; |
||||||
} else { |
} |
||||||
return Location.outer; |
|
||||||
} |
private Direction getDirection(Rectangle bounds, int x, int y) { |
||||||
} |
if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { |
||||||
|
return Location.outer; |
||||||
private void fireCreatorSelected() { |
} else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { |
||||||
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(), |
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { |
||||||
DesignerEvent.CREATOR_SELECTED); |
return Location.outer; |
||||||
} |
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { |
||||||
|
return Location.left_top; |
||||||
public void setSelectedCreator(XCreator rootComponent) { |
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { |
||||||
selection.setSelectedCreator(rootComponent); |
return Location.left; |
||||||
fireCreatorSelected(); |
} else if ((y >= (bounds.y + bounds.height)) |
||||||
} |
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { |
||||||
|
return Location.left_bottom; |
||||||
public void setSelectedCreators(ArrayList<XCreator> rebuildSelection) { |
} else { |
||||||
selection.setSelectedCreators(rebuildSelection); |
return Location.outer; |
||||||
fireCreatorSelected(); |
} |
||||||
} |
} 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); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSelectedCreator(XCreator rootComponent) { |
||||||
|
selection.setSelectedCreator(rootComponent); |
||||||
|
fireCreatorSelected(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSelectedCreators(ArrayList<XCreator> rebuildSelection) { |
||||||
|
selection.setSelectedCreators(rebuildSelection); |
||||||
|
fireCreatorSelected(); |
||||||
|
} |
||||||
} |
} |
@ -1,446 +1,476 @@ |
|||||||
package com.fr.design.designer.beans.models; |
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
import java.awt.Component; |
|
||||||
import java.awt.Cursor; |
|
||||||
import java.awt.Graphics; |
|
||||||
import java.awt.Point; |
|
||||||
import java.awt.Rectangle; |
|
||||||
import java.awt.Toolkit; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.util.ArrayList; |
|
||||||
|
|
||||||
import com.fr.design.beans.location.Absorptionline; |
import com.fr.design.beans.location.Absorptionline; |
||||||
import com.fr.design.mainframe.FormDesigner; |
|
||||||
import com.fr.design.mainframe.FormSelectionUtils; |
|
||||||
import com.fr.design.designer.beans.AdapterBus; |
import com.fr.design.designer.beans.AdapterBus; |
||||||
import com.fr.design.designer.beans.HoverPainter; |
import com.fr.design.designer.beans.HoverPainter; |
||||||
import com.fr.design.designer.beans.LayoutAdapter; |
import com.fr.design.designer.beans.LayoutAdapter; |
||||||
import com.fr.design.designer.beans.events.DesignerEvent; |
import com.fr.design.designer.beans.events.DesignerEvent; |
||||||
import com.fr.design.designer.beans.location.Direction; |
import com.fr.design.designer.beans.location.Direction; |
||||||
import com.fr.design.designer.beans.location.Location; |
import com.fr.design.designer.beans.location.Location; |
||||||
import com.fr.design.designer.creator.XConnector; |
import com.fr.design.designer.creator.*; |
||||||
import com.fr.design.designer.creator.XCreator; |
import com.fr.design.mainframe.FormDesigner; |
||||||
import com.fr.design.designer.creator.XCreatorUtils; |
import com.fr.design.mainframe.FormSelectionUtils; |
||||||
import com.fr.design.designer.creator.XLayoutContainer; |
|
||||||
import com.fr.design.designer.creator.XWAbsoluteLayout; |
|
||||||
import com.fr.design.utils.ComponentUtils; |
import com.fr.design.utils.ComponentUtils; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
/** |
/** |
||||||
* 普通模式下的状态model |
* 普通模式下的状态model |
||||||
*/ |
*/ |
||||||
public class StateModel { |
public class StateModel { |
||||||
// 对应的selection model
|
// 对应的selection model
|
||||||
|
|
||||||
private SelectionModel selectionModel; |
private SelectionModel selectionModel; |
||||||
// 当前鼠标进入拖拽区域的位置类型
|
// 当前鼠标进入拖拽区域的位置类型
|
||||||
private Direction driection; |
private Direction driection; |
||||||
|
|
||||||
// 当前拖拽的起始位置
|
// 当前拖拽的起始位置
|
||||||
private int current_x; |
private int currentX; |
||||||
private int current_y; |
private int currentY; |
||||||
|
|
||||||
private Point startPoint = new Point(); |
//拖拽组件原始位置大小备份
|
||||||
private Point currentPoint = new Point(); |
private Rectangle selectedPositionBackup; |
||||||
|
|
||||||
private Absorptionline lineInX; |
private Point startPoint = new Point(); |
||||||
private Absorptionline lineInY; |
private Point currentPoint = new Point(); |
||||||
//等距线
|
|
||||||
private Absorptionline lineEquidistant; |
private Absorptionline lineInX; |
||||||
|
private Absorptionline lineInY; |
||||||
// 当前是否处于拖拽选择状态
|
//等距线
|
||||||
private boolean selecting; |
private Absorptionline lineEquidistant; |
||||||
private boolean dragging; |
|
||||||
|
// 当前是否处于拖拽选择状态
|
||||||
private boolean addable; |
private boolean selecting; |
||||||
|
private boolean dragging; |
||||||
private FormDesigner designer; |
|
||||||
|
private boolean addable; |
||||||
public StateModel(FormDesigner designer) { |
|
||||||
this.designer = designer; |
private FormDesigner designer; |
||||||
selectionModel = designer.getSelectionModel(); |
|
||||||
} |
public StateModel(FormDesigner designer) { |
||||||
|
this.designer = designer; |
||||||
/** |
selectionModel = designer.getSelectionModel(); |
||||||
* 返回direction |
} |
||||||
* @return direction方向 |
|
||||||
*/ |
/** |
||||||
public Direction getDirection() { |
* 返回direction |
||||||
return driection; |
* |
||||||
} |
* @return direction方向 |
||||||
|
*/ |
||||||
/** |
public Direction getDirection() { |
||||||
* 是否有组件正被选中 |
return driection; |
||||||
* |
} |
||||||
* @return true 如果至少一个组件被选中 |
|
||||||
*/ |
/** |
||||||
public boolean isSelecting() { |
* 是否有组件正被选中 |
||||||
return selecting; |
* |
||||||
} |
* @return true 如果至少一个组件被选中 |
||||||
|
*/ |
||||||
|
public boolean isSelecting() { |
||||||
|
return selecting; |
||||||
|
} |
||||||
|
|
||||||
/** |
/** |
||||||
*是否能拖拽 |
* 是否能拖拽 |
||||||
|
* |
||||||
* @return 非outer且选中为空 |
* @return 非outer且选中为空 |
||||||
*/ |
*/ |
||||||
public boolean dragable() { |
public boolean dragable() { |
||||||
return ((driection != Location.outer) && !selecting); |
return ((driection != Location.outer) && !selecting); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* 拖拽中是否可以转换为添加模式: |
* 拖拽中是否可以转换为添加模式: |
||||||
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
* 如果拖拽组件只有一个,鼠标当前所在位置的最底层表单容器与这个组件的容器不同; |
||||||
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
* 如果拖拽组件为多个,鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外,还必须是绝对定位布局 |
||||||
*/ |
*/ |
||||||
private void checkAddable(MouseEvent e) { |
private void checkAddable(MouseEvent e) { |
||||||
addable = false; |
addable = false; |
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
|
|
||||||
if (driection != Location.inner) { |
if (driection != Location.inner) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator); |
||||||
if (creatorContainer != null && creatorContainer != container |
if (creatorContainer != null && creatorContainer != container |
||||||
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) { |
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
designer.setPainter(painter); |
designer.setPainter(painter); |
||||||
if (painter != null) { |
if (painter != null) { |
||||||
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
rect.x -= designer.getArea().getHorizontalValue(); |
rect.x -= designer.getArea().getHorizontalValue(); |
||||||
rect.y -= designer.getArea().getVerticalValue(); |
rect.y -= designer.getArea().getVerticalValue(); |
||||||
painter.setRenderingBounds(rect); |
painter.setRenderingBounds(rect); |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
painter.setCreator(creator); |
painter.setCreator(creator); |
||||||
} |
} |
||||||
addable = true; |
addable = true; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private boolean addBean(XLayoutContainer container, int x, int y) { |
/** |
||||||
LayoutAdapter adapter = container.getLayoutAdapter(); |
* @param container 容器 |
||||||
Rectangle r = ComponentUtils.getRelativeBounds(container); |
* @param mouseX 鼠标释放位置X |
||||||
if (selectionModel.getSelection().size() == 1) { |
* @param mouseY 鼠标释放位置Y |
||||||
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x |
* @return 是否成功 |
||||||
+ designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y); |
*/ |
||||||
} |
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) { |
||||||
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
LayoutAdapter adapter = container.getLayoutAdapter(); |
||||||
adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y); |
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container); |
||||||
} |
if (selectionModel.getSelection().size() == 1) { |
||||||
return true; |
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), |
||||||
} |
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
private void adding(int x, int y) { |
} |
||||||
|
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) { |
||||||
|
adapter.addBean(creator, |
||||||
|
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x, |
||||||
|
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param mouseReleasedX 鼠标释放位置X |
||||||
|
* @param mouseReleasedY 鼠标释放位置Y |
||||||
|
*/ |
||||||
|
private void adding(int mouseReleasedX, int mouseReleasedY) { |
||||||
// 当前鼠标所在的组件
|
// 当前鼠标所在的组件
|
||||||
XCreator hoveredComponent = designer.getComponentAt(x, y, selectionModel.getSelection().getSelectedCreators()); |
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators()); |
||||||
|
|
||||||
// 获取该组件所在的焦点容器
|
// 获取该组件所在的焦点容器
|
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent); |
||||||
|
|
||||||
boolean success = false; |
boolean success = false; |
||||||
|
|
||||||
if (container != null) { |
if (container != null) { |
||||||
// 如果是容器,则调用其acceptComponent接受组件
|
// 如果是容器,则调用其acceptComponent接受组件
|
||||||
success = addBean(container, x, y); |
success = addBean(container, mouseReleasedX, mouseReleasedY); |
||||||
} |
} |
||||||
|
|
||||||
if (success) { |
if (success) { |
||||||
FormSelectionUtils.rebuildSelection(designer); |
FormSelectionUtils.rebuildSelection(designer); |
||||||
designer.getEditListenerTable().fireCreatorModified( |
designer.getEditListenerTable().fireCreatorModified( |
||||||
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED); |
||||||
} else { |
} else { |
||||||
Toolkit.getDefaultToolkit().beep(); |
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer); |
||||||
} |
Toolkit.getDefaultToolkit().beep(); |
||||||
|
} |
||||||
// 取消提示
|
// 取消提示
|
||||||
designer.setPainter(null); |
designer.setPainter(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*是否拖拽 |
* 是否拖拽 |
||||||
|
* |
||||||
* @return dragging状态 |
* @return dragging状态 |
||||||
*/ |
*/ |
||||||
public boolean isDragging() { |
public boolean isDragging() { |
||||||
return dragging; |
return dragging; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*是否可以开始画线 |
* 是否可以开始画线 |
||||||
|
* |
||||||
* @return startPoint不为空返回true |
* @return startPoint不为空返回true |
||||||
*/ |
*/ |
||||||
public boolean prepareForDrawLining() { |
public boolean prepareForDrawLining() { |
||||||
return startPoint != null; |
return startPoint != null; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*设置开始位置 |
* 设置开始位置 |
||||||
|
* |
||||||
* @param p point位置 |
* @param p point位置 |
||||||
*/ |
*/ |
||||||
public void setStartPoint(Point p) { |
public void setStartPoint(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回开始位置 |
* 返回开始位置 |
||||||
|
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getStartPoint() { |
public Point getStartPoint() { |
||||||
return startPoint; |
return startPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回当前点位置 |
* 返回当前点位置 |
||||||
|
* |
||||||
* @return 点位置 |
* @return 点位置 |
||||||
*/ |
*/ |
||||||
public Point getEndPoint() { |
public Point getEndPoint() { |
||||||
return currentPoint; |
return currentPoint; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*当前选中组件 |
* 当前选中组件 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startSelecting(MouseEvent e) { |
public void startSelecting(MouseEvent e) { |
||||||
selecting = true; |
selecting = true; |
||||||
selectionModel.setHotspotBounds(new Rectangle()); |
selectionModel.setHotspotBounds(new Rectangle()); |
||||||
current_x = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
current_y = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*当前鼠标的xy |
* 当前鼠标的xy |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void startResizing(MouseEvent e) { |
public void startResizing(MouseEvent e) { |
||||||
if (!selectionModel.getSelection().isEmpty()) { |
if (!selectionModel.getSelection().isEmpty()) { |
||||||
driection.backupBounds(designer); |
driection.backupBounds(designer); |
||||||
} |
} |
||||||
current_x = getMouseXY(e).x; |
currentX = getMouseXY(e).x; |
||||||
current_y = getMouseXY(e).y; |
currentY = getMouseXY(e).y; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*起始点开始DrawLine |
* 起始点开始DrawLine |
||||||
|
* |
||||||
* @param p 点位置 |
* @param p 点位置 |
||||||
*/ |
*/ |
||||||
public void startDrawLine(Point p) { |
public void startDrawLine(Point p) { |
||||||
this.startPoint = p; |
this.startPoint = p; |
||||||
if(p != null) { |
if (p != null) { |
||||||
try { |
try { |
||||||
designer.setCursor(XConnector.connectorCursor); |
designer.setCursor(XConnector.connectorCursor); |
||||||
} catch (Exception e) { |
} catch (Exception e) { |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*鼠标释放时所在的区域及圈中的组件 |
* 鼠标释放时所在的区域及圈中的组件 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void selectCreators(MouseEvent e) { |
public void selectCreators(MouseEvent e) { |
||||||
int x = getMouseXY(e).x; |
int x = getMouseXY(e).x; |
||||||
int y = getMouseXY(e).y; |
int y = getMouseXY(e).y; |
||||||
|
|
||||||
Rectangle bounds = createCurrentBounds(x, y); |
Rectangle bounds = createCurrentBounds(x, y); |
||||||
|
|
||||||
if ((x != current_x) || (y != current_y)) { |
if ((x != currentX) || (y != currentY)) { |
||||||
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent())); |
||||||
} |
} |
||||||
selectionModel.setHotspotBounds(null); |
selectionModel.setHotspotBounds(null); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*画所在区域线 |
* 画所在区域线 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void drawLine(MouseEvent e) { |
public void drawLine(MouseEvent e) { |
||||||
designer.getDrawLineHelper().setDrawLine(true); |
designer.getDrawLineHelper().setDrawLine(true); |
||||||
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e); |
||||||
if (p != null) { |
if (p != null) { |
||||||
currentPoint = p; |
currentPoint = p; |
||||||
} else { |
} else { |
||||||
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue(); |
||||||
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
currentPoint.y = e.getY() + designer.getArea().getVerticalValue(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
private Rectangle createCurrentBounds(int x, int y) { |
private Rectangle createCurrentBounds(int x, int y) { |
||||||
Rectangle bounds = new Rectangle(); |
Rectangle bounds = new Rectangle(); |
||||||
|
|
||||||
bounds.x = Math.min(x, current_x); |
bounds.x = Math.min(x, currentX); |
||||||
bounds.y = Math.min(y, current_y); |
bounds.y = Math.min(y, currentY); |
||||||
bounds.width = Math.max(x, current_x) - bounds.x; |
bounds.width = Math.max(x, currentX) - bounds.x; |
||||||
bounds.height = Math.max(y, current_y) - bounds.y; |
bounds.height = Math.max(y, currentY) - bounds.y; |
||||||
|
|
||||||
return bounds; |
return bounds; |
||||||
} |
} |
||||||
|
|
||||||
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) { |
||||||
ArrayList<XCreator> creators = new ArrayList<XCreator>(); |
ArrayList<XCreator> creators = new ArrayList<>(); |
||||||
|
|
||||||
if (!root.isVisible() && !designer.isRoot(root)) { |
if (!root.isVisible() && !designer.isRoot(root)) { |
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
if (root instanceof XLayoutContainer) { |
if (root instanceof XLayoutContainer) { |
||||||
XLayoutContainer container = (XLayoutContainer) root; |
XLayoutContainer container = (XLayoutContainer) root; |
||||||
int count = container.getXCreatorCount(); |
int count = container.getXCreatorCount(); |
||||||
Rectangle clipped = new Rectangle(selection); |
Rectangle clipped = new Rectangle(selection); |
||||||
|
|
||||||
for (int i = count - 1; i >= 0; i--) { |
for (int i = count - 1; i >= 0; i--) { |
||||||
XCreator child = container.getXCreator(i); |
XCreator child = container.getXCreator(i); |
||||||
|
|
||||||
if (selection.contains(child.getBounds())) { |
if (selection.contains(child.getBounds())) { |
||||||
creators.add(child); |
creators.add(child); |
||||||
} else { |
} else { |
||||||
clipped.x = selection.x - child.getX(); |
clipped.x = selection.x - child.getX(); |
||||||
clipped.y = selection.y - child.getY(); |
clipped.y = selection.y - child.getY(); |
||||||
creators.addAll(getHotspotCreators(clipped, child)); |
creators.addAll(getHotspotCreators(clipped, child)); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return creators; |
return creators; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
*重置model |
* 重置model |
||||||
*/ |
*/ |
||||||
public void resetModel() { |
public void resetModel() { |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*重置 |
* 重置 |
||||||
*/ |
*/ |
||||||
public void reset() { |
public void reset() { |
||||||
driection = Location.outer; |
driection = Location.outer; |
||||||
dragging = false; |
dragging = false; |
||||||
selecting = false; |
selecting = false; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*取消拖拽 |
* 取消拖拽 |
||||||
*/ |
*/ |
||||||
public void draggingCancel() { |
public void draggingCancel() { |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
reset(); |
reset(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*设置可拉伸方向 |
* 设置可拉伸方向 |
||||||
|
* |
||||||
* @param dir 拉伸方向 |
* @param dir 拉伸方向 |
||||||
*/ |
*/ |
||||||
public void setDirection(Direction dir) { |
public void setDirection(Direction dir) { |
||||||
if(driection != dir) { |
if (driection != dir) { |
||||||
this.driection = dir; |
this.driection = dir; |
||||||
driection.updateCursor(designer); |
driection.updateCursor(designer); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*x吸附线赋值 |
* x吸附线赋值 |
||||||
|
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setXAbsorptionline(Absorptionline line) { |
public void setXAbsorptionline(Absorptionline line) { |
||||||
this.lineInX = line; |
this.lineInX = line; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* y吸附线赋值 |
||||||
|
* |
||||||
|
* @param line 线 |
||||||
|
*/ |
||||||
|
public void setYAbsorptionline(Absorptionline line) { |
||||||
|
this.lineInY = line; |
||||||
|
} |
||||||
|
|
||||||
/** |
/** |
||||||
*y吸附线赋值 |
* 等距线赋值 |
||||||
|
* |
||||||
* @param line 线 |
* @param line 线 |
||||||
*/ |
*/ |
||||||
public void setYAbsorptionline(Absorptionline line) { |
public void setEquidistantLine(Absorptionline line) { |
||||||
this.lineInY = line; |
this.lineEquidistant = line; |
||||||
} |
} |
||||||
|
|
||||||
/** |
|
||||||
* 等距线赋值 |
|
||||||
* @param line 线 |
|
||||||
*/ |
|
||||||
public void setEquidistantLine(Absorptionline line){ |
|
||||||
this.lineEquidistant = line; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
/** |
||||||
*画吸附线 |
* 画吸附线 |
||||||
|
* |
||||||
* @param g Graphics类 |
* @param g Graphics类 |
||||||
*/ |
*/ |
||||||
public void paintAbsorptionline(Graphics g) { |
public void paintAbsorptionline(Graphics g) { |
||||||
if(lineInX != null) { |
if (lineInX != null) { |
||||||
lineInX.paint(g,designer.getArea()); |
lineInX.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if(lineInY != null) { |
if (lineInY != null) { |
||||||
lineInY.paint(g,designer.getArea()); |
lineInY.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
if(lineEquidistant != null){ |
if (lineEquidistant != null) { |
||||||
lineEquidistant.paint(g,designer.getArea()); |
lineEquidistant.paint(g, designer.getArea()); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*拖拽 |
* 拖拽 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void dragging(MouseEvent e) { |
public void dragging(MouseEvent e) { |
||||||
checkAddable(e); |
//进入dragging状态时备份组件大小和位置
|
||||||
setDependLinePainter(e); |
if (!dragging) { |
||||||
driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer); |
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds(); |
||||||
this.dragging = true; |
} |
||||||
} |
checkAddable(e); |
||||||
|
setDependLinePainter(e); |
||||||
// 拖拽时画依附线用到的painter
|
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); |
||||||
private void setDependLinePainter(MouseEvent e){ |
this.dragging = true; |
||||||
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
} |
||||||
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
|
||||||
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
// 拖拽时画依附线用到的painter
|
||||||
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
private void setDependLinePainter(MouseEvent e) { |
||||||
designer.setPainter(painter); |
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators()); |
||||||
if (painter != null) { |
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp); |
||||||
painter.setHotspot(new Point(e.getX(), e.getY())); |
XCreator creator = selectionModel.getSelection().getSelectedCreator(); |
||||||
painter.setCreator(creator); |
HoverPainter painter = AdapterBus.getContainerPainter(designer, container); |
||||||
} |
designer.setPainter(painter); |
||||||
} |
if (painter != null) { |
||||||
|
painter.setHotspot(new Point(e.getX(), e.getY())); |
||||||
|
painter.setCreator(creator); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
/** |
/** |
||||||
*释放捕获 |
* 释放捕获 |
||||||
|
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void releaseDragging(MouseEvent e) { |
public void releaseDragging(MouseEvent e) { |
||||||
this.dragging = false; |
this.dragging = false; |
||||||
if (addable) { |
if (addable) { |
||||||
adding(e.getX(), e.getY()); |
adding(e.getX(), e.getY()); |
||||||
} else if (!selectionModel.getSelection().isEmpty()) { |
} else if (!selectionModel.getSelection().isEmpty()) { |
||||||
selectionModel.releaseDragging(); |
selectionModel.releaseDragging(); |
||||||
} |
} |
||||||
designer.repaint(); |
designer.repaint(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*改变选择区域 |
* 改变选择区域 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
*/ |
*/ |
||||||
public void changeSelection(MouseEvent e) { |
public void changeSelection(MouseEvent e) { |
||||||
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
||||||
selectionModel.setHotspotBounds(bounds); |
selectionModel.setHotspotBounds(bounds); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*返回鼠标所在的x、y 考虑滚动条的值 |
* 返回鼠标所在的x、y 考虑滚动条的值 |
||||||
* |
* |
||||||
* @param e 鼠标事件 |
* @param e 鼠标事件 |
||||||
* @return xy值 |
* @return xy值 |
||||||
*/ |
*/ |
||||||
public Point getMouseXY(MouseEvent e) { |
public Point getMouseXY(MouseEvent e) { |
||||||
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
||||||
+ designer.getArea().getVerticalValue()); |
+ designer.getArea().getVerticalValue()); |
||||||
return p1; |
return p1; |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,126 +1,239 @@ |
|||||||
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 com.fr.general.Inter; |
||||||
|
|
||||||
|
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_Y = 20; |
||||||
LayoutAdapter adapter = parent.getLayoutAdapter(); |
|
||||||
if (selection.size() == 1) { |
//组件重命名后缀
|
||||||
try { |
private static final String POSTFIX = "_c"; |
||||||
XCreator creator = selection.getSelectedCreator(); |
|
||||||
Widget cloned = new ClonedWidgetCreator(designer.getTarget()).clonedWidgetWithNoRepeatName(creator |
private FormSelectionUtils() { |
||||||
.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; |
*/ |
||||||
} |
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, |
||||||
} catch (CloneNotSupportedException e) { |
FormSelection clipboard, int x, int y) { |
||||||
FRContext.getLogger().error(e.getMessage(), e); |
LayoutAdapter adapter = parent.getLayoutAdapter(); |
||||||
} |
if (parent instanceof XWAbsoluteLayout) { |
||||||
} else if (selection.size() > 1) { |
//绝对布局
|
||||||
if (parent instanceof XWAbsoluteLayout) { |
absolutePaste(designer, clipboard, adapter, x, y); |
||||||
designer.getSelectionModel().getSelection().reset(); |
return; |
||||||
Rectangle rec = selection.getSelctionBounds(); |
} else if (parent instanceof XWFitLayout) { |
||||||
for (XCreator creator : selection.getSelectedCreators()) { |
//相对布局
|
||||||
try { |
relativePaste(designer, clipboard, adapter, x, y); |
||||||
Widget cloned = new ClonedWidgetCreator(designer.getTarget()) |
return; |
||||||
.clonedWidgetWithNoRepeatName(creator.toData()); |
} |
||||||
XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize()); |
Toolkit.getDefaultToolkit().beep(); |
||||||
// 设置位置,移动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); |
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||||
} |
|
||||||
} |
designer.getSelectionModel().getSelection().reset(); |
||||||
designer.getEditListenerTable().fireCreatorModified( |
Rectangle rec = clipboard.getSelctionBounds(); |
||||||
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||||
return; |
try { |
||||||
} |
Widget copied = copyWidget(designer, creator); |
||||||
} |
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); |
||||||
Toolkit.getDefaultToolkit().beep(); |
// 获取位置
|
||||||
} |
Point point = getPasteLocation((AbstractLayoutAdapter) adapter, |
||||||
|
copiedCreator, |
||||||
public static void rebuildSelection(FormDesigner designer) { |
x + creator.getX() - rec.x + copiedCreator.getWidth() / 2, |
||||||
ArrayList<XCreator> newSelection = new ArrayList<XCreator>(); |
y + creator.getY() - rec.y + copiedCreator.getHeight() / 2); |
||||||
List<Widget> widgetList = new ArrayList<Widget>(); |
if (!adapter.accept(copiedCreator, point.x, point.y)) { |
||||||
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) { |
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Large_To_Paste")); |
||||||
widgetList.add(comp.toData()); |
return; |
||||||
} |
} |
||||||
designer.getSelectionModel().setSelectedCreators( |
boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y); |
||||||
rebuildSelection(designer.getRootComponent(), widgetList, newSelection)); |
if (addSuccess) { |
||||||
} |
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); |
||||||
|
} |
||||||
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { |
} catch (CloneNotSupportedException e) { |
||||||
List<Widget> selectionWidget = new ArrayList<Widget>(); |
FRContext.getLogger().error(e.getMessage(), e); |
||||||
if(selectWidgets != null){ |
} |
||||||
selectionWidget.addAll(Arrays.asList(selectWidgets)); |
} |
||||||
} |
rebuildSelection(designer); |
||||||
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>()); |
designer.getEditListenerTable().fireCreatorModified( |
||||||
} |
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
||||||
|
|
||||||
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, |
} |
||||||
ArrayList<XCreator> newSelection) { |
|
||||||
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); |
/** |
||||||
if (newSelection.isEmpty()) { |
* 相对布局粘贴 |
||||||
newSelection.add(rootComponent); |
*/ |
||||||
} |
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) { |
||||||
return newSelection; |
designer.getSelectionModel().getSelection().reset(); |
||||||
} |
for (XCreator creator : clipboard.getSelectedCreators()) { |
||||||
|
try { |
||||||
private static void _rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) { |
Widget copied = copyWidget(designer, creator); |
||||||
if (selectionWidget.isEmpty()) { |
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize()); |
||||||
return; |
if (!adapter.accept(copiedCreator, x, y)) { |
||||||
} |
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste")); |
||||||
for (Widget x : selectionWidget) { |
return; |
||||||
if (ComparatorUtils.equals(x, root.toData())) { |
} |
||||||
if (!newSelection.contains(root)) { |
boolean addSuccess = adapter.addBean(copiedCreator, x, y); |
||||||
newSelection.add(root); |
if (addSuccess) { |
||||||
selectionWidget.remove(x); |
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator); |
||||||
} |
} |
||||||
break; |
} catch (CloneNotSupportedException e) { |
||||||
} |
FRContext.getLogger().error(e.getMessage(), e); |
||||||
} |
} |
||||||
|
} |
||||||
int count = root.getComponentCount(); |
rebuildSelection(designer); |
||||||
for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) { |
designer.getEditListenerTable().fireCreatorModified( |
||||||
Component c = root.getComponent(i); |
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED); |
||||||
if (c instanceof XCreator) { |
} |
||||||
XCreator creator = (XCreator) c; |
|
||||||
for (Widget x : selectionWidget) { |
/** |
||||||
if (ComparatorUtils.equals(x, creator.toData())) { |
* 组件复用绝对布局获取粘贴组件位置 |
||||||
newSelection.add(creator); |
*/ |
||||||
selectionWidget.remove(x); |
private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) { |
||||||
break; |
//当宽度为奇数时 设置偏移
|
||||||
} |
int xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0; |
||||||
} |
//当高度为奇数时 设置偏移
|
||||||
if (c instanceof XLayoutContainer) { |
int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0; |
||||||
_rebuild((XLayoutContainer) c, selectionWidget, newSelection); |
|
||||||
} else { |
if (!layoutAdapter.accept(copiedCreator, x, y)) { |
||||||
continue; |
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 = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset; |
||||||
|
//紧贴下边界
|
||||||
|
y = container.getHeight() - copiedCreator.getHeight() / 2 - yoffset; |
||||||
|
return new Point(x, y); |
||||||
|
} |
||||||
|
/* |
||||||
|
* 组件原始位置与布局边界距离小于20像素(下边界&右边界同时小于或者任意一个边界小于), |
||||||
|
* 则粘贴时距离小于20像素一侧直接贴近布局边界, |
||||||
|
* 距离大于20像素的一侧正常错开。 |
||||||
|
* x,y中只有一个越界 |
||||||
|
*/ |
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 拷贝组件 |
||||||
|
*/ |
||||||
|
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws |
||||||
|
CloneNotSupportedException { |
||||||
|
ArrayList<String> nameSpace = new ArrayList<>(); |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 组件拷贝命名规则 |
||||||
|
*/ |
||||||
|
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) { |
||||||
|
StringBuilder name = new StringBuilder(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<>(); |
||||||
|
List<Widget> 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<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) { |
||||||
|
List<Widget> selectionWidget = new ArrayList<>(); |
||||||
|
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