             return nil
         }
     }
+
+    override func viewDidMoveToWindow() {
+        self.window?.becomeKeyWindow()
+    }
     
     override func drawRect(dirtyRect: NSRect) {
         let cy = CGRectGetHeight(self.bounds) / 2

            if value.ratio >= 0.1 {
                let strx = cx + cos(midRadian) * radius * 0.5
                let stry = cy + sin(midRadian) * radius * 0.5
                let string = NSAttributedString(string: String(format: "%.1f%%", value.ratio * 100),
                    attributes: [NSForegroundColorAttributeName: NSColor.whiteColor(), NSFontAttributeName: NSFont.systemFontOfSize(14)])
                let line = CTLineCreateWithAttributedString(string)
                CGContextSetTextPosition(context, strx - 20, stry)
                CGContextSaveGState(context)
                CGContextSetShadow(context, CGSizeMake(1, 1), 5)
                CTLineDraw(line, context)
                CGContextRestoreGState(context)
            }
        }
    }
}

import Cocoa

class StatisticsView: NSView {
    enum LegendType {
        case Ratio
        case ApplicationName

        static let values: [LegendType] = [.Ratio, .ApplicationName]
    }

    private var values: [(legend: String, color: NSColor, ratio: Float)] = []
    private var legendType: LegendType = .Ratio
    
    func updateValues(values: [(legend: String, color: NSColor, ratio: Float)]) {
        self.values = values
