CPerimeterMeasureInfoWindowController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // CPerimeterMeasureInfoWindowController.swift
  3. // Cisdem PDFMaster
  4. //
  5. // Created by wanjun on 2024/7/16.
  6. //
  7. import Cocoa
  8. protocol CPerimeterMeasureInfoWindowControllerDelegate: AnyObject {
  9. func perimeterMeasureInfoWindowControllerSetting(_ perimeterMeasureInfoWindowController: CPerimeterMeasureInfoWindowController)
  10. }
  11. @objcMembers
  12. class CPerimeterMeasureInfoWindowController: NSWindowController {
  13. @IBOutlet weak var titleLabel: NSTextField!
  14. @IBOutlet weak var scaleTitleLabel: NSTextField!
  15. @IBOutlet weak var lengthTitleLabel: NSTextField!
  16. @IBOutlet weak var precisionTitleLabel: NSTextField!
  17. @IBOutlet weak var angleTitleLabel: NSTextField!
  18. @IBOutlet weak var scaleLabel: NSTextField!
  19. @IBOutlet weak var lengthLabel: NSTextField!
  20. @IBOutlet weak var precisionLabel: NSTextField!
  21. @IBOutlet weak var angleLabel: NSTextField!
  22. @IBOutlet weak var settingsButton: NSButton!
  23. weak var delegate: CPerimeterMeasureInfoWindowControllerDelegate?
  24. var measureInfo: CPDFPerimeterMeasureInfo = CPDFPerimeterMeasureInfo()
  25. convenience init() {
  26. self.init(windowNibName: "CPerimeterMeasureInfoWindowController")
  27. }
  28. override func windowDidLoad() {
  29. super.windowDidLoad()
  30. self.window?.level = .floating
  31. commonInit()
  32. configurationLanguage()
  33. }
  34. func hideFloatingWindow() {
  35. self.window?.orderOut(nil)
  36. }
  37. private func configurationLanguage() {
  38. titleLabel.stringValue = NSLocalizedString("Multilines", comment: "")
  39. scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "")
  40. lengthTitleLabel.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(with measureInfo: CPDFPerimeterMeasureInfo) {
  63. self.measureInfo = measureInfo
  64. scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
  65. let formatValue = measureInfo.formatValue
  66. lengthLabel.stringValue = ""
  67. if formatValue.count > 4 {
  68. let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..<formatValue.endIndex
  69. lengthLabel.stringValue = String(formatValue[range])
  70. }
  71. switch measureInfo.precision {
  72. case 1:
  73. precisionLabel.stringValue = "1"
  74. case 10:
  75. precisionLabel.stringValue = "0.1"
  76. case 100:
  77. precisionLabel.stringValue = "0.01"
  78. case 1000:
  79. precisionLabel.stringValue = "0.001"
  80. case 10000:
  81. precisionLabel.stringValue = "0.0001"
  82. default:
  83. break
  84. }
  85. }
  86. @IBAction func buttonItemClick_Setting(_ sender: Any) {
  87. delegate?.perimeterMeasureInfoWindowControllerSetting(self)
  88. }
  89. }