Browse Source

无任务 代码调整

master
yaoh.wu 8 years ago
parent
commit
2715c3c598
  1. 70
      designer_base/src/com/fr/design/actions/edit/CopyAction.java
  2. 2
      designer_base/src/com/fr/design/beans/location/MoveUtils.java
  3. 73
      designer_base/src/com/fr/design/parameter/ParameterDesignerProvider.java
  4. 303
      designer_base/src/com/fr/design/utils/ComponentUtils.java
  5. 186
      designer_form/src/com/fr/design/designer/beans/LayoutAdapter.java
  6. 59
      designer_form/src/com/fr/design/designer/beans/actions/CopyAction.java
  7. 376
      designer_form/src/com/fr/design/designer/beans/adapters/layout/AbstractLayoutAdapter.java
  8. 710
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java
  9. 2386
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java
  10. 209
      designer_form/src/com/fr/design/designer/beans/adapters/layout/FRTabFitLayoutAdapter.java
  11. 327
      designer_form/src/com/fr/design/designer/beans/location/AccessDirection.java
  12. 92
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  13. 190
      designer_form/src/com/fr/design/designer/creator/DedicateLayoutContainer.java
  14. 12
      designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java
  15. 170
      designer_form/src/com/fr/design/mainframe/ConnectorHelper.java
  16. 1239
      designer_form/src/com/fr/design/mainframe/EditingMouseListener.java
  17. 23
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  18. 6
      designer_form/src/com/fr/design/mainframe/FormSelectionUtils.java
  19. 1581
      designer_form/src/com/fr/design/mainframe/JForm.java
  20. 693
      designer_form/src/com/fr/design/mainframe/MobileWidgetTable.java
  21. 742
      designer_form/src/com/fr/design/mainframe/WidgetPropertyPane.java

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

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

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

@ -18,7 +18,7 @@ public class MoveUtils {
public static final int SORPTION_UNIT = 5; public static final int SORPTION_UNIT = 5;
private static final int EQUIDISTANTLINE_UNIT = 4; private static final int EQUIDISTANTLINE_UNIT = 4;
public static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>(); private static ArrayList<EquidistantLine> equidistantLines = new ArrayList<>();
private MoveUtils() { private MoveUtils() {

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

@ -1 +1,72 @@
package com.fr.design.parameter; import com.fr.base.Parameter; import com.fr.base.parameter.ParameterUI; import com.fr.design.mainframe.AuthorityEditPane; import javax.swing.*; import java.awt.*; /** * 参数设计界面接口 */ public interface ParameterDesignerProvider { void addListener(ParaDefinitePane paraDefinitePane); Component createWrapper(); void setDesignHeight(int height); Dimension getDesignSize(); Dimension getPreferredSize(); void populate(ParameterUI p); void refreshAllNameWidgets(); void refresh4TableData(String oldName, String newName); void refreshParameter(ParaDefinitePane paraDefinitePane); boolean isWithQueryButton(); java.util.List<String> getAllXCreatorNameList(); boolean isWithoutParaXCreator(Parameter[] ps); boolean isBlank(); ParameterUI getParaTarget(); boolean addingParameter2Editor(Parameter parameter, int index); boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index); void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex); JPanel[] toolbarPanes4Form(); JComponent[] toolBarButton4Form(); void initBeforeUpEdit(); void populateParameterPropertyPane(ParaDefinitePane p); void initWidgetToolbarPane(); AuthorityEditPane getAuthorityEditPane(); JPanel getEastUpPane(); JPanel getEastDownPane(); boolean isSupportAuthority(); void removeSelection(); ParameterBridge getParaComponent(); } package com.fr.design.parameter;
import com.fr.base.Parameter;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.mainframe.AuthorityEditPane;
import javax.swing.*;
import java.awt.*;
/**
* 参数设计界面接口
*/
public interface ParameterDesignerProvider {
void addListener(ParaDefinitePane paraDefinitePane);
Component createWrapper();
void setDesignHeight(int height);
Dimension getDesignSize();
Dimension getPreferredSize();
void populate(ParameterUI p);
void refreshAllNameWidgets();
void refresh4TableData(String oldName, String newName);
void refreshParameter(ParaDefinitePane paraDefinitePane);
boolean isWithQueryButton();
java.util.List<String> getAllXCreatorNameList();
boolean isWithoutParaXCreator(Parameter[] ps);
boolean isBlank();
ParameterUI getParaTarget();
boolean addingParameter2Editor(Parameter parameter, int index);
boolean addingParameter2EditorWithQueryButton(Parameter parameter, int index);
void addingAllParameter2Editor(Parameter[] parameterArray, int currentIndex);
JPanel[] toolbarPanes4Form();
JComponent[] toolBarButton4Form();
void initBeforeUpEdit();
void populateParameterPropertyPane(ParaDefinitePane p);
void initWidgetToolbarPane();
AuthorityEditPane getAuthorityEditPane();
JPanel getEastUpPane();
JPanel getEastDownPane();
boolean isSupportAuthority();
void removeSelection();
ParameterBridge getParaComponent();
}

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

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

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

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

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

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

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

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

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

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

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

File diff suppressed because it is too large Load Diff

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

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

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

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

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

@ -1,11 +1,5 @@
package com.fr.design.designer.beans.models; package com.fr.design.designer.beans.models;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.designer.beans.events.DesignerEvent;
@ -20,9 +14,12 @@ import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelection;
import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.mainframe.FormSelectionUtils;
import com.fr.design.utils.gui.LayoutUtils; import com.fr.design.utils.gui.LayoutUtils;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/** /**
* 该model保存当前选择的组件和剪切版信息 * 该model保存当前选择的组件和剪切版信息
*/ */
@ -30,10 +27,10 @@ public class SelectionModel {
//被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。 //被粘贴组件在所选组件位置处往下、往右各错开20像素。执行多次粘贴时,在上一次粘贴的位置处错开20像素。
private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离 private static final int DELTA_X_Y = 20; //粘贴时候的偏移距离
private static final int BORDER_PROPORTION = 20; private static final int BORDER_PROPORTION = 20;
private static FormSelection CLIP_BOARD = new FormSelection(); private static FormSelection clipboard = new FormSelection();
private FormDesigner designer; private FormDesigner designer;
private FormSelection selection; private FormSelection selection;
private Rectangle hotspot_bounds; private Rectangle hotspotBounds;
public SelectionModel(FormDesigner designer) { public SelectionModel(FormDesigner designer) {
this.designer = designer; this.designer = designer;
@ -45,7 +42,7 @@ public class SelectionModel {
*/ */
public void reset() { public void reset() {
selection.reset(); selection.reset();
hotspot_bounds = null; hotspotBounds = null;
} }
/** /**
@ -54,7 +51,7 @@ public class SelectionModel {
* @return 是否为空 * @return 是否为空
*/ */
public static boolean isEmpty() { public static boolean isEmpty() {
return CLIP_BOARD.isEmpty(); return clipboard.isEmpty();
} }
/** /**
@ -67,7 +64,6 @@ public class SelectionModel {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件 // 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset(); selection.reset();
} }
// 获取e所在的组件 // 获取e所在的组件
XCreator comp = designer.getComponentAt(e); XCreator comp = designer.getComponentAt(e);
@ -93,7 +89,7 @@ public class SelectionModel {
*/ */
public void cutSelectedCreator2ClipBoard() { public void cutSelectedCreator2ClipBoard() {
if (hasSelectionComponent()) { if (hasSelectionComponent()) {
selection.cut2ClipBoard(CLIP_BOARD); selection.cut2ClipBoard(clipboard);
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED); designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_CUTED);
designer.repaint(); designer.repaint();
} }
@ -104,7 +100,7 @@ public class SelectionModel {
*/ */
public void copySelectedCreator2ClipBoard() { public void copySelectedCreator2ClipBoard() {
if (!selection.isEmpty()) { if (!selection.isEmpty()) {
selection.copy2ClipBoard(CLIP_BOARD); selection.copy2ClipBoard(clipboard);
} }
} }
@ -114,7 +110,7 @@ public class SelectionModel {
* @return * @return
*/ */
public boolean pasteFromClipBoard() { public boolean pasteFromClipBoard() {
if (!CLIP_BOARD.isEmpty()) { if (!clipboard.isEmpty()) {
XLayoutContainer parent = null; XLayoutContainer parent = null;
//未选 //未选
if (!hasSelectionComponent()) { if (!hasSelectionComponent()) {
@ -124,14 +120,14 @@ public class SelectionModel {
Rectangle rec = selection.getRelativeBounds(); Rectangle rec = selection.getRelativeBounds();
//Tab布局 //Tab布局
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD, clipboard,
rec.x + rec.width / 2, rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION); rec.y + BORDER_PROPORTION);
} else { } else {
Rectangle rec = selection.getRelativeBounds(); Rectangle rec = selection.getRelativeBounds();
//自适应布局 //自适应布局
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
CLIP_BOARD, clipboard,
rec.x + rec.width / 2, rec.x + rec.width / 2,
rec.y + BORDER_PROPORTION); rec.y + BORDER_PROPORTION);
} }
@ -140,7 +136,7 @@ public class SelectionModel {
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
//当前选择的就是编辑器表层 //当前选择的就是编辑器表层
FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(), FormSelectionUtils.paste2Container(designer, (XLayoutContainer) selection.getSelectedCreator(),
CLIP_BOARD, clipboard,
DELTA_X_Y, DELTA_X_Y,
DELTA_X_Y); DELTA_X_Y);
} }
@ -148,7 +144,7 @@ public class SelectionModel {
//cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到 //cpt本地组件复用,编辑器就一层,是最底层,使用designer.getRootComponent()就可以获取到
//使用selection.getSelectedCreator()也应该是可以获取到的。 //使用selection.getSelectedCreator()也应该是可以获取到的。
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(), FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
CLIP_BOARD, clipboard,
DELTA_X_Y, DELTA_X_Y,
DELTA_X_Y); DELTA_X_Y);
} }
@ -157,19 +153,16 @@ public class SelectionModel {
else { else {
//获取到编辑器的表层容器(已选的组件的父容器就是表层容器) //获取到编辑器的表层容器(已选的组件的父容器就是表层容器)
parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator()); parent = XCreatorUtils.getParentXLayoutContainer(selection.getSelectedCreator());
if (selection.getSelectedCreator().getParent() instanceof XWFitLayout) { if (parent != null && selection.getSelectedCreator().getParent() instanceof XWFitLayout) {
//自适应布局 //自适应布局
if (parent != null) { Rectangle rec = selection.getRelativeBounds();
Rectangle rec = selection.getRelativeBounds(); FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + rec.width / 2, rec.y +
FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + rec.width / 2, rec.y + rec.height - BORDER_PROPORTION);
rec.height - BORDER_PROPORTION);
} } else if (parent != null && selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
} else if (selection.getSelectedCreator().getParent() instanceof XWAbsoluteLayout) {
//绝对布局 //绝对布局
if (parent != null) { Rectangle rec = selection.getSelctionBounds();
Rectangle rec = selection.getSelctionBounds(); FormSelectionUtils.paste2Container(designer, parent, clipboard, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
FormSelectionUtils.paste2Container(designer, parent, CLIP_BOARD, rec.x + DELTA_X_Y, rec.y + DELTA_X_Y);
}
} }
} }
} else { } else {
@ -223,14 +216,14 @@ public class SelectionModel {
* 设置选择区域 * 设置选择区域
*/ */
public void setHotspotBounds(Rectangle rect) { public void setHotspotBounds(Rectangle rect) {
hotspot_bounds = rect; hotspotBounds = rect;
} }
/** /**
* 获得当前选择区域 * 获得当前选择区域
*/ */
public Rectangle getHotspotBounds() { public Rectangle getHotspotBounds() {
return hotspot_bounds; return hotspotBounds;
} }
private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) { private void removeCreatorFromContainer(XCreator creator, int creatorWidth, int creatorHeight) {
@ -271,22 +264,28 @@ public class SelectionModel {
* 其他两层不是靠添加组件就可以编辑的 * 其他两层不是靠添加组件就可以编辑的
*/ */
public boolean hasSelectionComponent() { public boolean hasSelectionComponent() {
XCreator selectionXCreator = selection.getSelectedCreator();
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
//frm本地组件复用 //frm本地组件复用
return selection.getSelectedCreator() != null if (selectionXCreator != null) {
&& !( if (selectionXCreator.getClass().equals(XWAbsoluteBodyLayout.class)) {
//frm绝对布局编辑器 //frm绝对布局编辑器
selection.getSelectedCreator().getClass().equals(XWAbsoluteBodyLayout.class) return false;
//Tab布局编辑器 } else if (selectionXCreator.getClass().equals(XWCardMainBorderLayout.class)
|| selection.getSelectedCreator().getClass().equals(XWCardMainBorderLayout.class) || selectionXCreator.getClass().equals(XWCardLayout.class)
|| selection.getSelectedCreator().getClass().equals(XWCardLayout.class) || selectionXCreator.getClass().equals(XWTabFitLayout.class)) {
|| selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class) //Tab布局编辑器
//自适应布局编辑器 return false;
|| selection.getSelectedCreator().getClass().equals(XWFitLayout.class) } else {
); //自适应布局编辑器
return !selectionXCreator.getClass().equals(XWFitLayout.class);
}
} else {
return false;
}
} else { } else {
//cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout //cpt本地组件复用,selection.getSelectedCreator().getParent()=@XWParameterLayout instanceof @XWAbsoluteLayout
return selection.getSelectedCreator() != null && selection.getSelectedCreator().getParent() != null; return selectionXCreator != null && selectionXCreator.getParent() != null;
} }
} }
@ -330,10 +329,9 @@ public class SelectionModel {
int x = e.getX() + designer.getArea().getHorizontalValue(); int x = e.getX() + designer.getArea().getHorizontalValue();
int y = e.getY() + designer.getArea().getVerticalValue(); int y = e.getY() + designer.getArea().getVerticalValue();
dir = getDirection(selection.getRelativeBounds(), x, y); dir = getDirection(selection.getRelativeBounds(), x, y);
if (selection.size() == 1) { if (selection.size() == 1 && !ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir
if (!ArrayUtils.contains(selection.getSelectedCreator().getDirections(), dir.getActual())) { .getActual())) {
dir = Location.outer; dir = Location.outer;
}
} }
} else { } else {
dir = Location.outer; dir = Location.outer;

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

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

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

@ -313,7 +313,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
*/ */
public boolean isWithQueryButton() { public boolean isWithQueryButton() {
XLayoutContainer rootContainer = this.getRootComponent(); XLayoutContainer rootContainer = this.getRootComponent();
return SearchQueryCreators(rootContainer); return searchQueryCreators(rootContainer);
} }
/** /**
@ -322,18 +322,18 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
* @return 同上 * @return 同上
*/ */
public Action[] getActions() { public Action[] getActions() {
if (designer_actions == null) { if (designerActions == null) {
designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)}; new FormDeleteAction(this)};
} }
return designer_actions; return designerActions;
} }
private boolean SearchQueryCreators(XLayoutContainer rootContainer) { private boolean searchQueryCreators(XLayoutContainer rootContainer) {
boolean b = false; boolean b = false;
for (int i = 0; i < rootContainer.getXCreatorCount(); i++) { for (int i = 0; i < rootContainer.getXCreatorCount(); i++) {
if (rootContainer.getXCreator(i) instanceof XLayoutContainer) { if (rootContainer.getXCreator(i) instanceof XLayoutContainer) {
b = SearchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i)); b = searchQueryCreators((XLayoutContainer) rootContainer.getXCreator(i));
} else if (rootContainer.getXCreator(i) instanceof XFormSubmit) { } else if (rootContainer.getXCreator(i) instanceof XFormSubmit) {
b = true; b = true;
} }

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

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

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

File diff suppressed because it is too large Load Diff

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

@ -46,7 +46,6 @@ import com.fr.form.ui.container.WFitLayout;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.plugin.ExtraClassManager;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.bridge.StableFactory; import com.fr.stable.bridge.StableFactory;
@ -72,7 +71,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
protected static final ArrayList<String> NAME_ARRAY_LIST = new ArrayList<String>( protected static final ArrayList<String> NAME_ARRAY_LIST = new ArrayList<String>(
Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")}) Arrays.asList(new String[]{Inter.getLocText("M_Edit-Cut"), Inter.getLocText("M_Edit-Copy"), Inter.getLocText("M_Edit-Delete")})
); );
private static final int BORDER_WIDTH = 6;
//底层容器的默认大小 //底层容器的默认大小
protected static final Dimension LARGE_PREFERRED_SIZE = new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT); protected static final Dimension LARGE_PREFERRED_SIZE = new Dimension(WBorderLayout.DEFAULT_WIDTH, WBorderLayout.DEFAULT_HEIGHT);
private int paraHeight = 0; private int paraHeight = 0;
@ -84,7 +82,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
private XLayoutContainer paraComponent; private XLayoutContainer paraComponent;
private boolean drawLineMode; private boolean drawLineMode;
private FormArea formArea; private FormArea formArea;
private ConnectorHelper ConnectorHelper; private ConnectorHelper connectorHelper;
private boolean isReportBlockEditing = false; private boolean isReportBlockEditing = false;
//组件重叠 //组件重叠
@ -107,7 +105,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
// 编辑状态的事件表 // 编辑状态的事件表
private CreatorEventListenerTable edit; private CreatorEventListenerTable edit;
protected Action[] designer_actions; protected Action[] designerActions;
private FormDesignerModeForSpecial<?> desigerMode; private FormDesignerModeForSpecial<?> desigerMode;
private Action switchAction; private Action switchAction;
private FormElementCaseContainerProvider elementCaseContainer; private FormElementCaseContainerProvider elementCaseContainer;
@ -763,12 +761,9 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @param e 鼠标事件 * @param e 鼠标事件
*/ */
public void updateDrawLineMode(MouseEvent e) { public void updateDrawLineMode(MouseEvent e) {
Point p = ConnectorHelper.getNearWidgetPoint(e); Point p = connectorHelper.getNearWidgetPoint(e);
if (p == null) { if (p == null && getComponentAt(e) == rootComponent) {
XComponent comp = getComponentAt(e); p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
if (comp == rootComponent) {
p = new Point(e.getX() + formArea.getHorizontalValue(), e.getY() + formArea.getVerticalValue());
}
} }
stateModel.startDrawLine(p); stateModel.startDrawLine(p);
} }
@ -1120,11 +1115,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @return 同上 * @return 同上
*/ */
public Action[] getActions() { public Action[] getActions() {
if (designer_actions == null) { if (designerActions == null) {
designer_actions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this), designerActions = new Action[]{new CutAction(this), new CopyAction(this), new PasteAction(this),
new FormDeleteAction(this)}; new FormDeleteAction(this)};
} }
return designer_actions; return designerActions;
} }
protected Border getOuterBorder() { protected Border getOuterBorder() {
@ -1191,7 +1186,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @return ConnectorHelper类 * @return ConnectorHelper类
*/ */
public ConnectorHelper getDrawLineHelper() { public ConnectorHelper getDrawLineHelper() {
return ConnectorHelper; return connectorHelper;
} }
/** /**

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

@ -204,14 +204,14 @@ public class FormSelectionUtils {
private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget, private static ArrayList<XCreator> rebuildSelection(XCreator rootComponent, List<Widget> selectionWidget,
ArrayList<XCreator> newSelection) { ArrayList<XCreator> newSelection) {
FormSelectionUtils._rebuild(rootComponent, selectionWidget, newSelection); FormSelectionUtils.rebuild(rootComponent, selectionWidget, newSelection);
if (newSelection.isEmpty()) { if (newSelection.isEmpty()) {
newSelection.add(rootComponent); newSelection.add(rootComponent);
} }
return newSelection; return newSelection;
} }
private static void _rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) { private static void rebuild(XCreator root, List<Widget> selectionWidget, List<XCreator> newSelection) {
if (selectionWidget.isEmpty()) { if (selectionWidget.isEmpty()) {
return; return;
} }
@ -238,7 +238,7 @@ public class FormSelectionUtils {
} }
} }
if (c instanceof XLayoutContainer) { if (c instanceof XLayoutContainer) {
_rebuild((XLayoutContainer) c, selectionWidget, newSelection); rebuild((XLayoutContainer) c, selectionWidget, newSelection);
} }
} }
} }

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

File diff suppressed because it is too large Load Diff

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

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

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

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