张世豪
4 天以前 87d7cf316e983b0398b270de03a8092412af8487
src/set/Setsys.java
@@ -13,6 +13,9 @@
    private String firmwareVersion;
    private String appVersion;
    private int idleTrailDurationSeconds = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
    private boolean boundaryLengthVisible = false;  // 默认关闭显示边界距离
    private boolean measurementModeEnabled = false;  // 默认关闭测量模式
    private boolean manualBoundaryDrawingMode = false;  // 默认关闭手动绘制边界模式
    
    private static final String PROPERTIES_FILE = "set.properties";
@@ -86,6 +89,30 @@
    public void setIdleTrailDurationSeconds(int seconds) {
        this.idleTrailDurationSeconds = sanitizeIdleTrailDuration(String.valueOf(seconds));
    }
    public boolean isBoundaryLengthVisible() {
        return boundaryLengthVisible;
    }
    public void setBoundaryLengthVisible(boolean visible) {
        this.boundaryLengthVisible = visible;
    }
    public boolean isMeasurementModeEnabled() {
        return measurementModeEnabled;
    }
    public void setMeasurementModeEnabled(boolean enabled) {
        this.measurementModeEnabled = enabled;
    }
    public boolean isManualBoundaryDrawingMode() {
        return manualBoundaryDrawingMode;
    }
    public void setManualBoundaryDrawingMode(boolean enabled) {
        this.manualBoundaryDrawingMode = enabled;
    }
    /**
     * 初始化方法 - 从properties文件读取数据
@@ -104,15 +131,17 @@
            this.firmwareVersion = "-1".equals(props.getProperty("firmwareVersion")) ? null : props.getProperty("firmwareVersion");
            this.appVersion = "-1".equals(props.getProperty("appVersion")) ? null : props.getProperty("appVersion");
            this.idleTrailDurationSeconds = sanitizeIdleTrailDuration(props.getProperty("idleTrailDurationSeconds"));
            System.out.println("数据初始化完成");
        } catch (FileNotFoundException e) {
            System.err.println("属性文件未找到: " + PROPERTIES_FILE);
            String boundaryLengthVisibleStr = props.getProperty("boundaryLengthVisible");
            this.boundaryLengthVisible = "true".equalsIgnoreCase(boundaryLengthVisibleStr);
            String measurementModeEnabledStr = props.getProperty("measurementModeEnabled");
            this.measurementModeEnabled = "true".equalsIgnoreCase(measurementModeEnabledStr);
            String manualBoundaryDrawingModeStr = props.getProperty("manualBoundaryDrawingMode");
            this.manualBoundaryDrawingMode = "true".equalsIgnoreCase(manualBoundaryDrawingModeStr);
        } catch (FileNotFoundException e) {
            // 文件不存在时,设置所有属性为null
            setAllPropertiesToNull();
        } catch (IOException e) {
            System.err.println("读取属性文件时出错: " + e.getMessage());
        } catch (IOException e) {
            setAllPropertiesToNull();
        }
    }
@@ -149,9 +178,21 @@
                this.idleTrailDurationSeconds = durationSeconds;
                value = String.valueOf(durationSeconds);
                break;
            case "boundaryLengthVisible":
                this.boundaryLengthVisible = "true".equalsIgnoreCase(value);
                break;
            case "measurementModeEnabled":
                this.measurementModeEnabled = "true".equalsIgnoreCase(value);
                break;
            case "manualBoundaryDrawingMode":
                this.manualBoundaryDrawingMode = "true".equalsIgnoreCase(value);
                break;
            case "mapScale":
                // mapScale不需要在内存中存储,直接更新到文件
                break;
            default:
                System.err.println("未知的属性名: " + propertyName);
                return false;
                // 对于其他属性,也允许直接更新到文件(不打印错误)
                break;
        }
        // 更新properties文件
@@ -177,7 +218,6 @@
        // 写回文件
        try (FileOutputStream output = new FileOutputStream(PROPERTIES_FILE)) {
            props.store(output, "Mower Configuration Properties - Updated");
            System.out.println("属性 " + propertyName + " 已更新为: " + value);
            return true;
        } catch (IOException e) {
            System.err.println("更新属性文件失败: " + e.getMessage());
@@ -215,6 +255,9 @@
        this.firmwareVersion = null;
        this.appVersion = null;
        this.idleTrailDurationSeconds = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
        this.boundaryLengthVisible = false;  // 默认关闭
        this.measurementModeEnabled = false;  // 默认关闭测量模式
        this.manualBoundaryDrawingMode = false;  // 默认关闭手动绘制边界模式
    }
    /**