1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // 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 scaleLabel: NSTextField!
- @IBOutlet weak var areaLabel: NSTextField!
- @IBOutlet weak var precisionLabel: NSTextField!
- @IBOutlet weak var angleLabel: NSTextField!
- 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()
- }
-
- 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)
- }
- }
|