From c498385fb7e372d13e2ee76d7b54ae2381728082 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 19:35:57 +0800
Subject: [PATCH] 新增了测量模式
---
src/dikuai/Dikuaiguanli.java | 284 +++++++++++++++++++++++++++++++++++---------------------
1 files changed, 175 insertions(+), 109 deletions(-)
diff --git a/src/dikuai/Dikuaiguanli.java b/src/dikuai/Dikuaiguanli.java
index 5f0218e..c84eecb 100644
--- a/src/dikuai/Dikuaiguanli.java
+++ b/src/dikuai/Dikuaiguanli.java
@@ -213,8 +213,27 @@
headerPanel.add(nameLabel, BorderLayout.WEST);
+ // 鍙充晶鍖哄煙锛氱姸鎬佹枃瀛� + 鎸夐挳
+ JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
+ rightPanel.setBackground(CARD_BACKGROUND);
+ rightPanel.setOpaque(false);
+
+ // 鐘舵�佹枃瀛楁爣绛撅紙鏍规嵁鏄惁閫変腑鏄剧ず/闅愯棌锛�
+ JLabel statusLabel = new JLabel("宸茶缃负褰撳墠鍦板潡");
+ statusLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ statusLabel.setForeground(PRIMARY_COLOR);
+ boolean isCurrent = dikuai.getLandNumber() != null && dikuai.getLandNumber().equals(currentWorkLandNumber);
+ statusLabel.setVisible(isCurrent);
+
JButton workToggleBtn = createWorkToggleButton(dikuai);
- headerPanel.add(workToggleBtn, BorderLayout.EAST);
+
+ // 灏嗙姸鎬佹爣绛惧拰鎸夐挳鍏宠仈锛屼互渚垮湪鎸夐挳鐘舵�佸彉鍖栨椂鏇存柊鏍囩
+ workToggleBtn.putClientProperty("statusLabel", statusLabel);
+
+ rightPanel.add(statusLabel);
+ rightPanel.add(workToggleBtn);
+
+ headerPanel.add(rightPanel, BorderLayout.EAST);
card.add(headerPanel, BorderLayout.NORTH);
@@ -226,12 +245,12 @@
// 鍦板潡缂栧彿
contentPanel.add(createCardInfoItem("鍦板潡缂栧彿:", getDisplayValue(dikuai.getLandNumber(), "鏈煡")));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+
// 娣诲姞鏃堕棿
contentPanel.add(createCardInfoItem("娣诲姞鏃堕棿:", getDisplayValue(dikuai.getCreateTime(), "鏈煡")));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+
// 鍦板潡闈㈢Н
String landArea = dikuai.getLandArea();
if (landArea != null && !landArea.equals("-1")) {
@@ -240,14 +259,14 @@
landArea = "鏈煡";
}
contentPanel.add(createCardInfoItem("鍦板潡闈㈢Н:", landArea));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+
// 杩斿洖鐐瑰潗鏍囷紙甯︿慨鏀规寜閽級
- contentPanel.add(createCardInfoItemWithButton("杩斿洖鐐瑰潗鏍�:",
- getDisplayValue(dikuai.getReturnPointCoordinates(), "鏈缃�"),
+ contentPanel.add(createCardInfoItemWithButton("杩斿洖鐐瑰潗鏍�:",
+ getDisplayValue(dikuai.getReturnPointCoordinates(), "鏈缃�"),
"淇敼", e -> editReturnPoint(dikuai)));
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+
// 鍦板潡杈圭晫鍧愭爣锛堝甫鏄剧ず椤剁偣鎸夐挳锛�
JPanel boundaryPanel = createBoundaryInfoItem(dikuai,
getTruncatedValue(dikuai.getBoundaryCoordinates(), 12, "鏈缃�"));
@@ -256,27 +275,31 @@
() -> editBoundaryCoordinates(dikuai),
"鐐瑰嚮鏌ョ湅/缂栬緫鍦板潡杈圭晫鍧愭爣");
contentPanel.add(boundaryPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
-
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+
ObstacleSummary obstacleSummary = getObstacleSummaryFromCache(dikuai.getLandNumber());
JPanel obstaclePanel = createCardInfoItemWithButton("闅滅鐗�:",
obstacleSummary.buildDisplayValue(),
"鏂板",
e -> addNewObstacle(dikuai));
setInfoItemTooltip(obstaclePanel, obstacleSummary.buildTooltip());
+ // 璁╅殰纰嶇墿鏍囬鍙偣鍑伙紝鎵撳紑闅滅鐗╃鐞嗛〉闈�
+ configureInteractiveLabel(getInfoItemTitleLabel(obstaclePanel),
+ () -> showObstacleManagementPage(dikuai),
+ "鐐瑰嚮鏌ョ湅/绠$悊闅滅鐗�");
contentPanel.add(obstaclePanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
// 璺緞鍧愭爣锛堝甫鏌ョ湅鎸夐挳锛�
- JPanel pathPanel = createCardInfoItemWithButton("璺緞鍧愭爣:",
- getTruncatedValue(dikuai.getPlannedPath(), 12, "鏈缃�"),
+ JPanel pathPanel = createCardInfoItemWithButton("璺緞鍧愭爣:",
+ getTruncatedValue(dikuai.getPlannedPath(), 12, "鏈缃�"),
"澶嶅埗", e -> copyCoordinatesAction("璺緞鍧愭爣", dikuai.getPlannedPath()));
setInfoItemTooltip(pathPanel, dikuai.getPlannedPath());
configureInteractiveLabel(getInfoItemTitleLabel(pathPanel),
() -> editPlannedPath(dikuai),
"鐐瑰嚮鏌ョ湅/缂栬緫璺緞鍧愭爣");
contentPanel.add(pathPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
JPanel baseStationPanel = createCardInfoItemWithButton("鍩虹珯鍧愭爣:",
getTruncatedValue(dikuai.getBaseStationCoordinates(), 12, "鏈缃�"),
@@ -286,7 +309,7 @@
() -> editBaseStationCoordinates(dikuai),
"鐐瑰嚮鏌ョ湅/缂栬緫鍩虹珯鍧愭爣");
contentPanel.add(baseStationPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
JPanel boundaryOriginalPanel = createCardInfoItemWithButton("杈圭晫鍘熷鍧愭爣:",
getTruncatedValue(dikuai.getBoundaryOriginalCoordinates(), 12, "鏈缃�"),
@@ -296,7 +319,7 @@
() -> editBoundaryOriginalCoordinates(dikuai),
"鐐瑰嚮鏌ョ湅/缂栬緫杈圭晫鍘熷鍧愭爣");
contentPanel.add(boundaryOriginalPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
JPanel mowingPatternPanel = createCardInfoItemWithButton("鍓茶崏妯″紡:",
getTruncatedValue(dikuai.getMowingPattern(), 12, "鏈缃�"),
@@ -306,7 +329,7 @@
() -> editMowingPattern(dikuai),
"鐐瑰嚮鏌ョ湅/缂栬緫鍓茶崏妯″紡");
contentPanel.add(mowingPatternPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
String mowingWidthValue = dikuai.getMowingWidth();
String widthSource = null;
@@ -319,7 +342,7 @@
"缂栬緫", e -> editMowingWidth(dikuai));
setInfoItemTooltip(mowingWidthPanel, widthSource);
contentPanel.add(mowingWidthPanel);
- contentPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ contentPanel.add(Box.createRigidArea(new Dimension(0, 15)));
JPanel completedTrackPanel = createCardInfoItemWithButton("宸插畬鎴愬壊鑽夎矾寰�:",
getTruncatedValue(dikuai.getMowingTrack(), 12, "鏈褰�"),
@@ -371,7 +394,10 @@
private JPanel createCardInfoItemWithButton(String label, String value, String buttonText, ActionListener listener) {
JPanel itemPanel = new JPanel(new BorderLayout());
itemPanel.setBackground(CARD_BACKGROUND);
- itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽畬鏁存樉绀猴紙鎸夐挳楂樺害绾�24-28鍍忕礌锛屽姞涓婁笂涓嬭竟璺濓級
+ itemPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 35));
+ itemPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 30));
+ itemPanel.setMinimumSize(new Dimension(0, 28));
JLabel labelComp = new JLabel(label);
labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
@@ -379,13 +405,14 @@
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
rightPanel.setBackground(CARD_BACKGROUND);
+ // 娣诲姞鍨傜洿鍐呰竟璺濅互纭繚鎸夐挳涓嶈瑁佸壀
+ rightPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
JLabel valueComp = new JLabel(value);
valueComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
valueComp.setForeground(TEXT_COLOR);
- JButton button = createSmallButton(buttonText);
- button.addActionListener(listener);
+ JButton button = createSmallLinkButton(buttonText, listener);
rightPanel.add(valueComp);
rightPanel.add(button);
@@ -401,17 +428,19 @@
private JPanel createBoundaryInfoItem(Dikuai dikuai, String displayValue) {
JPanel itemPanel = new JPanel(new BorderLayout());
itemPanel.setBackground(CARD_BACKGROUND);
- int rowHeight = Math.max(36, BOUNDARY_TOGGLE_ICON_SIZE + 12);
+ // 澧炲姞楂樺害浠ョ‘淇濇寜閽笅杈圭紭瀹屾暣鏄剧ず锛堟寜閽珮搴�56锛屽姞涓婁笂涓嬭竟璺濓級
+ int rowHeight = Math.max(60, BOUNDARY_TOGGLE_ICON_SIZE + 16);
Dimension rowDimension = new Dimension(Integer.MAX_VALUE, rowHeight);
itemPanel.setMaximumSize(rowDimension);
itemPanel.setPreferredSize(rowDimension);
- itemPanel.setMinimumSize(new Dimension(0, 32));
+ itemPanel.setMinimumSize(new Dimension(0, 56));
JLabel labelComp = new JLabel("鍦板潡杈圭晫:");
labelComp.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
labelComp.setForeground(LIGHT_TEXT);
- int verticalPadding = Math.max(0, (rowHeight - BOUNDARY_TOGGLE_ICON_SIZE) / 2);
+ // 纭繚鎸夐挳鏈夎冻澶熺殑涓婁笅杈硅窛锛岄伩鍏嶄笅杈圭紭琚鍓�
+ int verticalPadding = Math.max(2, (rowHeight - BOUNDARY_TOGGLE_ICON_SIZE) / 2);
JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));
rightPanel.setBackground(CARD_BACKGROUND);
rightPanel.setBorder(BorderFactory.createEmptyBorder(verticalPadding, 0, verticalPadding, 0));
@@ -838,6 +867,12 @@
}
Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�璺緞瑙勫垝椤甸潰鏃跺叧闂�
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
// 鑾峰彇鍦板潡鍩烘湰鏁版嵁
String baseStationValue = prepareCoordinateForEditor(dikuai.getBaseStationCoordinates());
@@ -897,6 +932,11 @@
callback
);
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
dialog.setVisible(true);
}
@@ -1292,112 +1332,104 @@
return value;
}
+ /**
+ * 鍒涘缓绫讳技浜庨摼鎺ョ殑灏忔寜閽�
+ */
+ private JButton createSmallLinkButton(String text, ActionListener listener) {
+ JButton btn = new JButton(text);
+ btn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+ btn.setForeground(PRIMARY_COLOR);
+ btn.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(PRIMARY_COLOR, 1, true),
+ BorderFactory.createEmptyBorder(2, 6, 2, 6)
+ ));
+ btn.setContentAreaFilled(false);
+ btn.setFocusPainted(false);
+ btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ btn.addMouseListener(new MouseAdapter() {
+ public void mouseEntered(MouseEvent e) { btn.setOpaque(true); btn.setBackground(new Color(230, 250, 240)); }
+ public void mouseExited(MouseEvent e) { btn.setOpaque(false); }
+ });
+ if (listener != null) {
+ btn.addActionListener(listener);
+ }
+ return btn;
+ }
+
private JButton createSmallButton(String text) {
- return createSmallButton(text, PRIMARY_COLOR, PRIMARY_DARK);
+ return createSmallLinkButton(text, null);
}
private JButton createSmallButton(String text, Color backgroundColor, Color hoverColor) {
- JButton button = new JButton(text);
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ // 瀵逛簬闇�瑕佷笉鍚岄鑹茬殑鎸夐挳锛屼娇鐢ㄥ疄蹇冮鏍�
Color baseColor = backgroundColor == null ? PRIMARY_COLOR : backgroundColor;
- Color hover = hoverColor == null ? baseColor : hoverColor;
- button.setBackground(baseColor);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 10));
- button.setMargin(new Insets(0, 0, 0, 0));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
- button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- button.setBackground(hover);
- }
- public void mouseExited(MouseEvent e) {
- button.setBackground(baseColor);
- }
- });
-
- return button;
+ return createStyledButton(text, baseColor, true);
}
private JButton createActionButton(String text, Color color) {
- JButton button = new JButton(text);
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
- button.setBackground(color);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(8, 16, 8, 16));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ return createStyledButton(text, color, true); // 瀹炲績椋庢牸
+ }
- // 鎮仠鏁堟灉
- button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- if (color == RED_COLOR) {
- button.setBackground(RED_DARK);
+ /**
+ * 鍒涘缓鐜颁唬椋庢牸鎸夐挳 (瀹炲績/杞粨)
+ */
+ private JButton createStyledButton(String text, Color baseColor, boolean filled) {
+ JButton btn = new JButton(text) {
+ @Override
+ protected void paintComponent(Graphics g) {
+ Graphics2D g2 = (Graphics2D) g.create();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ boolean isPressed = getModel().isPressed();
+ boolean isRollover = getModel().isRollover();
+
+ if (filled) {
+ if (isPressed) g2.setColor(baseColor.darker());
+ else if (isRollover) g2.setColor(baseColor.brighter());
+ else g2.setColor(baseColor);
+ g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
+ g2.setColor(Color.WHITE);
} else {
- button.setBackground(PRIMARY_DARK);
+ g2.setColor(CARD_BACKGROUND); // 鑳屾櫙
+ g2.fillRoundRect(0, 0, getWidth(), getHeight(), 8, 8);
+
+ if (isPressed) g2.setColor(baseColor.darker());
+ else if (isRollover) g2.setColor(baseColor);
+ else g2.setColor(new Color(200, 200, 200)); // 榛樿杈规鐏�
+
+ g2.setStroke(new BasicStroke(1.2f));
+ g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, 8, 8);
+ g2.setColor(isRollover ? baseColor : TEXT_COLOR);
}
+
+ FontMetrics fm = g2.getFontMetrics();
+ int x = (getWidth() - fm.stringWidth(getText())) / 2;
+ int y = (getHeight() - fm.getHeight()) / 2 + fm.getAscent();
+ g2.drawString(getText(), x, y);
+
+ g2.dispose();
}
- public void mouseExited(MouseEvent e) {
- if (color == RED_COLOR) {
- button.setBackground(RED_COLOR);
- } else {
- button.setBackground(PRIMARY_COLOR);
- }
- }
- });
-
- return button;
+ };
+ btn.setFocusPainted(false);
+ btn.setContentAreaFilled(false);
+ btn.setBorderPainted(false);
+ btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ btn.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 12));
+ return btn;
}
private JButton createDeleteButton() {
- JButton button = new JButton("鍒犻櫎");
- button.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- button.setBackground(RED_COLOR);
- button.setForeground(WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(6, 12, 6, 12));
- button.setFocusPainted(false);
- button.setCursor(new Cursor(Cursor.HAND_CURSOR));
-
+ JButton button = createStyledButton("鍒犻櫎", RED_COLOR, false); // 杞粨椋庢牸
ImageIcon deleteIcon = loadIcon("image/delete.png", 16, 16);
if (deleteIcon != null) {
button.setIcon(deleteIcon);
button.setIconTextGap(6);
}
-
- // 鎮仠鏁堟灉
- button.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- button.setBackground(RED_DARK);
- }
- public void mouseExited(MouseEvent e) {
- button.setBackground(RED_COLOR);
- }
- });
-
return button;
}
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 MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- button.setBackground(PRIMARY_DARK);
- }
-
- public void mouseExited(MouseEvent e) {
- button.setBackground(PRIMARY_COLOR);
- }
- });
-
- return button;
+ return createStyledButton(text, PRIMARY_COLOR, true); // 瀹炲績椋庢牸
}
private JButton createWorkToggleButton(Dikuai dikuai) {
@@ -1427,6 +1459,13 @@
button.setText(isCurrent ? "褰撳墠鍦板潡" : "璁句负褰撳墠");
}
button.setToolTipText(isCurrent ? "鍙栨秷褰撳墠浣滀笟鍦板潡" : "璁句负褰撳墠浣滀笟鍦板潡");
+
+ // 鏇存柊鐘舵�佹枃瀛楁爣绛剧殑鏄剧ず/闅愯棌
+ Object statusLabelObj = button.getClientProperty("statusLabel");
+ if (statusLabelObj instanceof JLabel) {
+ JLabel statusLabel = (JLabel) statusLabelObj;
+ statusLabel.setVisible(isCurrent);
+ }
}
private void ensureWorkIconsLoaded() {
@@ -1507,6 +1546,8 @@
boolean showBoundaryPoints = sanitizedLandNumber != null && boundaryPointVisibility.getOrDefault(sanitizedLandNumber, false);
renderer.setBoundaryPointsVisible(showBoundaryPoints);
renderer.setBoundaryPointSizeScale(showBoundaryPoints ? 0.5d : 1.0d);
+ // 閫�鍑洪瑙堝悗锛屼笉鏄剧ず闅滅鐗╃偣锛堥殰纰嶇墿鐐瑰彧鍦ㄩ瑙堟椂鏄剧ず锛�
+ renderer.setObstaclePointsVisible(false);
}
shouye.refreshMowingIndicators();
}
@@ -1614,6 +1655,31 @@
}
}
+ /**
+ * 鏄剧ず闅滅鐗╃鐞嗛〉闈�
+ */
+ private void showObstacleManagementPage(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
+ }
+ Window owner = SwingUtilities.getWindowAncestor(this);
+
+ // 鑾峰彇鍦板潡绠$悊瀵硅瘽妗嗭紝鍑嗗鍦ㄦ墦寮�闅滅鐗╃鐞嗛〉闈㈡椂鍏抽棴
+ Window managementWindow = null;
+ if (owner instanceof JDialog) {
+ managementWindow = owner;
+ }
+
+ ObstacleManagementPage managementPage = new ObstacleManagementPage(owner, dikuai);
+
+ // 鍏抽棴鍦板潡绠$悊椤甸潰
+ if (managementWindow != null) {
+ managementWindow.dispose();
+ }
+
+ managementPage.setVisible(true);
+ }
+
private void addNewObstacle(Dikuai dikuai) {
if (dikuai == null) {
JOptionPane.showMessageDialog(this, "鏈壘鍒板綋鍓嶅湴鍧楋紝鏃犳硶鏂板闅滅鐗�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
--
Gitblit v1.10.0