| | |
| | | import java.awt.event.*; |
| | | import java.awt.datatransfer.*; |
| | | import java.awt.datatransfer.StringSelection; |
| | | import java.io.File; |
| | | import java.math.BigDecimal; |
| | | import ui.UIConfig; |
| | | import ui.UIUtils; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.ArrayList; |
| | | |
| | | import zhangaiwu.AddDikuai; |
| | | import zhangaiwu.Obstacledge; |
| | | import zhuye.MapRenderer; |
| | | import zhuye.Shouye; |
| | | import zhuye.Coordinate; |
| | | |
| | | /** |
| | | * 地块管理面板 - 卡片式布局设计 |
| | |
| | | if (renderer != null) { |
| | | String boundary = (dikuai != null) ? dikuai.getBoundaryCoordinates() : null; |
| | | String plannedPath = (dikuai != null) ? dikuai.getPlannedPath() : null; |
| | | String obstacles = (dikuai != null) ? dikuai.getObstacleCoordinates() : null; |
| | | renderer.setCurrentBoundary(boundary, landNumber, landNumber == null ? null : landName); |
| | | renderer.setCurrentPlannedPath(plannedPath); |
| | | renderer.setCurrentObstacles(obstacles, landNumber); |
| | | boolean showBoundaryPoints = landNumber != null && boundaryPointVisibility.getOrDefault(landNumber, false); |
| | | renderer.setBoundaryPointsVisible(showBoundaryPoints); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static String getCurrentWorkLandNumber() { |
| | | return currentWorkLandNumber; |
| | | } |
| | | |
| | | private ImageIcon loadIcon(String path, int width, int height) { |
| | | try { |
| | | ImageIcon rawIcon = new ImageIcon(path); |
| | |
| | | if (ownerWindow instanceof JDialog) { |
| | | ownerWindow.dispose(); |
| | | } |
| | | Coordinate.coordinates.clear(); |
| | | latestInstance = null; |
| | | SwingUtilities.invokeLater(() -> AddDikuai.showAddDikuaiDialog(parentComponent)); |
| | | }); |
| | |
| | | } |
| | | |
| | | private void addNewObstacle(Dikuai dikuai) { |
| | | String obstacleCoords = JOptionPane.showInputDialog(this, |
| | | "请输入障碍物坐标(格式: 纬度1,经度1;纬度2,经度2;...):"); |
| | | |
| | | if (obstacleCoords != null && !obstacleCoords.trim().isEmpty()) { |
| | | // 更新障碍物坐标 |
| | | Dikuai.updateField(dikuai.getLandNumber(), "obstacleCoordinates", obstacleCoords.trim()); |
| | | Dikuai.updateField(dikuai.getLandNumber(), "updateTime", getCurrentTime()); |
| | | |
| | | // 保存到文件 |
| | | Dikuai.saveToProperties(); |
| | | |
| | | // 刷新显示 |
| | | loadDikuaiData(); |
| | | |
| | | JOptionPane.showMessageDialog(this, "障碍物坐标已添加!", "成功", JOptionPane.INFORMATION_MESSAGE); |
| | | if (dikuai == null) { |
| | | JOptionPane.showMessageDialog(this, "未找到当前地块,无法新增障碍物", "提示", JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | Window windowAncestor = SwingUtilities.getWindowAncestor(this); |
| | | if (windowAncestor instanceof JDialog) { |
| | | windowAncestor.dispose(); |
| | | } |
| | | Component parent = windowAncestor != null ? windowAncestor.getOwner() instanceof Component ? (Component) windowAncestor.getOwner() : windowAncestor : null; |
| | | List<String> existingObstacleNames = loadObstacleNamesForLand(dikuai.getLandNumber()); |
| | | addzhangaiwu.showDialog(parent, dikuai, existingObstacleNames); |
| | | loadDikuaiData(); |
| | | } |
| | | |
| | | private List<String> loadObstacleNamesForLand(String landNumber) { |
| | | List<String> names = new ArrayList<>(); |
| | | if (landNumber == null || landNumber.trim().isEmpty()) { |
| | | return names; |
| | | } |
| | | try { |
| | | File configFile = new File("Obstacledge.properties"); |
| | | if (!configFile.exists()) { |
| | | return names; |
| | | } |
| | | Obstacledge.ConfigManager manager = new Obstacledge.ConfigManager(); |
| | | if (!manager.loadFromFile(configFile.getAbsolutePath())) { |
| | | return names; |
| | | } |
| | | Obstacledge.Plot plot = manager.getPlotById(landNumber.trim()); |
| | | if (plot == null) { |
| | | return names; |
| | | } |
| | | for (Obstacledge.Obstacle obstacle : plot.getObstacles()) { |
| | | if (obstacle == null) { |
| | | continue; |
| | | } |
| | | String name = obstacle.getObstacleName(); |
| | | if (name == null) { |
| | | continue; |
| | | } |
| | | String trimmed = name.trim(); |
| | | if (!trimmed.isEmpty() && !names.contains(trimmed)) { |
| | | names.add(trimmed); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | System.err.println("读取障碍物配置失败: " + ex.getMessage()); |
| | | } |
| | | return names; |
| | | } |
| | | |
| | | private void editMowingWidth(Dikuai dikuai) { |