Browse Source

REPORT-54885 【10.0.19】FRM布局推荐之布局优化部分

feature/10.0
方磊 3 years ago
parent
commit
6ecdf5a8d9
  1. 2
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  2. 4
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  3. 16
      designer-form/src/main/java/com/fr/design/mainframe/FormSpacingLineDrawer.java
  4. 23
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/AbstractMultiSelectionArrangementButton.java
  5. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/BottomAlignButton.java
  6. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalCenterButton.java
  7. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/HorizontalDistributionButton.java
  8. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/LeftAlignButton.java
  9. 16
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/MultiSelectionArrangementButton.java
  10. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/RightAlignButton.java
  11. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/TopAlignButton.java
  12. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalCenterButton.java
  13. 35
      designer-form/src/main/java/com/fr/design/mainframe/widget/arrangement/buttons/VerticalDistributionButton.java
  14. 125
      designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

2
designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java

@ -862,7 +862,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
}
}
public boolean isInAbsoluteContainer() {
public boolean isParentAbsolute() {
return ((XCreator) this.getParent()).acceptType(XWAbsoluteLayout.class);
}
}

4
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -1770,11 +1770,11 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
XCreator[] creators = this.getSelectionModel().getSelection().getSelectedCreators();
if (creators != null && creators.length > 1) {
for (int i = 0; i < creators.length - 1; i++) {
if (creators[i].getParent() != creators[i + 1].getParent() || !creators[i].isInAbsoluteContainer()) {
if (creators[i].getParent() != creators[i + 1].getParent() || !creators[i].isParentAbsolute()) {
return false;
}
}
return creators[creators.length - 1].isInAbsoluteContainer();
return creators[creators.length - 1].isParentAbsolute();
}
return false;
}

16
designer-form/src/main/java/com/fr/design/mainframe/FormSpacingLineDrawer.java

@ -36,11 +36,11 @@ public class FormSpacingLineDrawer {
public void draw(Graphics g) {
this.selectedRec = designer.getSelectionModel().getSelection().getSelctionBounds();
if (isSelectedForm() || isSelectedRootComponent() || isHoveredForm() || isHoveredRootComponent() || !isMouseMoveEvent) {
if (!isDrawSpacingLine()) {
return;
}
if (!hoverCreator.isInAbsoluteContainer()) {
if (!hoverCreator.isParentAbsolute()) {
return;
}
@ -259,4 +259,16 @@ public class FormSpacingLineDrawer {
private boolean isHoveredCreatorRightYSpacingLine() {
return hoverCreator.getX() > selectedRec.x + selectedRec.width / 2;
}
private boolean isSelectedRootPane() {
return isSelectedForm() || isSelectedRootComponent();
}
private boolean isHoveredRootPane() {
return isHoveredForm() || isHoveredRootComponent();
}
private boolean isDrawSpacingLine() {
return !isSelectedRootPane() && !isHoveredRootPane() && isMouseMoveEvent;
}
}

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

@ -0,0 +1,23 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.mainframe.MultiSelectionArrangement;
public abstract class AbstractMultiSelectionArrangementButton implements MultiSelectionArrangementButton {
protected MultiSelectionArrangement arrangement;
public AbstractMultiSelectionArrangementButton(MultiSelectionArrangement arrangement) {
this.arrangement = arrangement;
}
@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;
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class BottomAlignButton extends AbstractMultiSelectionArrangementButton {
public BottomAlignButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_bottom_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Bottom_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.bottomAlign();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class HorizontalCenterButton extends AbstractMultiSelectionArrangementButton {
public HorizontalCenterButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_horizontal_center_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Horizontal_Center_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.horizontalCenterAlign();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class HorizontalDistributionButton extends AbstractMultiSelectionArrangementButton {
public HorizontalDistributionButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_horizontal_auto_spacing.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Auto_Horizontal_Spacing");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.horizontalAutoDistribution();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LeftAlignButton extends AbstractMultiSelectionArrangementButton {
public LeftAlignButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_left_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Left_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.leftAlign();
}
};
}
}

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

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

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RightAlignButton extends AbstractMultiSelectionArrangementButton {
public RightAlignButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_right_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Right_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.rightAlign();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TopAlignButton extends AbstractMultiSelectionArrangementButton {
public TopAlignButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_top_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Top_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.topAlign();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class VerticalCenterButton extends AbstractMultiSelectionArrangementButton {
public VerticalCenterButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_vertical_center_align.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Vertical_Center_Align");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.verticalCenterAlign();
}
};
}
}

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

@ -0,0 +1,35 @@
package com.fr.design.mainframe.widget.arrangement.buttons;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.general.IOUtils;
import javax.swing.Icon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class VerticalDistributionButton extends AbstractMultiSelectionArrangementButton {
public VerticalDistributionButton(MultiSelectionArrangement arrangement) {
super(arrangement);
}
@Override
public Icon getIcon() {
return IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_vertical_auto_spacing.png");
}
@Override
public String getTipText() {
return Toolkit.i18nText("Fine-Design_Multi_Selection_Auto_Vertical_Spacing");
}
@Override
public ActionListener getActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.verticalAutoDistribution();
}
};
}
}

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

@ -9,6 +9,14 @@ import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.MultiSelectionArrangement;
import com.fr.design.mainframe.widget.arrangement.buttons.BottomAlignButton;
import com.fr.design.mainframe.widget.arrangement.buttons.HorizontalCenterButton;
import com.fr.design.mainframe.widget.arrangement.buttons.HorizontalDistributionButton;
import com.fr.design.mainframe.widget.arrangement.buttons.LeftAlignButton;
import com.fr.design.mainframe.widget.arrangement.buttons.RightAlignButton;
import com.fr.design.mainframe.widget.arrangement.buttons.TopAlignButton;
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;
@ -16,21 +24,10 @@ import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
public class FormMultiWidgetCardPane extends FormWidgetCardPane {
private static final int LEFT_ALIGN = 1;
private static final int RIGHT_ALIGN = 2;
private static final int HORIZONTAL_CENTER_ALIGN = 3;
private static final int TOP_ALIGN = 4;
private static final int BOTTOM_ALIGN = 5;
private static final int VERTICAL_CENTER_ALIGN = 6;
private static final int HORIZONTAL_AUTO_SPACING = 7;
private static final int VERTICAL_AUTO_SPACING = 8;
private MultiSelectionArrangement arrangement;
public FormMultiWidgetCardPane(FormDesigner designer) {
@ -74,12 +71,12 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
};
Component[][] components = new Component[][] {
new Component[] {
createArrangementButton(LEFT_ALIGN),
createArrangementButton(HORIZONTAL_CENTER_ALIGN),
createArrangementButton(RIGHT_ALIGN),
createArrangementButton(TOP_ALIGN),
createArrangementButton(VERTICAL_CENTER_ALIGN),
createArrangementButton(BOTTOM_ALIGN)
new LeftAlignButton(arrangement).create(),
new HorizontalCenterButton(arrangement).create(),
new RightAlignButton(arrangement).create(),
new TopAlignButton(arrangement).create(),
new VerticalCenterButton(arrangement).create(),
new BottomAlignButton(arrangement).create()
}
};
JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 18, 0);
@ -93,8 +90,8 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
TableLayout.PREFERRED,
TableLayout.PREFERRED
};
UIButton horizontalAutoSpacingBtn = createArrangementButton(HORIZONTAL_AUTO_SPACING);
UIButton verticalAutoSpacingBtn = createArrangementButton(VERTICAL_AUTO_SPACING);
UIButton horizontalAutoSpacingBtn = new HorizontalDistributionButton(arrangement).create();
UIButton verticalAutoSpacingBtn = new VerticalDistributionButton(arrangement).create();
if (designer.getSelectionModel().getSelection().size() < 3) {
horizontalAutoSpacingBtn.setEnabled(false);
verticalAutoSpacingBtn.setEnabled(false);
@ -178,94 +175,4 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane {
jPanel.add(centerPane, BorderLayout.CENTER);
return jPanel;
}
private UIButton createArrangementButton(int btnType) {
UIButton btn = new UIButton();
btn.setNormalPainted(false);
btn.setBorderPaintedOnlyWhenPressed(true);
switch (btnType) {
case LEFT_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_left_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Left_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.leftAlign();
}
});
break;
case RIGHT_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_right_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Right_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.rightAlign();
}
});
break;
case TOP_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_top_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Top_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.topAlign();
}
});
break;
case BOTTOM_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_bottom_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Bottom_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.bottomAlign();
}
});
break;
case HORIZONTAL_CENTER_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_horizontal_center_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Horizontal_Center_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.horizontalCenterAlign();
}
});
break;
case VERTICAL_CENTER_ALIGN:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_vertical_center_align.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Vertical_Center_Align"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.verticalCenterAlign();
}
});
break;
case HORIZONTAL_AUTO_SPACING:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_horizontal_auto_spacing.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Auto_Horizontal_Spacing"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.horizontalAutoDistribution();
}
});
break;
case VERTICAL_AUTO_SPACING:
btn.setIcon(IOUtils.readIcon("/com/fr/design/images/buttonicon/multi_selection_vertical_auto_spacing.png"));
btn.setToolTipText(Toolkit.i18nText("Fine-Design_Multi_Selection_Auto_Vertical_Spacing"));
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
arrangement.verticalAutoDistribution();
}
});
break;
default: break;
}
return btn;
}
}

Loading…
Cancel
Save