From b518f895dec5264fd25e22a68300c40ceba6f43d Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期六, 20 十二月 2025 15:30:20 +0800
Subject: [PATCH] 新增了按钮功能
---
src/dikuai/Dikuaiguanli.java | 169 +++++++++++++++++++++++++++++++++++++------------------
1 files changed, 113 insertions(+), 56 deletions(-)
diff --git a/src/dikuai/Dikuaiguanli.java b/src/dikuai/Dikuaiguanli.java
index 009cc73..740ccf8 100644
--- a/src/dikuai/Dikuaiguanli.java
+++ b/src/dikuai/Dikuaiguanli.java
@@ -11,8 +11,6 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
-import ui.UIConfig;
-import ui.UIUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@@ -30,6 +28,9 @@
import zhuye.MapRenderer;
import zhuye.Shouye;
import zhuye.Coordinate;
+import zhuye.buttonset;
+import zhuye.Fuzhibutton;
+import zhuye.Lookbutton;
import gecaoji.Device;
/**
@@ -314,10 +315,14 @@
contentPanel.add(mowingSafetyDistancePanel);
contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- // 杩斿洖鐐瑰潗鏍囷紙甯︿慨鏀规寜閽級
- contentPanel.add(createCardInfoItemWithButton("杩斿洖鐐瑰潗鏍�:",
- getDisplayValue(dikuai.getReturnPointCoordinates(), "鏈缃�"),
- "淇敼", e -> editReturnPoint(dikuai)));
+ // 寰�杩旂偣璺緞锛堝甫鏌ョ湅鍥炬爣鎸夐挳锛�
+ JPanel returnPathPanel = createCardInfoItemWithButton("寰�杩旂偣璺緞:",
+ getDisplayValue(dikuai.getReturnPathCoordinates(), "鏈缃�"),
+ createViewButton(e -> editReturnPath(dikuai)));
+ configureInteractiveLabel(getInfoItemTitleLabel(returnPathPanel),
+ () -> editReturnPath(dikuai),
+ "鐐瑰嚮鏌ョ湅/缂栬緫寰�杩旂偣璺緞");
+ contentPanel.add(returnPathPanel);
contentPanel.add(Box.createRigidArea(new Dimension(0, 10)));
ObstacleSummary obstacleSummary = getObstacleSummaryFromCache(dikuai.getLandNumber());
@@ -776,9 +781,80 @@
contentPanel.add(scrollPane, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- JButton okButton = new JButton("纭畾");
- JButton cancelButton = new JButton("鍙栨秷");
- JButton copyButton = new JButton("澶嶅埗");
+
+ // 鍒ゆ柇鏄惁鏄線杩旂偣璺緞瀵硅瘽妗�
+ boolean isReturnPathDialog = title != null && title.contains("寰�杩旂偣璺緞");
+ JButton okButton;
+ JButton cancelButton;
+ JButton copyButton;
+
+ if (isReturnPathDialog) {
+ // 寰�杩旂偣璺緞瀵硅瘽妗嗭細浣跨敤 buttonset 椋庢牸鐨勭‘瀹氭寜閽紝鍥炬爣鎸夐挳
+ okButton = buttonset.createStyledButton("鍘荤粯鍒�", new Color(70, 130, 220));
+
+ // 鍙栨秷鎸夐挳浣跨敤 closepage.png 鍥炬爣
+ cancelButton = new JButton();
+ ImageIcon closeIcon = loadIcon("image/closepage.png", 25, 25);
+ if (closeIcon != null) {
+ cancelButton.setIcon(closeIcon);
+ } else {
+ cancelButton.setText("鍏抽棴");
+ }
+ cancelButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+ cancelButton.setForeground(PRIMARY_COLOR);
+ cancelButton.setBorder(BorderFactory.createEmptyBorder());
+ cancelButton.setContentAreaFilled(false);
+ cancelButton.setFocusPainted(false);
+ cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
+ cancelButton.addMouseListener(new MouseAdapter() {
+ public void mouseEntered(MouseEvent e) { cancelButton.setOpaque(true); cancelButton.setBackground(new Color(255, 240, 240)); }
+ public void mouseExited(MouseEvent e) { cancelButton.setOpaque(false); }
+ });
+
+ // 浣跨敤 Fuzhibutton 鍒涘缓澶嶅埗鎸夐挳
+ copyButton = Fuzhibutton.createCopyButton(
+ (java.util.function.Supplier<String>) () -> {
+ String text = textArea.getText();
+ if (text == null) {
+ text = "";
+ }
+ String trimmed = text.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return null; // 杩斿洖null浼氳Е鍙�"鏈缃澶嶅埗鐨勫唴瀹�"鎻愮ず
+ }
+ return text;
+ },
+ "澶嶅埗" + title,
+ new Color(230, 250, 240)
+ );
+
+ } else {
+ // 鍏朵粬瀵硅瘽妗嗕繚鎸佸師鏈夋牱寮�
+ okButton = new JButton("纭畾");
+ cancelButton = new JButton("鍙栨秷");
+ copyButton = new JButton("澶嶅埗");
+
+ // 鍏朵粬瀵硅瘽妗嗙殑澶嶅埗鎸夐挳閫昏緫
+ copyButton.addActionListener(e -> {
+ String text = textArea.getText();
+ if (text == null) {
+ text = "";
+ }
+ String trimmed = text.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ JOptionPane.showMessageDialog(dialog, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ return;
+ }
+ try {
+ StringSelection selection = new StringSelection(text);
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(selection, selection);
+ JOptionPane.showMessageDialog(dialog, title + " 宸插鍒跺埌鍓创鏉�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+ } catch (Exception ex) {
+ JOptionPane.showMessageDialog(dialog, "澶嶅埗澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ });
+ }
final boolean[] confirmed = new boolean[] {false};
final String[] resultHolder = new String[1];
@@ -791,26 +867,6 @@
cancelButton.addActionListener(e -> dialog.dispose());
- copyButton.addActionListener(e -> {
- String text = textArea.getText();
- if (text == null) {
- text = "";
- }
- String trimmed = text.trim();
- if (trimmed.isEmpty() || "-1".equals(trimmed)) {
- JOptionPane.showMessageDialog(dialog, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- try {
- StringSelection selection = new StringSelection(text);
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(selection, selection);
- JOptionPane.showMessageDialog(dialog, title + " 宸插鍒跺埌鍓创鏉�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(dialog, "澶嶅埗澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
- }
- });
-
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
buttonPanel.add(copyButton);
@@ -819,6 +875,18 @@
dialog.setContentPane(contentPanel);
dialog.getRootPane().setDefaultButton(okButton);
dialog.pack();
+
+ // 濡傛灉鏄線杩旂偣璺緞瀵硅瘽妗嗭紝璁剧疆瀹藉害涓洪椤电殑90%锛岄珮搴︿繚鎸佷笉鍙�
+ if (isReturnPathDialog) {
+ Shouye shouye = Shouye.getInstance();
+ if (shouye != null && shouye.getWidth() > 0) {
+ int homeWidth = shouye.getWidth();
+ int dialogWidth = (int)(homeWidth * 0.9);
+ Dimension currentSize = dialog.getSize();
+ dialog.setSize(dialogWidth, currentSize.height);
+ }
+ }
+
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
@@ -1620,27 +1688,8 @@
}
private JButton createViewButton(ActionListener listener) {
- JButton btn = new JButton();
- ImageIcon lookIcon = loadIcon("image/look.png", 25, 25);
- if (lookIcon != null) {
- btn.setIcon(lookIcon);
- } else {
- btn.setText("鏌ョ湅");
- }
- btn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
- btn.setForeground(PRIMARY_COLOR);
- btn.setBorder(BorderFactory.createEmptyBorder());
- 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;
+ // 浣跨敤 Lookbutton 绫诲垱寤烘煡鐪嬫寜閽�
+ return Lookbutton.createViewButton(listener, new Color(230, 250, 240));
}
private JButton createPrimaryFooterButton(String text) {
@@ -1861,13 +1910,21 @@
});
}
- private void editReturnPoint(Dikuai dikuai) {
- FanhuiDialog fd = new FanhuiDialog(SwingUtilities.getWindowAncestor(this), dikuai);
- fd.setVisible(true);
- // 濡傛灉瀵硅瘽妗嗗凡鏇存柊鏁版嵁锛屽埛鏂版樉绀�
- if (fd.isUpdated()) {
- loadDikuaiData();
+ private void editReturnPath(Dikuai dikuai) {
+ if (dikuai == null) {
+ return;
}
+ String edited = promptCoordinateEditing("鏌ョ湅 / 缂栬緫寰�杩旂偣璺緞", dikuai.getReturnPathCoordinates());
+ if (edited == null) {
+ return;
+ }
+ String normalized = normalizeCoordinateInput(edited);
+ if (!saveFieldAndRefresh(dikuai, "returnPathCoordinates", normalized)) {
+ JOptionPane.showMessageDialog(this, "鏃犳硶鏇存柊寰�杩旂偣璺緞", "閿欒", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ String message = "-1".equals(normalized) ? "寰�杩旂偣璺緞宸叉竻绌�" : "寰�杩旂偣璺緞宸叉洿鏂�";
+ JOptionPane.showMessageDialog(this, message, "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
}
/**
--
Gitblit v1.10.0