package zhuye;
|
|
import ui.UIConfig;
|
|
import javax.swing.*;
|
|
import publicway.buttonset;
|
|
import java.awt.*;
|
import java.awt.event.*;
|
|
public class AreaSelectionDialog extends JDialog {
|
private final Color THEME_COLOR;
|
private final JLabel areaNameLabel;
|
private final JLabel statusLabel;
|
|
public AreaSelectionDialog(Component parent, Color themeColor, JLabel areaNameLabel, JLabel statusLabel) {
|
super(parent != null ? (JFrame) SwingUtilities.getWindowAncestor(parent) : null,
|
"选择地块", true);
|
this.THEME_COLOR = themeColor;
|
this.areaNameLabel = areaNameLabel;
|
this.statusLabel = statusLabel;
|
// 统一对话框尺寸
|
initializeDialog(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT);
|
initializeAreaContent();
|
if (parent == null) {
|
setLocationRelativeTo(null); // 居中显示
|
}
|
}
|
|
private void initializeDialog(int width, int height) {
|
setSize(width, height);
|
setLocationRelativeTo(getParent());
|
setResizable(false);
|
getContentPane().setBackground(Color.WHITE);
|
}
|
|
private void initializeAreaContent() {
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
|
String[][] areaOptions = {
|
{"🏡", "前院草坪"},
|
{"🌳", "后院草坪"},
|
{"🌷", "花园区域"}
|
};
|
|
for (String[] area : areaOptions) {
|
JButton areaBtn = createAreaButton(area[0], area[1]);
|
contentPanel.add(areaBtn);
|
contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
|
}
|
|
JButton addAreaBtn = buttonset.createStyledButton("➕ 新增地块", THEME_COLOR);
|
addAreaBtn.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
addAreaBtn.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0));
|
addAreaBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
|
addAreaBtn.addActionListener(e -> {
|
JOptionPane.showMessageDialog(this, "打开新增地块功能");
|
});
|
|
contentPanel.add(Box.createVerticalGlue());
|
contentPanel.add(addAreaBtn);
|
|
getContentPane().add(contentPanel);
|
}
|
|
private JButton createAreaButton(String icon, String text) {
|
JButton button = buttonset.createStyledButton("<html><center>" + icon + "<br>" + text + "</center></html>", Color.WHITE);
|
button.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
button.setPreferredSize(new Dimension(250, 80));
|
button.setBackground(Color.WHITE);
|
button.setForeground(new Color(80, 80, 80));
|
button.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(200, 200, 200)),
|
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
));
|
|
button.addMouseListener(new MouseAdapter() {
|
public void mouseEntered(MouseEvent e) {
|
button.setBackground(new Color(240, 250, 240));
|
button.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(THEME_COLOR),
|
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
));
|
}
|
public void mouseExited(MouseEvent e) {
|
button.setBackground(Color.WHITE);
|
button.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(200, 200, 200)),
|
BorderFactory.createEmptyBorder(10, 10, 10, 10)
|
));
|
}
|
});
|
|
button.addActionListener(e -> {
|
areaNameLabel.setText(text);
|
statusLabel.setText("待机");
|
this.dispose();
|
});
|
|
return button;
|
}
|
}
|