381 changed files with 38348 additions and 0 deletions
@ -1,2 +1,3 @@ |
|||||||
designer/bin |
designer/bin |
||||||
designer_chart/bin |
designer_chart/bin |
||||||
|
designer_form/bin |
||||||
|
@ -0,0 +1,15 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<classpath> |
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6u35"/> |
||||||
|
<classpathentry kind="src" path="src"/> |
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/lib"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/base"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/form"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/designer_base"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/base-stable"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/base-basic"/> |
||||||
|
<classpathentry kind="lib" path="/lib/3rd.jar"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/base-calculate"/> |
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/base-data"/> |
||||||
|
<classpathentry kind="output" path="bin"/> |
||||||
|
</classpath> |
@ -0,0 +1 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>designer_form</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription> |
@ -0,0 +1,21 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<module type="JAVA_MODULE" version="4"> |
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false"> |
||||||
|
<output url="file://$MODULE_DIR$/../../env/WebReport/WEB-INF/classes" /> |
||||||
|
<content url="file://$MODULE_DIR$"> |
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |
||||||
|
</content> |
||||||
|
<orderEntry type="jdk" jdkName="jdk1.8" jdkType="JavaSDK" /> |
||||||
|
<orderEntry type="sourceFolder" forTests="false" /> |
||||||
|
<orderEntry type="module" module-name="designer_base" exported="" /> |
||||||
|
<orderEntry type="library" scope="PROVIDED" name="lib" level="project" /> |
||||||
|
<orderEntry type="module" module-name="base" /> |
||||||
|
<orderEntry type="module" module-name="base-basic" /> |
||||||
|
<orderEntry type="module" module-name="base-calculate" /> |
||||||
|
<orderEntry type="module" module-name="base-data" /> |
||||||
|
<orderEntry type="module" module-name="base-file" /> |
||||||
|
<orderEntry type="module" module-name="base-performance" /> |
||||||
|
<orderEntry type="module" module-name="base-stable" /> |
||||||
|
<orderEntry type="module" module-name="form" /> |
||||||
|
</component> |
||||||
|
</module> |
@ -0,0 +1,78 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.RootPaneContainer; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
||||||
|
import com.fr.design.designer.beans.painters.NullLayoutPainter; |
||||||
|
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.utils.ComponentUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 适配器中枢,为组件和组件适配器、布局和布局适配器。 |
||||||
|
*/ |
||||||
|
public class AdapterBus { |
||||||
|
|
||||||
|
public static final String CLIENT_PROPERTIES = "component.adapter"; |
||||||
|
|
||||||
|
public static JComponent getJComponent(Component component) { |
||||||
|
JComponent jcomponent; |
||||||
|
if (component instanceof JComponent) { |
||||||
|
jcomponent = (JComponent) component; |
||||||
|
} else if (component instanceof RootPaneContainer) { |
||||||
|
jcomponent = (JComponent) ((RootPaneContainer) component).getContentPane(); |
||||||
|
} else { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return jcomponent; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取组件类型是componentClass对应的组件适配器,如果初始映射表中没有该适配器, |
||||||
|
* 则继续查找其父类对应的适配器,直至查找到Component类为止,如果还是没有查找到, |
||||||
|
* 则使用缺省的组件适配器:DefaultComponentAdapter |
||||||
|
* |
||||||
|
* @return 该组件类所对应的组件适配器对象 |
||||||
|
*/ |
||||||
|
public static ComponentAdapter getComponentAdapter(FormDesigner designer, JComponent creator) { |
||||||
|
JComponent jcomponent = getJComponent(creator); |
||||||
|
ComponentAdapter adapter = (ComponentAdapter) jcomponent.getClientProperty("component.adapter"); |
||||||
|
if (adapter == null) { |
||||||
|
adapter = new CompositeComponentAdapter(designer, creator); |
||||||
|
jcomponent.putClientProperty(CLIENT_PROPERTIES, adapter); |
||||||
|
} |
||||||
|
return adapter; |
||||||
|
} |
||||||
|
|
||||||
|
public static XCreator getFirstInvisibleParent(XCreator comp) { |
||||||
|
XCreator parent = comp; |
||||||
|
|
||||||
|
while ((parent != null) && parent.isVisible()) { |
||||||
|
parent = XCreatorUtils.getParentXLayoutContainer(parent); |
||||||
|
} |
||||||
|
|
||||||
|
return parent; |
||||||
|
} |
||||||
|
|
||||||
|
public static LayoutAdapter searchLayoutAdapter(FormDesigner designer, XCreator comp) { |
||||||
|
if (ComponentUtils.isRootComponent(comp)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return XCreatorUtils.getParentXLayoutContainer(comp).getLayoutAdapter(); |
||||||
|
} |
||||||
|
|
||||||
|
public static HoverPainter getContainerPainter(FormDesigner designer, XLayoutContainer container) { |
||||||
|
// 容器组件的适配器
|
||||||
|
LayoutAdapter containerAdapter = container.getLayoutAdapter(); |
||||||
|
HoverPainter painter = containerAdapter.getPainter(); |
||||||
|
if (painter != null) { |
||||||
|
return painter; |
||||||
|
} |
||||||
|
return new NullLayoutPainter(container); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPopupMenu; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
|
||||||
|
/** |
||||||
|
* 组件适配器接口 |
||||||
|
* 主要目的是为具体组件提供特殊设计行为 |
||||||
|
*/ |
||||||
|
public interface ComponentAdapter { |
||||||
|
|
||||||
|
/** |
||||||
|
* 在组件选择面板上选择了组件类型后,在设计界面上跟随鼠标移动用来代表当前要添加组件的图形 |
||||||
|
* 一般使用组件自身的图形代替。 |
||||||
|
* |
||||||
|
* @param component 要添加的组件 |
||||||
|
* @param g 当前设计器的图形上下文对象 |
||||||
|
*/ |
||||||
|
void paintComponentMascot(Graphics g); |
||||||
|
|
||||||
|
/** |
||||||
|
* 当鼠标在此设计组件上右键点击时,该方法根据上下文和组件类型提供弹出响应的菜单 |
||||||
|
* |
||||||
|
* @param 引发弹出菜单的鼠标事件 |
||||||
|
* |
||||||
|
* @return 弹出菜单 |
||||||
|
*/ |
||||||
|
JPopupMenu getContextPopupMenu(MouseEvent e); |
||||||
|
|
||||||
|
/** |
||||||
|
* 为当前组件创建描述属性表的model, 分组返回 |
||||||
|
* @return BeanPropertyModel |
||||||
|
*/ |
||||||
|
ArrayList<GroupModel> getXCreatorPropertyModel(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 提供双击设计器的编辑器 |
||||||
|
* @param bean 鼠标双击的被设计组件 |
||||||
|
* @return 被设计的编辑器 |
||||||
|
*/ |
||||||
|
public DesignerEditor<? extends JComponent> getDesignerEditor(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 实例化组件的适配器后,在这儿进行初始化 |
||||||
|
*/ |
||||||
|
void initialize(); |
||||||
|
} |
@ -0,0 +1,215 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.PriorityQueue; |
||||||
|
|
||||||
|
import com.fr.form.ui.container.WLayout; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; |
||||||
|
|
||||||
|
|
||||||
|
public class ConnectorCreator { |
||||||
|
|
||||||
|
public static final int UNIT = 10; |
||||||
|
public static final int SIDE = 2; |
||||||
|
public static final int CORNER_LOSS = 20; |
||||||
|
public static final int vector[][] = { { UNIT, 0 }, { -UNIT, 0 }, { 0, UNIT }, { 0, -UNIT } }; |
||||||
|
|
||||||
|
private long timeOut = 200; |
||||||
|
private boolean beyond; |
||||||
|
private WLayout container; |
||||||
|
private BoundsWidget IgnoreLayout; |
||||||
|
private Point startPoint; |
||||||
|
private Point endPoint; |
||||||
|
private PriorityQueue<AssessedPoint> open = new PriorityQueue<AssessedPoint>(); |
||||||
|
private PriorityQueue<AssessedPoint> close = new PriorityQueue<AssessedPoint>(); |
||||||
|
|
||||||
|
public ConnectorCreator(WLayout container, Point startPoint, Point endPoint) { |
||||||
|
this.container =container; |
||||||
|
this.startPoint = startPoint; |
||||||
|
this.endPoint = endPoint; |
||||||
|
if (getNearWidget(this.endPoint, SIDE * UNIT - 1) != null) { |
||||||
|
if ((IgnoreLayout = getNearWidget(this.endPoint, -1)) == null) { |
||||||
|
beyond = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static int difference(int x, int y) { |
||||||
|
int p; |
||||||
|
if (x < y) { |
||||||
|
p = x; |
||||||
|
x = y; |
||||||
|
y = p; |
||||||
|
} |
||||||
|
return x - y; |
||||||
|
} |
||||||
|
|
||||||
|
public static int getMinimumDistance(Point A, Point B) { |
||||||
|
return difference(A.x, B.x) + difference(A.y, B.y) + (A.x == B.x || A.y == B.y ? 0 : CORNER_LOSS); |
||||||
|
} |
||||||
|
|
||||||
|
private BoundsWidget getNearWidget(Point endPoint, int l) { |
||||||
|
Rectangle[] r = new Rectangle[container.getWidgetCount()]; |
||||||
|
Rectangle temp = new Rectangle(); |
||||||
|
BoundsWidget widget; |
||||||
|
for (int i = 0, size = r.length; i < size; i++) { |
||||||
|
widget = ((BoundsWidget) container.getWidget(i)); |
||||||
|
if (widget.isVisible()) { |
||||||
|
r[i] = widget.getBounds(); |
||||||
|
temp.setBounds(r[i]); |
||||||
|
temp.grow(l, l); |
||||||
|
if (inside(endPoint, temp)) { |
||||||
|
return widget; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean arrive(Point p1, Point p2) { |
||||||
|
if (!beyond) { |
||||||
|
return p1.x - p2.x < UNIT && p2.x - p1.x < UNIT && p1.y - p2.y < UNIT && p2.y - p1.y < UNIT; |
||||||
|
} else { |
||||||
|
return p1.x - p2.x < (SIDE +1)* UNIT && p2.x - p1.x < (SIDE +1) * UNIT && p1.y - p2.y < (SIDE +1)* UNIT && p2.y - p1.y < (SIDE +1) * UNIT; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private boolean inside(Point p, Rectangle r) { |
||||||
|
return p.x >= r.x && p.x <= r.x + r.width && p.y >= r.y && p.y <= r.y + r.height; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean check(Point p) { |
||||||
|
if (p.x <= 0 || p.y <= 0) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
BoundsWidget bw = getNearWidget(p, SIDE * UNIT - 1); |
||||||
|
return bw == IgnoreLayout || bw ==null; |
||||||
|
} |
||||||
|
|
||||||
|
public ArrayList<Point> createPointList() { |
||||||
|
ArrayList<Point> l = new ArrayList<Point>(); |
||||||
|
AssessedPoint pst = new AssessedPoint(startPoint,null,false); |
||||||
|
AssessedPoint temp ; |
||||||
|
long startTime = System.currentTimeMillis(); |
||||||
|
open.add(pst); |
||||||
|
while ((temp = open.poll()) != null || (checkClose() && (temp = open.poll()) != null)) { |
||||||
|
if (arrive(temp.p, endPoint)) { |
||||||
|
temp.getS(); |
||||||
|
l.addAll(temp.pointList); |
||||||
|
return l; |
||||||
|
} else { |
||||||
|
close.add(temp); |
||||||
|
temp.pushInto(); |
||||||
|
} |
||||||
|
if (System.currentTimeMillis() - startTime > timeOut) { |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
l.add(startPoint); |
||||||
|
l.add(new Point(startPoint.x,endPoint.y)); |
||||||
|
l.add(endPoint); |
||||||
|
return l; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean checkClose() { |
||||||
|
if(close.size() == 1) { |
||||||
|
AssessedPoint p = close.poll(); |
||||||
|
return p.reCheck(); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
class AssessedPoint implements Comparable<AssessedPoint>{ |
||||||
|
ArrayList<Point> pointList; |
||||||
|
Point p; |
||||||
|
Point parent; |
||||||
|
int distance; |
||||||
|
int g; |
||||||
|
|
||||||
|
AssessedPoint(Point p, AssessedPoint parent, boolean loss) { |
||||||
|
this.p = p; |
||||||
|
pointList = new ArrayList<Point>(); |
||||||
|
if (parent != null) { |
||||||
|
this.g = parent.g + (loss ? CORNER_LOSS : UNIT); |
||||||
|
this.parent = parent.p; |
||||||
|
pointList.addAll(parent.pointList); |
||||||
|
if (loss) { |
||||||
|
pointList.add(parent.p); |
||||||
|
} |
||||||
|
} else { |
||||||
|
pointList.add(p); |
||||||
|
g = 0; |
||||||
|
} |
||||||
|
this.distance = getMinimumDistance(p, endPoint) + g; |
||||||
|
} |
||||||
|
|
||||||
|
public void getS() { |
||||||
|
int size = pointList.size(); |
||||||
|
if(size > 1) { |
||||||
|
Point p1 = pointList.get(size - 1); |
||||||
|
if(p1.x == p.x) { |
||||||
|
if(endPoint.x != p1.x) { |
||||||
|
if(beyond) { |
||||||
|
pointList.add(new Point(p1.x,endPoint.y)); |
||||||
|
} else { |
||||||
|
p1.x = p.x = endPoint.x; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} else if(p1.y == p.y) { |
||||||
|
if(endPoint.y != p1.y) { |
||||||
|
if(beyond) { |
||||||
|
pointList.add(new Point(endPoint.x,p1.y)); |
||||||
|
} else { |
||||||
|
p1.y = p.y = endPoint.y; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else if (size == 1 && (startPoint.x != endPoint.x || startPoint.y != endPoint.y)) { |
||||||
|
pointList.add(new Point(startPoint.x, endPoint.y)); |
||||||
|
} |
||||||
|
pointList.add(endPoint); |
||||||
|
} |
||||||
|
|
||||||
|
public int compareTo(AssessedPoint o) { |
||||||
|
return distance - o.distance; |
||||||
|
} |
||||||
|
|
||||||
|
void pushInto() { |
||||||
|
for (int i = 0; i < vector.length; i++) { |
||||||
|
Point temp = new Point(p.x + vector[i][0], p.y + vector[i][1]); |
||||||
|
if (parent != null && parent.x == temp.x && parent.y == temp.y) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
AssessedPoint ap = new AssessedPoint(temp, this, loss(temp)); |
||||||
|
if (check(temp) && !open.contains(ap) && !close.contains(ap)) { |
||||||
|
open.add(ap); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
boolean reCheck() { |
||||||
|
for (int i = 0; i < vector.length; i++) { |
||||||
|
Point temp = new Point(p.x + SIDE * vector[i][0], p.y + SIDE * vector[i][1]); |
||||||
|
AssessedPoint ap = new AssessedPoint(temp, this, loss(temp)); |
||||||
|
if (check(temp)) { |
||||||
|
open.add(ap); |
||||||
|
} |
||||||
|
} |
||||||
|
return open.size() != 0; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean loss(Point temp) { |
||||||
|
return (parent != null && ((p.x == parent.x && temp.x != p.x) || (p.y == parent.y && temp.y != p.y))); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object o) { |
||||||
|
return o instanceof AssessedPoint && ((AssessedPoint) o).p.x == p.x && ((AssessedPoint) o).p.y == p.y; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
|
||||||
|
public interface ConstraintsGroupModel extends GroupModel { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
|
||||||
|
/** |
||||||
|
* 渲染器,目的是为组件或者布局管理器提供额外的渲染入口。 |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public interface HoverPainter extends Painter { |
||||||
|
/** |
||||||
|
* 当前焦点热点,即鼠标所在点 |
||||||
|
* @param p 焦点位置 |
||||||
|
*/ |
||||||
|
void setHotspot(Point p); |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前要放置的组件 |
||||||
|
* @param creator 组件 |
||||||
|
*/ |
||||||
|
void setCreator(XCreator creator); |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
/* |
||||||
|
* To change this template, choose Tools | Templates |
||||||
|
* and open the template in the editor. |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
/** |
||||||
|
* 编辑器的增量,包括上下左右4个方向的增量 |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class Incremental { |
||||||
|
public int top = 0; |
||||||
|
public int left = 0; |
||||||
|
public int bottom = 0; |
||||||
|
public int right = 0; |
||||||
|
|
||||||
|
public Incremental() { |
||||||
|
this(0, 0, 0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
public Incremental(int top, int left, int bottom, int right) { |
||||||
|
this.top = top; |
||||||
|
this.left = left; |
||||||
|
this.bottom = bottom; |
||||||
|
this.right = right; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,85 @@ |
|||||||
|
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); |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package com.fr.design.designer.beans; |
||||||
|
|
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
public interface Painter { |
||||||
|
//当前焦点区域,即所在容器的边界
|
||||||
|
void setRenderingBounds(Rectangle rect); |
||||||
|
|
||||||
|
//渲染入口,由FormDesigner调用来外成额外渲染
|
||||||
|
void paint(Graphics g, int startX, int startY); |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.actions; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.designer.creator.XWidgetCreator; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class ChangeNameAction extends FormUndoableAction { |
||||||
|
|
||||||
|
public ChangeNameAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
|
||||||
|
this.setName(Inter.getLocText("Form-Change_Widget_Name")); |
||||||
|
this.setMnemonic('G'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/refresh.png")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 重命名 |
||||||
|
* |
||||||
|
* @return 是否重命名成功 |
||||||
|
* |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
FormDesigner designer = getEditingComponent(); |
||||||
|
if (designer == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
// 如果选中了多个也只改变选中的第一个控件的名字
|
||||||
|
XWidgetCreator creator = (XWidgetCreator) designer.getSelectionModel().getSelection().getSelectedCreator(); |
||||||
|
if(creator == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
creator.ChangeCreatorName(designer, creator); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package com.fr.design.designer.beans.actions; |
||||||
|
|
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.actions.ToggleButtonUpdateAction; |
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.gui.ibutton.UIToggleButton; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.design.utils.gui.GUICoreUtils; |
||||||
|
|
||||||
|
//marro : 连接线按钮,目前用不到,但是类先留着。2012-3-26
|
||||||
|
public class ConnectionAction extends UpdateAction implements ToggleButtonUpdateAction { |
||||||
|
private FormDesigner fd; |
||||||
|
|
||||||
|
public ConnectionAction(FormDesigner fd) { |
||||||
|
this.fd = fd; |
||||||
|
this.setName(Inter.getLocText("Connectionline")); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/toolbarbtn/connector.png")); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
UIToggleButton toggleButton = this.createToolBarComponent(); |
||||||
|
fd.setDrawLineMode(toggleButton.isSelected()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public UIToggleButton createToolBarComponent() { |
||||||
|
return GUICoreUtils.createToolBarComponent(this); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
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 CutAction extends FormEditAction { |
||||||
|
|
||||||
|
public CutAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
this.setName(Inter.getLocText("M_Edit-Cut")); |
||||||
|
this.setMnemonic('T'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/cut.png")); |
||||||
|
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
FormDesigner editPane = getEditingComponent(); |
||||||
|
if (editPane == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return editPane.cut(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.actions; |
||||||
|
|
||||||
|
import java.awt.event.KeyEvent; |
||||||
|
|
||||||
|
import javax.swing.KeyStroke; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.mainframe.FormSelection; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class FormDeleteAction extends FormUndoableAction { |
||||||
|
|
||||||
|
public FormDeleteAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
|
||||||
|
this.setName(Inter.getLocText("M_Edit-Delete")); |
||||||
|
this.setMnemonic('D'); |
||||||
|
// Richie:删除菜单图标
|
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/delete.png")); |
||||||
|
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
* |
||||||
|
* @return 是否删除成功 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
FormDesigner designer = getEditingComponent(); |
||||||
|
if (designer == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
FormSelection selection = designer.getSelectionModel().getSelection(); |
||||||
|
XCreator creator = selection.getSelectedCreator(); |
||||||
|
designer.getSelectionModel().deleteSelection(); |
||||||
|
|
||||||
|
creator.deleteRelatedComponent(creator, designer); |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void update() { |
||||||
|
// FormDesigner f = this.getEditingComponent();
|
||||||
|
// if (f == null) {
|
||||||
|
// this.setEnabled(false);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// SelectionModel selection = f.getSelectionModel();
|
||||||
|
// this.setEnabled(selection.hasSelectionComponent());
|
||||||
|
this.setEnabled(true); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.fr.design.designer.beans.actions; |
||||||
|
|
||||||
|
import com.fr.design.actions.TemplateComponentAction; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public abstract class FormEditAction extends TemplateComponentAction<FormDesigner> { |
||||||
|
|
||||||
|
protected FormEditAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void update() { |
||||||
|
this.setEnabled(true); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.actions; |
||||||
|
|
||||||
|
import com.fr.design.actions.TemplateComponentAction; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public abstract class FormUndoableAction extends TemplateComponentAction<FormDesigner> { |
||||||
|
protected FormUndoableAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
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 PasteAction extends FormEditAction { |
||||||
|
|
||||||
|
public PasteAction(FormDesigner t) { |
||||||
|
super(t); |
||||||
|
this.setName(Inter.getLocText("M_Edit-Paste")); |
||||||
|
this.setMnemonic('P'); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_edit/paste.png")); |
||||||
|
this.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
FormDesigner tc = getEditingComponent(); |
||||||
|
if (tc == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return tc.paste(); |
||||||
|
} |
||||||
|
@Override |
||||||
|
public void update() { |
||||||
|
this.setEnabled(true); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,167 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.component; |
||||||
|
|
||||||
|
import java.awt.AlphaComposite; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Collections; |
||||||
|
import java.util.HashMap; |
||||||
|
|
||||||
|
import javax.swing.Action; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPopupMenu; |
||||||
|
|
||||||
|
import com.fr.base.FRContext; |
||||||
|
import com.fr.design.actions.UpdateAction; |
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.gui.xtable.PropertyGroupModel; |
||||||
|
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
|
import com.fr.design.designer.beans.actions.ChangeNameAction; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
import com.fr.design.designer.creator.CRPropertyDescriptor; |
||||||
|
import com.fr.design.designer.creator.XButton; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.form.ui.Button; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class CompositeComponentAdapter implements ComponentAdapter { |
||||||
|
|
||||||
|
protected FormDesigner designer; |
||||||
|
protected DesignerEditor<? extends JComponent> editorComponent; |
||||||
|
protected XCreator xCreator; |
||||||
|
|
||||||
|
public CompositeComponentAdapter(FormDesigner designer, Component c) { |
||||||
|
this.designer = designer; |
||||||
|
this.xCreator = (XCreator) c; |
||||||
|
} |
||||||
|
/** |
||||||
|
* 实例化组件的适配器后,在这儿进行初始化 |
||||||
|
*/ |
||||||
|
public void initialize() { |
||||||
|
initButtonText(); |
||||||
|
Dimension initialSize = xCreator.getPreferredSize(); |
||||||
|
xCreator.setSize(initialSize); |
||||||
|
LayoutUtils.layoutContainer(xCreator); |
||||||
|
} |
||||||
|
|
||||||
|
private void initButtonText() { |
||||||
|
Widget widget = xCreator.toData(); |
||||||
|
if (xCreator instanceof XButton && StringUtils.isEmpty(((Button) widget).getText())) { |
||||||
|
((Button) xCreator.toData()).setText(widget.getWidgetName()); |
||||||
|
((XButton) xCreator).setButtonText(widget.getWidgetName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paintComponentMascot(Graphics g) { |
||||||
|
//自适应交叉点渲染有点问题,拖拽的控件设置成半透明
|
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,.5f); |
||||||
|
g2d.setComposite(composite); |
||||||
|
xCreator.paint(g2d); |
||||||
|
g.setColor(XCreatorConstants.RESIZE_BOX_BORDER_COLOR); |
||||||
|
g.drawRect(0, 0, xCreator.getWidth() - 1, xCreator.getHeight() - 1); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public JPopupMenu getContextPopupMenu(MouseEvent e) { |
||||||
|
JPopupMenu popupMenu = new JPopupMenu(); |
||||||
|
if (changeVarNameAction == null) { |
||||||
|
changeVarNameAction = new ChangeNameAction(designer); |
||||||
|
} |
||||||
|
//底层布局或者是自适应布局都不能删除
|
||||||
|
boolean isRootComponent = ComponentUtils.isRootComponent(xCreator) || designer.isRoot(xCreator); |
||||||
|
changeVarNameAction.setEnabled(!isRootComponent); |
||||||
|
popupMenu.add(changeVarNameAction); |
||||||
|
|
||||||
|
Action[] actions = designer.getActions(); |
||||||
|
for (Action action : actions) { |
||||||
|
action.setEnabled(!designer.isRootRelatedAction(((UpdateAction)action).getName()) || !isRootComponent); |
||||||
|
popupMenu.add(action); |
||||||
|
} |
||||||
|
return popupMenu; |
||||||
|
} |
||||||
|
|
||||||
|
private ChangeNameAction changeVarNameAction; |
||||||
|
|
||||||
|
private ArrayList<PropertyGroupModel> createPropertyGroupModels(CRPropertyDescriptor[] properties) { |
||||||
|
HashMap<String, ArrayList<CRPropertyDescriptor>> maps = new HashMap<String, ArrayList<CRPropertyDescriptor>>(); |
||||||
|
ArrayList<String> groupNames = new ArrayList<String>(); |
||||||
|
for (CRPropertyDescriptor property : properties) { |
||||||
|
String groupName = (String) property.getValue(XCreatorConstants.PROPERTY_CATEGORY); |
||||||
|
if (StringUtils.isEmpty(groupName)) { |
||||||
|
groupName = XCreatorConstants.DEFAULT_GROUP_NAME; |
||||||
|
} |
||||||
|
ArrayList<CRPropertyDescriptor> groupProperties = maps.get(groupName); |
||||||
|
if (groupProperties == null) { |
||||||
|
groupProperties = new ArrayList<CRPropertyDescriptor>(); |
||||||
|
maps.put(groupName, groupProperties); |
||||||
|
groupNames.add(groupName); |
||||||
|
} |
||||||
|
groupProperties.add(property); |
||||||
|
} |
||||||
|
ArrayList<PropertyGroupModel> groups = new ArrayList<PropertyGroupModel>(); |
||||||
|
for (String groupName : groupNames) { |
||||||
|
ArrayList<CRPropertyDescriptor> groupProperties = maps.get(groupName); |
||||||
|
PropertyGroupModel groupModel = new PropertyGroupModel(groupName, xCreator, groupProperties |
||||||
|
.toArray(new CRPropertyDescriptor[0]), designer); |
||||||
|
groups.add(groupModel); |
||||||
|
} |
||||||
|
return groups; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ArrayList<GroupModel> getXCreatorPropertyModel() { |
||||||
|
ArrayList<GroupModel> groupModels = new ArrayList<GroupModel>(); |
||||||
|
CRPropertyDescriptor[] properties; |
||||||
|
properties = getCalculateCreatorProperties(); |
||||||
|
ArrayList<PropertyGroupModel> groups = createPropertyGroupModels(properties); |
||||||
|
Collections.sort(groups); |
||||||
|
groupModels.addAll(groups); |
||||||
|
return groupModels; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 自适应布局中放置文本框等用的scaleLayout和报表块、图表块支持的标题控件用的titleLayout时 |
||||||
|
* 控件树处只显示父容器,但是控件属性还是为自身的 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private CRPropertyDescriptor[] getCalculateCreatorProperties() { |
||||||
|
try { |
||||||
|
return xCreator.getPropertyDescriptorCreator().supportedDescriptor(); |
||||||
|
} catch (IntrospectionException ex) { |
||||||
|
FRContext.getLogger().error(ex.getMessage(), ex); |
||||||
|
return new CRPropertyDescriptor[0]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DesignerEditor<? extends JComponent> getDesignerEditor() { |
||||||
|
if (editorComponent == null) { |
||||||
|
editorComponent = xCreator.getDesignerEditor(); |
||||||
|
if (editorComponent != null) { |
||||||
|
editorComponent.addPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
designer.fireTargetModified(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
if (editorComponent != null) { |
||||||
|
editorComponent.reset(); |
||||||
|
} |
||||||
|
return editorComponent; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.design.designer.beans.ConstraintsGroupModel; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class AbsoluteLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public AbsoluteLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addComp(XCreator creator, int x, int y) { |
||||||
|
int w = creator.getWidth() / 2; |
||||||
|
int h = creator.getHeight() / 2; |
||||||
|
creator.setLocation(x - w, y - h); |
||||||
|
container.add(creator); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.awt.Stroke; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.Painter; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
|
||||||
|
public abstract class AbstractAnchorPainter implements Painter { |
||||||
|
|
||||||
|
protected Container container; |
||||||
|
protected Rectangle hotspot; |
||||||
|
|
||||||
|
public AbstractAnchorPainter(Container container) { |
||||||
|
this.container = container; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setRenderingBounds(Rectangle rect) { |
||||||
|
this.hotspot = rect; |
||||||
|
} |
||||||
|
|
||||||
|
protected void drawHotspot(Graphics g, Rectangle box, Color bColor) { |
||||||
|
drawHotspot(g, box.x, box.y, box.width, box.height, bColor); |
||||||
|
} |
||||||
|
|
||||||
|
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor) { |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
Stroke backup = g2d.getStroke(); |
||||||
|
g2d.setStroke(XCreatorConstants.STROKE); |
||||||
|
Color color = g2d.getColor(); |
||||||
|
g2d.setColor(bColor); |
||||||
|
g2d.drawRect(x, y, width, height); |
||||||
|
g2d.setColor(color); |
||||||
|
g2d.setStroke(backup); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,174 @@ |
|||||||
|
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; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
|
||||||
|
public class DefaultLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public DefaultLayoutAdapter(FormDesigner designer, XLayoutContainer c) { |
||||||
|
super(c); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HoverPainter getPainter() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addComp(XCreator child, int x, int y) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.ConstraintsGroupModel; |
||||||
|
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.properties.BoundsGroupModel; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRAbsoluteLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRAbsoluteLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否能在指定位置添加组件 |
||||||
|
* @param creator 组件 |
||||||
|
* @param x 坐标x |
||||||
|
* @param y 坐标y |
||||||
|
* @return 能则返回true |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return x >= 0 && y >= 0 && creator.getHeight() <= container.getHeight() |
||||||
|
&& creator.getWidth() <= container.getWidth(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
if (XCreatorUtils.getParentXLayoutContainer(creator) != null) { |
||||||
|
Rectangle r = ComponentUtils.getRelativeBounds(container); |
||||||
|
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); |
||||||
|
container.add(creator); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 组件拖拽后调整大小 |
||||||
|
* @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()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 调整组件大小到合适尺寸位置 |
||||||
|
* @param creator 组件 |
||||||
|
* @param x 坐标x |
||||||
|
* @param y 坐标y |
||||||
|
*/ |
||||||
|
public void fix(XCreator creator ,int x, int y) { |
||||||
|
if (x < 0) { |
||||||
|
x = 0; |
||||||
|
} else if (x + creator.getWidth() > container.getWidth()) { |
||||||
|
x = container.getWidth() - creator.getWidth(); |
||||||
|
} |
||||||
|
|
||||||
|
if (y < 0) { |
||||||
|
y = 0; |
||||||
|
} else if (y + creator.getHeight() > container.getHeight()) { |
||||||
|
y = container.getHeight() - creator.getHeight(); |
||||||
|
} |
||||||
|
|
||||||
|
creator.setLocation(x, y); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return new BoundsGroupModel((XWAbsoluteLayout)container, creator); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,188 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
|
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.design.designer.beans.ConstraintsGroupModel; |
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.beans.painters.FRBorderLayoutPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWBorderLayout; |
||||||
|
import com.fr.design.designer.properties.FRBorderLayoutConstraints; |
||||||
|
import com.fr.design.form.layout.FRBorderLayout; |
||||||
|
import com.fr.form.ui.container.WBorderLayout; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRBorderLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
private HoverPainter painter; |
||||||
|
|
||||||
|
public FRBorderLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
painter = new FRBorderLayoutPainter(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HoverPainter getPainter() { |
||||||
|
return painter; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 有的控件在拖拽调整大小后需要根据自身内容重新计算下当前的尺寸是否合适,如果不合适,就需要重新fix一下 |
||||||
|
* @param creator 组件 |
||||||
|
*/ |
||||||
|
public void fix(XCreator creator) { |
||||||
|
FRBorderLayout layout = (FRBorderLayout)container.getFRLayout(); |
||||||
|
Object constraints = layout.getConstraints(creator); |
||||||
|
if (ComparatorUtils.equals(constraints, BorderLayout.NORTH)) { |
||||||
|
((XWBorderLayout)container).toData().setNorthSize(creator.getHeight()); |
||||||
|
} else if (ComparatorUtils.equals(constraints, BorderLayout.SOUTH)) { |
||||||
|
((XWBorderLayout)container).toData().setSouthSize(creator.getHeight()); |
||||||
|
} else if (ComparatorUtils.equals(constraints, BorderLayout.EAST)) { |
||||||
|
((XWBorderLayout)container).toData().setEastSize(creator.getWidth()); |
||||||
|
} else if (ComparatorUtils.equals(constraints, BorderLayout.WEST)) { |
||||||
|
((XWBorderLayout)container).toData().setWestSize(creator.getWidth()); |
||||||
|
} else { |
||||||
|
return; |
||||||
|
} |
||||||
|
container.recalculateChildrenPreferredSize(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 增加组件 |
||||||
|
* @param child 组件 |
||||||
|
* @param x 横坐标 |
||||||
|
* @param y 纵坐标 |
||||||
|
*/ |
||||||
|
public void addComp(XCreator child, int x, int y) { |
||||||
|
String placement = getPlacement(child, x, y); |
||||||
|
container.add(child, placement); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 在添加组件状态时,当鼠标移动到某个容器上方时,如果该容器有布局管理器,则会调用该布局 |
||||||
|
* 管理适配器的accept来决定当前位置是否可以放置,并提供特殊的标识,比如红色区域标识。比 |
||||||
|
* 如在BorderLayout中,如果某个方位已经放置了组件,则此时应该返回false标识该区域不可以 |
||||||
|
* 放置。 |
||||||
|
*@param creator 组件 |
||||||
|
*@param x 添加的位置x,该位置是相对于container的 |
||||||
|
*@param y 添加的位置y,该位置是相对于container的 |
||||||
|
*@return 是否可以放置 |
||||||
|
*/ |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
String placement = getPlacement(creator, x, y); |
||||||
|
FRBorderLayout blayout = (FRBorderLayout) container.getLayout(); |
||||||
|
Component comp = blayout.getLayoutComponent(placement); |
||||||
|
return comp == null; |
||||||
|
} |
||||||
|
|
||||||
|
public Dimension getPreferredSize(XCreator creator) { |
||||||
|
int hw = container.getWidth(); |
||||||
|
int hh = container.getHeight(); |
||||||
|
|
||||||
|
Dimension prefSize = creator.getSize(); |
||||||
|
|
||||||
|
if (prefSize.width > (hw / 3)) { |
||||||
|
prefSize.width = hw / 3; |
||||||
|
} |
||||||
|
|
||||||
|
if (prefSize.height > (hh / 3)) { |
||||||
|
prefSize.height = hh / 3; |
||||||
|
} |
||||||
|
|
||||||
|
return prefSize; |
||||||
|
} |
||||||
|
|
||||||
|
private String getPlacement(XCreator creator, int x, int y) { |
||||||
|
int width = container.getWidth(); |
||||||
|
int height = container.getHeight(); |
||||||
|
WBorderLayout wLayout = ((XWBorderLayout)container).toData(); |
||||||
|
int northSize = wLayout.getNorthSize(); |
||||||
|
int southSize = wLayout.getSouthSize(); |
||||||
|
int eastSize = wLayout.getEastSize(); |
||||||
|
int westSize = wLayout.getWestSize(); |
||||||
|
if (y < northSize) { |
||||||
|
return BorderLayout.NORTH; |
||||||
|
} else if ((y >= northSize) && (y < (height - southSize))) { |
||||||
|
if (x < westSize) { |
||||||
|
return BorderLayout.WEST; |
||||||
|
} else if ((x >= westSize) && (x < (width - eastSize))) { |
||||||
|
return BorderLayout.CENTER; |
||||||
|
} else { |
||||||
|
return BorderLayout.EAST; |
||||||
|
} |
||||||
|
} else { |
||||||
|
return BorderLayout.SOUTH; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 增加下一个组件 |
||||||
|
* @param dragged 组件 |
||||||
|
*/ |
||||||
|
public void addNextComponent(XCreator dragged) { |
||||||
|
FRBorderLayout layout = (FRBorderLayout) container.getLayout(); |
||||||
|
Component north = layout.getLayoutComponent(BorderLayout.NORTH); |
||||||
|
Component south = layout.getLayoutComponent(BorderLayout.SOUTH); |
||||||
|
Component west = layout.getLayoutComponent(BorderLayout.WEST); |
||||||
|
Component east = layout.getLayoutComponent(BorderLayout.EAST); |
||||||
|
Component center = layout.getLayoutComponent(BorderLayout.CENTER); |
||||||
|
|
||||||
|
if (north == null) { |
||||||
|
container.add(dragged, BorderLayout.NORTH); |
||||||
|
} else if (south == null) { |
||||||
|
container.add(dragged, BorderLayout.SOUTH); |
||||||
|
} else if (west == null) { |
||||||
|
container.add(dragged, BorderLayout.WEST); |
||||||
|
} else if (east == null) { |
||||||
|
container.add(dragged, BorderLayout.EAST); |
||||||
|
} else if (center == null) { |
||||||
|
container.add(dragged, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 目标控件位置插入组件 |
||||||
|
* @param target 目标 |
||||||
|
* @param added 增加组件 |
||||||
|
*/ |
||||||
|
public void addBefore(XCreator target, XCreator added) { |
||||||
|
addNextComponent(added); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 插在目标组件后面 |
||||||
|
* @param target 目标 |
||||||
|
* @param added 增加组件 |
||||||
|
*/ |
||||||
|
public void addAfter(XCreator target, XCreator added) { |
||||||
|
addNextComponent(added); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否能接收更多的组件 |
||||||
|
* @return 能则返回true |
||||||
|
*/ |
||||||
|
public boolean canAcceptMoreComponent() { |
||||||
|
FRBorderLayout layout = (FRBorderLayout) container.getLayout(); |
||||||
|
Component north = layout.getLayoutComponent(BorderLayout.NORTH); |
||||||
|
Component south = layout.getLayoutComponent(BorderLayout.SOUTH); |
||||||
|
Component west = layout.getLayoutComponent(BorderLayout.WEST); |
||||||
|
Component east = layout.getLayoutComponent(BorderLayout.EAST); |
||||||
|
Component center = layout.getLayoutComponent(BorderLayout.CENTER); |
||||||
|
|
||||||
|
return (north == null) || (south == null) || (west == null) || (east == null) || (center == null); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return new FRBorderLayoutConstraints(container, creator); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,141 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import java.awt.CardLayout; |
||||||
|
import java.awt.LayoutManager; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.designer.beans.ConstraintsGroupModel; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardLayout; |
||||||
|
import com.fr.design.designer.properties.CardLayoutConstraints; |
||||||
|
import com.fr.design.designer.properties.CardLayoutPropertiesGroupModel; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRCardLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRCardLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前容器是否接受组件creator |
||||||
|
* |
||||||
|
* @param creator 拖入的组件 |
||||||
|
* @param x 坐标x |
||||||
|
* @param y 坐标y |
||||||
|
* |
||||||
|
* @return 是否接受 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:13:28 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将指定组件添加到当前布局 |
||||||
|
* |
||||||
|
* @param creator 待添加组件 |
||||||
|
* @param x x坐标 |
||||||
|
* @param y y坐标 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:17:46 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void addComp(XCreator creator, int x, int y) { |
||||||
|
container.add(creator, creator.toData().getWidgetName()); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将指定组件添加到当前布局 |
||||||
|
* |
||||||
|
* @param dragged 待添加组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:17:46 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void addNextComponent(XCreator dragged) { |
||||||
|
addComp(dragged, -1, -1); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将指定组件添加到目标组件前面 |
||||||
|
* |
||||||
|
* @param target 目标组件 |
||||||
|
* @param added 待添加组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:17:46 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void addBefore(XCreator target, XCreator added) { |
||||||
|
int index = ComponentUtils.indexOfComponent(container, target); |
||||||
|
|
||||||
|
if (index == -1) { |
||||||
|
container.add(added, added.toData().getWidgetName(), 0); |
||||||
|
} else { |
||||||
|
container.add(added, added.toData().getWidgetName(), index); |
||||||
|
} |
||||||
|
|
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将指定组件添加到目标组件后面 |
||||||
|
* |
||||||
|
* @param target 目标组件 |
||||||
|
* @param added 待添加组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:17:46 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void addAfter(XCreator target, XCreator added) { |
||||||
|
int index = ComponentUtils.indexOfComponent(container, target); |
||||||
|
|
||||||
|
if (index == -1) { |
||||||
|
container.add(added, added.toData().getWidgetName()); |
||||||
|
} else { |
||||||
|
index++; |
||||||
|
|
||||||
|
if (index >= container.getComponentCount()) { |
||||||
|
container.add(added, added.toData().getWidgetName()); |
||||||
|
} else { |
||||||
|
container.add(added, added.toData().getWidgetName(), index); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 展示组件 |
||||||
|
* |
||||||
|
* @param child 需要展示的组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-12-30-下午5:17:13 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void showComponent(XCreator child) { |
||||||
|
LayoutManager layout = container.getLayout(); |
||||||
|
CardLayout cardLayout = (CardLayout) layout; |
||||||
|
cardLayout.show(container, child.toData().getWidgetName()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return new CardLayoutConstraints((XWCardLayout) container, creator); |
||||||
|
} |
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return new CardLayoutPropertiesGroupModel((XWCardLayout) container); |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
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.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.properties.FRFormLayoutPropertiesGroupModel; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
* 表单布局适配器 |
||||||
|
*/ |
||||||
|
public class FRFormLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRFormLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
int w = creator.getWidth() / 2; |
||||||
|
int h = creator.getHeight() / 2; |
||||||
|
creator.setLocation(x - w, y - h); |
||||||
|
container.add(creator); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return new FRFormLayoutPropertiesGroupModel(container); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.beans.painters.FRGridLayoutPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.properties.FRGridLayoutPropertiesGroupModel; |
||||||
|
import com.fr.design.form.layout.FRGridLayout; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRGridLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRGridLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
container.add(creator, getLayoutGrid(creator, x, y)); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HoverPainter getPainter() { |
||||||
|
return new FRGridLayoutPainter(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return new FRGridLayoutPropertiesGroupModel(container); |
||||||
|
} |
||||||
|
|
||||||
|
private Point getLayoutGrid(XCreator creator, int x, int y) { |
||||||
|
FRGridLayout layout = (FRGridLayout)container.getLayout(); |
||||||
|
int w = container.getWidth() / layout.getColumns(); |
||||||
|
int h = container.getHeight() / layout.getRows(); |
||||||
|
return new Point(x / w, y / h); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
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.painters.FRHorizontalLayoutPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWHorizontalBoxLayout; |
||||||
|
import com.fr.design.designer.creator.XWidgetCreator; |
||||||
|
import com.fr.design.designer.properties.HorizontalLayoutConstraints; |
||||||
|
import com.fr.design.designer.properties.HorizontalLayoutPropertiesGroupModel; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.container.WHorizontalBoxLayout; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRHorizontalLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
public FRHorizontalLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addComp(XCreator creator, int x, int y) { |
||||||
|
if(whetherUseBackupSize(creator)) { |
||||||
|
creator.useBackupSize(); |
||||||
|
} |
||||||
|
container.add(creator, getPlaceIndex(x)); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean supportBackupSize() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private int getPlaceIndex(int x) { |
||||||
|
int place = -1; |
||||||
|
int count = container.getComponentCount(); |
||||||
|
for (int i = 0; i < count; i ++) { |
||||||
|
Rectangle bounds = container.getComponent(i).getBounds(); |
||||||
|
if (x < bounds.x) { |
||||||
|
return i; |
||||||
|
} |
||||||
|
} |
||||||
|
if (place == -1) { |
||||||
|
return count; |
||||||
|
} |
||||||
|
return place; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void fix(XCreator creator) { |
||||||
|
WHorizontalBoxLayout layout = ((XWHorizontalBoxLayout)container).toData(); |
||||||
|
Widget widget = ((XWidgetCreator)creator).toData(); |
||||||
|
creator.setPreferredSize(new Dimension(creator.getWidth(),0)); |
||||||
|
layout.setWidthAtWidget(widget, creator.getWidth()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HoverPainter getPainter() { |
||||||
|
return new FRHorizontalLayoutPainter(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return new HorizontalLayoutConstraints(container, creator); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return new HorizontalLayoutPropertiesGroupModel((XWHorizontalBoxLayout) container); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWHorizontalSplitLayout; |
||||||
|
import com.fr.design.form.layout.FRSplitLayout; |
||||||
|
import com.fr.form.ui.container.WHorizontalSplitLayout; |
||||||
|
|
||||||
|
public class FRHorizontalSplitLayoutAdapter extends FRVerticalSplitLayoutAdapter { |
||||||
|
|
||||||
|
public FRHorizontalSplitLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getPlacement(XCreator creator, int x, int y) { |
||||||
|
int width = container.getWidth(); |
||||||
|
WHorizontalSplitLayout wLayout = ((XWHorizontalSplitLayout) container).toData(); |
||||||
|
int asideSize = (int) (width * wLayout.getRatio()); |
||||||
|
if (x > asideSize) { |
||||||
|
return FRSplitLayout.CENTER; |
||||||
|
} else { |
||||||
|
return FRSplitLayout.ASIDE; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.beans.painters.FRParameterLayoutPainter; |
||||||
|
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.form.parameter.RootDesignGroupModel; |
||||||
|
import com.fr.form.ui.container.WParameterLayout; |
||||||
|
|
||||||
|
/** |
||||||
|
* 表单参数界面的监听器 |
||||||
|
*/ |
||||||
|
public class FRParameterLayoutAdapter extends FRAbsoluteLayoutAdapter { |
||||||
|
|
||||||
|
private HoverPainter painter; |
||||||
|
|
||||||
|
public FRParameterLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
painter = new FRParameterLayoutPainter(container); |
||||||
|
} |
||||||
|
|
||||||
|
public HoverPainter getPainter() { |
||||||
|
return painter; |
||||||
|
} |
||||||
|
|
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return new RootDesignGroupModel((XWParameterLayout)container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 待说明 |
||||||
|
* @param creator 组件 |
||||||
|
*/ |
||||||
|
public void fix(XCreator creator) { |
||||||
|
super.fix(creator); |
||||||
|
|
||||||
|
WParameterLayout wabs = (WParameterLayout)container.toData(); |
||||||
|
wabs.refreshTagList(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jim |
||||||
|
* @date 2014-8-5 |
||||||
|
*/ |
||||||
|
public class FRScaleLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造函数 |
||||||
|
* |
||||||
|
* @param container |
||||||
|
* 布局容器 |
||||||
|
*/ |
||||||
|
public FRScaleLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 能否对应位置放置当前组件 |
||||||
|
* |
||||||
|
* @param creator |
||||||
|
* 组件 |
||||||
|
* @param x |
||||||
|
* 添加的位置x,该位置是相对于container的 |
||||||
|
* @param y |
||||||
|
* 添加的位置y,该位置是相对于container的 |
||||||
|
* @return 是否可以放置 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @see com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter#addComp(com.fr.design.designer.creator.XCreator, |
||||||
|
* int, int) |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,94 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
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.XWidgetCreator; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardLayout; |
||||||
|
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.cardlayout.WCardMainBorderLayout; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 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高度减掉
|
||||||
|
private int adjustY(int y,XWTabFitLayout tabLayout){ |
||||||
|
XWCardLayout cardLayout = (XWCardLayout) tabLayout.getBackupParent(); |
||||||
|
LayoutBorderStyle style = cardLayout.toData().getBorderStyle(); |
||||||
|
if(ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)){ |
||||||
|
y -= WCardMainBorderLayout.TAB_HEIGHT; |
||||||
|
} |
||||||
|
return y; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
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; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jim |
||||||
|
* @date 2014-9-25 |
||||||
|
*/ |
||||||
|
public class FRTitleLayoutAdapter extends AbstractLayoutAdapter{ |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造函数 |
||||||
|
* |
||||||
|
* @param container 布局容器 |
||||||
|
*/ |
||||||
|
public FRTitleLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 能否对应位置放置当前组件 |
||||||
|
* |
||||||
|
* @param creator 组件 |
||||||
|
* @param x 添加的位置x,该位置是相对于container的 |
||||||
|
* @param y 添加的位置y,该位置是相对于container的 |
||||||
|
* @return 是否可以放置 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @see com.fr.design.designer.beans.adapters.layout.AbstractLayoutAdapter#addComp(com.fr.design.designer.creator.XCreator,nt, int) |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
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.painters.FRVerticalLayoutPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWVerticalBoxLayout; |
||||||
|
import com.fr.design.designer.creator.XWidgetCreator; |
||||||
|
import com.fr.design.designer.properties.VerticalBoxProperties; |
||||||
|
import com.fr.design.designer.properties.VerticalLayoutConstraints; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.container.WVerticalBoxLayout; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRVerticalLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRVerticalLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
if(whetherUseBackupSize(creator)) { |
||||||
|
creator.useBackupSize(); |
||||||
|
} |
||||||
|
container.add(creator, getPlaceIndex(y)); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean supportBackupSize() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
private int getPlaceIndex(int y) { |
||||||
|
int place = -1; |
||||||
|
int count = container.getComponentCount(); |
||||||
|
for (int i = 0; i < count; i++) { |
||||||
|
Rectangle bounds = container.getComponent(i).getBounds(); |
||||||
|
if (y < bounds.y) { |
||||||
|
return i; |
||||||
|
} |
||||||
|
} |
||||||
|
if (place == -1) { |
||||||
|
return count; |
||||||
|
} |
||||||
|
return place; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void fix(XCreator creator) { |
||||||
|
WVerticalBoxLayout layout = ((XWVerticalBoxLayout) container).toData(); |
||||||
|
Widget widget = ((XWidgetCreator) creator).toData(); |
||||||
|
creator.setPreferredSize(new Dimension(0, creator.getHeight())); |
||||||
|
layout.setHeightAtWidget(widget, creator.getHeight()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public HoverPainter getPainter() { |
||||||
|
return new FRVerticalLayoutPainter(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConstraintsGroupModel getLayoutConstraints(XCreator creator) { |
||||||
|
return new VerticalLayoutConstraints(container, creator); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
XWVerticalBoxLayout xbl = (XWVerticalBoxLayout) container; |
||||||
|
return new VerticalBoxProperties(xbl); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
package com.fr.design.designer.beans.adapters.layout; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
|
||||||
|
import com.fr.design.beans.GroupModel; |
||||||
|
import com.fr.design.designer.creator.XAbstractSplitLayout; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWVerticalSplitLayout; |
||||||
|
import com.fr.design.designer.properties.HorizontalSplitProperties; |
||||||
|
import com.fr.design.form.layout.FRSplitLayout; |
||||||
|
import com.fr.form.ui.container.WVerticalSplitLayout; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class FRVerticalSplitLayoutAdapter extends AbstractLayoutAdapter { |
||||||
|
|
||||||
|
public FRVerticalSplitLayoutAdapter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean accept(XCreator creator, int x, int y) { |
||||||
|
String place = getPlacement(creator, x, y); |
||||||
|
FRSplitLayout layout = (FRSplitLayout) container.getLayout(); |
||||||
|
Component comp = layout.getLayoutComponent(place); |
||||||
|
return comp == null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void addComp(XCreator creator, int x, int y) { |
||||||
|
String placement = getPlacement(creator, x, y); |
||||||
|
container.add(creator, placement); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public GroupModel getLayoutProperties() { |
||||||
|
XAbstractSplitLayout xbl = (XAbstractSplitLayout) container; |
||||||
|
return new HorizontalSplitProperties(xbl.toData()); |
||||||
|
} |
||||||
|
|
||||||
|
protected String getPlacement(XCreator creator, int x, int y) { |
||||||
|
int height = container.getHeight(); |
||||||
|
WVerticalSplitLayout wLayout = ((XWVerticalSplitLayout) container).toData(); |
||||||
|
int asideSize = (int) (height * wLayout.getRatio()); |
||||||
|
if (y > asideSize) { |
||||||
|
return FRSplitLayout.CENTER; |
||||||
|
} else { |
||||||
|
return FRSplitLayout.ASIDE; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.fr.design.designer.beans.events; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XComponent; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
|
public class CreatorEventListenerTable { |
||||||
|
|
||||||
|
protected ArrayList<DesignerEditListener> listeners; |
||||||
|
|
||||||
|
public CreatorEventListenerTable() { |
||||||
|
listeners = new ArrayList<DesignerEditListener>(); |
||||||
|
} |
||||||
|
|
||||||
|
public void addListener(DesignerEditListener listener) { |
||||||
|
if (listener == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (int i = 0; i < listeners.size(); i++) { |
||||||
|
if (ComparatorUtils.equals(listener,listeners.get(i))) { |
||||||
|
listeners.set(i, listener); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
listeners.add(listener); |
||||||
|
} |
||||||
|
|
||||||
|
private void fireCreatorModified(DesignerEvent evt) { |
||||||
|
for (int i = 0; i < listeners.size(); i++) { |
||||||
|
DesignerEditListener listener = listeners.get(i); |
||||||
|
listener.fireCreatorModified(evt); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void fireCreatorModified(XComponent creator, int eventID) { |
||||||
|
DesignerEvent evt = new DesignerEvent(eventID, creator); |
||||||
|
fireCreatorModified(evt); |
||||||
|
} |
||||||
|
|
||||||
|
public void fireCreatorModified(int eventID) { |
||||||
|
fireCreatorModified(null, eventID); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.design.designer.beans.events; |
||||||
|
|
||||||
|
import java.util.EventListener; |
||||||
|
|
||||||
|
/** |
||||||
|
* 界面设计组件触发的编辑处理器接口 |
||||||
|
* @since 6.5.4 |
||||||
|
* @author richer |
||||||
|
*/ |
||||||
|
public interface DesignerEditListener extends EventListener { |
||||||
|
|
||||||
|
void fireCreatorModified(DesignerEvent evt); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,82 @@ |
|||||||
|
package com.fr.design.designer.beans.events; |
||||||
|
|
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
import com.fr.stable.core.PropertyChangeListener; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
public class DesignerEditor<T extends JComponent> implements PropertyChangeListener<T> { |
||||||
|
|
||||||
|
private ArrayList<PropertyChangeAdapter> propertyChangeListenerList = new ArrayList<PropertyChangeAdapter>(); |
||||||
|
private ArrayList<PropertyChangeAdapter> stopEditListenerList = new ArrayList<PropertyChangeAdapter>(); |
||||||
|
private T comp; |
||||||
|
private boolean changed; |
||||||
|
|
||||||
|
public DesignerEditor(T comp) { |
||||||
|
this.comp = comp; |
||||||
|
} |
||||||
|
|
||||||
|
public void addStopEditingListener(PropertyChangeAdapter l) { |
||||||
|
int index = stopEditListenerList.indexOf(l); |
||||||
|
if (index == -1) { |
||||||
|
stopEditListenerList.add(l); |
||||||
|
} else { |
||||||
|
stopEditListenerList.set(index, l); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void fireEditStoped() { |
||||||
|
if (changed) { |
||||||
|
for (PropertyChangeAdapter l : stopEditListenerList) { |
||||||
|
l.propertyChange(); |
||||||
|
} |
||||||
|
changed = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void addPropertyChangeListener(PropertyChangeAdapter l) { |
||||||
|
int index = propertyChangeListenerList.indexOf(l); |
||||||
|
if (index == -1) { |
||||||
|
propertyChangeListenerList.add(l); |
||||||
|
} else { |
||||||
|
propertyChangeListenerList.set(index, l); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void propertyChange() { |
||||||
|
for (PropertyChangeAdapter l : propertyChangeListenerList) { |
||||||
|
l.propertyChange(); |
||||||
|
} |
||||||
|
changed = true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange(T mark) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange(T... marks) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void reset() { |
||||||
|
changed = false; |
||||||
|
} |
||||||
|
|
||||||
|
public void paintEditor(Graphics g, Dimension size) { |
||||||
|
if (this.comp != null) { |
||||||
|
comp.setSize(new Dimension(size.width - 2, size.height - 2)); |
||||||
|
LayoutUtils.layoutContainer(comp); |
||||||
|
Graphics clipg = g.create(1, 1, size.width, size.height); |
||||||
|
this.comp.paint(clipg); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public T getEditorTarget() { |
||||||
|
return comp; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package com.fr.design.designer.beans.events; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XComponent; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设计事件 |
||||||
|
*/ |
||||||
|
public class DesignerEvent { |
||||||
|
|
||||||
|
public static final int CREATOR_ADDED = 1; |
||||||
|
|
||||||
|
public static final int CREATOR_DELETED = 2; |
||||||
|
|
||||||
|
public static final int CREATOR_CUTED = 3; |
||||||
|
|
||||||
|
public static final int CREATOR_PASTED = 4; |
||||||
|
|
||||||
|
public static final int CREATOR_EDITED = 5; |
||||||
|
|
||||||
|
public static final int CREATOR_RESIZED = 6; |
||||||
|
|
||||||
|
public static final int CREATOR_SELECTED = 7; |
||||||
|
|
||||||
|
public static final int CREATOR_RENAMED = 8; |
||||||
|
|
||||||
|
private int eventID; |
||||||
|
private XComponent affectedXCreator; |
||||||
|
|
||||||
|
DesignerEvent(int eventID, XComponent comp) { |
||||||
|
this.eventID = eventID; |
||||||
|
this.affectedXCreator = comp; |
||||||
|
} |
||||||
|
|
||||||
|
public int getCreatorEventID() { |
||||||
|
return eventID; |
||||||
|
} |
||||||
|
|
||||||
|
public XComponent getAffectedCreator() { |
||||||
|
return affectedXCreator; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,184 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.beans.location.Absorptionline; |
||||||
|
import com.fr.design.beans.location.MoveUtils; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.mainframe.FormSelection; |
||||||
|
import com.fr.design.designer.creator.XCreatorUtils; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWBorderLayout; |
||||||
|
import com.fr.design.designer.creator.XWParameterLayout; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public abstract class AccessDirection implements Direction { |
||||||
|
private static final int MINHEIGHT = 21; |
||||||
|
private static final int MINWIDTH = 36; |
||||||
|
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()) { |
||||||
|
return new int[] { x, y }; |
||||||
|
} else { |
||||||
|
int posy = current_bounds.y; |
||||||
|
if (posy >= designer.getParaHeight() && !designer.isFormParaDesigner()) { |
||||||
|
return new int[] { x, 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(); |
||||||
|
} |
||||||
|
//参数面板可以无下限拉长
|
||||||
|
if (y < 0) { |
||||||
|
y = 0; |
||||||
|
} else if (y > designer.getRootComponent().getHeight() && designer.getSelectionModel().hasSelectionComponent() |
||||||
|
&& !designer.getSelectionModel().getSelection().getSelectedCreator().acceptType(XWParameterLayout.class)) { |
||||||
|
y = designer.getRootComponent().getHeight(); |
||||||
|
} |
||||||
|
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(); |
||||||
|
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 = temp.getBounds(); |
||||||
|
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; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
designer.getStateModel().setXAbsorptionline(findInX && current_bounds.getWidth() > MoveUtils.SORPTION_UNIT ? Absorptionline.createXAbsorptionline(point.x) : null); |
||||||
|
designer.getStateModel().setYAbsorptionline(findInY && current_bounds.getHeight() > MoveUtils.SORPTION_UNIT ? Absorptionline.createYAbsorptionline(point.y) : null); |
||||||
|
} |
||||||
|
|
||||||
|
private WAbsoluteLayout getLayout(final FormDesigner designer){ |
||||||
|
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( |
||||||
|
designer.getTarget().getContainer()); |
||||||
|
WAbsoluteLayout layout; |
||||||
|
if (formLayoutContainer.acceptType(XWBorderLayout.class)){ |
||||||
|
layout = (WAbsoluteLayout) designer.getParaComponent().toData(); |
||||||
|
} else{ |
||||||
|
layout = (WAbsoluteLayout) designer.getTarget().getContainer(); |
||||||
|
} |
||||||
|
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()); |
||||||
|
//设定控件最小高度21,因每次拖曳至少移动1,防止控件高度等于21时,拖曳导致rec.y的变化使得控件不停的向上或向下移动。
|
||||||
|
if(rec.height == MINHEIGHT){ |
||||||
|
ymin = rec.y; |
||||||
|
} |
||||||
|
if(rec.height == MINHEIGHT - 1){ |
||||||
|
ymin = ymin == rec.y ? rec.y : rec.y - 1; |
||||||
|
} |
||||||
|
if(rec.height < MINHEIGHT){ |
||||||
|
rec.height = MINHEIGHT; |
||||||
|
rec.y = ymin; |
||||||
|
} |
||||||
|
// 增加下宽度也设最小为21
|
||||||
|
if (rec.width == MINWIDTH) { |
||||||
|
xmin = rec.x; |
||||||
|
} |
||||||
|
if(rec.width == MINWIDTH - 1){ |
||||||
|
xmin = xmin == rec.x ? rec.x : rec.x - 1; |
||||||
|
} |
||||||
|
if (rec.width < MINWIDTH) { |
||||||
|
rec.width = MINWIDTH; |
||||||
|
rec.x = xmin; |
||||||
|
} |
||||||
|
if(rec != null) { |
||||||
|
designer.getSelectionModel().getSelection().setSelectionBounds(rec, designer); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新鼠标指针形状 |
||||||
|
* @param formEditor 设计界面组件 |
||||||
|
*/ |
||||||
|
public void updateCursor(FormDesigner formEditor) { |
||||||
|
|
||||||
|
// 调用位置枚举的多态方法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(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Toolkit; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Add extends Outer { |
||||||
|
|
||||||
|
private Cursor addCursor = Toolkit.getDefaultToolkit().createCustomCursor( |
||||||
|
BaseUtils.readImage("/com/fr/design/images/form/designer/cursor/add.png"), new Point(0, 0), |
||||||
|
"add"); |
||||||
|
|
||||||
|
public void updateCursor(FormDesigner formEditor) { |
||||||
|
formEditor.setCursor(addCursor); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Bottom extends AccessDirection { |
||||||
|
|
||||||
|
public Bottom() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
current_bounds.height = sorption(0, oldbounds.height + dy + oldbounds.y, current_bounds, designer)[1] |
||||||
|
- oldbounds.y; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.S_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.BOTTOM; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public interface Direction { |
||||||
|
|
||||||
|
/** |
||||||
|
* 拖拽组件 |
||||||
|
* @param dx 水平方向位移 |
||||||
|
* @param dy 垂直方向位移 |
||||||
|
* @param designer 设计器 |
||||||
|
*/ |
||||||
|
void drag(int dx, int dy, FormDesigner designer); |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新鼠标样式 |
||||||
|
* @param formEditor : 设计器 |
||||||
|
*/ |
||||||
|
void updateCursor(FormDesigner formEditor); |
||||||
|
|
||||||
|
/** |
||||||
|
* Direction的位置标示,top = 1,bottom = 2等 |
||||||
|
*/ |
||||||
|
int getActual(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 拖拽前先备份原始位置,拖拽过程中用于比较位移跟原始位置从而确定新位置大小 |
||||||
|
* @param formEditor 设计器 |
||||||
|
*/ |
||||||
|
void backupBounds(FormDesigner formEditor); |
||||||
|
|
||||||
|
public static final int TOP = 1; |
||||||
|
public static final int BOTTOM = 2; |
||||||
|
public static final int LEFT = 3; |
||||||
|
public static final int RIGHT = 4; |
||||||
|
public static final int LEFT_TOP = 5; |
||||||
|
public static final int LEFT_BOTTOM = 6; |
||||||
|
public static final int RIGHT_TOP = 7; |
||||||
|
public static final int RIGHT_BOTTOM = 8; |
||||||
|
public static final int INNER = 0; |
||||||
|
public static final int OUTER = -1; |
||||||
|
|
||||||
|
public static final int[] ALL = new int[]{TOP, BOTTOM, LEFT, RIGHT, LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM, INNER}; |
||||||
|
public static final int[] TOP_BOTTOM_LEFT_RIGHT= new int[]{TOP, BOTTOM, LEFT, RIGHT}; |
||||||
|
} |
@ -0,0 +1,138 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import com.fr.design.beans.location.Absorptionline; |
||||||
|
import com.fr.design.beans.location.MoveUtils; |
||||||
|
import com.fr.design.beans.location.MoveUtils.RectangleDesigner; |
||||||
|
import com.fr.design.beans.location.MoveUtils.RectangleIterator; |
||||||
|
import com.fr.design.designer.creator.XCreatorUtils; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWBorderLayout; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.mainframe.FormSelection; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout; |
||||||
|
import com.fr.form.ui.container.WAbsoluteLayout.BoundsWidget; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
public class Inner extends AccessDirection { |
||||||
|
|
||||||
|
public Inner() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.MOVE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.INNER; |
||||||
|
} |
||||||
|
|
||||||
|
protected Point getRelativePoint(int x, int y, Rectangle current_bounds, FormDesigner designer) { |
||||||
|
if (x < 0) { |
||||||
|
x = 0; |
||||||
|
} else if (x + current_bounds.getWidth() > designer.getRootComponent().getWidth() |
||||||
|
&& designer.getSelectionModel().hasSelectionComponent()) { |
||||||
|
x = designer.getRootComponent().getWidth() - current_bounds.width; |
||||||
|
} |
||||||
|
if (y < 0) { |
||||||
|
y = 0; |
||||||
|
} else if (y + current_bounds.getHeight() > designer.getRootComponent().getHeight() |
||||||
|
&& designer.getSelectionModel().hasSelectionComponent()) { |
||||||
|
y = designer.getRootComponent().getHeight() - current_bounds.height; |
||||||
|
} |
||||||
|
return new Point(x, y); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void sorptionPoint(Point point, Rectangle current_bounds, final FormDesigner designer) { |
||||||
|
RectangleDesigner rd = new RectangleDesigner() { |
||||||
|
public void setXAbsorptionline(Absorptionline line) { |
||||||
|
designer.getStateModel().setXAbsorptionline(line); |
||||||
|
} |
||||||
|
public void setYAbsorptionline(Absorptionline line) { |
||||||
|
designer.getStateModel().setYAbsorptionline(line); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前选中块的水平线数组 |
||||||
|
* |
||||||
|
* @return 块的水平线数组 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public int[] getHorizontalLine(){ |
||||||
|
return ArrayUtils.EMPTY_INT_ARRAY; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前选中块的垂直线数组 |
||||||
|
* |
||||||
|
* @return 块的垂直线数组 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public int[] getVerticalLine(){ |
||||||
|
return ArrayUtils.EMPTY_INT_ARRAY; |
||||||
|
} |
||||||
|
public RectangleIterator createRectangleIterator() { |
||||||
|
return getRectangleIterator(designer); |
||||||
|
} |
||||||
|
}; |
||||||
|
point.setLocation(MoveUtils.sorption(point.x, point.y, current_bounds.width, current_bounds.height, rd)); |
||||||
|
} |
||||||
|
|
||||||
|
private RectangleIterator getRectangleIterator(final FormDesigner designer){ |
||||||
|
return new RectangleIterator() { |
||||||
|
private int i; |
||||||
|
private WAbsoluteLayout layout = getLayout(designer); |
||||||
|
private int count = layout.getWidgetCount(); |
||||||
|
private FormSelection selection = designer.getSelectionModel().getSelection(); |
||||||
|
|
||||||
|
public boolean hasNext() { |
||||||
|
if (i >= count) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
BoundsWidget temp = (BoundsWidget) layout.getWidget(i); |
||||||
|
while (!temp.isVisible() || selection.contains(temp.getWidget())) { |
||||||
|
if (++i >= count) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
temp = (BoundsWidget) layout.getWidget(i); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
public int[] getHorizontalLine(){ |
||||||
|
return ArrayUtils.EMPTY_INT_ARRAY; |
||||||
|
} |
||||||
|
public int[] getVerticalLine(){ |
||||||
|
return ArrayUtils.EMPTY_INT_ARRAY; |
||||||
|
} |
||||||
|
public Rectangle nextRectangle() { |
||||||
|
BoundsWidget temp = (BoundsWidget) layout.getWidget(i++); |
||||||
|
return temp.getBounds(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
private WAbsoluteLayout getLayout(final FormDesigner designer){ |
||||||
|
XLayoutContainer formLayoutContainer = (XLayoutContainer) XCreatorUtils.createXCreator( |
||||||
|
designer.getTarget().getContainer()); |
||||||
|
WAbsoluteLayout layout; |
||||||
|
if (formLayoutContainer.acceptType(XWBorderLayout.class)){ |
||||||
|
layout = (WAbsoluteLayout) designer.getParaComponent().toData(); |
||||||
|
} else{ |
||||||
|
layout = (WAbsoluteLayout) designer.getTarget().getContainer(); |
||||||
|
} |
||||||
|
return layout; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
int[] xy = sorption(oldbounds.x + dx, oldbounds.y + dy, current_bounds, designer); |
||||||
|
current_bounds.x = xy[0]; |
||||||
|
current_bounds.y = xy[1]; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Left extends AccessDirection { |
||||||
|
|
||||||
|
public Left() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
current_bounds.x = sorption(oldbounds.x + dx, 0, current_bounds, designer)[0]; |
||||||
|
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.W_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.LEFT; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class LeftBottom extends AccessDirection { |
||||||
|
|
||||||
|
public LeftBottom() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
int[] xy = sorption(oldbounds.x + dx, oldbounds.y + dy + oldbounds.height, current_bounds, designer); |
||||||
|
current_bounds.x = xy[0]; |
||||||
|
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x; |
||||||
|
current_bounds.height = xy[1] - oldbounds.y; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.SW_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.LEFT_BOTTOM; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class LeftTop extends AccessDirection { |
||||||
|
public LeftTop() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
int[] xy = sorption(oldbounds.x + dx, oldbounds.y + dy, current_bounds, designer); |
||||||
|
current_bounds.x = xy[0]; |
||||||
|
current_bounds.y = xy[1]; |
||||||
|
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x; |
||||||
|
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.NW_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.LEFT_TOP; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public enum Location implements Direction{ |
||||||
|
// 枚举里面定义10个位置
|
||||||
|
outer(new Outer()), add(new Add()), inner(new Inner()), |
||||||
|
left_top(new LeftTop()), top(new Top()), right_top(new RightTop()), |
||||||
|
right(new Right()), right_bottom(new RightBottom()), |
||||||
|
bottom(new Bottom()),left_bottom(new LeftBottom()), left(new Left()); |
||||||
|
|
||||||
|
private Direction direction; |
||||||
|
|
||||||
|
private Location(Direction l) { |
||||||
|
direction = l; |
||||||
|
} |
||||||
|
|
||||||
|
public void drag(int dx, int dy, FormDesigner desinger) { |
||||||
|
direction.drag(dx, dy, desinger); |
||||||
|
} |
||||||
|
|
||||||
|
public int getActual() { |
||||||
|
return direction.getActual(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateCursor(FormDesigner formEditor) { |
||||||
|
direction.updateCursor(formEditor); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void backupBounds(FormDesigner formEditor) { |
||||||
|
direction.backupBounds(formEditor); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Outer extends AccessDirection { |
||||||
|
|
||||||
|
public Outer() { |
||||||
|
} |
||||||
|
|
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.DEFAULT_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.OUTER; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Right extends AccessDirection { |
||||||
|
|
||||||
|
public Right() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
current_bounds.width = sorption(oldbounds.x + dx + oldbounds.width, 0, current_bounds, designer)[0] |
||||||
|
- oldbounds.x; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.E_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.RIGHT; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class RightBottom extends AccessDirection { |
||||||
|
|
||||||
|
public RightBottom() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
int[] xy = sorption(oldbounds.x + dx + oldbounds.width, oldbounds.height + dy + oldbounds.y, current_bounds, designer); |
||||||
|
current_bounds.width = xy[0] - oldbounds.x; |
||||||
|
current_bounds.height = xy[1] - oldbounds.y; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.SE_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.RIGHT_BOTTOM; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class RightTop extends AccessDirection { |
||||||
|
|
||||||
|
public RightTop() { |
||||||
|
} |
||||||
|
|
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
int[] xy = sorption(oldbounds.x + dx + oldbounds.width, dy + oldbounds.y, current_bounds, designer); |
||||||
|
current_bounds.y = xy[1]; |
||||||
|
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y; |
||||||
|
current_bounds.width = xy[0] - oldbounds.x; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.NE_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.RIGHT_TOP; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 这个类用可以用来拖拽表单最底层容器的大小。目前只用于参数界面 |
||||||
|
*/ |
||||||
|
public abstract class RootResizeDirection implements Direction { |
||||||
|
|
||||||
|
public static RootResizeDirection BOTTOM_RESIZE = new RootResizeDirection(Direction.BOTTOM) { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Cursor getCursor() { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void resizeRootBounds(Rectangle rec, int dx, int dy) { |
||||||
|
rec.height += dy; |
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
public static RootResizeDirection RIGHT_RESIZE = new RootResizeDirection(Direction.RIGHT) { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Cursor getCursor() { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void resizeRootBounds(Rectangle rec, int dx, int dy) { |
||||||
|
rec.width += dx; |
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
public static RootResizeDirection RIGHT_BOTTOM_RESIZE = new RootResizeDirection(Direction.RIGHT_BOTTOM) { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Cursor getCursor() { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void resizeRootBounds(Rectangle rec, int dx, int dy) { |
||||||
|
rec.height += dy; |
||||||
|
rec.width += dx; |
||||||
|
} |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
private int actual; |
||||||
|
private Rectangle oldBounds; |
||||||
|
|
||||||
|
private RootResizeDirection(int actual) { |
||||||
|
this.actual = actual; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void drag(int dx, int dy, FormDesigner designer) { |
||||||
|
Rectangle rec = new Rectangle(oldBounds); |
||||||
|
if (actual == Direction.BOTTOM) { |
||||||
|
rec.height += dy; |
||||||
|
} else if (actual == Direction.RIGHT) { |
||||||
|
rec.width += dx; |
||||||
|
} else if (actual == Direction.RIGHT_BOTTOM) { |
||||||
|
rec.height += dy; |
||||||
|
rec.width += dx; |
||||||
|
} |
||||||
|
designer.getRootComponent().setBounds(rec); |
||||||
|
designer.populateRootSize(); |
||||||
|
LayoutUtils.layoutRootContainer(designer.getRootComponent()); |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract void resizeRootBounds(Rectangle rec, int dx, int dy); |
||||||
|
|
||||||
|
protected abstract Cursor getCursor(); |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return actual; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateCursor(FormDesigner formEditor) { |
||||||
|
formEditor.setCursor(getCursor()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void backupBounds(FormDesigner designer) { |
||||||
|
oldBounds = designer.getRootComponent().getBounds(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package com.fr.design.designer.beans.location; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public class Top extends AccessDirection { |
||||||
|
|
||||||
|
public Top() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getDraggedBounds(int dx, int dy, Rectangle current_bounds, FormDesigner designer, |
||||||
|
Rectangle oldbounds) { |
||||||
|
current_bounds.y = sorption(0, dy + oldbounds.y, current_bounds, designer)[1]; |
||||||
|
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y; |
||||||
|
return current_bounds; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getCursor() { |
||||||
|
return Cursor.N_RESIZE_CURSOR; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return Direction.TOP; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,126 @@ |
|||||||
|
package com.fr.design.designer.beans.models; |
||||||
|
|
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.designer.beans.AdapterBus; |
||||||
|
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
|
import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; |
||||||
|
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.utils.ComponentUtils; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加状态下的model |
||||||
|
*/ |
||||||
|
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(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 待说明 |
||||||
|
* @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 reset() { |
||||||
|
current_x = -this.creator.getWidth(); |
||||||
|
current_y = -this.creator.getHeight(); |
||||||
|
} |
||||||
|
|
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 移动组件图标到鼠标事件发生的位置 |
||||||
|
* @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 XCreator getXCreator() { |
||||||
|
return this.creator; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 当前组件是否已经添加到某个容器中 |
||||||
|
* @return 是返回true |
||||||
|
*/ |
||||||
|
public boolean isCreatorAdded() { |
||||||
|
return added; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 加入容器 |
||||||
|
* @param designer 设计器 |
||||||
|
* @param container 容器 |
||||||
|
* @param x 坐标 |
||||||
|
* @param y 坐标 |
||||||
|
* @return 成功返回true |
||||||
|
*/ |
||||||
|
public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { |
||||||
|
Rectangle rect = ComponentUtils.getRelativeBounds(container); |
||||||
|
if(!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())){ |
||||||
|
return added = container.getLayoutAdapter().addBean(creator,x,y); |
||||||
|
} |
||||||
|
return added = container.getLayoutAdapter().addBean(creator, |
||||||
|
x + designer.getArea().getHorizontalValue() - rect.x, |
||||||
|
y + designer.getArea().getVerticalValue() - rect.y); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,321 @@ |
|||||||
|
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); |
||||||
|
// 如果父层是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(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,433 @@ |
|||||||
|
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.utils.ComponentUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* 普通模式下的状态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 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) { |
||||||
|
// 当前鼠标所在的组件
|
||||||
|
XCreator hoveredComponent = designer.getComponentAt(x, y, 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(); |
||||||
|
} |
||||||
|
|
||||||
|
// 取消提示
|
||||||
|
designer.setPainter(null); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*是否拖拽 |
||||||
|
* @return dragging状态 |
||||||
|
*/ |
||||||
|
public boolean isDragging() { |
||||||
|
return dragging; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*是否可以开始画线 |
||||||
|
* @return startPoint不为空返回true |
||||||
|
*/ |
||||||
|
public boolean prepareForDrawLining() { |
||||||
|
return startPoint != null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*设置开始位置 |
||||||
|
* @param p point位置 |
||||||
|
*/ |
||||||
|
public void setStartPoint(Point p) { |
||||||
|
this.startPoint = p; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*返回开始位置 |
||||||
|
* @return 点位置 |
||||||
|
*/ |
||||||
|
public Point getStartPoint() { |
||||||
|
return startPoint; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*返回当前点位置 |
||||||
|
* @return 点位置 |
||||||
|
*/ |
||||||
|
public Point getEndPoint() { |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*当前鼠标的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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*起始点开始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)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*鼠标释放时所在的区域及圈中的组件 |
||||||
|
* @param e 鼠标事件 |
||||||
|
*/ |
||||||
|
public void selectCreators(MouseEvent e) { |
||||||
|
int x = getMouseXY(e).x; |
||||||
|
int y = getMouseXY(e).y; |
||||||
|
|
||||||
|
Rectangle bounds = createCurrentBounds(x, y); |
||||||
|
|
||||||
|
if ((x != current_x) || (y != current_y)) { |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
*重置model |
||||||
|
*/ |
||||||
|
public void resetModel() { |
||||||
|
dragging = false; |
||||||
|
selecting = false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*重置 |
||||||
|
*/ |
||||||
|
public void reset() { |
||||||
|
driection = Location.outer; |
||||||
|
dragging = false; |
||||||
|
selecting = false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*取消拖拽 |
||||||
|
*/ |
||||||
|
public void draggingCancel() { |
||||||
|
designer.repaint(); |
||||||
|
reset(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*设置可拉伸方向 |
||||||
|
* @param dir 拉伸方向 |
||||||
|
*/ |
||||||
|
public void setDirection(Direction dir) { |
||||||
|
if(driection != dir) { |
||||||
|
this.driection = dir; |
||||||
|
driection.updateCursor(designer); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*x吸附线赋值 |
||||||
|
* @param line 线 |
||||||
|
*/ |
||||||
|
public void setXAbsorptionline(Absorptionline line) { |
||||||
|
this.lineInX = line; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*y吸附线赋值 |
||||||
|
* @param line 线 |
||||||
|
*/ |
||||||
|
public void setYAbsorptionline(Absorptionline line) { |
||||||
|
this.lineInY = 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()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*拖拽 |
||||||
|
* @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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*释放捕获 |
||||||
|
* @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(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*改变选择区域 |
||||||
|
* |
||||||
|
* @param e 鼠标事件 |
||||||
|
*/ |
||||||
|
public void changeSelection(MouseEvent e) { |
||||||
|
Rectangle bounds = createCurrentBounds(getMouseXY(e).x, getMouseXY(e).y); |
||||||
|
selectionModel.setHotspotBounds(bounds); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*返回鼠标所在的x、y 考虑滚动条的值 |
||||||
|
* |
||||||
|
* @param e 鼠标事件 |
||||||
|
* @return xy值 |
||||||
|
*/ |
||||||
|
public Point getMouseXY(MouseEvent e) { |
||||||
|
Point p1 = new Point(e.getX() + designer.getArea().getHorizontalValue(), e.getY() |
||||||
|
+ designer.getArea().getVerticalValue()); |
||||||
|
return p1; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.awt.Stroke; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
public abstract class AbstractPainter implements HoverPainter { |
||||||
|
|
||||||
|
protected Point hotspot; |
||||||
|
protected Rectangle hotspot_bounds; |
||||||
|
protected XLayoutContainer container; |
||||||
|
protected XCreator creator; |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造函数 |
||||||
|
* @param container 容器 |
||||||
|
*/ |
||||||
|
public AbstractPainter(XLayoutContainer container) { |
||||||
|
this.container = container; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setHotspot(Point p) { |
||||||
|
hotspot = p; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 画初始区域 |
||||||
|
* @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 位置 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void setRenderingBounds(Rectangle rect) { |
||||||
|
hotspot_bounds = rect; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setCreator(XCreator component) { |
||||||
|
this.creator = component; |
||||||
|
} |
||||||
|
|
||||||
|
protected void drawHotspot(Graphics g, int x, int y, int width, int height, boolean accept) { |
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
protected void drawHotspot(Graphics g, int x, int y, int width, int height, Color bColor, boolean accept, boolean drawBackground) { |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
Color color = g2d.getColor(); |
||||||
|
Stroke backup = g2d.getStroke(); |
||||||
|
// 设置线条的样式
|
||||||
|
g2d.setStroke(XCreatorConstants.STROKE); |
||||||
|
g2d.setColor(bColor); |
||||||
|
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); |
||||||
|
} else { |
||||||
|
g2d.drawRect(x, y, width, height); |
||||||
|
} |
||||||
|
g2d.setStroke(backup); |
||||||
|
g2d.setColor(color); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,140 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Graphics; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.adapters.layout.FRBorderLayoutAdapter; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.designer.creator.XWBorderLayout; |
||||||
|
import com.fr.design.form.layout.FRBorderLayout; |
||||||
|
import com.fr.form.ui.container.WBorderLayout; |
||||||
|
|
||||||
|
public class FRBorderLayoutPainter extends AbstractPainter { |
||||||
|
|
||||||
|
public FRBorderLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
super.paint(g, startX, startY); |
||||||
|
int x = hotspot.x; |
||||||
|
int y = hotspot.y; |
||||||
|
int hotspot_x = hotspot_bounds.x; |
||||||
|
int hotspot_y = hotspot_bounds.y; |
||||||
|
int hotspot_w = hotspot_bounds.width; |
||||||
|
int hotspot_h = hotspot_bounds.height; |
||||||
|
FRBorderLayoutAdapter adapter = (FRBorderLayoutAdapter) container.getLayoutAdapter(); |
||||||
|
FRBorderLayout layout = (FRBorderLayout) container.getLayout(); |
||||||
|
boolean accept = adapter.accept(creator, x - hotspot_x, y - hotspot_y); |
||||||
|
WBorderLayout wLayout = ((XWBorderLayout)container).toData(); |
||||||
|
int northHeight = wLayout.getNorthSize(); |
||||||
|
int southHeight = wLayout.getSouthSize(); |
||||||
|
int eastWidth = wLayout.getEastSize(); |
||||||
|
int westWidth = wLayout.getWestSize(); |
||||||
|
|
||||||
|
int really_x = hotspot_x; |
||||||
|
int really_y = hotspot_y; |
||||||
|
int really_w = hotspot_w; |
||||||
|
int really_h = hotspot_h; |
||||||
|
|
||||||
|
if (y < (hotspot_y + northHeight)) { |
||||||
|
// NORTH
|
||||||
|
really_x = hotspot_x; |
||||||
|
really_y = hotspot_y; |
||||||
|
really_w = hotspot_w; |
||||||
|
really_h = northHeight; |
||||||
|
} else if ((y >= (hotspot_y + northHeight)) && (y < ((hotspot_y + hotspot_h) - southHeight))) { |
||||||
|
if (x < (hotspot_x + westWidth)) { |
||||||
|
// WEST
|
||||||
|
Component north = layout.getLayoutComponent(BorderLayout.NORTH); |
||||||
|
Component south = layout.getLayoutComponent(BorderLayout.SOUTH); |
||||||
|
really_x = hotspot_x; |
||||||
|
really_y = hotspot_y; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_y += northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
really_w = westWidth; |
||||||
|
really_h = hotspot_h; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_h -= northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
if (south != null) { |
||||||
|
really_h -= southHeight; |
||||||
|
} |
||||||
|
} else if ((x >= (hotspot_x + westWidth)) && (x < ((hotspot_x + hotspot_w) - eastWidth))) { |
||||||
|
// CENTER
|
||||||
|
Component north = layout.getLayoutComponent(BorderLayout.NORTH); |
||||||
|
Component south = layout.getLayoutComponent(BorderLayout.SOUTH); |
||||||
|
Component east = layout.getLayoutComponent(BorderLayout.EAST); |
||||||
|
Component west = layout.getLayoutComponent(BorderLayout.WEST); |
||||||
|
really_x = hotspot_x; |
||||||
|
|
||||||
|
if (west != null) { |
||||||
|
really_x += westWidth; |
||||||
|
} |
||||||
|
|
||||||
|
really_y = hotspot_y; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_y += northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
really_w = hotspot_w; |
||||||
|
|
||||||
|
if (west != null) { |
||||||
|
really_w -= westWidth; |
||||||
|
} |
||||||
|
|
||||||
|
if (east != null) { |
||||||
|
really_w -= eastWidth; |
||||||
|
} |
||||||
|
|
||||||
|
really_h = hotspot_h; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_h -= northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
if (south != null) { |
||||||
|
really_h -= southHeight; |
||||||
|
} |
||||||
|
} else { |
||||||
|
// EAST
|
||||||
|
Component north = layout.getLayoutComponent(BorderLayout.NORTH); |
||||||
|
Component south = layout.getLayoutComponent(BorderLayout.SOUTH); |
||||||
|
|
||||||
|
really_x = (hotspot_x + hotspot_w) - eastWidth; |
||||||
|
really_y = hotspot_y; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_y += northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
really_w = eastWidth; |
||||||
|
really_h = hotspot_h; |
||||||
|
|
||||||
|
if (north != null) { |
||||||
|
really_h -= northHeight; |
||||||
|
} |
||||||
|
|
||||||
|
if (south != null) { |
||||||
|
really_h -= southHeight; |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
// SOUTH
|
||||||
|
really_x = hotspot_x; |
||||||
|
really_y = (hotspot_y + hotspot_h) - southHeight; |
||||||
|
really_w = hotspot_w; |
||||||
|
really_h = southHeight; |
||||||
|
} |
||||||
|
|
||||||
|
drawHotspot(g, really_x, really_y, really_w, really_h, accept); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public abstract class FRBoxLayoutPainter extends AbstractPainter { |
||||||
|
|
||||||
|
public FRBoxLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
protected int[] calculateAddPosition(int x, int y) { |
||||||
|
int[] result = new int[2]; |
||||||
|
int count = container.getComponentCount(); |
||||||
|
for (int i = 0; i < count; i++) { |
||||||
|
Component c1 = container.getComponent(i); |
||||||
|
if(i == 0) { |
||||||
|
result[0] = c1.getBounds().x; |
||||||
|
result[1] = c1.getBounds().y; |
||||||
|
} |
||||||
|
Component c2 = null; |
||||||
|
if (i < count - 1) { |
||||||
|
c2 = container.getComponent(i + 1); |
||||||
|
} |
||||||
|
if (c2 != null) { |
||||||
|
if (x > c1.getBounds().x && x < c2.getBounds().x) { |
||||||
|
result[0] = c1.getBounds().x + c1.getBounds().width; |
||||||
|
} else if (x <= c1.getBounds().x && result[0] > c1.getBounds().x) { |
||||||
|
result[0] = c1.getBounds().x; |
||||||
|
} |
||||||
|
if (y > c1.getBounds().y && y < c2.getBounds().y) { |
||||||
|
result[1] = c1.getBounds().y + c1.getSize().height; |
||||||
|
} else if (y <= c1.getBounds().y && result[1] > c1.getBounds().y) { |
||||||
|
result[1] = c1.getBounds().y; |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (x > c1.getBounds().x) { |
||||||
|
result[0] = c1.getBounds().x + c1.getBounds().width; |
||||||
|
} |
||||||
|
if (y > c1.getBounds().y) { |
||||||
|
result[1] = c1.getBounds().y + c1.getSize().height; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
protected void drawHotLine(Graphics g, int startX, int startY, int x1, int y1, int x2, int y2) { |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
g2d.setPaint(XCreatorConstants.LAYOUT_HOTSPOT_COLOR); |
||||||
|
g2d.setStroke(XCreatorConstants.STROKE); |
||||||
|
g2d.drawLine(x1 - startX, y1 - startY, x2 - startY, y2 - startY); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,249 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.awt.Stroke; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.adapters.layout.FRFitLayoutAdapter; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jim |
||||||
|
* @date 2014-7-14 |
||||||
|
*/ |
||||||
|
public class FRFitLayoutPainter extends AbstractPainter{ |
||||||
|
|
||||||
|
private static final int BORDER_PROPORTION = 10; |
||||||
|
private static final int X = 0; |
||||||
|
private static final int Y = 1; |
||||||
|
private static final int WIDTH = 2; |
||||||
|
private static final int HEIGHT = 3; |
||||||
|
|
||||||
|
private static final Color DEPEND_LINE_COLOR = new Color(200,200,200); |
||||||
|
private static final int DEPEND_LINE_SOCOPE = 3; |
||||||
|
|
||||||
|
/** |
||||||
|
* 构造函数 |
||||||
|
* @param container |
||||||
|
*/ |
||||||
|
public FRFitLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 组件渲染 |
||||||
|
* @param g 画图类 |
||||||
|
* @param startX 开始位置x |
||||||
|
* @param startY 开始位置y |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
if(hotspot_bounds == null && creator != null && container != null){ |
||||||
|
drawDependingLine(g); |
||||||
|
return; |
||||||
|
} |
||||||
|
super.paint(g, startX, startY); |
||||||
|
int x = hotspot.x - hotspot_bounds.x; |
||||||
|
int y = hotspot.y - hotspot_bounds.y; |
||||||
|
FRFitLayoutAdapter adapter = (FRFitLayoutAdapter) container.getLayoutAdapter(); |
||||||
|
Component currentComp = container.getComponentAt(x, y); |
||||||
|
if (currentComp == null ) { |
||||||
|
return; |
||||||
|
} |
||||||
|
int[] hot_rec = new int[]{hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height}; |
||||||
|
boolean accept = adapter.accept(creator, x, y); |
||||||
|
Color bColor = XCreatorConstants.FIT_LAYOUT_HOTSPOT_COLOR; |
||||||
|
if (accept) { |
||||||
|
y = y==container.getHeight() ? y-1 : y; |
||||||
|
x = x==container.getWidth() ? x-1 : x; |
||||||
|
hot_rec = adapter.getChildPosition(currentComp, creator, x, y); |
||||||
|
} else { |
||||||
|
bColor = XCreatorConstants.LAYOUT_FORBIDDEN_COLOR; |
||||||
|
Rectangle rec = currentComp.getBounds(); |
||||||
|
hot_rec = currentComp == container ? new int[]{x, y, 0, 0} : new int[]{rec.x, rec.y, rec.width, rec.height}; |
||||||
|
} |
||||||
|
// tab布局的边界提示区域
|
||||||
|
if(!ComparatorUtils.equals(container.getBackupParent(),container.getOuterLayout()) && adapter.intersectsEdge(x, y, container)){ |
||||||
|
dealHotspotOfTab(hot_rec,container,x,y,bColor,g,accept); |
||||||
|
return; |
||||||
|
} |
||||||
|
hot_rec[X] += hotspot_bounds.x; |
||||||
|
hot_rec[Y] += hotspot_bounds.y; |
||||||
|
drawRegionBackground(g, hot_rec[X], hot_rec[Y], hot_rec[WIDTH], hot_rec[HEIGHT], bColor, accept); |
||||||
|
if (accept) { |
||||||
|
//画交叉区域和中间点区域
|
||||||
|
// 拖入的区域也改为整个渲染,点区域的后画下,不然被遮住了
|
||||||
|
paintCrossPoint(currentComp, g, x, y); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void dealHotspotOfTab(int[] hot_rec,XLayoutContainer container,int x,int y,Color bColor,Graphics g,boolean accept){ |
||||||
|
int containerX = container.getX(); |
||||||
|
int containerY = container.getY(); |
||||||
|
int containerWidth = container.getWidth(); |
||||||
|
int containerHeight = container.getHeight(); |
||||||
|
// 当前坐标点
|
||||||
|
Rectangle currentXY = new Rectangle(x, y, 1, 1); |
||||||
|
// 上边缘
|
||||||
|
Rectangle upEdge = new Rectangle(containerX, containerY, containerWidth, BORDER_PROPORTION); |
||||||
|
if(upEdge.intersects(currentXY)){ |
||||||
|
hotspot_bounds.y -= WCardMainBorderLayout.TAB_HEIGHT; |
||||||
|
hot_rec[WIDTH] = container.getWidth(); |
||||||
|
hot_rec[HEIGHT] = (container.getHeight() + WCardMainBorderLayout.TAB_HEIGHT)/2; |
||||||
|
} |
||||||
|
|
||||||
|
int bottomY = containerY + containerHeight - BORDER_PROPORTION; |
||||||
|
// 下边缘
|
||||||
|
Rectangle bottomEdge = new Rectangle(containerX, bottomY, containerWidth, BORDER_PROPORTION); |
||||||
|
if(bottomEdge.intersects(currentXY)){ |
||||||
|
hotspot_bounds.y -= WCardMainBorderLayout.TAB_HEIGHT/2; |
||||||
|
hot_rec[WIDTH] = container.getWidth(); |
||||||
|
hot_rec[HEIGHT] = (container.getHeight() + WCardMainBorderLayout.TAB_HEIGHT)/2; |
||||||
|
accept = false; |
||||||
|
} |
||||||
|
|
||||||
|
//左右边缘的高度 -10*2 是为了不和上下边缘重合
|
||||||
|
int verticalHeight = containerHeight - BORDER_PROPORTION * 2; |
||||||
|
int leftY = containerY + BORDER_PROPORTION; |
||||||
|
// 左边缘
|
||||||
|
Rectangle leftEdge = new Rectangle(containerX, leftY, BORDER_PROPORTION, verticalHeight); |
||||||
|
if(leftEdge.intersects(currentXY)){ |
||||||
|
hotspot_bounds.y -= WCardMainBorderLayout.TAB_HEIGHT; |
||||||
|
hot_rec[WIDTH] = container.getWidth()/2; |
||||||
|
hot_rec[HEIGHT] = (container.getHeight() + WCardMainBorderLayout.TAB_HEIGHT); |
||||||
|
} |
||||||
|
|
||||||
|
int rightY = containerY + BORDER_PROPORTION; |
||||||
|
int rightX = containerX + containerWidth - BORDER_PROPORTION; |
||||||
|
// 右边缘
|
||||||
|
Rectangle rightEdge = new Rectangle(rightX, rightY, BORDER_PROPORTION, verticalHeight); |
||||||
|
if(rightEdge.intersects(currentXY)){ |
||||||
|
hotspot_bounds.y -= WCardMainBorderLayout.TAB_HEIGHT; |
||||||
|
hotspot_bounds.x += container.getWidth()/2; |
||||||
|
hot_rec[WIDTH] = container.getWidth()/2; |
||||||
|
hot_rec[HEIGHT] = (container.getHeight() + WCardMainBorderLayout.TAB_HEIGHT); |
||||||
|
} |
||||||
|
hot_rec[X] += hotspot_bounds.x; |
||||||
|
hot_rec[Y] += hotspot_bounds.y; |
||||||
|
drawRegionBackground(g, hot_rec[X], hot_rec[Y], hot_rec[WIDTH], hot_rec[HEIGHT], bColor,accept); |
||||||
|
} |
||||||
|
|
||||||
|
private void paintCrossPoint(Component currentComp, Graphics g, int x, int y) { |
||||||
|
if (currentComp == container) { |
||||||
|
return; |
||||||
|
} |
||||||
|
Color bColor = XCreatorConstants.FIT_LAYOUT_POINT_COLOR; |
||||||
|
int cX = currentComp.getX(), cY = currentComp.getY(), cH = currentComp.getHeight(), cW = currentComp.getWidth(); |
||||||
|
int defaultWidth = cW/BORDER_PROPORTION, defaultHeight = cH/BORDER_PROPORTION; |
||||||
|
// 交叉点提示区域最大值为10px
|
||||||
|
int defaultLength = Math.min(BORDER_PROPORTION, Math.min(defaultWidth, defaultHeight)); |
||||||
|
Component topComp = container.getTopComp(cX, cY); |
||||||
|
Component bottomComp = container.getBottomComp(cX, cY, cH); |
||||||
|
Component rightComp = container.getRightComp(cX, cY, cW); //组件的左右组件要区分上侧和下侧
|
||||||
|
Component leftComp = container.getLeftComp(cX, cY); |
||||||
|
boolean top = topComp!=null && topComp!=container, left = leftComp!=null && leftComp!=container,bottom = bottomComp!=null && bottomComp!=container,right = rightComp!=null && rightComp!=container; |
||||||
|
if (top || left) { |
||||||
|
drawRegionBackground(g, cX+hotspot_bounds.x, cY+hotspot_bounds.y, defaultLength, defaultLength, bColor, true); |
||||||
|
} |
||||||
|
if (bottom || left) { |
||||||
|
drawRegionBackground(g, cX+hotspot_bounds.x, cY+cH-defaultLength+hotspot_bounds.y, defaultLength, defaultLength, bColor,true); |
||||||
|
} |
||||||
|
if (top || right) { |
||||||
|
drawRegionBackground(g, cX+cW-defaultLength+hotspot_bounds.x, cY+hotspot_bounds.y, defaultLength, defaultLength, bColor,true); |
||||||
|
} |
||||||
|
if (bottom || right) { |
||||||
|
drawRegionBackground(g, cX+cW-defaultLength+hotspot_bounds.x, cY+cH-defaultLength+hotspot_bounds.y, defaultLength, defaultLength, bColor,true); |
||||||
|
} |
||||||
|
if (left && right) { |
||||||
|
if (leftComp.getY()==cY && rightComp.getY()==cY) { |
||||||
|
drawRegionBackground(g, cX+cW/2-defaultWidth+hotspot_bounds.x, cY+hotspot_bounds.y, defaultWidth*2, defaultLength, bColor,true); |
||||||
|
} |
||||||
|
//底边线位置,左右组件都不为null且低端对齐,取左、右靠下侧组件判断
|
||||||
|
leftComp = container.getBottomLeftComp(cX, cY, cH); |
||||||
|
rightComp = container.getBottomRightComp(cX, cY, cH, cW); |
||||||
|
if (leftComp.getY()+leftComp.getHeight()==cY+cH && rightComp.getY()+rightComp.getHeight()==cY+cH) { |
||||||
|
drawRegionBackground(g, cX+cW/2-defaultWidth+hotspot_bounds.x, cY+cH-defaultLength+hotspot_bounds.y, defaultWidth*2, defaultLength, bColor,true); |
||||||
|
} |
||||||
|
} |
||||||
|
if (top && bottom) { |
||||||
|
if (topComp.getX()==cX && bottomComp.getX()==cX) { |
||||||
|
drawRegionBackground(g, cX+hotspot_bounds.x, cY+cH/2-defaultHeight+hotspot_bounds.y, defaultLength, defaultHeight*2, bColor,true); |
||||||
|
} |
||||||
|
// 右边线位置,上下组件不为null且右端对齐,取上、下靠右侧组件判断
|
||||||
|
topComp = container.getRightTopComp(cX, cY, cW); |
||||||
|
bottomComp = container.getRightBottomComp(cX, cY, cH, cW); |
||||||
|
if (topComp.getX()+topComp.getWidth()==cX+cW && bottomComp.getX()+bottomComp.getWidth()==cX+cW) { |
||||||
|
drawRegionBackground(g, cX+cW-defaultLength+hotspot_bounds.x, cY+cH/2-defaultHeight+hotspot_bounds.y, defaultLength, defaultHeight*2, bColor,true); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 画依附线
|
||||||
|
private void drawDependingLine(Graphics g){ |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
Stroke backup = g2d.getStroke(); |
||||||
|
|
||||||
|
// 当前拖拽组件的坐标
|
||||||
|
int oriX = creator.getX(); |
||||||
|
int oriY = creator.getY(); |
||||||
|
|
||||||
|
// 拖拽位置的即时坐标
|
||||||
|
double x = hotspot.getX(); |
||||||
|
double y = hotspot.getY(); |
||||||
|
|
||||||
|
// 容器所有的内部组件的横纵坐标值
|
||||||
|
int[] posXs = container.getHors(); |
||||||
|
int[] posYs = container.getVeris(); |
||||||
|
|
||||||
|
// 依附线的坐标
|
||||||
|
int lineX = 0; |
||||||
|
int lineY = 0; |
||||||
|
|
||||||
|
// 根据拖拽位置调整依附线的坐标
|
||||||
|
lineX = getDependLinePos(lineX, posXs, oriX, x); |
||||||
|
lineY = getDependLinePos(lineY, posYs, oriY, y); |
||||||
|
|
||||||
|
|
||||||
|
g2d.setStroke(backup); |
||||||
|
g2d.setColor(DEPEND_LINE_COLOR); |
||||||
|
if(lineX != 0){ |
||||||
|
g2d.drawRect(lineX, 0, 0, container.getHeight()); |
||||||
|
} |
||||||
|
if(lineY != 0){ |
||||||
|
g2d.drawRect(0, lineY, container.getWidth(), 0); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据容器内部组件的横纵坐标值画依附线 |
||||||
|
* |
||||||
|
* @param lineCoordinate 依附线坐标值 |
||||||
|
* @param referCoordinates 容器内部所有组件坐标值 |
||||||
|
* @param oriCoordinate 当前拖拽组件坐标 |
||||||
|
* @param currentCoordinate 拖拽位置的即时坐标 |
||||||
|
* @return 依附线的坐标 |
||||||
|
* |
||||||
|
*/ |
||||||
|
private int getDependLinePos(int lineCoordinate,int referCoordinates[],int oriCoordinate,double currentCoordinate){ |
||||||
|
for(int i=0; i<referCoordinates.length; i++){ |
||||||
|
if(referCoordinates[i] == oriCoordinate){ |
||||||
|
continue; |
||||||
|
} |
||||||
|
if(currentCoordinate > referCoordinates[i]-DEPEND_LINE_SOCOPE && currentCoordinate < referCoordinates[i] + DEPEND_LINE_SOCOPE){ |
||||||
|
lineCoordinate = referCoordinates[i]; |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
return lineCoordinate; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.BasicStroke; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Stroke; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.adapters.layout.AbstractAnchorPainter; |
||||||
|
import com.fr.design.form.layout.FRGridLayout; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
|
||||||
|
public class FRGridLayoutAnchorPainter extends AbstractAnchorPainter { |
||||||
|
|
||||||
|
protected FRGridLayout grid_layout; |
||||||
|
|
||||||
|
public FRGridLayoutAnchorPainter(Container container) { |
||||||
|
super(container); |
||||||
|
grid_layout = (FRGridLayout) container.getLayout(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
int columns = grid_layout.getColumns(); |
||||||
|
int rows = grid_layout.getRows(); |
||||||
|
int width = hotspot.width; |
||||||
|
int height = hotspot.height; |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
Stroke back = g2d.getStroke(); |
||||||
|
g2d.setStroke(new BasicStroke(1)); |
||||||
|
g.setColor(XCreatorConstants.LAYOUT_SEP_COLOR); |
||||||
|
g.drawRect(hotspot.x, hotspot.y, hotspot.width, hotspot.height); |
||||||
|
|
||||||
|
if (columns != 0) { |
||||||
|
for (int i = 1; i < columns; i++) { |
||||||
|
int x = (i * width) / columns; |
||||||
|
g.drawLine(hotspot.x + x, hotspot.y, hotspot.x + x, hotspot.y + height); |
||||||
|
} |
||||||
|
} |
||||||
|
if (rows != 0) { |
||||||
|
for (int i = 1; i < rows; i++) { |
||||||
|
int y = (i * height) / rows; |
||||||
|
g.drawLine(hotspot.x, hotspot.y + y, hotspot.x + width, hotspot.y + y); |
||||||
|
} |
||||||
|
} |
||||||
|
g2d.setStroke(back); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.creator.XCreator; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
|
||||||
|
public class FRGridLayoutPainter extends FRGridLayoutAnchorPainter implements HoverPainter { |
||||||
|
|
||||||
|
private Point point; |
||||||
|
private XCreator current; |
||||||
|
|
||||||
|
public FRGridLayoutPainter(Container container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setHotspot(Point p) { |
||||||
|
point = p; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setCreator(XCreator creator) { |
||||||
|
this.current = creator; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
super.paint(g, startX, startY); |
||||||
|
int x = point.x; |
||||||
|
int y = point.y; |
||||||
|
int column = grid_layout.getColumns(); |
||||||
|
int row = grid_layout.getRows(); |
||||||
|
if (column == 0) { |
||||||
|
column = 1; |
||||||
|
} |
||||||
|
if (row == 0) { |
||||||
|
row = 1; |
||||||
|
} |
||||||
|
double w = (double) hotspot.width / column; |
||||||
|
double h = (double) hotspot.height / row; |
||||||
|
int ix = (int) (x / w); |
||||||
|
int iy = (int) (y / h); |
||||||
|
x = (int) (ix * w + hotspot.x); |
||||||
|
y = (int) (iy * h + hotspot.y); |
||||||
|
drawHotspot(g, x, y, (int) w, (int) h, XCreatorConstants.SELECTION_COLOR); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class FRHorizontalLayoutPainter extends FRBoxLayoutPainter { |
||||||
|
|
||||||
|
public FRHorizontalLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
super.paint(g, startX, startY); |
||||||
|
int x = hotspot.x; |
||||||
|
Rectangle bounds = ComponentUtils.getRelativeBounds(container); |
||||||
|
int my = bounds.y; |
||||||
|
int mx = bounds.x; |
||||||
|
int[] xy = calculateAddPosition(x - mx + startX, 0); |
||||||
|
if (xy.length != 0) { |
||||||
|
drawHotLine(g, startX, startY, xy[0] + mx, my, xy[0] + mx, my + container.getSize().height); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created with IntelliJ IDEA. |
||||||
|
* User: zx |
||||||
|
* Date: 14-7-21 |
||||||
|
* Time: 下午7:57 |
||||||
|
*/ |
||||||
|
public class FRParameterLayoutPainter extends AbstractPainter{ |
||||||
|
|
||||||
|
public FRParameterLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
import com.fr.design.utils.ComponentUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class FRVerticalLayoutPainter extends FRBoxLayoutPainter { |
||||||
|
|
||||||
|
public FRVerticalLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g, int startX, int startY) { |
||||||
|
super.paint(g, startX, startY); |
||||||
|
int y = hotspot.y; |
||||||
|
Rectangle bounds = ComponentUtils.getRelativeBounds(container); |
||||||
|
int my = bounds.y; |
||||||
|
int mx = bounds.x; |
||||||
|
int[] xy = calculateAddPosition(0, y + startY - my); |
||||||
|
if (xy.length != 0) { |
||||||
|
drawHotLine(g, startX, startY, mx, xy[1] + my, mx + container.getSize().width, xy[1] + my); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Graphics; |
||||||
|
|
||||||
|
import com.fr.design.designer.beans.HoverPainter; |
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
|
||||||
|
public class NullLayoutPainter extends AbstractPainter { |
||||||
|
|
||||||
|
public NullLayoutPainter(XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g,int startX,int startY) { |
||||||
|
|
||||||
|
HoverPainter painter = container.getLayoutAdapter().getPainter(); |
||||||
|
if (painter != null) { |
||||||
|
painter.setCreator(this.creator); |
||||||
|
painter.setHotspot(this.hotspot); |
||||||
|
painter.setRenderingBounds(this.hotspot_bounds); |
||||||
|
painter.paint(g,startX,startY); |
||||||
|
} else { |
||||||
|
g.setColor(Color.lightGray); |
||||||
|
g.drawRect(hotspot_bounds.x, hotspot_bounds.y, hotspot_bounds.width, hotspot_bounds.height); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
package com.fr.design.designer.beans.painters; |
||||||
|
|
||||||
|
import com.fr.design.designer.creator.XLayoutContainer; |
||||||
|
|
||||||
|
public class NullPainter extends AbstractPainter { |
||||||
|
|
||||||
|
public NullPainter( XLayoutContainer container) { |
||||||
|
super(container); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.design.gui.xtable.AbstractPropertyGroupModel; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
import java.beans.IntrospectionException; |
||||||
|
import java.beans.PropertyDescriptor; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public final class CRPropertyDescriptor extends PropertyDescriptor { |
||||||
|
|
||||||
|
private PropertyChangeAdapter l; |
||||||
|
|
||||||
|
public CRPropertyDescriptor(String name, Class<?> beanClass) throws IntrospectionException { |
||||||
|
super(name, beanClass); |
||||||
|
} |
||||||
|
|
||||||
|
public CRPropertyDescriptor(String name, Class<?> beanClass, String readMethod, String writeMethod) throws IntrospectionException{ |
||||||
|
super(name, beanClass, readMethod, writeMethod); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public CRPropertyDescriptor putKeyValue(String key, Object value) { |
||||||
|
if (StringUtils.isNotEmpty(key)) { |
||||||
|
this.setValue(key, value); |
||||||
|
} |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public CRPropertyDescriptor setPropertyChangeListener(PropertyChangeAdapter l) { |
||||||
|
this.l = l; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public void firePropertyChanged() { |
||||||
|
if (l != null) { |
||||||
|
l.propertyChange(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public CRPropertyDescriptor setEditorClass(Class<?> clazz) { |
||||||
|
this.setPropertyEditorClass(clazz); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public CRPropertyDescriptor setRendererClass(Class<?> clazz) { |
||||||
|
this.putKeyValue(AbstractPropertyGroupModel.RENDERER, clazz); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public CRPropertyDescriptor setI18NName(String displayName) { |
||||||
|
this.setDisplayName(displayName); |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,244 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.CardLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Container; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.Insets; |
||||||
|
import java.awt.LayoutManager; |
||||||
|
import java.awt.event.ContainerListener; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.BoxLayout; |
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
|
||||||
|
public class FormCardPane extends JComponent implements SwingConstants { |
||||||
|
|
||||||
|
private boolean showTab; |
||||||
|
private int tabPlace; |
||||||
|
private JPanel tabPane; |
||||||
|
private JPanel cardPane; |
||||||
|
private CardLayout layout; |
||||||
|
private java.util.List<Component> tabComponent = new java.util.ArrayList<Component>(); |
||||||
|
private int showIndex; |
||||||
|
|
||||||
|
public FormCardPane(boolean showTab, int tabPlace) { |
||||||
|
this.showTab = showTab; |
||||||
|
this.tabPlace = tabPlace; |
||||||
|
initTabComponent(); |
||||||
|
initCardComponent(); |
||||||
|
setLayout(new FormCardLayout()); |
||||||
|
this.add(tabPane); |
||||||
|
this.add(cardPane); |
||||||
|
} |
||||||
|
|
||||||
|
public FormCardPane(ContainerListener containerListener) { |
||||||
|
this(true, TOP); |
||||||
|
cardPane.addContainerListener(containerListener); |
||||||
|
} |
||||||
|
|
||||||
|
private void initTabComponent() { |
||||||
|
tabPane = new JPanel(); |
||||||
|
tabPane.setOpaque(true); |
||||||
|
tabPane.setBorder(BorderFactory.createLineBorder(Color.pink)); |
||||||
|
tabPane.setBackground(Color.white); |
||||||
|
} |
||||||
|
|
||||||
|
private void initCardComponent() { |
||||||
|
cardPane = new JPanel(); |
||||||
|
cardPane.setBorder(BorderFactory.createLineBorder(Color.orange)); |
||||||
|
layout = new CardLayout(); |
||||||
|
cardPane.setLayout(layout); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSelectedIndex(int showIndex) { |
||||||
|
this.setSelectedComponent(this.getComponentAt(showIndex)); |
||||||
|
} |
||||||
|
|
||||||
|
public int getTabCount() { |
||||||
|
return cardPane.getComponentCount(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void add(Component comp, Object constraints) { |
||||||
|
this.add(comp, constraints, -1); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removeAll() { |
||||||
|
cardPane.removeAll(); |
||||||
|
tabComponent.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
private void reSetTabComponent() { |
||||||
|
if (tabPlace == TOP || tabPlace == BOTTOM) { |
||||||
|
int totalWidth = 0; |
||||||
|
for (Component comp : tabComponent) { |
||||||
|
totalWidth += comp.getWidth(); |
||||||
|
} |
||||||
|
showTabComponent(totalWidth > tabPane.getWidth()); |
||||||
|
|
||||||
|
} else if (tabPlace == LEFT || tabPlace == RIGHT) { |
||||||
|
int totalHeight = 0; |
||||||
|
for (Component comp : tabComponent) { |
||||||
|
totalHeight += comp.getHeight(); |
||||||
|
} |
||||||
|
showTabComponent(totalHeight > tabPane.getHeight()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void showTabComponent(boolean showButton) { |
||||||
|
tabPane.removeAll(); |
||||||
|
if (this.showIndex < 0 || this.showIndex >= tabComponent.size()) { |
||||||
|
this.showIndex = 0; |
||||||
|
} |
||||||
|
if (tabPlace == TOP || tabPlace == BOTTOM) { |
||||||
|
tabPane.setLayout(new FlowLayout(FlowLayout.LEFT)); |
||||||
|
|
||||||
|
} else if (tabPlace == LEFT || tabPlace == RIGHT) { |
||||||
|
tabPane.setLayout(new BoxLayout(tabPane, BoxLayout.Y_AXIS)); |
||||||
|
} else { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
for (Component comp : tabComponent) { |
||||||
|
tabPane.add(comp); |
||||||
|
} |
||||||
|
tabPane.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void add(Component comp, Object constraints, int index) { |
||||||
|
if (!(comp instanceof XCreator)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
JComponent tabComp = new JPanel(); |
||||||
|
if (constraints instanceof String) { |
||||||
|
tabComp = new UILabel((String) constraints); |
||||||
|
|
||||||
|
} else if (constraints instanceof Icon) { |
||||||
|
tabComp = new UILabel((Icon) constraints); |
||||||
|
} else { |
||||||
|
return; |
||||||
|
} |
||||||
|
tabComp.setOpaque(true); |
||||||
|
tabComp.setBorder(BorderFactory.createLineBorder(Color.red)); |
||||||
|
cardPane.add(comp, ((((XCreator) comp).toData())).getWidgetName(), index); |
||||||
|
if (index == -1) { |
||||||
|
tabComponent.add(tabComp); |
||||||
|
} else { |
||||||
|
tabComponent.add(index, tabComp); |
||||||
|
} |
||||||
|
|
||||||
|
reSetTabComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setTabPlacement(int tabPlace) { |
||||||
|
this.tabPlace = tabPlace; |
||||||
|
} |
||||||
|
|
||||||
|
public Component getComponentAt(int i) { |
||||||
|
return cardPane.getComponent(i); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSelectedComponent(Component child) { |
||||||
|
if (child instanceof XCreator) { |
||||||
|
int order = cardPane.getComponentZOrder(child); |
||||||
|
if (order == -1 || order == showIndex) { |
||||||
|
return; |
||||||
|
} |
||||||
|
tabComponent.get(showIndex).setBackground(null); |
||||||
|
this.showIndex = order; |
||||||
|
tabComponent.get(showIndex).setBackground(Color.orange); |
||||||
|
layout.show(cardPane, ((((XCreator) child).toData())).getWidgetName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class FormCardLayout implements LayoutManager { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addLayoutComponent(String name, Component comp) { |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void layoutContainer(Container parent) { |
||||||
|
Insets inset = parent.getInsets(); |
||||||
|
int parentWidth = parent.getWidth() - inset.left - inset.right; |
||||||
|
int parentHeight = parent.getHeight() - inset.top - inset.bottom; |
||||||
|
if (showTab) { |
||||||
|
if (tabPlace == TOP || tabPlace == BOTTOM) { |
||||||
|
int height = getTabPaneHeight(); |
||||||
|
tabPane.setSize(parentWidth, height); |
||||||
|
cardPane.setSize(parentWidth, parentHeight - height); |
||||||
|
if (tabPlace == TOP) { |
||||||
|
tabPane.setLocation(inset.left, inset.top); |
||||||
|
cardPane.setLocation(inset.left, inset.top + height); |
||||||
|
} else { |
||||||
|
cardPane.setLocation(inset.left, inset.top); |
||||||
|
tabPane.setLocation(inset.left, inset.top + parentHeight - height); |
||||||
|
} |
||||||
|
} else if (tabPlace == LEFT || tabPlace == RIGHT) { |
||||||
|
int width = getTabPaneWidth(); |
||||||
|
tabPane.setSize(width, parentHeight); |
||||||
|
cardPane.setSize(parentWidth - width, parentHeight); |
||||||
|
if (tabPlace == LEFT) { |
||||||
|
tabPane.setLocation(inset.left, inset.top); |
||||||
|
cardPane.setLocation(inset.left + width, inset.top); |
||||||
|
} else { |
||||||
|
cardPane.setLocation(inset.left, inset.top); |
||||||
|
tabPane.setLocation(inset.left + parentWidth - width, inset.top); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} else { |
||||||
|
tabPane.setVisible(false); |
||||||
|
cardPane.setSize(parent.getWidth(), parent.getHeight()); |
||||||
|
cardPane.setLocation(0, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension minimumLayoutSize(Container parent) { |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension preferredLayoutSize(Container parent) { |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removeLayoutComponent(Component comp) { |
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public int getTabPaneHeight() { |
||||||
|
return 22; |
||||||
|
} |
||||||
|
|
||||||
|
public int getTabPaneWidth() { |
||||||
|
return 40; |
||||||
|
} |
||||||
|
|
||||||
|
public void addCreatorListener(ContainerListener containerListener) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void setShowTab(boolean showTab) { |
||||||
|
this.showTab = showTab; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
|
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
|
||||||
|
//避免意外的发生导致整个模板打不开,尤其是不同版本之间
|
||||||
|
public class NullCreator extends XWidgetCreator { |
||||||
|
|
||||||
|
public NullCreator(Widget widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "none_widget.png"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
UILabel l = new UILabel("UNEXPECTED WIDGET"); |
||||||
|
l.setForeground(Color.red); |
||||||
|
l.setVerticalAlignment(SwingConstants.CENTER); |
||||||
|
l.setHorizontalAlignment(SwingConstants.CENTER); |
||||||
|
setBorder(DEFALUTBORDER); |
||||||
|
return editor = l; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.event.ContainerEvent; |
||||||
|
|
||||||
|
import com.fr.design.form.layout.FRSplitLayout; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.container.WSplitLayout; |
||||||
|
|
||||||
|
public abstract class XAbstractSplitLayout extends XLayoutContainer { |
||||||
|
|
||||||
|
public XAbstractSplitLayout(WSplitLayout widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public WSplitLayout toData() { |
||||||
|
return (WSplitLayout) data; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void convert() { |
||||||
|
isRefreshing = true; |
||||||
|
WSplitLayout wb = this.toData(); |
||||||
|
this.removeAll(); |
||||||
|
String[] arrs = { WSplitLayout.CENTER, WSplitLayout.ASIDE }; |
||||||
|
for (int i = 0; i < arrs.length; i++) { |
||||||
|
Widget wgt = wb.getLayoutWidget(arrs[i]); |
||||||
|
if (wgt != null) { |
||||||
|
XWidgetCreator comp = (XWidgetCreator) XCreatorUtils.createXCreator(wgt, calculatePreferredSize(wgt)); |
||||||
|
this.add(comp, arrs[i]); |
||||||
|
} |
||||||
|
} |
||||||
|
isRefreshing = false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void componentAdded(ContainerEvent e) { |
||||||
|
if (isRefreshing) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XWidgetCreator creator = (XWidgetCreator) e.getChild(); |
||||||
|
FRSplitLayout b = (FRSplitLayout) getLayout(); |
||||||
|
Object constraints = b.getConstraints(creator); |
||||||
|
WSplitLayout wb = this.toData(); |
||||||
|
Widget w = creator.toData(); |
||||||
|
wb.addWidget(w, constraints); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,149 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Insets; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.base.Formula; |
||||||
|
import com.fr.design.border.UIRoundedBorder; |
||||||
|
import com.fr.form.ui.AbstractBorderStyleWidget; |
||||||
|
import com.fr.form.ui.Label; |
||||||
|
import com.fr.form.ui.LayoutBorderStyle; |
||||||
|
import com.fr.form.ui.PaddingMargin; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.WidgetTitle; |
||||||
|
import com.fr.form.ui.WidgetValue; |
||||||
|
import com.fr.form.ui.container.WTitleLayout; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created with IntelliJ IDEA. |
||||||
|
* User: zx |
||||||
|
* Date: 14-9-22 |
||||||
|
* Time: 上午10:40 |
||||||
|
*/ |
||||||
|
|
||||||
|
public class XBorderStyleWidgetCreator extends XWidgetCreator{ |
||||||
|
private int cornerSize = 15; |
||||||
|
private int noneSize = 0; |
||||||
|
|
||||||
|
public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回容器对应的widget |
||||||
|
* @return 同上 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public AbstractBorderStyleWidget toData() { |
||||||
|
return (AbstractBorderStyleWidget) data; |
||||||
|
} |
||||||
|
|
||||||
|
protected void initStyle() { |
||||||
|
LayoutBorderStyle style = toData().getBorderStyle(); |
||||||
|
initBorderStyle(); |
||||||
|
if (ComparatorUtils.equals(style.getType(), LayoutBorderStyle.TITLE)) { |
||||||
|
initTitleStyle(style); |
||||||
|
} else { |
||||||
|
clearTitleWidget(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 边框默认值设为NONE,不然像scalelayout这种只用默认边框的会不显示边框
|
||||||
|
protected void initBorderStyle() { |
||||||
|
LayoutBorderStyle style = toData().getBorderStyle(); |
||||||
|
if (style != null && style.getBorder() != Constants.LINE_NONE) { |
||||||
|
this.setBorder(new UIRoundedBorder(style.getBorder(), style.getColor(), style.isCorner() ? cornerSize : noneSize)); |
||||||
|
} else { |
||||||
|
this.setBorder(DEFALUTBORDER); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void clearTitleWidget() { |
||||||
|
if (acceptType(XWFitLayout.class)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||||
|
if (parent.getComponentCount() > 1) { |
||||||
|
parent.remove(parent.getTitleCreator()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置样式为标题样式时,对应组件加上标题 |
||||||
|
* @param style 样式 |
||||||
|
*/ |
||||||
|
protected void initTitleStyle(LayoutBorderStyle style){ |
||||||
|
if (style.getTitle() == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
XWTitleLayout parent = (XWTitleLayout) this.getParent(); |
||||||
|
if (parent.getComponentCount() > 1) { |
||||||
|
XLabel title = (XLabel) parent.getTitleCreator(); |
||||||
|
Label widget = title.toData(); |
||||||
|
updateTitleWidgetStyle(widget, style); |
||||||
|
title.initXCreatorProperties(); |
||||||
|
return; |
||||||
|
} |
||||||
|
// 初始化标题控件
|
||||||
|
XLabel title = new XLabel(new Label(), new Dimension()); |
||||||
|
Label label = title.toData(); |
||||||
|
updateTitleWidgetStyle(label, style); |
||||||
|
parent.add(title, WTitleLayout.TITLE); |
||||||
|
// 初始化标题边框
|
||||||
|
title.initXCreatorProperties(); |
||||||
|
WTitleLayout layout = parent.toData(); |
||||||
|
layout.updateChildBounds(layout.getBodyBoundsWidget().getBounds()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新标题控件所有的样式 |
||||||
|
*/ |
||||||
|
private void updateTitleWidgetStyle(Label title, LayoutBorderStyle style) { |
||||||
|
//标题的边框样式目前是取对应的控件的边框样式
|
||||||
|
title.setBorder(style.getBorder()); |
||||||
|
title.setColor(style.getColor()); |
||||||
|
title.setCorner(style.isCorner()); |
||||||
|
|
||||||
|
WidgetTitle wTitle = style.getTitle(); |
||||||
|
//设置成随机不重复的, 不然都用一个名字的话, 联动只能联动一个
|
||||||
|
title.setWidgetName(wTitle.TITLE_NAME_INDEX + this.toData().getWidgetName()); |
||||||
|
title.setWidgetValue(getTitleValue(wTitle)); |
||||||
|
title.setFont(wTitle.getFrFont()); |
||||||
|
title.setTextalign(wTitle.getPosition()); |
||||||
|
title.setBackground(wTitle.getBackground()); |
||||||
|
} |
||||||
|
|
||||||
|
private WidgetValue getTitleValue(WidgetTitle wTitle){ |
||||||
|
String content = String.valueOf(wTitle.getTextObject()); |
||||||
|
Object vlaue = content.startsWith("=") ? new Formula(content) : content; |
||||||
|
return new WidgetValue(vlaue); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return StringUtils.EMPTY; |
||||||
|
} |
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 内边距 |
||||||
|
* @return 同上 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Insets getInsets() { |
||||||
|
PaddingMargin padding = toData().getMargin(); |
||||||
|
if (padding == null) { |
||||||
|
return new Insets(0, 0, 0, 0); |
||||||
|
} |
||||||
|
return new Insets(padding.getTop(), padding.getLeft(), padding.getBottom(), padding.getRight()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,291 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.AlphaComposite; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Font; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.geom.Rectangle2D; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
|
||||||
|
import com.fr.base.ScreenResolution; |
||||||
|
import com.fr.base.background.GradientBackground; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.mainframe.widget.editors.ButtonTypeEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.FontEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.IconEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.ImgBackgroundEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.ShortCutTextEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.FontCellRenderer; |
||||||
|
import com.fr.design.mainframe.widget.renderer.IconCellRenderer; |
||||||
|
import com.fr.form.parameter.FormSubmitButton; |
||||||
|
import com.fr.form.ui.Button; |
||||||
|
import com.fr.form.ui.FreeButton; |
||||||
|
import com.fr.general.Background; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XButton extends XWidgetCreator { |
||||||
|
|
||||||
|
public final static Background DEFAULTBG = new GradientBackground(new Color(247,247,247),new Color(210,210,210),GradientBackground.TOP2BOTTOM); |
||||||
|
public final static Font DEFAULTFT = new Font("Song_TypeFace",0,12); |
||||||
|
public final static Color DEFAULTFOREGROUNDCOLOR = Color.BLACK; |
||||||
|
private Background bg; |
||||||
|
private UILabel contentLabel; |
||||||
|
|
||||||
|
public XButton(Button widget, Dimension initSize) { |
||||||
|
this(new FreeButton(widget),initSize); |
||||||
|
} |
||||||
|
|
||||||
|
public XButton(FreeButton widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
public XButton(FormSubmitButton widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
public Background getContentBackground() { |
||||||
|
return bg; |
||||||
|
} |
||||||
|
|
||||||
|
public void setContentBackground(Background bg) { |
||||||
|
this.bg = bg; |
||||||
|
} |
||||||
|
|
||||||
|
public UILabel getContentLabel() { |
||||||
|
return contentLabel; |
||||||
|
} |
||||||
|
|
||||||
|
public void setContentLabel(UILabel contentLabel) { |
||||||
|
this.contentLabel = contentLabel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*根据下拉框选择返回按钮样式的默认设置或自定义设置列表 |
||||||
|
* @return 列表 |
||||||
|
* @throws IntrospectionException 抛错 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
CRPropertyDescriptor[] crp = ((FreeButton) data).isCustomStyle() ? getisCustomStyle() : getisnotCustomStyle(); |
||||||
|
|
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), crp); |
||||||
|
} |
||||||
|
|
||||||
|
protected CRPropertyDescriptor creatNonListenerStyle(int i) throws IntrospectionException{ |
||||||
|
CRPropertyDescriptor[] crPropertyDescriptors = { |
||||||
|
new CRPropertyDescriptor("text", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[] {"Form-Button", "Name"})), |
||||||
|
new CRPropertyDescriptor("customStyle", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Form-Button", "Style"})).setEditorClass( |
||||||
|
ButtonTypeEditor.class).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("initialBackground", this.data.getClass()).setEditorClass( |
||||||
|
ImgBackgroundEditor.class).setI18NName(Inter.getLocText("FR-Designer_Background-Initial")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("overBackground", this.data.getClass()).setEditorClass( |
||||||
|
ImgBackgroundEditor.class).setI18NName(Inter.getLocText("FR-Designer_Background-Over")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("clickBackground", this.data.getClass()).setEditorClass( |
||||||
|
ImgBackgroundEditor.class).setI18NName(Inter.getLocText("FR-Designer_Background-Click")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("font", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_FRFont")) |
||||||
|
.setEditorClass(FontEditor.class).setRendererClass(FontCellRenderer.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("iconName", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_Icon")) |
||||||
|
.setEditorClass(IconEditor.class).setRendererClass(IconCellRenderer.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("hotkeys", this.data.getClass()) |
||||||
|
.setI18NName(Inter.getLocText("FR-Designer_Button-Hotkeys")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
.setEditorClass(ShortCutTextEditor.class) |
||||||
|
|
||||||
|
}; |
||||||
|
return crPropertyDescriptors[i]; |
||||||
|
} |
||||||
|
protected CRPropertyDescriptor[] getisCustomStyle() throws IntrospectionException{ |
||||||
|
return new CRPropertyDescriptor[]{ |
||||||
|
creatNonListenerStyle(0) .setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
setButtonText(((FreeButton) data).getText()); |
||||||
|
} |
||||||
|
}), |
||||||
|
|
||||||
|
creatNonListenerStyle(1) .setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
checkButonType(); |
||||||
|
} |
||||||
|
}), |
||||||
|
creatNonListenerStyle(2).setPropertyChangeListener( |
||||||
|
new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
bg = ((FreeButton) data).getInitialBackground(); |
||||||
|
} |
||||||
|
}), |
||||||
|
creatNonListenerStyle(3), |
||||||
|
creatNonListenerStyle(4), |
||||||
|
creatNonListenerStyle(5) .setPropertyChangeListener( |
||||||
|
new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
FreeButton button = (FreeButton) data; |
||||||
|
if (button.getFont() != null) { |
||||||
|
contentLabel.setFont(button.getFont().applyResolutionNP( |
||||||
|
ScreenResolution.getScreenResolution())); |
||||||
|
contentLabel.setForeground(button.getFont().getForeground()); |
||||||
|
} |
||||||
|
} |
||||||
|
}), |
||||||
|
creatNonListenerStyle(6), |
||||||
|
creatNonListenerStyle(7) |
||||||
|
|
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
protected CRPropertyDescriptor[] getisnotCustomStyle() throws IntrospectionException { |
||||||
|
return new CRPropertyDescriptor[]{ |
||||||
|
new CRPropertyDescriptor("text", this.data.getClass()) |
||||||
|
.setI18NName(Inter.getLocText(new String[] {"Form-Button", "Name"})) |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
setButtonText(((FreeButton) data).getText()); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("customStyle", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Form-Button", "Style"})).setEditorClass( |
||||||
|
ButtonTypeEditor.class).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
checkButonType(); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("iconName", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_Icon")) |
||||||
|
.setEditorClass(IconEditor.class).setRendererClass(IconCellRenderer.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("hotkeys", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_Button-Hotkeys")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
.setEditorClass(ShortCutTextEditor.class) |
||||||
|
|
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
} |
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = new UILabel(); |
||||||
|
contentLabel = new UILabel(); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paintComponent(Graphics g) { |
||||||
|
super.paintComponent(g); |
||||||
|
|
||||||
|
//不可见时,按钮.4f透明
|
||||||
|
AlphaComposite composite = this.data.isVisible() ? (AlphaComposite)((Graphics2D)g).getComposite() : AlphaComposite.getInstance(AlphaComposite.SRC_OVER,HALF_OPACITY); |
||||||
|
((Graphics2D)g).setComposite(composite); |
||||||
|
Dimension panelSize = (contentLabel).getSize(); |
||||||
|
if(bg != null) { |
||||||
|
bg.paint(g, new Rectangle2D.Double(0, 0, panelSize.getWidth(), panelSize.getHeight())); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void setButtonText(String text) { |
||||||
|
contentLabel.setText(text); |
||||||
|
} |
||||||
|
|
||||||
|
private void checkButonType() { |
||||||
|
UILabel l = contentLabel; |
||||||
|
FreeButton button = (FreeButton) data; |
||||||
|
|
||||||
|
if (!button.isCustomStyle()) { |
||||||
|
l.setBorder(BorderFactory.createLineBorder(new Color(148, 148, 148))); |
||||||
|
bg = DEFAULTBG; |
||||||
|
contentLabel.setFont(DEFAULTFT); |
||||||
|
contentLabel.setForeground(DEFAULTFOREGROUNDCOLOR); |
||||||
|
editor.setLayout(new BorderLayout()); |
||||||
|
editor.add(l, BorderLayout.CENTER); |
||||||
|
} else { |
||||||
|
l.setBorder(null); |
||||||
|
editor.setLayout(new BorderLayout()); |
||||||
|
editor.add(l,BorderLayout.CENTER); |
||||||
|
if (button.getFont() != null) { |
||||||
|
contentLabel.setFont(button.getFont().applyResolutionNP( |
||||||
|
ScreenResolution.getScreenResolution())); |
||||||
|
contentLabel.setForeground(button.getFont().getForeground()); |
||||||
|
} |
||||||
|
l.setBounds(0, 0, button.getButtonWidth() == 0 ? this.getWidth() : button.getButtonWidth(), button |
||||||
|
.getButtonHeight() == 0 ? this.getHeight() : button.getButtonHeight()); |
||||||
|
bg = button.getInitialBackground(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
checkButonType(); |
||||||
|
UILabel l = contentLabel; |
||||||
|
FreeButton button = (FreeButton) data; |
||||||
|
l.setText(button.getText()); |
||||||
|
if (button.isCustomStyle() && button.getFont() != null) { |
||||||
|
l.setFont(button.getFont().applyResolutionNP(ScreenResolution.getScreenResolution())); |
||||||
|
l.setForeground(button.getFont().getForeground()); |
||||||
|
} |
||||||
|
|
||||||
|
l.setVerticalAlignment(SwingConstants.CENTER); |
||||||
|
l.setHorizontalAlignment(SwingConstants.CENTER); |
||||||
|
if (button.getButtonHeight() > 0 && button.getButtonWidth() > 0) { |
||||||
|
this.setSize(button.getButtonWidth(), button.getButtonHeight()); |
||||||
|
l.setSize(button.getButtonWidth(), button.getButtonHeight()); |
||||||
|
XLayoutContainer parent; |
||||||
|
if ((parent = XCreatorUtils.getParentXLayoutContainer(this)) instanceof XWAbsoluteLayout) { |
||||||
|
((XWAbsoluteLayout) parent).toData().setBounds(toData(), getBounds()); |
||||||
|
} |
||||||
|
} |
||||||
|
l.setEnabled(button.isEnabled()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化按钮的Size |
||||||
|
* @return 尺寸 |
||||||
|
*/ |
||||||
|
public Dimension initEditorSize() { |
||||||
|
FreeButton button = (FreeButton) data; |
||||||
|
if (checkbutton(button)) { |
||||||
|
return new Dimension(button.getButtonWidth(), button.getButtonHeight()); |
||||||
|
} |
||||||
|
return super.initEditorSize(); |
||||||
|
} |
||||||
|
private boolean checkbutton(FreeButton button){ |
||||||
|
return (button.isCustomStyle() && button.getButtonHeight() > 0 && button.getButtonWidth() > 0) ; |
||||||
|
} |
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "button_16.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,203 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
|
||||||
|
import com.fr.base.chart.BaseChart; |
||||||
|
import com.fr.base.chart.BaseChartCollection; |
||||||
|
import com.fr.design.gui.chart.BaseChartPropertyPane; |
||||||
|
import com.fr.design.gui.chart.MiddleChartComponent; |
||||||
|
import com.fr.design.mainframe.BaseJForm; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer; |
||||||
|
import com.fr.design.module.DesignModuleFactory; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
import com.fr.form.ui.AbstractBorderStyleWidget; |
||||||
|
import com.fr.form.ui.BaseChartEditor; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
/** |
||||||
|
* form中的图表按钮弹出的控件, 创建初始化图表内容. |
||||||
|
* |
||||||
|
* @author kunsnat E-mail:kunsnat@gmail.com |
||||||
|
* @version 创建时间:2013-7-5 上午10:28:30 |
||||||
|
* 类说明 |
||||||
|
*/ |
||||||
|
public class XChartEditor extends XBorderStyleWidgetCreator { |
||||||
|
private static final long serialVersionUID = -7009439442104836657L; |
||||||
|
//具体来说是DesignerEditor<SimpleChartComponent>
|
||||||
|
private DesignerEditor<JComponent> designerEditor; |
||||||
|
// private DesignerEditor<SimpleChartComponent> designerEditor;
|
||||||
|
//marro:无奈的属性,暂时想不出好办法
|
||||||
|
private boolean isRefreshing = false; |
||||||
|
|
||||||
|
public XChartEditor(BaseChartEditor editor) { |
||||||
|
this(editor, new Dimension(250, 150)); |
||||||
|
} |
||||||
|
|
||||||
|
public XChartEditor(BaseChartEditor editor, Dimension size) { |
||||||
|
super((Widget)editor, size); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getIconPath() { |
||||||
|
return super.getIconPath(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "Chart.png"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件默认名 |
||||||
|
* @return 组件类名(小写) |
||||||
|
*/ |
||||||
|
public String createDefaultName() { |
||||||
|
return "chart"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否支持设置标题 |
||||||
|
* @return 是返回true |
||||||
|
*/ |
||||||
|
public boolean hasTitleStyle() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 得到属性名 |
||||||
|
* @return 属性名 |
||||||
|
* @throws java.beans.IntrospectionException |
||||||
|
*/ |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Inter |
||||||
|
.getLocText("Form-Widget_Name")), |
||||||
|
new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( |
||||||
|
WLayoutBorderStyleEditor.class).setRendererClass(LayoutBorderStyleRenderer.class).setI18NName( |
||||||
|
Inter.getLocText("Chart-Style_Name")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
initStyle(); |
||||||
|
} |
||||||
|
}), |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖入参数面板 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean canEnterIntoParaPane(){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回设计器的Editor |
||||||
|
*/ |
||||||
|
public DesignerEditor<JComponent> getDesignerEditor() { |
||||||
|
return designerEditor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
initBorderStyle(); |
||||||
|
BaseChartCollection collection = ((BaseChartEditor) data).getChartCollection(); |
||||||
|
isRefreshing = true; |
||||||
|
((MiddleChartComponent) designerEditor.getEditorTarget()).populate(collection); |
||||||
|
isRefreshing = false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 点击选中的时候, 刷新界面 |
||||||
|
* 右键 reset之后, 触发事件 populate此方法 |
||||||
|
* |
||||||
|
* @param jform 表单 |
||||||
|
* @param formDesigner 表单设计器 |
||||||
|
* @return 控件. |
||||||
|
*/ |
||||||
|
public JComponent createToolPane(final BaseJForm jform, final FormDesigner formDesigner) { |
||||||
|
getDesignerEditorTarget().addStopEditingListener(new PropertyChangeAdapter() { |
||||||
|
public void propertyChange() { |
||||||
|
JComponent pane = jform.getEditingPane(); |
||||||
|
if (pane instanceof BaseChartPropertyPane) { |
||||||
|
((BaseChartPropertyPane) pane).setSupportCellData(true); |
||||||
|
((BaseChartPropertyPane) pane).populateChartPropertyPane(getDesignerEditorTarget().update(), formDesigner); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
final BaseChartPropertyPane propertyPane = DesignModuleFactory.getChartWidgetPropertyPane(formDesigner); |
||||||
|
SwingUtilities.invokeLater(new Runnable() { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
if (getDesignerEditor().getEditorTarget() != null) { |
||||||
|
propertyPane.setSupportCellData(true); |
||||||
|
propertyPane.populateChartPropertyPane(getDesignerEditorTarget().update(), formDesigner); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
return (JComponent)propertyPane; |
||||||
|
} |
||||||
|
|
||||||
|
private MiddleChartComponent getDesignerEditorTarget() { |
||||||
|
MiddleChartComponent bcc = null; |
||||||
|
if (getDesignerEditor().getEditorTarget() instanceof MiddleChartComponent) { |
||||||
|
bcc = (MiddleChartComponent) getDesignerEditor().getEditorTarget(); |
||||||
|
} |
||||||
|
return bcc; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 渲染Painter |
||||||
|
*/ |
||||||
|
public void paint(Graphics g) { |
||||||
|
super.paint(g); |
||||||
|
designerEditor.paintEditor(g, this.getSize()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化Editor大小. |
||||||
|
* |
||||||
|
* @return 返回大小. |
||||||
|
*/ |
||||||
|
public Dimension initEditorSize() { |
||||||
|
return new Dimension(250, 100); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (designerEditor == null) { |
||||||
|
final MiddleChartComponent chartComponent = DesignModuleFactory.getChartComponent(((BaseChartEditor) data).getChartCollection()); |
||||||
|
if (chartComponent != null) { |
||||||
|
JComponent jChart = chartComponent; |
||||||
|
jChart.setBorder(BorderFactory.createLineBorder(Color.lightGray)); |
||||||
|
designerEditor = new DesignerEditor<JComponent>(jChart); |
||||||
|
chartComponent.addStopEditingListener(designerEditor); |
||||||
|
designerEditor.addPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
public void propertyChange() { |
||||||
|
if (!isRefreshing) { |
||||||
|
((BaseChartEditor) data).resetChangeChartCollection(chartComponent.update()); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.form.ui.CheckBox; |
||||||
|
import com.fr.form.ui.WidgetValue; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XCheckBox extends XWidgetCreator { |
||||||
|
|
||||||
|
public XCheckBox(CheckBox widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("text", this.data.getClass()).setI18NName(Inter.getLocText("Text")) |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
((UICheckBox) editor).setText(((CheckBox) data).getText()); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Widget", "Value"})).setEditorClass(WidgetValueEditor.class) |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
WidgetValue value = ((CheckBox) data).getWidgetValue(); |
||||||
|
if (value != null && value.getValue() instanceof Boolean) { |
||||||
|
((UICheckBox) editor).setSelected((Boolean) value.getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("fontSize", this.data.getClass(), "getFontSize", "setFontSize") |
||||||
|
.setI18NName(Inter.getLocText(new String[]{"FRFont", "FRFont-Size"})) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = new UICheckBox(); |
||||||
|
editor.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
UICheckBox jCheckBox = (UICheckBox) editor; |
||||||
|
CheckBox check = (CheckBox) data; |
||||||
|
jCheckBox.setText(check.getText()); |
||||||
|
if (check.getWidgetValue() != null && check.getWidgetValue().getValue() instanceof Boolean) { |
||||||
|
jCheckBox.setSelected((Boolean) check.getWidgetValue().getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "check_box_16.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,92 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.widget.editors.DictionaryEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.InChangeBooleanEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.DictionaryRenderer; |
||||||
|
import com.fr.form.ui.CheckBoxGroup; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XCheckBoxGroup extends XFieldEditor { |
||||||
|
|
||||||
|
public XCheckBoxGroup(CheckBoxGroup widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), getCRPropertyDescriptor()); |
||||||
|
} |
||||||
|
|
||||||
|
private CRPropertyDescriptor[] getCRPropertyDescriptor() throws IntrospectionException { |
||||||
|
CRPropertyDescriptor[] crp = new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Widget", "Value"})).setEditorClass(WidgetValueEditor.class), |
||||||
|
new CRPropertyDescriptor("dictionary", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("DS-Dictionary")).setEditorClass(DictionaryEditor.class).setRendererClass( |
||||||
|
DictionaryRenderer.class), |
||||||
|
new CRPropertyDescriptor("adaptive", this.data.getClass()).setI18NName(Inter.getLocText("Adaptive")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced").setEditorClass(InChangeBooleanEditor.class), |
||||||
|
new CRPropertyDescriptor("chooseAll", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Provide", "Choose_All"})).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("returnString", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Return-String")).setEditorClass(InChangeBooleanEditor.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value") }; |
||||||
|
if (((CheckBoxGroup) this.toData()).isReturnString()) { |
||||||
|
crp = (CRPropertyDescriptor[]) ArrayUtils.addAll(crp, new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("delimiter", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Form-Delimiter")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Return-Value"), |
||||||
|
new CRPropertyDescriptor("startSymbol", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("ComboCheckBox-Start_Symbol")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value"), |
||||||
|
new CRPropertyDescriptor("endSymbol", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("ComboCheckBox-End_Symbol")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value") }); |
||||||
|
} |
||||||
|
if (!((CheckBoxGroup) this.toData()).isAdaptive()) { |
||||||
|
crp = (CRPropertyDescriptor[]) ArrayUtils.add(crp, new CRPropertyDescriptor("columnsInRow", this.data |
||||||
|
.getClass()).setI18NName(Inter.getLocText("Button-Group-Display-Columns")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced")); |
||||||
|
} |
||||||
|
return crp; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
editor.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
||||||
|
UICheckBox cb1 = new UICheckBox(); |
||||||
|
editor.add(cb1, BorderLayout.WEST); |
||||||
|
UICheckBox cb2 = new UICheckBox(); |
||||||
|
editor.add(cb2, BorderLayout.EAST); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "checkbox_group_16.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.widget.editors.DictionaryEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.DictionaryRenderer; |
||||||
|
import com.fr.form.ui.ComboBox; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XComboBox extends XCustomWriteAbleRepeatEditor { |
||||||
|
LimpidButton btn; |
||||||
|
|
||||||
|
public XComboBox(ComboBox widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 控件的属性列表 |
||||||
|
* @return 此控件所用的属性列表 |
||||||
|
* @throws IntrospectionException 异常 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll( |
||||||
|
super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[]{ |
||||||
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName(Inter.getLocText(new String[]{"Widget", "Value"})).setEditorClass(WidgetValueEditor.class), |
||||||
|
new CRPropertyDescriptor("dictionary", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_DS-Dictionary")).setEditorClass(DictionaryEditor.class).setRendererClass(DictionaryRenderer.class) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
UITextField textField = new UITextField(5); |
||||||
|
textField.setOpaque(false); |
||||||
|
editor.add(textField, BorderLayout.CENTER); |
||||||
|
btn = new LimpidButton("", this.getIconPath(), toData().isVisible() ? FULL_OPACITY : HALF_OPACITY); |
||||||
|
btn.setPreferredSize(new Dimension(21, 21)); |
||||||
|
btn.setOpaque(true); |
||||||
|
editor.add(btn, BorderLayout.EAST); |
||||||
|
editor.setBackground(Color.WHITE); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "combo_box_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
protected void makeVisible(boolean visible) { |
||||||
|
btn.makeVisible(visible); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前XCreator的一个封装父容器 |
||||||
|
* |
||||||
|
* @param widgetName 当前组件名 |
||||||
|
* |
||||||
|
* @return 封装的父容器 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:47:23 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected XLayoutContainer getCreatorWrapper(String widgetName){ |
||||||
|
return new XWScaleLayout(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将当前对象添加到父容器中 |
||||||
|
* |
||||||
|
* @param parentPanel 父容器组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:57:55 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected void addToWrapper(XLayoutContainer parentPanel, int width, int minHeight){ |
||||||
|
this.setSize(width, minHeight); |
||||||
|
parentPanel.add(this); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 此控件在自适应布局要保持原样高度 |
||||||
|
* |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean shouldScaleCreator() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.widget.editors.InChangeBooleanEditor; |
||||||
|
import com.fr.form.ui.ComboCheckBox; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XComboCheckBox extends XComboBox { |
||||||
|
|
||||||
|
public XComboCheckBox(ComboCheckBox widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), !((ComboCheckBox) this.toData()) |
||||||
|
.isReturnString() ? new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("supportTag", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Form-SupportTag")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced"), |
||||||
|
new CRPropertyDescriptor("delimiter", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Form-Delimiter")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced"), |
||||||
|
new CRPropertyDescriptor("returnString", this.data.getClass()).setEditorClass( |
||||||
|
InChangeBooleanEditor.class).setI18NName(Inter.getLocText("Return-String")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value") } : new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("delimiter", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Form-Delimiter")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced"), |
||||||
|
new CRPropertyDescriptor("returnString", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Return-String")).setEditorClass(InChangeBooleanEditor.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value"), |
||||||
|
new CRPropertyDescriptor("startSymbol", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("ComboCheckBox-Start_Symbol")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Return-Value"), |
||||||
|
new CRPropertyDescriptor("endSymbol", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("ComboCheckBox-End_Symbol")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Return-Value") }); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "combo_check_16.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Rectangle; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.BaseJForm; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
|
||||||
|
public interface XComponent { |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件的位置大小 |
||||||
|
* @return 返回bound |
||||||
|
*/ |
||||||
|
Rectangle getBounds(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置组件的位置大小 |
||||||
|
* @param oldbounds bound大小 |
||||||
|
*/ |
||||||
|
void setBounds(Rectangle oldbounds); |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成工具菜单界面 |
||||||
|
* @param jform BaseJForm类 |
||||||
|
* @param formeditor 设计界面组件 |
||||||
|
* @return 返回工具界面 |
||||||
|
*/ |
||||||
|
JComponent createToolPane(BaseJForm jform, FormDesigner formeditor); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,186 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Cursor; |
||||||
|
import java.awt.Point; |
||||||
|
import java.awt.Rectangle; |
||||||
|
import java.awt.Toolkit; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.mainframe.BaseJForm; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.designer.beans.location.Direction; |
||||||
|
import com.fr.form.ui.Connector; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
|
||||||
|
//这个类仅仅是对Connector包装下,使得表单设计页面逻辑更清晰
|
||||||
|
public class XConnector implements XComponent { |
||||||
|
|
||||||
|
private XWAbsoluteLayout parent; |
||||||
|
private Connector connector; |
||||||
|
public static Cursor connectorCursor; |
||||||
|
public static Cursor moveCursor; |
||||||
|
|
||||||
|
static { |
||||||
|
connectorCursor = Toolkit.getDefaultToolkit().createCustomCursor( |
||||||
|
BaseUtils.readImage("/com/fr/design/images/form/designer/cursor/connectorcursor.png"), new Point(0, 0), |
||||||
|
"connector"); |
||||||
|
moveCursor = Toolkit.getDefaultToolkit().createCustomCursor( |
||||||
|
BaseUtils.readImage("/com/fr/design/images/form/designer/cursor/move.png"), new Point(16, 16), |
||||||
|
"move"); |
||||||
|
} |
||||||
|
|
||||||
|
public XConnector(Connector connector, XWAbsoluteLayout xWAbsoluteLayout) { |
||||||
|
this.connector = connector; |
||||||
|
this.parent = xWAbsoluteLayout; |
||||||
|
} |
||||||
|
|
||||||
|
private boolean near(int x1, int x2) { |
||||||
|
return x1 - x2 >= -XCreatorConstants.RESIZE_BOX_SIZ && x1 - x2 <= XCreatorConstants.RESIZE_BOX_SIZ; |
||||||
|
} |
||||||
|
|
||||||
|
private Rectangle createRectangle(Point A, Point B) { |
||||||
|
return new Rectangle(Math.min(A.x, B.x), Math.min(A.y, B.y), Math.abs(A.x - B.x), Math.abs(A.y - B.y)); |
||||||
|
} |
||||||
|
|
||||||
|
public XLayoutContainer getParentXLayoutContainer() { |
||||||
|
return parent; |
||||||
|
} |
||||||
|
|
||||||
|
public Connector getConnector() { |
||||||
|
return connector; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Rectangle getBounds() { |
||||||
|
return createRectangle(connector.getStartPoint(), connector.getEndPoint()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setBounds(Rectangle oldbounds) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public JComponent createToolPane(BaseJForm jform, FormDesigner formEditor) { |
||||||
|
return jform.getEditingPane(); |
||||||
|
} |
||||||
|
|
||||||
|
public ConnectorDirection getDirection(int x, int y) { |
||||||
|
|
||||||
|
Point pS = connector.getStartPoint(); |
||||||
|
if (near(x, pS.x) && near(y, pS.y)) { |
||||||
|
return new ConnectorDirection(pS, null); |
||||||
|
} |
||||||
|
Point pE = connector.getEndPoint(); |
||||||
|
if (near(x, pE.x) && near(y, pE.y)) { |
||||||
|
return new ConnectorDirection(null, pE); |
||||||
|
} |
||||||
|
|
||||||
|
Point p1 = pS; |
||||||
|
Point p2; |
||||||
|
Point p; |
||||||
|
int size = connector.getPointCount(); |
||||||
|
for (int i = 0; i < size - 1; i++) { |
||||||
|
p2 = connector.getPointIndex(i + 1); |
||||||
|
p = connector.getMidPoint(p1, p2); |
||||||
|
if (near(p.x, x) && near(p.y, y)) { |
||||||
|
return new ConnectorDirection(p1, p2); |
||||||
|
} |
||||||
|
p1 = p2; |
||||||
|
} |
||||||
|
return new ConnectorDirection(); |
||||||
|
} |
||||||
|
|
||||||
|
public class ConnectorDirection implements Direction { |
||||||
|
|
||||||
|
private Point A; |
||||||
|
private Point B; |
||||||
|
private Rectangle oldbounds; |
||||||
|
|
||||||
|
private ConnectorDirection() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private ConnectorDirection(Point A, Point B) { |
||||||
|
this.A = A; |
||||||
|
this.B = B; |
||||||
|
} |
||||||
|
|
||||||
|
private Cursor getCursor() { |
||||||
|
if (A == null || B == null) { |
||||||
|
return A == B ? Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR) : moveCursor; |
||||||
|
} |
||||||
|
if (A.x == B.x) { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR); |
||||||
|
} else if (A.y == B.y) { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR); |
||||||
|
} else { |
||||||
|
return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void setXY(Point p1, Point p2, int dx, int dy, Rectangle oldbounds) { |
||||||
|
if (p1.x == p2.x) { |
||||||
|
p1.x = p2.x = oldbounds.x + dx; |
||||||
|
} else { |
||||||
|
p1.y = p2.y = oldbounds.y + dy; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void drag(int dx, int dy, FormDesigner designer) { |
||||||
|
if (A == null || B == null) { |
||||||
|
if (A != null) { |
||||||
|
A.x = oldbounds.x + dx; |
||||||
|
A.y = oldbounds.y + dy; |
||||||
|
} else if (B != null) { |
||||||
|
B.x = oldbounds.x + dx; |
||||||
|
B.y = oldbounds.y + dy; |
||||||
|
} else { |
||||||
|
setBounds(new Rectangle(oldbounds.x + dx, oldbounds.y + dy, oldbounds.width, oldbounds.height)); |
||||||
|
} |
||||||
|
designer.getDrawLineHelper().resetConnector(connector); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (A == connector.getStartPoint()) { |
||||||
|
this.A = new Point(A.x, A.y); |
||||||
|
connector.addPoint(1, A); |
||||||
|
} |
||||||
|
if (connector.getEndPoint() == B) { |
||||||
|
this.B = new Point(B.x, B.y); |
||||||
|
connector.addPoint(connector.getPointCount() - 1, B); |
||||||
|
} |
||||||
|
setXY(A, B, dx, dy, oldbounds); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Rectangle getBounds() { |
||||||
|
if (A == null || B == null) { |
||||||
|
if (A != null) { |
||||||
|
return new Rectangle(A.x, A.y, 0, 0); |
||||||
|
} else if (B != null) { |
||||||
|
return new Rectangle(B.x, B.y, 0, 0); |
||||||
|
} else { |
||||||
|
return XConnector.this.getBounds(); |
||||||
|
} |
||||||
|
} |
||||||
|
return createRectangle(A, B); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getActual() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateCursor(FormDesigner formEditor) { |
||||||
|
formEditor.setCursor(getCursor()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void backupBounds(FormDesigner formEditor) { |
||||||
|
oldbounds = getBounds(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,521 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.designer.beans.AdapterBus; |
||||||
|
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
import com.fr.design.designer.beans.models.SelectionModel; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.*; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
import com.fr.form.ui.Widget; |
||||||
|
import com.fr.form.ui.container.WTitleLayout; |
||||||
|
import com.fr.stable.StableUtils; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.border.Border; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 com.fr.base.listener.OB的设计组件 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public abstract class XCreator extends JPanel implements XComponent, XCreatorTools { |
||||||
|
|
||||||
|
protected static final Border DEFALUTBORDER = BorderFactory.createLineBorder(new Color(210, 210, 210), 1); |
||||||
|
public static final Dimension SMALL_PREFERRED_SIZE = new Dimension(80, 21); |
||||||
|
protected static final Dimension MIDDLE_PREFERRED_SIZE = new Dimension(80, 50); |
||||||
|
protected static final Dimension BIG_PREFERRED_SIZE = new Dimension(80, 80); |
||||||
|
// barry: 拖拽控件时,控件要恢复原始大小,就先把控件当前大小备份到这里。
|
||||||
|
protected Dimension backupSize; |
||||||
|
protected XLayoutContainer backupParent; |
||||||
|
|
||||||
|
protected Widget data; |
||||||
|
protected JComponent editor; |
||||||
|
// XCreator加入到某些XLayoutContainer中时,能调整宽度或者高度
|
||||||
|
private int[] directions; |
||||||
|
private Rectangle backupBound; |
||||||
|
|
||||||
|
public XCreator(Widget ob, Dimension initSize) { |
||||||
|
this.data = ob; |
||||||
|
|
||||||
|
this.initEditor(); |
||||||
|
|
||||||
|
if (editor != null && editor != this) { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
add(editor, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
if (initSize.width == 0) { |
||||||
|
initSize.width = this.initEditorSize().width; |
||||||
|
} |
||||||
|
if (initSize.height == 0) { |
||||||
|
initSize.height = this.initEditorSize().height; |
||||||
|
} |
||||||
|
this.setPreferredSize(initSize); |
||||||
|
this.setSize(initSize); |
||||||
|
this.setMaximumSize(initSize); |
||||||
|
this.initXCreatorProperties(); |
||||||
|
} |
||||||
|
|
||||||
|
public int[] getDirections() { |
||||||
|
return directions; |
||||||
|
} |
||||||
|
|
||||||
|
public void setDirections(int[] directions) { |
||||||
|
this.directions = directions; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 应用备份的大小 |
||||||
|
*/ |
||||||
|
public void useBackupSize() { |
||||||
|
if (this.backupSize != null) { |
||||||
|
setSize(this.backupSize); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 备份当前大小 |
||||||
|
*/ |
||||||
|
public void backupCurrentSize() { |
||||||
|
this.backupSize = getSize(); |
||||||
|
} |
||||||
|
|
||||||
|
public XLayoutContainer getBackupParent() { |
||||||
|
return backupParent; |
||||||
|
} |
||||||
|
|
||||||
|
public void setBackupParent(XLayoutContainer backupContainer) { |
||||||
|
this.backupParent = backupContainer; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 备份当前parent容器 |
||||||
|
*/ |
||||||
|
public void backupParent() { |
||||||
|
setBackupParent(XCreatorUtils.getParentXLayoutContainer(this)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前XCreator的一个封装父容器 |
||||||
|
* |
||||||
|
* @param widgetName 当前组件名 |
||||||
|
* |
||||||
|
* @return 封装的父容器 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:47:23 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected XLayoutContainer getCreatorWrapper(String widgetName){ |
||||||
|
return new XWTitleLayout(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将当前对象添加到父容器中 |
||||||
|
* |
||||||
|
* @param parentPanel 父容器组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:57:55 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected void addToWrapper(XLayoutContainer parentPanel, int width, int minHeight){ |
||||||
|
parentPanel.add(this, WTitleLayout.BODY); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置父容器的名字 |
||||||
|
* |
||||||
|
* @param parentPanel 当前父容器 |
||||||
|
* @param widgetName 当前控件名 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-27-上午9:47:00 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected void setWrapperName(XLayoutContainer parentPanel, String widgetName){ |
||||||
|
parentPanel.toData().setWidgetName(widgetName); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化当前组件的父容器 |
||||||
|
* 大体分为三种: Scale缩放型, Title标题型, Border自定义标题栏 |
||||||
|
* |
||||||
|
* @param minHeight 最小高度 |
||||||
|
* |
||||||
|
* @return 父容器 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午5:15:23 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public XLayoutContainer initCreatorWrapper(int minHeight){ |
||||||
|
XLayoutContainer parentPanel; |
||||||
|
String widgetName = this.toData().getWidgetName(); |
||||||
|
parentPanel = this.getCreatorWrapper(widgetName); |
||||||
|
|
||||||
|
int width = this.getWidth(); |
||||||
|
int height = this.getHeight(); |
||||||
|
|
||||||
|
parentPanel.setLocation(this.getX(), this.getY()); |
||||||
|
parentPanel.setSize(width, height); |
||||||
|
setWrapperName(parentPanel, widgetName); |
||||||
|
this.setLocation(0, 0); |
||||||
|
this.addToWrapper(parentPanel, width, minHeight); |
||||||
|
LayoutUtils.layoutRootContainer(parentPanel); |
||||||
|
|
||||||
|
return parentPanel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化creator的属性值 |
||||||
|
*/ |
||||||
|
public void rebuid() { |
||||||
|
initXCreatorProperties(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件属性值 |
||||||
|
* @return 返回组件属性值 |
||||||
|
* @throws IntrospectionException 异常 |
||||||
|
*/ |
||||||
|
public abstract CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成creator对应的控件widget |
||||||
|
* @return 控件widget |
||||||
|
*/ |
||||||
|
public Widget toData() { |
||||||
|
return this.data; |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract JComponent initEditor(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据Widget的属性值初始化XCreator的属性值 |
||||||
|
*/ |
||||||
|
protected abstract void initXCreatorProperties(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回XCreator的默认大小80x21 |
||||||
|
* @return 默认的最小大小 |
||||||
|
*/ |
||||||
|
public Dimension initEditorSize() { |
||||||
|
return SMALL_PREFERRED_SIZE; |
||||||
|
} |
||||||
|
|
||||||
|
protected String getIconName() { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
public String getIconPath() { |
||||||
|
return "/com/fr/web/images/form/resources/" + getIconName(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件默认名 |
||||||
|
* @return 组件类名(小写) |
||||||
|
*/ |
||||||
|
public String createDefaultName() { |
||||||
|
String name = this.getClass().getSimpleName(); |
||||||
|
return Character.toLowerCase(name.charAt(1)) + name.substring(2); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setBounds(Rectangle bounds) { |
||||||
|
Dimension size = this.getMinimumSize(); |
||||||
|
if (bounds.getWidth() < size.width) { |
||||||
|
bounds.width = size.width; |
||||||
|
//针对拖动,不大好。
|
||||||
|
bounds.x = this.getX(); |
||||||
|
} |
||||||
|
if (bounds.getHeight() < size.height) { |
||||||
|
bounds.height = size.height; |
||||||
|
bounds.y = this.getY(); |
||||||
|
} |
||||||
|
super.setBounds(bounds); |
||||||
|
} |
||||||
|
|
||||||
|
public DesignerEditor<? extends JComponent> getDesignerEditor() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据权限编辑工具界面 |
||||||
|
* @param jform 表单容器 |
||||||
|
*@param formEditor 设计界面组件 |
||||||
|
*@return 工具界面 |
||||||
|
*/ |
||||||
|
public JComponent createToolPane(BaseJForm jform, FormDesigner formEditor) { |
||||||
|
if (!BaseUtils.isAuthorityEditing()) { |
||||||
|
if (isDedicateContainer()) { |
||||||
|
// 图表块和报表块由于控件树处不显示,但对应的属性表要显示,此处处理下
|
||||||
|
XCreator child = ((XLayoutContainer) this).getXCreator(0); |
||||||
|
return child.createToolPane(jform, formEditor); |
||||||
|
} |
||||||
|
return WidgetPropertyPane.getInstance(formEditor); |
||||||
|
} else { |
||||||
|
//判断是不是布局,布局不支持权限编辑
|
||||||
|
if (formEditor.isSupportAuthority()) { |
||||||
|
AuthorityPropertyPane authorityPropertyPane = new AuthorityPropertyPane(formEditor); |
||||||
|
authorityPropertyPane.populate(); |
||||||
|
return authorityPropertyPane; |
||||||
|
} |
||||||
|
|
||||||
|
return new NoSupportAuthorityEdit(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension getMinimumSize() { |
||||||
|
return new Dimension(0, 0); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否支持切换到报表界面编辑 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean isReport(){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖入参数面板 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean canEnterIntoParaPane(){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖入表单主体 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean canEnterIntoAdaptPane(){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖拽(表单中参数面板和自适应布局不可以拖拽) |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean isSupportDrag(){ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public List<String> getAllXCreatorNameList(XCreator xCreator, List<String> namelist){ |
||||||
|
namelist.add(xCreator.toData().getWidgetName()); |
||||||
|
return namelist; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否有查询按钮 |
||||||
|
* @param xCreator 控件或容器 |
||||||
|
* @return 有无查询按钮 |
||||||
|
*/ |
||||||
|
public boolean SearchQueryCreators(XCreator xCreator) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the backupBound |
||||||
|
*/ |
||||||
|
public Rectangle getBackupBound() { |
||||||
|
return backupBound; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param rec the backupBound to set |
||||||
|
*/ |
||||||
|
public void setBackupBound(Rectangle rec) { |
||||||
|
this.backupBound = rec; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 控件树不显示此组件 |
||||||
|
* @param path 控件树list |
||||||
|
*/ |
||||||
|
public void notShowInComponentTree(ArrayList<Component> path) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 重置组件的名称 |
||||||
|
* @param name 名称 |
||||||
|
*/ |
||||||
|
public void resetCreatorName(String name) { |
||||||
|
toData().setWidgetName(name); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回编辑的子组件,scale为其内部组件 |
||||||
|
* @return 组件 |
||||||
|
*/ |
||||||
|
public XCreator getEditingChildCreator() { |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回对应属性表的组件,scale和title返回其子组件 |
||||||
|
* @return 组件 |
||||||
|
*/ |
||||||
|
public XCreator getPropertyDescriptorCreator() { |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新子组件的Bound; 没有不处理 |
||||||
|
* @param minHeight 最小高度 |
||||||
|
*/ |
||||||
|
public void updateChildBound(int minHeight) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否作为控件树的叶子节点 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean isComponentTreeLeaf() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否为sclae和title专属容器 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean isDedicateContainer() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否接收这种类型 |
||||||
|
* @param acceptTypes 接收的类型 |
||||||
|
* @return 接收指定的类型则返回true,否则返回false |
||||||
|
*/ |
||||||
|
public boolean acceptType(Class<?>... acceptTypes) { |
||||||
|
for (Class<?> type : acceptTypes) { |
||||||
|
if (StableUtils.classInstanceOf(this.getClass(), type)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否组件要缩放(自适应里部分组件需要, 如数字、文本、下拉框、下拉复选框、密码、下拉树、下拉复选树、日期) |
||||||
|
* |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean shouldScaleCreator() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否支持标题样式 |
||||||
|
* @return 默认false |
||||||
|
*/ |
||||||
|
public boolean hasTitleStyle() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应点击事件 |
||||||
|
* |
||||||
|
* @param editingMouseListener 鼠标点击,位置处理器 |
||||||
|
* @param e 鼠标点击事件 |
||||||
|
*/ |
||||||
|
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ |
||||||
|
FormDesigner designer = editingMouseListener.getDesigner(); |
||||||
|
SelectionModel selectionModel = editingMouseListener.getSelectionModel(); |
||||||
|
|
||||||
|
if (e.getClickCount() <= 1) { |
||||||
|
selectionModel.selectACreatorAtMouseEvent(e); |
||||||
|
} |
||||||
|
|
||||||
|
if (editingMouseListener.stopEditing()) { |
||||||
|
if (this != designer.getRootComponent()) { |
||||||
|
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); |
||||||
|
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除相关组件 |
||||||
|
* |
||||||
|
* @param creator 当前组件 |
||||||
|
* @param designer 表单设计器 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void deleteRelatedComponent(XCreator creator,FormDesigner designer){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 选择相关组件 |
||||||
|
* |
||||||
|
* @param creator 当前组件 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void seleteRelatedComponent(XCreator creator){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件 |
||||||
|
* @return |
||||||
|
* String |
||||||
|
*/ |
||||||
|
public XCreator getXCreator(){ |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 按百分比调整组件 |
||||||
|
* @param percent 百分比 |
||||||
|
* void |
||||||
|
*/ |
||||||
|
public void adjustCompSize(double percent){ |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回一些需要的子组件 |
||||||
|
* @return 返回一些需要的子组件 |
||||||
|
* ArrayList<?> |
||||||
|
*/ |
||||||
|
public ArrayList<?> getTargetChildrenList(){ |
||||||
|
return new ArrayList(); |
||||||
|
} |
||||||
|
|
||||||
|
public XLayoutContainer getOuterLayout(){ |
||||||
|
return this.getBackupParent(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 重新调整子组件宽度 |
||||||
|
* @param width 宽度 |
||||||
|
*/ |
||||||
|
public void recalculateChildWidth(int width){ |
||||||
|
return; |
||||||
|
} |
||||||
|
/** |
||||||
|
* 重新调整子组件高度 |
||||||
|
* @param height 高度 |
||||||
|
*/ |
||||||
|
public void recalculateChildHeight(int height){ |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Component; |
||||||
|
import java.util.ArrayList; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author jim |
||||||
|
* @date 2014-11-7 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public interface XCreatorTools { |
||||||
|
|
||||||
|
/** |
||||||
|
* 控件树不显示此组件 |
||||||
|
* @param path 控件树list |
||||||
|
*/ |
||||||
|
void notShowInComponentTree(ArrayList<Component> path); |
||||||
|
|
||||||
|
/** |
||||||
|
* 重置组件的名称 |
||||||
|
* @param name 名称 |
||||||
|
*/ |
||||||
|
void resetCreatorName(String name); |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回编辑的子组件,scale为其内部组件 |
||||||
|
* @return 组件 |
||||||
|
*/ |
||||||
|
XCreator getEditingChildCreator(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回对应属性表的组件,scale和title返回其子组件 |
||||||
|
* @return 组件 |
||||||
|
*/ |
||||||
|
XCreator getPropertyDescriptorCreator(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新子组件的Bound; 没有不处理 |
||||||
|
* @param minHeight 最小高度 |
||||||
|
*/ |
||||||
|
void updateChildBound(int minHeight); |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否作为控件树的叶子节点 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
boolean isComponentTreeLeaf(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否为sclae和title专属容器 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
boolean isDedicateContainer(); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,233 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.base.FRContext; |
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XCardAddButton; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardLayout; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout; |
||||||
|
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; |
||||||
|
import com.fr.design.module.DesignModuleFactory; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
import com.fr.form.parameter.FormSubmitButton; |
||||||
|
import com.fr.form.ui.Button; |
||||||
|
import com.fr.form.ui.*; |
||||||
|
import com.fr.form.ui.Label; |
||||||
|
import com.fr.form.ui.TextArea; |
||||||
|
import com.fr.form.ui.container.*; |
||||||
|
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout; |
||||||
|
import com.fr.form.ui.container.cardlayout.WCardTagLayout; |
||||||
|
import com.fr.form.ui.container.cardlayout.WCardTitleLayout; |
||||||
|
import com.fr.form.ui.container.cardlayout.WTabFitLayout; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.lang.reflect.Constructor; |
||||||
|
|
||||||
|
/** |
||||||
|
* XCreator的相关处理 |
||||||
|
* |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XCreatorUtils { |
||||||
|
|
||||||
|
public static java.util.Map<Class<? extends Widget>, Class<?>> objectMap = new java.util.HashMap<Class<? extends Widget>, Class<?>>(); |
||||||
|
public static java.util.Map<Class<? extends Widget>, Class<?>> xLayoutMap = new java.util.HashMap<Class<? extends Widget>, Class<?>>(); |
||||||
|
|
||||||
|
static { |
||||||
|
objectMap.put(TextEditor.class, XTextEditor.class); |
||||||
|
objectMap.put(TextArea.class, XTextArea.class); |
||||||
|
objectMap.put(NumberEditor.class, XNumberEditor.class); |
||||||
|
objectMap.put(FreeButton.class, XButton.class); |
||||||
|
objectMap.put(CheckBox.class, XCheckBox.class); |
||||||
|
objectMap.put(CheckBoxGroup.class, XCheckBoxGroup.class); |
||||||
|
objectMap.put(ComboBox.class, XComboBox.class); |
||||||
|
objectMap.put(ComboCheckBox.class, XComboCheckBox.class); |
||||||
|
objectMap.put(DateEditor.class, XDateEditor.class); |
||||||
|
objectMap.put(FileEditor.class, XFileUploader.class); |
||||||
|
objectMap.put(Table.class, XTableEditor.class); |
||||||
|
objectMap.put(IframeEditor.class, XIframeEditor.class); |
||||||
|
objectMap.put(FreeButton.class, XButton.class); |
||||||
|
objectMap.put(FormSubmitButton.class, XButton.class); |
||||||
|
objectMap.put(Button.class, XButton.class); |
||||||
|
objectMap.put(Label.class, XLabel.class); |
||||||
|
objectMap.put(ListEditor.class, XListEditor.class); |
||||||
|
objectMap.put(TableTree.class, XTableTree.class); |
||||||
|
objectMap.put(MultiFileEditor.class, XMultiFileUploader.class); |
||||||
|
objectMap.put(Password.class, XPassword.class); |
||||||
|
objectMap.put(Radio.class, XRadio.class); |
||||||
|
objectMap.put(RadioGroup.class, XRadioGroup.class); |
||||||
|
objectMap.put(TreeEditor.class, XTreeEditor.class); |
||||||
|
objectMap.put(TreeComboBoxEditor.class, XTreeComboBoxEditor.class); |
||||||
|
objectMap.put(EditorHolder.class, XEditorHolder.class); |
||||||
|
objectMap.put(DataTable.class, XDataTable.class); |
||||||
|
objectMap.put(ElementCaseEditor.class, XElementCase.class); |
||||||
|
objectMap.put(NameWidget.class, XNameWidget.class); |
||||||
|
objectMap.put(CardSwitchButton.class, XCardSwitchButton.class); |
||||||
|
objectMap.put(CardAddButton.class, XCardAddButton.class); |
||||||
|
putExtraEditor(); |
||||||
|
|
||||||
|
xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class); |
||||||
|
xLayoutMap.put(WParameterLayout.class, XWParameterLayout.class); |
||||||
|
xLayoutMap.put(WAbsoluteLayout.class, XWAbsoluteLayout.class); |
||||||
|
xLayoutMap.put(WHorizontalBoxLayout.class, XWHorizontalBoxLayout.class); |
||||||
|
xLayoutMap.put(WBorderLayout.class, XWBorderLayout.class); |
||||||
|
xLayoutMap.put(WCardLayout.class, XWCardLayout.class); |
||||||
|
xLayoutMap.put(WVerticalBoxLayout.class, XWVerticalBoxLayout.class); |
||||||
|
xLayoutMap.put(WHorizontalSplitLayout.class, XWHorizontalSplitLayout.class); |
||||||
|
xLayoutMap.put(WVerticalSplitLayout.class, XWVerticalSplitLayout.class); |
||||||
|
xLayoutMap.put(WGridLayout.class, XWGridLayout.class); |
||||||
|
|
||||||
|
xLayoutMap.put(WFitLayout.class, XWFitLayout.class); |
||||||
|
xLayoutMap.put(WScaleLayout.class, XWScaleLayout.class); |
||||||
|
xLayoutMap.put(WTitleLayout.class, XWTitleLayout.class); |
||||||
|
xLayoutMap.put(WCardTagLayout.class, XWCardTagLayout.class); |
||||||
|
xLayoutMap.put(WCardTitleLayout.class, XWCardTitleLayout.class); |
||||||
|
xLayoutMap.put(WTabFitLayout.class, XWTabFitLayout.class); |
||||||
|
xLayoutMap.put(WCardMainBorderLayout.class, XWCardMainBorderLayout.class); |
||||||
|
|
||||||
|
objectMap.putAll(ExtraDesignClassManager.getInstance().getParameterWidgetOptionsMap()); |
||||||
|
objectMap.putAll(ExtraDesignClassManager.getInstance().getFormWidgetOptionsMap()); |
||||||
|
} |
||||||
|
|
||||||
|
private static void putExtraEditor() { |
||||||
|
if (DesignModuleFactory.getChartEditorClass() != null) { |
||||||
|
objectMap.put(DesignModuleFactory.getChartEditorClass(), XChartEditor.class); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static Class<? extends XCreator> searchXCreatorClass(Class<? extends Widget> clazz) { |
||||||
|
Class<? extends XCreator> xClazz = (Class<? extends XCreator>) objectMap.get(clazz); |
||||||
|
if (xClazz == null) { |
||||||
|
xClazz = (Class<? extends XCreator>) xLayoutMap.get(clazz); |
||||||
|
} |
||||||
|
return xClazz; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*创建creator |
||||||
|
* @param widget 控件 |
||||||
|
* @return 返回控件的creator |
||||||
|
*/ |
||||||
|
public static XCreator createXCreator(Widget widget) { |
||||||
|
return createXCreator(widget, new Dimension()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 带初始大小的Widget转化为XCreator当然XCreator也需要把大小赋值上 |
||||||
|
* @param widget 控件 |
||||||
|
* @param d 大小 |
||||||
|
* @return 返回控件的xcreator |
||||||
|
*/ |
||||||
|
public static XCreator createXCreator(Widget widget, Dimension d) { |
||||||
|
Class<? extends Widget> widgetClass; |
||||||
|
Class<? extends XCreator> clazz; |
||||||
|
|
||||||
|
if (widget == null) { |
||||||
|
clazz = NullCreator.class; |
||||||
|
} else { |
||||||
|
widgetClass = widget.getClass(); |
||||||
|
clazz = XCreatorUtils.searchXCreatorClass(widgetClass); |
||||||
|
if (clazz == null) { |
||||||
|
FRContext.getLogger().error(widget + "'s" + " xcreator doesn't exsit!"); |
||||||
|
clazz = NullCreator.class; |
||||||
|
} |
||||||
|
} |
||||||
|
XCreator creator = null; |
||||||
|
Constructor[] constructors = clazz.getConstructors(); |
||||||
|
for (Constructor c : constructors) { |
||||||
|
try { |
||||||
|
creator = (XCreator) c.newInstance(widget, d); |
||||||
|
break; |
||||||
|
} catch (Exception ignore) { |
||||||
|
// richie:这里的错误可以忽略
|
||||||
|
// FRContext.getLogger().error(ignore.getMessage());
|
||||||
|
} |
||||||
|
} |
||||||
|
if (creator == null) { |
||||||
|
FRContext.getLogger().error("Error to create xcreator!"); |
||||||
|
creator = new NullCreator(widget, d); |
||||||
|
} |
||||||
|
return creator; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
*刷新所有名字控件 |
||||||
|
* @param container 布局容器 |
||||||
|
*/ |
||||||
|
public static void refreshAllNameWidgets(XLayoutContainer container) { |
||||||
|
_refreshNameWidget(container); |
||||||
|
LayoutUtils.layoutRootContainer(container); |
||||||
|
} |
||||||
|
|
||||||
|
private static void _refreshNameWidget(XLayoutContainer container) { |
||||||
|
for (int i = 0, len = container.getXCreatorCount(); i < len; i++) { |
||||||
|
XCreator creator = container.getXCreator(i); |
||||||
|
if (creator instanceof XLayoutContainer) { |
||||||
|
_refreshNameWidget((XLayoutContainer) creator); |
||||||
|
} else if (creator instanceof XNameWidget) { |
||||||
|
((XNameWidget) creator).rebuild(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取焦点组件所在的顶层容器,不包括目标本身 |
||||||
|
* |
||||||
|
* @param creator 组件 |
||||||
|
* @return 返回父容器 |
||||||
|
*/ |
||||||
|
public static XLayoutContainer getParentXLayoutContainer(XCreator creator) { |
||||||
|
Container c = creator.getParent(); |
||||||
|
while (c != null) { |
||||||
|
XCreator crea = (XCreator) c; |
||||||
|
if (crea.isDedicateContainer()) { |
||||||
|
return (XLayoutContainer) c.getParent(); |
||||||
|
} |
||||||
|
if (c instanceof XLayoutContainer) { |
||||||
|
return (XLayoutContainer) c; |
||||||
|
} |
||||||
|
c = c.getParent(); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取焦点组件所在的顶层容器,可能是目标本身 |
||||||
|
* |
||||||
|
* @param creator 组件 |
||||||
|
* @return 返回顶层容器 |
||||||
|
*/ |
||||||
|
public static XLayoutContainer getHotspotContainer(XCreator creator) { |
||||||
|
if (creator.isDedicateContainer()) { |
||||||
|
return (XLayoutContainer) creator.getParent(); |
||||||
|
} |
||||||
|
if (creator instanceof XLayoutContainer) { |
||||||
|
return (XLayoutContainer) creator; |
||||||
|
} |
||||||
|
return getParentXLayoutContainer(creator); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件的图标 |
||||||
|
* |
||||||
|
* @param creator 组件 |
||||||
|
* @return 组件icon |
||||||
|
*/ |
||||||
|
public static Icon getCreatorIcon(XCreator creator) { |
||||||
|
String iconPath = creator.getIconPath(); |
||||||
|
if (StringUtils.isEmpty(iconPath)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
return IOUtils.readIcon(iconPath); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
package com.fr.design.designer.creator;
import com.fr.form.ui.WriteAbleRepeatEditor;
import com.fr.general.Inter;
import com.fr.stable.ArrayUtils;
import java.awt.*;
import java.beans.IntrospectionException;
/**
* Author : Shockway
* Date: 13-9-22
* Time: 上午10:40
*/
public abstract class XCustomWriteAbleRepeatEditor extends XWriteAbleRepeatEditor {
public XCustomWriteAbleRepeatEditor(WriteAbleRepeatEditor widget, Dimension initSize) {
super(widget, initSize);
}
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException {
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(),
new CRPropertyDescriptor[] { new CRPropertyDescriptor("customData",
this.data.getClass()).setI18NName(Inter.getLocText("Form-Allow_CustomData"))});
}
} |
@ -0,0 +1,94 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
import com.fr.design.mainframe.widget.editors.DataTableConfigPane; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
import com.fr.form.data.DataTableConfig; |
||||||
|
import com.fr.form.ui.DataTable; |
||||||
|
import com.fr.form.ui.WidgetValue; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.design.utils.gui.LayoutUtils; |
||||||
|
|
||||||
|
public class XDataTable extends XWidgetCreator{ |
||||||
|
|
||||||
|
private DesignerEditor<DataTableConfigPane> designerEditor; |
||||||
|
|
||||||
|
public XDataTable(DataTable widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "text_field_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[] { new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Widget", "Value"})).setEditorClass(WidgetValueEditor.class) |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
if (((DataTable) toData()).getWidgetValue() != null |
||||||
|
&& ((DataTable) toData()).getWidgetValue().getValue() instanceof DataTableConfig) { |
||||||
|
designerEditor.getEditorTarget().populate( |
||||||
|
(DataTableConfig) ((DataTable) toData()).getWidgetValue().getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
}) }); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
super.paint(g); |
||||||
|
designerEditor.paintEditor(g, this.getSize()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
designerEditor.getEditorTarget().setSize(this.getSize()); |
||||||
|
LayoutUtils.layoutContainer(designerEditor.getEditorTarget()); |
||||||
|
if (((DataTable) toData()).getWidgetValue() != null |
||||||
|
&& ((DataTable) toData()).getWidgetValue().getValue() instanceof DataTableConfig) { |
||||||
|
designerEditor.getEditorTarget().populate( |
||||||
|
(DataTableConfig) ((DataTable) toData()).getWidgetValue().getValue()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension initEditorSize() { |
||||||
|
return new Dimension(250, 100); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DesignerEditor<DataTableConfigPane> getDesignerEditor() { |
||||||
|
return designerEditor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (designerEditor == null) { |
||||||
|
final DataTableConfigPane configPane = new DataTableConfigPane(); |
||||||
|
designerEditor = new DesignerEditor<DataTableConfigPane>(configPane); |
||||||
|
configPane.addpropertyChangeListener(designerEditor); |
||||||
|
designerEditor.addStopEditingListener(new PropertyChangeAdapter() { |
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
((DataTable) toData()).setWidgetValue(new WidgetValue(configPane.update())); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,175 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.widget.editors.DateFormatEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.DateRangeEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.DateCellRenderer; |
||||||
|
import com.fr.form.ui.DateEditor; |
||||||
|
import com.fr.form.ui.WidgetValue; |
||||||
|
import com.fr.general.DateUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XDateEditor extends XDirectWriteEditor { |
||||||
|
|
||||||
|
private UITextField textField; |
||||||
|
private LimpidButton btn; |
||||||
|
|
||||||
|
public XDateEditor(DateEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 控件的属性列表 |
||||||
|
* @return 此控件所用的属性列表 |
||||||
|
* @throws IntrospectionException 异常 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"Widget", "Value"})).setEditorClass( |
||||||
|
WidgetValueEditor.class).setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
initFieldText(); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("formatText", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Engine_Format")).setEditorClass(formatClass()).setRendererClass( |
||||||
|
DateCellRenderer.class).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("startDate", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_Start-Date")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced").setEditorClass(DateRangeEditor.class), |
||||||
|
new CRPropertyDescriptor("endDate", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_End-Date")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced").setEditorClass(DateRangeEditor.class), |
||||||
|
new CRPropertyDescriptor("returnDate", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_Return-Date")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Return-Value"), |
||||||
|
new CRPropertyDescriptor("waterMark", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_WaterMark")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced") |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
protected Class formatClass() { |
||||||
|
return DateFormatEditor.class; |
||||||
|
} |
||||||
|
|
||||||
|
private void initFieldText() { |
||||||
|
DateEditor dateEditor = (DateEditor) data; |
||||||
|
if (dateEditor.getWidgetValue() != null) { |
||||||
|
WidgetValue widgetValue = dateEditor.getWidgetValue(); |
||||||
|
//控件值.toString
|
||||||
|
String valueStr = widgetValue.toString(); |
||||||
|
//控件值
|
||||||
|
Object value = widgetValue.getValue(); |
||||||
|
//格式
|
||||||
|
String format = dateEditor.getFormatText(); |
||||||
|
|
||||||
|
if(value instanceof Date){ |
||||||
|
valueStr = DateUtils.getDate2Str(format, (Date) value); |
||||||
|
} |
||||||
|
|
||||||
|
//日期控件默认值
|
||||||
|
if(StringUtils.isEmpty(valueStr)){ |
||||||
|
valueStr = DateUtils.getDate2Str(format, new Date()); |
||||||
|
dateEditor.setWidgetValue(new WidgetValue(new Date())); |
||||||
|
} |
||||||
|
|
||||||
|
textField.setText(valueStr); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
initFieldText(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
editor.add(textField = new UITextField(5), BorderLayout.CENTER); |
||||||
|
btn = new LimpidButton("", this.getIconPath(), toData().isVisible() ? FULL_OPACITY : HALF_OPACITY); |
||||||
|
btn.setPreferredSize(new Dimension(21, 21)); |
||||||
|
editor.add(btn, BorderLayout.EAST); |
||||||
|
textField.setOpaque(false); |
||||||
|
editor.setBackground(Color.WHITE); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "date_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
protected void makeVisible(boolean visible) { |
||||||
|
btn.makeVisible(visible); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取当前XCreator的一个封装父容器 |
||||||
|
* |
||||||
|
* @param widgetName 当前组件名 |
||||||
|
* |
||||||
|
* @return 封装的父容器 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:47:23 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected XLayoutContainer getCreatorWrapper(String widgetName){ |
||||||
|
return new XWScaleLayout(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将当前对象添加到父容器中 |
||||||
|
* |
||||||
|
* @param parentPanel 父容器组件 |
||||||
|
* |
||||||
|
* |
||||||
|
* @date 2014-11-25-下午4:57:55 |
||||||
|
* |
||||||
|
*/ |
||||||
|
protected void addToWrapper(XLayoutContainer parentPanel, int width, int minHeight){ |
||||||
|
this.setSize(width, minHeight); |
||||||
|
parentPanel.add(this); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 此控件在自适应布局要保持原样高度 |
||||||
|
* |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean shouldScaleCreator() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import com.fr.form.ui.DirectWriteEditor; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public abstract class XDirectWriteEditor extends XFieldEditor { |
||||||
|
|
||||||
|
public XDirectWriteEditor(DirectWriteEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[] { new CRPropertyDescriptor("directEdit", this.data.getClass()) |
||||||
|
.setI18NName(Inter.getLocText("Form-Allow_Edit")) }); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.designer.beans.AdapterBus; |
||||||
|
import com.fr.design.designer.beans.ComponentAdapter; |
||||||
|
import com.fr.design.designer.beans.events.DesignerEditor; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.xpane.ToolTipEditor; |
||||||
|
import com.fr.design.mainframe.EditingMouseListener; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.form.ui.EditorHolder; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.FocusEvent; |
||||||
|
import java.awt.event.FocusListener; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
|
||||||
|
public class XEditorHolder extends XWidgetCreator { |
||||||
|
|
||||||
|
private DesignerEditor<UILabel> designerEditor; |
||||||
|
private static Icon icon = BaseUtils.readIcon("/com/fr/design/images/form/designer/holder.png"); |
||||||
|
|
||||||
|
// public XEditorHolder(EditorHolder widget) {
|
||||||
|
// super(widget);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public XEditorHolder(EditorHolder widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应点击事件 |
||||||
|
* |
||||||
|
* @param editingMouseListener 事件处理器 |
||||||
|
* @param e 点击事件 |
||||||
|
* |
||||||
|
*/ |
||||||
|
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ |
||||||
|
|
||||||
|
FormDesigner designer = editingMouseListener.getDesigner(); |
||||||
|
if (editingMouseListener.stopEditing()) { |
||||||
|
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); |
||||||
|
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); |
||||||
|
Rectangle rect = this.getBounds(); |
||||||
|
int min = rect.x + rect.width / 2 - editingMouseListener.getMinMoveSize(); |
||||||
|
int max = rect.x + rect.width / 2 + editingMouseListener.getMinMoveSize(); |
||||||
|
if (e.getX() > min && e.getX() < max) { |
||||||
|
ToolTipEditor.getInstance().showToolTip((XEditorHolder) this, e.getXOnScreen(), |
||||||
|
e.getYOnScreen()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "text_field_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DesignerEditor<UILabel> getDesignerEditor() { |
||||||
|
if (designerEditor == null) { |
||||||
|
UILabel comp = new UILabel(icon); |
||||||
|
designerEditor = new DesignerEditor<UILabel>(comp); |
||||||
|
|
||||||
|
comp.addFocusListener(new FocusListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void focusGained(FocusEvent e) { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void focusLost(FocusEvent e) { |
||||||
|
ToolTipEditor.getInstance().hideToolTip(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
comp.setBorder(BorderFactory.createLineBorder(new Color(128, 152, 186))); |
||||||
|
|
||||||
|
} |
||||||
|
return designerEditor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = new UILabel(icon); |
||||||
|
editor.setBorder(BorderFactory.createLineBorder(new Color(128, 152, 186))); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,235 @@ |
|||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.design.fun.FormElementCaseEditorProcessor; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.mainframe.CoverReportPane; |
||||||
|
import com.fr.design.mainframe.EditingMouseListener; |
||||||
|
import com.fr.design.mainframe.FormDesigner; |
||||||
|
import com.fr.design.mainframe.widget.editors.BooleanEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer; |
||||||
|
import com.fr.design.mainframe.widget.renderer.PaddingMarginCellRenderer; |
||||||
|
import com.fr.form.FormElementCaseContainerProvider; |
||||||
|
import com.fr.form.FormElementCaseProvider; |
||||||
|
import com.fr.form.ui.ElementCaseEditor; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
import java.beans.PropertyDescriptor; |
||||||
|
|
||||||
|
public class XElementCase extends XBorderStyleWidgetCreator implements FormElementCaseContainerProvider{ |
||||||
|
private UILabel imageLable; |
||||||
|
private JPanel coverPanel; |
||||||
|
|
||||||
|
public XElementCase(ElementCaseEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
// 报表块初始化时要加载对应的borderStyle
|
||||||
|
initBorderStyle(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否支持设置标题 |
||||||
|
* @return 是返回true |
||||||
|
*/ |
||||||
|
public boolean hasTitleStyle() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件属性值 |
||||||
|
* @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("borderStyle", this.data.getClass()).setEditorClass( |
||||||
|
WLayoutBorderStyleEditor.class).setRendererClass(LayoutBorderStyleRenderer.class).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer-Widget_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
initStyle(); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("margin", this.data.getClass()).setEditorClass(PaddingMarginEditor.class) |
||||||
|
.setRendererClass(PaddingMarginCellRenderer.class).setI18NName(Inter.getLocText("FR-Layout_Padding")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("showToolBar", this.data.getClass()).setEditorClass(BooleanEditor.class) |
||||||
|
.setI18NName(Inter.getLocText("Form-EC_toolbar")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
FormElementCaseEditorProcessor processor = ExtraDesignClassManager.getInstance().getPropertyTableEditor(); |
||||||
|
if (processor == null){ |
||||||
|
return propertyTableEditor; |
||||||
|
} |
||||||
|
PropertyDescriptor[] extraEditor = processor.createPropertyDescriptor(this.data.getClass()); |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(propertyTableEditor, extraEditor); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "text_field_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件默认名 |
||||||
|
* @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); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 从data中获取到图片背景, 并设置到Label上 |
||||||
|
*/ |
||||||
|
private UILabel initImageBackground(){ |
||||||
|
UILabel imageLable = new UILabel(); |
||||||
|
BufferedImage image = toData().getECImage(); |
||||||
|
setLabelBackground(image, imageLable); |
||||||
|
|
||||||
|
return imageLable; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置指定Label的背景 |
||||||
|
*/ |
||||||
|
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()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否展现覆盖的pane |
||||||
|
* @param display 是否 |
||||||
|
*/ |
||||||
|
public void displayCoverPane(boolean display){ |
||||||
|
coverPanel.setVisible(display); |
||||||
|
coverPanel.setPreferredSize(editor.getPreferredSize()); |
||||||
|
coverPanel.setBounds(editor.getBounds()); |
||||||
|
editor.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
public JComponent getCoverPane(){ |
||||||
|
return coverPanel; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 初始化大小 |
||||||
|
* @return 尺寸 |
||||||
|
*/ |
||||||
|
public Dimension initEditorSize() { |
||||||
|
return new Dimension(250, 100); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否是报表块 |
||||||
|
* @return 是 |
||||||
|
*/ |
||||||
|
public boolean isReport() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖入参数面板 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean canEnterIntoParaPane(){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回报表块对应的widget |
||||||
|
* @return 返回ElementCaseEditor |
||||||
|
*/ |
||||||
|
public ElementCaseEditor toData() { |
||||||
|
return ((ElementCaseEditor) data); |
||||||
|
} |
||||||
|
|
||||||
|
public FormElementCaseProvider getElementCase() { |
||||||
|
return toData().getElementCase(); |
||||||
|
} |
||||||
|
|
||||||
|
public String getElementCaseContainerName() { |
||||||
|
return toData().getWidgetName(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setElementCase(FormElementCaseProvider el) { |
||||||
|
toData().setElementCase(el); |
||||||
|
} |
||||||
|
|
||||||
|
public void setBackground(BufferedImage image){ |
||||||
|
toData().setECImage(image); |
||||||
|
setEditorIcon(image); |
||||||
|
} |
||||||
|
|
||||||
|
private void setEditorIcon(BufferedImage image){ |
||||||
|
setLabelBackground(image, imageLable); |
||||||
|
} |
||||||
|
|
||||||
|
public Dimension getSize(){ |
||||||
|
return new Dimension(this.getWidth(), this.getHeight()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应点击事件 |
||||||
|
* @param editingMouseListener 事件处理器 |
||||||
|
* @param e 点击事件 |
||||||
|
*/ |
||||||
|
public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ |
||||||
|
super.respondClick(editingMouseListener, e); |
||||||
|
switchTab(e,editingMouseListener); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.border.Border; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.widget.editors.InChangeBooleanEditor; |
||||||
|
import com.fr.form.ui.FieldEditor; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public abstract class XFieldEditor extends XWidgetCreator { |
||||||
|
|
||||||
|
protected static final Border FIELDBORDER = BorderFactory.createLineBorder(new Color(128, 152, 186), 1); |
||||||
|
|
||||||
|
public XFieldEditor(FieldEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll( |
||||||
|
super.supportedDescriptor(),getCRPropertyDescriptor() |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
private CRPropertyDescriptor[] getCRPropertyDescriptor() throws IntrospectionException { |
||||||
|
CRPropertyDescriptor allowBlank = new CRPropertyDescriptor("allowBlank", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Allow_Blank")).setEditorClass(InChangeBooleanEditor.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"); |
||||||
|
CRPropertyDescriptor blankErrorMsg = new CRPropertyDescriptor("errorMessage", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Verify-Message")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"); |
||||||
|
CRPropertyDescriptor fontSize = new CRPropertyDescriptor("fontSize", this.data.getClass(), "getFontSize", "setFontSize") |
||||||
|
.setI18NName(Inter.getLocText(new String[]{"FRFont", "FRFont-Size"})) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced"); |
||||||
|
return !((FieldEditor) toData()).isAllowBlank() ? |
||||||
|
new CRPropertyDescriptor[] {allowBlank, blankErrorMsg, fontSize} |
||||||
|
: new CRPropertyDescriptor[] {allowBlank, fontSize}; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
|
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.form.ui.FileEditor; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XFileUploader extends XFieldEditor { |
||||||
|
|
||||||
|
public XFileUploader(FileEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll( |
||||||
|
super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[]{ |
||||||
|
new CRPropertyDescriptor("allowTypes", this.data.getClass()) |
||||||
|
.setI18NName(Inter.getLocText("File-Allow_Upload_Files")) |
||||||
|
.putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Advanced") |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
UITextField textField = new UITextField(10); |
||||||
|
editor.add(textField, BorderLayout.CENTER); |
||||||
|
UIButton btn = new UIButton("..."); |
||||||
|
btn.setPreferredSize(new Dimension(24, 24)); |
||||||
|
editor.add(btn, BorderLayout.EAST); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "file_up.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,101 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPanel; |
||||||
|
|
||||||
|
import com.fr.stable.core.PropertyChangeAdapter; |
||||||
|
import com.fr.design.gui.itextfield.UITextField; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.mainframe.widget.editors.ParameterEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.ParameterRenderer; |
||||||
|
import com.fr.form.ui.IframeEditor; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XIframeEditor extends XWidgetCreator { |
||||||
|
|
||||||
|
public XIframeEditor(IframeEditor widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("src", this.data.getClass()).setI18NName(Inter.getLocText("Form-Url")) |
||||||
|
.setPropertyChangeListener(new PropertyChangeAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void propertyChange() { |
||||||
|
initFieldText(); |
||||||
|
} |
||||||
|
}), |
||||||
|
new CRPropertyDescriptor("overflowx", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Preference-Horizontal_Scroll_Bar_Visible")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("overflowy", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("Preference-Vertical_Scroll_Bar_Visible")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("parameters", this.data.getClass()) |
||||||
|
.setI18NName(Inter.getLocText("Parameters")).setEditorClass(ParameterEditor.class) |
||||||
|
.setRendererClass(ParameterRenderer.class).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, |
||||||
|
"Advanced") }); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
UITextField address = new UITextField(); |
||||||
|
editor.add(address, BorderLayout.NORTH); |
||||||
|
JPanel contentPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
||||||
|
contentPane.setBackground(Color.white); |
||||||
|
editor.add(contentPane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
private void initFieldText() { |
||||||
|
IframeEditor iframe = (IframeEditor) data; |
||||||
|
String src = iframe.getSrc(); |
||||||
|
((UITextField) editor.getComponent(0)).setText(StringUtils.isNotEmpty(src) ? src : "http://ip:port/address?"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
initFieldText(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension initEditorSize() { |
||||||
|
return new Dimension(160, 80); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 该组件是否可以拖入参数面板 |
||||||
|
* 这里控制 网页预定义控件在工具栏不显示 |
||||||
|
* @return 是则返回true |
||||||
|
*/ |
||||||
|
public boolean canEnterIntoParaPane(){ |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "iframe_16.png"; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,120 @@ |
|||||||
|
/* |
||||||
|
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
||||||
|
*/ |
||||||
|
package com.fr.design.designer.creator; |
||||||
|
|
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.geom.Rectangle2D; |
||||||
|
import java.beans.IntrospectionException; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.SwingConstants; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.base.ScreenResolution; |
||||||
|
import com.fr.base.Style; |
||||||
|
import com.fr.design.border.UIRoundedBorder; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.mainframe.widget.editors.FontEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.ItemCellEditor; |
||||||
|
import com.fr.design.mainframe.widget.editors.WidgetValueEditor; |
||||||
|
import com.fr.design.mainframe.widget.renderer.FontCellRenderer; |
||||||
|
import com.fr.design.mainframe.widget.renderer.LabelHorizontalAlignmentRenderer; |
||||||
|
import com.fr.form.ui.Label; |
||||||
|
import com.fr.design.form.util.XCreatorConstants; |
||||||
|
import com.fr.general.Inter; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richer |
||||||
|
* @since 6.5.3 |
||||||
|
*/ |
||||||
|
public class XLabel extends XWidgetCreator { |
||||||
|
|
||||||
|
private int cornerSize = 15; |
||||||
|
|
||||||
|
public XLabel(Label widget, Dimension initSize) { |
||||||
|
super(widget, initSize); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成creator对应的控件widget |
||||||
|
* @return 控件widget |
||||||
|
*/ |
||||||
|
public Label toData() { |
||||||
|
return (Label) data; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 返回组件属性值 |
||||||
|
* @return 返回组件属性值 |
||||||
|
* @throws IntrospectionException 异常 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { |
||||||
|
return (CRPropertyDescriptor[]) ArrayUtils.addAll(super.supportedDescriptor(), |
||||||
|
new CRPropertyDescriptor[] { |
||||||
|
new CRPropertyDescriptor("widgetValue", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText(new String[]{"FR-Designer_Widget", "Value"})).setEditorClass( |
||||||
|
WidgetValueEditor.class), |
||||||
|
new CRPropertyDescriptor("wrap", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_StyleAlignment-Wrap_Text")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("verticalCenter", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_PageSetup-Vertically")).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("textalign", this.data.getClass()).setI18NName( |
||||||
|
Inter.getLocText("FR-Designer_Alignment-Style")).setEditorClass(ItemCellEditor.class) |
||||||
|
.setRendererClass(LabelHorizontalAlignmentRenderer.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced"), |
||||||
|
new CRPropertyDescriptor("font", this.data.getClass()).setI18NName(Inter.getLocText("FR-Designer_Font")) |
||||||
|
.setEditorClass(FontEditor.class).setRendererClass(FontCellRenderer.class).putKeyValue( |
||||||
|
XCreatorConstants.PROPERTY_CATEGORY, "Advanced") }); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paintComponent(Graphics g) { |
||||||
|
super.paintComponent(g); |
||||||
|
Label label = (Label) data; |
||||||
|
Dimension size = this.getSize(); |
||||||
|
//先画背景,再画标题
|
||||||
|
if (toData().getBackground() != null) { |
||||||
|
toData().getBackground().paint(g,new Rectangle2D.Double(0, 0, size.getWidth(), size.getHeight())); |
||||||
|
} |
||||||
|
if (label.getWidgetValue() != null) { |
||||||
|
Graphics2D g2d = (Graphics2D) g.create(); |
||||||
|
BaseUtils.drawStringStyleInRotation(g2d, this.getWidth(), this.getHeight(), label.getWidgetValue() |
||||||
|
.toString(), Style.getInstance(label.getFont()).deriveHorizontalAlignment(label.getTextalign()) |
||||||
|
.deriveVerticalAlignment(label.isVerticalCenter() ? SwingConstants.CENTER : SwingConstants.TOP) |
||||||
|
.deriveTextStyle(label.isWrap() ? Style.TEXTSTYLE_WRAPTEXT : Style.TEXTSTYLE_SINGLELINE), |
||||||
|
ScreenResolution.getScreenResolution()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent initEditor() { |
||||||
|
if (editor == null) { |
||||||
|
editor = new UILabel(); |
||||||
|
} |
||||||
|
return editor; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void initXCreatorProperties() { |
||||||
|
super.initXCreatorProperties(); |
||||||
|
if (toData().getBorder() != Constants.LINE_NONE) { |
||||||
|
this.setBorder(new UIRoundedBorder(toData().getBorder(), toData().getColor(), toData().isCorner() ? cornerSize : 0)); |
||||||
|
} else { |
||||||
|
this.setBorder(DEFALUTBORDER); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String getIconName() { |
||||||
|
return "label_16.png"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue