From 68b1f4e85c29164d5de189262282454f9a0b1cc0 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 16 十二月 2025 16:27:41 +0800
Subject: [PATCH] 以割草机视图为中心显示功能
---
src/set/Sets.java | 324 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 202 insertions(+), 122 deletions(-)
diff --git a/src/set/Sets.java b/src/set/Sets.java
index 30829bd..1529e53 100644
--- a/src/set/Sets.java
+++ b/src/set/Sets.java
@@ -2,6 +2,11 @@
import baseStation.BaseStation;
+import zhuye.MapRenderer;
+import zhuye.Shouye;
+import zhuye.buttonset;
+import set.Setsys;
+
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
@@ -27,17 +32,20 @@
// 璁剧疆椤圭粍浠�
private JLabel mowerIdLabel;
+ private JLabel baseStationIdLabel;
private JLabel handheldMarkerLabel;
private JLabel simCardNumberLabel;
private JLabel baseStationSimLabel;
private JLabel firmwareVersionLabel;
private JLabel appVersionLabel;
+ private JLabel idleTrailDurationLabel;
private JButton mowerIdEditBtn;
+ private JButton baseStationIdEditBtn;
private JButton handheldEditBtn;
private JButton checkUpdateBtn;
- private JButton systemDebugButton;
private JButton feedbackButton;
+ private JButton idleTrailEditBtn;
// 鏁版嵁妯″瀷
private Setsys setData;
@@ -100,6 +108,11 @@
setData.getMowerId() != null ? setData.getMowerId() : "鏈缃�", true);
mowerIdLabel = (JLabel) mowerIdPanel.getClientProperty("valueLabel");
mowerIdEditBtn = (JButton) mowerIdPanel.getClientProperty("editButton");
+
+ JPanel baseStationIdPanel = createSettingItemPanel("宸垎鍩哄噯绔欑紪鍙�",
+ resolveBaseStationId(), true);
+ baseStationIdLabel = (JLabel) baseStationIdPanel.getClientProperty("valueLabel");
+ baseStationIdEditBtn = (JButton) baseStationIdPanel.getClientProperty("editButton");
JPanel handheldPanel = createSettingItemPanel("渚挎惡鎵撶偣鍣ㄧ紪鍙�",
setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "鏈缃�", true);
@@ -120,23 +133,37 @@
setData.getFirmwareVersion() != null ? setData.getFirmwareVersion() : "鏈缃�", false);
firmwareVersionLabel = (JLabel) firmwarePanel.getClientProperty("valueLabel");
+ JPanel idleTrailPanel = createSettingItemPanel("杞ㄨ抗鎷栧熬鏃堕暱",
+ formatIdleTrailDurationValue(), true);
+ idleTrailDurationLabel = (JLabel) idleTrailPanel.getClientProperty("valueLabel");
+ idleTrailEditBtn = (JButton) idleTrailPanel.getClientProperty("editButton");
+
JPanel feedbackPanel = createFeedbackPanel();
// APP鐗堟湰
JPanel appVersionPanel = createAppVersionPanel();
- addRowWithSpacing(panel, mowerIdPanel);
+ addRowWithSpacing(panel, mowerIdPanel);
+ addRowWithSpacing(panel, baseStationIdPanel);
addRowWithSpacing(panel, handheldPanel);
addRowWithSpacing(panel, simCardPanel);
addRowWithSpacing(panel, baseStationSimPanel);
addRowWithSpacing(panel, firmwarePanel);
+ addRowWithSpacing(panel, idleTrailPanel);
addRowWithSpacing(panel, feedbackPanel);
addRowWithSpacing(panel, appVersionPanel);
- panel.add(createDebugPanel());
return panel;
}
+ private String formatIdleTrailDurationValue() {
+ int seconds = setData != null ? setData.getIdleTrailDurationSeconds() : Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ if (seconds <= 0) {
+ seconds = Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ }
+ return seconds + "绉�";
+ }
+
private void addRowWithSpacing(JPanel container, JPanel row) {
container.add(row);
container.add(Box.createRigidArea(new Dimension(0, ROW_SPACING)));
@@ -223,28 +250,8 @@
gbc.anchor = GridBagConstraints.EAST;
panel.add(appVersionLabel, gbc);
- checkUpdateBtn = new JButton("妫�鏌ユ洿鏂�");
- checkUpdateBtn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- checkUpdateBtn.setBackground(THEME_COLOR);
- checkUpdateBtn.setForeground(Color.WHITE);
- checkUpdateBtn.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
- checkUpdateBtn.setPreferredSize(new Dimension(100, 28));
- checkUpdateBtn.setMinimumSize(new Dimension(100, 28));
- checkUpdateBtn.setMaximumSize(new Dimension(100, 28));
- checkUpdateBtn.setFocusPainted(false);
-
- checkUpdateBtn.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- checkUpdateBtn.setBackground(new Color(
- Math.max(THEME_COLOR.getRed() - 20, 0),
- Math.max(THEME_COLOR.getGreen() - 20, 0),
- Math.max(THEME_COLOR.getBlue() - 20, 0)
- ));
- }
- public void mouseExited(MouseEvent e) {
- checkUpdateBtn.setBackground(THEME_COLOR);
- }
- });
+ checkUpdateBtn = buttonset.createStyledButton("妫�鏌ユ洿鏂�", THEME_COLOR);
+ checkUpdateBtn.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
gbc = new GridBagConstraints();
gbc.gridx = 2;
@@ -256,62 +263,6 @@
return panel;
}
- private JPanel createDebugPanel() {
- JPanel panel = new JPanel(new GridBagLayout());
- panel.setBackground(PANEL_BACKGROUND);
- panel.setAlignmentX(Component.LEFT_ALIGNMENT);
- panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
- panel.setPreferredSize(new Dimension(Integer.MAX_VALUE, ROW_HEIGHT));
- panel.setMinimumSize(new Dimension(0, ROW_HEIGHT));
-
- GridBagConstraints gbc = new GridBagConstraints();
-
- JLabel titleLabel = new JLabel("绯荤粺璋冭瘯");
- titleLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 14));
- titleLabel.setForeground(Color.BLACK);
- titleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbc.weightx = 0;
- gbc.anchor = GridBagConstraints.EAST;
- gbc.insets = new Insets(0, 0, 0, 12);
- panel.add(titleLabel, gbc);
-
- systemDebugButton = new JButton("绯荤粺璋冭瘯");
- systemDebugButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- systemDebugButton.setBackground(new Color(
- Math.max(THEME_COLOR.getRed() - 20, 0),
- Math.max(THEME_COLOR.getGreen() - 20, 0),
- Math.max(THEME_COLOR.getBlue() - 20, 0)));
- systemDebugButton.setForeground(Color.WHITE);
- systemDebugButton.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
- systemDebugButton.setPreferredSize(new Dimension(100, 28));
- systemDebugButton.setMinimumSize(new Dimension(100, 28));
- systemDebugButton.setMaximumSize(new Dimension(100, 28));
- systemDebugButton.setFocusPainted(false);
-
- systemDebugButton.addMouseListener(new MouseAdapter() {
- public void mouseEntered(MouseEvent e) {
- systemDebugButton.setBackground(THEME_COLOR);
- }
- public void mouseExited(MouseEvent e) {
- systemDebugButton.setBackground(new Color(
- Math.max(THEME_COLOR.getRed() - 20, 0),
- Math.max(THEME_COLOR.getGreen() - 20, 0),
- Math.max(THEME_COLOR.getBlue() - 20, 0)));
- }
- });
-
- gbc = new GridBagConstraints();
- gbc.gridx = 1;
- gbc.gridy = 0;
- gbc.weightx = 1.0;
- gbc.anchor = GridBagConstraints.EAST;
- panel.add(systemDebugButton, gbc);
-
- return panel;
- }
-
private JPanel createFeedbackPanel() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBackground(PANEL_BACKGROUND);
@@ -333,30 +284,8 @@
gbc.insets = new Insets(0, 0, 0, 12);
panel.add(titleLabel, gbc);
- feedbackButton = new JButton("鍙嶉");
+ feedbackButton = buttonset.createStyledButton("鍙嶉", THEME_COLOR);
feedbackButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- feedbackButton.setBackground(THEME_COLOR);
- feedbackButton.setForeground(Color.WHITE);
- feedbackButton.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
- feedbackButton.setPreferredSize(new Dimension(100, 28));
- feedbackButton.setMinimumSize(new Dimension(100, 28));
- feedbackButton.setMaximumSize(new Dimension(100, 28));
- feedbackButton.setFocusPainted(false);
-
- feedbackButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseEntered(MouseEvent e) {
- feedbackButton.setBackground(new Color(
- Math.max(THEME_COLOR.getRed() - 20, 0),
- Math.max(THEME_COLOR.getGreen() - 20, 0),
- Math.max(THEME_COLOR.getBlue() - 20, 0)));
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- feedbackButton.setBackground(THEME_COLOR);
- }
- });
gbc = new GridBagConstraints();
gbc.gridx = 1;
@@ -405,6 +334,48 @@
setData.initializeFromProperties();
baseStation.load();
updateDisplay();
+ // 鍔犺浇骞跺簲鐢ㄤ笂娆′繚瀛樼殑瑙嗗浘涓績鍧愭爣
+ loadViewCenterFromProperties();
+ }
+
+ /**
+ * 浠庨厤缃枃浠跺姞杞借鍥句腑蹇冨潗鏍囧苟搴旂敤鍒癕apRenderer
+ */
+ private void loadViewCenterFromProperties() {
+ Shouye shouye = Shouye.getInstance();
+ if (shouye == null) {
+ return;
+ }
+ MapRenderer renderer = shouye.getMapRenderer();
+ if (renderer == null) {
+ return;
+ }
+
+ // 浠庨厤缃枃浠惰鍙栬鍥句腑蹇冨潗鏍�
+ String viewCenterXValue = Setsys.getPropertyValue("viewCenterX");
+ String viewCenterYValue = Setsys.getPropertyValue("viewCenterY");
+
+ double savedTranslateX = 0.0;
+ double savedTranslateY = 0.0;
+
+ if (viewCenterXValue != null && !viewCenterXValue.trim().isEmpty()) {
+ try {
+ savedTranslateX = Double.parseDouble(viewCenterXValue.trim());
+ } catch (NumberFormatException e) {
+ savedTranslateX = 0.0;
+ }
+ }
+ if (viewCenterYValue != null && !viewCenterYValue.trim().isEmpty()) {
+ try {
+ savedTranslateY = Double.parseDouble(viewCenterYValue.trim());
+ } catch (NumberFormatException e) {
+ savedTranslateY = 0.0;
+ }
+ }
+
+ // 搴旂敤瑙嗗浘涓績鍧愭爣锛堜繚鎸佸綋鍓嶇缉鏀炬瘮渚嬶級
+ double currentScale = renderer.getScale();
+ renderer.setViewTransform(currentScale, savedTranslateX, savedTranslateY);
}
private void updateDisplay() {
@@ -413,6 +384,10 @@
mowerIdLabel.setText(setData.getMowerId() != null ? setData.getMowerId() : "鏈缃�");
}
+ if (baseStationIdLabel != null) {
+ baseStationIdLabel.setText(resolveBaseStationId());
+ }
+
if (handheldMarkerLabel != null) {
handheldMarkerLabel.setText(setData.getHandheldMarkerId() != null ? setData.getHandheldMarkerId() : "鏈缃�");
}
@@ -432,6 +407,10 @@
firmwareVersionLabel.setText(setData.getFirmwareVersion() != null ?
setData.getFirmwareVersion() : "鏈缃�");
}
+
+ if (idleTrailDurationLabel != null) {
+ idleTrailDurationLabel.setText(formatIdleTrailDurationValue());
+ }
// 鏇存柊APP鐗堟湰鏄剧ず
if (appVersionLabel != null) {
@@ -454,12 +433,31 @@
}
return trimmed;
}
+
+ private String resolveBaseStationId() {
+ if (baseStation == null) {
+ return "鏈缃�";
+ }
+ String value = baseStation.getDeviceId();
+ if (value == null) {
+ return "鏈缃�";
+ }
+ String trimmed = value.trim();
+ if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+ return "鏈缃�";
+ }
+ return trimmed;
+ }
private void setupEventHandlers() {
// 鍓茶崏鏈虹紪鍙风紪杈戞寜閽簨浠�
if (mowerIdEditBtn != null) {
mowerIdEditBtn.addActionListener(e -> editMowerId());
}
+
+ if (baseStationIdEditBtn != null) {
+ baseStationIdEditBtn.addActionListener(e -> editBaseStationId());
+ }
// 妫�鏌ユ洿鏂版寜閽簨浠�
if (checkUpdateBtn != null) {
@@ -474,8 +472,8 @@
feedbackButton.addActionListener(e -> showFeedbackDialog());
}
- if (systemDebugButton != null) {
- systemDebugButton.addActionListener(e -> openSystemDebugDialog());
+ if (idleTrailEditBtn != null) {
+ idleTrailEditBtn.addActionListener(e -> editIdleTrailDuration());
}
}
@@ -532,6 +530,97 @@
}
}
+ private void editBaseStationId() {
+ String currentValue = "鏈缃�".equals(resolveBaseStationId()) ? "" : resolveBaseStationId();
+ String newValue = (String) JOptionPane.showInputDialog(this,
+ "璇疯緭鍏ュ樊鍒嗗熀鍑嗙珯缂栧彿:",
+ "淇敼宸垎鍩哄噯绔欑紪鍙�",
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ null,
+ currentValue);
+
+ if (newValue == null) {
+ return;
+ }
+
+ newValue = newValue.trim();
+ if (newValue.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "宸垎鍩哄噯绔欑紪鍙蜂笉鑳戒负绌�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ try {
+ baseStation.updateByDeviceId(newValue,
+ baseStation.getInstallationCoordinates(),
+ baseStation.getIotSimCardNumber(),
+ baseStation.getDeviceActivationTime(),
+ baseStation.getDataUpdateTime());
+ baseStation.load();
+ if (baseStationIdLabel != null) {
+ baseStationIdLabel.setText(resolveBaseStationId());
+ }
+ JOptionPane.showMessageDialog(this, "宸垎鍩哄噯绔欑紪鍙锋洿鏂版垚鍔�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ } catch (IllegalArgumentException ex) {
+ JOptionPane.showMessageDialog(this, ex.getMessage(), "杈撳叆閿欒", JOptionPane.WARNING_MESSAGE);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ JOptionPane.showMessageDialog(this, "宸垎鍩哄噯绔欑紪鍙锋洿鏂板け璐�", "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ private void editIdleTrailDuration() {
+ int currentSeconds = setData != null ? setData.getIdleTrailDurationSeconds() : Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ if (currentSeconds <= 0) {
+ currentSeconds = Setsys.DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ }
+
+ String input = JOptionPane.showInputDialog(this,
+ "璇疯緭鍏ヨ建杩规嫋灏炬椂闀匡紙鍗曚綅锛氱锛�",
+ currentSeconds);
+
+ if (input == null) {
+ return;
+ }
+
+ String trimmed = input.trim();
+ if (trimmed.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "杞ㄨ抗鎷栧熬鏃堕暱涓嶈兘涓虹┖", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ int parsedSeconds;
+ try {
+ parsedSeconds = Integer.parseInt(trimmed);
+ } catch (NumberFormatException ex) {
+ JOptionPane.showMessageDialog(this, "璇疯緭鍏ユ湁鏁堢殑鏁存暟绉掓暟", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ if (parsedSeconds < 5 || parsedSeconds > 600) {
+ JOptionPane.showMessageDialog(this, "璇疯緭鍏�5鍒�600涔嬮棿鐨勭鏁�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ if (setData.updateProperty("idleTrailDurationSeconds", String.valueOf(parsedSeconds))) {
+ int appliedSeconds = setData.getIdleTrailDurationSeconds();
+ if (idleTrailDurationLabel != null) {
+ idleTrailDurationLabel.setText(appliedSeconds + "绉�");
+ }
+ MapRenderer renderer = null;
+ Shouye shouye = Shouye.getInstance();
+ if (shouye != null) {
+ renderer = shouye.getMapRenderer();
+ }
+ if (renderer != null) {
+ renderer.setIdleTrailDurationSeconds(appliedSeconds);
+ }
+ JOptionPane.showMessageDialog(this, "杞ㄨ抗鎷栧熬鏃堕暱宸叉洿鏂颁负 " + appliedSeconds + " 绉�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ JOptionPane.showMessageDialog(this, "杞ㄨ抗鎷栧熬鏃堕暱鏇存柊澶辫触", "閿欒", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
private void showFeedbackDialog() {
JDialog dialog = new JDialog(this, "闂鍙嶉鍜ㄨ", true);
dialog.setLayout(new BorderLayout(0, 12));
@@ -566,9 +655,8 @@
photoControls.setAlignmentX(Component.LEFT_ALIGNMENT);
JLabel photoLabel = new JLabel("閫夋嫨鐓х墖锛堟渶澶�6寮狅級锛�");
photoLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 13));
- JButton selectPhotosButton = new JButton("閫夋嫨鐓х墖");
- selectPhotosButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
- selectPhotosButton.setFocusPainted(false);
+ JButton selectPhotosButton = buttonset.createStyledButton("閫夋嫨鐓х墖", THEME_COLOR);
+ selectPhotosButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
photoControls.add(photoLabel);
photoControls.add(selectPhotosButton);
content.add(photoControls);
@@ -588,13 +676,11 @@
content.add(Box.createRigidArea(new Dimension(0, 20)));
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- JButton cancelButton = new JButton("鏀惧純");
- JButton submitButton = new JButton("鎻愪氦");
- submitButton.setBackground(THEME_COLOR);
- submitButton.setForeground(Color.WHITE);
- submitButton.setFocusPainted(false);
- cancelButton.setFocusPainted(false);
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+ JButton cancelButton = buttonset.createStyledButton("鏀惧純", new Color(128, 128, 128));
+ cancelButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ JButton submitButton = buttonset.createStyledButton("鎻愪氦", THEME_COLOR);
+ submitButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
buttonPanel.add(cancelButton);
buttonPanel.add(submitButton);
@@ -703,12 +789,6 @@
timer.setRepeats(false);
timer.start();
}
-
- private void openSystemDebugDialog() {
- debug dialog = new debug(this, THEME_COLOR);
- dialog.setLocationRelativeTo(this);
- dialog.setVisible(true);
- }
@Override
public void setVisible(boolean visible) {
--
Gitblit v1.10.0