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/lujing/MowingPathGenerationPage.java | 119 ++++++++++++-----------------------------------------------
1 files changed, 25 insertions(+), 94 deletions(-)
diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 73a8fde..c55639b 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -3,8 +3,6 @@
import javax.swing.*;
import javax.swing.SwingUtilities;
import java.awt.*;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
@@ -23,6 +21,7 @@
import org.locationtech.jts.geom.Coordinate;
import gecaoji.Device;
import java.util.Locale;
+import zhuye.Fuzhibutton;
/**
* 鐢熸垚鍓茶崏璺緞椤甸潰
@@ -762,15 +761,18 @@
titleLabel.setForeground(TEXT_COLOR);
titlePanel.add(titleLabel, BorderLayout.WEST);
- // 鍒涘缓澶嶅埗鎸夐挳
- JButton copyButton = createCopyButton(title, () -> {
- String text = textArea.getText();
- if (text == null || text.trim().isEmpty()) {
- JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- copyToClipboard(text, title);
- });
+ // 鍒涘缓澶嶅埗鎸夐挳锛堜娇鐢� Fuzhibutton锛�
+ JButton copyButton = Fuzhibutton.createCopyButton(
+ () -> {
+ String text = textArea.getText();
+ if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) {
+ return null; // 杩斿洖null浼氳Е鍙�"鏈缃�"鎻愮ず
+ }
+ return text;
+ },
+ "澶嶅埗" + title,
+ new Color(230, 250, 240)
+ );
titlePanel.add(copyButton, BorderLayout.EAST);
section.add(titlePanel, BorderLayout.NORTH);
@@ -812,15 +814,18 @@
titleLabel.setForeground(TEXT_COLOR);
titlePanel.add(titleLabel, BorderLayout.WEST);
- // 鍒涘缓澶嶅埗鎸夐挳
- JButton copyButton = createCopyButton(title, () -> {
- String text = textField.getText();
- if (text == null || text.trim().isEmpty()) {
- JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
- copyToClipboard(text, title);
- });
+ // 鍒涘缓澶嶅埗鎸夐挳锛堜娇鐢� Fuzhibutton锛�
+ JButton copyButton = Fuzhibutton.createCopyButton(
+ () -> {
+ String text = textField.getText();
+ if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) {
+ return null; // 杩斿洖null浼氳Е鍙�"鏈缃�"鎻愮ず
+ }
+ return text;
+ },
+ "澶嶅埗" + title,
+ new Color(230, 250, 240)
+ );
titlePanel.add(copyButton, BorderLayout.EAST);
section.add(titlePanel, BorderLayout.NORTH);
@@ -962,80 +967,6 @@
return "parallel";
}
- /**
- * 鍒涘缓澶嶅埗鎸夐挳
- */
- private JButton createCopyButton(String title, Runnable copyAction) {
- JButton copyButton = new JButton();
- Font titleFont = new Font("寰蒋闆呴粦", Font.BOLD, 14);
- FontMetrics metrics = getFontMetrics(titleFont);
- int iconSize = metrics.getHeight(); // 浣跨敤鏍囬瀛椾綋楂樺害浣滀负鍥炬爣澶у皬
-
- // 鍔犺浇澶嶅埗鍥炬爣
- ImageIcon copyIcon = null;
- ImageIcon successIcon = null;
- try {
- ImageIcon originalCopyIcon = new ImageIcon("image/fuzhi.png");
- Image scaledCopyImage = originalCopyIcon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH);
- copyIcon = new ImageIcon(scaledCopyImage);
-
- // 鍔犺浇鎴愬姛鍥炬爣
- ImageIcon originalSuccessIcon = new ImageIcon("image/fuzhisucc.png");
- Image scaledSuccessImage = originalSuccessIcon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH);
- successIcon = new ImageIcon(scaledSuccessImage);
- } catch (Exception e) {
- // 濡傛灉鍥剧墖鍔犺浇澶辫触锛屼娇鐢ㄦ枃鏈�
- copyButton.setText("澶嶅埗");
- copyButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- System.err.println("鏃犳硶鍔犺浇澶嶅埗鍥炬爣: " + e.getMessage());
- }
-
- final ImageIcon finalCopyIcon = copyIcon;
- final ImageIcon finalSuccessIcon = successIcon;
-
- copyButton.setIcon(finalCopyIcon);
- copyButton.setContentAreaFilled(false);
- copyButton.setBorder(null);
- copyButton.setFocusPainted(false);
- copyButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
- copyButton.setToolTipText("澶嶅埗" + title);
-
- // 娣诲姞鐐瑰嚮浜嬩欢
- copyButton.addActionListener(e -> {
- copyAction.run();
- // 澶嶅埗鎴愬姛鍚庡垏鎹㈠浘鏍�
- if (finalSuccessIcon != null) {
- copyButton.setIcon(finalSuccessIcon);
- // 1绉掑悗鎭㈠鍘熷浘鏍�
- Timer timer = new Timer(1000, evt -> {
- copyButton.setIcon(finalCopyIcon);
- });
- timer.setRepeats(false);
- timer.start();
- }
- });
-
- return copyButton;
- }
-
- /**
- * 澶嶅埗鏂囨湰鍒板壀璐存澘
- */
- private void copyToClipboard(String text, String title) {
- if (text == null || text.trim().isEmpty()) {
- JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
- return;
- }
-
- try {
- StringSelection selection = new StringSelection(text);
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(selection, selection);
- // 鍘绘帀鎴愬姛鎻愮ず寮圭獥
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(this, "澶嶅埗澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
- }
- }
}
--
Gitblit v1.10.0