summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lockwood <alockwood@google.com>2014-10-10 16:20:18 +0000
committerAlex Lockwood <alockwood@google.com>2014-10-10 16:20:18 +0000
commitb8e23896b6d142f4c5ef12ff9eff07b51f671d9a (patch)
tree3a16c382b4b94bbc4b49651a8b3b5711971bccf0
parent3e1eaf1cb5ec4cf913b785c5100a539ce4cf7df9 (diff)
downloadlogin-b8e23896b6d142f4c5ef12ff9eff07b51f671d9a.tar.gz
Revert "Revert "Fixed user login image flicker/glitch""
This reverts commit 3e1eaf1cb5ec4cf913b785c5100a539ce4cf7df9. Change-Id: Iacc358ad4678ed55421faad98fe1a786e68d9a40
-rw-r--r--src/com/google/gct/login/CredentialedUserRoster.java57
-rw-r--r--src/com/google/gct/login/GoogleLogin.java76
-rw-r--r--src/com/google/gct/login/GoogleLoginListener.java3
-rw-r--r--src/com/google/gct/login/GoogleLoginPrefs.java7
-rw-r--r--src/com/google/gct/login/GoogleLoginUtils.java3
-rw-r--r--src/com/google/gct/login/OAuthScopeRegistry.java9
-rw-r--r--src/com/google/gct/login/ui/UsersListCellRenderer.java96
7 files changed, 127 insertions, 124 deletions
diff --git a/src/com/google/gct/login/CredentialedUserRoster.java b/src/com/google/gct/login/CredentialedUserRoster.java
index 7d50c70..d8936fb 100644
--- a/src/com/google/gct/login/CredentialedUserRoster.java
+++ b/src/com/google/gct/login/CredentialedUserRoster.java
@@ -29,22 +29,19 @@ import java.util.Map;
* {@link CredentialedUser} objects.
*/
public class CredentialedUserRoster {
- private final LinkedHashMap<String, CredentialedUser> allUsers = new LinkedHashMap<String, CredentialedUser>();
- private CredentialedUser activeUser;
- private Collection<GoogleLoginListener> listeners;
-
- public CredentialedUserRoster() {
- listeners = Lists.newLinkedList();
- }
+ private final LinkedHashMap<String, CredentialedUser> myAllUsers = new LinkedHashMap<String, CredentialedUser>();
+ private final Collection<GoogleLoginListener> myListeners = Lists.newLinkedList();
+ private CredentialedUser myActiveUser;
/**
* Returns a copy of the map of the current logged in users.
* @return Copy of current logged in users.
*/
+ @NotNull
public LinkedHashMap<String, CredentialedUser> getAllUsers() {
synchronized (this) {
LinkedHashMap<String, CredentialedUser> clone = new LinkedHashMap<String, CredentialedUser>();
- clone.putAll(allUsers);
+ clone.putAll(myAllUsers);
return clone;
}
}
@@ -55,8 +52,8 @@ public class CredentialedUserRoster {
*/
public void setAllUsers(Map<String, CredentialedUser> users) {
synchronized (this) {
- allUsers.clear();
- allUsers.putAll(users);
+ myAllUsers.clear();
+ myAllUsers.putAll(users);
}
}
@@ -66,7 +63,7 @@ public class CredentialedUserRoster {
*/
@Nullable
public CredentialedUser getActiveUser() {
- return activeUser;
+ return myActiveUser;
}
/**
@@ -78,16 +75,16 @@ public class CredentialedUserRoster {
*/
public void setActiveUser(@NotNull String userEmail) throws IllegalArgumentException {
synchronized (this) {
- if(!allUsers.containsKey(userEmail)) {
+ if (!myAllUsers.containsKey(userEmail)) {
throw new IllegalArgumentException(userEmail + " is not a logged in user.");
}
- if(activeUser != null) {
- activeUser.setActive(false);
+ if (myActiveUser != null) {
+ myActiveUser.setActive(false);
}
- activeUser = allUsers.get(userEmail);
- activeUser.setActive(true);
+ myActiveUser = myAllUsers.get(userEmail);
+ myActiveUser.setActive(true);
GoogleLoginPrefs.saveActiveUser(userEmail);
notifyLoginStatusChange();
}
@@ -98,9 +95,9 @@ public class CredentialedUserRoster {
*/
public void removeActiveUser() {
synchronized (this) {
- if(activeUser != null) {
- activeUser.setActive(false);
- activeUser = null;
+ if (myActiveUser != null) {
+ myActiveUser.setActive(false);
+ myActiveUser = null;
GoogleLoginPrefs.removeActiveUser();
notifyLoginStatusChange();
}
@@ -113,7 +110,7 @@ public class CredentialedUserRoster {
*/
public int numberOfUsers() {
synchronized (this) {
- return allUsers.size();
+ return myAllUsers.size();
}
}
@@ -122,7 +119,7 @@ public class CredentialedUserRoster {
* @return True if there is an active user and false otherwise.
*/
public boolean isActiveUserAvailable() {
- return activeUser != null;
+ return myActiveUser != null;
}
/**
@@ -134,7 +131,7 @@ public class CredentialedUserRoster {
*/
public void addUser(CredentialedUser user) {
synchronized (this) {
- allUsers.put(user.getEmail(), user);
+ myAllUsers.put(user.getEmail(), user);
setActiveUser(user.getEmail());
}
}
@@ -150,16 +147,16 @@ public class CredentialedUserRoster {
*/
public boolean removeUser(String userEmail) {
synchronized (this) {
- if(!allUsers.containsKey(userEmail)) {
+ if (!myAllUsers.containsKey(userEmail)) {
return false;
}
- if(activeUser.getEmail().equals(userEmail)) {
- activeUser = null;
+ if (myActiveUser.getEmail().equals(userEmail)) {
+ myActiveUser = null;
GoogleLoginPrefs.removeActiveUser();
}
- allUsers.remove(userEmail);
+ myAllUsers.remove(userEmail);
notifyLoginStatusChange();
return true;
}
@@ -172,14 +169,14 @@ public class CredentialedUserRoster {
* @param listener the specified {@code GoogleLoginListener}
*/
void addLoginListener(GoogleLoginListener listener) {
- synchronized(listeners) {
- listeners.add(listener);
+ synchronized(myListeners) {
+ myListeners.add(listener);
}
}
private void notifyLoginStatusChange() {
- synchronized(listeners) {
- for (GoogleLoginListener listener : listeners) {
+ synchronized(myListeners) {
+ for (GoogleLoginListener listener : myListeners) {
listener.statusChanged();
}
}
diff --git a/src/com/google/gct/login/GoogleLogin.java b/src/com/google/gct/login/GoogleLogin.java
index 7ddf670..4676152 100644
--- a/src/com/google/gct/login/GoogleLogin.java
+++ b/src/com/google/gct/login/GoogleLogin.java
@@ -70,9 +70,6 @@ public class GoogleLogin {
public static final Logger LOG = Logger.getInstance(GoogleLogin.class);
- /**
- * Constructor
- */
private GoogleLogin() {
this.clientInfo = getClientInfo();
this.uiFacade = new AndroidUiFacade();
@@ -85,8 +82,9 @@ public class GoogleLogin {
* Gets the {@link GoogleLogin} object.
* @return the {@link GoogleLogin} object.
*/
+ @NotNull
public static GoogleLogin getInstance() {
- if(instance == null) {
+ if (instance == null) {
instance = new GoogleLogin();
instance.dataStore.initializeUsers();
}
@@ -110,10 +108,10 @@ public class GoogleLogin {
* either succeeds or fails.
* @throws InvalidThreadTypeException
*/
- public static void promptToLogIn(final String message, @Nullable final IGoogleLoginCompletedCallback callback)
+ public static void promptToLogIn(@Nullable final String message, @Nullable final IGoogleLoginCompletedCallback callback)
throws InvalidThreadTypeException {
if (!instance.isLoggedIn()) {
- if(ApplicationManager.getApplication().isDispatchThread()) {
+ if (ApplicationManager.getApplication().isDispatchThread()) {
getInstance().logIn(message, callback);
} else {
throw new InvalidThreadTypeException("promptToLogin");
@@ -135,6 +133,7 @@ public class GoogleLogin {
* @return An HttpRequestFactory object that has been signed with the active user's
* authentication headers or null if there is no active user.
*/
+ @Nullable
public HttpRequestFactory createRequestFactory() {
return createRequestFactory(null);
}
@@ -156,9 +155,10 @@ public class GoogleLogin {
* @return An HttpRequestFactory object that has been signed with the active user's
* authentication headers or null if there is no active user.
*/
- public HttpRequestFactory createRequestFactory(String message) {
+ @Nullable
+ public HttpRequestFactory createRequestFactory(@Nullable String message) {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
// TODO: prompt user to select an existing user or sign in
return null;
}
@@ -173,9 +173,10 @@ public class GoogleLogin {
* @throws IOException if something goes wrong while fetching the token.
*
*/
+ @Nullable
public String fetchAccessToken() throws IOException {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().fetchAccessToken();
@@ -185,9 +186,10 @@ public class GoogleLogin {
* Returns the OAuth2 Client ID for the active user.
* @return the OAuth2 Client ID for the active user.
*/
+ @Nullable
public String fetchOAuth2ClientId() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().fetchOAuth2ClientId();
@@ -197,9 +199,10 @@ public class GoogleLogin {
* Returns the OAuth2 Client Secret for the active user.
* @return the OAuth2 Client Secret for the active user.
*/
+ @Nullable
public String fetchOAuth2ClientSecret() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().fetchOAuth2ClientSecret();
@@ -212,9 +215,10 @@ public class GoogleLogin {
*
* @return the refresh token, or {@code null} if the user cancels out of a request to log in
*/
+ @Nullable
public String fetchOAuth2RefreshToken() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().fetchOAuth2RefreshToken();
@@ -229,9 +233,10 @@ public class GoogleLogin {
* @throws IOException if something goes wrong while fetching the token.
*
*/
+ @Nullable
public String fetchOAuth2Token() throws IOException {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().fetchOAuth2Token();
@@ -242,9 +247,10 @@ public class GoogleLogin {
* returns credentials with the access token and refresh token set to null.
* @return the OAuth credentials.
*/
+ @Nullable
public Credential getCredential() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().getCredential();
@@ -254,9 +260,10 @@ public class GoogleLogin {
* Returns the active user's email address, or null if there is no active user,
* @return the active user's email address, or null if there is no active user,
*/
+ @Nullable
public String getEmail() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
}
return activeUser.getGoogleLoginState().getEmail();
@@ -331,7 +338,7 @@ public class GoogleLogin {
}
});
- loggedIn = state.logInWithLocalServer(message);
+ loggedIn = state != null && state.logInWithLocalServer(message);
}
@Override
@@ -383,7 +390,7 @@ public class GoogleLogin {
*/
public boolean logOut() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return false;
}
@@ -405,7 +412,7 @@ public class GoogleLogin {
*/
public boolean logOut(boolean showPrompt) {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return false;
}
return activeUser.getGoogleLoginState().logOut(showPrompt);
@@ -417,13 +424,13 @@ public class GoogleLogin {
* the access and refresh token will be set to null.
* @return a new {@link Credential}.
*/
+ @Nullable
public Credential makeCredential() {
CredentialedUser activeUser = users.getActiveUser();
- if(activeUser == null) {
+ if (activeUser == null) {
return null;
- } else {
- return activeUser.getGoogleLoginState().makeCredential();
}
+ return activeUser.getGoogleLoginState().makeCredential();
}
/**
@@ -502,7 +509,7 @@ public class GoogleLogin {
uiFacade,
new AndroidLoggerFacade());
- if(initializingUsers && !state.isLoggedIn()) {
+ if (initializingUsers && !state.isLoggedIn()) {
// Logs user out if oauth scope for active user's credentials
// does not match the current scope
return null;
@@ -515,7 +522,7 @@ public class GoogleLogin {
* Returns the Client Info for Android Studio in a {@link com.google.gct.login.GoogleLogin.ClientInfo}.
* @return the Client Info for Android Studio in a {@link com.google.gct.login.GoogleLogin.ClientInfo}.
*/
- private ClientInfo getClientInfo() {
+ private static ClientInfo getClientInfo() {
String id = LoginContext.getId();
String info = LoginContext.getInfo();
if (id != null && id.trim().length() > 0
@@ -527,7 +534,7 @@ public class GoogleLogin {
}
// TODO: update code to specify parent
- private void logErrorAndDisplayDialog(@NotNull final String title, @NotNull final Exception exception) {
+ private static void logErrorAndDisplayDialog(@NotNull final String title, @NotNull final Exception exception) {
LOG.error(exception.getMessage(), exception);
GoogleLoginUtils.showErrorDialog(exception.getMessage(), title);
}
@@ -627,13 +634,17 @@ public class GoogleLogin {
@Override
public boolean askYesOrNo(String title, String message) {
String updatedMessage = message;
- if(message.equals("Are you sure you want to sign out?")) {
+ if (message.equals("Are you sure you want to sign out?")) {
+ updatedMessage = "Are you sure you want to sign out";
CredentialedUser activeUser = getActiveUser();
- String name = activeUser.getName().isEmpty() ? "" : activeUser.getName() + " ";
- updatedMessage = "Are you sure you want to sign out " + name
- + "(" + activeUser.getEmail() + ")?";
+ if (activeUser != null && !Strings.isNullOrEmpty(activeUser.getName())) {
+ updatedMessage += (" " + activeUser.getName());
+ }
+ if (activeUser != null && !Strings.isNullOrEmpty(activeUser.getEmail())) {
+ updatedMessage += (" (" + activeUser.getEmail() + ")");
+ }
+ updatedMessage += "?";
}
-
Icon icon = IconLoader.getIcon(GOOGLE_IMG);
return (Messages.showYesNoDialog(updatedMessage, title, icon) == Messages.YES);
}
@@ -685,7 +696,7 @@ public class GoogleLogin {
List<String> allUsers = GoogleLoginPrefs.getStoredUsers();
String removedUsers = "";
- for(String aUser : allUsers) {
+ for (String aUser : allUsers) {
// Add a new user, so that loadOAuth called from the GoogleLoginState constructor
// will be able to create a customized key to get that user's OAuth data
// This will be overwritten with new GoogleLoginState object
@@ -728,9 +739,8 @@ public class GoogleLogin {
}
// Log removed users
- if(!removedUsers.isEmpty()) {
- String message = "The following user(s) had expired authentication scopes: " + removedUsers
- + "and have been logged out.";
+ if (!removedUsers.isEmpty()) {
+ String message = "The following user(s) had expired authentication scopes: " + removedUsers + "and have been logged out.";
GoogleLoginUtils.showErrorDialog(message, "Google Login");
}
}
diff --git a/src/com/google/gct/login/GoogleLoginListener.java b/src/com/google/gct/login/GoogleLoginListener.java
index 560f5f0..84f1778 100644
--- a/src/com/google/gct/login/GoogleLoginListener.java
+++ b/src/com/google/gct/login/GoogleLoginListener.java
@@ -21,8 +21,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
* Listener for changes in the login status.
*/
public interface GoogleLoginListener {
- public static ExtensionPointName<GoogleLoginListener> EP_NAME =
- new ExtensionPointName<GoogleLoginListener>("com.google.gct.login.googleLoginListener");
+ ExtensionPointName<GoogleLoginListener> EP_NAME = new ExtensionPointName<GoogleLoginListener>("com.google.gct.login.googleLoginListener");
/**
* Called when the login or active status of the user changes.
diff --git a/src/com/google/gct/login/GoogleLoginPrefs.java b/src/com/google/gct/login/GoogleLoginPrefs.java
index 1872f4e..0c9afd0 100644
--- a/src/com/google/gct/login/GoogleLoginPrefs.java
+++ b/src/com/google/gct/login/GoogleLoginPrefs.java
@@ -18,10 +18,12 @@ package com.google.gct.login;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
import com.google.gdt.eclipse.login.common.OAuthData;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -184,6 +186,7 @@ public class GoogleLoginPrefs {
* Retrieves the persistently stored active user.
* @return the stored active user.
*/
+ @Nullable
public static String getActiveUser() {
Preferences prefs = getPrefs();
String activeUser = prefs.get(ACTIVE_USER, null);
@@ -250,9 +253,9 @@ public class GoogleLoginPrefs {
flushPrefs(prefs);
}
- private static void removeUser(Preferences prefs, String user) {;
+ private static void removeUser(Preferences prefs, String user) {
String allUsersString = prefs.get(USERS, "");
- List<String> allUsers = new ArrayList<String>();
+ List<String> allUsers = Lists.newArrayList();
for (String scope : allUsersString.split(DELIMITER)) {
allUsers.add(scope);
}
diff --git a/src/com/google/gct/login/GoogleLoginUtils.java b/src/com/google/gct/login/GoogleLoginUtils.java
index adf1777..11a29a9 100644
--- a/src/com/google/gct/login/GoogleLoginUtils.java
+++ b/src/com/google/gct/login/GoogleLoginUtils.java
@@ -51,7 +51,6 @@ public class GoogleLoginUtils {
* @param pictureCallback
* @return the user's picture from <code>userInfo</code>
*/
- @Nullable
public static void getUserPicture(Userinfoplus userInfo, final IUserPropertyCallback pictureCallback) {
// set the size of the image before it is served
String urlString = userInfo.getPicture() + "?sz=" + DEFAULT_PICTURE_SIZE;
@@ -76,7 +75,6 @@ public class GoogleLoginUtils {
});
}
- @Nullable
public static void getUserInfo(@NotNull final Credential credential,
final IUserPropertyCallback callback) {
final Oauth2 userInfoService =
@@ -131,6 +129,7 @@ public class GoogleLoginUtils {
* Used for testing.
* @return a {@link Credential} object for the fake user.
*/
+ @NotNull
public static Credential makeFakeUserCredential() {
String clientId = System.getenv().get("ANDROID_CLIENT_ID");
String clientSecret = System.getenv().get("ANDROID_CLIENT_SECRET");
diff --git a/src/com/google/gct/login/OAuthScopeRegistry.java b/src/com/google/gct/login/OAuthScopeRegistry.java
index a0c23b5..31f96c7 100644
--- a/src/com/google/gct/login/OAuthScopeRegistry.java
+++ b/src/com/google/gct/login/OAuthScopeRegistry.java
@@ -15,8 +15,6 @@
*/
package com.google.gct.login;
-
-import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
@@ -27,19 +25,18 @@ import java.util.TreeSet;
* Holds the list of OAuth2 scopes for Google Login.
*/
class OAuthScopeRegistry {
- private static final SortedSet<String> sScopes;
+ private static final SortedSet<String> SCOPES;
static {
SortedSet<String> scopes = new TreeSet<String>();
scopes.add("https://www.googleapis.com/auth/userinfo#email");
scopes.add("https://www.googleapis.com/auth/appengine.admin");
scopes.add("https://www.googleapis.com/auth/cloud-platform");
-
- sScopes = Collections.unmodifiableSortedSet(scopes);
+ SCOPES = Collections.unmodifiableSortedSet(scopes);
}
@NotNull
public static SortedSet<String> getScopes() {
- return sScopes;
+ return SCOPES;
}
}
diff --git a/src/com/google/gct/login/ui/UsersListCellRenderer.java b/src/com/google/gct/login/ui/UsersListCellRenderer.java
index 928eeba..01e319a 100644
--- a/src/com/google/gct/login/ui/UsersListCellRenderer.java
+++ b/src/com/google/gct/login/ui/UsersListCellRenderer.java
@@ -16,6 +16,9 @@
package com.google.gct.login.ui;
import com.intellij.ui.ColorUtil;
+import com.google.api.client.util.Maps;
+import com.google.gct.login.CredentialedUser;
+import com.google.gct.login.GoogleLogin;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
@@ -42,7 +45,7 @@ import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.net.URL;
-
+import java.util.Map;
/**
* A custom cell render for {@link GoogleLoginUsersPanel#list} that manages
@@ -82,6 +85,11 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
private final Dimension myPlayLabelDimension;
private final Dimension myLearnMoreLabelDimension;
+ /** Maps user emails to large user image icons. */
+ private final Map<String, Image> myUserLargeImageCache = Maps.newHashMap();
+ /** Maps user emails to small user image icons. */
+ private final Map<String, Image> myUserSmallImageCache = Maps.newHashMap();
+
public UsersListCellRenderer() {
myNameFont = new Font("Helvetica", Font.BOLD, 13);
myGeneralFont = new Font("Helvetica", Font.PLAIN, 13);
@@ -101,49 +109,58 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
@Nullable
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
- if(value instanceof NoUsersListItem) {
+ if (value instanceof NoUsersListItem) {
return createNoUserDisplay();
}
-
- if(!(value instanceof UsersListItem)) {
+ if (!(value instanceof UsersListItem)) {
return null;
}
- UsersListItem usersListItem = (UsersListItem)value;
- boolean calcIsSelected;
- if (list.getSelectedIndex() == index) {
- calcIsSelected = true;
- } else {
- calcIsSelected = false;
- }
+ final UsersListItem usersListItem = (UsersListItem)value;
+ final CredentialedUser activeUser = GoogleLogin.getInstance().getActiveUser();
+ final boolean isActiveUserSelected = activeUser != null && usersListItem.getUserEmail().equals(activeUser.getEmail());
JPanel mainPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, HGAP, VGAP));
- mainPanel.setMinimumSize(calcIsSelected ? myActiveMainPanelDimension : myMainPanelDimension);
+ mainPanel.setMinimumSize(isActiveUserSelected ? myActiveMainPanelDimension : myMainPanelDimension);
mainPanel.setAlignmentX(LEFT_ALIGNMENT);
// Update colors
- final Color bg = calcIsSelected ? myActiveColor : myInactiveColor;
- final Color fg = calcIsSelected ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
+ final Color bg = isActiveUserSelected ? myActiveColor : myInactiveColor;
+ final Color fg = isActiveUserSelected ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
mainPanel.setBackground(bg);
mainPanel.setForeground(fg);
- // TODO: add step to cache scaled image
Image image = usersListItem.getUserPicture();
- if(image == null){
- // use default image
- URL url = UsersListCellRenderer.class.getResource(DEFAULT_AVATAR);
- image = Toolkit.getDefaultToolkit().getImage(url);
+ if (image == null){
+ // Use default profile image.
+ image = Toolkit.getDefaultToolkit().getImage(UsersListCellRenderer.class.getResource(DEFAULT_AVATAR));
}
- int imageWidth = calcIsSelected ? ACTIVE_USER_IMAGE_WIDTH : PLAIN_USER_IMAGE_WIDTH;
- int imageHeight = calcIsSelected ? ACTIVE_USER_IMAGE_HEIGHT : PLAIN_USER_IMAGE_HEIGHT;
- Image scaledImage = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH);
+ final int imageWidth, imageHeight;
+ final Map<String, Image> userImageCache;
+ if (isActiveUserSelected) {
+ imageWidth = ACTIVE_USER_IMAGE_WIDTH;
+ imageHeight = ACTIVE_USER_IMAGE_HEIGHT;
+ userImageCache = myUserLargeImageCache;
+ } else {
+ imageWidth = PLAIN_USER_IMAGE_WIDTH;
+ imageHeight = PLAIN_USER_IMAGE_HEIGHT;
+ userImageCache = myUserSmallImageCache;
+ }
+
+ final Image scaledImage;
+ if (!userImageCache.containsKey(usersListItem.getUserEmail())) {
+ scaledImage = image.getScaledInstance(imageWidth, imageHeight, Image.SCALE_SMOOTH);
+ userImageCache.put(usersListItem.getUserEmail(), scaledImage);
+ } else {
+ scaledImage = userImageCache.get(usersListItem.getUserEmail());
+ }
- JComponent textPanel;
- if (calcIsSelected) {
- textPanel = createActiveTextDisplay(usersListItem);
+ final JComponent textPanel;
+ if (isActiveUserSelected) {
+ textPanel = createActiveTextDisplay(usersListItem);
} else {
- textPanel = createTextDisplay(calcIsSelected, usersListItem);
+ textPanel = createTextDisplay(false, usersListItem);
}
mainPanel.add(new JLabel(new ImageIcon(scaledImage)));
@@ -161,13 +178,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
double playYEnd = playYStart + myPlayLabelDimension.getHeight();
double playXStart = ACTIVE_USER_IMAGE_WIDTH + HGAP + VGAP;
double playXEnd = playXStart + myPlayLabelDimension.getWidth();
-
- if((point.getX() > playXStart) && (point.getX() < playXEnd)
- && (point.getY() > playYStart) && (point.getY() < playYEnd)) {
- return true;
- }
-
- return false;
+ return (point.getX() > playXStart) && (point.getX() < playXEnd) && (point.getY() > playYStart) && (point.getY() < playYEnd);
}
public boolean inCloudConsoleUrl(Point point, int activeIndex) {
@@ -177,13 +188,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
double playYEnd = playYStart + myCloudLabelDimension.getHeight();
double playXStart = ACTIVE_USER_IMAGE_WIDTH + HGAP + VGAP;
double playXEnd = playXStart + myCloudLabelDimension.getWidth();
-
- if((point.getX() > playXStart) && (point.getX() < playXEnd)
- && (point.getY() > playYStart) && (point.getY() < playYEnd)) {
- return true;
- }
-
- return false;
+ return (point.getX() > playXStart) && (point.getX() < playXEnd) && (point.getY() > playYStart) && (point.getY() < playYEnd);
}
public boolean inLearnMoreUrl(Point point) {
@@ -193,13 +198,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
double urlYEnd = urlYStart + myLearnMoreLabelDimension.getHeight();
double urlXStart = GOOGLE_IMAGE_WEST;
double urlXEnd = urlXStart + myLearnMoreLabelDimension.getWidth();
-
- if((point.getX() > urlXStart) && (point.getX() < urlXEnd)
- && (point.getY() > urlYStart) && (point.getY() < urlYEnd)) {
- return true;
- }
-
- return false;
+ return (point.getX() > urlXStart) && (point.getX() < urlXEnd) && (point.getY() > urlYStart) && (point.getY() < urlYEnd);
}
public int getMainPanelHeight() {
@@ -286,8 +285,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
String googleIcon = UIUtil.isUnderDarcula() ? GOOGLE_IMG_WHITE : GOOGLE_IMG_COL;
URL url = UsersListCellRenderer.class.getResource(googleIcon);
Image image = Toolkit.getDefaultToolkit().getImage(url);
- Image scaledImage = image.getScaledInstance(
- GOOGLE_IMAGE_WIDTH, GOOGLE_IMAGE_HEIGHT, Image.SCALE_SMOOTH);
+ Image scaledImage = image.getScaledInstance(GOOGLE_IMAGE_WIDTH, GOOGLE_IMAGE_HEIGHT, Image.SCALE_SMOOTH);
JLabel imageLabel = new JLabel(new ImageIcon(scaledImage));
JLabel signInLabel = new JLabel(SIGN_IN_TEXT);