From 4bad4e373444e6929240285dd45f3937f927cbba Mon Sep 17 00:00:00 2001 From: Starryi Date: Fri, 9 Jul 2021 19:17:14 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55090=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8-=E6=A0=87=E9=A2=98=E5=9B=BE=E6=A1=88?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88=E5=9B=BE=EF=BC=8C?= =?UTF-8?q?=E5=92=8C=E4=BA=A4=E4=BA=92=E6=96=87=E6=A1=A3=E9=87=8C=E5=AE=9A?= =?UTF-8?q?=E7=9A=84=E6=82=AC=E6=B5=AE=E6=97=B6=E5=87=BA=E7=8E=B0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8C=89=E9=92=AE=E5=92=8C=E4=B8=8D=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E9=81=AE=E7=BD=A9=E9=A2=84=E6=9C=9F=E6=95=88=E6=9E=9C=E4=B8=8D?= =?UTF-8?q?=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 插图图片按钮的交互和样式不对,需要重新实现 【改动思路】 【review建议】 --- .../design/gui/xpane/TitleInsetImagePane.java | 69 ++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/gui/xpane/TitleInsetImagePane.java b/designer-form/src/main/java/com/fr/design/gui/xpane/TitleInsetImagePane.java index e3b3c00f4..b7161cbfb 100644 --- a/designer-form/src/main/java/com/fr/design/gui/xpane/TitleInsetImagePane.java +++ b/designer-form/src/main/java/com/fr/design/gui/xpane/TitleInsetImagePane.java @@ -33,6 +33,10 @@ import javax.swing.plaf.basic.BasicButtonUI; 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 java.awt.geom.RoundRectangle2D; /** * @author Starryi @@ -89,6 +93,28 @@ public class TitleInsetImagePane extends JPanel implements UIObserver { deletableImagePreviewPane.add(imageDeleteButton, 0); deletableImagePreviewPane.add(imagePreviewPane, 1); + imageDeleteButton.setVisible(false); + imageDeleteButton.setEnabled(false); + deletableImagePreviewPane.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + super.mouseEntered(e); + imageDeleteButton.setVisible(true); + imageDeleteButton.setEnabled(true); + } + + @Override + public void mouseExited(MouseEvent e) { + super.mouseExited(e); + int x = e.getX(); + int y = e.getY(); + if (x <= 0 || getWidth() <= x || y <= 0 || y >= getHeight()) { + imageDeleteButton.setVisible(false); + imageDeleteButton.setEnabled(false); + } + } + }); + return TableLayoutHelper.createCommonTableLayoutPane( new JComponent[][]{ {null, deletableImagePreviewPane}, @@ -110,15 +136,11 @@ public class TitleInsetImagePane extends JPanel implements UIObserver { private void initComponents() { imageChooseButton = new UIButton(IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_choose_inset.png")); - imageDeleteButton = new UIButton(IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_delete_inset.png")); - imageDeleteButton.setUI(new BasicButtonUI()); - imageDeleteButton.setOpaque(true); - imageDeleteButton.setBorderPainted(false); - imageDeleteButton.setBorder(null); - imageDeleteButton.setFocusPainted(false); - imageDeleteButton.setContentAreaFilled(true); + imageDeleteButton = new OpaqueColorButton( + IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_delete_inset.png"), + new Color(51, 51, 52, 178), + 2); imageDeleteButton.setPreferredSize(new Dimension(DELETE_BUTTON_SIZE, DELETE_BUTTON_SIZE)); - imageDeleteButton.setBackground(new Color(51, 51, 51)); imagePreviewPane = new ImagePreviewPane(); imagePreviewPane.setImageStyle(DEFAULT_IMAGE_LAYOUT_STYLE); @@ -255,4 +277,35 @@ public class TitleInsetImagePane extends JPanel implements UIObserver { public boolean shouldResponseChangeListener() { return true; } + + private static class OpaqueColorButton extends UIButton { + private final Color color; + private final int radius; + + public OpaqueColorButton(Icon icon, Color color, int radius) { + super(icon); + setUI(new BasicButtonUI()); + setOpaque(true); + setBorderPainted(false); + setBorder(null); + setFocusPainted(false); + setContentAreaFilled(false); + this.color = color; + this.radius = radius; + } + + @Override + public void paint(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + Color oldColor = g2d.getColor(); + + Shape shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), radius, radius); + g2d.clip(shape); + g2d.setColor(color); + g2d.fillRect(0, 0, getWidth(), getHeight()); + + g2d.setColor(oldColor); + super.paint(g); + } + } }