Browse Source

REPORT-55090【组件背景分离】组件复用-标题图案的图片预览图,和交互文档里定的悬浮时出现删除按钮和不透明遮罩预期效果不同

【问题原因】
插图图片按钮的交互和样式不对,需要重新实现
【改动思路】
【review建议】
feature/10.0
Starryi 3 years ago
parent
commit
4bad4e3734
  1. 69
      designer-form/src/main/java/com/fr/design/gui/xpane/TitleInsetImagePane.java

69
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);
}
}
}

Loading…
Cancel
Save