plough 8 years ago
parent
commit
945b6fabf2
  1. 21
      designer_base/build.dev.gradle
  2. 70
      designer_base/build.dev.gradle.bak
  3. 8
      designer_base/src/com/fr/design/actions/edit/CopyAction.java
  4. 140
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  5. 7
      designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java
  6. 2
      designer_base/src/com/fr/design/locale/designer.properties
  7. 2
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  8. 2
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  9. 2
      designer_base/src/com/fr/design/locale/designer_ko_KR.properties
  10. 2
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  11. 2
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  12. 67
      designer_base/src/com/fr/design/mainframe/BaseJForm.java
  13. 18
      designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java
  14. 73
      designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java
  15. 11
      designer_base/src/com/fr/design/utils/ComponentUtils.java
  16. 20
      designer_chart/build.dev.gradle
  17. 85
      designer_chart/build.dev.gradle.bak
  18. 2
      designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java
  19. 19
      designer_form/build.dev.gradle
  20. 4
      designer_form/build.dev.gradle.bak
  21. 17
      designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java
  22. 11
      designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java
  23. 27
      designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java
  24. 105
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  25. 57
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  26. 6
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  27. 93
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  28. 160
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  29. 12
      designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java
  30. 28
      designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java
  31. 2
      designer_form/src/com/fr/design/mainframe/ConnectorHelper.java
  32. 167
      designer_form/src/com/fr/design/mainframe/EditingMouseListener.java
  33. 183
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  34. 22
      designer_form/src/com/fr/design/mainframe/FormSelection.java
  35. 230
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java
  36. 65
      designer_form/src/com/fr/design/mainframe/JForm.java
  37. 52
      designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java
  38. 26
      designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java

21
designer_base/build.dev.gradle

@ -1,8 +1,25 @@
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包版本

70
designer_base/build.dev.gradle.bak

@ -0,0 +1,70 @@
apply plugin: 'java'
tasks.withType(JavaCompile){
options.encoding = 'UTF-8'
}
//jdk版本
sourceCompatibility=1.7
//jar包版本
version='8.0'
//jar包重命名
jar{
baseName='fr-designer-core'
}
def srcDir="."
//
sourceSets{
main{
java{
srcDirs=["${srcDir}/src"]
}
}
}
//
FileTree files =fileTree(dir:'./',include:'build.*.gradle')
def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('\\'))
buildDir=buildDir.substring(0,buildDir.lastIndexOf ('\\'))
def branchName=buildDir.substring(buildDir.lastIndexOf ('\\')+1)
//
dependencies{
compile fileTree(dir:"../../../finereport-lib-stable/${branchName}",include:'**/*.jar')
compile fileTree(dir:'../../../',include:"finereport-*-stable/${branchName}/**/build/libs/*.jar")
testCompile 'junit:junit:4.12'
}
//.java文件到classes文件夹下参与打包
task copyFile(type:Copy,dependsOn:compileJava){
copy{
from ("${srcDir}/src"){
exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html'
}
into 'build/classes/main'
}
}
//js文件
task compressJS{
ant.taskdef(name:'yuicompress',classname:'com.yahoo.platform.yui.compressor.YUICompressTask'){
classpath {
fileset(dir:'../../../finereport-lib4build-stable',includes:'**/*.jar')
}
}
ant.yuicompress(linebreak:"500",warn:"false", munge:"yes",preserveallsemicolons:"false",charset:"utf-8",encoding:"utf-8",outputfolder:'build/classes/main'){
fileset (dir:"${srcDir}/src"){
include (name:'**/*.js')
include (name:'**/*.css')
}
}
}
jar.dependsOn compressJS

8
designer_base/src/com/fr/design/actions/edit/CopyAction.java

@ -3,15 +3,14 @@
*/
package com.fr.design.actions.edit;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import com.fr.base.BaseUtils;
import com.fr.design.actions.TemplateComponentAction;
import com.fr.design.designer.TargetComponent;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.event.KeyEvent;
/**
* Copy.
*/
@ -31,7 +30,6 @@ public class CopyAction extends TemplateComponentAction {
if (tc != null) {
tc.copy();
}
return false;
}
}

140
designer_base/src/com/fr/design/beans/location/MoveUtils.java

@ -18,9 +18,7 @@ public class MoveUtils {
public static final int SORPTION_UNIT = 5;
private static final int EQUIDISTANTLINE_UNIT = 4;
public static WidgetForbidWindow widgetForbidWindow = new WidgetForbidWindow();
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private MoveUtils() {
@ -32,9 +30,7 @@ public class MoveUtils {
* 获取块边界的迭代器
*
* @return 块边界的迭代器
*
* @date 2015-2-12-下午2:43:47
*
*/
RectangleIterator createRectangleIterator();
@ -42,9 +38,7 @@ public class MoveUtils {
* 设置X轴的线
*
* @param line 连接线
*
* @date 2015-2-12-下午2:44:04
*
*/
void setXAbsorptionline(Absorptionline line);
@ -52,9 +46,7 @@ public class MoveUtils {
* 设置Y轴的线
*
* @param line 连接线
*
* @date 2015-2-12-下午2:44:04
*
*/
void setYAbsorptionline(Absorptionline line);
@ -62,7 +54,6 @@ public class MoveUtils {
* 获取当前选中块的垂直线数组
*
* @return 块的垂直线数组
*
*/
int[] getVerticalLine();
@ -70,42 +61,47 @@ public class MoveUtils {
* 获取当前选中块的水平线数组
*
* @return 块的水平线数组
*
*/
int[] getHorizontalLine();
/**
* 设置designer内部组件是否重叠的标志位
*
* @param isIntersects 是否重叠
*/
void setWidgetsIntersected(boolean isIntersects);
/**
* 获取designer内部组件是否重叠的标志位
*
* @return 重叠
*/
boolean isWidgetsIntersected();
/**
* 获取designer相对屏幕的位置
*
* @return 位置
*/
Point getDesignerLocationOnScreen();
/**
* 设置等距线
*
* @param line 吸附线
*/
void setEquidistantLine(Absorptionline line);
/**
* 获取设计器垂直滚动条的值
*
* @return 滚动条的值
*/
int getDesignerScrollVerticalValue();
/**
* 获取设计器水平滚动条的值
*
* @return 滚动条的值
*/
int getDesignerScrollHorizontalValue();
@ -117,9 +113,7 @@ public class MoveUtils {
* 是否存在下一个块
*
* @return 是否存在下一个块
*
* @date 2015-2-12-下午2:41:32
*
*/
boolean hasNext();
@ -127,9 +121,7 @@ public class MoveUtils {
* 获取下一个块的bounds
*
* @return 下一个块的bounds
*
* @date 2015-2-12-下午2:41:55
*
*/
Rectangle nextRectangle();
@ -137,9 +129,7 @@ public class MoveUtils {
* 获取块的垂直线数组
*
* @return 块的垂直线数组
*
* @date 2015-2-12-下午2:42:27
*
*/
int[] getVerticalLine();
@ -147,9 +137,7 @@ public class MoveUtils {
* 获取块的水平线数组
*
* @return 块的水平线数组
*
* @date 2015-2-12-下午2:42:27
*
*/
int[] getHorizontalLine();
}
@ -246,46 +234,38 @@ public class MoveUtils {
//等距线从各边中点画出,先要判断是不是在范围内
int topMiddleX = left + width / 2;
int leftMiddleY = top + height / 2;
if ((topMiddleX > bounds.getX()) && (topMiddleX < (bounds.getX() + bounds.getWidth()))){
if ((topMiddleX > bounds.getX()) && (topMiddleX < (bounds.getX() + bounds.getWidth()))) {
//当前操作rec在bounds的下方
if (top > (bounds.getY() + bounds.getHeight())){
if (top > (bounds.getY() + bounds.getHeight())) {
equidistantLineInfo.setDistance(top - (bounds.y + bounds.height));
equidistantLineInfo.setReference(bounds.y + bounds.height);
equidistantLineInfo.setDirection(SwingConstants.TOP);
}
//当前操作rec在bounds上方
if ((top + height) < bounds.getY()){
if ((top + height) < bounds.getY()) {
equidistantLineInfo.setDistance(bounds.y - (top + height));
equidistantLineInfo.setReference(bounds.y);
equidistantLineInfo.setDirection(SwingConstants.BOTTOM);
}
}
else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))){
} else if ((leftMiddleY > bounds.getY()) && (leftMiddleY < (bounds.getY() + bounds.getHeight()))) {
//当前操作rec在bounds的右侧
if (left > (bounds.getX() + bounds.getWidth())){
if (left > (bounds.getX() + bounds.getWidth())) {
equidistantLineInfo.setDistance(left - (bounds.x + bounds.width));
equidistantLineInfo.setReference(bounds.x + bounds.width);
equidistantLineInfo.setDirection(SwingConstants.LEFT);
}
//当前操作rec在bounds的左侧
if ((left + width) < bounds.getX()){
if ((left + width) < bounds.getX()) {
equidistantLineInfo.setDistance(bounds.x - (left + width));
equidistantLineInfo.setReference(bounds.x);
equidistantLineInfo.setDirection(SwingConstants.RIGHT);
}
}
if(equidistantLineInfo.getDistance() > 0) {
if (equidistantLineInfo.getDistance() > 0) {
equidistantLines.add(equidistantLineInfo);
}
}
public static void displayForbidWindow(int x, int y) {
widgetForbidWindow.showWindow(x, y);
}
public static void hideForbidWindow() {
widgetForbidWindow.hideWindow();
}
/**
* 吸附
@ -295,11 +275,8 @@ public class MoveUtils {
* @param width 宽度
* @param height 高度
* @param designer 块设计器
*
* @return 吸附后坐标
*
* @date 2015-2-12-下午2:39:16
*
*/
public static Point sorption(int x, int y, int width, int height, RectangleDesigner designer, boolean isParameterLayout) {
@ -318,53 +295,32 @@ public class MoveUtils {
RectangleIterator iterator = designer.createRectangleIterator();
java.util.List<Rectangle> cacheRecs = new ArrayList<Rectangle>();
//是否存在控件重叠
boolean isWidgetsIntersects = false;
while (iterator.hasNext()) {
Rectangle bounds = iterator.nextRectangle();
cacheRecs.add(bounds);
boolean isIntersects = operatingRectangle.intersects(bounds);
findX(px, bounds, left, right, width);
findY(py, bounds, top, bottom, height);
if(!isParameterLayout){
if(isIntersects) {
isWidgetsIntersects = true;
}
else{
if (!isParameterLayout) {
findEquidistantLine(bounds, left, top, height, width);
}
}
}
showForbiddenWindow(designer, x, y, isWidgetsIntersects);
createXAbsorptionline(px, designer, width, cacheRecs);
createYAbsorptionline(py, designer, height, cacheRecs);
operatingRectangle.x = px.palce;
operatingRectangle.y = py.palce;
createEquidistantLine(pEquidistantX, pEquidistantY, operatingRectangle, designer);
Point sorptionPoint = new Point(px.palce,py.palce);
if (!px.isFind()){
Point sorptionPoint = new Point(px.palce, py.palce);
if (!px.isFind()) {
sorptionPoint.x = pEquidistantX.palce;
}
if (!py.isFind()){
if (!py.isFind()) {
sorptionPoint.y = pEquidistantY.palce;
}
return sorptionPoint;
}
public static void showForbiddenWindow(RectangleDesigner designer, int x, int y, boolean isIntersects){
if (isIntersects){
if(designer.getDesignerLocationOnScreen() != null) {
displayForbidWindow(x + designer.getDesignerLocationOnScreen().x, y + designer.getDesignerLocationOnScreen().y);
}
designer.setWidgetsIntersected(true);
}
else{
designer.setWidgetsIntersected(false);
hideForbidWindow();
}
}
private static void createXAbsorptionline(PlacePointing px, RectangleDesigner designer, int width, java.util.List<Rectangle> cacheRecs) {
Absorptionline line = null;
@ -446,25 +402,25 @@ public class MoveUtils {
designer.setYAbsorptionline(line);
}
private static void createEquidistantLine(PlacePointing px, PlacePointing py, Rectangle operatingRectangle, RectangleDesigner designer){
private static void createEquidistantLine(PlacePointing px, PlacePointing py, Rectangle operatingRectangle, RectangleDesigner designer) {
processEquidistantLinesList(px, py, operatingRectangle);
Absorptionline line = null;
if(equidistantLines.size() > 0) {
if (equidistantLines.size() > 0) {
int top = -1;
int left = -1;
int bottom = -1;
int right = -1;
for(int i = 0; i < equidistantLines.size(); i++){
if (equidistantLines.get(i).getDirection() == SwingConstants.TOP){
for (int i = 0; i < equidistantLines.size(); i++) {
if (equidistantLines.get(i).getDirection() == SwingConstants.TOP) {
top = equidistantLines.get(i).getReference();
}
if (equidistantLines.get(i).getDirection() == SwingConstants.LEFT){
if (equidistantLines.get(i).getDirection() == SwingConstants.LEFT) {
left = equidistantLines.get(i).getReference();
}
if (equidistantLines.get(i).getDirection() == SwingConstants.BOTTOM){
if (equidistantLines.get(i).getDirection() == SwingConstants.BOTTOM) {
bottom = equidistantLines.get(i).getReference();
}
if (equidistantLines.get(i).getDirection() == SwingConstants.RIGHT){
if (equidistantLines.get(i).getDirection() == SwingConstants.RIGHT) {
right = equidistantLines.get(i).getReference();
}
}
@ -479,13 +435,13 @@ public class MoveUtils {
designer.setEquidistantLine(line);
}
private static void processEquidistantLinesList(PlacePointing pEquidistantX, PlacePointing pEquidistantY, Rectangle operatingRectangle){
private static void processEquidistantLinesList(PlacePointing pEquidistantX, PlacePointing pEquidistantY, Rectangle operatingRectangle) {
EquidistantLine[] equidistantLines1 = new EquidistantLine[EQUIDISTANTLINE_UNIT];
//先按方向处理,只保留四个方向上距离最近
for(int count = 0; count < equidistantLines.size(); count++){
for (int direction = 0; direction < EQUIDISTANTLINE_UNIT; direction++){
if(equidistantLines.get(count).getDirection() == (direction + 1)){//direction 1,2,3,4 分别对应top,left,bottom,right
if(equidistantLines1[direction] != null
for (int count = 0; count < equidistantLines.size(); count++) {
for (int direction = 0; direction < EQUIDISTANTLINE_UNIT; direction++) {
if (equidistantLines.get(count).getDirection() == (direction + 1)) {//direction 1,2,3,4 分别对应top,left,bottom,right
if (equidistantLines1[direction] != null
&& equidistantLines1[direction].getDistance() > equidistantLines.get(count).getDistance()
|| equidistantLines1[direction] == null) {
equidistantLines1[direction] = equidistantLines.get(count);
@ -496,9 +452,9 @@ public class MoveUtils {
equidistantLines.clear();
//找list中横纵分别等距的组合
if (equidistantLines1[0] != null && equidistantLines1[2] != null){//top, bottom
if (equidistantLines1[0] != null && equidistantLines1[2] != null) {//top, bottom
int offset = equidistantLines1[0].getDistance() - equidistantLines1[2].getDistance();
if (Math.abs(offset) <= SORPTION_UNIT * 2){
if (Math.abs(offset) <= SORPTION_UNIT * 2) {
pEquidistantY.direction = SwingConstants.TOP;
equidistantLines.add(equidistantLines1[0]);
equidistantLines.add(equidistantLines1[2]);
@ -506,9 +462,9 @@ public class MoveUtils {
operatingRectangle.y = pEquidistantY.palce;
}
}
if (equidistantLines1[1] != null && equidistantLines1[3] != null){//left, right
if (equidistantLines1[1] != null && equidistantLines1[3] != null) {//left, right
int offset = equidistantLines1[1].getDistance() - equidistantLines1[3].getDistance();
if (Math.abs(offset) <= SORPTION_UNIT * 2){
if (Math.abs(offset) <= SORPTION_UNIT * 2) {
pEquidistantX.direction = SwingConstants.LEFT;
equidistantLines.add(equidistantLines1[1]);
equidistantLines.add(equidistantLines1[3]);
@ -519,26 +475,26 @@ public class MoveUtils {
}
//更新纵向行列线
private static void updateVerticalLine(int[] selfVertical, RectangleIterator iterator, Absorptionline line){
private static void updateVerticalLine(int[] selfVertical, RectangleIterator iterator, Absorptionline line) {
int[] targetArray = iterator.getVerticalLine();
if (intersectArrays(targetArray, selfVertical)){
if (intersectArrays(targetArray, selfVertical)) {
line.setVerticalLines(targetArray);
}
}
//更新横向行列线
private static void updateHorizontalLine(int[] selfHorizontal, RectangleIterator iterator, Absorptionline line){
private static void updateHorizontalLine(int[] selfHorizontal, RectangleIterator iterator, Absorptionline line) {
int[] targetArray = iterator.getHorizontalLine();
if (intersectArrays(targetArray, selfHorizontal)){
if (intersectArrays(targetArray, selfHorizontal)) {
line.setHorizontalLines(targetArray);
}
}
//检测两个数组是否有相交的部分
private static boolean intersectArrays(int[] targetArray, int[] selfArray){
private static boolean intersectArrays(int[] targetArray, int[] selfArray) {
for (int i : targetArray) {
for (int j : selfArray) {
if(i == j){
if (i == j) {
return true;
}
}
@ -547,7 +503,7 @@ public class MoveUtils {
return false;
}
private static class EquidistantLine{
private static class EquidistantLine {
//与操作rectangle的距离
private int distance;
//参考rectangle的位置
@ -555,33 +511,33 @@ public class MoveUtils {
//等距线的方向
private int direction;
EquidistantLine(int distance, int reference, int direction){
EquidistantLine(int distance, int reference, int direction) {
this.distance = distance;
this.reference = reference;
this.direction = direction;
}
public void setDistance(int distance){
public void setDistance(int distance) {
this.distance = distance;
}
public int getDistance(){
public int getDistance() {
return this.distance;
}
public void setReference(int reference){
public void setReference(int reference) {
this.reference = reference;
}
public int getReference(){
public int getReference() {
return this.reference;
}
public void setDirection(int direction){
public void setDirection(int direction) {
this.direction = direction;
}
public int getDirection(){
public int getDirection() {
return this.direction;
}
}

7
designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java

@ -22,7 +22,6 @@ public class WidgetForbidWindow extends JWindow {
*/
public WidgetForbidWindow() {
this.add(promptButton);
this.setSize(WIDTH, HEIGHT);
}
@ -31,18 +30,16 @@ public class WidgetForbidWindow extends JWindow {
*
* @param x x坐标
* @param y y坐标
*
*/
public void showWindow(int x, int y){
public void showWindow(int x, int y) {
this.setLocation(x - WIDTH / 2, y - HEIGHT / 2);
this.setVisible(true);
}
/**
* 隐藏当前窗口
*
*/
public void hideWindow(){
public void hideWindow() {
this.setVisible(false);
}
}

2
designer_base/src/com/fr/design/locale/designer.properties

@ -543,7 +543,7 @@ FR-Designer_Left_Display=Left
FR-Designer_About_Version=Version
FR-Designer_About_CopyRight=Copy Right
FR-Designer_Service_Phone=Service Phone
FR-Designer_Allow_Blank=Allow Blank
FR-Designer_Allow_Null=Allow Null
FR-Designer_PageSetup_Page=Page
FR-Designer_Custom_Job_Description=Description
FR-Designer_Property=Property

2
designer_base/src/com/fr/design/locale/designer_en_US.properties

@ -544,7 +544,7 @@ FR-Designer_Left_Display=Left
FR-Designer_About_Version=Version
FR-Designer_About_CopyRight=Copy Right
FR-Designer_Service_Phone=Service Phone
FR-Designer_Allow_Blank=Allow Null
FR-Designer_Allow_Null=Allow Null
FR-Designer_PageSetup_Page=Page
FR-Designer_Custom_Job_Description=Description
FR-Designer_Property=Property

2
designer_base/src/com/fr/design/locale/designer_ja_JP.properties

@ -518,7 +518,7 @@ FR-Designer_Left_Display=\u5DE6\u8868\u793A
FR-Designer_About_Version=\u30D0\u30FC\u30B8\u30E7\u30F3
FR-Designer_About_CopyRight=\u8457\u4F5C\u6A29\u6240\u6709
FR-Designer_Service_Phone=\u30B5\u30FC\u30D3\u30B9\u96FB\u8A71\uFF1A
FR-Designer_Allow_Blank=\u7A7A\u6B04\u3042\u308A
FR-Designer_Allow_Null=\u7A7A\u6B04\u3042\u308A
FR-Designer_PageSetup_Page=\u30DA\u30FC\u30B8
FR-Designer_Custom_Job_Description=\u8A18\u8FF0
FR-Designer_Property=\u5C5E\u6027

2
designer_base/src/com/fr/design/locale/designer_ko_KR.properties

@ -514,7 +514,7 @@ FR-Designer_Left_Display=\uC67C\uCABD\uBCF4\uC774\uAE30
FR-Designer_About_Version=\uBC84\uC804
FR-Designer_About_CopyRight=\uD310\uAD8C\uC18C\uC720
FR-Designer_Service_Phone=\uC11C\uBE44\uC2A4\uC804\uD654\uFF1A
FR-Designer_Allow_Blank=\uBE48\uCE78\uD5C8\uC6A9
FR-Designer_Allow_Null=\uBE48\uCE78\uD5C8\uC6A9
FR-Designer_PageSetup_Page=\uC6F9\uD398\uC774\uC9C0
FR-Designer_Custom_Job_Description=\uC124\uBA85
FR-Designer_Property=\uC18D\uC131

2
designer_base/src/com/fr/design/locale/designer_zh_CN.properties

@ -548,7 +548,7 @@ FR-Designer_Left_Display=\u5DE6\u5C55\u793A
FR-Designer_About_Version=\u7248\u672C
FR-Designer_About_CopyRight=\u7248\u6743\u6240\u6709
FR-Designer_Service_Phone=\u670D\u52A1\u7535\u8BDD\uFF1A
FR-Designer_Allow_Blank=\u5141\u8BB8\u4E3A\u7A7A
FR-Designer_Allow_Null=\u5141\u8BB8\u4E3A\u7A7A
FR-Designer_PageSetup_Page=\u9875\u9762
FR-Designer_Custom_Job_Description=\u63CF\u8FF0
FR-Designer_Property=\u5C5E\u6027

2
designer_base/src/com/fr/design/locale/designer_zh_TW.properties

@ -536,7 +536,7 @@ FR-Designer_Left_Display=\u5DE6\u986F\u793A
FR-Designer_About_Version=\u7248\u672C
FR-Designer_About_CopyRight=\u7248\u6B0A\u6240\u6709
FR-Designer_Service_Phone=\u670D\u52D9\u96FB\u8A71\uFF1A
FR-Designer_Allow_Blank=\u5141\u8A31\u70BA\u7A7A\u767D
FR-Designer_Allow_Null=\u5141\u8A31\u70BA\u7A7A\u767D
FR-Designer_PageSetup_Page=\u9801\u9762
FR-Designer_Custom_Job_Description=\u63CF\u8FF0
FR-Designer_Property=\u5C6C\u6027

67
designer_base/src/com/fr/design/mainframe/BaseJForm.java

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

18
designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java

@ -12,52 +12,52 @@ public interface ToolBarMenuDockPlus {
*
* @return 工具
*/
public ToolBarDef[] toolbars4Target();
ToolBarDef[] toolbars4Target();
/**
* 文件菜单的子菜单
*
* @return 子菜单
*/
public ShortCut[] shortcut4FileMenu();
ShortCut[] shortcut4FileMenu();
/**
* 目标的菜单
*
* @return 菜单
*/
public MenuDef[] menus4Target();
MenuDef[] menus4Target();
/**
* 表单的工具栏
*
* @return 表单工具栏
*/
public JPanel[] toolbarPanes4Form();
JPanel[] toolbarPanes4Form();
/**
* 表单的工具按钮
*
* @return 工具按钮
*/
public JComponent[] toolBarButton4Form();
JComponent[] toolBarButton4Form();
/**
* 权限细粒度状态下的工具面板
*
* @return 工具面板
*/
public JComponent toolBar4Authority();
JComponent toolBar4Authority();
public int getMenuState();
int getMenuState();
public int getToolBarHeight();
int getToolBarHeight();
/**
* 导出菜单的子菜单 目前用于图表设计器
*
* @return 子菜单
*/
public ShortCut[] shortcut4ExportMenu();
ShortCut[] shortcut4ExportMenu();
}

73
designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java

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

11
designer_base/src/com/fr/design/utils/ComponentUtils.java

@ -12,6 +12,9 @@ import java.util.ArrayList;
*/
public class ComponentUtils {
private ComponentUtils() {
}
public static boolean isComponentVisible(Component comp) {
if (!comp.isVisible() && !isRootComponent(comp)) {
return false;
@ -79,7 +82,7 @@ public class ComponentUtils {
for (int i = 0; i < count; i++) {
Component child = container.getComponent(i);
if (child == target) {
if (child.equals(target)) {
return i;
}
}
@ -105,10 +108,10 @@ public class ComponentUtils {
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRect(JComponent root) {
Rectangle root_bounds = ComponentUtils.getRelativeBounds(root);
Rectangle rootBounds = ComponentUtils.getRelativeBounds(root);
Rectangle rect = computeVisibleRectRel2Root(root);
rect.x -= root_bounds.x;
rect.y -= root_bounds.y;
rect.x -= rootBounds.x;
rect.y -= rootBounds.y;
return rect;
}

20
designer_chart/build.dev.gradle

@ -1,8 +1,26 @@
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包的版本

85
designer_chart/build.dev.gradle.bak

@ -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

2
designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java

@ -22,7 +22,7 @@ public interface IndependentChartUIProvider extends Level {
String XML_TAG = "IndependentChartUIProvider";
int CURRENT_API_LEVEL = 4;
int CURRENT_API_LEVEL = 3;
/**
* 图表的类型定义界面类型就是属性表的第一个界面

19
designer_form/build.dev.gradle

@ -1,8 +1,25 @@
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包版本

4
designer_form/build.dev.gradle.bak

@ -4,7 +4,7 @@ tasks.withType(JavaCompile){
options.encoding = 'UTF-8'
}
//jdk版本
sourceCompatibility=1.8
sourceCompatibility=1.7
//jar包版本
version='8.0'
@ -20,7 +20,7 @@ sourceSets{
main{
java{
srcDirs=["${srcDir}/src",
"${srcDir}/../designer/src"]
"${srcDir}/../designer/src"]
}
}
}

17
designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java

@ -6,6 +6,7 @@ import com.fr.design.designer.creator.XCreator;
/**
* 该接口是LayoutManager的BeanInfo类标准Java平台没有提供布局管理器的BeanInfo类
* 对于界面设计工具来说还需一些特殊的行为
*
* @since 6.5.3
*/
public interface LayoutAdapter {
@ -15,15 +16,17 @@ public interface LayoutAdapter {
* 管理适配器的accept来决定当前位置是否可以放置并提供特殊的标识比如红色区域标识
* 如在BorderLayout中如果某个方位已经放置了组件则此时应该返回false标识该区域不可以
* 放置
*@param creator 组件
*@param x 添加的位置x该位置是相对于container的
*@param y 添加的位置y该位置是相对于container的
*@return 是否可以放置
*
* @param creator 组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否可以放置
*/
boolean accept(XCreator creator, int x, int y);
/**
* 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适如果不合适就需要重新fix一下
*
* @param creator 组件
*/
void fix(XCreator creator);
@ -31,6 +34,7 @@ public interface LayoutAdapter {
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
@ -45,6 +49,7 @@ public interface LayoutAdapter {
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
*
* @param child 组件
*/
void showComponent(XCreator child);
@ -53,6 +58,7 @@ public interface LayoutAdapter {
/**
* 组件叠放顺序前插入
*
* @param target 目标组件
* @param added 插入组件
*/
@ -60,6 +66,7 @@ public interface LayoutAdapter {
/**
* 组件叠放顺序后插入
*
* @param target 目标组件
* @param added 放置组件
*/
@ -67,6 +74,7 @@ public interface LayoutAdapter {
/**
* 能否放置更多组件
*
* @return 能则返回true
*/
boolean canAcceptMoreComponent();
@ -77,6 +85,7 @@ public interface LayoutAdapter {
/**
* 删除组件
*
* @param creator 组件
* @param initWidth 组件之前宽度
* @param initHeight 组件之前高度

11
designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java

@ -1,13 +1,12 @@
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 {

27
designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java

@ -1,8 +1,5 @@
package com.fr.design.designer.beans.adapters.layout;
import java.awt.LayoutManager;
import com.fr.general.ComparatorUtils;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -13,6 +10,9 @@ import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.general.ComparatorUtils;
import java.awt.*;
public abstract class AbstractLayoutAdapter implements LayoutAdapter {
@ -26,13 +26,14 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 是否使用控件备份大小
*
* @param xCreator 控件
* @return 所在容器相同且支持备份的话返回true
*/
public boolean whetherUseBackupSize(XCreator xCreator) {
Class clazz = container.getClass();
Class bkClazz = null;
if(xCreator.getBackupParent() != null) {
if (xCreator.getBackupParent() != null) {
bkClazz = xCreator.getBackupParent().getClass();
}
return ComparatorUtils.equals(bkClazz, clazz)
@ -41,6 +42,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 是否支持用备份大小
*
* @return
*/
public boolean supportBackupSize() {
@ -49,6 +51,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适如果不合适就需要重新fix一下
*
* @param creator 组件
*/
public void fix(XCreator creator) {
@ -56,6 +59,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
*
* @param child 组件
*/
@Override
@ -66,6 +70,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
@ -83,9 +88,10 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 删除组件
*
* @param creator 组件
* @param initWidth 组件之前宽度
* @param initHeight 组件之前高度
* @param creatorWidth
* @param creatorHeight
*/
public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) {
delete(creator, creatorWidth, creatorHeight);
@ -98,6 +104,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 增加下一个组件
*
* @param dragged 组件
*/
@Override
@ -108,6 +115,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 目标控件位置插入组件
*
* @param target 目标
* @param added 增加组件
*/
@ -126,6 +134,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 插在目标组件后面
*
* @param target 目标
* @param added 增加组件
*/
@ -155,6 +164,7 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
/**
* 是否能接收更多的组件
*
* @return 能则返回true
*/
@Override
@ -171,4 +181,9 @@ public abstract class AbstractLayoutAdapter implements LayoutAdapter {
public GroupModel getLayoutProperties() {
return null;
}
public XLayoutContainer getContainer() {
return this.container;
}
}

105
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java

@ -1,7 +1,5 @@
package com.fr.design.designer.beans.adapters.layout;
import java.awt.*;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -9,13 +7,14 @@ import com.fr.design.designer.beans.painters.FRAbsoluteLayoutPainter;
import com.fr.design.designer.creator.*;
import com.fr.design.designer.properties.BoundsGroupModel;
import com.fr.design.designer.properties.FRAbsoluteLayoutPropertiesGroupModel;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.widget.BoundsWidget;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import java.awt.*;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上
private boolean isAdd2ParentLayout = false;
@ -42,6 +41,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 是否能在指定位置添加组件
*
* @param creator 组件
* @param x 坐标x
* @param y 坐标y
@ -57,70 +57,61 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//布局控件要先判断是不是可编辑
//可以编辑,按原有逻辑判断
//不可编辑,当成一整个控件处理
if (comp == null){
if (comp == null) {
return false;
}
//参数面板内的组件不允许拖往绝对布局中
if (creator.getParent() != null && ((XCreator)creator.getParent()).acceptType(XWParameterLayout.class)){
if (creator.getParent() != null && ((XCreator) creator.getParent()).acceptType(XWParameterLayout.class)) {
Rectangle rec = creator.getBounds();
rec.y = creator.getParent().getHeight() - rec.height;
creator.setBounds(rec);
return false;
}
//判断下组件能不能拖入绝对布局
if (!creator.canEnterIntoAbsolutePane()){
//判断组件能不能拖入绝对布局
if (!creator.canEnterIntoAbsolutePane()) {
return false;
}
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout();
if(topLayout != null){
if (topLayout.isEditable()){
return topLayoutAccept(creator, x, y, topLayout);
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout();
if (topLayout != null) {
if (topLayout.isEditable()) {
return topLayoutAccept(creator, x, y);
}
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
else if (((XLayoutContainer) topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
return false;
} else {
return acceptWidget(x, y);
}
else {
return acceptWidget(creator, x, y);
}
}
else{
} else {
FRLogger.getLogger().error("top layout is null!");
}
return false;
}
//toplayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) {
//判断有没有和当前控件重叠
//topLayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y) {
//允许组件重叠,可以不判断有没有和当前控件重叠
//先计算当前控件的位置
int creatorX, creatorY;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
creatorX = creatorRectangle.x;
creatorY = creatorRectangle.y;
} else {
//这边计算得到的组件其实位置是正确的,
//因为传入的x和y已经加上了宽度或者高度的一半,再减去相同的宽度和高度的一半是没区别的,
// 例如高度为21,那么就是+10-10;
// 高度为20,那么就是+10-10; 没区别
int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2;
creatorX = x - w;
creatorY = y - h;
}
//再判断和布局中其他控件重叠
Rectangle curRec = new Rectangle(creatorX, creatorY, creator.getWidth(), creator.getHeight());
WAbsoluteLayout wAbsoluteLayout = (WAbsoluteLayout)topLayout.toData();
for (int i = 0, count = wAbsoluteLayout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) wAbsoluteLayout.getWidget(i);
Rectangle rectangle = temp.getBounds();
if (curRec.intersects(rectangle)){
return false;
}
}
if (creatorX < 0 || creatorX + creator.getWidth() > container.getWidth()) {
return false;
}
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()){
if (creatorY < 0 || creatorY + creator.getHeight() > container.getHeight()) {
return false;
}
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight()
@ -129,15 +120,16 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
*
* @param parentComp 鼠标所在区域的组件
* @param x 坐标x
* @param y 坐标y
* @return 是则返回true
*/
public boolean isTrisectionArea(Component parentComp, int x, int y) {
XCreator creator = (XCreator)parentComp;
XCreator creator = (XCreator) parentComp;
trisectAreaDirect = 0;
if (container.getComponentCount()<=1) {
if (container.getComponentCount() <= 1) {
return false;
}
int maxWidth = parentComp.getWidth();
@ -145,23 +137,23 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
int xL = parentComp.getX();
int yL = parentComp.getY();
// 组件宽高的十分之一和默认值取大
int minRangeWidth = Math.max(maxWidth/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int minRangeHeight = Math.max(maxHeight/BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
if(y<yL+minRangeHeight ) {
int minRangeWidth = Math.max(maxWidth / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
int minRangeHeight = Math.max(maxHeight / BORDER_PROPORTION, DEFAULT_AREA_LENGTH);
if (y < yL + minRangeHeight) {
// 在组件上侧三等分
trisectAreaDirect = COMP_TOP;
} else if(y>yL+maxHeight-minRangeHeight) {
} else if (y > yL + maxHeight - minRangeHeight) {
// 在组件下侧三等分
trisectAreaDirect = COMP_BOTTOM;
} else if (x<xL+minRangeWidth) {
} else if (x < xL + minRangeWidth) {
// 在组件左侧三等分
trisectAreaDirect = COMP_LEFT;
} else if(x>xL+maxWidth-minRangeWidth) {
} else if (x > xL + maxWidth - minRangeWidth) {
// 在组件右侧三等分
trisectAreaDirect = COMP_RIGHT;
}
// tab布局的边界特殊处理,不进行三等分
if(!creator.getTargetChildrenList().isEmpty()){
if (!creator.getTargetChildrenList().isEmpty()) {
return false;
}
@ -169,11 +161,10 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
}
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(XCreator creator, int x, int y){
private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;
@ -224,7 +215,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override
protected void addComp(XCreator creator, int x, int y) {
if(!isAdd2ParentLayout) {
if (!isAdd2ParentLayout) {
Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x;
y = y - r.y;
@ -250,7 +241,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
layout.updateBoundsWidget(creator);
updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container);
}else{
} else {
fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator);
@ -265,7 +256,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
}
private void updateCreatorBackBound() {
for (int i=0,size=container.getComponentCount(); i<size; i++) {
for (int i = 0, size = container.getComponentCount(); i < size; i++) {
XCreator creator = (XCreator) container.getComponent(i);
creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds());
@ -279,37 +270,40 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 新拖入组件时计算调整其他关联组件位置大小
*
* @param child 新拖入的组件
* @param x 鼠标所在x坐标
* @param y 鼠标所在y坐标
*/
private void fixAbsolute(XCreator child, int x, int y) {
Component parentComp = container.getComponentAt(x, y);
if (container.getComponentCount()==0){
if (container.getComponentCount() == 0) {
child.setLocation(0, 0);
child.setSize(parentComp.getWidth(), parentComp.getHeight());
} else if(isCrossPointArea(parentComp, x, y)){
} else if (isCrossPointArea(parentComp, x, y)) {
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y);
//TODO 尽量不要出现这种写法吧?if else条件要么互斥,要么多个if判断return,不要在一条if else语句里面return吧?
return;
} else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了
fixTrisect(parentComp, child, x, y);
return;
} else{
} else {
fixHalve(parentComp, child, x, y);
}
}
/**
* 组件拖拽后调整大小
*
* @param creator 组件
*/
@Override
public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout)container.toData();
fix(creator,creator.getX(),creator.getY());
wabs.setBounds(creator.toData(),creator.getBounds());
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData();
fix(creator, creator.getX(), creator.getY());
wabs.setBounds(creator.toData(), creator.getBounds());
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator);
@ -317,11 +311,12 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 调整组件大小到合适尺寸位置
*
* @param creator 组件
* @param x 坐标x
* @param y 坐标y
*/
public void fix(XCreator creator ,int x, int y) {
public void fix(XCreator creator, int x, int y) {
int height = creator.getHeight();
int width = creator.getWidth();
if (x < 0) {
@ -343,7 +338,7 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
@Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
return new BoundsGroupModel((XWAbsoluteLayout)container, creator);
return new BoundsGroupModel((XWAbsoluteLayout) container, creator);
}
@Override

57
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java

@ -3,12 +3,6 @@
*/
package com.fr.design.designer.beans.adapters.layout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
@ -31,6 +25,10 @@ import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.widget.BoundsWidget;
import com.fr.general.ComparatorUtils;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* 自适应布局的容器适配器
*
@ -52,6 +50,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
public void setEdit(boolean edit) {
isEdit = edit;
}
/**
* 构造函数
*
@ -269,15 +268,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
return super.isCrossPointArea(currentComp, x, y);
}
protected void initCompsList() {
super.initCompsList();
}
protected void clearCompsList() {
super.clearCompsList();
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout){
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return mainLayout.getBounds();
}
@ -359,7 +351,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param difference 偏移量
*/
public void calculateBounds(Rectangle backupBound, Rectangle bounds, XCreator xCreator, int row, int difference) {
Rectangle rc = new Rectangle(0,0,0,0);
Rectangle rc = new Rectangle(0, 0, 0, 0);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(xCreator);
if (parent != null) {
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
@ -370,17 +362,17 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
//处理左右延伸
switch (row) {
case 0:
if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() +rc.x) {
if (backupBound.width + backupBound.x == container.getWidth() - margin.getRight() + rc.x) {
x += difference;
}
break;
case 1:
if(backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() +rc.y){
if (backupBound.y + backupBound.height == container.getHeight() - margin.getBottom() + rc.y) {
y += difference;
}
break;
}
bounds.setLocation(x,y);
bounds.setLocation(x, y);
xCreator.setBackupBound(backupBound);
xCreator.setBounds(bounds);
this.fix(xCreator);
@ -424,7 +416,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的坐标值
private int adjustCoordinateByDependingLine(int coordinate, int[] coordinates) {
if(!isEdit) {
if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) {
if (coordinate == coordinates[i]) {
continue;
@ -440,7 +432,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
// 根据需要依附的位置调整拖拽的距离
private int adjustDiffByDependingLine(int coordinate, int[] coordinates, int diff) {
if(!isEdit) {
if (!isEdit) {
for (int i = 0; i < coordinates.length; i++) {
if (coordinate + diff > coordinates[i] - DEPENDING_SCOPE && coordinate + diff < coordinates[i] + DEPENDING_SCOPE) {
diff = coordinates[i] - coordinate;
@ -558,8 +550,8 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minWidth - getMinWidth(leftComps));
}
//重新计算左右两侧组件size、point
if (CalculateLefttRelatComponent(difference)) {
CalculateRightRelatComponent(objx + difference, -difference);
if (calculateLefttRelatComponent(difference)) {
calculateRightRelatComponent(objx + difference, -difference);
}
}
@ -674,10 +666,9 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
difference = Math.max(difference, minHeight - getMinHeight(upComps));
}
//重新计算上下两侧组件size、point
if (CalculateUpRelatComponent(difference)) {
CalculateDownRelatComponent(objY + difference, -difference);
if (calculateUpRelatComponent(difference)) {
calculateDownRelatComponent(objY + difference, -difference);
}
;
}
/**
@ -757,13 +748,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
int height = creatorHeight;
calculateRelatedComponent(x, y, width, height);
if (!rightComps.isEmpty() && getAllHeight(rightComps) == height) {
CalculateRightRelatComponent(x, width + actualVal);
calculateRightRelatComponent(x, width + actualVal);
} else if (!leftComps.isEmpty() && getAllHeight(leftComps) == height) {
CalculateLefttRelatComponent(width + actualVal);
calculateLefttRelatComponent(width + actualVal);
} else if (!downComps.isEmpty() && getAllWidth(downComps) == width) {
CalculateDownRelatComponent(y, height + actualVal);
calculateDownRelatComponent(y, height + actualVal);
} else if (!upComps.isEmpty() && getAllWidth(upComps) == width) {
CalculateUpRelatComponent(height + actualVal);
calculateUpRelatComponent(height + actualVal);
} else {
// 由于布局三等分的存在,可能会出现删除组件时,找不到关联的组件填充,此时特殊处理
calculateNoRelatedComponent(x, y, width, height);
@ -1069,7 +1060,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* @param objX 调整后的坐标x
* @param objWidth 调整后的宽度
*/
protected void CalculateRightRelatComponent(int objX, int objWidth) {
protected void calculateRightRelatComponent(int objX, int objWidth) {
int count = rightComps.size();
for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) rightComps.get(i);
@ -1109,7 +1100,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/
protected boolean CalculateLefttRelatComponent(int objWidth) {
protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) {
return false;
}
@ -1127,7 +1118,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸下边框 调整下方的组件位置大小
*/
protected void CalculateDownRelatComponent(int objY, int objHeight) {
protected void calculateDownRelatComponent(int objY, int objHeight) {
int count = downComps.size();
for (int i = 0; i < count; i++) {
XCreator creator = (XCreator) downComps.get(i);
@ -1167,7 +1158,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸上边框 调整上方的组件位置大小
*/
protected boolean CalculateUpRelatComponent(int objHeight) {
protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) {
return false;
}

6
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java

@ -7,7 +7,6 @@ package com.fr.design.designer.beans.adapters.layout;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.XWidgetCreator;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
@ -28,8 +27,6 @@ import java.awt.*;
* @date 2014-6-24
*/
public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
//标题栏高度对tab布局内部组件的y坐标造成了偏移
private static int TAB_HEIGHT = 40;
/**
* 构造函数
@ -63,13 +60,12 @@ public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
// 经过accept判断后,container会被改变,先备份
XLayoutContainer backUpContainer = container;
Rectangle rect = ComponentUtils.getRelativeBounds(container);
int posX = x - rect.x;
int posY = y - rect.y;
if (!accept(creator, posX, posY)) {
return false;
}
// posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到
// posX,posY是新拖入组件相对于容器的位置,若在tab布局的边缘,则需要把新组件添加到l
// 父层自适应布局中,这时候的添加位置就是tab布局所在的位置
if (this.intersectsEdge(posX, posY, backUpContainer)) {
if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) {

93
designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java

@ -3,19 +3,17 @@
*/
package com.fr.design.designer.beans.location;
import java.awt.*;
import com.fr.design.beans.location.Absorptionline;
import com.fr.design.beans.location.MoveUtils;
import com.fr.design.designer.creator.*;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WParameterLayout;
import com.fr.form.ui.widget.BoundsWidget;
import java.awt.*;
/**
* @author richer
* @since 6.5.3
@ -28,27 +26,25 @@ public abstract class AccessDirection implements Direction {
abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer,
Rectangle oldbounds);
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldBounds);
protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) {
protected int[] sorption(int x, int y, Rectangle currentBounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null);
designer.getStateModel().setXAbsorptionline(null);
designer.getStateModel().setYAbsorptionline(null);
return new int[] { x, y };
return new int[]{x, y};
} else {
int posy = current_bounds.y;
Point relativePoint = getRelativePoint(x, y, current_bounds,designer);
sorptionPoint(relativePoint,current_bounds, designer);
return new int[] { relativePoint.x, relativePoint.y };
Point relativePoint = getRelativePoint(x, y, currentBounds, designer);
sorptionPoint(relativePoint, currentBounds, designer);
return new int[]{relativePoint.x, relativePoint.y};
}
}
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) {
protected Point getRelativePoint(int x, int y, Rectangle currentBounds, FormDesigner designer) {
if (x < 0) {
x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
@ -64,12 +60,11 @@ public abstract class AccessDirection implements Direction {
return new Point(x, y);
}
protected void sorptionPoint(Point point, Rectangle current_bounds,FormDesigner designer) {
boolean findInX = current_bounds.getWidth() <= MoveUtils.SORPTION_UNIT ? true : false;
boolean findInY = current_bounds.getHeight() <= MoveUtils.SORPTION_UNIT ? true : false;
WAbsoluteLayout layout =getLayout(designer);
protected void sorptionPoint(Point point, Rectangle currentBounds, FormDesigner designer) {
boolean findInX = currentBounds.getWidth() <= MoveUtils.SORPTION_UNIT;
boolean findInY = currentBounds.getHeight() <= MoveUtils.SORPTION_UNIT;
WAbsoluteLayout layout = getLayout(designer);
FormSelection selection = designer.getSelectionModel().getSelection();
boolean isWidgetsIntersect = false;
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) {
@ -105,21 +100,18 @@ public abstract class AccessDirection implements Direction {
break;
}
if (current_bounds.intersects(bounds) && !(layout instanceof WParameterLayout)){
isWidgetsIntersect = true;
}
}
processRectangleIntersects(designer, point.x, point.y, isWidgetsIntersect);
setDesignerStateModelProperties(designer, findInX, findInY, current_bounds, point);
setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
}
private void setDesignerStateModelProperties (FormDesigner designer, boolean findInX, boolean findInY, Rectangle current_bounds, Point point) {
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
private void setDesignerStateModelProperties(FormDesigner designer, boolean findInX, boolean findInY, Rectangle
currentBounds, Point point) {
designer.getStateModel().setXAbsorptionline(findInX && currentBounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null);
designer.getStateModel().setYAbsorptionline(findInY && currentBounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null);
designer.getStateModel().setEquidistantLine(null);
}
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection){
private Rectangle getWidgetRelativeBounds(Rectangle bounds, FormSelection selection) {
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) {
@ -131,32 +123,19 @@ public abstract class AccessDirection implements Direction {
return relativeRec;
}
private void processRectangleIntersects(FormDesigner designer, int x, int y, boolean isIntersects){
if(isIntersects){
if(designer.getLocationOnScreen() != null) {
MoveUtils.displayForbidWindow(x + designer.getLocationOnScreen().x, y + designer.getLocationOnScreen().y);
}
designer.setWidgetsIntersect(true);
}
else{
MoveUtils.hideForbidWindow();
designer.setWidgetsIntersect(false);
}
}
private WAbsoluteLayout getLayout(final FormDesigner designer){
private WAbsoluteLayout getLayout(final FormDesigner designer) {
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(
designer.getTarget().getContainer());
WAbsoluteLayout layout;
if (formLayoutContainer.acceptType(XWBorderLayout.class)){//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面
if (formLayoutContainer.acceptType(XWBorderLayout.class)) {//看起来这边的作用应该是为了区别cpt(得到XWParameterLayout)还是frm(得到XWBorderLayout)的参数界面
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if(container instanceof XWAbsoluteLayout){
layout = ((XWAbsoluteLayout)container).toData();
}
else {
if (container instanceof XWAbsoluteLayout) {
layout = ((XWAbsoluteLayout) container).toData();
} else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData();
}
} else{
} else {
layout = (WAbsoluteLayout) designer.getTarget().getContainer();
}
return layout;
@ -164,20 +143,26 @@ public abstract class AccessDirection implements Direction {
/**
* 拖拽
*
* @param dx 坐标x
* @param dy 坐标y
* @param designer 设计界面
*/
public void drag(int dx, int dy, FormDesigner designer) {
Rectangle rec = getDraggedBounds(dx, dy, designer.getSelectionModel().getSelection().getRelativeBounds(), designer, designer.getSelectionModel().getSelection().getBackupBounds());
if (rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
} else {
return;
}
//设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。
if(rec.height == MINHEIGHT){
if (rec.height == MINHEIGHT) {
ymin = rec.y;
}
if(rec.height == MINHEIGHT - 1){
if (rec.height == MINHEIGHT - 1) {
ymin = ymin == rec.y ? rec.y : rec.y - 1;
}
if(rec.height < MINHEIGHT){
if (rec.height < MINHEIGHT) {
rec.height = MINHEIGHT;
rec.y = ymin;
}
@ -185,20 +170,19 @@ public abstract class AccessDirection implements Direction {
if (rec.width == MINWIDTH) {
xmin = rec.x;
}
if(rec.width == MINWIDTH - 1){
if (rec.width == MINWIDTH - 1) {
xmin = xmin == rec.x ? rec.x : rec.x - 1;
}
if (rec.width < MINWIDTH) {
rec.width = MINWIDTH;
rec.x = xmin;
}
if(rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
}
}
/**
* 更新鼠标指针形状
*
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
@ -214,6 +198,7 @@ public abstract class AccessDirection implements Direction {
/**
* 生成组件备用的bound
*
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {

160
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -1,21 +1,14 @@
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;
@ -23,15 +16,21 @@ import com.fr.design.mainframe.FormSelectionUtils;
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 static final int BORDER_PROPORTION = 20;
private static FormSelection clipboard = new FormSelection();
private FormDesigner designer;
private FormSelection selection;
private Rectangle hotspot_bounds;
private Rectangle hotspotBounds;
public SelectionModel(FormDesigner designer) {
this.designer = designer;
@ -43,19 +42,21 @@ public class SelectionModel {
*/
public void reset() {
selection.reset();
hotspot_bounds = null;
hotspotBounds = null;
}
/**
* formSelction是否为空
*
* @return 是否为空
*/
public static boolean isEmpty(){
return CLIP_BOARD.isEmpty();
public static boolean isEmpty() {
return clipboard.isEmpty();
}
/**
* 鼠标点击一下所选中的单个组件按下Ctrl或者shift键时鼠标可以进行多选
*
* @param e 鼠标事件
*/
public void selectACreatorAtMouseEvent(MouseEvent e) {
@ -63,13 +64,12 @@ public class SelectionModel {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset();
}
// 获取e所在的组件
XCreator comp = designer.getComponentAt(e);
//布局组件的顶层布局如不可编辑,要获取其顶层布局
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();
if(topLayout != null && !topLayout.isEditable()){
if (topLayout != null && !topLayout.isEditable()) {
comp = topLayout;
}
@ -89,7 +89,7 @@ public class SelectionModel {
*/
public void cutSelectedCreator2ClipBoard() {
if (hasSelectionComponent()) {
selection.cut2ClipBoard(CLIP_BOARD);
selection.cut2ClipBoard(clipboard);
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED);
designer.repaint();
}
@ -100,25 +100,23 @@ public class SelectionModel {
*/
public void copySelectedCreator2ClipBoard() {
if (!selection.isEmpty()) {
selection.copy2ClipBoard(CLIP_BOARD);
selection.copy2ClipBoard(clipboard);
}
}
/**
* 从剪切板粘帖组件
*
* @return
*/
public boolean pasteFromClipBoard() {
if (!CLIP_BOARD.isEmpty()) {
XLayoutContainer parent = null;
if (!clipboard.isEmpty()) {
if (!hasSelectionComponent()) {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),CLIP_BOARD, DELTA_X_Y, DELTA_X_Y);
//未选
unselectedPaste();
} 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);
}
//已选
selectedPaste();
}
} else {
Toolkit.getDefaultToolkit().beep();
@ -130,6 +128,65 @@ public class SelectionModel {
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 + BORDER_PROPORTION);
} else {
Rectangle rec = selection.getRelativeBounds();
//自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard,
rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION);
}
} 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 parent = null;
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局
Rectangle rec = selection.getRelativeBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + rec.width / 2, rec.y +
rec.height - BORDER_PROPORTION);
} else if (parent != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局
Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
}
/**
* 删除当前所有选择的组件
*/
@ -138,7 +195,7 @@ public class SelectionModel {
if (roots.length > 0) {
for (XCreator creator : roots) {
if(creator.acceptType(XWParameterLayout.class)){
if (creator.acceptType(XWParameterLayout.class)) {
designer.removeParaComponent();
}
@ -171,14 +228,14 @@ public class SelectionModel {
* 设置选择区域
*/
public void setHotspotBounds(Rectangle rect) {
hotspot_bounds = rect;
hotspotBounds = rect;
}
/**
* 获得当前选择区域
*/
public Rectangle getHotspotBounds() {
return hotspot_bounds;
return hotspotBounds;
}
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) {
@ -203,14 +260,48 @@ public class SelectionModel {
/**
* 是否有组件被选择如果所选组件是最底层容器也视为无选择
*
* @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 hasSelectionComponent() {
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null;
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);
//选中的是否是相对布局编辑器本身
boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class);
return !(tabEditor || absoluteEditor || relativeEditor);
} else {
return false;
}
} else {
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
return selectionXCreator != null && selectionXCreator.getParent() != null;
}
}
/**
* 移动组件至指定位置
*
* @param x 坐标x
* @param y 坐标y
*/
@ -248,11 +339,10 @@ public class SelectionModel {
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())) {
if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir
.getActual())) {
dir = Location.outer;
}
}
} else {
dir = Location.outer;
}

12
designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java

@ -11,6 +11,7 @@ import java.util.ArrayList;
/**
* 一些控件专属的容器如标题容器sclae容器
*
* @author jim
* @date 2014-11-7
*/
@ -22,6 +23,7 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
/**
* 得到属性名
*
* @return 属性名
* @throws IntrospectionException
*/
@ -36,7 +38,7 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
*/
@Override
public String getIconPath() {
if(this.getXCreator(XWScaleLayout.INDEX) != null){
if (this.getXCreator(XWScaleLayout.INDEX) != null) {
return this.getXCreator(XWScaleLayout.INDEX).getIconPath();
}
return "/com/fr/web/images/form/resources/text_field_16.png";
@ -45,24 +47,28 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
/**
* 控件树不显示此组件
*
* @param path 控件树list
*/
public void notShowInComponentTree(ArrayList<Component> path) {
path.remove(path.size()-1);
path.remove(path.size() - 1);
}
/**
* 重置组件的名称
*
* @param name 名称
*/
public void resetCreatorName(String name) {
super.resetCreatorName(name);
XCreator child = getXCreator(XWScaleLayout.INDEX);
//实现WTitleLayout的SetWidgetName
child.toData().setWidgetName(name);
}
/**
* 返回对应属性表的组件scale和title返回其子组件
*
* @return 组件
*/
public XCreator getPropertyDescriptorCreator() {
@ -71,6 +77,7 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
/**
* 是否作为控件树的叶子节点
*
* @return 是则返回true
*/
public boolean isComponentTreeLeaf() {
@ -79,6 +86,7 @@ public abstract class DedicateLayoutContainer extends XLayoutContainer {
/**
* 是否为sclae和title专属容器
*
* @return 是则返回true
*/
public boolean isDedicateContainer() {

28
designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java

@ -125,6 +125,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 创建权限编辑面板
*
* @return 面板
*/
public AuthorityEditPane createAuthorityEditPane() {
@ -133,6 +134,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 内容属性表面板
*
* @return 内容属性表面板
*/
public JPanel getEastUpPane() {
@ -141,6 +143,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 参数属性表
*
* @return 参数属性表
*/
@ -150,6 +153,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 权限编辑面板
*
* @return 权限编辑面板
*/
public AuthorityEditPane getAuthorityEditPane() {
@ -309,26 +313,27 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
*/
public boolean isWithQueryButton() {
XLayoutContainer rootContainer = this.getRootComponent();
return SearchQueryCreators(rootContainer);
return searchQueryCreators(rootContainer);
}
/**
* 返回复制粘贴删除等动作
*
* @return 同上
*/
public Action[] getActions() {
if (designer_actions == null) {
designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
if (designerActions == null) {
designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)};
}
return designer_actions;
return designerActions;
}
private boolean SearchQueryCreators(XLayoutContainer rootContainer) {
private boolean searchQueryCreators(XLayoutContainer rootContainer) {
boolean b = false;
for (int i = 0; i < rootContainer.getXCreatorCount(); i++) {
if (rootContainer.getXCreator(i) instanceof XLayoutContainer) {
b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i));
b = searchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i));
} else if (rootContainer.getXCreator(i) instanceof XFormSubmit) {
b = true;
}
@ -380,6 +385,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 报表直接判断底层是否是绝对布局
*
* @return 是则返回true
*/
public boolean hasWAbsoluteLayout() {
@ -401,9 +407,10 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 是否是报表的参数面板
*
* @return
*/
public boolean isFormParaDesigner(){
public boolean isFormParaDesigner() {
return true;
}
@ -494,7 +501,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
public void populateRootSize() {
((FormParameterUI) getTarget()).setDesignSize(getRootComponent().getSize());
if (getParaComponent().acceptType(XWParameterLayout.class)) {
WParameterLayout layout = (WParameterLayout)getParaComponent().toData();
WParameterLayout layout = (WParameterLayout) getParaComponent().toData();
layout.setDesignWidth(getRootComponent().getWidth());
}
}
@ -554,6 +561,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 加入参数
*
* @param parameter 参数 c
* @param currentIndex 位置 w
* @return 是否加入 s
@ -580,6 +588,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 加入参数
*
* @param parameter 参数 c
* @param currentIndex 位置 w
* @return 是否加入 s
@ -614,6 +623,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 加入参数
*
* @param parameterArray 参数 c
* @param currentIndex 位置 w
* @return 是否加入 s
@ -672,6 +682,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 工具栏
*
* @return 工具栏面板 g
*/
public JPanel[] toolbarPanes4Form() {
@ -680,6 +691,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
/**
* 复制等按钮
*
* @return 按钮组 a
*/
public JComponent[] toolBarButton4Form() {

2
designer_form/src/com/fr/design/mainframe/ConnectorHelper.java

@ -29,7 +29,7 @@ public class ConnectorHelper {
}
public void resetConnector(Connector connector) {
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(),connector.getStartPoint(),connector.getEndPoint());
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), connector.getStartPoint(), connector.getEndPoint());
connector.addAll(cc.createPointList());
}

167
designer_form/src/com/fr/design/mainframe/EditingMouseListener.java

@ -1,7 +1,6 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.beans.location.MoveUtils;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.ComponentAdapter;
import com.fr.design.designer.beans.events.DesignerEditor;
@ -31,7 +30,6 @@ import java.awt.event.MouseEvent;
*/
public class EditingMouseListener extends MouseInputAdapter {
private static final int INDEX = 0;
private FormDesigner designer;
/**
@ -56,6 +54,7 @@ public class EditingMouseListener extends MouseInputAdapter {
* 选择模型存储当前选择的组件和剪切板
*/
private SelectionModel selectionModel;
/**
* 获取选择模型
*
@ -65,10 +64,10 @@ public class EditingMouseListener extends MouseInputAdapter {
return selectionModel;
}
private XCreator last_creator;
private XCreator lastXCreator;
private MouseEvent lastPressEvent;
private DesignerEditor<? extends JComponent> current_editor;
private XCreator current_creator;
private DesignerEditor<? extends JComponent> currentEditor;
private XCreator currentXCreator;
//备份开始拖动的位置和大小
private Rectangle dragBackupBounds;
@ -103,25 +102,25 @@ public class EditingMouseListener extends MouseInputAdapter {
this.promptWindow.add(promptButton);
}
private void promptUser(int x, int y, XLayoutContainer container){
if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)){
promptWidgetForbidEnter(x ,y , container);
private void promptUser(int x, int y, XLayoutContainer container) {
if (!selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane() && container.acceptType(XWFitLayout.class)) {
promptWidgetForbidEnter(x, y, container);
} else {
cancelPromptWidgetForbidEnter();
}
}
private void promptWidgetForbidEnter(int x,int y, XLayoutContainer container){
private void promptWidgetForbidEnter(int x, int y, XLayoutContainer container) {
container.setBorder(BorderFactory.createLineBorder(Color.RED, Constants.LINE_MEDIUM));
int screen_X = (int)designer.getArea().getLocationOnScreen().getX();
int screen_Y = (int)designer.getArea().getLocationOnScreen().getY();
int screenX = (int) designer.getArea().getLocationOnScreen().getX();
int screenY = (int) designer.getArea().getLocationOnScreen().getY();
this.promptWindow.setSize(promptWindow.getPreferredSize());
this.promptWindow.setPreferredSize(promptWindow.getPreferredSize());
promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP);
promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP);
promptWindow.setVisible(true);
}
private void cancelPromptWidgetForbidEnter(){
private void cancelPromptWidgetForbidEnter() {
designer.getRootComponent().setBorder(BorderFactory.createLineBorder(XCreatorConstants.LAYOUT_SEP_COLOR, Constants.LINE_THIN));
promptWindow.setVisible(false);
}
@ -129,6 +128,7 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 按下
*
* @param e 鼠标事件
*/
public void mousePressed(MouseEvent e) {
@ -139,9 +139,7 @@ public class EditingMouseListener extends MouseInputAdapter {
// 获取焦点,以便获取热键
designer.requestFocus();
}
if (e.isPopupTrigger()) {
// 为触发上下文菜单预留
} else if (e.getButton() == MouseEvent.BUTTON1) {
if (e.getButton() == MouseEvent.BUTTON1) {
Direction dir = selectionModel.getDirectionAt(e);
if (!BaseUtils.isAuthorityEditing()) {
@ -157,7 +155,7 @@ public class EditingMouseListener extends MouseInputAdapter {
designer.getArea().getHorizontalValue() + e.getX(),
designer.getArea().getVerticalValue() + e.getY())) {
lastPressEvent = e;
last_creator = selectionModel.getSelection().getSelectedCreator();
lastXCreator = selectionModel.getSelection().getSelectedCreator();
} else {
stateModel.startSelecting(e);
}
@ -170,6 +168,7 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 释放
*
* @param e 鼠标事件
*/
public void mouseReleased(MouseEvent e) {
@ -192,17 +191,16 @@ public class EditingMouseListener extends MouseInputAdapter {
}
}
lastPressEvent = null;
last_creator = null;
lastXCreator = null;
}
private void mouseDraggingRelease(MouseEvent e) {
// 当前鼠标所在的组件
XCreator hoveredComponent = designer.getComponentAt(e.getX(), e.getY());
if(designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null){
if (designer.isWidgetsIntersect() && dragBackupBounds != null && hoveredComponent != null) {
XCreator selectionXCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
if(selectionXCreator != null){
if (selectionXCreator != null) {
selectionXCreator.setBounds(dragBackupBounds.x, dragBackupBounds.y, dragBackupBounds.width, dragBackupBounds.height);
MoveUtils.hideForbidWindow();
}
}
dragBackupBounds = null;
@ -219,7 +217,7 @@ public class EditingMouseListener extends MouseInputAdapter {
if (container != null) {
boolean formSubmit2Adapt = !selectionModel.getSelection().getSelectedCreator().canEnterIntoAdaptPane()
&& container.acceptType(XWFitLayout.class);
if ( !formSubmit2Adapt) {
if (!formSubmit2Adapt) {
// 如果是处于拖拽状态,则释放组件
stateModel.releaseDragging(e);
} else {
@ -231,17 +229,14 @@ public class EditingMouseListener extends MouseInputAdapter {
}
/**
* 激活上下文菜单待完善
* TODO 激活上下文菜单待完善
* 6.56暂时不支持右键 bugid 8777
*/
private void trigger_popup(MouseEvent e) {
private void triggerPopup(MouseEvent e) {
XCreator creator = selectionModel.getSelection().getSelectedCreator();
if (creator == null) {
return;
}
JPopupMenu popupMenu = null;
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, creator);
popupMenu = adapter.getContextPopupMenu(e);
@ -255,6 +250,7 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 移动
*
* @param e 鼠标事件
*/
public void mouseMoved(MouseEvent e) {
@ -262,7 +258,7 @@ public class EditingMouseListener extends MouseInputAdapter {
setCoverPaneNotDisplay(e, false);
if(processTopLayoutMouseMove(component, e)){
if (processTopLayoutMouseMove(component, e)) {
return;
}
if (component instanceof XEditorHolder) {
@ -301,9 +297,9 @@ public class EditingMouseListener extends MouseInputAdapter {
}
private void elementCaseMouseMoved(MouseEvent e, XCreator component) {
xElementCase = (XElementCase)component;
UIButton button = (UIButton)xElementCase.getCoverPane().getComponent(0);
if(designer.getCursor().getType() == Cursor.HAND_CURSOR) {
xElementCase = (XElementCase) component;
UIButton button = (UIButton) xElementCase.getCoverPane().getComponent(0);
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
} // component.getParent() 是报表块所在的XWTitleLayout
int minX = button.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue();
@ -337,12 +333,12 @@ public class EditingMouseListener extends MouseInputAdapter {
if (rect.contains(e.getPoint())) {
return;
}
if(isLinkedHelpDialog){
if (isLinkedHelpDialog) {
xElementCase.destroyHelpDialog();
}
xElementCase.displayCoverPane(false);
}
if (xChartEditor != null){
if (xChartEditor != null) {
xChartEditor.displayCoverPane(false);
}
@ -352,13 +348,13 @@ public class EditingMouseListener extends MouseInputAdapter {
designer.repaint();
}
private boolean processTopLayoutMouseMove(XCreator component, MouseEvent e){
private boolean processTopLayoutMouseMove(XCreator component, MouseEvent e) {
XLayoutContainer parent = XCreatorUtils.getHotspotContainer(component).getTopLayout();
if (parent != null){
if (parent != null) {
xTopLayoutContainer = parent;
xTopLayoutContainer.setMouseEnter(true);
designer.repaint();
if(!xTopLayoutContainer.isEditable()) {
if (!xTopLayoutContainer.isEditable()) {
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
@ -377,17 +373,17 @@ public class EditingMouseListener extends MouseInputAdapter {
return false;
}
private void processChartEditorMouseMove(XCreator component, MouseEvent e){
private void processChartEditorMouseMove(XCreator component, MouseEvent e) {
if (component instanceof XChartEditor) {
xChartEditor = (XChartEditor)component;
UIButton button = (UIButton)xChartEditor.getCoverPane().getComponent(0);
if(designer.getCursor().getType() ==Cursor.HAND_CURSOR) {
xChartEditor = (XChartEditor) component;
UIButton button = (UIButton) xChartEditor.getCoverPane().getComponent(0);
if (designer.getCursor().getType() == Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
int minX = button.getX() + getParentPositionX(component, 0) - designer.getArea().getHorizontalValue();
int minY = button.getY() + getParentPositionY(component, 0) - designer.getArea().getVerticalValue();
if(e.getX() + GAP > minX && e.getX() - GAP < minX + button.getWidth()){
if( e.getY() + GAP > minY && e.getY() - GAP < minY + button.getHeight()){
if (e.getX() + GAP > minX && e.getX() - GAP < minX + button.getWidth()) {
if (e.getY() + GAP > minY && e.getY() - GAP < minY + button.getHeight()) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
}
@ -397,9 +393,9 @@ public class EditingMouseListener extends MouseInputAdapter {
}
}
private int getParentPositionX(XCreator comp, int x){
private int getParentPositionX(XCreator comp, int x) {
return comp.getParent() == null ?
x : getParentPositionX((XCreator)comp.getParent(), comp.getParent().getX() + x);
x : getParentPositionX((XCreator) comp.getParent(), comp.getParent().getX() + x);
}
private int getParentPositionY(XCreator comp, int y) {
@ -409,6 +405,7 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 拖拽
*
* @param e 鼠标事件
*/
public void mouseDragged(MouseEvent e) {
@ -423,9 +420,9 @@ public class EditingMouseListener extends MouseInputAdapter {
stateModel.dragging(e);
// 获取e所在的焦点组件
XCreator hotspot = designer.getComponentAt(e.getX(), e.getY());
if(dragBackupBounds == null) {
if (dragBackupBounds == null) {
XCreator selectingXCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
if(selectingXCreator != null){
if (selectingXCreator != null) {
dragBackupBounds = new Rectangle(selectingXCreator.getX(), selectingXCreator.getY(), selectingXCreator.getWidth(), selectingXCreator.getHeight());
}
}
@ -446,13 +443,13 @@ public class EditingMouseListener extends MouseInputAdapter {
// 如果是拖拽选择区域状态,则更新选择区域
stateModel.changeSelection(e);
} else {
if ((lastPressEvent == null) || (last_creator == null)) {
if ((lastPressEvent == null) || (lastXCreator == null)) {
return;
}
if (e.getPoint().distance(lastPressEvent.getPoint()) > minDragSize) {
//参数面板和自适应布局不支持拖拽
if (last_creator.isSupportDrag()){
designer.startDraggingComponent(last_creator, lastPressEvent, e.getX(), e.getY());
if (lastXCreator.isSupportDrag()) {
designer.startDraggingComponent(lastXCreator, lastPressEvent, e.getX(), e.getY());
}
e.consume();
lastPressEvent = null;
@ -462,50 +459,50 @@ public class EditingMouseListener extends MouseInputAdapter {
}
//当前编辑的组件是在布局中,鼠标点击布局外部,需要一次性将布局及其父布局都置为不可编辑
private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout){
private void setTopLayoutUnEditable(XLayoutContainer clickedTopLayout, XLayoutContainer clickingTopLayout) {
//双击的前后点击click为相同对象,过滤掉
if (clickedTopLayout == null || clickedTopLayout == clickingTopLayout){
if (clickedTopLayout == null || clickedTopLayout == clickingTopLayout) {
return;
}
//位于同一层级的控件,父布局相同,过滤掉
if (clickingTopLayout != null && clickedTopLayout.getParent() == clickingTopLayout.getParent()){
if (clickingTopLayout != null && clickedTopLayout.getParent() == clickingTopLayout.getParent()) {
return;
}
//前后点击的位于不同层级,要置为不可编辑
XLayoutContainer xLayoutContainer = (XLayoutContainer)clickedTopLayout.getParent();
if (xLayoutContainer == clickingTopLayout){
XLayoutContainer xLayoutContainer = (XLayoutContainer) clickedTopLayout.getParent();
if (xLayoutContainer == clickingTopLayout) {
return;
}
if (xLayoutContainer != null){
if (xLayoutContainer != null) {
xLayoutContainer.setEditable(false);
setTopLayoutUnEditable((XLayoutContainer) clickedTopLayout.getParent(), clickingTopLayout);
}
}
private boolean isCreatorInLayout(XCreator creator, XCreator layout){
if (creator == layout){
private boolean isCreatorInLayout(XCreator creator, XCreator layout) {
if (creator.equals(layout)) {
return true;
}
if(layout.getParent() != null){
return isCreatorInLayout(creator, (XCreator)layout.getParent());
if (layout.getParent() != null) {
return isCreatorInLayout(creator, (XCreator) layout.getParent());
}
return false;
}
private XCreator processTopLayoutMouseClick(XCreator creator){
private XCreator processTopLayoutMouseClick(XCreator creator) {
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(creator).getTopLayout();
if(topLayout != null){
if (clickTopLayout != null && clickTopLayout != topLayout && !isCreatorInLayout(clickTopLayout, topLayout)){
if (topLayout != null) {
if (clickTopLayout != null && !clickTopLayout.equals(topLayout) && !isCreatorInLayout(clickTopLayout,
topLayout)) {
clickTopLayout.setEditable(false);
setTopLayoutUnEditable(clickTopLayout, topLayout);
}
clickTopLayout = topLayout;
if(!topLayout.isEditable()) {
if (!topLayout.isEditable()) {
creator = topLayout;
}
}
else{
if(clickTopLayout != null){
} else {
if (clickTopLayout != null) {
clickTopLayout.setEditable(false);
setTopLayoutUnEditable(clickTopLayout, null);
}
@ -513,8 +510,10 @@ public class EditingMouseListener extends MouseInputAdapter {
return creator;
}
/**
* 点击
*
* @param e 鼠标事件
*/
public void mouseClicked(MouseEvent e) {
@ -526,7 +525,7 @@ public class EditingMouseListener extends MouseInputAdapter {
creator = processTopLayoutMouseClick(creator);
if(creator != null){
if (creator != null) {
creator.respondClick(this, e);
}
creator.doLayout();
@ -534,9 +533,9 @@ public class EditingMouseListener extends MouseInputAdapter {
}
/**
* 离开
*
* @param e 鼠标事件
*/
public void mouseExited(MouseEvent e) {
@ -551,6 +550,7 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 开始编辑
*
* @param creator 容器
* @param designerEditor 设计器
* @param adapter 适配器
@ -558,8 +558,8 @@ public class EditingMouseListener extends MouseInputAdapter {
public void startEditing(XCreator creator, DesignerEditor<? extends JComponent> designerEditor, ComponentAdapter adapter) {
if (designerEditor != null) {
Rectangle rect = ComponentUtils.getRelativeBounds(creator);
current_editor = designerEditor;
current_creator = creator;
currentEditor = designerEditor;
currentXCreator = creator;
Rectangle bounds = new Rectangle(1, 1, creator.getWidth() - 2, creator.getHeight() - 2);
bounds.x += (rect.x - designer.getArea().getHorizontalValue());
bounds.y += (rect.y - designer.getArea().getVerticalValue());
@ -574,22 +574,23 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 停止编辑
*
* @return 是否编辑成功
*/
public boolean stopEditing() {
if (current_editor != null) {
designer.remove(current_editor.getEditorTarget());
current_editor.fireEditStoped();
if (currentEditor != null) {
designer.remove(currentEditor.getEditorTarget());
currentEditor.fireEditStoped();
Container container = current_creator.getParent();
Container container = currentXCreator.getParent();
if (container != null) {
LayoutUtils.layoutRootContainer(container);
}
designer.invalidate();
designer.repaint();
current_creator = null;
current_editor = null;
currentXCreator = null;
currentEditor = null;
return true;
}
return true;
@ -599,22 +600,22 @@ public class EditingMouseListener extends MouseInputAdapter {
* 重置编辑控件大小
*/
public void resetEditorComponentBounds() {
if (current_editor == null) {
if (currentEditor == null) {
return;
}
if (current_creator.getParent() == null) {
if (currentXCreator.getParent() == null) {
stopEditing();
return;
}
Rectangle rect = ComponentUtils.getRelativeBounds(current_creator);
Rectangle bounds = new Rectangle(1, 1, current_creator.getWidth() - 2, current_creator.getHeight() - 2);
Rectangle rect = ComponentUtils.getRelativeBounds(currentXCreator);
Rectangle bounds = new Rectangle(1, 1, currentXCreator.getWidth() - 2, currentXCreator.getHeight() - 2);
bounds.x += (rect.x - designer.getArea().getHorizontalValue());
bounds.y += (rect.y - designer.getArea().getVerticalValue());
if (current_creator instanceof XEditorHolder) {
ToolTipEditor.getInstance().resetBounds((XEditorHolder) current_creator, bounds, current_editor.getEditorTarget().getBounds());
if (currentXCreator instanceof XEditorHolder) {
ToolTipEditor.getInstance().resetBounds((XEditorHolder) currentXCreator, bounds, currentEditor.getEditorTarget().getBounds());
}
current_editor.getEditorTarget().setBounds(bounds);
currentEditor.getEditorTarget().setBounds(bounds);
}
}

183
designer_form/src/com/fr/design/mainframe/FormDesigner.java

@ -6,7 +6,10 @@ import com.fr.design.DesignState;
import com.fr.design.designer.TargetComponent;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.Painter;
import com.fr.design.designer.beans.actions.CopyAction;
import com.fr.design.designer.beans.actions.CutAction;
import com.fr.design.designer.beans.actions.FormDeleteAction;
import com.fr.design.designer.beans.actions.PasteAction;
import com.fr.design.designer.beans.adapters.layout.FRParameterLayoutAdapter;
import com.fr.design.designer.beans.events.CreatorEventListenerTable;
import com.fr.design.designer.beans.events.DesignerEditListener;
@ -43,7 +46,6 @@ import com.fr.form.ui.container.WFitLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.plugin.ExtraClassManager;
import com.fr.stable.ArrayUtils;
import com.fr.stable.bridge.StableFactory;
@ -65,11 +67,10 @@ import java.util.List;
/**
* 设计界面组件该组件是界面设计工具的核心主要负责的是被设计界面的显示界面设计操作状态的 显示编辑状态的显示等等
*/
public class FormDesigner extends TargetComponent<Form> implements TreeSelectionListener, InvocationHandler, BaseFormDesigner ,ParaDefinitePane{
public class FormDesigner extends TargetComponent<Form> implements TreeSelectionListener, InvocationHandler, BaseFormDesigner, ParaDefinitePane {
protected static final ArrayList<String> NAME_ARRAY_LIST = new ArrayList<String>(
Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")})
);
private static final int BORDER_WIDTH = 6;
//底层容器的默认大小
protected static final Dimension LARGE_PREFERRED_SIZE = new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT);
private int paraHeight = 0;
@ -81,7 +82,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
private XLayoutContainer paraComponent;
private boolean drawLineMode;
private FormArea formArea;
private ConnectorHelper ConnectorHelper;
private ConnectorHelper connectorHelper;
private boolean isReportBlockEditing = false;
//组件重叠
@ -104,7 +105,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
// 编辑状态的事件表
private CreatorEventListenerTable edit;
protected Action[] designer_actions;
protected Action[] designerActions;
private FormDesignerModeForSpecial<?> desigerMode;
private Action switchAction;
private FormElementCaseContainerProvider elementCaseContainer;
@ -159,7 +160,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
ParameterPropertyPane.getInstance().populateBean(this);
}
public Parameter[] getNoRepeatParas(Parameter[] paras){
public Parameter[] getNoRepeatParas(Parameter[] paras) {
List<Parameter> paraList = new ArrayList<Parameter>();
java.util.Set set = new java.util.HashSet();
for (Parameter p : paras) {
@ -171,23 +172,23 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return paraList.toArray(new Parameter[paraList.size()]);
}
public void setParameterArray(Parameter[] ps){
public void setParameterArray(Parameter[] ps) {
parameterArray = ps;
}
public Parameter[] getParameterArray(){
public Parameter[] getParameterArray() {
return parameterArray;
}
/**
* 刷新参数
*/
public void refreshParameter(){
public void refreshParameter() {
XLayoutContainer rootContainer = this.getParaComponent();
if (rootContainer != null){
if (rootContainer != null) {
java.util.List<String> namelist = new ArrayList<String>();
rootContainer.getAllXCreatorNameList(rootContainer,namelist);
rootContainer.getAllXCreatorNameList(rootContainer, namelist);
// parameterArray是报表的所有参数, nameList是已经在参数面板添加过控件的参数名
// 与已有的参数列表比较 如果已经存在 就除去
Parameter[] ps = getParameterArray();
@ -201,7 +202,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
EastRegionContainerPane.getInstance().setParameterHeight(ParameterPropertyPane.getInstance(this).getPreferredSize().height);
}
private void removeSame(Parameter[] parameters, List<String> namelist){
private void removeSame(Parameter[] parameters, List<String> namelist) {
for (Parameter parameter : parameters) {
for (String name : namelist) {
if (name.equalsIgnoreCase(parameter.getName())) {
@ -214,20 +215,22 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否有查询按钮
*
* @return 有无查询按钮
*/
public boolean isWithQueryButton(){
public boolean isWithQueryButton() {
XLayoutContainer rootContainer = this.getParaComponent();
return rootContainer != null && rootContainer.SearchQueryCreators(rootContainer);
}
/**
* 加入参数到参数面板
*
* @param parameter 参数
* @return 是否加入
*/
public void addingParameter2Editor(Parameter parameter){
if(getParaComponent() == null){
public void addingParameter2Editor(Parameter parameter) {
if (getParaComponent() == null) {
addParaPaneTooltips();
return;
}
@ -242,11 +245,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
if (!(this.autoAddComponent(xLabel, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE)
+ FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) {
return ;
return;
}
if (!(this.autoAddComponent(xCreator, H_COMPONENT_GAP * (currentIndex % NUM_IN_A_LINE)
+ SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP * (currentIndex / NUM_IN_A_LINE)))) {
return ;
return;
}
currentIndex++;
parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter);
@ -256,11 +259,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 加入参数到参数面板有查询按钮
*
* @param parameter 参数
* @return 是否加入
*/
public void addingParameter2EditorWithQueryButton(Parameter parameter){
if(getParaComponent() == null){
public void addingParameter2EditorWithQueryButton(Parameter parameter) {
if (getParaComponent() == null) {
addParaPaneTooltips();
return;
}
@ -276,12 +280,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
if (!(this.autoAddComponent(xLabel, FIRST_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP
* (currentIndex / NUM_IN_A_LINE)))) {
return ;
return;
}
if (!(this.autoAddComponent(xCreator, SECOND_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP
* (currentIndex / NUM_IN_A_LINE)))) {
return ;
return;
}
FormSubmitButton formSubmitButton = new FormSubmitButton();
formSubmitButton.setWidgetName("Search");
@ -289,7 +293,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
xCreator = XCreatorUtils.createXCreator(formSubmitButton);
if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP
* (currentIndex / NUM_IN_A_LINE)))) {
return ;
return;
}
currentIndex = currentIndex + NUM_IN_A_LINE - currentIndex % NUM_IN_A_LINE;
parameterArray = (Parameter[]) ArrayUtils.removeElement(parameterArray, parameter);
@ -300,8 +304,8 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 一键添加所有参数
*/
public void addingAllParameter2Editor(){
if(getParaComponent() == null){
public void addingAllParameter2Editor() {
if (getParaComponent() == null) {
addParaPaneTooltips();
return;
}
@ -350,13 +354,14 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
EastRegionContainerPane.getInstance().refreshDownPane();
}
private void addParaPaneTooltips(){
JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(),Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"),
private void addParaPaneTooltips() {
JOptionPane.showConfirmDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer-Form-Please_Drag_ParaPane"),
Inter.getLocText("FR-Designer_Tooltips"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
}
/**
* 自动添加组件
*
* @param xCreator 组件
* @param x 横坐标
* @param y 纵坐标
@ -375,6 +380,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 在参数很多时全部添加的时候可以向下一次排版若去掉就会在参数面板堆到一起
*
* @param creator 组件
* @param x 长度
* @param y 长度
@ -404,9 +410,9 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 加入参数面板
*/
public void addParaComponent(){
public void addParaComponent() {
if (paraComponent != null) {
return ;
return;
}
paraHeight = WBorderLayout.DEFAULT_SIZE;
paraComponent = new XWParameterLayout();
@ -414,7 +420,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
paraComponent.setSize(paraComponent.initEditorSize());
XWBorderLayout formLayoutContainer = (XWBorderLayout) rootComponent.getParent();
formLayoutContainer.toData().setNorthSize(paraHeight);
formLayoutContainer.add(paraComponent,WBorderLayout.NORTH);
formLayoutContainer.add(paraComponent, WBorderLayout.NORTH);
//设下northSize,增加para后,重置border大小,这时候para和root的大小会自适应调整
formLayoutContainer.setSize(formLayoutContainer.getWidth(), formLayoutContainer.getHeight() + paraHeight);
selectionModel.reset();
@ -425,10 +431,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回根节点父容器
*
* @return 父容器
*/
public Component getTopContainer(){
if(rootComponent != null){
public Component getTopContainer() {
if (rootComponent != null) {
// 返回root所在的父容器,非designer
return LayoutUtils.getTopContainer(rootComponent);
}
@ -437,17 +444,19 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回参数界面高度
*
* @return para高度
*/
public int getParaHeight(){
public int getParaHeight() {
return paraHeight;
}
/**
* 重置para的高度
*
* @param height 高度
*/
public void setParaHeight(int height){
public void setParaHeight(int height) {
XWBorderLayout container = (XWBorderLayout) getTopContainer();
container.toData().setNorthSize(height);
container.setSize(container.getWidth(), container.getHeight() + height - getParaHeight());
@ -457,7 +466,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 删除参数界面
*/
public void removeParaComponent(){
public void removeParaComponent() {
XWBorderLayout formLayoutContainer = (XWBorderLayout) getTopContainer();
formLayoutContainer.toData().removeWidget(paraComponent.toData());
paraHeight = 0;
@ -472,41 +481,42 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 切换
*
* @param elementCaseContainer 容器
*/
public void switchTab(FormElementCaseContainerProvider elementCaseContainer){
if(this.switchAction == null){
public void switchTab(FormElementCaseContainerProvider elementCaseContainer) {
if (this.switchAction == null) {
return;
}
this.elementCaseContainer = elementCaseContainer;
this.switchAction.actionPerformed(null);
}
public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer){
public void setElementCaseContainer(FormElementCaseContainerProvider elementCaseContainer) {
this.elementCaseContainer = elementCaseContainer;
}
public FormElementCaseProvider getElementCase(){
public FormElementCaseProvider getElementCase() {
return this.elementCaseContainer.getElementCase();
}
public String getElementCaseContainerName(){
public String getElementCaseContainerName() {
return this.elementCaseContainer.getElementCaseContainerName();
}
public void setElementCase(FormElementCaseProvider elementCase){
public void setElementCase(FormElementCaseProvider elementCase) {
this.elementCaseContainer.setElementCase(elementCase);
}
public void setElementCaseBackground(BufferedImage image){
public void setElementCaseBackground(BufferedImage image) {
this.elementCaseContainer.setBackground(image);
}
public Dimension getElementCaseContainerSize(){
public Dimension getElementCaseContainerSize() {
return this.elementCaseContainer.getSize();
}
public FormElementCaseContainerProvider getElementCaseContainer(){
public FormElementCaseContainerProvider getElementCaseContainer() {
return this.elementCaseContainer;
}
@ -524,6 +534,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 增加监听事件
*
* @param listener 界面组件编辑事件
*/
public void addDesignerEditListener(DesignerEditListener listener) {
@ -539,15 +550,15 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 表单则判断参数面板是否为绝对布局
*
* @return 是则返回true
*/
public boolean hasWAbsoluteLayout() {
if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)){
if (paraComponent != null && paraComponent.acceptType(XWParameterLayout.class)) {
return true;
}
else{
} else {
if (this.getSelectionModel().getSelection().getSelectedCreator().getParent() != null
&& ((XLayoutContainer)this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)){
&& ((XLayoutContainer) this.getSelectionModel().getSelection().getSelectedCreator().getParent()).acceptType(XWAbsoluteLayout.class)) {
return true;
}
}
@ -556,6 +567,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 设置是否为报表块编辑
*
* @param isEditing 是否为报表块编辑
*/
public void setReportBlockEditing(boolean isEditing) {
@ -564,22 +576,24 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否为报表块编辑
*
* @return 是否为报表块编辑
*/
public boolean isReportBlockEditing() {
return this.isReportBlockEditing;
}
public void setWidgetsIntersect(boolean isWidgetsIntersect){
public void setWidgetsIntersect(boolean isWidgetsIntersect) {
this.isWidgetsIntersect = isWidgetsIntersect;
}
public boolean isWidgetsIntersect(){
public boolean isWidgetsIntersect() {
return this.isWidgetsIntersect;
}
/**
* 是否重命名控件
*
* @param creator 组件
* @param newName 新的组件名
* @return 组件名有变化且不和其他一样返回true
@ -609,16 +623,17 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 更新界面布局重绘
*
* @param proxy 动态代理类
* @param method 接口方法
* @param args 参数
* @return 不返回任何对象
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if(rootComponent != null){
if (rootComponent != null) {
LayoutUtils.layoutRootContainer(rootComponent);
}
if(paraComponent != null){
if (paraComponent != null) {
LayoutUtils.layoutRootContainer(paraComponent);
}
repaint();
@ -654,6 +669,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 增加组件事件
*
* @param h 动态代理
*/
public void addInvocationHandler(InvocationHandler h) {
@ -741,16 +757,14 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 更新边框线状态
*
* @param e 鼠标事件
*/
public void updateDrawLineMode(MouseEvent e) {
Point p = ConnectorHelper.getNearWidgetPoint(e);
if (p == null) {
XComponent comp = getComponentAt(e);
if (comp == rootComponent) {
Point p = connectorHelper.getNearWidgetPoint(e);
if (p == null && getComponentAt(e) == rootComponent) {
p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
}
}
stateModel.startDrawLine(p);
}
@ -761,7 +775,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
// 撤销恢复操作都会refreshRoot,这时候的target.getContainer里的widget会和之前不一样,所以不用root判断来取
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator(this.getTarget().getContainer());
// 布局默认都是1,底层的border改为0,不然没意义
this.getTarget().getContainer().setMargin(new PaddingMargin(0,0,0,0));
this.getTarget().getContainer().setMargin(new PaddingMargin(0, 0, 0, 0));
formLayoutContainer.setBorder(null);
if (formLayoutContainer.acceptType(XWBorderLayout.class)) {
WBorderLayout borderLayout = (WBorderLayout) formLayoutContainer.toData();
@ -790,9 +804,9 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
XLayoutContainer northContainer = (XLayoutContainer) XCreatorUtils.createXCreator(northWidget);
paraHeight = ((XWBorderLayout)formLayoutContainer).toData().getNorthSize();
paraHeight = ((XWBorderLayout) formLayoutContainer).toData().getNorthSize();
paraComponent = northContainer;
northContainer.setSize(0,paraHeight);
northContainer.setSize(0, paraHeight);
formLayoutContainer.add(northContainer, WBorderLayout.NORTH);
}
@ -841,14 +855,16 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否是报表的参数面板
*
* @return (表单的)
*/
public boolean isFormParaDesigner(){
public boolean isFormParaDesigner() {
return false;
}
/**
* 是否为底层容器
*
* @param comp 组件
* @return 是则返回true
*/
@ -923,10 +939,10 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
public SelectionModel getSelectionModel() {
if (paraComponent!=null){
paraComponent.setSize(paraComponent.getWidth(),getParaHeight());
if (paraComponent != null) {
paraComponent.setSize(paraComponent.getWidth(), getParaHeight());
Rectangle rec = rootComponent.getBounds();
rootComponent.setBounds(rec.x,getParaHeight(),rec.width,rec.height);
rootComponent.setBounds(rec.x, getParaHeight(), rec.width, rec.height);
}
return selectionModel;
}
@ -941,6 +957,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 拖拽准备
*
* @param xCreator 组件
*/
public void startDraggingBean(XCreator xCreator) {
@ -954,6 +971,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 拖拽时相关处理
*
* @param xCreator 组件
* @param lastPressEvent 鼠标事件
* @param x 坐标x
@ -978,6 +996,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 改变组件值
*
* @param e 组件选择事件
*/
@Override
@ -1024,6 +1043,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否支持权限编辑
*
* @return 是则返回true
*/
public boolean isSupportAuthority() {
@ -1049,6 +1069,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否含有action名
*
* @param name action名
* @return 有则返回true
*/
@ -1058,6 +1079,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 显示组件
*
* @param comp 组件
*/
public void makeVisible(XCreator comp) {
@ -1088,16 +1110,16 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回复制粘贴删除等动作
* 鼠标右键菜单
*
* @return 同上
*/
public Action[] getActions() {
if (designer_actions == null) {
//先把复制粘贴按钮去掉,只留下删除
// designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
// new FormDeleteAction(this)};
designer_actions = new Action[]{new FormDeleteAction(this)};
if (designerActions == null) {
designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)};
}
return designer_actions;
return designerActions;
}
protected Border getOuterBorder() {
@ -1120,6 +1142,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回表单区域
*
* @return 表单区域
*/
public FormArea getArea() {
@ -1128,6 +1151,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 设置上层区域
*
* @param formArea 表单区域
*/
public void setParent(FormArea formArea) {
@ -1136,14 +1160,15 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 绘制组件根节点
*
* @param clipg 图形
*/
public void paintContent(Graphics clipg) {
rootComponent.paint(clipg);
}
public void paintPara(Graphics clipg){
if(paraComponent != null){
public void paintPara(Graphics clipg) {
if (paraComponent != null) {
paraComponent.paint(clipg);
}
}
@ -1157,14 +1182,16 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回连线类
*
* @return ConnectorHelper类
*/
public ConnectorHelper getDrawLineHelper() {
return ConnectorHelper;
return connectorHelper;
}
/**
* 是否画线模式
*
* @return 是则返回true
*/
public boolean isDrawLineMode() {
@ -1173,6 +1200,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 设置DrawLineMode
*
* @param mode 是or或
*/
public void setDrawLineMode(boolean mode) {
@ -1199,6 +1227,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回表单控件权限编辑pane
*
* @return 同上
*/
public AuthorityEditPane createAuthorityEditPane() {
@ -1249,6 +1278,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 粘贴
*
* @return
*/
@Override
@ -1259,6 +1289,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 剪切
*
* @return
*/
@Override
@ -1273,6 +1304,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 工具栏菜单
*
* @return 同上
*/
@Override
@ -1286,6 +1318,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 模版菜单
*
* @return 同上
*/
@Override
@ -1295,6 +1328,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 权限菜单
*
* @return 同上
*/
public ShortCut[] shortCuts4Authority() {
@ -1304,6 +1338,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回ToolBarDef
*
* @return 同上
*/
@Override
@ -1313,10 +1348,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回工具栏按钮组件
*
* @return 同上
*/
public JComponent[] toolBarButton4Form() {
return new JComponent[0];
return new JComponent[]{new CutAction(this).createToolBarComponent(), new CopyAction(this).createToolBarComponent(), new PasteAction(this).createToolBarComponent(),
new FormDeleteAction(this).createToolBarComponent()};
}

22
designer_form/src/com/fr/design/mainframe/FormSelection.java

@ -37,6 +37,7 @@ public class FormSelection {
/**
* 是否没有选中的组件
*
* @return 为空返回true
*/
public boolean isEmpty() {
@ -45,6 +46,7 @@ public class FormSelection {
/**
* 选中的组件数量
*
* @return 选中的组件数量
*/
public int size() {
@ -53,6 +55,7 @@ public class FormSelection {
/**
* 去除选中的组件中指定组件
*
* @param creator 待去除组件
*/
public void removeCreator(XCreator creator) {
@ -61,6 +64,7 @@ public class FormSelection {
/**
* 是否成功删除选择的组件
*
* @param comp 组件
* @return 是则返回true
*/
@ -74,6 +78,7 @@ public class FormSelection {
/**
* 成功增加选中的组件
*
* @param creator 组件
* @return 成功增加返回true
*/
@ -87,6 +92,7 @@ public class FormSelection {
/**
* 是否是可以增加的
*
* @param creator 组件
* @return 是则返回true
*/
@ -108,6 +114,7 @@ public class FormSelection {
/**
* 返回选中的第一个组件为空返回null
*
* @return 返回选中组件
*/
public XCreator getSelectedCreator() {
@ -116,6 +123,7 @@ public class FormSelection {
/**
* 返回选中的所有组件
*
* @return 所有组件s
*/
public XCreator[] getSelectedCreators() {
@ -146,6 +154,7 @@ public class FormSelection {
/**
* 是否包含当前控件
*
* @param widget 控件
* @return 是则返回true
*/
@ -196,7 +205,7 @@ public class FormSelection {
}
public Rectangle getSelctionBounds() {
if(selection.isEmpty()) {
if (selection.isEmpty()) {
return new Rectangle();
}
Rectangle bounds = selection.get(0).getBounds();
@ -221,8 +230,8 @@ public class FormSelection {
if (size == 1) {
XCreator creator = selection.get(0);
creator.setBounds(rec);
if(creator.acceptType(XWParameterLayout.class)){
designer.setParaHeight((int)rec.getHeight());
if (creator.acceptType(XWParameterLayout.class)) {
designer.setParaHeight((int) rec.getHeight());
designer.getArea().doLayout();
}
LayoutUtils.layoutContainer(creator);
@ -235,8 +244,8 @@ public class FormSelection {
newBounds.height = rec.height * newBounds.height / backupBounds.height;
XCreator creator = selection.get(i);
creator.setBounds(newBounds);
if(creator.acceptType(XWParameterLayout.class)){
designer.setParaHeight((int)rec.getHeight());
if (creator.acceptType(XWParameterLayout.class)) {
designer.setParaHeight((int) rec.getHeight());
designer.getArea().doLayout();
}
}
@ -246,6 +255,7 @@ public class FormSelection {
/**
* 调整组件大小
*
* @param designer 设计界面组件
*/
public void fixCreator(FormDesigner designer) {
@ -275,6 +285,7 @@ public class FormSelection {
/**
* 剪切选中的所有组件
*
* @param clipBoard 剪切板
*/
public void cut2ClipBoard(FormSelection clipBoard) {
@ -289,6 +300,7 @@ public class FormSelection {
/**
* 复制选中的所有组件
*
* @param clipBoard 复制板
*/
public void copy2ClipBoard(FormSelection clipBoard) {

230
designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java

@ -1,65 +1,211 @@
package com.fr.design.mainframe;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.fr.base.FRContext;
import com.fr.general.ComparatorUtils;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.form.main.ClonedWidgetCreator;
import com.fr.design.designer.creator.*;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FormSelectionUtils {
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection selection, int x,
int y) {
//组件复制时坐标偏移
private static final int DELAY_X = 20;
private static final int DELAY_Y = 20;
//组件复制时是否已经向左上偏移
private static boolean backoffset = false;
//组件重命名后缀
private static final String POSTFIX = "_c";
private FormSelectionUtils() {
}
/**
* @param designer 编辑器
* @param parent 粘贴依据的组件
* @param clipboard 剪贴板内容
* @param x x
* @param y y
*/
public static void paste2Container(FormDesigner designer, XLayoutContainer parent,
FormSelection clipboard, int x, int y) {
LayoutAdapter adapter = parent.getLayoutAdapter();
if (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);
if (parent instanceof XWAbsoluteLayout) {
//绝对布局
absolutePaste(designer, clipboard, adapter, x, y);
return;
} else if (parent instanceof XWFitLayout) {
//相对布局
relativePaste(designer, clipboard, adapter, x, y);
return;
}
Toolkit.getDefaultToolkit().beep();
}
/**
* 绝对布局粘贴
*
* @param designer
* @param clipboard
* @param adapter
* @param x
* @param y
*/
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
designer.getSelectionModel().getSelection().reset();
Rectangle rec = clipboard.getSelctionBounds();
for (XCreator creator : clipboard.getSelectedCreators()) {
try {
Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
// 获取位置
Point point = getPasteLocation((AbstractLayoutAdapter) adapter,
copiedCreator,
x + creator.getX() - rec.x + copiedCreator.getWidth() / 2,
y + creator.getY() - rec.y + copiedCreator.getHeight() / 2);
boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y);
if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
}
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
} else if (selection.size() > 1) {
if (parent instanceof XWAbsoluteLayout) {
}
rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED);
}
/**
* 相对布局粘贴
*
* @param designer
* @param clipboard
* @param adapter
* @param x
* @param y
*/
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
designer.getSelectionModel().getSelection().reset();
Rectangle rec = selection.getSelctionBounds();
for (XCreator creator : selection.getSelectedCreators()) {
for (XCreator creator : clipboard.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);
Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
}
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED);
return;
}
/**
* 组件复用绝对布局获取粘贴组件位置
*
* @param layoutAdapter 绝对布局容器AbstractLayoutAdapter
* @param copiedCreator 复制的组件
* @param x x=组件x + clonedCreator.getWidth() / 2
* @param y y=组件y + clonedCreator.getHeight() / 2
* 除2的步骤会导致当宽度或者高度为奇数是中心点向左上各偏移一个像素
* 由于中心点向左上各偏移一个像素依赖中心点计算的右下点就会相应的想做上偏移一个像素导致结果不准确
* @return 新位置坐标
*/
private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) {
//当宽度为奇数时 设置偏移
int xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0;
//当高度为奇数时 设置偏移
int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0;
if (!layoutAdapter.accept(copiedCreator, x, y)) {
XLayoutContainer container = layoutAdapter.getContainer();
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
/*
* 组件原始位置位于布局的右下角
* 和布局右下边界线紧挨
* 粘贴时组件在原始位置向左错开20像素
* x,y同时越界
*/
if (xOut && yOut) {
x = backoffset ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset
: container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X - xoffset;
y = backoffset ?
container.getHeight() - copiedCreator.getHeight() / 2 - yoffset
: container.getHeight() - copiedCreator.getHeight() / 2 - DELAY_Y - yoffset;
backoffset = !backoffset;
return new Point(x, y);
}
/*
* 组件原始位置与布局边界距离小于20像素下边界&右边界同时小于或者任意一个边界小于
* 则粘贴时距离小于20像素一侧直接贴近布局边界
* 距离大于20像素的一侧正常错开
* x,y中只有一个越界
*/
else if ((xOut || yOut)) {
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x;
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
return new Point(x, y);
}
Toolkit.getDefaultToolkit().beep();
}
return new Point(x, y);
}
/**
* 拷贝组件
*
* @param formDesigner
* @param xCreator
* @return
* @throws CloneNotSupportedException
*/
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws
CloneNotSupportedException {
ArrayList<String> nameSpace = new ArrayList<String>();
Widget copied = (Widget) xCreator.toData().clone();
//重命名拷贝的组件
String name = getCopiedName(formDesigner, copied, nameSpace);
if (copied instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) copied, xCreator.getSize());
xwTitleLayout.resetCreatorName(name);
} else {
copied.setWidgetName(name);
}
return copied;
}
/**
* 组件拷贝命名规则
*
* @param formDesigner
* @param copied
* @param nameSpace
* @return name
*/
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) {
StringBuffer name = new StringBuffer(copied.getWidgetName());
do {
name.append(POSTFIX);
} while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString()));
nameSpace.add(name.toString());
return name.toString();
}
public static void rebuildSelection(FormDesigner designer) {
@ -74,7 +220,7 @@ public class FormSelectionUtils {
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) {
List<Widget> selectionWidget = new ArrayList<Widget>();
if(selectWidgets != null){
if (selectWidgets != null) {
selectionWidget.addAll(Arrays.asList(selectWidgets));
}
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>());
@ -82,14 +228,14 @@ public class FormSelectionUtils {
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,
ArrayList<XCreator> newSelection) {
FormSelectionUtils._rebuild(rootComponent, selectionWidget, 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) {
private static void rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
if (selectionWidget.isEmpty()) {
return;
}
@ -116,9 +262,7 @@ public class FormSelectionUtils {
}
}
if (c instanceof XLayoutContainer) {
_rebuild((XLayoutContainer) c, selectionWidget, newSelection);
} else {
continue;
rebuild((XLayoutContainer) c, selectionWidget, newSelection);
}
}
}

65
designer_form/src/com/fr/design/mainframe/JForm.java

@ -4,10 +4,12 @@ import com.fr.base.BaseUtils;
import com.fr.design.DesignState;
import com.fr.design.actions.core.WorkBookSupportable;
import com.fr.design.actions.file.WebPreviewUtils;
import com.fr.design.mainframe.actions.FormMobileAttrAction;
import com.fr.design.cell.FloatElementsProvider;
import com.fr.design.constants.UIConstants;
import com.fr.design.designer.beans.actions.CopyAction;
import com.fr.design.designer.beans.actions.CutAction;
import com.fr.design.designer.beans.actions.FormDeleteAction;
import com.fr.design.designer.beans.actions.PasteAction;
import com.fr.design.designer.beans.events.DesignerEditListener;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*;
@ -20,6 +22,7 @@ import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.xpane.FormHyperlinkGroupPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.actions.EmbeddedFormExportExportAction;
import com.fr.design.mainframe.actions.FormMobileAttrAction;
import com.fr.design.mainframe.actions.TemplateParameterAction;
import com.fr.design.mainframe.form.FormECCompositeProvider;
import com.fr.design.mainframe.form.FormECDesignerProvider;
@ -40,7 +43,6 @@ import com.fr.form.FormElementCaseProvider;
import com.fr.form.main.Form;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
@ -274,10 +276,10 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
}
@Override
/**
*焦点放到JForm
* 焦点放到JForm
*/
@Override
public void requestFocus() {
super.requestFocus();
formDesign.requestFocus();
@ -291,12 +293,12 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
formDesign.requestFocus();
}
@Override
/**
* 保存文件的后缀名
*
* @return 返回后缀名
*/
@Override
public String suffix() {
// daniel改成三个字
return ".frm";
@ -329,30 +331,33 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
formDesign.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_SELECTED);
}
@Override
/**
*复制 f
* 复制
*/
@Override
public void copy() {
this.formDesign.copy();
}
@Override
/**
*
* 粘贴
*
* @return 是否成功
*/
@Override
public boolean paste() {
return this.formDesign.paste();
}
@Override
/**
*
* 剪切
*
* @return 是否成功
*/
@Override
public boolean cut() {
return this.formDesign.cut();
}
@ -362,36 +367,38 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
// ////////////////////////////////////////////////////////////////////
@Override
/**
* 目标菜单
*
* @return 菜单
*/
@Override
public MenuDef[] menus4Target() {
return this.index == FORM_TAB ?
(MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.formDesign.menus4Target()) :
(MenuDef[]) ArrayUtils.addAll(super.menus4Target(), this.elementCaseDesign.menus4Target());
}
@Override
/**
* 模板的工具
*
* @return 工具
*/
@Override
public ToolBarDef[] toolbars4Target() {
return this.index == FORM_TAB ?
this.formDesign.toolbars4Target() :
this.elementCaseDesign.toolbars4Target();
}
@Override
/**
* 模板菜单
*
* @return 返回菜单
*/
@Override
public ShortCut[] shortcut4TemplateMenu() {
if (this.index == FORM_TAB) {
return (ShortCut[]) ArrayUtils.addAll(new ShortCut[]{
@ -417,11 +424,6 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
}
@Override
/**
* undo的表单state
*
* @return 表单State
*/
protected FormUndoState createUndoState() {
FormUndoState cur = new FormUndoState(this, this.formDesign.getArea());
if (this.formDesign.isReportBlockEditing()) {
@ -455,17 +457,15 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
// 假如当前body是绝对布局的话就返回绝对布局body
private XLayoutContainer selectedBodyLayout() {
XLayoutContainer rootLayout = formDesign.getRootComponent();
for (int i = 0; i < rootLayout.getComponentCount(); i++){
if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)){
rootLayout = (XWAbsoluteBodyLayout)rootLayout.getXCreator(i);
for (int i = 0; i < rootLayout.getComponentCount(); i++) {
if (rootLayout.getXCreator(i).acceptType(XWAbsoluteBodyLayout.class)) {
rootLayout = (XWAbsoluteBodyLayout) rootLayout.getXCreator(i);
}
}
return rootLayout;
}
@Override
/**
* 应用undoState的表单数据
*/
protected void applyUndoState(FormUndoState u) {
try {
//JForm的target重置
@ -497,19 +497,11 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
}
@Override
/**
*
*/
protected FormModelAdapter createDesignModel() {
return new FormModelAdapter(this);
}
@Override
/**
* 表单的工具栏
*
* @return 表单工具栏
*/
public JPanel[] toolbarPanes4Form() {
return this.index == FORM_TAB ?
new JPanel[]{FormParaWidgetPane.getInstance(formDesign)} :
@ -524,10 +516,9 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
public JComponent[] toolBarButton4Form() {
return this.index == FORM_TAB ?
new JComponent[]{
//自适应布局里的复制粘贴意义不大, 先屏蔽掉
// new CutAction(formDesign).createToolBarComponent(),
// new CopyAction(formDesign).createToolBarComponent(),
// new PasteAction(formDesign).createToolBarComponent(),
new CutAction(formDesign).createToolBarComponent(),
new CopyAction(formDesign).createToolBarComponent(),
new PasteAction(formDesign).createToolBarComponent(),
new FormDeleteAction(formDesign).createToolBarComponent()} :
elementCaseDesign.toolBarButton4Form();
}

52
designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java

@ -36,7 +36,7 @@ public class MobileWidgetTable extends JTable {
private static final int WIDGET_TABLE_ROW_HEIGHT = 22;
private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件
private int selectedRow = -1;
private int GAP = 11;
private static final int GAP = 11;
private boolean draging = false;
private boolean collapsed = false; // 控件列表是否折叠
@ -57,7 +57,7 @@ public class MobileWidgetTable extends JTable {
TableModel defaultModel = new BeanTableModel();
this.setModel(defaultModel);
this.repaint();
this.setDefaultRenderer(Object.class,new DefaultTableCellRenderer());
this.setDefaultRenderer(Object.class, new DefaultTableCellRenderer());
refreshData();
this.addMouseListener(mouseAdapter);
this.addMouseMotionListener(mouseAdapter);
@ -90,7 +90,7 @@ public class MobileWidgetTable extends JTable {
@Override
public void mousePressed(MouseEvent e) {
getInstance().setCellSelected();
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2){ // 如果是点击在第一行
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2) { // 如果是点击在第一行
toggleCollapse();
}
}
@ -102,14 +102,14 @@ public class MobileWidgetTable extends JTable {
*/
@Override
public void mouseReleased(MouseEvent e) {
if(!draging){
if (!draging) {
return;
}
draging = false;
moveComponent.setVisible(false);
int toIndex = e.getY() < GAP ? 0 : (int)Math.rint((e.getY() - GAP)/WIDGET_TABLE_ROW_HEIGHT) + 1;
int toIndex = e.getY() < GAP ? 0 : (int) Math.rint((e.getY() - GAP) / WIDGET_TABLE_ROW_HEIGHT) + 1;
//当鼠标放开时,将选中的容器调整至新的顺序
((WSortLayout)designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
((WSortLayout) designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
//拿取排序后表格数据,然后重绘表格
getInstance().refreshData();
getInstance().repaint();
@ -124,8 +124,8 @@ public class MobileWidgetTable extends JTable {
@Override
public void mouseMoved(MouseEvent e) {
int overRow = 0;
for (int i = 0;i < getRowCount();i++) {
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT){
for (int i = 0; i < getRowCount(); i++) {
if (e.getY() > i * WIDGET_TABLE_ROW_HEIGHT && e.getY() <= (i + 1) * WIDGET_TABLE_ROW_HEIGHT) {
overRow = i; //判断鼠标在哪一行
}
}
@ -147,10 +147,10 @@ public class MobileWidgetTable extends JTable {
public void mouseDragged(MouseEvent e) {
int width = getColumnModel().getColumn(0).getWidth();
//如果当前选中的行的范围是合理的话,就可以拖动
if (selectedRow < getRowCount() && selectedRow > 0){
if (selectedRow < getRowCount() && selectedRow > 0) {
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
draging = true;
moveComponent.setText(getValueAt(selectedRow,0).toString());
moveComponent.setText(getValueAt(selectedRow, 0).toString());
moveComponent.setLocation(0, e.getY() - GAP);
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT));
moveComponent.setVisible(true);
@ -165,16 +165,16 @@ public class MobileWidgetTable extends JTable {
*/
@Override
public void mouseClicked(MouseEvent e) {
if(selectedRow > 0){
if (selectedRow > 0) {
//当前点击的控件的名字
String widgetName = cellData[selectedRow][0];
if (StringUtils.isNotEmpty(widgetName)){
if (StringUtils.isNotEmpty(widgetName)) {
//当前选择的容器
XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator();
WLayout selectedWidget = (WLayout)selectedContainer.toData();
WLayout selectedWidget = (WLayout) selectedContainer.toData();
//当前选择的容器中的控件数量
int count = selectedWidget.getWidgetCount();
for (int i = 0;i < count ;i++){
for (int i = 0; i < count; i++) {
XCreator xCreator = (XCreator) selectedContainer.getComponent(i);
Widget widget = xCreator.toData();
if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) {
@ -182,7 +182,7 @@ public class MobileWidgetTable extends JTable {
}
}
}
} else if (selectedRow == 0){ // 如果是点击在第一行
} else if (selectedRow == 0) { // 如果是点击在第一行
if (!e.isPopupTrigger() && e.getClickCount() > 1) {
toggleCollapse();
}
@ -200,11 +200,11 @@ public class MobileWidgetTable extends JTable {
}
};
public MobileWidgetTable getInstance(){
public MobileWidgetTable getInstance() {
return this;
}
public FormDesigner getEditingDesigner(){
public FormDesigner getEditingDesigner() {
return designer;
}
@ -236,7 +236,7 @@ public class MobileWidgetTable extends JTable {
/**
* 重新get排序后的数据
*/
public void refreshData(){
public void refreshData() {
cellData = getData();
}
@ -245,21 +245,22 @@ public class MobileWidgetTable extends JTable {
*
* @return String[][] 二维数组[0][0]widgetName
*/
private String[][] getData(){
if(designer.isFormParaDesigner()){
private String[][] getData() {
if (designer.isFormParaDesigner()) {
return new String[0][0];
}
//选择的控件
Widget selectedModel = designer.getSelectionModel().getSelection().getSelectedCreator().toData();
XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null;
if(selectedModel == null){
if (selectedModel == null) {
return new String[0][0];
}
// 选择的控件有两种类型,一种是WLayout,代表容器,一种是Widget,代表控件
if (selectedModel.acceptType(WSortLayout.class)) {
List<String> mobileWidgetList = ((WSortLayout)selectedModel).getOrderedMobileWidgetList();
List<String> mobileWidgetList = ((WSortLayout) selectedModel).getOrderedMobileWidgetList();
String[][] widgetName = new String[mobileWidgetList.size() + 1][1];
widgetName[0][0] = Inter.getLocText("FR-Designer_WidgetOrder");
for (int i = 0; i < mobileWidgetList.size(); i++) {
@ -284,7 +285,7 @@ public class MobileWidgetTable extends JTable {
*/
public class BeanTableModel extends DefaultTableModel {
public BeanTableModel() {
super(cellData,headers);
super(cellData, headers);
}
@Override
@ -307,7 +308,7 @@ public class MobileWidgetTable extends JTable {
return null;
}
if (row == 0) {
return (isCollapsed()? "+" : "-") + cellData[row][0];
return (isCollapsed() ? "+" : "-") + cellData[row][0];
}
return cellData[row][0];
@ -333,6 +334,7 @@ public class MobileWidgetTable extends JTable {
/**
* 是否可编辑
*
* @param row 行号
* @param column 列号
* @return 是否可编辑

26
designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java

@ -147,7 +147,8 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
designer.addDesignerEditListener(new mobileWidgetDesignerAdapter());
centerPane = FRGUIPaneFactory.createCardLayout_S_Pane();
cardLayout = (CardLayout) centerPane.getLayout();
centerPane.add(mobileParaWidgetTable, PARA);// 采用卡片布局的容器必须指定卡片名字,如果没有卡片名字
centerPane.add(mobileParaWidgetTable, PARA);
// 采用卡片布局的容器必须指定卡片名字,如果没有卡片名字
// 就会出现:Exception in thread "main" java.lang.IllegalArgumentException:
// cannot add to layout: constraint must be a string
// 第二个参数代表卡片的名字。后来show方法调用时通过名字找到要显示的卡片
@ -155,11 +156,11 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
//只有放到JScrollPanel中去表头才能正常显示,这就是MobileWidgetTable中定义了表头却没有显示的原因!
//解决方案:MobileWidgetTable实在无法直接放到JScrollPanel中去的时候,应该把表头get出来单独作为一个组件显示
if(hasSelectParaPane(designer)){
cardLayout.show(centerPane,PARA);
if (hasSelectParaPane(designer)) {
cardLayout.show(centerPane, PARA);
header = mobileParaWidgetTable.getTableHeader();
} else {
cardLayout.show(centerPane,BODY);
cardLayout.show(centerPane, BODY);
header = mobileWidgetTable.getTableHeader();
}
downPanel = new UIScrollPane(centerPane);
@ -200,6 +201,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
/**
* 判断是将拓展的tab放入属性表还是将原来的tab放入属性表
*
* @param widgetAttrProviders 拓展的tab
*/
private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) {
@ -219,6 +221,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
/**
* 如果是body的拓展属性表那么要额外加上一张控件顺序表
*
* @return
*/
private Component getExtraBodyTable(AbstractPropertyTable abstractPropertyTable) {
@ -243,18 +246,20 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp);
}
//
/**
* 选中的组件是否在参数面板里
*
* @param designer 设计器
* @return 是则返回true
*/
public boolean hasSelectParaPane(FormDesigner designer){
public boolean hasSelectParaPane(FormDesigner designer) {
XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
if(xCreator == null){
if (xCreator == null) {
xCreator = designer.getRootComponent();
}
XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator);
//TODO container可能为空,引发空指针异常
return xCreator.acceptType(XWParameterLayout.class) || container.acceptType(XWParameterLayout.class);
}
@ -335,6 +340,7 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
/**
* 响应界面改变事件
*
* @param evt 事件
*/
public void fireCreatorModified(DesignerEvent evt) {
@ -343,11 +349,11 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) {
int value = downPanel.getVerticalScrollBar().getValue();
if(hasSelectParaPane(getEditingFormDesigner())){
cardLayout.show(centerPane,PARA);
if (hasSelectParaPane(getEditingFormDesigner())) {
cardLayout.show(centerPane, PARA);
mobileParaWidgetTable.refreshData();
} else {
cardLayout.show(centerPane,BODY);
cardLayout.show(centerPane, BODY);
mobileWidgetTable.refreshData();
}
//出现滚动条

Loading…
Cancel
Save