diff --git a/designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java b/designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java index 1b0962febd..b9eb18f753 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/MultiSelectionArrangement.java @@ -1,6 +1,12 @@ package com.fr.design.mainframe; 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.util.Arrays; @@ -10,6 +16,7 @@ import java.util.List; public class MultiSelectionArrangement { private FormDesigner designer; + private XLayoutContainer parent; // 当前选中的那些组件所在父容器 private List selectedCreators; private Rectangle rec; @@ -22,42 +29,42 @@ public class MultiSelectionArrangement { for (XCreator creator : selectedCreators) { creator.setLocation(rec.x, creator.getY()); } - repaint(); + update(); } public void rightAlign() { for (XCreator creator : selectedCreators) { creator.setLocation(rec.x + rec.width - creator.getWidth(), creator.getY()); } - repaint(); + update(); } public void topAlign() { for (XCreator creator : selectedCreators) { creator.setLocation(creator.getX(), rec.y); } - repaint(); + update(); } public void bottomAlign() { for (XCreator creator : selectedCreators) { creator.setLocation(creator.getX(), rec.y + rec.height - creator.getHeight()); } - repaint(); + update(); } public void horizontalCenterAlign() { for (XCreator creator : selectedCreators) { creator.setLocation(rec.x + rec.width / 2 - creator.getWidth() / 2, creator.getY()); } - repaint(); + update(); } public void verticalCenterAlign() { for (XCreator creator : selectedCreators) { creator.setLocation(creator.getX(), rec.y + rec.height / 2 - creator.getHeight() / 2); } - repaint(); + update(); } // 水平分布,自动,间距由selectedCreators和border共同计算而来 @@ -79,7 +86,7 @@ public class MultiSelectionArrangement { XCreator preCreator = selectedCreators.get(i - 1); creator.setLocation(preCreator.getX() + preCreator.getWidth() + gap, creator.getY()); } - repaint(); + update(); } private void reSizeRecByHorizontal(int gap) { @@ -151,7 +158,7 @@ public class MultiSelectionArrangement { XCreator preCreator = selectedCreators.get(i - 1); creator.setLocation(creator.getX(), preCreator.getY() + preCreator.getHeight() + gap); } - repaint(); + update(); } private void reSizeRecByVertical(int gap) { @@ -209,10 +216,25 @@ public class MultiSelectionArrangement { FormSelection selection = designer.getSelectionModel().getSelection(); this.selectedCreators = Arrays.asList(selection.getSelectedCreators()); 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() { - designer.repaint(); - update(); + private XLayoutContainer getParent(XCreator source) { + if(source.acceptType(XWCardTagLayout.class)){ + return (XLayoutContainer)source.getParent(); + } + XLayoutContainer container = XCreatorUtils.getParentXLayoutContainer(source); + if (source.acceptType(XWFitLayout.class) || source.acceptType(XWParameterLayout.class)) { + container = null; + } + return container; } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java b/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java index b4fc1122bc..e61e8a600e 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/WidgetPropertyPane.java @@ -412,20 +412,6 @@ public class WidgetPropertyPane extends FormDockView implements BaseWidgetProper if (!isValid) { 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) { for (MobileWidgetDefinePane extraPane : mobileExtraPropertyPanes) { extraPane.populate(designer); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java index ac687d4256..dc268f4c5b 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java +++ b/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; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIButton; 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 UIObserverListener uiObserverListener; public AbstractMultiSelectionArrangementButton(MultiSelectionArrangement arrangement) { + super(); this.arrangement = arrangement; + this.setNormalPainted(false); + this.setBorderPaintedOnlyWhenPressed(true); + this.setIcon(getIcon()); + this.setToolTipText(getTipText()); + this.addActionListener(getActionListener()); } @Override - public UIButton create() { - UIButton btn = new UIButton(); - btn.setNormalPainted(false); - btn.setBorderPaintedOnlyWhenPressed(true); - btn.setIcon(getIcon()); - btn.setToolTipText(getTipText()); - btn.addActionListener(getActionListener()); - return btn; + public void registerChangeListener(UIObserverListener listener) { + uiObserverListener = listener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java index 41318ff67b..99bf3a6c3a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java @@ -29,6 +29,7 @@ public class BottomAlignButton extends AbstractMultiSelectionArrangementButton { @Override public void actionPerformed(ActionEvent e) { arrangement.bottomAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java index 7eface48f4..6dc9c09b4a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java @@ -29,6 +29,7 @@ public class HorizontalCenterButton extends AbstractMultiSelectionArrangementBut @Override public void actionPerformed(ActionEvent e) { arrangement.horizontalCenterAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java index 678ce895bf..0a0e225fc6 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java @@ -29,6 +29,7 @@ public class HorizontalDistributionButton extends AbstractMultiSelectionArrangem @Override public void actionPerformed(ActionEvent e) { arrangement.horizontalAutoDistribution(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java index 3f8d685c77..20a25a87cb 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java @@ -29,6 +29,7 @@ public class LeftAlignButton extends AbstractMultiSelectionArrangementButton { @Override public void actionPerformed(ActionEvent e) { arrangement.leftAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java index 06bc2026be..99b7635708 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java +++ b/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; -import com.fr.design.gui.ibutton.UIButton; - import javax.swing.Icon; import java.awt.event.ActionListener; @@ -11,6 +9,4 @@ public interface MultiSelectionArrangementButton { String getTipText(); ActionListener getActionListener(); - - UIButton create(); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java index 02f20fc45e..5fac70bd7a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java @@ -29,6 +29,7 @@ public class RightAlignButton extends AbstractMultiSelectionArrangementButton { @Override public void actionPerformed(ActionEvent e) { arrangement.rightAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java index 7100b3b960..ebb2c4d21a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java @@ -29,6 +29,7 @@ public class TopAlignButton extends AbstractMultiSelectionArrangementButton { @Override public void actionPerformed(ActionEvent e) { arrangement.topAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java index 81d86d5583..9898f9002c 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java @@ -29,6 +29,7 @@ public class VerticalCenterButton extends AbstractMultiSelectionArrangementButto @Override public void actionPerformed(ActionEvent e) { arrangement.verticalCenterAlign(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java index 538463b6b3..50ec6ac894 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java @@ -29,6 +29,7 @@ public class VerticalDistributionButton extends AbstractMultiSelectionArrangemen @Override public void actionPerformed(ActionEvent e) { arrangement.verticalAutoDistribution(); + uiObserverListener.doChange(); } }; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java index 699c34b2a4..b053ea6337 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java @@ -1,5 +1,7 @@ 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.ilable.UILabel; 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.general.IOUtils; import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; import javax.swing.BorderFactory; import javax.swing.JPanel; @@ -30,6 +33,7 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class FormMultiWidgetCardPane extends FormWidgetCardPane { + private AttributeChangeListener listener; private MultiSelectionArrangement arrangement; public FormMultiWidgetCardPane(FormDesigner designer) { @@ -40,6 +44,12 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { arrangement = new MultiSelectionArrangement(designer); content.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0)); content.add(createArrangementLayoutPane(), BorderLayout.CENTER); + this.listener = new AttributeChangeListener() { + @Override + public void attributeChange() { + designer.getEditListenerTable().fireCreatorModified(DesignerEvent.CREATOR_RESIZED); + } + }; } // 整个排列分布面板的layout,可以看成一个三行一列的表格,第一行是分布,第二行是自动间距,第三行是手动间距 @@ -73,12 +83,12 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { }; Component[][] components = new Component[][] { new Component[] { - new LeftAlignButton(arrangement).create(), - new HorizontalCenterButton(arrangement).create(), - new RightAlignButton(arrangement).create(), - new TopAlignButton(arrangement).create(), - new VerticalCenterButton(arrangement).create(), - new BottomAlignButton(arrangement).create() + new LeftAlignButton(arrangement), + new HorizontalCenterButton(arrangement), + new RightAlignButton(arrangement), + new TopAlignButton(arrangement), + new VerticalCenterButton(arrangement), + new BottomAlignButton(arrangement) } }; JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 18, 0); @@ -92,8 +102,8 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { TableLayout.PREFERRED, TableLayout.PREFERRED }; - UIButton horizontalAutoSpacingBtn = new HorizontalDistributionButton(arrangement).create(); - UIButton verticalAutoSpacingBtn = new VerticalDistributionButton(arrangement).create(); + UIButton horizontalAutoSpacingBtn = new HorizontalDistributionButton(arrangement); + UIButton verticalAutoSpacingBtn = new VerticalDistributionButton(arrangement); if (designer.getSelectionModel().getSelection().size() < 3) { horizontalAutoSpacingBtn.setEnabled(false); verticalAutoSpacingBtn.setEnabled(false); @@ -167,12 +177,13 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { } private void distributionDoChange(String text, boolean isVertical) { - if (StableUtils.isNumber(text)) { + if (StringUtils.isNotEmpty(text) && StableUtils.isNumber(text)) { if (isVertical) { arrangement.verticalManualDistribution(Math.round(Float.parseFloat(text))); } else { arrangement.horizontalManualDistribution(Math.round(Float.parseFloat(text))); } + attributeChanged(); } } @@ -184,4 +195,10 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { jPanel.add(centerPane, BorderLayout.CENTER); return jPanel; } + + @Override + public void populate() { + initListener(this); + this.addAttributeChangeListener(listener); + } }