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. 216
      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 extraY = (int) (bounds.y * designer.getScale());
popup.setLocation(designer.getLocationOnScreen().x + designer.getPaintX() + extraX, designer.getLocationOnScreen().y + designer.getPaintY() + extraY);
popup.updatePane(designer);
popup.setVisible(selected && accept);
popup.setRelativeBounds(bounds);
}

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

@ -1,35 +1,27 @@
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.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.VerticalFlowLayout;
import com.fr.design.mainframe.CoverReportPane;
import com.fr.design.mainframe.EditingMouseListener;
import com.fr.design.mainframe.FormDesigner;
import com.fr.general.IOUtils;
import com.fr.stable.ArrayUtils;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
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 javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.util.ArrayList;
import java.util.List;
/**
* @author hades
@ -40,25 +32,39 @@ public class PopupControlPanel extends JPanel {
private static final int ARC_VALUE = 4;
private static final Color FILLED_COLOR = new Color(60, 63, 65);
private static final int V_GAP = 10;
private static final int H_GAP = 2;
private static final int BUTTON_SIZE = 16;
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 final List<JComponent> buttons = new ArrayList<>();
private final JButton editButton;
private final JButton settingButton;
private final JToggleButton toggleButton;
private final XCreator creator;
private final UILabel firstLabel;
private final UILabel secondLabel;
public PopupControlPanel(XCreator creator, FormDesigner designer) {
if (creator.isShared()) {
defaultDimension = new Dimension(20, 85);
}
setLayout(getCustomLayout());
setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0));
setBorder(BorderFactory.createEmptyBorder());
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() {
@Override
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
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();
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);
creator.toData().setAspectRatioLocked(toggleBtn.isSelected());
designer.getEditListenerTable().fireCreatorModified(creator, DesignerEvent.CREATOR_RESIZED);
}
});
firstLabel = createLabel();
secondLabel = createLabel();
add(editButton);
add(toggleButton);
add(settingButton);
add(firstLabel);
add(secondLabel);
return button;
}
protected LayoutManager getCustomLayout() {
return new LayoutManager() {
private JButton createSettingButton() {
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
public void removeLayoutComponent(Component comp) {
public void actionPerformed(ActionEvent e) {
CoverReportPane.showShareConfig(creator.toData());
}
});
return settingButton;
}
@Override
public Dimension preferredLayoutSize(Container parent) {
return defaultDimension;
private void addButton(JComponent component, int index) {
buttons.add(index, component);
if (index > 0) {
this.add(new SeparatorLabel(), index * 2 - 1);
}
this.add(component, index * 2);
}
@Override
public Dimension minimumLayoutSize(Container parent) {
return null;
private void setButtonVisible(JComponent component, boolean visible) {
int index = buttons.indexOf(component);
boolean hasVisibleButtonBeforeCurrent = false;
for (int i = 0; i < index; i++) {
if (buttons.get(i).isVisible()) {
hasVisibleButtonBeforeCurrent = true;
break;
}
}
@Override
public void layoutContainer(Container parent) {
int width = parent.getPreferredSize().width;
int buttonWidth = editButton.getPreferredSize().width;
int buttonHeight = editButton.getPreferredSize().height;
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);
if (hasVisibleButtonBeforeCurrent) {
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);
@Override
public void addLayoutComponent(String name, Component comp) {
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) {
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);
button.setToolTipText(toolTipText);
return 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.setBorder(null);
button.setMargin(new Insets(0, 0, 0, 0));
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
protected void paintComponent(Graphics g) {
super.paintComponent(g);
@ -188,4 +191,41 @@ public class PopupControlPanel extends JPanel {
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());
}
public void updatePane(FormDesigner designer) {
controlPanel.updatePane(designer);
this.setSize(controlPanel.getDefaultDimension());
}
public void setRelativeBounds(Rectangle 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);
if (addingXCreator.isShared()) {
if (container.acceptType(XWAbsoluteLayout.class)) {
// 绝对布局中新添加的共享组件默认锁定尺寸比例
addingXCreator.toData().setAspectRatioLocked(true);
}
String shareId = addingXCreator.getShareId();
SharableEditorProvider sharableEditor = ShareLoader.getLoader().getSharedElCaseEditorById(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
public void stateChanged(ChangeEvent e) {
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
public void stateChanged(ChangeEvent e) {
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) {
mWidthSpinner.setValue(mHeightSpinner.getValue() * height4Backup / width4Backup, false);
mWidthSpinner.setValue(mHeightSpinner.getValue() * width4Backup / height4Backup, false);
}
}
});

Loading…
Cancel
Save