Browse Source

Merge pull request #817 in BA/design from ~PAUL/design:master to master

* commit '81e1e4ea8fb8f0444c69e188c17e906406e97572': (80 commits)
  无JIRA任务  屏蔽新翻页
  REPORT-2220 数据连接用户名和密码可以传参
  修改
  修改代码
  修改最大最小值值定义,兼容vancharts插件
  国际化修改 部分未翻译字段翻译 庄奇 201704130221
  REPORT-2344 国际化——繁体设计器少了key
  report-1945,tab|自适应,无组件时粘贴问题
  report-1945 自适应无组件是粘贴失败修复
  组件复用层叠顺序新添加的组件在上方
  无任务代码调整
  report-1945frm本地组件复用:1、自适应或者tab布局时,不选中粘贴默认为上下平分左上角的组件;2、tab布局(有无参数面板)粘贴位置问题
  国际化修改 design部分 庄奇 201704110018
  REPORT-2334 表单tab布局中图表放大缩小会明显
  REPORT-1916 模板耗时=》修复初次保存模板时,没有保存ID的bug
  report-1945组件复用bug
  REPORT-1916 模板耗时=》给TemplateInfoCollector加上serialVersionUID
  修改国际化
  调整代码
  REPORT-1916 模板耗时=》调整代码;发送数据失败时,输出日志
  ...
master
superman 7 years ago
parent
commit
f981f8f59a
  1. 1
      .gitignore
  2. 73
      designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj
  3. 2
      designer/src/com/fr/design/mainframe/InformationCollector.java
  4. 1
      designer/src/com/fr/design/mainframe/JPolyWorkBook.java
  5. 18
      designer/src/com/fr/design/mainframe/JWorkBook.java
  6. 74
      designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java
  7. 9
      designer/src/com/fr/grid/Grid.java
  8. 21
      designer/src/com/fr/start/ReportSplashPane.java
  9. 21
      designer_base/build.dev.gradle
  10. 70
      designer_base/build.dev.gradle.bak
  11. 60
      designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj
  12. 70
      designer_base/src/com/fr/design/actions/edit/CopyAction.java
  13. 25
      designer_base/src/com/fr/design/actions/help/AboutPane.java
  14. 1130
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  15. 7
      designer_base/src/com/fr/design/beans/location/WidgetForbidWindow.java
  16. 1
      designer_base/src/com/fr/design/dialog/BasicDialog.java
  17. 24
      designer_base/src/com/fr/design/dialog/BasicPane.java
  18. 2
      designer_base/src/com/fr/design/extra/PluginHelper.java
  19. 13
      designer_base/src/com/fr/design/formula/VariableResolverAdapter.java
  20. 18
      designer_base/src/com/fr/design/locale/designer.properties
  21. 17
      designer_base/src/com/fr/design/locale/designer_en_US.properties
  22. 89
      designer_base/src/com/fr/design/locale/designer_ja_JP.properties
  23. 49
      designer_base/src/com/fr/design/locale/designer_ko_KR.properties
  24. 14
      designer_base/src/com/fr/design/locale/designer_zh_CN.properties
  25. 48
      designer_base/src/com/fr/design/locale/designer_zh_TW.properties
  26. 67
      designer_base/src/com/fr/design/mainframe/BaseJForm.java
  27. 54
      designer_base/src/com/fr/design/mainframe/JTemplate.java
  28. 332
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java
  29. 26
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessInfo.java
  30. 20
      designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDockPlus.java
  31. 73
      designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java
  32. 303
      designer_base/src/com/fr/design/utils/ComponentUtils.java
  33. 20
      designer_chart/build.dev.gradle
  34. 85
      designer_chart/build.dev.gradle.bak
  35. 59
      designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj
  36. 52
      designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java
  37. 2
      designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java
  38. 20
      designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java
  39. 13
      designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java
  40. 14
      designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java
  41. 19
      designer_form/build.dev.gradle
  42. 4
      designer_form/build.dev.gradle.bak
  43. 59
      designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj
  44. 177
      designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java
  45. 59
      designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java
  46. 361
      designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java
  47. 542
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  48. 26
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java
  49. 75
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  50. 211
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  51. 333
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  52. 180
      designer_form/src/com/fr/design/designer/beans/models/AddingModel.java
  53. 787
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  54. 688
      designer_form/src/com/fr/design/designer/beans/models/StateModel.java
  55. 45
      designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java
  56. 182
      designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java
  57. 153
      designer_form/src/com/fr/design/designer/creator/XElementCase.java
  58. 435
      designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java
  59. 338
      designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java
  60. 1388
      designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java
  61. 170
      designer_form/src/com/fr/design/mainframe/ConnectorHelper.java
  62. 1239
      designer_form/src/com/fr/design/mainframe/EditingMouseListener.java
  63. 17
      designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java
  64. 245
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  65. 481
      designer_form/src/com/fr/design/mainframe/FormEditToolBar.java
  66. 584
      designer_form/src/com/fr/design/mainframe/FormSelection.java
  67. 377
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java
  68. 84
      designer_form/src/com/fr/design/mainframe/FormSettingToolBar.java
  69. 68
      designer_form/src/com/fr/design/mainframe/FormToolBar.java
  70. 164
      designer_form/src/com/fr/design/mainframe/FormToolBarButton.java
  71. 233
      designer_form/src/com/fr/design/mainframe/FormToolBarPane.java
  72. 54
      designer_form/src/com/fr/design/mainframe/FormWebWidgetConstants.java
  73. 1579
      designer_form/src/com/fr/design/mainframe/JForm.java
  74. 692
      designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java
  75. 736
      designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java
  76. 42
      designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java
  77. 57
      designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java
  78. 13
      designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarEditor.java
  79. 304
      designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarPane.java
  80. 34
      designer_form/src/com/fr/design/mainframe/widget/wrappers/ElementCaseToolBarWrapper.java

1
.gitignore vendored

@ -3,5 +3,6 @@ designer_base/bin
designer_chart/bin
designer_form/bin
*.iml
designer_base/src/com/fr/design/locale/.idea

73
designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj

@ -0,0 +1,73 @@
package com.fr.aspectj.designer;
/**
* 记录模板过程
* Created by plough on 2017/3/3.
*/
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.grid.Grid;
import org.aspectj.lang.reflect.SourceLocation;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.Date;
public aspect TemplateProcessTracker {
//声明一个pointcut,匹配你需要的方法
pointcut onMouseClicked(MouseEvent e) :
execution(* mouseClicked(MouseEvent)) && args(e);
pointcut onMousePressed(MouseEvent e) :
execution(* mousePressed(MouseEvent)) && args(e);
pointcut onMouseReleased(MouseEvent e) :
execution(* mouseReleased(MouseEvent)) && args(e);
pointcut onActionPerformed(ActionEvent e) :
execution(* actionPerformed(ActionEvent)) && args(e);
pointcut onSetValueAt(Object v, int r, int c) :
execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c);
pointcut onSetValue4EditingElement(Grid g, Object v) :
call(* setValue4EditingElement(java.lang.Object)) && target(g) && args(v);
//before表示之前的意思
//这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码
before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置
// String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(ActionEvent e) : onActionPerformed(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
// !within(LogHandlerBar) 没用, 手动过滤
if (e.getSource().toString().contains("javax.swing.Timer")) {
return;
}
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(Object v, int r, int c) : onSetValueAt(v, r, c) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
//String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c);
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(Grid g, Object v) : onSetValue4EditingElement(g, v) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
// String v = "test";
//String log = String.format("%s:\n%s\nset value: %s at %s\n\n", new Date(), sl, v, g.getEditingCellElement());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
}

2
designer/src/com/fr/design/mainframe/InformationCollector.java

@ -10,6 +10,7 @@ import com.fr.data.core.db.dml.Delete;
import com.fr.data.core.db.dml.Select;
import com.fr.data.core.db.dml.Table;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.general.*;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
@ -315,6 +316,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
}
sendFunctionsInfo();
sendUserInfo();
TemplateInfoCollector.getInstance().sendTemplateInfo();
}
});
sendThread.start();

1
designer/src/com/fr/design/mainframe/JPolyWorkBook.java

@ -24,7 +24,6 @@ public class JPolyWorkBook extends JWorkBook {
super(new WorkBook(new PolyWorkSheet()), DEFAULT_NAME);
populateReportParameterAttr();
}
/**
* 创建sheet名称tab面板

18
designer/src/com/fr/design/mainframe/JWorkBook.java

@ -3,6 +3,7 @@ package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.Parameter;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.DesignModelAdapter;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.AllowAuthorityEditAction;
@ -26,6 +27,8 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIModeControlContainer;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.mainframe.cell.QuickEditorRegion;
import com.fr.design.mainframe.templateinfo.JWorkBookProcessInfo;
import com.fr.design.mainframe.templateinfo.TemplateProcessInfo;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.*;
import com.fr.design.module.DesignModuleFactory;
@ -54,7 +57,10 @@ import com.fr.main.impl.WorkBook;
import com.fr.main.parameter.ReportParameterAttr;
import com.fr.poly.PolyDesigner;
import com.fr.privilege.finegrain.WorkSheetPrivilegeControl;
import com.fr.report.cellcase.CellCase;
import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.report.Report;
import com.fr.report.worksheet.WorkSheet;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
@ -66,10 +72,7 @@ import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* JWorkBook used to edit WorkBook.
@ -129,6 +132,13 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
return centerPane;
}
public TemplateProcessInfo getProcessInfo() {
if (processInfo == null) {
processInfo = new JWorkBookProcessInfo(template);
}
return processInfo;
}
/**
* 判断sheet权限
*

74
designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java

@ -0,0 +1,74 @@
package com.fr.design.mainframe.templateinfo;
import com.fr.base.parameter.ParameterUI;
import com.fr.main.impl.WorkBook;
import com.fr.report.cellcase.CellCase;
import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.worksheet.WorkSheet;
import java.util.Iterator;
/**
* Created by plough on 2017/3/17.
*/
public class JWorkBookProcessInfo extends TemplateProcessInfo<WorkBook> {
public JWorkBookProcessInfo(WorkBook wb) {
super(wb);
}
// 获取模板类型
public int getReportType() {
return template.isElementCaseBook() ? 0 : 1;
}
// 获取模板格子数
public int getCellCount() {
int cellCount = 0;
if (template.isElementCaseBook()) { // 如果是普通报表
for (int i = 0; i < template.getReportCount(); i++) {
WorkSheet r = (WorkSheet) template.getReport(i);
CellCase cc = r.getBlock().getCellCase();
for (int j = 0; j < cc.getRowCount(); j++) {
Iterator iter = cc.getRow(j);
while (iter.hasNext()) {
cellCount ++;
iter.next();
}
}
}
}
return cellCount;
}
// 获取模板悬浮元素个数
public int getFloatCount() {
int chartCount = 0;
if (template.isElementCaseBook()) { // 如果是普通报表
for (int i = 0; i < template.getReportCount(); i++) {
WorkSheet r = (WorkSheet) template.getReport(i);
Iterator fiter = r.getBlock().floatIterator();
while (fiter.hasNext()) {
chartCount ++;
fiter.next();
}
}
}
return chartCount;
}
// 获取模板聚合块个数
public int getBlockCount() {
int blockCount = 0;
if (!template.isElementCaseBook()) { // 如果是聚合报表
for (int i = 0; i < template.getReportCount(); i++) {
PolyWorkSheet r = (PolyWorkSheet) template.getReport(i);
blockCount += r.getBlockCount();
}
}
return blockCount;
}
// 获取模板控件数
public int getWidgetCount() {
ParameterUI pui = template.getReportParameterAttr().getParameterUI();
return pui == null ? 0 : (pui.getAllWidgets().length - 1);
}
}

9
designer/src/com/fr/grid/Grid.java

@ -10,6 +10,7 @@ import com.fr.design.constants.UIConstants;
import com.fr.design.fun.GridUIProcessor;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.mainframe.ElementCasePane;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
import com.fr.grid.event.CellEditorEvent;
@ -35,6 +36,7 @@ import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.Point2D;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
@ -1065,6 +1067,13 @@ public class Grid extends BaseGridComponent {
}
/**
* @return editingCellElement 的字符串表示
*/
public String getEditingCellElement() {
return editingCellElement.toString();
}
/**
* 将新值赋给editingCellElement
*

21
designer/src/com/fr/start/ReportSplashPane.java

@ -4,6 +4,7 @@
package com.fr.start;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper;
import com.fr.design.mainframe.bbs.BBSConstants;
import com.fr.general.GeneralContext;
@ -18,6 +19,7 @@ import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.LineMetrics;
import java.awt.image.BufferedImage;
import java.util.Locale;
import java.util.Random;
import java.util.TimerTask;
@ -117,9 +119,22 @@ public class ReportSplashPane extends SplashPane{
GraphHelper.drawString(splashG2d, showText, MODULE_INFO_X, y);
//每次随机感谢一位论坛用户
splashG2d.setPaint(THANK_COLOR);
String content = Inter.getLocText("FR-Designer_Thanks-To") + GUEST;
GraphHelper.drawString(splashG2d, content, THANK_INFO_X, y);
if (shouldShowThanks()) {
splashG2d.setPaint(THANK_COLOR);
String content = Inter.getLocText("FR-Designer_Thanks-To") + GUEST;
GraphHelper.drawString(splashG2d, content, THANK_INFO_X, y);
}
}
// 是否显示鸣谢文字
private boolean shouldShowThanks() {
Locale[] hideLocales = {Locale.US, Locale.KOREA, Locale.JAPAN};
for (Locale loc : hideLocales) {
if (FRContext.getLocale().equals(loc)) {
return false;
}
}
return true;
}
private static String getRandomUser(){

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

60
designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj

@ -0,0 +1,60 @@
package com.fr.aspectj.designerbase;
/**
* 记录模板过程
* Created by plough on 2017/3/3.
*/
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import org.aspectj.lang.reflect.SourceLocation;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.Date;
public aspect TemplateProcessTracker {
//声明一个pointcut,匹配你需要的方法
pointcut onMouseClicked(MouseEvent e) :
execution(* mouseClicked(MouseEvent)) && args(e);
pointcut onMousePressed(MouseEvent e) :
execution(* mousePressed(MouseEvent)) && args(e);
pointcut onMouseReleased(MouseEvent e) :
execution(* mouseReleased(MouseEvent)) && args(e);
pointcut onActionPerformed(ActionEvent e) :
execution(* actionPerformed(ActionEvent)) && args(e);
pointcut onSetValueAt(Object v, int r, int c) :
execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c);
//before表示之前的意思
//这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码
before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(ActionEvent e) : onActionPerformed(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
// !within(LogHandlerBar) 没用, 手动过滤
if (e.getSource().toString().contains("javax.swing.Timer")) {
return;
}
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(Object v, int r, int c) : onSetValueAt(v, r, c) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
//String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c);
String log = "";
TemplateInfoCollector.appendProcess(log);
}
}

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

@ -1,37 +1,35 @@
/*
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved.
*/
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;
/**
* Copy.
*/
public class CopyAction extends TemplateComponentAction {
public CopyAction(TargetComponent t) {
super(t);
this.setName(Inter.getLocText("M_Edit-Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
}
@Override
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc != null) {
tc.copy();
}
return false;
}
/*
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved.
*/
package com.fr.design.actions.edit;
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.
*/
public class CopyAction extends TemplateComponentAction {
public CopyAction(TargetComponent t) {
super(t);
this.setName(Inter.getLocText("M_Edit-Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
}
@Override
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc != null) {
tc.copy();
}
return false;
}
}

25
designer_base/src/com/fr/design/actions/help/AboutPane.java

@ -68,10 +68,7 @@ public class AboutPane extends JPanel {
Inter.getLocText("FR-Designer-Basic_Activation_Key_Copy_OK")
}));
// 英文去掉服务电话和 QQ
if (FRContext.getLocale().equals(Locale.US)){
// do nothing
} else {
if (shouldShowPhoneAndQQ()){
if(ComparatorUtils.equals(ProductConstants.APP_NAME,FINEREPORT)){
boxCenterAlignmentPane = new BoxCenterAligmentPane(Inter.getLocText("FR-Designer_Service_Phone") + ProductConstants.COMPARE_TELEPHONE);
contentPane.add(boxCenterAlignmentPane);
@ -85,8 +82,24 @@ public class AboutPane extends JPanel {
contentPane.add(actionLabel);
contentPane.add(emailLabel);
addThankPane(contentPane);
if (shouldShowThanks()) {
addThankPane(contentPane);
}
}
// 是否显示服务电话和 qq
private boolean shouldShowPhoneAndQQ() {
return !FRContext.getLocale().equals(Locale.US);
}
// 是否显示鸣谢面板
private boolean shouldShowThanks() {
Locale[] hideLocales = {Locale.US, Locale.KOREA, Locale.JAPAN};
for (Locale loc : hideLocales) {
if (FRContext.getLocale().equals(loc)) {
return false;
}
}
return true;
}
//添加鸣谢面板

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

File diff suppressed because it is too large Load Diff

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

1
designer_base/src/com/fr/design/dialog/BasicDialog.java

@ -13,6 +13,7 @@ public abstract class BasicDialog extends UIDialog {
public static final Dimension CHART = new Dimension(760, 560);
public static final Dimension MAP_SIZE = new Dimension(760, 450);
public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600,300);
public static final Dimension TOOLBAR_SIZE = new Dimension(660, 327);
public BasicDialog(Frame parent) {
super(parent);

24
designer_base/src/com/fr/design/dialog/BasicPane.java

@ -251,6 +251,30 @@ public abstract class BasicPane extends JPanel {
return dg;
}
/**
* 显示窗口
*
* @param window 窗口
* @param l 对话框监听器
* @return 对话框
*/
public BasicDialog showToolBarWindow(Window window, DialogActionListener l) {
BasicDialog dg;
if (window instanceof Frame) {
dg = new DIALOG((Frame) window);
} else {
dg = new DIALOG((Dialog) window);
}
if (l != null) {
dg.addDialogActionListener(l);
}
dg.setBasicDialogSize(BasicDialog.TOOLBAR_SIZE);
GUICoreUtils.centerWindow(dg);
dg.setResizable(false);
return dg;
}
protected abstract String title4PopupWindow();
public String getTitle() {

2
designer_base/src/com/fr/design/extra/PluginHelper.java

@ -322,6 +322,8 @@ public class PluginHelper {
if (plugin == null || env == null) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
//卸载前监听
plugin.preUninstall();
PluginLoader.getLoader().deletePlugin(plugin);
return env.deleteFileFromPluginAndLibFolder(plugin);
}

13
designer_base/src/com/fr/design/formula/VariableResolverAdapter.java

@ -4,12 +4,16 @@ import com.fr.base.ConfigManager;
import com.fr.base.Parameter;
import com.fr.design.DesignModelAdapter;
import com.fr.base.ConfigManagerProvider;
import com.fr.plugin.ExtraClassManager;
import com.fr.script.ScriptConstants;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.fun.BuiltInParametersProvider;
import com.fr.stable.script.CalculatorProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public abstract class VariableResolverAdapter implements VariableResolver {
private static final int TABLE_DATA_PARA = 0;
@ -21,7 +25,7 @@ public abstract class VariableResolverAdapter implements VariableResolver {
* @return 内置参数
*/
public String[] resolveCurReportVariables() {
return new String[] { ScriptConstants.SUMMARY_TAG + "page_number",
String [] variables = new String[] { ScriptConstants.SUMMARY_TAG + "page_number",
ScriptConstants.SUMMARY_TAG + "totalPage_number",
// 下面是权限相关的参数
ScriptConstants.DETAIL_TAG + Constants.P.PRIVILEGE_USERNAME, ScriptConstants.DETAIL_TAG + Constants.P.PRIVILEGE_AUTHORITY,
@ -32,6 +36,13 @@ public abstract class VariableResolverAdapter implements VariableResolver {
CalculatorProvider.REPORT_NAME, CalculatorProvider.FORMLET_NAME, CalculatorProvider.SERVLET_URL, CalculatorProvider.SERVER_SCHEMA, CalculatorProvider.SERVER_NAME,
CalculatorProvider.SERVER_PORT, CalculatorProvider.SERVER_URL, CalculatorProvider.CONTEXT_PATH, CalculatorProvider.SESSION_ID
};
Set<BuiltInParametersProvider> set = ExtraClassManager.getInstance().getArray(BuiltInParametersProvider.XML_TAG);
for (BuiltInParametersProvider provider : set) {
return (String[]) ArrayUtils.addAll(variables, new String []{
ScriptConstants.DETAIL_TAG + provider.getParametersName()
});
}
return variables;
}
private Parameter[] getCurrentModeParameters(int type) {

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=
FR-Designer_Data-confusion=
FR-Designer_Data_Type=
FR-Designer_Double_Click_Edit_OR_Clear=
FR-Designer_Edit_Button_ToolBar=
FR-Designer_Email=
FR-Designer_Enabled=
FR-Designer_End-Date=
@ -162,6 +163,7 @@ FR-Designer_Refresh_Parameter_In_SQL=
FR-Designer_Reg_Expressions=
FR-Designer_Reg_Max_Length=
FR-Designer_Reg_Min_Length=
FR-Designer_Remove_Button_ToolBar=
FR-Designer_ReportColumns-Columns=
FR-Designer_Return-Date=
FR-Designer_RichText=
@ -542,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_Null=Allow null
FR-Designer_Allow_Null=Allow Null
FR-Designer_PageSetup_Page=Page
FR-Designer_Custom_Job_Description=Description
FR-Designer_Property=Property
@ -587,4 +589,16 @@ FR-Designer_Mouse_Click_Tips=
FR-Designer-Move_Tab_First=move to first
FR-Designer-Move_Tab_End=move to end
FR-Designer-Move_Tab_Next=move to next
FR-Designer-Move_Tab_Prev=move to previous
FR-Designer-Move_Tab_Prev=move to previous
FR-Designer_AxisReversed=AxisValue
FR-Designer_Logarithmic=Logarithmic
FR-Designer_Chart_Log_Base=Log Base
FR-Designer_Chart_F_Radar_Axis=Chart_F_Radar_Axis
FR-Designer_Too_Large_To_Paste=too large to paste
FR-Designer_Too_Small_To_Paste=Too small to paste
FR-Designer_Validate=
FR-Designer_Get-CubeGetting cube=
FR-Designer_Get-CubeGetting=
FR-Designer_Fit=
FR-Designer_Properties_Mobile=
FR-Designer_Oracle=

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=Data Dictionary
FR-Designer_Data-confusion=Data Confusion
FR-Designer_Data_Type=Data type
FR-Designer_Double_Click_Edit_OR_Clear=Double Click to Edit or Clear
FR-Designer_Edit_Button_ToolBar=Edit Button ToolBar
FR-Designer_Email=Mail
FR-Designer_Enabled=Enabled
FR-Designer_End-Date=End Date
@ -163,6 +164,7 @@ FR-Designer_Refresh_Parameter_In_SQL=Whether to refresh parameters in the SQL
FR-Designer_Reg_Expressions=Regular expressions
FR-Designer_Reg_Max_Length=max length
FR-Designer_Reg_Min_Length=min length
FR-Designer_Remove_Button_ToolBar=Remove Button ToolBar
FR-Designer_ReportColumns-Columns=Multi-columns/lines
FR-Designer_Return-Date=Return Date
FR-Designer_RichText=Insert Rich Text
@ -542,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_Null=Allow null
FR-Designer_Allow_Null=Allow Null
FR-Designer_PageSetup_Page=Page
FR-Designer_Custom_Job_Description=Description
FR-Designer_Property=Property
@ -587,4 +589,15 @@ FR-Designer_Mouse_Click_Tips=The background of the mouse to click the button, in
FR-Designer-Move_Tab_First=move to first
FR-Designer-Move_Tab_End=move to end
FR-Designer-Move_Tab_Next=move to next
FR-Designer-Move_Tab_Prev=move to previous
FR-Designer-Move_Tab_Prev=move to previous
FR-Designer_AxisReversed=Axis in reverse order
FR-Designer_Logarithmic=Log scale
FR-Designer_Chart_Log_Base=Log Base
FR-Designer_Chart_F_Radar_Axis=Value Axis
FR-Designer_Too_Large_To_Paste=Too large to paste!
FR-Designer_Too_Small_To_Paste=Too small to paste!
FR-Designer_SimpleCross_Report=
FR-Designer_Get-Cube=
FR-Designer_DoubleLayer_Report=
FR-Designer_Get-CubeGetting=
FR-Designer_SimpleDetail_Report=

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=\u30C7\u30FC\u30BF\u5B57\u5178
FR-Designer_Data-confusion=\u30C7\u30FC\u30BF\u6DF7\u4EA4
FR-Designer_Data_Type=\u30C7\u30FC\u30BF\u30BF\u30A4\u30D7
FR-Designer_Double_Click_Edit_OR_Clear=\u30C0\u30D6\u30EB\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u7DE8\u96C6\u307E\u305F\u306F\u30AF\u30EA\u30A2\u3059\u308B
FR-Designer_Edit_Button_ToolBar=\u30DC\u30BF\u30F3\u306B\u3042\u308B\u30C4\u30FC\u30EB\u6B04\u7DE8\u96C6
FR-Designer_Email=\u30E1\u30FC\u30EB
FR-Designer_Enabled=\u4F7F\u7528\u53EF\u80FD
FR-Designer_End-Date=\u7D42\u4E86\u65E5\u671F
@ -162,6 +163,7 @@ FR-Designer_Refresh_Parameter_In_SQL=SQL\u4E2D\u306E\u30D1\u30E9\u30E1\u30FC\u30
FR-Designer_Reg_Expressions=\u6B63\u5247\u8868\u73FE\u5F0F
FR-Designer_Reg_Max_Length=\u6700\u5927\u9577\u3055
FR-Designer_Reg_Min_Length=\u6700\u5C0F\u9577\u3055
FR-Designer_Remove_Button_ToolBar=\u30DC\u30BF\u30F3\u304C\u3042\u308B\u30C4\u30FC\u30EB\u30D0\u30FC\u3092\u30EA\u30E0\u30FC\u30D6
FR-Designer_ReportColumns-Columns=\u6BB5\u7D44\u307F
FR-Designer_Return-Date=\u65E5\u671F\u306B\u623B\u308B
FR-Designer_RichText=\u30EA\u30C3\u30C1\u6587\u66F8\u633F\u5165
@ -364,24 +366,30 @@ FR-Designer_XMLA_Get_Catalog=\u30AB\u30BF\u30ED\u30B0\u3092\u691C\u7D22\u3059\u3
FR-Designer_XMLA_Not_NULL=\u3053\u3053\u306F\u7A7A\u6B04\u306B\u3059\u308B\u3053\u3068\u304C\u3067\u304D\u307E\u305B\u3093
FR-Designer_Column-Axis=\u5217\u8EF8
FR-Designer_LiteCondition_Common=\u4E00\u822C
FR-Designer_LiteCondition_Formula=\u516C\u5F0F
FR-Designer_LiteCondition_Formula=\u6570\u5F0F
FR-Designer_LiteCondition_ConditionB-AND=\u30A2\u30F3\u30C9(AND)
FR-Designer_LiteCondition_ConditionB-OR=\u30AA\u30A2(OR)
FR-Designer_LiteCondition_Common_Condition=\u666E\u901A\u6761\u4EF6
FR-Designer_LiteCondition_Formula_Condition=\u516C\u5F0F\u6761\u4EF6
FR-Designer_LiteCondition_Formula_Condition=\u6570\u5F0F\u6761\u4EF6
FR-Designer_LiteCondition_Define=\u5B9A\u7FA9
FR-Designer_Normal=\u6B63\u5E38
FR-Designer_Alert=\u30A2\u30E9\u30FC\u30C8
FR-Designer_Select_All=\u5168\u9078\u629E
FR-Designer-Plugin_Expire_Dialog_Title=\u671F\u9650\u5207\u308C\u306E\u30D7\u30E9\u30B0\u30A4\u30F3
FR-Designer-Plugin_Expire_Dialog_Text=\u30D7\u30E9\u30B0\u30A4\u30F3\u306F\u3001\u8CFC\u5165\u3092\u3059\u308B\u305F\u3081\u306B\u5E06\u30BD\u30D5\u30C8\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u30BB\u30F3\u30BF\u30FC\u3092\u884C\u304F\u3001\u6709\u52B9\u671F\u9650\u304C\u5207\u308C\u3066\u3044\u307E\u3059\u3002
FR-Designer-Plugin_Finerest_Addon=\u5E06\u8EDF\u5FDC\u7528\u30BB\u30F3\u30BF\u30FC
FR-Designer_Clear_All=\u5168\u3066\u3092\u30AF\u30EA\u30A2
FR-Designer_Copy=\u30B3\u30D4\u30FC
FR-Designer_Log=\u30ED\u30B0
FR-Designer-Plugin_Expire_Dialog_Title=\u30D7\u30E9\u30B0\u30A4\u30F3\u306F\u671F\u9650\u5207\u308C
FR-Designer-Plugin_Expire_Dialog_Text=\u30D7\u30E9\u30B0\u30A4\u30F3\u306F\u6709\u52B9\u671F\u9650\u304C\u5207\u308C\u3066\u3044\u307E\u3059\u3001\u30D5\u30A1\u30F3\u30E9\u30F3\u30A2\u30D7\u30EA\u30BB\u30F3\u30BF\u30FC\u3078\u8CFC\u5165\u3057\u3066\u304F\u3060\u3055\u3044\u3002
FR-Designer-Plugin_Finerest_Addon=\u30D5\u30A1\u30F3\u30E9\u30F3\u30A2\u30D7\u30EA\u30BB\u30F3\u30BF\u30FC
FR-Designer_Performance_First=\u6027\u80FD\u512A\u5148
FR-Designer_Total_N_Grade=\u5168\u90E8\u3067\:${N}\u5C64
FR-Designer_time(s)=\u56DE
FR-Designer_General=\u5E38\u7528
FR-Designer_Advanced=\u9AD8\u7D1A
FR-Designer_General=\u901A\u5E38
FR-Designer_Advanced=\u8A73\u7D30
FR-Designer_Validate=\u691C\u8A3C
FR-Designer_Oracle=\u3059\u3079\u3066\u306E\u30C6\u30FC\u30D6\u30EB
FR-Designer_Product_improve=\u88FD\u54C1\u6539\u5584
FR-Designer_Join_Product_improve=\u88FD\u54C1\u6539\u5584\u30D7\u30E9\u30F3\u306B\u52A0\u3048\u308B
FR-Designer_Join_Product_improve=\u88FD\u54C1\u6539\u5584\u30D7\u30E9\u30F3\u306B\u5165\u308B
FR-Designer_Preference-Function=\u30D5\u30A1\u30F3\u30AF\u30B7\u30E7\u30F3\u8A2D\u5B9A
FR-Designer_max_undo_limit=\u6700\u5927\u53D6\u308A\u6D88\u3057\u56DE\u6570
FR-Designer_Surport_String_To_Formula=\u30AD\u30E3\u30E9\u30AF\u30BF\u30FC\u6587\u5B57\u5217\u7DE8\u96C6\u3092\u516C\u5F0F\u3068\u3059\u308B\u3053\u3068\u306B\u30B5\u30DD\u30FC\u30C8
@ -537,21 +545,52 @@ FR-Designer_Show_As_Download=\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u30EA\u30F3\u3
FR-Designer_File_Name_For_Download=\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u30D5\u30A1\u30A4\u30EB\u540D
FR-Designer_No=\u3044\u3044\u3048
FR-Designer_Pagination=\u30DA\u30FC\u30B8\u30F3\u30B0
FR-Designer-Move_Tab_First=
FR-Designer-Move_Tab_End=
FR-Designer-Move_Tab_Next=
FR-Designer-Move_Tab_Prev=
FR-Designer_DS_TableData=\u30C7\u30FC\u30BF\u30BD\u30FC\u30B9
FR-Designer_DS_TableData=\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8
FR-Designer_Parameter-Formula=\u6570\u5F0F
FR-Designer_Background_Null=
FR-Designer_Background_Color=
FR-Designer_Background_Texture=
FR-Designer_Background_Pattern=
FR-Designer_Background_Gradient_Color=
FR-Designer_Background_Image=
FR-Designer_Background_Clear=
FR-Designer_Background_Image_Select=
FR-Designer_Initial_Background_Tips=
FR-Designer_Mouse_Move_Tips=
FR-Designer_Mouse_Click_Tips=
FR-Designer_Plugin_Should_Update_Please_Contact_Developer=
FR-Designer_Background_Null=\u80CC\u666F\u306A\u3057
FR-Designer_Background_Color=\u8272
FR-Designer_Background_Texture=\u30C6\u30AF\u30B9\u30C1\u30E3
FR-Designer_Background_Pattern=\u30D1\u30BF\u30FC\u30F3
FR-Designer_Background_Gradient_Color=\u30B0\u30E9\u30C7\u30FC\u30B7\u30E7\u30F3
FR-Designer_Background_Image=\u753B\u50CF
FR-Designer_Background_Clear=\u30AF\u30EA\u30A2
FR-Designer_Background_Image_Select=\u753B\u50CF\u9078\u629E
FR-Designer_Initial_Background_Tips=\u30DC\u30BF\u30F3\u306E\u521D\u671F\u80CC\u666F
FR-Designer_Mouse_Move_Tips=\u30DE\u30A6\u30B9\u304C\u30DC\u30BF\u30F3\u306B\u79FB\u3059\u6642\u5909\u5316\u3059\u308B\u80CC\u666F
FR-Designer_Mouse_Click_Tips=\u30DC\u30BF\u30F3\u3092\u30AF\u30EA\u30C3\u30AF\u3059\u308B\u6642\u5909\u5316\u3059\u308B\u80CC\u666F
FR-Designer-Move_Tab_First=\u30C8\u30C3\u30D7\u306B\u79FB\u3059
FR-Designer-Move_Tab_End=\u6700\u5F8C\u306B\u79FB\u3059
FR-Designer-Move_Tab_Next=\u5F8C\u308D\u306B\u79FB\u3059
FR-Designer-Move_Tab_Prev=\u524D\u306B\u79FB\u3059
FR-Designer_AxisReversed=\u8EF8\u9006\u9806
FR-Designer_Logarithmic=\u5BFE\u6570\u76EE\u76DB\u308A
FR-Designer_Chart_Log_Base=\u5E95\u6570
FR-Designer_Chart_F_Radar_Axis=\u5782\u76F4\u8EF8
FR-Designer_Too_Large_To_Paste=\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u30DC\u30FC\u30C0\u30FC\u306B\u8D85\u3048\u305F\u306E\u3067\u3001\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\uFF01
FR-Designer_Too_Small_To_Paste=\u8A72\u5F53\u51E6\u306B\u8CBC\u308A\u4ED8\u3051\u3067\u304D\u307E\u305B\u3093\u3001\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u306E\u30B5\u30A4\u30BA\u306F\u9AD8\u3059\u304E\uFF01
FR-Designer_DoubleLayer_Report=\u4E8C\u968E\u30BF\u30A4\u30C8\u30EB
FR-Designer_Printer_Native_Button=\u30ED\u30FC\u30AB\u30EB\u5370\u5237
FR-Designer_Mobile-Warning=\u6700\u5927\u306E\u9AD8\u3055\u306F\u8868\u793A\u30A8\u30EA\u30A2\u306E80\uFF05\u4EE5\u4E0A\u306B\u306A\u308A\u307E\u305B\u3093
FR-Designer_Form-Fit-Tip=\u81EA\u5DF1\u9069\u5FDC\u30D7\u30E9\u30B0\u30A4\u30F3
FR-Designer_Form-Forzen-Speed=\u3001\u305D\u3057\u3066\u6A2A\u65B9\u5411\u81EA\u5DF1\u9069\u5FDC\u307E\u305F\u306F2\u65B9\u5411\u81EA\u52D5\u9069\u5FDC\u3092\u5229\u7528\u3057\u3001\u5E33\u7968\u8868\u793A\u306E\u30B9\u30D4\u30FC\u30C9\u3092\u4E0A\u3052\u3067\u304D\u307E\u3059\u3002
FR-Designer_Mobile_Form_Analysis_Annotation=\u8AAC\u660E\:\u8A72\u5F53\u8A2D\u5B9A\u3088\u308A\u3001\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306E\u30A2\u30D7\u30EA\u3067\u306E\u89E3\u6790\u30E2\u30FC\u30C9\u3092\u8A2D\u5B9A\u3067\u304D\u307E\u3059\u3002
FR-Designer_TableData-Default-Para=\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30D1\u30E9\u30E1\u30FC\u30BF
FR-Designer-Selected_Widget=\u5F53\u306E\u30A6\u30A3\u30B8\u30A7\u30C3\u30C8
FR-Designer_Plugin_Should_Update_Please_Contact_Developer=\u30D7\u30E9\u30B0\u30A4\u30F3\u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u306F\u4F4E\u3044\u3067\u3059\u304C\u3001\u4E0D\u5177\u5408\u304C\u3067\u3063\u305F\u3001\u958B\u767A\u8005\u3068\u9023\u7D61\u3057\u3066\u304F\u3060\u3055\u3044\u3002
FR-Designer_SimpleCross_Report=\u7C21\u5358\u30AF\u30ED\u30FC\u30B9\u8868
FR-Designer_Button-Cancel=\u53D6\u308A\u6D88\u3057
FR-Designer_Delete_Template=\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u524A\u9664
FR-Designer_Install_Template=\u30B3\u30F3\u30DD\u30FC\u30CD\u30F3\u30C8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB
FR-Designer_SimpleDetail_Report=\u7C21\u5358\u660E\u7D30\u8868
FR-Designer_LocalWidget=\u30ED\u30FC\u30AB\u30EB\u30A6\u30A3\u30B8\u30A7\u30C3\u30C8\u30E9\u30A4\u30D6\u30E9\u30EA
FR-Designer_WidgetOrder=\u30A6\u30A3\u30B8\u30A7\u30C3\u30C8\u306E\u9806\u756A
FR-Designer_Form-Frozen-Tip=\u30D5\u30EA\u30FC\u30BA\u3092\u4F7F\u3046\u6642\u3001\u5F8C\u8A18\u306E\u30D7\u30E9\u30B0\u30A4\u30F3\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u3066\u304F\u3060\u3055\u3044\uFF1A
FR-Designer-Invalid_Page_Number=\u7121\u52B9\u306A\u30DA\u30FC\u30B8\u756A\u53F7
FR-Designer_Reset=\u30EA\u30BB\u30C3\u30C8
FR-Designer-Plugin_Please_Update_Jar=jar\u30D1\u30C3\u30AF\u3092\u30A2\u30C3\u30D7\u30C7\u30FC\u30C8\u3057\u3066\u304F\u3060\u3055\u3044
FR-Designer_Get-CubeGetting cube=
FR-Designer_Mobile_Report_Analysis_Annotation=\u8AAC\u660E\:\u8A72\u5F53\u5C5E\u6027\u3088\u308A\u3001\u30C0\u30C3\u30B7\u30E5\u30DC\u30FC\u30C9\u306E\u30A2\u30D7\u30EA\u3067\u306E\u89E3\u6790\u30E2\u30FC\u30C9\u3092\u8A2D\u5B9A\u3067\u304D\u307E\u3059\u3001\u9801\u5206\u3051\u30D7\u30EC\u30D3\u30E5\u30FC\u3060\u3051\u3092\u652F\u6301\u3001\u66F8\u304D\u8FBC\u307F\u306B\u8A2D\u5B9A\u3059\u308B\u6642\u7121\u52B9\u306B\u306A\u308A\u307E\u3059\u3002
FR-Designer_Properties_Mobile=\u30B9\u30DE\u30FC\u30C8\u30D5\u30A9\u30F3\u5C5E\u6027
FR-Designer_Button-OK=\u5206\u304B\u308A\u307E\u3057\u305F
FR-Designer_Allow-Blank=\u7A7A\u306B\u8A31\u3059
FR-Designer_AllCategories=\u5168\u3066\u306E\u7A2E\u985E

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=\uB370\uC774\uD130\uC0AC\uC804
FR-Designer_Data-confusion=\uB370\uC774\uD130\uD63C\uD569
FR-Designer_Data_Type=\uB370\uC774\uD130\uC720\uD615
FR-Designer_Double_Click_Edit_OR_Clear=\uB354\uBE14\uD074\uB9AD\uD558\uC5EC\uD3B8\uC9D1\uB610\uB294\uD074\uB9AC\uC5B4\uC2E4\uD589
FR-Designer_Edit_Button_ToolBar=\uD0A4\uAC00\uC788\uB294\uD234\uBC14\uD3B8\uC9D1
FR-Designer_Email=\uBA54\uC77C
FR-Designer_Enabled=\uC0AC\uC6A9\uAC00\uB2A5
FR-Designer_End-Date=\uC885\uB8CC\uB0A0\uC9DC
@ -162,6 +163,7 @@ FR-Designer_Refresh_Parameter_In_SQL=SQL\uC758\uB9E4\uAC1C\uBCC0\uC218\uB97C\uC0
FR-Designer_Reg_Expressions=\uC815\uADDC\uD45C\uD604\uC2DD
FR-Designer_Reg_Max_Length=\uCD5C\uB300\uAE38\uC774
FR-Designer_Reg_Min_Length=\uCD5C\uC18C\uAE38\uC774
FR-Designer_Remove_Button_ToolBar=\uD0A4\uAC00\uC788\uB294\uD234\uBC14\uC81C\uAC70
FR-Designer_ReportColumns-Columns=\uC140\uB098\uB204\uAE30
FR-Designer_Return-Date=\uB0A0\uC9DC\uB3CC\uC544\uAC00\uAE30
FR-Designer_RichText=\uB9AC\uCE58\uD14D\uC2A4\uD2B8\uBC15\uC2A4\uC0BD\uC785
@ -551,4 +553,49 @@ FR-Designer_Background_Image_Select=
FR-Designer_Initial_Background_Tips=
FR-Designer_Mouse_Move_Tips=
FR-Designer_Mouse_Click_Tips=
FR-Designer_Plugin_Should_Update_Please_Contact_Developer=
FR-Designer-Move_Tab_First=
FR-Designer-Move_Tab_End=
FR-Designer-Move_Tab_Next=
FR-Designer-Move_Tab_Prev=
FR-Designer_AxisReversed=\uCD95\uC5ED\uC21C
FR-Designer_Logarithmic=\uB85C\uADF8\uB208\uAE08
FR-Designer_Chart_Log_Base=\uAE30\uC218
FR-Designer_Chart_F_Radar_Axis=\uAC12\uCD95
FR-Designer_COMMUNITY_VIDEO=
FR-Designer_DoubleLayer_Report=
FR-Designer_Too_Small_To_Paste=
FR-Designer_formDesignerModule=
FR-Designer_Mobile-Warning=
FR-Designer_Mobile-Open=
FR-Designer_Form-Fit-Tip=
FR-Designer_Form-Forzen-Speed=
FR-Designer_Mobile_Form_Analysis_Annotation=
FR-Designer_Too_Large_To_Paste=
FR-Designer_COMMUNITY_HELP=
FR-Designer_Validate=
FR-Designer_Button-Cancel=
FR-Designer_Plugin_Should_Update_Please_Contact_Developer=
FR-Designer_COMMUNITY_QUESTIONS=
FR-Designer_SimpleCross_Report=
FR-Designer_COMMUNITY_NEED=
FR-Designer_Delete_Template=
FR-Designer_TableData-Default-Para=
FR-Designer_Allow-Blank=
FR-Designer_LocalWidget=
FR-Designer_WidgetOrder=
FR-Designer_Form-Frozen-Tip=
FR-Designer_Mobile-Horizontal=
FR-Designer-Invalid_Page_Number=
FR-Designer_COMMUNITY_BBS=
FR-Designer_COMMUNITY_SIGN=
FR-Designer_COMMUNITY_UPDATE=
FR-Designer_Mobile-Vertical=
FR-Designer_Get-CubeGetting cube=
FR-Designer_COMMUNITY=
FR-Designer_Mobile_Report_Analysis_Annotation=
FR-Designer_Properties_Mobile=
FR-Designer_Button-OK=
FR-Designer_COMMUNITY_BUG=
FR-Designer_AllCategories=
FR-Designer_Mobile-Attr=
FR-Designer_Mobile-Zoom=

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=\u6570\u636E\u5B57\u5178
FR-Designer_Data-confusion=\u6570\u636E\u6DF7\u6DC6
FR-Designer_Data_Type=\u6570\u636E\u7C7B\u578B
FR-Designer_Double_Click_Edit_OR_Clear=\u53CC\u51FB\u8FDB\u884C\u7F16\u8F91\u6216\u6E05\u9664
FR-Designer_Edit_Button_ToolBar=\u7F16\u8F91\u6309\u94AE\u6240\u5728\u5DE5\u5177\u680F
FR-Designer_Email=\u90AE\u4EF6
FR-Designer_Enabled=\u53EF\u7528
FR-Designer_End-Date=\u7ED3\u675F\u65E5\u671F
@ -163,6 +164,7 @@ FR-Designer_Refresh_Parameter_In_SQL=\u662F\u5426\u5237\u65B0SQL\u4E2D\u7684\u53
FR-Designer_Reg_Expressions=\u6B63\u5219\u8868\u8FBE\u5F0F
FR-Designer_Reg_Max_Length=\u6700\u5927\u957F\u5EA6
FR-Designer_Reg_Min_Length=\u6700\u5C0F\u957F\u5EA6
FR-Designer_Remove_Button_ToolBar=\u79FB\u9664\u6309\u94AE\u6240\u5728\u5DE5\u5177\u680F
FR-Designer_ReportColumns-Columns=\u5206\u680F
FR-Designer_Return-Date=\u8FD4\u56DE\u65E5\u671F
FR-Designer_RichText=\u63D2\u5165\u5BCC\u6587\u672C
@ -588,3 +590,15 @@ FR-Designer_Background_Image_Select=\u9009\u62E9\u56FE\u7247
FR-Designer_Initial_Background_Tips=\u6309\u94AE\u7684\u521D\u59CB\u80CC\u666F
FR-Designer_Mouse_Move_Tips=\u9F20\u6807\u79FB\u52A8\u5230\u6309\u94AE\u4E0A\u7684\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F
FR-Designer_Mouse_Click_Tips=\u9F20\u6807\u70B9\u51FB\u6309\u94AE\u65F6\u80CC\u666F\uFF0C\u82E5\u65E0\u5219\u4E0D\u6539\u53D8\u80CC\u666F
FR-Designer-Move_Tab_First=\u79FB\u52A8\u5230\u9996\u4F4D
FR-Designer-Move_Tab_End=\u79FB\u52A8\u5230\u672B\u5C3E
FR-Designer-Move_Tab_Next=\u5F80\u540E\u79FB\u52A8
FR-Designer-Move_Tab_Prev=\u5F80\u524D\u79FB\u52A8
FR-Designer_AxisReversed=\u8F74\u9006\u5E8F
FR-Designer_Logarithmic=\u5BF9\u6570\u523B\u5EA6
FR-Designer_Chart_Log_Base=\u5E95\u6570
FR-Designer_Chart_F_Radar_Axis=\u503C\u8F74
FR-Designer_Too_Large_To_Paste=\u7EC4\u4EF6\u5927\u5C0F\u8D85\u51FA\u8FB9\u754C\uFF0C\u65E0\u6CD5\u7C98\u8D34\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u5904\u65E0\u6CD5\u7C98\u8D34\uFF0C\u5C0F\u4E8E\u7EC4\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01
FR-Designer_Get-CubeGetting cube=

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

@ -91,6 +91,7 @@ FR-Designer_DS-Dictionary=\u8CC7\u6599\u5B57\u5178
FR-Designer_Data-confusion=\u8CC7\u6599\u6DF7\u6DC6
FR-Designer_Data_Type=\u8CC7\u6599\u985E\u578B
FR-Designer_Double_Click_Edit_OR_Clear=\u96D9\u64CA\u9032\u884C\u7DE8\u8F2F\u6216\u6E05\u9664
FR-Designer_Edit_Button_ToolBar=\u7DE8\u8F2F\u6309\u9215\u6240\u5728\u5DE5\u5177\u6B04
FR-Designer_Email=\u90F5\u4EF6
FR-Designer_Enabled=\u53EF\u7528
FR-Designer_End-Date=\u7D50\u675F\u65E5\u671F
@ -162,6 +163,7 @@ FR-Designer_Refresh_Parameter_In_SQL=\u5728SQL\u4E2D\u91CD\u65B0\u6574\u7406\u76
FR-Designer_Reg_Expressions=\u6B63\u5247\u8868\u9054\u5F0F
FR-Designer_Reg_Max_Length=\u6700\u5927\u9577\u5EA6
FR-Designer_Reg_Min_Length=\u6700\u5C0F\u9577\u5EA6
FR-Designer_Remove_Button_ToolBar=\u79FB\u9664\u6309\u9215\u6240\u5728\u5DE5\u5177\u6B04
FR-Designer_ReportColumns-Columns=\u5831\u8868\u6B04\u4F4D
FR-Designer_Return-Date=\u8FD4\u56DE\u65E5\u671F
FR-Designer_RichText= RTF
@ -565,14 +567,38 @@ FR-Designer_Plugin_Should_Update_Please_Contact_Developer=\u633F\u4EF6\u7248\u67
FR-Designer_WidgetOrder=\u63A7\u4EF6\u9806\u5E8F
FR-Designer_Mobile_Form_Analysis_Annotation=\u6CE8\u91CB\uFF1A\u53EF\u4EE5\u901A\u904E\u8A72\u5C6C\u6027\u63A7\u5236\u8868\u55AE\u5728APP\u4E2D\u7684\u89E3\u6790\u65B9\u5F0F\u3002
FR-Designer_Mobile_Report_Analysis_Annotation=\u6CE8\u91CB\uFF1A\u53EF\u4EE5\u901A\u904E\u8A72\u5C6C\u6027\u63A7\u5236\u5831\u8868\u5728APP\u4E2D\u7684\u89E3\u6790\u65B9\u5F0F\uFF0C\u53EA\u652F\u6301\u5206\u9801\u9810\u89BD\uFF0C\u586B\u5831\u9810\u89BD\u6642\u5C6C\u6027\u7121\u6548\u3002
FR-Designer_Background_Null=
FR-Designer_Background_Color=
FR-Designer_Background_Texture=
FR-Designer_Background_Pattern=
FR-Designer_Background_Gradient_Color=
FR-Designer_Background_Image=
FR-Designer_Background_Clear=
FR-Designer_Background_Image_Select=
FR-Designer_Initial_Background_Tips=
FR-Designer_Mouse_Move_Tips=
FR-Designer_Mouse_Click_Tips=
FR-Designer_Background_Null=\u6C92\u6709\u80CC\u666F
FR-Designer_Background_Color=\u984F\u8272
FR-Designer_Background_Texture=\u7D0B\u7406
FR-Designer_Background_Pattern=\u5716\u6848
FR-Designer_Background_Gradient_Color=\u6F38\u8B8A\u8272
FR-Designer_Background_Image=\u5716\u7247
FR-Designer_Background_Clear=\u6E05\u9664
FR-Designer_Background_Image_Select=\u9078\u64C7\u5716\u7247
FR-Designer_Initial_Background_Tips=\u6309\u9215\u7684\u521D\u59CB\u80CC\u666F
FR-Designer_Mouse_Move_Tips=\u6ED1\u9F20\u79FB\u52D5\u5230\u6309\u9215\u4E0A\u7684\u80CC\u666F\uFF0C\u82E5\u7121\u5247\u4E0D\u6539\u8B8A\u80CC\u666F
FR-Designer_Mouse_Click_Tips=\u6ED1\u9F20\u9EDE\u64CA\u6309\u9215\u6642\u80CC\u666F\uFF0C\u82E5\u7121\u5247\u4E0D\u6539\u8B8A\u80CC\u666F
FR-Designer-Move_Tab_First=\u79FB\u52D5\u5230\u9996\u4F4D
FR-Designer-Move_Tab_End=\u79FB\u52D5\u5230\u672B\u5C3E
FR-Designer-Move_Tab_Next=\u5F80\u5F8C\u79FB\u52D5
FR-Designer-Move_Tab_Prev=\u5F80\u524D\u79FB\u52D5
FR-Designer_AxisReversed=\u8EF8\u9006\u5E8F
FR-Designer_Logarithmic=\u5C0D\u6578\u523B\u5EA6
FR-Designer_Chart_Log_Base=\u5E95\u6578
FR-Designer_Chart_F_Radar_Axis=\u503C\u8EF8
FR-Designer_Too_Large_To_Paste=\u7D44\u4EF6\u5927\u5C0F\u8D85\u51FA\u908A\u754C\uFF0C\u7121\u6CD5\u7C98\u8CBC\uFF01
FR-Designer_Too_Small_To_Paste=\u6B64\u8655\u7121\u6CD5\u7C98\u8CBC\uFF0C\u5C0F\u65BC\u7D44\u4EF6\u6700\u5C0F\u9AD8\u5EA6\uFF01
FR-Designer_Download_Template=
FR-Designer-Selected_Widget=
FR-Designer_LocalWidget=
FR-Designer_Get-CubeGetting cube=
FR-Designer_Install_Template=
FR-Designer_Reset=
FR-Designer_SimpleCross_Report=
FR-Designer_Allow-Blank=
FR-Designer_AllCategories=
FR-Designer_SimpleDetail_Report=
FR-Designer_DoubleLayer_Report=
FR-Designer_Delete_Template=
FR-Designer_Validate=

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

54
designer_base/src/com/fr/design/mainframe/JTemplate.java

@ -27,6 +27,8 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.design.mainframe.templateinfo.TemplateProcessInfo;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.NameSeparator;
@ -72,16 +74,27 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
private UndoManager authorityUndoManager;
protected U undoState;
protected U authorityUndoState = null;
protected T template; // 当前模板
protected TemplateProcessInfo processInfo; // 模板过程的相关信息
private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复
private DesignModelAdapter<T, ?> designModel;
private PreviewProvider previewType;
private long openTime = 0L; // 打开模板的时间点(包括新建模板)
private TemplateInfoCollector tic = TemplateInfoCollector.getInstance();
private StringBuilder process = new StringBuilder(""); // 制作模板的过程
public JTemplate(T t, String defaultFileName) {
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)));
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true);
openTime = System.currentTimeMillis();
}
public JTemplate(T t, FILE file) {
this(t, file, false);
}
public JTemplate(T t, FILE file, boolean isNewFile) {
super(t);
this.template = t;
this.previewType = parserPreviewProvider(t.getPreviewType());
this.editingFILE = file;
this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -89,6 +102,39 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
this.add(createCenterPane(), BorderLayout.CENTER);
this.undoState = createUndoState();
designModel = createDesignModel();
// 如果不是新建模板,并且在收集列表中
if (!isNewFile && tic.inList(t)) {
openTime = System.currentTimeMillis();
process.append(tic.loadProcess(t));
}
}
// 为收集模版信息作准备
private void initForCollect() {
template.initTemplateID(); // 为新模板设置 templateID 属性
if (openTime == 0) {
openTime = System.currentTimeMillis();
}
}
private void collectInfo() { // 执行收集操作
if (openTime == 0) { // 旧模板,不收集数据
return;
}
long saveTime = System.currentTimeMillis(); // 保存模板的时间点
tic.collectInfo(template, this, openTime, saveTime);
openTime = saveTime; // 更新 openTime,准备下一次计算
}
public abstract TemplateProcessInfo getProcessInfo();
// 追加过程记录
public void appendProcess(String s) {
process.append(s);
}
// 获取过程记录
public String getProcess() {
return process.toString();
}
public U getUndoState() {
@ -439,6 +485,7 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_No-Privilege") + "!", Inter.getLocText("FR-Designer_Message"), JOptionPane.WARNING_MESSAGE);
return false;
}
collectInfo();
return this.saveFile();
}
@ -482,11 +529,14 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
}
protected boolean saveNewFile(FILE editingFILE, String oldName){
this.editingFILE = editingFILE;
// 在保存之前,初始化 templateID
initForCollect(); // 如果保存新模板(新建模板直接保存,或者另存为),则添加 templateID
this.editingFILE = editingFILE;
boolean result = this.saveFile();
if (result) {
DesignerFrameFileDealerPane.getInstance().refresh();
collectInfo();
}
//更换最近打开
DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldName, this.getFullPathName());

332
designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java

@ -0,0 +1,332 @@
package com.fr.design.mainframe.templateinfo;
import com.fr.base.FRContext;
import com.fr.base.io.IOFile;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.env.RemoteEnv;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.GeneralUtils;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.stable.*;
import org.json.JSONObject;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 做模板的过程和耗时收集辅助类
* Created by plough on 2017/2/21.
*/
public class TemplateInfoCollector<T extends IOFile> implements Serializable {
private static final String FILE_NAME = "tplInfo.ser";
private static TemplateInfoCollector instance;
private HashMap<String, HashMap<String, Object>> templateInfoList;
private String designerOpenDate; //设计器最近一次打开日期
private static final int VALID_CELL_COUNT = 5; // 有效报表模板的格子数
private static final int VALID_WIDGET_COUNT = 5; // 有效报表模板的控件数
private static final int COMPLETE_DAY_COUNT = 15; // 判断模板是否完成的天数
private static final int ONE_THOUSAND = 1000;
static final long serialVersionUID = 2007L;
@SuppressWarnings("unchecked")
private TemplateInfoCollector() {
templateInfoList = new HashMap<>();
setDesignerOpenDate();
}
/**
* 把设计器最近打开日期设定为当前日期
*/
private void setDesignerOpenDate() {
designerOpenDate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
}
/**
* 判断今天是否第一次打开设计器
*/
private boolean designerOpenFirstTime() {
String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
return !ComparatorUtils.equals(today, designerOpenDate);
}
/**
* 获取缓存文件存放路径
*/
private static File getInfoFile() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
}
public static TemplateInfoCollector getInstance() {
if (instance == null) {
// 先尝试从文件读取
try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile()));
instance = (TemplateInfoCollector) is.readObject();
} catch (FileNotFoundException ex) {
// 如果之前没有存储过,则创建新对象
instance = new TemplateInfoCollector();
} catch (InvalidClassException ex) {
// 如果 TemplateInfoCollecor 类结构有改动,则放弃之前收集的数据(下次保存时覆盖)
// 这种情况主要在开发、测试过程中遇到,正式上线后不应该出现
FRLogger.getLogger().info(ex.getMessage());
FRLogger.getLogger().info("use a new instance");
instance = new TemplateInfoCollector();
}
catch (Exception ex) {
FRLogger.getLogger().error(ex.getMessage(), ex);
}
}
return instance;
}
private boolean shouldCollectInfo() {
if (FRContext.getCurrentEnv() instanceof RemoteEnv) { // 远程设计不收集数据
return false;
}
return DesignerEnvManager.getEnvManager().isJoinProductImprove() && FRContext.isChineseEnv();
}
public void appendProcess(String log) {
if (!shouldCollectInfo()) {
return;
}
// 获取当前编辑的模板
JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate();
// 追加过程记录
jt.appendProcess(log);
}
/**
* 加载已经存储的模板过程
*/
@SuppressWarnings("unchecked")
public String loadProcess(T t) {
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfoList.get(t.getTemplateID()).get("processMap");
return (String)processMap.get("process");
}
/**
* 根据模板ID是否在收集列表中判断是否需要收集当前模板的信息
*/
public boolean inList(T t) {
return templateInfoList.containsKey(t.getTemplateID());
}
/**
* 将包含所有信息的对象保存到文件
*/
private void saveInfo() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile()));
String log = "";
int count = 1;
for (String key : templateInfoList.keySet()) {
String createTime = ((HashMap)templateInfoList.get(key).get("consumingMap")).get("create_time").toString();
log += (count + ". id: " + key + " " + createTime + "\n" + templateInfoList.get(key).toString() + "\n");
count ++;
}
FRLogger.getLogger().info("writing tplInfo: \n" + log);
os.writeObject(instance);
os.close();
} catch (Exception ex) {
FRLogger.getLogger().error(ex.getMessage());
}
}
/**
* 更新 day_count打开设计器却未编辑模板的连续日子
*/
private void addDayCount() {
if (designerOpenFirstTime()) {
for (String key : templateInfoList.keySet()) {
HashMap<String, Object> templateInfo = templateInfoList.get(key);
int dayCount = (int)templateInfo.get("day_count") + 1;
templateInfo.put("day_count", dayCount);
}
setDesignerOpenDate();
}
}
/**
* 收集模板信息如果之前没有记录则新增如果已有记录则更新
* 同时将最新数据保存到文件中
*/
@SuppressWarnings("unchecked")
public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) {
if (!shouldCollectInfo()) {
return;
}
HashMap<String, Object> templateInfo;
long timeConsume = ((saveTime - openTime) / ONE_THOUSAND); // 制作模板耗时(单位:s)
String templateID = t.getTemplateID();
if (inList(t)) { // 已有记录
templateInfo = templateInfoList.get(t.getTemplateID());
// 更新 conusmingMap
HashMap<String, Object> consumingMap = (HashMap<String, Object>) templateInfo.get("consumingMap");
timeConsume += (long)consumingMap.get("time_consume"); // 加上之前的累计编辑时间
consumingMap.put("time_consume", timeConsume);
}
else { // 新增
templateInfo = new HashMap<>();
templateInfo.put("consumingMap", getNewConsumingMap(templateID, openTime, timeConsume));
}
// 直接覆盖 processMap
templateInfo.put("processMap", getProcessMap(templateID, jt));
// 保存模板时,让 day_count 归零
templateInfo.put("day_count", 0);
templateInfoList.put(templateID, templateInfo);
saveInfo(); // 每次更新之后,都同步到暂存文件中
}
private HashMap<String, Object> getNewConsumingMap(String templateID, long openTime, long timeConsume) {
HashMap<String, Object> consumingMap = new HashMap<>();
String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
String jarTime = GeneralUtils.readBuildNO();
String version = ProductConstants.VERSION;
consumingMap.put("username", username);
consumingMap.put("uuid", uuid);
consumingMap.put("activitykey", activitykey);
consumingMap.put("templateID", templateID);
consumingMap.put("create_time", createTime);
consumingMap.put("time_consume", timeConsume);
consumingMap.put("jar_time", jarTime);
consumingMap.put("version", version);
return consumingMap;
}
private HashMap<String, Object> getProcessMap(String templateID, JTemplate jt) {
HashMap<String, Object> processMap = new HashMap<>();
processMap.put("templateID", templateID);
processMap.put("process", jt.getProcess());
TemplateProcessInfo info = jt.getProcessInfo();
processMap.put("report_type", info.getReportType());
processMap.put("cell_count", info.getCellCount());
processMap.put("float_count", info.getFloatCount());
processMap.put("block_count", info.getBlockCount());
processMap.put("widget_count", info.getWidgetCount());
return processMap;
}
/**
* 发送本地模板信息到服务器
*/
public void sendTemplateInfo() {
addDayCount();
String consumingUrl = SiteCenter.getInstance().acquireUrlByKind("tempinfo.consuming") + "/single";
String processUrl = SiteCenter.getInstance().acquireUrlByKind("tempinfo.process") + "/single";
ArrayList<HashMap<String, String>> completeTemplatesInfo = getCompleteTemplatesInfo();
for (HashMap<String, String> templateInfo : completeTemplatesInfo) {
String jsonConsumingMap = templateInfo.get("jsonConsumingMap");
String jsonProcessMap = templateInfo.get("jsonProcessMap");
if (sendSingleTemplateInfo(consumingUrl, jsonConsumingMap) && sendSingleTemplateInfo(processUrl, jsonProcessMap)) {
// 清空记录
FRLogger.getLogger().info("successfully send " + templateInfo.get("templateID"));
removeFromTemplateInfoList(templateInfo.get("templateID"));
} else {
FRLogger.getLogger().info("send template info failed, will try next time, " + templateInfo.get("templateID"));
}
}
saveInfo();
}
private boolean sendSingleTemplateInfo(String url, String content) {
HashMap<String, String> para = new HashMap<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
para.put("content", content);
HttpClient httpClient = new HttpClient(url, para, true);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return false;
}
String res = httpClient.getResponseText();
boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
return success;
}
/**
* 返回已完成的模板信息
*/
@SuppressWarnings("unchecked")
private ArrayList<HashMap<String, String>> getCompleteTemplatesInfo() {
ArrayList<HashMap<String, String>> completeTemplatesInfo = new ArrayList<>();
ArrayList<String> testTemplateKeys = new ArrayList<>(); // 保存测试模板的key
for (String key : templateInfoList.keySet()) {
HashMap<String, Object> templateInfo = templateInfoList.get(key);
if ((int)templateInfo.get("day_count") <= COMPLETE_DAY_COUNT) { // 未完成模板
continue;
}
if (isTestTemplate(templateInfo)) {
testTemplateKeys.add(key);
continue;
}
HashMap<String, Object> consumingMap = (HashMap<String, Object>) templateInfo.get("consumingMap");
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfo.get("processMap");
String jsonConsumingMap = new JSONObject(consumingMap).toString();
String jsonProcessMap = new JSONObject(processMap).toString();
HashMap<String, String> jsonTemplateInfo = new HashMap<>();
jsonTemplateInfo.put("jsonConsumingMap", jsonConsumingMap);
jsonTemplateInfo.put("jsonProcessMap", jsonProcessMap);
jsonTemplateInfo.put("templateID", key);
completeTemplatesInfo.add(jsonTemplateInfo);
}
// 删除测试模板
for (String key : testTemplateKeys) {
removeFromTemplateInfoList(key);
}
return completeTemplatesInfo;
}
private void removeFromTemplateInfoList(String key) {
templateInfoList.remove(key);
FRLogger.getLogger().info(key + " is removed...");
}
@SuppressWarnings("unchecked")
private boolean isTestTemplate(HashMap<String, Object> templateInfo) {
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfo.get("processMap");
int reportType = (int)processMap.get("report_type");
int cellCount = (int)processMap.get("cell_count");
int floatCount = (int)processMap.get("float_count");
int blockCount = (int)processMap.get("block_count");
int widgetCount = (int)processMap.get("widget_count");
boolean isTestTemplate = false;
if (reportType == 0) { // 普通报表
isTestTemplate = cellCount <= VALID_CELL_COUNT && floatCount <= 1 && widgetCount <= VALID_WIDGET_COUNT;
} else if (reportType == 1) { // 聚合报表
isTestTemplate = blockCount <= 1 && widgetCount <= VALID_WIDGET_COUNT;
} else { // 表单(reportType == 2)
isTestTemplate = widgetCount <= 1;
}
return isTestTemplate;
}
public static void main(String[] args) {
TemplateInfoCollector tic = TemplateInfoCollector.getInstance();
tic.sendTemplateInfo();
}
}

26
designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessInfo.java

@ -0,0 +1,26 @@
package com.fr.design.mainframe.templateinfo;
import com.fr.base.io.IOFile;
/**
* Created by plough on 2017/3/17.
*/
public abstract class TemplateProcessInfo<T extends IOFile> {
protected T template;
public TemplateProcessInfo(T template) {
this.template = template;
}
// 获取模板类型。0 代表普通报表,1 代表聚合报表,2 代表表单
public abstract int getReportType();
// 获取模板格子数
public abstract int getCellCount();
// 获取模板悬浮元素个数
public abstract int getFloatCount();
// 获取模板聚合块个数
public abstract int getBlockCount();
// 获取模板控件数
public abstract int getWidgetCount();
}

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

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

@ -1,151 +1,154 @@
package com.fr.design.utils;
import com.fr.general.ComparatorUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
/**
* 工具类提供常用的工具方法
*/
public class ComponentUtils {
public static boolean isComponentVisible(Component comp) {
if (!comp.isVisible() && !isRootComponent(comp)) {
return false;
}
Component parent = comp.getParent();
return parent == null || isComponentVisible(parent);
}
/**
* 获取component所在的容器的绝对位置
*/
public static Rectangle getRelativeBounds(Component component) {
Rectangle bounds = new Rectangle(0, 0, component.getWidth(), component.getHeight());
Container parent = component.getParent();
while (parent != null) {
bounds.x += component.getX();
bounds.y += component.getY();
component = parent;
parent = component.getParent();
}
return bounds;
}
/**
* 恢复双缓冲状态dbcomponents保存着初始状态为启动双缓冲的组件
*/
public static void resetBuffer(ArrayList<JComponent> dbcomponents) {
for (JComponent jcomponent : dbcomponents) {
jcomponent.setDoubleBuffered(true);
}
}
/**
* 禁止双缓冲状态并将初始状态为启动双缓冲的组件保存到dbcomponents中
*/
public static void disableBuffer(Component comp, ArrayList<JComponent> dbcomponents) {
if ((comp instanceof JComponent) && comp.isDoubleBuffered()) {
JComponent jcomponent = (JComponent) comp;
dbcomponents.add(jcomponent);
jcomponent.setDoubleBuffered(false);
}
if (comp instanceof Container) {
Container container = (Container) comp;
int count = container.getComponentCount();
if (count > 0) {
for (int i = 0; i < count; i++) {
Component component = container.getComponent(i);
disableBuffer(component, dbcomponents);
}
}
}
}
public static int indexOfComponent(Container container, Component target) {
int count = container.getComponentCount();
for (int i = 0; i < count; i++) {
Component child = container.getComponent(i);
if (child == target) {
return i;
}
}
return -1;
}
/**
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRectRel2Root(Component root) {
Container container = findAncestorScrollPane(root);
if (container == null) {
return getRelativeBounds(root);
} else {
// 如果是JScrollPane的子组件,需要计算其viewport与改组件的交叉的可见区域
return getBoundsRel2Parent(root, container);
}
}
/**
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRect(JComponent root) {
Rectangle root_bounds = ComponentUtils.getRelativeBounds(root);
Rectangle rect = computeVisibleRectRel2Root(root);
rect.x -= root_bounds.x;
rect.y -= root_bounds.y;
return rect;
}
private static Rectangle getBoundsRel2Parent(Component child, Container parent) {
Rectangle cRect = getRelativeBounds(child);
Rectangle pRect = getRelativeBounds(parent);
Rectangle bounds = new Rectangle();
Rectangle2D.intersect(cRect, pRect, bounds);
return bounds;
}
public static Container findAncestorScrollPane(Component p) {
if ((p == null) || !(p instanceof Container)) {
return null;
}
Container c = p.getParent();
return findAncestorScrollPane(c);
}
public static boolean isRootComponent(Component root) {
Container parent = root.getParent();
return parent == null;
}
public static boolean isChildOf(Component component, Class parent) {
Container container = component.getParent();
if (container != null) {
if (ComparatorUtils.equals(container.getClass(), parent)) {
return true;
} else {
return isChildOf(container, parent);
}
}
return false;
}
package com.fr.design.utils;
import com.fr.general.ComparatorUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
/**
* 工具类提供常用的工具方法
*/
public class ComponentUtils {
private ComponentUtils() {
}
public static boolean isComponentVisible(Component comp) {
if (!comp.isVisible() && !isRootComponent(comp)) {
return false;
}
Component parent = comp.getParent();
return parent == null || isComponentVisible(parent);
}
/**
* 获取component所在的容器的绝对位置
*/
public static Rectangle getRelativeBounds(Component component) {
Rectangle bounds = new Rectangle(0, 0, component.getWidth(), component.getHeight());
Container parent = component.getParent();
while (parent != null) {
bounds.x += component.getX();
bounds.y += component.getY();
component = parent;
parent = component.getParent();
}
return bounds;
}
/**
* 恢复双缓冲状态dbcomponents保存着初始状态为启动双缓冲的组件
*/
public static void resetBuffer(ArrayList<JComponent> dbcomponents) {
for (JComponent jcomponent : dbcomponents) {
jcomponent.setDoubleBuffered(true);
}
}
/**
* 禁止双缓冲状态并将初始状态为启动双缓冲的组件保存到dbcomponents中
*/
public static void disableBuffer(Component comp, ArrayList<JComponent> dbcomponents) {
if ((comp instanceof JComponent) && comp.isDoubleBuffered()) {
JComponent jcomponent = (JComponent) comp;
dbcomponents.add(jcomponent);
jcomponent.setDoubleBuffered(false);
}
if (comp instanceof Container) {
Container container = (Container) comp;
int count = container.getComponentCount();
if (count > 0) {
for (int i = 0; i < count; i++) {
Component component = container.getComponent(i);
disableBuffer(component, dbcomponents);
}
}
}
}
public static int indexOfComponent(Container container, Component target) {
int count = container.getComponentCount();
for (int i = 0; i < count; i++) {
Component child = container.getComponent(i);
if (child.equals(target)) {
return i;
}
}
return -1;
}
/**
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRectRel2Root(Component root) {
Container container = findAncestorScrollPane(root);
if (container == null) {
return getRelativeBounds(root);
} else {
// 如果是JScrollPane的子组件,需要计算其viewport与改组件的交叉的可见区域
return getBoundsRel2Parent(root, container);
}
}
/**
* 计算组件root相对于其顶层容器的可见区域
*/
public static Rectangle computeVisibleRect(JComponent root) {
Rectangle rootBounds = ComponentUtils.getRelativeBounds(root);
Rectangle rect = computeVisibleRectRel2Root(root);
rect.x -= rootBounds.x;
rect.y -= rootBounds.y;
return rect;
}
private static Rectangle getBoundsRel2Parent(Component child, Container parent) {
Rectangle cRect = getRelativeBounds(child);
Rectangle pRect = getRelativeBounds(parent);
Rectangle bounds = new Rectangle();
Rectangle2D.intersect(cRect, pRect, bounds);
return bounds;
}
public static Container findAncestorScrollPane(Component p) {
if ((p == null) || !(p instanceof Container)) {
return null;
}
Container c = p.getParent();
return findAncestorScrollPane(c);
}
public static boolean isRootComponent(Component root) {
Container parent = root.getParent();
return parent == null;
}
public static boolean isChildOf(Component component, Class parent) {
Container container = component.getParent();
if (container != null) {
if (ComparatorUtils.equals(container.getClass(), parent)) {
return true;
} else {
return isChildOf(container, parent);
}
}
return false;
}
}

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

59
designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj

@ -0,0 +1,59 @@
package com.fr.aspectj.designerchart;
/**
* Created by plough on 2017/3/3.
*/
import com.fr.chart.chartattr.Chart;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import org.aspectj.lang.reflect.SourceLocation;
import javax.swing.event.ListSelectionEvent;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.Date;
public aspect TemplateProcessTracker {
//声明一个pointcut,匹配你需要的方法
pointcut onMouseClicked(MouseEvent e) :
execution(* mouseClicked(MouseEvent)) && args(e);
pointcut onMousePressed(MouseEvent e) :
execution(* mousePressed(MouseEvent)) && args(e);
pointcut onMouseReleased(MouseEvent e) :
execution(* mouseReleased(MouseEvent)) && args(e);
pointcut onActionPerformed(ActionEvent e) :
execution(* actionPerformed(ActionEvent)) && args(e);
pointcut onChartUpdate(Chart c) :
execution(* update(Chart)) && args(c);
//before表示之前的意思
//这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码
before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(ActionEvent e) : onActionPerformed(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
// !within(LogHandlerBar) 没用, 手动过滤
if (e.getSource().toString().contains("javax.swing.Timer")) {
return;
}
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(Chart c) : onChartUpdate(c) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
//String log = String.format("%s:\n%s\n插入新图表:%s\n\n", new Date(), sl, c.getChartName());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
}

52
designer_chart/src/com/fr/design/chart/axis/MinMaxValuePane.java

@ -42,30 +42,40 @@ public class MinMaxValuePane extends JPanel {
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = { p, f };
double[] rowSize = { p, p, p, p};
Component[][] components = getPanelComponents();
JPanel panel = TableLayoutHelper.createTableLayoutPane(components ,rowSize,columnSize);
Component[][] components = getPanelComponents();
JPanel panel = TableLayoutHelper.createTableLayoutPane(components, getRowSize(p), columnSize);
this.setLayout(new BorderLayout());
this.add(panel,BorderLayout.CENTER);
for(int i = 0; i < components.length; i++) {
((UICheckBox)components[i][0]).addActionListener(new ActionListener() {
this.add(panel, BorderLayout.CENTER);
addComponentListener(components);
}
@Override
public void actionPerformed(ActionEvent e) {
checkBoxUse();
}
});
ChartSwingUtils.addListener((UICheckBox)components[i][0], (UITextField)components[i][1]);
}
protected double[] getRowSize(double p) {
return new double[]{p, p, p, p};
}
protected void addComponentListener(Component[][] components) {
for (int i = 0; i < components.length; i++) {
addListener((UICheckBox) components[i][0]);
ChartSwingUtils.addListener((UICheckBox) components[i][0], (UITextField) components[i][1]);
}
}
protected void addListener(UICheckBox checkBox) {
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkBoxUse();
}
});
}
protected Component[][] getPanelComponents() {
return new Component[][]{
new Component[]{minCheckBox, minValueField},
new Component[]{maxCheckBox, maxValueField},
new Component[]{isCustomMainUnitBox, mainUnitField},
new Component[]{isCustomSecUnitBox, secUnitField},
new Component[]{minCheckBox, minValueField},
new Component[]{maxCheckBox, maxValueField},
new Component[]{isCustomMainUnitBox, mainUnitField},
new Component[]{isCustomSecUnitBox, secUnitField},
};
}
@ -100,7 +110,7 @@ public class MinMaxValuePane extends JPanel {
if(axis.getMinValue() != null) {
minValueField.setText(axis.getMinValue().toString());
}
}
}
// 最大值
if (axis.isCustomMaxValue()) {
@ -108,7 +118,7 @@ public class MinMaxValuePane extends JPanel {
if(axis.getMaxValue() != null) {
maxValueField.setText(axis.getMaxValue().toString());
}
}
}
// 主次刻度单位
if (axis.isCustomMainUnit()) {
@ -116,7 +126,7 @@ public class MinMaxValuePane extends JPanel {
if(axis.getMainUnit() != null) {
mainUnitField.setText(axis.getMainUnit().toString());
}
}
}
if(axis.isCustomSecUnit()) {
isCustomSecUnitBox.setSelected(true);

2
designer_chart/src/com/fr/design/chart/series/SeriesCondition/impl/FormHyperlinkPane.java

@ -95,6 +95,8 @@ public class FormHyperlinkPane extends BasicBeanPane<FormHyperlinkProvider> {
parameterList.toArray(parameters);
formHyperlink.setParameters(parameters);
} else {
formHyperlink.setParameters(null);
}
}

20
designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java

@ -33,7 +33,7 @@ import java.util.List;
* @version 创建时间2012-12-26 上午10:56:51
*/
public class ChartTypePane extends AbstractChartAttrPane{
private ComboBoxPane chartTypePane;
private ComboBoxPane chartTypeComBox;
private ChartTypeButtonPane buttonPane;
private ChartEditPane editPane;
private ChartCollection editingCollection;
@ -72,13 +72,13 @@ public class ChartTypePane extends AbstractChartAttrPane{
if (editingCollection != null) {
relayoutChartTypePane(editingCollection);
}else {
chartTypePane = new ComboBoxPane();
chartTypeComBox = new ComboBoxPane();
}
BasicScrollPane scrollPane = new BasicScrollPane() {
@Override
protected JPanel createContentPane() {
return chartTypePane;
return chartTypeComBox;
}
@Override
@ -99,7 +99,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
};
content.add(scrollPane, BorderLayout.CENTER);
buttonPane.setEditingChartPane(chartTypePane);
buttonPane.setEditingChartPane(chartTypeComBox);
return content;
}
@ -286,7 +286,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
public void relayoutChartTypePane(ChartCollection collection){
if (needRelayout(collection)) {
chartTypePane.relayout(collection);
chartTypeComBox.relayout(collection);
//设置面板切换状态
updatePaneState(collection);
}
@ -314,7 +314,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
initContentPane();
buttonPane.populateBean(collection);
chartTypePane.populateBean(chart);
chartTypeComBox.populateBean(chart);
this.initAllListeners();
}
@ -326,7 +326,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
editingCollection = collection;
buttonPane.update(collection);// 内部操作时 已经做过处理.
Chart chart = collection.getSelectedChart();
chartTypePane.updateBean(chart);
chartTypeComBox.updateBean(chart);
}
/**
@ -334,7 +334,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
* @return 类型界面
*/
public FurtherBasicBeanPane[] getPaneList(){
return chartTypePane.getCards().toArray(new FurtherBasicBeanPane[0]);
return chartTypeComBox.getCards().toArray(new FurtherBasicBeanPane[0]);
}
/**
@ -342,7 +342,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
* @return 当前选中的图表的index
*/
public int getSelectedIndex(){
return chartTypePane.getSelectedIndex();
return chartTypeComBox.getSelectedIndex();
}
/**
@ -350,7 +350,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
* @return 选中的图标的序号
*/
public int getSelectedChartIndex(){
return chartTypePane.getSelectedIndex();
return chartTypeComBox.getSelectedIndex();
}
/**

13
designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java

@ -23,16 +23,19 @@ import com.fr.design.utils.gui.GUICoreUtils;
public class ChartTextAttrPane extends BasicPane {
private static final long serialVersionUID = 6731679928019436869L;
private static final int FONT_START = 6;
private static final int FONT_END = 72;
protected UIComboBox fontNameComboBox;
protected UIComboBox fontSizeComboBox;
protected UIToggleButton bold;
protected UIToggleButton italic;
protected UIColorButton fontColor;
public static Integer[] Font_Sizes = {new Integer(6), new Integer(8), new Integer(9), new Integer(10), new Integer(11), new Integer(12), new Integer(14), new Integer(16),
new Integer(18), new Integer(20), new Integer(22), new Integer(24), new Integer(26), new Integer(28), new Integer(36), new Integer(48), new Integer(72)};
public static Integer[] Font_Sizes = new Integer[FONT_END-FONT_START+1];
static{
for(int i = FONT_START; i <= FONT_END; i++){
Font_Sizes [i - FONT_START] = new Integer(i);
}
}
public ChartTextAttrPane() {
initComponents();
}

14
designer_chart/src/com/fr/design/mainframe/chart/gui/style/axis/ChartValuePane.java

@ -72,7 +72,7 @@ public class ChartValuePane extends ChartAxisUsePane<Axis>{
axisLineStylePane = new ChartAxisLineStylePane();
zeroPane = aliagnZero4Second();
axisReversed = new UICheckBox(Inter.getLocText("AxisReversed"));
axisReversed = new UICheckBox(Inter.getLocText("FR-Designer_AxisReversed"));
unitCombox = new UIComboBox(ChartConstants.UNIT_I18N_VALUES);
formatPane = new FormatPane();
axisLabelPane = new ChartAxisLabelPane();
@ -151,10 +151,10 @@ public class ChartValuePane extends ChartAxisUsePane<Axis>{
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = { LayoutConstants.CHART_ATTR_TOMARGIN,p,f};
double[] rowSize = {p, p};
double[] rowSize = { p, p};
Component[][] component = new Component[][]{
new Component[]{null,initMinMaxValue(),null},
new Component[]{null, addLogarithmicPane2ValuePane(), addLogText()},
new Component[]{null,initMinMaxValue(),null},
new Component[]{null, addLogarithmicPane2ValuePane(), addLogText()},
};
return TableLayoutHelper.createTableLayoutPane(component, rowSize, columnSize);
}
@ -171,8 +171,8 @@ public class ChartValuePane extends ChartAxisUsePane<Axis>{
// 返回对数相关界面. 百分比 没有此界面.
protected JPanel addLogarithmicPane2ValuePane() {
JPanel labelLogPane = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane();
labelLogPane.add(logBox = new UICheckBox(Inter.getLocText("Logarithmic")+":"));
labelLogPane.add(new UILabel(Inter.getLocText("Chart_Log_Base")));
labelLogPane.add(logBox = new UICheckBox(Inter.getLocText("FR-Designer_Logarithmic")+":"));
labelLogPane.add(new UILabel(Inter.getLocText("FR-Designer_Chart_Log_Base")));
logBaseField = new UITextField(4);
logBaseField.setText("10");
@ -221,7 +221,7 @@ public class ChartValuePane extends ChartAxisUsePane<Axis>{
* @return 返回标题.
*/
public String title4PopupWindow() {
return Inter.getLocText("Chart_F_Radar_Axis");
return Inter.getLocText("FR-Designer_Chart_F_Radar_Axis");
}
@Override

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"]
}
}
}

59
designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj

@ -0,0 +1,59 @@
package com.fr.aspectj.designerform;
/**
* Created by plough on 2017/3/3.
*/
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import org.aspectj.lang.reflect.SourceLocation;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.Date;
public aspect TemplateProcessTracker {
//声明一个pointcut,匹配你需要的方法
pointcut onMouseClicked(MouseEvent e) :
execution(* mouseClicked(MouseEvent)) && args(e);
pointcut onMousePressed(MouseEvent e) :
execution(* mousePressed(MouseEvent)) && args(e);
pointcut onMouseReleased(MouseEvent e) :
execution(* mouseReleased(MouseEvent)) && args(e);
pointcut onActionPerformed(ActionEvent e) :
execution(* actionPerformed(ActionEvent)) && args(e);
pointcut onSetValueAt(Object v, int r, int c) :
execution(* setValueAt(java.lang.Object, int, int)) && args(v, r, c);
//before表示之前的意思
//这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码
before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(ActionEvent e) : onActionPerformed(e) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
// !within(LogHandlerBar) 没用, 手动过滤
if (e.getSource().toString().contains("javax.swing.Timer")) {
return;
}
//String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource());
String log = "";
TemplateInfoCollector.appendProcess(log);
}
//同上
before(Object v, int r, int c) : onSetValueAt(v, r, c) {
SourceLocation sl = thisJoinPoint.getSourceLocation();
//String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c);
String log = "";
TemplateInfoCollector.appendProcess(log);
}
}

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

@ -1,85 +1,94 @@
package com.fr.design.designer.beans;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.creator.XCreator;
/**
* 该接口是LayoutManager的BeanInfo类标准Java平台没有提供布局管理器的BeanInfo类
* 对于界面设计工具来说还需一些特殊的行为
* @since 6.5.3
*/
public interface LayoutAdapter {
/**
* 在添加组件状态时当鼠标移动到某个容器上方时如果该容器有布局管理器则会调用该布局
* 管理适配器的accept来决定当前位置是否可以放置并提供特殊的标识比如红色区域标识
* 如在BorderLayout中如果某个方位已经放置了组件则此时应该返回false标识该区域不可以
* 放置
*@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);
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
boolean addBean(XCreator creator, int x, int y);
/**
* 返回该布局管理适配器的Painter为容器提供放置位置的标识
*/
HoverPainter getPainter();
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
* @param child 组件
*/
void showComponent(XCreator child);
void addNextComponent(XCreator dragged);
/**
* 组件叠放顺序前插入
* @param target 目标组件
* @param added 插入组件
*/
void addBefore(XCreator target, XCreator added);
/**
* 组件叠放顺序后插入
* @param target 目标组件
* @param added 放置组件
*/
void addAfter(XCreator target, XCreator added);
/**
* 能否放置更多组件
* @return 能则返回true
*/
boolean canAcceptMoreComponent();
ConstraintsGroupModel getLayoutConstraints(XCreator creator);
GroupModel getLayoutProperties();
/**
* 删除组件
* @param creator 组件
* @param initWidth 组件之前宽度
* @param initHeight 组件之前高度
*/
void removeBean(XCreator creator, int initWidth, int initHeight);
package com.fr.design.designer.beans;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.creator.XCreator;
/**
* 该接口是LayoutManager的BeanInfo类标准Java平台没有提供布局管理器的BeanInfo类
* 对于界面设计工具来说还需一些特殊的行为
*
* @since 6.5.3
*/
public interface LayoutAdapter {
/**
* 在添加组件状态时当鼠标移动到某个容器上方时如果该容器有布局管理器则会调用该布局
* 管理适配器的accept来决定当前位置是否可以放置并提供特殊的标识比如红色区域标识
* 如在BorderLayout中如果某个方位已经放置了组件则此时应该返回false标识该区域不可以
* 放置
*
* @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);
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
boolean addBean(XCreator creator, int x, int y);
/**
* 返回该布局管理适配器的Painter为容器提供放置位置的标识
*/
HoverPainter getPainter();
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
*
* @param child 组件
*/
void showComponent(XCreator child);
void addNextComponent(XCreator dragged);
/**
* 组件叠放顺序前插入
*
* @param target 目标组件
* @param added 插入组件
*/
void addBefore(XCreator target, XCreator added);
/**
* 组件叠放顺序后插入
*
* @param target 目标组件
* @param added 放置组件
*/
void addAfter(XCreator target, XCreator added);
/**
* 能否放置更多组件
*
* @return 能则返回true
*/
boolean canAcceptMoreComponent();
ConstraintsGroupModel getLayoutConstraints(XCreator creator);
GroupModel getLayoutProperties();
/**
* 删除组件
*
* @param creator 组件
* @param initWidth 组件之前宽度
* @param initHeight 组件之前高度
*/
void removeBean(XCreator creator, int initWidth, int initHeight);
}

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

@ -1,31 +1,30 @@
package com.fr.design.designer.beans.actions;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import com.fr.base.BaseUtils;
import com.fr.general.Inter;
import com.fr.design.mainframe.FormDesigner;
public class CopyAction extends FormEditAction {
public CopyAction(FormDesigner t) {
super(t);
this.setName(Inter.getLocText("M_Edit-Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
}
@Override
public boolean executeActionReturnUndoRecordNeeded() {
FormDesigner tc = getEditingComponent();
if (tc != null) {
tc.copy();
}
return false;
}
package com.fr.design.designer.beans.actions;
import com.fr.base.BaseUtils;
import com.fr.design.mainframe.FormDesigner;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class CopyAction extends FormEditAction {
public CopyAction(FormDesigner t) {
super(t);
this.setName(Inter.getLocText("M_Edit-Copy"));
this.setMnemonic('C');
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/copy.png"));
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
}
@Override
public boolean executeActionReturnUndoRecordNeeded() {
FormDesigner tc = getEditingComponent();
if (tc != null) {
tc.copy();
}
return false;
}
}

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

@ -1,174 +1,189 @@
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;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.painters.NullPainter;
import com.fr.design.designer.creator.XCreator;
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;
public abstract class AbstractLayoutAdapter implements LayoutAdapter {
protected XLayoutContainer container;
protected LayoutManager layout;
public AbstractLayoutAdapter(XLayoutContainer container) {
this.container = container;
this.layout = container.getLayout();
}
/**
* 是否使用控件备份大小
* @param xCreator 控件
* @return 所在容器相同且支持备份的话返回true
*/
public boolean whetherUseBackupSize(XCreator xCreator) {
Class clazz = container.getClass();
Class bkClazz = null;
if(xCreator.getBackupParent() != null) {
bkClazz = xCreator.getBackupParent().getClass();
}
return ComparatorUtils.equals(bkClazz, clazz)
&& supportBackupSize();
}
/**
* 是否支持用备份大小
* @return
*/
public boolean supportBackupSize() {
return false;
}
/**
* 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适如果不合适就需要重新fix一下
* @param creator 组件
*/
public void fix(XCreator creator) {
}
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
* @param child 组件
*/
@Override
public void showComponent(XCreator child) {
child.setVisible(true);
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
if (!accept(creator, x, y)) {
return false;
}
addComp(creator, x, y);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
/**
* 删除组件
* @param creator 组件
* @param initWidth 组件之前宽度
* @param initHeight 组件之前高度
*/
public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) {
delete(creator, creatorWidth, creatorHeight);
}
protected void delete(XCreator creator, int creatorWidth, int creatorHeight) {
}
protected abstract void addComp(XCreator creator, int x, int y);
/**
* 增加下一个组件
* @param dragged 组件
*/
@Override
public void addNextComponent(XCreator dragged) {
container.add(dragged);
LayoutUtils.layoutRootContainer(container);
}
/**
* 目标控件位置插入组件
* @param target 目标
* @param added 增加组件
*/
@Override
public void addBefore(XCreator target, XCreator added) {
int index = ComponentUtils.indexOfComponent(container, target);
if (index == -1) {
container.add(added, 0);
} else {
container.add(added, index);
}
LayoutUtils.layoutRootContainer(container);
}
/**
* 插在目标组件后面
* @param target 目标
* @param added 增加组件
*/
@Override
public void addAfter(XCreator target, XCreator added) {
int index = ComponentUtils.indexOfComponent(container, target);
if (index == -1) {
container.add(added);
} else {
index++;
if (index >= container.getComponentCount()) {
container.add(added);
} else {
container.add(added, index);
}
}
LayoutUtils.layoutRootContainer(container);
}
@Override
public HoverPainter getPainter() {
return new NullPainter(container);
}
/**
* 是否能接收更多的组件
* @return 能则返回true
*/
@Override
public boolean canAcceptMoreComponent() {
return true;
}
@Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
return null;
}
@Override
public GroupModel getLayoutProperties() {
return null;
}
package com.fr.design.designer.beans.adapters.layout;
import com.fr.design.beans.GroupModel;
import com.fr.design.designer.beans.ConstraintsGroupModel;
import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.painters.NullPainter;
import com.fr.design.designer.creator.XCreator;
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 {
protected XLayoutContainer container;
protected LayoutManager layout;
public AbstractLayoutAdapter(XLayoutContainer container) {
this.container = container;
this.layout = container.getLayout();
}
/**
* 是否使用控件备份大小
*
* @param xCreator 控件
* @return 所在容器相同且支持备份的话返回true
*/
public boolean whetherUseBackupSize(XCreator xCreator) {
Class clazz = container.getClass();
Class bkClazz = null;
if (xCreator.getBackupParent() != null) {
bkClazz = xCreator.getBackupParent().getClass();
}
return ComparatorUtils.equals(bkClazz, clazz)
&& supportBackupSize();
}
/**
* 是否支持用备份大小
*
* @return
*/
public boolean supportBackupSize() {
return false;
}
/**
* 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适如果不合适就需要重新fix一下
*
* @param creator 组件
*/
public void fix(XCreator creator) {
}
/**
* 显示parent的字组件child解决CardLayout中显示某个非显示组件的特殊情况
*
* @param child 组件
*/
@Override
public void showComponent(XCreator child) {
child.setVisible(true);
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
if (!accept(creator, x, y)) {
return false;
}
addComp(creator, x, y);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
/**
* 删除组件
*
* @param creator 组件
* @param creatorWidth
* @param creatorHeight
*/
public void removeBean(XCreator creator, int creatorWidth, int creatorHeight) {
delete(creator, creatorWidth, creatorHeight);
}
protected void delete(XCreator creator, int creatorWidth, int creatorHeight) {
}
protected abstract void addComp(XCreator creator, int x, int y);
/**
* 增加下一个组件
*
* @param dragged 组件
*/
@Override
public void addNextComponent(XCreator dragged) {
container.add(dragged);
LayoutUtils.layoutRootContainer(container);
}
/**
* 目标控件位置插入组件
*
* @param target 目标
* @param added 增加组件
*/
@Override
public void addBefore(XCreator target, XCreator added) {
int index = ComponentUtils.indexOfComponent(container, target);
if (index == -1) {
container.add(added, 0);
} else {
container.add(added, index);
}
LayoutUtils.layoutRootContainer(container);
}
/**
* 插在目标组件后面
*
* @param target 目标
* @param added 增加组件
*/
@Override
public void addAfter(XCreator target, XCreator added) {
int index = ComponentUtils.indexOfComponent(container, target);
if (index == -1) {
container.add(added);
} else {
index++;
if (index >= container.getComponentCount()) {
container.add(added);
} else {
container.add(added, index);
}
}
LayoutUtils.layoutRootContainer(container);
}
@Override
public HoverPainter getPainter() {
return new NullPainter(container);
}
/**
* 是否能接收更多的组件
*
* @return 能则返回true
*/
@Override
public boolean canAcceptMoreComponent() {
return true;
}
@Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
return null;
}
@Override
public GroupModel getLayoutProperties() {
return null;
}
public XLayoutContainer getContainer() {
return this.container;
}
}

542
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,346 +7,340 @@ 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.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
import com.fr.general.FRLogger;
import java.awt.*;
public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter {
//是不是添加到父容器上
private boolean isAdd2ParentLayout = false;
private HoverPainter painter;
//是不是添加到父容器上
private boolean isAdd2ParentLayout = false;
private HoverPainter painter;
public FRAbsoluteLayoutAdapter(XLayoutContainer container) {
super(container);
painter = new FRAbsoluteLayoutPainter(container);
initMinSize();
painter = new FRAbsoluteLayoutPainter(container);
initMinSize();
}
private void initMinSize() {
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
minWidth = layout.getActualMinWidth();
minHeight = layout.getActualMinHeight();
actualVal = layout.getAcualInterval();
margin = layout.toData().getMargin();
}
private void initMinSize() {
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
minWidth = layout.getActualMinWidth();
minHeight = layout.getActualMinHeight();
actualVal = layout.getAcualInterval();
margin = layout.toData().getMargin();
}
@Override
public HoverPainter getPainter() {
return painter;
}
@Override
public HoverPainter getPainter() {
return painter;
}
/**
* 是否能在指定位置添加组件
*
* @param creator 组件
* @param x 坐标x
* @param y 坐标y
* @param x 坐标x
* @param y 坐标y
* @return 能则返回true
*/
//这个地方的逻辑非常复杂,
// 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围,
// 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套)
// 3.当前绝对布局可编辑,那么控件添加
//这个地方的逻辑非常复杂,
// 1.当前绝对布局是不可编辑且是最外层,那么其他控件添加在它周围,
// 2.当前绝对布局是不可编辑且不是最外层,那么控件不可添加,(嵌套)
// 3.当前绝对布局可编辑,那么控件添加
@Override
public boolean accept(XCreator creator, int x, int y) {
Component comp = container.getComponentAt(x, y);
//布局控件要先判断是不是可编辑
//可以编辑,按原有逻辑判断
//不可编辑,当成一整个控件处理
if (comp == null){
return false;
}
//参数面板内的组件不允许拖往绝对布局中
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()){
return false;
}
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator)comp).getTopLayout();
if(topLayout != null){
if (topLayout.isEditable()){
return topLayoutAccept(creator, x, y, topLayout);
}
//绝对布局嵌套,处于内层,不可编辑,不添加,topLayout只能获取到最外层可编辑的布局
else if (((XLayoutContainer)topLayout.getParent()).acceptType(XWAbsoluteLayout.class)) {
return false;
}
else {
return acceptWidget(creator, x, y);
}
}
else{
FRLogger.getLogger().error("top layout is null!");
}
return false;
}
public boolean accept(XCreator creator, int x, int y) {
Component comp = container.getComponentAt(x, y);
//布局控件要先判断是不是可编辑
//可以编辑,按原有逻辑判断
//不可编辑,当成一整个控件处理
if (comp == null) {
return false;
}
//参数面板内的组件不允许拖往绝对布局中
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()) {
return false;
}
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)) {
return false;
} else {
return acceptWidget(x, y);
}
} else {
FRLogger.getLogger().error("top layout is null!");
}
//toplayout假如可以编辑的话就往里面添加组件
private boolean topLayoutAccept(XCreator creator, int x, int y, XLayoutContainer topLayout) {
//判断有没有和当前控件重叠
//先计算当前控件的位置
int creatorX, creatorY;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
return false;
}
//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()) {
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()
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight()
&& creator.getWidth() <= container.getWidth();
}
}
/**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
* @param parentComp 鼠标所在区域的组件
* @param x 坐标x
* @param y 坐标y
* @return 是则返回true
*/
public boolean isTrisectionArea(Component parentComp, int x, int y) {
XCreator creator = (XCreator)parentComp;
trisectAreaDirect = 0;
if (container.getComponentCount()<=1) {
return false;
}
int maxWidth = parentComp.getWidth();
int maxHeight = parentComp.getHeight();
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 ) {
// 在组件上侧三等分
trisectAreaDirect = COMP_TOP;
} else if(y>yL+maxHeight-minRangeHeight) {
// 在组件下侧三等分
trisectAreaDirect = COMP_BOTTOM;
} else if (x<xL+minRangeWidth) {
// 在组件左侧三等分
trisectAreaDirect = COMP_LEFT;
} else if(x>xL+maxWidth-minRangeWidth) {
// 在组件右侧三等分
trisectAreaDirect = COMP_RIGHT;
}
// tab布局的边界特殊处理,不进行三等分
if(!creator.getTargetChildrenList().isEmpty()){
return false;
}
/**
* 判断是否鼠标在组件的三等分区域如果组件在布局管理器中间上下左右都可能会三等分
*
* @param parentComp 鼠标所在区域的组件
* @param x 坐标x
* @param y 坐标y
* @return 是则返回true
*/
public boolean isTrisectionArea(Component parentComp, int x, int y) {
XCreator creator = (XCreator) parentComp;
trisectAreaDirect = 0;
if (container.getComponentCount() <= 1) {
return false;
}
int maxWidth = parentComp.getWidth();
int maxHeight = parentComp.getHeight();
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) {
// 在组件上侧三等分
trisectAreaDirect = COMP_TOP;
} else if (y > yL + maxHeight - minRangeHeight) {
// 在组件下侧三等分
trisectAreaDirect = COMP_BOTTOM;
} else if (x < xL + minRangeWidth) {
// 在组件左侧三等分
trisectAreaDirect = COMP_LEFT;
} else if (x > xL + maxWidth - minRangeWidth) {
// 在组件右侧三等分
trisectAreaDirect = COMP_RIGHT;
}
// tab布局的边界特殊处理,不进行三等分
if (!creator.getTargetChildrenList().isEmpty()) {
return false;
}
return !ComparatorUtils.equals(trisectAreaDirect, 0);
}
return !ComparatorUtils.equals(trisectAreaDirect, 0);
}
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(XCreator creator, int x, int y){
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
boolean isMatchEdge = false;
//如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;
isAdd2ParentLayout = true;
//当前绝对布局不可编辑,就当成一个控件,组件添加在周围
private boolean acceptWidget(int x, int y) {
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
//如果当前处于边缘地带, 那么就把他贴到父容器上
XLayoutContainer parent = container.findNearestFit();
container = parent != null ? parent : container;
isAdd2ParentLayout = true;
int componentHeight = comp.getHeight();
int componentWidth = comp.getWidth();
//上半部分高度
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY();
//下半部分高度
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
int componentHeight = comp.getHeight();
int componentWidth = comp.getWidth();
//上半部分高度
int upHeight = (int) (componentHeight * TOP_HALF) + comp.getY();
//下半部分高度
int downHeight = (int) (componentHeight * BOTTOM_HALF) + comp.getY();
if (isCrossPointArea(comp, x, y)) {
return canAcceptWhileCrossPoint(comp, x, y);
}
if (isCrossPointArea(comp, x, y)) {
return canAcceptWhileCrossPoint(comp, x, y);
}
if (isTrisectionArea(comp, x, y)) {
return canAcceptWhileTrisection(comp, x, y);
}
if (isTrisectionArea(comp, x, y)) {
return canAcceptWhileTrisection(comp, x, y);
}
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
return y > upHeight && y < downHeight ? horizonValid : verticalValid;
}
boolean horizonValid = componentWidth >= minWidth * 2 + actualVal;
boolean verticalValid = componentHeight >= minHeight * 2 + actualVal;
return y > upHeight && y < downHeight ? horizonValid : verticalValid;
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
Rectangle rect = ComponentUtils.getRelativeBounds(container);
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
Rectangle rect = ComponentUtils.getRelativeBounds(container);
int posX = x + rect.x;
int posY = y + rect.y;
if (!accept(creator, x, y)) {
return false;
}
addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
int posX = x + rect.x;
int posY = y + rect.y;
if (!accept(creator, x, y)) {
return false;
}
addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
@Override
protected void addComp(XCreator creator, int x, int y) {
if(!isAdd2ParentLayout) {
Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x;
y = y - r.y;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
@Override
protected void addComp(XCreator creator, int x, int y) {
if (!isAdd2ParentLayout) {
Rectangle r = ComponentUtils.getRelativeBounds(container);
x = x - r.x;
y = y - r.y;
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) {
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
x = creatorRectangle.x - r.x;
y = creatorRectangle.y - r.y;
} else {
int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2;
x = x - w;
y = y - h;
}
fix(creator, x, y);
Rectangle creatorRectangle = ComponentUtils.getRelativeBounds(creator);
x = creatorRectangle.x - r.x;
y = creatorRectangle.y - r.y;
} else {
int w = creator.getWidth() / 2;
int h = creator.getHeight() / 2;
x = x - w;
y = y - h;
}
fix(creator, x, y);
if (creator.hasTitleStyle()) {
addParentCreator(creator);
} else {
container.add(creator, creator.toData().getWidgetName());
}
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator);
updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container);
}else{
fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator);
} else {
container.add(creator, creator.toData().getWidgetName());
}
XWFitLayout layout = (XWFitLayout) container;
// 更新对应的BoundsWidget
layout.updateBoundsWidget();
updateCreatorBackBound();
}
}
if (creator.hasTitleStyle()) {
addParentCreator(creator);
} else {
container.add(creator, creator.toData().getWidgetName(),0);
}
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator);
updateCreatorBackBound();
LayoutUtils.layoutRootContainer(container);
} else {
fixAbsolute(creator, x, y);
if (creator.shouldScaleCreator() || creator.hasTitleStyle()) {
addParentCreator(creator);
} else {
container.add(creator, creator.toData().getWidgetName(),0);
}
XWFitLayout layout = (XWFitLayout) container;
// 更新对应的BoundsWidget
layout.updateBoundsWidget();
updateCreatorBackBound();
}
}
private void updateCreatorBackBound() {
for (int i=0,size=container.getComponentCount(); i<size; i++) {
XCreator creator = (XCreator) container.getComponent(i);
creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds());
}
}
private void updateCreatorBackBound() {
for (int i = 0, size = container.getComponentCount(); i < size; i++) {
XCreator creator = (XCreator) container.getComponent(i);
creator.updateChildBound(minHeight);
creator.setBackupBound(creator.getBounds());
}
}
private void addParentCreator(XCreator child) {
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
container.add(parentPanel, child.toData().getWidgetName());
}
private void addParentCreator(XCreator child) {
XLayoutContainer parentPanel = child.initCreatorWrapper(child.getHeight());
container.add(parentPanel, child.toData().getWidgetName(),0);
}
/**
* 新拖入组件时计算调整其他关联组件位置大小
* @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){
child.setLocation(0, 0);
child.setSize(parentComp.getWidth(), parentComp.getHeight());
} else if(isCrossPointArea(parentComp, x, y)){
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y);
return;
} else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了
fixTrisect(parentComp, child, x, y);
return;
} else{
fixHalve(parentComp, child, x, y);
}
}
/**
* 新拖入组件时计算调整其他关联组件位置大小
*
* @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) {
child.setLocation(0, 0);
child.setSize(parentComp.getWidth(), parentComp.getHeight());
} else if (isCrossPointArea(parentComp, x, y)) {
//交叉区域插入组件时,根据具体位置进行上下或者左右或者相邻三个组件的位置大小插入
fixCrossPointArea(parentComp, child, x, y);
return;
} else if (isTrisectionArea(parentComp, x, y)) {
// 在边界三等分区域,就不再和组件二等分了
fixTrisect(parentComp, child, x, y);
return;
} 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());
public void fix(XCreator creator) {
WAbsoluteLayout wabs = (WAbsoluteLayout) container.toData();
fix(creator, creator.getX(), creator.getY());
wabs.setBounds(creator.toData(), creator.getBounds());
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator);
XWAbsoluteLayout layout = (XWAbsoluteLayout) container;
layout.updateBoundsWidget(creator);
}
/**
* 调整组件大小到合适尺寸位置
*
* @param creator 组件
* @param x 坐标x
* @param y 坐标y
* @param x 坐标x
* @param y 坐标y
*/
public void fix(XCreator creator ,int x, int y) {
int height = creator.getHeight();
int width = creator.getWidth();
if (x < 0) {
width += x;
x = 0;
} else if (x + creator.getWidth() > container.getWidth()) {
width = container.getWidth() - x;
}
public void fix(XCreator creator, int x, int y) {
int height = creator.getHeight();
int width = creator.getWidth();
if (x < 0) {
x = container.getX();
} else if (x + creator.getWidth() > container.getWidth()) {
x = container.getWidth() - width;
}
if (y < 0) {
height += y;
y = 0;
} else if (y + creator.getHeight() > container.getHeight()) {
height = container.getHeight() - y;
}
if (y < 0) {
y = container.getY();
} else if (y + creator.getHeight() > container.getHeight()) {
y = container.getHeight() - height;
}
creator.setBounds(x, y, width, height);
creator.setBounds(x, y, width, height);
}
@Override
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) {
return new BoundsGroupModel((XWAbsoluteLayout)container, creator);
return new BoundsGroupModel((XWAbsoluteLayout) container, creator);
}
@Override
public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
}
@Override
public GroupModel getLayoutProperties() {
XWAbsoluteLayout xwAbsoluteLayout = (XWAbsoluteLayout) container;
return new FRAbsoluteLayoutPropertiesGroupModel(xwAbsoluteLayout);
}
}

26
designer_form/src/com/fr/design/designer/beans/adapters/layout/FRBodyLayoutAdapter.java

@ -640,11 +640,7 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter {
* 又通过ComponentUtils.getRelativeBounds()方法获取到了绝对坐标
* 再次计算相对坐标所以将y值重新变成绝对坐标
* */
if (currentCreator.getBackupParent().getLocation().y == WBorderLayout.DEFAULT_SIZE) {
y = y + WCardMainBorderLayout.TAB_HEIGHT + WBorderLayout.DEFAULT_SIZE;
} else {
y = y + WCardMainBorderLayout.TAB_HEIGHT;
}
y = y + WCardMainBorderLayout.TAB_HEIGHT + this.getParaEditorYOffset();
int tempX = x - rect.x;
int tempY = y - rect.y;
int containerX = container.getX();
@ -675,6 +671,26 @@ public class FRBodyLayoutAdapter extends AbstractLayoutAdapter {
return position;
}
/**
* 获取因为参数面板导致的Y坐标偏移
*
* @return 参数面板导致的Y坐标偏移
*/
protected int getParaEditorYOffset() {
int offset = 0;
if (container.getParent() != null) {
Component components[] = container.getParent().getComponents();
for (Component component : components) {
if (component instanceof XWParameterLayout) {
offset = component.getY() + component.getHeight();
break;
}
}
}
return offset;
}
/**
* 组件交叉区域进行插入时调整受到变动的其他组件,之前是交叉区域插入也按照三等分逻辑后面测试中发现有bug改为和bi一样的鼠标所在侧平分
* 默认左上角右下角区域是垂直方向插入组件

75
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.general.ComparatorUtils;
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget;
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;
}
/**
* 构造函数
*
@ -134,7 +133,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
isFindRelatedComps = false;
//拖入组件判断时,先判断是否为交叉点区域,其次三等分区域,再次平分区域
Component comp = container.getComponentAt(x, y);
if (checkInterval(comp)) {
if (comp == null || checkInterval(comp)) {
return false;
}
//如果当前处于边缘地带, 那么就把他贴到父容器上
@ -269,25 +268,14 @@ 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();
}
private Rectangle adjustBackupBound(Rectangle backupBound, XWCardMainBorderLayout mainLayout) {
// 参数界面高度对纵坐标产生的影响
JForm jform = (JForm) (HistoryTemplateListPane.getInstance().getCurrentEditingTemplate());
if (jform.getFormDesign().getParaComponent() != null) {
backupBound.y -= jform.getFormDesign().getParaHeight();
}
// zhouping: REPORT-2334 表单tab布局中图表放大缩小会明显
// 这边不需要单独处理参数面板高度了,下面的方法中获取的是XWCardMainBorderLayout相对坐标
Rectangle rec = getLayoutBound(mainLayout);
// XWTabLayout里面的横纵坐标收到外层XWCardMainBorderLayout的横纵坐标影响
// 减掉之后可以按照它原来的逻辑执行
@ -353,13 +341,13 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
* 拖拽控件边框后根据控件的大小尺寸进行相关组件的调整
*
* @param backupBound 边界备份
* @param bounds 组件边界
* @param xCreator 组件
* @param row 选中的行
* @param difference 偏移量
* @param bounds 组件边界
* @param xCreator 组件
* @param row 选中的行
* @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 +358,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 +412,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 +428,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 +546,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 +662,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 +744,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 +1056,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 +1096,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸控件左边框时 调整左侧的组件位置大小
*/
protected boolean CalculateLefttRelatComponent(int objWidth) {
protected boolean calculateLefttRelatComponent(int objWidth) {
if (isBeyondAdjustWidthScope(objWidth)) {
return false;
}
@ -1127,7 +1114,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 +1154,7 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter {
/**
* 删除或拉伸上边框 调整上方的组件位置大小
*/
protected boolean CalculateUpRelatComponent(int objHeight) {
protected boolean calculateUpRelatComponent(int objHeight) {
if (isBeyondAdjustHeightScope(objHeight)) {
return false;
}

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

@ -1,108 +1,105 @@
/**
*
*/
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;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils;
import java.awt.*;
/**
* tab布局tabFit适配器
*
* @author focus
* @date 2014-6-24
*/
public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
//标题栏高度对tab布局内部组件的y坐标造成了偏移
private static int TAB_HEIGHT = 40;
/**
* 构造函数
*
* @param container XWTabFitLayout容器
*/
public FRTabFitLayoutAdapter(XLayoutContainer container) {
super(container);
}
/**
* 返回布局自身属性方便一些特有设置在layout刷新时处理
*/
@Override
public GroupModel getLayoutProperties() {
XWTabFitLayout xfl = (XWTabFitLayout) container;
return new FRTabFitLayoutPropertiesGroupModel(xfl);
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
// 经过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布局的边缘,则需要把新组件添加到
// 父层自适应布局中,这时候的添加位置就是tab布局所在的位置
if (this.intersectsEdge(posX, posY, backUpContainer)) {
if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) {
XWTabFitLayout tabLayout = (XWTabFitLayout) backUpContainer;
y = adjustY(y, tabLayout);
}
addComp(creator, x, y);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
// 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置
addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
// tab布局的纵坐标受到tab高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界,
// 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度减掉
//将y值变为相对坐标以实现获取到鼠标drop位置的控件
//TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了
private int adjustY(int y, XWTabFitLayout tabLayout) {
XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent();
LayoutBorderStyle style = cardLayout.toData().getBorderStyle();
if (container.getLocation().y == WBorderLayout.DEFAULT_SIZE) {
y = y - WBorderLayout.DEFAULT_SIZE;
}
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) {
y = y - WCardMainBorderLayout.TAB_HEIGHT;
}
return y;
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return ComponentUtils.getRelativeBounds(mainLayout);
}
/**
*
*/
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;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.designer.properties.FRTabFitLayoutPropertiesGroupModel;
import com.fr.design.mainframe.widget.editors.ParameterEditor;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.LayoutBorderStyle;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.general.ComparatorUtils;
import java.awt.*;
/**
* tab布局tabFit适配器
*
* @author focus
* @date 2014-6-24
*/
public class FRTabFitLayoutAdapter extends FRFitLayoutAdapter {
/**
* 构造函数
*
* @param container XWTabFitLayout容器
*/
public FRTabFitLayoutAdapter(XLayoutContainer container) {
super(container);
}
/**
* 返回布局自身属性方便一些特有设置在layout刷新时处理
*/
@Override
public GroupModel getLayoutProperties() {
XWTabFitLayout xfl = (XWTabFitLayout) container;
return new FRTabFitLayoutPropertiesGroupModel(xfl);
}
/**
* 组件的ComponentAdapter在添加组件时如果发现布局管理器不为空会继而调用该布局管理器的
* addComp方法来完成组件的具体添加在该方法内布局管理器可以提供额外的功能
*
* @param creator 被添加的新组件
* @param x 添加的位置x该位置是相对于container的
* @param y 添加的位置y该位置是相对于container的
* @return 是否添加成功成功返回true否则false
*/
@Override
public boolean addBean(XCreator creator, int x, int y) {
// 经过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布局的边缘,则需要把新组件添加到l
// 父层自适应布局中,这时候的添加位置就是tab布局所在的位置
if (this.intersectsEdge(posX, posY, backUpContainer)) {
if (!ComparatorUtils.equals(backUpContainer.getOuterLayout(), backUpContainer.getBackupParent())) {
XWTabFitLayout tabLayout = (XWTabFitLayout) backUpContainer;
y = adjustY(y, tabLayout);
}
addComp(creator, x, y);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
// 如果不在边缘,容器为本自适应布局,增加组件的位置就是相对于容器的位置
addComp(creator, posX, posY);
((XWidgetCreator) creator).recalculateChildrenSize();
return true;
}
// tab布局的纵坐标受到tab高度以及参数面板高度的影响,判断的上边界取得是里面XWTabFitLayout的上边界,
// 实际计算的时候的纵坐标用了外层的CardMainBorerLayout,需要将tab高度和参数面板高度减掉
// 将y值变为相对坐标以实现获取到鼠标drop位置的控件
// TODO 可以直接在这边将x,y都变成相对坐标,这样在后面判断拖进来的新控件放置方式的时候就不用再判断了
private int adjustY(int y, XWTabFitLayout tabLayout) {
XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent();
LayoutBorderStyle style = cardLayout.toData().getBorderStyle();
y = y - this.getParaEditorYOffset();
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) {
y = y - WCardMainBorderLayout.TAB_HEIGHT;
}
return y;
}
protected Rectangle getLayoutBound(XWCardMainBorderLayout mainLayout) {
return ComponentUtils.getRelativeBounds(mainLayout);
}
}

333
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.container.WAbsoluteLayout.BoundsWidget;
import java.awt.*;
/**
* @author richer
* @since 6.5.3
@ -26,197 +24,184 @@ public abstract class AccessDirection implements Direction {
private int ymin;
private int xmin;
abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer,
Rectangle oldbounds);
protected int[] sorption(int x, int y,Rectangle current_bounds, FormDesigner designer) {
// 自适应布局不需要吸附线,但需要对齐线,对齐线后面处理
if (!designer.hasWAbsoluteLayout()) {
designer.getStateModel().setEquidistantLine(null);
designer.getStateModel().setXAbsorptionline(null);
designer.getStateModel().setYAbsorptionline(null);
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 };
}
}
protected Point getRelativePoint(int x, int y, Rectangle current_bounds,FormDesigner designer) {
if (x < 0) {
x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
x = designer.getRootComponent().getWidth();
}
abstract int getCursor();
protected abstract Rectangle getDraggedBounds(int dx, int dy, Rectangle currentBounds, FormDesigner designer,
Rectangle oldBounds);
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};
} else {
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 currentBounds, FormDesigner designer) {
if (x < 0) {
x = 0;
} else if (x > designer.getRootComponent().getWidth() && designer.getSelectionModel().hasSelectionComponent()) {
x = designer.getRootComponent().getWidth();
}
//参数面板可以无下限拉长
if (y < 0) {
y = 0;
} else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent()
if (y < 0) {
y = 0;
} else if (y > designer.getRootComponent().getHeight() + designer.getParaHeight() && designer.getSelectionModel().hasSelectionComponent()
&& !designer.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWParameterLayout.class)) {
y = designer.getRootComponent().getHeight() + designer.getParaHeight();
}
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);
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())) {
continue;
}
Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection);
if (!findInX) {
int x1 = bounds.x;
if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x1;
findInX = true;
}
int x2 = bounds.x + bounds.width;
if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x2;
findInX = true;
}
}
if (!findInY) {
int y1 = bounds.y;
if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y1;
findInY = true;
}
int y2 = bounds.y + bounds.height;
if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y2;
findInY = true;
}
}
if (findInX && findInY) {
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);
}
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);
designer.getStateModel().setEquidistantLine(null);
}
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) {
return relativeRec;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
relativeRec.x += rec.x;
relativeRec.y += rec.y;
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){
y = designer.getRootComponent().getHeight() + designer.getParaHeight();
}
return new Point(x, y);
}
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();
for (int i = 0, count = layout.getWidgetCount(); i < count; i++) {
BoundsWidget temp = (BoundsWidget) layout.getWidget(i);
if (!temp.isVisible() || selection.contains(temp.getWidget())) {
continue;
}
Rectangle bounds = getWidgetRelativeBounds(temp.getBounds(), selection);
if (!findInX) {
int x1 = bounds.x;
if (Math.abs(x1 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x1;
findInX = true;
}
int x2 = bounds.x + bounds.width;
if (Math.abs(x2 - point.x) <= MoveUtils.SORPTION_UNIT) {
point.x = x2;
findInX = true;
}
}
if (!findInY) {
int y1 = bounds.y;
if (Math.abs(y1 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y1;
findInY = true;
}
int y2 = bounds.y + bounds.height;
if (Math.abs(y2 - point.y) <= MoveUtils.SORPTION_UNIT) {
point.y = y2;
findInY = true;
}
}
if (findInX && findInY) {
break;
}
}
setDesignerStateModelProperties(designer, findInX, findInY, currentBounds, point);
}
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) {
Rectangle relativeRec = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent == null) {
return relativeRec;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
relativeRec.x += rec.x;
relativeRec.y += rec.y;
return relativeRec;
}
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)的参数界面
Container container = designer.getSelectionModel().getSelection().getSelectedCreator().getParent();
if(container instanceof XWAbsoluteLayout){
layout = ((XWAbsoluteLayout)container).toData();
}
else {
layout = (WAbsoluteLayout) designer.getParaComponent().toData();
}
} else{
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 {
layout = (WAbsoluteLayout) designer.getParaComponent().toData();
}
} else {
layout = (WAbsoluteLayout) designer.getTarget().getContainer();
}
return layout;
return layout;
}
/**
* 拖拽
* @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());
/**
* 拖拽
*
* @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;
}
// 增加下宽度也设最小为21
if (rec.width == MINWIDTH) {
xmin = rec.x;
xmin = rec.x;
}
if(rec.width == MINWIDTH - 1){
xmin = xmin == rec.x ? rec.x : rec.x - 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;
rec.width = MINWIDTH;
rec.x = xmin;
}
}
/**
* 更新鼠标指针形状
*
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
}
if(rec != null) {
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer);
}
}
/**
* 更新鼠标指针形状
* @param formEditor 设计界面组件
*/
public void updateCursor(FormDesigner formEditor) {
// 调用位置枚举的多态方法getCursor获取鼠标形状
int type = getCursor();
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
}
}
/**
* 生成组件备用的bound
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {
formEditor.getSelectionModel().getSelection().backupBounds();
}
}
/**
* 生成组件备用的bound
*
* @param formEditor 设计界面组件
*/
public void backupBounds(FormDesigner formEditor) {
formEditor.getSelectionModel().getSelection().backupBounds();
}
}

180
designer_form/src/com/fr/design/designer/beans/models/AddingModel.java

@ -18,116 +18,124 @@ import com.fr.general.ComparatorUtils;
*/
public class AddingModel {
// 当前要添加的组件
private XCreator creator;
// 记录当前鼠标的位置信息
private int current_x;
private int current_y;
private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator;
instantiateCreator(designer, creatorName);
// 初始的时候隐藏该组件的图标
current_x = -this.creator.getWidth();
current_y = -this.creator.getHeight();
}
// 当前要添加的组件
private XCreator creator;
// 记录当前鼠标的位置信息
private int currentX;
private int currentY;
private boolean added;
public AddingModel(FormDesigner designer, XCreator xCreator) {
String creatorName = getXCreatorName(designer, xCreator);
this.creator = xCreator;
instantiateCreator(designer, creatorName);
// 初始的时候隐藏该组件的图标
currentY = -this.creator.getWidth();
currentX = -this.creator.getHeight();
}
/**
* 待说明
* @param designer 设计器
* @param creatorName 组件名
*
* @param designer 设计器
* @param creatorName 组件名
*/
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
public AddingModel(XCreator xCreator, int x, int y) {
this.creator = xCreator;
this.creator.backupCurrentSize();
this.creator.backupParent();
this.creator.setSize(xCreator.initEditorSize());
current_x = x - (xCreator.getWidth() / 2);
current_y = y - (xCreator.getHeight() / 2);
}
public void instantiateCreator(FormDesigner designer, String creatorName) {
creator.toData().setWidgetName(creatorName);
ComponentAdapter adapter = new CompositeComponentAdapter(designer, creator);
adapter.initialize();
creator.addNotify();
creator.putClientProperty(AdapterBus.CLIENT_PROPERTIES, adapter);
}
public AddingModel(XCreator xCreator, int x, int y) {
this.creator = xCreator;
this.creator.backupCurrentSize();
this.creator.backupParent();
this.creator.setSize(xCreator.initEditorSize());
currentX = x - (xCreator.getWidth() / 2);
currentY = y - (xCreator.getHeight() / 2);
}
/**
* 隐藏当前组件的图标
*/
public void reset() {
current_x = -this.creator.getWidth();
current_y = -this.creator.getHeight();
}
public void reset() {
currentX = -this.creator.getWidth();
currentY = -this.creator.getHeight();
}
public String getXCreatorName(FormDesigner designer,XCreator x){
String def= x.createDefaultName();
public String getXCreatorName(FormDesigner designer, XCreator x) {
String def = x.createDefaultName();
if (x.acceptType(XWParameterLayout.class)) {
return def;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
i++;
}
return def+i;
}
public int getCurrentX() {
return current_x;
}
public int getCurrentY() {
return current_y;
}
int i = 0;
while (designer.getTarget().isNameExist(def + i)) {
i++;
}
return def + i;
}
public int getCurrentX() {
return currentX;
}
public int getCurrentY() {
return currentY;
}
/**
* 移动组件图标到鼠标事件发生的位置
* @param x 坐标
* @param y 坐标
*
* @param x 坐标
* @param y 坐标
*/
public void moveTo(int x, int y) {
current_x = x - (this.creator.getWidth() / 2);
current_y = y - (this.creator.getHeight() / 2);
}
public void moveTo(int x, int y) {
currentX = x - (this.creator.getWidth() / 2);
currentY = y - (this.creator.getHeight() / 2);
}
public XCreator getXCreator() {
return this.creator;
}
public XCreator getXCreator() {
return this.creator;
}
/**
* 当前组件是否已经添加到某个容器中
* @return 是返回true
*
* @return 是返回true
*/
public boolean isCreatorAdded() {
return added;
}
public boolean isCreatorAdded() {
return added;
}
/**
* 加入容器
* @param designer 设计器
* @param container 容器
* @param x 坐标
* @param y 坐标
* @return 成功返回true
*
* @param designer 设计器
* @param container 容器
* @param x 坐标
* @param y 坐标
* @return 成功返回true
*/
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) {
//考虑不同布局嵌套的情况,获取顶层容器
XLayoutContainer xLayoutContainer = container.getTopLayout();
if(xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)){
container = xLayoutContainer;
}
Rectangle rect = ComponentUtils.getRelativeBounds(container);
if(!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())){
return added = container.getLayoutAdapter().addBean(creator, x + designer.getArea().getHorizontalValue(), y + designer.getArea().getVerticalValue());
}
return added = container.getLayoutAdapter().addBean(creator,
x + designer.getArea().getHorizontalValue() - rect.x,
y + designer.getArea().getVerticalValue() - rect.y);
}
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) {
//考虑不同布局嵌套的情况,获取顶层容器
XLayoutContainer xLayoutContainer = container.getTopLayout();
if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) {
container = xLayoutContainer;
}
Rectangle rect = ComponentUtils.getRelativeBounds(container);
if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) {
added = container.getLayoutAdapter().addBean(creator,
x + designer.getArea().getHorizontalValue(),
y + designer.getArea().getVerticalValue());
return added;
}
added = container.getLayoutAdapter().addBean(creator,
x + designer.getArea().getHorizontalValue() - rect.x,
y + designer.getArea().getVerticalValue() - rect.y);
return added;
}
}

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

@ -1,328 +1,461 @@
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.form.util.XCreatorConstants;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.stable.ArrayUtils;
/**
* 该model保存当前选择的组件和剪切版信息
*/
public class SelectionModel {
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
private static FormSelection CLIP_BOARD = new FormSelection();
private FormDesigner designer;
private FormSelection selection;
private Rectangle hotspot_bounds;
public SelectionModel(FormDesigner designer) {
this.designer = designer;
selection = new FormSelection();
}
/**
* 重置清空formSelction以及选择区域
*/
public void reset() {
selection.reset();
hotspot_bounds = null;
}
/**
* formSelction是否为空
* @return 是否为空
*/
public static boolean isEmpty(){
return CLIP_BOARD.isEmpty();
}
/**
* 鼠标点击一下所选中的单个组件按下Ctrl或者shift键时鼠标可以进行多选
* @param e 鼠标事件
*/
public void selectACreatorAtMouseEvent(MouseEvent e) {
if (!e.isControlDown() && !e.isShiftDown()) {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset();
}
// 获取e所在的组件
XCreator comp = designer.getComponentAt(e);
//布局组件的顶层布局如不可编辑,要获取其顶层布局
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();
if(topLayout != null && !topLayout.isEditable()){
comp = topLayout;
}
// 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的
if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) {
XCreator parentContainer = (XCreator) comp.getParent();
comp = parentContainer.isDedicateContainer() ? parentContainer : comp;
}
if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) {
designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED);
designer.repaint();
}
}
/**
* 将所选组件剪切到剪切板上
*/
public void cutSelectedCreator2ClipBoard() {
if (hasSelectionComponent()) {
selection.cut2ClipBoard(CLIP_BOARD);
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED);
designer.repaint();
}
}
/**
* 复制当前选中的组件到剪切板
*/
public void copySelectedCreator2ClipBoard() {
if (!selection.isEmpty()) {
selection.copy2ClipBoard(CLIP_BOARD);
}
}
/**
* 从剪切板粘帖组件
* @return
*/
public boolean pasteFromClipBoard() {
if (!CLIP_BOARD.isEmpty()) {
XLayoutContainer parent = null;
if (!hasSelectionComponent()) {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),CLIP_BOARD, DELTA_X_Y, DELTA_X_Y);
} else {
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (parent != null) {
Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, parent,CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
}
} else {
Toolkit.getDefaultToolkit().beep();
}
return false;
}
public FormSelection getSelection() {
return selection;
}
/**
* 删除当前所有选择的组件
*/
public void deleteSelection() {
XCreator[] roots = selection.getSelectedCreators();
if (roots.length > 0) {
for (XCreator creator : roots) {
if(creator.acceptType(XWParameterLayout.class)){
designer.removeParaComponent();
}
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight());
creator.removeAll();
// 清除被选中的组件
selection.reset();
}
setSelectedCreator(designer.getRootComponent());
// 触发事件
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
designer.repaint();
}
}
/**
* 从选择组件中删除某组件
*
* @param creator 组件
* @param creatorWidth 组件之前宽度
* @param creatorHeight 组件之前高度
*/
public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) {
selection.removeCreator(creator);
removeCreatorFromContainer(creator, creatorWidth, creatorHeight);
designer.repaint();
}
/**
* 设置选择区域
*/
public void setHotspotBounds(Rectangle rect) {
hotspot_bounds = rect;
}
/**
* 获得当前选择区域
*/
public Rectangle getHotspotBounds() {
return hotspot_bounds;
}
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator);
if (parent == null) {
return;
}
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle();
if (parent.acceptType(XWFitLayout.class) && changeCreator) {
creator = (XCreator) creator.getParent();
}
parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight);
// 删除其根组件,同时就删除了同时被选择的叶子组件
parent.remove(creator);
LayoutManager layout = parent.getLayout();
if (layout != null) {
// 刷新组件容器的布局
LayoutUtils.layoutContainer(parent);
}
}
/**
* 是否有组件被选择如果所选组件是最底层容器也视为无选择
* @return 是则返回true
*/
public boolean hasSelectionComponent() {
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null;
}
/**
* 移动组件至指定位置
* @param x 坐标x
* @param y 坐标y
*/
public void move(int x, int y) {
for (XCreator creator : selection.getSelectedCreators()) {
creator.setLocation(creator.getX() + x, creator.getY() + y);
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter != null) {
layoutAdapter.fix(creator);
}
}
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_SELECTED);
}
/**
* 释放捕获
*/
public void releaseDragging() {
designer.setPainter(null);
selection.fixCreator(designer);
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_RESIZED);
}
public Direction getDirectionAt(MouseEvent e) {
Direction dir;
if (e.isControlDown() || e.isShiftDown()) {
XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators());
if (creator != designer.getRootComponent() && selection.addedable(creator)) {
return Location.add;
}
}
if (hasSelectionComponent()) {
int x = e.getX() + designer.getArea().getHorizontalValue();
int y = e.getY() + designer.getArea().getVerticalValue();
dir = getDirection(selection.getRelativeBounds(), x, y);
if (selection.size() == 1) {
if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) {
dir = Location.outer;
}
}
} else {
dir = Location.outer;
}
if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) {
dir = designer.getLoc2Root(e);
}
return dir;
}
private Direction getDirection(Rectangle bounds, int x, int y) {
if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.left_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.left;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.left_bottom;
} else {
return Location.outer;
}
} else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.inner;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.bottom;
} else {
return Location.outer;
}
} else if ((x >= (bounds.x + bounds.width))
&& (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.right_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.right;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.right_bottom;
} else {
return Location.outer;
}
} else {
return Location.outer;
}
}
private void fireCreatorSelected() {
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_SELECTED);
}
public void setSelectedCreator(XCreator rootComponent) {
selection.setSelectedCreator(rootComponent);
fireCreatorSelected();
}
public void setSelectedCreators(ArrayList<XCreator> rebuildSelection) {
selection.setSelectedCreators(rebuildSelection);
fireCreatorSelected();
}
package com.fr.design.designer.beans.models;
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.*;
import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.stable.ArrayUtils;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
* 该model保存当前选择的组件和剪切版信息
*/
public class SelectionModel {
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
private static final double OFFSET_RELATIVE = 0.80;
private static FormSelection clipboard = new FormSelection();
private FormDesigner designer;
private FormSelection selection;
private Rectangle hotspotBounds;
public SelectionModel(FormDesigner designer) {
this.designer = designer;
selection = new FormSelection();
}
/**
* 重置清空formSelction以及选择区域
*/
public void reset() {
selection.reset();
hotspotBounds = null;
}
/**
* formSelction是否为空
*
* @return 是否为空
*/
public static boolean isEmpty() {
return clipboard.isEmpty();
}
/**
* 鼠标点击一下所选中的单个组件按下Ctrl或者shift键时鼠标可以进行多选
*
* @param e 鼠标事件
*/
public void selectACreatorAtMouseEvent(MouseEvent e) {
if (!e.isControlDown() && !e.isShiftDown()) {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset();
}
// 获取e所在的组件
XCreator comp = designer.getComponentAt(e);
//布局组件的顶层布局如不可编辑,要获取其顶层布局
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();
if (topLayout != null && !topLayout.isEditable()) {
comp = topLayout;
}
// 如果父层是scale和title两个专属容器,返回其父层,组件本身是不让被选中的
if (comp != designer.getRootComponent() && comp != designer.getParaComponent()) {
XCreator parentContainer = (XCreator) comp.getParent();
comp = parentContainer.isDedicateContainer() ? parentContainer : comp;
}
if (selection.removeSelectedCreator(comp) || selection.addSelectedCreator(comp)) {
designer.getEditListenerTable().fireCreatorModified(comp, DesignerEvent.CREATOR_SELECTED);
designer.repaint();
}
}
/**
* 将所选组件剪切到剪切板上
*/
public void cutSelectedCreator2ClipBoard() {
if (hasSelectionComponent()) {
selection.cut2ClipBoard(clipboard);
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED);
designer.repaint();
}
}
/**
* 复制当前选中的组件到剪切板
*/
public void copySelectedCreator2ClipBoard() {
if (!selection.isEmpty()) {
selection.copy2ClipBoard(clipboard);
}
}
/**
* 从剪切板粘帖组件
*
* @return
*/
public boolean pasteFromClipBoard() {
if (!clipboard.isEmpty()) {
if (!hasSelectedPasteSource()) {
//未选
unselectedPaste();
} else {
//已选
selectedPaste();
}
} else {
Toolkit.getDefaultToolkit().beep();
}
return false;
}
public FormSelection getSelection() {
return selection;
}
/**
* 粘贴时未选择组件
*/
private void unselectedPaste() {
if (designer.getClass().equals(FormDesigner.class)) {
if (selection.getSelectedCreator() instanceof XWFitLayout) {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) {
XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator();
//tab布局编辑器内部左上角第一个坐标点
int leftUpX = container.toData().getMargin().getLeft() + 1;
int leftUpY = container.toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, container, clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
} else {
//自适应布局编辑器内部左上角第一个坐标点
int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1;
int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
}
} else {
//绝对布局
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
//当前选择的就是编辑器表层
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
clipboard,
DELTA_X_Y,
DELTA_X_Y);
}
} else {
//cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到
//使用selection.getSelectedCreator()也应该是可以获取到的。
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard,
DELTA_X_Y,
DELTA_X_Y);
}
}
/**
* 粘贴时选择组件
*/
private void selectedPaste() {
XLayoutContainer container = null;
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
container = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (container != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局
Rectangle selectionRec = selection.getRelativeBounds();
//获取父容器位置,补充因参数面板高度导致的位置坐标计算偏移
Rectangle containerRec = ComponentUtils.getRelativeBounds(container);
int positionX, positionY;
if (container.getClass().equals(XWTabFitLayout.class)) {
//tab内部粘贴不补充高度偏移
//且不计算参数面板造成的影响,因为在
//@see com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter#addBean中做了
positionX = selectionRec.x + selectionRec.width / 2;
positionY = (int) (selectionRec.y + selectionRec.height * OFFSET_RELATIVE);
} else {
//计算自适应布局位置
positionX = selectionRec.x - containerRec.x + selectionRec.width / 2;
positionY = (int) (selectionRec.y - containerRec.y + selectionRec.height * OFFSET_RELATIVE);
}
FormSelectionUtils.paste2Container(designer, container, clipboard, positionX, positionY);
} else if (container != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局
Rectangle rec = selection.getSelctionBounds();
FormSelectionUtils.paste2Container(designer, container, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
}
/**
* 删除当前所有选择的组件
*/
public void deleteSelection() {
XCreator[] roots = selection.getSelectedCreators();
if (roots.length > 0) {
for (XCreator creator : roots) {
if (creator.acceptType(XWParameterLayout.class)) {
designer.removeParaComponent();
}
removeCreatorFromContainer(creator, creator.getWidth(), creator.getHeight());
creator.removeAll();
// 清除被选中的组件
selection.reset();
}
setSelectedCreator(designer.getRootComponent());
FormSelectionUtils.rebuildSelection(designer);
// 触发事件
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_DELETED);
designer.repaint();
}
}
/**
* 从选择组件中删除某组件
*
* @param creator 组件
* @param creatorWidth 组件之前宽度
* @param creatorHeight 组件之前高度
*/
public void removeCreator(XCreator creator, int creatorWidth, int creatorHeight) {
selection.removeCreator(creator);
removeCreatorFromContainer(creator, creatorWidth, creatorHeight);
designer.repaint();
}
/**
* 设置选择区域
*/
public void setHotspotBounds(Rectangle rect) {
hotspotBounds = rect;
}
/**
* 获得当前选择区域
*/
public Rectangle getHotspotBounds() {
return hotspotBounds;
}
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator);
if (parent == null) {
return;
}
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle();
if (parent.acceptType(XWFitLayout.class) && changeCreator) {
creator = (XCreator) creator.getParent();
}
parent.getLayoutAdapter().removeBean(creator, creatorWidth, creatorHeight);
// 删除其根组件,同时就删除了同时被选择的叶子组件
parent.remove(creator);
LayoutManager layout = parent.getLayout();
if (layout != null) {
// 刷新组件容器的布局
LayoutUtils.layoutContainer(parent);
}
}
/**
* 是否有组件被选择如果所选组件是最底层容器也视为无选择
*
* @return 是则返回true
* yaoh.wu 不应该通过判断是否是最底层容器来判断是否选择了组件
* 而是应该判断选择的容器是否是编辑器的最表层容器,也就是点击空白地方选择的容器
* 但是直接判断选择的容器是否是编辑器最表层类型又会引发拖动时选不上的情况
* 因此通过判断父容器来实现
* <p>
* 举例frm组件复用 绝对布局情况下不选择时有三层容器
* 底层@see {@link com.fr.design.designer.creator.XWBorderLayout}
* 中层@see {@link XWFitLayout}
* 表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout}
* <p>
* 但是编辑窗口的最外层其实是表层@see {@link com.fr.design.designer.creator.XWAbsoluteBodyLayout},
* 其他两层不是靠添加组件就可以编辑的
*/
public boolean hasSelectedPasteSource() {
XCreator selectionXCreator = selection.getSelectedCreator();
if (designer.getClass().equals(FormDesigner.class)) {
//frm本地组件复用
if (selectionXCreator != null) {
//选中的是否是tab布局编辑器本身
boolean tabEditor = selectionXCreator.getClass().equals(XWCardMainBorderLayout.class)
|| selectionXCreator.getClass().equals(XWCardLayout.class)
|| selectionXCreator.getClass().equals(XWTabFitLayout.class);
//选中的是否是frm绝对布局编辑器本身
boolean absoluteEditor = selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class);
//选中是否是frm绝对画布块编辑器本身
boolean absoluteCanvas = selectionXCreator.getClass().equals(XWAbsoluteLayout.class);
//选中的是否是相对布局编辑器本身
boolean relativeEditor = selectionXCreator.getClass().equals(XWFitLayout.class);
return !(tabEditor || absoluteEditor || absoluteCanvas || relativeEditor);
} else {
return false;
}
} else {
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
return selectionXCreator != null && selectionXCreator.getParent() != null;
}
}
/**
* 是否有组件被选择如果所选组件是最底层容器也视为无选择
*
* @return 是则返回true
*/
public boolean hasSelectionComponent() {
return !selection.isEmpty() && selection.getSelectedCreator().getParent() != null;
}
/**
* 移动组件至指定位置
*
* @param x 坐标x
* @param y 坐标y
*/
public void move(int x, int y) {
for (XCreator creator : selection.getSelectedCreators()) {
creator.setLocation(creator.getX() + x, creator.getY() + y);
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter != null) {
layoutAdapter.fix(creator);
}
}
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_SELECTED);
}
/**
* 释放捕获
*/
public void releaseDragging() {
designer.setPainter(null);
selection.fixCreator(designer);
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_RESIZED);
}
public Direction getDirectionAt(MouseEvent e) {
Direction dir;
if (e.isControlDown() || e.isShiftDown()) {
XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators());
if (creator != designer.getRootComponent() && selection.addedable(creator)) {
return Location.add;
}
}
if (hasSelectionComponent()) {
int x = e.getX() + designer.getArea().getHorizontalValue();
int y = e.getY() + designer.getArea().getVerticalValue();
dir = getDirection(selection.getRelativeBounds(), x, y);
if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir
.getActual())) {
dir = Location.outer;
}
} else {
dir = Location.outer;
}
if (designer.getDesignerMode().isFormParameterEditor() && dir == Location.outer) {
dir = designer.getLoc2Root(e);
}
return dir;
}
private Direction getDirection(Rectangle bounds, int x, int y) {
if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.left_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.left;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.left_bottom;
} else {
return Location.outer;
}
} else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.inner;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.bottom;
} else {
return Location.outer;
}
} else if ((x >= (bounds.x + bounds.width))
&& (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.right_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.right;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.right_bottom;
} else {
return Location.outer;
}
} else {
return Location.outer;
}
}
private void fireCreatorSelected() {
designer.getEditListenerTable().fireCreatorModified(selection.getSelectedCreator(),
DesignerEvent.CREATOR_SELECTED);
}
public void setSelectedCreator(XCreator rootComponent) {
selection.setSelectedCreator(rootComponent);
fireCreatorSelected();
}
public void setSelectedCreators(ArrayList<XCreator> rebuildSelection) {
selection.setSelectedCreators(rebuildSelection);
fireCreatorSelected();
}
}

688
designer_form/src/com/fr/design/designer/beans/models/StateModel.java

@ -1,446 +1,476 @@
package com.fr.design.designer.beans.models;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import com.fr.design.beans.location.Absorptionline;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.HoverPainter;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.beans.location.Location;
import com.fr.design.designer.creator.XConnector;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.*;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.ComponentUtils;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
* 普通模式下的状态model
*/
public class StateModel {
// 对应的selection model
private SelectionModel selectionModel;
// 当前鼠标进入拖拽区域的位置类型
private Direction driection;
// 当前拖拽的起始位置
private int current_x;
private int current_y;
private Point startPoint = new Point();
private Point currentPoint = new Point();
private Absorptionline lineInX;
private Absorptionline lineInY;
//等距线
private Absorptionline lineEquidistant;
// 当前是否处于拖拽选择状态
private boolean selecting;
private boolean dragging;
private boolean addable;
private FormDesigner designer;
public StateModel(FormDesigner designer) {
this.designer = designer;
selectionModel = designer.getSelectionModel();
}
/**
* 返回direction
* @return direction方向
*/
public Direction getDirection() {
return driection;
}
/**
* 是否有组件正被选中
*
* @return true 如果至少一个组件被选中
*/
public boolean isSelecting() {
return selecting;
}
// 对应的selection model
private SelectionModel selectionModel;
// 当前鼠标进入拖拽区域的位置类型
private Direction driection;
// 当前拖拽的起始位置
private int currentX;
private int currentY;
//拖拽组件原始位置大小备份
private Rectangle selectedPositionBackup;
private Point startPoint = new Point();
private Point currentPoint = new Point();
private Absorptionline lineInX;
private Absorptionline lineInY;
//等距线
private Absorptionline lineEquidistant;
// 当前是否处于拖拽选择状态
private boolean selecting;
private boolean dragging;
private boolean addable;
private FormDesigner designer;
public StateModel(FormDesigner designer) {
this.designer = designer;
selectionModel = designer.getSelectionModel();
}
/**
*是否能拖拽
* 返回direction
*
* @return direction方向
*/
public Direction getDirection() {
return driection;
}
/**
* 是否有组件正被选中
*
* @return true 如果至少一个组件被选中
*/
public boolean isSelecting() {
return selecting;
}
/**
* 是否能拖拽
*
* @return 非outer且选中为空
*/
public boolean dragable() {
return ((driection != Location.outer) && !selecting);
}
/**
* 拖拽中是否可以转换为添加模式
* 如果拖拽组件只有一个鼠标当前所在位置的最底层表单容器与这个组件的容器不同
* 如果拖拽组件为多个鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外还必须是绝对定位布局
*/
private void checkAddable(MouseEvent e) {
addable = false;
designer.setPainter(null);
if (driection != Location.inner) {
return;
}
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator();
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator);
if (creatorContainer != null && creatorContainer != container
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) {
HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter);
if (painter != null) {
Rectangle rect = ComponentUtils.getRelativeBounds(container);
rect.x -= designer.getArea().getHorizontalValue();
rect.y -= designer.getArea().getVerticalValue();
painter.setRenderingBounds(rect);
painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator);
}
addable = true;
}
}
private boolean addBean(XLayoutContainer container, int x, int y) {
LayoutAdapter adapter = container.getLayoutAdapter();
Rectangle r = ComponentUtils.getRelativeBounds(container);
if (selectionModel.getSelection().size() == 1) {
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(), x
+ designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue() - r.y);
}
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) {
adapter.addBean(creator, x + designer.getArea().getHorizontalValue() - r.x, y + designer.getArea().getVerticalValue()- r.y);
}
return true;
}
private void adding(int x, int y) {
public boolean dragable() {
return ((driection != Location.outer) && !selecting);
}
/**
* 拖拽中是否可以转换为添加模式
* 如果拖拽组件只有一个鼠标当前所在位置的最底层表单容器与这个组件的容器不同
* 如果拖拽组件为多个鼠标当前所在位置的最底层表单容器除了要求要跟这些组件的容器不同外还必须是绝对定位布局
*/
private void checkAddable(MouseEvent e) {
addable = false;
designer.setPainter(null);
if (driection != Location.inner) {
return;
}
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator();
Component creatorContainer = XCreatorUtils.getParentXLayoutContainer(creator);
if (creatorContainer != null && creatorContainer != container
&& (selectionModel.getSelection().size() == 1 || container instanceof XWAbsoluteLayout)) {
HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter);
if (painter != null) {
Rectangle rect = ComponentUtils.getRelativeBounds(container);
rect.x -= designer.getArea().getHorizontalValue();
rect.y -= designer.getArea().getVerticalValue();
painter.setRenderingBounds(rect);
painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator);
}
addable = true;
}
}
/**
* @param container 容器
* @param mouseX 鼠标释放位置X
* @param mouseY 鼠标释放位置Y
* @return 是否成功
*/
private boolean addBean(XLayoutContainer container, int mouseX, int mouseY) {
LayoutAdapter adapter = container.getLayoutAdapter();
Rectangle rectangleContainer = ComponentUtils.getRelativeBounds(container);
if (selectionModel.getSelection().size() == 1) {
return adapter.addBean(selectionModel.getSelection().getSelectedCreator(),
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x,
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y);
}
for (XCreator creator : selectionModel.getSelection().getSelectedCreators()) {
adapter.addBean(creator,
mouseX + designer.getArea().getHorizontalValue() - rectangleContainer.x,
mouseY + designer.getArea().getVerticalValue() - rectangleContainer.y);
}
return true;
}
/**
* @param mouseReleasedX 鼠标释放位置X
* @param mouseReleasedY 鼠标释放位置Y
*/
private void adding(int mouseReleasedX, int mouseReleasedY) {
// 当前鼠标所在的组件
XCreator hoveredComponent = designer.getComponentAt(x, y, selectionModel.getSelection().getSelectedCreators());
XCreator hoveredComponent = designer.getComponentAt(mouseReleasedX, mouseReleasedY, selectionModel.getSelection().getSelectedCreators());
// 获取该组件所在的焦点容器
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent);
boolean success = false;
if (container != null) {
// 如果是容器,则调用其acceptComponent接受组件
success = addBean(container, x, y);
}
if (success) {
FormSelectionUtils.rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED);
} else {
Toolkit.getDefaultToolkit().beep();
}
if (container != null) {
// 如果是容器,则调用其acceptComponent接受组件
success = addBean(container, mouseReleasedX, mouseReleasedY);
}
if (success) {
FormSelectionUtils.rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
selectionModel.getSelection().getSelectedCreator(), DesignerEvent.CREATOR_ADDED);
} else {
selectionModel.getSelection().setSelectionBounds(selectedPositionBackup, designer);
Toolkit.getDefaultToolkit().beep();
}
// 取消提示
designer.setPainter(null);
}
/**
*是否拖拽
* 是否拖拽
*
* @return dragging状态
*/
public boolean isDragging() {
return dragging;
}
public boolean isDragging() {
return dragging;
}
/**
*是否可以开始画线
* 是否可以开始画线
*
* @return startPoint不为空返回true
*/
public boolean prepareForDrawLining() {
return startPoint != null;
}
public boolean prepareForDrawLining() {
return startPoint != null;
}
/**
*设置开始位置
* 设置开始位置
*
* @param p point位置
*/
public void setStartPoint(Point p) {
this.startPoint = p;
}
public void setStartPoint(Point p) {
this.startPoint = p;
}
/**
*返回开始位置
* 返回开始位置
*
* @return 点位置
*/
public Point getStartPoint() {
return startPoint;
}
public Point getStartPoint() {
return startPoint;
}
/**
*返回当前点位置
* 返回当前点位置
*
* @return 点位置
*/
public Point getEndPoint() {
return currentPoint;
}
return currentPoint;
}
/**
*当前选中组件
* 当前选中组件
*
* @param e 鼠标事件
*/
public void startSelecting(MouseEvent e) {
selecting = true;
selectionModel.setHotspotBounds(new Rectangle());
current_x = getMouseXY(e).x;
current_y = getMouseXY(e).y;
}
public void startSelecting(MouseEvent e) {
selecting = true;
selectionModel.setHotspotBounds(new Rectangle());
currentX = getMouseXY(e).x;
currentY = getMouseXY(e).y;
}
/**
*当前鼠标的xy
* 当前鼠标的xy
*
* @param e 鼠标事件
*/
public void startResizing(MouseEvent e) {
if (!selectionModel.getSelection().isEmpty()) {
driection.backupBounds(designer);
}
current_x = getMouseXY(e).x;
current_y = getMouseXY(e).y;
}
public void startResizing(MouseEvent e) {
if (!selectionModel.getSelection().isEmpty()) {
driection.backupBounds(designer);
}
currentX = getMouseXY(e).x;
currentY = getMouseXY(e).y;
}
/**
*起始点开始DrawLine
* 起始点开始DrawLine
*
* @param p 点位置
*/
public void startDrawLine(Point p) {
this.startPoint = p;
if(p != null) {
try {
designer.setCursor(XConnector.connectorCursor);
} catch (Exception e) {
}
} else {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
public void startDrawLine(Point p) {
this.startPoint = p;
if (p != null) {
try {
designer.setCursor(XConnector.connectorCursor);
} catch (Exception e) {
}
} else {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
/**
*鼠标释放时所在的区域及圈中的组件
* 鼠标释放时所在的区域及圈中的组件
*
* @param e 鼠标事件
*/
public void selectCreators(MouseEvent e) {
int x = getMouseXY(e).x;
int y = getMouseXY(e).y;
public void selectCreators(MouseEvent e) {
int x = getMouseXY(e).x;
int y = getMouseXY(e).y;
Rectangle bounds = createCurrentBounds(x, y);
Rectangle bounds = createCurrentBounds(x, y);
if ((x != current_x) || (y != current_y)) {
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent()));
}
selectionModel.setHotspotBounds(null);
}
if ((x != currentX) || (y != currentY)) {
selectionModel.setSelectedCreators(getHotspotCreators(bounds, designer.getRootComponent()));
}
selectionModel.setHotspotBounds(null);
}
/**
*画所在区域线
* 画所在区域线
*
* @param e 鼠标事件
*/
public void drawLine(MouseEvent e) {
designer.getDrawLineHelper().setDrawLine(true);
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e);
if (p != null) {
currentPoint = p;
} else {
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue();
currentPoint.y = e.getY() + designer.getArea().getVerticalValue();
}
}
private Rectangle createCurrentBounds(int x, int y) {
Rectangle bounds = new Rectangle();
bounds.x = Math.min(x, current_x);
bounds.y = Math.min(y, current_y);
bounds.width = Math.max(x, current_x) - bounds.x;
bounds.height = Math.max(y, current_y) - bounds.y;
return bounds;
}
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) {
ArrayList<XCreator> creators = new ArrayList<XCreator>();
if (!root.isVisible() && !designer.isRoot(root)) {
return creators;
}
if (root instanceof XLayoutContainer) {
XLayoutContainer container = (XLayoutContainer) root;
int count = container.getXCreatorCount();
Rectangle clipped = new Rectangle(selection);
for (int i = count - 1; i >= 0; i--) {
XCreator child = container.getXCreator(i);
if (selection.contains(child.getBounds())) {
creators.add(child);
} else {
clipped.x = selection.x - child.getX();
clipped.y = selection.y - child.getY();
creators.addAll(getHotspotCreators(clipped, child));
}
}
}
return creators;
}
public void drawLine(MouseEvent e) {
designer.getDrawLineHelper().setDrawLine(true);
Point p = designer.getDrawLineHelper().getNearWidgetPoint(e);
if (p != null) {
currentPoint = p;
} else {
currentPoint.x = e.getX() + designer.getArea().getHorizontalValue();
currentPoint.y = e.getY() + designer.getArea().getVerticalValue();
}
}
private Rectangle createCurrentBounds(int x, int y) {
Rectangle bounds = new Rectangle();
bounds.x = Math.min(x, currentX);
bounds.y = Math.min(y, currentY);
bounds.width = Math.max(x, currentX) - bounds.x;
bounds.height = Math.max(y, currentY) - bounds.y;
return bounds;
}
private ArrayList<XCreator> getHotspotCreators(Rectangle selection, XCreator root) {
ArrayList<XCreator> creators = new ArrayList<>();
if (!root.isVisible() && !designer.isRoot(root)) {
return creators;
}
if (root instanceof XLayoutContainer) {
XLayoutContainer container = (XLayoutContainer) root;
int count = container.getXCreatorCount();
Rectangle clipped = new Rectangle(selection);
for (int i = count - 1; i >= 0; i--) {
XCreator child = container.getXCreator(i);
if (selection.contains(child.getBounds())) {
creators.add(child);
} else {
clipped.x = selection.x - child.getX();
clipped.y = selection.y - child.getY();
creators.addAll(getHotspotCreators(clipped, child));
}
}
}
return creators;
}
/**
*重置model
* 重置model
*/
public void resetModel() {
dragging = false;
selecting = false;
}
public void resetModel() {
dragging = false;
selecting = false;
}
/**
*重置
* 重置
*/
public void reset() {
driection = Location.outer;
dragging = false;
selecting = false;
}
public void reset() {
driection = Location.outer;
dragging = false;
selecting = false;
}
/**
*取消拖拽
* 取消拖拽
*/
public void draggingCancel() {
designer.repaint();
reset();
}
public void draggingCancel() {
designer.repaint();
reset();
}
/**
*设置可拉伸方向
* 设置可拉伸方向
*
* @param dir 拉伸方向
*/
public void setDirection(Direction dir) {
if(driection != dir) {
this.driection = dir;
driection.updateCursor(designer);
}
}
public void setDirection(Direction dir) {
if (driection != dir) {
this.driection = dir;
driection.updateCursor(designer);
}
}
/**
*x吸附线赋值
* x吸附线赋值
*
* @param line 线
*/
public void setXAbsorptionline(Absorptionline line) {
this.lineInX = line;
}
public void setXAbsorptionline(Absorptionline line) {
this.lineInX = line;
}
/**
*y吸附线赋值
* y吸附线赋值
*
* @param line 线
*/
public void setYAbsorptionline(Absorptionline line) {
this.lineInY = line;
}
/**
* 等距线赋值
*
* @param line 线
*/
public void setYAbsorptionline(Absorptionline line) {
this.lineInY = line;
}
/**
* 等距线赋值
* @param line 线
*/
public void setEquidistantLine(Absorptionline line){
this.lineEquidistant = line;
}
public void setEquidistantLine(Absorptionline line) {
this.lineEquidistant = line;
}
/**
*画吸附线
* 画吸附线
*
* @param g Graphics类
*/
public void paintAbsorptionline(Graphics g) {
if(lineInX != null) {
lineInX.paint(g,designer.getArea());
}
if(lineInY != null) {
lineInY.paint(g,designer.getArea());
}
if(lineEquidistant != null){
lineEquidistant.paint(g,designer.getArea());
}
}
public void paintAbsorptionline(Graphics g) {
if (lineInX != null) {
lineInX.paint(g, designer.getArea());
}
if (lineInY != null) {
lineInY.paint(g, designer.getArea());
}
if (lineEquidistant != null) {
lineEquidistant.paint(g, designer.getArea());
}
}
/**
*拖拽
* 拖拽
*
* @param e 鼠标事件
*/
public void dragging(MouseEvent e) {
checkAddable(e);
setDependLinePainter(e);
driection.drag(getMouseXY(e).x-current_x, getMouseXY(e).y-current_y, designer);
this.dragging = true;
}
// 拖拽时画依附线用到的painter
private void setDependLinePainter(MouseEvent e){
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator();
HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter);
if (painter != null) {
painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator);
}
}
public void dragging(MouseEvent e) {
//进入dragging状态时备份组件大小和位置
if (!dragging) {
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds();
}
checkAddable(e);
setDependLinePainter(e);
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer);
this.dragging = true;
}
// 拖拽时画依附线用到的painter
private void setDependLinePainter(MouseEvent e) {
XCreator comp = designer.getComponentAt(e.getX(), e.getY(), selectionModel.getSelection().getSelectedCreators());
XLayoutContainer container = XCreatorUtils.getHotspotContainer(comp);
XCreator creator = selectionModel.getSelection().getSelectedCreator();
HoverPainter painter = AdapterBus.getContainerPainter(designer, container);
designer.setPainter(painter);
if (painter != null) {
painter.setHotspot(new Point(e.getX(), e.getY()));
painter.setCreator(creator);
}
}
/**
*释放捕获
* 释放捕获
*
* @param e 鼠标事件
*/
public void releaseDragging(MouseEvent e) {
this.dragging = false;
if (addable) {
adding(e.getX(), e.getY());
} else if (!selectionModel.getSelection().isEmpty()) {
selectionModel.releaseDragging();
}
designer.repaint();
}
public void releaseDragging(MouseEvent e) {
this.dragging = false;
if (addable) {
adding(e.getX(), e.getY());
} else if (!selectionModel.getSelection().isEmpty()) {
selectionModel.releaseDragging();
}
designer.repaint();
}
/**
*改变选择区域
* 改变选择区域
*
* @param e 鼠标事件
* @param e 鼠标事件
*/
public void changeSelection(MouseEvent e) {
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y);
selectionModel.setHotspotBounds(bounds);
}
public void changeSelection(MouseEvent e) {
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y);
selectionModel.setHotspotBounds(bounds);
}
/**
*返回鼠标所在的xy 考虑滚动条的值
* 返回鼠标所在的xy 考虑滚动条的值
*
* @param e 鼠标事件
* @return xy值
*/
public Point getMouseXY(MouseEvent e) {
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY()
+ designer.getArea().getVerticalValue());
return p1;
}
public Point getMouseXY(MouseEvent e) {
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY()
+ designer.getArea().getVerticalValue());
return p1;
}
}

45
designer_form/src/com/fr/design/designer/beans/painters/AbstractPainter.java

@ -22,6 +22,7 @@ public abstract class AbstractPainter implements HoverPainter {
/**
* 构造函数
*
* @param container 容器
*/
public AbstractPainter(XLayoutContainer container) {
@ -32,23 +33,25 @@ public abstract class AbstractPainter implements HoverPainter {
public void setHotspot(Point p) {
hotspot = p;
}
/**
* 画初始区域
* @param g 画图类
* @param startX 起始x位置
* @param startY 起始y位置
* 画初始区域
*
* @param g 画图类
* @param startX 起始x位置
* @param startY 起始y位置
*/
public void paint(Graphics g, int startX, int startY) {
if (hotspot_bounds != null) {
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false);
}
}
/**
* 设置边界
*
* @param rect 位置
*/
public void paint(Graphics g, int startX, int startY) {
if(hotspot_bounds != null){
drawHotspot(g, hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height, Color.lightGray, true, false);
}
}
/**
* 设置边界
* @param rect 位置
*/
@Override
public void setRenderingBounds(Rectangle rect) {
hotspot_bounds = rect;
@ -63,12 +66,12 @@ public abstract class AbstractPainter implements HoverPainter {
Color bColor = accept ? XCreatorConstants.LAYOUT_HOTSPOT_COLOR : XCreatorConstants.LAYOUT_FORBIDDEN_COLOR;
drawHotspot(g, x, y, width, height, bColor, accept, false);
}
/**
* 自适应布局那边渲染提示要画整个背景不是画边框
*/
protected void drawRegionBackground(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept) {
drawHotspot(g, x, y, width, height, bColor, accept, true);
drawHotspot(g, x, y, width, height, bColor, accept, true);
}
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) {
@ -81,13 +84,13 @@ public abstract class AbstractPainter implements HoverPainter {
if (!accept) {
g2d.drawString(Inter.getLocText("Cannot-Add_To_This_Area") + "!", x + width / 3, y + height / 2);
} else if (drawBackground) {
g2d.fillRect(x, y, width, height);
g2d.fillRect(x, y, width, height);
} else {
g2d.drawRect(x, y, width, height);
g2d.drawRect(x, y, width, height);
}
g2d.setStroke(backup);
g2d.setColor(color);
}
}

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

@ -1,88 +1,96 @@
/**
*
*/
package com.fr.design.designer.creator;
import com.fr.form.ui.container.WLayout;
import java.awt.*;
import java.beans.IntrospectionException;
import java.util.ArrayList;
/**
* 一些控件专属的容器如标题容器sclae容器
* @author jim
* @date 2014-11-7
*/
public abstract class DedicateLayoutContainer extends XLayoutContainer {
public DedicateLayoutContainer(WLayout widget, Dimension initSize) {
super(widget, initSize);
}
/**
* 得到属性名
* @return 属性名
* @throws IntrospectionException
*/
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[0];
}
/**
* 返回容器图标
*
* @return
*/
@Override
public String getIconPath() {
if(this.getXCreator(XWScaleLayout.INDEX) != null){
return this.getXCreator(XWScaleLayout.INDEX).getIconPath();
}
return "/com/fr/web/images/form/resources/text_field_16.png";
}
/**
* 控件树不显示此组件
* @param path 控件树list
*/
public void notShowInComponentTree(ArrayList<Component> path) {
path.remove(path.size()-1);
}
/**
* 重置组件的名称
* @param name 名称
*/
public void resetCreatorName(String name) {
super.resetCreatorName(name);
XCreator child = getXCreator(XWScaleLayout.INDEX);
child.toData().setWidgetName(name);
}
/**
* 返回对应属性表的组件scale和title返回其子组件
* @return 组件
*/
public XCreator getPropertyDescriptorCreator() {
return getXCreator(XWScaleLayout.INDEX);
}
/**
* 是否作为控件树的叶子节点
* @return 是则返回true
*/
public boolean isComponentTreeLeaf() {
return true;
}
/**
* 是否为sclae和title专属容器
* @return 是则返回true
*/
public boolean isDedicateContainer() {
return true;
}
/**
*
*/
package com.fr.design.designer.creator;
import com.fr.form.ui.container.WLayout;
import java.awt.*;
import java.beans.IntrospectionException;
import java.util.ArrayList;
/**
* 一些控件专属的容器如标题容器sclae容器
*
* @author jim
* @date 2014-11-7
*/
public abstract class DedicateLayoutContainer extends XLayoutContainer {
public DedicateLayoutContainer(WLayout widget, Dimension initSize) {
super(widget, initSize);
}
/**
* 得到属性名
*
* @return 属性名
* @throws IntrospectionException
*/
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[0];
}
/**
* 返回容器图标
*
* @return
*/
@Override
public String getIconPath() {
if (this.getXCreator(XWScaleLayout.INDEX) != null) {
return this.getXCreator(XWScaleLayout.INDEX).getIconPath();
}
return "/com/fr/web/images/form/resources/text_field_16.png";
}
/**
* 控件树不显示此组件
*
* @param path 控件树list
*/
public void notShowInComponentTree(ArrayList<Component> path) {
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() {
return getXCreator(XWScaleLayout.INDEX);
}
/**
* 是否作为控件树的叶子节点
*
* @return 是则返回true
*/
public boolean isComponentTreeLeaf() {
return true;
}
/**
* 是否为sclae和title专属容器
*
* @return 是则返回true
*/
public boolean isDedicateContainer() {
return true;
}
}

153
designer_form/src/com/fr/design/designer/creator/XElementCase.java

@ -36,8 +36,8 @@ import java.beans.PropertyDescriptor;
import java.util.Set;
public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{
private UILabel imageLable;
private CoverReportPane coverPanel;
private UILabel imageLable;
private CoverReportPane coverPanel;
private FormDesigner designer;
//缩略图
private BufferedImage thumbnailImage;
@ -66,30 +66,23 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
}
/**
* 是否支持设置标题
* @return 是返回true
*/
public boolean hasTitleStyle() {
* 是否支持设置标题
* @return 是返回true
*/
public boolean hasTitleStyle() {
return true;
}
/**
* 返回组件属性值
* @return 返回组件属性值
* @throws IntrospectionException 异常
*/
/**
* 返回组件属性值
* @return 返回组件属性值
* @throws IntrospectionException 异常
*/
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
CRPropertyDescriptor[] propertyTableEditor = new CRPropertyDescriptor[]{
new CRPropertyDescriptor("widgetName", this.data.getClass())
.setI18NName(Inter.getLocText("Form-Widget_Name")),
new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName(
Inter.getLocText("FR-Designer_Widget-Visible")).setPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
makeVisible(toData().isVisible());}
}),
new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass(
WLayoutBorderStyleEditor.class).setI18NName(
Inter.getLocText("FR-Designer-Widget_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced")
@ -150,30 +143,30 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
return "text_field_16.png";
}
/**
* 返回组件默认名
* @return 组件类名(小写)
*/
public String createDefaultName() {
return "report";
}
/**
* 返回组件默认名
* @return 组件类名(小写)
*/
public String createDefaultName() {
return "report";
}
@Override
protected JComponent initEditor() {
if (editor == null) {
setBorder(DEFALUTBORDER);
editor = new JPanel();
editor.setBackground(null);
editor.setLayout(null);
imageLable = initImageBackground();
coverPanel = new CoverReportPane();
coverPanel.setPreferredSize(imageLable.getPreferredSize());
coverPanel.setBounds(imageLable.getBounds());
editor.add(coverPanel);
coverPanel.setVisible(false);
editor.add(imageLable);
editor = new JPanel();
editor.setBackground(null);
editor.setLayout(null);
imageLable = initImageBackground();
coverPanel = new CoverReportPane();
coverPanel.setPreferredSize(imageLable.getPreferredSize());
coverPanel.setBounds(imageLable.getBounds());
editor.add(coverPanel);
coverPanel.setVisible(false);
editor.add(imageLable);
}
return editor;
}
@ -186,7 +179,7 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
BufferedImage image = getThumbnailImage();
setLabelBackground(image, imageLable);
return imageLable;
return imageLable;
}
/**
@ -195,16 +188,16 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
private void setLabelBackground(Image image, UILabel imageLable){
ImageIcon icon = new ImageIcon(image);
imageLable.setIcon(icon);
imageLable.setOpaque(true);
imageLable.setLayout(null);
imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
imageLable.setOpaque(true);
imageLable.setLayout(null);
imageLable.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
}
/**
* 是否展现覆盖的pane
* @param display 是否
*/
public void displayCoverPane(boolean display){
/**
* 是否展现覆盖的pane
* @param display 是否
*/
public void displayCoverPane(boolean display){
coverPanel.setVisible(display);
coverPanel.setBounds(1, 1, (int) editor.getBounds().getWidth(), (int) editor.getBounds().getHeight());
editor.repaint();
@ -217,41 +210,41 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
coverPanel.destroyHelpDialog();
}
public JComponent getCoverPane(){
return coverPanel;
}
public JComponent getCoverPane(){
return coverPanel;
}
/**
* 初始化大小
* @return 尺寸
*/
/**
* 初始化大小
* @return 尺寸
*/
public Dimension initEditorSize() {
return BORDER_PREFERRED_SIZE;
}
/**
* 是否是报表块
* @return
*/
/**
* 是否是报表块
* @return
*/
public boolean isReport() {
return true;
}
/**
* 该组件是否可以拖入参数面板
* @return 是则返回true
*/
public boolean canEnterIntoParaPane(){
return false;
}
/**
* 返回报表块对应的widget
* @return 返回ElementCaseEditor
*/
public ElementCaseEditor toData() {
return ((ElementCaseEditor) data);
}
/**
* 该组件是否可以拖入参数面板
* @return 是则返回true
*/
public boolean canEnterIntoParaPane(){
return false;
}
/**
* 返回报表块对应的widget
* @return 返回ElementCaseEditor
*/
public ElementCaseEditor toData() {
return ((ElementCaseEditor) data);
}
public FormElementCaseProvider getElementCase() {
return toData().getElementCase();
@ -302,14 +295,14 @@ public class XElementCase extends XBorderStyleWidgetCreator implements FormEleme
}
private void switchTab(MouseEvent e,EditingMouseListener editingMouseListener){
FormDesigner designer = editingMouseListener.getDesigner();
if (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR){
FormElementCaseContainerProvider component = (FormElementCaseContainerProvider) designer.getComponentAt(e);
//切换设计器
designer.switchTab(component);
}
}
private void switchTab(MouseEvent e,EditingMouseListener editingMouseListener){
FormDesigner designer = editingMouseListener.getDesigner();
if (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR){
FormElementCaseContainerProvider component = (FormElementCaseContainerProvider) designer.getComponentAt(e);
//切换设计器
designer.switchTab(component);
}
}
@Override
public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() {

435
designer_form/src/com/fr/design/designer/creator/XLayoutContainer.java

@ -30,12 +30,12 @@ import java.util.List;
* @since 6.5.3
*/
public abstract class XLayoutContainer extends XBorderStyleWidgetCreator implements ContainerListener, ParameterBridge {
// 布局内部组件默认最小宽度36,最小高度21
public static int MIN_WIDTH = 36;
public static int MIN_HEIGHT = 21;
protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200);
// 布局内部组件默认最小宽度36,最小高度21
public static int MIN_WIDTH = 36;
public static int MIN_HEIGHT = 21;
protected static final Dimension LARGEPREFERREDSIZE = new Dimension(200, 200);
protected boolean isRefreshing;
protected int default_Length = 5; // 取指定点坐在的组件,默认为5保证取四侧相邻的组件时x、y在组件内非边框上
@ -45,6 +45,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
protected boolean editable = false;
//鼠标移动到布局画出编辑层
protected boolean isMouseEnter = false;
public void setMouseEnter(boolean mouseEnter) {
isMouseEnter = mouseEnter;
}
@ -55,12 +56,13 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
}
/**
* 得到属性名
* 得到属性名
*
* @return 属性名
* @throws IntrospectionException
*/
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[] {
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return new CRPropertyDescriptor[]{
new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter
.getLocText("FR-Designer_Form-Widget_Name")),
new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass(
@ -68,19 +70,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
Inter.getLocText("FR-Engine_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced")
.setPropertyChangeListener(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
initStyle();
}
}),
@Override
public void propertyChange() {
initStyle();
}
}),
new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class)
.setI18NName(Inter.getLocText("FR-Designer_Layout-Padding"))
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"),
};
}
};
}
/**
* 控件名属性
*
* @return
* @throws IntrospectionException
*/
@ -91,6 +94,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 边距属性
*
* @return
* @throws IntrospectionException
*/
@ -101,47 +105,50 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
}
/**
* 返回对应的wlayout
* 返回对应的wlayout
*
* @return wlayout控件
*/
public WLayout toData() {
return (WLayout) data;
}
@Override
protected void initXCreatorProperties() {
super.initXCreatorProperties();
initBorderStyle();
this.initLayoutManager();
this.convert();
}
@Override
protected void initXCreatorProperties() {
super.initXCreatorProperties();
initBorderStyle();
this.initLayoutManager();
this.convert();
}
@Override
protected JComponent initEditor() {
return this;
}
/**
* 当前组件zorder位置替换新的控件
* @param widget 控件
* @param oldcreator 旧组件
* @return 组件
*/
public XCreator replace(Widget widget, XCreator oldcreator) {
int i = this.getComponentZOrder(oldcreator);
if (i != -1) {
this.toData().replace(widget, oldcreator.toData());
this.convert();
XCreator creator = (XCreator) this.getComponent(i);
creator.setSize(oldcreator.getSize());
return creator;
}
return null;
}
/**
* 初始化时默认的组件大小
* @return 默认Dimension
protected JComponent initEditor() {
return this;
}
/**
* 当前组件zorder位置替换新的控件
*
* @param widget 控件
* @param oldcreator 旧组件
* @return 组件
*/
public XCreator replace(Widget widget, XCreator oldcreator) {
int i = this.getComponentZOrder(oldcreator);
if (i != -1) {
this.toData().replace(widget, oldcreator.toData());
this.convert();
XCreator creator = (XCreator) this.getComponent(i);
creator.setSize(oldcreator.getSize());
return creator;
}
return null;
}
/**
* 初始化时默认的组件大小
*
* @return 默认Dimension
*/
public Dimension initEditorSize() {
return LARGEPREFERREDSIZE;
@ -172,7 +179,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 设计界面中有组件添加时要通知WLayout容器重新paint
* @param e 待说明
*
* @param e 待说明
*/
@Override
public void componentAdded(ContainerEvent e) {
@ -188,7 +196,8 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 设计界面中有组件添加时要通知WLayout容器重新paint
* @param e 待说明
*
* @param e 待说明
*/
@Override
public void componentRemoved(ContainerEvent e) {
@ -203,6 +212,7 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 根据widget的属性值来获取
*
* @param wgt
* @return
*/
@ -226,30 +236,32 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
public int getXCreatorCount() {
return getComponentCount();
}
public XCreator getXCreator(int i) {
return (XCreator) getComponent(i);
}
/**
* 该组件是否可以拖入参数面板
*
* @return 是则返回true
*/
public boolean canEnterIntoParaPane(){
public boolean canEnterIntoParaPane() {
return false;
}
/**
* 是否作为控件树的叶子节点
* @return 是则返回true
*/
public boolean isComponentTreeLeaf() {
return false;
}
* 是否作为控件树的叶子节点
*
* @return 是则返回true
*/
public boolean isComponentTreeLeaf() {
return false;
}
public List<String> getAllXCreatorNameList(XCreator xCreator, List<String> namelist){
for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i);
public List<String> getAllXCreatorNameList(XCreator xCreator, List<String> namelist) {
for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i);
creatorSon.getAllXCreatorNameList(creatorSon, namelist);
}
return namelist;
@ -257,19 +269,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 是否有查询按钮
* @param xCreator 控件或容器
* @return 有无查询按钮
*
* @param xCreator 控件或容器
* @return 有无查询按钮
*/
public boolean SearchQueryCreators(XCreator xCreator) {
for (int i = 0; i < ((XLayoutContainer)xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer)xCreator).getXCreator(i);
if(creatorSon.SearchQueryCreators(creatorSon)){
for (int i = 0; i < ((XLayoutContainer) xCreator).getXCreatorCount(); i++) {
XCreator creatorSon = ((XLayoutContainer) xCreator).getXCreator(i);
if (creatorSon.SearchQueryCreators(creatorSon)) {
return true;
}
}
return false;
}
public FRLayoutManager getFRLayout() {
LayoutManager layout = getLayout();
if (layout instanceof FRLayoutManager) {
@ -279,111 +292,120 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
return null;
}
public abstract LayoutAdapter getLayoutAdapter();
public int getIndexOfChild(Object child) {
int count = getComponentCount();
for (int i = 0; i < count; i++) {
Component comp = getComponent(i);
if (comp == child) {
return i;
}
}
return -1;
}
/**
* 主要为自适应用
* 返回指定point的上方组件
* @param x x位置
* @param y y位置
* @return 指定位置的组件
*/
public Component getTopComp(int x, int y) {
return this.getComponentAt(x, y-default_Length);
}
/**
* 主要为自适应用
* 返回指定point的左方组件
* @param x x位置
* @param y y位置
* @return 指定位置的组件
*/
public Component getLeftComp(int x, int y) {
return this.getComponentAt(x-default_Length, y);
}
/**
* 返回指定point的右方组件
* @param x x位置
* @param y y位置
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightComp(int x, int y, int w) {
return this.getComponentAt(x+w+default_Length, y);
}
/**
* 返回指定point的下方组件
* @param x x位置
* @param y y位置
* @param h 高度
* @return 指定位置的组件
*/
public Component getBottomComp(int x, int y, int h) {
return this.getComponentAt(x, y+h+default_Length);
}
/**
* 返回指定point的上方且是右侧的组件
* @param x x位置
* @param y y位置
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightTopComp(int x, int y, int w) {
return this.getComponentAt(x+w-default_Length, y-default_Length);
}
/**
* 返回指定point的左方且是下侧的组件
* @param x x位置
* @param y y位置
* @param h 高度
* @return 指定位置的组件
*/
public Component getBottomLeftComp(int x, int y, int h) {
return this.getComponentAt(x-default_Length, y+h-default_Length);
}
/**
* 返回指定point的右方且是下侧的组件
* @param x x位置
* @param y y位置
* @param h 高度
* @param w 宽度
* @return 指定位置的组件
*/
public Component getBottomRightComp(int x, int y, int h, int w) {
return this.getComponentAt(x+w+default_Length, y+h-default_Length);
}
/**
* 返回指定point的下方且是右侧的组件
* @param x x位置
* @param y y位置
* @param h 高度
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightBottomComp(int x, int y, int h, int w) {
return this.getComponentAt(x+w-default_Length, y+h+default_Length);
}
public abstract LayoutAdapter getLayoutAdapter();
public int getIndexOfChild(Object child) {
int count = getComponentCount();
for (int i = 0; i < count; i++) {
Component comp = getComponent(i);
if (comp == child) {
return i;
}
}
return -1;
}
/**
* 主要为自适应用
* 返回指定point的上方组件
*
* @param x x位置
* @param y y位置
* @return 指定位置的组件
*/
public Component getTopComp(int x, int y) {
return this.getComponentAt(x, y - default_Length);
}
/**
* 主要为自适应用
* 返回指定point的左方组件
*
* @param x x位置
* @param y y位置
* @return 指定位置的组件
*/
public Component getLeftComp(int x, int y) {
return this.getComponentAt(x - default_Length, y);
}
/**
* 返回指定point的右方组件
*
* @param x x位置
* @param y y位置
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightComp(int x, int y, int w) {
return this.getComponentAt(x + w + default_Length, y);
}
/**
* 返回指定point的下方组件
*
* @param x x位置
* @param y y位置
* @param h 高度
* @return 指定位置的组件
*/
public Component getBottomComp(int x, int y, int h) {
return this.getComponentAt(x, y + h + default_Length);
}
/**
* 返回指定point的上方且是右侧的组件
*
* @param x x位置
* @param y y位置
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightTopComp(int x, int y, int w) {
return this.getComponentAt(x + w - default_Length, y - default_Length);
}
/**
* 返回指定point的左方且是下侧的组件
*
* @param x x位置
* @param y y位置
* @param h 高度
* @return 指定位置的组件
*/
public Component getBottomLeftComp(int x, int y, int h) {
return this.getComponentAt(x - default_Length, y + h - default_Length);
}
/**
* 返回指定point的右方且是下侧的组件
*
* @param x x位置
* @param y y位置
* @param h 高度
* @param w 宽度
* @return 指定位置的组件
*/
public Component getBottomRightComp(int x, int y, int h, int w) {
return this.getComponentAt(x + w + default_Length, y + h - default_Length);
}
/**
* 返回指定point的下方且是右侧的组件
*
* @param x x位置
* @param y y位置
* @param h 高度
* @param w 宽度
* @return 指定位置的组件
*/
public Component getRightBottomComp(int x, int y, int h, int w) {
return this.getComponentAt(x + w - default_Length, y + h + default_Length);
}
/**
* 是否延迟展示报表内容也就是说是否要等点击了查询之后才执行报表
*
* @return 如果是true则表示点击之后才开始计算false则表示会根据参数默认值直接计算报表并展现
*/
public boolean isDelayDisplayContent() {
@ -392,18 +414,20 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 是否显示参数界面
*
* @return 显示参数界面则返回true否则返回false
*/
public boolean isDisplay() {
return false;
}
public Background getDataBackground(){
public Background getDataBackground() {
return toData().getBackground();
}
/**
* 获取参数界面的宽度
*
* @return 宽度
*/
public int getDesignWidth() {
@ -412,83 +436,82 @@ public abstract class XLayoutContainer extends XBorderStyleWidgetCreator impleme
/**
* 获取参数面板的对齐方式
*
* @return 左中右三种对齐方式
*/
public int getPosition() {
return 0;
}
/**
* 切换到非添加状态
*
*
* @param designer 表单设计器
*/
public void stopAddingState(FormDesigner designer){
return;
}
/**
* 寻找最近的为自适应布局的父容器
*
* @return 布局容器
*
*
* @date 2014-12-30-下午3:15:28
*
*/
public XLayoutContainer findNearestFit(){
//一层一层网上找, 找到最近的fit那一层就return
XLayoutContainer parent = this.getBackupParent();
return parent == null ? null : parent.findNearestFit();
}
public void stopAddingState(FormDesigner designer) {
}
/**
* 寻找最近的为自适应布局的父容器
*
* @return 布局容器
* @date 2014-12-30-下午3:15:28
*/
public XLayoutContainer findNearestFit() {
//一层一层网上找, 找到最近的fit那一层就return
XLayoutContainer parent = this.getBackupParent();
return parent == null ? null : parent.findNearestFit();
}
/**
* 获取容器所有内部组件横坐标值
*
*
* @return 横坐标数组
*/
public int[] getHors(){
return ArrayUtils.EMPTY_INT_ARRAY;
public int[] getHors() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
/**
* 获取容器所有内部组件纵坐标值
*
*
* @return 纵坐标数组
*/
public int[] getVeris(){
return ArrayUtils.EMPTY_INT_ARRAY;
public int[] getVeris() {
return ArrayUtils.EMPTY_INT_ARRAY;
}
public void setDelayDisplayContent(boolean delayPlaying){
public void setDelayDisplayContent(boolean delayPlaying) {
}
public void setPosition(int align){
public void setPosition(int align) {
}
public void setDisplay(boolean showWindow){
public void setDisplay(boolean showWindow) {
}
public void setBackground(Background background){
public void setBackground(Background background) {
}
/**
* 布局是否可编辑不可则显示编辑蒙层
*
* @return 可否编辑
*/
public boolean isEditable(){
public boolean isEditable() {
return this.editable;
}
/**
* 设置布局是否可编辑不可则显示编辑蒙层
*
* @param isEditable 可否编辑
*/
public void setEditable(boolean isEditable){
public void setEditable(boolean isEditable) {
this.editable = isEditable;
}
}

338
designer_form/src/com/fr/design/designer/creator/cardlayout/XWCardTagLayout.java

@ -1,5 +1,5 @@
/**
*
*
*/
package com.fr.design.designer.creator.cardlayout;
@ -25,114 +25,109 @@ import com.fr.form.ui.container.cardlayout.WCardTagLayout;
import com.fr.form.ui.container.cardlayout.WTabFitLayout;
/**
*
*
* @date: 2014-11-25-下午3:11:14
*/
public class XWCardTagLayout extends XWHorizontalBoxLayout {
private static final int MIN_SIZE = 1;
private String tagName = "Tab";
private boolean switchingTab = false;
//增加一个tabNameIndex防止tabFitLayout重名
private int tabFitIndex = 0;
private CardSwitchButton currentCard;
public CardSwitchButton getCurrentCard() {
return currentCard;
}
public void setCurrentCard(CardSwitchButton currentCard) {
this.currentCard = currentCard;
}
public int getTabFitIndex() {
return tabFitIndex;
}
public void setTabFitIndex(int tabFitIndex) {
this.tabFitIndex = tabFitIndex;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
public boolean isSwitchingTab() {
return switchingTab;
}
public void setSwitchingTab(boolean switchingTab) {
this.switchingTab = switchingTab;
}
private XWCardLayout cardLayout;
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize){
super(widget, initSize);
}
/**
* 构造函数
*/
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize, XWCardLayout cardLayout) {
super(widget, initSize);
this.cardLayout = cardLayout;
}
/**
* 添加组件的监听事件
*
* @param e 事件
*
*
* @date 2014-11-25-下午6:20:10
*
*/
public void componentAdded(ContainerEvent e) {
super.componentAdded(e);
if (isSwitchingTab()){
return;
}
if(this.cardLayout == null){
initCardLayout();
}
int index = this.cardLayout.toData().getWidgetCount();
//新加一个card
String widgetName = tagName+getTabNameIndex();
WTabFitLayout fitLayout = new WTabFitLayout(widgetName,tabFitIndex,currentCard);
fitLayout.setTabNameIndex(getTabNameIndex());
XWTabFitLayout tabFitLayout = new XWTabFitLayout(fitLayout, new Dimension());
tabFitLayout.setBackupParent(cardLayout);
cardLayout.add(tabFitLayout, widgetName);
this.cardLayout.toData().setShowIndex(index);
cardLayout.showCard();
}
private void initCardLayout(){
XWCardTitleLayout titleLayout = (XWCardTitleLayout)this.getBackupParent();
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent();
this.cardLayout = borderLayout.getCardPart();
}
private static final int MIN_SIZE = 1;
private String tagName = "Tab";
private boolean switchingTab = false;
//增加一个tabNameIndex防止tabFitLayout重名
private int tabFitIndex = 0;
private CardSwitchButton currentCard;
public CardSwitchButton getCurrentCard() {
return currentCard;
}
public void setCurrentCard(CardSwitchButton currentCard) {
this.currentCard = currentCard;
}
public int getTabFitIndex() {
return tabFitIndex;
}
public void setTabFitIndex(int tabFitIndex) {
this.tabFitIndex = tabFitIndex;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
public boolean isSwitchingTab() {
return switchingTab;
}
public void setSwitchingTab(boolean switchingTab) {
this.switchingTab = switchingTab;
}
private XWCardLayout cardLayout;
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize) {
super(widget, initSize);
}
/**
* 构造函数
*/
public XWCardTagLayout(WCardTagLayout widget, Dimension initSize, XWCardLayout cardLayout) {
super(widget, initSize);
this.cardLayout = cardLayout;
}
/**
* 添加组件的监听事件
*
* @param e 事件
* @date 2014-11-25-下午6:20:10
*/
public void componentAdded(ContainerEvent e) {
super.componentAdded(e);
if (isSwitchingTab()) {
return;
}
if (this.cardLayout == null) {
initCardLayout();
}
int index = this.cardLayout.toData().getWidgetCount();
//新加一个card
String widgetName = tagName + getTabNameIndex();
WTabFitLayout fitLayout = new WTabFitLayout(widgetName, tabFitIndex, currentCard);
fitLayout.setTabNameIndex(getTabNameIndex());
XWTabFitLayout tabFitLayout = new XWTabFitLayout(fitLayout, new Dimension());
tabFitLayout.setBackupParent(cardLayout);
cardLayout.add(tabFitLayout, widgetName);
this.cardLayout.toData().setShowIndex(index);
cardLayout.showCard();
}
private void initCardLayout() {
XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent();
XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent();
this.cardLayout = borderLayout.getCardPart();
}
/**
* 将WLayout转换为XLayoutContainer
*/
public void convert() {
isRefreshing = true;
WCardTagLayout layout = (WCardTagLayout)this.toData();
WCardTagLayout layout = (WCardTagLayout) this.toData();
this.removeAll();
for (int i = 0; i < layout.getWidgetCount(); i++) {
Widget wgt = layout.getWidget(i);
@ -144,82 +139,81 @@ public class XWCardTagLayout extends XWHorizontalBoxLayout {
}
isRefreshing = false;
}
/**
* 切换到非添加状态
*
*
* @return designer 表单设计器
*/
public void stopAddingState(FormDesigner designer){
designer.stopAddingState();
return;
public void stopAddingState(FormDesigner designer) {
designer.stopAddingState();
}
//新增时去tabFitLayout名字中最大的Index+1,防止重名
private int getTabNameIndex(){
int tabNameIndex = 0;
WCardLayout layout = this.cardLayout.toData();
int size = layout.getWidgetCount();
if(size < MIN_SIZE){
return tabNameIndex;
}
for(int i=0;i<size;i++){
WTabFitLayout fitLayout = (WTabFitLayout) layout.getWidget(i);
int tempIndex = fitLayout.getTabNameIndex();
tabNameIndex = Math.max(tempIndex, tabNameIndex);
}
return ++tabNameIndex;
}
/**
* 调整tab宽度
*
* void
*/
public void adjustComponentWidth(){
}
/**
* 该布局需要隐藏无需对边框进行操作
* @param 边框
*
*/
private int getTabNameIndex() {
int tabNameIndex = 0;
WCardLayout layout = this.cardLayout.toData();
int size = layout.getWidgetCount();
if (size < MIN_SIZE) {
return tabNameIndex;
}
for (int i = 0; i < size; i++) {
WTabFitLayout fitLayout = (WTabFitLayout) layout.getWidget(i);
int tempIndex = fitLayout.getTabNameIndex();
tabNameIndex = Math.max(tempIndex, tabNameIndex);
}
return ++tabNameIndex;
}
/**
* 调整tab宽度
* <p>
* void
*/
public void adjustComponentWidth() {
}
/**
* 该布局需要隐藏无需对边框进行操作
*
* @param
*/
public void setBorder(Border border) {
return;
}
@Override
/**
* 该布局隐藏点击该布局时选中相应的tab布局主体
* @param editingMouseListener 监听
* @param e 鼠标点击事件
*
*/
public void respondClick(EditingMouseListener editingMouseListener,
MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent();
if(titleLayout != null){
XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent();
if(mainLayout != null){
XWCardLayout cardLayout = mainLayout.getCardPart();
selectionModel.setSelectedCreator(cardLayout);
}
}
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
}
}
@Override
public XLayoutContainer getTopLayout() {
return this.getBackupParent().getTopLayout();
}
}
@Override
/**
* 该布局隐藏点击该布局时选中相应的tab布局主体
* @param editingMouseListener 监听
* @param e 鼠标点击事件
*
*/
public void respondClick(EditingMouseListener editingMouseListener,
MouseEvent e) {
FormDesigner designer = editingMouseListener.getDesigner();
SelectionModel selectionModel = editingMouseListener.getSelectionModel();
XWCardTitleLayout titleLayout = (XWCardTitleLayout) this.getBackupParent();
if (titleLayout != null) {
XWCardMainBorderLayout mainLayout = (XWCardMainBorderLayout) titleLayout.getBackupParent();
if (mainLayout != null) {
XWCardLayout cardLayout = mainLayout.getCardPart();
selectionModel.setSelectedCreator(cardLayout);
}
}
if (editingMouseListener.stopEditing()) {
if (this != designer.getRootComponent()) {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
}
}
}
@Override
public XLayoutContainer getTopLayout() {
return this.getBackupParent().getTopLayout();
}
}

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

File diff suppressed because it is too large Load Diff

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

@ -15,96 +15,96 @@ import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.form.ui.Connector;
public class ConnectorHelper {
//这个类是用来画连接线的,暂时用不到
public static final int NEAR = 5;
private static double ratio = 0.5;
private final static int ADSORPTION = 15; // 吸附距离
private ArrayList<Point> drawingPoint;
private FormDesigner designer;
private boolean drawing;
//这个类是用来画连接线的,暂时用不到
public ConnectorHelper(FormDesigner formEditor) {
this.designer = formEditor;
}
public void resetConnector(Connector connector) {
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(),connector.getStartPoint(),connector.getEndPoint());
connector.addAll(cc.createPointList());
}
public boolean drawLining() {
return this.drawing;
}
public static final int NEAR = 5;
private static double ratio = 0.5;
private final static int ADSORPTION = 15; // 吸附距离
private ArrayList<Point> drawingPoint;
private FormDesigner designer;
private boolean drawing;
public void setDrawLine(boolean d) {
this.drawing = d;
}
private boolean near(Point p1, Point p2) {
return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR;
}
public ConnectorHelper(FormDesigner formEditor) {
this.designer = formEditor;
}
private Point getNearPoint(MouseEvent e, Rectangle r) {
Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y);
Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio));
Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight()));
Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio)));
Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue());
if (near(p, p1)) {
return p1;
} else if (near(p, p2)) {
return p2;
} else if (near(p, p3)) {
return p3;
} else if (near(p, p4)) {
return p4;
}
return null;
}
private ArrayList<Point> createDefalutNode(Point startPoint, Point endPoint) {
long s = System.currentTimeMillis();
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint));
ArrayList<Point> p = cc.createPointList();
long e = System.currentTimeMillis();
return p;
}
public void resetConnector(Connector connector) {
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), connector.getStartPoint(), connector.getEndPoint());
connector.addAll(cc.createPointList());
}
public void drawAuxiliaryLine(Graphics g) {
Point startPoint = designer.getStateModel().getStartPoint();
Point endPoint = designer.getStateModel().getEndPoint();
drawingPoint = createDefalutNode(startPoint, endPoint);
Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]);
g.setColor(Color.green);
for (int i = 0; i < p.length - 1; i++) {
GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y
- designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(),
p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR);
}
}
public boolean drawLining() {
return this.drawing;
}
public void createDefalutLine() {
if (drawingPoint != null
&& drawingPoint.size() > 1
&& ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > ADSORPTION) {
((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint));
}
drawingPoint = null;
}
public void setDrawLine(boolean d) {
this.drawing = d;
}
public Point getNearWidgetPoint(MouseEvent e) {
BoundsWidget widget;
Point p = null;
for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) {
widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i));
if (widget.isVisible()) {
if ((p = getNearPoint(e, widget.getBounds())) != null) {
break;
}
}
}
return p;
}
private boolean near(Point p1, Point p2) {
return p1.x - p2.x < NEAR && p2.x - p1.x < NEAR && p1.y - p2.y < NEAR && p2.y - p1.y < NEAR;
}
private Point getNearPoint(MouseEvent e, Rectangle r) {
Point p1 = new Point((int) (r.x + r.getWidth() * ratio), r.y);
Point p2 = new Point((int) (r.x + r.getWidth()), (int) (r.y + r.getHeight() * ratio));
Point p3 = new Point((int) (r.x + r.getWidth() * (1 - ratio)), (int) (r.y + r.getHeight()));
Point p4 = new Point(r.x, (int) (r.y + r.getHeight() * (1 - ratio)));
Point p = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() + designer.getArea().getVerticalValue());
if (near(p, p1)) {
return p1;
} else if (near(p, p2)) {
return p2;
} else if (near(p, p3)) {
return p3;
} else if (near(p, p4)) {
return p4;
}
return null;
}
private ArrayList<Point> createDefalutNode(Point startPoint, Point endPoint) {
long s = System.currentTimeMillis();
ConnectorCreator cc = new ConnectorCreator(designer.getTarget().getContainer(), new Point(startPoint), new Point(endPoint));
ArrayList<Point> p = cc.createPointList();
long e = System.currentTimeMillis();
return p;
}
public void drawAuxiliaryLine(Graphics g) {
Point startPoint = designer.getStateModel().getStartPoint();
Point endPoint = designer.getStateModel().getEndPoint();
drawingPoint = createDefalutNode(startPoint, endPoint);
Point[] p = drawingPoint.toArray(new Point[drawingPoint.size()]);
g.setColor(Color.green);
for (int i = 0; i < p.length - 1; i++) {
GraphHelper.drawLine(g, p[i].x - designer.getArea().getHorizontalValue(), p[i].y
- designer.getArea().getVerticalValue(), p[i + 1].x - designer.getArea().getHorizontalValue(),
p[i + 1].y - designer.getArea().getVerticalValue(), Constants.LINE_HAIR);
}
}
public void createDefalutLine() {
if (drawingPoint != null
&& drawingPoint.size() > 1
&& ConnectorCreator.getMinimumDistance(drawingPoint.get(0), drawingPoint.get(drawingPoint.size() - 1)) > ADSORPTION) {
((XWAbsoluteLayout) designer.getRootComponent()).addConnector(new Connector().addAll(drawingPoint));
}
drawingPoint = null;
}
public Point getNearWidgetPoint(MouseEvent e) {
BoundsWidget widget;
Point p = null;
for (int i = 0, size = designer.getTarget().getContainer().getWidgetCount(); i < size; i++) {
widget = ((BoundsWidget) designer.getTarget().getContainer().getWidget(i));
if (widget.isVisible()) {
if ((p = getNearPoint(e, widget.getBounds())) != null) {
break;
}
}
}
return p;
}
}

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

File diff suppressed because it is too large Load Diff

17
designer_form/src/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -43,7 +43,7 @@ public class FormCreatorDropTarget extends DropTarget {
* 当前添加模式对应的model
*/
private AddingModel addingModel;
private final static int GAP = 30;
private static final int GAP = 30;
private JWindow promptWindow = new JWindow();
private UIButton promptButton = new UIButton("", BaseUtils.readIcon(IconPathConstants.FORBID_ICON_PATH));
@ -59,10 +59,11 @@ public class FormCreatorDropTarget extends DropTarget {
XCreator hoveredComponent = designer.getComponentAt(x, y);
// 获取该组件所在的焦点容器
XLayoutContainer container = XCreatorUtils.getHotspotContainer(hoveredComponent);
//cardTagLayout里用到
container.stopAddingState(designer);
boolean success = false;
if (container != null) {
//XWCardTagLayout 切换添加状态到普通状态
container.stopAddingState(designer);
// 如果是容器,则调用其acceptComponent接受组件
AddingModel model = designer.getAddingModel();
@ -129,9 +130,7 @@ public class FormCreatorDropTarget extends DropTarget {
//提示组件是否可以拖入
promptUser(x, y, container);
if (container != null) {
dealWithContainer(x, y, container);
} else {
// 如果鼠标不在任何组件上,则取消提示器
designer.setPainter(null);
@ -197,11 +196,9 @@ public class FormCreatorDropTarget extends DropTarget {
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();
this.promptWindow.setSize(promptWindow.getPreferredSize());
this.promptWindow.setPreferredSize(promptWindow.getPreferredSize());
promptWindow.setLocation(screen_X + x + GAP, screen_Y + y + GAP);
int screenX = designer.getArea().getLocationOnScreen().x;
int screenY = designer.getArea().getLocationOnScreen().y;
promptWindow.setLocation(screenX + x + GAP, screenY + y + GAP);
promptWindow.setVisible(true);
}

245
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 有无查询按钮
*
* @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,16 +354,17 @@ 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 纵坐标
*
* @param xCreator 组件
* @param x 横坐标
* @param y 纵坐标
* @return 是否添加成功
*/
public boolean autoAddComponent(XCreator xCreator, int x, int y) {
@ -375,10 +380,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 在参数很多时全部添加的时候可以向下一次排版若去掉就会在参数面板堆到一起
*
* @param creator 组件
* @param x 长度
* @param y 长度
* @param layout 布局
* @param x 长度
* @param y 长度
* @param layout 布局
* @return 是否扩展
*/
public boolean prepareForAdd(XCreator creator, int x, int y, XWParameterLayout layout) {
@ -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();
@ -424,30 +430,33 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
/**
* 返回根节点父容器
* @return 父容器
* 返回根节点父容器
*
* @return 父容器
*/
public Component getTopContainer(){
if(rootComponent != null){
public Component getTopContainer() {
if (rootComponent != null) {
// 返回root所在的父容器,非designer
return LayoutUtils.getTopContainer(rootComponent);
}
return XCreatorUtils.createXCreator(this.getTarget().getContainer());
return XCreatorUtils.createXCreator(this.getTarget().getContainer());
}
/**
* 返回参数界面高度
* @return para高度
*
* @return para高度
*/
public int getParaHeight(){
public int getParaHeight() {
return paraHeight;
}
/**
* 重置para的高度
* @param height 高度
*
* @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 容器
*
* @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;
}
}
@ -555,7 +566,8 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
/**
* 设置是否为报表块编辑
* 设置是否为报表块编辑
*
* @param isEditing 是否为报表块编辑
*/
public void setReportBlockEditing(boolean isEditing) {
@ -564,25 +576,27 @@ 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
* @return 组件名有变化且不和其他一样返回true
*/
public boolean renameCreator(XCreator creator, String newName) {
if (ComparatorUtils.equals(creator.toData().getWidgetName(), newName)) {
@ -598,6 +612,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
return true;
}
public void showMessageDialog(String message) {
JOptionPane.showMessageDialog(this, message, Inter.getLocText("FR-Designer_Alert"), JOptionPane.WARNING_MESSAGE);
FormSelectionUtils.rebuildSelection(this);
repaint();
}
/**
* 保存参数界面的宽度
*
@ -609,16 +629,17 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 更新界面布局重绘
* @param proxy 动态代理类
*
* @param proxy 动态代理类
* @param method 接口方法
* @param args 参数
* @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 +675,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 增加组件事件
*
* @param h 动态代理
*/
public void addInvocationHandler(InvocationHandler h) {
@ -678,7 +700,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
/**
* 设置其UI类为DesignerUI负责渲染
* 设置其UI类为DesignerUI负责渲染
*/
@Override
public void updateUI() {
@ -741,15 +763,13 @@ 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) {
p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
}
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 +781,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();
@ -774,7 +794,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
refreshNorth(northWidget, formLayoutContainer);
refreshCenter(centerWidget, formLayoutContainer);
} else {
} else {
formLayoutContainer.setSize(LARGE_PREFERRED_SIZE);
setRootComponent(formLayoutContainer);
}
@ -790,9 +810,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 +861,16 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否是报表的参数面板
* @return (表单的)
*
* @return (表单的)
*/
public boolean isFormParaDesigner(){
public boolean isFormParaDesigner() {
return false;
}
/**
* 是否为底层容器
* 是否为底层容器
*
* @param comp 组件
* @return 是则返回true
*/
@ -923,10 +945,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 +963,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 拖拽准备
*
* @param xCreator 组件
*/
public void startDraggingBean(XCreator xCreator) {
@ -953,11 +976,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
/**
* 拖拽时相关处理
* @param xCreator 组件
* 拖拽时相关处理
*
* @param xCreator 组件
* @param lastPressEvent 鼠标事件
* @param x 坐标x
* @param y 坐标y
* @param x 坐标x
* @param y 坐标y
*/
public void startDraggingComponent(XCreator xCreator, MouseEvent lastPressEvent, int x, int y) {
// 根据所选择的组件的BeanInfo生成相应的AddingModel
@ -978,6 +1002,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 改变组件值
*
* @param e 组件选择事件
*/
@Override
@ -1024,6 +1049,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 是否支持权限编辑
*
* @return 是则返回true
*/
public boolean isSupportAuthority() {
@ -1048,7 +1074,8 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
}
/**
* 是否含有action名
* 是否含有action名
*
* @param name action名
* @return 有则返回true
*/
@ -1058,6 +1085,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 显示组件
*
* @param comp 组件
*/
public void makeVisible(XCreator comp) {
@ -1088,16 +1116,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 +1148,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回表单区域
*
* @return 表单区域
*/
public FormArea getArea() {
@ -1128,6 +1157,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 设置上层区域
*
* @param formArea 表单区域
*/
public void setParent(FormArea formArea) {
@ -1136,14 +1166,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 +1188,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 +1206,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 设置DrawLineMode
*
* @param mode 是or或
*/
public void setDrawLineMode(boolean mode) {
@ -1199,6 +1233,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回表单控件权限编辑pane
*
* @return 同上
*/
public AuthorityEditPane createAuthorityEditPane() {
@ -1249,6 +1284,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 粘贴
*
* @return
*/
@Override
@ -1259,6 +1295,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 剪切
*
* @return
*/
@Override
@ -1273,6 +1310,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 工具栏菜单
*
* @return 同上
*/
@Override
@ -1286,6 +1324,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 模版菜单
*
* @return 同上
*/
@Override
@ -1295,6 +1334,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 权限菜单
*
* @return 同上
*/
public ShortCut[] shortCuts4Authority() {
@ -1304,6 +1344,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
/**
* 返回ToolBarDef
*
* @return 同上
*/
@Override
@ -1313,10 +1354,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()};
}

481
designer_form/src/com/fr/design/mainframe/FormEditToolBar.java

@ -0,0 +1,481 @@
package com.fr.design.mainframe;
import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itoolbar.UIToolbar;
import com.fr.design.javascript.JavaScriptActionPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.style.background.BackgroundPane;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.widget.IconDefinePane;
import com.fr.form.ui.*;
import com.fr.form.ui.Button;
import com.fr.form.web.button.Export;
import com.fr.general.Background;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
/**
* Created by harry on 2017-3-2.
*/
public class FormEditToolBar extends BasicPane {
private JList list;
private DefaultListModel listModel;
private JPanel right;
private CardLayout card;
private ButtonPane bp;
private FormToolBarButton lastButton;
private Background background = null;
private UICheckBox defaultCheckBox;
private ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
if (lastButton != null) {
lastButton.setWidget(bp.update());
}
if (list.getSelectedValue() instanceof FormToolBarButton) {
lastButton = (FormToolBarButton) list.getSelectedValue();
if (lastButton.getWidget() instanceof Button) {
card.show(right, "button");
bp.populate(lastButton.getWidget());
} else {
bp.populate(lastButton.getWidget());
card.show(right, "none");
}
}
}
};
private ActionListener actioner = new ActionListener() {
/**
*
*/
public void actionPerformed(ActionEvent arg0) {
final BackgroundPane backgroundPane = new BackgroundPane();
BasicDialog dialog = backgroundPane.showWindow(DesignerContext.getDesignerFrame());
backgroundPane.populate(FormEditToolBar.this.background);
dialog.addDialogActionListener(new DialogActionAdapter() {
public void doOk() {
FormEditToolBar.this.background = backgroundPane.update();
if (FormEditToolBar.this.background != null) {
FormEditToolBar.this.defaultCheckBox.setSelected(false);
}
}
});
dialog.setVisible(true);
}
};
public FormEditToolBar() {
initComponent();
}
/**
* 初始化
*/
public void initComponent() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel left = FRGUIPaneFactory.createBorderLayout_S_Pane();
listModel = new DefaultListModel();
list = new JList(listModel);
list.setCellRenderer(render);
left.add(new JScrollPane(list), BorderLayout.CENTER);
if (listModel.getSize() > 0) {
list.setSelectedIndex(0);
}
ToolBarDef toolbarDef = new ToolBarDef();
toolbarDef.addShortCut(new MoveUpItemAction());
toolbarDef.addShortCut(new MoveDownItemAction());
toolbarDef.addShortCut(new RemoveAction());
UIToolbar toolBar = ToolBarDef.createJToolBar();
toolbarDef.updateToolBar(toolBar);
left.add(toolBar, BorderLayout.NORTH);
right = FRGUIPaneFactory.createCardLayout_S_Pane();
card = new CardLayout();
right.setLayout(card);
bp = new ButtonPane();
right.add("none", FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane());
right.add("button", bp);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, left, right);
// splitPane.setDividerLocation(left.getMinimumSize().width);
splitPane.setDividerLocation(120);
this.add(splitPane);
list.addListSelectionListener(listSelectionListener);
JPanel backgroundPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
UIButton bgButton = new UIButton(Inter.getLocText("FR-Designer-Output_Background_Set"));
defaultCheckBox = new UICheckBox(Inter.getLocText("FR-Designer-Output_Default_Background"));
bgButton.addActionListener(actioner);
backgroundPane.add(defaultCheckBox);
backgroundPane.add(bgButton);
backgroundPane.setBorder(BorderFactory.createTitledBorder(Inter.getLocText("FR-Designer-Output_Background_Set")));
this.add(backgroundPane, BorderLayout.SOUTH);
}
ListCellRenderer render = new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof FormToolBarButton) {
FormToolBarButton button = (FormToolBarButton) value;
this.setText(button.getNameOption().optionName());
this.setIcon(button.getNameOption().optionIcon());
}
return this;
}
};
@Override
protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer_Edit");
}
public void populate(FormToolBar ftoolbar) {
this.populate(ftoolbar, null);
}
public void populate(FormToolBar ftoolbar, FormToolBarButton button) {
if (ftoolbar == null) {
return;
}
for (int i = 0; i < ftoolbar.getButtonlist().size(); i++) {
listModel.addElement(ftoolbar.getButtonlist().get(i));
}
this.list.validate();
this.list.repaint();
if (ftoolbar.getButtonlist().size() > 0) {
this.list.setSelectedIndex(0);
}
if (button != null) {
this.list.setSelectedValue(button, true);
}
this.background = ftoolbar.getBackground();
this.defaultCheckBox.setSelected(ftoolbar.isDefault() ? true : false);
}
public FormToolBar update() {
if (this.list.getSelectedIndex() > -1) {
for (int i = 0; i < listModel.getSize(); i++) {
this.list.setSelectedIndex(i);
FormToolBarButton toolBarButton = (FormToolBarButton) this.list.getSelectedValue();
Widget widget = this.bp.update();
toolBarButton.setWidget(widget);
if (widget instanceof Button) {
String iconname = ((Button) widget).getIconName();
if (StringUtils.isNotBlank(iconname)) {
Image iimage = WidgetManager.getProviderInstance().getIconManager().getIconImage(iconname);
toolBarButton.setIcon(new ImageIcon(iimage));
}
}
}
}
java.util.List<FormToolBarButton> list = new ArrayList<FormToolBarButton>();
for (int i = 0; i < listModel.size(); i++) {
list.add((FormToolBarButton) listModel.get(i));
}
FormToolBar ftoolBar = new FormToolBar();
ftoolBar.setButtonlist(list);
ftoolBar.setDefault(this.defaultCheckBox.isSelected());
if (!ftoolBar.isDefault()) {
ftoolBar.setBackground(this.background);
}
return ftoolBar;
}
private class MoveUpItemAction extends UpdateAction {
public MoveUpItemAction() {
this.setName(Inter.getLocText("Utils-Move_Up"));
this.setMnemonic('U');
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/up.png"));
}
/**
*
*/
public void actionPerformed(ActionEvent evt) {
int selectedIndex = list.getSelectedIndex();
if (selectedIndex == -1) {
return;
}
// 上移
if (selectedIndex > 0) {
DefaultListModel listModel = (DefaultListModel) list.getModel();
Object selecteObj1 = listModel.get(selectedIndex - 1);
listModel.set(selectedIndex - 1, listModel.get(selectedIndex));
listModel.set(selectedIndex, selecteObj1);
list.setSelectedIndex(selectedIndex - 1);
list.ensureIndexIsVisible(selectedIndex - 1);
list.validate();
}
}
}
private class MoveDownItemAction extends UpdateAction {
public MoveDownItemAction() {
this.setName(Inter.getLocText("Utils-Move_Down"));
this.setMnemonic('D');
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/control/down.png"));
}
/**
*
*/
public void actionPerformed(ActionEvent evt) {
int selectedIndex = list.getSelectedIndex();
if (selectedIndex == -1) {
return;
}
// 下移
if (selectedIndex == -1) {
return;
}
if (selectedIndex < list.getModel().getSize() - 1) {
DefaultListModel listModel = (DefaultListModel) list.getModel();
Object selecteObj1 = listModel.get(selectedIndex + 1);
listModel.set(selectedIndex + 1, listModel.get(selectedIndex));
listModel.set(selectedIndex, selecteObj1);
list.setSelectedIndex(selectedIndex + 1);
list.ensureIndexIsVisible(selectedIndex + 1);
list.validate();
}
}
}
public class RemoveAction extends UpdateAction {
public RemoveAction() {
this.setName(Inter.getLocText("FR-Designer_Delete"));
this.setSmallIcon(IOUtils.readIcon("/com/fr/base/images/cell/control/remove.png"));
}
/**
* 动作
* @param e 事件
*/
public void actionPerformed(ActionEvent e) {
int i = list.getSelectedIndex();
if (i < 0 || !(listModel.getElementAt(i) instanceof FormToolBarButton)) {
return;
}
int val = JOptionPane.showConfirmDialog(FormEditToolBar.this, Inter.getLocText("FR-Designer_Are_You_Sure_To_Delete_The_Data") + "?", "Message", JOptionPane.YES_NO_OPTION);
if (val != JOptionPane.YES_OPTION) {
return;
}
listModel.removeElementAt(i);
list.validate();
if (listModel.size() > 0) {
list.setSelectedIndex(0);
} else {
card.show(right, "none");
}
}
}
public class ButtonPane extends BasicPane {
private CardLayout card;
private JPanel centerPane;
private UICheckBox icon, text, excelP, excelO;
private Widget widget;
private UITextField nameField;
private IconDefinePane iconPane;
private UIButton button;
private JavaScriptActionPane javaScriptPane;
public ButtonPane() {
this.initComponents();
}
/**
* 初始化元素
*/
public void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel north = FRGUIPaneFactory.createBorderLayout_S_Pane();
icon = new UICheckBox(Inter.getLocText("FR-Designer_Show_Icon"));
text = new UICheckBox(Inter.getLocText("FR-Designer_Show_Text"));
north.add(icon, BorderLayout.NORTH);
north.add(text, BorderLayout.CENTER);
nameField = new UITextField(8);
iconPane = new IconDefinePane();
javaScriptPane = JavaScriptActionPane.createDefault();
double p = TableLayout.PREFERRED;
double rowSize[] = {p, p};
double columnSize[] = {p, p};
Component[][] coms = new Component[][]{{new UILabel(Inter.getLocText(new String[]{"Widget", "Printer-Alias"}) + ":"), nameField}, {new UILabel(Inter.getLocText(new String[]{"Widget", "Icon"}) + ":"), iconPane}};
JPanel nameIconPane = TableLayoutHelper.createTableLayoutPane(coms, rowSize, columnSize);
north.add(nameIconPane, BorderLayout.SOUTH);
north.setBorder(BorderFactory.createTitledBorder(Inter.getLocText(new String[]{"Form-Button", "Property", "Set"})));
this.add(north, BorderLayout.NORTH);
JPanel none = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
centerPane = FRGUIPaneFactory.createCardLayout_S_Pane();
card = new CardLayout();
centerPane.setLayout(card);
centerPane.add("custom", getCustomPane());
centerPane.add("export", getExport());
centerPane.add("none", none);
this.add(centerPane, BorderLayout.CENTER);
}
private JPanel getCustomPane() {
JPanel customPane = FRGUIPaneFactory.createCenterFlowInnerContainer_S_Pane();
button = new UIButton(Inter.getLocText("FR-Designer_User_Defined_Event"));
customPane.add(button);
customPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("FR-Designer_Edit") + "JS", null));
button.addActionListener(l);
return customPane;
}
private JPanel getExport() {
JPanel export = FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane();
// export.setLayout(new BoxLayout(export, BoxLayout.Y_AXIS));
excelP = new UICheckBox(Inter.getLocText("FR-Designer-Output_Excel_Page"));
excelO = new UICheckBox(Inter.getLocText("FR-Designer-Output_Excel_Simple"));
export.add(excelP);
export.add(Box.createVerticalStrut(2));
export.add(excelO);
export.add(Box.createVerticalStrut(2));
export.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText(new String[]{"Form-Button", "Property", "Set"}), null));
return export;
}
@Override
protected String title4PopupWindow() {
return "Button";
}
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!(widget instanceof CustomToolBarButton)) {
return;
}
if (javaScriptPane == null || ((CustomToolBarButton)widget).getJSImpl() == null) {
javaScriptPane = JavaScriptActionPane.createDefault();
}
javaScriptPane.setPreferredSize(new Dimension(750, 500));
BasicDialog dialog = javaScriptPane.showWindow(SwingUtilities.getWindowAncestor(ButtonPane.this));
dialog.addDialogActionListener(new DialogActionAdapter() {
@Override
public void doOk() {
((CustomToolBarButton) widget).setJSImpl(javaScriptPane.updateBean());
}
});
dialog.setVisible(true);
}
};
/**
* 更新
* @param widget 对应组件
*/
public void populate(Widget widget) {
this.widget = widget;
card.show(centerPane, "none");
if (widget instanceof Button) {
populateDefault();
}
if (widget instanceof Export) {
populateExport();
} else if (widget instanceof CustomToolBarButton) {
populateCustomToolBarButton();
}
}
private void populateExport(){
card.show(centerPane, "export");
Export export = (Export) widget;
this.excelP.setSelected(export.isExcelPAvailable());
this.excelO.setSelected(export.isExcelOAvailable());
}
private void populateCustomToolBarButton(){
card.show(centerPane, "custom");
CustomToolBarButton customToolBarButton = (CustomToolBarButton) widget;
if (customToolBarButton.getJSImpl() != null) {
this.javaScriptPane.populateBean(customToolBarButton.getJSImpl());
}
}
private void populateDefault(){
Button button = (Button) widget;
this.icon.setSelected(button.isShowIcon());
this.text.setSelected(button.isShowText());
this.nameField.setText(button.getText());
this.iconPane.populate(((Button) widget).getIconName());
}
/**
* 更新
*
* @return 对应组件
*/
public Widget update() {
if (widget instanceof Export) {
updateExport();
} else if (widget instanceof CustomToolBarButton) {
((CustomToolBarButton) widget).setJSImpl(this.javaScriptPane.updateBean());
}
if (widget instanceof Button) {
updateDefault();
}
return widget;
}
private void updateDefault(){
((Button) widget).setShowIcon(this.icon.isSelected());
((Button) widget).setShowText(this.text.isSelected());
((Button) widget).setText(this.nameField.getText());
((Button) widget).setIconName(this.iconPane.update());
}
private void updateExport(){
Export export = (Export) widget;
export.setExcelPAvailable(this.excelP.isSelected());
export.setExcelOAvailable(this.excelO.isSelected());
}
}
}

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

@ -8,300 +8,312 @@ import com.fr.base.FRContext;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.creator.XComponent;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer;
import com.fr.design.designer.creator.XWAbsoluteLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.*;
import com.fr.form.ui.Widget;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
public class FormSelection {
private ArrayList<XCreator> selection;
private Rectangle backupBounds;
private ArrayList<Rectangle> recs = new ArrayList<Rectangle>();
public FormSelection() {
selection = new ArrayList<XCreator>();
}
/**
* 重置选中的组件
*/
public void reset() {
selection.clear();
}
/**
* 是否没有选中的组件
* @return 为空返回true
*/
public boolean isEmpty() {
return selection.isEmpty();
}
/**
* 选中的组件数量
* @return 选中的组件数量
*/
public int size() {
return selection.size();
}
/**
* 去除选中的组件中指定组件
* @param creator 待去除组件
*/
public void removeCreator(XCreator creator) {
selection.remove(creator);
}
/**
* 是否成功删除选择的组件
* @param comp 组件
* @return 是则返回true
*/
public boolean removeSelectedCreator(XCreator comp) {
if (selection.size() > 1 && selection.contains(comp)) {
removeCreator(comp);
return true;
}
return false;
}
/**
* 成功增加选中的组件
* @param creator 组件
* @return 成功增加返回true
*/
public boolean addSelectedCreator(XCreator creator) {
if (addedable(creator)) {
selection.add(creator);
return true;
}
return false;
}
/**
* 是否是可以增加的
* @param creator 组件
* @return 是则返回true
*/
public boolean addedable(XCreator creator) {
if (selection.isEmpty()) {
return true;
}
XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(creator);
if (!(container instanceof XWAbsoluteLayout)) {
return false;
}
for (XCreator selected : selection) {
if (selected == creator || XCreatorUtils.getParentXLayoutContainer(selected) != container) {
return false;
}
}
return true;
}
/**
* 返回选中的第一个组件为空返回null
* @return 返回选中组件
*/
public XCreator getSelectedCreator() {
return !selection.isEmpty() ? selection.get(0) : null;
}
/**
* 返回选中的所有组件
* @return 所有组件s
*/
public XCreator[] getSelectedCreators() {
return selection.toArray(new XCreator[selection.size()]);
}
public Widget[] getSelectedWidgets() {
Widget[] selectWidget = new Widget[selection.size()];
for (int i = 0; i < selection.size(); i++) {
selectWidget[i] = selection.get(i).toData();
}
return selectWidget;
}
public void setSelectedCreator(XCreator creator) {
reset();
selection.add(creator);
}
public void setSelectedCreators(ArrayList<XCreator> selections) {
reset();
for (XCreator creator : selections) {
if (addedable(creator)) {
selection.add(creator);
}
}
}
/**
* 是否包含当前控件
* @param widget 控件
* @return 是则返回true
*/
public boolean contains(Widget widget) {
for (XCreator creator : selection) {
if (creator.toData() == widget) {
return true;
}
}
return false;
}
public int[] getDirections() {
if (this.selection.size() > 1) {
return Direction.ALL;
} else if (this.selection.size() == 1) {
return this.selection.get(0).getDirections();
} else {
return new int[0];
}
}
/**
* 备份组件的bound
*/
public void backupBounds() {
backupBounds = getRelativeBounds();
recs.clear();
for (XComponent comp : selection) {
recs.add(comp.getBounds());
}
}
public Rectangle getBackupBounds() {
return backupBounds;
}
public Rectangle getRelativeBounds() {
Rectangle bounds = getSelctionBounds();
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0));
if (parent == null) {
return bounds;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
bounds.x += rec.x;
bounds.y += rec.y;
return bounds;
}
public Rectangle getSelctionBounds() {
if(selection.isEmpty()) {
return new Rectangle();
}
Rectangle bounds = selection.get(0).getBounds();
for (int i = 1, len = selection.size(); i < len; i++) {
bounds = bounds.union(selection.get(i).getBounds());
}
return bounds;
}
public void setSelectionBounds(Rectangle rec, FormDesigner designer) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0));
Rectangle backupBounds = new Rectangle(this.backupBounds);
if (parent != null) {
Rectangle r = ComponentUtils.getRelativeBounds(parent);
rec.x -= r.x;
rec.y -= r.y;
backupBounds.x -= r.x;
backupBounds.y -= r.y;
}
int size = selection.size();
if (size == 1) {
XCreator creator = selection.get(0);
creator.setBounds(rec);
if(creator.acceptType(XWParameterLayout.class)){
designer.setParaHeight((int)rec.getHeight());
private ArrayList<XCreator> selection;
private Rectangle backupBounds;
private ArrayList<Rectangle> recs = new ArrayList<Rectangle>();
public FormSelection() {
selection = new ArrayList<XCreator>();
}
/**
* 重置选中的组件
*/
public void reset() {
selection.clear();
}
/**
* 是否没有选中的组件
*
* @return 为空返回true
*/
public boolean isEmpty() {
return selection.isEmpty();
}
/**
* 选中的组件数量
*
* @return 选中的组件数量
*/
public int size() {
return selection.size();
}
/**
* 去除选中的组件中指定组件
*
* @param creator 待去除组件
*/
public void removeCreator(XCreator creator) {
selection.remove(creator);
}
/**
* 是否成功删除选择的组件
*
* @param comp 组件
* @return 是则返回true
*/
public boolean removeSelectedCreator(XCreator comp) {
if (selection.size() > 1 && selection.contains(comp)) {
removeCreator(comp);
return true;
}
return false;
}
/**
* 成功增加选中的组件
*
* @param creator 组件
* @return 成功增加返回true
*/
public boolean addSelectedCreator(XCreator creator) {
if (addedable(creator)) {
selection.add(creator);
return true;
}
return false;
}
/**
* 是否是可以增加的
*
* @param creator 组件
* @return 是则返回true
*/
public boolean addedable(XCreator creator) {
if (selection.isEmpty()) {
return true;
}
XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(creator);
if (!(container instanceof XWAbsoluteLayout)) {
return false;
}
for (XCreator selected : selection) {
if (selected == creator || XCreatorUtils.getParentXLayoutContainer(selected) != container) {
return false;
}
}
return true;
}
/**
* 返回选中的第一个组件为空返回null
*
* @return 返回选中组件
*/
public XCreator getSelectedCreator() {
return !selection.isEmpty() ? selection.get(0) : null;
}
/**
* 返回选中的所有组件
*
* @return 所有组件s
*/
public XCreator[] getSelectedCreators() {
return selection.toArray(new XCreator[selection.size()]);
}
public Widget[] getSelectedWidgets() {
Widget[] selectWidget = new Widget[selection.size()];
for (int i = 0; i < selection.size(); i++) {
selectWidget[i] = selection.get(i).toData();
}
return selectWidget;
}
public void setSelectedCreator(XCreator creator) {
reset();
selection.add(creator);
}
public void setSelectedCreators(ArrayList<XCreator> selections) {
reset();
for (XCreator creator : selections) {
if (addedable(creator)) {
selection.add(creator);
}
}
}
/**
* 是否包含当前控件
*
* @param widget 控件
* @return 是则返回true
*/
public boolean contains(Widget widget) {
for (XCreator creator : selection) {
if (creator.toData() == widget) {
return true;
}
}
return false;
}
public int[] getDirections() {
if (this.selection.size() > 1) {
return Direction.ALL;
} else if (this.selection.size() == 1) {
return this.selection.get(0).getDirections();
} else {
return new int[0];
}
}
/**
* 备份组件的bound
*/
public void backupBounds() {
backupBounds = getRelativeBounds();
recs.clear();
for (XComponent comp : selection) {
recs.add(comp.getBounds());
}
}
public Rectangle getBackupBounds() {
return backupBounds;
}
public Rectangle getRelativeBounds() {
Rectangle bounds = getSelctionBounds();
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0));
if (parent == null) {
return bounds;
}
Rectangle rec = ComponentUtils.getRelativeBounds(parent);
bounds.x += rec.x;
bounds.y += rec.y;
return bounds;
}
public Rectangle getSelctionBounds() {
if (selection.isEmpty()) {
return new Rectangle();
}
Rectangle bounds = selection.get(0).getBounds();
for (int i = 1, len = selection.size(); i < len; i++) {
bounds = bounds.union(selection.get(i).getBounds());
}
return bounds;
}
public void setSelectionBounds(Rectangle rec, FormDesigner designer) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(selection.get(0));
Rectangle backupBounds = new Rectangle(this.backupBounds);
if (parent != null) {
Rectangle r = ComponentUtils.getRelativeBounds(parent);
rec.x -= r.x;
rec.y -= r.y;
backupBounds.x -= r.x;
backupBounds.y -= r.y;
}
int size = selection.size();
if (size == 1) {
XCreator creator = selection.get(0);
creator.setBounds(rec);
if (creator.acceptType(XWParameterLayout.class)) {
designer.setParaHeight((int) rec.getHeight());
designer.getArea().doLayout();
}
LayoutUtils.layoutContainer(creator);
} else if (size > 1) {
for (int i = 0; i < selection.size(); i++) {
Rectangle newBounds = new Rectangle(recs.get(i));
newBounds.x = rec.x + (newBounds.x - backupBounds.x) * rec.width / backupBounds.width;
newBounds.y = rec.y + (newBounds.y - backupBounds.y) * rec.height / backupBounds.height;
newBounds.width = rec.width * newBounds.width / backupBounds.width;
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());
LayoutUtils.layoutContainer(creator);
} else if (size > 1) {
for (int i = 0; i < selection.size(); i++) {
Rectangle newBounds = new Rectangle(recs.get(i));
newBounds.x = rec.x + (newBounds.x - backupBounds.x) * rec.width / backupBounds.width;
newBounds.y = rec.y + (newBounds.y - backupBounds.y) * rec.height / backupBounds.height;
newBounds.width = rec.width * newBounds.width / backupBounds.width;
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());
designer.getArea().doLayout();
}
}
LayoutUtils.layoutRootContainer(designer.getRootComponent());
}
}
/**
* 调整组件大小
* @param designer 设计界面组件
*/
public void fixCreator(FormDesigner designer) {
for (XCreator creator : selection) {
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter != null) {
creator.setBackupBound(backupBounds);
layoutAdapter.fix(creator);
}
}
}
private void removeCreatorFromContainer(XCreator creator) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator);
if (parent == null) {
return;
}
// 删除其根组件,同时就删除了同时被选择的叶子组件
parent.remove(creator);
LayoutManager layout = parent.getLayout();
if (layout != null) {
// 刷新组件容器的布局
LayoutUtils.layoutContainer(parent);
}
}
/**
* 剪切选中的所有组件
* @param clipBoard 剪切板
*/
public void cut2ClipBoard(FormSelection clipBoard) {
clipBoard.reset();
clipBoard.selection.addAll(selection);
for (XCreator creator : selection) {
removeCreatorFromContainer(creator);
}
reset();
}
/**
* 复制选中的所有组件
* @param clipBoard 复制板
*/
public void copy2ClipBoard(FormSelection clipBoard) {
clipBoard.reset();
for (XCreator root : selection) {
try {
XCreator creator = XCreatorUtils.createXCreator((Widget) root.toData().clone());
creator.setBounds(root.getBounds());
clipBoard.selection.add(creator);
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
}
LayoutUtils.layoutRootContainer(designer.getRootComponent());
}
}
/**
* 调整组件大小
*
* @param designer 设计界面组件
*/
public void fixCreator(FormDesigner designer) {
for (XCreator creator : selection) {
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter != null) {
creator.setBackupBound(backupBounds);
layoutAdapter.fix(creator);
}
}
}
private void removeCreatorFromContainer(XCreator creator) {
XLayoutContainer parent = XCreatorUtils.getParentXLayoutContainer(creator);
if (parent == null) {
return;
}
boolean changeCreator = creator.shouldScaleCreator() || creator.hasTitleStyle();
if (parent.acceptType(XWFitLayout.class) && changeCreator) {
creator = (XCreator) creator.getParent();
}
parent.getLayoutAdapter().removeBean(creator, creator.getWidth(), creator.getHeight());
// 删除其根组件,同时就删除了同时被选择的叶子组件
parent.remove(creator);
LayoutManager layout = parent.getLayout();
if (layout != null) {
// 刷新组件容器的布局
LayoutUtils.layoutContainer(parent);
}
}
/**
* 剪切选中的所有组件
*
* @param clipBoard 剪切板
*/
public void cut2ClipBoard(FormSelection clipBoard) {
clipBoard.reset();
clipBoard.selection.addAll(selection);
for (XCreator creator : selection) {
removeCreatorFromContainer(creator);
}
reset();
}
/**
* 复制选中的所有组件
*
* @param clipBoard 复制板
*/
public void copy2ClipBoard(FormSelection clipBoard) {
clipBoard.reset();
for (XCreator root : selection) {
try {
XCreator creator = XCreatorUtils.createXCreator((Widget) root.toData().clone());
creator.setBounds(root.getBounds());
clipBoard.selection.add(creator);
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
}
}

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

@ -1,126 +1,253 @@
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.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.form.ui.Widget;
public class FormSelectionUtils {
public static void paste2Container(FormDesigner designer, XLayoutContainer parent, FormSelection selection, int x,
int y) {
LayoutAdapter adapter = parent.getLayoutAdapter();
if (selection.size() == 1) {
try {
XCreator creator = selection.getSelectedCreator();
Widget cloned = new ClonedWidgetCreator(designer.getTarget()).clonedWidgetWithNoRepeatName(creator
.toData());
XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize());
if (adapter.addBean(clondCreator, x + clondCreator.getWidth() / 2, y + clondCreator.getHeight() / 2)) {
designer.getSelectionModel().getSelection().setSelectedCreator(clondCreator);
designer.getEditListenerTable().fireCreatorModified(clondCreator, DesignerEvent.CREATOR_PASTED);
return;
}
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
} else if (selection.size() > 1) {
if (parent instanceof XWAbsoluteLayout) {
designer.getSelectionModel().getSelection().reset();
Rectangle rec = selection.getSelctionBounds();
for (XCreator creator : selection.getSelectedCreators()) {
try {
Widget cloned = new ClonedWidgetCreator(designer.getTarget())
.clonedWidgetWithNoRepeatName(creator.toData());
XCreator clondCreator = XCreatorUtils.createXCreator(cloned, creator.getSize());
// 设置位置,移动20x20,防止被粘帖的组件重叠,照顾表单布局情况下
adapter.addBean(clondCreator, x + creator.getX() - rec.x + clondCreator.getWidth() / 2, y
+ creator.getY() - rec.y + clondCreator.getHeight() / 2);
designer.getSelectionModel().getSelection().addSelectedCreator(clondCreator);
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
designer.getEditListenerTable().fireCreatorModified(
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED);
return;
}
}
Toolkit.getDefaultToolkit().beep();
}
public static void rebuildSelection(FormDesigner designer) {
ArrayList<XCreator> newSelection = new ArrayList<XCreator>();
List<Widget> widgetList = new ArrayList<Widget>();
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) {
widgetList.add(comp.toData());
}
designer.getSelectionModel().setSelectedCreators(
rebuildSelection(designer.getRootComponent(), widgetList, newSelection));
}
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) {
List<Widget> selectionWidget = new ArrayList<Widget>();
if(selectWidgets != null){
selectionWidget.addAll(Arrays.asList(selectWidgets));
}
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>());
}
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,
ArrayList<XCreator> newSelection) {
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection);
if (newSelection.isEmpty()) {
newSelection.add(rootComponent);
}
return newSelection;
}
private static void _rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
if (selectionWidget.isEmpty()) {
return;
}
for (Widget x : selectionWidget) {
if (ComparatorUtils.equals(x, root.toData())) {
if (!newSelection.contains(root)) {
newSelection.add(root);
selectionWidget.remove(x);
}
break;
}
}
int count = root.getComponentCount();
for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) {
Component c = root.getComponent(i);
if (c instanceof XCreator) {
XCreator creator = (XCreator) c;
for (Widget x : selectionWidget) {
if (ComparatorUtils.equals(x, creator.toData())) {
newSelection.add(creator);
selectionWidget.remove(x);
break;
}
}
if (c instanceof XLayoutContainer) {
_rebuild((XLayoutContainer) c, selectionWidget, newSelection);
} else {
continue;
}
}
}
}
package com.fr.design.mainframe;
import com.fr.base.FRContext;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRTabFitLayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.designer.creator.*;
import com.fr.design.utils.ComponentUtils;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FormSelectionUtils {
//组件复制时坐标偏移
private static final int DELAY_X_Y = 20;
//组件重命名后缀
private static final String POSTFIX = "_c";
private FormSelectionUtils() {
}
/**
* 粘贴到容器
*/
public static void paste2Container(FormDesigner designer, XLayoutContainer parent,
FormSelection clipboard, int x, int y) {
LayoutAdapter adapter = parent.getLayoutAdapter();
if (parent instanceof XWAbsoluteLayout) {
//绝对布局
absolutePaste(designer, clipboard, adapter, x, y);
return;
} else if (parent instanceof XWFitLayout) {
//相对布局
relativePaste(designer, clipboard, adapter, x, y);
return;
}
Toolkit.getDefaultToolkit().beep();
}
/**
* 绝对布局粘贴
*/
private static void absolutePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
designer.getSelectionModel().getSelection().reset();
Rectangle rec = clipboard.getSelctionBounds();
for (XCreator creator : clipboard.getSelectedCreators()) {
try {
Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
// 获取位置
Point point = getPasteLocation((AbstractLayoutAdapter) adapter,
copiedCreator,
x + creator.getX() - rec.x + copiedCreator.getWidth() / 2,
y + creator.getY() - rec.y + copiedCreator.getHeight() / 2);
if (!adapter.accept(copiedCreator, point.x, point.y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Large_To_Paste"));
return;
}
boolean addSuccess = adapter.addBean(copiedCreator, point.x, point.y);
if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
}
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED);
}
/**
* 相对布局粘贴
*/
private static void relativePaste(FormDesigner designer, FormSelection clipboard, LayoutAdapter adapter, int x, int y) {
//@see FRTabFitLayoutAdapter
Rectangle tabContainerRect = ComponentUtils.getRelativeBounds(designer.getSelectionModel().getSelection()
.getSelectedCreator().getParent());
designer.getSelectionModel().getSelection().reset();
for (XCreator creator : clipboard.getSelectedCreators()) {
try {
Widget copied = copyWidget(designer, creator);
XCreator copiedCreator = XCreatorUtils.createXCreator(copied, creator.getSize());
if (adapter.getClass().equals(FRTabFitLayoutAdapter.class)) {
if (!adapter.accept(copiedCreator, x - tabContainerRect.x, y - tabContainerRect.y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
} else {
if (!adapter.accept(copiedCreator, x, y)) {
designer.showMessageDialog(Inter.getLocText("FR-Designer_Too_Small_To_Paste"));
return;
}
}
boolean addSuccess = adapter.addBean(copiedCreator, x, y);
if (addSuccess) {
designer.getSelectionModel().getSelection().addSelectedCreator(copiedCreator);
}
} catch (CloneNotSupportedException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
rebuildSelection(designer);
designer.getEditListenerTable().fireCreatorModified(
designer.getSelectionModel().getSelection().getSelectedCreator(), DesignerEvent.CREATOR_PASTED);
}
/**
* 组件复用绝对布局获取粘贴组件位置
*/
private static Point getPasteLocation(AbstractLayoutAdapter layoutAdapter, XCreator copiedCreator, int x, int y) {
//当宽度为奇数时 设置偏移
int xoffset = (copiedCreator.getWidth() & 1) == 1 ? 1 : 0;
//当高度为奇数时 设置偏移
int yoffset = (copiedCreator.getHeight() & 1) == 1 ? 1 : 0;
if (!layoutAdapter.accept(copiedCreator, x, y)) {
XLayoutContainer container = layoutAdapter.getContainer();
boolean xOut = x < 0 || x + copiedCreator.getWidth() / 2 + xoffset > container.getWidth();
boolean yOut = y < 0 || y + copiedCreator.getHeight() / 2 + yoffset > container.getHeight();
/*
* 组件原始位置位于布局的右下角
* 和布局右下边界线紧挨
* 粘贴时组件在原始位置向左错开20像素
* x,y同时越界
*/
if (xOut && yOut) {
//向左偏移
x = container.getWidth() - copiedCreator.getWidth() / 2 - DELAY_X_Y - xoffset;
//紧贴下边界
y = container.getHeight() - copiedCreator.getHeight() / 2 - yoffset;
return new Point(x, y);
}
/*
* 组件原始位置与布局边界距离小于20像素下边界&右边界同时小于或者任意一个边界小于
* 则粘贴时距离小于20像素一侧直接贴近布局边界
* 距离大于20像素的一侧正常错开
* x,y中只有一个越界
*/
if ((xOut || yOut)) {
x = xOut ? container.getWidth() - copiedCreator.getWidth() / 2 - xoffset : x;
y = yOut ? container.getHeight() - copiedCreator.getHeight() / 2 - yoffset : y;
return new Point(x, y);
}
}
return new Point(x, y);
}
/**
* 拷贝组件
*/
private static Widget copyWidget(FormDesigner formDesigner, XCreator xCreator) throws
CloneNotSupportedException {
ArrayList<String> nameSpace = new ArrayList<>();
Widget copied = (Widget) xCreator.toData().clone();
//重命名拷贝的组件
String name = getCopiedName(formDesigner, copied, nameSpace);
if (copied instanceof WTitleLayout) {
XWTitleLayout xwTitleLayout = new XWTitleLayout((WTitleLayout) copied, xCreator.getSize());
xwTitleLayout.resetCreatorName(name);
} else {
copied.setWidgetName(name);
}
return copied;
}
/**
* 组件拷贝命名规则
*/
private static String getCopiedName(FormDesigner formDesigner, Widget copied, ArrayList<String> nameSpace) {
StringBuilder name = new StringBuilder(copied.getWidgetName());
do {
name.append(POSTFIX);
} while (formDesigner.getTarget().isNameExist(name.toString()) || nameSpace.contains(name.toString()));
nameSpace.add(name.toString());
return name.toString();
}
public static void rebuildSelection(FormDesigner designer) {
ArrayList<XCreator> newSelection = new ArrayList<>();
List<Widget> widgetList = new ArrayList<>();
for (XCreator comp : designer.getSelectionModel().getSelection().getSelectedCreators()) {
widgetList.add(comp.toData());
}
designer.getSelectionModel().setSelectedCreators(
rebuildSelection(designer.getRootComponent(), widgetList, newSelection));
}
public static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, Widget[] selectWidgets) {
List<Widget> selectionWidget = new ArrayList<>();
if (selectWidgets != null) {
selectionWidget.addAll(Arrays.asList(selectWidgets));
}
return FormSelectionUtils.rebuildSelection(rootComponent, selectionWidget, new ArrayList<XCreator>());
}
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,
ArrayList<XCreator> newSelection) {
FormSelectionUtils.rebuild(rootComponent, selectionWidget, newSelection);
if (newSelection.isEmpty()) {
newSelection.add(rootComponent);
}
return newSelection;
}
private static void rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
if (selectionWidget.isEmpty()) {
return;
}
for (Widget x : selectionWidget) {
if (ComparatorUtils.equals(x, root.toData())) {
if (!newSelection.contains(root)) {
newSelection.add(root);
selectionWidget.remove(x);
}
break;
}
}
int count = root.getComponentCount();
for (int i = 0; i < count && !selectionWidget.isEmpty(); i++) {
Component c = root.getComponent(i);
if (c instanceof XCreator) {
XCreator creator = (XCreator) c;
for (Widget x : selectionWidget) {
if (ComparatorUtils.equals(x, creator.toData())) {
newSelection.add(creator);
selectionWidget.remove(x);
break;
}
}
if (c instanceof XLayoutContainer) {
rebuild((XLayoutContainer) c, selectionWidget, newSelection);
}
}
}
}
}

84
designer_form/src/com/fr/design/mainframe/FormSettingToolBar.java

@ -0,0 +1,84 @@
package com.fr.design.mainframe;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by harry on 2017-3-2.
*/
public class FormSettingToolBar extends JPanel {
private Icon setIcon = IOUtils.readIcon("com/fr/design/images/toolbarbtn/toolbarbtnsetting.png");
private Icon delIcon = IOUtils.readIcon("com/fr/design/images/toolbarbtn/toolbarbtnclear.png");
private UIButton setButton;
private UIButton delButton;
private FormToolBarPane toolBarPane;
public FormSettingToolBar(String name, FormToolBarPane toolBarPane) {
super();
this.setBackground(Color.lightGray);
this.add(new UILabel(name));
this.toolBarPane = toolBarPane;
setButton = GUICoreUtils.createTransparentButton(setIcon, setIcon, setIcon);
setButton.setToolTipText(Inter.getLocText("FR-Designer_Edit_Button_ToolBar"));
setButton.setAction(new SetAction());
delButton = GUICoreUtils.createTransparentButton(delIcon, delIcon, delIcon);
delButton.setToolTipText(Inter.getLocText("FR-Designer_Remove_Button_ToolBar"));
delButton.setAction(new DelAction());
this.add(setButton);
this.add(delButton);
}
public void setEnabled(boolean b) {
setButton.setEnabled(b);
delButton.setEnabled(b);
}
public void addActionListener(ActionListener l){
setButton.addActionListener(l);
delButton.addActionListener(l);
}
private class SetAction extends AbstractAction {
public SetAction() {
this.putValue(Action.SMALL_ICON, setIcon);
}
@Override
public void actionPerformed(ActionEvent arg0) {
final FormEditToolBar tb = new FormEditToolBar();
tb.populate(toolBarPane.getFToolBar());
BasicDialog dialog = tb.showWindow(DesignerContext.getDesignerFrame());
dialog.addDialogActionListener(new DialogActionAdapter() {
public void doOk() {
toolBarPane.setFToolBar(tb.update());
}
});
dialog.setVisible(true);
}
}
private class DelAction extends AbstractAction {
public DelAction() {
this.putValue(Action.SMALL_ICON, delIcon);
}
@Override
public void actionPerformed(ActionEvent arg0) {
toolBarPane.removeAll();
toolBarPane.removeButtonList();
toolBarPane.repaint();
}
}
}

68
designer_form/src/com/fr/design/mainframe/FormToolBar.java

@ -0,0 +1,68 @@
package com.fr.design.mainframe;
import com.fr.form.ui.ToolBar;
import com.fr.form.ui.Widget;
import com.fr.general.Background;
import java.util.ArrayList;
import java.util.List;
/**
* Created by harry on 2017-3-2.
*/
public class FormToolBar {
private List<FormToolBarButton> buttonlist = new ArrayList<FormToolBarButton>();
private Background background = null;
private boolean isDefault = true;
public List<FormToolBarButton> getButtonlist() {
return buttonlist;
}
public void setButtonlist(List<FormToolBarButton> buttonlist) {
if (buttonlist == null || buttonlist.size() < 0) {
this.buttonlist = new ArrayList<FormToolBarButton>();
} else {
this.buttonlist = buttonlist;
}
}
public void addButton(FormToolBarButton toolBarButton) {
this.buttonlist.add(toolBarButton);
}
public void removeButton(FormToolBarButton toolBarButton) {
this.buttonlist.remove(toolBarButton);
}
public void clearButton() {
this.buttonlist.clear();
}
public Background getBackground() {
return background;
}
public void setBackground(Background background) {
this.background = background;
}
public boolean isDefault() {
return isDefault;
}
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}
public ToolBar getToolBar() {
Widget[] widgets = new Widget[this.getButtonlist().size()];
for (int j = 0; j < this.getButtonlist().size(); j++) {
widgets[j] = this.getButtonlist().get(j).getWidget();
}
ToolBar toolBar = new ToolBar(widgets);
toolBar.setBackground(this.background);
toolBar.setDefault(this.isDefault);
return toolBar;
}
}

164
designer_form/src/com/fr/design/mainframe/FormToolBarButton.java

@ -0,0 +1,164 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.core.WidgetOption;
import com.fr.design.roleAuthority.ReportAndFSManagePane;
import com.fr.design.utils.gui.GUIPaintUtils;
import com.fr.form.ui.Widget;
import com.fr.form.ui.WidgetManager;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* Created by harry on 2017-3-2.
*/
public class FormToolBarButton extends JButton implements MouseListener {
private Widget widget;
private WidgetOption widgetOption;
public FormToolBarButton(Icon icon, Widget widget) {
this(null, icon, widget);
}
public FormToolBarButton(String text, Icon icon, Widget widget) {
super(text, icon);
setBackground(null);
setRolloverEnabled(true);
this.widget = widget;
if (widget instanceof com.fr.form.ui.Button) {
com.fr.form.ui.Button button = (com.fr.form.ui.Button) widget;
String iconName = button.getIconName();
if (StringUtils.isNotEmpty(iconName)) {
Image iimage = WidgetManager.getProviderInstance().getIconManager().getIconImage(iconName);
if (iimage != null) {
setIcon(new ImageIcon(iimage));
}
}
}
this.addMouseListener(this);
setMargin(new Insets(0, 0, 0, 0));
}
/**
* 改变按钮的权限细粒度状态
*
* @param selectedRole 选择的角色
* @param isVisible 是否可见
*/
public void changeAuthorityState(String selectedRole, boolean isVisible) {
this.widget.changeOnlyVisibleAuthorityState(selectedRole, isVisible);
}
/**
* 是都做过权限细粒度
*
* @param role 选择的角色
* @return 若是对应的该角色做过权限细粒度则返回true
*/
public boolean isDoneAuthorityEdited(String role) {
return this.widget.isDoneVisibleAuthority(role);
}
public Widget getWidget() {
return this.widget;
}
public void setWidget(Widget widget) {
this.widget = widget;
}
public WidgetOption getNameOption() {
return this.widgetOption;
}
public void setNameOption(WidgetOption widgetOption) {
this.widgetOption = widgetOption;
}
protected void paintBorder(Graphics g) {
paintBorder(g, this);
}
protected void paintBorder(Graphics g, FormToolBarButton b) {
String selectedRoles = ReportAndFSManagePane.getInstance().getRoleTree().getSelectedRoleName();
GUIPaintUtils.drawBorder((Graphics2D) g, 0, 0, b.getWidth(), b.getHeight(), true, Constants.NULL, b.isDoneAuthorityEdited(selectedRoles));
}
/**
* 处理鼠标点击事件
*
* @param e 鼠标点击事件
*/
public void mouseClicked(MouseEvent e) {
//该button只在报表块工具栏中使用,
//parent只有FormToolBarPane一种,故可以直接强转
final FormToolBarPane toolBarPane = (FormToolBarPane) this.getParent();
if (BaseUtils.isAuthorityEditing()) {
auhtorityMouseAction();
return;
}
if (e.getClickCount() >= 2) {
final FormEditToolBar editToolBar = new FormEditToolBar();
editToolBar.populate(toolBarPane.getFToolBar(), this);
BasicDialog dialog = editToolBar.showWindow(DesignerContext.getDesignerFrame());
dialog.addDialogActionListener(new DialogActionAdapter() {
public void doOk() {
toolBarPane.setFToolBar(editToolBar.update());
}
});
dialog.setVisible(true);
}
}
private void auhtorityMouseAction() {
if (this.isEnabled()) {
this.setSelected(!this.isSelected());
}
}
/**
* 鼠标进入事件
*
* @param e 鼠标进入事件
*/
public void mouseEntered(MouseEvent e) {
}
/**
* 鼠标退出事件
*
* @param e 鼠标退出事件
*/
public void mouseExited(MouseEvent e) {
}
/**
* 鼠标按下事件
*
* @param e 鼠标事件
*/
public void mousePressed(MouseEvent e) {
}
/**
* 鼠标释放事件
*
* @param e 鼠标事件
*/
public void mouseReleased(MouseEvent e) {
}
}

233
designer_form/src/com/fr/design/mainframe/FormToolBarPane.java

@ -0,0 +1,233 @@
package com.fr.design.mainframe;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.core.WidgetOption;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.ui.ToolBar;
import com.fr.form.ui.Widget;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
/**
* Created by harry on 2017-3-2.
*/
public class FormToolBarPane extends BasicBeanPane<ToolBar> {
private FormToolBar ftoolbar = new FormToolBar();
public FormToolBarPane() {
super();
this.initComponent();
}
/**
* 添加鼠标监听
*
* @param mouselistener 鼠标监听
*/
public void addAuthorityListener(MouseListener mouselistener) {
List<FormToolBarButton> list = ftoolbar.getButtonlist();
for (int i = 0; i < list.size(); i++) {
list.get(i).addMouseListener(mouselistener);
}
}
public FormToolBarPane(FormToolBarButton button) {
super();
this.initComponent();
this.add(button);
}
/**
* 初始化组件
*/
public void initComponent() {
this.addMouseListener(listener);
this.setLayout(FRGUIPaneFactory.createBoxFlowLayout());
this.setTransferHandler(new ToolBarHandler(TransferHandler.COPY));
this.setBorder(BorderFactory.createTitledBorder(""));
}
/**
* 删除鼠标事件
*/
public void removeDefaultMouseListener() {
this.removeMouseListener(listener);
}
@Override
protected String title4PopupWindow() {
return "Toolbar";
}
public void setSelectedButton(FormToolBarButton button) {
this.ftoolbar.addButton(button);
}
/**
* 添加组件
*
* @param comp 组件
*
* @return 被添加的组件
*/
public Component add(Component comp) {
if (comp instanceof FormToolBarButton) {
this.ftoolbar.addButton((FormToolBarButton) comp);
}
return super.add(comp);
}
private Component addComp(Component comp) {
return super.add(comp);
}
public void removeButtonList() {
this.ftoolbar.clearButton();
}
protected void setFToolBar(FormToolBar ftoolbar) {
if (ftoolbar == null) {
ftoolbar = new FormToolBar();
}
this.ftoolbar = ftoolbar;
this.setToolBar(this.ftoolbar.getButtonlist());
}
public List<FormToolBarButton> getToolBarButtons() {
return ftoolbar.getButtonlist();
}
protected FormToolBar getFToolBar() {
return this.ftoolbar;
}
public boolean isEmpty() {
return this.ftoolbar.getButtonlist().size() <= 0;
}
private void setToolBar(List<FormToolBarButton> list) {
if (list == null || list.size() < 0) {
return;
}
this.removeAll();
for (int i = 0; i < list.size(); i++) {
this.addComp(list.get(i));
}
this.validate();
this.repaint();
}
@Override
public void populateBean(ToolBar toolbar) {
this.removeAll();
this.getFToolBar().clearButton();
for (int j = 0; j < toolbar.getWidgetSize(); j++) {
Widget widget = toolbar.getWidget(j);
WidgetOption no = WidgetOption.getToolBarButton(widget.getClass());
if (no == null){
//如果装了什么插件, 放到了工具栏上, 后来删除了插件, 模板里还存着之前的控件
continue;
}
FormToolBarButton button = new FormToolBarButton(no.optionIcon(), widget);
button.setNameOption(no);
this.add(button);
this.validate();
this.repaint();
}
this.getFToolBar().setBackground(toolbar.getBackground());
this.getFToolBar().setDefault(toolbar.isDefault());
}
@Override
public ToolBar updateBean() {
return this.ftoolbar.getToolBar();
}
MouseListener listener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2 && !SwingUtilities.isRightMouseButton(e)) {
final FormEditToolBar tb = new FormEditToolBar();
tb.populate(getFToolBar());
BasicDialog dialog = tb.showWindow(SwingUtilities.getWindowAncestor(FormToolBarPane.this));
dialog.addDialogActionListener(new DialogActionAdapter() {
@Override
public void doOk() {
FormToolBarPane.this.setFToolBar(tb.update());
}
});
dialog.setVisible(true);
}
}
};
/*
* 拖拽属性设置
*/
private class ToolBarHandler extends TransferHandler {
private int action;
public ToolBarHandler(int action) {
this.action = action;
}
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDrop()) {
return false;
}
if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return false;
}
boolean actionSupported = (action & support.getSourceDropActions()) == action;
if (actionSupported) {
support.setDropAction(action);
return true;
}
return false;
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
WidgetOption data;
try {
data = (WidgetOption) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException e) {
return false;
} catch (java.io.IOException e) {
return false;
}
Widget widget = data.createWidget();
FormToolBarButton btn = new FormToolBarButton(data.optionIcon(), widget);
btn.setNameOption(data);
FormToolBarPane.this.add(btn);
FormToolBarPane.this.validate();
FormToolBarPane.this.repaint();
return true;
}
}
}

54
designer_form/src/com/fr/design/mainframe/FormWebWidgetConstants.java

@ -0,0 +1,54 @@
package com.fr.design.mainframe;
import com.fr.design.gui.core.WidgetOption;
import com.fr.design.gui.core.WidgetOptionFactory;
import com.fr.form.ui.CustomToolBarButton;
import com.fr.form.web.button.ExcelO;
import com.fr.form.web.button.ExcelP;
import com.fr.form.web.button.Export;
import com.fr.form.web.button.page.*;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
/**
* Created by harry on 2017-3-3.
*/
public class FormWebWidgetConstants {
private FormWebWidgetConstants() {
}
public static WidgetOption[] getFormElementCaseToolBarInstance() {
return new WidgetOption[]{FIRST, PREVIOUS, PAGENAVI, NEXT, LAST, EXPORT, EXCELP, EXCELO, CUSTOM_BUTTON};
}
// 当前页/总页数
public static final WidgetOption PAGENAVI = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"HJS-Current_Page", "HF-Number_of_Page"}, new String[]{"/", ""}),
IOUtils.readIcon("/com/fr/web/images/pageNumber.png"), PageNavi.class);
// 首页
public static final WidgetOption FIRST = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-First"), IOUtils.readIcon("/com/fr/web/images/first.png"),
First.class);
// 末页
public static final WidgetOption LAST = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Last"), IOUtils.readIcon("/com/fr/web/images/last.png"),
Last.class);
// 前一页
public static final WidgetOption PREVIOUS = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Previous"),
IOUtils.readIcon("/com/fr/web/images/previous.png"), Previous.class);
// 后一页
public static final WidgetOption NEXT = WidgetOptionFactory.createByWidgetClass(Inter.getLocText("FR-Engine_ReportServerP-Next"), IOUtils.readIcon("/com/fr/web/images/next.png"),
Next.class);
// 导出成Excel 分页导出
public static final WidgetOption EXCELP = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Page"}, new String[]{"(", ")"}),
IOUtils.readIcon("/com/fr/web/images/excel.png"), ExcelP.class);
// 导出成Excel 原样导出
public static final WidgetOption EXCELO = WidgetOptionFactory.createByWidgetClass(Inter.getLocText(new String[]{"Excel", "FR-Designer_Export_Excel_Simple"}, new String[]{"(", ")"}),
IOUtils.readIcon("/com/fr/web/images/excel.png"), ExcelO.class);
// 导出
public static final WidgetOption EXPORT = WidgetOptionFactory
.createByWidgetClass(Inter.getLocText("FR-Engine_Export"), IOUtils.readIcon("/com/fr/web/images/export.png"), Export.class);
public static final WidgetOption CUSTOM_BUTTON = WidgetOptionFactory
.createByWidgetClass(Inter.getLocText(new String[]{"Custom", "Form-Button"}), CustomToolBarButton.class);
}

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

File diff suppressed because it is too large Load Diff

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

@ -1,346 +1,348 @@
package com.fr.design.mainframe;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.*;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itable.GroupRenderer;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.*;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
/**
* MobileWidgetTable类主要显示各种容器的控件列表bodytab绝对布局快不包括参数面板
* Created with IntelliJ IDEA.
* User: zx
* Date: 14-9-15
* Time: 下午4:52
* Modified by fanglei at 2017/01/23
*/
public class MobileWidgetTable extends JTable {
private FormDesigner designer;
private String[][] cellData;
private String[] headers = {Inter.getLocText("Form-Widget_Name")};
private static final int WIDGET_TABLE_ROW_HEIGHT = 22;
private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件
private int selectedRow = -1;
private int GAP = 11;
private boolean draging = false;
private boolean collapsed = false; // 控件列表是否折叠
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//第一行渲染成为标题的样子
if (row == 0) {
return new GroupRenderer();
}
return super.getCellRenderer(row, column);
}
public MobileWidgetTable(FormDesigner designer) {
this.designer = designer;
cellData = getData();
this.setTableProperties();
TableModel defaultModel = new BeanTableModel();
this.setModel(defaultModel);
this.repaint();
this.setDefaultRenderer(Object.class,new DefaultTableCellRenderer());
refreshData();
this.addMouseListener(mouseAdapter);
this.addMouseMotionListener(mouseAdapter);
add(moveComponent);
}
private void setTableProperties() {
JTableHeader header = getTableHeader();
header.setReorderingAllowed(false);
header.setPreferredSize(new Dimension(0, 0)); // 隐藏表头
GroupRenderer headerRenderer = new GroupRenderer();
headerRenderer.setPreferredSize(new Dimension(0, 0)); //这行代码隐藏表头。因为要实现折叠效果,表头不好监听事件
headerRenderer.setHorizontalAlignment(JLabel.LEFT);
header.setDefaultRenderer(headerRenderer);
this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT);
this.setGridColor(new Color(212, 208, 200));
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.setColumnSelectionAllowed(false);
this.setRowSelectionAllowed(false);
this.setFillsViewportHeight(false);
this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}
private MouseAdapter mouseAdapter = new MouseAdapter() {
/**
* 鼠标按下时处理的事件设置当前选中的行列
* @param e
*/
@Override
public void mousePressed(MouseEvent e) {
getInstance().setCellSelected();
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2){ // 如果是点击在第一行
toggleCollapse();
}
}
/**
* 鼠标放开时处理的事件如果是正在拖动则执行换位操作重新绘制属性表如果不是则什么也不做
* 所谓的换行就是简单的重新拿到一次表格数据然后重新绘制表格
* @param e
*/
@Override
public void mouseReleased(MouseEvent e) {
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;
//当鼠标放开时,将选中的容器调整至新的顺序
((WSortLayout)designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
//拿取排序后表格数据,然后重绘表格
getInstance().refreshData();
getInstance().repaint();
designer.fireTargetModified();
getInstance().setCellSelected();
}
/**
* 设置鼠标在属性表区域移动时候的事件
* @param e
*/
@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){
overRow = i; //判断鼠标在哪一行
}
}
//如果鼠标移动到当前选中的行上面的时候
if (overRow == selectedRow && selectedRow > 0) {
//把当前选中的那一行的光标改成(除了第一列)移动样式MOVE_CURSOR
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
/**
* 鼠标拖动事件如果鼠标当前是<code>MOVE_CURSOR</code>状态则执行开始拖动的代码
* 绘制一个<code>moveComponent</code>来跟随鼠标移动
* @param e
*/
@Override
public void mouseDragged(MouseEvent e) {
int width = getColumnModel().getColumn(0).getWidth();
//如果当前选中的行的范围是合理的话,就可以拖动
if (selectedRow < getRowCount() && selectedRow > 0){
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
draging = true;
moveComponent.setText(getValueAt(selectedRow,0).toString());
moveComponent.setLocation(0, e.getY() - GAP);
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT));
moveComponent.setVisible(true);
moveComponent.setForeground(Color.lightGray);
moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray));
}
}
/**
* 设置鼠标单击时处理的事件单击控件列表进入控件属性表
* @param e
*/
@Override
public void mouseClicked(MouseEvent e) {
if(selectedRow > 0){
//当前点击的控件的名字
String widgetName = cellData[selectedRow][0];
if (StringUtils.isNotEmpty(widgetName)){
//当前选择的容器
XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator();
WLayout selectedWidget = (WLayout)selectedContainer.toData();
//当前选择的容器中的控件数量
int count = selectedWidget.getWidgetCount();
for (int i = 0;i < count ;i++){
XCreator xCreator = (XCreator) selectedContainer.getComponent(i);
Widget widget = xCreator.toData();
if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) {
getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator);
}
}
}
} else if (selectedRow == 0){ // 如果是点击在第一行
if (!e.isPopupTrigger() && e.getClickCount() > 1) {
toggleCollapse();
}
}
}
/**
* 鼠标离开属性表区域事件
* @param e
*/
public void mouseExited(MouseEvent e) {
draging = false;
moveComponent.setVisible(false);
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
};
public MobileWidgetTable getInstance(){
return this;
}
public FormDesigner getEditingDesigner(){
return designer;
}
/**
* 设置当前get到的行列的单元格为选中状态
*/
private void setCellSelected() {
selectedRow = getSelectedRow();
if (selectedRow != -1) {
this.setRowSelectionInterval(selectedRow, selectedRow);
this.setColumnSelectionInterval(0, 0);
}
}
/**
* 切换属性组折叠属性true/false
*/
private void toggleCollapse() {
this.setCollapsed(!this.isCollapsed());
//这里获取表格的父控件是为了当表格被折叠了后,装表格的父控件也要相应的重新布局一下
//比如折叠之后表格行数应该比原来的少,占用父容器空间应该小点,不重新布局父容器,表格大小不会改变
Container parent = MobileWidgetTable.this.getParent();
if (parent != null) {
parent.revalidate();
}
repaint();
}
/**
* 重新get排序后的数据
*/
public void refreshData(){
cellData = getData();
}
/**
* 获取选中控件的控件列表
*
* @return String[][] 二维数组[0][0]widgetName
*/
private String[][] getData(){
if(designer.isFormParaDesigner()){
return new String[0][0];
}
//选择的控件
Widget selectedModel = designer.getSelectionModel().getSelection().getSelectedCreator().toData();
if(selectedModel == null){
return new String[0][0];
}
// 选择的控件有两种类型,一种是WLayout,代表容器,一种是Widget,代表控件
if (selectedModel.acceptType(WSortLayout.class)) {
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++) {
widgetName[i + 1][0] = mobileWidgetList.get(i);
}
return widgetName;
} else {
return new String[0][0];
}
}
public boolean isCollapsed() {
return collapsed;
}
public void setCollapsed(boolean collapsed) {
this.collapsed = collapsed;
}
/**
* 自定义的tableEditor类
*/
public class BeanTableModel extends DefaultTableModel {
public BeanTableModel() {
super(cellData,headers);
}
@Override
public int getRowCount() {
if (isCollapsed()) {
return 1;
}
return cellData.length;
}
@Override
public int getColumnCount() {
return 1;
}
@Override
public Object getValueAt(int row, int column) {
if (row >= getRowCount() || column >= getColumnCount()) {
return null;
}
if (row == 0) {
return (isCollapsed()? "+" : "-") + cellData[row][0];
}
return cellData[row][0];
}
@Override
public String getColumnName(int column) {
return headers[0];
}
@Override
public void setValueAt(Object aValue, int row, int column) {
if (row >= getRowCount() || column >= getColumnCount()) {
return;
}
if (aValue == null) {
cellData[row] = null;
return;
}
cellData[row][0] = aValue.toString();
}
/**
* 是否可编辑
* @param row 行号
* @param column 列号
* @return 是否可编辑
*/
public boolean isCellEditable(int row, int column) {
return false;
}
}
package com.fr.design.mainframe;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.*;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itable.GroupRenderer;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.*;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
/**
* MobileWidgetTable类主要显示各种容器的控件列表bodytab绝对布局快不包括参数面板
* Created with IntelliJ IDEA.
* User: zx
* Date: 14-9-15
* Time: 下午4:52
* Modified by fanglei at 2017/01/23
*/
public class MobileWidgetTable extends JTable {
private FormDesigner designer;
private String[][] cellData;
private String[] headers = {Inter.getLocText("Form-Widget_Name")};
private static final int WIDGET_TABLE_ROW_HEIGHT = 22;
private UILabel moveComponent = new UILabel(); // 作为拖动时候随鼠标移动的那个半透明控件
private int selectedRow = -1;
private static final int GAP = 11;
private boolean draging = false;
private boolean collapsed = false; // 控件列表是否折叠
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//第一行渲染成为标题的样子
if (row == 0) {
return new GroupRenderer();
}
return super.getCellRenderer(row, column);
}
public MobileWidgetTable(FormDesigner designer) {
this.designer = designer;
cellData = getData();
this.setTableProperties();
TableModel defaultModel = new BeanTableModel();
this.setModel(defaultModel);
this.repaint();
this.setDefaultRenderer(Object.class, new DefaultTableCellRenderer());
refreshData();
this.addMouseListener(mouseAdapter);
this.addMouseMotionListener(mouseAdapter);
add(moveComponent);
}
private void setTableProperties() {
JTableHeader header = getTableHeader();
header.setReorderingAllowed(false);
header.setPreferredSize(new Dimension(0, 0)); // 隐藏表头
GroupRenderer headerRenderer = new GroupRenderer();
headerRenderer.setPreferredSize(new Dimension(0, 0)); //这行代码隐藏表头。因为要实现折叠效果,表头不好监听事件
headerRenderer.setHorizontalAlignment(JLabel.LEFT);
header.setDefaultRenderer(headerRenderer);
this.setRowHeight(WIDGET_TABLE_ROW_HEIGHT);
this.setGridColor(new Color(212, 208, 200));
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.setColumnSelectionAllowed(false);
this.setRowSelectionAllowed(false);
this.setFillsViewportHeight(false);
this.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
}
private MouseAdapter mouseAdapter = new MouseAdapter() {
/**
* 鼠标按下时处理的事件设置当前选中的行列
* @param e
*/
@Override
public void mousePressed(MouseEvent e) {
getInstance().setCellSelected();
if (selectedRow == 0 && !e.isPopupTrigger() && e.getClickCount() == 1 && e.getX() < WIDGET_TABLE_ROW_HEIGHT / 2) { // 如果是点击在第一行
toggleCollapse();
}
}
/**
* 鼠标放开时处理的事件如果是正在拖动则执行换位操作重新绘制属性表如果不是则什么也不做
* 所谓的换行就是简单的重新拿到一次表格数据然后重新绘制表格
* @param e
*/
@Override
public void mouseReleased(MouseEvent e) {
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;
//当鼠标放开时,将选中的容器调整至新的顺序
((WSortLayout) designer.getSelectionModel().getSelection().getSelectedCreator().toData()).adjustOrder(selectedRow - 1, toIndex - 1);
//拿取排序后表格数据,然后重绘表格
getInstance().refreshData();
getInstance().repaint();
designer.fireTargetModified();
getInstance().setCellSelected();
}
/**
* 设置鼠标在属性表区域移动时候的事件
* @param e
*/
@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) {
overRow = i; //判断鼠标在哪一行
}
}
//如果鼠标移动到当前选中的行上面的时候
if (overRow == selectedRow && selectedRow > 0) {
//把当前选中的那一行的光标改成(除了第一列)移动样式MOVE_CURSOR
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else {
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
/**
* 鼠标拖动事件如果鼠标当前是<code>MOVE_CURSOR</code>状态则执行开始拖动的代码
* 绘制一个<code>moveComponent</code>来跟随鼠标移动
* @param e
*/
@Override
public void mouseDragged(MouseEvent e) {
int width = getColumnModel().getColumn(0).getWidth();
//如果当前选中的行的范围是合理的话,就可以拖动
if (selectedRow < getRowCount() && selectedRow > 0) {
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
draging = true;
moveComponent.setText(getValueAt(selectedRow, 0).toString());
moveComponent.setLocation(0, e.getY() - GAP);
moveComponent.setSize(new Dimension(width, WIDGET_TABLE_ROW_HEIGHT));
moveComponent.setVisible(true);
moveComponent.setForeground(Color.lightGray);
moveComponent.setBorder(BorderFactory.createLineBorder(Color.lightGray));
}
}
/**
* 设置鼠标单击时处理的事件单击控件列表进入控件属性表
* @param e
*/
@Override
public void mouseClicked(MouseEvent e) {
if (selectedRow > 0) {
//当前点击的控件的名字
String widgetName = cellData[selectedRow][0];
if (StringUtils.isNotEmpty(widgetName)) {
//当前选择的容器
XCreator selectedContainer = designer.getSelectionModel().getSelection().getSelectedCreator();
WLayout selectedWidget = (WLayout) selectedContainer.toData();
//当前选择的容器中的控件数量
int count = selectedWidget.getWidgetCount();
for (int i = 0; i < count; i++) {
XCreator xCreator = (XCreator) selectedContainer.getComponent(i);
Widget widget = xCreator.toData();
if (ComparatorUtils.equals(widgetName, widget.getWidgetName())) {
getEditingDesigner().getSelectionModel().setSelectedCreator(xCreator);
}
}
}
} else if (selectedRow == 0) { // 如果是点击在第一行
if (!e.isPopupTrigger() && e.getClickCount() > 1) {
toggleCollapse();
}
}
}
/**
* 鼠标离开属性表区域事件
* @param e
*/
public void mouseExited(MouseEvent e) {
draging = false;
moveComponent.setVisible(false);
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
};
public MobileWidgetTable getInstance() {
return this;
}
public FormDesigner getEditingDesigner() {
return designer;
}
/**
* 设置当前get到的行列的单元格为选中状态
*/
private void setCellSelected() {
selectedRow = getSelectedRow();
if (selectedRow != -1) {
this.setRowSelectionInterval(selectedRow, selectedRow);
this.setColumnSelectionInterval(0, 0);
}
}
/**
* 切换属性组折叠属性true/false
*/
private void toggleCollapse() {
this.setCollapsed(!this.isCollapsed());
//这里获取表格的父控件是为了当表格被折叠了后,装表格的父控件也要相应的重新布局一下
//比如折叠之后表格行数应该比原来的少,占用父容器空间应该小点,不重新布局父容器,表格大小不会改变
Container parent = MobileWidgetTable.this.getParent();
if (parent != null) {
parent.revalidate();
}
repaint();
}
/**
* 重新get排序后的数据
*/
public void refreshData() {
cellData = getData();
}
/**
* 获取选中控件的控件列表
*
* @return String[][] 二维数组[0][0]widgetName
*/
private String[][] getData() {
if (designer.isFormParaDesigner()) {
return new String[0][0];
}
//选择的控件
XCreator selectedCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
Widget selectedModel = selectedCreator != null ? selectedCreator.toData() : null;
if (selectedModel == null) {
return new String[0][0];
}
// 选择的控件有两种类型,一种是WLayout,代表容器,一种是Widget,代表控件
if (selectedModel.acceptType(WSortLayout.class)) {
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++) {
widgetName[i + 1][0] = mobileWidgetList.get(i);
}
return widgetName;
} else {
return new String[0][0];
}
}
public boolean isCollapsed() {
return collapsed;
}
public void setCollapsed(boolean collapsed) {
this.collapsed = collapsed;
}
/**
* 自定义的tableEditor类
*/
public class BeanTableModel extends DefaultTableModel {
public BeanTableModel() {
super(cellData, headers);
}
@Override
public int getRowCount() {
if (isCollapsed()) {
return 1;
}
return cellData.length;
}
@Override
public int getColumnCount() {
return 1;
}
@Override
public Object getValueAt(int row, int column) {
if (row >= getRowCount() || column >= getColumnCount()) {
return null;
}
if (row == 0) {
return (isCollapsed() ? "+" : "-") + cellData[row][0];
}
return cellData[row][0];
}
@Override
public String getColumnName(int column) {
return headers[0];
}
@Override
public void setValueAt(Object aValue, int row, int column) {
if (row >= getRowCount() || column >= getColumnCount()) {
return;
}
if (aValue == null) {
cellData[row] = null;
return;
}
cellData[row][0] = aValue.toString();
}
/**
* 是否可编辑
*
* @param row 行号
* @param column 列号
* @return 是否可编辑
*/
public boolean isCellEditable(int row, int column) {
return false;
}
}
}

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

@ -1,366 +1,372 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.designer.beans.events.DesignerEditListener;
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.XWParameterLayout;
import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.designer.properties.WidgetPropertyTable;
import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itable.AbstractPropertyTable;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* 控件属性表绘制
* Modified by fanglei
*/
public class WidgetPropertyPane extends FormDockView implements BaseWidgetPropertyPane {
private static final String PARA = "para";
private static final String BODY = "body";
private WidgetPropertyTable propertyTable; // 控件的属性表
private EventPropertyTable eventTable; // 控件的事件表
private List<AbstractPropertyTable> widgetPropertyTables; // 这个变量应该是保存控件拓展的属性tab
private FormDesigner designer; // 当前designer
private UIScrollPane psp; // 用来装载属性表table的容器
private UIScrollPane esp; //用来装载事件table的容器
private JPanel wsp; // 装载移动端tab的容器,包括移动端属性表和控件拓展的移动端属性表
private MobileParaWidgetTable mobileParaWidgetTable; // 参数面板的移动端属性tab(和body的移动端属性tab区别是没有标签名column)
private MobileWidgetTable mobileWidgetTable; // body的移动端属性tab
private UIScrollPane downPanel; // 这个滚动容器是用于装载centerPane的
private JPanel centerPane; // 此centerPane采用的是cardLayout布局,装载着mobileWidgetTable和mobileBodyWidgetTable
private CardLayout cardLayout; // 卡片布局,选中参数面板时显示mobileWidgetTable,选中body时显示mobileBodyWidgetTable
private JTableHeader header;//把表头单独get出来作为一个组件
public static WidgetPropertyPane getInstance() {
if (HOLDER.singleton == null) {
HOLDER.singleton = new WidgetPropertyPane();
}
return HOLDER.singleton;
}
public static WidgetPropertyPane getInstance(FormDesigner formEditor) {
HOLDER.singleton.setEditingFormDesigner(formEditor);
HOLDER.singleton.refreshDockingView();
return HOLDER.singleton;
}
private static class HOLDER {
private static WidgetPropertyPane singleton = new WidgetPropertyPane();
}
private WidgetPropertyPane() {
setLayout(FRGUIPaneFactory.createBorderLayout());
}
@Override
public String getViewTitle() {
return Inter.getLocText("Form-Widget_Property_Table");
}
@Override
public Icon getViewIcon() {
return BaseUtils.readIcon("/com/fr/design/images/m_report/attributes.png");
}
@Override
/**
* 绘制属性表tab
*/
public void refreshDockingView() {
designer = this.getEditingFormDesigner();
removeAll();
if (designer == null) {
clearDockingView();
return;
}
widgetPropertyTables = new ArrayList<AbstractPropertyTable>();
//依次创建属性表、事件表、移动端表,再将它们整合到TabPane中去
this.createPropertyTable();
this.createEventTable();
this.createMobileWidgetTable();
this.createTabPane();
this.initTables();
}
/**
* 初始化属性表事件表移动端拓展的属性表
*/
private void initTables() {
propertyTable.initPropertyGroups(null);
eventTable.refresh();
for (AbstractPropertyTable propertyTable : widgetPropertyTables) {
propertyTable.initPropertyGroups(designer);
}
}
/**
* 创建属性表table
*/
private void createPropertyTable() {
propertyTable = new WidgetPropertyTable(designer);
designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable));
propertyTable.setBorder(null);
psp = new UIScrollPane(propertyTable); // 用来装载属性表table
psp.setBorder(null);
}
/**
* 创建事件表事件选项卡不是JTable
*/
private void createEventTable() {
eventTable = new EventPropertyTable(designer);
designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable));
eventTable.setBorder(null);
esp = new UIScrollPane(eventTable); //用来装载事件table
esp.setBorder(null);
}
/**
* 创建移动端控件列表
*/
private void createMobileWidgetTable() {
//加上表头后,这里不再使用borderLayout布局,而采用BoxLayout布局
wsp = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
wsp.setBorder(null);
mobileParaWidgetTable = new MobileParaWidgetTable(designer);
mobileWidgetTable = new MobileWidgetTable(designer);
designer.addDesignerEditListener(new mobileWidgetDesignerAdapter());
centerPane = FRGUIPaneFactory.createCardLayout_S_Pane();
cardLayout = (CardLayout) centerPane.getLayout();
centerPane.add(mobileParaWidgetTable, PARA);// 采用卡片布局的容器必须指定卡片名字,如果没有卡片名字
// 就会出现:Exception in thread "main" java.lang.IllegalArgumentException:
// cannot add to layout: constraint must be a string
// 第二个参数代表卡片的名字。后来show方法调用时通过名字找到要显示的卡片
centerPane.add(mobileWidgetTable, BODY); //这两句代码,是把JTable放到一个JPanel中去了,表头不会显示,
//只有放到JScrollPanel中去表头才能正常显示,这就是MobileWidgetTable中定义了表头却没有显示的原因!
//解决方案:MobileWidgetTable实在无法直接放到JScrollPanel中去的时候,应该把表头get出来单独作为一个组件显示
if(hasSelectParaPane(designer)){
cardLayout.show(centerPane,PARA);
header = mobileParaWidgetTable.getTableHeader();
} else {
cardLayout.show(centerPane,BODY);
header = mobileWidgetTable.getTableHeader();
}
downPanel = new UIScrollPane(centerPane);
downPanel.setBorder(new LineBorder(Color.GRAY));
//获取拓展移动端属性tab
WidgetPropertyUIProvider[] widgetAttrProviders = getExtraPropertyUIProviders();
addWidgetAttr(widgetAttrProviders);
}
/**
* 将属性表事件表移动端控件列表整合到TabPane里面去
*/
private void createTabPane() {
UITabbedPane tabbedPane = new UITabbedPane(); // tab选项卡容器
initTabPane(tabbedPane);
add(tabbedPane, BorderLayout.CENTER);
}
/**
* 获取当前控件扩展的属性tab
* 来源有两个:
* 1, 各个控件从各自的Xcreator里扩展例如手机重布局的tab就是从Xcreator中扩展的;
* 2, 所有的控件从插件里扩展.
*
* @return 扩展的tab
*/
private WidgetPropertyUIProvider[] getExtraPropertyUIProviders() {
FormSelection selection = designer.getSelectionModel().getSelection();
WidgetPropertyUIProvider[] embeddedPropertyUIProviders = null;
if (selection != null && selection.getSelectedCreator() != null) {
embeddedPropertyUIProviders = selection.getSelectedCreator().getWidgetPropertyUIProviders();
}
Set<WidgetPropertyUIProvider> set = ExtraDesignClassManager.getInstance().getArray(WidgetPropertyUIProvider.XML_TAG);
return ArrayUtils.addAll(embeddedPropertyUIProviders, set.toArray(new WidgetPropertyUIProvider[set.size()]));
}
/**
* 判断是将拓展的tab放入属性表还是将原来的tab放入属性表
* @param widgetAttrProviders 拓展的tab
*/
private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) {
if (widgetAttrProviders.length == 0) { // 判断有没有拓展的tab,没有就使用原来的
wsp.add(header);
wsp.add(downPanel);
} else {
for (WidgetPropertyUIProvider widgetAttrProvider : widgetAttrProviders) {
AbstractPropertyTable propertyTable = widgetAttrProvider.createWidgetAttrTable();
widgetPropertyTables.add(propertyTable);
designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable));
UIScrollPane uiScrollPane = new UIScrollPane(getExtraBodyTable(propertyTable));
wsp.add(uiScrollPane);
}
}
}
/**
* 如果是body的拓展属性表那么要额外加上一张控件顺序表
* @return
*/
private Component getExtraBodyTable(AbstractPropertyTable abstractPropertyTable) {
Widget selection = designer.getSelectionModel().getSelection().getSelectedCreator().toData();
if (selection.getWidgetName().equals("body")) {
JPanel jPanel = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
jPanel.add(abstractPropertyTable);
MobileWidgetTable mobileWidgetTable = new MobileWidgetTable(designer);
jPanel.add(mobileWidgetTable.getTableHeader());
jPanel.add(mobileWidgetTable);
return jPanel;
}
return abstractPropertyTable;
}
private void initTabPane(UITabbedPane tabbedPane) {
tabbedPane.setOpaque(true);
tabbedPane.setBorder(null);
tabbedPane.setTabPlacement(SwingConstants.BOTTOM);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), esp);
tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp);
}
//
/**
* 选中的组件是否在参数面板里
* @param designer 设计器
* @return 是则返回true
*/
public boolean hasSelectParaPane(FormDesigner designer){
XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
if(xCreator == null){
xCreator = designer.getRootComponent();
}
XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator);
return xCreator.acceptType(XWParameterLayout.class) || container.acceptType(XWParameterLayout.class);
}
public void setEditingFormDesigner(BaseFormDesigner editor) {
FormDesigner fd = (FormDesigner) editor;
super.setEditingFormDesigner(fd);
}
private void clearDockingView() {
propertyTable = null;
eventTable = null;
if (widgetPropertyTables != null) {
widgetPropertyTables.clear();
}
JScrollPane psp = new JScrollPane();
psp.setBorder(null);
this.add(psp, BorderLayout.CENTER);
}
/**
* 属性表监听界面事件(编辑删除选中改变大小)
*/
private class WidgetPropertyDesignerAdapter implements DesignerEditListener {
AbstractPropertyTable propertyTable;
WidgetPropertyDesignerAdapter(AbstractPropertyTable propertyTable) {
this.propertyTable = propertyTable;
}
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
propertyTable.initPropertyGroups(designer);
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED) {
repaint();
}
}
@Override
public boolean equals(Object o) {
return o instanceof WidgetPropertyDesignerAdapter && ((WidgetPropertyDesignerAdapter) o).propertyTable == this.propertyTable;
}
}
/**
* 事件表监听界面事件编辑选中
*/
private class EventPropertyDesignerAdapter implements DesignerEditListener {
EventPropertyTable propertyTable;
EventPropertyDesignerAdapter(EventPropertyTable eventTable) {
this.propertyTable = eventTable;
}
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
propertyTable.refresh();
}
}
@Override
public boolean equals(Object o) {
return o instanceof EventPropertyDesignerAdapter;
}
}
/**
* 移动端属性表监听界面事件改变大小编辑选中增加控件
*/
private class mobileWidgetDesignerAdapter implements DesignerEditListener {
mobileWidgetDesignerAdapter() {
}
/**
* 响应界面改变事件
* @param evt 事件
*/
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) {
int value = downPanel.getVerticalScrollBar().getValue();
if(hasSelectParaPane(getEditingFormDesigner())){
cardLayout.show(centerPane,PARA);
mobileParaWidgetTable.refreshData();
} else {
cardLayout.show(centerPane,BODY);
mobileWidgetTable.refreshData();
}
//出现滚动条
downPanel.doLayout();
//控件列表选中某组件,触发表单中选中控件,选中事件又触发列表刷新,滚动条回到0
//此处设置滚动条值为刷新前
downPanel.getVerticalScrollBar().setValue(value);
}
}
}
@Override
public Location preferredLocation() {
return Location.WEST_BELOW;
}
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.designer.beans.events.DesignerEditListener;
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.XWParameterLayout;
import com.fr.design.designer.properties.EventPropertyTable;
import com.fr.design.designer.properties.WidgetPropertyTable;
import com.fr.design.fun.WidgetPropertyUIProvider;
import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.itable.AbstractPropertyTable;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.ui.Widget;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* 控件属性表绘制
* Modified by fanglei
*/
public class WidgetPropertyPane extends FormDockView implements BaseWidgetPropertyPane {
private static final String PARA = "para";
private static final String BODY = "body";
private WidgetPropertyTable propertyTable; // 控件的属性表
private EventPropertyTable eventTable; // 控件的事件表
private List<AbstractPropertyTable> widgetPropertyTables; // 这个变量应该是保存控件拓展的属性tab
private FormDesigner designer; // 当前designer
private UIScrollPane psp; // 用来装载属性表table的容器
private UIScrollPane esp; //用来装载事件table的容器
private JPanel wsp; // 装载移动端tab的容器,包括移动端属性表和控件拓展的移动端属性表
private MobileParaWidgetTable mobileParaWidgetTable; // 参数面板的移动端属性tab(和body的移动端属性tab区别是没有标签名column)
private MobileWidgetTable mobileWidgetTable; // body的移动端属性tab
private UIScrollPane downPanel; // 这个滚动容器是用于装载centerPane的
private JPanel centerPane; // 此centerPane采用的是cardLayout布局,装载着mobileWidgetTable和mobileBodyWidgetTable
private CardLayout cardLayout; // 卡片布局,选中参数面板时显示mobileWidgetTable,选中body时显示mobileBodyWidgetTable
private JTableHeader header;//把表头单独get出来作为一个组件
public static WidgetPropertyPane getInstance() {
if (HOLDER.singleton == null) {
HOLDER.singleton = new WidgetPropertyPane();
}
return HOLDER.singleton;
}
public static WidgetPropertyPane getInstance(FormDesigner formEditor) {
HOLDER.singleton.setEditingFormDesigner(formEditor);
HOLDER.singleton.refreshDockingView();
return HOLDER.singleton;
}
private static class HOLDER {
private static WidgetPropertyPane singleton = new WidgetPropertyPane();
}
private WidgetPropertyPane() {
setLayout(FRGUIPaneFactory.createBorderLayout());
}
@Override
public String getViewTitle() {
return Inter.getLocText("Form-Widget_Property_Table");
}
@Override
public Icon getViewIcon() {
return BaseUtils.readIcon("/com/fr/design/images/m_report/attributes.png");
}
@Override
/**
* 绘制属性表tab
*/
public void refreshDockingView() {
designer = this.getEditingFormDesigner();
removeAll();
if (designer == null) {
clearDockingView();
return;
}
widgetPropertyTables = new ArrayList<AbstractPropertyTable>();
//依次创建属性表、事件表、移动端表,再将它们整合到TabPane中去
this.createPropertyTable();
this.createEventTable();
this.createMobileWidgetTable();
this.createTabPane();
this.initTables();
}
/**
* 初始化属性表事件表移动端拓展的属性表
*/
private void initTables() {
propertyTable.initPropertyGroups(null);
eventTable.refresh();
for (AbstractPropertyTable propertyTable : widgetPropertyTables) {
propertyTable.initPropertyGroups(designer);
}
}
/**
* 创建属性表table
*/
private void createPropertyTable() {
propertyTable = new WidgetPropertyTable(designer);
designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable));
propertyTable.setBorder(null);
psp = new UIScrollPane(propertyTable); // 用来装载属性表table
psp.setBorder(null);
}
/**
* 创建事件表事件选项卡不是JTable
*/
private void createEventTable() {
eventTable = new EventPropertyTable(designer);
designer.addDesignerEditListener(new EventPropertyDesignerAdapter(eventTable));
eventTable.setBorder(null);
esp = new UIScrollPane(eventTable); //用来装载事件table
esp.setBorder(null);
}
/**
* 创建移动端控件列表
*/
private void createMobileWidgetTable() {
//加上表头后,这里不再使用borderLayout布局,而采用BoxLayout布局
wsp = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
wsp.setBorder(null);
mobileParaWidgetTable = new MobileParaWidgetTable(designer);
mobileWidgetTable = new MobileWidgetTable(designer);
designer.addDesignerEditListener(new mobileWidgetDesignerAdapter());
centerPane = FRGUIPaneFactory.createCardLayout_S_Pane();
cardLayout = (CardLayout) centerPane.getLayout();
centerPane.add(mobileParaWidgetTable, PARA);
// 采用卡片布局的容器必须指定卡片名字,如果没有卡片名字
// 就会出现:Exception in thread "main" java.lang.IllegalArgumentException:
// cannot add to layout: constraint must be a string
// 第二个参数代表卡片的名字。后来show方法调用时通过名字找到要显示的卡片
centerPane.add(mobileWidgetTable, BODY); //这两句代码,是把JTable放到一个JPanel中去了,表头不会显示,
//只有放到JScrollPanel中去表头才能正常显示,这就是MobileWidgetTable中定义了表头却没有显示的原因!
//解决方案:MobileWidgetTable实在无法直接放到JScrollPanel中去的时候,应该把表头get出来单独作为一个组件显示
if (hasSelectParaPane(designer)) {
cardLayout.show(centerPane, PARA);
header = mobileParaWidgetTable.getTableHeader();
} else {
cardLayout.show(centerPane, BODY);
header = mobileWidgetTable.getTableHeader();
}
downPanel = new UIScrollPane(centerPane);
downPanel.setBorder(new LineBorder(Color.GRAY));
//获取拓展移动端属性tab
WidgetPropertyUIProvider[] widgetAttrProviders = getExtraPropertyUIProviders();
addWidgetAttr(widgetAttrProviders);
}
/**
* 将属性表事件表移动端控件列表整合到TabPane里面去
*/
private void createTabPane() {
UITabbedPane tabbedPane = new UITabbedPane(); // tab选项卡容器
initTabPane(tabbedPane);
add(tabbedPane, BorderLayout.CENTER);
}
/**
* 获取当前控件扩展的属性tab
* 来源有两个:
* 1, 各个控件从各自的Xcreator里扩展例如手机重布局的tab就是从Xcreator中扩展的;
* 2, 所有的控件从插件里扩展.
*
* @return 扩展的tab
*/
private WidgetPropertyUIProvider[] getExtraPropertyUIProviders() {
FormSelection selection = designer.getSelectionModel().getSelection();
WidgetPropertyUIProvider[] embeddedPropertyUIProviders = null;
if (selection != null && selection.getSelectedCreator() != null) {
embeddedPropertyUIProviders = selection.getSelectedCreator().getWidgetPropertyUIProviders();
}
Set<WidgetPropertyUIProvider> set = ExtraDesignClassManager.getInstance().getArray(WidgetPropertyUIProvider.XML_TAG);
return ArrayUtils.addAll(embeddedPropertyUIProviders, set.toArray(new WidgetPropertyUIProvider[set.size()]));
}
/**
* 判断是将拓展的tab放入属性表还是将原来的tab放入属性表
*
* @param widgetAttrProviders 拓展的tab
*/
private void addWidgetAttr(WidgetPropertyUIProvider[] widgetAttrProviders) {
if (widgetAttrProviders.length == 0) { // 判断有没有拓展的tab,没有就使用原来的
wsp.add(header);
wsp.add(downPanel);
} else {
for (WidgetPropertyUIProvider widgetAttrProvider : widgetAttrProviders) {
AbstractPropertyTable propertyTable = widgetAttrProvider.createWidgetAttrTable();
widgetPropertyTables.add(propertyTable);
designer.addDesignerEditListener(new WidgetPropertyDesignerAdapter(propertyTable));
UIScrollPane uiScrollPane = new UIScrollPane(getExtraBodyTable(propertyTable));
wsp.add(uiScrollPane);
}
}
}
/**
* 如果是body的拓展属性表那么要额外加上一张控件顺序表
*
* @return
*/
private Component getExtraBodyTable(AbstractPropertyTable abstractPropertyTable) {
Widget selection = designer.getSelectionModel().getSelection().getSelectedCreator().toData();
if (selection.getWidgetName().equals("body")) {
JPanel jPanel = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
jPanel.add(abstractPropertyTable);
MobileWidgetTable mobileWidgetTable = new MobileWidgetTable(designer);
jPanel.add(mobileWidgetTable.getTableHeader());
jPanel.add(mobileWidgetTable);
return jPanel;
}
return abstractPropertyTable;
}
private void initTabPane(UITabbedPane tabbedPane) {
tabbedPane.setOpaque(true);
tabbedPane.setBorder(null);
tabbedPane.setTabPlacement(SwingConstants.BOTTOM);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Properties"), psp);
tabbedPane.addTab(Inter.getLocText("FR-Designer_Event"), esp);
tabbedPane.addTab(Inter.getLocText("FR-Widget_Mobile_Terminal"), wsp);
}
/**
* 选中的组件是否在参数面板里
*
* @param designer 设计器
* @return 是则返回true
*/
public boolean hasSelectParaPane(FormDesigner designer) {
XCreator xCreator = designer.getSelectionModel().getSelection().getSelectedCreator();
if (xCreator == null) {
xCreator = designer.getRootComponent();
}
XLayoutContainer container = XCreatorUtils.getHotspotContainer(xCreator);
//TODO container可能为空,引发空指针异常
return xCreator.acceptType(XWParameterLayout.class) || container.acceptType(XWParameterLayout.class);
}
public void setEditingFormDesigner(BaseFormDesigner editor) {
FormDesigner fd = (FormDesigner) editor;
super.setEditingFormDesigner(fd);
}
private void clearDockingView() {
propertyTable = null;
eventTable = null;
if (widgetPropertyTables != null) {
widgetPropertyTables.clear();
}
JScrollPane psp = new JScrollPane();
psp.setBorder(null);
this.add(psp, BorderLayout.CENTER);
}
/**
* 属性表监听界面事件(编辑删除选中改变大小)
*/
private class WidgetPropertyDesignerAdapter implements DesignerEditListener {
AbstractPropertyTable propertyTable;
WidgetPropertyDesignerAdapter(AbstractPropertyTable propertyTable) {
this.propertyTable = propertyTable;
}
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
propertyTable.initPropertyGroups(designer);
} else if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED) {
repaint();
}
}
@Override
public boolean equals(Object o) {
return o instanceof WidgetPropertyDesignerAdapter && ((WidgetPropertyDesignerAdapter) o).propertyTable == this.propertyTable;
}
}
/**
* 事件表监听界面事件编辑选中
*/
private class EventPropertyDesignerAdapter implements DesignerEditListener {
EventPropertyTable propertyTable;
EventPropertyDesignerAdapter(EventPropertyTable eventTable) {
this.propertyTable = eventTable;
}
@Override
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED) {
propertyTable.refresh();
}
}
@Override
public boolean equals(Object o) {
return o instanceof EventPropertyDesignerAdapter;
}
}
/**
* 移动端属性表监听界面事件改变大小编辑选中增加控件
*/
private class mobileWidgetDesignerAdapter implements DesignerEditListener {
mobileWidgetDesignerAdapter() {
}
/**
* 响应界面改变事件
*
* @param evt 事件
*/
public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_RESIZED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_SELECTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED) {
int value = downPanel.getVerticalScrollBar().getValue();
if (hasSelectParaPane(getEditingFormDesigner())) {
cardLayout.show(centerPane, PARA);
mobileParaWidgetTable.refreshData();
} else {
cardLayout.show(centerPane, BODY);
mobileWidgetTable.refreshData();
}
//出现滚动条
downPanel.doLayout();
//控件列表选中某组件,触发表单中选中控件,选中事件又触发列表刷新,滚动条回到0
//此处设置滚动条值为刷新前
downPanel.getVerticalScrollBar().setValue(value);
}
}
}
@Override
public Location preferredLocation() {
return Location.WEST_BELOW;
}
}

42
designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java

@ -0,0 +1,42 @@
package com.fr.design.mainframe.templateinfo;
import com.fr.form.main.Form;
import com.fr.form.ui.container.WLayout;
/**
* Created by plough on 2017/3/17.
*/
public class JFormProcessInfo extends TemplateProcessInfo<Form> {
public JFormProcessInfo(Form form) {
super(form);
}
// 获取模板类型
public int getReportType() {
return 2;
}
// 获取模板格子数
public int getCellCount() {
return 0;
}
// 获取模板悬浮元素个数
public int getFloatCount() {
return 0;
}
// 获取模板聚合块个数
public int getBlockCount() {
return 0;
}
// 获取模板控件数
public int getWidgetCount() {
int widgetCount = 0;
for (int i = 0; i < template.getContainer().getWidgetCount(); i++) {
WLayout wl = (WLayout) template.getContainer().getWidget(i);
widgetCount += wl.getWidgetCount();
}
int a = 1;
int b = 2;
return widgetCount;
}
}

57
designer_form/src/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java

@ -0,0 +1,57 @@
package com.fr.design.mainframe.widget.accessibles;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.core.WidgetOption;
import com.fr.design.mainframe.FormWebWidgetConstants;
import com.fr.design.mainframe.widget.editors.ElementCaseToolBarPane;
import com.fr.design.mainframe.widget.wrappers.ElementCaseToolBarWrapper;
import com.fr.form.web.FormToolBarManager;
import com.fr.stable.ArrayUtils;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by harry on 2017-2-23.
*/
public class AccessibleElementCaseToolBarEditor extends UneditableAccessibleEditor {
private ElementCaseToolBarPane pane;
public AccessibleElementCaseToolBarEditor() {
super(new ElementCaseToolBarWrapper());
}
@Override
protected void showEditorPane() {
if (pane == null) {
pane = new ElementCaseToolBarPane();
pane.setDefaultToolBar(getDefaultToolBarManager(), getToolBarInstance());
}
BasicDialog dlg = pane.showToolBarWindow(SwingUtilities.getWindowAncestor(this), new DialogActionAdapter() {
@Override
public void doOk() {
setValue(pane.updateBean());
fireStateChanged();
}
});
FormToolBarManager[] managers = (FormToolBarManager[]) getValue();
pane.setCheckBoxSelected(ArrayUtils.isNotEmpty(managers));
pane.populateBean((FormToolBarManager[]) getValue());
dlg.setVisible(true);
}
private FormToolBarManager getDefaultToolBarManager() {
return FormToolBarManager.createDefaultToolBar();
}
private WidgetOption[] getToolBarInstance() {
List<WidgetOption> defaultOptions = Arrays.asList(FormWebWidgetConstants.getFormElementCaseToolBarInstance());
List<WidgetOption> options = new ArrayList<WidgetOption>();
options.addAll(defaultOptions);
return options.toArray(new WidgetOption[options.size()]);
}
}

13
designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarEditor.java

@ -0,0 +1,13 @@
package com.fr.design.mainframe.widget.editors;
import com.fr.design.mainframe.widget.accessibles.AccessibleElementCaseToolBarEditor;
import com.fr.design.mainframe.widget.accessibles.AccessiblePropertyEditor;
/**
* Created by harry on 2017-2-23.
*/
public class ElementCaseToolBarEditor extends AccessiblePropertyEditor {
public ElementCaseToolBarEditor() {
super(new AccessibleElementCaseToolBarEditor());
}
}

304
designer_form/src/com/fr/design/mainframe/widget/editors/ElementCaseToolBarPane.java

@ -0,0 +1,304 @@
package com.fr.design.mainframe.widget.editors;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.core.WidgetOption;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.FormSettingToolBar;
import com.fr.design.mainframe.FormToolBarButton;
import com.fr.design.mainframe.FormToolBarPane;
import com.fr.form.ui.Widget;
import com.fr.form.web.FormToolBarManager;
import com.fr.form.web.Location;
import com.fr.general.IOUtils;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Constants;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.ImageObserver;
import java.util.*;
import java.util.List;
/**
* Created by harry on 2017-2-23.
*/
public class ElementCaseToolBarPane extends BasicBeanPane<FormToolBarManager[]> {
private static final int COLUMN = 2;
private int row = 6;
private DefaultTableModel toolbarButtonTableModel;
private JTable layoutTable;
private UICheckBox isUseToolBarCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Use_ToolBar") + ":"); // 是否使用工具栏
private FormToolBarPane northToolBar;
private FormToolBarPane southToolBar;
private FormToolBarManager defaultToolBar;
public ElementCaseToolBarPane() {
toolbarButtonTableModel = new TableModel(row ,COLUMN);
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel north = FRGUIPaneFactory.createBorderLayout_S_Pane();
UIButton defaultButton = new UIButton(Inter.getLocText("FR-Designer_Restore_Default"));
// 恢复默认按钮
defaultButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
northToolBar.removeButtonList();
northToolBar.removeAll();
southToolBar.removeButtonList();
southToolBar.removeAll();
if (defaultToolBar == null) {
return;
}
FormToolBarManager toolBarManager = defaultToolBar;
toolBarManager.setToolBarLocation(Location.createTopEmbedLocation());
FormToolBarManager[] tbm = new FormToolBarManager[] { toolBarManager };
populateBean(tbm);
ElementCaseToolBarPane.this.repaint();
}
});
north.add(isUseToolBarCheckBox, BorderLayout.WEST);
JPanel aa = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
aa.add(defaultButton);
north.add(aa, BorderLayout.CENTER);
this.add(north, BorderLayout.NORTH);
northToolBar = new FormToolBarPane();
northToolBar.setPreferredSize(new Dimension(ImageObserver.WIDTH, 26));
northToolBar.setBackground(Color.lightGray);
UIButton topButton = new UIButton(IOUtils.readIcon("com/fr/design/images/arrow/arrow_up.png"));
topButton.setBorder(null);
topButton.setOpaque(false);
topButton.setContentAreaFilled(false);
topButton.setFocusPainted(false);
topButton.setRequestFocusEnabled(false);
topButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (isSelectedtable()) {
WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn());
Widget widget = no.createWidget();
FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget);
tb.setNameOption(no);
northToolBar.add(tb);
northToolBar.validate();
northToolBar.repaint();
} else {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_ChooseOneButton"));
}
}
});
UIButton downButton = new UIButton(IOUtils.readIcon("com/fr/design/images/arrow/arrow_down.png"));
downButton.setBorder(null);
downButton.setMargin(null);
downButton.setOpaque(false);
downButton.setContentAreaFilled(false);
downButton.setFocusPainted(false);
downButton.setRequestFocusEnabled(false);
downButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (isSelectedtable()) {
WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn());
Widget widget = no.createWidget();
FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget);
tb.setNameOption(no);
southToolBar.add(tb);
southToolBar.validate();
southToolBar.repaint();
} else {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_ChooseOneButton"));
}
}
});
initLayoutTable();
JPanel center = FRGUIPaneFactory.createBorderLayout_S_Pane();
center.setBackground(Color.white);
center.add(topButton, BorderLayout.NORTH);
JPanel small = FRGUIPaneFactory.createBorderLayout_S_Pane();
small.setBackground(Color.white);
small.add(new UILabel(StringUtils.BLANK), BorderLayout.NORTH);
small.add(layoutTable, BorderLayout.CENTER);
center.add(small, BorderLayout.CENTER);
center.add(downButton, BorderLayout.SOUTH);
southToolBar = new FormToolBarPane();
southToolBar.setPreferredSize(new Dimension(ImageObserver.WIDTH, 26));
southToolBar.setBackground(Color.lightGray);
JPanel movePane = FRGUIPaneFactory.createBorderLayout_S_Pane();
JPanel northContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
FormSettingToolBar top = new FormSettingToolBar(Inter.getLocText("FR-Designer_ToolBar_Top"), northToolBar);
northContentPane.add(top, BorderLayout.EAST);
northContentPane.add(northToolBar, BorderLayout.CENTER);
northContentPane.setBackground(Color.lightGray);
JPanel southContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
FormSettingToolBar bottom = new FormSettingToolBar(Inter.getLocText("FR-Designer_ToolBar_Bottom"), southToolBar);
southContentPane.add(bottom, BorderLayout.EAST);
southContentPane.add(southToolBar, BorderLayout.CENTER);
southContentPane.setBackground(Color.lightGray);
movePane.add(northContentPane, BorderLayout.NORTH);
movePane.add(center, BorderLayout.CENTER);
movePane.add(southContentPane, BorderLayout.SOUTH);
this.add(new JScrollPane(movePane), BorderLayout.CENTER);
isUseToolBarCheckBox.setSelected(false);
}
private void initLayoutTable() {
layoutTable = new JTable(toolbarButtonTableModel);
layoutTable.setDefaultRenderer(Object.class, tableRenderer);
layoutTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
layoutTable.setColumnSelectionAllowed(false);
layoutTable.setRowSelectionAllowed(false);
layoutTable.setBackground(Color.white);
int columnWidth = Integer.parseInt(Inter.getLocText("FR-Designer_LayoutTable_Column_Width"));
for (int i = 0; i < layoutTable.getColumnModel().getColumnCount(); i++) {
layoutTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidth);
}
layoutTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1 && !SwingUtilities.isRightMouseButton(e)) {
WidgetOption no = (WidgetOption)layoutTable.getValueAt(layoutTable.getSelectedRow(), layoutTable.getSelectedColumn());
Widget widget = no.createWidget();
FormToolBarButton tb = new FormToolBarButton(no.optionIcon(), widget);
tb.setNameOption(no);
northToolBar.add(tb);
northToolBar.validate();
northToolBar.repaint();
}
}
});
}
private boolean isSelectedtable() {
for (int i = 0; i < layoutTable.getColumnCount(); i++) {
if (layoutTable.isColumnSelected(i)) {
return true;
}
}
return false;
}
/**
* 是否被选中
* @return 同上
*/
public boolean isUseToolbar() {
return this.isUseToolBarCheckBox.isSelected();
}
public void setDefaultToolBar(FormToolBarManager defaultToolBar, WidgetOption[] buttonArray) {
this.defaultToolBar = defaultToolBar;
if (buttonArray != null) {
for (int i = 0; i < buttonArray.length; i++) {
toolbarButtonTableModel.setValueAt(buttonArray[i], i % row, i / row);
}
}
}
DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof WidgetOption) {
WidgetOption nameOption = (WidgetOption)value;
this.setText(nameOption.optionName());
Icon icon = nameOption.optionIcon();
if (icon != null) {
this.setIcon(icon);
}
}
if (value == null) {
this.setText(StringUtils.EMPTY);
this.setIcon(null);
}
return this;
}
};
@Override
protected String title4PopupWindow() {
return Inter.getLocText(new String[]{"Form-EC_toolbar", "Set"});
}
public void setCheckBoxSelected(boolean b) {
this.isUseToolBarCheckBox.setSelected(b);
}
@Override
public void populateBean(FormToolBarManager[] toolBarManager) {
if (ArrayUtils.isEmpty(toolBarManager)) {
defaultToolBar.setToolBarLocation(Location.createTopEmbedLocation());
toolBarManager = new FormToolBarManager[] { defaultToolBar };
}
if (ArrayUtils.isEmpty(toolBarManager)) {
return;
}
for (int i = 0; i < toolBarManager.length; i++) {
Location location = toolBarManager[i].getToolBarLocation();
if (location instanceof Location.Embed) {
if (((Location.Embed)location).getPosition() == Constants.TOP) {
northToolBar.populateBean(toolBarManager[i].getToolBar());
} else if (((Location.Embed)location).getPosition() == Constants.BOTTOM) {
southToolBar.populateBean(toolBarManager[i].getToolBar());
}
}
}
}
@Override
public FormToolBarManager[] updateBean() {
if(!isUseToolbar()){
return new FormToolBarManager[0];
}
List<FormToolBarManager> toolBarManagerList = new ArrayList<FormToolBarManager>();
if (!northToolBar.isEmpty()) {
FormToolBarManager north = new FormToolBarManager();
north.setToolBar(northToolBar.updateBean());
north.setToolBarLocation(Location.createTopEmbedLocation());
toolBarManagerList.add(north);
}
if (!southToolBar.isEmpty()) {
FormToolBarManager south = new FormToolBarManager();
south.setToolBar(southToolBar.updateBean());
south.setToolBarLocation(Location.createBottomEmbedLocation());
toolBarManagerList.add(south);
}
return toolBarManagerList.toArray(new FormToolBarManager[toolBarManagerList.size()]);
}
private class TableModel extends DefaultTableModel {
public TableModel(int i, int j) {
super(i, j);
}
// 禁止jtable的双击编辑功能
public boolean isCellEditable(int row, int column) {
return false;
}
}
}

34
designer_form/src/com/fr/design/mainframe/widget/wrappers/ElementCaseToolBarWrapper.java

@ -0,0 +1,34 @@
package com.fr.design.mainframe.widget.wrappers;
import com.fr.design.Exception.ValidationException;
import com.fr.design.designer.properties.Decoder;
import com.fr.design.designer.properties.Encoder;
import com.fr.form.web.FormToolBarManager;
import com.fr.general.Inter;
/**
* Created by harry on 2017-3-1.
*/
public class ElementCaseToolBarWrapper implements Encoder, Decoder {
@Override
public Object decode(String txt) {
return null;
}
@Override
public void validate(String txt) throws ValidationException {
}
@Override
public String encode(Object v) {
if (v == null) {
return null;
}
FormToolBarManager[] toolBarManager = (FormToolBarManager[])v;
if (toolBarManager.length != 0) {
return Inter.getLocText("FR-Designer_Open");
}
return Inter.getLocText("FR-Designer_Close");
}
}
Loading…
Cancel
Save