// // CDistanceMeasureInfoWindowController.swift // Cisdem PDFMaster // // Created by wanjun on 2024/7/16. // import Cocoa protocol CDistanceMeasureInfoWindowControllerDelegate: AnyObject { func distanceMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController) func cancelMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController) } @objcMembers class CDistanceMeasureInfoWindowController: NSWindowController { @IBOutlet weak var scaleLabel: NSTextField! @IBOutlet weak var lengthLabel: NSTextField! @IBOutlet weak var precisionLabel: NSTextField! @IBOutlet weak var angleLabel: NSTextField! @IBOutlet weak var xLabel: NSTextField! @IBOutlet weak var yLabel: NSTextField! @IBOutlet weak var cancelButton: NSButton! weak var delegate: CDistanceMeasureInfoWindowControllerDelegate? var measureInfo: CPDFDistanceMeasureInfo = CPDFDistanceMeasureInfo() convenience init() { self.init(windowNibName: "CDistanceMeasureInfoWindowController") } override func windowDidLoad() { super.windowDidLoad() cancelButton.stringValue = NSLocalizedString("Cancel", comment: "") self.window?.level = .floating commonInit() } func hideFloatingWindow() { self.window?.orderOut(nil) } func reloadData(with measureInfo: CPDFDistanceMeasureInfo) { self.measureInfo = measureInfo updateLabels() } private func commonInit() { updateLabels() } private func updateLabels() { scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit) switch measureInfo.precision { case 1: precisionLabel.stringValue = "1" case 10: precisionLabel.stringValue = "0.1" case 100: precisionLabel.stringValue = "0.01" case 1000: precisionLabel.stringValue = "0.001" case 10000: precisionLabel.stringValue = "0.0001" default: precisionLabel.stringValue = "" } let formatValue = measureInfo.formatValue if formatValue.count > 0 { let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..