Browse Source

Pull request #5375: REPORT-57233 【FRM布局推荐】组件复用-对齐、自动间距、手动间距,调整后没有触发模板的保存和还原按钮,导致关闭再打开此模板还是调整前的效果

Merge in DESIGN/design from ~FANGLEI/design10.0:feature/10.0 to feature/10.0

* commit 'd09a4584793f1dcc35147ebf8a383ebe1355b013':
  REPORT-57233 修正本地调试的修改
  REPORT-57233 【FRM布局推荐】组件复用-对齐、自动间距、手动间距,调整后没有触发模板的保存和还原按钮,导致关闭再打开此模板还是调整前的效果
feature/10.0
fanglei 3 years ago
parent
commit
37e5fe9de9
  1. 44
      designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java
  2. 14
      designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java
  3. 27
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java
  4. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java
  5. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java
  6. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java
  7. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java
  8. 4
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java
  9. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java
  10. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java
  11. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java
  12. 1
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java
  13. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

44
designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java

@ -1,6 +1,12 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
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.XLayoutContainer;
import com.fr.design.designer.creator.XWFitLayout;
import com.fr.design.designer.creator.XWParameterLayout;
import com.fr.design.designer.creator.cardlayout.XWCardTagLayout;
import com.fr.form.ui.container.WLayout;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.Arrays; import java.util.Arrays;
@ -10,6 +16,7 @@ import java.util.List;
public class MultiSelectionArrangement { public class MultiSelectionArrangement {
private FormDesigner designer; private FormDesigner designer;
private XLayoutContainer parent; // 当前选中的那些组件所在父容器
private List<XCreator> selectedCreators; private List<XCreator> selectedCreators;
private Rectangle rec; private Rectangle rec;
@ -22,42 +29,42 @@ public class MultiSelectionArrangement {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(rec.x, creator.getY()); creator.setLocation(rec.x, creator.getY());
} }
repaint(); update();
} }
public void rightAlign() { public void rightAlign() {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(rec.x + rec.width - creator.getWidth(), creator.getY()); creator.setLocation(rec.x + rec.width - creator.getWidth(), creator.getY());
} }
repaint(); update();
} }
public void topAlign() { public void topAlign() {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(creator.getX(), rec.y); creator.setLocation(creator.getX(), rec.y);
} }
repaint(); update();
} }
public void bottomAlign() { public void bottomAlign() {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(creator.getX(), rec.y + rec.height - creator.getHeight()); creator.setLocation(creator.getX(), rec.y + rec.height - creator.getHeight());
} }
repaint(); update();
} }
public void horizontalCenterAlign() { public void horizontalCenterAlign() {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(rec.x + rec.width / 2 - creator.getWidth() / 2, creator.getY()); creator.setLocation(rec.x + rec.width / 2 - creator.getWidth() / 2, creator.getY());
} }
repaint(); update();
} }
public void verticalCenterAlign() { public void verticalCenterAlign() {
for (XCreator creator : selectedCreators) { for (XCreator creator : selectedCreators) {
creator.setLocation(creator.getX(), rec.y + rec.height / 2 - creator.getHeight() / 2); creator.setLocation(creator.getX(), rec.y + rec.height / 2 - creator.getHeight() / 2);
} }
repaint(); update();
} }
// 水平分布,自动,间距由selectedCreators和border共同计算而来 // 水平分布,自动,间距由selectedCreators和border共同计算而来
@ -79,7 +86,7 @@ public class MultiSelectionArrangement {
XCreator preCreator = selectedCreators.get(i - 1); XCreator preCreator = selectedCreators.get(i - 1);
creator.setLocation(preCreator.getX() + preCreator.getWidth() + gap, creator.getY()); creator.setLocation(preCreator.getX() + preCreator.getWidth() + gap, creator.getY());
} }
repaint(); update();
} }
private void reSizeRecByHorizontal(int gap) { private void reSizeRecByHorizontal(int gap) {
@ -151,7 +158,7 @@ public class MultiSelectionArrangement {
XCreator preCreator = selectedCreators.get(i - 1); XCreator preCreator = selectedCreators.get(i - 1);
creator.setLocation(creator.getX(), preCreator.getY() + preCreator.getHeight() + gap); creator.setLocation(creator.getX(), preCreator.getY() + preCreator.getHeight() + gap);
} }
repaint(); update();
} }
private void reSizeRecByVertical(int gap) { private void reSizeRecByVertical(int gap) {
@ -209,10 +216,25 @@ public class MultiSelectionArrangement {
FormSelection selection = designer.getSelectionModel().getSelection(); FormSelection selection = designer.getSelectionModel().getSelection();
this.selectedCreators = Arrays.asList(selection.getSelectedCreators()); this.selectedCreators = Arrays.asList(selection.getSelectedCreators());
this.rec = selection.getSelctionBounds(); this.rec = selection.getSelctionBounds();
this.parent = getParent(selection.getSelectedCreator());
if (parent != null) {
// 这里要修改修改engine里面的对象才能成功保存,光修改设计器对象没用
WLayout wabs = parent.toData();
for (XCreator creator : selectedCreators) {
wabs.setBounds(creator.toData(), creator.getBounds());
}
}
} }
private void repaint() { private XLayoutContainer getParent(XCreator source) {
designer.repaint(); if(source.acceptType(XWCardTagLayout.class)){
update(); return (XLayoutContainer)source.getParent();
}
XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(source);
if (source.acceptType(XWFitLayout.class) || source.acceptType(XWParameterLayout.class)) {
container = null;
}
return container;
} }
} }

14
designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java

@ -412,20 +412,6 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper
if (!isValid) { if (!isValid) {
return; return;
} }
//fanglei:下面的注释不要删,只是暂时屏蔽
// int value = downPanel.getVerticalScrollBar().getValue();
// if (hasSelectParaPane(getEditingFormDesigner())) {
// cardLayout.show(centerPane, PARA);
// mobileParaWidgetTable.refreshData();
// } else {
// cardLayout.show(centerPane, BODY);
// mobileWidgetTable.refreshData();
// }
// //出现滚动条
// downPanel.doLayout();
// //控件列表选中某组件,触发表单中选中控件,选中事件又触发列表刷新,滚动条回到0
// //此处设置滚动条值为刷新前
// downPanel.getVerticalScrollBar().setValue(value);
if (mobileExtraPropertyPanes != null) { if (mobileExtraPropertyPanes != null) {
for (MobileWidgetDefinePane extraPane : mobileExtraPropertyPanes) { for (MobileWidgetDefinePane extraPane : mobileExtraPropertyPanes) {
extraPane.populate(designer); extraPane.populate(designer);

27
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java

@ -1,23 +1,32 @@
package com.fr.design.mainframe.widget.arrangement.buttons; package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.mainframe.MultiSelectionArrangement; import com.fr.design.mainframe.MultiSelectionArrangement;
public abstract class AbstractMultiSelectionArrangementButton implements MultiSelectionArrangementButton { public abstract class AbstractMultiSelectionArrangementButton extends UIButton implements MultiSelectionArrangementButton, UIObserver {
private static final long serialVersionUID = -2114423583742242771L;
protected MultiSelectionArrangement arrangement; protected MultiSelectionArrangement arrangement;
protected UIObserverListener uiObserverListener;
public AbstractMultiSelectionArrangementButton(MultiSelectionArrangement arrangement) { public AbstractMultiSelectionArrangementButton(MultiSelectionArrangement arrangement) {
super();
this.arrangement = arrangement; this.arrangement = arrangement;
this.setNormalPainted(false);
this.setBorderPaintedOnlyWhenPressed(true);
this.setIcon(getIcon());
this.setToolTipText(getTipText());
this.addActionListener(getActionListener());
} }
@Override @Override
public UIButton create() { public void registerChangeListener(UIObserverListener listener) {
UIButton btn = new UIButton(); uiObserverListener = listener;
btn.setNormalPainted(false); }
btn.setBorderPaintedOnlyWhenPressed(true);
btn.setIcon(getIcon()); @Override
btn.setToolTipText(getTipText()); public boolean shouldResponseChangeListener() {
btn.addActionListener(getActionListener()); return true;
return btn;
} }
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java

@ -29,6 +29,7 @@ public class BottomAlignButton extends AbstractMultiSelectionArrangementButton {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.bottomAlign(); arrangement.bottomAlign();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java

@ -29,6 +29,7 @@ public class HorizontalCenterButton extends AbstractMultiSelectionArrangementBut
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.horizontalCenterAlign(); arrangement.horizontalCenterAlign();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java

@ -29,6 +29,7 @@ public class HorizontalDistributionButton extends AbstractMultiSelectionArrangem
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.horizontalAutoDistribution(); arrangement.horizontalAutoDistribution();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java

@ -29,6 +29,7 @@ public class LeftAlignButton extends AbstractMultiSelectionArrangementButton {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.leftAlign(); arrangement.leftAlign();
uiObserverListener.doChange();
} }
}; };
} }

4
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java

@ -1,7 +1,5 @@
package com.fr.design.mainframe.widget.arrangement.buttons; package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.gui.ibutton.UIButton;
import javax.swing.Icon; import javax.swing.Icon;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -11,6 +9,4 @@ public interface MultiSelectionArrangementButton {
String getTipText(); String getTipText();
ActionListener getActionListener(); ActionListener getActionListener();
UIButton create();
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java

@ -29,6 +29,7 @@ public class RightAlignButton extends AbstractMultiSelectionArrangementButton {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.rightAlign(); arrangement.rightAlign();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java

@ -29,6 +29,7 @@ public class TopAlignButton extends AbstractMultiSelectionArrangementButton {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.topAlign(); arrangement.topAlign();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java

@ -29,6 +29,7 @@ public class VerticalCenterButton extends AbstractMultiSelectionArrangementButto
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.verticalCenterAlign(); arrangement.verticalCenterAlign();
uiObserverListener.doChange();
} }
}; };
} }

1
designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java

@ -29,6 +29,7 @@ public class VerticalDistributionButton extends AbstractMultiSelectionArrangemen
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
arrangement.verticalAutoDistribution(); arrangement.verticalAutoDistribution();
uiObserverListener.doChange();
} }
}; };
} }

35
designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

@ -1,5 +1,7 @@
package com.fr.design.mainframe.widget.ui; package com.fr.design.mainframe.widget.ui;
import com.fr.design.designer.beans.events.DesignerEvent;
import com.fr.design.gui.frpane.AttributeChangeListener;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UIPositiveAndNegativeIntNumberField; import com.fr.design.gui.itextfield.UIPositiveAndNegativeIntNumberField;
@ -19,6 +21,7 @@ import com.fr.design.mainframe.widget.arrangement.buttons.VerticalCenterButton;
import com.fr.design.mainframe.widget.arrangement.buttons.VerticalDistributionButton; import com.fr.design.mainframe.widget.arrangement.buttons.VerticalDistributionButton;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -30,6 +33,7 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class FormMultiWidgetCardPane extends FormWidgetCardPane { public class FormMultiWidgetCardPane extends FormWidgetCardPane {
private AttributeChangeListener listener;
private MultiSelectionArrangement arrangement; private MultiSelectionArrangement arrangement;
public FormMultiWidgetCardPane(FormDesigner designer) { public FormMultiWidgetCardPane(FormDesigner designer) {
@ -40,6 +44,12 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
arrangement = new MultiSelectionArrangement(designer); arrangement = new MultiSelectionArrangement(designer);
content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
content.add(createArrangementLayoutPane(), BorderLayout.CENTER); content.add(createArrangementLayoutPane(), BorderLayout.CENTER);
this.listener = new AttributeChangeListener() {
@Override
public void attributeChange() {
designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_RESIZED);
}
};
} }
// 整个排列分布面板的layout,可以看成一个三行一列的表格,第一行是分布,第二行是自动间距,第三行是手动间距 // 整个排列分布面板的layout,可以看成一个三行一列的表格,第一行是分布,第二行是自动间距,第三行是手动间距
@ -73,12 +83,12 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
}; };
Component[][] components = new Component[][] { Component[][] components = new Component[][] {
new Component[] { new Component[] {
new LeftAlignButton(arrangement).create(), new LeftAlignButton(arrangement),
new HorizontalCenterButton(arrangement).create(), new HorizontalCenterButton(arrangement),
new RightAlignButton(arrangement).create(), new RightAlignButton(arrangement),
new TopAlignButton(arrangement).create(), new TopAlignButton(arrangement),
new VerticalCenterButton(arrangement).create(), new VerticalCenterButton(arrangement),
new BottomAlignButton(arrangement).create() new BottomAlignButton(arrangement)
} }
}; };
JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 18, 0); JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 18, 0);
@ -92,8 +102,8 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED TableLayout.PREFERRED
}; };
UIButton horizontalAutoSpacingBtn = new HorizontalDistributionButton(arrangement).create(); UIButton horizontalAutoSpacingBtn = new HorizontalDistributionButton(arrangement);
UIButton verticalAutoSpacingBtn = new VerticalDistributionButton(arrangement).create(); UIButton verticalAutoSpacingBtn = new VerticalDistributionButton(arrangement);
if (designer.getSelectionModel().getSelection().size() < 3) { if (designer.getSelectionModel().getSelection().size() < 3) {
horizontalAutoSpacingBtn.setEnabled(false); horizontalAutoSpacingBtn.setEnabled(false);
verticalAutoSpacingBtn.setEnabled(false); verticalAutoSpacingBtn.setEnabled(false);
@ -167,12 +177,13 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
} }
private void distributionDoChange(String text, boolean isVertical) { private void distributionDoChange(String text, boolean isVertical) {
if (StableUtils.isNumber(text)) { if (StringUtils.isNotEmpty(text) && StableUtils.isNumber(text)) {
if (isVertical) { if (isVertical) {
arrangement.verticalManualDistribution(Math.round(Float.parseFloat(text))); arrangement.verticalManualDistribution(Math.round(Float.parseFloat(text)));
} else { } else {
arrangement.horizontalManualDistribution(Math.round(Float.parseFloat(text))); arrangement.horizontalManualDistribution(Math.round(Float.parseFloat(text)));
} }
attributeChanged();
} }
} }
@ -184,4 +195,10 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
jPanel.add(centerPane, BorderLayout.CENTER); jPanel.add(centerPane, BorderLayout.CENTER);
return jPanel; return jPanel;
} }
@Override
public void populate() {
initListener(this);
this.addAttributeChangeListener(listener);
}
} }

Loading…
Cancel
Save