Browse Source

Merge pull request #4972 in DESIGN/design from feature/10.0 to release/11.0

* commit '0864ef891f3b80b140375277adb8810f71c0f2e9':
  REPORT-55187【组件背景分离】组件复用-body和参数面板里的控件(frm参面和body 以及 cpt参面),应该也有只显示锁按钮的工具栏,现在是没有工具栏的
  REPORT-54374 拖拽修改tab里的绝对画布块高度,绝对画布块错乱 右侧设置面板修改高度,绝对画布块内部组件位移成画布块
  REPORT-53175 【10.0.18】组件背景分离为标题/背景/边框
  REPORT-55211【组件背景分离】组件复用-图表块取消勾选标题可见,设置的主体背景(颜色/渐变色/图片),在设计界面里会遮盖住图表,可见图。web效果正常
  REPORT-53175 【10.0.18】组件背景分离为标题/背景/边框
  REPORT-53130 npe判断
  REPORT-53130 避免组件配置面板界面在点击当前组件的时候被重置到属性面板
fix-lag
superman 3 years ago
parent
commit
f3681c49aa
  1. BIN
      designer-base/src/main/resources/com/fr/design/images/control/aspect_ratio_lock.png
  2. BIN
      designer-base/src/main/resources/com/fr/design/images/control/aspect_ratio_unlock.png
  3. BIN
      designer-base/src/main/resources/com/fr/design/images/transparent_background.jpg
  4. 8
      designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java
  5. 8
      designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java
  6. 13
      designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java
  7. 11
      designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java
  8. 2
      designer-form/src/main/java/com/fr/design/designer/creator/XCreator.java
  9. 21
      designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java
  10. 19
      designer-form/src/main/java/com/fr/design/designer/ui/PopupControlPanel.java
  11. 4
      designer-form/src/main/java/com/fr/design/designer/ui/SelectedPopupDialog.java
  12. 246
      designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java
  13. 7
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  14. 2
      designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java
  15. 4
      designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java

BIN
designer-base/src/main/resources/com/fr/design/images/control/aspect_ratio_lock.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
designer-base/src/main/resources/com/fr/design/images/control/aspect_ratio_unlock.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

BIN
designer-base/src/main/resources/com/fr/design/images/transparent_background.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

8
designer-form/src/main/java/com/fr/design/designer/beans/models/SelectionModel.java

@ -30,6 +30,7 @@ import com.fr.design.utils.ComponentUtils;
import com.fr.design.utils.gui.LayoutUtils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import java.awt.LayoutManager;
import java.awt.Rectangle;
@ -83,7 +84,14 @@ public class SelectionModel {
XCreator comp = designer.getComponentAt(e);
if (e.getButton() == MouseEvent.BUTTON3 || (!InputEventBaseOnOS.isControlDown(e) && !e.isShiftDown())) {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
XCreator selectXCreator = selection.getSelectedCreator();
if (selectXCreator != null && comp != null) {
if (StringUtils.equals(selectXCreator.toData().getWidgetName(), comp.toData().getWidgetName())) {
return;
}
}
selection.reset();
} else {
//按下Ctrl或者shift键时鼠标可以进行多选,两次点击同一控件就取消选中
XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer(comp).getTopLayout();

8
designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java

@ -18,8 +18,7 @@ import com.fr.stable.bridge.StableFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
@ -102,7 +101,8 @@ public class XAutoChartCreator extends XChartEditor {
}
public void paint(Graphics g) {
@Override
public void paintForeground(Graphics2D g) {
BufferedImage bufferedImage = IOUtils.readImage("com/fr/design/form/images/auto_chart_preview.png");
GraphHelper.paintImage(
g, this.getWidth(), this.getHeight(), bufferedImage,
@ -110,7 +110,7 @@ public class XAutoChartCreator extends XChartEditor {
0,
0, -1, -1
);
super.paint(g);
super.paintForeground(g);
}
private void initChart(BaseChartCollection chartCollection) {

13
designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java

@ -222,24 +222,23 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{
}
// 设计器预览界面中绘制组件背景效果
private void paintBackground(Graphics2D g2d) {
public void paintBackground(Graphics2D g2d) {
Background background4Painting = getBackground4Painting();
if (background4Painting != null) {
background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
}
}
@Override
protected void paintComponent(Graphics g) {
this.paintBackground((Graphics2D) g);
super.paintComponent(g);
public void paintForeground(Graphics2D g2d) {
super.paint(g2d);
super.paintBorder(g2d);
}
@Override
public void paint(Graphics g) {
this.clipByRoundedBorder((Graphics2D) g);
super.paint(g);
paintBorder(g);
this.paintBackground((Graphics2D) g);
this.paintForeground((Graphics2D) g);
}
@Override

11
designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java

@ -29,12 +29,8 @@ import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.beans.IntrospectionException;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
/**
@ -228,7 +224,8 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
/**
* 渲染Painter
*/
public void paint(Graphics g) {
@Override
public void paintForeground(Graphics2D g) {
Dimension size = getSize();
PaddingMargin margin = toData().getMargin();
designerEditor.paintEditor(g, size, margin);
@ -237,7 +234,7 @@ public class XChartEditor extends XBorderStyleWidgetCreator {
int verticalMargin = margin != null ? margin.getTop() + margin.getBottom() : 0;
coverPanel.setSize(size.width - horizonMargin, size.height - verticalMargin);
}
super.paint(g);
super.paintForeground(g);
if (isEditing) {
g.setColor(INNER_BORDER_COLOR);
GraphHelper.draw(g, new Rectangle(0, 0, getWidth(), getHeight()), Constants.LINE_MEDIUM);

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

@ -778,7 +778,7 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo
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.setVisible(selected && accept && popup.hasVisibleButtons());
popup.setRelativeBounds(bounds);
}

21
designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java

@ -758,6 +758,11 @@ public class XWFitLayout extends XLayoutContainer {
int[] veris = getVeris(true);
int containerWidth = 0;
int containerHeight = 0;
PaddingMargin margin = toData().getMargin();
int maxW = this.getWidth() - margin.getRight();
int maxH = this.getHeight() - margin.getBottom();
for (int index=0, n=this.getComponentCount(); index<n; index++) {
XCreator creator = (XCreator) this.getComponent(index);
BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData());
@ -793,6 +798,14 @@ public class XWFitLayout extends XLayoutContainer {
BoundsWidget wgt = (BoundsWidget) layout.getBoundsWidget(creator.toData());
//如果子组件是绝对布局,则内部的widget也要更新
if (creator.acceptType(XWAbsoluteLayout.class)){
// backupBounds处理下内边距 否则计算缩放比例时总是存在一个内边距的误差
if (creator.getBackupBound() != null) {
Rectangle backUpBound = creator.getBackupBound();
processContainerMargin(margin, backUpBound, maxW, maxH);
creator.setBackupBound(backUpBound);
}
//更新的时候一定要带上backupBound
if (creator.getBackupBound() == null && wgt.getBeforeScaleBounds() != null) {
creator.setBackupBound(dealWgtBound(wgt.getBeforeScaleBounds()));
@ -1064,6 +1077,12 @@ public class XWFitLayout extends XLayoutContainer {
for (int i=0; i<num; i++) {
Component comp = this.getComponent(i);
Rectangle rec = comp.getBounds();
processContainerMargin(margin, rec, maxW, maxH);
comp.setBounds(rec);
}
}
private void processContainerMargin(PaddingMargin margin, Rectangle rec, int maxW, int maxH) {
if (rec.x == margin.getLeft()) {
rec.x = 0;
rec.width += margin.getLeft();
@ -1078,8 +1097,6 @@ public class XWFitLayout extends XLayoutContainer {
if (rec.y + rec.height == maxH) {
rec.height += margin.getBottom();
}
comp.setBounds(rec);
}
}
public Component getTopComp(int x, int y) {

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

@ -4,6 +4,7 @@ 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.XWTitleLayout;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.VerticalFlowLayout;
@ -58,7 +59,7 @@ public class PopupControlPanel extends JPanel {
addButton(toggleButton, 1);
addButton(settingButton, 2);
setButtonVisible(editButton, true);
setButtonVisible(editButton, false);
setButtonVisible(toggleButton, false);
setButtonVisible(settingButton, false);
}
@ -81,9 +82,9 @@ public class PopupControlPanel extends JPanel {
}
private JToggleButton createAspectRatioLockedButton(FormDesigner designer) {
JToggleButton button = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/edit_unlock.png"));
JToggleButton button = new JToggleButton(IOUtils.readIcon("/com/fr/design/images/control/aspect_ratio_unlock.png"));
initButtonStyle(button);
button.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/edit_lock.png"));
button.setSelectedIcon(IOUtils.readIcon("com/fr/design/images/control/aspect_ratio_lock.png"));
button.setToolTipText(Toolkit.i18nText("Fine-Design_Form_UnLock_Widget_Ratio"));
button.addActionListener(new ActionListener() {
@Override
@ -139,7 +140,7 @@ public class PopupControlPanel extends JPanel {
if (index > 0) {
getComponent(2 * index - 1).setVisible(false);
}
buttons.get(index).setVisible(true);
buttons.get(index).setVisible(visible);
if (!visible) {
// 如果当前按钮设置为不可见,且在当前按钮之前的其他按钮也不可见,则下一个可见按钮前无分割线
@ -192,6 +193,7 @@ public class PopupControlPanel extends JPanel {
}
public void updatePane(FormDesigner designer) {
setButtonVisible(editButton, creator.acceptType(XWTitleLayout.class));
setButtonVisible(settingButton, creator.isShared());
setButtonVisible(toggleButton, AdapterBus.searchLayoutAdapter(designer, creator) instanceof FRAbsoluteLayoutAdapter);
toggleButton.setSelected(creator.toData().isAspectRatioLocked());
@ -199,6 +201,15 @@ public class PopupControlPanel extends JPanel {
updateDimension();
}
public boolean hasVisibleButtons() {
for (int i = 0; i < buttons.size(); i++) {
if (buttons.get(i).isVisible()) {
return true;
}
}
return false;
}
private void updateDimension() {
int height = 0;
for (int i = 0; i < buttons.size(); i++) {

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

@ -34,6 +34,10 @@ public class SelectedPopupDialog extends JDialog {
this.setSize(controlPanel.getDefaultDimension());
}
public boolean hasVisibleButtons() {
return controlPanel.hasVisibleButtons();
}
public void setRelativeBounds(Rectangle rectangle) {
this.controlPanel.setRelativeBounds(rectangle);
}

246
designer-form/src/main/java/com/fr/design/gui/xpane/BorderLineAndImagePane.java

@ -20,6 +20,7 @@ import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.ibutton.UIColorButton;
import com.fr.design.gui.icombobox.LineComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
@ -44,11 +45,13 @@ import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Line2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URI;
@ -65,7 +68,7 @@ import java.util.Arrays;
public class BorderLineAndImagePane extends JPanel implements UIObserver {
private final int SETTING_LABEL_WIDTH = LayoutStylePane.SETTING_LABEL_WIDTH;
private final Style DEFAULT_IMAGE_LAYOUT_STYLE = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_DEFAULT);
private final String TWEAK_NINE_POINT_HELP_URL = "";
private final String TWEAK_NINE_POINT_HELP_URL = "https://help.fanruan.com/finereport/doc-view-4135.html";
private UIObserverListener uiObserverListener;
@ -415,18 +418,11 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
private void initComponents() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Style_Border_Image_Config_Nine_Point_Fill_Preview")));
setBorder(BorderFactory.createEmptyBorder());
add(previewPane, BorderLayout.CENTER);
JPanel content = FRGUIPaneFactory.createBorderLayout_S_Pane();
content.setBorder(BorderFactory.createEmptyBorder(
IntervalConstants.INTERVAL_W1,
IntervalConstants.INTERVAL_W1,
IntervalConstants.INTERVAL_W1,
IntervalConstants.INTERVAL_W1));
content.add(previewPane);
previewPane.setPreferredSize(new Dimension(611, 457));
add(content, BorderLayout.CENTER);
previewPane.setPreferredSize(new Dimension(615, 462));
previewPane.setBorder(BorderFactory.createEmptyBorder());
}
@Override
@ -436,18 +432,23 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
}
private class NinePointLinePreviewPane extends JPanel implements MouseMotionListener, MouseListener {
private final BufferedImage transparentImage = IOUtils.readImage("/com/fr/design/images/transparent_background.jpg");
public final Color PATCH_COLOR = new Color(0, 0, 0, 38);
public final Color DIVIDER_COLOR = new Color(250, 250, 250);
public final Color TEXT_COLOR = Color.WHITE;
public final int PADDING = 15;
public final Color BACKGROUND_PANE_COLOR = Color.WHITE;
public final Color BACKGROUND_IMG_COLOR = Color.lightGray;
public final Color DIVIDER_BACKGROUND_COLOR = Color.WHITE;
public final Color DIVIDER_FOREGROUND_COLOR = Color.BLACK;
public final Color HINT_BACKGROUND_COLOR = new Color(255, 255, 255, 100);
public final Color HINT_FOREGROUND_COLOR = Color.RED;
public final Color HINT_LINE_BACKGROUND_COLOR = Color.WHITE;
public final Color HINT_LINE_FOREGROUND_COLOR = Color.RED;
public final int PADDING = 20;
private int ninePointLeft = -1;
private int ninePointTop = -1;
private int ninePointRight = -1;
private int ninePointBottom = -1;
private static final int MIN_NINE_POINT = 0;
private int imgWidth;
private int imgHeight;
private int scaleImgWidth;
@ -456,9 +457,52 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
private int scaleImgY;
private double scale = 1.0;
private final UIIntNumberField topField = createNumberField();
private final UIIntNumberField bottomField = createNumberField();
private final UIIntNumberField leftField = createNumberField();
private final UIIntNumberField rightField = createNumberField();
public NinePointLinePreviewPane() {
this.setLayout(null);
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setFocusable(true);
this.add(topField);
this.add(bottomField);
this.add(leftField);
this.add(rightField);
topField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int value = (int) topField.getValue();
onNinePointTopChanged(value);
}
});
bottomField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int value = (int) bottomField.getValue();
onNinePointBottomChanged(value);
}
});
leftField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int value = (int) leftField.getValue();
onNinePointLeftChanged(value);
}
});
rightField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int value = (int) rightField.getValue();
onNinePointRightChanged(value);
}
});
}
@Override
@ -466,7 +510,9 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(transparentImage, 0, 0, getWidth(), getHeight(), null);
g2d.setColor(BACKGROUND_PANE_COLOR);
g2d.fillRect(0, 0, getWidth(), getHeight());
Image image = imagePreviewPane.getImage();
@ -491,6 +537,8 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
scale = 1.0 * scaleImgHeight / imgHeight;
}
g2d.setColor(BACKGROUND_IMG_COLOR);
g2d.fillRect(scaleImgX, scaleImgY, scaleImgWidth, scaleImgHeight);
g2d.drawImage(image, scaleImgX, scaleImgY, scaleImgWidth, scaleImgHeight, null);
int scaleLeft = (int) (ninePointLeft * scale);
@ -503,28 +551,45 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
double leftXInPane = scaleImgX + scaleLeft;
double rightXInPane = scaleImgX + scaleImgWidth - scaleRight;
g2d.setColor(PATCH_COLOR);
// draw horizontal patch
GraphDrawHelper.fillRect(g2d, 0, topYInPane, getWidth(), scaleImgHeight - scaleTop - scaleBottom);
// draw vertical patch
GraphDrawHelper.fillRect(g2d, scaleImgX + scaleLeft, 0,scaleImgWidth - scaleLeft - scaleRight, getHeight());
g2d.setColor(DIVIDER_COLOR);
// draw top divider
GraphDrawHelper.drawLine(g2d, 0, topYInPane, getWidth(), topYInPane);
// draw bottom divider
GraphDrawHelper.drawLine(g2d, 0, bottomYInPane, getWidth(), bottomYInPane);
// draw left divider
GraphDrawHelper.drawLine(g2d, leftXInPane, 0, leftXInPane, getHeight());
// draw right divider
GraphDrawHelper.drawLine(g2d, rightXInPane, 0, rightXInPane, getHeight());
g2d.setColor(TEXT_COLOR);
// draw nine point info
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointTop), (leftXInPane + rightXInPane) / 2.0F, topYInPane / 2.0);
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointBottom), (leftXInPane + rightXInPane) / 2.0F, (bottomYInPane + getHeight()) / 2.0);
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointLeft), leftXInPane / 2.0, (topYInPane + bottomYInPane) / 2.0);
GraphDrawHelper.drawString(g2d, Integer.toString(ninePointRight), (rightXInPane + getWidth()) / 2.0, (topYInPane + bottomYInPane) / 2.0);
// 绘制分割线
// 顶部
drawLine(g2d, DIVIDER_BACKGROUND_COLOR, DIVIDER_FOREGROUND_COLOR, scaleImgX, topYInPane, scaleImgX + scaleImgWidth, topYInPane);
// 底部
drawLine(g2d, DIVIDER_BACKGROUND_COLOR, DIVIDER_FOREGROUND_COLOR, scaleImgX, bottomYInPane, scaleImgX + scaleImgWidth, bottomYInPane);
// 左侧
drawLine(g2d, DIVIDER_BACKGROUND_COLOR, DIVIDER_FOREGROUND_COLOR, leftXInPane, scaleImgY, leftXInPane, scaleImgY + scaleImgHeight);
// 右侧
drawLine(g2d, DIVIDER_BACKGROUND_COLOR, DIVIDER_FOREGROUND_COLOR, rightXInPane, scaleImgY, rightXInPane, scaleImgY + scaleImgHeight);
// 绘制分割线位置提示
// 顶部
drawLine(g2d, HINT_LINE_BACKGROUND_COLOR, HINT_LINE_FOREGROUND_COLOR, (leftXInPane + rightXInPane) / 2.0F, scaleImgY, (leftXInPane + rightXInPane) / 2.0F, topYInPane);
drawHint(g2d, Integer.toString(ninePointTop), (leftXInPane + rightXInPane) / 2.0F, (scaleImgY + topYInPane) / 2.0, topField);
// 底部
drawLine(g2d, HINT_LINE_BACKGROUND_COLOR, HINT_LINE_FOREGROUND_COLOR, (leftXInPane + rightXInPane) / 2.0F, bottomYInPane, (leftXInPane + rightXInPane) / 2.0F, scaleImgY + scaleImgHeight);
drawHint(g2d, Integer.toString(ninePointBottom), (leftXInPane + rightXInPane) / 2.0F, (bottomYInPane + scaleImgY + scaleImgHeight) / 2.0, bottomField);
// 左侧
drawLine(g2d, HINT_LINE_BACKGROUND_COLOR, HINT_LINE_FOREGROUND_COLOR, scaleImgX, (topYInPane + bottomYInPane) / 2.0, leftXInPane, (topYInPane + bottomYInPane) / 2.0);
drawHint(g2d, Integer.toString(ninePointLeft), (scaleImgX + leftXInPane) / 2.0, (topYInPane + bottomYInPane) / 2.0, leftField);
// 右侧
drawLine(g2d, HINT_LINE_BACKGROUND_COLOR, HINT_LINE_FOREGROUND_COLOR, rightXInPane, (topYInPane + bottomYInPane) / 2.0, scaleImgX + scaleImgWidth, (topYInPane + bottomYInPane) / 2.0);
drawHint(g2d, Integer.toString(ninePointRight), (rightXInPane + scaleImgX + scaleImgWidth) / 2.0, (topYInPane + bottomYInPane) / 2.0, rightField);
}
private void drawHint(Graphics2D g2d, String hint, double centerX, double centerY, UIIntNumberField hintField) {
FontMetrics metrics = GraphDrawHelper.getFontMetrics(g2d.getFont());
double height = metrics.getAscent() + metrics.getDescent();
double width = Math.max(metrics.stringWidth(" " + hint + " "), metrics.stringWidth(" 123 "));
hintField.setBounds((int) (centerX - width / 2.0), (int) (centerY - height / 2.0), (int) width, (int) height);
}
private void drawLine(Graphics2D g2d, Color backgroundColor, Color foregroundColor, double x1, double y1, double x2, double y2) {
g2d.setColor(backgroundColor);
GraphDrawHelper.draw(g2d, new Line2D.Double(x1, y1, x2, y2), Constants.LINE_THIN, 2.0F);
g2d.setColor(foregroundColor);
GraphDrawHelper.draw(g2d, new Line2D.Double(x1, y1, x2, y2), Constants.LINE_DASH, 1.0F);
}
@Override
@ -537,34 +602,22 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
switch (cursorType) {
case Cursor.W_RESIZE_CURSOR: {
int nextLeft = (int) ((x - scaleImgX) / scale);
if (1 <= nextLeft && nextLeft < imgWidth - ninePointRight) {
ninePointLeft = nextLeft;
repaint();
}
this.onNinePointLeftChanged(nextLeft);
return;
}
case Cursor.E_RESIZE_CURSOR: {
int nextRight = (int) ((scaleImgX + scaleImgWidth - x) / scale);
if (1 <= nextRight && nextRight < imgWidth - ninePointLeft) {
ninePointRight = nextRight;
repaint();
}
this.onNinePointRightChanged(nextRight);
return;
}
case Cursor.N_RESIZE_CURSOR: {
int nextTop = (int) ((y - scaleImgY) / scale);
if (1 <= nextTop && nextTop < imgHeight - ninePointBottom) {
ninePointTop = nextTop;
repaint();
}
this.onNinePointTopChanged(nextTop);
return;
}
case Cursor.S_RESIZE_CURSOR: {
int nextBottom = (int) ((scaleImgY + scaleImgHeight - y) / scale);
if (1 <= nextBottom && nextBottom < imgHeight - ninePointTop) {
ninePointBottom = nextBottom;
repaint();
}
this.onNinePointBottomChanged(nextBottom);
}
}
}
@ -584,10 +637,17 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
// determine cursor
int cursorType = Cursor.DEFAULT_CURSOR;
boolean hoveringLeftDivider = Math.abs(x - (scaleImgX + scaleLeft)) < 2;
boolean hoveringRightDivider = Math.abs(x - (scaleImgX + scaleImgWidth - scaleRight)) < 2;
boolean hoveringTopDivider = Math.abs(y - (scaleImgY + scaleTop)) < 2;
boolean hoveringBottomDivider = Math.abs(y - (scaleImgY + scaleImgHeight - scaleBottom)) < 2;
boolean hoveringLeftDivider = false;
boolean hoveringRightDivider = false;
boolean hoveringTopDivider = false;
boolean hoveringBottomDivider = false;
if (scaleImgX - 2 <= x && x <= scaleImgX + scaleImgWidth + 2 && scaleImgY - 2 <= y && y <= scaleImgY + scaleImgHeight + 2) {
hoveringLeftDivider = Math.abs(x - (scaleImgX + scaleLeft)) < 2;
hoveringRightDivider = Math.abs(x - (scaleImgX + scaleImgWidth - scaleRight)) < 2;
hoveringTopDivider = Math.abs(y - (scaleImgY + scaleTop)) < 2;
hoveringBottomDivider = Math.abs(y - (scaleImgY + scaleImgHeight - scaleBottom)) < 2;
}
if (hoveringLeftDivider) {
cursorType = Cursor.W_RESIZE_CURSOR;
@ -609,7 +669,7 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
@Override
public void mouseClicked(MouseEvent e) {
requestFocus();
}
@Override
@ -634,12 +694,72 @@ public class BorderLineAndImagePane extends JPanel implements UIObserver {
}
private void onNinePointTopChanged(int value) {
if (value < MIN_NINE_POINT) {
value = MIN_NINE_POINT;
} else if (value >= imgHeight - ninePointBottom) {
value = imgHeight - ninePointBottom - MIN_NINE_POINT;
}
this.ninePointTop = value;
topField.setText(Integer.toString(value));
repaint();
}
private void onNinePointBottomChanged(int value) {
if (value < MIN_NINE_POINT) {
value = MIN_NINE_POINT;
} else if (value >= imgHeight - ninePointTop) {
value = imgHeight - ninePointTop - MIN_NINE_POINT;
}
this.ninePointBottom = value;
bottomField.setText(Integer.toString(value));
repaint();
}
private void onNinePointLeftChanged(int value) {
if (value < MIN_NINE_POINT) {
value = MIN_NINE_POINT;
} else if (value >= imgWidth - ninePointRight) {
value = imgWidth - ninePointRight - MIN_NINE_POINT;
}
this.ninePointLeft = value;
leftField.setText(Integer.toString(value));
repaint();
}
private void onNinePointRightChanged(int value) {
if (value < MIN_NINE_POINT) {
value = MIN_NINE_POINT;
} else if (value >= imgWidth - ninePointLeft) {
value = imgWidth - ninePointLeft - MIN_NINE_POINT;
}
this.ninePointRight = value;
rightField.setText(Integer.toString(value));
repaint();
}
private UIIntNumberField createNumberField() {
UIIntNumberField field = new UIIntNumberField();
field.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
field.setOpaque(true);
field.setMinValue(MIN_NINE_POINT);
field.setForeground(HINT_FOREGROUND_COLOR);
field.setBackground(HINT_BACKGROUND_COLOR);
field.setHorizontalAlignment(SwingConstants.CENTER);
return field;
}
public void setNinePoint(int[] ninePoint) {
ninePointLeft = ninePoint[0];
ninePointTop = ninePoint[1];
ninePointRight = ninePoint[2];
ninePointBottom = ninePoint[3];
leftField.setValue(ninePointLeft);
rightField.setValue(ninePointRight);
topField.setValue(ninePointTop);
bottomField.setValue(ninePointBottom);
}
public int[] getNinePoint() {

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

@ -69,6 +69,7 @@ import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.bridge.StableFactory;
import com.fr.third.javax.annotation.Nullable;
@ -1477,6 +1478,12 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
editingMouseListener.stopEditing();
editingMouseListener.stopEditTopLayout(comp);
XCreator selectXCreator = editingMouseListener.getSelectionModel().getSelection().getSelectedCreator();
if (selectXCreator != null && comp != null) {
if (StringUtils.equals(selectXCreator.toData().getWidgetName(), comp.toData().getWidgetName())) {
return;
}
}
editingMouseListener.getSelectionModel().reset();
editingMouseListener.getSelectionModel().selectACreator(comp);
}

2
designer-form/src/main/java/com/fr/design/mainframe/FormDesignerUI.java

@ -326,7 +326,7 @@ public class FormDesignerUI extends ComponentUI {
}
creator.paintBorder(g, creatorBounds);
// 拖拽时不绘制
creator.showSelectedPopup(designer, creatorBounds, !designer.getStateModel().isDragging() && creator.acceptType(XWTitleLayout.class));
creator.showSelectedPopup(designer, creatorBounds, !designer.getStateModel().isDragging());
}
}

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

@ -277,7 +277,9 @@ public class FormSelection {
for (XCreator creator : selection) {
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter != null) {
if (creator.acceptType(XWAbsoluteLayout.class) && recs.size() > i) {
// 这里处理绝对画布块 仅局限于选中多个组件且其中包含了绝对画布块的情况
boolean accept = creator.acceptType(XWAbsoluteLayout.class) && recs.size() > i && selection.size() > 1;
if (accept) {
Rectangle rectangle = recs.get(i);
check4ParaPane(rectangle);
creator.setBackupBound(rectangle);

Loading…
Cancel
Save