Merge "Style fixes to Login code" into studio-1.0-dev
diff --git a/src/com/google/gct/login/ui/GoogleLoginAction.java b/src/com/google/gct/login/ui/GoogleLoginAction.java
index 3c28c15..2a655aa 100644
--- a/src/com/google/gct/login/ui/GoogleLoginAction.java
+++ b/src/com/google/gct/login/ui/GoogleLoginAction.java
@@ -45,10 +45,9 @@
   /**
    * Opens up the Google Login panel as a popup.
    */
-  private void showPopup(AnActionEvent e) {
+  private static void showPopup(AnActionEvent e) {
     GoogleLoginUsersPanel usersPanel = new GoogleLoginUsersPanel();
     JComponent source = (JComponent)e.getInputEvent().getSource();
-
     ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(usersPanel, usersPanel.getList());
     JBPopup popup = popupBuilder.createPopup();
     JComponent component = popup.getContent();
diff --git a/src/com/google/gct/login/ui/GoogleLoginCopyAndPasteDialog.java b/src/com/google/gct/login/ui/GoogleLoginCopyAndPasteDialog.java
index ae8ef05..286f647 100644
--- a/src/com/google/gct/login/ui/GoogleLoginCopyAndPasteDialog.java
+++ b/src/com/google/gct/login/ui/GoogleLoginCopyAndPasteDialog.java
@@ -18,7 +18,6 @@
 import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.ValidationInfo;
-import com.intellij.openapi.util.SystemInfo;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -45,22 +44,21 @@
 // TODO: set a maximum size for the dialog
 public class GoogleLoginCopyAndPasteDialog extends DialogWrapper {
   private static final String TITLE = "Sign in to Google Services";
-  private static final String SUB_TITLE_1 =
-    "Please sign in to Google Services from the link below.";
-  private static final String SUB_TITLE_2 =
-    "Copy and paste the verification code that will be provided into the text box below.";
-  private static final String ERROR_MESSAGE = "Please log in using the Google Login url above,"
+  private static final String SUB_TITLE_1 = "Please sign in to Google Services from the link below.";
+  private static final String SUB_TITLE_2 = "Copy and paste the verification code that will be provided into the text box below.";
+  private static final String ERROR_MESSAGE = "Please log in using the Google Login url above, "
     + "and copy and paste the generated verification code.";
-  private String verificationCode = "";
-  private String urlString;
-  private JTextField codeTextField;
+
+  private String myVerificationCode = "";
+  private String myUrlString;
+  private JTextField myCodeTextField;
 
   public GoogleLoginCopyAndPasteDialog(JComponent parent, GoogleAuthorizationCodeRequestUrl requestUrl, String message)
   {
     super(parent, true);
-    urlString = requestUrl.build();
+    myUrlString = requestUrl.build();
 
-    if(message != null) {
+    if (message != null) {
       setTitle(message);
     } else {
       setTitle(TITLE);
@@ -98,9 +96,9 @@
     urlPanel.add(urlLabel);
     urlPanel.add(urlTextField);
 
-    codeLabel.setLabelFor(codeTextField);
+    codeLabel.setLabelFor(myCodeTextField);
     codePanel.add(codeLabel);
-    codePanel.add(codeTextField);
+    codePanel.add(myCodeTextField);
 
     // Add to main panel
     mainPanel.add(Box.createVerticalStrut(10));
@@ -119,7 +117,7 @@
       @Override
       public void actionPerformed(ActionEvent e) {
         super.actionPerformed(e);
-        verificationCode = codeTextField.getText();
+        myVerificationCode = myCodeTextField.getText();
       }
     };
     return myOKAction;
@@ -128,8 +126,8 @@
   @Override
   @Nullable
   protected ValidationInfo doValidate() {
-    if(codeTextField.getText().isEmpty()) {
-      return new ValidationInfo(ERROR_MESSAGE, codeTextField);
+    if(myCodeTextField.getText().isEmpty()) {
+      return new ValidationInfo(ERROR_MESSAGE, myCodeTextField);
     }
     return null;
   }
@@ -137,12 +135,12 @@
 
   @NotNull
   public String getVerificationCode() {
-    return verificationCode;
+    return myVerificationCode;
   }
 
 
   private JTextField createUrlText() {
-    final JTextField urlTextField = new JTextField(urlString);
+    final JTextField urlTextField = new JTextField(myUrlString);
     urlTextField.setBorder(null);
     urlTextField.setEditable(false);
     urlTextField.setBackground(UIUtil.getLabelBackground());
@@ -166,18 +164,18 @@
 
 
   private void createCodeText() {
-    codeTextField = new JTextField();
+    myCodeTextField = new JTextField();
 
     // Add context menu to Url String
     JPopupMenu popup = new JPopupMenu();
-    codeTextField.add(popup);
-    codeTextField.setComponentPopupMenu(popup);
+    myCodeTextField.add(popup);
+    myCodeTextField.setComponentPopupMenu(popup);
 
     JMenuItem copyMenu = new JMenuItem("Paste");
     copyMenu.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {
-        codeTextField.paste();
+        myCodeTextField.paste();
       }
     });
 
diff --git a/src/com/google/gct/login/ui/GoogleLoginEmptyPanel.java b/src/com/google/gct/login/ui/GoogleLoginEmptyPanel.java
index f3e48da..ab83d9c 100644
--- a/src/com/google/gct/login/ui/GoogleLoginEmptyPanel.java
+++ b/src/com/google/gct/login/ui/GoogleLoginEmptyPanel.java
@@ -30,7 +30,6 @@
 public class GoogleLoginEmptyPanel extends JPanel {
   private static final String ADD_ACCOUNT = "Add Account";
   private static final String SIGN_IN = "Sign In";
-  private JButton myAddAccountButton;
   private JBScrollPane myContentScrollPane;
   private JPanel myBottomPane;
 
@@ -38,15 +37,19 @@
     super(new BorderLayout());
 
     myContentScrollPane = new JBScrollPane();
-    myAddAccountButton = new JButton(needsToSignIn() ? SIGN_IN : ADD_ACCOUNT);
-    AddAccountListener addAccountListener = new AddAccountListener();
-    myAddAccountButton.addActionListener(addAccountListener);
-    myAddAccountButton.setHorizontalAlignment(SwingConstants.LEFT);
+    JButton addAccountButton = new JButton(needsToSignIn() ? SIGN_IN : ADD_ACCOUNT);
+    addAccountButton.addActionListener(new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        doLogin();
+      }
+    });
+    addAccountButton.setHorizontalAlignment(SwingConstants.LEFT);
 
     //Create a panel to hold the buttons
     JPanel buttonPane = new JPanel();
     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
-    buttonPane.add(myAddAccountButton);
+    buttonPane.add(addAccountButton);
     buttonPane.add(Box.createHorizontalGlue());
     buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 
@@ -59,20 +62,9 @@
 
   private static boolean needsToSignIn() {
     Map<String, CredentialedUser> users = GoogleLogin.getInstance().getAllUsers();
-
     return users == null || users.isEmpty();
   }
 
-  /**
-   * The action listener for {@code myAddAccountButton}
-   */
-  private class AddAccountListener implements ActionListener {
-    @Override
-    public void actionPerformed(ActionEvent e) {
-      doLogin();
-    }
-  }
-
   protected void doLogin() {
     GoogleLogin.getInstance().logIn();
   }
diff --git a/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java b/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
index a98ce85..0c2853f 100644
--- a/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
+++ b/src/com/google/gct/login/ui/GoogleLoginUsersPanel.java
@@ -49,17 +49,17 @@
 public class GoogleLoginUsersPanel extends JPanel implements ListSelectionListener {
   private static final String PLAY_CONSOLE_URL = "https://play.google.com/apps/publish/#ProfilePlace";
   private static final String CLOUD_CONSOLE_URL = "https://console.developers.google.com/accountsettings";
-  private final static String LEARN_MORE_URL = "https://developers.google.com/cloud/devtools/android_studio_templates/";
-  private JBList list;
-  private DefaultListModel listModel;
+  private static final String LEARN_MORE_URL = "https://developers.google.com/cloud/devtools/android_studio_templates/";
+  private static final String ADD_ACCOUNT = "Add Account";
+  private static final String SIGN_IN = "Sign In";
+  private static final String SIGN_OUT = "Sign Out";
   private static final int MAX_VISIBLE_ROW_COUNT = 3;
-  private static final String addAccountString = "Add Account";
-  private static final String signInString = "Sign In";
-  private static final String signOutString = "Sign Out";
-  private JButton signOutButton;
-  private JButton addAccountButton;
-  private boolean valueChanged = false;
-  private boolean ignoreSelection = false;
+
+  private JBList myList;
+  private DefaultListModel myListModel;
+  private JButton mySignOutButton;
+  private boolean myValueChanged;
+  private boolean myIgnoreSelection;
 
   public GoogleLoginUsersPanel() {
     super(new BorderLayout());
@@ -68,10 +68,10 @@
     final UsersListCellRenderer usersListCellRenderer = new UsersListCellRenderer();
 
     //Create the list that displays the users and put it in a scroll pane.
-    list = new JBList(listModel) {
+    myList = new JBList(myListModel) {
       @Override
       public Dimension getPreferredScrollableViewportSize() {
-        int numUsers = listModel.size();
+        int numUsers = myListModel.size();
         Dimension superPreferredSize = super.getPreferredScrollableViewportSize();
         if(numUsers <= 1) {
           return superPreferredSize;
@@ -91,58 +91,61 @@
       }
     };
 
-    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-    list.setSelectedIndex(indexToSelect);
-    list.addListSelectionListener(this);
-    list.setVisibleRowCount(getVisibleRowCount());
-    list.setCellRenderer(usersListCellRenderer);
-    JBScrollPane listScrollPane = new JBScrollPane(list);
+    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+    myList.setSelectedIndex(indexToSelect);
+    myList.addListSelectionListener(this);
+    myList.setVisibleRowCount(getVisibleRowCount());
+    myList.setCellRenderer(usersListCellRenderer);
+    JBScrollPane listScrollPane = new JBScrollPane(myList);
 
-    list.addMouseListener(new MouseAdapter() {
+    myList.addMouseListener(new MouseAdapter() {
       @Override
       public void mouseClicked(MouseEvent mouseEvent) {
-        list.updateUI();
+        myList.updateUI();
 
-        if(listModel.getSize() == 1 && (listModel.get(0) instanceof NoUsersListItem)) {
+        if (myListModel.getSize() == 1 && (myListModel.get(0) instanceof NoUsersListItem)) {
           // When there are no users available
-          if(usersListCellRenderer.inLearnMoreUrl(mouseEvent.getPoint())){
+          if (usersListCellRenderer.inLearnMoreUrl(mouseEvent.getPoint())) {
             BrowserUtil.browse(LEARN_MORE_URL);
           }
-        } else {
+        }
+        else {
           // When users are available
-          if(!valueChanged) {
+          if (!myValueChanged) {
             // Clicking on an already active user
-            int index = list.locationToIndex(mouseEvent.getPoint());
+            int index = myList.locationToIndex(mouseEvent.getPoint());
             if (index >= 0) {
               boolean inPlayUrl = usersListCellRenderer.inPlayConsoleUrl(mouseEvent.getPoint(), index);
-              if(inPlayUrl){
+              if (inPlayUrl) {
                 BrowserUtil.browse(PLAY_CONSOLE_URL);
-              } else {
+              }
+              else {
                 boolean inCloudUrl = usersListCellRenderer.inCloudConsoleUrl(mouseEvent.getPoint(), index);
-                if(inCloudUrl) {
+                if (inCloudUrl) {
                   BrowserUtil.browse(CLOUD_CONSOLE_URL);
                 }
               }
             }
           }
         }
-        valueChanged = false;
+        myValueChanged = false;
       }
     });
 
-    list.addMouseMotionListener(new MouseMotionListener() {
+    myList.addMouseMotionListener(new MouseMotionListener() {
       @Override
       public void mouseMoved(MouseEvent mouseEvent) {
         // Determine if the user under the cursor is an active user, a non-active user or a non-user
-        int index = list.locationToIndex(mouseEvent.getPoint());
+        int index = myList.locationToIndex(mouseEvent.getPoint());
         if (index >= 0) {
           // If current object is the non-user list item, use default cursor
-          Object currentObject = listModel.get(index);
-          if(currentObject instanceof NoUsersListItem) {
-            if(usersListCellRenderer.inLearnMoreUrl(mouseEvent.getPoint())) {
-              list.setCursor(new Cursor(Cursor.HAND_CURSOR));
-            } else {
-              list.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+          Object currentObject = myListModel.get(index);
+          if (currentObject instanceof NoUsersListItem) {
+            if (usersListCellRenderer.inLearnMoreUrl(mouseEvent.getPoint())) {
+              myList.setCursor(new Cursor(Cursor.HAND_CURSOR));
+            }
+            else {
+              myList.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
             }
             return;
           }
@@ -152,13 +155,13 @@
             boolean inPlayUrl = usersListCellRenderer.inPlayConsoleUrl(mouseEvent.getPoint(), index);
             boolean inCloudUrl = usersListCellRenderer.inCloudConsoleUrl(mouseEvent.getPoint(), index);
             if (inPlayUrl || inCloudUrl) {
-              list.setCursor(new Cursor(Cursor.HAND_CURSOR));
+              myList.setCursor(new Cursor(Cursor.HAND_CURSOR));
             } else {
-              list.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+              myList.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
             }
           } else {
             // For non-active user
-            list.setCursor(new Cursor(Cursor.HAND_CURSOR));
+            myList.setCursor(new Cursor(Cursor.HAND_CURSOR));
           }
         }
       }
@@ -168,24 +171,33 @@
       }
     });
 
-    boolean noUsersAvailable = (listModel.getSize() == 1) && (listModel.get(0) instanceof NoUsersListItem);
-    addAccountButton = new JButton(noUsersAvailable ? signInString : addAccountString);
-    AddAccountListener addAccountListener = new AddAccountListener();
-    addAccountButton.addActionListener(addAccountListener);
+    boolean noUsersAvailable = (myListModel.getSize() == 1) && (myListModel.get(0) instanceof NoUsersListItem);
+    JButton addAccountButton = new JButton(noUsersAvailable ? SIGN_IN : ADD_ACCOUNT);
+    addAccountButton.addActionListener(new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        GoogleLogin.getInstance().logIn();
+      }
+    });
     addAccountButton.setHorizontalAlignment(SwingConstants.LEFT);
 
-    signOutButton = new JButton(signOutString);
-    signOutButton.addActionListener(new SignOutListener());
+    mySignOutButton = new JButton(SIGN_OUT);
+    mySignOutButton.addActionListener(new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        GoogleLogin.getInstance().logOut();
+      }
+    });
 
-    if(list.isSelectionEmpty()) {
-      signOutButton.setEnabled(false);
+    if (myList.isSelectionEmpty()) {
+      mySignOutButton.setEnabled(false);
     } else {
       // If list contains the NoUsersListItem place holder
       // sign out button should be hidden
-      if(noUsersAvailable) {
-        signOutButton.setVisible(false);
+      if (noUsersAvailable) {
+        mySignOutButton.setVisible(false);
       } else {
-        signOutButton.setEnabled(true);
+        mySignOutButton.setEnabled(true);
       }
     }
 
@@ -194,92 +206,72 @@
     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
     buttonPane.add(addAccountButton);
     buttonPane.add(Box.createHorizontalGlue());
-    buttonPane.add(signOutButton);
+    buttonPane.add(mySignOutButton);
     buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
 
     add(listScrollPane, BorderLayout.CENTER);
     add(buttonPane, BorderLayout.PAGE_END);
   }
 
-  /**
-   * The action listener for {@code signOutButton}
-   */
-  class SignOutListener implements ActionListener {
-    @Override
-    public void actionPerformed(ActionEvent e) {
-      GoogleLogin.getInstance().logOut();
-    }
-  }
-
-  /**
-   * The action listener for {@code addAccountButton}
-   */
-  class AddAccountListener implements ActionListener {
-    @Override
-    public void actionPerformed(ActionEvent e) {
-      GoogleLogin.getInstance().logIn();
-    }
-  }
-
   //This method is required by ListSelectionListener.
   @Override
   public void valueChanged(ListSelectionEvent e) {
-    if(ignoreSelection) {
+    if(myIgnoreSelection) {
       return;
     }
-    valueChanged = true;
-    if (e.getValueIsAdjusting() == false) {
-      if (list.getSelectedIndex() == -1) {
-        signOutButton.setEnabled(false);
+    myValueChanged = true;
+    if (!e.getValueIsAdjusting()) {
+      if (myList.getSelectedIndex() == -1) {
+        mySignOutButton.setEnabled(false);
       } else {
-        signOutButton.setEnabled(true);
+        mySignOutButton.setEnabled(true);
 
         // Make newly selected value the active value
-        UsersListItem selectedUser = (UsersListItem)listModel.get(list.getSelectedIndex());
+        UsersListItem selectedUser = (UsersListItem)myListModel.get(myList.getSelectedIndex());
         if(!selectedUser.isActiveUser()) {
           GoogleLogin.getInstance().setActiveUser(selectedUser.getUserEmail());
         }
 
         // Change order of elements in the list so that the
         // active user becomes the first element in the list
-        ignoreSelection = true;
+        myIgnoreSelection = true;
         try {
-          listModel.remove(list.getSelectedIndex());
-          listModel.add(0, selectedUser);
+          myListModel.remove(myList.getSelectedIndex());
+          myListModel.add(0, selectedUser);
 
           // Re-select the active user
-          list.setSelectedIndex(0);
+          myList.setSelectedIndex(0);
         } finally {
-          ignoreSelection = false;
+          myIgnoreSelection = false;
         }
       }
     }
   }
 
   public JBList getList() {
-    return list;
+    return myList;
   }
 
   private int initializeUsers() {
     LinkedHashMap<String, CredentialedUser> allUsers = GoogleLogin.getInstance().getAllUsers();
-    listModel = new DefaultListModel();
+    myListModel = new DefaultListModel();
 
     int activeUserIndex = allUsers.size();
     for(CredentialedUser aUser : allUsers.values()) {
-      listModel.addElement(new UsersListItem(aUser));
+      myListModel.addElement(new UsersListItem(aUser));
       if(aUser.isActive()) {
-        activeUserIndex = listModel .getSize() - 1;
+        activeUserIndex = myListModel.getSize() - 1;
       }
     }
 
-    if(listModel.getSize() == 0) {
+    if(myListModel.getSize() == 0) {
       // Add no user panel
-      listModel.addElement(NoUsersListItem.INSTANCE);
-    } else if ((activeUserIndex != 0) && (activeUserIndex < listModel.getSize())) {
+      myListModel.addElement(NoUsersListItem.INSTANCE);
+    } else if ((activeUserIndex != 0) && (activeUserIndex < myListModel.getSize())) {
       // Change order of elements in the list so that the
       // active user becomes the first element in the list
-      UsersListItem activeUser = (UsersListItem)listModel.remove(activeUserIndex);
-      listModel.add(0, activeUser);
+      UsersListItem activeUser = (UsersListItem)myListModel.remove(activeUserIndex);
+      myListModel.add(0, activeUser);
       activeUserIndex = 0;
     }
 
@@ -287,11 +279,11 @@
   }
 
   private int getVisibleRowCount(){
-    if (listModel == null) {
+    if (myListModel == null) {
       return 0;
     }
 
-    int size = listModel.getSize();
+    int size = myListModel.getSize();
     if(size >= MAX_VISIBLE_ROW_COUNT) {
       return MAX_VISIBLE_ROW_COUNT;
     } else if (size == 0) {
@@ -302,11 +294,11 @@
   }
 
   private boolean isActiveUserInVisibleArea() {
-    int max = listModel.getSize() < MAX_VISIBLE_ROW_COUNT ?
-      listModel.getSize() : MAX_VISIBLE_ROW_COUNT;
+    int max = myListModel.getSize() < MAX_VISIBLE_ROW_COUNT ?
+      myListModel.getSize() : MAX_VISIBLE_ROW_COUNT;
 
     for(int i = 0; i < max; i++){
-      if(((UsersListItem)listModel.get(i)).isActiveUser()) {
+      if(((UsersListItem)myListModel.get(i)).isActiveUser()) {
         return true;
       }
     }
diff --git a/src/com/google/gct/login/ui/NoUsersListItem.java b/src/com/google/gct/login/ui/NoUsersListItem.java
index 26b1427..9461dbd 100644
--- a/src/com/google/gct/login/ui/NoUsersListItem.java
+++ b/src/com/google/gct/login/ui/NoUsersListItem.java
@@ -16,11 +16,10 @@
 package com.google.gct.login.ui;
 
 /**
- * A place holder for when no user exist. This allows us to create
- * a customized panel when no users exist.
+ * A place holder for when no user exist. This allows us to create a customized panel when no users exist.
  */
 public class NoUsersListItem {
-  public static NoUsersListItem INSTANCE = new NoUsersListItem();
+  public static final NoUsersListItem INSTANCE = new NoUsersListItem();
 
   private NoUsersListItem() {
   }
diff --git a/src/com/google/gct/login/ui/UsersListCellRenderer.java b/src/com/google/gct/login/ui/UsersListCellRenderer.java
index a0534a7..61bf310 100644
--- a/src/com/google/gct/login/ui/UsersListCellRenderer.java
+++ b/src/com/google/gct/login/ui/UsersListCellRenderer.java
@@ -48,9 +48,7 @@
   private final static String DEFAULT_AVATAR = "/icons/loginAvatar@2x.png";
   private final static String SIGN_IN_TEXT = "<HTML> Sign in with your Google account to start <br> adding "
     + "Cloud functionality to your <br> Android applications from Android Studio. </HTML>";
-  private final static String LEARN_MORE_TEXT = "Learn more";
-  private final Color myActiveColor;
-  private final Color myInactiveColor;
+  private static final String LEARN_MORE_TEXT = "Learn more";
   private static final int PLAIN_USER_IMAGE_WIDTH = 48;
   private static final int PLAIN_USER_IMAGE_HEIGHT = 48;
   private static final int ACTIVE_USER_IMAGE_WIDTH = 96;
@@ -63,6 +61,8 @@
   private static final int USER_LABEL_VERTICAL_STRUT = 3;
   private static final int HGAP = 10;
   private static final int VGAP = 10;
+  private final Color myActiveColor;
+  private final Color myInactiveColor;
   private final int myGeneralFontHeight;
   private final Font myNameFont;
   private final Font myGeneralFont;
diff --git a/src/com/google/gct/login/ui/UsersListItem.java b/src/com/google/gct/login/ui/UsersListItem.java
index b8f9893..4fac9b1 100644
--- a/src/com/google/gct/login/ui/UsersListItem.java
+++ b/src/com/google/gct/login/ui/UsersListItem.java
@@ -25,7 +25,7 @@
 public class UsersListItem {
   private final CredentialedUser myUser;
 
-  public UsersListItem (CredentialedUser aUser) {
+  public UsersListItem(CredentialedUser aUser) {
     myUser = aUser;
   }