123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // 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)..<formatValue.endIndex
- lengthLabel.stringValue = String(formatValue[range])
- }
- }
-
- // MARK: Action
-
- @IBAction func buttonItemClick_Setting(_ sender: Any) {
- delegate?.distanceMeasureInfoWindowControllerSetting(self)
- }
- @IBAction func buttonItemClick_Cancel(_ sender: Any) {
- delegate?.cancelMeasureInfoWindowControllerSetting(self)
- }
- }
|