CAreaMeasureInfoWindowController.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // CAreaMeasureInfoWindowController.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by wanjun on 2024/7/16.
  6. //
  7. import Cocoa
  8. import ComPDFKit
  9. @objc protocol CAreaMeasureInfoWindowControllerDelegate: AnyObject {
  10. @objc optional func areaMeasureInfoWindowControllerSetting(_ areaMeasureInfoWindowController: CAreaMeasureInfoWindowController)
  11. }
  12. class CAreaMeasureInfoWindowController: NSWindowController {
  13. @IBOutlet weak var scaleLabel: NSTextField!
  14. @IBOutlet weak var areaLabel: NSTextField!
  15. @IBOutlet weak var precisionLabel: NSTextField!
  16. @IBOutlet weak var angleLabel: NSTextField!
  17. weak var delegate: CAreaMeasureInfoWindowControllerDelegate?
  18. var measureInfo: CPDFAreaMeasureInfo = CPDFAreaMeasureInfo()
  19. convenience init() {
  20. self.init(windowNibName: "CAreaMeasureInfoWindowController")
  21. }
  22. func hideFloatingWindow() {
  23. self.window?.orderOut(nil)
  24. }
  25. override func windowDidLoad() {
  26. super.windowDidLoad()
  27. self.window?.level = .floating
  28. commonInit()
  29. }
  30. private func commonInit() {
  31. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  32. switch measureInfo.precision {
  33. case 1:
  34. precisionLabel.stringValue = "1"
  35. case 10:
  36. precisionLabel.stringValue = "0.1"
  37. case 100:
  38. precisionLabel.stringValue = "0.01"
  39. case 1000:
  40. precisionLabel.stringValue = "0.001"
  41. case 10000:
  42. precisionLabel.stringValue = "0.0001"
  43. default:
  44. break
  45. }
  46. }
  47. func reloadData(_ measureInfo: CPDFAreaMeasureInfo) {
  48. self.measureInfo = measureInfo
  49. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  50. let formatValues = measureInfo.formatValue
  51. areaLabel.stringValue = ""
  52. if !formatValues.isEmpty {
  53. let formatArray = formatValues.components(separatedBy: "\n")
  54. let formatValue = formatArray[0]
  55. let range = NSRange(location: 4, length: formatValue.count - 4)
  56. if let range = Range(range, in: formatValue) {
  57. areaLabel.stringValue = String(formatValue[range])
  58. }
  59. }
  60. switch measureInfo.precision {
  61. case 1:
  62. precisionLabel.stringValue = "1"
  63. case 10:
  64. precisionLabel.stringValue = "0.1"
  65. case 100:
  66. precisionLabel.stringValue = "0.01"
  67. case 1000:
  68. precisionLabel.stringValue = "0.001"
  69. case 10000:
  70. precisionLabel.stringValue = "0.0001"
  71. default:
  72. break
  73. }
  74. }
  75. @IBAction func buttonItemClick_Setting(_ sender: Any) {
  76. delegate?.areaMeasureInfoWindowControllerSetting?(self)
  77. }
  78. }