张世豪
15 小时以前 ed6936545d20cc490145d2936cee4387be2afd53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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;
    }
}