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