CDistanceMeasureInfoWindowController.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // CDistanceMeasureInfoWindowController.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by wanjun on 2024/7/16.
  6. //
  7. import Cocoa
  8. protocol CDistanceMeasureInfoWindowControllerDelegate: AnyObject {
  9. func distanceMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController)
  10. func cancelMeasureInfoWindowControllerSetting(_ distanceMeasureInfoWindowController: CDistanceMeasureInfoWindowController)
  11. }
  12. @objcMembers
  13. class CDistanceMeasureInfoWindowController: NSWindowController {
  14. @IBOutlet weak var scaleLabel: NSTextField!
  15. @IBOutlet weak var lengthLabel: NSTextField!
  16. @IBOutlet weak var precisionLabel: NSTextField!
  17. @IBOutlet weak var angleLabel: NSTextField!
  18. @IBOutlet weak var xLabel: NSTextField!
  19. @IBOutlet weak var yLabel: NSTextField!
  20. @IBOutlet weak var cancelButton: NSButton!
  21. weak var delegate: CDistanceMeasureInfoWindowControllerDelegate?
  22. var measureInfo: CPDFDistanceMeasureInfo = CPDFDistanceMeasureInfo()
  23. convenience init() {
  24. self.init(windowNibName: "CDistanceMeasureInfoWindowController")
  25. }
  26. override func windowDidLoad() {
  27. super.windowDidLoad()
  28. cancelButton.stringValue = NSLocalizedString("Cancel", comment: "")
  29. self.window?.level = .floating
  30. commonInit()
  31. }
  32. func hideFloatingWindow() {
  33. self.window?.orderOut(nil)
  34. }
  35. func reloadData(with measureInfo: CPDFDistanceMeasureInfo) {
  36. self.measureInfo = measureInfo
  37. updateLabels()
  38. }
  39. private func commonInit() {
  40. updateLabels()
  41. }
  42. private func updateLabels() {
  43. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  44. switch measureInfo.precision {
  45. case 1:
  46. precisionLabel.stringValue = "1"
  47. case 10:
  48. precisionLabel.stringValue = "0.1"
  49. case 100:
  50. precisionLabel.stringValue = "0.01"
  51. case 1000:
  52. precisionLabel.stringValue = "0.001"
  53. case 10000:
  54. precisionLabel.stringValue = "0.0001"
  55. default:
  56. precisionLabel.stringValue = ""
  57. }
  58. let formatValue = measureInfo.formatValue
  59. if formatValue.count > 0 {
  60. let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..<formatValue.endIndex
  61. lengthLabel.stringValue = String(formatValue[range])
  62. }
  63. }
  64. // MARK: Action
  65. @IBAction func buttonItemClick_Setting(_ sender: Any) {
  66. delegate?.distanceMeasureInfoWindowControllerSetting(self)
  67. }
  68. @IBAction func buttonItemClick_Cancel(_ sender: Any) {
  69. delegate?.cancelMeasureInfoWindowControllerSetting(self)
  70. }
  71. }