CAreaMeasureInfoWindowController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 titleLabel: NSTextField!
  14. @IBOutlet weak var scaleTitleLabel: NSTextField!
  15. @IBOutlet weak var areaTitleLabel: NSTextField!
  16. @IBOutlet weak var precisionTitleLabel: NSTextField!
  17. @IBOutlet weak var angleTitleLabel: NSTextField!
  18. @IBOutlet weak var scaleLabel: NSTextField!
  19. @IBOutlet weak var areaLabel: NSTextField!
  20. @IBOutlet weak var precisionLabel: NSTextField!
  21. @IBOutlet weak var angleLabel: NSTextField!
  22. @IBOutlet weak var settingsButton: NSButton!
  23. weak var delegate: CAreaMeasureInfoWindowControllerDelegate?
  24. var measureInfo: CPDFAreaMeasureInfo = CPDFAreaMeasureInfo()
  25. convenience init() {
  26. self.init(windowNibName: "CAreaMeasureInfoWindowController")
  27. }
  28. func hideFloatingWindow() {
  29. self.window?.orderOut(nil)
  30. }
  31. override func windowDidLoad() {
  32. super.windowDidLoad()
  33. self.window?.level = .floating
  34. commonInit()
  35. configurationLanguage()
  36. }
  37. private func configurationLanguage() {
  38. titleLabel.stringValue = NSLocalizedString("Polygon", comment: "")
  39. scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "")
  40. areaTitleLabel.stringValue = NSLocalizedString("Area", comment: "") + ":"
  41. precisionTitleLabel.stringValue = NSLocalizedString("Precision", comment: "") + ":"
  42. angleTitleLabel.stringValue = NSLocalizedString("Angle", comment: "") + ":"
  43. settingsButton.title = NSLocalizedString("Settings", comment: "")
  44. }
  45. private func commonInit() {
  46. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  47. switch measureInfo.precision {
  48. case 1:
  49. precisionLabel.stringValue = "1"
  50. case 10:
  51. precisionLabel.stringValue = "0.1"
  52. case 100:
  53. precisionLabel.stringValue = "0.01"
  54. case 1000:
  55. precisionLabel.stringValue = "0.001"
  56. case 10000:
  57. precisionLabel.stringValue = "0.0001"
  58. default:
  59. break
  60. }
  61. }
  62. func reloadData(_ measureInfo: CPDFAreaMeasureInfo) {
  63. self.measureInfo = measureInfo
  64. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  65. let formatValues = measureInfo.formatValue
  66. areaLabel.stringValue = ""
  67. if !formatValues.isEmpty {
  68. let formatArray = formatValues.components(separatedBy: "\n")
  69. let formatValue = formatArray[0]
  70. let range = NSRange(location: 4, length: formatValue.count - 4)
  71. if let range = Range(range, in: formatValue) {
  72. areaLabel.stringValue = String(formatValue[range])
  73. }
  74. }
  75. switch measureInfo.precision {
  76. case 1:
  77. precisionLabel.stringValue = "1"
  78. case 10:
  79. precisionLabel.stringValue = "0.1"
  80. case 100:
  81. precisionLabel.stringValue = "0.01"
  82. case 1000:
  83. precisionLabel.stringValue = "0.001"
  84. case 10000:
  85. precisionLabel.stringValue = "0.0001"
  86. default:
  87. break
  88. }
  89. }
  90. @IBAction func buttonItemClick_Setting(_ sender: Any) {
  91. delegate?.areaMeasureInfoWindowControllerSetting?(self)
  92. }
  93. }