Browse Source

REPORT-4883 代码规范

master
plough 7 years ago
parent
commit
8a9a1d7e73
  1. 23
      designer/src/com/fr/design/parameter/ParameterDefinitePane.java
  2. 150
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java
  3. 16
      designer_form/src/com/fr/design/form/parameter/FormParaDesigner.java
  4. 8
      designer_form/src/com/fr/design/mainframe/FormDesigner.java
  5. 14
      designer_form/src/com/fr/design/parameter/ParameterToolBarPane.java

23
designer/src/com/fr/design/parameter/ParameterDefinitePane.java

@ -75,12 +75,23 @@ public class ParameterDefinitePane extends JPanel implements ToolBarMenuDockPlus
this.setBorder(null); this.setBorder(null);
this.setLayout(FRGUIPaneFactory.createBorderLayout()); this.setLayout(FRGUIPaneFactory.createBorderLayout());
setComponentBg(this); setComponentBg(this);
// formParaDesignEditor = new FormParaDesigner(new FormParameterUI());
paraDesignEditor = DesignModuleFactory.getFormParaDesigner(); paraDesignEditor = DesignModuleFactory.getFormParaDesigner();
if (paraDesignEditor == null) { if (paraDesignEditor == null) {
return; return;
} }
paraDesignEditor.initWidgetToolbarPane(); paraDesignEditor.initWidgetToolbarPane();
this.add(paraDesignEditor.createWrapper(), BorderLayout.CENTER);
setButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/toolbarbtn/parametersetting.png"));
setButton.set4ToolbarButton();
isshowWindowItem = new JCheckBoxMenuItem(Inter.getLocText("ParameterD-Show_Parameter_Window"));
isdelayItem = new JCheckBoxMenuItem(Inter.getLocText("ParameterD-Delay_Playing"));
initListeners();
}
private void initListeners() {
((TargetComponent) paraDesignEditor).addTargetModifiedListener(new TargetModifiedListener() { ((TargetComponent) paraDesignEditor).addTargetModifiedListener(new TargetModifiedListener() {
@Override @Override
public void targetModified(TargetModifiedEvent e) { public void targetModified(TargetModifiedEvent e) {
@ -93,7 +104,6 @@ public class ParameterDefinitePane extends JPanel implements ToolBarMenuDockPlus
paraDesignEditor.addListener(this); paraDesignEditor.addListener(this);
propertyChangeListener = new PropertyChangeAdapter() { propertyChangeListener = new PropertyChangeAdapter() {
@Override @Override
public void propertyChange() { public void propertyChange() {
if (isEditing) { if (isEditing) {
@ -102,12 +112,7 @@ public class ParameterDefinitePane extends JPanel implements ToolBarMenuDockPlus
} }
} }
}; };
this.add(paraDesignEditor.createWrapper(), BorderLayout.CENTER);
// WidgetToolBarPane.getRecentSearchManger(formParaDesignEditor);
setButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/toolbarbtn/parametersetting.png"));
setButton.set4ToolbarButton();
isshowWindowItem = new JCheckBoxMenuItem(Inter.getLocText("ParameterD-Show_Parameter_Window"));
isshowWindowItem.addItemListener(new ItemListener() { isshowWindowItem.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
@ -116,9 +121,8 @@ public class ParameterDefinitePane extends JPanel implements ToolBarMenuDockPlus
} }
} }
}); });
isdelayItem = new JCheckBoxMenuItem(Inter.getLocText("ParameterD-Delay_Playing"));
isdelayItem.addItemListener(new ItemListener() {
isdelayItem.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (propertyChangeListener != null) { if (propertyChangeListener != null) {
@ -128,7 +132,6 @@ public class ParameterDefinitePane extends JPanel implements ToolBarMenuDockPlus
} }
}); });
setButton.addActionListener(new ActionListener() { setButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

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

@ -136,37 +136,7 @@ public class SelectionModel {
private void unselectedPaste() { private void unselectedPaste() {
if (designer.getClass().equals(FormDesigner.class)) { if (designer.getClass().equals(FormDesigner.class)) {
if (selection.getSelectedCreator() instanceof XWFitLayout) { if (selection.getSelectedCreator() instanceof XWFitLayout) {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) { pasteXWFitLayout();
XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator();
//tab布局编辑器内部左上角第一个坐标点
int leftUpX = container.toData().getMargin().getLeft() + 1;
int leftUpY = container.toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, container, clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
} else {
//自适应布局编辑器内部左上角第一个坐标点
int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1;
int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
}
} else { } else {
//绝对布局 //绝对布局
//编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层 //编辑器外面还有两层容器,使用designer.getRootComponent()获取到的是编辑器中层的容器,不是编辑器表层
@ -186,6 +156,40 @@ public class SelectionModel {
} }
} }
private void pasteXWFitLayout() {
if (selection.getSelectedCreator().getClass().equals(XWTabFitLayout.class)) {
XLayoutContainer container = (XLayoutContainer) selection.getSelectedCreator();
//tab布局编辑器内部左上角第一个坐标点
int leftUpX = container.toData().getMargin().getLeft() + 1;
int leftUpY = container.toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) container.getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, container, clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
} else {
//自适应布局编辑器内部左上角第一个坐标点
int leftUpX = designer.getRootComponent().toData().getMargin().getLeft() + 1;
int leftUpY = designer.getRootComponent().toData().getMargin().getTop() + 1;
//选中第一个坐标点坐在的组件
selection.setSelectedCreator((XCreator) designer.getRootComponent().getComponentAt(leftUpX, leftUpY));
Rectangle rectangle = selection.getRelativeBounds();
if (hasSelectedPasteSource()) {
selectedPaste();
} else {
FormSelectionUtils.paste2Container(designer, designer.getRootComponent(),
clipboard,
rectangle.x + rectangle.width / 2,
rectangle.y + DELTA_X_Y);
}
}
}
/** /**
* 粘贴时选择组件 * 粘贴时选择组件
*/ */
@ -404,45 +408,57 @@ public class SelectionModel {
if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) { if (x < (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer; return Location.outer;
} else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) { } else if ((x >= (bounds.x - XCreatorConstants.RESIZE_BOX_SIZ)) && (x <= bounds.x)) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { return getDirectionLeft(bounds, y);
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.left_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.left;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.left_bottom;
} else {
return Location.outer;
}
} else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) { } else if ((x > bounds.x) && (x < (bounds.x + bounds.width))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { return getDirectionCenter(bounds, y);
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.inner;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.bottom;
} else {
return Location.outer;
}
} else if ((x >= (bounds.x + bounds.width)) } else if ((x >= (bounds.x + bounds.width))
&& (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) { && (x <= (bounds.x + bounds.width + XCreatorConstants.RESIZE_BOX_SIZ))) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) { return getDirectionRight(bounds, y);
return Location.outer; } else {
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) { return Location.outer;
return Location.right_top; }
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) { }
return Location.right;
} else if ((y >= (bounds.y + bounds.height)) private Direction getDirectionRight(Rectangle bounds, int y) {
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) { if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.right_bottom; return Location.outer;
} else { } else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.outer; return Location.right_top;
} } else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.right;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.right_bottom;
} else {
return Location.outer;
}
}
private Direction getDirectionCenter(Rectangle bounds, int y) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.inner;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.bottom;
} else {
return Location.outer;
}
}
private Direction getDirectionLeft(Rectangle bounds, int y) {
if (y < (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) {
return Location.outer;
} else if ((y >= (bounds.y - XCreatorConstants.RESIZE_BOX_SIZ)) && (y <= bounds.y)) {
return Location.left_top;
} else if ((y > bounds.y) && (y < (bounds.y + bounds.height))) {
return Location.left;
} else if ((y >= (bounds.y + bounds.height))
&& (y <= (bounds.y + bounds.height + XCreatorConstants.RESIZE_BOX_SIZ))) {
return Location.left_bottom;
} else { } else {
return Location.outer; return Location.outer;
} }

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

@ -70,6 +70,9 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
private static final int SECOND_H_LOCATION = 170; private static final int SECOND_H_LOCATION = 170;
private static final int ADD_HEIGHT = 20; private static final int ADD_HEIGHT = 20;
private static final int H_GAP = 105; private static final int H_GAP = 105;
private static final int SUBMIT_BUTTON_H_LOCATION = 270;
private static final int PARA_IMAGE_SHIFT_X = -4;
private static final int FORM_AREA_PADDING_LEFT = 13;
private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png"); private static Image paraImage = BaseUtils.readImage("/com/fr/design/images/form/parameter.png");
@ -166,12 +169,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
@Override @Override
public void fireCreatorModified(DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_ADDED if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) {
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_CUTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_PASTED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_EDITED
|| evt.getCreatorEventID() == DesignerEvent.CREATOR_RENAMED) {
paraDefinitePane.setParameterArray( paraDefinitePane.setParameterArray(
paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters()));
paraDefinitePane.refreshParameter(); paraDefinitePane.refreshParameter();
@ -187,7 +185,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
*/ */
public Component createWrapper() { public Component createWrapper() {
FormArea area = new FormArea(this, false); FormArea area = new FormArea(this, false);
area.setBorder(BorderFactory.createEmptyBorder(0, 13, 0, 0)); area.setBorder(BorderFactory.createEmptyBorder(0, FORM_AREA_PADDING_LEFT, 0, 0));
return area; return area;
} }
@ -439,7 +437,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
} }
for (Parameter p : paras) { for (Parameter p : paras) {
if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) { if (p.getName().equalsIgnoreCase(creator.toData().getWidgetName())) {
g.drawImage(paraImage, creator.getX() - 4, creator.getY() + 2, null); g.drawImage(paraImage, creator.getX() + PARA_IMAGE_SHIFT_X, creator.getY() + 2, null);
break; break;
} }
} }
@ -617,7 +615,7 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
formSubmitButton.setWidgetName("Search"); formSubmitButton.setWidgetName("Search");
formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); formSubmitButton.setText(Inter.getLocText("FR-Designer_Query"));
xCreator = XCreatorUtils.createXCreator(formSubmitButton); xCreator = XCreatorUtils.createXCreator(formSubmitButton);
if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP if (!(this.autoAddComponent(xCreator, SUBMIT_BUTTON_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP
* (currentIndex / NUM_IN_A_LINE)))) { * (currentIndex / NUM_IN_A_LINE)))) {
return false; return false;
} }

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

@ -123,6 +123,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
private static final int SECOND_H_LOCATION = 170; private static final int SECOND_H_LOCATION = 170;
private static final int ADD_HEIGHT = 20; private static final int ADD_HEIGHT = 20;
private static final int H_GAP = 105; private static final int H_GAP = 105;
private static final int SUBMIT_BUTTON_H_LOCATION = 270;
public FormDesigner(Form form) { public FormDesigner(Form form) {
this(form, null); this(form, null);
@ -294,7 +295,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
formSubmitButton.setWidgetName("Search"); formSubmitButton.setWidgetName("Search");
formSubmitButton.setText(Inter.getLocText("FR-Designer_Query")); formSubmitButton.setText(Inter.getLocText("FR-Designer_Query"));
xCreator = XCreatorUtils.createXCreator(formSubmitButton); xCreator = XCreatorUtils.createXCreator(formSubmitButton);
if (!(this.autoAddComponent(xCreator, 270, FIRST_V_LOCATION + V_COMPONENT_GAP if (!(this.autoAddComponent(xCreator, SUBMIT_BUTTON_H_LOCATION, FIRST_V_LOCATION + V_COMPONENT_GAP
* (currentIndex / NUM_IN_A_LINE)))) { * (currentIndex / NUM_IN_A_LINE)))) {
return; return;
} }
@ -1146,7 +1147,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* 同步 * 同步
*/ */
public void populateRootSize() { public void populateRootSize() {
// do nothing
} }
/** /**
@ -1232,6 +1233,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
*/ */
@Override @Override
public void stopEditing() { public void stopEditing() {
// do nothing
} }
/** /**
@ -1411,7 +1413,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
parent = parent.getParent(); parent = parent.getParent();
} }
Object[] components = path.toArray(); Object[] components = (Object[]) path.toArray();
if (components.length == 0) { if (components.length == 0) {
return null; return null;
} }

14
designer_form/src/com/fr/design/parameter/ParameterToolBarPane.java

@ -35,6 +35,7 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
private static final int BUTTON_HEIGHT = 20; private static final int BUTTON_HEIGHT = 20;
private static final int WIDTH = 225; private static final int WIDTH = 225;
private static final int L_H = 18; private static final int L_H = 18;
private static final int LABEL_PADDING_LEFT = 4;
public ParameterToolBarPane() { public ParameterToolBarPane() {
this.setLayout(new FlowParameterPaneLayout()); this.setLayout(new FlowParameterPaneLayout());
@ -47,9 +48,9 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
return new Dimension(super.getPreferredSize().width, 18); return new Dimension(super.getPreferredSize().width, 18);
} }
}; };
label.setText(Inter.getLocText("FR-Following_parameters_are_not_generated")+":"); label.setText(Inter.getLocText("FR-Following_parameters_are_not_generated") + ":");
label.setHorizontalAlignment(SwingConstants.LEFT); label.setHorizontalAlignment(SwingConstants.LEFT);
label.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); label.setBorder(BorderFactory.createEmptyBorder(0, LABEL_PADDING_LEFT, 0, 0));
this.add(label); this.add(label);
addAll = new UIButton(Inter.getLocText("FR-Designer_Add_all")); addAll = new UIButton(Inter.getLocText("FR-Designer_Add_all"));
@ -68,7 +69,7 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
public Parameter getTargetParameter(UIButton button) { public Parameter getTargetParameter(UIButton button) {
int index = parameterSelectedLabellist.indexOf(button); int index = parameterSelectedLabellist.indexOf(button);
if(index < 0 || index > parameterList.length - 1) { if (index < 0 || index > parameterList.length - 1) {
return null; return null;
} }
return parameterList[index]; return parameterList[index];
@ -122,12 +123,15 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
private class FlowParameterPaneLayout implements LayoutManager { private class FlowParameterPaneLayout implements LayoutManager {
public FlowParameterPaneLayout() { public FlowParameterPaneLayout() {
// do nothing
} }
public void addLayoutComponent(String name, Component comp) { public void addLayoutComponent(String name, Component comp) {
// do nothing
} }
public void removeLayoutComponent(Component comp) { public void removeLayoutComponent(Component comp) {
// do nothing
} }
public Dimension preferredLayoutSize(Container parent) { public Dimension preferredLayoutSize(Container parent) {
@ -135,7 +139,7 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
layoutContainer(parent); layoutContainer(parent);
int h= ((parameterSelectedLabellist.size() == 0) ? 0 : breakid * (BUTTON_HEIGHT + GAP_V) + GAP_BV + L_H + GAP_H + addAll.getPreferredSize().height); int h= (parameterSelectedLabellist.isEmpty() ? 0 : breakid * (BUTTON_HEIGHT + GAP_V) + GAP_BV + L_H + GAP_H + addAll.getPreferredSize().height);
return new Dimension(w, h); return new Dimension(w, h);
} }
@ -153,7 +157,7 @@ public class ParameterToolBarPane extends BasicBeanPane<Parameter[]> {
breakid = 1; breakid = 1;
for (UIButton tab : parameterSelectedLabellist) { for (UIButton tab : parameterSelectedLabellist) {
Dimension dim = tab.getPreferredSize(); Dimension dim = tab.getPreferredSize();
if(x + dim.width > width) { if (x + dim.width > width) {
breakid++; breakid++;
x = 0; x = 0;
y += (dim.height + GAP_V); y += (dim.height + GAP_V);

Loading…
Cancel
Save