|
|
|
@ -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 |
|
|
|
@ -40,7 +44,7 @@ import java.awt.event.ActionListener;
|
|
|
|
|
* Created by Starryi on 2021/7/3 |
|
|
|
|
*/ |
|
|
|
|
public class TitleInsetImagePane extends JPanel implements UIObserver { |
|
|
|
|
private final int SETTING_LABEL_WIDTH = 60; |
|
|
|
|
private final int SETTING_LABEL_WIDTH = LayoutStylePane.SETTING_LABEL_WIDTH; |
|
|
|
|
private final int DELETE_BUTTON_SIZE = 24; |
|
|
|
|
private final int IMAGE_PREVIEW_SIZE = 145; |
|
|
|
|
private final Style DEFAULT_IMAGE_LAYOUT_STYLE = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_DEFAULT); |
|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|