Browse Source

REPORT-53175 【10.0.18】组件背景分离为标题/背景/边框

【问题原因】
组件尺寸比例锁定提示及共享组件默认锁定尺寸比例锁定交互更新
【改动思路】
【review建议】
feature/10.0
Starryi 3 years ago
parent
commit
d710e8c7f8
  1. 1
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  2. 222
      designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java
  3. 5
      designer-form/src/main/java/com/fr/design/designer/ui/SelectedPopupDialog.java
  4. 5
      designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java
  5. 4
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

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

@ -777,6 +777,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
int extraX = (int) ((bounds.x + bounds.width + SelectedPopupDialog.OFFSET_X) * designer.getScale()); int extraX = (int) ((bounds.x + bounds.width + SelectedPopupDialog.OFFSET_X) * designer.getScale());
int extraY = (int) (bounds.y * designer.getScale()); int extraY = (int) (bounds.y * designer.getScale());
popup.setLocation(designer.getLocationOnScreen().x + designer.getPaintX() + extraX, designer.getLocationOnScreen().y + designer.getPaintY() + extraY); popup.setLocation(designer.getLocationOnScreen().x + designer.getPaintX() + extraX, designer.getLocationOnScreen().y + designer.getPaintY() + extraY);
popup.updatePane(designer);
popup.setVisible(selected && accept); popup.setVisible(selected && accept);
popup.setRelativeBounds(bounds); popup.setRelativeBounds(bounds);
} }

222
designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java

@ -1,35 +1,27 @@
package com.fr.design.designer.ui; package com.fr.design.designer.ui;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter;
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.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.VerticalFlowLayout;
import com.fr.design.mainframe.CoverReportPane; import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EditingMouseListener; import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormDesigner;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import java.awt.Color;
import java.awt.Component; import javax.swing.*;
import java.awt.Container; import java.awt.*;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import javax.swing.AbstractButton; import java.util.ArrayList;
import javax.swing.Icon; import java.util.List;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/** /**
* @author hades * @author hades
@ -40,25 +32,39 @@ public class PopupControlPanel extends JPanel {
private static final int ARC_VALUE = 4; private static final int ARC_VALUE = 4;
private static final Color FILLED_COLOR = new Color(60, 63, 65); private static final Color FILLED_COLOR = new Color(60, 63, 65);
private static final int V_GAP = 10; private static final int BUTTON_SIZE = 16;
private static final int H_GAP = 2; private static final int BUTTON_MARGIN = 4;
private static final int PANE_WIDTH = BUTTON_SIZE + BUTTON_MARGIN * 2; // 24
private Dimension defaultDimension = new Dimension(20, 60); private final Dimension defaultDimension = new Dimension(PANE_WIDTH, 0);
private Rectangle rectangle; private Rectangle rectangle;
private final List<JComponent> buttons = new ArrayList<>();
private final JButton editButton; private final JButton editButton;
private final JButton settingButton; private final JButton settingButton;
private final JToggleButton toggleButton; private final JToggleButton toggleButton;
private final XCreator creator; private final XCreator creator;
private final UILabel firstLabel;
private final UILabel secondLabel;
public PopupControlPanel(XCreator creator, FormDesigner designer) { public PopupControlPanel(XCreator creator, FormDesigner designer) {
if (creator.isShared()) { setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0));
defaultDimension = new Dimension(20, 85); setBorder(BorderFactory.createEmptyBorder());
}
setLayout(getCustomLayout());
this.creator = creator; this.creator = creator;
editButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_edit.png"), Toolkit.i18nText("Fine-Design_Form_Edit_Widget"));
editButton = createEditButton(designer);
toggleButton = createAspectRatioLockedButton(designer);
settingButton = createSettingButton();
addButton(editButton, 0);
addButton(toggleButton, 1);
addButton(settingButton, 2);
setButtonVisible(editButton, true);
setButtonVisible(toggleButton, false);
setButtonVisible(settingButton, false);
}
private JButton createEditButton(FormDesigner designer) {
JButton editButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_edit.png"), Toolkit.i18nText("Fine-Design_Form_Edit_Widget"));
editButton.addMouseListener(new MouseAdapter() { editButton.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@ -71,102 +77,99 @@ public class PopupControlPanel extends JPanel {
} }
} }
}); });
settingButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_setting.png"), Toolkit.i18nText("Fine-Design_Share_Help_Settings")); return editButton;
}
settingButton.addActionListener(new ActionListener() { private JToggleButton createAspectRatioLockedButton(FormDesigner designer) {
JToggleButton button = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/edit_unlock.png"));
initButtonStyle(button);
button.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/edit_lock.png"));
button.setToolTipText(Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio"));
button.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
CoverReportPane.showShareConfig(creator.toData());
}
});
toggleButton = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/edit_lock.png"));
initButtonStyle(toggleButton);
toggleButton.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/edit_unlock.png"));
toggleButton.setToolTipText(Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio"));
toggleButton.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
JToggleButton toggleBtn = (JToggleButton) e.getSource(); JToggleButton toggleBtn = (JToggleButton) e.getSource();
String toolTipText = toggleBtn.isSelected() ? Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio") : Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio"); String toolTipText = toggleBtn.isSelected() ? Toolkit.i18nText("Fine-Design_Form_Lock_Widget_Ratio") : Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio");
toggleBtn.setToolTipText(toolTipText); toggleBtn.setToolTipText(toolTipText);
creator.toData().setAspectRatioLocked(toggleBtn.isSelected());
designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_RESIZED);
} }
}); });
return button;
firstLabel = createLabel();
secondLabel = createLabel();
add(editButton);
add(toggleButton);
add(settingButton);
add(firstLabel);
add(secondLabel);
} }
protected LayoutManager getCustomLayout() { private JButton createSettingButton() {
return new LayoutManager() { JButton settingButton = createNormalButton(IOUtils.readIcon("/com/fr/design/images/control/show_setting.png"), Toolkit.i18nText("Fine-Design_Share_Help_Settings"));
settingButton.addActionListener(new ActionListener() {
@Override @Override
public void removeLayoutComponent(Component comp) { public void actionPerformed(ActionEvent e) {
CoverReportPane.showShareConfig(creator.toData());
} }
});
return settingButton;
}
@Override private void addButton(JComponent component, int index) {
public Dimension preferredLayoutSize(Container parent) { buttons.add(index, component);
return defaultDimension; if (index > 0) {
} this.add(new SeparatorLabel(), index * 2 - 1);
}
this.add(component, index * 2);
}
@Override private void setButtonVisible(JComponent component, boolean visible) {
public Dimension minimumLayoutSize(Container parent) { int index = buttons.indexOf(component);
return null;
}
@Override boolean hasVisibleButtonBeforeCurrent = false;
public void layoutContainer(Container parent) { for (int i = 0; i < index; i++) {
int width = parent.getPreferredSize().width; if (buttons.get(i).isVisible()) {
int buttonWidth = editButton.getPreferredSize().width; hasVisibleButtonBeforeCurrent = true;
int buttonHeight = editButton.getPreferredSize().height; break;
int x = (width - buttonWidth) / 2;
editButton.setBounds(x, V_GAP, buttonWidth, buttonHeight);
firstLabel.setBounds(x, V_GAP + editButton.getHeight() + V_GAP / 2, buttonWidth, buttonHeight);
toggleButton.setBounds(x, V_GAP * 2 + editButton.getHeight(), buttonWidth, buttonHeight);
if (creator.isShared()) {
secondLabel.setBounds(x, V_GAP * 2 + editButton.getHeight() + toggleButton.getHeight() + V_GAP / 2, buttonWidth, buttonHeight);
settingButton.setBounds(x, V_GAP * 3 + editButton.getHeight() + toggleButton.getHeight(), buttonWidth, buttonHeight);
}
} }
}
@Override if (hasVisibleButtonBeforeCurrent) {
public void addLayoutComponent(String name, Component comp) { buttons.get(index).setVisible(visible);
getComponent(2 * index - 1).setVisible(visible);
return;
}
// 在当前按钮之前没有可见的按钮了
if (index > 0) {
getComponent(2 * index - 1).setVisible(false);
}
buttons.get(index).setVisible(true);
if (!visible) {
// 如果当前按钮设置为不可见,且在当前按钮之前的其他按钮也不可见,则下一个可见按钮前无分割线
for (int i = index + 1; i < buttons.size(); i++) {
if (buttons.get(i).isVisible()) {
if (i > 0) {
getComponent(2 * i - 1).setVisible(false);
}
break;
}
} }
}; }
} }
private JButton createNormalButton(Icon icon, String toolTipText) { private JButton createNormalButton(Icon icon, String toolTipText) {
JButton button = new JButton(icon); JButton button = new JButton(icon);
button.setPreferredSize(new Dimension(BUTTON_SIZE + 2 * BUTTON_MARGIN, BUTTON_SIZE + 2 * BUTTON_MARGIN));
button.setBorder(BorderFactory.createEmptyBorder(BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN));
initButtonStyle(button); initButtonStyle(button);
button.setToolTipText(toolTipText); button.setToolTipText(toolTipText);
return button; return button;
} }
private void initButtonStyle(AbstractButton button) { private void initButtonStyle(AbstractButton button) {
button.setPreferredSize(new Dimension(BUTTON_SIZE + 2 * BUTTON_MARGIN, BUTTON_SIZE + 2 * BUTTON_MARGIN));
button.setBorder(BorderFactory.createEmptyBorder(BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN, BUTTON_MARGIN));
button.setBorderPainted(false); button.setBorderPainted(false);
button.setBorder(null);
button.setMargin(new Insets(0, 0, 0, 0));
button.setContentAreaFilled(false); button.setContentAreaFilled(false);
} }
private UILabel createLabel() {
return new UILabel() {
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.WHITE);
g2d.drawLine(H_GAP, 0, toggleButton.getWidth() - H_GAP, 0);
}
};
}
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
@ -188,4 +191,41 @@ public class PopupControlPanel extends JPanel {
this.rectangle = rectangle; this.rectangle = rectangle;
} }
public void updatePane(FormDesigner designer) {
setButtonVisible(settingButton, creator.isShared());
setButtonVisible(toggleButton, AdapterBus.searchLayoutAdapter(designer, creator) instanceof FRAbsoluteLayoutAdapter);
toggleButton.setSelected(creator.toData().isAspectRatioLocked());
updateDimension();
}
private void updateDimension() {
int height = 0;
for (int i = 0; i < buttons.size(); i++) {
JComponent component = buttons.get(i);
if (component.isVisible()) {
if (i > 0) {
height += 1;
}
height += component.getHeight();
}
}
height += 2;
defaultDimension.height = height;
}
private static class SeparatorLabel extends UILabel {
public SeparatorLabel() {
setPreferredSize(new Dimension(PANE_WIDTH, 1));
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.WHITE);
g2d.drawLine(BUTTON_MARGIN, 0, getWidth() - BUTTON_MARGIN, 0);
}
}
} }

5
designer-form/src/main/java/com/fr/design/designer/ui/SelectedPopupDialog.java

@ -29,6 +29,11 @@ public class SelectedPopupDialog extends JDialog {
this.setSize(controlPanel.getDefaultDimension()); this.setSize(controlPanel.getDefaultDimension());
} }
public void updatePane(FormDesigner designer) {
controlPanel.updatePane(designer);
this.setSize(controlPanel.getDefaultDimension());
}
public void setRelativeBounds(Rectangle rectangle) { public void setRelativeBounds(Rectangle rectangle) {
this.controlPanel.setRelativeBounds(rectangle); this.controlPanel.setRelativeBounds(rectangle);
} }

5
designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java

@ -110,6 +110,11 @@ public class FormCreatorDropTarget extends DropTarget {
//图表埋点 //图表埋点
dealChartBuryingPoint(widget); dealChartBuryingPoint(widget);
if (addingXCreator.isShared()) { if (addingXCreator.isShared()) {
if (container.acceptType(XWAbsoluteLayout.class)) {
// 绝对布局中新添加的共享组件默认锁定尺寸比例
addingXCreator.toData().setAspectRatioLocked(true);
}
String shareId = addingXCreator.getShareId(); String shareId = addingXCreator.getShareId();
SharableEditorProvider sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(shareId); SharableEditorProvider sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(shareId);
SharableWidgetProvider bindInfo = ShareLoader.getLoader().getElCaseBindInfoById(shareId); SharableWidgetProvider bindInfo = ShareLoader.getLoader().getElCaseBindInfoById(shareId);

4
designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

@ -251,7 +251,7 @@ public class WidgetBoundPane extends BasicPane {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) {
mHeightSpinner.setValue(mWidthSpinner.getValue() * width4Backup / height4Backup, false); mHeightSpinner.setValue(mWidthSpinner.getValue() * height4Backup / width4Backup, false);
} }
} }
}); });
@ -259,7 +259,7 @@ public class WidgetBoundPane extends BasicPane {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) { if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) {
mWidthSpinner.setValue(mHeightSpinner.getValue() * height4Backup / width4Backup, false); mWidthSpinner.setValue(mHeightSpinner.getValue() * width4Backup / height4Backup, false);
} }
} }
}); });

Loading…
Cancel
Save