123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // CAreaMeasureInfoWindowController.swift
- // Cisdem PDFMaster
- //
- // Created by wanjun on 2024/7/16.
- //
- import Cocoa
- import ComPDFKit
- @objc protocol CAreaMeasureInfoWindowControllerDelegate: AnyObject {
- @objc optional func areaMeasureInfoWindowControllerSetting(_ areaMeasureInfoWindowController: CAreaMeasureInfoWindowController)
- }
- class CAreaMeasureInfoWindowController: NSWindowController {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var scaleTitleLabel: NSTextField!
- @IBOutlet weak var areaTitleLabel: NSTextField!
- @IBOutlet weak var precisionTitleLabel: NSTextField!
- @IBOutlet weak var angleTitleLabel: NSTextField!
- @IBOutlet weak var scaleLabel: NSTextField!
- @IBOutlet weak var areaLabel: NSTextField!
- @IBOutlet weak var precisionLabel: NSTextField!
- @IBOutlet weak var angleLabel: NSTextField!
- @IBOutlet weak var settingsButton: NSButton!
- weak var delegate: CAreaMeasureInfoWindowControllerDelegate?
- var measureInfo: CPDFAreaMeasureInfo = CPDFAreaMeasureInfo()
-
- convenience init() {
- self.init(windowNibName: "CAreaMeasureInfoWindowController")
- }
- func hideFloatingWindow() {
- self.window?.orderOut(nil)
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- self.window?.level = .floating
- commonInit()
- configurationLanguage()
- }
-
- private func configurationLanguage() {
- titleLabel.stringValue = NSLocalizedString("Polygon", comment: "")
- scaleTitleLabel.stringValue = NSLocalizedString("Scale:", comment: "")
- areaTitleLabel.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(_ measureInfo: CPDFAreaMeasureInfo) {
- self.measureInfo = measureInfo
- scaleLabel.stringValue = String(format: "%0.0f %@ = %0.0f %@", measureInfo.rulerBase, measureInfo.rulerBaseUnit, measureInfo.rulerTranslate, measureInfo.rulerTranslateUnit)
- let formatValues = measureInfo.formatValue
- areaLabel.stringValue = ""
- if !formatValues.isEmpty {
- let formatArray = formatValues.components(separatedBy: "\n")
- let formatValue = formatArray[0]
- let range = NSRange(location: 4, length: formatValue.count - 4)
- if let range = Range(range, in: formatValue) {
- areaLabel.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?.areaMeasureInfoWindowControllerSetting?(self)
- }
- }
|