123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // ImageCompareCellView.swift
- // KdanAuto
- //
- // Created by 朱东勇 on 2022/11/21.
- //
- import Foundation
- import AppKit
- class StringCompareCellView : NSTableCellView {
- @IBOutlet var _titleLbl : NSTextField!
- @IBOutlet var _degreeInfoLbl : NSTextField!
-
- @IBOutlet var _contentView : NSView!
-
- @IBOutlet var _sepLine : NSView!
-
- @IBOutlet var m_textScrollView: NSScrollView!
- @IBOutlet var m_textView: NSTextView!
-
- var _title : String!
- var _fileInfo : NSMutableDictionary!
-
- class func shared() -> StringCompareCellView? {
- var objects : NSArray!
-
- Bundle.main.loadNibNamed("StringCompareCellView", owner: nil, topLevelObjects: &objects)
-
- for tView in objects {
- if let tv = tView as? StringCompareCellView {
- return tv
- }
- }
-
- return nil
- }
-
- override func awakeFromNib() {
- _sepLine.wantsLayer = true;
- _sepLine.layer?.backgroundColor = NSColor.lightGray.cgColor
-
- m_textScrollView.hasVerticalScroller = false
- m_textScrollView.horizontalScrollElasticity = .none
- }
-
- // Setter & Getter
- public func setTitle(_ title:String) {
- _title = title;
-
- _titleLbl.stringValue = _title ?? ""
- }
-
- public func title() -> String? {
- return _title
- }
-
- public func setFileInfo(_ fileInfo:NSMutableDictionary) {
- _fileInfo = fileInfo;
-
- if nil != _fileInfo {
- autoreleasepool {
- let resultPath = NSString(string: _fileInfo.resultPath()).appendingPathExtension("rtf")!
-
- let checkData = NSData.init(contentsOfFile: resultPath as String)! as Data
- var documentAttributes:NSDictionary!
- let attString = NSAttributedString.init(rtf: checkData, documentAttributes: &documentAttributes)
- self.m_textView.textStorage?.setAttributedString(attString!)
-
- if (nil == _fileInfo.refFilePath()) {
- setTitle(String("[\(_fileInfo.objc().fileType()):\(_fileInfo.objc().name())]\(_fileInfo.fileName())"))
- }else {
- let lastPathComponent = NSString(string: _fileInfo.refFilePath()!).lastPathComponent
- setTitle(String("[\(_fileInfo.objc().fileType()):\(_fileInfo.objc().name())]\(_fileInfo.fileName())/\(lastPathComponent)"))
- }
-
- let degree = _fileInfo.degree()
- if degree == -1 {
- _degreeInfoLbl.stringValue = "对照文件不存在"
- _degreeInfoLbl.textColor = NSColor.red
- } else {
- if abs(degree - 100) > 0 {
- _degreeInfoLbl.textColor = NSColor.red
- }else {
- _degreeInfoLbl.textColor = NSColor.blue
- }
- _degreeInfoLbl.stringValue = NSString(format: "相似度:%.2f%%", degree) as String
- }
- }
- }else {
- setTitle("")
- _degreeInfoLbl.stringValue = ""
- }
- }
-
- public func fileInfo() -> NSMutableDictionary {
- return _fileInfo
- }
-
- }
- extension StringCompareCellView {
-
- class func heightFor(_ fileInfo:NSMutableDictionary) -> CGFloat {
- let resultPath = NSString(string: fileInfo.resultPath()).appendingPathExtension("rtf")!
-
- let checkData = NSData.init(contentsOfFile: resultPath as String)! as Data
- var documentAttributes:NSDictionary!
- let attString = NSAttributedString.init(rtf: checkData, documentAttributes: &documentAttributes)
-
- var retSize = attString!.boundingRect(with: CGSizeMake(990, CGFLOAT_MAX),
- options: .usesLineFragmentOrigin.union(.usesFontLeading)).size
-
- return retSize.height + 50
- }
-
- }
- class CustomScrollView: NSScrollView {
-
- override func scroll(_ point: NSPoint) {
- }
-
- override func scrollWheel(with event: NSEvent) {
- self.nextResponder?.scrollWheel(with: event);
- }
- }
|