UI improvements

Change-Id: I8b3540f8a49c6a151d5cc54d9a49005e0a3c98d8
diff --git a/osx/MainMenu.xib b/osx/MainMenu.xib
index 62d73fc..8c18853 100644
--- a/osx/MainMenu.xib
+++ b/osx/MainMenu.xib
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4510" systemVersion="12F45" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4510"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -20,8 +20,10 @@
                 <outlet property="daemonStatusHtml" destination="3Ah-G1-XHY" id="dSt-SZ-GY8"/>
                 <outlet property="daemonStatusHtmlView" destination="pEE-BK-JGJ" id="bPo-et-95L"/>
                 <outlet property="daemonStatusView" destination="NBE-Gf-zLc" id="vpG-7z-Wdp"/>
+                <outlet property="dataSentRecv" destination="4e0-ZL-CIw" id="vNx-Ab-CHZ"/>
                 <outlet property="forwardingSettingsView" destination="lQz-E7-PRx" id="8MT-1G-PZi"/>
                 <outlet property="generalSettingsView" destination="A7D-GN-X5W" id="Apc-XD-aOH"/>
+                <outlet property="interestSentRecv" destination="Ryr-5l-j6E" id="APS-Fe-ayk"/>
                 <outlet property="ndnPreferences" destination="c5x-Oa-5tb" id="5qP-ZT-G5y"/>
                 <outlet property="preferencesDelegate" destination="0yn-TQ-4SC" id="OUx-zN-9bt"/>
                 <outlet property="preferencesPanel" destination="coQ-VU-5RU" id="Jb0-qB-W2K"/>
@@ -51,7 +53,6 @@
                 <menuItem title="NDN disconnected" id="yhj-L6-nZL">
                     <modifierMask key="keyEquivalentModifierMask"/>
                 </menuItem>
-                <menuItem isSeparatorItem="YES" id="2xJ-1J-1HK"/>
                 <menuItem title="Status" id="Tap-5m-ZRP">
                     <modifierMask key="keyEquivalentModifierMask"/>
                     <connections>
@@ -90,7 +91,7 @@
             <rect key="frame" x="0.0" y="0.0" width="400" height="200"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3Ah-G1-XHY">
+                <textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" misplaced="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3Ah-G1-XHY">
                     <rect key="frame" x="-3" y="0.0" width="406" height="200"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <constraints>
@@ -112,13 +113,49 @@
             </constraints>
         </customView>
         <customView id="NBE-Gf-zLc">
-            <rect key="frame" x="0.0" y="0.0" width="150" height="20"/>
+            <rect key="frame" x="0.0" y="0.0" width="193" height="67"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="T4F-W2-p5Y">
-                    <rect key="frame" x="19" y="2" width="46" height="18"/>
+                    <rect key="frame" x="3" y="24" width="63" height="18"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Status" id="3iV-EO-iJG">
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Interests" id="3iV-EO-iJG">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GG0-EG-paT">
+                    <rect key="frame" x="3" y="3" width="36" height="18"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Data" id="rfg-ho-nUP">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="saw-m1-FXa">
+                    <rect key="frame" x="70" y="45" width="125" height="18"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title=" Sent / Recv" id="lAv-EF-k8S">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ryr-5l-j6E">
+                    <rect key="frame" x="70" y="24" width="125" height="18"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="0 / 0" id="YpI-NB-6cc">
+                        <font key="font" size="14" name="LucidaGrande"/>
+                        <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4e0-ZL-CIw">
+                    <rect key="frame" x="70" y="3" width="125" height="18"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="0 / 0" id="iWE-0h-6gy">
                         <font key="font" size="14" name="LucidaGrande"/>
                         <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                         <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
@@ -126,12 +163,12 @@
                 </textField>
             </subviews>
         </customView>
-        <customView id="24d-37-bzd">
-            <rect key="frame" x="0.0" y="0.0" width="155" height="20"/>
+        <customView id="24d-37-bzd" customClass="TightMenuItemView">
+            <rect key="frame" x="0.0" y="0.0" width="195" height="20"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
                 <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EUJ-R2-Os4">
-                    <rect key="frame" x="0.0" y="0.0" width="155" height="20"/>
+                    <rect key="frame" x="0.0" y="0.0" width="201" height="20"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Disconnected" drawsBackground="YES" id="4JT-Ml-4Z3">
                         <font key="font" size="14" name="LucidaGrande"/>
@@ -284,7 +321,7 @@
                                     <action selector="openTrafficMapPage:" target="0yn-TQ-4SC" id="62g-PA-oMS"/>
                                 </connections>
                             </button>
-                            <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="1EJ-ak-3K9">
+                            <button verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1EJ-ak-3K9">
                                 <rect key="frame" x="12" y="16" width="178" height="17"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                                 <buttonCell key="cell" type="inline" title="Open Testbed Routing Status" bezelStyle="inline" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Ca1-IW-7he">
@@ -321,7 +358,7 @@
             <rect key="frame" x="0.0" y="0.0" width="480" height="253"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8C0-3r-hw7">
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8C0-3r-hw7">
                     <rect key="frame" x="17" y="210" width="446" height="33"/>
                     <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <constraints>
@@ -394,11 +431,11 @@
                         </subviews>
                         <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
                     </clipView>
-                    <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" id="l9T-JI-kUJ">
+                    <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="l9T-JI-kUJ">
                         <rect key="frame" x="-100" y="-100" width="438" height="16"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
-                    <scroller key="verticalScroller" verticalHuggingPriority="750" id="Ohc-CY-k3U">
+                    <scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="Ohc-CY-k3U">
                         <rect key="frame" x="423" y="17" width="16" height="131"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
@@ -451,6 +488,37 @@
         <customView id="o3g-Q4-BEo">
             <rect key="frame" x="0.0" y="0.0" width="480" height="142"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+            <subviews>
+                <box autoresizesSubviews="NO" ambiguous="YES" misplaced="YES" title="Box" borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="AjO-Oq-adZ">
+                    <rect key="frame" x="17" y="51" width="446" height="73"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <view key="contentView">
+                        <rect key="frame" x="1" y="1" width="444" height="71"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <button verticalHuggingPriority="750" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QOB-7K-MZh">
+                                <rect key="frame" x="12" y="27" width="142" height="17"/>
+                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+                                <buttonCell key="cell" type="inline" title="Obtain NDN Certificate" bezelStyle="inline" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Ojj-gd-p4g">
+                                    <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                                    <font key="font" metaFont="smallSystemBold"/>
+                                </buttonCell>
+                                <connections>
+                                    <action selector="openCertificationPage:" target="0yn-TQ-4SC" id="rAV-xk-Oqt"/>
+                                </connections>
+                            </button>
+                        </subviews>
+                    </view>
+                    <constraints>
+                        <constraint firstAttribute="height" constant="67" id="8oL-hp-hZT"/>
+                        <constraint firstItem="QOB-7K-MZh" firstAttribute="leading" secondItem="AjO-Oq-adZ" secondAttribute="leading" constant="10" id="9fH-IV-tqE"/>
+                        <constraint firstItem="QOB-7K-MZh" firstAttribute="top" secondItem="AjO-Oq-adZ" secondAttribute="top" constant="13" id="JGN-Ek-9g7"/>
+                        <constraint firstAttribute="width" constant="440" id="Y1O-uV-s8j"/>
+                    </constraints>
+                    <color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
+                    <color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                </box>
+            </subviews>
         </customView>
         <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="tRY-ba-DfO" customClass="NSPanel">
             <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" utility="YES"/>
@@ -529,7 +597,7 @@
                     <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KSW-vV-1ew">
                         <rect key="frame" x="20" y="84" width="241" height="24"/>
                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Endpoint (IP address or DNS name)" id="fkh-lb-BcV">
+                        <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Endpoint (IP address)" id="fkh-lb-BcV">
                             <font key="font" size="14" name="LucidaGrande"/>
                             <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                             <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
diff --git a/osx/menu-delegate.h b/osx/menu-delegate.h
index d279fe2..4520f8a 100644
--- a/osx/menu-delegate.h
+++ b/osx/menu-delegate.h
@@ -9,6 +9,7 @@
 #import <Cocoa/Cocoa.h>
 #import "preference-delegate.h"
 #import "system-events.h"
+#import "tight-menu-item-view.h"
 
 @interface MenuDelegate : NSObject <NSApplicationDelegate>
 {
@@ -33,13 +34,15 @@
   
   BOOL m_daemonStarted;
   
+  IBOutlet NSTextField *interestSentRecv;
+  IBOutlet NSTextField *dataSentRecv;
+  
   IBOutlet NSView *daemonStatusView;
   IBOutlet NSTextField *daemonStatusHtml;
   IBOutlet NSView *daemonStatusHtmlView;
   NSAttributedString *m_statusString;
   
-  IBOutlet NSView *connectionStatusView;
-  IBOutlet NSTextField *connectionStatusText;
+  TightMenuItemView *connectionStatusView;
   
   IBOutlet PreferenceDelegate *preferencesDelegate;
 
@@ -47,8 +50,6 @@
   bool m_autoconfInProgress;
 }
 
--(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item;
-
 -(IBAction)openDaemonStatus:(id)sender;
 -(IBAction)showExitConfirmationWindow:(id)sender;
 
diff --git a/osx/menu-delegate.mm b/osx/menu-delegate.mm
index 34ef2d0..eac903b 100644
--- a/osx/menu-delegate.mm
+++ b/osx/menu-delegate.mm
@@ -9,6 +9,7 @@
 #include "config.h"
 #import "menu-delegate.h"
 #import "ndnd-status-operation.h"
+#import "tight-menu-item-view.h"
 
 @implementation MenuDelegate
 
@@ -72,7 +73,13 @@
   [statusItem setTitle:@""];
   [statusItem setImage:m_disconnectedIcon];
   
-  [connectionStatus setView: connectionStatusView];
+  float menuItemHeight = 20;
+
+  NSRect viewRect = NSMakeRect(0, 0, /* width autoresizes */ 1, menuItemHeight);
+  connectionStatusView = [[TightMenuItemView alloc] initWithFrame:viewRect];
+  connectionStatusView.autoresizingMask = NSViewWidthSizable;
+
+  [connectionStatus setView:connectionStatusView];
   [connectionStatus setTarget:self];
   
   [daemonStatus setView: daemonStatusView];
@@ -130,22 +137,6 @@
   }
 }
 
--(void)menu:(NSMenu *)menu willHighlightItem:(NSMenuItem *)item
-{
-  if( ([item view]!=nil) && (item == daemonStatus) )
-  {
-    NSView *view = [item view];
-    
-    [statusPopover showRelativeToRect:[view bounds]
-                   ofView:view
-                   preferredEdge:NSMinXEdge];
-  }
-  else
-  {
-    [statusPopover performClose:nil];
-  }
-}
-
 -(void)onTick:(NSTimer *)timer
 {
   [self updateStatus];
@@ -170,7 +161,7 @@
 {
   if (!m_daemonStarted) {
     m_daemonStarted = true;
-    [connectionStatusText setStringValue:@"Active"];
+    [connectionStatusView setStatus:@"Active"];
     
     [statusItem setImage:m_connectedIcon];
   }
@@ -203,7 +194,7 @@
   if (m_daemonStarted) {
     m_daemonStarted = false;
     
-    [connectionStatusText setStringValue:@"Starting..."];
+    [connectionStatusView setStatus:@"Starting..."];
     
     [statusItem setImage:m_disconnectedIcon];
   }
diff --git a/osx/preference-delegate.h b/osx/preference-delegate.h
index b711155..aa2d28b 100644
--- a/osx/preference-delegate.h
+++ b/osx/preference-delegate.h
@@ -44,6 +44,7 @@
 
 -(IBAction)openRoutingStatusPage:(id)sender;
 -(IBAction)openTrafficMapPage:(id)sender;
+-(IBAction)openCertificationPage:(id)sender;
 
 -(void)updateFibStatus:(NSXMLDocument*)status;
 
diff --git a/osx/preference-delegate.mm b/osx/preference-delegate.mm
index b6a6686..dd0bfaf 100644
--- a/osx/preference-delegate.mm
+++ b/osx/preference-delegate.mm
@@ -121,5 +121,12 @@
   [[NSWorkspace sharedWorkspace] openURL: pageURL];
 }
 
+-(IBAction)openCertificationPage:(id)sender
+{
+  NSURL *pageURL = [NSURL URLWithString:@"http://ndncert.named-data.net"];
+
+  [[NSWorkspace sharedWorkspace] openURL: pageURL];
+}
+
 
 @end
diff --git a/osx/tight-menu-item-view.h b/osx/tight-menu-item-view.h
new file mode 100644
index 0000000..43b04b6
--- /dev/null
+++ b/osx/tight-menu-item-view.h
@@ -0,0 +1,20 @@
+/* -*- Mode: objc; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#import <Foundation/Foundation.h>
+#import <Cocoa/Cocoa.h>
+
+@interface TightMenuItemView : NSView
+{
+  NSString *status;
+}
+
+-(void)setStatus:(NSString*)value;
+
+
+@end
diff --git a/osx/tight-menu-item-view.mm b/osx/tight-menu-item-view.mm
new file mode 100644
index 0000000..acd7830
--- /dev/null
+++ b/osx/tight-menu-item-view.mm
@@ -0,0 +1,49 @@
+//
+/* -*- Mode: objc; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * @copyright See LICENCE for copyright and license information.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Ilya Moiseenko <iliamo@ucla.edu>
+ */
+
+#import "tight-menu-item-view.h"
+
+@implementation TightMenuItemView
+
+-(void)setStatus:(NSString*)value
+{
+  status = value;
+}
+
+- (void) drawRect:(NSRect)dirtyRect
+{
+  [self setSubviews:[NSArray array]];
+
+  NSRect fullBounds = [self bounds];
+  fullBounds.size.height += 4;
+  [[NSBezierPath bezierPathWithRect:fullBounds] setClip];
+
+
+  [[NSColor colorWithCalibratedRed:(70.0f/255.0f)
+                              green:(70.0f/255.0f)
+                              blue:(70.0f/255.0f)
+                              alpha:1.0] set];
+  NSRectFill(fullBounds);
+  
+  NSTextField *connectionStatusText = [[NSTextField alloc] initWithFrame:[self bounds]];
+  [connectionStatusText setTextColor:[NSColor whiteColor]];
+  [connectionStatusText setStringValue:status];
+  [connectionStatusText setEditable:NO];
+  [connectionStatusText setBezeled:NO];
+  [connectionStatusText setDrawsBackground:NO];
+  [connectionStatusText setSelectable:NO];
+  [connectionStatusText setAlignment:NSCenterTextAlignment];
+  NSFont *theFont = [NSFont fontWithName:@"Lucida Grande" size:14];
+  [connectionStatusText setFont:theFont];
+  
+  [self addSubview: connectionStatusText];
+}
+
+
+@end