ASIntPropertyCell.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // ASIntPropertyCell.swift
  3. // KdanAuto
  4. //
  5. // Created by 朱东勇 on 2023/4/17.
  6. //
  7. import Cocoa
  8. class ASIntPropertyCell: ASPropertyCell, NSTextFieldDelegate {
  9. @IBOutlet var m_titleLbl:NSTextField!
  10. @IBOutlet var m_valueLbl:NSTextField!
  11. override class func shared() -> ASPropertyCell? {
  12. var objects : NSArray!
  13. Bundle.main.loadNibNamed("ASIntPropertyCell", owner: nil, topLevelObjects: &objects)
  14. for tView in objects {
  15. if let tv = tView as? ASIntPropertyCell {
  16. return tv
  17. }
  18. }
  19. return nil
  20. }
  21. /// Setter
  22. override func setPropertyInfo(_ info:NSDictionary) {
  23. super.setPropertyInfo(info)
  24. self.m_titleLbl.stringValue = "\(info.value(forKey: "Name") ?? ""):"
  25. setValue((info.value(forKey: "DefaultValue") ?? "0") as AnyObject)
  26. }
  27. override func setValue(_ value:AnyObject) {
  28. super.setValue(value)
  29. if (value as? NSNumber) != nil {
  30. self.m_valueLbl.stringValue = "\((value as! NSNumber).intValue)"
  31. }else if ((value as? String) != nil) {
  32. self.m_valueLbl.stringValue = "\((value as! NSString).intValue)"
  33. }
  34. }
  35. override func value() -> AnyObject {
  36. return NSNumber(value: NSString(string: self.m_valueLbl.stringValue).intValue)
  37. }
  38. override func setEnabled(_ enabled:Bool) {
  39. super.setEnabled(enabled)
  40. self.alphaValue = enabled ? 1 : 0.6
  41. self.m_valueLbl.isEnabled = enabled;
  42. }
  43. }