|
@@ -33,6 +33,7 @@ class ActivityView : NSView {
|
|
|
// var _activityView : NSView = NSView()
|
|
|
// var _angle : CGFloat = 0
|
|
|
// var _shapeLayer : CAShapeLayer = CAShapeLayer()
|
|
|
+ var _degree : Double = 0
|
|
|
|
|
|
|
|
|
public override init(frame frameRect: NSRect) {
|
|
@@ -57,6 +58,8 @@ class ActivityView : NSView {
|
|
|
super.awakeFromNib()
|
|
|
|
|
|
loadSubviews()
|
|
|
+
|
|
|
+ updateStatus()
|
|
|
}
|
|
|
|
|
|
|
|
@@ -88,13 +91,12 @@ class ActivityView : NSView {
|
|
|
_titleLbl.wantsLayer = true
|
|
|
_titleLbl.frame = NSMakeRect(0, (height - kActivityTitleHeight) / 2.0, width, kActivityTitleHeight)
|
|
|
_titleLbl.backgroundColor = NSColor.clear
|
|
|
+ _titleLbl.font = NSFont.systemFont(ofSize: 12.0)
|
|
|
_titleLbl.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
_titleLbl.autoresizingMask = .width.union(.minXMargin).union(.maxXMargin).union(.height)
|
|
|
_titleLbl.alignment = .center
|
|
|
_titleLbl.layer?.borderWidth = 1
|
|
|
_titleLbl.layer?.cornerRadius = 4
|
|
|
- _titleLbl.textColor = NSColor.gray
|
|
|
- _titleLbl.layer?.borderColor = NSColor.lightGray.cgColor
|
|
|
|
|
|
if nil == _activityView {
|
|
|
_activityView = NSProgressIndicator.init(frame: self.bounds)
|
|
@@ -155,7 +157,7 @@ class ActivityView : NSView {
|
|
|
case .Wait: do {
|
|
|
_titleLbl.textColor = NSColor.gray
|
|
|
_titleLbl.layer?.borderColor = NSColor.lightGray.cgColor
|
|
|
- _titleLbl.stringValue = "Waiting"
|
|
|
+ _titleLbl.stringValue = "等待中..."
|
|
|
_timer.invalidate()
|
|
|
_timer = Timer()
|
|
|
}
|
|
@@ -166,9 +168,16 @@ class ActivityView : NSView {
|
|
|
// userInfo: nil, repeats: true)
|
|
|
}
|
|
|
case .Finished: do {
|
|
|
- _titleLbl.textColor = NSColor.blue
|
|
|
- _titleLbl.layer?.borderColor = NSColor.blue.cgColor
|
|
|
- _titleLbl.stringValue = "Done"
|
|
|
+ NSLog("_degree=\(_degree)")
|
|
|
+ _titleLbl.stringValue = NSString(format: "完成 %.0f%%", _degree) as String
|
|
|
+
|
|
|
+ if fabs(_degree-100)>=0.1 {
|
|
|
+ _titleLbl.textColor = NSColor.red
|
|
|
+ _titleLbl.layer?.borderColor = NSColor.red.cgColor
|
|
|
+ }else {
|
|
|
+ _titleLbl.textColor = NSColor.blue
|
|
|
+ _titleLbl.layer?.borderColor = NSColor.blue.cgColor
|
|
|
+ }
|
|
|
_timer.invalidate()
|
|
|
_timer = Timer()
|
|
|
}
|
|
@@ -183,34 +192,6 @@ class ActivityView : NSView {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// @objc func updateAnge() {
|
|
|
-// _angle = self._angle + Double.pi/30.0
|
|
|
-//
|
|
|
-//
|
|
|
-// let width = self.frame.width
|
|
|
-// let height = self.frame.height
|
|
|
-//
|
|
|
-// let activitySize = min(width, height)
|
|
|
-// var mulPath = CGMutablePath()
|
|
|
-// let inRadius = activitySize/2 - 3
|
|
|
-// let outRadius = activitySize/2
|
|
|
-// let endRage = self._angle - Double.pi / 3.0
|
|
|
-// mulPath.move(to: CGPointMake(activitySize/2.0 + inRadius*sin(self._angle),
|
|
|
-// activitySize/2.0 + inRadius * cos(self._angle)))
|
|
|
-// mulPath.addLine(to: CGPointMake(activitySize/2.0 + outRadius*sin(self._angle),
|
|
|
-// activitySize/2.0 + outRadius * cos(self._angle)))
|
|
|
-// mulPath.addArc(center: CGPoint(x: activitySize/2.0, y: activitySize/2.0),
|
|
|
-// radius: outRadius,
|
|
|
-// startAngle: self._angle, endAngle: endRage, clockwise: true)
|
|
|
-// mulPath.addLine(to: CGPointMake(activitySize/2 + inRadius*sin(endRage),
|
|
|
-// activitySize/2 + inRadius * cos(endRage)))
|
|
|
-// mulPath.addArc(center: CGPoint(x: activitySize/2.0, y: activitySize/2.0),
|
|
|
-// radius: inRadius,
|
|
|
-// startAngle: endRage, endAngle: self._angle, clockwise: false)
|
|
|
-// self._shapeLayer.path = mulPath
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
/// Setter & Getter
|
|
|
///
|
|
|
func setActivityStatus(_ status:ActivityStatus) {
|
|
@@ -225,5 +206,10 @@ class ActivityView : NSView {
|
|
|
return _status
|
|
|
}
|
|
|
|
|
|
+ func setDegree(_ degree:Double) {
|
|
|
+ _degree = degree;
|
|
|
+
|
|
|
+ updateStatus()
|
|
|
+ }
|
|
|
|
|
|
}
|