123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // 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 titleLabel: NSTextField!
- @IBOutlet weak var scaleTitleLabel: NSTextField!
- @IBOutlet weak var lengthTitleLabel: NSTextField!
- @IBOutlet weak var precisionTitleLabel: NSTextField!
- @IBOutlet weak var angleTitleLabel: NSTextField!
- @IBOutlet weak var xTitleLabel: NSTextField!
- @IBOutlet weak var yTitleLabel: NSTextField!
- @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!
- @IBOutlet weak var settingsButton: 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()
- configurationLanguage()
- }
-
- private func configurationLanguage() {
- titleLabel.stringValue = NSLocalizedString("Distance Measurement", comment: "")
- scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "")
- lengthTitleLabel.stringValue = NSLocalizedString("Distance", comment: "") + ":"
- precisionTitleLabel.stringValue = NSLocalizedString("Precision", comment: "") + ":"
- angleTitleLabel.stringValue = NSLocalizedString("Angle", comment: "") + ":"
- xTitleLabel.stringValue = NSLocalizedString("X", comment: "") + ":"
- yTitleLabel.stringValue = NSLocalizedString("Y", comment: "") + ""
- settingsButton.title = NSLocalizedString("Settings", comment: "")
- }
-
- func hideFloatingWindow() {
- self.window?.orderOut(nil)
- }
-
- func reloadData(with measureInfo: CPDFDistanceMeasureInfo) {
- self.measureInfo = measureInfo
- updateLabels()
- }
-
- func clearData() {
- self.lengthLabel.stringValue = ""
- self.angleLabel.stringValue = ""
- self.xLabel.stringValue = ""
- self.yLabel.stringValue = ""
-
- self.measureInfo = CPDFDistanceMeasureInfo()
-
- 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)
- }
- }
|