package dikuai;
|
|
import javax.swing.*;
|
import java.awt.*;
|
import java.awt.event.*;
|
import publicway.Fuzhibutton;
|
import zhuye.Shouye;
|
|
/**
|
* 查看/编辑往返点路径页面
|
* 独立的对话框类,用于显示和编辑往返路径
|
*/
|
public class Wangfanpathpage extends JDialog {
|
private static final long serialVersionUID = 1L;
|
|
// 尺寸常量 - 与地块管理页面保持一致
|
private static final int SCREEN_WIDTH = 400;
|
private static final int SCREEN_HEIGHT = 800;
|
|
// 颜色常量
|
private static final Color PRIMARY_COLOR = new Color(46, 139, 87);
|
private static final Color PRIMARY_DARK = new Color(30, 107, 69);
|
private static final Color TEXT_COLOR = new Color(51, 51, 51);
|
private static final Color WHITE = Color.WHITE;
|
private static final Color BORDER_COLOR = new Color(200, 200, 200);
|
private static final Color BACKGROUND_COLOR = new Color(250, 250, 250);
|
|
private String result = null;
|
|
public Wangfanpathpage(Window owner, String title, String initialValue, Dikuai dikuai) {
|
super(owner, title, Dialog.ModalityType.APPLICATION_MODAL);
|
initializeUI(title, initialValue, dikuai);
|
}
|
|
public String getResult() {
|
return result;
|
}
|
|
private void initializeUI(String title, String initialValue, Dikuai dikuai) {
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
getContentPane().setLayout(new BorderLayout());
|
getContentPane().setBackground(BACKGROUND_COLOR);
|
|
JPanel contentPanel = new JPanel();
|
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
|
contentPanel.setBackground(BACKGROUND_COLOR);
|
contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 16, 12, 16));
|
|
// 标题
|
String landName = dikuai != null ? (dikuai.getLandName() != null ? dikuai.getLandName() : "未知地块") : "未知地块";
|
String landNumber = dikuai != null ? (dikuai.getLandNumber() != null ? dikuai.getLandNumber() : "未知编号") : "未知编号";
|
JLabel headerLabel = new JLabel(landName + " / " + landNumber);
|
headerLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
|
headerLabel.setForeground(TEXT_COLOR);
|
headerLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
contentPanel.add(headerLabel);
|
contentPanel.add(Box.createVerticalStrut(12));
|
|
// 1. 原始往返路径坐标区域
|
String rawCoords = dikuai != null ? prepareCoordinateForEditor(dikuai.getReturnPathRawCoordinates()) : "";
|
int rawCount = 0;
|
if (rawCoords != null && !rawCoords.isEmpty() && !"-1".equals(rawCoords)) {
|
rawCount = rawCoords.split(";").length;
|
}
|
JTextArea rawTextArea = createInfoTextArea(rawCoords, false, 4);
|
contentPanel.add(createTextAreaSection("原始往返路径坐标 (" + rawCount + "点)", rawTextArea));
|
|
// 2. 优化后往返路径坐标区域
|
String optCoords = prepareCoordinateForEditor(initialValue);
|
int optCount = 0;
|
if (optCoords != null && !optCoords.isEmpty() && !"-1".equals(optCoords)) {
|
optCount = optCoords.split(";").length;
|
}
|
JTextArea optTextArea = createInfoTextArea(optCoords, true, 4);
|
contentPanel.add(createTextAreaSection("优化后往返路径坐标 (" + optCount + "点)", optTextArea));
|
|
JScrollPane dialogScrollPane = new JScrollPane(contentPanel);
|
dialogScrollPane.setBorder(BorderFactory.createEmptyBorder());
|
dialogScrollPane.getVerticalScrollBar().setUnitIncrement(16);
|
add(dialogScrollPane, BorderLayout.CENTER);
|
|
// 按钮面板
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 12, 12));
|
buttonPanel.setBackground(BACKGROUND_COLOR);
|
|
JButton goDrawBtn = createPrimaryFooterButton("去绘制");
|
JButton closeBtn = createPrimaryFooterButton("关闭");
|
|
goDrawBtn.addActionListener(e -> {
|
String currentText = optTextArea.getText();
|
if (currentText != null && !currentText.trim().isEmpty() && !"-1".equals(currentText.trim())) {
|
result = "__OPEN_DRAW_PAGE_REFRESH__";
|
} else {
|
result = "__OPEN_DRAW_PAGE__";
|
}
|
dispose();
|
});
|
|
closeBtn.addActionListener(e -> dispose());
|
|
buttonPanel.add(goDrawBtn);
|
buttonPanel.add(closeBtn);
|
add(buttonPanel, BorderLayout.SOUTH);
|
|
pack();
|
setSize(SCREEN_WIDTH, SCREEN_HEIGHT); // 设置为固定尺寸
|
setLocationRelativeTo(getOwner());
|
}
|
|
private String prepareCoordinateForEditor(String value) {
|
if (value == null) {
|
return "";
|
}
|
String trimmed = value.trim();
|
if (trimmed.isEmpty() || "-1".equals(trimmed)) {
|
return "";
|
}
|
return trimmed;
|
}
|
|
private JTextArea createInfoTextArea(String text, boolean editable, int rows) {
|
JTextArea area = new JTextArea(text);
|
area.setEditable(editable);
|
area.setLineWrap(true);
|
area.setWrapStyleWord(true);
|
area.setFont(new Font("微软雅黑", Font.PLAIN, 13));
|
area.setRows(Math.max(rows, 2));
|
area.setCaretPosition(0);
|
area.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
|
area.setBackground(editable ? WHITE : new Color(245, 245, 245));
|
return area;
|
}
|
|
private JPanel createTextAreaSection(String title, JTextArea textArea) {
|
JPanel section = new JPanel(new BorderLayout(0, 6));
|
section.setBackground(BACKGROUND_COLOR);
|
section.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
// 创建标题面板,包含标题和复制图标
|
JPanel titlePanel = new JPanel(new BorderLayout());
|
titlePanel.setBackground(BACKGROUND_COLOR);
|
titlePanel.setOpaque(false);
|
|
JLabel titleLabel = new JLabel(title);
|
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
titleLabel.setForeground(TEXT_COLOR);
|
titlePanel.add(titleLabel, BorderLayout.WEST);
|
|
// 创建复制按钮(使用 Fuzhibutton)
|
JButton copyButton = Fuzhibutton.createCopyButton(
|
() -> {
|
String text = textArea.getText();
|
if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) {
|
return null; // 返回null会触发"未设置"提示
|
}
|
return text;
|
},
|
"复制", // 简化按钮文字,只显示"复制"
|
new Color(230, 250, 240)
|
);
|
// 调整复制按钮样式以匹配
|
copyButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
copyButton.setPreferredSize(new Dimension(50, 24));
|
copyButton.setMargin(new Insets(0,0,0,0));
|
|
titlePanel.add(copyButton, BorderLayout.EAST);
|
|
section.add(titlePanel, BorderLayout.NORTH);
|
|
JScrollPane scrollPane = new JScrollPane(textArea);
|
scrollPane.setBorder(BorderFactory.createLineBorder(BORDER_COLOR));
|
scrollPane.getVerticalScrollBar().setUnitIncrement(12);
|
section.add(scrollPane, BorderLayout.CENTER);
|
|
section.setBorder(BorderFactory.createEmptyBorder(4, 0, 12, 0));
|
return section;
|
}
|
|
private JButton createPrimaryFooterButton(String text) {
|
JButton button = new JButton(text);
|
button.setFont(new Font("微软雅黑", Font.PLAIN, 12));
|
button.setBackground(PRIMARY_COLOR);
|
button.setForeground(WHITE);
|
button.setBorder(BorderFactory.createEmptyBorder(6, 12, 6, 12));
|
button.setFocusPainted(false);
|
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
|
button.addMouseListener(new java.awt.event.MouseAdapter() {
|
public void mouseEntered(java.awt.event.MouseEvent e) {
|
button.setBackground(PRIMARY_DARK);
|
}
|
|
public void mouseExited(java.awt.event.MouseEvent e) {
|
button.setBackground(PRIMARY_COLOR);
|
}
|
});
|
|
return button;
|
}
|
}
|