123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- //
- // CPerimeterMeasureInfoWindowController.swift
- // Cisdem PDFMaster
- //
- // Created by wanjun on 2024/7/16.
- //
- import Cocoa
- protocol CPerimeterMeasureInfoWindowControllerDelegate: AnyObject {
- func perimeterMeasureInfoWindowControllerSetting(_ perimeterMeasureInfoWindowController: CPerimeterMeasureInfoWindowController)
- }
- @objcMembers
- class CPerimeterMeasureInfoWindowController: 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 scaleLabel: NSTextField!
- @IBOutlet weak var lengthLabel: NSTextField!
- @IBOutlet weak var precisionLabel: NSTextField!
- @IBOutlet weak var angleLabel: NSTextField!
- @IBOutlet weak var settingsButton: NSButton!
- weak var delegate: CPerimeterMeasureInfoWindowControllerDelegate?
- var measureInfo: CPDFPerimeterMeasureInfo = CPDFPerimeterMeasureInfo()
-
- convenience init() {
- self.init(windowNibName: "CPerimeterMeasureInfoWindowController")
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- self.window?.level = .floating
- commonInit()
- configurationLanguage()
- }
-
- func hideFloatingWindow() {
- self.window?.orderOut(nil)
- }
-
- private func configurationLanguage() {
- titleLabel.stringValue = NSLocalizedString("Multilines", comment: "")
- scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "")
- lengthTitleLabel.stringValue = NSLocalizedString("Area", comment: "") + ":"
- precisionTitleLabel.stringValue = NSLocalizedString("Precision", comment: "") + ":"
- angleTitleLabel.stringValue = NSLocalizedString("Angle", comment: "") + ":"
- settingsButton.title = NSLocalizedString("Settings", comment: "")
- }
-
- private func commonInit() {
- 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:
- break
- }
- }
-
- func reloadData(with measureInfo: CPDFPerimeterMeasureInfo) {
- self.measureInfo = measureInfo
- scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
- let formatValue = measureInfo.formatValue
- lengthLabel.stringValue = ""
- if formatValue.count > 4 {
- let range = formatValue.index(formatValue.startIndex, offsetBy: 4)..<formatValue.endIndex
- lengthLabel.stringValue = String(formatValue[range])
- }
- 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:
- break
- }
- }
-
- @IBAction func buttonItemClick_Setting(_ sender: Any) {
- delegate?.perimeterMeasureInfoWindowControllerSetting(self)
- }
- }
|