张世豪
2025-12-01 d709e6dad60398fd599900cf781d0dd1e8c37c1c
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
package zhangaiwu;
 
import javax.swing.*;
 
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
 
import bianjie.jisuanmianjie;
import dikuai.Dikuai;
import dikuai.Dikuaiguanli;
import gecaoji.Device;
import bianjie.bianjieguihua2;
import lujing.Lunjingguihua;
import ui.UIConfig;
import zhuye.MowerLocationData;
import zhuye.Shouye;
import zhuye.Coordinate;
 
/**
 * 新增地块对话框 - 多步骤表单设计
 * 适配6.5寸竖屏优化版本 - 左对齐版
 */
public class AddDikuai extends JDialog {
    private static final long serialVersionUID = 1L;
    
    // 主题颜色 - 优化配色方案
    private final Color PRIMARY_COLOR = new Color(46, 139, 87);
    private final Color PRIMARY_LIGHT = new Color(232, 245, 233);
    private final Color PRIMARY_DARK = new Color(30, 107, 69);
    private final Color WHITE = Color.WHITE;
    private final Color LIGHT_GRAY = new Color(248, 249, 250);
    private final Color MEDIUM_GRAY = new Color(233, 236, 239);
    private final Color TEXT_COLOR = new Color(33, 37, 41);
    private final Color LIGHT_TEXT = new Color(108, 117, 125);
    private final Color BORDER_COLOR = new Color(222, 226, 230);
    private final Color SUCCESS_COLOR = new Color(40, 167, 69);
    
    // 步骤面板
    private JPanel mainPanel;
    private CardLayout cardLayout;
    private JPanel stepsPanel;
    
    // 步骤组件
    private JTextField landNumberField;
    private JTextField areaNameField;
    private JComboBox<String> mowingPatternCombo;
    private JSpinner mowingWidthSpinner;
    private JPanel previewPanel;
    private Map<String, JPanel> drawingOptionPanels = new HashMap<>();
    
    // 步骤控制
    private int currentStep = 1;
    private JButton prevButton;
    private JButton nextButton;
    private JButton createButton;
    private JLabel boundaryCountLabel;
    private JPanel obstacleListContainer;
    
    // 地块数据
    private Map<String, String> dikuaiData = new HashMap<>();
    private String createdLandNumber;
    private String pendingLandNumber;
    
    // 步骤2选项状态
    private JPanel selectedOptionPanel = null;
    private JButton startEndDrawingBtn;
    private boolean isDrawing = false;
 
    private static DrawingSession activeSession;
    private static boolean resumeRequested;
 
    private static class DrawingSession {
        String landNumber;
        String areaName;
        Map<String, String> data = new HashMap<>();
        boolean drawingCompleted;
    }
    
    public AddDikuai(JFrame parent) {
        super(parent, "新增地块", true);
        Dikuai.initFromProperties();
        initializeUI();
        setupEventHandlers();
    }
    
    public AddDikuai(JDialog parent) {
        super(parent, "新增地块", true);
        Dikuai.initFromProperties();
        initializeUI();
        setupEventHandlers();
    }
    
    private void initializeUI() {
        setLayout(new BorderLayout());
        setBackground(WHITE);
        
        // 统一使用 6.5 寸竖屏适配尺寸
        setSize(UIConfig.DIALOG_WIDTH, UIConfig.DIALOG_HEIGHT);
        setLocationRelativeTo(getParent());
        setResizable(false);
        
        createMainPanel();
        add(mainPanel, BorderLayout.CENTER);
    }
    
    private void createMainPanel() {
        mainPanel = new JPanel(new BorderLayout());
        mainPanel.setBackground(WHITE);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        
        // 步骤内容面板
        cardLayout = new CardLayout();
        stepsPanel = new JPanel(cardLayout);
        stepsPanel.setBackground(WHITE);
        stepsPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
        
        stepsPanel.add(createStep1Panel(), "step1");
        stepsPanel.add(createStep2Panel(), "step2");
        stepsPanel.add(createStep3Panel(), "step3");
        
        mainPanel.add(stepsPanel, BorderLayout.CENTER);
        
        // 按钮面板
        mainPanel.add(createButtonPanel(), BorderLayout.SOUTH);
        
        // 显示第一步
        showStep(1);
    }
    
    private JPanel createStep1Panel() {
        JPanel stepPanel = new JPanel();
        stepPanel.setLayout(new BoxLayout(stepPanel, BoxLayout.Y_AXIS));
        stepPanel.setBackground(WHITE);
        stepPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
        
        // 步骤标题 - 左对齐
        JLabel stepTitle = new JLabel("步骤1:基本信息");
        stepTitle.setFont(new Font("微软雅黑", Font.BOLD, 20));
        stepTitle.setForeground(TEXT_COLOR);
        stepTitle.setAlignmentX(Component.LEFT_ALIGNMENT);
        stepPanel.add(stepTitle);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 表单组
        JPanel formGroup = new JPanel();
        formGroup.setLayout(new BoxLayout(formGroup, BoxLayout.Y_AXIS));
        formGroup.setBackground(WHITE);
        formGroup.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        JLabel numberLabel = new JLabel("地块编号");
        numberLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        numberLabel.setForeground(TEXT_COLOR);
        numberLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
 
        landNumberField = new JTextField();
        landNumberField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        landNumberField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
        landNumberField.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR, 2),
            BorderFactory.createEmptyBorder(12, 15, 12, 15)
        ));
        landNumberField.setEditable(false);
        landNumberField.setFocusable(false);
        landNumberField.setBackground(LIGHT_GRAY);
        landNumberField.setAlignmentX(Component.LEFT_ALIGNMENT);
 
        JLabel nameLabel = new JLabel("地块名称");
        nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        nameLabel.setForeground(TEXT_COLOR);
        nameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        areaNameField = new JTextField();
        areaNameField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        areaNameField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
        areaNameField.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR, 2),
            BorderFactory.createEmptyBorder(12, 15, 12, 15)
        ));
        areaNameField.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 添加输入框焦点效果
        areaNameField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                areaNameField.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
                    BorderFactory.createEmptyBorder(12, 15, 12, 15)
                ));
            }
            
            @Override
            public void focusLost(FocusEvent e) {
                areaNameField.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(BORDER_COLOR, 2),
                    BorderFactory.createEmptyBorder(12, 15, 12, 15)
                ));
            }
        });
        
        JLabel hintLabel = new JLabel("例如: 前院草坪、后院草坪等");
        hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        hintLabel.setForeground(LIGHT_TEXT);
        hintLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        formGroup.add(numberLabel);
        formGroup.add(Box.createRigidArea(new Dimension(0, 10)));
        formGroup.add(landNumberField);
        formGroup.add(Box.createRigidArea(new Dimension(0, 18)));
        formGroup.add(nameLabel);
        formGroup.add(Box.createRigidArea(new Dimension(0, 10)));
        formGroup.add(areaNameField);
        formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
        formGroup.add(hintLabel);
 
    formGroup.add(Box.createRigidArea(new Dimension(0, 20)));
    JPanel obstacleSection = createObstacleSummarySection();
    formGroup.add(obstacleSection);
        
        stepPanel.add(formGroup);
        stepPanel.add(Box.createVerticalGlue());
 
        landNumberField.setText(getPendingLandNumber());
        
        return stepPanel;
    }
 
    private JPanel createObstacleSummarySection() {
        JPanel section = new JPanel();
        section.setLayout(new BoxLayout(section, BoxLayout.Y_AXIS));
        section.setOpaque(false);
        section.setAlignmentX(Component.LEFT_ALIGNMENT);
 
        JLabel title = new JLabel("已有障碍物");
        title.setFont(new Font("微软雅黑", Font.BOLD, 16));
        title.setForeground(TEXT_COLOR);
        title.setAlignmentX(Component.LEFT_ALIGNMENT);
        section.add(title);
        section.add(Box.createRigidArea(new Dimension(0, 8)));
 
        obstacleListContainer = new JPanel();
        obstacleListContainer.setLayout(new BoxLayout(obstacleListContainer, BoxLayout.Y_AXIS));
        obstacleListContainer.setOpaque(false);
        obstacleListContainer.setAlignmentX(Component.LEFT_ALIGNMENT);
        section.add(obstacleListContainer);
 
        updateObstacleSummary();
 
        return section;
    }
 
    private void updateObstacleSummary() {
        if (obstacleListContainer == null) {
            return;
        }
 
        obstacleListContainer.removeAll();
        List<ObstacleSummary> summaries = loadExistingObstacles();
 
        if (summaries.isEmpty()) {
            JLabel emptyLabel = new JLabel("暂无障碍物");
            emptyLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
            emptyLabel.setForeground(LIGHT_TEXT);
            emptyLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
            obstacleListContainer.add(emptyLabel);
        } else {
            int index = 1;
            for (ObstacleSummary summary : summaries) {
                JPanel row = new JPanel(new BorderLayout());
                row.setOpaque(false);
                row.setAlignmentX(Component.LEFT_ALIGNMENT);
                row.setBorder(BorderFactory.createEmptyBorder(6, 0, 6, 0));
 
                String labelText = String.format(Locale.CHINA, "%02d. %s", index++, summary.getName());
                JLabel nameLabel = new JLabel(labelText);
                nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 14));
                nameLabel.setForeground(TEXT_COLOR);
 
                JLabel coordLabel = new JLabel(summary.getDisplayCoords());
                coordLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
                coordLabel.setForeground(LIGHT_TEXT);
                coordLabel.setToolTipText(summary.getFullCoords());
 
                row.add(nameLabel, BorderLayout.WEST);
                row.add(coordLabel, BorderLayout.CENTER);
                obstacleListContainer.add(row);
            }
        }
 
        obstacleListContainer.revalidate();
        obstacleListContainer.repaint();
    }
 
    private List<ObstacleSummary> loadExistingObstacles() {
        List<ObstacleSummary> summaries = new ArrayList<>();
 
        String landNumber = getPendingLandNumber();
        String raw = null;
        if (landNumber != null) {
            Dikuai dikuai = Dikuai.getDikuai(landNumber);
            if (dikuai != null) {
                raw = normalizeCoordinateValue(dikuai.getObstacleCoordinates());
            }
        }
        if (raw == null) {
            raw = normalizeCoordinateValue(dikuaiData.get("obstacleCoordinates"));
        }
        if (!isMeaningfulValue(raw)) {
            return summaries;
        }
 
        String normalized = stripInlineComment(raw);
        if (normalized.isEmpty()) {
            return summaries;
        }
 
        List<String> entries = splitObstacleEntries(normalized);
        int defaultIndex = 1;
 
        for (String entry : entries) {
            String trimmedEntry = stripInlineComment(entry);
            if (trimmedEntry.isEmpty()) {
                continue;
            }
 
            String nameToken = null;
            String shapeToken = null;
            String coordsSection = trimmedEntry;
 
            if (trimmedEntry.contains("::")) {
                String[] parts = trimmedEntry.split("::", 3);
                if (parts.length == 3) {
                    nameToken = parts[0].trim();
                    shapeToken = parts[1].trim();
                    coordsSection = parts[2].trim();
                }
            } else if (trimmedEntry.contains("@")) {
                String[] parts = trimmedEntry.split("@", 3);
                if (parts.length == 3) {
                    nameToken = parts[0].trim();
                    shapeToken = parts[1].trim();
                    coordsSection = parts[2].trim();
                } else if (parts.length == 2) {
                    shapeToken = parts[0].trim();
                    coordsSection = parts[1].trim();
                }
            } else if (trimmedEntry.contains(":")) {
                String[] parts = trimmedEntry.split(":", 3);
                if (parts.length == 3) {
                    nameToken = parts[0].trim();
                    shapeToken = parts[1].trim();
                    coordsSection = parts[2].trim();
                } else if (parts.length == 2) {
                    if (looksLikeShapeToken(parts[0])) {
                        shapeToken = parts[0].trim();
                        coordsSection = parts[1].trim();
                    } else {
                        nameToken = parts[0].trim();
                        coordsSection = parts[1].trim();
                    }
                }
            }
 
            String sanitizedCoords = sanitizeCoordinateString(coordsSection);
            if (!isMeaningfulValue(sanitizedCoords)) {
                continue;
            }
 
            String resolvedName;
            if (nameToken != null && !nameToken.isEmpty()) {
                resolvedName = nameToken;
            } else {
                resolvedName = "障碍物" + defaultIndex++;
            }
 
            String displayCoords = truncateCoordinateForDisplay(sanitizedCoords, 12);
            summaries.add(new ObstacleSummary(resolvedName, sanitizedCoords, displayCoords));
        }
 
        return summaries;
    }
 
    private List<String> splitObstacleEntries(String data) {
        List<String> entries = new ArrayList<>();
        if (data.indexOf('|') >= 0) {
            String[] parts = data.split("\\|");
            for (String part : parts) {
                if (part != null && !part.trim().isEmpty()) {
                    entries.add(part.trim());
                }
            }
        } else if (data.contains("\n")) {
            String[] lines = data.split("\r?\n");
            for (String line : lines) {
                if (line != null && !line.trim().isEmpty()) {
                    entries.add(line.trim());
                }
            }
        } else {
            entries.add(data);
        }
        return entries;
    }
 
    private String stripInlineComment(String text) {
        if (text == null) {
            return "";
        }
        int hashIndex = text.indexOf('#');
        if (hashIndex >= 0) {
            return text.substring(0, hashIndex).trim();
        }
        return text.trim();
    }
 
    private boolean looksLikeShapeToken(String token) {
        if (token == null) {
            return false;
        }
        String normalized = token.trim().toLowerCase(Locale.ROOT);
        return "circle".equals(normalized)
                || "polygon".equals(normalized)
                || "圆形".equals(normalized)
                || "多边形".equals(normalized)
                || "0".equals(normalized)
                || "1".equals(normalized);
    }
 
    private String sanitizeCoordinateString(String value) {
        if (value == null) {
            return "";
        }
        String stripped = stripInlineComment(value);
        if (stripped.isEmpty()) {
            return "";
        }
        return stripped.replace("\r", "").replace("\n", "").replace("\t", "").replace(" ", "");
    }
 
    private String truncateCoordinateForDisplay(String coords, int maxLength) {
        if (coords == null) {
            return "";
        }
        String trimmed = coords.trim();
        if (trimmed.length() <= maxLength) {
            return trimmed;
        }
        if (maxLength <= 3) {
            return trimmed.substring(0, maxLength);
        }
        return trimmed.substring(0, maxLength - 3) + "...";
    }
 
    private static final class ObstacleSummary {
        private final String name;
        private final String fullCoords;
        private final String displayCoords;
 
        ObstacleSummary(String name, String fullCoords, String displayCoords) {
            this.name = name;
            this.fullCoords = fullCoords;
            this.displayCoords = displayCoords;
        }
 
        public String getName() {
            return name;
        }
 
        public String getFullCoords() {
            return fullCoords;
        }
 
        public String getDisplayCoords() {
            return displayCoords;
        }
    }
    
    private JPanel createStep2Panel() {
        JPanel stepPanel = new JPanel();
        stepPanel.setLayout(new BoxLayout(stepPanel, BoxLayout.Y_AXIS));
        stepPanel.setBackground(WHITE);
        stepPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
        
        // 步骤标题 - 左对齐
        JLabel stepTitle = new JLabel("步骤2:绘制边界");
        stepTitle.setFont(new Font("微软雅黑", Font.BOLD, 20));
        stepTitle.setForeground(TEXT_COLOR);
        stepTitle.setAlignmentX(Component.LEFT_ALIGNMENT);
        stepPanel.add(stepTitle);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 步骤说明
        JPanel instructionPanel = createInstructionPanel(
            "请选择绘制边界的方式。割草机绘制需要驾驶割草机沿边界行驶," +
            "手持设备绘制则使用便携设备标记边界点。"
        );
        instructionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        stepPanel.add(instructionPanel);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 25)));
        
        // 绘制方式选择
        JLabel methodLabel = new JLabel("选择绘制方式");
        methodLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        methodLabel.setForeground(TEXT_COLOR);
        methodLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        stepPanel.add(methodLabel);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 15)));
        
        // 绘制选项面板 - 垂直布局以完整显示图标
        JPanel optionsPanel = new JPanel();
        optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
        optionsPanel.setBackground(WHITE);
        optionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 割草机绘制选项
        JPanel mowerOption = createDrawingOption("🚜", "割草机绘制", 
            "", "mower");
        mowerOption.setAlignmentX(Component.LEFT_ALIGNMENT);
        mowerOption.setBorder(BorderFactory.createLineBorder(BORDER_COLOR, 2));
        
        // 手持设备绘制选项
        JPanel handheldOption = createDrawingOption("📱", "手持设备绘制", 
            "", "handheld");
        handheldOption.setAlignmentX(Component.LEFT_ALIGNMENT);
        handheldOption.setBorder(BorderFactory.createLineBorder(BORDER_COLOR, 2));
        
        optionsPanel.add(mowerOption);
        optionsPanel.add(Box.createRigidArea(new Dimension(0, 15)));
        optionsPanel.add(handheldOption);
        
        stepPanel.add(optionsPanel);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 30)));
        
        // 开始/结束绘制按钮
        startEndDrawingBtn = createPrimaryButton("开始绘制", 16);
        startEndDrawingBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
        startEndDrawingBtn.setMaximumSize(new Dimension(400, 55));
        startEndDrawingBtn.setEnabled(false); // 初始不可用
        
        startEndDrawingBtn.addActionListener(e -> toggleDrawing());
        
        stepPanel.add(startEndDrawingBtn);
        boundaryCountLabel = new JLabel("已采集到边界点0个");
        boundaryCountLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        boundaryCountLabel.setForeground(LIGHT_TEXT);
        boundaryCountLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        boundaryCountLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
        boundaryCountLabel.setVisible(false);
        stepPanel.add(boundaryCountLabel);
        stepPanel.add(Box.createVerticalGlue());
        
        return stepPanel;
    }
    
    private JPanel createDrawingOption(String icon, String text, String description, String type) {
        JPanel optionPanel = new JPanel(new BorderLayout(15, 0));
        optionPanel.setBackground(WHITE);
        optionPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
        optionPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        optionPanel.setMaximumSize(new Dimension(500, 120));
        
        // 图标区域
        JLabel iconLabel;
        if ("handheld".equals(type) || "mower".equals(type)) {
            iconLabel = new JLabel();
            iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
            iconLabel.setPreferredSize(new Dimension(80, 80));
            String iconPath = "handheld".equals(type) ? "image/URT.png" : "image/mow.png";
            ImageIcon rawIcon = new ImageIcon(iconPath);
            if (rawIcon.getIconWidth() > 0 && rawIcon.getIconHeight() > 0) {
                Image scaled = rawIcon.getImage().getScaledInstance(64, 64, Image.SCALE_SMOOTH);
                iconLabel.setIcon(new ImageIcon(scaled));
            } else {
                iconLabel.setText(icon);
                iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 48));
            }
        } else {
            iconLabel = new JLabel(icon, JLabel.CENTER);
            iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 48));
            iconLabel.setPreferredSize(new Dimension(80, 80));
        }
        
        // 文本区域
        JPanel textPanel = new JPanel(new GridBagLayout());
        textPanel.setBackground(WHITE);
 
        JLabel textLabel = new JLabel(text);
        textLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        textLabel.setHorizontalAlignment(SwingConstants.CENTER);
        textLabel.setVerticalAlignment(SwingConstants.CENTER);
 
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1;
        gbc.weighty = description == null || description.trim().isEmpty() ? 1 : 0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.CENTER;
        textPanel.add(textLabel, gbc);
 
        if (description != null && !description.trim().isEmpty()) {
            JLabel descLabel = new JLabel(description);
            descLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
            descLabel.setForeground(LIGHT_TEXT);
            descLabel.setHorizontalAlignment(SwingConstants.CENTER);
 
            GridBagConstraints descGbc = new GridBagConstraints();
            descGbc.gridx = 0;
            descGbc.gridy = 1;
            descGbc.weightx = 1;
            descGbc.weighty = 1;
            descGbc.fill = GridBagConstraints.HORIZONTAL;
            descGbc.anchor = GridBagConstraints.CENTER;
            textPanel.add(descLabel, descGbc);
        }
 
        optionPanel.putClientProperty("titleLabel", textLabel);
        
        optionPanel.add(iconLabel, BorderLayout.WEST);
        optionPanel.add(textPanel, BorderLayout.CENTER);
        
        // 添加点击事件
        optionPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (!optionPanel.isEnabled()) {
                    return;
                }
                selectDrawingOption(optionPanel, type);
                startEndDrawingBtn.setEnabled(true); // 选择后启用按钮
            }
            
            @Override
            public void mouseEntered(MouseEvent e) {
                if (optionPanel != selectedOptionPanel) {
                    optionPanel.setBackground(new Color(245, 245, 245));
                }
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                if (optionPanel != selectedOptionPanel) {
                    optionPanel.setBackground(WHITE);
                }
            }
        });
        
        drawingOptionPanels.put(type, optionPanel);
        return optionPanel;
    }
    
    private void selectDrawingOption(JPanel optionPanel, String type) {
        // 重置之前选中的选项
        if (selectedOptionPanel != null) {
            selectedOptionPanel.setBorder(BorderFactory.createLineBorder(BORDER_COLOR, 2));
            selectedOptionPanel.setBackground(WHITE);
            Object oldTitle = selectedOptionPanel.getClientProperty("titleLabel");
            if (oldTitle instanceof JLabel) {
                ((JLabel) oldTitle).setForeground(TEXT_COLOR);
            }
        }
        
        // 设置新的选中状态
        optionPanel.setBorder(BorderFactory.createLineBorder(PRIMARY_COLOR, 3));
        optionPanel.setBackground(PRIMARY_LIGHT);
        Object titleObj = optionPanel.getClientProperty("titleLabel");
        if (titleObj instanceof JLabel) {
            ((JLabel) titleObj).setForeground(PRIMARY_COLOR);
        }
        selectedOptionPanel = optionPanel;
        
        // 保存选择
        dikuaiData.put("drawingMethod", type);
    }
    
    private void toggleDrawing() {
        if (!isDrawing) {
            if (!prepareDrawingSession()) {
                return;
            }
            isDrawing = true;
            hideBoundaryPointSummary();
            Coordinate.setStartSaveGngga(true);
            startEndDrawingBtn.setText("结束绘制");
            startEndDrawingBtn.setBackground(new Color(220, 53, 69));
            updateOtherOptionsState(true);
 
            if (!startDrawingBoundary()) {
                Coordinate.setStartSaveGngga(false);
                resetDrawingState();
            }
        } else {
            // 用户在对话框内主动结束(未触发外部流程)
            isDrawing = false;
            Coordinate.setStartSaveGngga(false);
            startEndDrawingBtn.setText("开始绘制");
            startEndDrawingBtn.setBackground(PRIMARY_COLOR);
            updateOtherOptionsState(false);
            dikuaiData.put("boundaryDrawn", "true");
            JOptionPane.showMessageDialog(this, "边界绘制已完成", "提示", JOptionPane.INFORMATION_MESSAGE);
            showBoundaryPointSummary();
        }
    }
 
    private boolean prepareDrawingSession() {
        String areaName = areaNameField.getText().trim();
        if (areaName.isEmpty()) {
            JOptionPane.showMessageDialog(this, "请先填写地块名称", "提示", JOptionPane.WARNING_MESSAGE);
            areaNameField.requestFocus();
            return false;
        }
        if (!dikuaiData.containsKey("drawingMethod")) {
            JOptionPane.showMessageDialog(this, "请选择绘制方式", "提示", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        dikuaiData.put("areaName", areaName);
 
        String landNumber = getPendingLandNumber();
        if (activeSession == null) {
            activeSession = new DrawingSession();
        }
        activeSession.landNumber = landNumber;
        activeSession.areaName = areaName;
        activeSession.drawingCompleted = false;
        activeSession.data = new HashMap<>(dikuaiData);
 
        return true;
    }
 
    private void updateOtherOptionsState(boolean disable) {
        if (selectedOptionPanel == null) {
            return;
        }
        Component[] components = selectedOptionPanel.getParent().getComponents();
        for (Component comp : components) {
            if (comp instanceof JPanel && comp != selectedOptionPanel) {
                comp.setEnabled(!disable);
                ((JPanel) comp).setBackground(disable ? LIGHT_GRAY : WHITE);
            }
        }
    }
 
    private void resetDrawingState() {
        isDrawing = false;
        Coordinate.setStartSaveGngga(false);
        startEndDrawingBtn.setText("开始绘制");
        startEndDrawingBtn.setBackground(PRIMARY_COLOR);
        updateOtherOptionsState(false);
        hideBoundaryPointSummary();
    }
    
    private JPanel createStep3Panel() {
        JPanel stepPanel = new JPanel();
        stepPanel.setLayout(new BoxLayout(stepPanel, BoxLayout.Y_AXIS));
        stepPanel.setBackground(WHITE);
        stepPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
        
        // 步骤标题 - 左对齐
        JLabel stepTitle = new JLabel("步骤3:生成割草路径");
        stepTitle.setFont(new Font("微软雅黑", Font.BOLD, 20));
        stepTitle.setForeground(TEXT_COLOR);
        stepTitle.setAlignmentX(Component.LEFT_ALIGNMENT);
        stepPanel.add(stepTitle);
        stepPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 设置面板容器
        JPanel settingsPanel = new JPanel();
        settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.Y_AXIS));
        settingsPanel.setBackground(WHITE);
        settingsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 割草模式选择
        JPanel patternPanel = createFormGroup("割草模式", "选择割草路径的生成模式");
        mowingPatternCombo = new JComboBox<>(new String[]{"平行线", "螺旋式"});
        mowingPatternCombo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        mowingPatternCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
        mowingPatternCombo.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR, 2),
            BorderFactory.createEmptyBorder(10, 12, 10, 12)
        ));
        mowingPatternCombo.setSelectedIndex(0);
        mowingPatternCombo.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        // 添加下拉框焦点效果
        mowingPatternCombo.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                mowingPatternCombo.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
                ));
            }
            
            @Override
            public void focusLost(FocusEvent e) {
                mowingPatternCombo.setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(BORDER_COLOR, 2),
                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
                ));
            }
        });
        
        patternPanel.add(mowingPatternCombo);
        settingsPanel.add(patternPanel);
        settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        
        // 割草宽度设置
        JPanel widthPanel = createFormGroup("割草宽度", "设置割草机单次割草的宽度");
        JPanel widthInputPanel = new JPanel(new BorderLayout());
        widthInputPanel.setBackground(WHITE);
        widthInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
        widthInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        SpinnerNumberModel widthModel = new SpinnerNumberModel(40, 20, 60, 1);
        mowingWidthSpinner = new JSpinner(widthModel);
        mowingWidthSpinner.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) mowingWidthSpinner.getEditor();
        editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR, 2),
            BorderFactory.createEmptyBorder(10, 12, 10, 12)
        ));
        
        // 添加微调器焦点效果
        mowingWidthSpinner.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
                ));
            }
            
            @Override
            public void focusLost(FocusEvent e) {
                editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(BORDER_COLOR, 2),
                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
                ));
            }
        });
        
        JLabel unitLabel = new JLabel("厘米");
        unitLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
        unitLabel.setForeground(LIGHT_TEXT);
        unitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
        
        widthInputPanel.add(mowingWidthSpinner, BorderLayout.CENTER);
        widthInputPanel.add(unitLabel, BorderLayout.EAST);
        
        widthPanel.add(widthInputPanel);
        settingsPanel.add(widthPanel);
        settingsPanel.add(Box.createRigidArea(new Dimension(0, 25)));
        
        stepPanel.add(settingsPanel);
        
        JButton generatePathButton = createPrimaryButton("生成割草路径", 16);
        generatePathButton.setAlignmentX(Component.LEFT_ALIGNMENT);
        generatePathButton.setMaximumSize(new Dimension(Integer.MAX_VALUE, 55));
        generatePathButton.addActionListener(e -> generateMowingPath());
 
        stepPanel.add(Box.createRigidArea(new Dimension(0, 20)));
        stepPanel.add(generatePathButton);
        stepPanel.add(Box.createVerticalGlue());
 
        return stepPanel;
    }
    
    private JPanel createInstructionPanel(String text) {
        JPanel instructionPanel = new JPanel(new BorderLayout());
        instructionPanel.setBackground(PRIMARY_LIGHT);
        instructionPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createMatteBorder(0, 5, 0, 0, PRIMARY_COLOR),
            BorderFactory.createEmptyBorder(12, 12, 12, 12)
        ));
        instructionPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 70));
        
        JLabel iconLabel = new JLabel("💡");
        iconLabel.setFont(new Font("Segoe UI Emoji", Font.PLAIN, 16));
        iconLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
        
        JTextArea instructionText = new JTextArea(text);
        instructionText.setFont(new Font("微软雅黑", Font.PLAIN, 13));
        instructionText.setForeground(TEXT_COLOR);
        instructionText.setBackground(PRIMARY_LIGHT);
        instructionText.setLineWrap(true);
        instructionText.setWrapStyleWord(true);
        instructionText.setEditable(false);
        
        instructionPanel.add(iconLabel, BorderLayout.WEST);
        instructionPanel.add(instructionText, BorderLayout.CENTER);
        
        return instructionPanel;
    }
    
    private JPanel createFormGroup(String label, String hint) {
        JPanel formGroup = new JPanel();
        formGroup.setLayout(new BoxLayout(formGroup, BoxLayout.Y_AXIS));
        formGroup.setBackground(WHITE);
        formGroup.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        JLabel nameLabel = new JLabel(label);
        nameLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
        nameLabel.setForeground(TEXT_COLOR);
        nameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        JLabel hintLabel = new JLabel(hint);
        hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 13));
        hintLabel.setForeground(LIGHT_TEXT);
        hintLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
        
        formGroup.add(nameLabel);
        formGroup.add(Box.createRigidArea(new Dimension(0, 6)));
        formGroup.add(hintLabel);
        formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
        
        return formGroup;
    }
 
    private void generateMowingPath() {
        if (!dikuaiData.containsKey("boundaryDrawn")) {
            JOptionPane.showMessageDialog(this, "请先完成边界绘制后再生成路径", "提示", JOptionPane.WARNING_MESSAGE);
            showStep(2);
            return;
        }
        Dikuai dikuai = getOrCreatePendingDikuai();
        String boundaryCoords = null;
        if (dikuai != null) {
            boundaryCoords = normalizeCoordinateValue(dikuai.getBoundaryCoordinates());
        }
        if (boundaryCoords == null) {
            boundaryCoords = normalizeCoordinateValue(dikuaiData.get("boundaryCoordinates"));
        }
        if (boundaryCoords == null) {
            JOptionPane.showMessageDialog(this, "未找到有效的地块边界坐标,无法生成路径", "提示", JOptionPane.WARNING_MESSAGE);
            if (createButton != null) {
                createButton.setEnabled(false);
            }
            return;
        }
 
        String obstacleCoords = null;
        if (dikuai != null) {
            obstacleCoords = normalizeCoordinateValue(dikuai.getObstacleCoordinates());
        }
        if (obstacleCoords == null) {
            obstacleCoords = normalizeCoordinateValue(dikuaiData.get("obstacleCoordinates"));
        }
 
        String patternDisplay = (String) mowingPatternCombo.getSelectedItem();
        dikuaiData.put("mowingPattern", patternDisplay);
 
        Object widthObj = mowingWidthSpinner.getValue();
        if (!(widthObj instanceof Number)) {
            JOptionPane.showMessageDialog(this, "割草宽度输入无效", "提示", JOptionPane.WARNING_MESSAGE);
            if (createButton != null) {
                createButton.setEnabled(false);
            }
            return;
        }
        double widthCm = ((Number) widthObj).doubleValue();
        if (widthCm <= 0) {
            JOptionPane.showMessageDialog(this, "割草宽度必须大于0", "提示", JOptionPane.WARNING_MESSAGE);
            if (createButton != null) {
                createButton.setEnabled(false);
            }
            return;
        }
        dikuaiData.put("mowingWidth", widthObj.toString());
 
        String widthMeters = String.format(Locale.US, "%.2f", widthCm / 100.0);
        String plannerMode = resolvePlannerMode(patternDisplay);
 
        try {
            List<Lunjingguihua.PathSegment> segments = Lunjingguihua.generatePathSegments(
                boundaryCoords,
                obstacleCoords,
                widthMeters,
                plannerMode
            );
            String plannedPath = Lunjingguihua.formatPathSegments(segments);
            if (!isMeaningfulValue(plannedPath)) {
                JOptionPane.showMessageDialog(this, "生成割草路径失败: 生成结果为空", "错误", JOptionPane.ERROR_MESSAGE);
                if (createButton != null) {
                    createButton.setEnabled(false);
                }
                return;
            }
            dikuaiData.put("plannedPath", plannedPath);
            if (createButton != null) {
                createButton.setEnabled(true);
            }
            JOptionPane.showMessageDialog(this,
                "已根据当前设置生成割草路径,共生成 " + segments.size() + " 段。",
                "成功",
                JOptionPane.INFORMATION_MESSAGE);
        } catch (IllegalArgumentException ex) {
            JOptionPane.showMessageDialog(this, "生成割草路径失败: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
            if (createButton != null) {
                createButton.setEnabled(false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, "生成割草路径时发生异常: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
            if (createButton != null) {
                createButton.setEnabled(false);
            }
        }
    }
    
    private JButton createPrimaryButton(String text, int fontSize) {
        JButton button = new JButton(text);
        button.setFont(new Font("微软雅黑", Font.BOLD, fontSize));
        button.setBackground(PRIMARY_COLOR);
        button.setForeground(WHITE);
        button.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(PRIMARY_DARK, 2),
            BorderFactory.createEmptyBorder(12, 25, 12, 25)
        ));
        button.setFocusPainted(false);
        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
        
        // 按钮悬停效果
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                if (button.isEnabled()) {
                    button.setBackground(PRIMARY_DARK);
                }
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                if (button.isEnabled()) {
                    button.setBackground(PRIMARY_COLOR);
                }
            }
        });
        
        return button;
    }
    
    private JPanel createButtonPanel() {
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
        buttonPanel.setBackground(WHITE);
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
 
        prevButton = new JButton("上一步");
        prevButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
        prevButton.setBackground(MEDIUM_GRAY);
        prevButton.setForeground(TEXT_COLOR);
        prevButton.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(BORDER_COLOR, 2),
            BorderFactory.createEmptyBorder(10, 25, 10, 25)
        ));
        prevButton.setFocusPainted(false);
        prevButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
 
        nextButton = createPrimaryButton("下一步", 16);
        createButton = createPrimaryButton("保存", 16);
        createButton.setVisible(false);
    createButton.setEnabled(false);
 
        buttonPanel.add(prevButton);
        buttonPanel.add(Box.createHorizontalGlue());
        buttonPanel.add(nextButton);
        buttonPanel.add(Box.createHorizontalStrut(15));
        buttonPanel.add(createButton);
 
        return buttonPanel;
    }
 
    private void showBoundaryPointSummary() {
        if (boundaryCountLabel == null) {
            return;
        }
        int count = Coordinate.coordinates != null ? Coordinate.coordinates.size() : 0;
        double area = jisuanmianjie.calculatePolygonArea();
        DecimalFormat areaFormat = new DecimalFormat("0.00");
        boundaryCountLabel.setText("已采集到边界点" + count + "个,当前地块面积为" + areaFormat.format(area) + "㎡");
        boundaryCountLabel.setVisible(true);
    }
 
    private boolean prepareBoundaryTransition() {
        int count = Coordinate.coordinates != null ? Coordinate.coordinates.size() : 0;
        // TODO: 恢复边界点数校验
        // if (count < 3) {
        //     JOptionPane.showMessageDialog(this, "采集的边界点不足,无法生成地块边界", "提示", JOptionPane.WARNING_MESSAGE);
        //     return false;
        // }
 
        double area = jisuanmianjie.calculatePolygonArea();
        // TODO: 恢复地块面积校验
        // if (area <= 0) {
        //     JOptionPane.showMessageDialog(this, "当前地块面积为0,无法继续", "提示", JOptionPane.WARNING_MESSAGE);
        //     return false;
        // }
 
        Device device = new Device();
        device.initFromProperties();
        String baseStationCoordinates = device.getBaseStationCoordinates();
        if (baseStationCoordinates != null) {
            baseStationCoordinates = baseStationCoordinates.trim();
        }
        if (baseStationCoordinates == null || baseStationCoordinates.isEmpty() || "-1".equals(baseStationCoordinates)) {
            JOptionPane.showMessageDialog(this, "未获取到有效的基准站坐标,请先在基准站管理中设置", "提示", JOptionPane.WARNING_MESSAGE);
            return false;
        }
 
        String optimizedBoundary;
        try {
            optimizedBoundary = bianjieguihua2.processCoordinateListAuto(baseStationCoordinates);
        } catch (RuntimeException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, "生成地块边界失败: " + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
            return false;
        }
 
        String originalBoundary = buildOriginalBoundaryString();
        DecimalFormat areaFormat = new DecimalFormat("0.00");
        String areaString = areaFormat.format(area);
 
        String landNumber = getPendingLandNumber();
        Dikuai dikuai = getOrCreatePendingDikuai();
        if (dikuai != null) {
            dikuai.setBoundaryOriginalCoordinates(originalBoundary);
            dikuai.setBoundaryCoordinates(optimizedBoundary);
            dikuai.setLandArea(areaString);
            dikuai.setBaseStationCoordinates(baseStationCoordinates);
            dikuai.setUpdateTime(getCurrentTime());
            Dikuai.putDikuai(landNumber, dikuai);
        }
 
        dikuaiData.put("boundaryOriginalCoordinates", originalBoundary);
        dikuaiData.put("boundaryCoordinates", optimizedBoundary);
        dikuaiData.put("landArea", areaString);
        dikuaiData.put("baseStationCoordinates", baseStationCoordinates);
 
        return true;
    }
 
    private String buildOriginalBoundaryString() {
        if (Coordinate.coordinates == null || Coordinate.coordinates.isEmpty()) {
            return "-1";
        }
        StringBuilder sb = new StringBuilder();
        DecimalFormat latLonFormat = new DecimalFormat("0.000000");
        DecimalFormat elevationFormat = new DecimalFormat("0.00");
        for (Coordinate coord : Coordinate.coordinates) {
            double lat = convertToDecimalDegree(coord.getLatitude(), coord.getLatDirection());
            double lon = convertToDecimalDegree(coord.getLongitude(), coord.getLonDirection());
            double elevation = coord.getElevation();
 
            if (sb.length() > 0) {
                sb.append(";");
            }
            sb.append(latLonFormat.format(lat)).append(",")
              .append(latLonFormat.format(lon)).append(",")
              .append(elevationFormat.format(elevation));
        }
        return sb.toString();
    }
 
    private double convertToDecimalDegree(String dmm, String direction) {
        if (dmm == null || dmm.isEmpty()) {
            return 0.0;
        }
        try {
            int dotIndex = dmm.indexOf('.');
            if (dotIndex == -1) {
                dotIndex = dmm.length();
            }
            if (dotIndex < 2) {
                return 0.0;
            }
 
            int degrees = Integer.parseInt(dmm.substring(0, dotIndex - 2));
            double minutes = Double.parseDouble(dmm.substring(dotIndex - 2));
            double decimalDegrees = degrees + minutes / 60.0;
 
            if (direction != null && ("S".equalsIgnoreCase(direction) || "W".equalsIgnoreCase(direction))) {
                decimalDegrees = -decimalDegrees;
            }
 
            return decimalDegrees;
        } catch (NumberFormatException ex) {
            System.err.println("坐标格式转换错误: " + dmm);
            return 0.0;
        }
    }
 
    private Dikuai getOrCreatePendingDikuai() {
        String landNumber = getPendingLandNumber();
        if (landNumber == null) {
            return null;
        }
        Dikuai dikuai = Dikuai.getDikuai(landNumber);
        if (dikuai == null) {
            dikuai = new Dikuai();
            dikuai.setLandNumber(landNumber);
            Dikuai.putDikuai(landNumber, dikuai);
        }
        return dikuai;
    }
 
    private void hideBoundaryPointSummary() {
        if (boundaryCountLabel != null) {
            boundaryCountLabel.setVisible(false);
        }
    }
 
    private boolean hasGeneratedPath() {
        return isMeaningfulValue(dikuaiData.get("plannedPath"));
    }
 
    private String normalizeCoordinateValue(String value) {
        return isMeaningfulValue(value) ? value.trim() : null;
    }
 
    private boolean isMeaningfulValue(String value) {
        if (value == null) {
            return false;
        }
        String trimmed = value.trim();
        return !trimmed.isEmpty() && !"-1".equals(trimmed);
    }
 
    private String resolvePlannerMode(String patternDisplay) {
        if (patternDisplay == null) {
            return "parallel";
        }
        String trimmed = patternDisplay.trim();
        if (trimmed.isEmpty()) {
            return "parallel";
        }
        if ("螺旋式".equals(trimmed) || "spiral".equalsIgnoreCase(trimmed) || "1".equals(trimmed)) {
            return "spiral";
        }
        return "parallel";
    }
    
    private void setupEventHandlers() {
        // 上一步按钮
        prevButton.addActionListener(e -> {
            if (currentStep > 1) {
                showStep(currentStep - 1);
            }
        });
        
        // 下一步按钮
        nextButton.addActionListener(e -> {
            if (validateCurrentStep()) {
                if (currentStep < 3) {
                    // 步骤2特殊验证:必须完成边界绘制才能进入下一步
                    if (currentStep == 2 && !dikuaiData.containsKey("boundaryDrawn")) {
                        JOptionPane.showMessageDialog(this, "请先完成边界绘制", "提示", JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    if (currentStep == 2 && !prepareBoundaryTransition()) {
                        return;
                    }
                    showStep(currentStep + 1);
                }
            }
        });
        
        // 创建地块按钮
        createButton.addActionListener(e -> createDikuai());
        
        // 关闭对话框
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                dispose();
            }
        });
    }
    
    private void showStep(int step) {
        currentStep = step;
        cardLayout.show(stepsPanel, "step" + step);
        
        if (step == 1) {
            updateObstacleSummary();
        }
 
        // 更新按钮状态
        updateButtonState(step);
    }
    
    private void updateButtonState(int step) {
        prevButton.setVisible(step > 1);
        
        if (step < 3) {
            nextButton.setVisible(true);
            createButton.setVisible(false);
            createButton.setEnabled(false);
        } else {
            nextButton.setVisible(false);
            createButton.setVisible(true);
            createButton.setEnabled(hasGeneratedPath());
        }
 
        Container parent = prevButton.getParent();
        if (parent != null) {
            parent.revalidate();
            parent.repaint();
        }
    }
    
    private boolean validateCurrentStep() {
        switch (currentStep) {
            case 1:
                String name = areaNameField.getText().trim();
                if (name.isEmpty()) {
                    JOptionPane.showMessageDialog(this, "请输入地块名称", "提示", JOptionPane.WARNING_MESSAGE);
                    areaNameField.requestFocus();
                    return false;
                }
                String currentLandNumber = getPendingLandNumber();
                if (isLandNameDuplicate(name, currentLandNumber)) {
                    JOptionPane.showMessageDialog(this, "地块名称已存在,请输入唯一名称", "提示", JOptionPane.WARNING_MESSAGE);
                    areaNameField.requestFocus();
                    return false;
                }
                dikuaiData.put("areaName", name);
                break;
 
            case 2:
                if (!dikuaiData.containsKey("drawingMethod")) {
                    JOptionPane.showMessageDialog(this, "请选择绘制方式", "提示", JOptionPane.WARNING_MESSAGE);
                    return false;
                }
                // 步骤2的特殊验证:必须完成边界绘制
                if (!dikuaiData.containsKey("boundaryDrawn")) {
                    JOptionPane.showMessageDialog(this, "请先完成边界绘制", "提示", JOptionPane.WARNING_MESSAGE);
                    return false;
                }
                break;
 
            case 3:
                dikuaiData.put("mowingPattern", (String) mowingPatternCombo.getSelectedItem());
                dikuaiData.put("mowingWidth", mowingWidthSpinner.getValue().toString());
                if (!hasGeneratedPath()) {
                    JOptionPane.showMessageDialog(this, "请先生成割草路径", "提示", JOptionPane.WARNING_MESSAGE);
                    return false;
                }
                break;
        }
        return true;
    }
    
    private boolean startDrawingBoundary() {
        String method = dikuaiData.get("drawingMethod");
        if ("mower".equals(method)) {
//            if (captureGnssSnapshot()) {
            if (true) {
                JOptionPane.showMessageDialog(this, "已记录割草机当前位置作为边界起点,请继续驾驶割草机完成边界绘制", "开始绘制边界", JOptionPane.INFORMATION_MESSAGE);
                closeForDrawingSession();
                return true;
            } else {
                JOptionPane.showMessageDialog(this, "未能获取有效的割草机定位数据,请确认设备状态后重试", "提示", JOptionPane.WARNING_MESSAGE);
                return false;
            }
        } else if ("handheld".equals(method)) {
            JOptionPane.showMessageDialog(this, "正在使用手持设备绘制边界,请沿地块边界行走...", "开始绘制边界", JOptionPane.INFORMATION_MESSAGE);
            closeForDrawingSession();
            return true;
        }
        return false;
    }
 
    private boolean captureGnssSnapshot() {
        if (activeSession != null && activeSession.drawingCompleted) {
            return false;
        }
        Object qualityObj = MowerLocationData.getProperty("positioningQuality");
        if (!"4".equals(String.valueOf(qualityObj))) {
            return false;
        }
 
        Object latObj = MowerLocationData.getProperty("latitude");
        Object lonObj = MowerLocationData.getProperty("longitude");
        if (!(latObj instanceof Number) || !(lonObj instanceof Number)) {
            return false;
        }
 
        double latitude = ((Number) latObj).doubleValue();
        double longitude = ((Number) lonObj).doubleValue();
 
        if (!Double.isFinite(latitude) || !Double.isFinite(longitude)) {
            return false;
        }
 
        File file = new File("huizhiibanjieGNSS.propertie");
        try {
            if (!file.exists()) {
                File parent = file.getAbsoluteFile().getParentFile();
                if (parent != null && !parent.exists()) {
                    parent.mkdirs();
                }
                file.createNewFile();
            }
 
            List<String> lines = Files.exists(file.toPath()) ? Files.readAllLines(file.toPath(), StandardCharsets.UTF_8) : new ArrayList<>();
            String formatted = formatCoordinate(latitude, longitude);
            if (lines.isEmpty()) {
                lines.add(formatted);
            } else {
                String existing = lines.get(0).trim();
                if (!existing.isEmpty()) {
                    existing = existing + ";" + formatted;
                } else {
                    existing = formatted;
                }
                lines.set(0, existing);
            }
 
            Files.write(file.toPath(), lines, StandardCharsets.UTF_8);
            appendCoordinateToSession(formatted);
            return true;
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        }
    }
 
    private void appendCoordinateToSession(String coordinate) {
        if (coordinate == null || coordinate.isEmpty()) {
            return;
        }
        if (activeSession != null && activeSession.drawingCompleted) {
            return;
        }
        if (getPendingLandNumber() == null) {
            return;
        }
        String existing = dikuaiData.get("boundaryOriginalCoordinates");
        if ((existing == null || existing.isEmpty()) && activeSession != null) {
            existing = activeSession.data.get("boundaryOriginalCoordinates");
        }
        String updated = mergeCoordinates(existing, coordinate);
 
        dikuaiData.put("boundaryOriginalCoordinates", updated);
        if (activeSession != null) {
            activeSession.data.put("boundaryOriginalCoordinates", updated);
        }
    }
 
    private String formatCoordinate(double latitude, double longitude) {
        DecimalFormat df = new DecimalFormat("0.000000");
        return df.format(latitude) + "," + df.format(longitude);
    }
 
    private String mergeCoordinates(String existing, String coordinate) {
        if (existing == null || existing.trim().isEmpty() || "-1".equals(existing.trim())) {
            return coordinate;
        }
        String trimmed = existing.trim();
        if (trimmed.endsWith(";")) {
            trimmed = trimmed.substring(0, trimmed.length() - 1);
        }
        if (trimmed.contains(coordinate)) {
            return trimmed;
        }
        return trimmed + ";" + coordinate;
    }
 
    private String getPendingLandNumber() {
        if (pendingLandNumber != null) {
            updateLandNumberField(pendingLandNumber);
            return pendingLandNumber;
        }
        if (activeSession != null && activeSession.landNumber != null) {
            pendingLandNumber = activeSession.landNumber;
            updateLandNumberField(pendingLandNumber);
            return pendingLandNumber;
        }
        pendingLandNumber = generateNewLandNumber();
        if (activeSession != null) {
            activeSession.landNumber = pendingLandNumber;
        }
        updateLandNumberField(pendingLandNumber);
        return pendingLandNumber;
    }
 
    private String generateNewLandNumber() {
        Map<String, Dikuai> existing = Dikuai.getAllDikuai();
        int attempt = 1;
        while (true) {
            String candidate = "LAND" + attempt;
            if (!existing.containsKey(candidate)) {
                return candidate;
            }
            attempt++;
        }
    }
 
    private void updateLandNumberField(String value) {
        if (landNumberField != null && value != null) {
            landNumberField.setText(value);
        }
    }
 
    private boolean isLandNameDuplicate(String name, String currentLandNumber) {
        if (name == null || name.isEmpty()) {
            return false;
        }
        Map<String, Dikuai> existing = Dikuai.getAllDikuai();
        for (Map.Entry<String, Dikuai> entry : existing.entrySet()) {
            String key = entry.getKey();
            Dikuai dikuai = entry.getValue();
            if (key == null || dikuai == null) {
                continue;
            }
            if (key.equals(currentLandNumber)) {
                continue;
            }
            String existingName = dikuai.getLandName();
            if (existingName != null && !"-1".equals(existingName) && existingName.trim().equalsIgnoreCase(name.trim())) {
                return true;
            }
        }
        return false;
    }
 
    private void closeForDrawingSession() {
        isDrawing = false;
        Shouye shouye = Shouye.getInstance();
        if (shouye != null) {
            shouye.showEndDrawingButton(AddDikuai::finishDrawingSession);
        }
        setVisible(false);
        dispose();
    }
 
    private void applySessionData(DrawingSession session) {
        if (session == null) {
            return;
        }
        pendingLandNumber = session.landNumber;
        dikuaiData.clear();
        dikuaiData.putAll(session.data);
    updateLandNumberField(pendingLandNumber);
        areaNameField.setText(session.areaName != null ? session.areaName : "");
 
        String method = session.data.get("drawingMethod");
        if (method != null) {
            JPanel panel = drawingOptionPanels.get(method);
            if (panel != null) {
                selectDrawingOption(panel, method);
            }
        }
 
        if (session.drawingCompleted) {
            dikuaiData.put("boundaryDrawn", "true");
            if (startEndDrawingBtn != null) {
                startEndDrawingBtn.setText("已完成");
                startEndDrawingBtn.setBackground(MEDIUM_GRAY);
                startEndDrawingBtn.setEnabled(false);
            }
            updateOtherOptionsState(true);
            isDrawing = false;
            showStep(2);
            showBoundaryPointSummary();
        } else {
            if (startEndDrawingBtn != null) {
                startEndDrawingBtn.setText("开始绘制");
                startEndDrawingBtn.setBackground(PRIMARY_COLOR);
                startEndDrawingBtn.setEnabled(true);
            }
            updateOtherOptionsState(false);
            showStep(1);
            hideBoundaryPointSummary();
        }
    }
 
    public static void finishDrawingSession() {
        if (activeSession == null) {
            Shouye shouye = Shouye.getInstance();
            if (shouye != null) {
                shouye.hideEndDrawingButton();
            }
            return;
        }
 
        activeSession.drawingCompleted = true;
        activeSession.data.put("boundaryDrawn", "true");
        Coordinate.setStartSaveGngga(false);
 
        Shouye shouye = Shouye.getInstance();
        if (shouye != null) {
            shouye.hideEndDrawingButton();
        }
 
        resumeRequested = true;
        Component parent = shouye != null ? shouye : null;
        showAddDikuaiDialog(parent);
    }
    
    private void createDikuai() {
        if (!validateCurrentStep()) {
            return;
        }
        
        String areaName = areaNameField.getText().trim();
        dikuaiData.put("areaName", areaName);
 
        String landNumber = getPendingLandNumber();
        Dikuai dikuai = Dikuai.getDikuai(landNumber);
        if (dikuai == null) {
            dikuai = new Dikuai();
            dikuai.setLandNumber(landNumber);
            dikuai.setCreateTime(getCurrentTime());
        } else if (dikuai.getCreateTime() == null || "-1".equals(dikuai.getCreateTime())) {
            dikuai.setCreateTime(getCurrentTime());
        }
 
        dikuai.setLandName(areaName);
        dikuai.setUpdateTime(getCurrentTime());
 
        if (dikuaiData.containsKey("boundaryOriginalCoordinates")) {
            dikuai.setBoundaryOriginalCoordinates(dikuaiData.get("boundaryOriginalCoordinates"));
        }
        if (dikuaiData.containsKey("boundaryCoordinates")) {
            dikuai.setBoundaryCoordinates(dikuaiData.get("boundaryCoordinates"));
        }
        if (dikuaiData.containsKey("landArea")) {
            dikuai.setLandArea(dikuaiData.get("landArea"));
        }
        if (dikuaiData.containsKey("baseStationCoordinates")) {
            dikuai.setBaseStationCoordinates(dikuaiData.get("baseStationCoordinates"));
        }
 
        if (dikuaiData.containsKey("mowingPattern")) {
            dikuai.setMowingPattern(dikuaiData.get("mowingPattern"));
        }
        if (dikuaiData.containsKey("mowingWidth")) {
            dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
        }
 
        String plannedPath = dikuaiData.get("plannedPath");
        if (isMeaningfulValue(plannedPath)) {
            dikuai.setPlannedPath(plannedPath);
        }
 
        Dikuai.putDikuai(landNumber, dikuai);
        Dikuai.saveToProperties();
        
        JOptionPane.showMessageDialog(this, 
            "地块创建成功!\n地块编号: " + landNumber + "\n地块名称: " + areaName, 
            "成功", 
            JOptionPane.INFORMATION_MESSAGE);
 
        createdLandNumber = landNumber;
        pendingLandNumber = null;
        if (activeSession != null && landNumber.equals(activeSession.landNumber)) {
            activeSession = null;
        }
        resumeRequested = false;
        Shouye shouye = Shouye.getInstance();
        if (shouye != null) {
            shouye.hideEndDrawingButton();
        }
        Dikuaiguanli.notifyExternalCreation(landNumber);
        dispose();
    }
 
    private static String getCurrentTime() {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new java.util.Date());
    }
    
    /**
     * 显示新增地块对话框
     * @param parent 父组件
     */
    public static String showAddDikuaiDialog(Component parent) {
        AddDikuai dialog;
        
        Window parentWindow = null;
        if (parent != null) {
            parentWindow = SwingUtilities.getWindowAncestor(parent);
        }
        
        if (parentWindow instanceof JFrame) {
            dialog = new AddDikuai((JFrame) parentWindow);
        } else if (parentWindow instanceof JDialog) {
            dialog = new AddDikuai((JDialog) parentWindow);
        } else {
            dialog = new AddDikuai((JFrame) null);
        }
        if (resumeRequested && activeSession != null) {
            dialog.applySessionData(activeSession);
            resumeRequested = false;
        }
        
        dialog.setVisible(true);
        return dialog.createdLandNumber;
    }
}